[PATCH v2 10/11] OPP: Allow copying OPPs tables between devices

From: Saravana Kannan
Date: Fri Jun 14 2019 - 00:23:00 EST


Some hardware devices might create multiple children devices to manage
different components of the hardware. In these cases, it might be necessary
for the original hardware device to copy specific OPP tables to a specific
the new child device. Add dev_pm_opp_add_opp_table() to do that.

Signed-off-by: Saravana Kannan <saravanak@xxxxxxxxxx>
---
drivers/opp/core.c | 8 ++++++++
include/linux/pm_opp.h | 7 +++++++
2 files changed, 15 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index c9914afd508a..668a377f59a5 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -943,6 +943,14 @@ struct opp_device *_add_opp_dev(const struct device *dev,
return opp_dev;
}

+int dev_pm_opp_add_opp_table(struct device *dev, struct opp_table *opp_table)
+{
+ if (!dev || !opp_table)
+ return -EINVAL;
+
+ return _add_opp_dev(dev, opp_table) ? 0 : -ENOMEM;
+}
+
static struct opp_table *_allocate_opp_table(struct device *dev, int index)
{
struct opp_table *opp_table;
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index d9156b62d966..3694d703817f 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -81,6 +81,7 @@ struct dev_pm_set_opp_data {
struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *dev, int index);
void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
+int dev_pm_opp_add_opp_table(struct device *dev, struct opp_table *opp_table);

unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);

@@ -158,6 +159,12 @@ static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *

static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}

+static int dev_pm_opp_add_opp_table(struct device *dev,
+ struct opp_table *opp_table)
+{
+ return -ENOTSUPP;
+}
+
static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
{
return 0;
--
2.22.0.rc2.383.gf4fbbf30c2-goog