Skip to contentSkip to conversation

pmic: pca9450: Initialization of pmic like done in linux

PATCH In review Heiko Thiery 4 participants 8 messages Jun 28, 2022 – Jun 29, 2022

lore
Share & tools
lore
#0 lore raw

cover pmic: pca9450: Initialization of pmic like done in linux

To be able to initialize the PMIC voltages by using the PCA9450 regulator driver we need to properly disable the BUCK1/2/3 preset behavior.

Also the RESET_CTRL/WDOG_B_CFG behavior can be done by the PC9450 PMIC driver.

With that enabled the PMIC custom configurations done in SPL code for boards that has the PCA9450 implemented can be cleaned.

Heiko Thiery (2):
pmic: pca9450: enable system reset on WDOG_B assertion
pmic: pca9450: clear PRESET_EN bit for BUCK1/2/3 voltage settings

 drivers/power/pmic/Kconfig   |  4 ++++
 drivers/power/pmic/pca9450.c | 21 +++++++++++++++++++++
 include/power/pca9450.h      | 10 ++++++++++
 3 files changed, 35 insertions(+)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 pmic: pca9450: enable system reset on WDOG_B assertion

By default the PCA9450 doesn't handle the assertion of the WDOG_B signal, but this is required to guarantee that things like software resets triggered by the watchdog work reliably.

This is a port of the same changes in the Linux kernel:
f7684f5a048f ("regulator: pca9450: Enable system reset on WDOG_B assertion") 2364a64d0673 ("regulator: pca9450: Make warm reset on WDOG_B assertion")

Cc Frieder Schrempf <[email protected]>
---
 drivers/power/pmic/Kconfig   |  4 ++++
 drivers/power/pmic/pca9450.c | 15 +++++++++++++++
 include/power/pca9450.h      |  7 +++++++
 3 files changed, 26 insertions(+)
drivers/power/pmic/Kconfig +4 -0
index bb3960020d..d30d6d25c4 100644
@@ -158,6 +158,8 @@ config SPL_DM_PMIC_MP5416
 
 config DM_PMIC_PCA9450
 	bool "Enable Driver Model for PMIC PCA9450"
+	select REGMAP
+	select SYSCON
 	help
 	  This config enables implementation of driver-model pmic uclass features
 	  for PMIC PCA9450. The driver implements read/write operations.
@@ -165,6 +167,8 @@ config DM_PMIC_PCA9450
 config SPL_DM_PMIC_PCA9450
 	bool "Enable Driver Model for PMIC PCA9450"
 	depends on SPL_DM_PMIC
+	select SPL_REGMAP
+	select SPL_SYSCON
 	help
 	  This config enables implementation of driver-model pmic uclass features
 	  for PMIC PCA9450 in SPL. The driver implements read/write operations.
drivers/power/pmic/pca9450.c +15 -0
index a186edc08d..fecab0496f 100644
@@ -11,6 +11,8 @@
 #include <i2c.h>
 #include <linux/err.h>
 #include <log.h>
+#include <regmap.h>
+#include <syscon.h>
 #include <asm/global_data.h>
 #include <asm-generic/gpio.h>
 #include <power/pmic.h>
@@ -30,6 +32,7 @@ static const struct pmic_child_info pmic_children_info[] = {
 };
 
 struct pca9450_priv {
+	struct regmap *regmap;
 	struct gpio_desc *sd_vsel_gpio;
 };
 
