RE: [PATCH v2 00/21] Add support for MMC higher speed modes for TI's am65x, j721e and j7200 platforms

2020-10-19 Thread Peng Fan
> Subject: [PATCH v2 00/21] Add support for MMC higher speed modes for TI's
> am65x, j721e and j7200 platforms

For the mmc driver part, 

Reviewed-by: Peng Fan 

> 
> The following patches add support for higher speeds in the SD card and eMMC
> for TI's am65x, j721e, j7200 platforms.
> 
> With these patches, the following max speeds are supported:
> j721e: DDR50, HS200
> j7200: SDR104, HS200
> am65x: SDR104*, HS200
> 
> v2:
> 1. Added patches to support UHS modes for the SD card even in am654x
> platforms.
> 2. Fixed an issue with patch 1 that was breaking builds on some platforms.
> 
> * There's an issue with the am65x base board such that the power cycle
> circuit to the card takes way longer than the wait time in mmc core.
> Until this is fixed, am654x-evm and -idk will only support High speed mode at
> 3.3V (see patch 20) but this shouldn't block us from adding UHS modes in the
> dtsi as well as in the configs so other boards can still take advantage of the
> higher speed. UHS modes have been tested by adding the appropriate delay in
> the power cycle circuit.
> 
> Link to v1:
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatch
> work.ozlabs.org%2Fproject%2Fuboot%2Flist%2F%3Fseries%3D206622
> data=04%7C01%7Cpeng.fan%40nxp.com%7C60aff07a45894e36209308d871c
> 3e441%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6373844334
> 69526801%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoi
> V2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000sdata=bRq92%2
> FV4JzEhNipqsw5%2BqsgTOfJPqsmaSe3%2BkmnU3%2BU%3Dreserved
> =0
> 
> Faiz Abbas (21):
>   mmc: sdhci: Add helper functions for UHS modes
>   mmc: am654_sdhci: Unconditionally switch off DLL in the beginning of
> ios_post()
>   mmc: am654_sdhci: Convert flag fields to BIT macro
>   mmc: am654_sdhci: Add flag for PHY calibration
>   mmc: am654_sdhci: Add support for AM65x SR2.0
>   mmc: am654_sdhci: Add support for input tap delay
>   mmc: am654_sdhci: Add support for writing to clkbuf_sel
>   mmc: am654_sdhci: Add support for software tuning
>   mmc: am654_sdhci: Fix HISPD bit configuration in some lower speed
> modes
>   mmc: am654_sdhci: Use sdhci_set_control_reg()
>   arm: dts: k3-am65: Fix mmc nodes
>   arm: dts: k3-j721e-main: Update otap-delay values
>   arm: dts: k3-j721e-common-proc-board: Add support for UHS modes for SD
> card
>   arm: dts: k3-j7200-main: Add support for gpio0
>   arm: dts: k3-j7200-common-proc-board: Enable support for UHS modes
>   configs: j721e_evm: Add support for UHS modes
>   configs: j7200_evm: Add support for UHS modes
>   i2c: Makefile: Add SPL_DM_I2C_GPIO
>   arm: dts: k3-am65-main: Add itapdly and clkbuf-sel values
>   arm: dts: k3-am654-base-board: Limit Sd card to High speed modes
>   configs: am65x_evm: Add configs for UHS modes
> 
>  arch/arm/dts/k3-am65-main.dtsi|  31 ++
>  arch/arm/dts/k3-am654-base-board-u-boot.dtsi  |  67 +--
>  arch/arm/dts/k3-am654-base-board.dts  |  26 ++
>  arch/arm/dts/k3-am654-r5-base-board.dts   |  20 +-
>  arch/arm/dts/k3-j7200-common-proc-board.dts   |  49 ++-
>  arch/arm/dts/k3-j7200-main.dtsi   |  23 ++
>  .../arm/dts/k3-j7200-r5-common-proc-board.dts |  15 +
>  arch/arm/dts/k3-j721e-common-proc-board.dts   |  32 ++
>  arch/arm/dts/k3-j721e-main.dtsi   |   8 +-
>  configs/am65x_evm_a53_defconfig   |   8 +
>  configs/am65x_evm_r5_defconfig|   2 +
>  configs/j7200_evm_a72_defconfig   |   8 +
>  configs/j7200_evm_r5_defconfig|   1 +
>  configs/j721e_evm_a72_defconfig   |   8 +
>  configs/j721e_evm_r5_defconfig|   1 +
>  drivers/i2c/Makefile  |   2 +-
>  drivers/mmc/Kconfig   |   1 +
>  drivers/mmc/am654_sdhci.c | 384
> +-
>  drivers/mmc/sdhci.c   |  51 +++
>  include/sdhci.h   |   1 +
>  20 files changed, 564 insertions(+), 174 deletions(-)
> 
> --
> 2.17.1



[PATCH] arm: octeontx: Enable network support in supported boards

2020-10-19 Thread Stefan Roese
Enable the now included network drivers in the currently supported
Marvell Octeon TX & TX2 boards.

Signed-off-by: Stefan Roese 
Cc: Aaron Williams 
Cc: Suneel Garapati 
Cc: Chandrakala Chavva 
---
 configs/octeontx2_95xx_defconfig | 2 ++
 configs/octeontx2_96xx_defconfig | 2 ++
 configs/octeontx_81xx_defconfig  | 2 ++
 configs/octeontx_83xx_defconfig  | 2 ++
 4 files changed, 8 insertions(+)

diff --git a/configs/octeontx2_95xx_defconfig b/configs/octeontx2_95xx_defconfig
index e37c83742b..591caa7a0d 100644
--- a/configs/octeontx2_95xx_defconfig
+++ b/configs/octeontx2_95xx_defconfig
@@ -86,6 +86,8 @@ CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_DM_ETH=y
+CONFIG_NET_OCTEONTX2=y
+CONFIG_OCTEONTX_SMI=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
 CONFIG_DM_PCI_COMPAT=y
diff --git a/configs/octeontx2_96xx_defconfig b/configs/octeontx2_96xx_defconfig
index 8db34a729e..c7cfae4d0f 100644
--- a/configs/octeontx2_96xx_defconfig
+++ b/configs/octeontx2_96xx_defconfig
@@ -99,6 +99,8 @@ CONFIG_DM_ETH=y
 CONFIG_E1000=y
 CONFIG_E1000_SPI=y
 CONFIG_CMD_E1000=y
+CONFIG_NET_OCTEONTX2=y
+CONFIG_OCTEONTX_SMI=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
diff --git a/configs/octeontx_81xx_defconfig b/configs/octeontx_81xx_defconfig
index 78efcf5533..c006a14bdc 100644
--- a/configs/octeontx_81xx_defconfig
+++ b/configs/octeontx_81xx_defconfig
@@ -100,6 +100,8 @@ CONFIG_DM_ETH=y
 CONFIG_E1000=y
 CONFIG_E1000_SPI=y
 CONFIG_CMD_E1000=y
+CONFIG_NET_OCTEONTX=y
+CONFIG_OCTEONTX_SMI=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
diff --git a/configs/octeontx_83xx_defconfig b/configs/octeontx_83xx_defconfig
index f5b052871c..86b4bc5190 100644
--- a/configs/octeontx_83xx_defconfig
+++ b/configs/octeontx_83xx_defconfig
@@ -97,6 +97,8 @@ CONFIG_DM_ETH=y
 CONFIG_E1000=y
 CONFIG_E1000_SPI=y
 CONFIG_CMD_E1000=y
+CONFIG_NET_OCTEONTX=y
+CONFIG_OCTEONTX_SMI=y
 CONFIG_NVME=y
 CONFIG_PCI=y
 CONFIG_DM_PCI=y
-- 
2.28.0



Re: SMBIOS entry point

2020-10-19 Thread Michal Simek
Hi Heinrich,

On 15. 10. 20 19:18, Heinrich Schuchardt wrote:
> According to
> 
> DSP0134, 3.4.0, System Management BIOS (SMBIOS) Reference Specification
> https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.4.0.pdf
> 
> our struct smbios_entry is an SMBIOS 2.1 (32-bit) Entry Point structure.
> This structure requires that the SMBIOS table is located below 4 GiB.
> 
> Some boards (ZynqMP, Versal) do not have memory mapped in the low 4 GiB
> of the address space. So shouldn't we use the SMBIOS 3.0 (64-bit) Entry
> Point structure?

Just to make it clear. Yes there are configurations which can be done
like this that there is no memory in low 4GB.

Thanks,
Michal


Re: [PATCH v2 2/3] allow positional arguments with "run" command

2020-10-19 Thread Wolfgang Denk
Dear Rasmus,

In message <2284dd1d-f20c-6246-805e-55454a581...@prevas.dk> you wrote:
>
> > Yes that's good, but is the plan now to take these patches rather than
> > update to the latest hush? I was wondering is Buzybox has any tests
> > for hush.
>
> Well, updating the whole hush code is not, as I've said before,
> something I can or will take on me ATM, and it's not even clear that
> that would automatically provide real shell functions.

Yes, current versions of busybox hush do implement shell functions;
tested under Fedora 32:

-> rpm -q busybox
busybox-1.31.1-2.fc32.x86_64
-> cd /tmp
-> ln -s /sbin/busybox hush
-> ./hush
-> foo() {
> echo argc=$# arg1=$1 arg2=$2 arg3=$3
> }
-> foo
argc=0 arg1= arg2= arg3=
-> foo aa
argc=1 arg1=aa arg2= arg3=
-> foo aa bb
argc=2 arg1=aa arg2=bb arg3=
-> foo aa bb cc
argc=3 arg1=aa arg2=bb arg3=cc
-> foo aa bb cc dd
argc=4 arg1=aa arg2=bb arg3=cc
-> exit

No, I cannot see any shell / hush related test code in the busybox
repository.

> Whether "the plan" includes accepting these patches I can't say. I'm
> just trying to plug a hole and make the U-Boot shell a little more
> usable. It's somewhat similar to the setexpr command; we don't have
> $((a+4)) arithmetic, but can achieve the same thing with an extra
> command. Or askenv, which takes the place of 'read -p'. Or run, for that
> matter, which combined with setenv can do much of what eval in a POSIX
> shell could do. And with 3/3, there's a place to put tests of e.g.
> setexpr (not that adding the boilerplate is hard, but it is a tedious
> first step; once that is in place, adding extra test cases is somewhat
> easier and natural).

Well, that's note really the same.  For shell functions, ther eis
now a (hopefully) clean implementation in recent versions of hush,
so upgrading to a recent version would not only solve the
problem/task we're discussing here, but also bring a lot of other
bug fixes and improvements.

The examples you mentioned above are moe related to U-Boots concept
of environment handling, which is idependent of the shell we are
using i. e. it's the same with U-Boots own trivial command parser.


My big concern here is that adding bells and whistles to our ancient
version of hush will just make it all the harder to upgrade to a
recent version.  Already now we have the situation that we must be
afraid to break existing code which works around some of the
problems.  Adding more "special code" will not make this better.

And even if we can upgrade to a new version independently, we still
might have to keep this workaround code for compatibility, as people
started using it, and it is not compatible with any existing shell.


So the _much_ better approach would indeed be to upgrade to a recent
version of hush.


Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
I have a very small mind and must live with it.-- Edsger Dijkstra


Re: [PATCH v3] armv8: layerscape: don't remove crypto node if just partially disabled

2020-10-19 Thread Horia Geantă
On 10/16/2020 8:38 PM, Michael Walle wrote:
> On all newer Layerscape SoCs, only the export-controlled ciphers of the
> crypto module are disabled on non-E parts. Thus it doesn't make sense to
> completely remove the node. Linux will figure out what is there and what
> is not.
> 
> Just remove it for older SoCs, where the module is indeed completely
> disabled on non-E parts.
> 
> Signed-off-by: Michael Walle 
Reviewed-by: Horia Geantă 

Thanks,
Horia


Re: [PATCH v2 2/3] allow positional arguments with "run" command

2020-10-19 Thread Rasmus Villemoes
On 19/10/2020 09.31, Wolfgang Denk wrote:
> Dear Rasmus,
> 
> In message <2284dd1d-f20c-6246-805e-55454a581...@prevas.dk> you wrote:
>>
>>> Yes that's good, but is the plan now to take these patches rather than
>>> update to the latest hush? I was wondering is Buzybox has any tests
>>> for hush.
>>
>> Well, updating the whole hush code is not, as I've said before,
>> something I can or will take on me ATM, and it's not even clear that
>> that would automatically provide real shell functions.
> 
> Yes, current versions of busybox hush do implement shell functions;
> tested under Fedora 32:

Not what I meant, of course busybox hush does that. What I meant is that
it is not at all obvious how that support would actually benefit U-Boot.
The problem is how one would go about getting the functions defined. Putting

define_func='func() { do_stuff $1 $2; do_more_stuff $3; }'

in the environment and then having to say

run define_func; func foo ...

does not really look like an improvement to me. In contrast, the current
way of defining "one-liner" functions and running with, well, run, is
quite ergonomic - but I do miss the ability to provide parameters other
than via global settings. With these patches, the above would just be

func='do_stuff $1 $2; do_more_stuff $3;'

run func -- foo ...

I guess one could have something like CONFIG_DOT_PROFILE and have that
point at a script that gets built into the U-Boot binary and sourced at
shell startup; then one could put one's functions in there, or have the
flexibility of having that file load some stdlib.sh from somewhere.

> 
> My big concern here is that adding bells and whistles to our ancient
> version of hush will just make it all the harder to upgrade to a
> recent version.  Already now we have the situation that we must be
> afraid to break existing code which works around some of the
> problems.  Adding more "special code" will not make this better.
> 
> And even if we can upgrade to a new version independently, we still
> might have to keep this workaround code for compatibility, as people
> started using it, and it is not compatible with any existing shell.
> 
> So the _much_ better approach would indeed be to upgrade to a recent
> version of hush.

I agree in principle - there are other shell features I'm also missing
(though see above, I don't immediately see how an upgrade would make
functions available in a useful way).

Someone speaking up and saying "I'm going to look at an overhaul of hush
within the next year or so" would clearly be a strong argument against
inclusion of these patches. Lacking such a pony promise, this really
boils down to an idealist/pragmatist issue, and we can keep going around
this in circles forever, so I think someone (Tom?) should make a decision.

Rasmus


Re: [PATCH v2 2/5] ARM: dts: sun8i: v3s: Add simple-framebuffer

2020-10-19 Thread Maxime Ripard
On Fri, Oct 16, 2020 at 07:17:02PM +0200, Martin Cerveny wrote:
> Add support for "allwinner,simple-framebuffer" with "mixer0-lcd0" pipeline.
> 
> Signed-off-by: Martin Cerveny 

Acked-by: Maxime Ripard 

Maxime


signature.asc
Description: PGP signature


Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Marek Vasut
On 10/19/20 5:46 AM, Chunfeng Yun wrote:
> Fix up the following build warning/error:
> 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
>mtu3_gadget_ep_set_halt()
> 2. implicit declaration of function ‘flush_dcache_range’ and
>‘invalidate_dcache_range’

Which patch of the ones in usb/next do I squash this in ?


RE: [PATCH] mx6: peripheral clock from oscillator

2020-10-19 Thread Peng Fan
> Subject: [PATCH] mx6: peripheral clock from oscillator
> 
> In order to be able to run the I2C bus at 400Khz, the chip errata[1]
> recommends that the peripheral clock runs out of the 24MHz oscillator.
> 
> [1] Rev 2, 10/2019, ERR007805
> 
> Signed-off-by: Jorge Ramirez-Ortiz 
> ---
>  arch/arm/mach-imx/mx6/soc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> index e129286065..1da250bbcd 100644
> --- a/arch/arm/mach-imx/mx6/soc.c
> +++ b/arch/arm/mach-imx/mx6/soc.c
> @@ -469,7 +469,7 @@ int arch_cpu_init(void)
>   }
> 
>   /* Set perclk to source from OSC 24MHz */
> - if (is_mx6sl())
> + if (is_mx6sl() || is_mx6ull())
>   setbits_le32(>cscmr1,
> MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
> 
>   imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register
> */
> --

Reviewed-by: Peng Fan 


Re: [PATCH] arm: sunxi: disable obsolete VIDEO config

2020-10-19 Thread Maxime Ripard
On Sun, Oct 18, 2020 at 09:18:15PM +0200, Anatolij Gustschin wrote:
> DM_VIDEO conversion deadline has passed, disable VIDEO config
> option by default. Boards should convert to DM_VIDEO if they
> need video console support.
> 
> Signed-off-by: Anatolij Gustschin 
> Cc: Jagan Teki 
> Cc: Maxime Ripard 
> ---
>  arch/arm/mach-sunxi/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index be0822bfb7..f672bb8b4e 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -760,7 +760,7 @@ config VIDEO_SUNXI
>   depends on !MACH_SUN50I_H6
>   select VIDEO
>   imply VIDEO_DT_SIMPLEFB
> - default y
> + default n

default n is the default with Kconfig iirc

Otherwise, I can't say that I agree with the forced conversion strategy
to the DM in general. We're struggling to keep U-Boot working from one
release to the other, so adding pressure to convert drivers feels a bit
too much.

I can see where you're coming from though, so I guess that's a
reluctantly-acked-by ? :)

Maxime


signature.asc
Description: PGP signature


Re: [PATCH v2 4/5] sunxi: video: v3s: Enable LCD support

2020-10-19 Thread Maxime Ripard
On Fri, Oct 16, 2020 at 07:17:04PM +0200, Martin Cerveny wrote:
> Enable support for V3s LCD display with following changes:
> 
> V3s has 2x VI and 1x UI channels (use UI channel).
> V3s uses PLL3 (PLL_VIDEO) for both DE2 and TCON0 pixelclock.
> V3s does not support doubleclock for PLL3.
> V3s supports resolution upto 1024x1024.
> V3s does not support HDMI.
> 
> Signed-off-by: Martin Cerveny 
> ---
>  arch/arm/include/asm/arch-sunxi/clock_sun6i.h |  5 ++--
>  arch/arm/include/asm/arch-sunxi/gpio.h|  1 +
>  arch/arm/mach-sunxi/Kconfig   |  1 +
>  drivers/video/sunxi/lcdc.c|  5 ++--
>  drivers/video/sunxi/sunxi_de2.c   | 25 ---
>  drivers/video/sunxi/sunxi_dw_hdmi.c   |  2 ++
>  drivers/video/sunxi/sunxi_lcd.c   |  9 ++-
>  7 files changed, 40 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/arm/include/asm/arch-sunxi/clock_sun6i.h 
> b/arch/arm/include/asm/arch-sunxi/clock_sun6i.h
> index ee387127f3..9efe05d103 100644
> --- a/arch/arm/include/asm/arch-sunxi/clock_sun6i.h
> +++ b/arch/arm/include/asm/arch-sunxi/clock_sun6i.h
> @@ -329,7 +329,7 @@ struct sunxi_ccm_reg {
>  #define AHB_GATE_OFFSET_DE   12
>  #define AHB_GATE_OFFSET_HDMI 11
>  #define AHB_GATE_OFFSET_TVE  9
> -#ifndef CONFIG_SUNXI_DE2
> +#if !defined(CONFIG_SUNXI_DE2) || defined(CONFIG_MACH_SUN8I_V3S)
>  #define AHB_GATE_OFFSET_LCD1 5
>  #define AHB_GATE_OFFSET_LCD0 4
>  #else
> @@ -476,7 +476,7 @@ struct sunxi_ccm_reg {
>  #define AHB_RESET_OFFSET_HDMI11
>  #define AHB_RESET_OFFSET_HDMI2   10
>  #define AHB_RESET_OFFSET_TVE 9
> -#ifndef CONFIG_SUNXI_DE2
> +#if !defined(CONFIG_SUNXI_DE2) || defined(CONFIG_MACH_SUN8I_V3S)

These two changes are confusing. The V3S has a DE2, so having that
condition is weird. I'd just add an elif there

>  #define AHB_RESET_OFFSET_LCD15
>  #define AHB_RESET_OFFSET_LCD04
>  #else
> @@ -510,6 +510,7 @@ struct sunxi_ccm_reg {
>  #define CCM_DE2_CTRL_PLL_MASK(3 << 24)
>  #define CCM_DE2_CTRL_PLL6_2X (0 << 24)
>  #define CCM_DE2_CTRL_PLL10   (1 << 24)
> +#define CCM_DE2_CTRL_PLL3_V3S(0 << 24)
>  #define CCM_DE2_CTRL_GATE(0x1 << 31)
>  
>  /* CCU security switch, H3 only */
> diff --git a/arch/arm/include/asm/arch-sunxi/gpio.h 
> b/arch/arm/include/asm/arch-sunxi/gpio.h
> index d83dfdf605..9b580fbe26 100644
> --- a/arch/arm/include/asm/arch-sunxi/gpio.h
> +++ b/arch/arm/include/asm/arch-sunxi/gpio.h
> @@ -181,6 +181,7 @@ enum sunxi_gpio_number {
>  #define SUN5I_GPE_SDC2   3
>  #define SUN8I_GPE_TWI2   3
>  #define SUN50I_GPE_TWI2  3
> +#define SUN8I_V3S_GPE_LCD0   3
>  
>  #define SUNXI_GPF_SDC0   2
>  #define SUNXI_GPF_UART0  4
> diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> index be0822bfb7..dc0ee2cdef 100644
> --- a/arch/arm/mach-sunxi/Kconfig
> +++ b/arch/arm/mach-sunxi/Kconfig
> @@ -258,6 +258,7 @@ config MACH_SUN8I_V3S
>   select CPU_V7_HAS_NONSEC
>   select CPU_V7_HAS_VIRT
>   select ARCH_SUPPORT_PSCI
> + select SUNXI_DE2
>   select SUNXI_GEN_SUN6I
>   select SUNXI_DRAM_DW
>   select SUNXI_DRAM_DW_16BIT
> diff --git a/drivers/video/sunxi/lcdc.c b/drivers/video/sunxi/lcdc.c
> index 73033c3b85..3d50f9d567 100644
> --- a/drivers/video/sunxi/lcdc.c
> +++ b/drivers/video/sunxi/lcdc.c
> @@ -244,7 +244,7 @@ void lcdc_pll_set(struct sunxi_ccm_reg *ccm, int tcon, 
> int dotclock,
>* not sync to higher frequencies.
>*/
>   for (m = min_m; m <= max_m; m++) {
> -#ifndef CONFIG_SUNXI_DE2
> +#if !defined(CONFIG_SUNXI_DE2) || defined(CONFIG_MACH_SUN8I_V3S)
>   n = (m * dotclock) / step;
>  
>   if ((n >= 9) && (n <= 127)) {
> @@ -262,7 +262,7 @@ void lcdc_pll_set(struct sunxi_ccm_reg *ccm, int tcon, 
> int dotclock,
>   if (!(m & 1))
>   continue;
>  #endif
> -
> +#ifndef CONFIG_MACH_SUN8I_V3S
>   /* No double clock on DE2 */
>   n = (m * dotclock) / (step * 2);
>   if ((n >= 9) && (n <= 127)) {
> @@ -275,6 +275,7 @@ void lcdc_pll_set(struct sunxi_ccm_reg *ccm, int tcon, 
> int dotclock,
>   best_double = 1;
>   }
>   }
> +#endif

I'm still not seeing any indication as to where you're getting this from

>   }
>  
>  #ifdef CONFIG_MACH_SUN6I
> diff --git a/drivers/video/sunxi/sunxi_de2.c b/drivers/video/sunxi/sunxi_de2.c
> index b657e163f0..49d41eb243 100644
> --- a/drivers/video/sunxi/sunxi_de2.c
> +++ b/drivers/video/sunxi/sunxi_de2.c
> @@ -26,12 +26,21 @@
>  
>  DECLARE_GLOBAL_DATA_PTR;
>  
> +#ifdef CONFIG_MACH_SUN8I_V3S
> +enum {
> + /* Maximum LCD size we support */
> + LCD_MAX_WIDTH   = 1024,
> + LCD_MAX_HEIGHT  = 1024,
> + 

Re: [PATCH v1 2/8] riscv: dts: Add device tree for Microchip Icicle Kit

2020-10-19 Thread Padmarao Begari
Hi anup,

On Sat, Oct 17, 2020 at 3:10 PM Anup Patel  wrote:

> On Fri, Oct 16, 2020 at 7:54 PM  wrote:
> >
> > From: Padmarao Begari 
> >
> > Add device tree for Microchip PolarFire SoC Icicle Kit.
> >
> > Signed-off-by: Padmarao Begari 
> > ---
> >  arch/riscv/dts/Makefile  |   1 +
> >  arch/riscv/dts/microchip-icicle-kit-a000.dts | 419 +++
> >  2 files changed, 420 insertions(+)
> >  create mode 100644 arch/riscv/dts/microchip-icicle-kit-a000.dts
> >
> > diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
> > index 3a6f96c67d..48c43bd122 100644
> > --- a/arch/riscv/dts/Makefile
> > +++ b/arch/riscv/dts/Makefile
> > @@ -3,6 +3,7 @@
> >  dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
> >  dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
> >  dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
> > +dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-icicle-kit-a000.dtb
> >
> >  targets += $(dtb-y)
> >
> > diff --git a/arch/riscv/dts/microchip-icicle-kit-a000.dts
> b/arch/riscv/dts/microchip-icicle-kit-a000.dts
> > new file mode 100644
> > index 00..e7f0ec6926
> > --- /dev/null
> > +++ b/arch/riscv/dts/microchip-icicle-kit-a000.dts
> > @@ -0,0 +1,419 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/* Copyright (c) 2020 Microchip Technology Inc */
> > +
> > +/dts-v1/;
> > +#include "dt-bindings/clock/microchip,pfsoc-clock.h"
> > +
> > +/ {
> > +   #address-cells = <2>;
> > +   #size-cells = <2>;
> > +   model = "Microchip PolarFire-SoC";
> > +   compatible = "microchip,polarfire-soc";
> > +
> > +   aliases {
> > +   serial0 = 
> > +   ethernet0 = 
>
> I see that HSS uses uart0 and over here we are assigning uart1. This
> forces users to always use two UARTs on the ICICLE board. This is very
> inconvenient and not at all consistent with SiFive Unleashed  and other
> ARM boards.
>
> It should be user's choice to use whether or not to use separate uart for
> S-mode software. Please don't force multiple uarts by default.
>
> By default, I suggest to use uart0 for U-Boot S-mode. If users want to
> use separate uart for Linux then they can do it using "bootargs" passed
> to Linux kernel from U-Boot.
>
> U-Boot being transient in the boot flow should use same uart as
> previous booting stage (in this case HSS).
>
> ok, will use UART0

> > +   };
> > +
> > +   chosen {
> > +   stdout-path = "serial0";
> > +   };
> > +
> > +   cpucomplex: cpus {
> > +   #address-cells = <1>;
> > +   #size-cells = <0>;
> > +   timebase-frequency = <100>;
> > +   cpu0: cpu@0 {
> > +   clocks = < CLK_CPU>;
> > +   compatible = "sifive,e51", "sifive,rocket0",
> "riscv";
> > +   device_type = "cpu";
> > +   i-cache-block-size = <64>;
> > +   i-cache-sets = <128>;
> > +   i-cache-size = <16384>;
> > +   reg = <0>;
> > +   riscv,isa = "rv64imac";
> > +   status = "disabled";
> > +   operating-points = <
> > +   /* kHz  uV */
> > +   60  110
> > +   30   95
> > +   15   75
> > +   >;
> > +   cpu0intc: interrupt-controller {
> > +   #interrupt-cells = <1>;
> > +   compatible = "riscv,cpu-intc";
> > +   interrupt-controller;
> > +   };
> > +   };
> > +   cpu1: cpu@1 {
> > +   clocks = < CLK_CPU>;
> > +   compatible = "sifive,u54-mc", "sifive,rocket0",
> "riscv";
> > +   d-cache-block-size = <64>;
> > +   d-cache-sets = <64>;
> > +   d-cache-size = <32768>;
> > +   d-tlb-sets = <1>;
> > +   d-tlb-size = <32>;
> > +   device_type = "cpu";
> > +   i-cache-block-size = <64>;
> > +   i-cache-sets = <64>;
> > +   i-cache-size = <32768>;
> > +   i-tlb-sets = <1>;
> > +   i-tlb-size = <32>;
> > +   mmu-type = "riscv,sv39";
> > +   reg = <1>;
> > +   riscv,isa = "rv64imafdc";
> > +   tlb-split;
> > +   status = "okay";
> > +   operating-points = <
> > +   /* kHz  uV */
> > +   60  110
> > +   30   95
> > +   15   75
> > +   >;

Re: [PATCH 03/18] mips: mtmips: fix dram size detection in dram_init

2020-10-19 Thread Stefan Roese

On 16.10.20 09:35, Weijie Gao wrote:

CONFIG_SYS_SDRAM_BASE points to cached memory, i.e. KSEG0, which is not
suitable for detecting memory size.

Replace CONFIG_SYS_SDRAM_BASE with KSEG1, and make dram_init() always do
memory size detection in any stage.

Signed-off-by: Weijie Gao 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/mips/mach-mtmips/cpu.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/mips/mach-mtmips/cpu.c b/arch/mips/mach-mtmips/cpu.c
index 2ddf8cb096..ca1967055a 100644
--- a/arch/mips/mach-mtmips/cpu.c
+++ b/arch/mips/mach-mtmips/cpu.c
@@ -6,6 +6,7 @@
  #include 
  #include 
  #include 
+#include 
  #include 
  #include 
  #include 
@@ -14,9 +15,7 @@ DECLARE_GLOBAL_DATA_PTR;
  
  int dram_init(void)

  {
-#ifdef CONFIG_SKIP_LOWLEVEL_INIT
-   gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, SZ_256M);
-#endif
+   gd->ram_size = get_ram_size((void *)KSEG1, SZ_256M);
  
  	return 0;

  }




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH] mx6: peripheral clock from oscillator

2020-10-19 Thread Jorge Ramirez-Ortiz, Foundries
On 19/10/20, Fabio Estevam wrote:
> Hi Jorge,
> 
> On Wed, Oct 14, 2020 at 10:07 AM Jorge Ramirez-Ortiz  
> wrote:
> >
> > In order to be able to run the I2C bus at 400Khz, the chip errata[1]
> > recommends that the peripheral clock runs out of the 24MHz oscillator.
> >
> > [1] Rev 2, 10/2019, ERR007805
> >
> > Signed-off-by: Jorge Ramirez-Ortiz 
> > ---
> >  arch/arm/mach-imx/mx6/soc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> > index e129286065..1da250bbcd 100644
> > --- a/arch/arm/mach-imx/mx6/soc.c
> > +++ b/arch/arm/mach-imx/mx6/soc.c
> > @@ -469,7 +469,7 @@ int arch_cpu_init(void)
> > }
> >
> > /* Set perclk to source from OSC 24MHz */
> > -   if (is_mx6sl())
> > +   if (is_mx6sl() || is_mx6ull())
> 
> According to https://www.nxp.com/docs/en/errata/IMX6SDLCE.pdf the
> mx6solo and mx6dl are also affected by ERR007805.

ah ok, I'll repost.

just as background info, this is needed in order for OP-TEE to access
the EdgeLock SE050 secure element at a decent speed. I couldnt merge
the support for the imx6ul i2c driver during the last OP-TEE release
but will try again when I find some time (surely before their next
release)


> 
> These variants should be handled too.


Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Chunfeng Yun
On Mon, 2020-10-19 at 08:07 +0200, Marek Vasut wrote:
> On 10/19/20 5:46 AM, Chunfeng Yun wrote:
> > Fix up the following build warning/error:
> > 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
> >mtu3_gadget_ep_set_halt()
> > 2. implicit declaration of function ‘flush_dcache_range’ and
> >‘invalidate_dcache_range’
> 
> Which patch of the ones in usb/next do I squash this in ?

squash in:  ab703ebb1c usb: add MediaTek USB3 DRD driver

Thanks a lot


Re: [PATCH] dm: core: add function uclass_probe_all() to probe all devices

2020-10-19 Thread Stefan Roese

On 19.10.20 11:37, Vabhav Sharma wrote:

From: Vabhav Sharma 

Support a common method to probe all devices associated with uclass.

This includes data structures and code for finding the first device and
looping for remaining devices associated with uclasses (groups of devices
with the same purpose, e.g. all SERIAL ports will be in the same uclass).

An example is SBSA compliant PL011 UART IP, where firmware does the serial
port initialization and prepare uart device to let the kernel use it for
sending and reveiving the characters.SERIAL uclass will use this function
to initialize PL011 UART ports.

The feature is enabled with CONFIG_DM.

Signed-off-by: Vabhav Sharma 
--
   Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400
385-11854-1-git-send-email-vabhav.sha...@oss.nxp.com/
---
  drivers/core/uclass.c | 17 +
  include/dm/uclass.h   | 12 
  2 files changed, 29 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73..0725e8e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
  }
  #endif
  
+int uclass_probe_all(enum uclass_id id)

+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device(id, );
+   if (ret || !dev)
+   return ret;
+   if (dev) {
+   /* Scanning uclass to probe all devices */
+   for (; dev; uclass_next_device())
+   ;
+   }
+
+   return 0;
+}
+
  UCLASS_DRIVER(nop) = {
.id = UCLASS_NOP,
.name   = "nop",
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 67ff746..0fce83f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong 
driver_data,
  int uclass_resolve_seq(struct udevice *dev);
  
  /**

+ * uclass_probe_all() - Probe all devices based on an uclass ID
+ *
+ * Every uclass is identified by an ID, a number from 0 to n-1 where n is
+ * the number of uclasses. This function probe all devices asocciated with
+ * a uclass by looking its ID.
+ *
+ * @id: uclass ID to look up
+ * @return 0 if OK, other -ve on error
+ */
+int uclass_probe_all(enum uclass_id id);
+
+/**
   * uclass_id_foreach_dev() - Helper function to iteration through devices
   *
   * This creates a for() loop which works through the available devices in



Ahh, here is the function. You should better move both patches into one
patchset, so that the dependency can be seen. Especially while applying.

Other that that:

Reviewed-by: Stefan Roese 

Thanks,
Stefan


Re: [PATCH 1/2] clk: at91: clk-master: add 5th divisor for mck master

2020-10-19 Thread Eugen.Hristev
On 08.10.2020 14:46, Eugen Hristev wrote:
> clk-master can have 5 divisors with a field width of 3 bits
> on some products.
> 
> Change the mask and number of divisors accordingly.
> 
> Reported-by: Mihai Sain 
> Signed-off-by: Eugen Hristev 
> Reviewed-by: Claudiu Beznea 
> ---

Applied both to u-boot-atmel/master



Re: [PATCH] ARM: at91: Add chip ID for SAM9X60 SiP

2020-10-19 Thread Eugen.Hristev
On 08.10.2020 16:01, Eugen Hristev wrote:
> From: Nicolas Ferre 
> 
> SAM9X60 SiP (System in Package) are added for SoC identification.
> 
> Signed-off-by: Nicolas Ferre 
> ---
>   arch/arm/mach-at91/arm926ejs/sam9x60_devices.c | 6 ++
>   arch/arm/mach-at91/include/mach/sam9x60.h  | 3 +++
>   2 files changed, 9 insertions(+)


Applied to u-boot-atmel/master


Re: [PATCH 07/18] configs: mtmips: refresh for mt7628 based boards

2020-10-19 Thread Stefan Roese

On 16.10.20 09:35, Weijie Gao wrote:

Since mt7620 is added into Kconfig, the CONFIG_SOC_MT7628=y which is
omitted by default must be added back, otherwise make xxx_defconfig for
these boards will be configured for mt7620 platform.

Signed-off-by: Weijie Gao 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  configs/gardena-smart-gateway-mt7688_defconfig | 1 +
  configs/linkit-smart-7688_defconfig| 1 +
  configs/mt7628_rfb_defconfig   | 1 +
  configs/vocore2_defconfig  | 1 +
  4 files changed, 4 insertions(+)

diff --git a/configs/gardena-smart-gateway-mt7688_defconfig 
b/configs/gardena-smart-gateway-mt7688_defconfig
index 001a66d0f6..c03123f6e4 100644
--- a/configs/gardena-smart-gateway-mt7688_defconfig
+++ b/configs/gardena-smart-gateway-mt7688_defconfig
@@ -12,6 +12,7 @@ CONFIG_SPL=y
  CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
  CONFIG_ENV_OFFSET_REDUND=0xB
  CONFIG_ARCH_MTMIPS=y
+CONFIG_SOC_MT7628=y
  CONFIG_DEFAULT_DEVICE_TREE="gardena-smart-gateway-mt7688"
  CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
  # CONFIG_MIPS_BOOT_ENV_LEGACY is not set
diff --git a/configs/linkit-smart-7688_defconfig 
b/configs/linkit-smart-7688_defconfig
index 437000b4c7..dd2524e4ec 100644
--- a/configs/linkit-smart-7688_defconfig
+++ b/configs/linkit-smart-7688_defconfig
@@ -9,6 +9,7 @@ CONFIG_SPL_SERIAL_SUPPORT=y
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4
  CONFIG_SPL=y
  CONFIG_ARCH_MTMIPS=y
+CONFIG_SOC_MT7628=y
  CONFIG_BOARD_LINKIT_SMART_7688=y
  CONFIG_DEFAULT_DEVICE_TREE="linkit-smart-7688"
  CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
diff --git a/configs/mt7628_rfb_defconfig b/configs/mt7628_rfb_defconfig
index 69025728b2..831e54e9f3 100644
--- a/configs/mt7628_rfb_defconfig
+++ b/configs/mt7628_rfb_defconfig
@@ -9,6 +9,7 @@ CONFIG_SPL_SERIAL_SUPPORT=y
  CONFIG_SPL_SYS_MALLOC_F_LEN=0x4
  CONFIG_SPL=y
  CONFIG_ARCH_MTMIPS=y
+CONFIG_SOC_MT7628=y
  CONFIG_BOARD_MT7628_RFB=y
  CONFIG_DEFAULT_DEVICE_TREE="mediatek,mt7628-rfb"
  CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y
diff --git a/configs/vocore2_defconfig b/configs/vocore2_defconfig
index acb9abf1be..e255829366 100644
--- a/configs/vocore2_defconfig
+++ b/configs/vocore2_defconfig
@@ -10,6 +10,7 @@ CONFIG_SPL_SYS_MALLOC_F_LEN=0x4
  CONFIG_SPL=y
  CONFIG_SYS_BOOTCOUNT_SINGLEWORD=y
  CONFIG_ARCH_MTMIPS=y
+CONFIG_SOC_MT7628=y
  CONFIG_BOARD_VOCORE2=y
  CONFIG_DEFAULT_DEVICE_TREE="vocore_vocore2"
  CONFIG_RESTORE_EXCEPTION_VECTOR_BASE=y




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


[PATCH] dm: core: add function uclass_probe_all() to probe all devices

2020-10-19 Thread Vabhav Sharma
From: Vabhav Sharma 

Support a common method to probe all devices associated with uclass.

This includes data structures and code for finding the first device and
looping for remaining devices associated with uclasses (groups of devices
with the same purpose, e.g. all SERIAL ports will be in the same uclass).

An example is SBSA compliant PL011 UART IP, where firmware does the serial
port initialization and prepare uart device to let the kernel use it for
sending and reveiving the characters.SERIAL uclass will use this function
to initialize PL011 UART ports.

The feature is enabled with CONFIG_DM.

Signed-off-by: Vabhav Sharma 
--
  Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400
385-11854-1-git-send-email-vabhav.sha...@oss.nxp.com/
---
 drivers/core/uclass.c | 17 +
 include/dm/uclass.h   | 12 
 2 files changed, 29 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73..0725e8e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
 }
 #endif
 
+int uclass_probe_all(enum uclass_id id)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device(id, );
+   if (ret || !dev)
+   return ret;
+   if (dev) {
+   /* Scanning uclass to probe all devices */
+   for (; dev; uclass_next_device())
+   ;
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(nop) = {
.id = UCLASS_NOP,
.name   = "nop",
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 67ff746..0fce83f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong 
driver_data,
 int uclass_resolve_seq(struct udevice *dev);
 
 /**
+ * uclass_probe_all() - Probe all devices based on an uclass ID
+ *
+ * Every uclass is identified by an ID, a number from 0 to n-1 where n is
+ * the number of uclasses. This function probe all devices asocciated with
+ * a uclass by looking its ID.
+ *
+ * @id: uclass ID to look up
+ * @return 0 if OK, other -ve on error
+ */
+int uclass_probe_all(enum uclass_id id);
+
+/**
  * uclass_id_foreach_dev() - Helper function to iteration through devices
  *
  * This creates a for() loop which works through the available devices in
-- 
2.7.4



RE: [PATCH v2] drivers: serial: probe all uart devices

2020-10-19 Thread Vabhav Sharma (OSS)
Hi Simon, Stefan,
Thank you for feedback and time

> -Original Message-
> From: Simon Glass 
> Sent: Thursday, October 15, 2020 8:35 PM
> To: Stefan Roese 
> Cc: Vabhav Sharma (OSS) ;
> andre.przyw...@arm.com; u-boot@lists.denx.de
> Subject: Re: [PATCH v2] drivers: serial: probe all uart devices
> 
> Hi,
> 
> On Wed, 14 Oct 2020 at 06:47, Stefan Roese  wrote:
> >
> > Hi Vabhav,
> >
> > On 14.10.20 13:15, Vabhav Sharma (OSS) wrote:
> > > Hi Stefan,
> > > Sorry for delayed reply, Occupied with high priority task
> > >
> > >> -Original Message-
> > >> From: Stefan Roese 
> > >> Sent: Wednesday, September 30, 2020 10:46 AM
> > >> To: Vabhav Sharma (OSS) ;
> > >> andre.przyw...@arm.com; u-boot@lists.denx.de; s...@chromium.org
> > >> Cc: Vabhav Sharma 
> > >> Subject: Re: [PATCH v2] drivers: serial: probe all uart devices
> > >>
> > >> On 29.09.20 19:26, Vabhav Sharma wrote:
> > >>> From: Vabhav Sharma 
> > >>>
> > >>> U-Boot DM model probe only single device at a time which is
> > >>> enabled and configured using device tree or platform data method.
> > >>>
> > >>> PL011 UART IP is SBSA compliant and firmware does the serial port
> > >>> set-up, initialization and let the kernel use UART port for
> > >>> sending and receiving characters.
> > >>>
> > >>> Normally software talk to one serial port time but some LayerScape
> > >>> platform require all the UART devices enabled in Linux for various
> > >>> use case.
> > >>>
> > >>> Adding support to probe all enabled serial devices like SBSA
> > >>> compliant
> > >>> PL011 UART ports probe and initialization by firmware.
> > >>>
> > >>> Signed-off-by: Vabhav Sharma 
> > >>> ---
> > >>> v2:
> > >>>  Incorporated Stefan review comment, Update #ifdef with macro
> > >>>  if (IS_ENABLED)..
> > >>
> > >> Better, thanks. But...
> > >>
> > >>> ---
> > >>> ---
> > >>>drivers/serial/Kconfig | 17 +
> > >>>drivers/serial/serial-uclass.c | 30 ++
> > >>>2 files changed, 47 insertions(+)
> > >>>
> > >>> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig index
> > >>> e344677..b2e30f1 100644
> > >>> --- a/drivers/serial/Kconfig
> > >>> +++ b/drivers/serial/Kconfig
> > >>> @@ -134,6 +134,23 @@ config SERIAL_SEARCH_ALL
> > >>>
> > >>>   If unsure, say N.
> > >>>
> > >>> +config SERIAL_PROBE_ALL
> > >>> +   bool "Probe all available serial devices"
> > >>> +   depends on DM_SERIAL
> > >>> +   default n
> > >>> +   help
> > >>> + The serial subsystem only probe for single serial device,
> > >>> + but does not probe for other remaining serial devices.
> > >>> + With this option set,we make probing and searching for
> > >>> + all available devices optional.
> > >>> + Normally, U-Boot talk to one serial port at a time but SBSA
> > >>> + compliant UART devices like PL011 require initialization
> > >>> + by firmware and let the kernel use serial port for sending
> > >>> + and receiving the characters.
> > >>> +
> > >>> + If probing is not required for all remaining available
> > >>> + devices other than default current console device, say N.
> > >>> +
> > >>>config SPL_DM_SERIAL
> > >>> bool "Enable Driver Model for serial drivers in SPL"
> > >>> depends on DM_SERIAL && SPL_DM diff --git
> > >>> a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
> > >>> index 0027625..d303a66 100644
> > >>> --- a/drivers/serial/serial-uclass.c
> > >>> +++ b/drivers/serial/serial-uclass.c
> > >>> @@ -86,6 +86,11 @@ static void serial_find_console_or_panic(void)
> > >>> uclass_first_device(UCLASS_SERIAL, );
> > >>> if (dev) {
> > >>> gd->cur_serial_dev = dev;
> > >>> +   if (IS_ENABLED(CONFIG_SERIAL_PROBE_ALL)) {
> > >>> +   /* Scanning uclass to probe all devices */
> > >>> +   for (; dev; uclass_next_device())
> > >>> +   ;
> > >>> +   }
> > >>> return;
> > >>> }
> > >>> } else if (CONFIG_IS_ENABLED(OF_CONTROL) && blob) { @@ -96,11
> > >>> +101,21 @@ static void serial_find_console_or_panic(void)
> > >>> if (np
> > >> && !uclass_get_device_by_ofnode(UCLASS_SERIAL,
> > >>> np_to_ofnode(np), )) {
> > >>> gd->cur_serial_dev = dev;
> > >>> +   if
> > >>> + (IS_ENABLED(CONFIG_SERIAL_PROBE_ALL))
> > >> {
> > >>> +   /* Scanning uclass to probe
> > >>> + devices
> > >> */
> > >>> +   for (; dev; 
> > >>> uclass_next_device())
> > >>> +   ;
> > >>> +   }
> > >>
> > >> This code sequence (incl. gd->cur_serial_dev = dev;) is repeated
> > >> multiple times (below as well). Could you instead move this into a
> > >> function and call 

[PATCH v3] drivers: serial: probe all uart devices

2020-10-19 Thread Vabhav Sharma
From: Vabhav Sharma 

U-Boot DM model probe only single device at a time
which is enabled and configured using device tree
or platform data method.

PL011 UART IP is SBSA compliant and firmware does the
serial port set-up, initialization and let the kernel use
UART port for sending and receiving characters.

Normally software talk to one serial port time but some
LayerScape platform require all the UART devices enabled
in Linux for various use case.

Adding support to probe all enabled serial devices like SBSA
compliant PL011 UART ports probe and initialization by firmware.

Signed-off-by: Vabhav Sharma 
--
v3:
  Incorporated Simon and Stephan review comment
  - Define generic function uclass_probe_all(enum uclass_id)
in drivers/core/uclass.c
  - Added the function in caller of serial_find_console_or_panic()
  - Removed repeated sequence with generic function call uclass_probe_all()
  - Dependent on other patch [PATCH] dm: core: add function uclass_probe_all()
to probe all devices

v2:
  Incorporated Stefan review comment, Update #ifdef with macro
  if (IS_ENABLED)..
---
 drivers/serial/Kconfig | 17 +
 drivers/serial/serial-uclass.c |  4 
 2 files changed, 21 insertions(+)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b4805a2..af8779b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -134,6 +134,23 @@ config SERIAL_SEARCH_ALL
 
  If unsure, say N.
 
+config SERIAL_PROBE_ALL
+   bool "Probe all available serial devices"
+   depends on DM_SERIAL
+   default n
+   help
+ The serial subsystem only probe for single serial device,
+ but does not probe for other remaining serial devices.
+ With this option set,we make probing and searching for
+ all available devices optional.
+ Normally, U-Boot talk to one serial port at a time but SBSA
+ compliant UART devices like PL011 require initialization
+ by firmware and let the kernel use serial port for sending
+ and receiving the characters.
+
+ If probing is not required for all remaining available
+ devices other than default current console device, say N.
+
 config SPL_DM_SERIAL
bool "Enable Driver Model for serial drivers in SPL"
depends on DM_SERIAL && SPL_DM
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 0027625..09bc6f4 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -172,6 +172,10 @@ int serial_init(void)
 /* Called after relocation */
 int serial_initialize(void)
 {
+   /* Scanning uclass to probe devices */
+   if (IS_ENABLED(CONFIG_SERIAL_PROBE_ALL))
+   uclass_probe_all(UCLASS_SERIAL);
+
return serial_init();
 }
 
-- 
2.7.4



Re: [PATCH v1 1/8] riscv: Add Microchip MPFS Icicle Kit support

2020-10-19 Thread Padmarao Begari
On Sun, Oct 18, 2020 at 6:37 AM Sean Anderson  wrote:

> On 10/16/20 10:23 AM, padmarao.beg...@microchip.com wrote:
> > From: Padmarao Begari 
> >
> > This patch adds Microchip MPFS Icicle Kit support. For now, only
> > NS16550 Serial, Microchip clock, Cadence eMMC and MACB drivers are
> > only enabled. The Microchip MPFS Icicle defconfig by default builds
> > U-Boot for S-Mode because U-Boot on Microchip PolarFire SoC will run
> > in S-Mode as payload of HSS + OpenSBI.
> >
> > Signed-off-by: Padmarao Begari 
> > ---
> >  board/microchip/mpfs_icicle/Kconfig   | 26 ++
> >  board/microchip/mpfs_icicle/mpfs_icicle.c | 96 ++-
> >  configs/microchip_mpfs_icicle_defconfig   |  9 ++-
> >  include/configs/microchip_mpfs_icicle.h   | 60 +-
> >  4 files changed, 146 insertions(+), 45 deletions(-)
> >
> > diff --git a/board/microchip/mpfs_icicle/Kconfig
> b/board/microchip/mpfs_icicle/Kconfig
> > index bf8e1a13ec..4406d1a13f 100644
> > --- a/board/microchip/mpfs_icicle/Kconfig
> > +++ b/board/microchip/mpfs_icicle/Kconfig
> > @@ -20,7 +20,33 @@ config BOARD_SPECIFIC_OPTIONS # dummy
> >   def_bool y
> >   select GENERIC_RISCV
> >   select BOARD_EARLY_INIT_F
> > + select BOARD_LATE_INIT
> >   imply SMP
> > + imply CLK
> > + imply CLK_CCF
> > + imply CLK_MPFS
> >   imply SYS_NS16550
> > + imply CMD_DHCP
> > + imply CMD_EXT2
> > + imply CMD_EXT4
> > + imply CMD_FAT
> > + imply CMD_FS_GENERIC
> > + imply CMD_NET
> > + imply CMD_PING
>
> Perhaps just imply DISTRO_DEFAULTS?
>
Hi Sean,

CONFIG_ DISTRO_DEFAULTS  is defined in microchip_mpfs_icicle_defconfig
still you want to add  "imply DISTRO_DEFAULTS" here

Regards
Padmarao

>
> > + imply CMD_MMC
> > + imply DOS_PARTITION
> > + imply EFI_PARTITION
> > + imply IP_DYN
> > + imply ISO_PARTITION
> > + imply MACB
> > + imply MII
> > + imply NET_RANDOM_ETHADDR
> > + imply PHY_LIB
> > + imply PHY_VITESSE
> > + imply DMA_ADDR_T_64BIT
> > + imply MMC
> > + imply MMC_WRITE
> > + imply MMC_SDHCI
> > + imply MMC_SDHCI_CADENCE
> >
> >  endif
> > diff --git a/board/microchip/mpfs_icicle/mpfs_icicle.c
> b/board/microchip/mpfs_icicle/mpfs_icicle.c
> > index 8381361ec3..64133aee59 100644
> > --- a/board/microchip/mpfs_icicle/mpfs_icicle.c
> > +++ b/board/microchip/mpfs_icicle/mpfs_icicle.c
> > @@ -5,11 +5,47 @@
> >   */
> >
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> >
> > -#define MPFS_SYSREG_SOFT_RESET   ((unsigned int *)0x20002088)
> > +#define MPFS_SYSREG_SOFT_RESET   ((unsigned int
> *)0x20002088)
> > +#define MPFS_SYS_SERVICE_CR  ((unsigned int *)0x37020050)
> > +#define MPFS_SYS_SERVICE_SR  ((unsigned int *)0x37020054)
> > +#define MPFS_SYS_SERVICE_MAILBOX ((unsigned char *)0x37020800)
> > +
> > +#define PERIPH_RESET_VALUE   0x1e8u
> > +#define SERVICE_CR_REQ   0x1u
> > +#define SERVICE_SR_BUSY  0x2u
> > +
> > +static void read_device_serial_number(u8 *response, u8 response_size)
> > +{
> > + u8 idx;
> > + u8 *response_buf;
> > + unsigned int val;
> > +
> > + response_buf = (u8 *)response;
> > +
> > + writel(SERVICE_CR_REQ, MPFS_SYS_SERVICE_CR);
> > +
> > + /* REQ bit will remain set till the system controller starts
> > +  * processing.
> > +  */
> > + do {
> > + val = readl(MPFS_SYS_SERVICE_CR);
> > + } while (SERVICE_CR_REQ == (val & SERVICE_CR_REQ));
> > +
> > + /* Once system controller starts processing the busy bit will
> > +  * go high and service is completed when busy bit is gone low
> > +  */
> > + do {
> > + val = readl(MPFS_SYS_SERVICE_SR);
> > + } while (SERVICE_SR_BUSY == (val & SERVICE_SR_BUSY));
> > +
> > + for (idx = 0; idx < response_size; idx++)
> > + response_buf[idx] = readb(MPFS_SYS_SERVICE_MAILBOX + idx);
> > +}
> >
> >  int board_init(void)
> >  {
> > @@ -22,10 +58,64 @@ int board_early_init_f(void)
> >  {
> >   unsigned int val;
> >
> > - /* Reset uart peripheral */
> > + /* Reset uart, mmc peripheral */
> >   val = readl(MPFS_SYSREG_SOFT_RESET);
> > - val = (val & ~(1u << 5u));
> > + val = (val & ~(PERIPH_RESET_VALUE));
> >   writel(val, MPFS_SYSREG_SOFT_RESET);
> >
> >   return 0;
> >  }
> > +
> > +int board_late_init(void)
> > +{
> > + u32 ret;
> > + u32 node;
> > + u8 idx;
> > + u8 device_serial_number[16] = { 0 };
> > + unsigned char mac_addr[6];
> > + char icicle_mac_addr[20];
> > + void *blob = (void *)gd->fdt_blob;
> > +
> > + node = fdt_path_offset(blob, "ethernet0");
> > + if (node < 0) {
> > + printf("No ethernet0 path offset\n");
> > + return -ENODEV;
> > + }
> > +
> > + ret = fdtdec_get_byte_array(blob, node, "mac-address", mac_addr,
> 6);
> > + if (ret) {
> > +

Re: [PATCH v3 0/8] add SAM9X60 clock support

2020-10-19 Thread Eugen.Hristev
On 07.10.2020 18:17, Claudiu Beznea wrote:
> Hi,
> 
> This series adds SAM9X60 clock support, CCF compatible, so that
> SAM9X60 based boards (e.g. SAM9X60-EK in this case) to be able
> to boot with mainline code.
> 
> This series is based on u-boot-atmel/next.
> 
> Thank you,
> Claudiu Beznea
> 
> Changes in v3:
> - move u-boot,dm-pre-reloc properties to sam9x60ek-u-boot.dtsi
> - add main_xtal to sam9x60ek-u-boot.dtsi in patch 8/8
> 
> Changes in v2:
> - remove "Alignment should match open parenthesis" and
>"Please don't use multiple blank lines" checkpatch.pl warnings
> - use u-boot,dm-pre-reloc also in sam9x60ek-u-boot.dtsi
> - add patch 8/8
> 
> Claudiu Beznea (8):
>board: atmel: sam9x60ek: add SYS_MALLOC_F_LEN to SYS_INIT_SP_ADDR
>clk: at91: sam9x60: add support compatible with CCF
>ARM: dts: sam9x60ek: add clock frequencies to board file
>ARM: dts: sam9x60: use u-boot,dm-pre-reloc
>ARM: dts: sam9x60: use slow clock CCF compatible bindings
>ARM: dts: sam9x60: use CCF compatibles for PMC
>configs: sam9x60ek: update defconfigs for CCF
>ARM: dts: sam9x60: use alphabetical order
> 
>   arch/arm/dts/sam9x60.dtsi | 171 ++---
>   arch/arm/dts/sam9x60ek-u-boot.dtsi|  70 +---
>   arch/arm/dts/sam9x60ek.dts|  12 +-
>   configs/sam9x60ek_mmc_defconfig   |   4 +-
>   configs/sam9x60ek_nandflash_defconfig |   4 +-
>   configs/sam9x60ek_qspiflash_defconfig |   4 +-
>   drivers/clk/at91/Makefile |   1 +
>   drivers/clk/at91/sam9x60.c| 649 
> ++
>   include/configs/sam9x60ek.h   |   3 +-
>   9 files changed, 716 insertions(+), 202 deletions(-)
>   create mode 100644 drivers/clk/at91/sam9x60.c
> 

Applied series to u-boot-atmel/master, thanks !


[PATCH next] usb: mtu3: fix build error caused by dev_xxx()

2020-10-19 Thread Chunfeng Yun
Due to the following to patches:
4a1989c0bc77 ("dm: Don't undefine dev_xxx macros")
69dae8902b16 ("linux/compat.h: Remove redefinition of dev_xxx macros")

Need include device_compat.h and no need use __maybe_unused anymore
to fix unused variable warning

Signed-off-by: Chunfeng Yun 
---
Please squash in: ab703ebb1cc0 ("usb: add MediaTek USB3 DRD driver")
in u-boot-usb/next

Sorry for inconvenience
---
 drivers/usb/mtu3/mtu3.h| 1 +
 drivers/usb/mtu3/mtu3_gadget.c | 4 ++--
 drivers/usb/mtu3/mtu3_plat.c   | 3 ++-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/mtu3/mtu3.h b/drivers/usb/mtu3/mtu3.h
index a51251c661..8a7ae83ee9 100644
--- a/drivers/usb/mtu3/mtu3.h
+++ b/drivers/usb/mtu3/mtu3.h
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
diff --git a/drivers/usb/mtu3/mtu3_gadget.c b/drivers/usb/mtu3/mtu3_gadget.c
index c981407b29..027b7e6111 100644
--- a/drivers/usb/mtu3/mtu3_gadget.c
+++ b/drivers/usb/mtu3/mtu3_gadget.c
@@ -306,7 +306,7 @@ static int mtu3_gadget_dequeue(struct usb_ep *ep, struct 
usb_request *req)
struct mtu3_ep *mep = to_mtu3_ep(ep);
struct mtu3_request *mreq = to_mtu3_request(req);
struct mtu3_request *r;
-   __maybe_unused struct mtu3 *mtu = mep->mtu;
+   struct mtu3 *mtu = mep->mtu;
unsigned long flags;
int ret = 0;
 
@@ -344,7 +344,7 @@ done:
 static int mtu3_gadget_ep_set_halt(struct usb_ep *ep, int value)
 {
struct mtu3_ep *mep = to_mtu3_ep(ep);
-   __maybe_unused struct mtu3 *mtu = mep->mtu;
+   struct mtu3 *mtu = mep->mtu;
struct mtu3_request *mreq;
unsigned long flags = 0;
int ret = 0;
diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 24ffdb360a..3795e695e8 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -347,7 +347,8 @@ static int mtu3_glue_bind(struct udevice *parent)
 
ret = device_bind_driver_to_node(parent, driver, name, node, );
if (ret)
-   dev_err("%s: not able to bind usb device mode\n", __func__);
+   dev_err(parent, "%s: not able to bind usb device mode\n",
+   __func__);
 
return ret;
 }
-- 
2.18.0


Re: [PATCH v2 2/3] allow positional arguments with "run" command

2020-10-19 Thread Wolfgang Denk
Dear Rasmus,

In message  you wrote:
>
> > Yes, current versions of busybox hush do implement shell functions;
> > tested under Fedora 32:
>
> Not what I meant, of course busybox hush does that. What I meant is that
> it is not at all obvious how that support would actually benefit U-Boot.

um... I think you should define what you want.  You asked for shell
functions; I tell you they are supported; now you ask for something
else

> The problem is how one would go about getting the functions defined. Putting
>
> define_func='func() { do_stuff $1 $2; do_more_stuff $3; }'
>
> in the environment and then having to say
>
> run define_func; func foo ...
>
> does not really look like an improvement to me. In contrast, the current

Shell functions is something you usually use as part of longer
scripts.  You can either define these as part of one or more
envrionment variables, or you can put these into a file or a U-Boot
image etc. and source it when needed.  There are many ways.

> way of defining "one-liner" functions and running with, well, run, is
> quite ergonomic - but I do miss the ability to provide parameters other
> than via global settings. With these patches, the above would just be
>
> func='do_stuff $1 $2; do_more_stuff $3;'
>
> run func -- foo ...

I can't see why you cannot do the same with shell fnctions?

setenv define_func 'func() { do_stuff $1 $2; do_more_stuff $3; }'
...
run define_func
func foo ...

> I guess one could have something like CONFIG_DOT_PROFILE and have that
> point at a script that gets built into the U-Boot binary and sourced at
> shell startup; then one could put one's functions in there, or have the
> flexibility of having that file load some stdlib.sh from somewhere.

You don't need any new defines for such a thing.   You can define
something like a sequence "test if file .profile exisits in some
stroage device; if yes, then source it" as past of your
CONFIG_USE_PREBOOT settings.

> I agree in principle - there are other shell features I'm also missing
> (though see above, I don't immediately see how an upgrade would make
> functions available in a useful way).

So do you want shell functions or any other standard shell features,
or do you just want to implement your own nonstandard ideas?  The
former I do support, the latter I don't...

> Someone speaking up and saying "I'm going to look at an overhaul of hush
> within the next year or so" would clearly be a strong argument against
> inclusion of these patches. Lacking such a pony promise, this really
> boils down to an idealist/pragmatist issue, and we can keep going around
> this in circles forever, so I think someone (Tom?) should make a decision.

As mentioned - addin more non-standard stuff will just create new
compatibility problems and make an upgrade more difficult and thus
less likely.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
I had the rare misfortune of being one of the first people to try and
implement a PL/1 compiler. -- T. Cheatham


Re: [PATCH v2 5/5] sunxi: add drivers and configs needed for LCD display

2020-10-19 Thread Maxime Ripard
On Fri, Oct 16, 2020 at 07:17:05PM +0200, Martin Cerveny wrote:
> Add PWM and dummy power regulator support.
> Modify phase of data signal for LCD display.
> 
> Signed-off-by: Martin Cerveny 
> ---
>  configs/LicheePi_Zero_defconfig | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/configs/LicheePi_Zero_defconfig b/configs/LicheePi_Zero_defconfig
> index 04d7b64504..ba1c085ec3 100644
> --- a/configs/LicheePi_Zero_defconfig
> +++ b/configs/LicheePi_Zero_defconfig
> @@ -3,5 +3,9 @@ CONFIG_ARCH_SUNXI=y
>  CONFIG_SPL=y
>  CONFIG_MACH_SUN8I_V3S=y
>  CONFIG_DRAM_CLK=360
> +CONFIG_VIDEO_LCD_DCLK_PHASE=0

I'm not sure you answered on that one either, but you'd need some
display timings as well, right? If so, why do we need that change in the
first place if we're expected to change it anyway?

Maxime


signature.asc
Description: PGP signature


Re: [PATCH 02/18] mips: mtmips: move mt7628 related Kconfig into mt7628 subdirectory

2020-10-19 Thread Stefan Roese

On 16.10.20 09:35, Weijie Gao wrote:

This patch is a preparation for add a new soc fot mtmips.

Move all mt7628 related Kconfig (boards and UART selection) into mt7628
subdirectory and make sure the top directory of mtmips contains only
selection for SoCs.

Signed-off-by: Weijie Gao 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/mips/mach-mtmips/Kconfig| 53 +---
  arch/mips/mach-mtmips/mt7628/Kconfig | 53 
  2 files changed, 54 insertions(+), 52 deletions(-)
  create mode 100644 arch/mips/mach-mtmips/mt7628/Kconfig

diff --git a/arch/mips/mach-mtmips/Kconfig b/arch/mips/mach-mtmips/Kconfig
index 737de2cb8e..7c07430a0c 100644
--- a/arch/mips/mach-mtmips/Kconfig
+++ b/arch/mips/mach-mtmips/Kconfig
@@ -58,57 +58,6 @@ config SOC_MT7628
  
  endchoice
  
-choice

-   prompt "Board select"
-
-config BOARD_GARDENA_SMART_GATEWAY_MT7688
-   bool "GARDENA smart Gateway"
-   depends on SOC_MT7628
-   select BOARD_LATE_INIT
-   help
- GARDENA smart Gateway boards have a MT7688 SoC with 128 MiB of RAM
- and 8 MiB of flash (SPI NOR) and additional SPI NAND storage.
-
-config BOARD_LINKIT_SMART_7688
-   bool "LinkIt Smart 7688"
-   depends on SOC_MT7628
-   help
- Seeed LinkIt Smart 7688 boards have a MT7688 SoC with 128 MiB of RAM
- and 32 MiB of flash (SPI).
- Between its different peripherals there's an integrated switch with 4
- ethernet ports, 1 USB port, 1 UART, GPIO buttons and LEDs, and
- a MT7688 (PCIe).
-
-config BOARD_MT7628_RFB
-   bool "MediaTek MT7628 RFB"
-   depends on SOC_MT7628
-   help
- The reference design of MT7628. The board has 128 MiB DDR2, 8 MiB
- SPI-NOR flash, 1 built-in switch with 5 ports, 1 UART, 1 USB host,
- 1 SDXC, 1 PCIe socket and JTAG pins.
-
-config BOARD_VOCORE2
-   bool "VoCore2"
-   depends on SOC_MT7628
-   select SPL_SERIAL_SUPPORT
-   select SPL_UART2_SPIS_PINMUX
-   help
- VoCore VoCore2 board has a MT7628 SoC with 128 MiB of RAM
- and 16 MiB of flash (SPI).
-
-endchoice
-
-config SPL_UART2_SPIS_PINMUX
-   bool "Use alternative pinmux for UART2 in SPL stage"
-   depends on SPL_SERIAL_SUPPORT
-   default n
-   help
- Select this if the UART2 of your board is connected to GPIO 16/17
- (shared with SPIS) rather than the usual GPIO 20/21.
-
-source "board/gardena/smart-gateway-mt7688/Kconfig"
-source "board/mediatek/mt7628/Kconfig"
-source "board/seeed/linkit-smart-7688/Kconfig"
-source "board/vocore/vocore2/Kconfig"
+source "arch/mips/mach-mtmips/mt7628/Kconfig"
  
  endmenu

diff --git a/arch/mips/mach-mtmips/mt7628/Kconfig 
b/arch/mips/mach-mtmips/mt7628/Kconfig
new file mode 100644
index 00..e3f56e782e
--- /dev/null
+++ b/arch/mips/mach-mtmips/mt7628/Kconfig
@@ -0,0 +1,53 @@
+
+if SOC_MT7628
+
+choice
+   prompt "Board select"
+
+config BOARD_GARDENA_SMART_GATEWAY_MT7688
+   bool "GARDENA smart Gateway"
+   select BOARD_LATE_INIT
+   help
+ GARDENA smart Gateway boards have a MT7688 SoC with 128 MiB of RAM
+ and 8 MiB of flash (SPI NOR) and additional SPI NAND storage.
+
+config BOARD_LINKIT_SMART_7688
+   bool "LinkIt Smart 7688"
+   help
+ Seeed LinkIt Smart 7688 boards have a MT7688 SoC with 128 MiB of RAM
+ and 32 MiB of flash (SPI).
+ Between its different peripherals there's an integrated switch with 4
+ ethernet ports, 1 USB port, 1 UART, GPIO buttons and LEDs, and
+ a MT7688 (PCIe).
+
+config BOARD_MT7628_RFB
+   bool "MediaTek MT7628 RFB"
+   help
+ The reference design of MT7628. The board has 128 MiB DDR2, 8 MiB
+ SPI-NOR flash, 1 built-in switch with 5 ports, 1 UART, 1 USB host,
+ 1 SDXC, 1 PCIe socket and JTAG pins.
+
+config BOARD_VOCORE2
+   bool "VoCore2"
+   select SPL_SERIAL_SUPPORT
+   select SPL_UART2_SPIS_PINMUX
+   help
+ VoCore VoCore2 board has a MT7628 SoC with 128 MiB of RAM
+ and 16 MiB of flash (SPI).
+
+endchoice
+
+config SPL_UART2_SPIS_PINMUX
+   bool "Use alternative pinmux for UART2 in SPL stage"
+   depends on SPL_SERIAL_SUPPORT
+   default n
+   help
+ Select this if the UART2 of your board is connected to GPIO 16/17
+ (shared with SPIS) rather than the usual GPIO 20/21.
+
+source "board/gardena/smart-gateway-mt7688/Kconfig"
+source "board/mediatek/mt7628/Kconfig"
+source "board/seeed/linkit-smart-7688/Kconfig"
+source "board/vocore/vocore2/Kconfig"
+
+endif




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH 01/18] mips: dts: switch to board defines for dtb for mtmips

2020-10-19 Thread Stefan Roese

On 16.10.20 09:35, Weijie Gao wrote:

Previous the dts files for gardena-smart-gateway-mt7688 and
linkit-smart-7688 are set to be built when mtmips is selected.

This can lead to a compilation error if another soc is added to this arch
with different dtsi files.

So it's better to build the dtb only if their board is selected.

Signed-off-by: Weijie Gao 


Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  arch/mips/dts/Makefile | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/mips/dts/Makefile b/arch/mips/dts/Makefile
index dc85901dca..e82f96d4e4 100644
--- a/arch/mips/dts/Makefile
+++ b/arch/mips/dts/Makefile
@@ -1,8 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0+
  
-dtb-$(CONFIG_ARCH_MTMIPS) += \

-   gardena-smart-gateway-mt7688.dtb \
-   linkit-smart-7688.dtb
  dtb-$(CONFIG_TARGET_AP121) += ap121.dtb
  dtb-$(CONFIG_TARGET_AP143) += ap143.dtb
  dtb-$(CONFIG_TARGET_AP152) += ap152.dtb
@@ -18,6 +15,8 @@ dtb-$(CONFIG_BOARD_COMTREND_VR3032U) += comtrend,vr-3032u.dtb
  dtb-$(CONFIG_BOARD_COMTREND_WAP5813N) += comtrend,wap-5813n.dtb
  dtb-$(CONFIG_BOARD_HUAWEI_HG556A) += huawei,hg556a.dtb
  dtb-$(CONFIG_BOARD_MT7628_RFB) += mediatek,mt7628-rfb.dtb
+dtb-$(CONFIG_BOARD_GARDENA_SMART_GATEWAY_MT7688) += 
gardena-smart-gateway-mt7688.dtb
+dtb-$(CONFIG_BOARD_LINKIT_SMART_7688) += linkit-smart-7688.dtb
  dtb-$(CONFIG_TARGET_OCTEON_EBB7304) += mrvl,octeon-ebb7304.dtb
  dtb-$(CONFIG_BOARD_NETGEAR_CG3100D) += netgear,cg3100d.dtb
  dtb-$(CONFIG_BOARD_NETGEAR_DGND3700V2) += netgear,dgnd3700v2.dtb




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Chunfeng Yun
On Mon, 2020-10-19 at 12:34 +0200, Marek Vasut wrote:
> On 10/19/20 11:32 AM, Chunfeng Yun wrote:
> > On Mon, 2020-10-19 at 08:07 +0200, Marek Vasut wrote:
> >> On 10/19/20 5:46 AM, Chunfeng Yun wrote:
> >>> Fix up the following build warning/error:
> >>> 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
> >>>mtu3_gadget_ep_set_halt()
> >>> 2. implicit declaration of function ‘flush_dcache_range’ and
> >>>‘invalidate_dcache_range’
> >>
> >> Which patch of the ones in usb/next do I squash this in ?
> > 
> > squash in:  ab703ebb1c usb: add MediaTek USB3 DRD driver
> > 
> > Thanks a lot
> 
> Build fails:
> https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/pipelines/5036

Sorry, the patch is already sent out, thanks



Re: [PATCH v1 8/8] doc: board: Add Microchip MPFS Icicle Kit doc

2020-10-19 Thread Padmarao Begari
Hi Anup,

On Sat, Oct 17, 2020 at 3:17 PM Anup Patel  wrote:

> On Fri, Oct 16, 2020 at 7:55 PM  wrote:
> >
> > From: Padmarao Begari 
> >
> > This doc describes the procedure to build, flash and
> > boot Linux using U-boot on Microchip MPFS Icicle Kit.
> >
> > Signed-off-by: Padmarao Begari 
> > ---
> >  doc/board/index.rst |   1 +
> >  doc/board/microchip/index.rst   |   9 +
> >  doc/board/microchip/mpfs_icicle.rst | 605 
> >  3 files changed, 615 insertions(+)
> >  create mode 100644 doc/board/microchip/index.rst
> >  create mode 100644 doc/board/microchip/mpfs_icicle.rst
> >
> > diff --git a/doc/board/index.rst b/doc/board/index.rst
> > index 63935abcd7..e50a78d752 100644
> > --- a/doc/board/index.rst
> > +++ b/doc/board/index.rst
> > @@ -15,6 +15,7 @@ Board-specific doc
> > freescale/index
> > google/index
> > intel/index
> > +   microchip/index
> > renesas/index
> > rockchip/index
> > sifive/index
> > diff --git a/doc/board/microchip/index.rst
> b/doc/board/microchip/index.rst
> > new file mode 100644
> > index 00..b09e6788af
> > --- /dev/null
> > +++ b/doc/board/microchip/index.rst
> > @@ -0,0 +1,9 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +
> > +Microchip
> > +==
> > +
> > +.. toctree::
> > +   :maxdepth: 2
> > +
> > +   mpfs_icicle
> > diff --git a/doc/board/microchip/mpfs_icicle.rst
> b/doc/board/microchip/mpfs_icicle.rst
> > new file mode 100644
> > index 00..d1e6bd2077
> > --- /dev/null
> > +++ b/doc/board/microchip/mpfs_icicle.rst
> > @@ -0,0 +1,605 @@
> > +.. SPDX-License-Identifier: GPL-2.0+
> > +
> > +Microchip PolarFire SoC Icicle Kit
> > +==
> > +
> > +RISC-V PolarFire SoC
> > +-
> > +The PolarFire SoC is the 4+1 64-bit RISC-V SoC from Microchip.
> > +
> > +The Icicle Kit development platform is based on PolarFire SoC and
> capable
> > +of running Linux.
> > +
> > +Mainline support
> > +
> > +The support for following drivers are already enabled:
> > +
> > +1. NS16550 UART Driver.
> > +2. Microchip Clock Driver.
> > +3. Cadence MACB ethernet driver for networking support.
> > +4. Cadence MMC Driver for eMMC/SD support.
> > +
> > +Booting from eMMC using HSS
> > +---
> > +
> > +Building
> > +
> > +
> > +1. Add the RISC-V toolchain to your PATH.
> > +2. Setup ARCH & cross compilation environment variable:
> > +
> > +.. code-block:: none
> > +
> > +   export CROSS_COMPILE=
> > +
> > +3. make microchip_mpfs_icicle_defconfig
> > +4. make
> > +
> > +Flashing
> > +
> > +
> > +The current U-Boot port is supported in S-mode only and loaded from
> DRAM.
> > +
> > +A prior stage M-mode firmware/bootloader (e.g HSS with OpenSBI) is
> required to
> > +boot the u-boot.bin in S-mode.
> > +
> > +Currently, the u-boot.bin is used as a payload of the HSS firmware.
> > +
> > +You will be creating a payload from `u-boot-dtb.bin`.
> > +Copy this file to the toplevel HSS (Hart Software Services) directory.
> > +
> > +Creating the HSS payload
> > +
> > +
> > +Please refer to HSS documenation to build the HSS firmware.
> > +(Note: HSS git repo is at
> > +https://github.com/polarfire-soc/hart-software-services/blob/master
> > +/tools/hss-payload-generator/README.md)
> > +
> > +Once the payload binary is generated, it should be copied to the eMMC.
> > +
> > +FPGA design with HSS programming file
> > +-
> > +
> https://github.com/polarfire-soc/polarfire-soc-documentation/blob/master/boards
> >
> +/mpfs-icicle-kit-es/updating-icicle-kit/updating-icicle-kit-design-and-linux.md
> > +
> > +The HSS firmware runs from the PolarFire SoC eNVM on reset.
> > +
> > +eMMC
> > +
> > +Program eMMC with payload binary is explained in the PolarFire SoC
> documentation.
> > +
> > +(Note: PolarFire SoC Documentation git repo is at
> > +
> https://github.com/polarfire-soc/polarfire-soc-documentation/blob/master/boards
> >
> +/mpfs-icicle-kit-es/updating-icicle-kit/updating-icicle-kit-design-and-linux.md#eMMC
> > +
> > +Once the payload image is copied to the eMMC, press CTRL+C in the HSS
> command
> > +line interface, then type 'boot' and enter to boot the newly copied
> image.
> > +
> > +.. code-block:: none
> > +
> > +sudo dd if= of=/dev/sdX bs=512
> > +
> > +Booting
> > +---
> > +you should see the U-Boot prompt on UART1.
>
> Like I mentioned in another PATCH, all the HSS boot logs are on
> UART0 and U-Boot appears on UART1. This is very inconvenient.
>
> Please use UART0 for U-Boot and users can easily use UART1
> for Linux (if they want) using bootargs passed to Linux kernel.
>
> This will be consistent with other boards as well.
>
> Regards,
> Anup
>
> ok, will use UART0

Regards
Padmarao

> > +
> > +Sample boot log from MPFS Icicle Kit
> > +---
> > +
> > +.. code-block:: none
> > +
> > +   U-Boot 

Re: [PATCH v3] drivers: serial: probe all uart devices

2020-10-19 Thread Stefan Roese

On 19.10.20 11:53, Vabhav Sharma wrote:

From: Vabhav Sharma 

U-Boot DM model probe only single device at a time
which is enabled and configured using device tree
or platform data method.

PL011 UART IP is SBSA compliant and firmware does the
serial port set-up, initialization and let the kernel use
UART port for sending and receiving characters.

Normally software talk to one serial port time but some
LayerScape platform require all the UART devices enabled
in Linux for various use case.

Adding support to probe all enabled serial devices like SBSA
compliant PL011 UART ports probe and initialization by firmware.

Signed-off-by: Vabhav Sharma 
--
v3:
   Incorporated Simon and Stephan review comment
   - Define generic function uclass_probe_all(enum uclass_id)
 in drivers/core/uclass.c


Hmmm, seems to be missing (see below).


   - Added the function in caller of serial_find_console_or_panic()
   - Removed repeated sequence with generic function call uclass_probe_all()
   - Dependent on other patch [PATCH] dm: core: add function uclass_probe_all()
 to probe all devices

v2:
   Incorporated Stefan review comment, Update #ifdef with macro
   if (IS_ENABLED)..
---
  drivers/serial/Kconfig | 17 +
  drivers/serial/serial-uclass.c |  4 
  2 files changed, 21 insertions(+)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b4805a2..af8779b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -134,6 +134,23 @@ config SERIAL_SEARCH_ALL
  
  	  If unsure, say N.
  
+config SERIAL_PROBE_ALL

+   bool "Probe all available serial devices"
+   depends on DM_SERIAL
+   default n


Not needed as it's default?


+   help
+ The serial subsystem only probe for single serial device,
+ but does not probe for other remaining serial devices.
+ With this option set,we make probing and searching for
+ all available devices optional.
+ Normally, U-Boot talk to one serial port at a time but SBSA
+ compliant UART devices like PL011 require initialization
+ by firmware and let the kernel use serial port for sending
+ and receiving the characters.
+
+ If probing is not required for all remaining available
+ devices other than default current console device, say N.
+
  config SPL_DM_SERIAL
bool "Enable Driver Model for serial drivers in SPL"
depends on DM_SERIAL && SPL_DM
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 0027625..09bc6f4 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -172,6 +172,10 @@ int serial_init(void)
  /* Called after relocation */
  int serial_initialize(void)
  {
+   /* Scanning uclass to probe devices */
+   if (IS_ENABLED(CONFIG_SERIAL_PROBE_ALL))
+   uclass_probe_all(UCLASS_SERIAL);
+
return serial_init();
  }


So where is the uclass_probe_all() function defined? You seem to have
missed something in your patch.

Thanks,
Stefan


Re: [PATCH] mx6: peripheral clock from oscillator

2020-10-19 Thread Fabio Estevam
Hi Jorge,

On Wed, Oct 14, 2020 at 10:07 AM Jorge Ramirez-Ortiz  wrote:
>
> In order to be able to run the I2C bus at 400Khz, the chip errata[1]
> recommends that the peripheral clock runs out of the 24MHz oscillator.
>
> [1] Rev 2, 10/2019, ERR007805
>
> Signed-off-by: Jorge Ramirez-Ortiz 
> ---
>  arch/arm/mach-imx/mx6/soc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> index e129286065..1da250bbcd 100644
> --- a/arch/arm/mach-imx/mx6/soc.c
> +++ b/arch/arm/mach-imx/mx6/soc.c
> @@ -469,7 +469,7 @@ int arch_cpu_init(void)
> }
>
> /* Set perclk to source from OSC 24MHz */
> -   if (is_mx6sl())
> +   if (is_mx6sl() || is_mx6ull())

According to https://www.nxp.com/docs/en/errata/IMX6SDLCE.pdf the
mx6solo and mx6dl are also affected by ERR007805.

These variants should be handled too.


Re: [PATCH next] usb: mtu3: fix build warning/error

2020-10-19 Thread Marek Vasut
On 10/19/20 11:32 AM, Chunfeng Yun wrote:
> On Mon, 2020-10-19 at 08:07 +0200, Marek Vasut wrote:
>> On 10/19/20 5:46 AM, Chunfeng Yun wrote:
>>> Fix up the following build warning/error:
>>> 1. unused variable 'mtu' in mtu3_gadget_dequeue() and
>>>mtu3_gadget_ep_set_halt()
>>> 2. implicit declaration of function ‘flush_dcache_range’ and
>>>‘invalidate_dcache_range’
>>
>> Which patch of the ones in usb/next do I squash this in ?
> 
> squash in:  ab703ebb1c usb: add MediaTek USB3 DRD driver
> 
> Thanks a lot

Build fails:
https://gitlab.denx.de/u-boot/custodians/u-boot-usb/-/pipelines/5036


Re: [PATCH v1 0/8] Microchip PolarFire SoC support

2020-10-19 Thread Padmarao Begari
Hi Anup,

On Sat, Oct 17, 2020 at 3:01 PM Anup Patel  wrote:

> On Fri, Oct 16, 2020 at 7:54 PM  wrote:
> >
> > From: Padmarao Begari 
> >
> > This patch set adds Microchip PolarFire SoC Icicle Kit support
> > to RISC-V U-Boot.
> >
> > The patches are based upon latest U-Boot tree
> > (https://gitlab.denx.de/u-boot/u-boot.git) at commit id
> > 9dc6aef8c963ae17e1263b89c692792fce0c7198
> >
> > All drivers namely: NS16550 Serial, Microchip clock,
> > Cadence eMMC and Cadence MACB Ethernet work fine on actual
> > Microchip PolarFire SoC Icicle Kit.
> >
> > Padmarao Begari (8):
> >   riscv: Add Microchip MPFS Icicle Kit support
> >   riscv: dts: Add device tree for Microchip Icicle Kit
> >   dt-bindings: clock: Add indexes for reset signals
> >   riscv: Add DMA 64-bit address support
> >   net: macb: Add DMA 64-bit address support for macb
> >   net: macb: Add phy address to read it from device tree
> >   clk: Add Microchip PolarFire SoC clock driver
> >   doc: board: Add Microchip MPFS Icicle Kit doc
>
> The way patches are organized, it breaks git bisect-ability
> because PATCH2 depends on PATCH3. Also, PATCH3 should
> be squashed into PATCH7.
>
> Based on dependency, here's better ordering of patches:
> PATCH1) riscv: Add DMA 64-bit address support
> PATCH2) net: macb: Add DMA 64-bit address support for macb
> PATCH3) net: macb: Add phy address to read it from device tree
> PATCH4) clk: Add Microchip PolarFire SoC clock driver
> (Note: PATCH4 also include "dt-bindings: clock: Add indexes for reset
> signals")
> PATCH5) riscv: dts: Add device tree for Microchip Icicle Kit
> PATCH6) riscv: Add Microchip MPFS Icicle Kit support
> PATCH7) doc: board: Add Microchip MPFS Icicle Kit doc
>
> Regards,
> Anup
>
>  ok, I will bring PATCH2 into PATCH7 and re-order patches.

Regards
Padmarao

> >
> >  arch/riscv/Kconfig|   5 +
> >  arch/riscv/dts/Makefile   |   1 +
> >  arch/riscv/dts/microchip-icicle-kit-a000.dts  | 419 
> >  arch/riscv/include/asm/types.h|   4 +
> >  board/microchip/mpfs_icicle/Kconfig   |  26 +
> >  board/microchip/mpfs_icicle/mpfs_icicle.c |  96 ++-
> >  configs/microchip_mpfs_icicle_defconfig   |   9 +-
> >  doc/board/index.rst   |   1 +
> >  doc/board/microchip/index.rst |   9 +
> >  doc/board/microchip/mpfs_icicle.rst   | 605 ++
> >  drivers/clk/Kconfig   |   1 +
> >  drivers/clk/Makefile  |   1 +
> >  drivers/clk/microchip/Kconfig |   5 +
> >  drivers/clk/microchip/Makefile|   1 +
> >  drivers/clk/microchip/clk_pfsoc.c | 120 
> >  drivers/clk/microchip/clk_pfsoc.h |  19 +
> >  drivers/clk/microchip/clk_pfsoc_cfg.c | 135 
> >  drivers/clk/microchip/clk_pfsoc_periph.c  | 171 +
> >  drivers/net/macb.c|  57 +-
> >  drivers/net/macb.h|   6 +
> >  include/configs/microchip_mpfs_icicle.h   |  60 +-
> >  .../dt-bindings/clock/microchip,pfsoc-clock.h |  45 ++
> >  22 files changed, 1744 insertions(+), 52 deletions(-)
> >  create mode 100644 arch/riscv/dts/microchip-icicle-kit-a000.dts
> >  create mode 100644 doc/board/microchip/index.rst
> >  create mode 100644 doc/board/microchip/mpfs_icicle.rst
> >  create mode 100644 drivers/clk/microchip/Kconfig
> >  create mode 100644 drivers/clk/microchip/Makefile
> >  create mode 100644 drivers/clk/microchip/clk_pfsoc.c
> >  create mode 100644 drivers/clk/microchip/clk_pfsoc.h
> >  create mode 100644 drivers/clk/microchip/clk_pfsoc_cfg.c
> >  create mode 100644 drivers/clk/microchip/clk_pfsoc_periph.c
> >  create mode 100644 include/dt-bindings/clock/microchip,pfsoc-clock.h
> >
> > --
> > 2.17.1
> >
>


Re: [PATCH v1 2/8] riscv: dts: Add device tree for Microchip Icicle Kit

2020-10-19 Thread Padmarao Begari
On Sun, Oct 18, 2020 at 7:12 AM Sean Anderson  wrote:

> On 10/16/20 10:23 AM, padmarao.beg...@microchip.com wrote:
> > From: Padmarao Begari 
> >
> > Add device tree for Microchip PolarFire SoC Icicle Kit.
> >
> > Signed-off-by: Padmarao Begari 
> > ---
> >  arch/riscv/dts/Makefile  |   1 +
> >  arch/riscv/dts/microchip-icicle-kit-a000.dts | 419 +++
> >  2 files changed, 420 insertions(+)
> >  create mode 100644 arch/riscv/dts/microchip-icicle-kit-a000.dts
> >
> > diff --git a/arch/riscv/dts/Makefile b/arch/riscv/dts/Makefile
> > index 3a6f96c67d..48c43bd122 100644
> > --- a/arch/riscv/dts/Makefile
> > +++ b/arch/riscv/dts/Makefile
> > @@ -3,6 +3,7 @@
> >  dtb-$(CONFIG_TARGET_AX25_AE350) += ae350_32.dtb ae350_64.dtb
> >  dtb-$(CONFIG_TARGET_SIFIVE_FU540) += hifive-unleashed-a00.dtb
> >  dtb-$(CONFIG_TARGET_SIPEED_MAIX) += k210-maix-bit.dtb
> > +dtb-$(CONFIG_TARGET_MICROCHIP_ICICLE) += microchip-icicle-kit-a000.dtb
> >
> >  targets += $(dtb-y)
> >
> > diff --git a/arch/riscv/dts/microchip-icicle-kit-a000.dts
> b/arch/riscv/dts/microchip-icicle-kit-a000.dts
> > new file mode 100644
> > index 00..e7f0ec6926
> > --- /dev/null
> > +++ b/arch/riscv/dts/microchip-icicle-kit-a000.dts
> > @@ -0,0 +1,419 @@
> > +// SPDX-License-Identifier: GPL-2.0+
> > +/* Copyright (c) 2020 Microchip Technology Inc */
> > +
> > +/dts-v1/;
> > +#include "dt-bindings/clock/microchip,pfsoc-clock.h"
> > +
> > +/ {
> > + #address-cells = <2>;
> > + #size-cells = <2>;
> > + model = "Microchip PolarFire-SoC";
> > + compatible = "microchip,polarfire-soc";
> > +
> > + aliases {
> > + serial0 = 
> > + ethernet0 = 
> > + };
> > +
> > + chosen {
> > + stdout-path = "serial0";
> > + };
> > +
> > + cpucomplex: cpus {
> > + #address-cells = <1>;
> > + #size-cells = <0>;
> > + timebase-frequency = <100>;
> > + cpu0: cpu@0 {
> > + clocks = < CLK_CPU>;
> > + compatible = "sifive,e51", "sifive,rocket0",
> "riscv";
> > + device_type = "cpu";
> > + i-cache-block-size = <64>;
> > + i-cache-sets = <128>;
> > + i-cache-size = <16384>;
> > + reg = <0>;
> > + riscv,isa = "rv64imac";
> > + status = "disabled";
> > + operating-points = <
> > + /* kHz  uV */
> > + 60  110
> > + 30   95
> > + 15   75
> > + >;
> > + cpu0intc: interrupt-controller {
> > + #interrupt-cells = <1>;
> > + compatible = "riscv,cpu-intc";
> > + interrupt-controller;
> > + };
> > + };
> > + cpu1: cpu@1 {
> > + clocks = < CLK_CPU>;
> > + compatible = "sifive,u54-mc", "sifive,rocket0",
> "riscv";
> > + d-cache-block-size = <64>;
> > + d-cache-sets = <64>;
> > + d-cache-size = <32768>;
> > + d-tlb-sets = <1>;
> > + d-tlb-size = <32>;
> > + device_type = "cpu";
> > + i-cache-block-size = <64>;
> > + i-cache-sets = <64>;
> > + i-cache-size = <32768>;
> > + i-tlb-sets = <1>;
> > + i-tlb-size = <32>;
> > + mmu-type = "riscv,sv39";
> > + reg = <1>;
> > + riscv,isa = "rv64imafdc";
> > + tlb-split;
> > + status = "okay";
> > + operating-points = <
> > + /* kHz  uV */
> > + 60  110
> > + 30   95
> > + 15   75
> > + >;
> > + cpu1intc: interrupt-controller {
> > + #interrupt-cells = <1>;
> > + compatible = "riscv,cpu-intc";
> > + interrupt-controller;
> > + };
> > + };
> > + cpu2: cpu@2 {
> > + clocks = < CLK_CPU>;
> > + compatible = "sifive,u54-mc", "sifive,rocket0",
> "riscv";
> > + d-cache-block-size = <64>;
> > + d-cache-sets = <64>;
> > + d-cache-size = <32768>;
> > + d-tlb-sets = <1>;
> > + d-tlb-size = <32>;
> > + device_type = "cpu";
> > + i-cache-block-size = <64>;
> > +  

Re: [PATCH v1 3/8] dt-bindings: clock: Add indexes for reset signals

2020-10-19 Thread Padmarao Begari
On Sat, Oct 17, 2020 at 3:11 PM Anup Patel  wrote:

> On Fri, Oct 16, 2020 at 7:54 PM  wrote:
> >
> > From: Padmarao Begari 
> >
> > Add indexes for reset and clock control signals within the system
> register
> > module of the Microchip PolarFire SoC.
>
> This patch should be squashed into your PATCH7.
>
> ok

Regards
Padmarao

> >
> > Signed-off-by: Padmarao Begari 
> > ---
> >  .../dt-bindings/clock/microchip,pfsoc-clock.h | 45 +++
> >  1 file changed, 45 insertions(+)
> >  create mode 100644 include/dt-bindings/clock/microchip,pfsoc-clock.h
> >
> > diff --git a/include/dt-bindings/clock/microchip,pfsoc-clock.h
> b/include/dt-bindings/clock/microchip,pfsoc-clock.h
> > new file mode 100644
> > index 00..527cff1a28
> > --- /dev/null
> > +++ b/include/dt-bindings/clock/microchip,pfsoc-clock.h
> > @@ -0,0 +1,45 @@
> > +/* SPDX-License-Identifier: GPL-2.0+ */
> > +/*
> > + * Copyright (C) 2020 Microchip Technology Inc.
> > + * Padmarao Begari 
> > + */
> > +
> > +#ifndef _DT_BINDINGS_CLK_MICROCHIP_PFSOC_H_
> > +#define _DT_BINDINGS_CLK_MICROCHIP_PFSOC_H_
> > +
> > +#define CLK_CPU0
> > +#define CLK_AXI1
> > +#define CLK_AHB2
> > +
> > +#define CLK_ENVM   3
> > +#define CLK_MAC0   4
> > +#define CLK_MAC1   5
> > +#define CLK_MMC6
> > +#define CLK_TIMER  7
> > +#define CLK_MMUART08
> > +#define CLK_MMUART19
> > +#define CLK_MMUART210
> > +#define CLK_MMUART311
> > +#define CLK_MMUART412
> > +#define CLK_SPI0   13
> > +#define CLK_SPI1   14
> > +#define CLK_I2C0   15
> > +#define CLK_I2C1   16
> > +#define CLK_CAN0   17
> > +#define CLK_CAN1   18
> > +#define CLK_USB19
> > +#define CLK_RESERVED   20
> > +#define CLK_RTC21
> > +#define CLK_QSPI   22
> > +#define CLK_GPIO0  23
> > +#define CLK_GPIO1  24
> > +#define CLK_GPIO2  25
> > +#define CLK_DDRC   26
> > +#define CLK_FIC0   27
> > +#define CLK_FIC1   28
> > +#define CLK_FIC2   29
> > +#define CLK_FIC3   30
> > +#define CLK_ATHENA 31
> > +#define CLK_CFM32
> > +
> > +#endif /* _DT_BINDINGS_CLK_MICROCHIP_PFSOC_H_ */
> > --
> > 2.17.1
> >
>
> Regards,
> Anup
>


Re: [PATCH 18/18] MAINTAINERS: add maintainer for MediaTek MIPS platform

2020-10-19 Thread Stefan Roese

On 16.10.20 09:37, Weijie Gao wrote:

Update maintainer for MediaTek MIPS platform

Signed-off-by: Weijie Gao 


Great. Thanks Weijie!

Acked-by: Stefan Roese 
Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  MAINTAINERS | 23 +++
  1 file changed, 23 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index fb9ba37984..f9a7a2c4b7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -790,6 +790,29 @@ F: drivers/mmc/ca_dw_mmc.c
  F:drivers/i2c/i2c-cortina.c
  F:drivers/i2c/i2c-cortina.h
  
+MIPS MEDIATEK

+M: Weijie Gao 
+R: GSS_MTK_Uboot_upstream 
+S: Maintained
+F: arch/mips/mach-mtmips/
+F: arch/mips/dts/mt7620.dtsi
+F: arch/mips/dts/mt7620-u-boot.dtsi
+F: include/configs/mt7620.h
+F: include/dt-bindings/clock/mt7620-clk.h
+F: include/dt-bindings/clock/mt7628-clk.h
+F: include/dt-bindings/reset/mt7620-reset.h
+F: include/dt-bindings/reset/mt7628-reset.h
+F: drivers/clk/mtmips/
+F: drivers/pinctrl/mtmips/
+F: drivers/gpio/mt7620_gpio.c
+F: drivers/net/mt7620-eth.c
+F: drivers/phy/mt7620-usb-phy.c
+F: drivers/reset/reset-mtmips.c
+F: drivers/serial/serial_mt7620.c
+F: drivers/spi/mt7620_spi.c
+F: drivers/sysreset/sysreset_resetctl.c
+F: drivers/watchdog/mt7620_wdt.c
+
  MIPS MSCC
  M:Gregory CLEMENT 
  M:Lars Povlsen 




Viele Grüße,
Stefan

--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: s...@denx.de


[PULL] u-boot-atmel-2021.01-b

2020-10-19 Thread Eugen.Hristev
Hello Tom,

Please pull tag u-boot-atmel-2021.01-b, the second set of new features 
and fixes for 2021.01 cycle.

This feature set brings the rework of the clock tree for sam9x60 SoC. 
This makes the clock tree fully compatible with Common Clock Framework 
and allows full clock configuration in U-boot. This means that the 
sam9x60 boards can boot now using U-boot.
This also includes the definitions for sam9x60 SiPs and a divisor fix 
for the clock on sama7g5 SoC.

Thanks !
Eugen

The following changes since commit 3d19a7ee8ca7af01f75ff24622ea3c9840cd5bca:

   test: Fix sandbox tests failing to build (2020-10-17 09:03:22 -0400)

are available in the Git repository at:

   https://gitlab.denx.de/u-boot/custodians/u-boot-atmel.git 
tags/u-boot-atmel-2021.01-b

for you to fetch changes up to dc470834a1ea50749c19ebac2c34e0edb898ab18:

   clk: at91: sama7g5: add 5th divisor for mck0 layout and 
characteristics (2020-10-19 09:19:53 +0300)


Second set of u-boot-atmel features for 2021.01 cycle


Claudiu Beznea (8):
   board: atmel: sam9x60ek: add SYS_MALLOC_F_LEN to SYS_INIT_SP_ADDR
   clk: at91: sam9x60: add support compatible with CCF
   ARM: dts: sam9x60ek: add clock frequencies to board file
   ARM: dts: sam9x60: use u-boot,dm-pre-reloc
   ARM: dts: sam9x60: use slow clock CCF compatible bindings
   ARM: dts: sam9x60: use CCF compatibles for PMC
   configs: sam9x60ek: update defconfigs for CCF
   ARM: dts: sam9x60: use alphabetical order

Eugen Hristev (2):
   clk: at91: clk-master: add 5th divisor for mck master
   clk: at91: sama7g5: add 5th divisor for mck0 layout and 
characteristics

Nicolas Ferre (1):
   ARM: at91: Add chip ID for SAM9X60 SiP

  arch/arm/dts/sam9x60.dtsi  | 171 ++-
  arch/arm/dts/sam9x60ek-u-boot.dtsi |  70 +--
  arch/arm/dts/sam9x60ek.dts |  12 +-
  arch/arm/mach-at91/arm926ejs/sam9x60_devices.c |   6 +
  arch/arm/mach-at91/include/mach/sam9x60.h  |   3 +
  configs/sam9x60ek_mmc_defconfig|   4 +-
  configs/sam9x60ek_nandflash_defconfig  |   4 +-
  configs/sam9x60ek_qspiflash_defconfig  |   4 +-
  drivers/clk/at91/Makefile  |   1 +
  drivers/clk/at91/clk-master.c  |   2 +-
  drivers/clk/at91/pmc.h |   2 +-
  drivers/clk/at91/sam9x60.c | 649 
+
  drivers/clk/at91/sama7g5.c |   4 +-
  include/configs/sam9x60ek.h|   3 +-
  14 files changed, 729 insertions(+), 206 deletions(-)
  create mode 100644 drivers/clk/at91/sam9x60.c


[PATCH 07/11] bootm: Split out bootargs environment reading / writing

2020-10-19 Thread Simon Glass
At present bootm_process_cmdline_env() reads the 'bootargs' variable and
then writes it back afterwards. This is painful for tests, which would
rather use a simple buffer.

It is also useful for zimage to use a buffer, since it does not actually
put the Linux command line in the bootargs variable.

Refactor the existing code into two pieces. One handles reading and
writing the environment variable, as well as allocating a buffer for use
by the rest of the code, which now operates on a buffer.

Signed-off-by: Simon Glass 
---

 common/bootm.c | 95 ++
 1 file changed, 73 insertions(+), 22 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index bbe59752609..41965fa304c 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #if defined(CONFIG_CMD_USB)
 #include 
 #endif
@@ -35,6 +36,8 @@
 #define CONFIG_SYS_BOOTM_LEN   0x80
 #endif
 
+#define MAX_CMDLINE_SIZE   SZ_4K
+
 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
 
 #ifndef USE_HOSTCC
@@ -466,20 +469,31 @@ ulong bootm_disable_interrupts(void)
 #define CONSOLE_ARG"console="
 #define CONSOLE_ARG_SIZE   sizeof(CONSOLE_ARG)
 
-int bootm_process_cmdline_env(bool do_silent)
+/**
+ * fixup_silent_linux() - Handle silencing the linux boot if required
+ *
+ * This uses the silent_linux envvar to control whether to add/set a "console="
+ * parameter to the command line
+ *
+ * @buf: Buffer containing the string to process
+ * @maxlen: Maximum length of buffer
+ * @return 0 if OK, -ENOSPC if @maxlen is too small
+ */
+static int fixup_silent_linux(char *buf, int maxlen)
 {
-   char *buf;
-   const char *env_val;
-   char *cmdline;
int want_silent;
+   char *cmdline;
+   int size;
 
-   /* First check if any action is needed */
-   do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
-   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && do_silent;
-   if (!do_silent)
-   return 0;
-   cmdline = env_get("bootargs");
-
+   /*
+* Move the input string to the end of buffer. The output string will be
+* built up at the start.
+*/
+   size = strlen(buf) + 1;
+   if (size * 2 > maxlen)
+   return -ENOSPC;
+   cmdline = buf + maxlen - size;
+   memmove(cmdline, buf, size);
/*
 * Only fix cmdline when requested. The environment variable can be:
 *
@@ -494,15 +508,12 @@ int bootm_process_cmdline_env(bool do_silent)
return 0;
 
debug("before silent fix-up: %s\n", cmdline);
-   if (cmdline && (cmdline[0] != '\0')) {
+   if (*cmdline) {
char *start = strstr(cmdline, CONSOLE_ARG);
 
-   /* Allocate space for maximum possible new command line */
-   buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_SIZE);
-   if (!buf) {
-   debug("%s: out of memory\n", __func__);
+   /* Check space for maximum possible new command line */
+   if (size + CONSOLE_ARG_SIZE > maxlen)
return -ENOSPC;
-   }
 
if (start) {
char *end = strchr(start, ' ');
@@ -517,15 +528,55 @@ int bootm_process_cmdline_env(bool do_silent)
} else {
sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
}
-   env_val = buf;
+   if (buf + strlen(buf) >= cmdline)
+   return -ENOSPC;
} else {
-   buf = NULL;
-   env_val = CONSOLE_ARG;
+   if (maxlen < sizeof(CONSOLE_ARG))
+   return -ENOSPC;
+   strcpy(buf, CONSOLE_ARG);
}
+   debug("after silent fix-up: %s\n", buf);
 
-   env_set("bootargs", env_val);
-   debug("after silent fix-up: %s\n", env_val);
+   return 0;
+}
+
+int bootm_process_cmdline_env(bool do_silent)
+{
+   const int maxlen = MAX_CMDLINE_SIZE;
+   const char *env;
+   char *buf;
+   int ret;
+
+   /* First check if any action is needed */
+   do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
+   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && do_silent;
+   if (!do_silent)
+   return 0;
+
+   env = env_get("bootargs");
+   if (env && strlen(env) >= maxlen)
+   return -E2BIG;
+   buf = malloc(maxlen);
+   if (!buf)
+   return -ENOMEM;
+   if (env)
+   strcpy(buf, env);
+   else
+   *buf = '\0';
+   ret = fixup_silent_linux(buf, maxlen);
+   if (!ret) {
+   ret = env_set("bootargs", buf);
+
+   /*
+* If buf is "" and bootargs does not exist, this will produce
+* an error trying to delete bootargs. Ignore it
+*/
+   if (ret == -ENOENT)
+   ret = 0;
+  

[PATCH 05/11] bootm: Add a bool parameter to bootm_process_cmdline_env()

2020-10-19 Thread Simon Glass
This function will soon do more than just handle the 'silent linux'
feature. As a first step, update it to take a boolean parameter,
indicating whether or not the processing is required.

Signed-off-by: Simon Glass 
---

 common/bootm.c  | 20 ++--
 include/bootm.h |  3 ++-
 test/bootm.c| 10 +-
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index ace5771d53f..fa2aecdbc68 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -466,15 +466,17 @@ ulong bootm_disable_interrupts(void)
 #define CONSOLE_ARG "console="
 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
 
-int bootm_process_cmdline_env(void)
+int bootm_process_cmdline_env(bool do_silent)
 {
char *buf;
const char *env_val;
char *cmdline;
int want_silent;
 
-   if (!IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
-   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY))
+   /* First check if any action is needed */
+   do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
+   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && do_silent;
+   if (!do_silent)
return 0;
cmdline = env_get("bootargs");
 
@@ -629,13 +631,11 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
if (!ret && (states & BOOTM_STATE_OS_BD_T))
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) {
-   if (images->os.os == IH_OS_LINUX) {
-   ret = bootm_process_cmdline_env();
-   if (ret) {
-   printf("Cmdline setup failed (err=%d)\n", ret);
-   ret = CMD_RET_FAILURE;
-   goto err;
-   }
+   ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX);
+   if (ret) {
+   printf("Cmdline setup failed (err=%d)\n", ret);
+   ret = CMD_RET_FAILURE;
+   goto err;
}
ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
}
diff --git a/include/bootm.h b/include/bootm.h
index 35c27ab9609..f12ee2b3cb3 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -91,8 +91,9 @@ void board_preboot_os(void);
  * Updates the 'bootargs' envvar as required. This handles making Linux boot
  * silently if requested ('silent_linux' envvar)
  *
+ * @do_silent: Process bootargs for silent console
  * @return 0 if OK, -ENOMEM if out of memory
  */
-int bootm_process_cmdline_env(void);
+int bootm_process_cmdline_env(bool do_silent);
 
 #endif
diff --git a/test/bootm.c b/test/bootm.c
index b69bfad4f67..c203f0acd60 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state 
*uts)
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env());
+   ut_assertok(bootm_process_cmdline_env(true));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
env_set("bootargs", NULL);
-   ut_assertok(bootm_process_cmdline_env());
+   ut_assertok(bootm_process_cmdline_env(true));
ut_assertnull(env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "no"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env());
+   ut_assertok(bootm_process_cmdline_env(true));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "yes"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env());
+   ut_assertok(bootm_process_cmdline_env(true));
ut_asserteq_str("console=", env_get("bootargs"));
 
/* Empty buffer should still add the string */
env_set("bootargs", NULL);
-   ut_assertok(bootm_process_cmdline_env());
+   ut_assertok(bootm_process_cmdline_env(true));
ut_asserteq_str("console=", env_get("bootargs"));
 
return 0;
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH 00/11] bootm: Support substitions in bootargs and add tests

