Re: [PATCH v5 4/4] regulator: qcom-rpmh: Add debounce delay before disabling regulator
From: Mark Brown
Date: Fri Nov 13 2026 - 17:37:03 EST
> Some consumers rapidly toggle a regulator off and back on, e.g. a
> driver that disables its supply on -EPROBE_DEFER and re-enables it on
> the next probe attempt. Sending the disable to RPMh immediately causes
> needless power cycling of the rail.
Looking at the code here this doesn't really seem at all driver specific
- we could implement this in the core around any disable and enable
operation. Is there anything that really ties this to the driver code,
or could it be factored out and available to everything?
There's also a bunch of stuff from Sashiko a lot of which looks valid
but I didn't check it carefully.
> + * @lock: Serializes disable() against the teardown
> + * action, since both make a read-then-act decision
> + * on @debounce_delay that must be atomic to avoid
> + * queuing @delayed_off_work after teardown has
> + * swept it. enable() needs no lock: its only
> + * shared-state access is cancel_delayed_work_sync(),
> + * which already serializes against
> + * @delayed_off_work. @enabled and @rdev are also
> + * written by @delayed_off_work without this lock
> + * held, so they use READ_ONCE()/WRITE_ONCE() there.
The work doesn't seem to write rdev, but does write last_off?
> +static void rpmh_delayed_off_work(struct work_struct *work)
> +{
> + struct rpmh_vreg *vreg = container_of(work,
> + struct rpmh_vreg, delayed_off_work.work);
> +
> + /*
> + * No locking needed. cancel_delayed_work_sync() already guarantees
> + * this work has either not started or has fully finished by the
> + * time enable()/teardown proceed to touch shared state.
> + */
> + if (!_rpmh_regulator_set_enable_state(vreg, READ_ONCE(vreg->rdev), false))
> + vreg->last_off = ktime_get_boottime();
> +}
There's no reporting if the actual disable fails which seems bad.
> static int rpmh_regulator_enable(struct regulator_dev *rdev)
> {
> - return rpmh_regulator_set_enable_state(rdev, true);
> + struct rpmh_vreg *vreg = rdev_get_drvdata(rdev);
> + s64 remaining;
> +
> + /* See struct rpmh_vreg's @lock for why no lock is needed here. */
> + if (cancel_delayed_work_sync(&vreg->delayed_off_work)) {
> + /* Queued disable never reached RPMh, so undo disable()'s flip. */
> + WRITE_ONCE(vreg->enabled, true);
> + return 0;
> + }
Nor do we restore this flag.
--
Mark Brown <broonie@xxxxxxxxxx>