U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply
@ 2026-06-28 10:25 Jonas Karlman
  2026-06-28 10:25 ` [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range Jonas Karlman
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Jonas Karlman @ 2026-06-28 10:25 UTC (permalink / raw)
  To: Peng Fan, Jaehoon Chung, Tom Rini
  Cc: Kaustabh Chakraborty, Simon Glass, u-boot, Jonas Karlman

The Rockchip RK3399 SoC SDMMC IO domain supports 1.8V and 3.0V mode, so
vqmmc-supply for SD-cards is typically limited to max 3.0V to avoid
damage to the SoC.

The SD Standards allow for an operating voltage range of 1.70V-1.95V and
2.7V-3.6V, meaning the 3.0V mode follows spec.

The commit 0b75109b6aaf ("mmc: dw_mmc: return error for invalid voltage
setting") help enforce strict 1.8V and 3.3V when setting vqmmc-supply
making mmc_set_signal_voltage() possible fail for MMC_SIGNAL_VOLTAGE_330
and can lead to an improper switch to MMC_SIGNAL_VOLTAGE_180.

This series adds a regulator_set_value_clamp() helper set voltage value
within a requested voltage range instead of an exact value, and changes
dw_mmc to use this helper to set a voltage within in-spec range to fix
use of SD-cards with 3.3V signal voltage on Rockchip RK3399 boards using
MMC_IO_VOLTAGE=y.

Jonas Karlman (4):
  power: regulator: Add helper to set voltage within an acceptable range
  test: dm: regulator: Add regulator_set_value_clamp() tests
  mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply
  mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE

 arch/sandbox/dts/sandbox_pmic.dtsi         |  6 ++++
 doc/usage/cmd/dm.rst                       |  3 +-
 drivers/mmc/dw_mmc.c                       |  6 ++--
 drivers/mmc/sdhci.c                        |  2 +-
 drivers/power/regulator/regulator-uclass.c | 27 +++++++++++++++
 drivers/power/regulator/sandbox.c          | 11 ++++---
 include/power/regulator.h                  | 12 +++++++
 include/power/sandbox_pmic.h               | 15 +++++++--
 test/dm/regulator.c                        | 38 ++++++++++++++++++++++
 9 files changed, 109 insertions(+), 11 deletions(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range
  2026-06-28 10:25 [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
@ 2026-06-28 10:25 ` Jonas Karlman
  2026-06-29  5:21   ` Peng Fan
  2026-06-28 10:25 ` [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests Jonas Karlman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: Jonas Karlman @ 2026-06-28 10:25 UTC (permalink / raw)
  To: Peng Fan, Jaehoon Chung, Tom Rini
  Cc: Kaustabh Chakraborty, Simon Glass, u-boot, Jonas Karlman

Add regulator_set_value_clamp() that clamps a requested target voltage
to both caller-provided limits and the regulator constraints before
setting the regulator voltage value.

Return -EINVAL when the caller limits cannot be satisfied by the
regulator constraints or when the requested range is invalid.

This helper will initially be used to set vqmmc-supply voltage within an
acceptable range according to SD Standards, i.e. 1.70V-1.95V and
2.7V-3.6V.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 drivers/power/regulator/regulator-uclass.c | 27 ++++++++++++++++++++++
 include/power/regulator.h                  | 12 ++++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 1c7f75a9338c..0f5ba51ad6c2 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -111,6 +111,33 @@ int regulator_get_suspend_value(struct udevice *dev)
 	return ops->get_suspend_value(dev);
 }
 
