Skip to content

Commit da07ecd

Browse files
committed
regulator: Implement deferred disable support
It is a reasonably common pattern for hardware to require some delay after being quiesced before the disable has finalised, especially in mixed signal devices. For example, an active discharge may be required to ensure that the circuit starts up again in a known state. Avoid having to implement such delays in the regulator API by providing regulator_deferred_disable() which will do a regulator_disable() a specified number of milliseconds after it is called. Due to the reference counting done on regulators a deferred disable can be cancelled by doing another regulator_enable(). Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@ti.com>
1 parent 30ab1e7 commit da07ecd

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,63 @@ int regulator_force_disable(struct regulator *regulator)
15521552
}
15531553
EXPORT_SYMBOL_GPL(regulator_force_disable);
15541554

1555+
static void regulator_disable_work(struct work_struct *work)
1556+
{
1557+
struct regulator_dev *rdev = container_of(work, struct regulator_dev,
1558+
disable_work.work);
1559+
int count, i, ret;
1560+
1561+
mutex_lock(&rdev->mutex);
1562+
1563+
BUG_ON(!rdev->deferred_disables);
1564+
1565+
count = rdev->deferred_disables;
1566+
rdev->deferred_disables = 0;
1567+
1568+
for (i = 0; i < count; i++) {
1569+
ret = _regulator_disable(rdev);
1570+
if (ret != 0)
1571+
rdev_err(rdev, "Deferred disable failed: %d\n", ret);
1572+
}
1573+
1574+
mutex_unlock(&rdev->mutex);
1575+
1576+
if (rdev->supply) {
1577+
for (i = 0; i < count; i++) {
1578+
ret = regulator_disable(rdev->supply);
1579+
if (ret != 0) {
1580+
rdev_err(rdev,
1581+
"Supply disable failed: %d\n", ret);
1582+
}
1583+
}
1584+
}
1585+
}
1586+
1587+
/**
1588+
* regulator_disable_deferred - disable regulator output with delay
1589+
* @regulator: regulator source
1590+
* @ms: miliseconds until the regulator is disabled
1591+
*
1592+
* Execute regulator_disable() on the regulator after a delay. This
1593+
* is intended for use with devices that require some time to quiesce.
1594+
*
1595+
* NOTE: this will only disable the regulator output if no other consumer
1596+
* devices have it enabled, the regulator device supports disabling and
1597+
* machine constraints permit this operation.
1598+
*/
1599+
int regulator_disable_deferred(struct regulator *regulator, int ms)
1600+
{
1601+
struct regulator_dev *rdev = regulator->rdev;
1602+
1603+
mutex_lock(&rdev->mutex);
1604+
rdev->deferred_disables++;
1605+
mutex_unlock(&rdev->mutex);
1606+
1607+
return schedule_delayed_work(&rdev->disable_work,
1608+
msecs_to_jiffies(ms));
1609+
}
1610+
EXPORT_SYMBOL_GPL(regulator_disable_deferred);
1611+
15551612
static int _regulator_is_enabled(struct regulator_dev *rdev)
15561613
{
15571614
/* If we don't know then assume that the regulator is always on */
@@ -2622,6 +2679,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
26222679
INIT_LIST_HEAD(&rdev->consumer_list);
26232680
INIT_LIST_HEAD(&rdev->list);
26242681
BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
2682+
INIT_DELAYED_WORK(&rdev->disable_work, regulator_disable_work);
26252683

26262684
/* preform any regulator specific init */
26272685
if (init_data->regulator_init) {
@@ -2729,6 +2787,7 @@ void regulator_unregister(struct regulator_dev *rdev)
27292787
#ifdef CONFIG_DEBUG_FS
27302788
debugfs_remove_recursive(rdev->debugfs);
27312789
#endif
2790+
flush_work_sync(&rdev->disable_work.work);
27322791
WARN_ON(rdev->open_count);
27332792
unset_regulator_supplies(rdev);
27342793
list_del(&rdev->list);

‎include/linux/regulator/consumer.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ int regulator_enable(struct regulator *regulator);
141141
int regulator_disable(struct regulator *regulator);
142142
int regulator_force_disable(struct regulator *regulator);
143143
int regulator_is_enabled(struct regulator *regulator);
144+
int regulator_disable_deferred(struct regulator *regulator, int ms);
144145

145146
int regulator_bulk_get(struct device *dev, int num_consumers,
146147
struct regulator_bulk_data *consumers);
@@ -211,6 +212,12 @@ static inline int regulator_disable(struct regulator *regulator)
211212
return 0;
212213
}
213214

215+
static inline int regulator_disable_deferred(struct regulator *regulator,
216+
int ms)
217+
{
218+
return 0;
219+
}
220+
214221
static inline int regulator_is_enabled(struct regulator *regulator)
215222
{
216223
return 1;

‎include/linux/regulator/driver.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ struct regulator_dev {
199199
struct regulation_constraints *constraints;
200200
struct regulator *supply; /* for tree */
201201

202+
struct delayed_work disable_work;
203+
int deferred_disables;
204+
202205
void *reg_data; /* regulator_dev data */
203206

204207
#ifdef CONFIG_DEBUG_FS

0 commit comments

Comments
 (0)