[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210311192105.14998-6-digetx@gmail.com>
Date: Thu, 11 Mar 2021 22:20:56 +0300
From: Dmitry Osipenko <digetx@...il.com>
To: Qiang Yu <yuq825@...il.com>, Rob Clark <robdclark@...il.com>,
Sean Paul <sean@...rly.run>, Rob Herring <robh@...nel.org>,
Tomeu Vizoso <tomeu.vizoso@...labora.com>,
Steven Price <steven.price@....com>,
Alyssa Rosenzweig <alyssa.rosenzweig@...labora.com>,
Stanimir Varbanov <stanimir.varbanov@...aro.org>,
Andy Gross <agross@...nel.org>,
Bjorn Andersson <bjorn.andersson@...aro.org>,
Mauro Carvalho Chehab <mchehab@...nel.org>,
Lukasz Luba <lukasz.luba@....com>,
Krzysztof Kozlowski <krzysztof.kozlowski@...onical.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Ulf Hansson <ulf.hansson@...aro.org>,
Viresh Kumar <vireshk@...nel.org>, Nishanth Menon <nm@...com>,
Stephen Boyd <sboyd@...nel.org>,
Mark Brown <broonie@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jirislaby@...nel.org>,
Yangtao Li <tiny.windzz@...il.com>
Cc: Daniel Vetter <daniel@...ll.ch>, dri-devel@...ts.freedesktop.org,
lima@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
linux-arm-msm@...r.kernel.org, freedreno@...ts.freedesktop.org,
linux-media@...r.kernel.org, linux-pm@...r.kernel.org,
linux-samsung-soc@...r.kernel.org, linux-mmc@...r.kernel.org,
linux-spi@...r.kernel.org, linux-serial@...r.kernel.org,
linux-tegra@...r.kernel.org
Subject: [PATCH v2 05/14] opp: Add devres wrapper for dev_pm_opp_register_notifier
From: Yangtao Li <tiny.windzz@...il.com>
Add devres wrapper for dev_pm_opp_register_notifier() to simplify driver
code.
Signed-off-by: Yangtao Li <tiny.windzz@...il.com>
Signed-off-by: Dmitry Osipenko <digetx@...il.com>
---
drivers/opp/core.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/pm_opp.h | 6 ++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index f9e4ebb7aad0..509b2e052f3c 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -2899,6 +2899,44 @@ int dev_pm_opp_unregister_notifier(struct device *dev,
}
EXPORT_SYMBOL(dev_pm_opp_unregister_notifier);
+static void devm_pm_opp_notifier_release(struct device *dev, void *res)
+{
+ struct notifier_block *nb = *(struct notifier_block **)res;
+
+ WARN_ON(dev_pm_opp_unregister_notifier(dev, nb));
+}
+
+/**
+ * devm_pm_opp_register_notifier() - Register OPP notifier for the device
+ * @dev: Device for which notifier needs to be registered
+ * @nb: Notifier block to be registered
+ *
+ * Return: 0 on success or a negative error value.
+ *
+ * The notifier will be unregistered after the device is destroyed.
+ */
+int devm_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
+{
+ struct notifier_block **ptr;
+ int ret;
+
+ ptr = devres_alloc(devm_pm_opp_notifier_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return -ENOMEM;
+
+ ret = dev_pm_opp_register_notifier(dev, nb);
+ if (ret) {
+ devres_free(ptr);
+ return ret;
+ }
+
+ *ptr = nb;
+ devres_add(dev, ptr);
+
+ return 0;
+}
+EXPORT_SYMBOL(devm_pm_opp_register_notifier);
+
/**
* dev_pm_opp_remove_table() - Free all OPPs associated with the device
* @dev: device pointer used to lookup OPP table.
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 2f5dc123c1a0..7088997491b2 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -141,6 +141,7 @@ int dev_pm_opp_disable(struct device *dev, unsigned long freq);
int dev_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb);
+int devm_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb);
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
@@ -313,6 +314,11 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti
return -EOPNOTSUPP;
}
+static inline int devm_pm_opp_register_notifier(struct device *dev, struct notifier_block *nb)
+{
+ return -EOPNOTSUPP;
+}
+
static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
const u32 *versions,
unsigned int count)
--
2.29.2
Powered by blists - more mailing lists