+int regulator_set_value_clamp(struct udevice *dev,
+			      int min_uV, int target_uV, int max_uV)
+{
+	const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
+	struct dm_regulator_uclass_plat *uc_pdata;
+	int uV;
+
+	if (!ops || !ops->set_value)
+		return -ENOSYS;
+
+	uc_pdata = dev_get_uclass_plat(dev);
+	if (uc_pdata->min_uV != -ENODATA && max_uV < uc_pdata->min_uV)
+		return -EINVAL;
+	if (uc_pdata->max_uV != -ENODATA && min_uV > uc_pdata->max_uV)
+		return -EINVAL;
+	if (min_uV > max_uV)
+		return -EINVAL;
+
+	if (uc_pdata->min_uV != -ENODATA)
+		min_uV = max(min_uV, uc_pdata->min_uV);
+	if (uc_pdata->max_uV != -ENODATA)
+		max_uV = min(max_uV, uc_pdata->max_uV);
+	uV = clamp(target_uV, min_uV, max_uV);
+
+	return regulator_set_value(dev, uV);
+}
+
 /*
  * To be called with at most caution as there is no check
  * before setting the actual voltage value.
diff --git a/include/power/regulator.h b/include/power/regulator.h
index 4011fb1d254b..a48bb3a5a1db 100644
--- a/include/power/regulator.h
+++ b/include/power/regulator.h
@@ -315,6 +315,18 @@ int regulator_set_suspend_value(struct udevice *dev, int uV);
  */
 int regulator_get_suspend_value(struct udevice *dev);
 
+/**
+ * regulator_set_value_clamp: set clamped microvoltage value of a given regulator
+ *
+ * @dev       - pointer to the regulator device
+ * @min_uV    - the minimum output value to set [micro Volts]
+ * @target_uV - the target output value to set [micro Volts]
+ * @max_uV    - the maximum output value to set [micro Volts]
+ * Return:    - 0 on success or -errno val if fails
+ */
+int regulator_set_value_clamp(struct udevice *dev,
+			      int min_uV, int target_uV, int max_uV);
+
 /**
  * regulator_set_value_force: set the microvoltage value of a given regulator
  *			      without any min-,max condition check
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests
  2026-06-28 10:25 [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
  2026-06-28 10:25 ` [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range Jonas Karlman
@ 2026-06-28 10:25 ` Jonas Karlman
  2026-06-29  5:31   ` Peng Fan
  2026-06-28 10:25 ` [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
  2026-06-28 10:25 ` [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE Jonas Karlman
  3 siblings, 1 reply; 9+ messages in thread
From: Jonas Karlman @ 2026-06-28 10:25 UTC (permalink / raw)
  To: Peng Fan, Jaehoon Chung, Tom Rini, Simon Glass
  Cc: Kaustabh Chakraborty, u-boot, Jonas Karlman

Add a sandbox LDO3 with a configurable 1.8V to 3.3V range and use it
to test regulator_set_value_clamp().

Test in-range requests, clamping against the regulator limits, invalid
ranges outside the regulator limits and a min value higher than max.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 arch/sandbox/dts/sandbox_pmic.dtsi |  6 +++++
 doc/usage/cmd/dm.rst               |  3 ++-
 drivers/power/regulator/sandbox.c  | 11 +++++----
 include/power/sandbox_pmic.h       | 15 ++++++++++--
 test/dm/regulator.c                | 38 ++++++++++++++++++++++++++++++
 5 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/arch/sandbox/dts/sandbox_pmic.dtsi b/arch/sandbox/dts/sandbox_pmic.dtsi
index ff2cb42844cc..d90ab0408278 100644
--- a/arch/sandbox/dts/sandbox_pmic.dtsi
+++ b/arch/sandbox/dts/sandbox_pmic.dtsi
@@ -47,6 +47,12 @@
 		regulator-min-microvolt = <1500000>;
 		regulator-max-microvolt = <1500000>;
 	};
+
+	ldo3 {
+		regulator-name = "SUPPLY_1.8_3.3V";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <3300000>;
+	};
 };
 
 &mc34708 {
diff --git a/doc/usage/cmd/dm.rst b/doc/usage/cmd/dm.rst
index 196b22d13764..ac1c437bd9c2 100644
--- a/doc/usage/cmd/dm.rst
+++ b/doc/usage/cmd/dm.rst
@@ -409,7 +409,8 @@ This example shows the abridged sandbox output::
     regulator     1  [   ]   sandbox_buck          |   |   |-- buck2
     regulator     2  [   ]   sandbox_ldo           |   |   |-- ldo1
     regulator     3  [   ]   sandbox_ldo           |   |   |-- ldo2
-    regulator     4  [   ]   sandbox_buck          |   |   `-- no_match_by_nodename
+    regulator     4  [   ]   sandbox_buck          |   |   |-- no_match_by_nodename
+    regulator     5  [   ]   sandbox_ldo           |   |   `-- ldo3
     pmic          1  [   ]   mc34708_pmic          |   `-- pmic@41
     bootcount     0  [ + ]   bootcount-rtc         |-- bootcount@0
     bootcount     1  [   ]   bootcount-i2c-eeprom  |-- bootcount
diff --git a/drivers/power/regulator/sandbox.c b/drivers/power/regulator/sandbox.c
index 80a68f5a30d5..813ee301e73b 100644
--- a/drivers/power/regulator/sandbox.c
+++ b/drivers/power/regulator/sandbox.c
@@ -56,10 +56,11 @@ static struct dm_regulator_mode sandbox_buck_modes[] = {
 	MODE(BUCK_OM_PWM, OM2REG(BUCK_OM_PWM), "PWM"),
 };
 
-/* LDO: 1,2 - voltage range */
+/* LDO: 1,2,3 - voltage range */
 static struct output_range ldo_voltage_range[] = {
 	RANGE(OUT_LDO1_UV_MIN, OUT_LDO1_UV_MAX, OUT_LDO1_UV_STEP),
 	RANGE(OUT_LDO2_UV_MIN, OUT_LDO2_UV_MAX, OUT_LDO2_UV_STEP),
+	RANGE(OUT_LDO3_UV_MIN, OUT_LDO3_UV_MAX, OUT_LDO3_UV_STEP),
 };
 
 /* LDO: 1 - current range */
