From: Peng Fan <peng.fan@oss.nxp.com>
To: Jonas Karlman <jonas@kwiboo.se>
Cc: Peng Fan <peng.fan@nxp.com>,
Jaehoon Chung <jh80.chung@samsung.com>,
Tom Rini <trini@konsulko.com>,
Kaustabh Chakraborty <kauschluss@disroot.org>,
Simon Glass <sjg@chromium.org>,
u-boot@lists.denx.de
Subject: Re: [PATCH 1/4] power: regulator: Add helper to set voltage within an acceptable range
Date: Mon, 29 Jun 2026 13:21:11 +0800 [thread overview]
Message-ID: <akIAx9umMKvjMTgs@shlinux89> (raw)
In-Reply-To: <20260628102527.1247889-2-jonas@kwiboo.se>
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
next prev parent reply other threads:[~2026-06-29 5:17 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=akIAx9umMKvjMTgs@shlinux89 \
--to=peng.fan@oss.nxp.com \
--cc=jh80.chung@samsung.com \
--cc=jonas@kwiboo.se \
--cc=kauschluss@disroot.org \
--cc=peng.fan@nxp.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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.