lkml.org 
[lkml]   [2021]   [Jun]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC PATCH v2] regulator: devres: add devm_regulator_enable() as short-hand
Date
Evidently, this came about after doing a few of these types of constructs:

static void reg_disable(void *reg)
{
regulator_disable(reg)
}
...
ret = regulator_enable(reg);
if (ret)
return ret;

ret = devm_add_action_or_reset(dev, reg_disable, reg);
...

A previous proposal was done via [1], to automatically decrease the enable
refcount in devm_regulator_release() if it's 1.
A point was made that this [indeed] can cause issues with
reviewing/tracking enable refcount.

I'm not sure [at this point in time] whether a devm_regulator_enable()
function is still something that would be a good idea, given that this can
cause issues with consumers potentially mixing regulator_enable() and
devm_regulator_enable() calls. This concern was mentioned in [2].

But, there are now a number of simple drivers that are implementing the above
construct already, so it may be an idea to propose this short-hand in the
regulator framework.

References:
[1] https://lore.kernel.org/lkml/20210625125307.330831-1-aardelean@deviqon.com/
[2] https://lore.kernel.org/lkml/20170213023249.GA27688@dtor-ws/
[3] https://lkml.org/lkml/2014/2/4/940

Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
---
.../driver-api/driver-model/devres.rst | 1 +
drivers/regulator/devres.c | 20 +++++++++++++++++++
include/linux/regulator/consumer.h | 8 ++++++++
3 files changed, 29 insertions(+)

diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst
index e0814d214048..8a92e0888cb8 100644
--- a/Documentation/driver-api/driver-model/devres.rst
+++ b/Documentation/driver-api/driver-model/devres.rst
@@ -408,6 +408,7 @@ REGULATOR
devm_regulator_get()
devm_regulator_put()
devm_regulator_register()
+ devm_regulator_enable()

RESET
devm_reset_control_get()
diff --git a/drivers/regulator/devres.c b/drivers/regulator/devres.c
index a8de0aa88bad..dfb23ac178a0 100644
--- a/drivers/regulator/devres.c
+++ b/drivers/regulator/devres.c
@@ -533,3 +533,23 @@ void *devm_regulator_irq_helper(struct device *dev,
return ptr;
}
EXPORT_SYMBOL_GPL(devm_regulator_irq_helper);
+
+static void devm_regulator_disable(void *regulator)
+{
+ regulator_disable(regulator);
+}
+
+/**
+ * devm_regulator_enable - device-managed regulator_enable
+ * @dev: device for regulator "consumer"
+ * @regulator: regulator source
+ *
+ * This will register an action handler for disabling the regulator
+ * by reistering a regulator_disable() call via devm_add_action_or_reset().
+ * It's meant to be a short-hand for all the drivers using this construct.
+ */
+int devm_regulator_enable(struct device *dev, struct regulator *regulator)
+{
+ return devm_add_action_or_reset(dev, devm_regulator_disable, regulator);
+}
+EXPORT_SYMBOL_GPL(devm_regulator_enable);
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h
index f72ca73631be..01f17205c567 100644
--- a/include/linux/regulator/consumer.h
+++ b/include/linux/regulator/consumer.h
@@ -236,6 +236,8 @@ void devm_regulator_bulk_unregister_supply_alias(struct device *dev,

/* regulator output control and status */
int __must_check regulator_enable(struct regulator *regulator);
+int __must_check devm_regulator_enable(struct device *dev,
+ struct regulator *regulator);
int regulator_disable(struct regulator *regulator);
int regulator_force_disable(struct regulator *regulator);
int regulator_is_enabled(struct regulator *regulator);
@@ -432,6 +434,12 @@ static inline int regulator_enable(struct regulator *regulator)
return 0;
}

+static inline int devm_regulator_enable(struct device *dev,
+ struct regulator *regulator)
+{
+ return 0;
+}
+
static inline int regulator_disable(struct regulator *regulator)
{
return 0;
--
2.31.1
\
 
 \ /
  Last update: 2021-06-30 14:51    [W:0.039 / U:2.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site