Skip to contentSkip to conversation

ARM: dts: stm32: Configure Buck3 voltage per PMIC NVM on Avenger96

PATCH In review Marek Vasut 2 participants 11 messages May 11, 2022 – May 20, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: dts: stm32: Configure Buck3 voltage per PMIC NVM on Avenger96

The Avenger96 board comes in multiple regulator configurations.
- rev.100 or rev.200 have Buck3 preconfigured to 3V3 operation on boot and contains extra Enpirion EP53A8LQI DCDC converter which supplies the IO. Reduce Buck3 voltage to 2V9 to not waste power.
- rev.200L have Buck3 preconfigured to 1V8 operation and have no Enpirion EP53A8LQI DCDC anymore, the IO is supplied from Buck3.

Configure the Buck3 voltage on this board per PMIC NVM settings and update buck3 voltage limits in DT passed to OS before booting OS to prevent potential hardware damage.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
 arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi |   2 +-
 board/dhelectronics/dh_stm32mp1/board.c   | 109 +++++++++++++++++++++-
 2 files changed, 107 insertions(+), 4 deletions(-)
arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi +1 -1
index 9937b28548c..e20917824bf 100644
@@ -19,7 +19,7 @@
 };
 
 &vdd {
-	regulator-min-microvolt = <2900000>;
+	regulator-min-microvolt = <1800000>;
 	regulator-max-microvolt = <2900000>;
 };
 
board/dhelectronics/dh_stm32mp1/board.c +106 -3

126 lines not on this page · raw message

Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Hi,

Quoted 48 lines · Marek Vasut

The Avenger96 board comes in multiple regulator configurations.
- rev.100 or rev.200 have Buck3 preconfigured to 3V3 operation on boot and contains extra Enpirion EP53A8LQI DCDC converter which supplies the IO. Reduce Buck3 voltage to 2V9 to not waste power.
- rev.200L have Buck3 preconfigured to 1V8 operation and have no Enpirion EP53A8LQI DCDC anymore, the IO is supplied from Buck3.

Configure the Buck3 voltage on this board per PMIC NVM settings and update buck3 voltage limits in DT passed to OS before booting OS to prevent potential hardware damage.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>
---
  arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi |   2 +-
  board/dhelectronics/dh_stm32mp1/board.c   | 109 +++++++++++++++++++++-
  2 files changed, 107 insertions(+), 4 deletions(-)
arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi +1 -1
index 9937b28548c..e20917824bf 100644
@@ -19,7 +19,7 @@
  };
 
  &vdd {http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/
-	regulator-min-microvolt = <2900000>;
+	regulator-min-microvolt = <1800000>;
  	regulator-max-microvolt = <2900000>;
  };
 
board/dhelectronics/dh_stm32mp1/board.c +8 -0
index 67273f90992..d407f0bf592 100644
@@ -594,14 +594,98 @@ static void board_init_fmc2(void)
  	setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, STM32_FMC2_BCRx_FMCEN);
  }
 
+#ifdef CONFIG_DM_REGULATOR
+#define STPMIC_NVM_BUCKS_VOUT_SHR		http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/	0xfc
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V2		0
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V8		1
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V0		2
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3		3
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK		GENMASK(1, 0)
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(n)	((((n) - 1) & 3) * 2)

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+	const void *fdt = gd->fdt_blob;
+	struct udevice *dev;
+	u8 bucks_vout = 0;
+	const char *prop;
+	int len, ret;
+
+	/* Check whether this is Avenger96 board. */
+	prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96"))

	return -EINVAL;

See also
http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/

Quoted 96 lines
board/dhelectronics/dh_stm32mp1/board.c +81 -3
+	if (!prop || !len)
+		return -ENODEV;
+
+	if (!strstr(prop, "avenger96"))
+		return -EINVAL;
+
+	/* Read out STPMIC1 NVM and determine default Buck3 voltage. */
+	ret = uclass_get_device_by_driver(UCLASS_MISC,
+					  DM_DRIVER_GET(stpmic1_nvm),
+					  &dev);
+	if (ret)
+		return ret;
+
+	ret = misc_read(dev, STPMIC_NVM_BUCKS_VOUT_SHR, &bucks_vout, 1);
+	if (ret != 1)
+		return -EINVAL;
+
+	bucks_vout >>= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(3);
+	bucks_vout &= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK;
+
+	/*
+	 * Avenger96 board comes in multiple regulator configurations:
+	 * - rev.100 or rev.200 have Buck3 preconfigured to 3V3 operation on
+	 *   boot and contains extra Enpirion EP53A8LQI DCDC converter which
+	 *   supplies the IO. Reduce Buck3 voltage to 2V9 to not waste power.
+	 * - rev.200L have Buck3 preconfigured to 1V8 operation and have no
+	 *   Enpirion EP53A8LQI DCDC anymore, http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/the IO is supplied from Buck3.
+	 */
+	if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3)
+		*uv = 2900000;
+	else
+		*uv = 1800000;
+
+	return 0;
+}
+
+static void board_init_regulator_av96(void)
+{
+	struct udevice *rdev;
+	int ret, uv;
+
+	ret = board_get_regulator_buck3_nvm_uv_av96(&uv);
+	if (ret)	/* Not Avenger96 board. */
+		return;
+
+	ret = regulator_get_by_devname("buck3", &rdev);
+	if (ret)
+		return;
+
+	/* Adjust Buck3 per preconfigured PMIC voltage from NVM. */
+	regulator_set_value(rdev, uv);
+}
+
+static void board_init_regulator(void)
+{
+	board_init_regulator_av96();
+
+	regulators_enable_boot_on(_DEBUG);http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/
+}
+#else
+static inline int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+	return -EINVAL;
+}
+
+static inline void board_init_regulator(void) {}
+#endif
+
  /* board dependent setup after realloc */
  int board_init(void)
  {
  	board_key_check();
  http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/
-#ifdef CONFIG_DM_REGULATOR
-	regulators_enable_boot_on(_DEBUG);
-#endif
+	board_init_regulator();
 
  	sysconf_init();
 
@@ -721,6 +805,25 @@ int board_interface_eth_init(struct udevice *dev,
  #if defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+	const char *buck3path = "/soc/i2c@5c002000/stpmic@33/regulators/buck3";
+	int buck3off, ret, uv;
+
+	ret = board_get_regulator_buck3_nvm_uvhttp://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/_av96(&uv);
+	if (ret)	/* Not Avenger96 board, do not patch Buck3 in DT. */
+		return 0;
+
+	buck3off = fdt_path_offset(blob, buck3path);
+	if (buck3off < 0)	/* No Buck3 regulator found. */
+		return 0;
+
+	ret = fdt_setprop_u32(blob, buck3off, "regulator-min-microvolt", uv);

board/dhelectronics/dh_stm32mp1/board.c int board_interface_eth_init(struct udevice *dev, · line 829

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +7 -0
+	if (ret < 0)
+		return ret;
+
+	ret = fdt_setprop_u32(blob, buck3off, "regulator-max-microvolt", uv);
+	if (ret < 0)
+		return ret;
+http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/
  	return 0;
  }
  #endif

Thanks
Patrick

#2 lore raw

On 5/17/22 14:39, Patrick DELAUNAY wrote:

Hi,

[...]

Quoted 14 lines

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96"))
    return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

#3 lore raw

Hi,

Quoted 20 lines · Marek Vasut

On 5/17/22 14:39, Patrick DELAUNAY wrote:

Hi,

[...]

Quoted 14 lines

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 6 lines
Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

Ok, I check on existing DT and I found only on compatible with "avenger96" string.

arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts:15:

    compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";

But you can forget my proposal with of_machine_is_compatible, consider:

   prop = ofnode_read_prop(ofnode_root(), "compatible", &len);

But it is just minor remark.

Do you expect this patch for next pull-request for v2022.07 or for next ?

Patrick

#4 lore raw
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

Quoted 26 lines
Quoted 14 lines
Quoted 14 lines

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 6 lines
Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

Ok, I check on existing DT and I found only on compatible with "avenger96" string.

arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts:15:

Quoted 8 lines

    compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";

But you can forget my proposal with of_machine_is_compatible, consider:

   prop = ofnode_read_prop(ofnode_root(), "compatible", &len);

But it is just minor remark.

There are multiple other fdt_getprop() calls in both board/st/ and board/dh , maybe if you want to do OF_LIVE enablement (do you?), let's convert them all at once ?

Quoted 1 line

Do you expect this patch for next pull-request for v2022.07 or for next ?

Ideally 2022.07.

#5 lore raw
Quoted 33 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

Quoted 28 lines
Quoted 14 lines
Quoted 14 lines

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 6 lines
Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

Ok, I check on existing DT and I found only on compatible with "avenger96" string.

arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts:15:

     compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";

Quoted 8 lines
Quoted 6 lines

But you can forget my proposal with of_machine_is_compatible, consider:

    prop = ofnode_read_prop(ofnode_root(), "compatible", &len);

But it is just minor remark.

There are multiple other fdt_getprop() calls in both board/st/ and board/dh , maybe if you want to do OF_LIVE enablement (do you?), let's convert them all at once ?

Ok. It is more a minor remark linked to checkpatch warning for all the added code:

"Use the livetree API (dev_read_...)"

I let you handle OF_LIVE  for your boards (code & defconfig),

FYI: it is already enable for STMicroelectronics boards (defconfig and in driver, mach-stm32mp and board code).

Quoted 4 lines
Quoted 2 lines

Do you expect this patch for next pull-request for v2022.07 or for next ?

Ideally 2022.07.

Ok, I plan that.

Patrick

#6 lore raw

On 5/17/22 17:32, Patrick DELAUNAY wrote:

Hi,

Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 6 lines
Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

Ok, I check on existing DT and I found only on compatible with "avenger96" string.

arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts:15:

     compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";

Quoted 8 lines
Quoted 6 lines

But you can forget my proposal with of_machine_is_compatible, consider:

    prop = ofnode_read_prop(ofnode_root(), "compatible", &len);

But it is just minor remark.

There are multiple other fdt_getprop() calls in both board/st/ and board/dh , maybe if you want to do OF_LIVE enablement (do you?), let's convert them all at once ?

Quoted 8 lines

Ok. It is more a minor remark linked to checkpatch warning for all the added code:

"Use the livetree API (dev_read_...)"

I let you handle OF_LIVE  for your boards (code & defconfig),

FYI: it is already enable for STMicroelectronics boards (defconfig and in driver, mach-stm32mp and board code).

But look:

c387e626147 ("Merge branch '2022-05-11-Kconfig-cleanups-etc'") with this patch:

u-boot$ git grep fdt_getprop.*comp board/dhelectronics/dh_stm32mp1/*c board/st/stm32mp1/*c

board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
board/dhelectronics/dh_stm32mp1/board.c:        compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL);
board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
board/st/stm32mp1/stm32mp1.c:   fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
board/st/stm32mp1/stm32mp1.c:           fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Am I missing a patch or something ?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Do you expect this patch for next pull-request for v2022.07 or for next ?

Ideally 2022.07.

Ok, I plan that.

Thank you

#7 lore raw

Hi,

Quoted 61 lines · Marek Vasut

On 5/17/22 17:32, Patrick DELAUNAY wrote:

Hi,

Quoted 38 lines
Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

Quoted 6 lines
Quoted 4 lines

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

I explicitly don't want to use of_machine_is_compatible, I need to search for the avenger96 substring in the machine compatible, since the stm32mp15xx can be anything (15{1,3,7}{a,d}) and it might not even have the arrow prefix.

Ok, I check on existing DT and I found only on compatible with "avenger96" string.

arch/arm/dts/stm32mp15xx-dhcor-avenger96.dts:15:

     compatible = "arrow,stm32mp15xx-avenger96", "st,stm32mp15x";

Quoted 8 lines
Quoted 6 lines

But you can forget my proposal with of_machine_is_compatible, consider:

    prop = ofnode_read_prop(ofnode_root(), "compatible", &len);

But it is just minor remark.

There are multiple other fdt_getprop() calls in both board/st/ and board/dh , maybe if you want to do OF_LIVE enablement (do you?), let's convert them all at once ?

Quoted 8 lines

Ok. It is more a minor remark linked to checkpatch warning for all the added code:

"Use the livetree API (dev_read_...)"

I let you handle OF_LIVE  for your boards (code & defconfig),

FYI: it is already enable for STMicroelectronics boards (defconfig and in driver, mach-stm32mp and board code).

But look:

c387e626147 ("Merge branch '2022-05-11-Kconfig-cleanups-etc'") with this patch:

u-boot$ git grep fdt_getprop.*comp board/dhelectronics/dh_stm32mp1/*c board/st/stm32mp1/*c board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/dhelectronics/dh_stm32mp1/board.c:        compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL); board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Quoted 4 lines

board/st/stm32mp1/stm32mp1.c:   fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/st/stm32mp1/stm32mp1.c:           fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Am I missing a patch or something ?

No, it is my fault, I forget these references....

I prepare a serie to solve this issue in STMicroelectronics Boards code.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Do you expect this patch for next pull-request for v2022.07 or for next ?

Ideally 2022.07.

Ok, I plan that.

Thank you

regards

Patrick

#8 lore raw
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

[...]

Quoted 17 lines
Quoted 17 lines
Quoted 3 lines

I let you handle OF_LIVE  for your boards (code & defconfig),

FYI: it is already enable for STMicroelectronics boards (defconfig and in driver, mach-stm32mp and board code).

But look:

c387e626147 ("Merge branch '2022-05-11-Kconfig-cleanups-etc'") with this patch:

u-boot$ git grep fdt_getprop.*comp board/dhelectronics/dh_stm32mp1/*c board/st/stm32mp1/*c board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/dhelectronics/dh_stm32mp1/board.c:        compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL); board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

board/st/stm32mp1/stm32mp1.c:   fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/st/stm32mp1/stm32mp1.c:           fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Quoted 6 lines
Quoted 1 line

Am I missing a patch or something ?

No, it is my fault, I forget these references....

I prepare a serie to solve this issue in STMicroelectronics Boards code.

Hehe, glad I could help you spot it.

You can prepare very much identical series for DH and CC me on it, the changes will be very much the same and I can test the result just fine.

[...]

#9 lore raw

Hi

Quoted 29 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi,

Hi,

[...]

Quoted 22 lines
Quoted 14 lines
Quoted 3 lines

I let you handle OF_LIVE  for your boards (code & defconfig),

FYI: it is already enable for STMicroelectronics boards (defconfig and in driver, mach-stm32mp and board code).

But look:

c387e626147 ("Merge branch '2022-05-11-Kconfig-cleanups-etc'") with this patch:

u-boot$ git grep fdt_getprop.*comp board/dhelectronics/dh_stm32mp1/*c board/st/stm32mp1/*c board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/dhelectronics/dh_stm32mp1/board.c:        compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL); board/dhelectronics/dh_stm32mp1/board.c:        fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Quoted 4 lines

board/st/stm32mp1/stm32mp1.c:   fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", board/st/stm32mp1/stm32mp1.c:           fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",

Am I missing a patch or something ?

No, it is my fault, I forget these references....

Quoted 7 lines
Quoted 1 line

I prepare a serie to solve this issue in STMicroelectronics Boards code.

Hehe, glad I could help you spot it.

You can prepare very much identical series for DH and CC me on it, the changes will be very much the same and I can test the result just fine.

[...]

Applied to u-boot-stm/master, thanks!

And RFC serie to activate OF_LIVE is:

http://patchwork.ozlabs.org/project/uboot/list/?series=301157&state=*

[RFC,1/2] board: dhelectronics: stm32mp1: convert to livetree

[RFC,2/2] ARM: stm32: activate OF_LIVE for DHSOM

Regards
Patrick

#10 lore raw
In reply to Patrick DELAUNAY

Hi,

Quoted 191 lines · Patrick DELAUNAY

Hi,

Quoted 47 lines · Marek Vasut

The Avenger96 board comes in multiple regulator configurations.
  - rev.100 or rev.200 have Buck3 preconfigured to 3V3 operation on boot and contains extra Enpirion EP53A8LQI DCDC converter which supplies the IO. Reduce Buck3 voltage to 2V9 to not waste power.
  - rev.200L have Buck3 preconfigured to 1V8 operation and have no Enpirion EP53A8LQI DCDC anymore, the IO is supplied from Buck3.

Configure the Buck3 voltage on this board per PMIC NVM settings and update buck3 voltage limits in DT passed to OS before booting OS to prevent potential hardware damage.

Cc Patrice Chotard <[email protected]>
Cc Patrick Delaunay <[email protected]>

---
  arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi |   2 +- board/dhelectronics/dh_stm32mp1/board.c   | 109 +++++++++++++++++++++-

  2 files changed, 107 insertions(+), 4 deletions(-)
arch/arm/dts/stm32mp15xx-dhcor-io1v8.dtsi +0 -0
index 9937b28548c..e20917824bf 100644
@@ -19,7 +19,7 @@
   };

    &vdd {http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ -    regulator-min-microvolt = <2900000>;
+    regulator-min-microvolt = <1800000>;
      regulator-max-microvolt = <2900000>;
  };
  diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c
index 67273f90992..d407f0bf592 100644

board/dhelectronics/dh_stm32mp1/board.c +0 -0
@@ -594,14 +594,98 @@ static void board_init_fmc2(void)
       setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, STM32_FMC2_BCRx_FMCEN);
   }

  +#ifdef CONFIG_DM_REGULATOR
+#define STPMIC_NVM_BUCKS_VOUT_SHR
http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/ 0xfc

board/dhelectronics/dh_stm32mp1/board.c +6 -0
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V2        0
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V8        1
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V0        2
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3        3
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK        GENMASK(1, 0)
+#define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(n)    ((((n) - 1) & 3) 

* 2)

board/dhelectronics/dh_stm32mp1/board.c static void board_init_fmc2(void) · line 614

Quoted 10 lines
board/dhelectronics/dh_stm32mp1/board.c +10 -0
+static int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    const void *fdt = gd->fdt_blob;
+    struct udevice *dev;
+    u8 bucks_vout = 0;
+    const char *prop;
+    int len, ret;
+
+    /* Check whether this is Avenger96 board. */
+    prop = fdt_getprop(fdt, 0, "compatible", &len);

This API is not compatible with CONFIG_OF_LIVE

consider replacement with ofnode_read_prop or with of_machine_is_compatible, for example

if (!of_machine_is_compatible(prop, "arrow,stm32mp15xx-avenger96")) return -EINVAL;

See also
http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/

Quoted 111 lines

+    if (!prop || !len)
+        return -ENODEV;

board/dhelectronics/dh_stm32mp1/board.c +21 -0
+
+    if (!strstr(prop, "avenger96"))
+        return -EINVAL;
+
+    /* Read out STPMIC1 NVM and determine default Buck3 voltage. */
+    ret = uclass_get_device_by_driver(UCLASS_MISC,
+                      DM_DRIVER_GET(stpmic1_nvm),
+                      &dev);
+    if (ret)
+        return ret;
+
+    ret = misc_read(dev, STPMIC_NVM_BUCKS_VOUT_SHR, &bucks_vout, 1);
+    if (ret != 1)
+        return -EINVAL;
+
+    bucks_vout >>= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(3);
+    bucks_vout &= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK;
+
+    /*
+     * Avenger96 board comes in multiple regulator configurations:
+     * - rev.100 or rev.200 have Buck3 preconfigured to 3V3 

operation on
+     *   boot and contains extra Enpirion EP53A8LQI DCDC converter
which
+     *   supplies the IO. Reduce Buck3 voltage to 2V9 to not waste
power.
+     * - rev.200L have Buck3 preconfigured to 1V8 operation and have no
+     *   Enpirion EP53A8LQI DCDC anymore,
http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/the IO is supplied from Buck3. +     */
+    if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3)
+        *uv = 2900000;
+    else
+        *uv = 1800000;

board/dhelectronics/dh_stm32mp1/board.c +26 -0
+
+    return 0;
+}
+
+static void board_init_regulator_av96(void)
+{
+    struct udevice *rdev;
+    int ret, uv;
+
+    ret = board_get_regulator_buck3_nvm_uv_av96(&uv);
+    if (ret)    /* Not Avenger96 board. */
+        return;
+
+    ret = regulator_get_by_devname("buck3", &rdev);
+    if (ret)
+        return;
+
+    /* Adjust Buck3 per preconfigured PMIC voltage from NVM. */
+    regulator_set_value(rdev, uv);
+}
+
+static void board_init_regulator(void)
+{
+    board_init_regulator_av96();
+
+ 

regulators_enable_boot_on(_DEBUG);http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/

board/dhelectronics/dh_stm32mp1/board.c +10 -0
+}
+#else
+static inline int board_get_regulator_buck3_nvm_uv_av96(int *uv)
+{
+    return -EINVAL;
+}
+
+static inline void board_init_regulator(void) {}
+#endif
+

  /* board dependent setup after realloc */
  int board_init(void)
  {
      board_key_check();
http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/

board/dhelectronics/dh_stm32mp1/board.c +1 -3
-#ifdef CONFIG_DM_REGULATOR
-    regulators_enable_boot_on(_DEBUG);
-#endif
+    board_init_regulator();

        sysconf_init();
  @@ -721,6 +805,25 @@ int board_interface_eth_init(struct udevice *dev,
  #if defined(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, struct bd_info *bd)
  {
+    const char *buck3path =
"/soc/i2c@5c002000/stpmic@33/regulators/buck3";
+    int buck3off, ret, uv;
+
+    ret = board_get_regulator_buck3_nvm_uvhttp://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/_av96(&uv); +    if (ret)    /* Not Avenger96 board, do not patch Buck3 in DT. */
+        return 0;

board/dhelectronics/dh_stm32mp1/board.c +6 -0
+
+    buck3off = fdt_path_offset(blob, buck3path);
+    if (buck3off < 0)    /* No Buck3 regulator found. */
+        return 0;
+
+    ret = fdt_setprop_u32(blob, buck3off, "regulator-min-microvolt", 

uv);
+    if (ret < 0)
+        return ret;
+
+    ret = fdt_setprop_u32(blob, buck3off, "regulator-max-microvolt",
uv);
+    if (ret < 0)
+        return ret; +http://patchwork.ozlabs.org/project/uboot/patch/20220517143655.1.I4d61d5a725e965f1476b26412ed1e8329aa9ba98@changeid/

Quoted 3 lines

      return 0;
  }
  #endif

Quoted 3 lines

Thanks
Patrick

Applied to u-boot-stm/master, thanks!

Regards
Patrick