All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frieder Schrempf <frieder@fris.de>
To: u-boot@lists.denx.de, Jaehoon Chung <jh80.chung@samsung.com>,
	Tom Rini <trini@konsulko.com>
Cc: Frieder Schrempf <frieder.schrempf@kontron.de>,
	Joy Zou <joy.zou@nxp.com>, Peng Fan <peng.fan@nxp.com>,
	Ye Li <ye.li@nxp.com>
Subject: [PATCH 3/6] pmic: pca9450: Fix control register for LDO5
Date: Mon, 11 Aug 2025 15:11:59 +0200	[thread overview]
Message-ID: <20250811131213.211124-4-frieder@fris.de> (raw)
In-Reply-To: <20250811131213.211124-1-frieder@fris.de>

From: Frieder Schrempf <frieder.schrempf@kontron.de>

For LDO5 we need to be able to check the status of the SD_VSEL input in
order to know which control register is used. Read the status of the
SD_VSEL signal via GPIO and use the correct register accordingly.

To use this, the LDO5 node in the devicetree needs the sd-vsel-gpios
property to reference the GPIO that is used to read back the SD_VSEL
status internally. Please note that the SION bit in the IOMUX must be
set if the signal is muxed as VSELECT and controlled by the USDHC
controller.

This is equivalent to the following change in Linux:

3ce6f4f943dd ("regulator: pca9450: Fix control register for LDO5")

Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---
 drivers/power/regulator/pca9450.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/drivers/power/regulator/pca9450.c b/drivers/power/regulator/pca9450.c
index 27db55e688d..9d8d142b464 100644
--- a/drivers/power/regulator/pca9450.c
+++ b/drivers/power/regulator/pca9450.c
@@ -7,9 +7,12 @@
  * ROHM BD71837 regulator driver
  */
 
+#include <asm-generic/gpio.h>
 #include <dm.h>
+#include <dm/device_compat.h>
 #include <log.h>
 #include <linux/bitops.h>
+#include <linux/err.h>
 #include <power/pca9450.h>
 #include <power/pmic.h>
 #include <power/regulator.h>
@@ -52,6 +55,7 @@ struct pca9450_plat {
 	u8			volt_mask;
 	struct pca9450_vrange	*ranges;
 	unsigned int		numranges;
+	struct gpio_desc	*sd_vsel_gpio;
 };
 
 #define PCA_RANGE(_min, _vstep, _sel_low, _sel_hi) \
@@ -222,13 +226,23 @@ static int pca9450_set_enable(struct udevice *dev, bool enable)
 			       val);
 }
 
+static u8 pca9450_get_vsel_reg(struct pca9450_plat *plat)
+{
+	if (!strcmp(plat->name, "LDO5") &&
+	    (plat->sd_vsel_gpio && !dm_gpio_get_value(plat->sd_vsel_gpio)) {
+		return PCA9450_LDO5CTRL_L;
+	}
+
+	return plat->volt_reg;
+}
+
 static int pca9450_get_value(struct udevice *dev)
 {
 	struct pca9450_plat *plat = dev_get_plat(dev);
 	unsigned int reg, tmp;
 	int i, ret;
 
-	ret = pmic_reg_read(dev->parent, plat->volt_reg);
+	ret = pmic_reg_read(dev->parent, pca9450_get_vsel_reg(plat));
 	if (ret < 0)
 		return ret;
 
@@ -274,7 +288,7 @@ static int pca9450_set_value(struct udevice *dev, int uvolt)
 	if (!found)
 		return -EINVAL;
 
-	return pmic_clrsetbits(dev->parent, plat->volt_reg,
+	return pmic_clrsetbits(dev->parent, pca9450_get_vsel_reg(plat),
 			       plat->volt_mask, sel);
 }
 
@@ -335,6 +349,19 @@ static int pca9450_regulator_probe(struct udevice *dev)
 
 		*plat = pca9450_reg_data[i];
 
+		if (!strcmp(plat->name, "LDO5")) {
+			if (CONFIG_IS_ENABLED(DM_GPIO) && CONFIG_IS_ENABLED(DM_REGULATOR_PCA9450)) {
+				plat->sd_vsel_gpio = devm_gpiod_get_optional(dev, "sd-vsel",
+									     GPIOD_IS_IN);
+				if (IS_ERR(plat->sd_vsel_gpio)) {
+					ret = PTR_ERR(plat->sd_vsel_gpio);
+					dev_err(dev, "Failed to request SD_VSEL GPIO: %d\n", ret);
+					if (ret)
+						return ret;
+				}
+			}
+		}
+
 		return 0;
 	}
 
-- 
2.50.1


  parent reply	other threads:[~2025-08-11 13:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-11 13:11 [PATCH 0/6] Use correct LDO5 control registers for PCA9450 Frieder Schrempf
2025-08-11 13:11 ` [PATCH 1/6] Revert "pmic: pca9450: Add optional SD_VSEL GPIO for LDO5" Frieder Schrempf
2025-08-11 13:11 ` [PATCH 2/6] pmic: pca9450: Fix enable register for LDO5 Frieder Schrempf
2025-08-11 13:11 ` Frieder Schrempf [this message]
2025-08-11 13:12 ` [PATCH 4/6] pmic: pca9450: Handle hardware with fixed SD_VSEL " Frieder Schrempf
2025-08-11 13:12 ` [PATCH 5/6] arm: dts: imx8mp-data-modul-edm-sbc: Remove deprecated sd-vsel-gpios Frieder Schrempf
2025-08-11 14:22   ` Marek Vasut
2025-08-11 13:12 ` [PATCH 6/6] arm: dts: imx8mp-dhcom-som: " Frieder Schrempf
2025-08-11 14:21   ` Marek Vasut
2025-08-25  8:40 ` [PATCH 0/6] Use correct LDO5 control registers for PCA9450 Frieder Schrempf
2025-08-27  5:46   ` Peng Fan
2025-08-27  7:37     ` Frieder Schrempf
2025-08-27 14:32       ` Tom Rini
2025-09-01  7:44 ` Peng Fan (OSS)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250811131213.211124-4-frieder@fris.de \
    --to=frieder@fris.de \
    --cc=frieder.schrempf@kontron.de \
    --cc=jh80.chung@samsung.com \
    --cc=joy.zou@nxp.com \
    --cc=peng.fan@nxp.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=ye.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.