@@ -86,8 +89,20 @@ static int pca9450_bind(struct udevice *dev)
 static int pca9450_probe(struct udevice *dev)
 {
 	struct pca9450_priv *priv = dev_get_priv(dev);
+	unsigned int reset_ctrl;
 	int ret = 0;
 
+	priv->regmap = syscon_node_to_regmap(dev_ofnode(dev));
+
+	if (dev_read_bool(dev, "nxp,wdog_b-warm-reset"))
+		reset_ctrl = WDOG_B_CFG_WARM;
+	else
+		reset_ctrl = WDOG_B_CFG_COLD_LDO12;
+
+	/* Set reset behavior on assertion of WDOG_B signal */
+	ret = regmap_update_bits(priv->regmap, PCA9450_RESET_CTRL,
+				 WDOG_B_CFG_MASK, reset_ctrl);
+
 	if (CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(DM_REGULATOR_PCA9450)) {
 		priv->sd_vsel_gpio = devm_gpiod_get_optional(dev, "sd-vsel",
 							     GPIOD_IS_OUT |
include/power/pca9450.h +7 -0
index fa0405fcb8..bf9be7d6bb 100644
@@ -67,4 +67,11 @@ enum {
 #define PCA9450_LDO34_MASK		0x1f
 #define PCA9450_LDO5_MASK		0x0f
 
+/* PCA9450_REG_RESET_CTRL bits */
+#define WDOG_B_CFG_MASK			0xC0
+#define WDOG_B_CFG_NONE			0x00
+#define WDOG_B_CFG_WARM			0x40
+#define WDOG_B_CFG_COLD_LDO12		0x80
+#define WDOG_B_CFG_COLD			0xC0
+
 #endif
Signature · 1 line
2.30.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] pmic: pca9450: enable system reset on WDOG_B assertion

Quoted 10 lines · Heiko Thiery

By default the PCA9450 doesn't handle the assertion of the WDOG_B signal, but this is required to guarantee that things like software resets triggered by the watchdog work reliably.

This is a port of the same changes in the Linux kernel:
f7684f5a048f ("regulator: pca9450: Enable system reset on WDOG_B assertion") 2364a64d0673 ("regulator: pca9450: Make warm reset on WDOG_B assertion")

Cc Frieder Schrempf <[email protected]>
Reviewed-by on v1 1/2
#3 lore raw

Re: [PATCH 1/2] pmic: pca9450: enable system reset on WDOG_B assertion

In reply to Heiko Thiery

Am 28.06.22 um 16:06 schrieb Heiko Thiery:

Quoted 10 lines

By default the PCA9450 doesn't handle the assertion of the WDOG_B signal, but this is required to guarantee that things like software resets triggered by the watchdog work reliably.

This is a port of the same changes in the Linux kernel:
f7684f5a048f ("regulator: pca9450: Enable system reset on WDOG_B assertion") 2364a64d0673 ("regulator: pca9450: Make warm reset on WDOG_B assertion")

Cc Frieder Schrempf <[email protected]>
#4 lore raw

PATCH 2/2 pmic: pca9450: clear PRESET_EN bit for BUCK1/2/3 voltage settings

In reply to Heiko Thiery

The regulator driver uses the DVS registers PCA9450_REG_BUCKxOUT_DVS0 to set the voltage for the buck regulators 1, 2 and 3. This has no effect as the PRESET_EN bit is set by default and therefore the preset values are used instead, which are set to 850 mV.

This is a port of the same change in the Linux kernel:
98b94b6e38ca0 ("regulator: pca9450: Clear PRESET_EN bit to fix BUCK1/2/3 voltage setting")

Cc Frieder Schrempf <[email protected]>
---
 drivers/power/pmic/pca9450.c | 6 ++++++
 include/power/pca9450.h      | 3 +++
 2 files changed, 9 insertions(+)
drivers/power/pmic/pca9450.c +6 -0
index fecab0496f..1c59362ab4 100644
@@ -94,6 +94,12 @@ static int pca9450_probe(struct udevice *dev)
 
 	priv->regmap = syscon_node_to_regmap(dev_ofnode(dev));
 
+	/* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
+	if (CONFIG_IS_ENABLED(DM_REGULATOR_PCA9450)) {
+		ret = regmap_update_bits(priv->regmap, PCA9450_BUCK123_DVS,
+					 BUCK123_PRESET_EN, 0);
+	}
+
 	if (dev_read_bool(dev, "nxp,wdog_b-warm-reset"))
 		reset_ctrl = WDOG_B_CFG_WARM;
 	else
include/power/pca9450.h +3 -0
index bf9be7d6bb..60e37c671a 100644
@@ -67,6 +67,9 @@ enum {
 #define PCA9450_LDO34_MASK		0x1f
 #define PCA9450_LDO5_MASK		0x0f
 
+/* PCA9450_REG_BUCK123_PRESET_EN bit */
+#define BUCK123_PRESET_EN		0x80
+
 /* PCA9450_REG_RESET_CTRL bits */
 #define WDOG_B_CFG_MASK			0xC0
 #define WDOG_B_CFG_NONE			0x00
Signature · 1 line
2.30.2
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] pmic: pca9450: clear PRESET_EN bit for BUCK1/2/3 voltage settings

Quoted 21 lines · Heiko Thiery

The regulator driver uses the DVS registers PCA9450_REG_BUCKxOUT_DVS0 to set the voltage for the buck regulators 1, 2 and 3. This has no effect as the PRESET_EN bit is set by default and therefore the preset values are used instead, which are set to 850 mV.

This is a port of the same change in the Linux kernel:
98b94b6e38ca0 ("regulator: pca9450: Clear PRESET_EN bit to fix BUCK1/2/3 voltage setting")

Cc Frieder Schrempf <[email protected]>
---
 drivers/power/pmic/pca9450.c | 6 ++++++
 include/power/pca9450.h      | 3 +++
 2 files changed, 9 insertions(+)
drivers/power/pmic/pca9450.c +0 -0
index fecab0496f..1c59362ab4 100644

drivers/power/pmic/pca9450.c static int pca9450_probe(struct udevice *dev) · line 101

Quoted 8 lines
drivers/power/pmic/pca9450.c +5 -0
@@ -94,6 +94,12 @@ static int pca9450_probe(struct udevice *dev)
 
 	priv->regmap = syscon_node_to_regmap(dev_ofnode(dev));
 
+	/* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
+	if (CONFIG_IS_ENABLED(DM_REGULATOR_PCA9450)) {
+		ret = regmap_update_bits(priv->regmap, PCA9450_BUCK123_DVS,
+					 BUCK123_PRESET_EN, 0);
+	}

Nit: the braces could be dropped.

#6 lore raw

Re: [PATCH 2/2] pmic: pca9450: clear PRESET_EN bit for BUCK1/2/3 voltage settings

Quoted 25 lines · Fabio Estevam
Quoted 24 lines · Heiko Thiery

The regulator driver uses the DVS registers PCA9450_REG_BUCKxOUT_DVS0 to set the voltage for the buck regulators 1, 2 and 3. This has no effect as the PRESET_EN bit is set by default and therefore the preset values are used instead, which are set to 850 mV.

This is a port of the same change in the Linux kernel:
98b94b6e38ca0 ("regulator: pca9450: Clear PRESET_EN bit to fix BUCK1/2/3 voltage setting")

Cc Frieder Schrempf <[email protected]>

---
 drivers/power/pmic/pca9450.c | 6 ++++++
 include/power/pca9450.h      | 3 +++

 2 files changed, 9 insertions(+)
drivers/power/pmic/pca9450.c +0 -0
index fecab0496f..1c59362ab4 100644
@@ -94,6 +94,12 @@ static int pca9450_probe(struct udevice *dev)
 
      priv->regmap = syscon_node_to_regmap(dev_ofnode(dev));
 
Quoted 7 lines

drivers/power/pmic/pca9450.c static int pca9450_probe(struct udevice *dev) · line 101

Quoted 5 lines
drivers/power/pmic/pca9450.c +5 -0
+    /* Clear PRESET_EN bit in BUCK123_DVS to use DVS registers */
+    if (CONFIG_IS_ENABLED(DM_REGULATOR_PCA9450)) {
+        ret = regmap_update_bits(priv->regmap, PCA9450_BUCK123_DVS,
+                     BUCK123_PRESET_EN, 0);
+    }

Nit: the braces could be dropped.

IIRC they were recommended on multi-line code in conditional. I think checkpatch --strict might even warn about them missing.

Reviewed-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] pmic: pca9450: clear PRESET_EN bit for BUCK1/2/3 voltage settings

In reply to Heiko Thiery

Am 28.06.22 um 16:06 schrieb Heiko Thiery:

Quoted 10 lines

The regulator driver uses the DVS registers PCA9450_REG_BUCKxOUT_DVS0 to set the voltage for the buck regulators 1, 2 and 3. This has no effect as the PRESET_EN bit is set by default and therefore the preset values are used instead, which are set to 850 mV.

This is a port of the same change in the Linux kernel:
98b94b6e38ca0 ("regulator: pca9450: Clear PRESET_EN bit to fix BUCK1/2/3 voltage setting")

Cc Frieder Schrempf <[email protected]>