@@ -288,8 +289,8 @@ static int ldo_set_voltage(struct udevice *dev, int uV)
 
 static int ldo_get_current(struct udevice *dev)
 {
-	/* LDO2 - unsupported */
-	if (dev->driver_data == 2)
+	/* LDO: 2,3 - unsupported */
+	if (dev->driver_data >= 2)
 		return -ENOSYS;
 
 	return out_get_value(dev, SANDBOX_LDO_COUNT, OUT_REG_UA,
@@ -298,8 +299,8 @@ static int ldo_get_current(struct udevice *dev)
 
 static int ldo_set_current(struct udevice *dev, int uA)
 {
-	/* LDO2 - unsupported */
-	if (dev->driver_data == 2)
+	/* LDO: 2,3 - unsupported */
+	if (dev->driver_data >= 2)
 		return -ENOSYS;
 
 	return out_set_value(dev, SANDBOX_LDO_COUNT, OUT_REG_UA,
diff --git a/include/power/sandbox_pmic.h b/include/power/sandbox_pmic.h
index 1dbd15b52354..50ef39b45e9b 100644
--- a/include/power/sandbox_pmic.h
+++ b/include/power/sandbox_pmic.h
@@ -13,10 +13,10 @@
 #define SANDBOX_OF_BUCK_PREFIX		"buck"
 
 #define SANDBOX_BUCK_COUNT	3
-#define SANDBOX_LDO_COUNT	2
+#define SANDBOX_LDO_COUNT	3
 /*
  * Sandbox PMIC registers:
- * We have only 12 significant registers, but we alloc 16 for padding.
+ * We have only 15 significant registers, but we alloc 16 for padding.
  */
 enum {
 	SANDBOX_PMIC_REG_BUCK1_UV = 0,
@@ -36,6 +36,10 @@ enum {
 	SANDBOX_PMIC_REG_LDO2_UA,
 	SANDBOX_PMIC_REG_LDO2_OM,
 
+	SANDBOX_PMIC_REG_LDO3_UV,
+	SANDBOX_PMIC_REG_LDO3_UA,
+	SANDBOX_PMIC_REG_LDO3_OM,
+
 	SANDBOX_PMIC_REG_COUNT = 16,
 };
 
@@ -94,6 +98,11 @@ enum {
 #define OUT_LDO2_UV_MAX		3950000
 #define OUT_LDO2_UV_STEP	50000
 
+/* LDO3 Voltage: min: 0.75V, step: 50mV, max 3.95V */
+#define OUT_LDO3_UV_MIN		750000
+#define OUT_LDO3_UV_MAX		3950000
+#define OUT_LDO3_UV_STEP	50000
+
 /* register <-> value conversion */
 #define REG2VAL(min, step, reg)		((min) + ((step) * (reg)))
 #define VAL2REG(min, step, val)		(((val) - (min)) / (step))
@@ -116,6 +125,8 @@ enum {
 #define SANDBOX_LDO1_PLATNAME	"VDD_EMMC_1.8V"
 #define SANDBOX_LDO2_DEVNAME	"ldo2"
 #define SANDBOX_LDO2_PLATNAME	"VDD_LCD_3.3V"
+#define SANDBOX_LDO3_DEVNAME	"ldo3"
+#define SANDBOX_LDO3_PLATNAME	"SUPPLY_1.8_3.3V"
 
 /*
  * Expected regulators setup after call of:
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 449748ad52f2..51007d4079db 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -28,6 +28,7 @@ enum {
 	BUCK3,
 	LDO1,
 	LDO2,
+	LDO3,
 	OUTPUT_COUNT,
 };
 
@@ -44,6 +45,7 @@ static const char *regulator_names[OUTPUT_COUNT][OUTPUT_NAME_COUNT] = {
 	{ SANDBOX_BUCK3_DEVNAME, SANDBOX_BUCK3_PLATNAME },
 	{ SANDBOX_LDO1_DEVNAME, SANDBOX_LDO1_PLATNAME},
 	{ SANDBOX_LDO2_DEVNAME, SANDBOX_LDO2_PLATNAME},
+	{ SANDBOX_LDO3_DEVNAME, SANDBOX_LDO3_PLATNAME},
 };
 
 /* Test regulator get method */
@@ -118,6 +120,42 @@ static int dm_test_power_regulator_set_get_voltage(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_power_regulator_set_get_voltage, UTF_SCAN_FDT);
 
+/* Test regulator set Voltage clamp method */
+static int dm_test_power_regulator_set_value_clamp(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	const char *platname;
+
+	/* LDO3 have 'min' 1.8V and 'max' 3.3V */
+	platname = regulator_names[LDO3][PLATNAME];
+	ut_assertok(regulator_get_by_platname(platname, &dev));
+
+	/* 'target' in 'min'/'max' range - should not clamp voltage */
+	ut_assertok(regulator_set_value_clamp(dev, 1700000, 1800000, 1950000));
+	ut_asserteq(1800000, regulator_get_value(dev));
+	ut_assertok(regulator_set_value_clamp(dev, 2700000, 3300000, 3600000));
+	ut_asserteq(3300000, regulator_get_value(dev));
+
+	/* 'target' out of 'min'/'max' range - should clamp voltage */
+	ut_assertok(regulator_set_value_clamp(dev, 1700000, 1700000, 1950000));
+	ut_asserteq(1800000, regulator_get_value(dev));
+	ut_assertok(regulator_set_value_clamp(dev, 2700000, 3400000, 3600000));
+	ut_asserteq(3300000, regulator_get_value(dev));
+
+	/* 'min'/'max' out of range - should return -EINVAL */
+	ut_asserteq(-EINVAL,
+		    regulator_set_value_clamp(dev, 1200000, 1500000, 1700000));
+	ut_asserteq(-EINVAL,
+		    regulator_set_value_clamp(dev, 3500000, 4000000, 5000000));
+
+	/* 'min' higher than 'max' - should return -EINVAL */
+	ut_asserteq(-EINVAL,
+		    regulator_set_value_clamp(dev, 3100000, 3000000, 2900000));
+
+	return 0;
+}
+DM_TEST(dm_test_power_regulator_set_value_clamp, UTF_SCAN_FDT);
+
 /* Test regulator set and get Current method */
 static int dm_test_power_regulator_set_get_current(struct unit_test_state *uts)
 {
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply
  2026-06-28 10:25 [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
  2026-06-28 10:25 ` [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range Jonas Karlman
  2026-06-28 10:25 ` [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests Jonas Karlman
@ 2026-06-28 10:25 ` Jonas Karlman
  2026-06-29  5:27   ` Peng Fan
  2026-06-28 10:25 ` [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE Jonas Karlman
  3 siblings, 1 reply; 9+ messages in thread
From: Jonas Karlman @ 2026-06-28 10:25 UTC (permalink / raw)
  To: Peng Fan, Jaehoon Chung, Tom Rini, Kaustabh Chakraborty
  Cc: Simon Glass, u-boot, Jonas Karlman

The Rockchip RK3399 SoC SDMMC IO domain supports 1.8V and 3.0V mode, and
the 3.0V mode is within SD Standards allowed 2.7V-3.6V range. However,
the commit 0b75109b6aaf ("mmc: dw_mmc: return error for invalid voltage
setting") help enforce strict 1.8V and 3.3V when setting vqmmc-supply
making mmc_set_signal_voltage() now fail for MMC_SIGNAL_VOLTAGE_330 and
leading to an improper switch to MMC_SIGNAL_VOLTAGE_180.

Use regulator_set_value_clamp() to set an SD Standards voltage range,
1.70V-1.95V and 2.7V-3.6V, I/O voltage instead of requiring an exact
regulator value to closer match Linux and to fix use of 3.3V signal
voltage on Rockchip RK3399 boards using MMC_IO_VOLTAGE=y.

Fixes: 0b75109b6aaf ("mmc: dw_mmc: return error for invalid voltage setting")
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 drivers/mmc/dw_mmc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/dw_mmc.c b/drivers/mmc/dw_mmc.c
index d9c05b223d5f..c2424d7875ca 100644
--- a/drivers/mmc/dw_mmc.c
+++ b/drivers/mmc/dw_mmc.c
@@ -645,9 +645,11 @@ static int dwmci_set_ios(struct mmc *mmc)
 		int ret;
 
 		if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
-			ret = regulator_set_value(mmc->vqmmc_supply, 1800000);
+			ret = regulator_set_value_clamp(mmc->vqmmc_supply,
+							1700000, 1800000, 1950000);
 		else
-			ret = regulator_set_value(mmc->vqmmc_supply, 3300000);
+			ret = regulator_set_value_clamp(mmc->vqmmc_supply,
+							2700000, 3300000, 3600000);
 		if (ret && ret != -ENOSYS)
 			return ret;
 	}
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE
  2026-06-28 10:25 [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
                   ` (2 preceding siblings ...)
  2026-06-28 10:25 ` [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
@ 2026-06-28 10:25 ` Jonas Karlman
  2026-06-29  5:31   ` Peng Fan
  3 siblings, 1 reply; 9+ messages in thread
From: Jonas Karlman @ 2026-06-28 10:25 UTC (permalink / raw)
  To: Peng Fan, Jaehoon Chung, Tom Rini
  Cc: Kaustabh Chakraborty, Simon Glass, u-boot, Jonas Karlman

Use CONFIG_IS_ENABLED() instead of IS_ENABLED() when checking the
MMC_IO_VOLTAGE symbol so the Kconfig option is evaluated correctly for
xPL builds.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
 drivers/mmc/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 08594e102669..71a6d8ea2f56 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -551,7 +551,7 @@ void sdhci_set_uhs_timing(struct sdhci_host *host)
 
 void sdhci_set_voltage(struct sdhci_host *host)
 {
-	if (IS_ENABLED(CONFIG_MMC_IO_VOLTAGE)) {
+	if (CONFIG_IS_ENABLED(MMC_IO_VOLTAGE)) {
 		struct mmc *mmc = (struct mmc *)host->mmc;
 		u32 ctrl;
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range
  2026-06-28 10:25 ` [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range Jonas Karlman
@ 2026-06-29  5:21   ` Peng Fan
  0 siblings, 0 replies; 9+ messages in thread
From: Peng Fan @ 2026-06-29  5:21 UTC (permalink / raw)
  To: Jonas Karlman
  Cc: Peng Fan, Jaehoon Chung, Tom Rini, Kaustabh Chakraborty,
	Simon Glass, u-boot

On Sun, Jun 28, 2026 at 10:25:23AM +0000, Jonas Karlman wrote:
>Add regulator_set_value_clamp() that clamps a requested target voltage
>to both caller-provided limits and the regulator constraints before
>setting the regulator voltage value.
>
>Return -EINVAL when the caller limits cannot be satisfied by the
>regulator constraints or when the requested range is invalid.
>
>This helper will initially be used to set vqmmc-supply voltage within an
>acceptable range according to SD Standards, i.e. 1.70V-1.95V and
>2.7V-3.6V.
>
>Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
>---
> drivers/power/regulator/regulator-uclass.c | 27 ++++++++++++++++++++++
> include/power/regulator.h                  | 12 ++++++++++
> 2 files changed, 39 insertions(+)
>
>diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
>index 1c7f75a9338c..0f5ba51ad6c2 100644
>--- a/drivers/power/regulator/regulator-uclass.c
>+++ b/drivers/power/regulator/regulator-uclass.c
>@@ -111,6 +111,33 @@ int regulator_get_suspend_value(struct udevice *dev)
> 	return ops->get_suspend_value(dev);
> }
> 
>+int regulator_set_value_clamp(struct udevice *dev,
>+			      int min_uV, int target_uV, int max_uV)
>+{
>+	const struct dm_regulator_ops *ops = dev_get_driver_ops(dev);
>+	struct dm_regulator_uclass_plat *uc_pdata;
>+	int uV;
>+
>+	if (!ops || !ops->set_value)
>+		return -ENOSYS;
>+
>+	uc_pdata = dev_get_uclass_plat(dev);
>+	if (uc_pdata->min_uV != -ENODATA && max_uV < uc_pdata->min_uV)
>+		return -EINVAL;
>+	if (uc_pdata->max_uV != -ENODATA && min_uV > uc_pdata->max_uV)
>+		return -EINVAL;
>+	if (min_uV > max_uV)
>+		return -EINVAL;
>+
>+	if (uc_pdata->min_uV != -ENODATA)
>+		min_uV = max(min_uV, uc_pdata->min_uV);
>+	if (uc_pdata->max_uV != -ENODATA)
>+		max_uV = min(max_uV, uc_pdata->max_uV);
>+	uV = clamp(target_uV, min_uV, max_uV);
>+
>+	return regulator_set_value(dev, uV);
>+}
>+
> /*
>  * To be called with at most caution as there is no check
>  * before setting the actual voltage value.
>diff --git a/include/power/regulator.h b/include/power/regulator.h
>index 4011fb1d254b..a48bb3a5a1db 100644
>--- a/include/power/regulator.h
>+++ b/include/power/regulator.h
>@@ -315,6 +315,18 @@ int regulator_set_suspend_value(struct udevice *dev, int uV);
>  */
> int regulator_get_suspend_value(struct udevice *dev);
> 
>+/**
>+ * regulator_set_value_clamp: set clamped microvoltage value of a given regulator
>+ *
>+ * @dev       - pointer to the regulator device
>+ * @min_uV    - the minimum output value to set [micro Volts]
>+ * @target_uV - the target output value to set [micro Volts]
>+ * @max_uV    - the maximum output value to set [micro Volts]
>+ * Return:    - 0 on success or -errno val if fails
>+ */
>+int regulator_set_value_clamp(struct udevice *dev,
>+			      int min_uV, int target_uV, int max_uV);

A static inline stub in regulator.h #else block is required.

Thanks,
Peng

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply
  2026-06-28 10:25 ` [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
@ 2026-06-29  5:27   ` Peng Fan
  0 siblings, 0 replies; 9+ messages in thread
From: Peng Fan @ 2026-06-29  5:27 UTC (permalink / raw)
  To: Jonas Karlman
  Cc: Peng Fan, Jaehoon Chung, Tom Rini, Kaustabh Chakraborty,
	Simon Glass, u-boot

On Sun, Jun 28, 2026 at 10:25:25AM +0000, Jonas Karlman wrote:
>The Rockchip RK3399 SoC SDMMC IO domain supports 1.8V and 3.0V mode, and
>the 3.0V mode is within SD Standards allowed 2.7V-3.6V range. However,
>the commit 0b75109b6aaf ("mmc: dw_mmc: return error for invalid voltage
>setting") help enforce strict 1.8V and 3.3V when setting vqmmc-supply
>making mmc_set_signal_voltage() now fail for MMC_SIGNAL_VOLTAGE_330 and
>leading to an improper switch to MMC_SIGNAL_VOLTAGE_180.
>
>Use regulator_set_value_clamp() to set an SD Standards voltage range,
>1.70V-1.95V and 2.7V-3.6V, I/O voltage instead of requiring an exact
>regulator value to closer match Linux and to fix use of 3.3V signal
>voltage on Rockchip RK3399 boards using MMC_IO_VOLTAGE=y.
>
>Fixes: 0b75109b6aaf ("mmc: dw_mmc: return error for invalid voltage setting")
>Signed-off-by: Jonas Karlman <jonas@kwiboo.se>

Reviewed-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests
  2026-06-28 10:25 ` [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests Jonas Karlman
@ 2026-06-29  5:31   ` Peng Fan
  0 siblings, 0 replies; 9+ messages in thread
From: Peng Fan @ 2026-06-29  5:31 UTC (permalink / raw)
  To: Jonas Karlman
  Cc: Peng Fan, Jaehoon Chung, Tom Rini, Simon Glass,
	Kaustabh Chakraborty, u-boot

On Sun, Jun 28, 2026 at 10:25:24AM +0000, Jonas Karlman wrote:
>Add a sandbox LDO3 with a configurable 1.8V to 3.3V range and use it
>to test regulator_set_value_clamp().
>
>Test in-range requests, clamping against the regulator limits, invalid
>ranges outside the regulator limits and a min value higher than max.
>
>Signed-off-by: Jonas Karlman <jonas@kwiboo.se>

Reviewed-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE
  2026-06-28 10:25 ` [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE Jonas Karlman
@ 2026-06-29  5:31   ` Peng Fan
  0 siblings, 0 replies; 9+ messages in thread
From: Peng Fan @ 2026-06-29  5:31 UTC (permalink / raw)
  To: Jonas Karlman
  Cc: Peng Fan, Jaehoon Chung, Tom Rini, Kaustabh Chakraborty,
	Simon Glass, u-boot

On Sun, Jun 28, 2026 at 10:25:26AM +0000, Jonas Karlman wrote:
>Use CONFIG_IS_ENABLED() instead of IS_ENABLED() when checking the
>MMC_IO_VOLTAGE symbol so the Kconfig option is evaluated correctly for
>xPL builds.
>
>Signed-off-by: Jonas Karlman <jonas@kwiboo.se>

Reviewed-by: Peng Fan <peng.fan@nxp.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-06-29  5:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-28 10:25 [PATCH 0/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
2026-06-28 10:25 ` [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range Jonas Karlman
2026-06-29  5:21   ` Peng Fan
2026-06-28 10:25 ` [PATCH 2/4] test: dm: regulator: Add regulator_set_value_clamp() tests Jonas Karlman
2026-06-29  5:31   ` Peng Fan
2026-06-28 10:25 ` [PATCH 3/4] mmc: dw_mmc: Allow use of in-spec voltage range for vqmmc-supply Jonas Karlman
2026-06-29  5:27   ` Peng Fan
2026-06-28 10:25 ` [PATCH 4/4] mmc: sdhci: Use CONFIG_IS_ENABLED for MMC_IO_VOLTAGE Jonas Karlman
2026-06-29  5:31   ` Peng Fan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox