opp: Add devres wrapper for dev_pm_opp_set_regulators
authorYangtao Li <tiny.windzz@gmail.com>
Sun, 14 Mar 2021 16:33:55 +0000 (19:33 +0300)
committerViresh Kumar <viresh.kumar@linaro.org>
Mon, 15 Mar 2021 03:56:53 +0000 (09:26 +0530)
Add devres wrapper for dev_pm_opp_set_regulators() to simplify drivers
code.

Signed-off-by: Yangtao Li <tiny.windzz@gmail.com>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/opp/core.c
include/linux/pm_opp.h

index 61c48b2d467907e9d3df5c0fe2d6cb052e93e981..d77ec2c55783c33209b9a6c1181407963527f1f3 100644 (file)
@@ -2047,6 +2047,36 @@ put_opp_table:
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
 
+static void devm_pm_opp_regulators_release(void *data)
+{
+       dev_pm_opp_put_regulators(data);
+}
+
+/**
+ * devm_pm_opp_set_regulators() - Set regulator names for the device
+ * @dev: Device for which regulator name is being set.
+ * @names: Array of pointers to the names of the regulator.
+ * @count: Number of regulators.
+ *
+ * This is a resource-managed variant of dev_pm_opp_set_regulators().
+ *
+ * Return: 0 on success and errorno otherwise.
+ */
+int devm_pm_opp_set_regulators(struct device *dev,
+                              const char * const names[],
+                              unsigned int count)
+{
+       struct opp_table *opp_table;
+
+       opp_table = dev_pm_opp_set_regulators(dev, names, count);
+       if (IS_ERR(opp_table))
+               return PTR_ERR(opp_table);
+
+       return devm_add_action_or_reset(dev, devm_pm_opp_regulators_release,
+                                       opp_table);
+}
+EXPORT_SYMBOL_GPL(devm_pm_opp_set_regulators);
+
 /**
  * dev_pm_opp_set_clkname() - Set clk name for the device
  * @dev: Device for which clk name is being set.
index 0583d775aa5ab55c90e3a1c3423c31f0d616fea6..3e667af572119109cdb3923a3f853822244ee01b 100644 (file)
@@ -148,6 +148,7 @@ struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
 void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
 struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
 void dev_pm_opp_put_regulators(struct opp_table *opp_table);
+int devm_pm_opp_set_regulators(struct device *dev, const char * const names[], unsigned int count);
 struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
 void dev_pm_opp_put_clkname(struct opp_table *opp_table);
 int devm_pm_opp_set_clkname(struct device *dev, const char *name);
@@ -349,6 +350,13 @@ static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, co
 
 static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
 
+static inline int devm_pm_opp_set_regulators(struct device *dev,
+                                            const char * const names[],
+                                            unsigned int count)
+{
+       return -EOPNOTSUPP;
+}
+
 static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
 {
        return ERR_PTR(-EOPNOTSUPP);