Re: [PATCH 0/5] Add TI LM51772 buck-boost voltage regulator
From: Paul Louvel
Date: Fri Oct 23 2026 - 06:31:58 EST
On Thu Oct 22, 2026 at 3:42 PM CEST, Mark Brown wrote:
> On Wed, Oct 21, 2026 at 12:27:41PM +0200, Paul Louvel wrote:
>
>> static int ptn5110_tcpc_set_vbus(struct tcpci *tcpci, struct tcpci_data *data, bool source,
>> bool sink)
>> {
>> struct ptn5110_priv *priv = container_of(data, struct ptn5110_priv, data);
>> int ret;
>>
>> ret = regulator_is_enabled(priv->vbus_high);
>> if (ret < 0)
>> return ret;
>>
>> if (ret && !source)
>> return regulator_disable(priv->vbus_high);
>
> This is buggy, if the driver is not using regulator_get_exclusive() it
> has no idea why the underlying physical regulator is enabled or if it
> has the ability to affect that state. Even if the regulator is held
> exclusively we still do reference counting for the driver so it needs to
> be certain that it never enables twice. Outside of bootstrapping your
> driver's internal state you should neve use regulator_is_enabled().
Ok. The PTN5110 should take ownership of the regulator with
devm_regulator_get_exclusive() then, because there is no reason the regulator
for power delivery should be shared with any other consumer.
Then making sure the regulator is disabled at probe should not lead to
unbalanced disabled because the core would have incremented the enable count to
1 [1].
regulator_is_enabled() can then be removed because we own the regulator and its
state should not change.
The pattern shown above is used in the MT6370 TCPCI driver [2].
[1]: https://elixir.bootlin.com/linux/v7.3/source/drivers/regulator/core.c#L2521
[2]: https://elixir.bootlin.com/linux/v7.3/source/drivers/usb/typec/tcpm/tcpci_mt6370.c#L77
Thanks.
Best regards,
--
Paul Louvel, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com