From: "Paul Louvel" <paul.louvel@bootlin.com>
To: "Mark Brown" <broonie@kernel.org>,
"Paul Louvel" <paul.louvel@bootlin.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Herve Codina" <herve.codina@bootlin.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>
Subject: Re: [PATCH 5/5] regulator: Add TI LM51772 support
Date: Fri, 23 Oct 2026 09:24:13 +0200 [thread overview]
Message-ID: <DMC1DQX9EJ3P.4VWHJ27R9JLG@bootlin.com> (raw)
In-Reply-To: <atpJCnOMOlLSNvqL@sirena.org.uk>
Hi Mark,
On Thu Oct 22, 2026 at 7:34 PM CEST, Mark Brown wrote:
> On Wed, Oct 21, 2026 at 12:27:46PM +0200, Paul Louvel wrote:
>
>> +static int lm51772_regulator_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
>> +{
>> + const struct lm51772_priv *priv = rdev_get_drvdata(rdev);
>> + int ret;
>
>> + /*
>> + * The LM51772 uses hardcoded OVP thresholds. Update the OVP threshold
>> + * to match the new voltage.
>> + */
>> + if (priv->ovp_thres) {
>> + ret = regulator_list_voltage_pickable_linear_range(rdev, selector);
>> + if (ret < 0)
>> + return ret;
>> +
>> + ret = lm51772_set_ov(rdev, ret + priv->ovp_thres);
>> + if (ret)
>> + return ret;
>> + }
>> +
>> + return regulator_set_voltage_sel_pickable_regmap(rdev, selector);
>
> If the voltage is being lowered this will lower the threashold prior to
> lowering the voltage which could cause the protection to flag. I guess
> we need to look to see if the voltage is being raised or lowered and do
> the change before or after as appropriate.
>
If new_uV > old_uV, and we set ovp after or before, that doesn't matter, because
the voltage only ramp up without getting a chance to be > ovp.
If new_uV < old_uV, if we set ovp before, the protection will flag, and if we
set ovp after, the protection might still flag because of the slew rate delay
(or put another way, there is no guarantee that the voltage will be low enough
so that the ovp don't trip).
My idea is to implement the .set_voltage_time() callback, to inform the core how
much time it will take for the regulator to reach the new voltage, to that we
fsleep() for the correct amount of time [1].
Then, the core could call .set_over_voltage_protection() if the driver enabled a
new 'fixed_ovp' flag:
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -4014,6 +4014,16 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
(void *)data);
}
+ if (old_uV != best_val) {
+ if (rdev->desc->fixed_ovp && ops->set_over_voltage_protection) {
+ ret = handle_notify_limits(
+ rdev, ops->set_over_voltage_protection,
+ &rdev->constraints->over_voltage_limits);
+ if (ret == -EOPNOTSUPP)
+ ret = 0;
+ }
+ }
+
[1]: https://elixir.bootlin.com/linux/v7.3/source/drivers/regulator/core.c#L4005
>> +static int lm51772_regulator_set_current_limit(struct regulator_dev *rdev, int min_uA, int max_uA)
>> +{
>> + struct lm51772_priv *priv = rdev_get_drvdata(rdev);
>> + u64 voltage_uV = ((u64)priv->sense_res_milliohms * max_uA) / 1000;
>
> Does this build on arm32 or similar things that need a libgcc division
> implmentation? div_u64().
>
>> + if (status_reg & LM51772_STAT_INPUT)
>> + errors |= REGULATOR_ERROR_UNDER_VOLTAGE;
>
> That sounds like an error with the input so I'm not sure under voltage
> is the right error to report.
Since there is no error for input under voltage, I guess I can use
REGULATOR_ERROR_FAIL then ?
>
>> +static int lm51772_irq_map_event(int irq, struct regulator_irq_data *rid,
>> + unsigned long *dev_mask)
>> +{
>> + struct regmap *regmap = rid->data;
>> + unsigned int reg, errors;
>> + int ret;
>> +
>> + ret = regmap_read(regmap, LM51772_REG_STATUS_BYTE, ®);
>> + if (ret)
>> + return REGULATOR_FAILED_RETRY;
>> +
>> + errors = lm51772_status2err(reg);
>
> Does this do the right thing if multiple errors are flagged?
>
No.. should iterate with for_each_set_bit() on errors and then do
regulator_err2notif() on each bit.
>> +static int lm51772_irq_renable(struct regulator_irq_data *rid)
>> +{
>> + struct regmap *regmap = rid->data;
>> + unsigned int reg;
>> + int ret;
>> +
>> + ret = regmap_read(regmap, LM51772_REG_STATUS_BYTE, ®);
>> + if (ret)
>> + return REGULATOR_FAILED_RETRY;
>> +
>> + if (rid->opaque && rid->opaque == reg) {
>> + ret = regmap_read(regmap, LM51772_REG_CLEAR_FAULTS, ®);
>> + if (ret)
>> + return REGULATOR_FAILED_RETRY;
>
> Shoud _CLEAR_FAULTS be volatile?
>
Yes.
>> +static const struct reg_default lm51772_reg_defaults[] = {
>> + { LM51772_REG_CLEAR_FAULTS, 0x00 }, { LM51772_REG_ILIM_THRESHOLD, 0x64 },
>> + { LM51772_REG_VOUT_TARGET1_LSB, 0x58 }, { LM51772_REG_VOUT_TARGET1_MSB, 0x02 },
>> + { LM51772_REG_STATUS_BYTE, 0x00 }, { LM51772_REG_USB_PD_CONTROL_0, 0x01 },
>
> STATUS_BYTE is volatile so a default isn't terribly sensible (but
> harmless).
Thanks.
Best regards,
--
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2026-10-23 7:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-21 10:27 [PATCH 0/5] Add TI LM51772 buck-boost voltage regulator Paul Louvel
2026-10-21 10:27 ` [PATCH 1/5] regulator: dt-bindings: Add regulator-boot-force-off property Paul Louvel
2026-10-21 17:01 ` Conor Dooley
2026-10-21 17:11 ` Paul Louvel
2026-10-22 7:08 ` Krzysztof Kozlowski
2026-10-22 12:22 ` Mark Brown
2026-10-22 12:39 ` Paul Louvel
2026-10-21 10:27 ` [PATCH 2/5] regulator: dt-bindings: Add TI LM51772 support Paul Louvel
2026-10-21 10:27 ` [PATCH 3/5] regulator: core: Add mechanism to force disable a regulator at boot Paul Louvel
2026-10-22 13:48 ` Mark Brown
2026-10-21 10:27 ` [PATCH 4/5] regulator: Support regulators where the voltage selector spans two registers Paul Louvel
2026-10-22 17:21 ` Mark Brown
2026-10-23 10:02 ` Paul Louvel
2026-10-21 10:27 ` [PATCH 5/5] regulator: Add TI LM51772 support Paul Louvel
2026-10-21 15:10 ` Uwe Kleine-König
2026-10-22 17:34 ` Mark Brown
2026-10-23 7:24 ` Paul Louvel [this message]
2026-10-24 19:28 ` kernel test robot
2026-10-22 13:42 ` [PATCH 0/5] Add TI LM51772 buck-boost voltage regulator Mark Brown
2026-10-23 10:31 ` Paul Louvel
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=DMC1DQX9EJ3P.4VWHJ27R9JLG@bootlin.com \
--to=paul.louvel@bootlin.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=herve.codina@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=robh@kernel.org \
--cc=thomas.petazzoni@bootlin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®