2020-10-19 Thread Simon Glass
This series adds tests to the fixup_silent-linux() function and extends
the 'zimage' command to use it.

It also adds a new string-substition feature to allow bootargs to be a
template, rather than having to build it up piece by piece with
information obtained in a build script.

It also updates zimage to use the same command-line processing.

With these additions it is possible to boot Chrome OS from a U-Boot script
on most Chromebooks.


Simon Glass (11):
  env: Allow returning errors from hdelete_r()
  bootm: Add tests for fixup_silent_linux()
  bootm: Update fixup_silent_linux() to return an error
  bootm: Rename fixup_silent_linux()
  bootm: Add a bool parameter to bootm_process_cmdline_env()
  bootm: Use size rather than length for CONSOLE_ARG
  bootm: Split out bootargs environment reading / writing
  bootm: Update bootm_process_cmdline_env() to use flags
  bootm: Allow updating the bootargs in a buffer
  x86: zimage: Add silent-console processing
  bootm: Support string substitution in bootargs

 README|  16 +++
 arch/Kconfig  |   2 +
 arch/x86/lib/zimage.c |  14 +++
 cmd/nvedit.c  |   6 +-
 common/Kconfig.boot   |  20 
 common/bootm.c| 206 +--
 include/bootm.h   |  40 +++
 include/search.h  |  11 +-
 include/test/suites.h |   1 +
 lib/hashtable.c   |  12 +--
 test/Makefile |   1 +
 test/bootm.c  | 243 ++
 test/cmd_ut.c |   1 +
 test/env/hashtable.c  |   2 +-
 14 files changed, 534 insertions(+), 41 deletions(-)
 create mode 100644 test/bootm.c

-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH 09/11] bootm: Allow updating the bootargs in a buffer

2020-10-19 Thread Simon Glass
At present we only support updating the 'bootargs' environment
variable. Add another function to update a buffer instead. This will
allow zimage to use this feature.

Also add a lot more tests to cover various cases.

Signed-off-by: Simon Glass 
---

 common/bootm.c  |  18 +++-
 include/bootm.h |  16 +++
 test/bootm.c| 114 +---
 3 files changed, 132 insertions(+), 16 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 5a5b79c5cd0..5484c2be900 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -540,6 +540,22 @@ static int fixup_silent_linux(char *buf, int maxlen)
return 0;
 }
 
