linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leonard Crestez <leonard.crestez@nxp.com>
To: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Artur Świgoń" <a.swigon@partner.samsung.com>,
	"Saravana Kannan" <saravanak@google.com>,
	"Krzysztof Kozlowski" <krzk@kernel.org>,
	"Georgi Djakov" <georgi.djakov@linaro.org>,
	"Chanwoo Choi" <cw00.choi@samsung.com>,
	"MyungJoo Ham" <myungjoo.ham@samsung.com>,
	"Kyungmin Park" <kyungmin.park@samsung.com>,
	"Alexandre Bailon" <abailon@baylibre.com>,
	linux-pm@vger.kernel.org
Subject: [RFC 2/4] opp: Add dev_pm_opp_table_get_device
Date: Tue,  6 Aug 2019 14:12:26 +0300	[thread overview]
Message-ID: <53d047703057fb09a0345b0a13715576d6eea3da.1565089196.git.leonard.crestez@nxp.com> (raw)
In-Reply-To: <cover.1565089196.git.leonard.crestez@nxp.com>
In-Reply-To: <cover.1565089196.git.leonard.crestez@nxp.com>

This API is the opposite of dev_pm_opp_get_opp_table. OPP tables can be
shared between devices but this ambiguity can be handled by returning an
error if opp table is not exclusive.

This can used for fetching the device pointed to by "required-opps".

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
---
 drivers/opp/core.c     | 30 ++++++++++++++++++++++++++++++
 include/linux/pm_opp.h |  6 ++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/opp/core.c b/drivers/opp/core.c
index 77814d3bc4e6..b8bbabbbe44a 100644
--- a/drivers/opp/core.c
+++ b/drivers/opp/core.c
@@ -87,10 +87,40 @@ struct opp_table *_find_opp_table(struct device *dev)
 	mutex_unlock(&opp_table_lock);
 
 	return opp_table;
 }
 
+/**
+ * _find_opp_table() - find device struct using opp_table pointer
+ *
+ * OPP table must be exclusive: not be shared between devices.
+ */
+struct device *dev_pm_opp_table_get_device(struct opp_table *opp_table)
+{
+	struct opp_device *opp_dev;
+	struct device *dev = ERR_PTR(-EINVAL);
+	int opp_dev_cnt = 0;
+
+	mutex_lock(&opp_table->lock);
+
+	/* OPP table must not be shared: only one device */
+	if (opp_table->shared_opp != OPP_TABLE_ACCESS_EXCLUSIVE)
+		goto out;
+	list_for_each_entry(opp_dev, &opp_table->dev_list, node)
+		opp_dev_cnt++;
+	if (opp_dev_cnt != 1)
+		goto out;
+
+	opp_dev = list_first_entry(&opp_table->dev_list, struct opp_device, node);
+	dev = opp_dev->dev;
+
+out:
+	mutex_unlock(&opp_table->lock);
+	return dev;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_table_get_device);
+
 /**
  * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
  * @opp:	opp for which voltage has to be returned for
  *
  * Return: voltage in micro volt corresponding to the opp, else
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index b8197ab014f2..a4db3f42d787 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -76,10 +76,11 @@ struct dev_pm_set_opp_data {
 #if defined(CONFIG_PM_OPP)
 
 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);
+struct device *dev_pm_opp_table_get_device(struct opp_table *opp_table);
 
 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
 
 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
 
@@ -149,10 +150,15 @@ static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *
 	return ERR_PTR(-ENOTSUPP);
 }
 
 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
 
+struct struct device *dev_pm_opp_table_get_device(struct opp_table *opp_table)
+{
+	return ERR_PTR(-ENOTSUPP);
+}
+
 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
 {
 	return 0;
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-08-06 11:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 11:12 [RFC 0/4] opp: Parse required-opp as dev_pm_qos_request Leonard Crestez
2019-08-06 11:12 ` [RFC 1/4] opp: Drop const from opp_device struct device Leonard Crestez
2019-08-06 11:12 ` Leonard Crestez [this message]
2019-08-06 11:12 ` [RFC 3/4] opp: Add dev_pm_parse_required_opp_as_qos Leonard Crestez
2019-08-06 11:12 ` [RFC 4/4] PM / QoS: Add dev_pm_qos_get_curr_value Leonard Crestez
2019-08-20  6:52 ` [RFC 0/4] opp: Parse required-opp as dev_pm_qos_request Viresh Kumar
2019-08-20  9:02   ` Leonard Crestez
2019-08-20  9:22     ` Viresh Kumar
2019-08-20 15:48       ` Leonard Crestez
2019-08-21  5:18         ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53d047703057fb09a0345b0a13715576d6eea3da.1565089196.git.leonard.crestez@nxp.com \
    --to=leonard.crestez@nxp.com \
    --cc=a.swigon@partner.samsung.com \
    --cc=abailon@baylibre.com \
    --cc=cw00.choi@samsung.com \
    --cc=georgi.djakov@linaro.org \
    --cc=krzk@kernel.org \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=myungjoo.ham@samsung.com \
    --cc=rjw@rjwysocki.net \
    --cc=saravanak@google.com \
    --cc=sboyd@kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).