Skip to content

Commit 1cb7d29

Browse files
bijudasbroonie
authored andcommitted
regulator: core: Add helper for allow HW access to enable/disable regulator
Add a helper function that allow regulator consumers to allow low-level HW access, in order to enable/disable regulator in atomic context. The use-case for RZ/G2L SoC is to enable VBUS selection register based on vbus detection that happens in interrupt context. Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Link: https://patch.msgid.link/20240616105402.45211-4-biju.das.jz@bp.renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f266106 commit 1cb7d29

3 files changed

Lines changed: 41 additions & 0 deletions

File tree

Documentation/power/regulator/consumer.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,9 @@ directly written to the voltage selector register, use::
227227

228228
int regulator_list_hardware_vsel(struct regulator *regulator,
229229
unsigned selector);
230+
231+
To access the hardware for enabling/disabling the regulator, consumers must
232+
use regulator_get_exclusive(), as it can't work if there's more than one
233+
consumer. To enable/disable regulator use::
234+
235+
int regulator_hardware_enable(struct regulator *regulator, bool enable);

drivers/regulator/core.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,6 +3408,34 @@ int regulator_list_hardware_vsel(struct regulator *regulator,
34083408
}
34093409
EXPORT_SYMBOL_GPL(regulator_list_hardware_vsel);
34103410

3411+
/**
3412+
* regulator_hardware_enable - access the HW for enable/disable regulator
3413+
* @regulator: regulator source
3414+
* @enable: true for enable, false for disable
3415+
*
3416+
* Request that the regulator be enabled/disabled with the regulator output at
3417+
* the predefined voltage or current value.
3418+
*
3419+
* On success 0 is returned, otherwise a negative errno is returned.
3420+
*/
3421+
int regulator_hardware_enable(struct regulator *regulator, bool enable)
3422+
{
3423+
struct regulator_dev *rdev = regulator->rdev;
3424+
const struct regulator_ops *ops = rdev->desc->ops;
3425+
int ret = -EOPNOTSUPP;
3426+
3427+
if (!rdev->exclusive || !ops || !ops->enable || !ops->disable)
3428+
return ret;
3429+
3430+
if (enable)
3431+
ret = ops->enable(rdev);
3432+
else
3433+
ret = ops->disable(rdev);
3434+
3435+
return ret;
3436+
}
3437+
EXPORT_SYMBOL_GPL(regulator_hardware_enable);
3438+
34113439
/**
34123440
* regulator_get_linear_step - return the voltage step size between VSEL values
34133441
* @regulator: regulator source

include/linux/regulator/consumer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ int regulator_get_hardware_vsel_register(struct regulator *regulator,
250250
unsigned *vsel_mask);
251251
int regulator_list_hardware_vsel(struct regulator *regulator,
252252
unsigned selector);
253+
int regulator_hardware_enable(struct regulator *regulator, bool enable);
253254

254255
/* regulator notifier block */
255256
int regulator_register_notifier(struct regulator *regulator,
@@ -571,6 +572,12 @@ static inline int regulator_list_hardware_vsel(struct regulator *regulator,
571572
return -EOPNOTSUPP;
572573
}
573574

575+
static inline int regulator_hardware_enable(struct regulator *regulator,
576+
bool enable)
577+
{
578+
return -EOPNOTSUPP;
579+
}
580+
574581
static inline int regulator_register_notifier(struct regulator *regulator,
575582
struct notifier_block *nb)
576583
{

0 commit comments

Comments
 (0)