+int bootm_process_cmdline(char *buf, int maxlen, int flags)
+{
+   int ret;
+
+   /* Check config first to enable compiler to eliminate code */
+   if (IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
+   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) &&
+   (flags & BOOTM_CL_SILENT)) {
+   ret = fixup_silent_linux(buf, maxlen);
+   if (ret)
+   return log_msg_ret("silent", ret);
+   }
+
+   return 0;
+}
+
 int bootm_process_cmdline_env(int flags)
 {
const int maxlen = MAX_CMDLINE_SIZE;
@@ -564,7 +580,7 @@ int bootm_process_cmdline_env(int flags)
strcpy(buf, env);
else
*buf = '\0';
-   ret = fixup_silent_linux(buf, maxlen);
+   ret = bootm_process_cmdline(buf, maxlen, flags);
if (!ret) {
ret = env_set("bootargs", buf);
 
diff --git a/include/bootm.h b/include/bootm.h
index 4876d7b2882..8d95fb2a90a 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -93,6 +93,22 @@ void arch_preboot_os(void);
 void board_preboot_os(void);
 
 /*
+ * bootm_process_cmdline() - Process fix-ups for the command line
+ *
+ * This handles: making Linux boot silently if requested ('silent_linux' 
envvar)
+ *
+ * @maxlen must provide enough space for the string being processed plus the
+ * resulting string
+ *
+ * @buf: buffer holding commandline string to adjust
+ * @maxlen: Maximum length of buffer at @buf (including \0)
+ * @flags: Flags to control what happens (see bootm_cmdline_t)
+ * @return 0 if OK, -ENOMEM if out of memory, -ENOSPC if the commandline is too
+ * long
+ */
+int bootm_process_cmdline(char *buf, int maxlen, int flags);
+
+/**
  * bootm_process_cmdline_env() - Process fix-ups for the command line
  *
  * Updates the 'bootargs' envvar as required. This handles making Linux boot
diff --git a/test/bootm.c b/test/bootm.c
index ba08920bb17..d0b29441d65 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -15,33 +15,117 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define BOOTM_TEST(_name, _flags)  UNIT_TEST(_name, _flags, bootm_test)
 
+enum {
+   BUF_SIZE= 1024,
+};
+
 #define CONSOLE_STR"console=/dev/ttyS0"
 
-/* Test silent processing in the bootargs variable */
-static int bootm_test_silent_var(struct unit_test_state *uts)
+/* Test cmdline processing where nothing happens */
+static int bootm_test_nop(struct unit_test_state *uts)
+{
+   char buf[BUF_SIZE];
+
+   *buf = '\0';
+   ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+   ut_asserteq_str("", buf);
+
+   strcpy(buf, "test");
+   ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+   ut_asserteq_str("test", buf);
+
+   return 0;
+}
+BOOTM_TEST(bootm_test_nop, 0);
+
+/* Test cmdline processing when out of space */
+static int bootm_test_nospace(struct unit_test_state *uts)
+{
+   char buf[BUF_SIZE];
+
+   /* Zero buffer size */
+   *buf = '\0';
+   ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, 0, true));
+
+   /* Buffer string not terminated */
+   memset(buf, 'a', BUF_SIZE);
+   ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+
+   /* Not enough space to copy string */
+   memset(buf, '\0', BUF_SIZE);
+   memset(buf, 'a', BUF_SIZE / 2);
+   ut_asserteq(-ENOSPC, bootm_process_cmdline(buf, BUF_SIZE, true));
+
+   /* Just enough space */
+   memset(buf, '\0', BUF_SIZE);
+   memset(buf, 'a', BUF_SIZE / 2 - 1);
+   ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, true));
+
+   return 0;
+}
+BOOTM_TEST(bootm_test_nospace, 0);
+
+/* Test silent processing */
+static int bootm_test_silent(struct unit_test_state *uts)
 {
+   char buf[BUF_SIZE];
+
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
-   env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
-   ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
-
-   env_set("bootargs", NULL);
-   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
-   ut_assertnull(env_get("bootargs"));
+   strcpy(buf, CONSOLE_STR);
+   ut_assertok(bootm_process_cmdline(buf, BUF_SIZE, BOOTM_CL_SILENT));
+   ut_asserteq_str(CONSOLE_STR, buf);
 
ut_assertok(env_set("silent_linux", 

[PATCH 04/11] bootm: Rename fixup_silent_linux()

2020-10-19 Thread Simon Glass
We want to add more processing to this function. Before doing so, rename
it to bootm_process_cmdline_env(), which is more generic.

Signed-off-by: Simon Glass 
---

 common/bootm.c  |  4 ++--
 include/bootm.h |  4 ++--
 test/bootm.c| 10 +-
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 0ca66188c2b..ace5771d53f 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -466,7 +466,7 @@ ulong bootm_disable_interrupts(void)
 #define CONSOLE_ARG "console="
 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
 
-int fixup_silent_linux(void)
+int bootm_process_cmdline_env(void)
 {
char *buf;
const char *env_val;
@@ -630,7 +630,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) {
if (images->os.os == IH_OS_LINUX) {
-   ret = fixup_silent_linux();
+   ret = bootm_process_cmdline_env();
if (ret) {
printf("Cmdline setup failed (err=%d)\n", ret);
ret = CMD_RET_FAILURE;
diff --git a/include/bootm.h b/include/bootm.h
index 438829af0fe..35c27ab9609 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -86,13 +86,13 @@ void arch_preboot_os(void);
 void board_preboot_os(void);
 
 /*
- * fixup_silent_linux() - Process fix-ups for the command line
+ * bootm_process_cmdline_env() - Process fix-ups for the command line
  *
  * Updates the 'bootargs' envvar as required. This handles making Linux boot
  * silently if requested ('silent_linux' envvar)
  *
  * @return 0 if OK, -ENOMEM if out of memory
  */
-int fixup_silent_linux(void);
+int bootm_process_cmdline_env(void);
 
 #endif
diff --git a/test/bootm.c b/test/bootm.c
index ab1711609ba..b69bfad4f67 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state 
*uts)
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(fixup_silent_linux());
+   ut_assertok(bootm_process_cmdline_env());
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
env_set("bootargs", NULL);
-   ut_assertok(fixup_silent_linux());
+   ut_assertok(bootm_process_cmdline_env());
ut_assertnull(env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "no"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(fixup_silent_linux());
+   ut_assertok(bootm_process_cmdline_env());
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "yes"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(fixup_silent_linux());
+   ut_assertok(bootm_process_cmdline_env());
ut_asserteq_str("console=", env_get("bootargs"));
 
/* Empty buffer should still add the string */
env_set("bootargs", NULL);
-   ut_assertok(fixup_silent_linux());
+   ut_assertok(bootm_process_cmdline_env());
ut_asserteq_str("console=", env_get("bootargs"));
 
return 0;
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH 06/11] bootm: Use size rather than length for CONSOLE_ARG

2020-10-19 Thread Simon Glass
Use the size (including terminator) for in this function, rather than
the length. This is arguably easier to follow, with the coming
refactor.

Signed-off-by: Simon Glass 
---

 common/bootm.c | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index fa2aecdbc68..bbe59752609 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -463,8 +463,8 @@ ulong bootm_disable_interrupts(void)
return iflag;
 }
 
-#define CONSOLE_ARG "console="
-#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
+#define CONSOLE_ARG"console="
+#define CONSOLE_ARG_SIZE   sizeof(CONSOLE_ARG)
 
 int bootm_process_cmdline_env(bool do_silent)
 {
@@ -498,7 +498,7 @@ int bootm_process_cmdline_env(bool do_silent)
char *start = strstr(cmdline, CONSOLE_ARG);
 
/* Allocate space for maximum possible new command line */
-   buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
+   buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_SIZE);
if (!buf) {
debug("%s: out of memory\n", __func__);
return -ENOSPC;
@@ -506,13 +506,14 @@ int bootm_process_cmdline_env(bool do_silent)
 
if (start) {
char *end = strchr(start, ' ');
-   int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
+   int start_bytes;
 
-   strncpy(buf, cmdline, num_start_bytes);
+   start_bytes = start - cmdline + CONSOLE_ARG_SIZE - 1;
+   strncpy(buf, cmdline, start_bytes);
if (end)
-   strcpy(buf + num_start_bytes, end);
+   strcpy(buf + start_bytes, end);
else
-   buf[num_start_bytes] = '\0';
+   buf[start_bytes] = '\0';
} else {
sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
}
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH v2] serial: pl01x: Add error value checking

2020-10-19 Thread Michal Simek
There also a need to check return values to make sure that clocks were
enabled and setup properly.

Signed-off-by: Michal Simek 
Reviewed-by: Simon Glass 
---

Changes in v2:
- Add missing header
- Add Simon's tag

 drivers/serial/serial_pl01x.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c
index 2772c25f1d2d..d9e35c6a2b47 100644
--- a/drivers/serial/serial_pl01x.c
+++ b/drivers/serial/serial_pl01x.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "serial_pl01x_internal.h"
@@ -362,8 +363,18 @@ int pl01x_serial_ofdata_to_platdata(struct udevice *dev)
plat->clock = dev_read_u32_default(dev, "clock", CONFIG_PL011_CLOCK);
ret = clk_get_by_index(dev, 0, );
if (!ret) {
-   clk_enable();
+   ret = clk_enable();
+   if (ret && ret != -ENOSYS) {
+   dev_err(dev, "failed to enable clock\n");
+   return ret;
+   }
+
plat->clock = clk_get_rate();
+   if (IS_ERR_VALUE(plat->clock)) {
+   dev_err(dev, "failed to get rate\n");
+   return plat->clock;
+   }
+   debug("%s: CLK %d\n", __func__, plat->clock);
}
plat->type = dev_get_driver_data(dev);
plat->skip_init = dev_read_bool(dev, "skip-init");
-- 
2.28.0



[PATCH v2] spi: zynq_spi: Use clk subsystem to get reference spi clk

2020-10-19 Thread Michal Simek
From: T Karthik Reddy 

Remove fixed reference clk used by plat->frequency and use clk
subsystem to get reference clk. As per spi dt bindings
"spi-max-frequency" property should be used by the slave devices.
This property is read by spi-uclass driver for the slave device.
So avoid reading above property from the platform driver.

Signed-off-by: T Karthik Reddy 
Signed-off-by: Michal Simek 
---

Changes in v2:
- Fix dev_err message first parameter and add missing header

 drivers/spi/zynq_spi.c | 35 ---
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/zynq_spi.c b/drivers/spi/zynq_spi.c
index 9923931e36ec..cb911c34f68d 100644
--- a/drivers/spi/zynq_spi.c
+++ b/drivers/spi/zynq_spi.c
@@ -8,10 +8,12 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -79,17 +81,10 @@ static int zynq_spi_ofdata_to_platdata(struct udevice *bus)
 
plat->regs = dev_read_addr_ptr(bus);
 
-   /* FIXME: Use 250MHz as a suitable default */
-   plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
-   25000);
plat->deactivate_delay_us = fdtdec_get_int(blob, node,
"spi-deactivate-delay", 0);
plat->activate_delay_us = fdtdec_get_int(blob, node,
 "spi-activate-delay", 0);
-   plat->speed_hz = plat->frequency / 2;
-
-   debug("%s: regs=%p max-frequency=%d\n", __func__,
- plat->regs, plat->frequency);
 
return 0;
 }
@@ -128,13 +123,39 @@ static int zynq_spi_probe(struct udevice *bus)
 {
struct zynq_spi_platdata *plat = dev_get_platdata(bus);
struct zynq_spi_priv *priv = dev_get_priv(bus);
+   struct clk clk;
+   unsigned long clock;
+   int ret;
 
priv->regs = plat->regs;
priv->fifo_depth = ZYNQ_SPI_FIFO_DEPTH;
 
+   ret = clk_get_by_name(bus, "ref_clk", );
+   if (ret < 0) {
+   dev_err(bus, "failed to get clock\n");
+   return ret;
+   }
+
+   clock = clk_get_rate();
+   if (IS_ERR_VALUE(clock)) {
+   dev_err(bus, "failed to get rate\n");
+   return clock;
+   }
+
+   ret = clk_enable();
+   if (ret && ret != -ENOSYS) {
+   dev_err(bus, "failed to enable clock\n");
+   return ret;
+   }
+
/* init the zynq spi hw */
zynq_spi_init_hw(priv);
 
+   plat->frequency = clock;
+   plat->speed_hz = plat->frequency / 2;
+
+   debug("%s: max-frequency=%d\n", __func__, plat->speed_hz);
+
return 0;
 }
 
-- 
2.28.0



[PATCH v2] spi: zynq_qspi: Use clk subsystem to get reference qspi clk

2020-10-19 Thread Michal Simek
From: T Karthik Reddy 

Remove fixed reference clk used by plat->frequency and use clk
subsystem to get reference clk. As per spi dt bindings
"spi-max-frequency" property should be used by the slave devices.
This property is read by spi-uclass driver for the slave device.
So avoid reading above property from the platform driver.

Signed-off-by: T Karthik Reddy 
Signed-off-by: Michal Simek 
---

Changes in v2:
- Fix dev_err message first parameter and add missing header

 drivers/spi/zynq_qspi.c | 36 
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/zynq_qspi.c b/drivers/spi/zynq_qspi.c
index 3f39ef05f2d6..4219a35c8406 100644
--- a/drivers/spi/zynq_qspi.c
+++ b/drivers/spi/zynq_qspi.c
@@ -6,8 +6,10 @@
  * Xilinx Zynq Quad-SPI(QSPI) controller driver (master mode only)
  */
 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -105,14 +107,6 @@ static int zynq_qspi_ofdata_to_platdata(struct udevice 
*bus)
plat->regs = (struct zynq_qspi_regs *)fdtdec_get_addr(blob,
  node, "reg");
 
-   /* FIXME: Use 166MHz as a suitable default */
-   plat->frequency = fdtdec_get_int(blob, node, "spi-max-frequency",
-   1);
-   plat->speed_hz = plat->frequency / 2;
-
-   debug("%s: regs=%p max-frequency=%d\n", __func__,
- plat->regs, plat->frequency);
-
return 0;
 }
 
@@ -159,13 +153,39 @@ static int zynq_qspi_probe(struct udevice *bus)
 {
struct zynq_qspi_platdata *plat = dev_get_platdata(bus);
struct zynq_qspi_priv *priv = dev_get_priv(bus);
+   struct clk clk;
+   unsigned long clock;
+   int ret;
 
priv->regs = plat->regs;
priv->fifo_depth = ZYNQ_QSPI_FIFO_DEPTH;
 
+   ret = clk_get_by_name(bus, "ref_clk", );
+   if (ret < 0) {
+   dev_err(bus, "failed to get clock\n");
+   return ret;
+   }
+
+   clock = clk_get_rate();
+   if (IS_ERR_VALUE(clock)) {
+   dev_err(bus, "failed to get rate\n");
+   return clock;
+   }
+
+   ret = clk_enable();
+   if (ret && ret != -ENOSYS) {
+   dev_err(bus, "failed to enable clock\n");
+   return ret;
+   }
+
/* init the zynq spi hw */
zynq_qspi_init_hw(priv);
 
+   plat->frequency = clock;
+   plat->speed_hz = plat->frequency / 2;
+
+   debug("%s: max-frequency=%d\n", __func__, plat->speed_hz);
+
return 0;
 }
 
-- 
2.28.0



Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Wolfgang Denk
Dear Simon,

In message <20201019135602.3943835-12-...@chromium.org> you wrote:
> In some cases it is necessary to pass parameters to Linux so that it will
> boot correctly. For example, the rootdev parameter is often used to
> specify the root device. However the root device may change depending on
> whence U-Boot loads the kernel. At present it is necessary to build up
> the command line by adding device strings to it one by one.
>
> It is often more convenient to provide a template for bootargs, with
> U-Boot doing the substitution from other environment variables.
>
> Add a way to substitute strings in the bootargs variable. This allows
> things like "rootdev=%U" to be used in bootargs, with the %U substitution
> providing the UUID of the root device.

Argh, no, please don't.

You add something unconditionally to common code which very few
people need.  U-Boot size is growing all the time because of such
... features.  This may be acceptable on the systems you have in
mind, but I consider this selfish.

Why do we have to add yet another non-standard way of substituting
variables in a string?  Can we not use alreay existing methonds
instead?

Why do you have to use "%U" in your template instead of for example
"${uuid}" ?



Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
If you use modules, you pay the price. Sane embedded solutions
running in "tight" environments don't use modules :-)
-- Benjamin Herrenschmidt in <1258234866.2140.451.camel@pasglop>


Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Simon Glass
Hi Rasmus,

On Mon, 19 Oct 2020 at 08:43, Rasmus Villemoes
 wrote:
>
> On 19/10/2020 15.56, Simon Glass wrote:
> > In some cases it is necessary to pass parameters to Linux so that it will
> > boot correctly. For example, the rootdev parameter is often used to
> > specify the root device. However the root device may change depending on
> > whence U-Boot loads the kernel. At present it is necessary to build up
> > the command line by adding device strings to it one by one.
> >
> > It is often more convenient to provide a template for bootargs, with
> > U-Boot doing the substitution from other environment variables.
> >
> > Add a way to substitute strings in the bootargs variable. This allows
> > things like "rootdev=%U" to be used in bootargs, with the %U substitution
> > providing the UUID of the root device.
> >
> > For example, to substitute the GUID of the kernel partition:
> >
> >   setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U"
> >   part uuid mmc 2:2 uuid
> >   setenv bootargs_U $uuid
> >   bootm
> >
> > This is particularly useful when the command line from another place. For
> > example, Chrome OS stores the command line next to the kernel itself. It
> > depends on the kernel version being used as well as the hardware features,
> > so it is extremely difficult to devise a U-Boot script that works on all
> > boards and kernel versions. With this feature, the command line can be
> > read from disk and used directly, with a few substitutions set up.
> >
> > Signed-off-by: Simon Glass 
> > ---
> >
> >  README  |  16 +++
> >  arch/Kconfig|   1 +
> >  common/Kconfig.boot |  20 
> >  common/bootm.c  |  72 +++--
> >  include/bootm.h |  14 --
> >  test/bootm.c| 110 ++--
> >  6 files changed, 221 insertions(+), 12 deletions(-)
> >
> > diff --git a/README b/README
> > index 91c5a1a8fa3..263e31ab7f6 100644
> > --- a/README
> > +++ b/README
> > @@ -3229,6 +3229,22 @@ List of environment variables (most likely not 
> > complete):
> >
> >bootargs   - Boot arguments when booting an RTOS image
> >
> > +  bootargs_subst - Substitution parameters for bootargs. These are applied 
> > after
> > +   the commandline has been built. The format is:
> > +
> > + =[!=...]
> > +
> > +   where
> > +  is a string to replace
> > +  is the value to replace it with (either a simple
> > +string or an environment variable starting with $
> > +
> > +   One use for this is to insert the root-disk UUID into the
> > +   command line where bootargs contains "root=%U"
> > +
> > + part uuid mmc 2:2 uuid
> > + setenv cmdline_repl %U=$uuid
>
> cmdline_repl seems to be stale, it should be bootargs_subst. But the
> whole paragraph seems stale, as you actually implement and test the
> bootargs_X approach.

Yes, thanks, will fix.

>
> Anyway, this does seem useful, but I really question the choice of
> leaving %A in there if bootargs_A does not exist. It's hard if not
> impossible to create an environment variable whose value is empty, and I
> can easily imagine it would be useful to allow a %A to expand to
> nothing. So why not just use the usual semantics of requiring a double
> %% to put a single % in the output? It's probably quite rare that one
> would need that anyway.

I did wonder about the empty env var thing. IMO it would be nice to
support empty variables, so we can distinguish between an empty one
and a missing one.

My concern with removing the var is if people have % in the string.
This way I don't have to worry about quoting, etc. See Wolgang's email
in this thread too.

Regards,
Simon


Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Rasmus Villemoes
On 19/10/2020 15.56, Simon Glass wrote:
> In some cases it is necessary to pass parameters to Linux so that it will
> boot correctly. For example, the rootdev parameter is often used to
> specify the root device. However the root device may change depending on
> whence U-Boot loads the kernel. At present it is necessary to build up
> the command line by adding device strings to it one by one.
> 
> It is often more convenient to provide a template for bootargs, with
> U-Boot doing the substitution from other environment variables.
> 
> Add a way to substitute strings in the bootargs variable. This allows
> things like "rootdev=%U" to be used in bootargs, with the %U substitution
> providing the UUID of the root device.
> 
> For example, to substitute the GUID of the kernel partition:
> 
>   setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U"
>   part uuid mmc 2:2 uuid
>   setenv bootargs_U $uuid
>   bootm
> 
> This is particularly useful when the command line from another place. For
> example, Chrome OS stores the command line next to the kernel itself. It
> depends on the kernel version being used as well as the hardware features,
> so it is extremely difficult to devise a U-Boot script that works on all
> boards and kernel versions. With this feature, the command line can be
> read from disk and used directly, with a few substitutions set up.
> 
> Signed-off-by: Simon Glass 
> ---
> 
>  README  |  16 +++
>  arch/Kconfig|   1 +
>  common/Kconfig.boot |  20 
>  common/bootm.c  |  72 +++--
>  include/bootm.h |  14 --
>  test/bootm.c| 110 ++--
>  6 files changed, 221 insertions(+), 12 deletions(-)
> 
> diff --git a/README b/README
> index 91c5a1a8fa3..263e31ab7f6 100644
> --- a/README
> +++ b/README
> @@ -3229,6 +3229,22 @@ List of environment variables (most likely not 
> complete):
>  
>bootargs   - Boot arguments when booting an RTOS image
>  
> +  bootargs_subst - Substitution parameters for bootargs. These are applied 
> after
> +   the commandline has been built. The format is:
> +
> + =[!=...]
> +
> +   where
> +  is a string to replace
> +  is the value to replace it with (either a simple
> +string or an environment variable starting with $
> +
> +   One use for this is to insert the root-disk UUID into the
> +   command line where bootargs contains "root=%U"
> +
> + part uuid mmc 2:2 uuid
> + setenv cmdline_repl %U=$uuid

cmdline_repl seems to be stale, it should be bootargs_subst. But the
whole paragraph seems stale, as you actually implement and test the
bootargs_X approach.

Anyway, this does seem useful, but I really question the choice of
leaving %A in there if bootargs_A does not exist. It's hard if not
impossible to create an environment variable whose value is empty, and I
can easily imagine it would be useful to allow a %A to expand to
nothing. So why not just use the usual semantics of requiring a double
%% to put a single % in the output? It's probably quite rare that one
would need that anyway.

Rasmus


Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Simon Glass
Hi Wolfgang,

On Mon, 19 Oct 2020 at 08:55, Wolfgang Denk  wrote:
>
> Dear Simon,
>
> In message <20201019135602.3943835-12-...@chromium.org> you wrote:
> > In some cases it is necessary to pass parameters to Linux so that it will
> > boot correctly. For example, the rootdev parameter is often used to
> > specify the root device. However the root device may change depending on
> > whence U-Boot loads the kernel. At present it is necessary to build up
> > the command line by adding device strings to it one by one.
> >
> > It is often more convenient to provide a template for bootargs, with
> > U-Boot doing the substitution from other environment variables.
> >
> > Add a way to substitute strings in the bootargs variable. This allows
> > things like "rootdev=%U" to be used in bootargs, with the %U substitution
> > providing the UUID of the root device.
>
> Argh, no, please don't.
>
> You add something unconditionally to common code which very few
> people need.  U-Boot size is growing all the time because of such
> ... features.  This may be acceptable on the systems you have in
> mind, but I consider this selfish.

Did you see the Kconfig option?

>
> Why do we have to add yet another non-standard way of substituting
> variables in a string?  Can we not use alreay existing methonds
> instead?

What sort of methods?

>
> Why do you have to use "%U" in your template instead of for example
> "${uuid}" ?

This is what Chrome OS uses, so it is easier this way, Otherwise I
have to replace %U with ${uuid} first.

Which code can I use to parse the ${var} thing?

Regards,
Simon


Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Simon Glass
Hi Michael,

On Mon, 19 Oct 2020 at 09:47, Michael Walle  wrote:
>
> Am 2020-10-19 16:54, schrieb Wolfgang Denk:
> > Dear Simon,
> >
> > In message <20201019135602.3943835-12-...@chromium.org> you wrote:
> >> In some cases it is necessary to pass parameters to Linux so that it
> >> will
> >> boot correctly. For example, the rootdev parameter is often used to
> >> specify the root device. However the root device may change depending
> >> on
> >> whence U-Boot loads the kernel. At present it is necessary to build up
> >> the command line by adding device strings to it one by one.
> >>
> >> It is often more convenient to provide a template for bootargs, with
> >> U-Boot doing the substitution from other environment variables.
> >>
> >> Add a way to substitute strings in the bootargs variable. This allows
> >> things like "rootdev=%U" to be used in bootargs, with the %U
> >> substitution
> >> providing the UUID of the root device.
> >
> > Argh, no, please don't.
> >
> > You add something unconditionally to common code which very few
> > people need.  U-Boot size is growing all the time because of such
> > ... features.  This may be acceptable on the systems you have in
> > mind, but I consider this selfish.
> >
> > Why do we have to add yet another non-standard way of substituting
> > variables in a string?  Can we not use alreay existing methonds
> > instead?
> >
> > Why do you have to use "%U" in your template instead of for example
> > "${uuid}" ?
>
> I'd second that. Having variables evaluated inside the bootargs would
> be very valuable IMHO.
>
> At the moment we have some cumbersome constructs like
>set_bootargs="setenv bootargs bla ${var}"

Yes it is a real pain. The substitution happens on first parse two, so
you have to put these commands in separate variables if you are
building things up.

Another thing to mention is that years ago I sent a series to help
with that last bit, i.e. make variables evaluate recursively. I'm
trying to remember what happened to it.

Regards,
Simon


Re: [PATCH 07/11] bootm: Split out bootargs environment reading / writing

2020-10-19 Thread Wolfgang Denk
Dear Simon,

In message <20201019135602.3943835-8-...@chromium.org> you wrote:
...
>
> It is also useful for zimage to use a buffer, since it does not actually
> put the Linux command line in the bootargs variable.

...which I consider a bug that should be fixed.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
A good marriage would be between a blind wife and deaf husband.
   -- Michel de Montaigne


Re: [PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Michael Walle

Am 2020-10-19 16:54, schrieb Wolfgang Denk:

Dear Simon,

In message <20201019135602.3943835-12-...@chromium.org> you wrote:
In some cases it is necessary to pass parameters to Linux so that it 
will

boot correctly. For example, the rootdev parameter is often used to
specify the root device. However the root device may change depending 
on

whence U-Boot loads the kernel. At present it is necessary to build up
the command line by adding device strings to it one by one.

It is often more convenient to provide a template for bootargs, with
U-Boot doing the substitution from other environment variables.

Add a way to substitute strings in the bootargs variable. This allows
things like "rootdev=%U" to be used in bootargs, with the %U 
substitution

providing the UUID of the root device.


Argh, no, please don't.

You add something unconditionally to common code which very few
people need.  U-Boot size is growing all the time because of such
... features.  This may be acceptable on the systems you have in
mind, but I consider this selfish.

Why do we have to add yet another non-standard way of substituting
variables in a string?  Can we not use alreay existing methonds
instead?

Why do you have to use "%U" in your template instead of for example
"${uuid}" ?


I'd second that. Having variables evaluated inside the bootargs would
be very valuable IMHO.

At the moment we have some cumbersome constructs like
  set_bootargs="setenv bootargs bla ${var}"

-michael


[PATCH 01/11] env: Allow returning errors from hdelete_r()

2020-10-19 Thread Simon Glass
At present this function returns 1 on success and 0 on failure. But in
the latter case it provides no indication of what went wrong.

If an attempt is made to delete a non-existent variable, the caller may
want to ignore this error. This happens when setting a non-existent
variable to "", for example.

Update the function to return 0 on success and a useful error code on
failure. Add a function comment too.

Make sure that env_set() does not return an error if it is deleting a
variable that doesn't exist. We could update env_set() to return useful
error numbers also, but that is beyond the scope of this change.

Signed-off-by: Simon Glass 

wip

---

 cmd/nvedit.c |  6 --
 include/search.h | 11 ++-
 lib/hashtable.c  | 12 ++--
 test/env/hashtable.c |  2 +-
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 7fce723800d..d0d2eca9047 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -266,7 +266,9 @@ static int _do_env_set(int flag, int argc, char *const 
argv[], int env_flag)
/* Delete only ? */
if (argc < 3 || argv[2] == NULL) {
int rc = hdelete_r(name, _htab, env_flag);
-   return !rc;
+
+   /* If the variable didn't exist, don't report an error */
+   return rc && rc != -ENOENT ? 1 : 0;
}
 
/*
@@ -895,7 +897,7 @@ static int do_env_delete(struct cmd_tbl *cmdtp, int flag,
while (--argc > 0) {
char *name = *++argv;
 
-   if (!hdelete_r(name, _htab, env_flag))
+   if (hdelete_r(name, _htab, env_flag))
ret = 1;
}
 
diff --git a/include/search.h b/include/search.h
index e56843c26fd..d0bb44388e1 100644
--- a/include/search.h
+++ b/include/search.h
@@ -80,7 +80,16 @@ int hsearch_r(struct env_entry item, enum env_action action,
 int hmatch_r(const char *match, int last_idx, struct env_entry **retval,
 struct hsearch_data *htab);
 
-/* Search and delete entry matching "key" in internal hash table. */
+/**
+ * hdelete_r() - Search and delete entry in internal hash table
+ *
+ * @key: Name of entry to delete
+ * @htab: Hash table
+ * @flag: Flags to use (H_...)
+ * @return 0 on success, -ENOENT if not found, -EPERM if the hash table 
callback
+ * rejected changing the variable, -EINVAL if the hash table refused to
+ * delete the variable
+ */
 int hdelete_r(const char *key, struct hsearch_data *htab, int flag);
 
 ssize_t hexport_r(struct hsearch_data *htab, const char sep, int flag,
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 7c08f5c8055..ff5ff726394 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -472,7 +472,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab, 
int flag)
idx = hsearch_r(e, ENV_FIND, , htab, 0);
if (idx == 0) {
__set_errno(ESRCH);
-   return 0;   /* not found */
+   return -ENOENT; /* not found */
}
 
/* Check for permission */
@@ -481,7 +481,7 @@ int hdelete_r(const char *key, struct hsearch_data *htab, 
int flag)
debug("change_ok() rejected deleting variable "
"%s, skipping it!\n", key);
__set_errno(EPERM);
-   return 0;
+   return -EPERM;
}
 
/* If there is a callback, call it */
@@ -490,12 +490,12 @@ int hdelete_r(const char *key, struct hsearch_data *htab, 
int flag)
debug("callback() rejected deleting variable "
"%s, skipping it!\n", key);
__set_errno(EINVAL);
-   return 0;
+   return -EINVAL;
}
 
_hdelete(key, htab, ep, idx);
 
-   return 1;
+   return 0;
 }
 
 #if !(defined(CONFIG_SPL_BUILD) && !defined(CONFIG_SPL_SAVEENV))
@@ -917,7 +917,7 @@ int himport_r(struct hsearch_data *htab,
if (!drop_var_from_set(name, nvars, localvars))
continue;
 
-   if (hdelete_r(name, htab, flag) == 0)
+   if (hdelete_r(name, htab, flag))
debug("DELETE ERROR 
##\n");
 
continue;
@@ -979,7 +979,7 @@ int himport_r(struct hsearch_data *htab,
 * b) if the variable was not present in current env, we notify
 *it might be a typo
 */
-   if (hdelete_r(localvars[i], htab, flag) == 0)
+   if (hdelete_r(localvars[i], htab, flag))
printf("WARNING: '%s' neither in running nor in 
imported env!\n", localvars[i]);
else
printf("WARNING: '%s' not in imported env, deleting 
it!\n", localvars[i]);
diff --git a/test/env/hashtable.c b/test/env/hashtable.c
index 339cc19ba14..70102f9121c 100644
--- a/test/env/hashtable.c
+++ b/test/env/hashtable.c
@@ -80,7 +80,7 

[PATCH 02/11] bootm: Add tests for fixup_silent_linux()

2020-10-19 Thread Simon Glass
This function currently has no tests. Export it so that we can implement
a simple test on sandbox. Use IS_ENABLED() to remove the unused code,
instead #ifdef.

Signed-off-by: Simon Glass 
---

 arch/Kconfig  |  1 +
 common/bootm.c| 14 +-
 include/bootm.h   |  3 +++
 include/test/suites.h |  1 +
 test/Makefile |  1 +
 test/bootm.c  | 59 +++
 test/cmd_ut.c |  1 +
 7 files changed, 73 insertions(+), 7 deletions(-)
 create mode 100644 test/bootm.c

diff --git a/arch/Kconfig b/arch/Kconfig
index 683e3843190..6caf2338bcf 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -140,6 +140,7 @@ config SANDBOX
imply ACPI_PMC_SANDBOX
imply CMD_PMC
imply CMD_CLONE
+   imply SILENT_CONSOLE
 
 config SH
bool "SuperH architecture"
diff --git a/common/bootm.c b/common/bootm.c
index b3377490b3e..8e1e5337036 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -463,18 +463,21 @@ ulong bootm_disable_interrupts(void)
return iflag;
 }
 
-#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
-
 #define CONSOLE_ARG "console="
 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
 
-static void fixup_silent_linux(void)
+void fixup_silent_linux(void)
 {
char *buf;
const char *env_val;
-   char *cmdline = env_get("bootargs");
+   char *cmdline;
int want_silent;
 
+   if (!IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
+   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY))
+   return;
+   cmdline = env_get("bootargs");
+
/*
 * Only fix cmdline when requested. The environment variable can be:
 *
@@ -521,7 +524,6 @@ static void fixup_silent_linux(void)
debug("after silent fix-up: %s\n", env_val);
free(buf);
 }
-#endif /* CONFIG_SILENT_CONSOLE */
 
 /**
  * Execute selected states of the bootm command.
@@ -625,10 +627,8 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
if (!ret && (states & BOOTM_STATE_OS_BD_T))
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) {
-#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
if (images->os.os == IH_OS_LINUX)
fixup_silent_linux();
-#endif
ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
}
 
diff --git a/include/bootm.h b/include/bootm.h
index a812a6bf24f..6d675e64559 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -85,4 +85,7 @@ void arch_preboot_os(void);
  */
 void board_preboot_os(void);
 
+/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */
+void fixup_silent_linux(void);
+
 #endif
diff --git a/include/test/suites.h b/include/test/suites.h
index ab7b3bd9cad..c1d8fa9a650 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -26,6 +26,7 @@ int cmd_ut_category(const char *name, const char *prefix,
struct unit_test *tests, int n_ents,
int argc, char *const argv[]);
 
+int do_ut_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_bloblist(struct cmd_tbl *cmdtp, int flag, int argc,
   char *const argv[]);
 int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc,
diff --git a/test/Makefile b/test/Makefile
index 7c4039964e1..099f855aefe 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -3,6 +3,7 @@
 # (C) Copyright 2012 The Chromium Authors
 
 obj-$(CONFIG_SANDBOX) += bloblist.o
+obj-$(CONFIG_SANDBOX) += bootm.o
 obj-$(CONFIG_CMDLINE) += cmd/
 obj-$(CONFIG_UNIT_TEST) += cmd_ut.o
 obj-$(CONFIG_UNIT_TEST) += ut.o
diff --git a/test/bootm.c b/test/bootm.c
new file mode 100644
index 000..59d16cb3df6
--- /dev/null
+++ b/test/bootm.c
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for bootm routines
+ *
+ * Copyright 2020 Google LLC
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define BOOTM_TEST(_name, _flags)  UNIT_TEST(_name, _flags, bootm_test)
+
+#define CONSOLE_STR"console=/dev/ttyS0"
+
+/* Test silent processing in the bootargs variable */
+static int bootm_test_silent_var(struct unit_test_state *uts)
+{
+   /* 'silent_linux' not set should do nothing */
+   env_set("silent_linux", NULL);
+   env_set("bootargs", CONSOLE_STR);
+   fixup_silent_linux();
+   ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
+
+   env_set("bootargs", NULL);
+   fixup_silent_linux();
+   ut_assertnull(env_get("bootargs"));
+
+   ut_assertok(env_set("silent_linux", "no"));
+   env_set("bootargs", CONSOLE_STR);
+   fixup_silent_linux();
+   ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
+
+   ut_assertok(env_set("silent_linux", "yes"));
+   env_set("bootargs", CONSOLE_STR);
+   fixup_silent_linux();
+   

Re: [PATCH 00/11] bootm: Support substitions in bootargs and add tests

2020-10-19 Thread Heinrich Schuchardt
On 19.10.20 15:55, Simon Glass wrote:
> This series adds tests to the fixup_silent-linux() function and extends
> the 'zimage' command to use it.
>
> It also adds a new string-substition feature to allow bootargs to be a
> template, rather than having to build it up piece by piece with
> information obtained in a build script.
>
> It also updates zimage to use the same command-line processing.
>
> With these additions it is possible to boot Chrome OS from a U-Boot script
> on most Chromebooks.

Hello Simon,

could you, please, add a patch documenting the usage of the new
string-substitution feature in the HTML documentation.

Best regards

Heinrich

>
>
> Simon Glass (11):
>   env: Allow returning errors from hdelete_r()
>   bootm: Add tests for fixup_silent_linux()
>   bootm: Update fixup_silent_linux() to return an error
>   bootm: Rename fixup_silent_linux()
>   bootm: Add a bool parameter to bootm_process_cmdline_env()
>   bootm: Use size rather than length for CONSOLE_ARG
>   bootm: Split out bootargs environment reading / writing
>   bootm: Update bootm_process_cmdline_env() to use flags
>   bootm: Allow updating the bootargs in a buffer
>   x86: zimage: Add silent-console processing
>   bootm: Support string substitution in bootargs
>
>  README|  16 +++
>  arch/Kconfig  |   2 +
>  arch/x86/lib/zimage.c |  14 +++
>  cmd/nvedit.c  |   6 +-
>  common/Kconfig.boot   |  20 
>  common/bootm.c| 206 +--
>  include/bootm.h   |  40 +++
>  include/search.h  |  11 +-
>  include/test/suites.h |   1 +
>  lib/hashtable.c   |  12 +--
>  test/Makefile |   1 +
>  test/bootm.c  | 243 ++
>  test/cmd_ut.c |   1 +
>  test/env/hashtable.c  |   2 +-
>  14 files changed, 534 insertions(+), 41 deletions(-)
>  create mode 100644 test/bootm.c
>



Re: [PATCH] arm: sunxi: disable obsolete VIDEO config

2020-10-19 Thread Tom Rini
On Mon, Oct 19, 2020 at 11:17:54AM +0200, Maxime Ripard wrote:
> On Sun, Oct 18, 2020 at 09:18:15PM +0200, Anatolij Gustschin wrote:
> > DM_VIDEO conversion deadline has passed, disable VIDEO config
> > option by default. Boards should convert to DM_VIDEO if they
> > need video console support.
> > 
> > Signed-off-by: Anatolij Gustschin 
> > Cc: Jagan Teki 
> > Cc: Maxime Ripard 
> > ---
> >  arch/arm/mach-sunxi/Kconfig | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig
> > index be0822bfb7..f672bb8b4e 100644
> > --- a/arch/arm/mach-sunxi/Kconfig
> > +++ b/arch/arm/mach-sunxi/Kconfig
> > @@ -760,7 +760,7 @@ config VIDEO_SUNXI
> > depends on !MACH_SUN50I_H6
> > select VIDEO
> > imply VIDEO_DT_SIMPLEFB
> > -   default y
> > +   default n
> 
> default n is the default with Kconfig iirc
> 
> Otherwise, I can't say that I agree with the forced conversion strategy
> to the DM in general. We're struggling to keep U-Boot working from one
> release to the other, so adding pressure to convert drivers feels a bit
> too much.
> 
> I can see where you're coming from though, so I guess that's a
> reluctantly-acked-by ? :)

Can you please elaborate on your struggles?  The only thing right now
keeping me from having some sunxi target in my HW CI loop is I didn't
have anything that wasn't leaking in power via UART, even, seemingly.
Thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH 03/11] bootm: Update fixup_silent_linux() to return an error

2020-10-19 Thread Simon Glass
At present this function fails silently on error. Update it to produce
an error code. Report this error to the user and abort the boot, since it
likely will prevent a successful start.

No tests are added at this stage, since additional refactoring is taking
place in subsequent patches.

Signed-off-by: Simon Glass 
---

 common/bootm.c  | 22 +++---
 include/bootm.h | 11 +--
 test/bootm.c| 10 +-
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 8e1e5337036..0ca66188c2b 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -466,7 +466,7 @@ ulong bootm_disable_interrupts(void)
 #define CONSOLE_ARG "console="
 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
 
-void fixup_silent_linux(void)
+int fixup_silent_linux(void)
 {
char *buf;
const char *env_val;
@@ -475,7 +475,7 @@ void fixup_silent_linux(void)
 
if (!IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
!IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY))
-   return;
+   return 0;
cmdline = env_get("bootargs");
 
/*
@@ -487,9 +487,9 @@ void fixup_silent_linux(void)
 */
want_silent = env_get_yesno("silent_linux");
if (want_silent == 0)
-   return;
+   return 0;
else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
-   return;
+   return 0;
 
debug("before silent fix-up: %s\n", cmdline);
if (cmdline && (cmdline[0] != '\0')) {
@@ -499,7 +499,7 @@ void fixup_silent_linux(void)
buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
if (!buf) {
debug("%s: out of memory\n", __func__);
-   return;
+   return -ENOSPC;
}
 
if (start) {
@@ -523,6 +523,8 @@ void fixup_silent_linux(void)
env_set("bootargs", env_val);
debug("after silent fix-up: %s\n", env_val);
free(buf);
+
+   return 0;
 }
 
 /**
@@ -627,8 +629,14 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
if (!ret && (states & BOOTM_STATE_OS_BD_T))
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) {
-   if (images->os.os == IH_OS_LINUX)
-   fixup_silent_linux();
+   if (images->os.os == IH_OS_LINUX) {
+   ret = fixup_silent_linux();
+   if (ret) {
+   printf("Cmdline setup failed (err=%d)\n", ret);
+   ret = CMD_RET_FAILURE;
+   goto err;
+   }
+   }
ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
}
 
diff --git a/include/bootm.h b/include/bootm.h
index 6d675e64559..438829af0fe 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -85,7 +85,14 @@ void arch_preboot_os(void);
  */
 void board_preboot_os(void);
 
-/* Adjust the 'bootargs' to ensure that Linux boots silently, if required */
-void fixup_silent_linux(void);
+/*
+ * fixup_silent_linux() - Process fix-ups for the command line
+ *
+ * Updates the 'bootargs' envvar as required. This handles making Linux boot
+ * silently if requested ('silent_linux' envvar)
+ *
+ * @return 0 if OK, -ENOMEM if out of memory
+ */
+int fixup_silent_linux(void);
 
 #endif
diff --git a/test/bootm.c b/test/bootm.c
index 59d16cb3df6..ab1711609ba 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state 
*uts)
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
env_set("bootargs", CONSOLE_STR);
-   fixup_silent_linux();
+   ut_assertok(fixup_silent_linux());
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
env_set("bootargs", NULL);
-   fixup_silent_linux();
+   ut_assertok(fixup_silent_linux());
ut_assertnull(env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "no"));
env_set("bootargs", CONSOLE_STR);
-   fixup_silent_linux();
+   ut_assertok(fixup_silent_linux());
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "yes"));
env_set("bootargs", CONSOLE_STR);
-   fixup_silent_linux();
+   ut_assertok(fixup_silent_linux());
ut_asserteq_str("console=", env_get("bootargs"));
 
