From: Viresh Kumar <viresh.kumar@linaro.org>
To: rjw@sisk.pl
Cc: linaro-kernel@lists.linaro.org, patches@linaro.org,
cpufreq@vger.kernel.org, linux-pm@vger.kernel.org,
linux-kernel@vger.kernel.org,
Viresh Kumar <viresh.kumar@linaro.org>
Subject: [PATCH 01/16] cpufreq: create cpufreq_generic_get() routine
Date: Fri, 23 Aug 2013 21:20:36 +0530 [thread overview]
Message-ID: <b33d9c5cd16c41f739fa8ca5ea382c8d51a24157.1377272740.git.viresh.kumar@linaro.org> (raw)
In-Reply-To: <cover.1377272740.git.viresh.kumar@linaro.org>
In-Reply-To: <cover.1377272740.git.viresh.kumar@linaro.org>
CPUFreq drivers that use clock frameworks interface,i.e. clk_get_rate(), to get
CPUs clk rate, has similar sort of code used for most of them.
This patch adds a generic ->get() which will do the same thing for them. All
those drivers are required to now is to set .get to cpufreq_generic_get() and
set their clk pointer in policy->clk during ->init().
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
drivers/cpufreq/cpufreq.c | 26 ++++++++++++++++++++------
include/linux/cpufreq.h | 3 +++
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 5fc9c6b..b068f00 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -219,6 +219,20 @@ int cpufreq_generic_init(struct cpufreq_policy *policy,
}
EXPORT_SYMBOL_GPL(cpufreq_generic_init);
+unsigned int cpufreq_generic_get(unsigned int cpu)
+{
+ struct cpufreq_policy *policy = per_cpu(cpufreq_cpu_data, cpu);
+
+ if (!policy || IS_ERR(policy->clk)) {
+ pr_err("%s: No %s associated to cpu: %d\n", __func__,
+ policy ? "clk" : "policy", cpu);
+ return 0;
+ }
+
+ return clk_get_rate(policy->clk) / 1000;
+}
+EXPORT_SYMBOL_GPL(cpufreq_generic_get);
+
struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
{
struct cpufreq_policy *policy = NULL;
@@ -1058,6 +1072,11 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
goto err_set_policy_cpu;
}
+ write_lock_irqsave(&cpufreq_driver_lock, flags);
+ for_each_cpu(j, policy->cpus)
+ per_cpu(cpufreq_cpu_data, j) = policy;
+ write_unlock_irqrestore(&cpufreq_driver_lock, flags);
+
if (cpufreq_driver->get) {
policy->cur = cpufreq_driver->get(policy->cpu);
if (!policy->cur) {
@@ -1090,11 +1109,6 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
}
#endif
- write_lock_irqsave(&cpufreq_driver_lock, flags);
- for_each_cpu(j, policy->cpus)
- per_cpu(cpufreq_cpu_data, j) = policy;
- write_unlock_irqrestore(&cpufreq_driver_lock, flags);
-
if (!frozen) {
ret = cpufreq_add_dev_interface(policy, dev);
if (ret)
@@ -1115,12 +1129,12 @@ static int __cpufreq_add_dev(struct device *dev, struct subsys_interface *sif,
return 0;
err_out_unregister:
+err_get_freq:
write_lock_irqsave(&cpufreq_driver_lock, flags);
for_each_cpu(j, policy->cpus)
per_cpu(cpufreq_cpu_data, j) = NULL;
write_unlock_irqrestore(&cpufreq_driver_lock, flags);
-err_get_freq:
if (cpufreq_driver->exit)
cpufreq_driver->exit(policy);
err_set_policy_cpu:
diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
index 6adea26..7746d11 100644
--- a/include/linux/cpufreq.h
+++ b/include/linux/cpufreq.h
@@ -11,6 +11,7 @@
#ifndef _LINUX_CPUFREQ_H
#define _LINUX_CPUFREQ_H
+#include <linux/clk.h>
#include <linux/cpumask.h>
#include <linux/completion.h>
#include <linux/kobject.h>
@@ -66,6 +67,7 @@ struct cpufreq_policy {
unsigned int cpu; /* cpu nr of CPU managing this policy */
unsigned int last_cpu; /* cpu nr of previous CPU that managed
* this policy */
+ struct clk *clk;
struct cpufreq_cpuinfo cpuinfo;/* see above */
unsigned int min; /* in kHz */
@@ -424,6 +426,7 @@ void cpufreq_frequency_table_put_attr(unsigned int cpu);
int cpufreq_table_validate_and_show(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *table);
+unsigned int cpufreq_generic_get(unsigned int cpu);
int cpufreq_generic_init(struct cpufreq_policy *policy,
struct cpufreq_frequency_table *table,
unsigned int transition_latency);
--
1.7.12.rc2.18.g61b472e
next prev parent reply other threads:[~2013-08-23 15:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 15:50 [PATCH 00/16] cpufreq: create & use cpufreq_generic_get() routine Viresh Kumar
2013-08-23 15:50 ` Viresh Kumar [this message]
2013-08-23 15:50 ` [PATCH 02/16] cpufreq: arm_big_little: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 03/16] cpufreq: at32ap: " Viresh Kumar
2013-08-26 7:12 ` Hans-Christian Egtvedt
2013-08-23 15:50 ` [PATCH 04/16] cpufreq: cpu0: " Viresh Kumar
2013-08-29 13:07 ` Shawn Guo
2013-08-23 15:50 ` [PATCH 05/16] cpufreq: davinci: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 06/16] cpufreq: dbx500: " Viresh Kumar
2013-08-28 12:14 ` Linus Walleij
2013-08-23 15:50 ` [PATCH 07/16] cpufreq: exynos: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 08/16] cpufreq: imx6q: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 09/16] cpufreq: loongson2: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 10/16] cpufreq: omap: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 11/16] cpufreq: ppc: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 12/16] cpufreq: s3c: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 13/16] cpufreq: s5pv210: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 14/16] cpufreq: spear: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 15/16] cpufreq: tegra: " Viresh Kumar
2013-08-23 15:50 ` [PATCH 16/16] cpufreq: unicore2: " Viresh Kumar
2013-08-23 19:40 ` [PATCH 00/16] cpufreq: create & " Rafael J. Wysocki
2013-08-24 4:20 ` Viresh Kumar
2013-08-24 14:50 ` Rafael J. Wysocki
2013-08-26 4:30 ` 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=b33d9c5cd16c41f739fa8ca5ea382c8d51a24157.1377272740.git.viresh.kumar@linaro.org \
--to=viresh.kumar@linaro.org \
--cc=cpufreq@vger.kernel.org \
--cc=linaro-kernel@lists.linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=patches@linaro.org \
--cc=rjw@sisk.pl \
/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).