Re: [PATCH v3 1/1] timer: imx-gpt: Add timer support for i.MX SoCs family

2021-02-11 Thread Jesse T
I'm very sorry for my email issues I some how mess it up each time.

On Thu, Feb 11, 2021, 8:11 PM Jesse  wrote:

> From: Jesse Taube 
>
> This timer driver is using GPT Timer (General Purpose Timer)
> available on almost all i.MX SoCs family.
> Since this driver is only meant to provide u-boot's timer and counter,
> and most of the i.MX* SoCs use a 24Mhz crystal,
> let's only deal with that specific source.
>
> Signed-off-by: Giulio Benetti 
> Signed-off-by: Jesse Taube 
> ---
>  drivers/timer/Kconfig |   7 ++
>  drivers/timer/Makefile|   1 +
>  drivers/timer/imx-gpt-timer.c | 149 ++
>  3 files changed, 157 insertions(+)
>  create mode 100644 drivers/timer/imx-gpt-timer.c
>
> diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
> index 80743a2551..ee81dfa776 100644
> --- a/drivers/timer/Kconfig
> +++ b/drivers/timer/Kconfig
> @@ -227,4 +227,11 @@ config MCHP_PIT64B_TIMER
>   Select this to enable support for Microchip 64-bit periodic
>   interval timer.
>
> +config IMX_GPT_TIMER
> +   bool "NXP i.MX GPT timer support"
> +   depends on TIMER
> +   help
> + Select this to enable support for the timer found on
> + NXP i.MX devices.
> +
>  endmenu
> diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
> index eb5c48cc6c..e214ba7268 100644
> --- a/drivers/timer/Makefile
> +++ b/drivers/timer/Makefile
> @@ -25,3 +25,4 @@ obj-$(CONFIG_STM32_TIMER) += stm32_timer.o
>  obj-$(CONFIG_X86_TSC_TIMER)+= tsc_timer.o
>  obj-$(CONFIG_MTK_TIMER)+= mtk_timer.o
>  obj-$(CONFIG_MCHP_PIT64B_TIMER)+= mchp-pit64b-timer.o
> +obj-$(CONFIG_IMX_GPT_TIMER)+= imx-gpt-timer.o
> diff --git a/drivers/timer/imx-gpt-timer.c b/drivers/timer/imx-gpt-timer.c
> new file mode 100644
> index 00..62db6e663a
> --- /dev/null
> +++ b/drivers/timer/imx-gpt-timer.c
> @@ -0,0 +1,149 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (C) 2020
> + * Author(s): Giulio Benetti 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +#define GPT_CR_SWR 0x8000
> +#define GPT_CR_CLKSRC  0x01C0
> +#define GPT_CR_EN_24M  0x0400
> +#define GPT_CR_EN  0x0001
> +#define GPT_PR_PRESCALER   0x0FFF
> +#define GPT_PR_PRESCALER24M0xF000
> +
> +#define NO_CLOCK   (0)
> +#define IPG_CLK(1 << 6)
> +#define IPG_CLK_HF (2 << 6)
> +#define IPG_EXT(3 << 6)
> +#define IPG_CLK_32K(4 << 6)
> +#define IPG_CLK_24M(5 << 6)
> +
> +struct imx_gpt_timer_regs {
> +   u32 cr;
> +   u32 pr;
> +   u32 sr;
> +   u32 ir;
> +   u32 ocr1;
> +   u32 ocr2;
> +   u32 ocr3;
> +   u32 icr1;
> +   u32 icr2;
> +   u32 cnt;
> +};
> +
> +struct imx_gpt_timer_priv {
> +   struct imx_gpt_timer_regs *base;
> +};
> +
> +static u64 imx_gpt_timer_get_count(struct udevice *dev)
> +{
> +   struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
> +   struct imx_gpt_timer_regs *regs = priv->base;
> +
> +   return readl(>cnt);
> +}
> +
> +u32 imxrt_gpt_setup_ctrl(u32 rate)
> +{
> +   u32 ctlr = 0;
> +
> +   if (rate == 2400UL) {
> +   ctlr |= IPG_CLK_24M;
> +   ctlr |= GPT_CR_EN_24M;
> +   } else {
> +   ctlr |= IPG_CLK;
> +   }
> +
> +   return ctlr;
> +}
> +
> +static int imx_gpt_timer_probe(struct udevice *dev)
> +{
> +   struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> +   struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
> +   struct imx_gpt_timer_regs *regs;
> +   struct clk clk;
> +   fdt_addr_t addr;
> +   u32 prescaler;
> +   u32 rate;
> +   u32 ctlr;
> +   int ret;
> +
> +   addr = dev_read_addr(dev);
> +   if (addr == FDT_ADDR_T_NONE)
> +   return -EINVAL;
> +
> +   priv->base = (struct imx_gpt_timer_regs *)addr;
> +
> +   ret = clk_get_by_index(dev, 0, );
> +   if (ret < 0)
> +   return ret;
> +
> +   ret = clk_enable();
> +   if (ret) {
> +   dev_err(dev, "Failed to enable clock\n");
> +   return ret;
> +   }
> +
> +   regs = priv->base;
> +
> +   /* Reset the timer */
> +   setbits_le32(>cr, GPT_CR_SWR);
> +
> +   /* Wait for timer to finish reset */
> +   while (readl(>cr) & GPT_CR_SWR)
> +   ;
> +
> +   /* Get timer clock rate */
> +   rate = clk_get_rate();
> +   if (rate <= 0) {
> +   dev_err(dev, "Could not get clock rate...\n");
> +   return -EINVAL;
> +   }
> +
> +   /* Set timer frequency to 1MHz */
> +   uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
> +   prescaler = (rate / CONFIG_SYS_HZ_CLOCK) - 1;
> +
> +   if (prescaler > 0xfff) {
> +   dev_err(dev, "Could not set 

[PATCH v3 1/1] timer: imx-gpt: Add timer support for i.MX SoCs family

2021-02-11 Thread Jesse
From: Jesse Taube 

This timer driver is using GPT Timer (General Purpose Timer) 
available on almost all i.MX SoCs family.
Since this driver is only meant to provide u-boot's timer and counter,
and most of the i.MX* SoCs use a 24Mhz crystal, 
let's only deal with that specific source.

Signed-off-by: Giulio Benetti 
Signed-off-by: Jesse Taube 
---
 drivers/timer/Kconfig |   7 ++
 drivers/timer/Makefile|   1 +
 drivers/timer/imx-gpt-timer.c | 149 ++
 3 files changed, 157 insertions(+)
 create mode 100644 drivers/timer/imx-gpt-timer.c

diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
index 80743a2551..ee81dfa776 100644
--- a/drivers/timer/Kconfig
+++ b/drivers/timer/Kconfig
@@ -227,4 +227,11 @@ config MCHP_PIT64B_TIMER
  Select this to enable support for Microchip 64-bit periodic
  interval timer.
 
+config IMX_GPT_TIMER
+   bool "NXP i.MX GPT timer support"
+   depends on TIMER
+   help
+ Select this to enable support for the timer found on
+ NXP i.MX devices.
+
 endmenu
diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
index eb5c48cc6c..e214ba7268 100644
--- a/drivers/timer/Makefile
+++ b/drivers/timer/Makefile
@@ -25,3 +25,4 @@ obj-$(CONFIG_STM32_TIMER) += stm32_timer.o
 obj-$(CONFIG_X86_TSC_TIMER)+= tsc_timer.o
 obj-$(CONFIG_MTK_TIMER)+= mtk_timer.o
 obj-$(CONFIG_MCHP_PIT64B_TIMER)+= mchp-pit64b-timer.o
+obj-$(CONFIG_IMX_GPT_TIMER)+= imx-gpt-timer.o
diff --git a/drivers/timer/imx-gpt-timer.c b/drivers/timer/imx-gpt-timer.c
new file mode 100644
index 00..62db6e663a
--- /dev/null
+++ b/drivers/timer/imx-gpt-timer.c
@@ -0,0 +1,149 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020
+ * Author(s): Giulio Benetti 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define GPT_CR_SWR 0x8000
+#define GPT_CR_CLKSRC  0x01C0
+#define GPT_CR_EN_24M  0x0400
+#define GPT_CR_EN  0x0001
+#define GPT_PR_PRESCALER   0x0FFF
+#define GPT_PR_PRESCALER24M0xF000
+
+#define NO_CLOCK   (0)
+#define IPG_CLK(1 << 6)
+#define IPG_CLK_HF (2 << 6)
+#define IPG_EXT(3 << 6)
+#define IPG_CLK_32K(4 << 6)
+#define IPG_CLK_24M(5 << 6)
+
+struct imx_gpt_timer_regs {
+   u32 cr;
+   u32 pr;
+   u32 sr;
+   u32 ir;
+   u32 ocr1;
+   u32 ocr2;
+   u32 ocr3;
+   u32 icr1;
+   u32 icr2;
+   u32 cnt;
+};
+
+struct imx_gpt_timer_priv {
+   struct imx_gpt_timer_regs *base;
+};
+
+static u64 imx_gpt_timer_get_count(struct udevice *dev)
+{
+   struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
+   struct imx_gpt_timer_regs *regs = priv->base;
+
+   return readl(>cnt);
+}
+
+u32 imxrt_gpt_setup_ctrl(u32 rate)
+{
+   u32 ctlr = 0;
+
+   if (rate == 2400UL) {
+   ctlr |= IPG_CLK_24M;
+   ctlr |= GPT_CR_EN_24M;
+   } else {
+   ctlr |= IPG_CLK;
+   }
+
+   return ctlr;
+}
+
+static int imx_gpt_timer_probe(struct udevice *dev)
+{
+   struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+   struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
+   struct imx_gpt_timer_regs *regs;
+   struct clk clk;
+   fdt_addr_t addr;
+   u32 prescaler;
+   u32 rate;
+   u32 ctlr;
+   int ret;
+
+   addr = dev_read_addr(dev);
+   if (addr == FDT_ADDR_T_NONE)
+   return -EINVAL;
+
+   priv->base = (struct imx_gpt_timer_regs *)addr;
+
+   ret = clk_get_by_index(dev, 0, );
+   if (ret < 0)
+   return ret;
+
+   ret = clk_enable();
+   if (ret) {
+   dev_err(dev, "Failed to enable clock\n");
+   return ret;
+   }
+
+   regs = priv->base;
+
+   /* Reset the timer */
+   setbits_le32(>cr, GPT_CR_SWR);
+
+   /* Wait for timer to finish reset */
+   while (readl(>cr) & GPT_CR_SWR)
+   ;
+
+   /* Get timer clock rate */
+   rate = clk_get_rate();
+   if (rate <= 0) {
+   dev_err(dev, "Could not get clock rate...\n");
+   return -EINVAL;
+   }
+
+   /* Set timer frequency to 1MHz */
+   uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
+   prescaler = (rate / CONFIG_SYS_HZ_CLOCK) - 1;
+
+   if (prescaler > 0xfff) {
+   dev_err(dev, "Could not set prescaler...\n");
+   return -EINVAL;
+   }
+   /* We set timer prescaler to obtain a 1MHz timer counter frequency */
+   writel(prescaler, >pr);
+
+   ctlr = imxrt_gpt_setup_ctrl(rate);
+
+   /* Start timer */
+   writel(ctlr, >cr);
+   setbits_le32(>cr, GPT_CR_EN);
+
+   return 0;
+}
+
+static const struct timer_ops imx_gpt_timer_ops = {
+   .get_count = imx_gpt_timer_get_count,
+};
+

[PATCH v3 0/1] timer: imx-gpt: Add timer support for i.MX SoCs family

2021-02-11 Thread Jesse
From: Jesse Taube 

This timer driver is using GPT Timer (General Purpose Timer) 
available on almost all i.MX SoCs family.
Since this driver is only meant to provide u-boot's timer and counter,
and most of the i.MX* SoCs use a 24Mhz crystal, 
let's only deal with that specific source.

Jesse Taube (1):
  timer: imx-gpt: Add timer support for i.MX SoCs family

 drivers/timer/Kconfig |   7 ++
 drivers/timer/Makefile|   1 +
 drivers/timer/imx-gpt-timer.c | 149 ++
 3 files changed, 157 insertions(+)
 create mode 100644 drivers/timer/imx-gpt-timer.c
---
V1->V2:
* Fixed indentation
* Fixed capitals
* Made timer work on only 24MHz clock
---
---
V1->V3:
* Fixed indentation
* Made implementation imatate the Linux kernel
* Fix wrong definition 
---
-- 
2.30.0



Re: [PATCH] serial: s5p: Allow independent selection

2021-02-11 Thread Mark Kettenis
Bleah.  Sent this out to quickly.  Will do a v2 when I've properly
tested building an actual S5P family target.

> From: Mark Kettenis 
> Date: Fri, 12 Feb 2021 00:34:49 +0100
> 
> Currently support for the Samsung serial port driver is part
> of CONFIG_S5P which controls selection of several drivers for
> the S5P family.  Give it its own config option such that we
> can use it on other SoCs as well.
> 
> Signed-off-by: Mark Kettenis 
> ---
>  drivers/serial/Kconfig  | 7 +++
>  drivers/serial/Makefile | 2 +-
>  2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
> index 9db4cae1df..5335f32f99 100644
> --- a/drivers/serial/Kconfig
> +++ b/drivers/serial/Kconfig
> @@ -722,6 +722,13 @@ config ROCKCHIP_SERIAL
> This uses the ns16550 driver, converting the platdata from of-platdata
> to the ns16550 format.
>  
> +config S5P_SERIAL
> + bool "Support for Samsung S5P UART"
> + depends on ARCH_APPLE || _ARCH_EXYNOS || ARCH_S5PC1XX
> + default y if S5P
> + help
> +   Select this to enable Samsung S5P UART support.
> +
>  config SANDBOX_SERIAL
>   bool "Sandbox UART support"
>   depends on SANDBOX
> diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
> index 0c3810f5d5..92bcb30b85 100644
> --- a/drivers/serial/Makefile
> +++ b/drivers/serial/Makefile
> @@ -41,7 +41,7 @@ obj-$(CONFIG_EFI_APP) += serial_efi.o
>  obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o
>  obj-$(CONFIG_MCFUART) += serial_mcf.o
>  obj-$(CONFIG_SYS_NS16550) += ns16550.o
> -obj-$(CONFIG_S5P) += serial_s5p.o
> +obj-$(CONFIG_S5P_SERIAL) += serial_s5p.o
>  obj-$(CONFIG_MXC_UART) += serial_mxc.o
>  obj-$(CONFIG_PXA_SERIAL) += serial_pxa.o
>  obj-$(CONFIG_MESON_SERIAL) += serial_meson.o
> -- 
> 2.30.0
> 
> 


[PATCH] serial: s5p: Allow independent selection

2021-02-11 Thread Mark Kettenis
Currently support for the Samsung serial port driver is part
of CONFIG_S5P which controls selection of several drivers for
the S5P family.  Give it its own config option such that we
can use it on other SoCs as well.

Signed-off-by: Mark Kettenis 
---
 drivers/serial/Kconfig  | 7 +++
 drivers/serial/Makefile | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 9db4cae1df..5335f32f99 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -722,6 +722,13 @@ config ROCKCHIP_SERIAL
  This uses the ns16550 driver, converting the platdata from of-platdata
  to the ns16550 format.
 
+config S5P_SERIAL
+   bool "Support for Samsung S5P UART"
+   depends on ARCH_APPLE || _ARCH_EXYNOS || ARCH_S5PC1XX
+   default y if S5P
+   help
+ Select this to enable Samsung S5P UART support.
+
 config SANDBOX_SERIAL
bool "Sandbox UART support"
depends on SANDBOX
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 0c3810f5d5..92bcb30b85 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -41,7 +41,7 @@ obj-$(CONFIG_EFI_APP) += serial_efi.o
 obj-$(CONFIG_LPC32XX_HSUART) += lpc32xx_hsuart.o
 obj-$(CONFIG_MCFUART) += serial_mcf.o
 obj-$(CONFIG_SYS_NS16550) += ns16550.o
-obj-$(CONFIG_S5P) += serial_s5p.o
+obj-$(CONFIG_S5P_SERIAL) += serial_s5p.o
 obj-$(CONFIG_MXC_UART) += serial_mxc.o
 obj-$(CONFIG_PXA_SERIAL) += serial_pxa.o
 obj-$(CONFIG_MESON_SERIAL) += serial_meson.o
-- 
2.30.0



Re: Final of-platdata thing

2021-02-11 Thread Tom Rini
On Wed, Feb 10, 2021 at 11:39:54AM -0700, Simon Glass wrote:

> Hi Tom,
> 
> I have the dtoc changes ready to go but I was thinking it best to
> apply the driver-model updates before sending a pull request.
> 
> But that is (currently) designed to set on top of the SPL test
> improvements...have you had a look at that one? I can probably
> separate them if needed.

I think both are going to need to wait for the next merge window to
open, to start with.  So I don't have a strong feeling about needing to
split it up further.

-- 
Tom


signature.asc
Description: PGP signature


Re: [PULL] u-boot-usb/master

2021-02-11 Thread Tom Rini
On Wed, Feb 10, 2021 at 11:39:51PM +0100, Marek Vasut wrote:

> The following changes since commit c7182c02cefb11431a79a8abb4d8a821e4a478b5:
> 
>   Merge tag 'u-boot-amlogic-20210210' of
> https://gitlab.denx.de/u-boot/custodians/u-boot-amlogic (2021-02-10 07:56:57
> -0500)
> 
> are available in the Git repository at:
> 
>   git://git.denx.de/u-boot-usb.git master
> 
> for you to fetch changes up to db8fb2ffc4f3f63b9005f676ab3879a06de6cdda:
> 
>   usb: dwc2: change compatible st,stm32mp1-hsotg to st,stm32mp15-hsotg
> (2021-02-10 22:23:35 +0100)
> 

Applied to u-boot/master, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/1] timer: imx-gpt: Add timer support for i.MX SoCs family

2021-02-11 Thread Jesse T
On Wed, Feb 10, 2021 at 3:09 PM Giulio Benetti <
giulio.bene...@benettiengineering.com> wrote:

> Hi Jesse,
>
> I re-add all people and ML in Cc so they can follow. Next time reply to
> all.
>
> On 2/10/21 8:00 PM, Jesse Taube wrote:
> >
> > On 2/10/21 12:49 PM, Giulio Benetti wrote:
> >> On 2/10/21 1:04 AM, Jesse Taube wrote:
> >>> This timer driver is using GPT Timer (General Purpose Timer)
> >>> available on almost all i.MX SoCs family.
> >>> Since this driver is only meant to provide u-boot's timer and
> >>> counter, and most of the i.MX* SoCs use a 24Mhz crystal, let's only
> >>> deal with that specific source.
> >>
> >> We have a problem with columns on commit log, they shouldn't be longer
> >> than 72 cols, so please check the editor you're using for commit log
> >> writing and set 72 cols costrains. I use nano and you only need to set
> >> in .gitconfig under [core]:
> >> editor = nano -b -r 72
> >>
> >> This way nano automatically put a CR.
> >>
> >>>
> >>> Signed-off-by: Giulio Benetti 
> >>> Signed-off-by: Jesse Taube 
> >>>
> >>> ---
> >>>drivers/timer/Kconfig |   7 ++
> >>>drivers/timer/Makefile|   1 +
> >>>drivers/timer/imx-gpt-timer.c | 132
> ++
> >>>3 files changed, 140 insertions(+)
> >>>create mode 100644 drivers/timer/imx-gpt-timer.c
> >>>
> >>> diff --git a/drivers/timer/Kconfig b/drivers/timer/Kconfig
> >>> index 80743a2551..ee81dfa776 100644
> >>> --- a/drivers/timer/Kconfig
> >>> +++ b/drivers/timer/Kconfig
> >>> @@ -227,4 +227,11 @@ config MCHP_PIT64B_TIMER
> >>>  Select this to enable support for Microchip 64-bit periodic
> >>>  interval timer.
> >>>+config IMX_GPT_TIMER
> >>> +bool "NXP i.MX GPT timer support"
> >>> +depends on TIMER
> >>> +help
> >>> +  Select this to enable support for the timer found on
> >>> +  NXP i.MX devices.
> >>> +
> >>>endmenu
> >>> diff --git a/drivers/timer/Makefile b/drivers/timer/Makefile
> >>> index eb5c48cc6c..e214ba7268 100644
> >>> --- a/drivers/timer/Makefile
> >>> +++ b/drivers/timer/Makefile
> >>> @@ -25,3 +25,4 @@ obj-$(CONFIG_STM32_TIMER)+= stm32_timer.o
> >>>obj-$(CONFIG_X86_TSC_TIMER)+= tsc_timer.o
> >>>obj-$(CONFIG_MTK_TIMER)+= mtk_timer.o
> >>>obj-$(CONFIG_MCHP_PIT64B_TIMER)+= mchp-pit64b-timer.o
> >>> +obj-$(CONFIG_IMX_GPT_TIMER)+= imx-gpt-timer.o
> >>> diff --git a/drivers/timer/imx-gpt-timer.c
> >>> b/drivers/timer/imx-gpt-timer.c
> >>> new file mode 100644
> >>> index 00..58c37db300
> >>> --- /dev/null
> >>> +++ b/drivers/timer/imx-gpt-timer.c
> >>> @@ -0,0 +1,132 @@
> >>> +// SPDX-License-Identifier: GPL-2.0+
> >>> +/*
> >>> + * Copyright (C) 2020
> >>> + * Author(s): Giulio Benetti 
> >>> + */
> >>> +
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +#include 
> >>> +
> >>> +#include 
> >>> +
> >>> +#define GPT_CR_SWR0x8000
> >>> +#define GPT_CR_CLKSRC0x01C0
> >>> +#define GPT_CR_EN_24M0x4000
> >>> +#define GPT_CR_EN0x0001
> >>> +#define GPT_PR_PRESCALER0x0FFF
> >>> +#define GPT_PR_PRESCALER24M0xF000
> >>
> >> Here ^^^ and
> >>
> >>> +#define NO_CLOCK(0)
> >>> +#define IPG_CLK(1 << 6)
> >>> +#define IPG_CLK_HF(2 << 6)
> >>> +#define IPG_EXT(3 << 6)
> >>> +#define IPG_CLK_32K(4 << 6)
> >>> +#define IPG_CLK_24M(5 << 6)
> >> here you still have different tab numbers. Enable in your editor the
> >> option to show whitespaces and tabs, that way everything it easier.
> > I still don't exactly understand what you mean here. Should I press tab
> > 3 times exactly instead of making the values line up.
>
> You need to check using an editor with whitespaces and tabs options
> enabled and tabs set to 8 spaces how that code looks like.
>
> > In the commit log
> > it seems to change weirdly because of the '+' in front of the define.
>
> Here it is the same, this should be due to the editor you use for commit
> log.
>
> >>> +
> >>> +struct imx_gpt_timer_regs {
> >>> +u32 cr;
> >>> +u32 pr;
> >>> +u32 sr;
> >>> +u32 ir;
> >>> +u32 ocr1;
> >>> +u32 ocr2;
> >>> +u32 ocr3;
> >>> +u32 icr1;
> >>> +u32 icr2;
> >>> +u32 cnt;
> >>> +};
> >>> +
> >>> +struct imx_gpt_timer_priv {
> >>> +struct imx_gpt_timer_regs *base;
> >>> +};
> >>> +
> >>> +static u64 imx_gpt_timer_get_count(struct udevice *dev)
> >>> +{
> >>> +struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
> >>> +struct imx_gpt_timer_regs *regs = priv->base;
> >>> +
> >>> +return readl(>cnt);
> >>> +}
> >>> +
> >>> +static int imx_gpt_timer_probe(struct udevice *dev)
> >>> +{
> >>> +struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
> >>> +struct imx_gpt_timer_priv *priv = dev_get_priv(dev);
> >>> +struct imx_gpt_timer_regs *regs;

Re: [PATCH 14/25] arm: Remove sheevaplug board

2021-02-11 Thread Tom Rini
On Wed, Feb 10, 2021 at 09:09:56PM -0800, Rick Thomas wrote:
> 
> 
> On Wed, Feb 10, 2021, at 8:57 PM, Vagrant Cascadian wrote:
> > On 2021-02-10, Rick Thomas wrote:
> > > I have not recently (since before 2019) done anything more than allow
> > > aptitude to upgrade packages as it thinks best.  In particular, I have
> > > not made any attempt to burn new firmware on the device.
> > 
> > The debian u-boot packages do not automatically upgrade the u-boot
> > installed to the device; it requires manual intervention on the part of
> > the system administrator above and beyond just upgrading the debian
> > packages through apt, aptitude, etc.
> > 
> > I think u-boot upstream is talking about dropping it for 2021.04, so my
> > guess is you would still have another entire debian release cycle with
> > the available 2021.01 version of u-boot *if* that version still works...
> 
> If you can point me to instructions for doing that manual
> intervention, I'll be happy to test whatever version you recommend,  I
> hope the instructions also include how to recover if it *doesn't*
> work!

I think this unfortunately gets to the heart of the problem.  We need
someone that cares about the platform to step up and do the maintenance.
Most of the work shouldn't be too hard and there's examples of many
previous conversions.  The mvsata_ide driver is probably the hardest
part but I think it just means that the ide_preinit() call needs to be
worked in to the new ide_probe() function rather than the old
ide_init().

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH v2 1/1] timer: imx-gpt: Add timer support for i.MX SoCs family

2021-02-11 Thread Giulio Benetti

On 2/11/21 7:54 PM, Jesse T wrote:
[SNIP]

 >
 > The IPG_CLK_24M needs a different prescaler and a second enable bit.
 > This will completely bypass all other clock sources making the
check for
 > the clock rate useless.

Yes, in the operative way yes, you could also avoid passing clock
source
through dts, but this way we check that the right clock source is
passed
to dts, and that is the correct way to work I think.

 > It will also mean that even if we don't have a
 > correct clock source it will work at the correct timing.

Yes if they provide 24Mhz.

I wanted it to be like that at the moment, because a lot of imx SoCs
setup GPT like that. Take a look here:

https://gitlab.denx.de/u-boot/u-boot/-/blob/master/arch/arm/mach-imx/timer.c#L80-99

This way the imx6* and imx7 could add their .compatible to this driver
in the future. If someone will need some specific tweaking then they
would send a patch adding such new DT property, like using 32K source.
But that comes next IMHO, otherwise we should describe entirely GPT
peripheral but what we need at the moment is getting 1ms tick like lot
of other imx SoCs already do.

The other chance would be to treat all the clock sources possibilities,
but, at least for me, to begin this is sufficient and can be
improved later.

 > I changed it to use only the 24MHz clock and ignore all others,

Ok

 > at some
 > point it would be nice to have it only as a backup clock if the
ccm was
 > not configured.

I don't understand what you mean with backup clock can you elaborate
more?

If we have a clock source that is 0, we can still use the 24MHz clock as 
that is an always known source, and isn't controlled by the ccm. 
Therefore if we have a dummy clock the soc will still have delays and 
timeouts at the right time. But this would make it so that we never 
return an error from clk_get_rate();


I'm not sure it is that safe. I'd prefer something that doesn't work at
all rather than something that works by a default specified inside a 
driver. Since we're trying to imitate linux driver I would avoid this 
solution. Often code is exchanged between u-boot, linux etc. so I'd 
prefer to keep it like linux does.


Best regards
--
Giulio Benetti
Benetti Engineering sas



Thank you

Best regards
-- 
Giulio Benetti

Benetti Engineering sas





[PATCH v2 2/2] mtd: nand: spi: Support GigaDevice GD5F1GQ5UExxG

2021-02-11 Thread Reto Schneider
From: Reto Schneider 

The relevant changes to the already existing GD5F1GQ4UExxG support has
been determined by consulting the GigaDevice product change notice
AN-0392-10, version 1.0 from November 30, 2020.

As the overlaps are huge, variable names have been generalized
accordingly.

Apart form the lowered ECC strength (4 instead of 8 bits per 512 bytes),
the new device ID, and the extra quad IO dummy byte, no changes had to
be taken into account.

New hardware features are not supported, namely:
 - Power on reset
 - Unique ID
 - Double transfer rate (DTR)
 - Parameter page
 - Random data quad IO

The inverted semantic of the "driver strength" register bits, defaulting
to 100% instead of 50% for the Q5 devices, got ignored as the driver has
never touched them anyway.

The no longer supported "read from cache during block erase"
functionality is not reflected as the current SPI NAND core does not
support it anyway.

Implementation has been tested on MediaTek MT7688 based GARDENA smart
Gateways using both, GigaDevice GD5F1GQ5UEYIG and GD5F1GQ4UBYIG.

Signed-off-by: Reto Schneider 
Reviewed-by: Stefan Roese 
---
Changes in v2:
 - Clarify effect of no longer supported feature

 drivers/mtd/nand/spi/gigadevice.c | 79 +++
 1 file changed, 69 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/spi/gigadevice.c 
b/drivers/mtd/nand/spi/gigadevice.c
index 5de0ebbb7b..a2c93486f4 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -17,9 +17,13 @@
 #define GD5FXGQ4XA_STATUS_ECC_1_7_BITFLIPS (1 << 4)
 #define GD5FXGQ4XA_STATUS_ECC_8_BITFLIPS   (3 << 4)
 
-#define GD5FXGQ4XEXXG_REG_STATUS2  0xf0
+#define GD5FXGQ5XE_STATUS_ECC_1_4_BITFLIPS (1 << 4)
+#define GD5FXGQ5XE_STATUS_ECC_4_BITFLIPS   (3 << 4)
 
-static SPINAND_OP_VARIANTS(read_cache_variants,
+#define GD5FXGQXXEXXG_REG_STATUS2  0xf0
+
+/* Q4 devices, QUADIO: Dummy bytes valid for 1 and 2 GBit variants */
+static SPINAND_OP_VARIANTS(gd5fxgq4_read_cache_variants,
SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
@@ -27,6 +31,15 @@ static SPINAND_OP_VARIANTS(read_cache_variants,
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
 
+/* Q5 devices, QUADIO: Dummy bytes only valid for 1 GBit variants */
+static SPINAND_OP_VARIANTS(gd5f1gq5_read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
 static SPINAND_OP_VARIANTS(write_cache_variants,
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
SPINAND_PROG_LOAD(true, 0, NULL, 0));
@@ -35,7 +48,7 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
SPINAND_PROG_LOAD(false, 0, NULL, 0));
 
-static int gd5fxgq4xexxg_ooblayout_ecc(struct mtd_info *mtd, int section,
+static int gd5fxgqxxexxg_ooblayout_ecc(struct mtd_info *mtd, int section,
   struct mtd_oob_region *region)
 {
if (section)
@@ -47,7 +60,7 @@ static int gd5fxgq4xexxg_ooblayout_ecc(struct mtd_info *mtd, 
int section,
return 0;
 }
 
-static int gd5fxgq4xexxg_ooblayout_free(struct mtd_info *mtd, int section,
+static int gd5fxgqxxexxg_ooblayout_free(struct mtd_info *mtd, int section,
struct mtd_oob_region *region)
 {
if (section)
@@ -64,7 +77,7 @@ static int gd5fxgq4xexxg_ecc_get_status(struct spinand_device 
*spinand,
u8 status)
 {
u8 status2;
-   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQ4XEXXG_REG_STATUS2,
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQXXEXXG_REG_STATUS2,
  );
int ret;
 
@@ -102,21 +115,67 @@ static int gd5fxgq4xexxg_ecc_get_status(struct 
spinand_device *spinand,
return -EINVAL;
 }
 
-static const struct mtd_ooblayout_ops gd5fxgq4xexxg_ooblayout = {
-   .ecc = gd5fxgq4xexxg_ooblayout_ecc,
-   .rfree = gd5fxgq4xexxg_ooblayout_free,
+static int gd5fxgq5xexxg_ecc_get_status(struct spinand_device *spinand,
+   u8 status)
+{
+   u8 status2;
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQXXEXXG_REG_STATUS2,
+ );
+   int ret;
+
+   switch (status & 

Re: [Uboot-stm32] [PATCH] usb: dwc2: change compatible st, stm32mp1-hsotg to st, stm32mp15-hsotg

2021-02-11 Thread Ahmad Fatoum
Hi,

On 10.02.21 20:59, Tom Rini wrote:
> On Tue, Feb 09, 2021 at 08:51:26PM +0100, Patrick DELAUNAY wrote:
>>
>> On 2/9/21 11:39 AM, Marek Vasut wrote:
>>> On 2/9/21 11:14 AM, Patrick Delaunay wrote:
>>> Hi,
>>>
>>> [...]
>>>
 diff --git a/drivers/usb/gadget/dwc2_udc_otg.c
 b/drivers/usb/gadget/dwc2_udc_otg.c
 index e3871e381e..ecac80fc11 100644
 --- a/drivers/usb/gadget/dwc2_udc_otg.c
 +++ b/drivers/usb/gadget/dwc2_udc_otg.c
 @@ -1176,7 +1176,7 @@ static int dwc2_udc_otg_remove(struct udevice
 *dev)
   static const struct udevice_id dwc2_udc_otg_ids[] = {
   { .compatible = "snps,dwc2" },
   { .compatible = "brcm,bcm2835-usb" },
 -    { .compatible = "st,stm32mp1-hsotg",
 +    { .compatible = "st,stm32mp15-hsotg",
     .data = (ulong)dwc2_set_stm32mp1_hsotg_params },
>>>
>>> I have to point out the obvious, DT is ABI, this breaks ABI. However, do
>>> we care about out-of-tree DTs here ?
>>
>>
>> I know that the binding backward compatibility and "binary compatible" the
>> is a key element of DT
>>
>> for the Linux kernel (for example the latest kernel image should work with a
>> old device tree).
> 
> The way we use DTs in U-Boot we don't enforce ABI because we allow for
> DTS and bindings to come in before they're fully stabilized in
> linux-next/similar and then it's required to re-sync them once they are
> final.

I think platforms like the STM32MP1 should be handled specially, because
they support having an external device tree passed from the FSBL at runtime.
See 
https://github.com/trini/u-boot/blob/master/arch/arm/mach-stm32mp/boot_params.c#L32

@Patrick, wouldn't this change break booting newer U-Boot with older TF-A in
some configurations? Or is this reusing-fsbl-fdt feature unused?

Cheers,
Ahmad

> 
> 
> ___
> Uboot-stm32 mailing list
> uboot-st...@st-md-mailman.stormreply.com
> https://st-md-mailman.stormreply.com/mailman/listinfo/uboot-stm32
> 

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |


Bug: filesystem btrfs: ls mmc 0:3

2021-02-11 Thread Georg Gast

Hello u-boot team,

today i compiled u-boot v2021.01 with the am335x_evm_defconfig (Hardware 
Beaglebone Black) and enabled additional the btrfs filesystem as it 
should boot the kernel sitting there. Listing the content of the 
filesystem triggers a bug:


The filesystem was created with kernel 5.10.9 on Debian Bullseye.

See the log:
U-Boot 2021.01 (Feb 11 2021 - 16:21:23 +)

CPU  : AM335X-GP rev 2.0
Model: TI AM335x BeagleBone Black
DRAM:  512 MiB
WDT:   Started with servicing (60s timeout)
NAND:  0 MiB
MMC:   OMAP SD/MMC: 0, OMAP SD/MMC: 1
Loading Environment from FAT... *** Warning - bad CRC, using default 
environment


 not set. Validating first E-fuse MAC
Net:   eth2: ethernet@4a10, eth3: usb_ether
Hit any key to stop autoboot:  0
=> fstype mmc 0:3
btrfs
=> ls mmc 0:3
BUG at fs/btrfs/disk-io.c:736/btrfs_read_fs_root()!
BUG!
resetting ...

U-Boot SPL 2021.01 (Feb 11 2021 - 16:21:23 +)
Trying to boot from MMC1


https://github.com/u-boot/u-boot/blob/c7182c02cefb11431a79a8abb4d8a821e4a478b5/fs/btrfs/disk-io.c#L736


[PATCH v2 1/2] mtd: nand: spi: Only one dummy byte in QUADIO

2021-02-11 Thread Reto Schneider
From: Hauke Mehrtens 

The datasheet only lists one dummy byte in the 0xEB operation for the
following chips:
* GD5F1GQ4xExxG
* GD5F1GQ4xFxxG
* GD5F1GQ4UAYIG
* GD5F4GQ4UAYIG

Reto Schneider:
- Linux patch ported to U-Boot
- Checked for compatibility with GD5F1GQ4xBxxG
- Fixed operation code in original commit message (0xEH -> 0xEB)

Signed-off-by: Reto Schneider 
Reviewed-by: Stefan Roese 
---
Changes in v2:
 - Adjust authorship to original author, declare own work separately

 drivers/mtd/nand/spi/gigadevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/gigadevice.c 
b/drivers/mtd/nand/spi/gigadevice.c
index 0b228dcb5b..5de0ebbb7b 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -20,7 +20,7 @@
 #define GD5FXGQ4XEXXG_REG_STATUS2  0xf0
 
 static SPINAND_OP_VARIANTS(read_cache_variants,
-   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
-- 
2.29.2



RE: [PATCH v3 3/3] dm: i2c: use CONFIG_IS_ENABLED macro for DM_I2C/DM_I2C_GPIO

2021-02-11 Thread Priyanka Jain
>-Original Message-
>From: Igor Opaniuk 
>Sent: Tuesday, February 9, 2021 5:23 PM
>To: u-boot@lists.denx.de
>Cc: rica...@foundries.io; Michael Scott ;
>jo...@foundries.io; s...@chromium.org; tr...@konsulko.com; Igor Opaniuk
>; Heiko Schocher ; Adam Ford
>; Alison Wang ; Andre Przywara
>; Ashish Kumar ; Ashok
>Reddy Soma ; Bhaskar Upadhaya
>; Biwen Li ; Fabio Estevam
>; Faiz Abbas ; Feng Li
>; Frieder Schrempf ; Hans
>de Goede ; Heinrich Schuchardt
>; Holger Brunck powergrids.com>; Z.q. Hou ; Jaehoon Chung
>; Jagan Teki ; Jernej
>Skrabec ; Jonas Smedegaard ; Kuldeep
>Singh ; Lokesh Vutla ; Lukasz
>Majewski ; Madalin Bucur (OSS)
>; Manish Tomar ;
>Marek Szyprowski ; Marek Vasut
>; Masahiro Yamada ; Meenakshi
>Aggarwal ; Michael Walle ;
>Michal Simek ; Mingkai Hu ;
>dl-uboot-imx ; Neil Armstrong
>; Niel Fourie ; Ovidiu Panait
>; Pali Rohár ; Prabhakar
>Kushwaha ; Pramod Kumar
>; Priyanka Jain ; Priyanka
>Singh ; Qiang Zhao ; Rai
>Harninder ; Rajesh Bhagat ;
>Shengzhou Liu ; Stefan Bosch ;
>Stefan Roese ; Stefano Babic ; Sudhanshu Gupta
>; Suman Anna ; Sumit Garg
>; Andy Tang ; Udit Agarwal
>; Vitaly Andrianov ; Vladimir Oltean
>; Wasim Khan ; Wolfgang Denk
>
>Subject: [PATCH v3 3/3] dm: i2c: use CONFIG_IS_ENABLED macro for
>DM_I2C/DM_I2C_GPIO
>
>From: Igor Opaniuk 
>
>Use CONFIG_IS_ENABLED() macro, which provides more convenient
>way to check $(SPL)DM_I2C/$(SPL)DM_I2C_GPIO configs
>for both SPL and U-Boot proper.
>
>CONFIG_IS_ENABLED(DM_I2C) expands to:
>- 1 if CONFIG_SPL_BUILD is undefined and CONFIG_DM_I2C is set to 'y',
>- 1 if CONFIG_SPL_BUILD is defined and CONFIG_SPL_DM_I2C is set to 'y',
>- 0 otherwise.
>
>All occurences were replaced automatically using these bash cmds:
>$ find . -type f -exec sed -i
> 's/ifndef CONFIG_DM_I2C/if !CONFIG_IS_ENABLED(DM_I2C)/g' {} +
>$ find . -type f -exec sed -i
>'s/ifdef CONFIG_DM_I2C/if CONFIG_IS_ENABLED(DM_I2C)/g' {} +
>$ find . -type f -exec sed -i
>'s/defined(CONFIG_DM_I2C)/CONFIG_IS_ENABLED(DM_I2C)/g' {} +
>$ find . -type f -exec sed -i
>'s/ifndef CONFIG_DM_I2C_GPIO/if !CONFIG_IS_ENABLED(DM_I2C_GPIO)/g' {}
>+
>$ find . -type f -exec sed -i
>'s/ifdef CONFIG_DM_I2C_GPIO/if CONFIG_IS_ENABLED(DM_I2C_GPIO)/g' {} +
>$ find . -type f -exec sed -i
>'s/defined(CONFIG_DM_I2C_GPIO)/CONFIG_IS_ENABLED(DM_I2C_GPIO)/g' {}
>+
>
>Reviewed-by: Heiko Schocher 
>Reviewed-by: Simon Glass 
>Signed-off-by: Igor Opaniuk 
>
>---
>
Reviewed-by: Priyanka Jain 


[PATCH v2 1/2] mtd: nand: spi: Only one dummy byte in QUADIO

2021-02-11 Thread Reto Schneider
From: Hauke Mehrtens 

The datasheet only lists one dummy byte in the 0xEB operation for the
following chips:
* GD5F1GQ4xExxG
* GD5F1GQ4xFxxG
* GD5F1GQ4UAYIG
* GD5F4GQ4UAYIG

Reto Schneider:
- Linux patch ported to U-Boot
- Checked for compatibility with GD5F1GQ4xBxxG
- Fixed operation code in original commit message (0xEH -> 0xEB)

Signed-off-by: Reto Schneider 
Reviewed-by: Stefan Roese 
---
Changes in v2:
 - Adjust authorship to original author, declare own work separately

 drivers/mtd/nand/spi/gigadevice.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/gigadevice.c 
b/drivers/mtd/nand/spi/gigadevice.c
index 0b228dcb5b..5de0ebbb7b 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -20,7 +20,7 @@
 #define GD5FXGQ4XEXXG_REG_STATUS2  0xf0
 
 static SPINAND_OP_VARIANTS(read_cache_variants,
-   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
-- 
2.29.2



[PATCH] net: gem: Fix error path in zynq_gem_probe

2021-02-11 Thread Michal Simek
Clean up error path in connection where priv->rxbuffers and priv->tx_bd are
allocated.

Signed-off-by: Michal Simek 
---

Based on
https://lists.denx.de/pipermail/u-boot/2021-February/440943.html
https://lists.denx.de/pipermail/u-boot/2021-February/441021.html
---
 drivers/net/zynq_gem.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
index 9ed013ee5124..baf06a2ad897 100644
--- a/drivers/net/zynq_gem.c
+++ b/drivers/net/zynq_gem.c
@@ -708,14 +708,14 @@ static int zynq_gem_probe(struct udevice *dev)
ret = clk_get_by_name(dev, "tx_clk", >tx_clk);
if (ret < 0) {
dev_err(dev, "failed to get tx_clock\n");
-   goto err1;
+   goto err2;
}
 
if (priv->clk_en_info & RXCLK_EN) {
ret = clk_get_by_name(dev, "rx_clk", >rx_clk);
if (ret < 0) {
dev_err(dev, "failed to get rx_clock\n");
-   goto err1;
+   goto err2;
}
}
 
@@ -737,9 +737,9 @@ static int zynq_gem_probe(struct udevice *dev)
 err3:
mdio_unregister(priv->bus);
 err2:
-   free(priv->rxbuffers);
-err1:
free(priv->tx_bd);
+err1:
+   free(priv->rxbuffers);
return ret;
 }
 
-- 
2.30.0



Re: [PATCH] net: gem: unregister mdio bus if probe fails

2021-02-11 Thread Michal Simek



On 2/10/21 10:41 PM, Michael Walle wrote:
> If probe fails, the mdio bus isn't unregistered. Fix it.
> 
> Signed-off-by: Michael Walle 
> ---
>  drivers/net/zynq_gem.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
> index 5cb02bb3a7..585c06d6bd 100644
> --- a/drivers/net/zynq_gem.c
> +++ b/drivers/net/zynq_gem.c
> @@ -711,10 +711,12 @@ static int zynq_gem_probe(struct udevice *dev)
>  
>   ret = zynq_phy_init(dev);
>   if (ret)
> - goto err2;
> + goto err3;
>  
>   return ret;
>  
> +err3:
> + mdio_unregister(priv->bus);
>  err2:
>   free(priv->rxbuffers);
>  err1:
> 


Applied.
M


Re: [PATCH] net: gem: unregister mdio bus if probe fails

2021-02-11 Thread Ramon Fried
On Wed, Feb 10, 2021 at 11:42 PM Michael Walle  wrote:
>
> If probe fails, the mdio bus isn't unregistered. Fix it.
>
> Signed-off-by: Michael Walle 
> ---
>  drivers/net/zynq_gem.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
> index 5cb02bb3a7..585c06d6bd 100644
> --- a/drivers/net/zynq_gem.c
> +++ b/drivers/net/zynq_gem.c
> @@ -711,10 +711,12 @@ static int zynq_gem_probe(struct udevice *dev)
>
> ret = zynq_phy_init(dev);
> if (ret)
> -   goto err2;
> +   goto err3;
>
> return ret;
>
> +err3:
> +   mdio_unregister(priv->bus);
>  err2:
> free(priv->rxbuffers);
>  err1:
> --
> 2.20.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Igor Opaniuk
Hi Heinrich,

On Thu, Feb 11, 2021 at 5:34 PM Heinrich Schuchardt  wrote:
>
> On 11.02.21 15:56, Ard Biesheuvel wrote:
> > On Thu, 11 Feb 2021 at 15:18, Heinrich Schuchardt  
> > wrote:
> >>
> >> On 11.02.21 13:04, Igor Opaniuk wrote:
> >>> From: Igor Opaniuk 
> >>>
> >>> When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
> >>> In case amount of memory provided to QEMU is not multiple
> >>> of 2 MB, round down the amount of available memory to avoid hang
> >>> during MMU initialization.
> >>>
> >>> How to reproduce:
> >>> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
> >>> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
> >>>
> >>> DRAM:  1 GiB
> >>> initcall: 60011df8
> >>> initcall: 60011904
> >>> New Stack Pointer is: 80fffe90
> >>> initcall: 60011a20
> >>> initcall: 60011bcc
> >>> initcall: 60011bd4
> >>> initcall: 600119b4
> >>> Relocation Offset is: 22042000
> >>> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> >>> initcall: 60011b8c
> >>> initcall: 82053ea0
> >>> initcall: 82053ea8
> >>> initcall: 60012040 (relocated to 82054040)
> >>> dram_bank_mmu_setup: bank: 0
> >>> --- hang here during mmu init ---
> >>>
> >>> Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
> >>> Signed-off-by: Igor Opaniuk 
> >>>
> >>> ---
> >>>
> >>>  board/emulation/qemu-arm/qemu-arm.c | 12 
> >>>  1 file changed, 12 insertions(+)
> >>>
> >>> diff --git a/board/emulation/qemu-arm/qemu-arm.c 
> >>> b/board/emulation/qemu-arm/qemu-arm.c
> >>> index aa68bef469..841dd7af0e 100644
> >>> --- a/board/emulation/qemu-arm/qemu-arm.c
> >>> +++ b/board/emulation/qemu-arm/qemu-arm.c
> >>> @@ -84,6 +84,18 @@ int dram_init(void)
> >>>   if (fdtdec_setup_mem_size_base() != 0)
> >>>   return -EINVAL;
> >>>
> >>> + /*
> >>> +  * When LPAE is enabled (ARMv7),
> >>> +  * 1:1 mapping is created using 2 MB blocks.
> >>> +  *
> >>> +  * In case amount of memory provided to QEMU
> >>> +  * is not multiple of 2 MB, round down the amount
> >>> +  * of available memory to avoid hang during MMU
> >>> +  * initialization.
> >>> +  */
> >>> + if (CONFIG_IS_ENABLED(ARMV7_LPAE))
> >>> + gd->ram_size -= (gd->ram_size % 0x20);
> >>
> >> Is the problem LPAE specific?
> >> Couldn't you provoke same problem using an odd memory size without LPAE,
> >> e.g qemu-system-arm -m 536870908 (512 MiB - 4)?
> >>
> >
> > The above value means 512 GiB - 4 MiB, so that shouldn't be a problem.
> > I don't think QEMU's -m option takes fractional megabyte values.
> >
>
> $ qemu-system-arm -machine virt -cpu cortex-a15 -m 15k \
> -bios denx/u-boot.bin -nographic
>
> => fdt addr $fdt_addr
> => fdt print /memory@4000
> memory@4000 {
> reg = <0x 0x4000 0x 0x061aa000>;
> device_type = "memory";
> };
>
> Granularity seems to be 0x2000 = 8 KiB.
I've just run some tests (including the mem=15k ) with LPAE disabled
and haven't faced any issues:

$ cat .config | grep LPAE
# CONFIG_ARMV7_LPAE is not set

$ qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin
U-Boot 2021.04-rc1-01218-g85e959f09c-dirty (Feb 11 2021 - 17:31:31 +0200)

DRAM:  1 GiB
Flash: 128 MiB
...
=>

$ qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin

U-Boot 2021.04-rc1-01218-g85e959f09c-dirty (Feb 11 2021 - 17:31:31 +0200)

DRAM:  1 GiB
Flash: 128 MiB
...
=>

$ qemu-system-arm -machine virt -m 15k -nographic -bios u-boot.bin

U-Boot 2021.04-rc1-01218-g85e959f09c-dirty (Feb 11 2021 - 17:31:31 +0200)
DRAM:  97.7 MiB
Flash: 128 MiB
...
=>

>
> Best regards
>
> Heinrich

Regards,
Igor

-- 
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Embedded Software Engineer
T:  +380 938364067
E: igor.opan...@foundries.io
W: www.foundries.io


Re: [PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Ard Biesheuvel
On Thu, 11 Feb 2021 at 16:34, Heinrich Schuchardt  wrote:
>
> On 11.02.21 15:56, Ard Biesheuvel wrote:
> > On Thu, 11 Feb 2021 at 15:18, Heinrich Schuchardt  
> > wrote:
> >>
> >> On 11.02.21 13:04, Igor Opaniuk wrote:
> >>> From: Igor Opaniuk 
> >>>
> >>> When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
> >>> In case amount of memory provided to QEMU is not multiple
> >>> of 2 MB, round down the amount of available memory to avoid hang
> >>> during MMU initialization.
> >>>
> >>> How to reproduce:
> >>> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
> >>> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
> >>>
> >>> DRAM:  1 GiB
> >>> initcall: 60011df8
> >>> initcall: 60011904
> >>> New Stack Pointer is: 80fffe90
> >>> initcall: 60011a20
> >>> initcall: 60011bcc
> >>> initcall: 60011bd4
> >>> initcall: 600119b4
> >>> Relocation Offset is: 22042000
> >>> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> >>> initcall: 60011b8c
> >>> initcall: 82053ea0
> >>> initcall: 82053ea8
> >>> initcall: 60012040 (relocated to 82054040)
> >>> dram_bank_mmu_setup: bank: 0
> >>> --- hang here during mmu init ---
> >>>
> >>> Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
> >>> Signed-off-by: Igor Opaniuk 
> >>>
> >>> ---
> >>>
> >>>  board/emulation/qemu-arm/qemu-arm.c | 12 
> >>>  1 file changed, 12 insertions(+)
> >>>
> >>> diff --git a/board/emulation/qemu-arm/qemu-arm.c 
> >>> b/board/emulation/qemu-arm/qemu-arm.c
> >>> index aa68bef469..841dd7af0e 100644
> >>> --- a/board/emulation/qemu-arm/qemu-arm.c
> >>> +++ b/board/emulation/qemu-arm/qemu-arm.c
> >>> @@ -84,6 +84,18 @@ int dram_init(void)
> >>>   if (fdtdec_setup_mem_size_base() != 0)
> >>>   return -EINVAL;
> >>>
> >>> + /*
> >>> +  * When LPAE is enabled (ARMv7),
> >>> +  * 1:1 mapping is created using 2 MB blocks.
> >>> +  *
> >>> +  * In case amount of memory provided to QEMU
> >>> +  * is not multiple of 2 MB, round down the amount
> >>> +  * of available memory to avoid hang during MMU
> >>> +  * initialization.
> >>> +  */
> >>> + if (CONFIG_IS_ENABLED(ARMV7_LPAE))
> >>> + gd->ram_size -= (gd->ram_size % 0x20);
> >>
> >> Is the problem LPAE specific?
> >> Couldn't you provoke same problem using an odd memory size without LPAE,
> >> e.g qemu-system-arm -m 536870908 (512 MiB - 4)?
> >>
> >
> > The above value means 512 GiB - 4 MiB, so that shouldn't be a problem.
> > I don't think QEMU's -m option takes fractional megabyte values.
> >
>
> $ qemu-system-arm -machine virt -cpu cortex-a15 -m 15k \
> -bios denx/u-boot.bin -nographic
>
> => fdt addr $fdt_addr
> => fdt print /memory@4000
> memory@4000 {
> reg = <0x 0x4000 0x 0x061aa000>;
> device_type = "memory";
> };
>
> Granularity seems to be 0x2000 = 8 KiB.
>

In that case, it seems easiest to me to always round down to the
nearest multiple of 2MB


Re: [PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Heinrich Schuchardt
On 11.02.21 15:56, Ard Biesheuvel wrote:
> On Thu, 11 Feb 2021 at 15:18, Heinrich Schuchardt  wrote:
>>
>> On 11.02.21 13:04, Igor Opaniuk wrote:
>>> From: Igor Opaniuk 
>>>
>>> When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
>>> In case amount of memory provided to QEMU is not multiple
>>> of 2 MB, round down the amount of available memory to avoid hang
>>> during MMU initialization.
>>>
>>> How to reproduce:
>>> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
>>> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
>>>
>>> DRAM:  1 GiB
>>> initcall: 60011df8
>>> initcall: 60011904
>>> New Stack Pointer is: 80fffe90
>>> initcall: 60011a20
>>> initcall: 60011bcc
>>> initcall: 60011bd4
>>> initcall: 600119b4
>>> Relocation Offset is: 22042000
>>> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
>>> initcall: 60011b8c
>>> initcall: 82053ea0
>>> initcall: 82053ea8
>>> initcall: 60012040 (relocated to 82054040)
>>> dram_bank_mmu_setup: bank: 0
>>> --- hang here during mmu init ---
>>>
>>> Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
>>> Signed-off-by: Igor Opaniuk 
>>>
>>> ---
>>>
>>>  board/emulation/qemu-arm/qemu-arm.c | 12 
>>>  1 file changed, 12 insertions(+)
>>>
>>> diff --git a/board/emulation/qemu-arm/qemu-arm.c 
>>> b/board/emulation/qemu-arm/qemu-arm.c
>>> index aa68bef469..841dd7af0e 100644
>>> --- a/board/emulation/qemu-arm/qemu-arm.c
>>> +++ b/board/emulation/qemu-arm/qemu-arm.c
>>> @@ -84,6 +84,18 @@ int dram_init(void)
>>>   if (fdtdec_setup_mem_size_base() != 0)
>>>   return -EINVAL;
>>>
>>> + /*
>>> +  * When LPAE is enabled (ARMv7),
>>> +  * 1:1 mapping is created using 2 MB blocks.
>>> +  *
>>> +  * In case amount of memory provided to QEMU
>>> +  * is not multiple of 2 MB, round down the amount
>>> +  * of available memory to avoid hang during MMU
>>> +  * initialization.
>>> +  */
>>> + if (CONFIG_IS_ENABLED(ARMV7_LPAE))
>>> + gd->ram_size -= (gd->ram_size % 0x20);
>>
>> Is the problem LPAE specific?
>> Couldn't you provoke same problem using an odd memory size without LPAE,
>> e.g qemu-system-arm -m 536870908 (512 MiB - 4)?
>>
>
> The above value means 512 GiB - 4 MiB, so that shouldn't be a problem.
> I don't think QEMU's -m option takes fractional megabyte values.
>

$ qemu-system-arm -machine virt -cpu cortex-a15 -m 15k \
-bios denx/u-boot.bin -nographic

=> fdt addr $fdt_addr
=> fdt print /memory@4000
memory@4000 {
reg = <0x 0x4000 0x 0x061aa000>;
device_type = "memory";
};

Granularity seems to be 0x2000 = 8 KiB.

Best regards

Heinrich


Re: [PATCH v1] usb: kbd: destroy device after console is stopped

2021-02-11 Thread Andy Shevchenko
On Wed, Feb 03, 2021 at 01:25:38PM +0100, Nicolas Saenz Julienne wrote:
> Andy, Tony,
> Sorry for my late reply, but I got a bad cold.

I hope you are doing well.

Unfortunately I haven't heard from you lately, so I have decided to send out
whatever I have as a patch series. You are Cc'ed on the last patch (it has
prerequisites, so better to apply entire series for easy going).

That said, I have dropped the 'iomux' branch from my public tree.

> On Thu, 2021-01-28 at 15:46 -0500, Tom Rini wrote:
> > On Thu, Jan 28, 2021 at 10:35:37PM +0200, Andy Shevchenko wrote:
> > > On Thu, Jan 28, 2021 at 06:19:56PM +0100, Nicolas Saenz Julienne wrote:
> > > > Hi Andy,
> > > > 
> > > > On Thu, 2021-01-28 at 18:55 +0200, Andy Shevchenko wrote:
> > > > > In case of IOMUX enabled it assumes that console devices in the list
> > > > > are available to get them stopped properly via ->stop() callback.
> > > > > However, the USB keyboard driver violates this assumption and tries
> > > > > to play tricks so the device get destroyed while being listed as
> > > > > an active console.
> > > > > 
> > > > > Swap the order of device deregistration and IOMUX update to avoid
> > > > > the use-after-free.
> > > > > 
> > > > > Fixes: 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing 
> > > > > is used")
> > > > > Fixes: 8a8348703081 ("dm: usb: Add a remove() method for USB 
> > > > > keyboards")
> > > > > Reported-by: Nicolas Saenz Julienne 
> > > > > Signed-off-by: Andy Shevchenko 
> > > > > ---
> > > > > v2: Nicolas, can you test this one instead of yours?
> > > > 
> > > > Sadly this doesn't seem to work, and breaks a bunch of other tests in 
> > > > the
> > > > process. You can try it yourself by running: './test/py/test.py --bd 
> > > > sandbox
> > > > --build'
> > > 
> > > Now I'm able to run test cases. I see some of them failing even without my
> > > patch, but few definitely related. Can you give a list of failed ones on 
> > > your
> > > side?  I can compare that we are on the same page here.
> > 
> > Running this here on sandbox I get:
> > FAILED test/py/tests/test_ut.py::test_ut[ut_dm_bootcount] - OSError: [Errno 
> > 5] Input/output ...
> > FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_flash] - OSError: [Errno 
> > 5] Input/output ...
> > FAILED test/py/tests/test_ut.py::test_ut[ut_dm_usb_multi] - OSError: [Errno 
> > 5] Input/output ...
> > FAILED test/py/tests/test_ut.py::test_ut[ut_dm_video_ansi] - OSError: 
> > [Errno 5] Input/output...
> 
> This is what I'm seeing too.

-- 
With Best Regards,
Andy Shevchenko




[PATCH v1 11/11] usb: kbd: destroy device after console is stopped

2021-02-11 Thread Andy Shevchenko
In case of IOMUX enabled it assumes that console devices in the list
are available to get them stopped properly via ->stop() callback.
However, the USB keyboard driver violates this assumption and tries
to play tricks so the device get destroyed while being listed as
an active console.

Swap the order of device deregistration and IOMUX update along with
converting to use iomux_replace_device() jelper to avoid the use-after-free.

Fixes: 3cbcb2892809 ("usb: Fix usb_kbd_deregister when console-muxing is used")
Fixes: 8a8348703081 ("dm: usb: Add a remove() method for USB keyboards")
Reported-by: Nicolas Saenz Julienne 
Signed-off-by: Andy Shevchenko 
---
 common/usb_kbd.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index b316807844b1..60c6027e048d 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -617,12 +617,12 @@ int usb_kbd_deregister(int force)
if (dev) {
usb_kbd_dev = (struct usb_device *)dev->priv;
data = usb_kbd_dev->privptr;
-   if (stdio_deregister_dev(dev, force) != 0)
-   return 1;
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-   if (iomux_doenv(stdin, env_get("stdin")) != 0)
+   if (iomux_replace_device(stdin, DEVNAME, force ? "nulldev" : 
""))
return 1;
 #endif
+   if (stdio_deregister_dev(dev, force) != 0)
+   return 1;
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
destroy_int_queue(usb_kbd_dev, data->intq);
 #endif
@@ -660,16 +660,16 @@ static int usb_kbd_remove(struct udevice *dev)
goto err;
}
data = udev->privptr;
-   if (stdio_deregister_dev(sdev, true)) {
-   ret = -EPERM;
-   goto err;
-   }
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-   if (iomux_doenv(stdin, env_get("stdin"))) {
+   if (iomux_replace_device(stdin, DEVNAME, "nulldev")) {
ret = -ENOLINK;
goto err;
}
 #endif
+   if (stdio_deregister_dev(sdev, true)) {
+   ret = -EPERM;
+   goto err;
+   }
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
destroy_int_queue(udev, data->intq);
 #endif
-- 
2.30.0



[PATCH v1 06/11] console: Set file and devices at one go

2021-02-11 Thread Andy Shevchenko
Logical continuation of the change that brought console_devices_set() is
to unify console_setfile() with it and replace in the callers.

Signed-off-by: Andy Shevchenko 
---
 common/console.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/common/console.c b/common/console.c
index 4595376dcc0b..672b4a1cc678 100644
--- a/common/console.c
+++ b/common/console.c
@@ -232,7 +232,7 @@ static struct stdio_dev *tstcdev;
 struct stdio_dev **console_devices[MAX_FILES];
 int cd_count[MAX_FILES];
 
-static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+static void console_devices_set(int file, struct stdio_dev *dev)
 {
console_devices[file][0] = dev;
cd_count[file] = 1;
@@ -369,7 +369,7 @@ static inline void console_doenv(int file, struct stdio_dev 
*dev)
 #endif
 #else
 
-static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
+static void console_devices_set(int file, struct stdio_dev *dev)
 {
 }
 
@@ -417,6 +417,12 @@ static inline void console_doenv(int file, struct 
stdio_dev *dev)
 #endif
 #endif /* CONIFIG_IS_ENABLED(CONSOLE_MUX) */
 
+static void __maybe_unused console_setfile_and_devices(int file, struct 
stdio_dev *dev)
+{
+   console_setfile(file, dev);
+   console_devices_set(file, dev);
+}
+
 int console_start(int file, struct stdio_dev *sdev)
 {
int error;
@@ -1071,17 +1077,13 @@ int console_init_r(void)
 
/* Initializes output console first */
if (outputdev != NULL) {
-   console_setfile(stdout, outputdev);
-   console_setfile(stderr, outputdev);
-   console_devices_set(stdout, outputdev);
-   console_devices_set(stderr, outputdev);
+   console_setfile_and_devices(stdout, outputdev);
+   console_setfile_and_devices(stderr, outputdev);
}
 
/* Initializes input console */
-   if (inputdev != NULL) {
-   console_setfile(stdin, inputdev);
-   console_devices_set(stdin, inputdev);
-   }
+   if (inputdev != NULL)
+   console_setfile_and_devices(stdin, inputdev);
 
if (!IS_ENABLED(CONFIG_SYS_CONSOLE_INFO_QUIET))
stdio_print_current_devices();
-- 
2.30.0



[PATCH v1 10/11] IOMUX: Introduce iomux_replace_device()

2021-02-11 Thread Andy Shevchenko
Some console devices may appear or disappear at run time. In order to
support such a hotplug mechanism introduce a new iomux_replace_device()
helper to update the list of devices without altering environment.

Signed-off-by: Andy Shevchenko 
---
 common/iomux.c  | 33 +
 include/iomux.h |  1 +
 2 files changed, 34 insertions(+)

diff --git a/common/iomux.c b/common/iomux.c
index 5290b13b668b..b9088aa3b58b 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -139,4 +139,37 @@ int iomux_doenv(const int console, const char *arg)
free(old_set);
return 0;
 }
+
+int iomux_replace_device(const int console, const char *old, const char *new)
+{
+   struct stdio_dev *dev;
+   char *arg = NULL;   /* Initial empty list */
+   int size = 1;   /* For NUL terminator */
+   int i, ret;
+
+   for_each_console_dev(i, console, dev) {
+   const char *name = strcmp(dev->name, old) ? dev->name : new;
+   char *tmp;
+
+   /* Append name with a ',' (comma) separator */
+   tmp = realloc(arg, size + strlen(name) + 1);
+   if (!tmp) {
+   free(arg);
+   return -ENOMEM;
+   }
+
+   strcat(tmp, ",");
+   strcat(tmp, name);
+
+   arg = tmp;
+   size = strlen(tmp) + 1;
+   }
+
+   ret = iomux_doenv(console, arg);
+   if (ret)
+   ret = -EINVAL;
+
+   free(arg);
+   return ret;
+}
 #endif /* CONSOLE_MUX */
diff --git a/include/iomux.h b/include/iomux.h
index bd4a143b1e60..37f5f6dee69f 100644
--- a/include/iomux.h
+++ b/include/iomux.h
@@ -31,6 +31,7 @@ extern int cd_count[MAX_FILES];
 
 int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
 int iomux_doenv(const int, const char *);
+int iomux_replace_device(const int, const char *, const char *);
 void iomux_printdevs(const int);
 
 #endif /* _IO_MUX_H */
-- 
2.30.0



[PATCH v1 08/11] IOMUX: Split out iomux_match_device() helper

2021-02-11 Thread Andy Shevchenko
Deduplicate the code used in a few places by splitting out a common helper.

Signed-off-by: Andy Shevchenko 
---
 common/console.c |  7 +++
 common/iomux.c   | 27 ++-
 include/iomux.h  |  1 +
 3 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/common/console.c b/common/console.c
index 672b4a1cc678..27e881a46bda 100644
--- a/common/console.c
+++ b/common/console.c
@@ -251,15 +251,14 @@ static void console_devices_set(int file, struct 
stdio_dev *dev)
  */
 static bool console_needs_start_stop(int file, struct stdio_dev *sdev)
 {
-   int i, j;
+   int i;
 
for (i = 0; i < ARRAY_SIZE(cd_count); i++) {
if (i == file)
continue;
 
-   for (j = 0; j < cd_count[i]; j++)
-   if (console_devices[i][j] == sdev)
-   return false;
+   if (iomux_match_device(console_devices[i], cd_count[i], sdev) 
>= 0)
+   return false;
}
return true;
 }
diff --git a/common/iomux.c b/common/iomux.c
index 5d027561bb6f..a8be1ac7d8ab 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -22,11 +22,21 @@ void iomux_printdevs(const int console)
printf("\n");
 }
 
+int iomux_match_device(struct stdio_dev **set, const int n, struct stdio_dev 
*sdev)
+{
+   int i;
+
+   for (i = 0; i < n; i++)
+   if (sdev == set[i])
+   return i;
+   return -ENOENT;
+}
+
 /* This tries to preserve the old list if an error occurs. */
 int iomux_doenv(const int console, const char *arg)
 {
char *console_args, *temp, **start;
-   int i, j, k, io_flag, cs_idx, repeat;
+   int i, j, io_flag, cs_idx, repeat;
struct stdio_dev **cons_set, **old_set;
struct stdio_dev *dev;
 
@@ -96,14 +106,8 @@ int iomux_doenv(const int console, const char *arg)
/*
 * Prevent multiple entries for a device.
 */
-repeat = 0;
-for (k = 0; k < cs_idx; k++) {
-   if (dev == cons_set[k]) {
-   repeat++;
-   break;
-   }
-}
-if (repeat)
+repeat = iomux_match_device(cons_set, cs_idx, dev);
+if (repeat >= 0)
continue;
/*
 * Try assigning the specified device.
@@ -129,10 +133,7 @@ int iomux_doenv(const int console, const char *arg)
 
/* Stop dropped consoles */
for (i = 0; i < repeat; i++) {
-   for (j = 0; j < cs_idx; j++) {
-   if (old_set[i] == cons_set[j])
-   break;
-   }
+   j = iomux_match_device(cons_set, cs_idx, old_set[i]);
if (j == cs_idx)
console_stop(console, old_set[i]);
}
diff --git a/include/iomux.h b/include/iomux.h
index da7ff697d218..9c2d5796066c 100644
--- a/include/iomux.h
+++ b/include/iomux.h
@@ -24,6 +24,7 @@ extern struct stdio_dev **console_devices[MAX_FILES];
  */
 extern int cd_count[MAX_FILES];
 
+int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
 int iomux_doenv(const int, const char *);
 void iomux_printdevs(const int);
 
-- 
2.30.0



[PATCH v1 07/11] IOMUX: Switch to use stdio_file_to_flags()

2021-02-11 Thread Andy Shevchenko
Deduplicate code by replacing with stdio_file_to_flags() helper.

Signed-off-by: Andy Shevchenko 
---
 common/iomux.c | 11 ++-
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/common/iomux.c b/common/iomux.c
index 15bf53388559..5d027561bb6f 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -75,15 +75,8 @@ int iomux_doenv(const int console, const char *arg)
return 1;
}
 
-   switch (console) {
-   case stdin:
-   io_flag = DEV_FLAGS_INPUT;
-   break;
-   case stdout:
-   case stderr:
-   io_flag = DEV_FLAGS_OUTPUT;
-   break;
-   default:
+   io_flag = stdio_file_to_flags(console);
+   if (io_flag < 0) {
free(start);
free(console_args);
free(cons_set);
-- 
2.30.0



[PATCH v1 09/11] IOMUX: Split out for_each_console_dev() helper macro

2021-02-11 Thread Andy Shevchenko
It is not only less lines of code, but also better readability
when new macro is being in use. Introduce for_each_console_dev()
helper macro and convert current users to it.

Signed-off-by: Andy Shevchenko 
---
 common/console.c | 15 +--
 common/iomux.c   |  4 +---
 include/iomux.h  |  5 +
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/common/console.c b/common/console.c
index 27e881a46bda..197b4de23bb4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -292,8 +292,7 @@ static int console_tstc(int file)
int prev;
 
prev = disable_ctrlc(1);
-   for (i = 0; i < cd_count[file]; i++) {
-   dev = console_devices[file][i];
+   for_each_console_dev(i, file, dev) {
if (dev->tstc != NULL) {
ret = dev->tstc(dev);
if (ret > 0) {
@@ -313,8 +312,7 @@ static void console_putc(int file, const char c)
int i;
struct stdio_dev *dev;
 
-   for (i = 0; i < cd_count[file]; i++) {
-   dev = console_devices[file][i];
+   for_each_console_dev(i, file, dev) {
if (dev->putc != NULL)
dev->putc(dev, c);
}
@@ -333,11 +331,9 @@ static void console_puts_select(int file, bool 
serial_only, const char *s)
int i;
struct stdio_dev *dev;
 
-   for (i = 0; i < cd_count[file]; i++) {
-   bool is_serial;
+   for_each_console_dev(i, file, dev) {
+   bool is_serial = console_dev_is_serial(dev);
 
-   dev = console_devices[file][i];
-   is_serial = console_dev_is_serial(dev);
if (dev->puts && serial_only == is_serial)
dev->puts(dev, s);
}
@@ -353,8 +349,7 @@ static void console_puts(int file, const char *s)
int i;
struct stdio_dev *dev;
 
-   for (i = 0; i < cd_count[file]; i++) {
-   dev = console_devices[file][i];
+   for_each_console_dev(i, file, dev) {
if (dev->puts != NULL)
dev->puts(dev, s);
}
diff --git a/common/iomux.c b/common/iomux.c
index a8be1ac7d8ab..5290b13b668b 100644
--- a/common/iomux.c
+++ b/common/iomux.c
@@ -15,10 +15,8 @@ void iomux_printdevs(const int console)
int i;
struct stdio_dev *dev;
 
-   for (i = 0; i < cd_count[console]; i++) {
-   dev = console_devices[console][i];
+   for_each_console_dev(i, console, dev)
printf("%s ", dev->name);
-   }
printf("\n");
 }
 
diff --git a/include/iomux.h b/include/iomux.h
index 9c2d5796066c..bd4a143b1e60 100644
--- a/include/iomux.h
+++ b/include/iomux.h
@@ -24,6 +24,11 @@ extern struct stdio_dev **console_devices[MAX_FILES];
  */
 extern int cd_count[MAX_FILES];
 
+#define for_each_console_dev(i, file, dev) \
+   for (i = 0, dev = console_devices[file][i]; \
+i < cd_count[file];\
+i++, dev = console_devices[file][i])
+
 int iomux_match_device(struct stdio_dev **, const int, struct stdio_dev *);
 int iomux_doenv(const int, const char *);
 void iomux_printdevs(const int);
-- 
2.30.0



[PATCH v1 05/11] console: Set console device counter in console_devices_set()

2021-02-11 Thread Andy Shevchenko
console_devices_set() missed the console device counter to be set correctly.

Fixes: 45375adc9799 ("console: add function console_devices_set")
Cc: Patrick Delaunay 
Signed-off-by: Andy Shevchenko 
---
 common/console.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/common/console.c b/common/console.c
index b1c3ed17cc03..4595376dcc0b 100644
--- a/common/console.c
+++ b/common/console.c
@@ -235,6 +235,7 @@ int cd_count[MAX_FILES];
 static void __maybe_unused console_devices_set(int file, struct stdio_dev *dev)
 {
console_devices[file][0] = dev;
+   cd_count[file] = 1;
 }
 
 /**
-- 
2.30.0



[PATCH v1 04/11] console: Switch to use stdio_file_to_flags()

2021-02-11 Thread Andy Shevchenko
Deduplicate code by replacing with stdio_file_to_flags() helper.

Signed-off-by: Andy Shevchenko 
---
 common/console.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/common/console.c b/common/console.c
index f3cc45cab548..b1c3ed17cc03 100644
--- a/common/console.c
+++ b/common/console.c
@@ -854,17 +854,9 @@ int console_assign(int file, const char *devname)
struct stdio_dev *dev;
 
/* Check for valid file */
-   switch (file) {
-   case stdin:
-   flag = DEV_FLAGS_INPUT;
-   break;
-   case stdout:
-   case stderr:
-   flag = DEV_FLAGS_OUTPUT;
-   break;
-   default:
-   return -1;
-   }
+   flag = stdio_file_to_flags(file);
+   if (flag < 0)
+   return flag;
 
/* Check for valid device name */
 
-- 
2.30.0



[PATCH v1 02/11] stdio: Split out nulldev_register() and move it under #if

2021-02-11 Thread Andy Shevchenko
It's possible that NULLDEV can be disabled while it makes leftovers,
move entire device under #if.

Signed-off-by: Andy Shevchenko 
---
 common/stdio.c | 33 +
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/common/stdio.c b/common/stdio.c
index e3e24f0dbf89..2935d0d9ba8a 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -28,6 +28,7 @@ static struct stdio_dev devs;
 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
 
+#if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)
 static void nulldev_putc(struct stdio_dev *dev, const char c)
 {
/* nulldev is empty! */
@@ -44,6 +45,25 @@ static int nulldev_input(struct stdio_dev *dev)
return 0;
 }
 
+static void nulldev_register(void)
+{
+   struct stdio_dev dev;
+
+   memset(, '\0', sizeof(dev));
+
+   strcpy(dev.name, "nulldev");
+   dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
+   dev.putc = nulldev_putc;
+   dev.puts = nulldev_puts;
+   dev.getc = nulldev_input;
+   dev.tstc = nulldev_input;
+
+   stdio_register();
+}
+#else
+static inline void nulldev_register(void) {}
+#endif /* SYS_DEVICE_NULLDEV */
+
 static void stdio_serial_putc(struct stdio_dev *dev, const char c)
 {
serial_putc(c);
@@ -83,18 +103,7 @@ static void drv_system_init (void)
dev.tstc = stdio_serial_tstc;
stdio_register ();
 
-   if (CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)) {
-   memset(, '\0', sizeof(dev));
-
-   strcpy(dev.name, "nulldev");
-   dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
-   dev.putc = nulldev_putc;
-   dev.puts = nulldev_puts;
-   dev.getc = nulldev_input;
-   dev.tstc = nulldev_input;
-
-   stdio_register();
-   }
+   nulldev_register();
 }
 
 /**
-- 
2.30.0



[PATCH v1 03/11] stdio: Introduce a new helper stdio_file_to_flags()

2021-02-11 Thread Andy Shevchenko
Let's deduplicate existing copies by splitting off to a new helper.

Signed-off-by: Andy Shevchenko 
---
 common/stdio.c  | 13 +
 include/stdio_dev.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/common/stdio.c b/common/stdio.c
index 2935d0d9ba8a..aa003b308a21 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -28,6 +28,19 @@ static struct stdio_dev devs;
 struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
 char *stdio_names[MAX_FILES] = { "stdin", "stdout", "stderr" };
 
+int stdio_file_to_flags(const int file)
+{
+   switch (file) {
+   case stdin:
+   return DEV_FLAGS_INPUT;
+   case stdout:
+   case stderr:
+   return DEV_FLAGS_OUTPUT;
+   default:
+   return -EINVAL;
+   }
+}
+
 #if CONFIG_IS_ENABLED(SYS_DEVICE_NULLDEV)
 static void nulldev_putc(struct stdio_dev *dev, const char c)
 {
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index 109a68d06409..8fb9a12dd876 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -18,6 +18,8 @@
 #define DEV_FLAGS_OUTPUT 0x0002/* Device can be used as output console 
*/
 #define DEV_FLAGS_DM 0x0004/* Device priv is a struct udevice * */
 
+int stdio_file_to_flags(const int file);
+
 /* Device information */
 struct stdio_dev {
int flags;  /* Device flags: input/output/system
*/
-- 
2.30.0



[PATCH v1 01/11] stdio: Get rid of dead code, i.e. stdio_deregister()

2021-02-11 Thread Andy Shevchenko
Nobody is using stdio_deregister(), remove for good.

Note, even its parameters are not consistent with stdio_register().
So, if anyone want to introduce this again, better with some consistency.

Signed-off-by: Andy Shevchenko 
---
 common/stdio.c  | 11 ---
 include/stdio_dev.h |  1 -
 2 files changed, 12 deletions(-)

diff --git a/common/stdio.c b/common/stdio.c
index abf9b1e91588..e3e24f0dbf89 100644
--- a/common/stdio.c
+++ b/common/stdio.c
@@ -261,17 +261,6 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force)
return 0;
 }
 
-int stdio_deregister(const char *devname, int force)
-{
-   struct stdio_dev *dev;
-
-   dev = stdio_get_by_name(devname);
-   if (!dev) /* device not found */
-   return -ENODEV;
-
-   return stdio_deregister_dev(dev, force);
-}
-
 int stdio_init_tables(void)
 {
 #if defined(CONFIG_NEEDS_MANUAL_RELOC)
diff --git a/include/stdio_dev.h b/include/stdio_dev.h
index 48871a6a22b8..109a68d06409 100644
--- a/include/stdio_dev.h
+++ b/include/stdio_dev.h
@@ -83,7 +83,6 @@ int stdio_add_devices(void);
 int stdio_init(void);
 
 void stdio_print_current_devices(void);
-int stdio_deregister(const char *devname, int force);
 
 /**
  * stdio_deregister_dev() - deregister the device "devname".
-- 
2.30.0



Re: [PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Ard Biesheuvel
On Thu, 11 Feb 2021 at 15:18, Heinrich Schuchardt  wrote:
>
> On 11.02.21 13:04, Igor Opaniuk wrote:
> > From: Igor Opaniuk 
> >
> > When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
> > In case amount of memory provided to QEMU is not multiple
> > of 2 MB, round down the amount of available memory to avoid hang
> > during MMU initialization.
> >
> > How to reproduce:
> > qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
> > qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
> >
> > DRAM:  1 GiB
> > initcall: 60011df8
> > initcall: 60011904
> > New Stack Pointer is: 80fffe90
> > initcall: 60011a20
> > initcall: 60011bcc
> > initcall: 60011bd4
> > initcall: 600119b4
> > Relocation Offset is: 22042000
> > Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> > initcall: 60011b8c
> > initcall: 82053ea0
> > initcall: 82053ea8
> > initcall: 60012040 (relocated to 82054040)
> > dram_bank_mmu_setup: bank: 0
> > --- hang here during mmu init ---
> >
> > Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
> > Signed-off-by: Igor Opaniuk 
> >
> > ---
> >
> >  board/emulation/qemu-arm/qemu-arm.c | 12 
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/board/emulation/qemu-arm/qemu-arm.c 
> > b/board/emulation/qemu-arm/qemu-arm.c
> > index aa68bef469..841dd7af0e 100644
> > --- a/board/emulation/qemu-arm/qemu-arm.c
> > +++ b/board/emulation/qemu-arm/qemu-arm.c
> > @@ -84,6 +84,18 @@ int dram_init(void)
> >   if (fdtdec_setup_mem_size_base() != 0)
> >   return -EINVAL;
> >
> > + /*
> > +  * When LPAE is enabled (ARMv7),
> > +  * 1:1 mapping is created using 2 MB blocks.
> > +  *
> > +  * In case amount of memory provided to QEMU
> > +  * is not multiple of 2 MB, round down the amount
> > +  * of available memory to avoid hang during MMU
> > +  * initialization.
> > +  */
> > + if (CONFIG_IS_ENABLED(ARMV7_LPAE))
> > + gd->ram_size -= (gd->ram_size % 0x20);
>
> Is the problem LPAE specific?
> Couldn't you provoke same problem using an odd memory size without LPAE,
> e.g qemu-system-arm -m 536870908 (512 MiB - 4)?
>

The above value means 512 GiB - 4 MiB, so that shouldn't be a problem.
I don't think QEMU's -m option takes fractional megabyte values.


Re: [PATCH v2 1/4] test: Include /sbin to the PATH when creating ext4 disk image

2021-02-11 Thread Andy Shevchenko
On Thu, Feb 11, 2021 at 04:40:09PM +0200, Andy Shevchenko wrote:
> On some distributions the mkfs.ext4 is under /sbin and /sbin is not set
> for mere users. Include /sbin to the PATH when creating ext4 disk image,
> so that users won't get a scary traceback from Python.

Note, patches 1 and 4 may be applied to U-Boot sources directly (while patches
2 and 3 are based on top of dm/test-working). Moreover, patch 4 fixes a quite
annoying fix, without which I have got reprimanded by an admin of our build
system.

Please, consider to apply patch 4 ASAP.

> Cc: Patrick Delaunay 
> Signed-off-by: Andy Shevchenko 
> ---
> v2: used '/sbin' as is (Simon)
>  test/py/tests/test_env.py | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
> index 940279651da0..9bed2f48d77e 100644
> --- a/test/py/tests/test_env.py
> +++ b/test/py/tests/test_env.py
> @@ -414,6 +414,8 @@ def mk_env_ext4(state_test_env):
>  if os.path.exists(persistent):
>  c.log.action('Disk image file ' + persistent + ' already exists')
>  else:
> +# Some distributions do not add /sbin to the default PATH, where 
> mkfs.ext4 lives
> +os.environ["PATH"] += os.pathsep + '/sbin'
>  try:
>  u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M 
> count=16' % persistent)
>  u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
> -- 
> 2.30.0
> 

-- 
With Best Regards,
Andy Shevchenko




[PATCH v2 2/4] test: Allow simple glob pattern in the test name

2021-02-11 Thread Andy Shevchenko
When run `ut dm [test name]` allow to use simple pattern to run all tests
started with given prefix. For example, to run all ACPI test cases:
ut dm acpi*

Signed-off-by: Andy Shevchenko 
---
v2: rebased against dm/test-working branch (Simon)
 test/test-main.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/test/test-main.c b/test/test-main.c
index e1b49e091ab6..8fcbc2361214 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -128,10 +128,17 @@ static bool ut_test_run_on_flattree(struct unit_test 
*test)
 static bool test_matches(const char *prefix, const char *test_name,
 const char *select_name)
 {
+   size_t len;
+
if (!select_name)
return true;
 
-   if (!strcmp(test_name, select_name))
+   /* Allow glob expansion in the test name */
+   len = select_name[strlen(select_name) - 1] == '*' ? strlen(select_name) 
: 0;
+   if (len-- == 1)
+   return true;
+
+   if (!strncmp(test_name, select_name, len))
return true;
 
if (!prefix) {
@@ -146,7 +153,7 @@ static bool test_matches(const char *prefix, const char 
*test_name,
test_name += strlen(prefix);
}
 
-   if (!strcmp(test_name, select_name))
+   if (!strncmp(test_name, select_name, len))
return true;
 
return false;
-- 
2.30.0



[PATCH v2 3/4] test: Use positive conditional in test_matches()

2021-02-11 Thread Andy Shevchenko
It is easier to read the positive conditional.

While at it, convert hard coded length of "_test_" to strlen("_test_")
which will be converted to a constant bu optimizing compiler.

Signed-off-by: Andy Shevchenko 
---
v2: new patch
 test/test-main.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/test/test-main.c b/test/test-main.c
index 8fcbc2361214..344122074e12 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -141,16 +141,16 @@ static bool test_matches(const char *prefix, const char 
*test_name,
if (!strncmp(test_name, select_name, len))
return true;
 
-   if (!prefix) {
+   if (prefix) {
+   /* All tests have this prefix */
+   if (!strncmp(test_name, prefix, strlen(prefix)))
+   test_name += strlen(prefix);
+   } else {
const char *p = strstr(test_name, "_test_");
 
/* convert xxx_test_yyy to yyy, i.e. remove the suite name */
if (p)
-   test_name = p + 6;
-   } else {
-   /* All tests have this prefix */
-   if (!strncmp(test_name, prefix, strlen(prefix)))
-   test_name += strlen(prefix);
+   test_name = p + strlen("_test_");
}
 
if (!strncmp(test_name, select_name, len))
-- 
2.30.0



[PATCH v2 4/4] test: Don't unmount not (yet) mounted system

2021-02-11 Thread Andy Shevchenko
When test suite tries to create a file for a new filesystem test case and fails,
the clean up of the exception tries to unmount the image, that has not yet been
mounted. When it happens, the fuse_mounted global variable is set to False and
inconveniently the test case tries to use sudo, so without this change the
admin of the machine gets an (annoying) email:

  Subject: *** SECURITY information for example.com ***

  example.com : Feb  5 19:43:47 : ... COMMAND=/bin/umount 
.../build-sandbox/persistent-data/mnt

and second run of the test cases on uncleaned build folder will ask for sudo
which is not what expected.

Besides that there is a double unmount calls during successfully run test case.

All of these due to over engineered Python try-except clause and people didn't
get it properly at all. The rule of thumb is that don't use more keywords than
try-except in the exception handling code. Nevertheless, here we adjust code
to be less intrusive to the initial logic behind that complex and unclear
constructions in the test case, although it adds a lot of lines of the code,
i.e. splits one exception handler to three, so on each step we know what
cleanup shall perform.

Signed-off-by: Andy Shevchenko 
---
v2: new patch
 test/py/tests/test_fs/conftest.py | 78 ++-
 1 file changed, 56 insertions(+), 22 deletions(-)

diff --git a/test/py/tests/test_fs/conftest.py 
b/test/py/tests/test_fs/conftest.py
index ec70e8c4ef3f..50af9efcf768 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -270,9 +270,20 @@ def fs_obj_basic(request, u_boot_config):
 
 # 3GiB volume
 fs_img = mk_fs(u_boot_config, fs_type, 0xc000, '3GB')
+except CalledProcessError as err:
+pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
+return
 
-# Mount the image so we can populate it.
+try:
 check_call('mkdir -p %s' % mount_dir, shell=True)
+except CalledProcessError as err:
+pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
+return
+finally:
+call('rm -f %s' % fs_img, shell=True)
+
+try:
+# Mount the image so we can populate it.
 mount_fs(fs_type, fs_img, mount_dir)
 
 # Create a subdirectory.
@@ -335,18 +346,15 @@ def fs_obj_basic(request, u_boot_config):
% big_file, shell=True).decode()
 md5val.append(out.split()[0])
 
-umount_fs(mount_dir)
 except CalledProcessError as err:
-pytest.skip('Setup failed for filesystem: ' + fs_type + \
-'. {}'.format(err))
+pytest.skip('Setup failed for filesystem: ' + fs_type + '. 
{}'.format(err))
 return
 else:
 yield [fs_ubtype, fs_img, md5val]
 finally:
 umount_fs(mount_dir)
 call('rmdir %s' % mount_dir, shell=True)
-if fs_img:
-call('rm -f %s' % fs_img, shell=True)
+call('rm -f %s' % fs_img, shell=True)
 
 #
 # Fixture for extended fs test
@@ -378,9 +386,20 @@ def fs_obj_ext(request, u_boot_config):
 
 # 128MiB volume
 fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
+except CalledProcessError as err:
+pytest.skip('Creating failed for filesystem: ' + fs_type + '. 
{}'.format(err))
+return
 
-# Mount the image so we can populate it.
+try:
 check_call('mkdir -p %s' % mount_dir, shell=True)
+except CalledProcessError as err:
+pytest.skip('Preparing mount folder failed for filesystem: ' + fs_type 
+ '. {}'.format(err))
+return
+finally:
+call('rm -f %s' % fs_img, shell=True)
+
+try:
+# Mount the image so we can populate it.
 mount_fs(fs_type, fs_img, mount_dir)
 
 # Create a test directory
@@ -422,7 +441,6 @@ def fs_obj_ext(request, u_boot_config):
 md5val.append(out.split()[0])
 
 check_call('rm %s' % tmp_file, shell=True)
-umount_fs(mount_dir)
 except CalledProcessError:
 pytest.skip('Setup failed for filesystem: ' + fs_type)
 return
@@ -431,8 +449,7 @@ def fs_obj_ext(request, u_boot_config):
 finally:
 umount_fs(mount_dir)
 call('rmdir %s' % mount_dir, shell=True)
-if fs_img:
-call('rm -f %s' % fs_img, shell=True)
+call('rm -f %s' % fs_img, shell=True)
 
 #
 # Fixture for mkdir test
@@ -460,11 +477,10 @@ def fs_obj_mkdir(request, u_boot_config):
 fs_img = mk_fs(u_boot_config, fs_type, 0x800, '128MB')
 except:
 pytest.skip('Setup failed for filesystem: ' + fs_type)
+return
 else:
 yield [fs_ubtype, fs_img]
-finally:
-if fs_img:
-call('rm -f %s' % fs_img, shell=True)
+call('rm -f %s' % fs_img, shell=True)
 
 #
 # Fixture for unlink test
@@ -493,9 +509,20 @@ def fs_obj_unlink(request, u_boot_config):
 
 # 128MiB volume
 fs_img = 

[PATCH v2 1/4] test: Include /sbin to the PATH when creating ext4 disk image

2021-02-11 Thread Andy Shevchenko
On some distributions the mkfs.ext4 is under /sbin and /sbin is not set
for mere users. Include /sbin to the PATH when creating ext4 disk image,
so that users won't get a scary traceback from Python.

Cc: Patrick Delaunay 
Signed-off-by: Andy Shevchenko 
---
v2: used '/sbin' as is (Simon)
 test/py/tests/test_env.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/test/py/tests/test_env.py b/test/py/tests/test_env.py
index 940279651da0..9bed2f48d77e 100644
--- a/test/py/tests/test_env.py
+++ b/test/py/tests/test_env.py
@@ -414,6 +414,8 @@ def mk_env_ext4(state_test_env):
 if os.path.exists(persistent):
 c.log.action('Disk image file ' + persistent + ' already exists')
 else:
+# Some distributions do not add /sbin to the default PATH, where 
mkfs.ext4 lives
+os.environ["PATH"] += os.pathsep + '/sbin'
 try:
 u_boot_utils.run_and_log(c, 'dd if=/dev/zero of=%s bs=1M count=16' 
% persistent)
 u_boot_utils.run_and_log(c, 'mkfs.ext4 %s' % persistent)
-- 
2.30.0



Re: [PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Heinrich Schuchardt
On 11.02.21 13:04, Igor Opaniuk wrote:
> From: Igor Opaniuk 
>
> When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
> In case amount of memory provided to QEMU is not multiple
> of 2 MB, round down the amount of available memory to avoid hang
> during MMU initialization.
>
> How to reproduce:
> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
>
> DRAM:  1 GiB
> initcall: 60011df8
> initcall: 60011904
> New Stack Pointer is: 80fffe90
> initcall: 60011a20
> initcall: 60011bcc
> initcall: 60011bd4
> initcall: 600119b4
> Relocation Offset is: 22042000
> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> initcall: 60011b8c
> initcall: 82053ea0
> initcall: 82053ea8
> initcall: 60012040 (relocated to 82054040)
> dram_bank_mmu_setup: bank: 0
> --- hang here during mmu init ---
>
> Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
> Signed-off-by: Igor Opaniuk 
>
> ---
>
>  board/emulation/qemu-arm/qemu-arm.c | 12 
>  1 file changed, 12 insertions(+)
>
> diff --git a/board/emulation/qemu-arm/qemu-arm.c 
> b/board/emulation/qemu-arm/qemu-arm.c
> index aa68bef469..841dd7af0e 100644
> --- a/board/emulation/qemu-arm/qemu-arm.c
> +++ b/board/emulation/qemu-arm/qemu-arm.c
> @@ -84,6 +84,18 @@ int dram_init(void)
>   if (fdtdec_setup_mem_size_base() != 0)
>   return -EINVAL;
>
> + /*
> +  * When LPAE is enabled (ARMv7),
> +  * 1:1 mapping is created using 2 MB blocks.
> +  *
> +  * In case amount of memory provided to QEMU
> +  * is not multiple of 2 MB, round down the amount
> +  * of available memory to avoid hang during MMU
> +  * initialization.
> +  */
> + if (CONFIG_IS_ENABLED(ARMV7_LPAE))
> + gd->ram_size -= (gd->ram_size % 0x20);

Is the problem LPAE specific?
Couldn't you provoke same problem using an odd memory size without LPAE,
e.g qemu-system-arm -m 536870908 (512 MiB - 4)?

Best regards

Heinrich

> +
>   return 0;
>  }
>
>



Re: [Uboot-stm32] [PATCH] usb: dwc2: change compatible st, stm32mp1-hsotg to st, stm32mp15-hsotg

2021-02-11 Thread Tom Rini
On Thu, Feb 11, 2021 at 12:14:51PM +0100, Ahmad Fatoum wrote:
> Hi,
> 
> On 10.02.21 20:59, Tom Rini wrote:
> > On Tue, Feb 09, 2021 at 08:51:26PM +0100, Patrick DELAUNAY wrote:
> >>
> >> On 2/9/21 11:39 AM, Marek Vasut wrote:
> >>> On 2/9/21 11:14 AM, Patrick Delaunay wrote:
> >>> Hi,
> >>>
> >>> [...]
> >>>
>  diff --git a/drivers/usb/gadget/dwc2_udc_otg.c
>  b/drivers/usb/gadget/dwc2_udc_otg.c
>  index e3871e381e..ecac80fc11 100644
>  --- a/drivers/usb/gadget/dwc2_udc_otg.c
>  +++ b/drivers/usb/gadget/dwc2_udc_otg.c
>  @@ -1176,7 +1176,7 @@ static int dwc2_udc_otg_remove(struct udevice
>  *dev)
>    static const struct udevice_id dwc2_udc_otg_ids[] = {
>    { .compatible = "snps,dwc2" },
>    { .compatible = "brcm,bcm2835-usb" },
>  -    { .compatible = "st,stm32mp1-hsotg",
>  +    { .compatible = "st,stm32mp15-hsotg",
>      .data = (ulong)dwc2_set_stm32mp1_hsotg_params },
> >>>
> >>> I have to point out the obvious, DT is ABI, this breaks ABI. However, do
> >>> we care about out-of-tree DTs here ?
> >>
> >>
> >> I know that the binding backward compatibility and "binary compatible" the
> >> is a key element of DT
> >>
> >> for the Linux kernel (for example the latest kernel image should work with 
> >> a
> >> old device tree).
> > 
> > The way we use DTs in U-Boot we don't enforce ABI because we allow for
> > DTS and bindings to come in before they're fully stabilized in
> > linux-next/similar and then it's required to re-sync them once they are
> > final.
> 
> I think platforms like the STM32MP1 should be handled specially, because
> they support having an external device tree passed from the FSBL at runtime.
> See 
> https://github.com/trini/u-boot/blob/master/arch/arm/mach-stm32mp/boot_params.c#L32
> 
> @Patrick, wouldn't this change break booting newer U-Boot with older TF-A in
> some configurations? Or is this reusing-fsbl-fdt feature unused?

The long stated policy of U-Boot is to allow non-final bindings to be
used until they're finalized in Linux in order to address the "chicken
and egg" problem, since it's already a terrible idea to go to production
with a Linux kernel that's using non-final bindings.  Any older TF-A
that doesn't work with this newer binding should be on a developer board
and they can just upgrade.  Linux says "DT is ABI" and allows the ABI to
break when there's a bug in the DT.  We don't say "DT is ABI" we say "we
use the Linux kernel binding".

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] configs: fsl: move bootrom specific defines to Kconfig

2021-02-11 Thread Rajesh Bhagat
Moves below bootrom specific defines to Kconfig:

CONFIG_SYS_FSL_BOOTROM_BASE
CONFIG_SYS_FSL_BOOTROM_SIZE

Signed-off-by: Rajesh Bhagat 
---
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig  | 10 ++
 arch/arm/include/asm/arch-fsl-layerscape/cpu.h |  2 --
 scripts/config_whitelist.txt   |  2 --
 3 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig 
b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
index 4d46587214..ae0b7b21e8 100644
--- a/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
+++ b/arch/arm/cpu/armv8/fsl-layerscape/Kconfig
@@ -640,3 +640,13 @@ config HAS_FSL_XHCI_USB
help
  For some SoC(such as LS1043A and LS1046A), USB and QE-HDLC multiplex 
use
  pins, select it when the pins are assigned to USB.
+
+config SYS_FSL_BOOTROM_BASE
+   hex
+   depends on FSL_LSCH2
+   default 0
+
+config SYS_FSL_BOOTROM_SIZE
+   hex
+   depends on FSL_LSCH2
+   default 0x100
diff --git a/arch/arm/include/asm/arch-fsl-layerscape/cpu.h 
b/arch/arm/include/asm/arch-fsl-layerscape/cpu.h
index 4335aa0ec2..c51b65ea36 100644
--- a/arch/arm/include/asm/arch-fsl-layerscape/cpu.h
+++ b/arch/arm/include/asm/arch-fsl-layerscape/cpu.h
@@ -69,8 +69,6 @@
 #define CONFIG_SYS_FSL_DRAM_SIZE2  0x7F8000
 #endif
 #elif defined(CONFIG_FSL_LSCH2)
-#define CONFIG_SYS_FSL_BOOTROM_BASE0x0
-#define CONFIG_SYS_FSL_BOOTROM_SIZE0x100
 #define CONFIG_SYS_FSL_CCSR_BASE   0x100
 #define CONFIG_SYS_FSL_CCSR_SIZE   0xf00
 #define CONFIG_SYS_FSL_DCSR_BASE   0x2000
diff --git a/scripts/config_whitelist.txt b/scripts/config_whitelist.txt
index c6a8312495..6934c7ed2e 100644
--- a/scripts/config_whitelist.txt
+++ b/scripts/config_whitelist.txt
@@ -2296,8 +2296,6 @@ CONFIG_SYS_FSL_AIOP1_SIZE
 CONFIG_SYS_FSL_B4860QDS_XFI_ERR
 CONFIG_SYS_FSL_BMAN_ADDR
 CONFIG_SYS_FSL_BMAN_OFFSET
-CONFIG_SYS_FSL_BOOTROM_BASE
-CONFIG_SYS_FSL_BOOTROM_SIZE
 CONFIG_SYS_FSL_CCSR_BASE
 CONFIG_SYS_FSL_CCSR_GUR_BE
 CONFIG_SYS_FSL_CCSR_GUR_LE
-- 
2.17.1



[PATCH v1] qemu-arm: round down memory to multiple of 2MB

2021-02-11 Thread Igor Opaniuk
From: Igor Opaniuk 

When LPAE is enabled, 1:1 mapping is created using 2 MB blocks.
In case amount of memory provided to QEMU is not multiple
of 2 MB, round down the amount of available memory to avoid hang
during MMU initialization.

How to reproduce:
qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots
qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs

DRAM:  1 GiB
initcall: 60011df8
initcall: 60011904
New Stack Pointer is: 80fffe90
initcall: 60011a20
initcall: 60011bcc
initcall: 60011bd4
initcall: 600119b4
Relocation Offset is: 22042000
Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
initcall: 60011b8c
initcall: 82053ea0
initcall: 82053ea8
initcall: 60012040 (relocated to 82054040)
dram_bank_mmu_setup: bank: 0
--- hang here during mmu init ---

Fixes: 3fa914af82("arm: qemu: implement enable_caches()")
Signed-off-by: Igor Opaniuk 

---

 board/emulation/qemu-arm/qemu-arm.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/board/emulation/qemu-arm/qemu-arm.c 
b/board/emulation/qemu-arm/qemu-arm.c
index aa68bef469..841dd7af0e 100644
--- a/board/emulation/qemu-arm/qemu-arm.c
+++ b/board/emulation/qemu-arm/qemu-arm.c
@@ -84,6 +84,18 @@ int dram_init(void)
if (fdtdec_setup_mem_size_base() != 0)
return -EINVAL;
 
+   /*
+* When LPAE is enabled (ARMv7),
+* 1:1 mapping is created using 2 MB blocks.
+*
+* In case amount of memory provided to QEMU
+* is not multiple of 2 MB, round down the amount
+* of available memory to avoid hang during MMU
+* initialization.
+*/
+   if (CONFIG_IS_ENABLED(ARMV7_LPAE))
+   gd->ram_size -= (gd->ram_size % 0x20);
+
return 0;
 }
 
-- 
2.25.1



Re: [PATCH] clk: at91: compat: partially revert "dm: Remove uses of device_bind_offset()"

2021-02-11 Thread Eugen.Hristev
On 03.02.2021 14:59, Simon Glass wrote:
> On Tue, 2 Feb 2021 at 01:48, Eugen Hristev  
> wrote:
>>
>> Revert changes in at91 compat.c that cause u-boot to fail booting on
>> sama5d4_xplained and sama5d2_xplained
>>
>> Log below:
>>
>> 
>> No serial driver found
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Could not initialize timer (err -19)
>>
>> Fixes: a2703ce10c ("dm: Remove uses of device_bind_offset()")
>> Cc: Simon Glass 
>> Signed-off-by: Eugen Hristev 
>> ---
>>   drivers/clk/at91/compat.c | 20 
>>   1 file changed, 12 insertions(+), 8 deletions(-)
> 
> Reviewed-by: Simon Glass 
> 
> Nice work.
> 

Applied to u-boot-atmel/master


Re: [PATCH] ARM: dts: at91: sama7g5ek: enable pull-up for serial debug line

2021-02-11 Thread Eugen.Hristev
On 28.01.2021 10:14, Eugen Hristev wrote:
> If the serial tx/rx are floating, it can happen that bogus characters
> are detected on the line at boot time. This leads to U-boot accidentally
> thinking someone pressed a key to stop autoboot, thus stopping booting 
> process.
> This can happen if the serial cable is not connected. There are hardware
> pull-ups on the board connected to serial cable VBUS.
> To solve this when the cable is not plugged, enable internal pull-ups as well
> for the tx/rx lines.
> 
> Signed-off-by: Eugen Hristev 
> ---
>   arch/arm/dts/sama7g5ek.dts | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/dts/sama7g5ek.dts b/arch/arm/dts/sama7g5ek.dts
> index ff9c9eb45c..3a4fdd38a5 100644
> --- a/arch/arm/dts/sama7g5ek.dts
> +++ b/arch/arm/dts/sama7g5ek.dts
> @@ -122,7 +122,7 @@
>   pinctrl_flx3_default: flx3_default {
>   pinmux = ,
>;
> - bias-disable;
> + bias-pull-up;
>   };
>   
>   pinctrl_sdmmc0_cmd_data_default: sdmmc0_cmd_data_default {
> 

Applied to u-boot-atmel/master


Re: [PATCH] usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

2021-02-11 Thread Marek Vasut

On 2/11/21 10:58 AM, Patrice CHOTARD wrote:

Hi Marek

On 2/10/21 3:26 PM, Marek Vasut wrote:

On 2/10/21 3:17 PM, Patrice Chotard wrote:

Since commit 8745b9ebccae ("usb: gadget: add super speed support")
ums was no more functional on platform which use dwc2_udc_otg driver.

Remove the speed test in dwc2_gadget_start() to fix it.
Tested on stm32mp157c-ev1 board.


Isn't the speed check correct though ?


I am not sure this speed test is needed.



What is really going on when this fails ?



Since 8745b9ebccae ("usb: gadget: add super speed support"),
driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

and this forbids dwc2_udc_otg.c to be registered.


That sounds like a bug in the USB gadget/otg core , no ?


[PATCH v2 1/1] efi_loader: fix get_last_capsule()

2021-02-11 Thread Heinrich Schuchardt
fix get_last_capsule() leads to writes beyond the stack allocated buffer.
This was indicated when enabling the stack protector.

utf16_utf8_strcpy() only stops copying when reaching '\0'. The current
invocation always writes beyond the end of value[].

The output length of utf16_utf8_strcpy() may be longer than the number of
UTF-16 tokens. E.g has "CapsuleКиев" has 11 UTF-16 tokens but 15 UTF-8
tokens. Hence, using utf16_utf8_strcpy() without checking the input may
lead to further writes beyond value[].

The current invocation of strict_strtoul() reads beyond the end of value[].

A non-hexadecimal value after "Capsule" (e.g. "Capsule") must result in
an error. We cat catch this by checking the return value of strict_strtoul().

A value that is too short after "Capsule" (e.g. "Capsule0") must result in
an error. We must check the string length of value[].

Signed-off-by: Heinrich Schuchardt 
---
v2:
check for non-ANSI character
---
 lib/efi_loader/efi_capsule.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c
index d39d731080..0017f0c0db 100644
--- a/lib/efi_loader/efi_capsule.c
+++ b/lib/efi_loader/efi_capsule.c
@@ -42,20 +42,28 @@ static struct efi_file_handle *bootdev_root;
 static __maybe_unused unsigned int get_last_capsule(void)
 {
u16 value16[11]; /* "Capsule": non-null-terminated */
-   char value[11], *p;
+   char value[5];
efi_uintn_t size;
unsigned long index = 0x;
efi_status_t ret;
+   int i;

size = sizeof(value16);
ret = efi_get_variable_int(L"CapsuleLast", _guid_capsule_report,
   NULL, , value16, NULL);
-   if (ret != EFI_SUCCESS || u16_strncmp(value16, L"Capsule", 7))
+   if (ret != EFI_SUCCESS || size != 22 ||
+   u16_strncmp(value16, L"Capsule", 7))
goto err;
+   for (i = 0; i < 4; ++i) {
+   u16 c = value16[i + 7];

-   p = value;
-   utf16_utf8_strcpy(, value16);
-   strict_strtoul([7], 16, );
+   if (!c || c > 0x7f)
+   goto err;
+   value[i] = c;
+   }
+   value[4] = 0;
+   if (strict_strtoul(value, 16, ))
+   index = 0x;
 err:
return index;
 }
--
2.30.0



[PATCH 1/1] buildman: 'Thread' object has no attribute 'isAlive'

2021-02-11 Thread Heinrich Schuchardt
The isAlive() method was deprecated in Python 3.8 and has been removed in
Python 3.9. See https://bugs.python.org/issue37804. Use is_alive() instead.

Since Python 2.6 is_alive() has been a synonym for isAlive(). So there
should be no problems for users using elder Python 3 versions.

Signed-off-by: Heinrich Schuchardt 
---
 tools/buildman/builder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index c93946842a..6f6d759329 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1691,7 +1691,7 @@ class Builder:
 term = threading.Thread(target=self.queue.join)
 term.setDaemon(True)
 term.start()
-while term.isAlive():
+while term.is_alive():
 term.join(100)

 # Wait until we have processed all output
--
2.30.0



Re: [PATCH v4] armv8: Handle EL2 Host mode

2021-02-11 Thread Marc Zyngier

Hi Mark,

On 2021-02-11 10:22, Mark Kettenis wrote:

Date: Thu, 11 Feb 2021 09:58:49 +
From: Marc Zyngier 

On 2021-02-10 19:14, Mark Kettenis wrote:
> On implementations that support VHE, the layout of the CPTR_EL2
> register depends on whether HCR_EL2.E2H is set.  If the bit is
> set, CPTR_EL2 uses the same layout as CPACR_EL1 and can in fact
> be accessed through that register.  In that case, jump to the
> EL1 code to enable access to the FP/SIMD registers.  This allows
> U-Boot to run on systems that pass control to U-Boot in EL2 with
> EL2 Host mode enabled such as machines using Apple's M1 SoC.
>
> Signed-off-by: Mark Kettenis 
> ---
>
> v4: use EL1 codepath when HCR_EL2.E2H is set
> suggested by Marc Zyngier 
>
> v2: rename label
>
>  arch/arm/cpu/armv8/start.S | 6 --
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> index 662449156b..9e9c6140cd 100644
> --- a/arch/arm/cpu/armv8/start.S
> +++ b/arch/arm/cpu/armv8/start.S
> @@ -132,11 +132,13 @@ pie_fixup_done:
>msr cntfrq_el0, x0  /* Initialize CNTFRQ */
>  #endif

This seems to skip the CNTFRQ_EL0 setup. However, this should
probably also be done on CPUs that do not have EL3, such as M1.
Unless the lower level FW already deals with it? Doesn't have to
be part of this patch though.


Hi Marc,

I think the basic assumption that U-Boot makes is that if you enter in
EL2 or EL1 there is firmware (e.g. TF-A) that does the CNTFRQ_EL0
setup.

On the M1 there is defenitely lower level FW that deals with this, so
this assumption is still fine.


Right. As long as CNTFRQ_EL0 gets set to the correct value on all CPUs,
I'm happy!

Thanks,

M.
--
Jazz is not dead. It just smells funny...


RE: [PATCH 10/16] ppc: Remove MPC8544DS board

2021-02-11 Thread Priyanka Jain
>-Original Message-
>From: Tom Rini 
>Sent: Wednesday, February 10, 2021 8:13 AM
>To: u-boot@lists.denx.de
>Cc: Priyanka Jain 
>Subject: [PATCH 10/16] ppc: Remove MPC8544DS board
>
>This board relies on using CONFIG_LIBATA but does not enable CONFIG_AHCI.
>The deadline for this conversion was the v2019.07 release.  The use of
>CONFIG_AHCI requires CONFIG_DM.  The deadline for this conversion was
>v2020.01.  Remove this board.
>
>Cc: Priyanka Jain 
>Signed-off-by: Tom Rini 
>---
Reviewed-by: Priyanka Jain 


RE: [PATCH 11/16] ppc: Remove MPC8572DS board

2021-02-11 Thread Priyanka Jain



>-Original Message-
>From: Tom Rini 
>Sent: Wednesday, February 10, 2021 8:13 AM
>To: u-boot@lists.denx.de
>Cc: Priyanka Jain 
>Subject: [PATCH 11/16] ppc: Remove MPC8572DS board
>
>This board relies on using CONFIG_LIBATA but does not enable CONFIG_AHCI.
>The deadline for this conversion was the v2019.07 release.  The use of
>CONFIG_AHCI requires CONFIG_DM.  The deadline for this conversion was
>v2020.01.  Remove this board.
>
>Cc: Priyanka Jain 
>Signed-off-by: Tom Rini 
>---
Reviewed-by: Priyanka Jain 


RE: [PATCH 12/16] ppc: Remove MPC8610HPCD board

2021-02-11 Thread Priyanka Jain
>-Original Message-
>From: Tom Rini 
>Sent: Wednesday, February 10, 2021 8:13 AM
>To: u-boot@lists.denx.de
>Cc: Priyanka Jain 
>Subject: [PATCH 12/16] ppc: Remove MPC8610HPCD board
>
>This board relies on using CONFIG_LIBATA but does not enable CONFIG_AHCI.
>The deadline for this conversion was the v2019.07 release.  The use of
>CONFIG_AHCI requires CONFIG_DM.  The deadline for this conversion was
>v2020.01.  Remove this board.
>
>Cc: Priyanka Jain 
>Signed-off-by: Tom Rini 
>---
Reviewed-by: Priyanka Jain 


RE: [PATCH 13/16] ppc: Remove MPC8641HPCN board

2021-02-11 Thread Priyanka Jain



>-Original Message-
>From: Tom Rini 
>Sent: Wednesday, February 10, 2021 8:13 AM
>To: u-boot@lists.denx.de
>Cc: Priyanka Jain 
>Subject: [PATCH 13/16] ppc: Remove MPC8641HPCN board
>
>This board relies on using CONFIG_LIBATA but does not enable CONFIG_AHCI.
>The deadline for this conversion was the v2019.07 release.  The use of
>CONFIG_AHCI requires CONFIG_DM.  The deadline for this conversion was
>v2020.01.  Remove this board.
>
>Cc: Priyanka Jain 
>Signed-off-by: Tom Rini 
>---
Reviewed-by: Priyanka Jain 


RE: [PATCH 18/25] arm: Remove ls2080a_simu board

2021-02-11 Thread Priyanka Jain
>-Original Message-
>From: Tom Rini 
>Sent: Tuesday, February 9, 2021 6:33 PM
>To: u-boot@lists.denx.de
>Cc: Prabhakar Kushwaha ; Priyanka Jain
>
>Subject: [PATCH 18/25] arm: Remove ls2080a_simu board
>
>This board has not been converted to CONFIG_DM_MMC by the deadline of
>v2019.04, which is almost two years ago.  In addition there are other DM
>migrations it is also missing.  Remove it.
>
>Cc: Prabhakar Kushwaha 
>Cc: Priyanka Jain 
>Signed-off-by: Tom Rini 
>---
Reviewed-by: Priyanka Jain 


Re: [PATCH v4] armv8: Handle EL2 Host mode

2021-02-11 Thread Mark Kettenis
> Date: Thu, 11 Feb 2021 09:58:49 +
> From: Marc Zyngier 
> 
> On 2021-02-10 19:14, Mark Kettenis wrote:
> > On implementations that support VHE, the layout of the CPTR_EL2
> > register depends on whether HCR_EL2.E2H is set.  If the bit is
> > set, CPTR_EL2 uses the same layout as CPACR_EL1 and can in fact
> > be accessed through that register.  In that case, jump to the
> > EL1 code to enable access to the FP/SIMD registers.  This allows
> > U-Boot to run on systems that pass control to U-Boot in EL2 with
> > EL2 Host mode enabled such as machines using Apple's M1 SoC.
> > 
> > Signed-off-by: Mark Kettenis 
> > ---
> > 
> > v4: use EL1 codepath when HCR_EL2.E2H is set
> > suggested by Marc Zyngier 
> > 
> > v2: rename label
> > 
> >  arch/arm/cpu/armv8/start.S | 6 --
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
> > index 662449156b..9e9c6140cd 100644
> > --- a/arch/arm/cpu/armv8/start.S
> > +++ b/arch/arm/cpu/armv8/start.S
> > @@ -132,11 +132,13 @@ pie_fixup_done:
> > msr cntfrq_el0, x0  /* Initialize CNTFRQ */
> >  #endif
> 
> This seems to skip the CNTFRQ_EL0 setup. However, this should
> probably also be done on CPUs that do not have EL3, such as M1.
> Unless the lower level FW already deals with it? Doesn't have to
> be part of this patch though.

Hi Marc,

I think the basic assumption that U-Boot makes is that if you enter in
EL2 or EL1 there is firmware (e.g. TF-A) that does the CNTFRQ_EL0
setup.

On the M1 there is defenitely lower level FW that deals with this, so
this assumption is still fine.

> > b   0f
> > -2: set_vbarvbar_el2, x0
> > +2: mrs x1, hcr_el2
> > +   tbnzx1, #34, 1f /* HCR_EL2.E2H */
> > +   set_vbar vbar_el2, x0
> > mov x0, #0x33ff
> > msr cptr_el2, x0/* Enable FP/SIMD */
> > b   0f
> > -1: set_vbarvbar_el1, x0
> > +1: set_vbar vbar_el1, x0
> > mov x0, #3 << 20
> > msr cpacr_el1, x0   /* Enable FP/SIMD */
> >  0:
> 
> This otherwise looks good.
> 
> Acked-by: Marc Zyngier 
> 
>  M.
> -- 
> Jazz is not dead. It just smells funny...
> 


Re: [PATCH v6 5/5] test: add a simple test for the adc-keys button driver

2021-02-11 Thread Heinrich Schuchardt
On 11.02.21 09:47, Marek Szyprowski wrote:
> Add adc-keys device to the sandbox/test.dts and connect it to the channel
> #3 of the sandbox_adc driver. The default values sampled by sandbox_adc
> driver determines that button3 and button4 are released and button5 is
> pressed.
>
> Signed-off-by: Marek Szyprowski 
> ---
>  arch/sandbox/dts/test.dts | 24 ++-
>  configs/sandbox_defconfig |  1 +
>  test/dm/button.c  | 50 +--
>  3 files changed, 72 insertions(+), 3 deletions(-)
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index e95f4631bf..a32b019ae7 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -69,6 +69,27 @@
>   };
>   };
>
> + buttons2 {
> + compatible = "adc-keys";
> + io-channels = < 3>;
> + keyup-threshold-microvolt = <300>;
> +
> + button-up {
> + label = "button3";
> + press-threshold-microvolt = <150>;

In patch 1/5 you wrote that "linux,code" is a required property.

Even if you don't use the property currently, I suggest to keep test.dts
compliant.

Best regards

Heinrich

> + };
> +
> + button-down {
> + label = "button4";
> + press-threshold-microvolt = <100>;
> + };
> +
> + button-enter {
> + label = "button5";
> + press-threshold-microvolt = <50>;
> + };
> + };
> +
>   cros_ec: cros-ec {
>   reg = <0 0>;
>   compatible = "google,cros-ec-sandbox";
> @@ -587,8 +608,9 @@
>   i2c-eeprom = <_i2c>;
>   };
>
> - adc@0 {
> + adc: adc@0 {
>   compatible = "sandbox,adc";
> + #io-channel-cells = <1>;
>   vdd-supply = <>;
>   vss-microvolts = <0>;
>   };
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index 0c7674efc9..3731bf05ff 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -122,6 +122,7 @@ CONFIG_DM_BOOTCOUNT=y
>  CONFIG_DM_BOOTCOUNT_RTC=y
>  CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y
>  CONFIG_BUTTON=y
> +CONFIG_BUTTON_ADC=y
>  CONFIG_BUTTON_GPIO=y
>  CONFIG_CLK=y
>  CONFIG_CLK_COMPOSITE_CCF=y
> diff --git a/test/dm/button.c b/test/dm/button.c
> index ecaa47cf5f..f8a7fab61d 100644
> --- a/test/dm/button.c
> +++ b/test/dm/button.c
> @@ -7,7 +7,10 @@
>
>  #include 
>  #include 
> +#include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -17,11 +20,20 @@ static int dm_test_button_base(struct unit_test_state 
> *uts)
>  {
>   struct udevice *dev;
>
> - /* Get the top-level device */
> + /* Get the top-level gpio buttons device */
>   ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, ));
> + /* Get the 2 gpio buttons */
>   ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, ));
>   ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, ));
> - ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, ));
> +
> + /* Get the top-level adc buttons device */
> + ut_assertok(uclass_get_device(UCLASS_BUTTON, 3, ));
> + /* Get the 3 adc buttons */
> + ut_assertok(uclass_get_device(UCLASS_BUTTON, 4, ));
> + ut_assertok(uclass_get_device(UCLASS_BUTTON, 5, ));
> + ut_assertok(uclass_get_device(UCLASS_BUTTON, 6, ));
> +
> + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 7, ));
>
>   return 0;
>  }
> @@ -72,3 +84,37 @@ static int dm_test_button_label(struct unit_test_state 
> *uts)
>   return 0;
>  }
>  DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
> +
> +/* Test adc-keys driver */
> +static int dm_test_button_keys_adc(struct unit_test_state *uts)
> +{
> + struct udevice *supply;
> + struct udevice *dev;
> + int uV;
> +
> + ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc@0", ));
> +
> + ut_assertok(regulator_get_by_devname(SANDBOX_BUCK2_DEVNAME, ));
> + ut_assertok(regulator_set_value(supply, SANDBOX_BUCK2_SET_UV));
> + ut_asserteq(SANDBOX_BUCK2_SET_UV, regulator_get_value(supply));
> + /* Update ADC plat and get new Vdd value */
> + ut_assertok(adc_vdd_value(dev, ));
> + ut_asserteq(SANDBOX_BUCK2_SET_UV, uV);
> +
> + /*
> +  * sandbox-adc returns constant value on channel 3, is used by adc-keys:
> +  * SANDBOX_ADC_CHANNEL3_DATA * SANDBOX_BUCK2_SET_UV / 
> SANDBOX_ADC_DATA_MASK =
> +  * 0x3000 * 330 / 0x = 618759uV
> +  * This means that button3 and button4 are released and button5
> +  * is pressed.
> +  */
> + ut_assertok(button_get_by_label("button3", ));
> + ut_asserteq(BUTTON_OFF, button_get_state(dev));
> + ut_assertok(button_get_by_label("button4", ));
> + ut_asserteq(BUTTON_OFF, button_get_state(dev));
> + ut_assertok(button_get_by_label("button5", ));
> + 

Re: [PATCH v4] armv8: Handle EL2 Host mode

2021-02-11 Thread Marc Zyngier

On 2021-02-10 19:14, Mark Kettenis wrote:

On implementations that support VHE, the layout of the CPTR_EL2
register depends on whether HCR_EL2.E2H is set.  If the bit is
set, CPTR_EL2 uses the same layout as CPACR_EL1 and can in fact
be accessed through that register.  In that case, jump to the
EL1 code to enable access to the FP/SIMD registers.  This allows
U-Boot to run on systems that pass control to U-Boot in EL2 with
EL2 Host mode enabled such as machines using Apple's M1 SoC.

Signed-off-by: Mark Kettenis 
---

v4: use EL1 codepath when HCR_EL2.E2H is set
suggested by Marc Zyngier 

v2: rename label

 arch/arm/cpu/armv8/start.S | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S
index 662449156b..9e9c6140cd 100644
--- a/arch/arm/cpu/armv8/start.S
+++ b/arch/arm/cpu/armv8/start.S
@@ -132,11 +132,13 @@ pie_fixup_done:
msr cntfrq_el0, x0  /* Initialize CNTFRQ */
 #endif


This seems to skip the CNTFRQ_EL0 setup. However, this should
probably also be done on CPUs that do not have EL3, such as M1.
Unless the lower level FW already deals with it? Doesn't have to
be part of this patch though.


b   0f
-2: set_vbarvbar_el2, x0
+2: mrs x1, hcr_el2
+   tbnzx1, #34, 1f /* HCR_EL2.E2H */
+   set_vbar vbar_el2, x0
mov x0, #0x33ff
msr cptr_el2, x0/* Enable FP/SIMD */
b   0f
-1: set_vbarvbar_el1, x0
+1: set_vbar vbar_el1, x0
mov x0, #3 << 20
msr cpacr_el1, x0   /* Enable FP/SIMD */
 0:


This otherwise looks good.

Acked-by: Marc Zyngier 

M.
--
Jazz is not dead. It just smells funny...


Re: [PATCH] usb: gadget: dwc2_udc_otg: Fix dwc2_gadget_start()

2021-02-11 Thread Patrice CHOTARD
Hi Marek

On 2/10/21 3:26 PM, Marek Vasut wrote:
> On 2/10/21 3:17 PM, Patrice Chotard wrote:
>> Since commit 8745b9ebccae ("usb: gadget: add super speed support")
>> ums was no more functional on platform which use dwc2_udc_otg driver.
>>
>> Remove the speed test in dwc2_gadget_start() to fix it.
>> Tested on stm32mp157c-ev1 board.
> 
> Isn't the speed check correct though ?

I am not sure this speed test is needed.

> 
> What is really going on when this fails ?


Since 8745b9ebccae ("usb: gadget: add super speed support"), 
driver->speed is now set to USB_SPEED_SUPER in drivers/usb/gadget/composite.c

and this forbids dwc2_udc_otg.c to be registered.

Patrice

> 
>> Fixes: c791c8431c34 ("usb: dwc2: convert driver to DM_USB_GADGET")
>>
>> Signed-off-by: Patrice Chotard 
>> ---
>>
>>   drivers/usb/gadget/dwc2_udc_otg.c | 10 ++
>>   1 file changed, 2 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/dwc2_udc_otg.c 
>> b/drivers/usb/gadget/dwc2_udc_otg.c
>> index e3871e381e..4f3d761eb1 100644
>> --- a/drivers/usb/gadget/dwc2_udc_otg.c
>> +++ b/drivers/usb/gadget/dwc2_udc_otg.c
>> @@ -248,10 +248,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver 
>> *driver)
>>     debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
>>   -    if (!driver
>> -    || (driver->speed != USB_SPEED_FULL
>> -    && driver->speed != USB_SPEED_HIGH)
>> -    || !driver->bind || !driver->disconnect || !driver->setup)
>> +    if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
>>   return -EINVAL;
>>   if (!dev)
>>   return -ENODEV;
>> @@ -320,10 +317,7 @@ static int dwc2_gadget_start(struct usb_gadget *g,
>>     debug_cond(DEBUG_SETUP != 0, "%s: %s\n", __func__, "no name");
>>   -    if (!driver ||
>> -    (driver->speed != USB_SPEED_FULL &&
>> - driver->speed != USB_SPEED_HIGH) ||
>> -    !driver->bind || !driver->disconnect || !driver->setup)
>> +    if (!driver || !driver->bind || !driver->disconnect || !driver->setup)
>>   return -EINVAL;
>>     if (!dev)
>>
> 
> 
> [...]


Re: [PATCH 2/2] mtd: nand: spi: Support GigaDevice GD5F1GQ5UExxG

2021-02-11 Thread Stefan Roese

On 10.02.21 19:36, Reto Schneider wrote:

From: Reto Schneider 

The relevant changes to the already existing GD5F1GQ4UExxG support has
been determined by consulting the GigaDevice product change notice
AN-0392-10, version 1.0 from November 30, 2020.

As the overlaps are huge, variable names have been generalized
accordingly.

Apart form the lowered ECC strength (4 instead of 8 bits per 512 bytes),
the new device ID, and the extra quad IO dummy byte, no changes had to
be taken into account.

New hardware features are not supported, namely:
  - Power on reset
  - Unique ID
  - Double transfer rate (DTR)
  - Parameter page
  - Random data quad IO

The inverted semantic of the "driver strength" register bits, defaulting
to 100% instead of 50% for the Q5 devices, got ignored as the driver has
never touched them anyway.

The no longer supported "read from cache during block erase"
functionality I do not know how to reflect.

Implementation has been tested on MediaTek MT7688 based GARDENA smart
Gateways using both, GigaDevice GD5F1GQ5UEYIG and GD5F1GQ4UBYIG.

Signed-off-by: Reto Schneider 
CC: Stefan Roese 


Looks good, so:

Reviewed-by: Stefan Roese 

Thanks,
Stefan


---
  drivers/mtd/nand/spi/gigadevice.c | 79 +++
  1 file changed, 69 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/nand/spi/gigadevice.c 
b/drivers/mtd/nand/spi/gigadevice.c
index 5de0ebbb7b..a2c93486f4 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -17,9 +17,13 @@
  #define GD5FXGQ4XA_STATUS_ECC_1_7_BITFLIPS(1 << 4)
  #define GD5FXGQ4XA_STATUS_ECC_8_BITFLIPS  (3 << 4)
  
-#define GD5FXGQ4XEXXG_REG_STATUS2		0xf0

+#define GD5FXGQ5XE_STATUS_ECC_1_4_BITFLIPS (1 << 4)
+#define GD5FXGQ5XE_STATUS_ECC_4_BITFLIPS   (3 << 4)
  
-static SPINAND_OP_VARIANTS(read_cache_variants,

+#define GD5FXGQXXEXXG_REG_STATUS2  0xf0
+
+/* Q4 devices, QUADIO: Dummy bytes valid for 1 and 2 GBit variants */
+static SPINAND_OP_VARIANTS(gd5fxgq4_read_cache_variants,
SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
@@ -27,6 +31,15 @@ static SPINAND_OP_VARIANTS(read_cache_variants,
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
  
+/* Q5 devices, QUADIO: Dummy bytes only valid for 1 GBit variants */

+static SPINAND_OP_VARIANTS(gd5f1gq5_read_cache_variants,
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
+
  static SPINAND_OP_VARIANTS(write_cache_variants,
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
SPINAND_PROG_LOAD(true, 0, NULL, 0));
@@ -35,7 +48,7 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
SPINAND_PROG_LOAD(false, 0, NULL, 0));
  
-static int gd5fxgq4xexxg_ooblayout_ecc(struct mtd_info *mtd, int section,

+static int gd5fxgqxxexxg_ooblayout_ecc(struct mtd_info *mtd, int section,
   struct mtd_oob_region *region)
  {
if (section)
@@ -47,7 +60,7 @@ static int gd5fxgq4xexxg_ooblayout_ecc(struct mtd_info *mtd, 
int section,
return 0;
  }
  
-static int gd5fxgq4xexxg_ooblayout_free(struct mtd_info *mtd, int section,

+static int gd5fxgqxxexxg_ooblayout_free(struct mtd_info *mtd, int section,
struct mtd_oob_region *region)
  {
if (section)
@@ -64,7 +77,7 @@ static int gd5fxgq4xexxg_ecc_get_status(struct spinand_device 
*spinand,
u8 status)
  {
u8 status2;
-   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQ4XEXXG_REG_STATUS2,
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQXXEXXG_REG_STATUS2,
  );
int ret;
  
@@ -102,21 +115,67 @@ static int gd5fxgq4xexxg_ecc_get_status(struct spinand_device *spinand,

return -EINVAL;
  }
  
-static const struct mtd_ooblayout_ops gd5fxgq4xexxg_ooblayout = {

-   .ecc = gd5fxgq4xexxg_ooblayout_ecc,
-   .rfree = gd5fxgq4xexxg_ooblayout_free,
+static int gd5fxgq5xexxg_ecc_get_status(struct spinand_device *spinand,
+   u8 status)
+{
+   u8 status2;
+   struct spi_mem_op op = SPINAND_GET_FEATURE_OP(GD5FXGQXXEXXG_REG_STATUS2,
+ );
+   int ret;
+
+   switch (status & 

Re: [PATCH 1/2] mtd: nand: spi: Only one dummy byte in QUADIO

2021-02-11 Thread Stefan Roese

On 10.02.21 19:36, Reto Schneider wrote:

From: Reto Schneider 

The datasheet only lists one dummy byte in the 0xEH operation for the
following chips:
* GD5F1GQ4xBxxG
* GD5F1GQ4xExxG
* GD5F1GQ4xFxxG
* GD5F1GQ4UAYIG
* GD5F4GQ4UAYIG

This patch and its commit message reflects what has been done in Linux
and has not been tested by me.

Signed-off-by: Reto Schneider 
CC: Stefan Roese 


AFAICT, you are posting a Linux patch ported to U-Boot here. Which is
good of course. But if you didn't do substantial changes to this
patch, then please keep the original (Linux) authorship of Hauke for
this patch (From: ...). You might want to add something like:

Reto Schneider:
Linux patch ported to U-Boot

to the end of the commit text and add your Sob of course.

Other than this:

Reviewed-by: Stefan Roese 

Thanks,
Stefan



---
  drivers/mtd/nand/spi/gigadevice.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/spi/gigadevice.c 
b/drivers/mtd/nand/spi/gigadevice.c
index 0b228dcb5b..5de0ebbb7b 100644
--- a/drivers/mtd/nand/spi/gigadevice.c
+++ b/drivers/mtd/nand/spi/gigadevice.c
@@ -20,7 +20,7 @@
  #define GD5FXGQ4XEXXG_REG_STATUS2 0xf0
  
  static SPINAND_OP_VARIANTS(read_cache_variants,

-   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
+   SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 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: qemu-arm: hang during MMU initialization

2021-02-11 Thread Ard Biesheuvel
On Fri, 5 Feb 2021 at 18:38, Igor Opaniuk  wrote:
>
> Hi,
>
> With this commit 3fa914af82("arm: qemu: implement enable_caches()") 
> introduced,
> which enables instruction/data caches for qemu-arm target,
> U-Boot sometimes hangs during MMU init procedure :
>
> DRAM:  1 GiB
> initcall: 60011df8
> initcall: 60011904
> New Stack Pointer is: 80fffe90
> initcall: 60011a20
> initcall: 60011bcc
> initcall: 60011bd4
> initcall: 600119b4
> Relocation Offset is: 22042000
> Relocating to 82042000, new gd at 81001ed0, sp at 80fffe90
> initcall: 60011b8c
> initcall: 82053ea0
> initcall: 82053ea8
> initcall: 60012040 (relocated to 82054040)
> dram_bank_mmu_setup: bank: 0
>
> This issue reproduces every time when the amount of memory provided to QEMU
> is not 2MB granular. Looks like it might be some unexpected alignment issue.
>
> Test results (QEMU v5.2.0 release):
> qemu-system-arm -machine virt -m 1058 -nographic -bios u-boot.bin - boots OK
> qemu-system-arm -machine virt -m 1057 -nographic -bios u-boot.bin - hangs
> qemu-system-arm -machine virt -m 1056 -nographic -bios u-boot.bin - boots OK
> qemu-system-arm -machine virt -m 1055 -nographic -bios u-boot.bin - hangs
>
> Unfortunately I didn't have a chance to investigate this further, so
> just sharing my current observations. Thanks for any input.
>

Hello Igor,

enable_caches() results in a 1:1 mapping to be created, and since LPAE
has been enabled as well, the 1:1 mapping is created using 2 MB
blocks. So I am not surprised that using a value that is not a
multiple of 2 MB causes problems.

I'd suggest implementing a simple fix, e.g., just round down the
amount of available memory, as this is not something that is likely to
ever be a problem on real systems.

-- 
Ard.


[PATCH v6 5/5] test: add a simple test for the adc-keys button driver

2021-02-11 Thread Marek Szyprowski
Add adc-keys device to the sandbox/test.dts and connect it to the channel
#3 of the sandbox_adc driver. The default values sampled by sandbox_adc
driver determines that button3 and button4 are released and button5 is
pressed.

Signed-off-by: Marek Szyprowski 
---
 arch/sandbox/dts/test.dts | 24 ++-
 configs/sandbox_defconfig |  1 +
 test/dm/button.c  | 50 +--
 3 files changed, 72 insertions(+), 3 deletions(-)

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e95f4631bf..a32b019ae7 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -69,6 +69,27 @@
};
};
 
+   buttons2 {
+   compatible = "adc-keys";
+   io-channels = < 3>;
+   keyup-threshold-microvolt = <300>;
+
+   button-up {
+   label = "button3";
+   press-threshold-microvolt = <150>;
+   };
+
+   button-down {
+   label = "button4";
+   press-threshold-microvolt = <100>;
+   };
+
+   button-enter {
+   label = "button5";
+   press-threshold-microvolt = <50>;
+   };
+   };
+
cros_ec: cros-ec {
reg = <0 0>;
compatible = "google,cros-ec-sandbox";
@@ -587,8 +608,9 @@
i2c-eeprom = <_i2c>;
};
 
-   adc@0 {
+   adc: adc@0 {
compatible = "sandbox,adc";
+   #io-channel-cells = <1>;
vdd-supply = <>;
vss-microvolts = <0>;
};
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 0c7674efc9..3731bf05ff 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -122,6 +122,7 @@ CONFIG_DM_BOOTCOUNT=y
 CONFIG_DM_BOOTCOUNT_RTC=y
 CONFIG_DM_BOOTCOUNT_I2C_EEPROM=y
 CONFIG_BUTTON=y
+CONFIG_BUTTON_ADC=y
 CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
 CONFIG_CLK_COMPOSITE_CCF=y
diff --git a/test/dm/button.c b/test/dm/button.c
index ecaa47cf5f..f8a7fab61d 100644
--- a/test/dm/button.c
+++ b/test/dm/button.c
@@ -7,7 +7,10 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
@@ -17,11 +20,20 @@ static int dm_test_button_base(struct unit_test_state *uts)
 {
struct udevice *dev;
 
-   /* Get the top-level device */
+   /* Get the top-level gpio buttons device */
ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, ));
+   /* Get the 2 gpio buttons */
ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, ));
ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, ));
-   ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, ));
+
+   /* Get the top-level adc buttons device */
+   ut_assertok(uclass_get_device(UCLASS_BUTTON, 3, ));
+   /* Get the 3 adc buttons */
+   ut_assertok(uclass_get_device(UCLASS_BUTTON, 4, ));
+   ut_assertok(uclass_get_device(UCLASS_BUTTON, 5, ));
+   ut_assertok(uclass_get_device(UCLASS_BUTTON, 6, ));
+
+   ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 7, ));
 
return 0;
 }
@@ -72,3 +84,37 @@ static int dm_test_button_label(struct unit_test_state *uts)
return 0;
 }
 DM_TEST(dm_test_button_label, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+/* Test adc-keys driver */
+static int dm_test_button_keys_adc(struct unit_test_state *uts)
+{
+   struct udevice *supply;
+   struct udevice *dev;
+   int uV;
+
+   ut_assertok(uclass_get_device_by_name(UCLASS_ADC, "adc@0", ));
+
+   ut_assertok(regulator_get_by_devname(SANDBOX_BUCK2_DEVNAME, ));
+   ut_assertok(regulator_set_value(supply, SANDBOX_BUCK2_SET_UV));
+   ut_asserteq(SANDBOX_BUCK2_SET_UV, regulator_get_value(supply));
+   /* Update ADC plat and get new Vdd value */
+   ut_assertok(adc_vdd_value(dev, ));
+   ut_asserteq(SANDBOX_BUCK2_SET_UV, uV);
+
+   /*
+* sandbox-adc returns constant value on channel 3, is used by adc-keys:
+* SANDBOX_ADC_CHANNEL3_DATA * SANDBOX_BUCK2_SET_UV / 
SANDBOX_ADC_DATA_MASK =
+* 0x3000 * 330 / 0x = 618759uV
+* This means that button3 and button4 are released and button5
+* is pressed.
+*/
+   ut_assertok(button_get_by_label("button3", ));
+   ut_asserteq(BUTTON_OFF, button_get_state(dev));
+   ut_assertok(button_get_by_label("button4", ));
+   ut_asserteq(BUTTON_OFF, button_get_state(dev));
+   ut_assertok(button_get_by_label("button5", ));
+   ut_asserteq(BUTTON_ON, button_get_state(dev));
+
+   return 0;
+}
+DM_TEST(dm_test_button_keys_adc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
-- 
2.17.1



[PATCH v6 2/5] button: add a simple Analog to Digital Converter device based button driver

2021-02-11 Thread Marek Szyprowski
Add a simple Analog to Digital Converter device based button driver. This
driver binds to the 'adc-keys' device tree node.

Signed-off-by: Marek Szyprowski 
---
 drivers/button/Kconfig  |   8 ++
 drivers/button/Makefile |   1 +
 drivers/button/button-adc.c | 146 
 3 files changed, 155 insertions(+)
 create mode 100644 drivers/button/button-adc.c

diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
index 6b3ec7e55d..6db3c5e93a 100644
--- a/drivers/button/Kconfig
+++ b/drivers/button/Kconfig
@@ -9,6 +9,14 @@ config BUTTON
  can provide access to board-specific buttons. Use of the device tree
  for configuration is encouraged.
 
+config BUTTON_ADC
+   bool "Button adc"
+   depends on BUTTON
+   help
+ Enable support for buttons which are connected to Analog to Digital
+ Converter device. The ADC driver must use driver model. Buttons are
+ configured using the device tree.
+
 config BUTTON_GPIO
bool "Button gpio"
depends on BUTTON
diff --git a/drivers/button/Makefile b/drivers/button/Makefile
index fcc10ebe8d..bbd18af149 100644
--- a/drivers/button/Makefile
+++ b/drivers/button/Makefile
@@ -3,4 +3,5 @@
 # Copyright (C) 2020 Philippe Reynes 
 
 obj-$(CONFIG_BUTTON) += button-uclass.o
+obj-$(CONFIG_BUTTON_ADC) += button-adc.o
 obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o
diff --git a/drivers/button/button-adc.c b/drivers/button/button-adc.c
new file mode 100644
index 00..eed86564fb
--- /dev/null
+++ b/drivers/button/button-adc.c
@@ -0,0 +1,146 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 Samsung Electronics Co., Ltd.
+ * http://www.samsung.com
+ * Author: Marek Szyprowski 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/**
+ * struct button_adc_priv - private data for button-adc driver.
+ *
+ * @adc: Analog to Digital Converter device to which button is connected.
+ * @channel: channel of the ADC device to probe the button state.
+ * @min: minimal uV value to consider button as pressed.
+ * @max: maximal uV value to consider button as pressed.
+ */
+struct button_adc_priv {
+   struct udevice *adc;
+   int channel;
+   int min;
+   int max;
+};
+
+static enum button_state_t button_adc_get_state(struct udevice *dev)
+{
+   struct button_adc_priv *priv = dev_get_priv(dev);
+   unsigned int val;
+   int ret, uV;
+
+   ret = adc_start_channel(priv->adc, priv->channel);
+   if (ret)
+   return ret;
+
+   ret = adc_channel_data(priv->adc, priv->channel, );
+   if (ret)
+   return ret;
+
+   ret = adc_raw_to_uV(priv->adc, val, );
+   if (ret)
+   return ret;
+
+   return (uV >= priv->min && uV < priv->max) ? BUTTON_ON : BUTTON_OFF;
+}
+
+static int button_adc_of_to_plat(struct udevice *dev)
+{
+   struct button_uc_plat *uc_plat = dev_get_uclass_plat(dev);
+   struct button_adc_priv *priv = dev_get_priv(dev);
+   struct ofnode_phandle_args args;
+   u32 treshold, up_treshold, t;
+   ofnode node;
+   int ret;
+
+   /* Ignore the top-level button node */
+   if (!uc_plat->label)
+   return 0;
+
+   ret = dev_read_phandle_with_args(dev->parent, "io-channels",
+"#io-channel-cells", 0, 0, );
+   if (ret)
+   return ret;
+
+   ret = uclass_get_device_by_ofnode(UCLASS_ADC, args.node, >adc);
+   if (ret)
+   return ret;
+
+   ret = ofnode_read_u32(dev_ofnode(dev->parent),
+ "keyup-threshold-microvolt", _treshold);
+   if (ret)
+   return ret;
+
+   ret = ofnode_read_u32(dev_ofnode(dev), "press-threshold-microvolt",
+ );
+   if (ret)
+   return ret;
+
+   dev_for_each_subnode(node, dev->parent) {
+   ret = ofnode_read_u32(node, "press-threshold-microvolt", );
+   if (ret)
+   return ret;
+
+   if (t > treshold)
+   up_treshold = t;
+   }
+
+   priv->channel = args.args[0];
+   priv->min = treshold;
+   priv->max = up_treshold;
+
+   return ret;
+}
+
+static int button_adc_bind(struct udevice *parent)
+{
+   struct udevice *dev;
+   ofnode node;
+   int ret;
+
+   dev_for_each_subnode(node, parent) {
+   struct button_uc_plat *uc_plat;
+   const char *label;
+
+   label = ofnode_read_string(node, "label");
+   if (!label) {
+   debug("%s: node %s has no label\n", __func__,
+ ofnode_get_name(node));
+   return -EINVAL;
+   }
+   ret = device_bind_driver_to_node(parent, "button_adc",
+ofnode_get_name(node),
+   

[PATCH v6 4/5] configs: khadas-vim3(l): enable Function button support

2021-02-11 Thread Marek Szyprowski
Add options required to check the 'Function' button state.

Signed-off-by: Marek Szyprowski 
Reviewed-by: Simon Glass 
---
 configs/khadas-vim3_defconfig  | 2 ++
 configs/khadas-vim3l_defconfig | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/configs/khadas-vim3_defconfig b/configs/khadas-vim3_defconfig
index 5d16652fd6..bc17430569 100644
--- a/configs/khadas-vim3_defconfig
+++ b/configs/khadas-vim3_defconfig
@@ -31,6 +31,8 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ADC=y
 CONFIG_SARADC_MESON=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_ADC=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MESON=y
 CONFIG_DM_MMC=y
diff --git a/configs/khadas-vim3l_defconfig b/configs/khadas-vim3l_defconfig
index 6b13ce045c..c1877922c7 100644
--- a/configs/khadas-vim3l_defconfig
+++ b/configs/khadas-vim3l_defconfig
@@ -31,6 +31,8 @@ CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
 CONFIG_ADC=y
 CONFIG_SARADC_MESON=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_ADC=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_MESON=y
 CONFIG_DM_MMC=y
-- 
2.17.1



[PATCH v6 0/5] VIM3: add support for checking 'Function' button state

2021-02-11 Thread Marek Szyprowski
Hi All,

This patchset adds all building blocks needed for checking the 'Function'
button state in the boot script on Amlogic A311D based VIM3 board. This
button is connected to the ADC line of the SoC, so it required to enable
meson SARADC, the clocks needed for it and a simple button-adc drivers.

Once applied, one can use following commands in the boot scripts:
-->8---
echo Checking Func button state: \\c
if button Function
then
echo Selected alternative boot
...
fi
--->8---

Best regards
Marek Szyprowski
Samsung R Institute Poland


Changelog:
v6:
- added a simple sandbox test for adc-keys
- use of_to_plat and adc_raw_to_uV to simplify code in the adc button driver

v5: https://lists.denx.de/pipermail/u-boot/2021-January/438751.html
- rebased onto latest uboot-amlogic/u-boot-amlogic-next branch
- synchronized adc-keys binding with the recent version from the Linux
  kernel
- updated adc-keys driver to match behavior from dt-bindings
- added a patch for meson-saradc driver to register vdd reference supply
  to the ADC framework

v4: https://lists.denx.de/pipermail/u-boot/2020-December/435641.html
- rebased onto uboot-amlogic/u-boot-amlogic-next and dropped merged patches
- added adc-keys bindings docs (copied from Linux kernel)
- minor code adjustments pointed by Simon
- enabled driver also in khadas-vim3l_defconfig

v3: https://lists.denx.de/pipermail/u-boot/2020-December/435072.html
- removed 'button' env variable
- extended kconfig and patch descriptions

v2: https://lists.denx.de/pipermail/u-boot/2020-December/434991.html
- removed Change-Id tags
- split defconfig changes into ADC and button related

v1: https://lists.denx.de/pipermail/u-boot/2020-December/434875.html
- initial submission


Patch summary:

Marek Szyprowski (5):
  dt-bindings: input: adc-keys bindings documentation
  button: add a simple Analog to Digital Converter device based button
driver
  adc: meson-saradc: add support for getting reference voltage value
  configs: khadas-vim3(l): enable Function button support
  test: add a simple test for the adc-keys button driver

 arch/sandbox/dts/test.dts   |  24 +++-
 configs/khadas-vim3_defconfig   |   2 +
 configs/khadas-vim3l_defconfig  |   2 +
 configs/sandbox_defconfig   |   1 +
 doc/device-tree-bindings/input/adc-keys.txt |  67 +
 drivers/adc/meson-saradc.c  |  21 +++
 drivers/button/Kconfig  |   8 ++
 drivers/button/Makefile |   1 +
 drivers/button/button-adc.c | 146 
 test/dm/button.c|  50 ++-
 10 files changed, 319 insertions(+), 3 deletions(-)
 create mode 100644 doc/device-tree-bindings/input/adc-keys.txt
 create mode 100644 drivers/button/button-adc.c

-- 
2.17.1



[PATCH v6 1/5] dt-bindings: input: adc-keys bindings documentation

2021-02-11 Thread Marek Szyprowski
Dump adc-keys bindings documentation from Linux kernel source tree from
commit 698dc0cf9447 ("dt-bindings: input: adc-keys: clarify
description").

Signed-off-by: Marek Szyprowski 
Reviewed-by: Simon Glass 
---
 doc/device-tree-bindings/input/adc-keys.txt | 67 +
 1 file changed, 67 insertions(+)
 create mode 100644 doc/device-tree-bindings/input/adc-keys.txt

diff --git a/doc/device-tree-bindings/input/adc-keys.txt 
b/doc/device-tree-bindings/input/adc-keys.txt
new file mode 100644
index 00..6c8be6a9ac
--- /dev/null
+++ b/doc/device-tree-bindings/input/adc-keys.txt
@@ -0,0 +1,67 @@
+ADC attached resistor ladder buttons
+
+
+Required properties:
+ - compatible: "adc-keys"
+ - io-channels: Phandle to an ADC channel
+ - io-channel-names = "buttons";
+ - keyup-threshold-microvolt: Voltage above or equal to which all the keys are
+ considered up.
+
+Optional properties:
+   - poll-interval: Poll interval time in milliseconds
+   - autorepeat: Boolean, Enable auto repeat feature of Linux input
+ subsystem.
+
+Each button (key) is represented as a sub-node of "adc-keys":
+
+Required subnode-properties:
+   - label: Descriptive name of the key.
+   - linux,code: Keycode to emit.
+   - press-threshold-microvolt: voltage above or equal to which this key is
+considered pressed.
+
+No two values of press-threshold-microvolt may be the same.
+All values of press-threshold-microvolt must be less than
+keyup-threshold-microvolt.
+
+Example:
+
+#include 
+
+   adc-keys {
+   compatible = "adc-keys";
+   io-channels = < 0>;
+   io-channel-names = "buttons";
+   keyup-threshold-microvolt = <200>;
+
+   button-up {
+   label = "Volume Up";
+   linux,code = ;
+   press-threshold-microvolt = <150>;
+   };
+
+   button-down {
+   label = "Volume Down";
+   linux,code = ;
+   press-threshold-microvolt = <100>;
+   };
+
+   button-enter {
+   label = "Enter";
+   linux,code = ;
+   press-threshold-microvolt = <50>;
+   };
+   };
+
++++
+| 2.000.000 <= value | no key pressed |
++++
+| 1.500.000 <= value < 2.000.000 | KEY_VOLUMEUP pressed   |
++++
+| 1.000.000 <= value < 1.500.000 | KEY_VOLUMEDOWN pressed |
++++
+|   500.000 <= value < 1.000.000 | KEY_ENTER pressed  |
++++
+|  value <   500.000 | no key pressed |
++++
-- 
2.17.1



[PATCH v6 3/5] adc: meson-saradc: add support for getting reference voltage value

2021-02-11 Thread Marek Szyprowski
Add support for getting the 'vref-supply' regulator and register it as
ADC's reference voltage regulator, so clients can translate sampled ADC
values to the voltage.

Signed-off-by: Marek Szyprowski 
Reviewed-by: Simon Glass 
---
 drivers/adc/meson-saradc.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/drivers/adc/meson-saradc.c b/drivers/adc/meson-saradc.c
index 21db55831d..1a45a3a265 100644
--- a/drivers/adc/meson-saradc.c
+++ b/drivers/adc/meson-saradc.c
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define MESON_SAR_ADC_REG0 0x00
#define MESON_SAR_ADC_REG0_PANEL_DETECT BIT(31)
@@ -656,7 +657,10 @@ static int meson_saradc_stop(struct udevice *dev)
 
 static int meson_saradc_probe(struct udevice *dev)
 {
+   struct adc_uclass_plat *uc_pdata = dev_get_uclass_plat(dev);
struct meson_saradc_priv *priv = dev_get_priv(dev);
+   struct udevice *vref;
+   int vref_uv;
int ret;
 
ret = regmap_init_mem(dev_ofnode(dev), >regmap);
@@ -675,6 +679,23 @@ static int meson_saradc_probe(struct udevice *dev)
 
priv->active_channel = -1;
 
+   ret = device_get_supply_regulator(dev, "vref-supply", );
+   if (ret) {
+   printf("can't get vref-supply: %d\n", ret);
+   return ret;
+   }
+
+   vref_uv = regulator_get_value(vref);
+   if (vref_uv < 0) {
+   printf("can't get vref-supply value: %d\n", vref_uv);
+   return vref_uv;
+   }
+
+   /* VDD supplied by common vref pin */
+   uc_pdata->vdd_supply = vref;
+   uc_pdata->vdd_microvolts = vref_uv;
+   uc_pdata->vss_microvolts = 0;
+
return 0;
 }
 
-- 
2.17.1