/* Empty buffer should still add the string */
env_set("bootargs", NULL);
-   fixup_silent_linux();
+   ut_assertok(fixup_silent_linux());
ut_asserteq_str("console=", env_get("bootargs"));
 
return 0;
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH 08/11] bootm: Update bootm_process_cmdline_env() to use flags

2020-10-19 Thread Simon Glass
At present only one transformation is supported: making the Linux console
silent. To prepare for adding more, convert the boolean parameter into a
flag value.

Signed-off-by: Simon Glass 
---

 common/bootm.c  |  8 +---
 include/bootm.h | 11 +--
 test/bootm.c| 10 +-
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 41965fa304c..5a5b79c5cd0 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -540,16 +540,17 @@ static int fixup_silent_linux(char *buf, int maxlen)
return 0;
 }
 
-int bootm_process_cmdline_env(bool do_silent)
+int bootm_process_cmdline_env(int flags)
 {
const int maxlen = MAX_CMDLINE_SIZE;
+   bool do_silent;
const char *env;
char *buf;
int ret;
 
/* First check if any action is needed */
do_silent = IS_ENABLED(CONFIG_SILENT_CONSOLE) &&
-   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && do_silent;
+   !IS_ENABLED(CONFIG_SILENT_U_BOOT_ONLY) && (flags & BOOTM_CL_SILENT);
if (!do_silent)
return 0;
 
@@ -683,7 +684,8 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int 
argc,
if (!ret && (states & BOOTM_STATE_OS_BD_T))
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) {
-   ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX);
+   ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX ?
+   BOOTM_CL_SILENT : 0);
if (ret) {
printf("Cmdline setup failed (err=%d)\n", ret);
ret = CMD_RET_FAILURE;
diff --git a/include/bootm.h b/include/bootm.h
index f12ee2b3cb3..4876d7b2882 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -75,6 +75,13 @@ void board_quiesce_devices(void);
  */
 void switch_to_non_secure_mode(void);
 
+/* Flags to control bootm_process_cmdline() */
+enum bootm_cmdline_t {
+   BOOTM_CL_SILENT = 1 << 0,   /* Do silent console processing */
+
+   BOOTM_CL_ALL= 1,/* All substitutions */
+};
+
 /**
  * arch_preboot_os() - arch specific configuration before booting
  */
@@ -91,9 +98,9 @@ void board_preboot_os(void);
  * Updates the 'bootargs' envvar as required. This handles making Linux boot
  * silently if requested ('silent_linux' envvar)
  *
- * @do_silent: Process bootargs for silent console
+ * @flags: Flags to control what happens (see bootm_cmdline_t)
  * @return 0 if OK, -ENOMEM if out of memory
  */
-int bootm_process_cmdline_env(bool do_silent);
+int bootm_process_cmdline_env(int flags);
 
 #endif
diff --git a/test/bootm.c b/test/bootm.c
index c203f0acd60..ba08920bb17 100644
--- a/test/bootm.c
+++ b/test/bootm.c
@@ -23,26 +23,26 @@ static int bootm_test_silent_var(struct unit_test_state 
*uts)
/* 'silent_linux' not set should do nothing */
env_set("silent_linux", NULL);
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env(true));
+   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
env_set("bootargs", NULL);
-   ut_assertok(bootm_process_cmdline_env(true));
+   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_assertnull(env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "no"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env(true));
+   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str(CONSOLE_STR, env_get("bootargs"));
 
ut_assertok(env_set("silent_linux", "yes"));
env_set("bootargs", CONSOLE_STR);
-   ut_assertok(bootm_process_cmdline_env(true));
+   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str("console=", env_get("bootargs"));
 
/* Empty buffer should still add the string */
env_set("bootargs", NULL);
-   ut_assertok(bootm_process_cmdline_env(true));
+   ut_assertok(bootm_process_cmdline_env(BOOTM_CL_SILENT));
ut_asserteq_str("console=", env_get("bootargs"));
 
return 0;
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH 11/11] bootm: Support string substitution in bootargs

2020-10-19 Thread Simon Glass
In some cases it is necessary to pass parameters to Linux so that it will
boot correctly. For example, the rootdev parameter is often used to
specify the root device. However the root device may change depending on
whence U-Boot loads the kernel. At present it is necessary to build up
the command line by adding device strings to it one by one.

It is often more convenient to provide a template for bootargs, with
U-Boot doing the substitution from other environment variables.

Add a way to substitute strings in the bootargs variable. This allows
things like "rootdev=%U" to be used in bootargs, with the %U substitution
providing the UUID of the root device.

For example, to substitute the GUID of the kernel partition:

  setenv bootargs "console=/dev/ttyS0 rootdev=%U/PARTNROFF=1 kern_guid=%U"
  part uuid mmc 2:2 uuid
  setenv bootargs_U $uuid
  bootm

This is particularly useful when the command line from another place. For
example, Chrome OS stores the command line next to the kernel itself. It
depends on the kernel version being used as well as the hardware features,
so it is extremely difficult to devise a U-Boot script that works on all
boards and kernel versions. With this feature, the command line can be
read from disk and used directly, with a few substitutions set up.

Signed-off-by: Simon Glass 
---

 README  |  16 +++
 arch/Kconfig|   1 +
 common/Kconfig.boot |  20 
 common/bootm.c  |  72 +++--
 include/bootm.h |  14 --
 test/bootm.c| 110 ++--
 6 files changed, 221 insertions(+), 12 deletions(-)

diff --git a/README b/README
index 91c5a1a8fa3..263e31ab7f6 100644
--- a/README
+++ b/README
@@ -3229,6 +3229,22 @@ List of environment variables (most likely not complete):
 
   bootargs - Boot arguments when booting an RTOS image
 
