devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Viresh Kumar <viresh.kumar@linaro.org>
To: Rafael Wysocki <rjw@rjwysocki.net>, rob.herring@linaro.org
Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org,
	arnd.bergmann@linaro.org, grant.likely@linaro.org,
	olof@lixom.net, nm@ti.com, Sudeep.Holla@arm.com,
	sboyd@codeaurora.org, devicetree@vger.kernel.org,
	santosh.shilimkar@oracle.com, mike.turquette@linaro.org,
	kesavan.abhilash@gmail.com, catalin.marinas@arm.com,
	ta.omasab@gmail.com, linux-arm-kernel@lists.infradead.org,
	thomas.petazzoni@free-electrons.com, l.stach@pengutronix.de,
	broonie@kernel.org, viswanath.puttagunta@linaro.org,
	Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH 6/7] opp: Add helpers for initializing CPU opps
Date: Wed, 11 Feb 2015 16:16:29 +0800	[thread overview]
Message-ID: <6bd4f6207604d97c0fd46ee39b0d296d5208ac68.1423642246.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1423642246.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1423642246.git.viresh.kumar@linaro.org>

This provides helpers to find which CPUs share OPPs and initialize OPPs for
them.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 drivers/base/power/opp.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pm_opp.h   |  17 +++++++
 2 files changed, 130 insertions(+)

diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c
index 24a014b7a68a..751f56f323bf 100644
--- a/drivers/base/power/opp.c
+++ b/drivers/base/power/opp.c
@@ -11,6 +11,7 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/cpu.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/err.h>
@@ -1321,6 +1322,44 @@ int of_init_opp_table(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(of_init_opp_table);
 
+int of_cpumask_init_opp_table(cpumask_var_t cpumask)
+{
+	struct device *cpu_dev;
+	int cpu, tcpu, ret = 0;
+
+	if (cpumask_empty(cpumask))
+		return -EINVAL;
+
+	for_each_cpu(cpu, cpumask) {
+		cpu_dev = get_cpu_device(cpu);
+		if (!cpu_dev) {
+			pr_err("%s: failed to get cpu%d device\n", __func__,
+			       cpu);
+			continue;
+		}
+
+		ret = of_init_opp_table(cpu_dev);
+		if (ret) {
+			pr_err("%s: couldn't find opp table for cpu:%d, %d\n",
+			       __func__, cpu, ret);
+
+			/* Free all other OPPs */
+			for_each_cpu(tcpu, cpumask) {
+				if (cpu == tcpu)
+					break;
+
+				cpu_dev = get_cpu_device(tcpu);
+				if (cpu_dev)
+					of_free_opp_table(cpu_dev);
+			}
+			break;
+		}
+	}
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_cpumask_init_opp_table);
+
 /**
  * of_free_opp_table() - Free OPP table entries created from static DT entries
  * @dev:	device pointer used to lookup device OPPs.
@@ -1368,4 +1407,78 @@ void of_free_opp_table(struct device *dev)
 	mutex_unlock(&dev_opp_list_lock);
 }
 EXPORT_SYMBOL_GPL(of_free_opp_table);
+
+void of_cpumask_free_opp_table(cpumask_var_t cpumask)
+{
+	struct device *cpu_dev;
+	int cpu;
+
+	WARN_ON(cpumask_empty(cpumask));
+
+	for_each_cpu(cpu, cpumask) {
+		cpu_dev = get_cpu_device(cpu);
+		if (!cpu_dev) {
+			pr_err("%s: failed to get cpu%d device\n", __func__,
+			       cpu);
+			continue;
+		}
+
+		of_free_opp_table(cpu_dev);
+	}
+}
+EXPORT_SYMBOL_GPL(of_cpumask_free_opp_table);
+
+/* Works only for OPP v2 bindings */
+int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
+{
+	struct device_node *np, *tmp_np;
+	struct device *tcpu_dev;
+	int cpu, ret = 0;
+
+	cpumask_set_cpu(cpu_dev->id, cpumask);
+
+	/* Get OPP descriptor node */
+	np = of_get_opp_desc_node(cpu_dev);
+	if (IS_ERR(np)) {
+		dev_info(cpu_dev, "%s: Couldn't find opp node: %ld\n", __func__,
+			 PTR_ERR(np));
+		return -EINVAL;
+	}
+
+	/* OPPs are shared ? */
+	if (!of_get_property(np, "shared-opp", NULL))
+		goto put_cpu_node;
+
+	for_each_possible_cpu(cpu) {
+		if (cpu == cpu_dev->id)
+			continue;
+
+		tcpu_dev = get_cpu_device(cpu);
+		if (!tcpu_dev) {
+			pr_err("failed to get cpu%d device\n", cpu);
+			ret = -ENODEV;
+			goto put_cpu_node;
+		}
+
+		/* Get OPP descriptor node */
+		tmp_np = of_get_opp_desc_node(tcpu_dev);
+		if (IS_ERR(tmp_np)) {
+			dev_info(tcpu_dev, "%s: Couldn't find opp node: %ld\n",
+				 __func__, PTR_ERR(np));
+			ret = -EINVAL;
+			goto put_cpu_node;
+		}
+
+		/* CPUs are sharing opp node */
+		if (np == tmp_np)
+			cpumask_set_cpu(cpu, cpumask);
+
+		of_node_put(tmp_np);
+	}
+
+put_cpu_node:
+	of_node_put(np);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(of_get_cpus_sharing_opps);
 #endif
diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h
index 9949d07a93f9..41cbc7469b5a 100644
--- a/include/linux/pm_opp.h
+++ b/include/linux/pm_opp.h
@@ -115,6 +115,9 @@ static inline struct srcu_notifier_head *dev_pm_opp_get_notifier(
 #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
 int of_init_opp_table(struct device *dev);
 void of_free_opp_table(struct device *dev);
+int of_cpumask_init_opp_table(cpumask_var_t cpumask);
+void of_cpumask_free_opp_table(cpumask_var_t cpumask);
+int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask);
 struct device_node *of_get_opp_desc_node(struct device *dev);
 #else
 static inline int of_init_opp_table(struct device *dev)
@@ -126,6 +129,20 @@ static inline void of_free_opp_table(struct device *dev)
 {
 }
 
+static inline int of_cpumask_init_opp_table(cpumask_var_t cpumask)
+{
+	return -EINVAL;
+}
+
+static inline void of_cpumask_free_opp_table(cpumask_var_t cpumask)
+{
+}
+
+static inline int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask)
+{
+	return -EINVAL;
+}
+
 static inline struct device_node *of_get_opp_desc_node(struct device *dev)
 {
 	return ERR_PTR(-EINVAL);
-- 
2.3.0.rc0.44.ga94655d


  parent reply	other threads:[~2015-02-11  8:16 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11  8:16 [PATCH 0/7] OPP: Introduce OPP bindings V2 and supporting code Viresh Kumar
2015-02-11  8:16 ` [PATCH 1/7] OPP: Redefine bindings to overcome shortcomings Viresh Kumar
2015-02-23 22:36   ` Kevin Hilman
2015-02-24  4:24     ` Viresh Kumar
2015-02-24 17:12       ` Kevin Hilman
2015-02-25  3:45         ` viresh kumar
2015-02-11  8:16 ` [PATCH 2/7] opp: Relocate few routines Viresh Kumar
2015-02-11  8:16 ` [PATCH 3/7] OPP: Break _opp_add_dynamic() into smaller functions Viresh Kumar
2015-02-11  8:16 ` [PATCH 4/7] opp: Parse new (v2) bindings Viresh Kumar
     [not found] ` <cover.1423642246.git.viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2015-02-11  8:16   ` [PATCH 5/7] opp: convert device_opp->dev to a list of devices Viresh Kumar
2015-02-27  5:25   ` [PATCH 0/7] OPP: Introduce OPP bindings V2 and supporting code Viresh Kumar
     [not found]     ` <CAKohpokF0_or8aXwzWZ=bUX1Robk8THyqRpKjbaarg9NHufLmw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-16  9:54       ` Viresh Kumar
2015-02-11  8:16 ` Viresh Kumar [this message]
2015-02-11  8:16 ` [PATCH 7/7] cpufreq-dt: Use DT to set policy->cpus/related_cpus Viresh Kumar
2015-02-12  0:52 ` [PATCH 0/7] OPP: Introduce OPP bindings V2 and supporting code Stephen Boyd
2015-02-12  7:22   ` Viresh Kumar
2015-02-12  8:20     ` Stephen Boyd
2015-02-17  7:46       ` Viresh Kumar
2015-03-22 18:56         ` Mark Brown
2015-04-01  6:22 ` Viresh Kumar
     [not found]   ` <CAKohpokDhHo1ftcB6b4b+hO125_sqjK0NKESt79GVcWEwiq04w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-01 16:43     ` Rob Herring
     [not found]       ` <CAL_JsqLCjkrb2gT-_hj-UTAs+qn2LZtEm=f_C05ovhdwkZKB-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-04-02  3:00         ` 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=6bd4f6207604d97c0fd46ee39b0d296d5208ac68.1423642246.git.viresh.kumar@linaro.org \
    --to=viresh.kumar@linaro.org \
    --cc=Sudeep.Holla@arm.com \
    --cc=arnd.bergmann@linaro.org \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=devicetree@vger.kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=kesavan.abhilash@gmail.com \
    --cc=l.stach@pengutronix.de \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mike.turquette@linaro.org \
    --cc=nm@ti.com \
    --cc=olof@lixom.net \
    --cc=rjw@rjwysocki.net \
    --cc=rob.herring@linaro.org \
    --cc=santosh.shilimkar@oracle.com \
    --cc=sboyd@codeaurora.org \
    --cc=ta.omasab@gmail.com \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=viswanath.puttagunta@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).