+  bootargs_subst - Substitution parameters for bootargs. These are applied 
after
+ the commandline has been built. The format is:
+
+   =[!=...]
+
+ where
+is a string to replace
+is the value to replace it with (either a simple
+  string or an environment variable starting with $
+
+ One use for this is to insert the root-disk UUID into the
+ command line where bootargs contains "root=%U"
+
+   part uuid mmc 2:2 uuid
+   setenv cmdline_repl %U=$uuid
+
   bootfile - Name of the image to load with TFTP
 
   bootm_low- Memory range available for image processing in the bootm
diff --git a/arch/Kconfig b/arch/Kconfig
index 6caf2338bcf..421ea9a9b51 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -141,6 +141,7 @@ config SANDBOX
imply CMD_PMC
imply CMD_CLONE
imply SILENT_CONSOLE
+   imply BOOTARGS_SUBST
 
 config SH
bool "SuperH architecture"
diff --git a/common/Kconfig.boot b/common/Kconfig.boot
index 4191bfb34df..c5668cf2931 100644
--- a/common/Kconfig.boot
+++ b/common/Kconfig.boot
@@ -848,6 +848,26 @@ config BOOTARGS
  CONFIG_BOOTARGS goes into the environment value "bootargs". Note that
  this value will also override the "chosen" node in FDT blob.
 
+config BOOTARGS_SUBST
+   bool "Support substituting strings in boot arguments"
+   help
+ This allows substituting string values in the boot arguments. These
+ are applied after the commandline has been built. Set the
+ 'bootargs_subst' envvar to control this. The format is:
+
+   =[!=...]
+
+ where
+is a string to replace
+is the value to replace it with (either a simple
+  string or an environment variable starting with $
+
+ One use for this is to insert the root-disk UUID into the
+ command line where bootargs contains "root=%U"
+
+   part uuid mmc 2:2 uuid
+   setenv cmdline_repl %U=$uuid
+
 config USE_BOOTCOMMAND
bool "Enable a default value for bootcmd"
help
diff --git a/common/bootm.c b/common/bootm.c
index 5484c2be900..0a89a72a660 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -540,6 +540,68 @@ static int fixup_silent_linux(char *buf, int maxlen)
return 0;
 }
 
+/**
+ * process_subst() - Handle substitution of %x fields in the environment
+ *
+ * For every "%x" found, it is replaced with the value of envvar "bootargs_x"
+ * where x is a case-sensitive alphanumeric character. If that environment
+ * variable does not exist, no substitution is made and the %x remains, to
+ * allow for plain % characters in the string.
+ *
+ * @buf: Buffer containing the string to process
+ * @maxlen: Maximum length of buffer
+ * @return 0 if OK, -ENOSPC if @maxlen is too small
+ */
+static int process_subst(char *buf, int maxlen)
+{
+   const char *in;
+   char *cmdline, 

[PATCH 10/11] x86: zimage: Add silent-console processing

2020-10-19 Thread Simon Glass
At present zimage does its own command-line processing and does not
support the 'silent console' feature. There doesn't seem to be any good
reason for this.

Add support for silent console to zimage.

Signed-off-by: Simon Glass 
---

 arch/x86/lib/zimage.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index a00964cc8d9..8e1e8017bd8 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -13,6 +13,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -317,6 +318,11 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
}
 
if (cmd_line) {
+   int max_size = 0xff;
+   int ret;
+
+   if (bootproto >= 0x0206)
+   max_size = hdr->cmdline_size;
if (bootproto >= 0x0202) {
hdr->cmd_line_ptr = (uintptr_t)cmd_line;
} else if (bootproto >= 0x0200) {
@@ -332,6 +338,14 @@ int setup_zimage(struct boot_params *setup_base, char 
*cmd_line, int auto_boot,
strcpy(cmd_line, (char *)cmdline_force);
else
build_command_line(cmd_line, auto_boot);
+   ret = bootm_process_cmdline(cmd_line, max_size, BOOTM_CL_ALL);
+   if (ret) {
+   printf("Cmdline setup failed (err=%d)\n", ret);
+   return ret;
+   }
+   printf("Kernel command line: \"");
+   puts(cmd_line);
+   printf("\"\n");
}
 
if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
-- 
2.29.0.rc1.297.gfa9743e501-goog



[PATCH] mx6: peripheral clock from oscillator

2020-10-19 Thread Jorge Ramirez-Ortiz
In order to be able to run the I2C bus at 400Khz, the chip errata[1]
recommends that the peripheral clock runs out of the 24MHz oscillator.

[1] Rev 2, 10/2019, ERR007805

Signed-off-by: Jorge Ramirez-Ortiz 
---
 arch/arm/mach-imx/mx6/soc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
index e129286065..f498c93b00 100644
--- a/arch/arm/mach-imx/mx6/soc.c
+++ b/arch/arm/mach-imx/mx6/soc.c
@@ -26,6 +26,8 @@
 #include 
 #include 
 
+#define ERRATA_ERR007805 (is_mx6dl() || is_mx6solo() || is_mx6ull())
+
 struct scu_regs {
u32 ctrl;
u32 config;
@@ -469,7 +471,7 @@ int arch_cpu_init(void)
}
 
/* Set perclk to source from OSC 24MHz */
-   if (is_mx6sl())
+   if (is_mx6sl() || ERRATA_ERR007805)
setbits_le32(>cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
 
imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
-- 
2.17.1



Re: [PATCH] mx6: peripheral clock from oscillator

2020-10-19 Thread Jorge Ramirez-Ortiz, Foundries
On 19/10/20, Jorge Ramirez-Ortiz, Foundries wrote:
> On 19/10/20, Fabio Estevam wrote:
> > Hi Jorge,
> > 
> > On Wed, Oct 14, 2020 at 10:07 AM Jorge Ramirez-Ortiz  
> > wrote:
> > >
> > > In order to be able to run the I2C bus at 400Khz, the chip errata[1]
> > > recommends that the peripheral clock runs out of the 24MHz oscillator.
> > >
> > > [1] Rev 2, 10/2019, ERR007805
> > >
> > > Signed-off-by: Jorge Ramirez-Ortiz 
> > > ---
> > >  arch/arm/mach-imx/mx6/soc.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/arch/arm/mach-imx/mx6/soc.c b/arch/arm/mach-imx/mx6/soc.c
> > > index e129286065..1da250bbcd 100644
> > > --- a/arch/arm/mach-imx/mx6/soc.c
> > > +++ b/arch/arm/mach-imx/mx6/soc.c
> > > @@ -469,7 +469,7 @@ int arch_cpu_init(void)
> > > }
> > >
> > > /* Set perclk to source from OSC 24MHz */
> > > -   if (is_mx6sl())
> > > +   if (is_mx6sl() || is_mx6ull())
> > 
> > According to https://www.nxp.com/docs/en/errata/IMX6SDLCE.pdf the
> > mx6solo and mx6dl are also affected by ERR007805.
> 
> ah ok, I'll repost.
> 
> just as background info, this is needed in order for OP-TEE to access
> the EdgeLock SE050 secure element at a decent speed. I couldnt merge
> the support for the imx6ul i2c driver during the last OP-TEE release
> but will try again when I find some time (surely before their next
> release)
> 
> 
> > 
> > These variants should be handled too.

I just reposted but realized I forgot to ammend the patch version. let
me know if you would like me to repost with that corrected or if that
is ok.



[PATCH v4 1/2] spl: Use standard FIT entries

2020-10-19 Thread Michal Simek
SPL is creating fit-images DT node when loadables are recorded in selected
configuration. Entries which are created are using entry-point and
load-addr property names. But there shouldn't be a need to use non standard
properties because entry/load are standard FIT properties. But using
standard FIT properties enables option to use generic FIT functions to
descrease SPL size. Here is result for ZynqMP virt configuration:
xilinx_zynqmp_virt: spl/u-boot-spl:all -82 spl/u-boot-spl:rodata -22 
spl/u-boot-spl:text -60

The patch causes change in run time fit image record.
Before:
fit-images {
uboot {
os = "u-boot";
type = "firmware";
size = <0xfd520>;
entry-point = <0x800>;
load-addr = <0x800>;
};
};

After:
fit-images {
uboot {
os = "u-boot";
type = "firmware";
size = <0xfd520>;
entry = <0x800>;
load = <0x800>;
};
};

Replacing calling fdt_getprop_u32() by fit_image_get_entry/load() also
enables support for reading entry/load properties recorded in 64bit format.

Signed-off-by: Michal Simek 
Reviewed-by: Simon Glass 
---

Changes in v4:
- In case of missing entry point initialize image_info->entry_point to
  FDT_ERROR. This has been seen on RISCV instances. FDT_ERROR handling
  should be changed separately because entry_point is uintptr_t and there
  is no way how to pass error conditions that's why FDT_ERROR is used
  instead.

Changes in v3:
- Change example to have 64bit addresses for u-boot
- Add reviewed-by from Simon

Changes in v2:
- Also fix opensbi
- Add record to doc/uImage.FIT/howto.txt - reported by Simon

Would be good to know history of fit-images and it's property names but
there shouldn't be a need to use non standard names where we have
FIT_*_PROP recorded as macros in include/image.h.

Concern regarding backward compatibility is definitely valid but not sure
how many systems can be affected by this change.

Adding temporary support for entry-point/load-addr is also possible.
Or second way around is to create new wrappers as
fit_image_get_entry_point()/fit_image_get_load_addr() or
call fit_image_get_address() directly.

---
 common/fdt_support.c |  4 +-
 common/spl/spl_atf.c |  7 ++--
 common/spl/spl_fit.c |  8 +++-
 common/spl/spl_opensbi.c |  8 ++--
 doc/uImage.FIT/howto.txt | 84 
 5 files changed, 100 insertions(+), 11 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index a565b470f81e..b8a8768a2147 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -616,9 +616,9 @@ int fdt_record_loadable(void *blob, u32 index, const char 
*name,
 * However, spl_fit.c is not 64bit safe either: i.e. we should not
 * have an issue here.
 */
-   fdt_setprop_u32(blob, node, "load-addr", load_addr);
+   fdt_setprop_u32(blob, node, "load", load_addr);
if (entry_point != -1)
-   fdt_setprop_u32(blob, node, "entry-point", entry_point);
+   fdt_setprop_u32(blob, node, "entry", entry_point);
fdt_setprop_u32(blob, node, "size", size);
if (type)
fdt_setprop_string(blob, node, "type", type);
diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c
index b54b4f0d22e2..9bd25f6b32c1 100644
--- a/common/spl/spl_atf.c
+++ b/common/spl/spl_atf.c
@@ -132,10 +132,11 @@ static int spl_fit_images_find(void *blob, int os)
 uintptr_t spl_fit_images_get_entry(void *blob, int node)
 {
ulong  val;
+   int ret;
 
-   val = fdt_getprop_u32(blob, node, "entry-point");
-   if (val == FDT_ERROR)
-   val = fdt_getprop_u32(blob, node, "load-addr");
+   ret = fit_image_get_entry(blob, node, );
+   if (ret)
+   ret = fit_image_get_load(blob, node, );
 
debug("%s: entry point 0x%lx\n", __func__, val);
return val;
diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c
index 0e27ad1d6a55..3cbaa840dd4f 100644
--- a/common/spl/spl_fit.c
+++ b/common/spl/spl_fit.c
@@ -332,9 +332,15 @@ static int spl_load_fit_image(struct spl_load_info *info, 
ulong sector,
}
 
if (image_info) {
+   ulong entry_point;
+
image_info->load_addr = load_addr;
image_info->size = length;
-   image_info->entry_point = fdt_getprop_u32(fit, node, "entry");
+
+   if (!fit_image_get_entry(fit, node, _point))
+   image_info->entry_point = entry_point;
+   else
+   image_info->entry_point = FDT_ERROR;
}
 
return 0;
diff --git a/common/spl/spl_opensbi.c b/common/spl/spl_opensbi.c
index 14f335f75f02..41e0746bb012 100644
--- a/common/spl/spl_opensbi.c
+++ b/common/spl/spl_opensbi.c
@@ -61,11 +61,9 @@ void spl_invoke_opensbi(struct spl_image_info *spl_image)
}
 
/* 

[PATCH v4 0/2] Add support for loading images above 4GB

2020-10-19 Thread Michal Simek
Hi,

We have several use cases where customers want to partition memory by
putting NS images above 4GB. On Xilinx arm 64bit SOC 0-2GB can be used for
others CPU in the systems (like R5) or for secure sw.
Currently there is limitation in SPL to record load/entry addresses in
64bit format because they are recorded in 32bit only.
This series add support for it.
Patches have been tested on Xilinx ZynqMP zcu102 board in SD bootmode with
images generated by binman. Because u-boot is using
CONFIG_POSITION_INDEPENDENT it can be put to others 4k aligned addresses
and there is no real need to build it to certain offset.

Thanks,
Michal

Changes in v4:
- In case of missing entry point initialize image_info->entry_point to
  FDT_ERROR. This has been seen on RISCV instances. FDT_ERROR handling
  should be changed separately because entry_point is uintptr_t and there
  is no way how to pass error conditions that's why FDT_ERROR is used
  instead.
- RISCV32_SPL reports issue that two cells format (64bit value) is
  unsupported address size. But that's not accurate because two cell format
  is valid on any 32bit platform. What it is not supported is address above
  4GB. That's why code is fixed by reading value to 64bit type first and then
  check if upper 32bits are zero or not. On all 32bit platforms upper bits
  should be 0 and if not, message is shown.

Changes in v3:
- Change example to have 64bit addresses for u-boot
- Add reviewed-by from Simon

Changes in v2:
- Also fix opensbi
- Add record to doc/uImage.FIT/howto.txt - reported by Simon

Michal Simek (2):
  spl: Use standard FIT entries
  spl: fdt: Record load/entry fit-images entries in 64bit format

 common/fdt_support.c |  9 +
 common/image-fit.c   | 11 +++---
 common/spl/spl_atf.c |  7 ++--
 common/spl/spl_fit.c |  8 +++-
 common/spl/spl_opensbi.c |  8 ++--
 doc/uImage.FIT/howto.txt | 84 
 6 files changed, 106 insertions(+), 21 deletions(-)

-- 
2.28.0



[PATCH v4 2/2] spl: fdt: Record load/entry fit-images entries in 64bit format

2020-10-19 Thread Michal Simek
The commit 9f45aeb93727 ("spl: fit: implement fdt_record_loadable") which
introduced fdt_record_loadable() state there spl_fit.c is not 64bit safe.
Based on my tests on Xilinx ZynqMP zcu102 platform there shouldn't be a
problem to record these addresses in 64bit format.
The patch adds support for systems which need to load images above 4GB.

Signed-off-by: Michal Simek 
Reviewed-by: Simon Glass 
---

Changes in v4:
- RISCV32_SPL reports issue that two cells format (64bit value) is
  unsupported address size. But that's not accurate because two cell format
  is valid on any 32bit platform. What it is not supported is address above
  4GB. That's why code is fixed by reading value to 64bit type first and then
  check if upper 32bits are zero or not. On all 32bit platforms upper bits
  should be 0 and if not, message is shown.

 common/fdt_support.c |  9 ++---
 common/image-fit.c   | 11 ++-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/common/fdt_support.c b/common/fdt_support.c
index b8a8768a2147..5ae75df3c658 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -611,14 +611,9 @@ int fdt_record_loadable(void *blob, u32 index, const char 
*name,
if (node < 0)
return node;
 
-   /*
-* We record these as 32bit entities, possibly truncating addresses.
-* However, spl_fit.c is not 64bit safe either: i.e. we should not
-* have an issue here.
-*/
-   fdt_setprop_u32(blob, node, "load", load_addr);
+   fdt_setprop_u64(blob, node, "load", load_addr);
if (entry_point != -1)
-   fdt_setprop_u32(blob, node, "entry", entry_point);
+   fdt_setprop_u64(blob, node, "entry", entry_point);
fdt_setprop_u32(blob, node, "size", size);
if (type)
fdt_setprop_string(blob, node, "type", type);
diff --git a/common/image-fit.c b/common/image-fit.c
index d54eff9033cc..c82d4d8015f0 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -791,17 +791,18 @@ static int fit_image_get_address(const void *fit, int 
noffset, char *name,
return -1;
}
 
-   if (len > sizeof(ulong)) {
-   printf("Unsupported %s address size\n", name);
-   return -1;
-   }
-
cell_len = len >> 2;
/* Use load64 to avoid compiling warning for 32-bit target */
while (cell_len--) {
load64 = (load64 << 32) | uimage_to_cpu(*cell);
cell++;
}
+
+   if (len > sizeof(ulong) && (uint32_t)(load64 >> 32)) {
+   printf("Unsupported %s address size\n", name);
+   return -1;
+   }
+
*load = (ulong)load64;
 
return 0;
-- 
2.28.0



Re: [PATCH 09/11] bootm: Allow updating the bootargs in a buffer

2020-10-19 Thread Wolfgang Denk
Dear Simon Glass,

In message <20201019135602.3943835-10-...@chromium.org> you wrote:
> At present we only support updating the 'bootargs' environment
> variable. Add another function to update a buffer instead. This will
> allow zimage to use this feature.

I think this is the wrong way to address a problem.

Instead, zimage should use bootargs as well.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: w...@denx.de
The faster I go, the behinder I get. -- Lewis Carroll


[PATCH v4 01/27] clk: export generic routines

2020-10-19 Thread Dario Binacchi
Export routines that can be used by other drivers avoiding duplicating
code.

Signed-off-by: Dario Binacchi 
Reviewed-by: Simon Glass 

---

(no changes since v2)

Changes in v2:
- Add the clk_ prefix to the divider functions.
- Add kernel-doc comments to the exported functions.

 drivers/clk/clk-divider.c| 24 +++
 include/linux/clk-provider.h | 57 
 2 files changed, 69 insertions(+), 12 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 8f59d7fb72..9df50a5e72 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -28,8 +28,8 @@
 
 #define UBOOT_DM_CLK_CCF_DIVIDER "ccf_clk_divider"
 
-static unsigned int _get_table_div(const struct clk_div_table *table,
-  unsigned int val)
+unsigned int clk_divider_get_table_div(const struct clk_div_table *table,
+  unsigned int val)
 {
const struct clk_div_table *clkt;
 
@@ -49,7 +49,7 @@ static unsigned int _get_div(const struct clk_div_table 
*table,
if (flags & CLK_DIVIDER_MAX_AT_ZERO)
return val ? val : clk_div_mask(width) + 1;
if (table)
-   return _get_table_div(table, val);
+   return clk_divider_get_table_div(table, val);
return val + 1;
 }
 
@@ -89,8 +89,8 @@ static ulong clk_divider_recalc_rate(struct clk *clk)
   divider->flags, divider->width);
 }
 
-static bool _is_valid_table_div(const struct clk_div_table *table,
-   unsigned int div)
+bool clk_divider_is_valid_table_div(const struct clk_div_table *table,
+   unsigned int div)
 {
const struct clk_div_table *clkt;
 
@@ -100,18 +100,18 @@ static bool _is_valid_table_div(const struct 
clk_div_table *table,
return false;
 }
 
-static bool _is_valid_div(const struct clk_div_table *table, unsigned int div,
- unsigned long flags)
+bool clk_divider_is_valid_div(const struct clk_div_table *table,
+ unsigned int div, unsigned long flags)
 {
if (flags & CLK_DIVIDER_POWER_OF_TWO)
return is_power_of_2(div);
if (table)
-   return _is_valid_table_div(table, div);
+   return clk_divider_is_valid_table_div(table, div);
return true;
 }
 
-static unsigned int _get_table_val(const struct clk_div_table *table,
-  unsigned int div)
+unsigned int clk_divider_get_table_val(const struct clk_div_table *table,
+  unsigned int div)
 {
const struct clk_div_table *clkt;
 
@@ -131,7 +131,7 @@ static unsigned int _get_val(const struct clk_div_table 
*table,
if (flags & CLK_DIVIDER_MAX_AT_ZERO)
return (div == clk_div_mask(width) + 1) ? 0 : div;
if (table)
-   return  _get_table_val(table, div);
+   return clk_divider_get_table_val(table, div);
return div - 1;
 }
 int divider_get_val(unsigned long rate, unsigned long parent_rate,
@@ -142,7 +142,7 @@ int divider_get_val(unsigned long rate, unsigned long 
parent_rate,
 
div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
 
-   if (!_is_valid_div(table, div, flags))
+   if (!clk_divider_is_valid_div(table, div, flags))
return -EINVAL;
 
value = _get_val(table, div, flags, width);
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 79dce8f0ad..a94539037a 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -76,6 +76,19 @@ struct clk_mux {
 extern const struct clk_ops clk_mux_ops;
 u8 clk_mux_get_parent(struct clk *clk);
 
+/**
+ * clk_mux_index_to_val() - Convert the parent index to the register value
+ *
+ * It returns the value to write in the hardware register to output the 
selected
+ * input clock parent.
+ *
+ * @table: array of register values corresponding to the parent index 
(optional)
+ * @flags: hardware-specific flags
+ * @index: parent clock index
+ * @return the register value
+ */
+unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
+
 struct clk_gate {
struct clk  clk;
void __iomem*reg;
@@ -125,6 +138,50 @@ struct clk_divider {
 #define CLK_DIVIDER_READ_ONLY  BIT(5)
 #define CLK_DIVIDER_MAX_AT_ZEROBIT(6)
 extern const struct clk_ops clk_divider_ops;
+
+/**
+ * clk_divider_get_table_div() - convert the register value to the divider
+ *
+ * @table:  array of register values corresponding to valid dividers
+ * @val: value to convert
+ * @return the divider
+ */
+unsigned int clk_divider_get_table_div(const struct clk_div_table *table,
+  unsigned int val);
+
+/**
+ * clk_divider_get_table_val() - convert the divider to the register value
+ *
+ * It returns the value to write in the 

[PATCH v4 13/27] clk: ti: move drivers to 'ti' directory

2020-10-19 Thread Dario Binacchi
Add drivers/clk/ti/ folder and move all TI's code in this folder for
better maintenance.

Signed-off-by: Dario Binacchi 
---

(no changes since v1)

 drivers/clk/Kconfig   | 40 +-
 drivers/clk/Makefile  |  8 +---
 drivers/clk/ti/Kconfig| 42 +++
 drivers/clk/ti/Makefile   | 12 ++
 .../clk-am3-dpll-x2.c}|  0
 .../{clk-ti-am3-dpll.c => ti/clk-am3-dpll.c}  |  0
 drivers/clk/{clk-ti-ctrl.c => ti/clk-ctrl.c}  |  0
 .../{clk-ti-divider.c => ti/clk-divider.c}|  2 +-
 drivers/clk/{clk-ti-gate.c => ti/clk-gate.c}  |  0
 drivers/clk/{clk-ti-mux.c => ti/clk-mux.c}|  2 +-
 drivers/clk/{clk-ti-sci.c => ti/clk-sci.c}|  0
 drivers/clk/{clk-ti.c => ti/clk.c}|  2 +-
 drivers/clk/{clk-ti.h => ti/clk.h}|  0
 13 files changed, 59 insertions(+), 49 deletions(-)
 create mode 100644 drivers/clk/ti/Kconfig
 create mode 100644 drivers/clk/ti/Makefile
 rename drivers/clk/{clk-ti-am3-dpll-x2.c => ti/clk-am3-dpll-x2.c} (100%)
 rename drivers/clk/{clk-ti-am3-dpll.c => ti/clk-am3-dpll.c} (100%)
 rename drivers/clk/{clk-ti-ctrl.c => ti/clk-ctrl.c} (100%)
 rename drivers/clk/{clk-ti-divider.c => ti/clk-divider.c} (99%)
 rename drivers/clk/{clk-ti-gate.c => ti/clk-gate.c} (100%)
 rename drivers/clk/{clk-ti-mux.c => ti/clk-mux.c} (99%)
 rename drivers/clk/{clk-ti-sci.c => ti/clk-sci.c} (100%)
 rename drivers/clk/{clk-ti.c => ti/clk.c} (96%)
 rename drivers/clk/{clk-ti.h => ti/clk.h} (100%)

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index f383e295d3..99b1254de6 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -98,45 +98,6 @@ config CLK_STM32F
  This clock driver adds support for RCC clock management
  for STM32F4 and STM32F7 SoCs.
 
-config CLK_TI_AM3_DPLL
-   bool "TI AM33XX Digital Phase-Locked Loop (DPLL) clock drivers"
-   depends on CLK && OF_CONTROL
-   help
- This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
- provides all interface clocks and functional clocks to the processor.
-
-config CLK_TI_CTRL
-   bool "TI OMAP4 clock controller"
-   depends on CLK && OF_CONTROL
-   help
- This enables the clock controller driver support on TI's SoCs.
-
-config CLK_TI_DIVIDER
-   bool "TI divider clock driver"
-   depends on CLK && OF_CONTROL && CLK_CCF
-   help
- This enables the divider clock driver support on TI's SoCs.
-
-config CLK_TI_GATE
-   bool "TI gate clock driver"
-   depends on CLK && OF_CONTROL
-   help
- This enables the gate clock driver support on TI's SoCs.
-
-config CLK_TI_MUX
-   bool "TI mux clock driver"
-   depends on CLK && OF_CONTROL && CLK_CCF
-   help
- This enables the mux clock driver support on TI's SoCs.
-
-config CLK_TI_SCI
-   bool "TI System Control Interface (TI SCI) clock driver"
-   depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
-   help
- This enables the clock driver support over TI System Control Interface
- available on some new TI's SoCs. If you wish to use clock resources
- managed by the TI System Controller, say Y here. Otherwise, say N.
-
 config CLK_HSDK
bool "Enable cgu clock driver for HSDK boards"
depends on CLK && TARGET_HSDK
@@ -209,6 +170,7 @@ source "drivers/clk/owl/Kconfig"
 source "drivers/clk/renesas/Kconfig"
 source "drivers/clk/sunxi/Kconfig"
 source "drivers/clk/sifive/Kconfig"
+source "drivers/clk/ti/Kconfig"
 source "drivers/clk/tegra/Kconfig"
 source "drivers/clk/uniphier/Kconfig"
 
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index c98aa27e71..848cfd46f5 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -13,12 +13,12 @@ obj-$(CONFIG_$(SPL_TPL_)CLK_COMPOSITE_CCF) += 
clk-composite.o
 
 obj-y += analogbits/
 obj-y += imx/
+obj-y += ti/
 obj-y += tegra/
 obj-$(CONFIG_ARCH_ASPEED) += aspeed/
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_MTMIPS) += mtmips/
 obj-$(CONFIG_ARCH_MESON) += meson/
-obj-$(CONFIG_ARCH_OMAP2PLUS) += clk-ti.o
 obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_ARCH_SOCFPGA) += altera/
 obj-$(CONFIG_CLK_AT91) += at91/
@@ -48,11 +48,5 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
-obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
-obj-$(CONFIG_CLK_TI_CTRL) += clk-ti-ctrl.o
-obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
-obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
-obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
-obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
 obj-$(CONFIG_CLK_CDCE9XX) += clk-cdce9xx.o
diff --git a/drivers/clk/ti/Kconfig b/drivers/clk/ti/Kconfig
new file mode 100644
index 00..3c61046728
--- /dev/null
+++ 

[PATCH v4 05/27] clk: add clk_round_rate()

2020-10-19 Thread Dario Binacchi
It returns the rate which will be set if you ask clk_set_rate() to set
that rate. It provides a way to query exactly what rate you'll get if
you call clk_set_rate() with that same argument.
So essentially, clk_round_rate() and clk_set_rate() are equivalent
except the former does not modify the clock hardware in any way.

Signed-off-by: Dario Binacchi 
Reviewed-by: Simon Glass 
Reviewed-by: Sean Anderson 

---

Changes in v4:
- Update clk_round_rate description.
- Add Sean Anderson review.

 arch/sandbox/include/asm/clk.h |  9 +
 drivers/clk/clk-uclass.c   | 15 +++
 drivers/clk/clk_sandbox.c  | 17 +
 drivers/clk/clk_sandbox_test.c | 10 ++
 include/clk-uclass.h   |  8 
 include/clk.h  | 28 
 test/dm/clk.c  | 22 ++
 7 files changed, 109 insertions(+)

diff --git a/arch/sandbox/include/asm/clk.h b/arch/sandbox/include/asm/clk.h
index c184c4bffc..0294baee27 100644
--- a/arch/sandbox/include/asm/clk.h
+++ b/arch/sandbox/include/asm/clk.h
@@ -105,6 +105,15 @@ int sandbox_clk_test_get_bulk(struct udevice *dev);
  * @return:The rate of the clock.
  */
 ulong sandbox_clk_test_get_rate(struct udevice *dev, int id);
+/**
+ * sandbox_clk_test_round_rate - Ask the sandbox clock test device to round a
+ * clock's rate.
+ *
+ * @dev:   The sandbox clock test (client) device.
+ * @id:The test device's clock ID to configure.
+ * @return:The rounded rate of the clock.
+ */
+ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate);
 /**
  * sandbox_clk_test_set_rate - Ask the sandbox clock test device to set a
  * clock's rate.
diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
index 31c5997aea..c16a8b120c 100644
--- a/drivers/clk/clk-uclass.c
+++ b/drivers/clk/clk-uclass.c
@@ -524,6 +524,21 @@ long long clk_get_parent_rate(struct clk *clk)
return pclk->rate;
 }
 
+ulong clk_round_rate(struct clk *clk, ulong rate)
+{
+   const struct clk_ops *ops;
+
+   debug("%s(clk=%p, rate=%lu)\n", __func__, clk, rate);
+   if (!clk_valid(clk))
+   return 0;
+
+   ops = clk_dev_ops(clk->dev);
+   if (!ops->round_rate)
+   return -ENOSYS;
+
+   return ops->round_rate(clk, rate);
+}
+
 ulong clk_set_rate(struct clk *clk, ulong rate)
 {
const struct clk_ops *ops;
diff --git a/drivers/clk/clk_sandbox.c b/drivers/clk/clk_sandbox.c
index 768fbb7c52..8361b930df 100644
--- a/drivers/clk/clk_sandbox.c
+++ b/drivers/clk/clk_sandbox.c
@@ -30,6 +30,22 @@ static ulong sandbox_clk_get_rate(struct clk *clk)
return priv->rate[clk->id];
 }
 
+static ulong sandbox_clk_round_rate(struct clk *clk, ulong rate)
+{
+   struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
+
+   if (!priv->probed)
+   return -ENODEV;
+
+   if (clk->id >= SANDBOX_CLK_ID_COUNT)
+   return -EINVAL;
+
+   if (!rate)
+   return -EINVAL;
+
+   return rate;
+}
+
 static ulong sandbox_clk_set_rate(struct clk *clk, ulong rate)
 {
struct sandbox_clk_priv *priv = dev_get_priv(clk->dev);
@@ -103,6 +119,7 @@ static int sandbox_clk_free(struct clk *clk)
 }
 
 static struct clk_ops sandbox_clk_ops = {
+   .round_rate = sandbox_clk_round_rate,
.get_rate   = sandbox_clk_get_rate,
.set_rate   = sandbox_clk_set_rate,
.enable = sandbox_clk_enable,
diff --git a/drivers/clk/clk_sandbox_test.c b/drivers/clk/clk_sandbox_test.c
index 873383856f..f7b77aa674 100644
--- a/drivers/clk/clk_sandbox_test.c
+++ b/drivers/clk/clk_sandbox_test.c
@@ -86,6 +86,16 @@ ulong sandbox_clk_test_get_rate(struct udevice *dev, int id)
return clk_get_rate(sbct->clkps[id]);
 }
 
+ulong sandbox_clk_test_round_rate(struct udevice *dev, int id, ulong rate)
+{
+   struct sandbox_clk_test *sbct = dev_get_priv(dev);
+
+   if (id < 0 || id >= SANDBOX_CLK_TEST_ID_COUNT)
+   return -EINVAL;
+
+   return clk_round_rate(sbct->clkps[id], rate);
+}
+
 ulong sandbox_clk_test_set_rate(struct udevice *dev, int id, ulong rate)
 {
struct sandbox_clk_test *sbct = dev_get_priv(dev);
diff --git a/include/clk-uclass.h b/include/clk-uclass.h
index dac42dab36..50e8681b55 100644
--- a/include/clk-uclass.h
+++ b/include/clk-uclass.h
@@ -61,6 +61,14 @@ struct clk_ops {
 * @return 0 if OK, or a negative error code.
 */
int (*rfree)(struct clk *clock);
+   /**
+* round_rate() - Adjust a rate to the exact rate a clock can provide.
+*
+* @clk:The clock to manipulate.
+* @rate:   Desidered clock rate in Hz.
+* @return rounded rate in Hz, or -ve error code.
+*/
+   ulong (*round_rate)(struct clk *clk, ulong rate);
/**
 * get_rate() - Get current clock rate.
 *
diff --git a/include/clk.h b/include/clk.h
index 

[PATCH v4 24/27] video: omap: set LCD clock rate through DM API

2020-10-19 Thread Dario Binacchi
The patch configures the display DPLL using the functions provided by
the driver model API for the clock. The device tree contains everything
needed to get the DPLL clock. The round rate function developed for
calculating the DPLL multiplier and divisor and the platform routines
for accessing the DPLL registers are removed from the LCD driver code
because they are implemented inside the DPLL clock driver.

Signed-off-by: Dario Binacchi 

---

(no changes since v3)

Changes in v3:
- Add clk.h header.
- Fix an error code returned by the probe function.

 drivers/video/am335x-fb.c | 129 ++
 1 file changed, 103 insertions(+), 26 deletions(-)

diff --git a/drivers/video/am335x-fb.c b/drivers/video/am335x-fb.c
index dc959baa27..a0a635cc29 100644
--- a/drivers/video/am335x-fb.c
+++ b/drivers/video/am335x-fb.c
@@ -12,6 +12,7 @@
  * - starts output DMA from gd->fb_base buffer
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -112,6 +113,27 @@ struct am335x_lcdhw {
unsigned intclkc_reset; /* 0x70 */
 };
 
+DECLARE_GLOBAL_DATA_PTR;
+
+#if !CONFIG_IS_ENABLED(DM_VIDEO)
+
+#if !defined(LCD_CNTL_BASE)
+#error "hw-base address of LCD-Controller (LCD_CNTL_BASE) not defined!"
+#endif
+
+/* Macro definitions */
+#define FBSIZE(x)  (((x)->hactive * (x)->vactive * (x)->bpp) >> 3)
+
+#define LCDC_RASTER_TIMING_2_INVMASK(x)((x) & GENMASK(25, 20))
+
+static struct am335x_lcdhw *lcdhw = (void *)LCD_CNTL_BASE;
+
+int lcd_get_size(int *line_length)
+{
+   *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
+   return *line_length * panel_info.vl_row + 0x20;
+}
+
 struct dpll_data {
unsigned long rounded_rate;
u16 rounded_m;
@@ -119,8 +141,6 @@ struct dpll_data {
u8 rounded_div;
 };
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /**
  * am335x_dpll_round_rate() - Round a target rate for an OMAP DPLL
  *
@@ -199,25 +219,6 @@ static ulong am335x_fb_set_pixel_clk_rate(struct 
am335x_lcdhw *regs, ulong rate)
return round_rate;
 }
 
-#if !CONFIG_IS_ENABLED(DM_VIDEO)
-
-#if !defined(LCD_CNTL_BASE)
-#error "hw-base address of LCD-Controller (LCD_CNTL_BASE) not defined!"
-#endif
-
-/* Macro definitions */
-#define FBSIZE(x)  (((x)->hactive * (x)->vactive * (x)->bpp) >> 3)
-
-#define LCDC_RASTER_TIMING_2_INVMASK(x)((x) & GENMASK(25, 20))
-
-static struct am335x_lcdhw *lcdhw = (void *)LCD_CNTL_BASE;
-
-int lcd_get_size(int *line_length)
-{
-   *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
-   return *line_length * panel_info.vl_row + 0x20;
-}
-
 int am335xfb_init(struct am335x_lcdpanel *panel)
 {
u32 raster_ctrl = 0;
@@ -335,14 +336,58 @@ enum {
 
 struct am335x_fb_priv {
struct am335x_lcdhw *regs;
+   struct clk gclk;
+   struct clk dpll_m2_clk;
 };
 
+static ulong tilcdc_set_pixel_clk_rate(struct udevice *dev, ulong rate)
+{
+   struct am335x_fb_priv *priv = dev_get_priv(dev);
+   struct am335x_lcdhw *regs = priv->regs;
+   ulong mult_rate, mult_round_rate, best_err, err;
+   u32 v;
+   int div, i;
+
+   best_err = rate;
+   div = 0;
+   for (i = 2; i <= 255; i++) {
+   mult_rate = rate * i;
+   mult_round_rate = clk_round_rate(>gclk, mult_rate);
+   if (IS_ERR_VALUE(mult_round_rate))
+   return mult_round_rate;
+
+   err = mult_rate - mult_round_rate;
+   if (err < best_err) {
+   best_err = err;
+   div = i;
+   if (err == 0)
+   break;
+   }
+   }
+
+   if (div == 0) {
+   dev_err(dev, "failed to find a divisor\n");
+   return -EFAULT;
+   }
+
+   mult_rate = clk_set_rate(>gclk, rate * div);
+   v = readl(>ctrl) & ~LCDC_CTRL_CLK_DIVISOR_MASK;
+   v |= LCDC_CTRL_CLK_DIVISOR(div);
+   writel(v, >ctrl);
+   rate = mult_rate / div;
+   dev_dbg(dev, "rate=%ld, div=%d, err=%ld\n", rate, div, err);
+   return rate;
+}
+
 static int am335x_fb_remove(struct udevice *dev)
 {
struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
+   struct am335x_fb_priv *priv = dev_get_priv(dev);
 
uc_plat->base -= 0x20;
uc_plat->size += 0x20;
+   clk_release_all(>gclk, 1);
+   clk_release_all(>dpll_m2_clk, 1);
return 0;
 }
 
@@ -352,10 +397,10 @@ static int am335x_fb_probe(struct udevice *dev)
struct video_priv *uc_priv = dev_get_uclass_priv(dev);
struct am335x_fb_priv *priv = dev_get_priv(dev);
struct am335x_lcdhw *regs = priv->regs;
-   struct udevice *panel;
+   struct udevice *panel, *clk_dev;
struct tilcdc_panel_info info;
struct display_timing timing;
-   struct cm_dpll *const cmdpll = (struct cm_dpll *)CM_DPLL;
+   ulong rate;
u32 reg;
int err;
 
@@ 

[PATCH v4 25/27] video: omap: split the legacy code from the DM code

2020-10-19 Thread Dario Binacchi
The schedule for deprecating the features of the pre-driver-model puts
2019.17 as the deadline for the video subsystem. Furthermore, the latest
patches applied to the am335x-fb.c module have decreased the amount of
code shared with the pre-driver-model implementation. Splitting the two
implementations into two modules improves the readability of the code
and will make it easier to drop the pre-driver-model code.
I have not created a header file with the data structures and the
constants for accessing the LCD controller registers, but I preferred to
keep them inside the two c modules. This is a code replication until the
pre-driver-model version is dropped.

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

 drivers/video/Makefile   |   5 +-
 drivers/video/am335x-fb.c| 336 ---
 drivers/video/am335x-fb.h|  35 ---
 drivers/video/tilcdc-panel.c |   2 +-
 drivers/video/tilcdc-panel.h |   2 +-
 drivers/video/tilcdc.c   | 425 +++
 drivers/video/tilcdc.h   |  38 
 7 files changed, 468 insertions(+), 375 deletions(-)
 create mode 100644 drivers/video/tilcdc.c
 create mode 100644 drivers/video/tilcdc.h

diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 132a63ecea..29f3434f7c 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -16,7 +16,9 @@ obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o
 obj-$(CONFIG_DM_VIDEO) += video_bmp.o
 obj-$(CONFIG_PANEL) += panel-uclass.o
 obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.o
-obj-$(CONFIG_AM335X_LCD) += tilcdc-panel.o
+obj-$(CONFIG_AM335X_LCD) += tilcdc.o tilcdc-panel.o
+else
+obj-$(CONFIG_AM335X_LCD) += am335x-fb.o
 endif
 
 obj-${CONFIG_EXYNOS_FB} += exynos/
@@ -24,7 +26,6 @@ obj-${CONFIG_VIDEO_ROCKCHIP} += rockchip/
 obj-${CONFIG_VIDEO_STM32} += stm32/
 obj-${CONFIG_VIDEO_TEGRA124} += tegra124/
 
-obj-$(CONFIG_AM335X_LCD) += am335x-fb.o
 obj-$(CONFIG_ATI_RADEON_FB) += ati_radeon_fb.o videomodes.o
 obj-$(CONFIG_ATMEL_HLCD) += atmel_hlcdfb.o
 obj-$(CONFIG_ATMEL_LCD) += atmel_lcdfb.o
diff --git a/drivers/video/am335x-fb.c b/drivers/video/am335x-fb.c
index a0a635cc29..eb9d692035 100644
--- a/drivers/video/am335x-fb.c
+++ b/drivers/video/am335x-fb.c
@@ -12,22 +12,15 @@
  * - starts output DMA from gd->fb_base buffer
  */
 #include 
-#include 
-#include 
 #include 
 #include 
-#include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
 #include "am335x-fb.h"
-#include "tilcdc-panel.h"
 
 #define LCDC_FMAX  2
 
@@ -115,8 +108,6 @@ struct am335x_lcdhw {
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if !CONFIG_IS_ENABLED(DM_VIDEO)
-
 #if !defined(LCD_CNTL_BASE)
 #error "hw-base address of LCD-Controller (LCD_CNTL_BASE) not defined!"
 #endif
@@ -323,330 +314,3 @@ int am335xfb_init(struct am335x_lcdpanel *panel)
 
return 0;
 }
-
-#else /* CONFIG_DM_VIDEO */
-
-#define FBSIZE(t, p)   (((t).hactive.typ * (t).vactive.typ * (p).bpp) >> 3)
-
-enum {
-   LCD_MAX_WIDTH   = 2048,
-   LCD_MAX_HEIGHT  = 2048,
-   LCD_MAX_LOG2_BPP= VIDEO_BPP32,
-};
-
-struct am335x_fb_priv {
-   struct am335x_lcdhw *regs;
-   struct clk gclk;
-   struct clk dpll_m2_clk;
-};
-
-static ulong tilcdc_set_pixel_clk_rate(struct udevice *dev, ulong rate)
-{
-   struct am335x_fb_priv *priv = dev_get_priv(dev);
-   struct am335x_lcdhw *regs = priv->regs;
-   ulong mult_rate, mult_round_rate, best_err, err;
-   u32 v;
-   int div, i;
-
-   best_err = rate;
-   div = 0;
-   for (i = 2; i <= 255; i++) {
-   mult_rate = rate * i;
-   mult_round_rate = clk_round_rate(>gclk, mult_rate);
-   if (IS_ERR_VALUE(mult_round_rate))
-   return mult_round_rate;
-
-   err = mult_rate - mult_round_rate;
-   if (err < best_err) {
-   best_err = err;
-   div = i;
-   if (err == 0)
-   break;
-   }
-   }
-
-   if (div == 0) {
-   dev_err(dev, "failed to find a divisor\n");
-   return -EFAULT;
-   }
-
-   mult_rate = clk_set_rate(>gclk, rate * div);
-   v = readl(>ctrl) & ~LCDC_CTRL_CLK_DIVISOR_MASK;
-   v |= LCDC_CTRL_CLK_DIVISOR(div);
-   writel(v, >ctrl);
-   rate = mult_rate / div;
-   dev_dbg(dev, "rate=%ld, div=%d, err=%ld\n", rate, div, err);
-   return rate;
-}
-
-static int am335x_fb_remove(struct udevice *dev)
-{
-   struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
-   struct am335x_fb_priv *priv = dev_get_priv(dev);
-
-   uc_plat->base -= 0x20;
-   uc_plat->size += 0x20;
-   clk_release_all(>gclk, 1);
-   clk_release_all(>dpll_m2_clk, 1);
-   return 0;
-}
-
-static int am335x_fb_probe(struct udevice *dev)
-{
-   

[PATCH v4 22/27] video: omap: add panel driver

2020-10-19 Thread Dario Binacchi
The previous version of am335x-fb.c contained the functionalities of two
drivers that this patch has split. It was a video type driver that used
the same registration compatible string that now registers a panel type
driver. The proof of this is that two compatible strings were referred
to within the same driver.
There are now two drivers, each with its own compatible string,
functions and API.
Furthermore, the panel driver, in addition to decoding the display
timings, is now also able to manage the backlight.

Signed-off-by: Dario Binacchi 
Reviewed-by: Simon Glass 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.
- Add Simon Glass review.

Changes in v3:
- Update the DTS lcdc node of the am335x boards because of the
  am33xx.dtsi resynced with Linux 5.9-rc7.

 arch/arm/dts/am335x-brppt1-mmc.dts   |  17 +-
 arch/arm/dts/am335x-brppt1-nand.dts  |  17 +-
 arch/arm/dts/am335x-brppt1-spi.dts   |  17 +-
 arch/arm/dts/am335x-brsmarc1.dts |  20 +-
 arch/arm/dts/am335x-brxre1.dts   |  21 +-
 arch/arm/dts/am335x-evm-u-boot.dtsi  |  15 +-
 arch/arm/dts/am335x-evmsk-u-boot.dtsi|  14 +-
 arch/arm/dts/am335x-guardian-u-boot.dtsi |  18 +-
 arch/arm/dts/am335x-pdu001-u-boot.dtsi   |  18 +-
 arch/arm/dts/am335x-pxm50-u-boot.dtsi|  14 +-
 arch/arm/dts/am335x-rut-u-boot.dtsi  |  14 +-
 arch/arm/dts/da850-evm-u-boot.dtsi   |  18 +-
 drivers/video/Makefile   |   1 +
 drivers/video/am335x-fb.c| 255 ++-
 drivers/video/am335x-fb.h|  31 +++
 drivers/video/tilcdc-panel.c | 172 +++
 drivers/video/tilcdc-panel.h |  14 ++
 17 files changed, 478 insertions(+), 198 deletions(-)
 create mode 100644 drivers/video/tilcdc-panel.c
 create mode 100644 drivers/video/tilcdc-panel.h

diff --git a/arch/arm/dts/am335x-brppt1-mmc.dts 
b/arch/arm/dts/am335x-brppt1-mmc.dts
index 6f919711f0..bd2f6c2e3e 100644
--- a/arch/arm/dts/am335x-brppt1-mmc.dts
+++ b/arch/arm/dts/am335x-brppt1-mmc.dts
@@ -53,8 +53,6 @@
bkl-pwm = <>;
bkl-tps = <_bl>;
 
-   u-boot,dm-pre-reloc;
-
panel-info {
ac-bias = <255>;
ac-bias-intrpt  = <0>;
@@ -238,8 +236,19 @@
status = "okay";
 };
 
- {
-   status = "disabled";
+_per {
+
+   segment@30 {
+
+   target-module@e000 {
+   u-boot,dm-pre-reloc;
+
+   lcdc: lcdc@0 {
+   u-boot,dm-pre-reloc;
+   status = "disabled";
+   };
+   };
+   };
 };
 
  {
diff --git a/arch/arm/dts/am335x-brppt1-nand.dts 
b/arch/arm/dts/am335x-brppt1-nand.dts
index 9d4340f591..67c609739f 100644
--- a/arch/arm/dts/am335x-brppt1-nand.dts
+++ b/arch/arm/dts/am335x-brppt1-nand.dts
@@ -53,8 +53,6 @@
bkl-pwm = <>;
bkl-tps = <_bl>;
 
-   u-boot,dm-pre-reloc;
-
panel-info {
ac-bias = <255>;
ac-bias-intrpt  = <0>;
@@ -228,8 +226,19 @@
status = "disabled";
 };
 
- {
-   status = "disabled";
+_per {
+
+   segment@30 {
+
+   target-module@e000 {
+   u-boot,dm-pre-reloc;
+
+   lcdc: lcdc@0 {
+   u-boot,dm-pre-reloc;
+   status = "disabled";
+   };
+   };
+   };
 };
 
  {
diff --git a/arch/arm/dts/am335x-brppt1-spi.dts 
b/arch/arm/dts/am335x-brppt1-spi.dts
index c078af8fba..ce3dce204d 100644
--- a/arch/arm/dts/am335x-brppt1-spi.dts
+++ b/arch/arm/dts/am335x-brppt1-spi.dts
@@ -54,8 +54,6 @@
bkl-pwm = <>;
bkl-tps = <_bl>;
 
-   u-boot,dm-pre-reloc;
-
panel-info {
ac-bias = <255>;
ac-bias-intrpt  = <0>;
@@ -259,8 +257,19 @@
status = "okay";
 };
 
- {
-   status = "disabled";
+_per {
+
+   segment@30 {
+
+   target-module@e000 {
+   u-boot,dm-pre-reloc;
+
+   lcdc: lcdc@0 {
+   u-boot,dm-pre-reloc;
+   status = "disabled";
+   };
+   };
+   };
 };
 
  {
diff --git a/arch/arm/dts/am335x-brsmarc1.dts b/arch/arm/dts/am335x-brsmarc1.dts
index 7e9516e8f8..25cdb11164 100644
--- a/arch/arm/dts/am335x-brsmarc1.dts
+++ b/arch/arm/dts/am335x-brsmarc1.dts
@@ -59,7 +59,6 @@
/*backlight = <_bl>; */
compatible = "ti,tilcdc,panel";
status = "okay";
-   u-boot,dm-pre-reloc;
 
panel-info {
ac-bias = <255>;
@@ -298,10 +297,21 @@
status = "okay";
 };
 
- {
-   status = 

[PATCH v4 23/27] video: omap: drop domain clock enabling by SOC api

2020-10-19 Thread Dario Binacchi
Enabling the domain clock is performed by the sysc interconnect target
module driver during the video device probing.

Signed-off-by: Dario Binacchi 

---

(no changes since v3)

Changes in v3:
- Remove clock domain enabling/disabling.
- Update the commit message.

 arch/arm/mach-omap2/am33xx/clock_am33xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-omap2/am33xx/clock_am33xx.c 
b/arch/arm/mach-omap2/am33xx/clock_am33xx.c
index 2427933c8b..cf71192360 100644
--- a/arch/arm/mach-omap2/am33xx/clock_am33xx.c
+++ b/arch/arm/mach-omap2/am33xx/clock_am33xx.c
@@ -226,7 +226,7 @@ void enable_basic_clocks(void)
>usb0clkctrl,
>emiffwclkctrl,
>emifclkctrl,
-#if CONFIG_IS_ENABLED(AM335X_LCD)
+#if CONFIG_IS_ENABLED(AM335X_LCD) && !CONFIG_IS_ENABLED(DM_VIDEO)
>lcdclkctrl,
>lcdcclkstctrl,
 #endif
-- 
2.17.1



[PATCH v4 21/27] dm: core: add a function to decode display timings

2020-10-19 Thread Dario Binacchi
The patch adds a function to get display timings from the device tree
node attached to the device.

Signed-off-by: Dario Binacchi 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 arch/sandbox/dts/test.dts | 46 ++
 drivers/core/read.c   |  6 +++
 include/dm/read.h | 24 
 test/dm/test-fdt.c| 80 +++
 4 files changed, 156 insertions(+)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 4a7a28559a..b3c1a7f2fd 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -134,6 +134,52 @@
interrupts-extended = < 3 0>;
acpi,name = "GHIJ";
phandle-value = <_c 10>, <0x 20>, <_a 30>;
+   display-timings {
+   timing0: 240x320 {
+   clock-frequency = <650>;
+   hactive = <240>;
+   vactive = <320>;
+   hfront-porch = <6>;
+   hback-porch = <7>;
+   hsync-len = <1>;
+   vback-porch = <5>;
+   vfront-porch = <8>;
+   vsync-len = <2>;
+   hsync-active = <1>;
+   vsync-active = <0>;
+   de-active = <1>;
+   pixelclk-active = <1>;
+   interlaced;
+   doublescan;
+   doubleclk;
+   };
+   timing1: 480x800 {
+   clock-frequency = <900>;
+   hactive = <480>;
+   vactive = <800>;
+   hfront-porch = <10>;
+   hback-porch = <59>;
+   hsync-len = <12>;
+   vback-porch = <15>;
+   vfront-porch = <17>;
+   vsync-len = <16>;
+   hsync-active = <0>;
+   vsync-active = <1>;
+   de-active = <0>;
+   pixelclk-active = <0>;
+   };
+   timing2: 800x480 {
+   clock-frequency = <3350>;
+   hactive = <800>;
+   vactive = <480>;
+   hback-porch = <89>;
+   hfront-porch = <164>;
+   vback-porch = <23>;
+   vfront-porch = <10>;
+   hsync-len = <11>;
+   vsync-len = <13>;
+   };
+   };
};
 
junk {
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 076125824c..7925c09f60 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -377,3 +377,9 @@ int dev_read_pci_bus_range(const struct udevice *dev,
 
return 0;
 }
+
+int dev_decode_display_timing(const struct udevice *dev, int index,
+ struct display_timing *config)
+{
+   return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
+}
diff --git a/include/dm/read.h b/include/dm/read.h
index 0585eb1228..0ac26d9f1d 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -694,6 +694,23 @@ int dev_get_child_count(const struct udevice *dev);
  */
 int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
 
+/**
+ * dev_decode_display_timing() - decode display timings
+ *
+ * Decode display timings from the supplied 'display-timings' node.
+ * See doc/device-tree-bindings/video/display-timing.txt for binding
+ * information.
+ *
+ * @dev: device to read DT display timings from. The node linked to the device
+ *   contains a child node called 'display-timings' which in turn contains
+ *   one or more display timing nodes.
+ * @index: index number to read (0=first timing subnode)
+ * @config: place to put timings
+ * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
+ */
+int dev_decode_display_timing(const struct udevice *dev, int index,
+ struct display_timing *config);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 
 static inline int dev_read_u32(const struct udevice *dev,
@@ -1016,6 +1033,13 @@ static inline int dev_get_child_count(const struct 
udevice *dev)
return ofnode_get_child_count(dev_ofnode(dev));
 }
 
+static inline int dev_decode_display_timing(const struct udevice *dev,
+   int index,
+   struct display_timing *config)
+{
+   return ofnode_decode_display_timing(dev_ofnode(dev), 

[PATCH v4 26/27] video: omap: move drivers to 'ti' directory

2020-10-19 Thread Dario Binacchi
Add drivers/video/ti/ folder and move all TI's code in this folder for
better maintenance.

Signed-off-by: Dario Binacchi 
---

(no changes since v1)

 drivers/video/Kconfig |  5 +
 drivers/video/Makefile|  4 +---
 drivers/video/ti/Kconfig  |  8 
 drivers/video/ti/Makefile | 10 ++
 drivers/video/{ => ti}/am335x-fb.c|  0
 drivers/video/{ => ti}/am335x-fb.h|  0
 drivers/video/{ => ti}/tilcdc-panel.c |  0
 drivers/video/{ => ti}/tilcdc-panel.h |  0
 drivers/video/{ => ti}/tilcdc.c   |  0
 drivers/video/{ => ti}/tilcdc.h   |  0
 10 files changed, 20 insertions(+), 7 deletions(-)
 create mode 100644 drivers/video/ti/Kconfig
 create mode 100644 drivers/video/ti/Makefile
 rename drivers/video/{ => ti}/am335x-fb.c (100%)
 rename drivers/video/{ => ti}/am335x-fb.h (100%)
 rename drivers/video/{ => ti}/tilcdc-panel.c (100%)
 rename drivers/video/{ => ti}/tilcdc-panel.h (100%)
 rename drivers/video/{ => ti}/tilcdc.c (100%)
 rename drivers/video/{ => ti}/tilcdc.h (100%)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index e2e1f9c476..31a6d84e20 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -546,10 +546,7 @@ config ATMEL_HLCD
help
   HLCDC supports video output to an attached LCD panel.
 
-config AM335X_LCD
-   bool "Enable AM335x video support"
-   help
-  Supports video output to an attached LCD panel.
+source "drivers/video/ti/Kconfig"
 
 config LOGICORE_DP_TX
bool "Enable Logicore DP TX driver"
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 29f3434f7c..38e181a779 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -16,15 +16,13 @@ obj-$(CONFIG_DM_VIDEO) += video-uclass.o vidconsole-uclass.o
 obj-$(CONFIG_DM_VIDEO) += video_bmp.o
 obj-$(CONFIG_PANEL) += panel-uclass.o
 obj-$(CONFIG_SIMPLE_PANEL) += simple_panel.o
-obj-$(CONFIG_AM335X_LCD) += tilcdc.o tilcdc-panel.o
-else
-obj-$(CONFIG_AM335X_LCD) += am335x-fb.o
 endif
 
 obj-${CONFIG_EXYNOS_FB} += exynos/
 obj-${CONFIG_VIDEO_ROCKCHIP} += rockchip/
 obj-${CONFIG_VIDEO_STM32} += stm32/
 obj-${CONFIG_VIDEO_TEGRA124} += tegra124/
+obj-${CONFIG_AM335X_LCD} += ti/
 
 obj-$(CONFIG_ATI_RADEON_FB) += ati_radeon_fb.o videomodes.o
 obj-$(CONFIG_ATMEL_HLCD) += atmel_hlcdfb.o
diff --git a/drivers/video/ti/Kconfig b/drivers/video/ti/Kconfig
new file mode 100644
index 00..3081e9e8c0
--- /dev/null
+++ b/drivers/video/ti/Kconfig
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2020 Dario Binacchi 
+#
+config AM335X_LCD
+   bool "Enable AM335x video support"
+   help
+  Supports video output to an attached LCD panel.
diff --git a/drivers/video/ti/Makefile b/drivers/video/ti/Makefile
new file mode 100644
index 00..f0410debf4
--- /dev/null
+++ b/drivers/video/ti/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2020 Dario Binacchi 
+#
+
+ifdef CONFIG_DM
+obj-$(CONFIG_AM335X_LCD) += tilcdc.o tilcdc-panel.o
+else
+obj-$(CONFIG_AM335X_LCD) += am335x-fb.o
+endif
diff --git a/drivers/video/am335x-fb.c b/drivers/video/ti/am335x-fb.c
similarity index 100%
rename from drivers/video/am335x-fb.c
rename to drivers/video/ti/am335x-fb.c
diff --git a/drivers/video/am335x-fb.h b/drivers/video/ti/am335x-fb.h
similarity index 100%
rename from drivers/video/am335x-fb.h
rename to drivers/video/ti/am335x-fb.h
diff --git a/drivers/video/tilcdc-panel.c b/drivers/video/ti/tilcdc-panel.c
similarity index 100%
rename from drivers/video/tilcdc-panel.c
rename to drivers/video/ti/tilcdc-panel.c
diff --git a/drivers/video/tilcdc-panel.h b/drivers/video/ti/tilcdc-panel.h
similarity index 100%
rename from drivers/video/tilcdc-panel.h
rename to drivers/video/ti/tilcdc-panel.h
diff --git a/drivers/video/tilcdc.c b/drivers/video/ti/tilcdc.c
similarity index 100%
rename from drivers/video/tilcdc.c
rename to drivers/video/ti/tilcdc.c
diff --git a/drivers/video/tilcdc.h b/drivers/video/ti/tilcdc.h
similarity index 100%
rename from drivers/video/tilcdc.h
rename to drivers/video/ti/tilcdc.h
-- 
2.17.1



[PATCH v4 27/27] board: ti: am335x-ice: get CDCE913 clock device

2020-10-19 Thread Dario Binacchi
With support for other clock drivers, the potentially supported CDCE913
device can no longer be probed without specifying its DT node name.

Signed-off-by: Dario Binacchi 

---

(no changes since v1)

 board/ti/am335x/board.c | 2 +-
 board/ti/am43xx/board.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/board/ti/am335x/board.c b/board/ti/am335x/board.c
index 984cc5e3ba..e1f64859cf 100644
--- a/board/ti/am335x/board.c
+++ b/board/ti/am335x/board.c
@@ -879,7 +879,7 @@ int board_late_init(void)
}
 
/* Just probe the potentially supported cdce913 device */
-   uclass_get_device(UCLASS_CLK, 0, );
+   uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", );
 
return 0;
 }
diff --git a/board/ti/am43xx/board.c b/board/ti/am43xx/board.c
index de49590031..62ed37cb48 100644
--- a/board/ti/am43xx/board.c
+++ b/board/ti/am43xx/board.c
@@ -744,7 +744,7 @@ int board_late_init(void)
 #endif
 
/* Just probe the potentially supported cdce913 device */
-   uclass_get_device(UCLASS_CLK, 0, );
+   uclass_get_device_by_name(UCLASS_CLK, "cdce913@65", );
 
return 0;
 }
-- 
2.17.1



Re: [PATCH v1] arm: socfpga: fix Gen5 enable of EMAC via FPGA

2020-10-19 Thread Ralph Siemsen

On Tue, Sep 29, 2020 at 02:52:05PM -0400, Ralph Siemsen wrote:
Fixes: db5741f7a85ec3ee79b64496172afaa7dc2cb225 ("arm: socfpga: Convert 
system manager from struct to defines")


Just curious if you have had a chance to look over this patch?
http://patchwork.ozlabs.org/project/uboot/patch/20200929145152.v1.1.I7900a579743ce0fc5fe382213612b5af29e3706f@changeid/

It fixes a problem introduced here: 
https://gitlab.denx.de/u-boot/u-boot/-/commit/db5741f7a85ec3ee79b64496172afaa7dc2cb225?view=parallel#fd949530559c32d01169ed7f0667e63ab210fe14_16_16

after which one of the GMAC on Gen 5 devices no longer operates at 100mbit.

Thanks,
Ralph


[PATCH v4 04/27] arm: dts: sync am33xx with Linux 5.9-rc7

2020-10-19 Thread Dario Binacchi
There have been several changes to the am33xx.dtsi, so this patch
re-syncs it with Linux.

Let's add proper interconnect hierarchy for l4 interconnect instances
with the related ti-sysc interconnect module data as documented in
Documentation/devicetree/bindings/bus/ti-sysc.txt of the Linux kernel.
With l4 interconnect hierarchy and ti-sysc interconnect target module
data in place, we can simply move all the related child devices to their
proper location and enable probing using ti-sysc.

The am33xx-clock.dtsi file is the same as that of the Linux kernel,
except for the reg property of the node l4-wkup-clkctrl@0.
As for the am33xx.dtsi file, all the devices with drivers not yet
implemented and those I was able to test with this patch have been moved
to am33xx-l4.dtsi. In case of any regressions, problem devices can be
reverted by moving them back and removing the related interconnect
target module node.

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Remove a blank line at end of file arch/arm/dts/am33xx-l4.dtsi.

 arch/arm/dts/am335x-draco.dtsi   |   11 +-
 arch/arm/dts/am335x-evm.dts  |2 +-
 arch/arm/dts/am335x-evmsk.dts|2 +-
 arch/arm/dts/am335x-guardian-u-boot.dtsi |5 -
 arch/arm/dts/am335x-pxm2.dtsi|2 +-
 arch/arm/dts/am335x-rut.dts  |2 +-
 arch/arm/dts/am335x-shc.dts  |2 +-
 arch/arm/dts/am33xx-clocks.dtsi  |  106 +-
 arch/arm/dts/am33xx-l4.dtsi  | 1962 ++
 arch/arm/dts/am33xx.dtsi |  721 +++-
 10 files changed, 2273 insertions(+), 542 deletions(-)
 create mode 100644 arch/arm/dts/am33xx-l4.dtsi

diff --git a/arch/arm/dts/am335x-draco.dtsi b/arch/arm/dts/am335x-draco.dtsi
index b38ff55e1d..2c125fcec9 100644
--- a/arch/arm/dts/am335x-draco.dtsi
+++ b/arch/arm/dts/am335x-draco.dtsi
@@ -20,11 +20,6 @@
};
 
ocp {
-   uart0: serial@44e09000 {
-   pinctrl-names = "default";
-   pinctrl-0 = <_pins>;
-   status = "okay";
-   };
 
i2c0: i2c@44e0b000 {
pinctrl-names = "default";
@@ -112,6 +107,12 @@
status = "disabled";
 };
 
+ {
+   pinctrl-names = "default";
+   pinctrl-0 = <_pins>;
+   status = "okay";
+};
+
  {
status = "disabled";
 };
diff --git a/arch/arm/dts/am335x-evm.dts b/arch/arm/dts/am335x-evm.dts
index 0bda4d4429..07288fb188 100644
--- a/arch/arm/dts/am335x-evm.dts
+++ b/arch/arm/dts/am335x-evm.dts
@@ -486,7 +486,7 @@
  {
status = "okay";
 
-   ecap0: ecap@48300100 {
+   ecap0: ecap@100 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/dts/am335x-evmsk.dts b/arch/arm/dts/am335x-evmsk.dts
index 5762967cf7..c94c33b595 100644
--- a/arch/arm/dts/am335x-evmsk.dts
+++ b/arch/arm/dts/am335x-evmsk.dts
@@ -531,7 +531,7 @@
  {
status = "okay";
 
-   ecap2: ecap@48304100 {
+   ecap2: ecap@100 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/dts/am335x-guardian-u-boot.dtsi 
b/arch/arm/dts/am335x-guardian-u-boot.dtsi
index 705ef335bf..eae027c541 100644
--- a/arch/arm/dts/am335x-guardian-u-boot.dtsi
+++ b/arch/arm/dts/am335x-guardian-u-boot.dtsi
@@ -26,11 +26,6 @@
u-boot,dm-pre-reloc;
 };
 
- {
-   clocks = <_per_clkctrl AM3_CLKDIV32K_CLKCTRL 0>;
-   clock-names = "int-clk";
-};
-
  {
u-boot,dm-pre-reloc;
 };
diff --git a/arch/arm/dts/am335x-pxm2.dtsi b/arch/arm/dts/am335x-pxm2.dtsi
index 19bd7e2420..645d221507 100644
--- a/arch/arm/dts/am335x-pxm2.dtsi
+++ b/arch/arm/dts/am335x-pxm2.dtsi
@@ -148,7 +148,7 @@
  {
status = "okay";
 
-   ecap0: ecap@48300100 {
+   ecap0: ecap@100 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/dts/am335x-rut.dts b/arch/arm/dts/am335x-rut.dts
index 145247344f..cc06f5d23a 100644
--- a/arch/arm/dts/am335x-rut.dts
+++ b/arch/arm/dts/am335x-rut.dts
@@ -174,7 +174,7 @@
  {
status = "okay";
 
-   ecap0: ecap@48300100 {
+   ecap0: ecap@100 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <_pins>;
diff --git a/arch/arm/dts/am335x-shc.dts b/arch/arm/dts/am335x-shc.dts
index 8e35c439e5..a41a0606b1 100644
--- a/arch/arm/dts/am335x-shc.dts
+++ b/arch/arm/dts/am335x-shc.dts
@@ -136,7 +136,7 @@
  {
status = "okay";
 
-   ehrpwm1: pwm@48302200 {
+   ehrpwm1: pwm@200 {
pinctrl-names = "default";
pinctrl-0 = <_pins>;
status = "okay";
diff --git a/arch/arm/dts/am33xx-clocks.dtsi b/arch/arm/dts/am33xx-clocks.dtsi
index 95d5c9d136..87c4410ee2 100644
--- a/arch/arm/dts/am33xx-clocks.dtsi
+++ 

[PATCH v4 02/27] dt-bindings: bus: ti-sysc: resync with Linux 5.9-rc7

2020-10-19 Thread Dario Binacchi
Add support for PRUSS SYSC type:
The PRUSS module has a SYSCFG which is unique. The SYSCFG has two
additional unique fields called STANDBY_INIT and SUB_MWAIT in addition
to regular IDLE_MODE and STANDBY_MODE fields. Add the bindings for this
new sysc type.

Add support for MCAN on dra76x:
The dra76x MCAN generic interconnect module has a its own format for the
bits in the control registers.

Signed-off-by: Dario Binacchi 
---

(no changes since v1)

 include/dt-bindings/bus/ti-sysc.h | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/include/dt-bindings/bus/ti-sysc.h 
b/include/dt-bindings/bus/ti-sysc.h
index 2c005376ac..eae4274543 100644
--- a/include/dt-bindings/bus/ti-sysc.h
+++ b/include/dt-bindings/bus/ti-sysc.h
@@ -15,6 +15,12 @@
 /* SmartReflex sysc found on 36xx and later */
 #define SYSC_OMAP3_SR_ENAWAKEUP(1 << 26)
 
+#define SYSC_DRA7_MCAN_ENAWAKEUP   (1 << 4)
+
+/* PRUSS sysc found on AM33xx/AM43xx/AM57xx */
+#define SYSC_PRUSS_SUB_MWAIT   (1 << 5)
+#define SYSC_PRUSS_STANDBY_INIT(1 << 4)
+
 /* SYSCONFIG STANDBYMODE/MIDLEMODE/SIDLEMODE supported by hardware */
 #define SYSC_IDLE_FORCE0
 #define SYSC_IDLE_NO   1
-- 
2.17.1



[PATCH v4 03/27] bus: ti: add minimal sysc interconnect target driver

2020-10-19 Thread Dario Binacchi
We can handle the sysc interconnect target module in a generic way for
many TI SoCs. Initially let's just enable domain clocks before the
children are probed.

The code is loosely based on the drivers/bus/ti-sysc.c of the Linux
kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/bus/ti-sysc.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

 arch/arm/Kconfig  |   1 +
 drivers/bus/Kconfig   |   7 ++
 drivers/bus/Makefile  |   1 +
 drivers/bus/ti-sysc.c | 166 ++
 4 files changed, 175 insertions(+)
 create mode 100644 drivers/bus/ti-sysc.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 80f09601e4..7c9e7b3d2e 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -799,6 +799,7 @@ config ARCH_OMAP2PLUS
select SPL_BOARD_INIT if SPL
select SPL_STACK_R if SPL
select SUPPORT_SPL
+   select TI_SYSC
imply FIT
 
 config ARCH_MESON
diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index 07a33c6287..733bec5a56 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -5,6 +5,13 @@
 
 menu "Bus devices"
 
+config TI_SYSC
+   bool "TI sysc interconnect target module driver"
+   depends on ARCH_OMAP2PLUS
+   help
+ Generic driver for Texas Instruments interconnect target module
+ found on many TI SoCs.
+
 config UNIPHIER_SYSTEM_BUS
bool "UniPhier System Bus driver"
depends on ARCH_UNIPHIER
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index 0b97fc1f8b..875bb4ed42 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -3,4 +3,5 @@
 # Makefile for the bus drivers.
 #
 
+obj-$(CONFIG_TI_SYSC)  += ti-sysc.o
 obj-$(CONFIG_UNIPHIER_SYSTEM_BUS) += uniphier-system-bus.o
diff --git a/drivers/bus/ti-sysc.c b/drivers/bus/ti-sysc.c
new file mode 100644
index 00..65974a70a6
--- /dev/null
+++ b/drivers/bus/ti-sysc.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments sysc interconnect target driver
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+enum ti_sysc_clocks {
+   TI_SYSC_FCK,
+   TI_SYSC_ICK,
+   TI_SYSC_MAX_CLOCKS,
+};
+
+static const char *const clock_names[] = {"fck", "ick"};
+
+struct ti_sysc_priv {
+   int clocks_count;
+   struct clk clocks[TI_SYSC_MAX_CLOCKS];
+};
+
+static const struct udevice_id ti_sysc_ids[] = {
+   {.compatible = "ti,sysc-omap2"},
+   {.compatible = "ti,sysc-omap4"},
+   {.compatible = "ti,sysc-omap4-simple"},
+   {.compatible = "ti,sysc-omap3430-sr"},
+   {.compatible = "ti,sysc-omap3630-sr"},
+   {.compatible = "ti,sysc-omap4-sr"},
+   {.compatible = "ti,sysc-omap3-sham"},
+   {.compatible = "ti,sysc-omap-aes"},
+   {.compatible = "ti,sysc-mcasp"},
+   {.compatible = "ti,sysc-usb-host-fs"},
+   {}
+};
+
+static int ti_sysc_get_one_clock(struct udevice *dev, enum ti_sysc_clocks 
index)
+{
+   struct ti_sysc_priv *priv = dev_get_priv(dev);
+   const char *name;
+   int err;
+
+   switch (index) {
+   case TI_SYSC_FCK:
+   break;
+   case TI_SYSC_ICK:
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   name = clock_names[index];
+
+   err = clk_get_by_name(dev, name, >clocks[index]);
+   if (err) {
+   if (err == -ENODATA)
+   return 0;
+
+   dev_err(dev, "failed to get %s clock\n", name);
+   return err;
+   }
+
+   return 0;
+}
+
+static int ti_sysc_put_clocks(struct udevice *dev)
+{
+   struct ti_sysc_priv *priv = dev_get_priv(dev);
+   int err;
+
+   err = clk_release_all(priv->clocks, priv->clocks_count);
+   if (err)
+   dev_err(dev, "failed to release all clocks\n");
+
+   return err;
+}
+
+static int ti_sysc_get_clocks(struct udevice *dev)
+{
+   struct ti_sysc_priv *priv = dev_get_priv(dev);
+   int i, err;
+
+   for (i = 0; i < TI_SYSC_MAX_CLOCKS; i++) {
+   err = ti_sysc_get_one_clock(dev, i);
+   if (!err)
+   priv->clocks_count++;
+   else if (err != -ENOENT)
+   return err;
+   }
+
+   return 0;
+}
+
+static int ti_sysc_child_post_remove(struct udevice *dev)
+{
+   struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
+   int i, err;
+
+   for (i = 0; i < priv->clocks_count; i++) {
+   err = clk_disable(>clocks[i]);
+   if (err) {
+   dev_err(dev->parent, "failed to disable %s clock\n",
+   clock_names[i]);
+   return err;
+   }
+   }
+
+   return 0;
+}
+
+static int ti_sysc_child_pre_probe(struct udevice *dev)
+{
+   struct ti_sysc_priv *priv = dev_get_priv(dev->parent);
+   int i, 

[PATCH v3 1/2] dm: core: add function uclass_probe_all() to probe all devices

2020-10-19 Thread Vabhav Sharma
From: Vabhav Sharma 

Support a common method to probe all devices associated with uclass.

This includes data structures and code for finding the first device and
looping for remaining devices associated with uclasses (groups of devices
with the same purpose, e.g. all SERIAL ports will be in the same uclass).

An example is SBSA compliant PL011 UART IP, where firmware does the serial
port initialization and prepare uart device to let the kernel use it for
sending and reveiving the characters.SERIAL uclass will use this function
to initialize PL011 UART ports.

The feature is enabled with CONFIG_DM.

Signed-off-by: Vabhav Sharma 
Reviewed-by: Stefan Roese 
--
  v3:
  Incorporated review comments of Stephan,Simon
  Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400
385-11854-1-git-send-email-vabhav.sha...@oss.nxp.com/
---
 drivers/core/uclass.c | 17 +
 include/dm/uclass.h   | 12 
 2 files changed, 29 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73..0725e8e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
 }
 #endif
 
+int uclass_probe_all(enum uclass_id id)
+{
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_first_device(id, );
+   if (ret || !dev)
+   return ret;
+   if (dev) {
+   /* Scanning uclass to probe all devices */
+   for (; dev; uclass_next_device())
+   ;
+   }
+
+   return 0;
+}
+
 UCLASS_DRIVER(nop) = {
.id = UCLASS_NOP,
.name   = "nop",
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 67ff746..0fce83f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong 
driver_data,
 int uclass_resolve_seq(struct udevice *dev);
 
 /**
+ * uclass_probe_all() - Probe all devices based on an uclass ID
+ *
+ * Every uclass is identified by an ID, a number from 0 to n-1 where n is
+ * the number of uclasses. This function probe all devices asocciated with
+ * a uclass by looking its ID.
+ *
+ * @id: uclass ID to look up
+ * @return 0 if OK, other -ve on error
+ */
+int uclass_probe_all(enum uclass_id id);
+
+/**
  * uclass_id_foreach_dev() - Helper function to iteration through devices
  *
  * This creates a for() loop which works through the available devices in
-- 
2.7.4



[PATCH v3 0/2] dm: core: drivers: add function uclass_probe_all()

2020-10-19 Thread Vabhav Sharma
From: Vabhav Sharma 

- Add common method to probe devices belonging to same uclass 
- Add config in serial uclass to support optional inclusion of uclass_probe_all
- Enable support for available serial devices probe

Changes for v3:
  Incorporated Simon and Stephan review comment
  - Define generic function uclass_probe_all(enum uclass_id)
in drivers/core/uclass.c
  - Added the function in caller of serial_find_console_or_panic()
  - Removed repeated sequence with generic function call uclass_probe_all()
 
Changes for v2:
  Incorporated Stefan review comment,Update #ifdef with macro if (IS_ENABLED).

Vabhav Sharma (2):
  dm: core: add function uclass_probe_all() to probe all devices
  drivers: serial: probe all uart devices

 drivers/core/uclass.c  | 17 +
 drivers/serial/Kconfig | 17 +
 drivers/serial/serial-uclass.c |  4 
 include/dm/uclass.h| 12 
 4 files changed, 50 insertions(+)

-- 
2.7.4



[PATCH v4 00/27] Add DM support for omap PWM backlight

2020-10-19 Thread Dario Binacchi


The series was born from the need to manage the PWM backlight of the
display connected to my beaglebone board. To hit the target, I had to
develop drivers for PWM management which in turn relied on drivers for
managing timers and clocks, all developed according to the driver model.
My intention was to use the SoC-specific API only at strictly necessary
points in the code. My previous patches for migrating the AM335x display
driver to the driver model had required the implementation of additional
functions outside the concerns of the driver, (settings for dividing the
pixel clock rate, configuring the display DPLL rate, ) not being
able to use the API of the related clock drivers. This series shouldn't
have repeated the same kind of mistake. Furthermore, I also wanted to fix
that kind of forced choice. Almost everything should have been accessible
via the driver model API. In the series there are also some patches that
could be submitted separately, but which I have however inserted to avoid
applying future patches to incorporate them.
With this last consideration, I hope I have convincingly justified the
large number of patches in the series.

The patch enabling address translation into a CPU physical address from
device-tree even in case of crossing levels with #size-cells = <0>, is
crucial for the series. The previous implementation was unable to
perform the address translation required by the am33xx device tree.
I tried to apply in a conservative way as few changes as possible and
to verify the execution of all the tests already developed, as well as
the new ones I added for the new feature.

The patch series can be cleanly applied to the HEAD of the master which
at the time of release points to 3d19a7ee8c commit.

Changes in v4:
- Include device_compat.h header for dev_xxx macros.
- Remove a blank line at end of file arch/arm/dts/am33xx-l4.dtsi.
- Update clk_round_rate description.
- Add Sean Anderson review.
- Include device_compat.h header for dev_xxx macros.
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.
- Include device_compat.h header for dev_xxx macros.
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.
- Include device_compat.h header for dev_xxx macros.
- Add Sphinx documentation for dm_flags.
- Convert GD_DM_FLG_* to enum.
- Include device_compat.h header in test/dm/test-fdt.c for dev_xxx macros.
- Include device_compat.h header for dev_xxx macros.
- Include device_compat.h header for dev_xxx macros.
- Include device_compat.h header for dev_xxx macros.
- Add Simon Glass review.
- Include device_compat.h header for dev_xxx macros.

Changes in v3:
- Remove doc/device-tree-bindings/clock/clock-bindings.txt.
- Remove doc/device-tree-bindings/clock/ti,mux.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Remove doc/device-tree-bindings/clock/ti,dpll.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Remove doc/device-tree-bindings/clock/ti,autoidle.txt.
- Remove doc/device-tree-bindings/clock/ti,divider.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Remove doc/device-tree-bindings/clock/gpio-gate-clock.txt.
- Remove doc/device-tree-bindings/clock/ti,clockdomain.txt.
- Remove doc/device-tree-bindings/clock/ti,gate.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Fix access to registers listed by device tree following resync of
  am33xx-clock.dtsi with Linux 5.9-rc7.
- Remove doc/device-tree-bindings/clock/ti,clkctrl.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- doc/device-tree-bindings/arm/omap,prcm.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Comment dm_flags field in the global_data structure.
- Remove doc/device-tree-bindings/arm/omap,ctrl.txt.
- Remove doc/device-tree-bindings/pinctrl/pinctrl-single.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Adds PWM_TI_EHRPWM dependency on ARCH_OMAP2PLUS in Kconfig.
- Add error message in case of invalid address.
- Remove doc/device-tree-bindings/pwm/ti,ehrpwm.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.
- Move Kconfig symbol from drivers/pwm to drivers/bus.
- Remove the domain clock reference from the pwmss nodes of the device
  tree in am33xx.dtsi. The resync of am33xx.dtsi with Linux 5.9-rc7
  already contains such references.
- Remove domain clock enabling/disabling. Enabling the domain clock is
  performed by the sysc interconnect target module driver during the pwm
  

[PATCH v3 2/2] drivers: serial: probe all uart devices

2020-10-19 Thread Vabhav Sharma
From: Vabhav Sharma 

U-Boot DM model probe only single device at a time
which is enabled and configured using device tree
or platform data method.

PL011 UART IP is SBSA compliant and firmware does the
serial port set-up, initialization and let the kernel use
UART port for sending and receiving characters.

Normally software talk to one serial port time but some
LayerScape platform require all the UART devices enabled
in Linux for various use case.

Adding support to probe all enabled serial devices like SBSA
compliant PL011 UART ports probe and initialization by firmware.

Signed-off-by: Vabhav Sharma 
Reviewed-by: Stefan Roese 
--
v3:
  Incorporated Simon and Stephan review comment
  - Define generic function uclass_probe_all(enum uclass_id)
in drivers/core/uclass.c
  - Added the function in caller of serial_find_console_or_panic()
  - Removed repeated sequence with generic function call uclass_probe_all()
  - Dependent on other patch [PATCH] dm: core: add function uclass_probe_all()
to probe all devices

v2:
  Incorporated Stefan review comment, Update #ifdef with macro
  if (IS_ENABLED)..
---
 drivers/serial/Kconfig | 17 +
 drivers/serial/serial-uclass.c |  4 
 2 files changed, 21 insertions(+)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index b4805a2..af8779b 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -134,6 +134,23 @@ config SERIAL_SEARCH_ALL
 
  If unsure, say N.
 
+config SERIAL_PROBE_ALL
+   bool "Probe all available serial devices"
+   depends on DM_SERIAL
+   default n
+   help
+ The serial subsystem only probe for single serial device,
+ but does not probe for other remaining serial devices.
+ With this option set,we make probing and searching for
+ all available devices optional.
+ Normally, U-Boot talk to one serial port at a time but SBSA
+ compliant UART devices like PL011 require initialization
+ by firmware and let the kernel use serial port for sending
+ and receiving the characters.
+
+ If probing is not required for all remaining available
+ devices other than default current console device, say N.
+
 config SPL_DM_SERIAL
bool "Enable Driver Model for serial drivers in SPL"
depends on DM_SERIAL && SPL_DM
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 0027625..09bc6f4 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -172,6 +172,10 @@ int serial_init(void)
 /* Called after relocation */
 int serial_initialize(void)
 {
+   /* Scanning uclass to probe devices */
+   if (IS_ENABLED(CONFIG_SERIAL_PROBE_ALL))
+   uclass_probe_all(UCLASS_SERIAL);
+
return serial_init();
 }
 
-- 
2.7.4



[PATCH v4 12/27] clk: ti: add support for clkctrl clocks

2020-10-19 Thread Dario Binacchi
Until now the clkctrl clocks have been enabled/disabled through platform
routines. Thanks to this patch they can be enabled and configured directly
by the probed devices that need to use them.

For DT binding details see Linux doc:
- Documentation/devicetree/bindings/clock/ti-clkctrl.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.

Changes in v3:
- Fix access to registers listed by device tree following resync of
  am33xx-clock.dtsi with Linux 5.9-rc7.
- Remove doc/device-tree-bindings/clock/ti,clkctrl.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/clk/Kconfig   |   6 ++
 drivers/clk/Makefile  |   1 +
 drivers/clk/clk-ti-ctrl.c | 154 ++
 3 files changed, 161 insertions(+)
 create mode 100644 drivers/clk/clk-ti-ctrl.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 480ffc7d9c..f383e295d3 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -105,6 +105,12 @@ config CLK_TI_AM3_DPLL
  This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
  provides all interface clocks and functional clocks to the processor.
 
+config CLK_TI_CTRL
+   bool "TI OMAP4 clock controller"
+   depends on CLK && OF_CONTROL
+   help
+ This enables the clock controller driver support on TI's SoCs.
+
 config CLK_TI_DIVIDER
bool "TI divider clock driver"
depends on CLK && OF_CONTROL && CLK_CCF
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 809672e92e..c98aa27e71 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -49,6 +49,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
+obj-$(CONFIG_CLK_TI_CTRL) += clk-ti-ctrl.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
 obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
diff --git a/drivers/clk/clk-ti-ctrl.c b/drivers/clk/clk-ti-ctrl.c
new file mode 100644
index 00..74271aaf56
--- /dev/null
+++ b/drivers/clk/clk-ti-ctrl.c
@@ -0,0 +1,154 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * OMAP clock controller support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct clk_ti_ctrl_offs {
+   fdt_addr_t start;
+   fdt_size_t end;
+};
+
+struct clk_ti_ctrl_priv {
+   int offs_num;
+   struct clk_ti_ctrl_offs *offs;
+};
+
+static int clk_ti_ctrl_check_offs(struct clk *clk, fdt_addr_t offs)
+{
+   struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev);
+   int i;
+
+   for (i = 0; i < priv->offs_num; i++) {
+   if (offs >= priv->offs[i].start && offs <= priv->offs[i].end)
+   return 0;
+   }
+
+   return -EFAULT;
+}
+
+static int clk_ti_ctrl_disable(struct clk *clk)
+{
+   struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev);
+   u32 *clk_modules[2] = { };
+   fdt_addr_t offs;
+   int err;
+
+   offs = priv->offs[0].start + clk->id;
+   err = clk_ti_ctrl_check_offs(clk, offs);
+   if (err) {
+   dev_err(clk->dev, "invalid offset: 0x%lx\n", offs);
+   return err;
+   }
+
+   clk_modules[0] = (u32 *)(offs);
+   dev_dbg(clk->dev, "module address=%p\n", clk_modules[0]);
+   do_disable_clocks(NULL, clk_modules, 1);
+   return 0;
+}
+
+static int clk_ti_ctrl_enable(struct clk *clk)
+{
+   struct clk_ti_ctrl_priv *priv = dev_get_priv(clk->dev);
+   u32 *clk_modules[2] = { };
+   fdt_addr_t offs;
+   int err;
+
+   offs = priv->offs[0].start + clk->id;
+   err = clk_ti_ctrl_check_offs(clk, offs);
+   if (err) {
+   dev_err(clk->dev, "invalid offset: 0x%lx\n", offs);
+   return err;
+   }
+
+   clk_modules[0] = (u32 *)(offs);
+   dev_dbg(clk->dev, "module address=%p\n", clk_modules[0]);
+   do_enable_clocks(NULL, clk_modules, 1);
+   return 0;
+}
+
+static ulong clk_ti_ctrl_get_rate(struct clk *clk)
+{
+   return 0;
+}
+
+static int clk_ti_ctrl_of_xlate(struct clk *clk,
+   struct ofnode_phandle_args *args)
+{
+   if (args->args_count != 2) {
+   dev_err(clk->dev, "invaild args_count: %d\n", args->args_count);
+   return -EINVAL;
+   }
+
+   if (args->args_count)
+   clk->id = args->args[0];
+   else
+   clk->id = 0;
+
+   dev_dbg(clk->dev, "name=%s, id=%ld\n", clk->dev->name, clk->id);
+   return 0;
+}
+
+static int clk_ti_ctrl_ofdata_to_platdata(struct udevice *dev)
+{
+   struct clk_ti_ctrl_priv *priv = dev_get_priv(dev);
+   fdt_size_t fdt_size;
+   int i, size;
+
+   size = 

[PATCH v4 07/27] arm: ti: am33xx: add DPLL_EN_FAST_RELOCK_BYPASS macro

2020-10-19 Thread Dario Binacchi
Add missing DPLL_EN_FAST_RELOCK_BYPASS macro. Used to put the DPLL in
idle bypass fast relock mode.

Signed-off-by: Dario Binacchi 
---

(no changes since v1)

 arch/arm/include/asm/arch-am33xx/clock.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/include/asm/arch-am33xx/clock.h 
b/arch/arm/include/asm/arch-am33xx/clock.h
index dc7a9b188d..5d775902bb 100644
--- a/arch/arm/include/asm/arch-am33xx/clock.h
+++ b/arch/arm/include/asm/arch-am33xx/clock.h
@@ -66,6 +66,7 @@
 #define DPLL_EN_STOP   1
 #define DPLL_EN_MN_BYPASS  4
 #define DPLL_EN_LOW_POWER_BYPASS   5
+#define DPLL_EN_FAST_RELOCK_BYPASS 6
 #define DPLL_EN_LOCK   7
 
 /* CM_IDLEST_DPLL fields */
-- 
2.17.1



[PATCH v4 08/27] clk: ti: am33xx: add DPLL clock drivers

2020-10-19 Thread Dario Binacchi
The digital phase-locked loop (DPLL) provides all interface clocks and
functional clocks to the processor of the AM33xx device. The AM33xx
device integrates five different DPLLs:
 * Core DPLL
 * Per DPLL
 * LCD DPLL
 * DDR DPLL
 * MPU DPLL

The patch adds support for the compatible strings:
 * "ti,am3-dpll-core-clock"
 * "ti,am3-dpll-no-gate-clock"
 * "ti,am3-dpll-no-gate-j-type-clock"
 * "ti,am3-dpll-x2-clock"

The code is loosely based on the drivers/clk/ti/dpll.c drivers of the
Linux kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/clock/ti/dpll.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.

Changes in v3:
- Remove doc/device-tree-bindings/clock/ti,dpll.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/clk/Kconfig  |   7 +
 drivers/clk/Makefile |   1 +
 drivers/clk/clk-ti-am3-dpll-x2.c |  79 +
 drivers/clk/clk-ti-am3-dpll.c| 268 +++
 4 files changed, 355 insertions(+)
 create mode 100644 drivers/clk/clk-ti-am3-dpll-x2.c
 create mode 100644 drivers/clk/clk-ti-am3-dpll.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 85fb337150..301ecac652 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -98,6 +98,13 @@ config CLK_STM32F
  This clock driver adds support for RCC clock management
  for STM32F4 and STM32F7 SoCs.
 
+config CLK_TI_AM3_DPLL
+   bool "TI AM33XX Digital Phase-Locked Loop (DPLL) clock drivers"
+   depends on CLK && OF_CONTROL
+   help
+ This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
+ provides all interface clocks and functional clocks to the processor.
+
 config CLK_TI_MUX
bool "TI mux clock driver"
depends on CLK && OF_CONTROL && CLK_CCF
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5582e8df04..f1eaae03c5 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
+obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
diff --git a/drivers/clk/clk-ti-am3-dpll-x2.c b/drivers/clk/clk-ti-am3-dpll-x2.c
new file mode 100644
index 00..3aa35f0e6c
--- /dev/null
+++ b/drivers/clk/clk-ti-am3-dpll-x2.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI DPLL x2 clock support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Loosely based on Linux kernel drivers/clk/ti/dpll.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct clk_ti_am3_dpll_x2_priv {
+   struct clk parent;
+};
+
+static ulong clk_ti_am3_dpll_x2_get_rate(struct clk *clk)
+{
+   struct clk_ti_am3_dpll_x2_priv *priv = dev_get_priv(clk->dev);
+   unsigned long rate;
+
+   rate = clk_get_rate(>parent);
+   if (IS_ERR_VALUE(rate))
+   return rate;
+
+   rate *= 2;
+   dev_dbg(clk->dev, "rate=%ld\n", rate);
+   return rate;
+}
+
+const struct clk_ops clk_ti_am3_dpll_x2_ops = {
+   .get_rate = clk_ti_am3_dpll_x2_get_rate,
+};
+
+static int clk_ti_am3_dpll_x2_remove(struct udevice *dev)
+{
+   struct clk_ti_am3_dpll_x2_priv *priv = dev_get_priv(dev);
+   int err;
+
+   err = clk_release_all(>parent, 1);
+   if (err) {
+   dev_err(dev, "failed to release parent clock\n");
+   return err;
+   }
+
+   return 0;
+}
+
+static int clk_ti_am3_dpll_x2_probe(struct udevice *dev)
+{
+   struct clk_ti_am3_dpll_x2_priv *priv = dev_get_priv(dev);
+   int err;
+
+   err = clk_get_by_index(dev, 0, >parent);
+   if (err) {
+   dev_err(dev, "%s: failed to get parent clock\n", __func__);
+   return err;
+   }
+
+   return 0;
+}
+
+static const struct udevice_id clk_ti_am3_dpll_x2_of_match[] = {
+   {.compatible = "ti,am3-dpll-x2-clock"},
+   {}
+};
+
+U_BOOT_DRIVER(clk_ti_am3_dpll_x2) = {
+   .name = "ti_am3_dpll_x2_clock",
+   .id = UCLASS_CLK,
+   .of_match = clk_ti_am3_dpll_x2_of_match,
+   .probe = clk_ti_am3_dpll_x2_probe,
+   .remove = clk_ti_am3_dpll_x2_remove,
+   .priv_auto_alloc_size = sizeof(struct clk_ti_am3_dpll_x2_priv),
+   .ops = _ti_am3_dpll_x2_ops,
+};
diff --git a/drivers/clk/clk-ti-am3-dpll.c b/drivers/clk/clk-ti-am3-dpll.c
new file mode 100644
index 00..d50660aae2
--- /dev/null
+++ b/drivers/clk/clk-ti-am3-dpll.c
@@ -0,0 +1,268 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI DPLL clock support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Loosely based on Linux kernel 

[PATCH v4 06/27] clk: ti: add mux clock driver

2020-10-19 Thread Dario Binacchi
The driver manages a register-mapped multiplexer with multiple input
clock signals or parents, one of which can be selected as output. It
uses routines provided by the common clock framework (ccf).

The code is based on the drivers/clk/ti/mux.c driver of the Linux
kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/clock/ti/mux.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

Changes in v3:
- Remove doc/device-tree-bindings/clock/clock-bindings.txt.
- Remove doc/device-tree-bindings/clock/ti,mux.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/clk/Kconfig  |   6 +
 drivers/clk/Makefile |   1 +
 drivers/clk/clk-ti-mux.c | 276 +++
 3 files changed, 283 insertions(+)
 create mode 100644 drivers/clk/clk-ti-mux.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 4dfbad7986..85fb337150 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -98,6 +98,12 @@ config CLK_STM32F
  This clock driver adds support for RCC clock management
  for STM32F4 and STM32F7 SoCs.
 
+config CLK_TI_MUX
+   bool "TI mux clock driver"
+   depends on CLK && OF_CONTROL && CLK_CCF
+   help
+ This enables the mux clock driver support on TI's SoCs.
+
 config CLK_TI_SCI
bool "TI System Control Interface (TI SCI) clock driver"
depends on CLK && TI_SCI_PROTOCOL && OF_CONTROL
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index d1e295ac7c..5582e8df04 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -47,6 +47,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox.o
 obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
+obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
 obj-$(CONFIG_CLK_CDCE9XX) += clk-cdce9xx.o
diff --git a/drivers/clk/clk-ti-mux.c b/drivers/clk/clk-ti-mux.c
new file mode 100644
index 00..9720c84513
--- /dev/null
+++ b/drivers/clk/clk-ti-mux.c
@@ -0,0 +1,276 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI multiplexer clock support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Based on Linux kernel drivers/clk/ti/mux.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct clk_ti_mux_priv {
+   struct clk_bulk parents;
+   fdt_addr_t reg;
+   u32 flags;
+   u32 mux_flags;
+   u32 mask;
+   u32 shift;
+   s32 latch;
+};
+
+static void clk_ti_mux_rmw(u32 val, u32 mask, fdt_addr_t reg)
+{
+   u32 v;
+
+   v = readl(reg);
+   v &= ~mask;
+   v |= val;
+   writel(v, reg);
+}
+
+static void clk_ti_mux_latch(fdt_addr_t reg, s8 shift)
+{
+   u32 latch;
+
+   if (shift < 0)
+   return;
+
+   latch = 1 << shift;
+
+   clk_ti_mux_rmw(latch, latch, reg);
+   clk_ti_mux_rmw(0, latch, reg);
+   readl(reg); /* OCP barrier */
+}
+
+static struct clk *clk_ti_mux_get_parent_by_index(struct clk_bulk *parents,
+ int index)
+{
+   if (index < 0 || !parents)
+   return ERR_PTR(-EINVAL);
+
+   if (index >= parents->count)
+   return ERR_PTR(-ENODEV);
+
+   return >clks[index];
+}
+
+static int clk_ti_mux_get_parent_index(struct clk_bulk *parents,
+  struct clk *parent)
+{
+   int i;
+
+   if (!parents || !parent)
+   return -EINVAL;
+
+   for (i = 0; i < parents->count; i++) {
+   if (parents->clks[i].dev == parent->dev)
+   return i;
+   }
+
+   return -ENODEV;
+}
+
+static int clk_ti_mux_get_index(struct clk *clk)
+{
+   struct clk_ti_mux_priv *priv = dev_get_priv(clk->dev);
+   u32 val;
+
+   val = readl(priv->reg);
+   val >>= priv->shift;
+   val &= priv->mask;
+
+   if (val && (priv->flags & CLK_MUX_INDEX_BIT))
+   val = ffs(val) - 1;
+
+   if (val && (priv->flags & CLK_MUX_INDEX_ONE))
+   val--;
+
+   if (val >= priv->parents.count)
+   return -EINVAL;
+
+   return val;
+}
+
+static int clk_ti_mux_set_parent(struct clk *clk, struct clk *parent)
+{
+   struct clk_ti_mux_priv *priv = dev_get_priv(clk->dev);
+   int index;
+   u32 val;
+
+   index = clk_ti_mux_get_parent_index(>parents, parent);
+   if (index < 0) {
+   dev_err(clk->dev, "failed to get parent clock\n");
+   return index;
+   }
+
+   index = clk_mux_index_to_val(NULL, priv->flags, index);
+
+   if (priv->flags & CLK_MUX_HIWORD_MASK) {
+   val = priv->mask << (priv->shift + 16);
+   } else {
+   val = readl(priv->reg);
+   val &= ~(priv->mask << priv->shift);
+   }
+
+   

[PATCH v4 11/27] ti: am33xx: fix do_enable_clocks() to accept NULL parameters

2020-10-19 Thread Dario Binacchi
Up till this commit passing NULL as input parameter was allowed, but not
handled properly. When a NULL parameter was passed to the function a data
abort was raised.

Signed-off-by: Dario Binacchi 
Reviewed-by: Simon Glass 
---

(no changes since v1)

 arch/arm/mach-omap2/am33xx/clock.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-omap2/am33xx/clock.c 
b/arch/arm/mach-omap2/am33xx/clock.c
index 8819062aaa..130ee6c6e3 100644
--- a/arch/arm/mach-omap2/am33xx/clock.c
+++ b/arch/arm/mach-omap2/am33xx/clock.c
@@ -194,13 +194,14 @@ void do_enable_clocks(u32 *const *clk_domains,
u32 i, max = 100;
 
/* Put the clock domains in SW_WKUP mode */
-   for (i = 0; (i < max) && clk_domains[i]; i++) {
+   for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++) {
enable_clock_domain(clk_domains[i],
CD_CLKCTRL_CLKTRCTRL_SW_WKUP);
}
 
/* Clock modules that need to be put in SW_EXPLICIT_EN mode */
-   for (i = 0; (i < max) && clk_modules_explicit_en[i]; i++) {
+   for (i = 0; (i < max) && clk_modules_explicit_en &&
+clk_modules_explicit_en[i]; i++) {
enable_clock_module(clk_modules_explicit_en[i],
MODULE_CLKCTRL_MODULEMODE_SW_EXPLICIT_EN,
wait_for_enable);
@@ -215,12 +216,13 @@ void do_disable_clocks(u32 *const *clk_domains,
 
 
/* Clock modules that need to be put in SW_DISABLE */
-   for (i = 0; (i < max) && clk_modules_disable[i]; i++)
+   for (i = 0; (i < max) && clk_modules_disable && clk_modules_disable[i];
+i++)
disable_clock_module(clk_modules_disable[i],
 wait_for_disable);
 
/* Put the clock domains in SW_SLEEP mode */
-   for (i = 0; (i < max) && clk_domains[i]; i++)
+   for (i = 0; (i < max) && clk_domains && clk_domains[i]; i++)
disable_clock_domain(clk_domains[i]);
 }
 
-- 
2.17.1



RE: [PATCH] dm: core: add function uclass_probe_all() to probe all devices

2020-10-19 Thread Vabhav Sharma (OSS)


> -Original Message-
> From: Stefan Roese 
> Sent: Monday, October 19, 2020 3:40 PM
> To: Vabhav Sharma (OSS) ; u-
> b...@lists.denx.de; s...@chromium.org
> Cc: Varun Sethi ; andre.przyw...@arm.com; Vabhav
> Sharma 
> Subject: Re: [PATCH] dm: core: add function uclass_probe_all() to probe all
> devices
> 
> On 19.10.20 11:37, Vabhav Sharma wrote:
> > From: Vabhav Sharma 
> >
> > Support a common method to probe all devices associated with uclass.
> >
> > This includes data structures and code for finding the first device
> > and looping for remaining devices associated with uclasses (groups of
> > devices with the same purpose, e.g. all SERIAL ports will be in the same
> uclass).
> >
> > An example is SBSA compliant PL011 UART IP, where firmware does the
> > serial port initialization and prepare uart device to let the kernel
> > use it for sending and reveiving the characters.SERIAL uclass will use
> > this function to initialize PL011 UART ports.
> >
> > The feature is enabled with CONFIG_DM.
> >
> > Signed-off-by: Vabhav Sharma 
> > --
> >Related discussion
> > https://patchwork.ozlabs.org/project/uboot/patch/1601400
> > 385-11854-1-git-send-email-vabhav.sha...@oss.nxp.com/
> > ---
> >   drivers/core/uclass.c | 17 +
> >   include/dm/uclass.h   | 12 
> >   2 files changed, 29 insertions(+)
> >
> > diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index
> > c3f1b73..0725e8e 100644
> > --- a/drivers/core/uclass.c
> > +++ b/drivers/core/uclass.c
> > @@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
> >   }
> >   #endif
> >
> > +int uclass_probe_all(enum uclass_id id) {
> > +   struct udevice *dev;
> > +   int ret;
> > +
> > +   ret = uclass_first_device(id, );
> > +   if (ret || !dev)
> > +   return ret;
> > +   if (dev) {
> > +   /* Scanning uclass to probe all devices */
> > +   for (; dev; uclass_next_device())
> > +   ;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >   UCLASS_DRIVER(nop) = {
> > .id = UCLASS_NOP,
> > .name   = "nop",
> > diff --git a/include/dm/uclass.h b/include/dm/uclass.h index
> > 67ff746..0fce83f 100644
> > --- a/include/dm/uclass.h
> > +++ b/include/dm/uclass.h
> > @@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id,
> ulong driver_data,
> >   int uclass_resolve_seq(struct udevice *dev);
> >
> >   /**
> > + * uclass_probe_all() - Probe all devices based on an uclass ID
> > + *
> > + * Every uclass is identified by an ID, a number from 0 to n-1 where
> > +n is
> > + * the number of uclasses. This function probe all devices asocciated
> > +with
> > + * a uclass by looking its ID.
> > + *
> > + * @id: uclass ID to look up
> > + * @return 0 if OK, other -ve on error  */ int uclass_probe_all(enum
> > +uclass_id id);
> > +
> > +/**
> >* uclass_id_foreach_dev() - Helper function to iteration through devices
> >*
> >* This creates a for() loop which works through the available
> > devices in
> >
> 
> Ahh, here is the function. You should better move both patches into one
> patchset, so that the dependency can be seen. Especially while applying.
Sure.
> 
> Other that that:
> 
> Reviewed-by: Stefan Roese 
> 
> Thanks,
> Stefan


[PATCH v4 19/27] pwm: ti: am33xx: add enhanced pwm driver

2020-10-19 Thread Dario Binacchi
Enhanced high resolution PWM module (EHRPWM) hardware can be used to
generate PWM output over 2 channels. This commit adds PWM driver support
for EHRPWM device present on AM33XX SOC.

The code is based on the drivers/pwm/pwm-tiehrpwm.c driver of the Linux
kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/pwm/pwm-tiehrpwm.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

Changes in v3:
- Adds PWM_TI_EHRPWM dependency on ARCH_OMAP2PLUS in Kconfig.
- Add error message in case of invalid address.
- Remove doc/device-tree-bindings/pwm/ti,ehrpwm.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/pwm/Kconfig |   7 +
 drivers/pwm/Makefile|   1 +
 drivers/pwm/pwm-ti-ehrpwm.c | 468 
 3 files changed, 476 insertions(+)
 create mode 100644 drivers/pwm/pwm-ti-ehrpwm.c

diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig
index b3bd5c6bb7..ccf81abbe9 100644
--- a/drivers/pwm/Kconfig
+++ b/drivers/pwm/Kconfig
@@ -75,3 +75,10 @@ config PWM_SUNXI
help
  This PWM is found on H3, A64 and other Allwinner SoCs. It supports a
  programmable period and duty cycle. A 16-bit counter is used.
+
+config PWM_TI_EHRPWM
+   bool "Enable support for EHRPWM PWM"
+   depends on DM_PWM && ARCH_OMAP2PLUS
+   default y
+   help
+ PWM driver support for the EHRPWM controller found on TI SOCs.
diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile
index f21ae7d76e..0b9d2698a3 100644
--- a/drivers/pwm/Makefile
+++ b/drivers/pwm/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_PWM_SANDBOX) += sandbox_pwm.o
 obj-$(CONFIG_PWM_SIFIVE)   += pwm-sifive.o
 obj-$(CONFIG_PWM_TEGRA)+= tegra_pwm.o
 obj-$(CONFIG_PWM_SUNXI)+= sunxi_pwm.o
+obj-$(CONFIG_PWM_TI_EHRPWM)+= pwm-ti-ehrpwm.o
diff --git a/drivers/pwm/pwm-ti-ehrpwm.c b/drivers/pwm/pwm-ti-ehrpwm.c
new file mode 100644
index 00..df995c8865
--- /dev/null
+++ b/drivers/pwm/pwm-ti-ehrpwm.c
@@ -0,0 +1,468 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * EHRPWM PWM driver
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Based on Linux kernel drivers/pwm/pwm-tiehrpwm.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define NSEC_PER_SEC   10L
+
+/* Time base module registers */
+#define TI_EHRPWM_TBCTL0x00
+#define TI_EHRPWM_TBPRD0x0A
+
+#define TI_EHRPWM_TBCTL_PRDLD_MASK BIT(3)
+#define TI_EHRPWM_TBCTL_PRDLD_SHDW 0
+#define TI_EHRPWM_TBCTL_PRDLD_IMDT BIT(3)
+#define TI_EHRPWM_TBCTL_CLKDIV_MASKGENMASK(12, 7)
+#define TI_EHRPWM_TBCTL_CTRMODE_MASK   GENMASK(1, 0)
+#define TI_EHRPWM_TBCTL_CTRMODE_UP 0
+#define TI_EHRPWM_TBCTL_CTRMODE_DOWN   BIT(0)
+#define TI_EHRPWM_TBCTL_CTRMODE_UPDOWN BIT(1)
+#define TI_EHRPWM_TBCTL_CTRMODE_FREEZE GENMASK(1, 0)
+
+#define TI_EHRPWM_TBCTL_HSPCLKDIV_SHIFT7
+#define TI_EHRPWM_TBCTL_CLKDIV_SHIFT   10
+
+#define TI_EHRPWM_CLKDIV_MAX   7
+#define TI_EHRPWM_HSPCLKDIV_MAX7
+#define TI_EHRPWM_PERIOD_MAX   0x
+
+/* Counter compare module registers */
+#define TI_EHRPWM_CMPA 0x12
+#define TI_EHRPWM_CMPB 0x14
+
+/* Action qualifier module registers */
+#define TI_EHRPWM_AQCTLA   0x16
+#define TI_EHRPWM_AQCTLB   0x18
+#define TI_EHRPWM_AQSFRC   0x1A
+#define TI_EHRPWM_AQCSFRC  0x1C
+
+#define TI_EHRPWM_AQCTL_CBU_MASK   GENMASK(9, 8)
+#define TI_EHRPWM_AQCTL_CBU_FRCLOW BIT(8)
+#define TI_EHRPWM_AQCTL_CBU_FRCHIGHBIT(9)
+#define TI_EHRPWM_AQCTL_CBU_FRCTOGGLE  GENMASK(9, 8)
+#define TI_EHRPWM_AQCTL_CAU_MASK   GENMASK(5, 4)
+#define TI_EHRPWM_AQCTL_CAU_FRCLOW BIT(4)
+#define TI_EHRPWM_AQCTL_CAU_FRCHIGHBIT(5)
+#define TI_EHRPWM_AQCTL_CAU_FRCTOGGLE  GENMASK(5, 4)
+#define TI_EHRPWM_AQCTL_PRD_MASK   GENMASK(3, 2)
+#define TI_EHRPWM_AQCTL_PRD_FRCLOW BIT(2)
+#define TI_EHRPWM_AQCTL_PRD_FRCHIGHBIT(3)
+#define TI_EHRPWM_AQCTL_PRD_FRCTOGGLE  GENMASK(3, 2)
+#define TI_EHRPWM_AQCTL_ZRO_MASK   GENMASK(1, 0)
+#define TI_EHRPWM_AQCTL_ZRO_FRCLOW BIT(0)
+#define TI_EHRPWM_AQCTL_ZRO_FRCHIGHBIT(1)
+#define TI_EHRPWM_AQCTL_ZRO_FRCTOGGLE  GENMASK(1, 0)
+
+#define TI_EHRPWM_AQCTL_CHANA_POLNORMAL
(TI_EHRPWM_AQCTL_CAU_FRCLOW | \
+TI_EHRPWM_AQCTL_PRD_FRCHIGH | \
+TI_EHRPWM_AQCTL_ZRO_FRCHIGH)
+#define 

[PATCH v4 16/27] fdt: translate address if #size-cells = <0>

2020-10-19 Thread Dario Binacchi
The __of_translate_address routine translates an address from the
device tree into a CPU physical address. A note in the description of
the routine explains that the crossing of any level with
#size-cells = <0> is to be considered an error not by specification but
since inherited from IBM. This does not happen for Texas Instruments, or
at least for the beaglebone device tree. Without this patch, in fact,
the translation into physical addresses of the registers contained in the
am33xx-clocks.dtsi nodes would not be possible. They all have a parent
with #size-cells = <0>.

The CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS symbol makes translation
possible even in the case of crossing levels with #size-cells = <0>.

The patch acts conservatively on address translation, except for
removing a check within the of_translate_one function in the
drivers/core/of_addr.c file:

+
ranges = of_get_property(parent, rprop, );
-   if (ranges == NULL && !of_empty_ranges_quirk(parent)) {
-   debug("no ranges; cannot translate\n");
-   return 1;
-   }
if (ranges == NULL || rlen == 0) {
offset = of_read_number(addr, na);
memset(addr, 0, pna * 4);
debug("empty ranges; 1:1 translation\n");

There are two reasons:
1 The function of_empty_ranges_quirk always returns false, invalidating
  the following if statement in case of null ranges. Therefore one of
  the two checks is useless.

2 The implementation of the of_translate_one function found in the
  common/fdt_support.c file has removed this check while keeping the one
  about the 1:1 translation.

The patch adds a test and modifies a check for the correctness of an
address in the case of enabling translation also for zero size cells.
The added test checks translations of addresses generated by nodes of
a device tree similar to those you can find in the files am33xx.dtsi
and am33xx-clocks.dtsi for which the patch was created.

The patch was also tested on a beaglebone black board. The addresses
generated for the registers of the loaded drivers are those specified
by the AM335x reference manual.

Signed-off-by: Dario Binacchi 
Tested-by: Dario Binacchi 
Reviewed-by: Simon Glass 

---

Changes in v4:
- Add Sphinx documentation for dm_flags.
- Convert GD_DM_FLG_* to enum.
- Include device_compat.h header in test/dm/test-fdt.c for dev_xxx macros.

Changes in v3:
- Comment dm_flags field in the global_data structure.

Changes in v2:
- Fix a missing line in the commit message.
- Add dm_flags to global_data structure and GD_DM_FLG_SIZE_CELLS_0 macro
  to test without recompiling.
- Update the OF_CHECK_COUNTS macro in order to have just one
  #define by bringing the GD_DM_FLG_SIZE_CELLS_0 into the expression.
- Lower-case the 0xC019 hex number.

 arch/sandbox/dts/test.dts | 21 ++
 common/fdt_support.c  |  6 ++-
 drivers/core/Kconfig  | 12 ++
 drivers/core/fdtaddr.c|  2 +-
 drivers/core/of_addr.c| 14 ++-
 drivers/core/ofnode.c |  7 +++-
 drivers/core/root.c   |  3 ++
 include/asm-generic/global_data.h | 18 
 test/dm/test-fdt.c| 69 ++-
 9 files changed, 136 insertions(+), 16 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index fa84b2c10f..4a7a28559a 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -40,6 +40,7 @@
fdt-dummy1 = "/translation-test@8000/dev@1,100";
fdt-dummy2 = "/translation-test@8000/dev@2,200";
fdt-dummy3 = "/translation-test@8000/noxlatebus@3,300/dev@42";
+   fdt-dummy4 = 
"/translation-test@8000/xlatebus@4,400/devs/dev@19";
usb0 = _0;
usb1 = _1;
usb2 = _2;
@@ -1028,6 +1029,7 @@
  1 0x100 0x9000 0x1000
  2 0x200 0xA000 0x1000
  3 0x300 0xB000 0x1000
+ 4 0x400 0xC000 0x1000
 >;
 
dma-ranges = <0 0x000 0x1000 0x1000
@@ -1064,6 +1066,25 @@
reg = <0x42>;
};
};
+
+   xlatebus@4,400 {
+   compatible = "sandbox,zero-size-cells-bus";
+   reg = <4 0x400 0x1000>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   ranges = <0 4 0x400 0x1000>;
+
+   devs {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   dev@19 {
+   compatible = "denx,u-boot-fdt-dummy";
+   reg = <0x19>;
+   };
+   };
+   };
+
};
 
osd {
diff --git 

[PATCH v4 20/27] bus: ti: am33xx: add pwm subsystem driver

2020-10-19 Thread Dario Binacchi
The TI PWMSS driver is a simple bus driver for providing clock and power
management for the PWM peripherals on TI AM33xx SoCs, namely eCAP,
eHRPWM and eQEP.

For DT binding details see Linux doc:
- Documentation/devicetree/bindings/pwm/pwm-tipwmss.txt

Signed-off-by: Dario Binacchi 

---

(no changes since v3)

Changes in v3:
- Move Kconfig symbol from drivers/pwm to drivers/bus.
- Remove the domain clock reference from the pwmss nodes of the device
  tree in am33xx.dtsi. The resync of am33xx.dtsi with Linux 5.9-rc7
  already contains such references.
- Remove domain clock enabling/disabling. Enabling the domain clock is
  performed by the sysc interconnect target module driver during the pwm
  device probing.
- Remove doc/device-tree-bindings/pwm/ti,pwmss.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/bus/Kconfig|  6 ++
 drivers/bus/Makefile   |  1 +
 drivers/bus/ti-pwmss.c | 21 +
 3 files changed, 28 insertions(+)
 create mode 100644 drivers/bus/ti-pwmss.c

diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig
index 733bec5a56..d742ed333b 100644
--- a/drivers/bus/Kconfig
+++ b/drivers/bus/Kconfig
@@ -5,6 +5,12 @@
 
 menu "Bus devices"
 
+config TI_PWMSS
+   bool
+   default y if ARCH_OMAP2PLUS && PWM_TI_EHRPWM
+   help
+ PWM Subsystem driver support for AM33xx SOC.
+
 config TI_SYSC
bool "TI sysc interconnect target module driver"
depends on ARCH_OMAP2PLUS
diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile
index 875bb4ed42..a2e71c7b3b 100644
--- a/drivers/bus/Makefile
+++ b/drivers/bus/Makefile
@@ -3,5 +3,6 @@
 # Makefile for the bus drivers.
 #
 
+obj-$(CONFIG_TI_PWMSS) += ti-pwmss.o
 obj-$(CONFIG_TI_SYSC)  += ti-sysc.o
 obj-$(CONFIG_UNIPHIER_SYSTEM_BUS) += uniphier-system-bus.o
diff --git a/drivers/bus/ti-pwmss.c b/drivers/bus/ti-pwmss.c
new file mode 100644
index 00..265b4cf83b
--- /dev/null
+++ b/drivers/bus/ti-pwmss.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Pulse-Width Modulation Subsystem (pwmss)
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ */
+
+#include 
+#include 
+
+static const struct udevice_id ti_pwmss_ids[] = {
+   {.compatible = "ti,am33xx-pwmss"},
+   {}
+};
+
+U_BOOT_DRIVER(ti_pwmss) = {
+   .name = "ti_pwmss",
+   .id = UCLASS_SIMPLE_BUS,
+   .of_match = ti_pwmss_ids,
+   .bind = dm_scan_fdt_dev,
+};
-- 
2.17.1



[PATCH v4 18/27] misc: am33xx: add control module driver

2020-10-19 Thread Dario Binacchi
The implementation of this driver was needed to bind the device tree
sub-nodes of the 'clocks' node. In fact, the lack of the compatible
property in the 'clocks' node does not allow the generic 'syscon' or
'simple-bus' drivers linked to the 'scm_conf@0' node to bind the
'clocks' node and in turn its sub-nodes.
The 'scm@21' node is therefore the node closest to the 'clocks' node
whose driver can bind all the 'clocks' sub-nodes. In this way, the
address translation functions are able to walk along the device tree
towards the upper nodes until the address composition is completed.

scm: scm@21 {
compatible = "ti,am3-scm", "simple-bus";
...

scm_conf: scm_conf@0 {
compatible = "syscon", "simple-bus";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0 0 0x800>;

scm_clocks: clocks {
#address-cells = <1>;
#size-cells = <0>;
};
};
};

For DT binding details see Linux doc:
- Documentation/devicetree/bindings/arm/omap/ctrl.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

Changes in v3:
- Remove doc/device-tree-bindings/arm/omap,ctrl.txt.
- Remove doc/device-tree-bindings/pinctrl/pinctrl-single.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

Changes in v2:
- Remove the 'ti_am3_scm_clocks' driver. Handle 'scm_clocks' node in
  the 'ti_am3_scm' driver.
- Update the commit message.

 drivers/misc/Kconfig  |  7 
 drivers/misc/Makefile |  1 +
 drivers/misc/ti-am3-scm.c | 82 +++
 3 files changed, 90 insertions(+)
 create mode 100644 drivers/misc/ti-am3-scm.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index b67e906a76..9e8b676637 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -500,4 +500,11 @@ config ESM_PMIC
  Support ESM (Error Signal Monitor) on PMIC devices. ESM is used
  typically to reboot the board in error condition.
 
+config TI_AM3_SCM
+   bool "AM33XX specific control module support (SCM)"
+   depends on ARCH_OMAP2PLUS
+   help
+The control module includes status and control logic not addressed
+within the peripherals or the rest of the device infrastructure.
+
 endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 947bd3a647..056fb3b522 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -75,3 +75,4 @@ obj-$(CONFIG_MICROCHIP_FLEXCOM) += microchip_flexcom.o
 obj-$(CONFIG_K3_AVS0) += k3_avs.o
 obj-$(CONFIG_ESM_K3) += k3_esm.o
 obj-$(CONFIG_ESM_PMIC) += esm_pmic.o
+obj-$(CONFIG_TI_AM3_SCM) += ti-am3-scm.o
diff --git a/drivers/misc/ti-am3-scm.c b/drivers/misc/ti-am3-scm.c
new file mode 100644
index 00..ed886e6916
--- /dev/null
+++ b/drivers/misc/ti-am3-scm.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * AM335x specific control module (scm)
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int ti_am3_scm_bind(struct udevice *dev)
+{
+   ofnode clocks_node, conf_node, node;
+   struct udevice *conf_dev;
+   int err;
+
+   if (!strcmp("clocks", ofnode_get_name(dev_ofnode(dev {
+   ofnode_for_each_subnode(node, dev_ofnode(dev)) {
+   dev_dbg(dev, "%s: node=%s\n", __func__,
+   ofnode_get_name(node));
+   err = lists_bind_fdt(dev, node, NULL, false);
+   if (err) {
+   dev_err(dev, "%s: lists_bind_fdt, err=%d\n",
+   __func__, err);
+   return err;
+   }
+   }
+
+   return 0;
+   }
+
+   err = dm_scan_fdt_dev(dev);
+   if (err) {
+   dev_err(dev, "%s: dm_scan_fdt, err=%d\n", __func__, err);
+   return err;
+   }
+
+   conf_node = dev_read_subnode(dev, "scm_conf@0");
+   if (!ofnode_valid(conf_node)) {
+   dev_err(dev, "%s: failed to get conf sub-node\n", __func__);
+   return -ENODEV;
+   }
+
+   if (uclass_get_device_by_ofnode(UCLASS_SYSCON, conf_node, _dev)) {
+   if (uclass_get_device_by_ofnode(UCLASS_SIMPLE_BUS, conf_node,
+   _dev)) {
+   dev_err(dev, "%s: failed to get conf device\n",
+   __func__);
+   return -ENODEV;
+   }
+   }
+
+   clocks_node = dev_read_subnode(conf_dev, "clocks");
+   if (!ofnode_valid(clocks_node)) {
+   dev_err(dev, "%s: failed to get clocks sub-node\n", __func__);
+   return -ENODEV;
+   }
+
+   err = device_bind_driver_to_node(conf_dev, "ti_am3_scm", 

[PATCH v4 10/27] clk: ti: add gate clock driver

2020-10-19 Thread Dario Binacchi
The patch adds support for TI gate clock binding. The code is based on
the drivers/clk/ti/gate.c driver of the Linux kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/clock/ti/gate.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.

Changes in v3:
- Remove doc/device-tree-bindings/clock/gpio-gate-clock.txt.
- Remove doc/device-tree-bindings/clock/ti,clockdomain.txt.
- Remove doc/device-tree-bindings/clock/ti,gate.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/clk/Kconfig   |  6 +++
 drivers/clk/Makefile  |  1 +
 drivers/clk/clk-ti-gate.c | 93 +++
 3 files changed, 100 insertions(+)
 create mode 100644 drivers/clk/clk-ti-gate.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index bc6bb57904..480ffc7d9c 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -111,6 +111,12 @@ config CLK_TI_DIVIDER
help
  This enables the divider clock driver support on TI's SoCs.
 
+config CLK_TI_GATE
+   bool "TI gate clock driver"
+   depends on CLK && OF_CONTROL
+   help
+ This enables the gate clock driver support on TI's SoCs.
+
 config CLK_TI_MUX
bool "TI mux clock driver"
depends on CLK && OF_CONTROL && CLK_CCF
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index ee218aff08..809672e92e 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -50,6 +50,7 @@ obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
+obj-$(CONFIG_CLK_TI_GATE) += clk-ti-gate.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
diff --git a/drivers/clk/clk-ti-gate.c b/drivers/clk/clk-ti-gate.c
new file mode 100644
index 00..6c5432c823
--- /dev/null
+++ b/drivers/clk/clk-ti-gate.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI gate clock support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Loosely based on Linux kernel drivers/clk/ti/gate.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+struct clk_ti_gate_priv {
+   fdt_addr_t reg;
+   u8 enable_bit;
+   u32 flags;
+   bool invert_enable;
+};
+
+static int clk_ti_gate_disable(struct clk *clk)
+{
+   struct clk_ti_gate_priv *priv = dev_get_priv(clk->dev);
+   u32 v;
+
+   v = readl(priv->reg);
+   if (priv->invert_enable)
+   v |= (1 << priv->enable_bit);
+   else
+   v &= ~(1 << priv->enable_bit);
+
+   writel(v, priv->reg);
+   /* No OCP barrier needed here since it is a disable operation */
+   return 0;
+}
+
+static int clk_ti_gate_enable(struct clk *clk)
+{
+   struct clk_ti_gate_priv *priv = dev_get_priv(clk->dev);
+   u32 v;
+
+   v = readl(priv->reg);
+   if (priv->invert_enable)
+   v &= ~(1 << priv->enable_bit);
+   else
+   v |= (1 << priv->enable_bit);
+
+   writel(v, priv->reg);
+   /* OCP barrier */
+   v = readl(priv->reg);
+   return 0;
+}
+
+static int clk_ti_gate_ofdata_to_platdata(struct udevice *dev)
+{
+   struct clk_ti_gate_priv *priv = dev_get_priv(dev);
+
+   priv->reg = dev_read_addr(dev);
+   if (priv->reg == FDT_ADDR_T_NONE) {
+   dev_err(dev, "failed to get control register\n");
+   return -EINVAL;
+   }
+
+   dev_dbg(dev, "reg=0x%08lx\n", priv->reg);
+   priv->enable_bit = dev_read_u32_default(dev, "ti,bit-shift", 0);
+   if (dev_read_bool(dev, "ti,set-rate-parent"))
+   priv->flags |= CLK_SET_RATE_PARENT;
+
+   priv->invert_enable = dev_read_bool(dev, "ti,set-bit-to-disable");
+   return 0;
+}
+
+static struct clk_ops clk_ti_gate_ops = {
+   .enable = clk_ti_gate_enable,
+   .disable = clk_ti_gate_disable,
+};
+
+static const struct udevice_id clk_ti_gate_of_match[] = {
+   { .compatible = "ti,gate-clock" },
+   { },
+};
+
+U_BOOT_DRIVER(clk_ti_gate) = {
+   .name = "ti_gate_clock",
+   .id = UCLASS_CLK,
+   .of_match = clk_ti_gate_of_match,
+   .ofdata_to_platdata = clk_ti_gate_ofdata_to_platdata,
+   .priv_auto_alloc_size = sizeof(struct clk_ti_gate_priv),
+   .ops = _ti_gate_ops,
+};
-- 
2.17.1



[PATCH v4 09/27] clk: ti: add divider clock driver

2020-10-19 Thread Dario Binacchi
The patch adds support for TI divider clock binding. The driver uses
routines provided by the common clock framework (ccf).

The code is based on the drivers/clk/ti/divider.c driver of the Linux
kernel version 5.9-rc7.
For DT binding details see:
- Documentation/devicetree/bindings/clock/ti/divider.txt

Signed-off-by: Dario Binacchi 

---

Changes in v4:
- Include device_compat.h header for dev_xxx macros.
- Fix compilation errors on the dev parameter of the dev_xx macros.

Changes in v3:
- Remove doc/device-tree-bindings/clock/ti,autoidle.txt.
- Remove doc/device-tree-bindings/clock/ti,divider.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

Changes in v2:
- Merged to patch [09/31] clk: ti: refactor mux and divider clock
  drivers.

 drivers/clk/Kconfig  |   6 +
 drivers/clk/Makefile |   2 +
 drivers/clk/clk-ti-divider.c | 381 +++
 drivers/clk/clk-ti-mux.c |  27 +--
 drivers/clk/clk-ti.c |  34 
 drivers/clk/clk-ti.h |  13 ++
 6 files changed, 438 insertions(+), 25 deletions(-)
 create mode 100644 drivers/clk/clk-ti-divider.c
 create mode 100644 drivers/clk/clk-ti.c
 create mode 100644 drivers/clk/clk-ti.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 301ecac652..bc6bb57904 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -105,6 +105,12 @@ config CLK_TI_AM3_DPLL
  This enables the DPLL clock drivers support on AM33XX SoCs. The DPLL
  provides all interface clocks and functional clocks to the processor.
 
+config CLK_TI_DIVIDER
+   bool "TI divider clock driver"
+   depends on CLK && OF_CONTROL && CLK_CCF
+   help
+ This enables the divider clock driver support on TI's SoCs.
+
 config CLK_TI_MUX
bool "TI mux clock driver"
depends on CLK && OF_CONTROL && CLK_CCF
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index f1eaae03c5..ee218aff08 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_ARCH_ASPEED) += aspeed/
 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek/
 obj-$(CONFIG_ARCH_MTMIPS) += mtmips/
 obj-$(CONFIG_ARCH_MESON) += meson/
+obj-$(CONFIG_ARCH_OMAP2PLUS) += clk-ti.o
 obj-$(CONFIG_ARCH_ROCKCHIP) += rockchip/
 obj-$(CONFIG_ARCH_SOCFPGA) += altera/
 obj-$(CONFIG_CLK_AT91) += at91/
@@ -48,6 +49,7 @@ obj-$(CONFIG_SANDBOX) += clk_sandbox_test.o
 obj-$(CONFIG_SANDBOX_CLK_CCF) += clk_sandbox_ccf.o
 obj-$(CONFIG_STM32H7) += clk_stm32h7.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-ti-am3-dpll.o clk-ti-am3-dpll-x2.o
+obj-$(CONFIG_CLK_TI_DIVIDER) += clk-ti-divider.o
 obj-$(CONFIG_CLK_TI_MUX) += clk-ti-mux.o
 obj-$(CONFIG_CLK_TI_SCI) += clk-ti-sci.o
 obj-$(CONFIG_CLK_VERSAL) += clk_versal.o
diff --git a/drivers/clk/clk-ti-divider.c b/drivers/clk/clk-ti-divider.c
new file mode 100644
index 00..cb6923ddb5
--- /dev/null
+++ b/drivers/clk/clk-ti-divider.c
@@ -0,0 +1,381 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * TI divider clock support
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ *
+ * Loosely based on Linux kernel drivers/clk/ti/divider.c
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "clk-ti.h"
+
+/*
+ * The reverse of DIV_ROUND_UP: The maximum number which
+ * divided by m is r
+ */
+#define MULT_ROUND_UP(r, m) ((r) * (m) + (m) - 1)
+
+struct clk_ti_divider_priv {
+   struct clk parent;
+   fdt_addr_t reg;
+   const struct clk_div_table *table;
+   u8 shift;
+   u8 flags;
+   u8 div_flags;
+   s8 latch;
+   u16 min;
+   u16 max;
+   u16 mask;
+};
+
+static unsigned int _get_div(const struct clk_div_table *table, ulong flags,
+unsigned int val)
+{
+   if (flags & CLK_DIVIDER_ONE_BASED)
+   return val;
+
+   if (flags & CLK_DIVIDER_POWER_OF_TWO)
+   return 1 << val;
+
+   if (table)
+   return clk_divider_get_table_div(table, val);
+
+   return val + 1;
+}
+
+static unsigned int _get_val(const struct clk_div_table *table, ulong flags,
+unsigned int div)
+{
+   if (flags & CLK_DIVIDER_ONE_BASED)
+   return div;
+
+   if (flags & CLK_DIVIDER_POWER_OF_TWO)
+   return __ffs(div);
+
+   if (table)
+   return clk_divider_get_table_val(table, div);
+
+   return div - 1;
+}
+
+static int _div_round_up(const struct clk_div_table *table, ulong parent_rate,
+ulong rate)
+{
+   const struct clk_div_table *clkt;
+   int up = INT_MAX;
+   int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
+
+   for (clkt = table; clkt->div; clkt++) {
+   if (clkt->div == div)
+   return clkt->div;
+   else if (clkt->div < div)
+   continue;
+
+   if ((clkt->div - div) < (up - div))
+   up = 

[PATCH v4 14/27] clk: ti: omap4: add clock manager driver

2020-10-19 Thread Dario Binacchi
This minimal driver is only used to bind child devices.

For DT binding details see Linux doc:
- Documentation/devicetree/bindings/arm/omap/prcm.txt

Signed-off-by: Dario Binacchi 

---

(no changes since v3)

Changes in v3:
- doc/device-tree-bindings/arm/omap,prcm.txt.
- Add to commit message the references to linux kernel dt binding
  documentation.

 drivers/clk/ti/Makefile   |  2 +-
 drivers/clk/ti/omap4-cm.c | 22 ++
 2 files changed, 23 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/ti/omap4-cm.c

diff --git a/drivers/clk/ti/Makefile b/drivers/clk/ti/Makefile
index a279a2838d..0b7e61cdf7 100644
--- a/drivers/clk/ti/Makefile
+++ b/drivers/clk/ti/Makefile
@@ -3,7 +3,7 @@
 # Copyright (C) 2020 Dario Binacchi 
 #
 
-obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o
+obj-$(CONFIG_ARCH_OMAP2PLUS) += clk.o omap4-cm.o
 obj-$(CONFIG_CLK_TI_AM3_DPLL) += clk-am3-dpll.o clk-am3-dpll-x2.o
 obj-$(CONFIG_CLK_TI_CTRL) += clk-ctrl.o
 obj-$(CONFIG_CLK_TI_DIVIDER) += clk-divider.o
diff --git a/drivers/clk/ti/omap4-cm.c b/drivers/clk/ti/omap4-cm.c
new file mode 100644
index 00..3cdc9b2888
--- /dev/null
+++ b/drivers/clk/ti/omap4-cm.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * OMAP4 clock manager (cm)
+ *
+ * Copyright (C) 2020 Dario Binacchi 
+ */
+
+#include 
+#include 
+#include 
+
+static const struct udevice_id ti_omap4_cm_ids[] = {
+   {.compatible = "ti,omap4-cm"},
+   {}
+};
+
+U_BOOT_DRIVER(ti_omap4_cm) = {
+   .name = "ti_omap4_cm",
+   .id = UCLASS_SIMPLE_BUS,
+   .of_match = ti_omap4_cm_ids,
+   .bind = dm_scan_fdt_dev,
+};
-- 
2.17.1



  1   2   >