aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/s3c64xx-cpufreq.c
diff options
context:
space:
mode:
authorViresh Kumar <viresh.kumar@linaro.org>2014-01-09 10:08:43 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2014-01-16 20:00:44 -0500
commit652ed95d5fa6074b3c4ea245deb0691f1acb6656 (patch)
tree7b01079f3a582b0d6b08f541a8a344440bec8eae /drivers/cpufreq/s3c64xx-cpufreq.c
parent0ad04fb30db0341d0b1134e2f592d9146c9abb64 (diff)
cpufreq: introduce cpufreq_generic_get() routine
CPUFreq drivers that use clock frameworks interface,i.e. clk_get_rate(), to get CPUs clk rate, have similar sort of code used in 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(). Acked-by: Hans-Christian Egtvedt <egtvedt@samfundet.no> Acked-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/cpufreq/s3c64xx-cpufreq.c')
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c33
1 files changed, 12 insertions, 21 deletions
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index 8435f45d7e9d..c4226de079ab 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -19,7 +19,6 @@
19#include <linux/regulator/consumer.h> 19#include <linux/regulator/consumer.h>
20#include <linux/module.h> 20#include <linux/module.h>
21 21
22static struct clk *armclk;
23static struct regulator *vddarm; 22static struct regulator *vddarm;
24static unsigned long regulator_latency; 23static unsigned long regulator_latency;
25 24
@@ -54,14 +53,6 @@ static struct cpufreq_frequency_table s3c64xx_freq_table[] = {
54}; 53};
55#endif 54#endif
56 55
57static unsigned int s3c64xx_cpufreq_get_speed(unsigned int cpu)
58{
59 if (cpu != 0)
60 return 0;
61
62 return clk_get_rate(armclk) / 1000;
63}
64
65static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy, 56static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
66 unsigned int index) 57 unsigned int index)
67{ 58{
@@ -69,7 +60,7 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
69 unsigned int old_freq, new_freq; 60 unsigned int old_freq, new_freq;
70 int ret; 61 int ret;
71 62
72 old_freq = clk_get_rate(armclk) / 1000; 63 old_freq = clk_get_rate(policy->clk) / 1000;
73 new_freq = s3c64xx_freq_table[index].frequency; 64 new_freq = s3c64xx_freq_table[index].frequency;
74 dvfs = &s3c64xx_dvfs_table[s3c64xx_freq_table[index].driver_data]; 65 dvfs = &s3c64xx_dvfs_table[s3c64xx_freq_table[index].driver_data];
75 66
@@ -86,7 +77,7 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
86 } 77 }
87#endif 78#endif
88 79
89 ret = clk_set_rate(armclk, new_freq * 1000); 80 ret = clk_set_rate(policy->clk, new_freq * 1000);
90 if (ret < 0) { 81 if (ret < 0) {
91 pr_err("Failed to set rate %dkHz: %d\n", 82 pr_err("Failed to set rate %dkHz: %d\n",
92 new_freq, ret); 83 new_freq, ret);
@@ -101,7 +92,7 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
101 if (ret != 0) { 92 if (ret != 0) {
102 pr_err("Failed to set VDDARM for %dkHz: %d\n", 93 pr_err("Failed to set VDDARM for %dkHz: %d\n",
103 new_freq, ret); 94 new_freq, ret);
104 if (clk_set_rate(armclk, old_freq * 1000) < 0) 95 if (clk_set_rate(policy->clk, old_freq * 1000) < 0)
105 pr_err("Failed to restore original clock rate\n"); 96 pr_err("Failed to restore original clock rate\n");
106 97
107 return ret; 98 return ret;
@@ -110,7 +101,7 @@ static int s3c64xx_cpufreq_set_target(struct cpufreq_policy *policy,
110#endif 101#endif
111 102
112 pr_debug("Set actual frequency %lukHz\n", 103 pr_debug("Set actual frequency %lukHz\n",
113 clk_get_rate(armclk) / 1000); 104 clk_get_rate(policy->clk) / 1000);
114 105
115 return 0; 106 return 0;
116} 107}
@@ -169,11 +160,11 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
169 return -ENODEV; 160 return -ENODEV;
170 } 161 }
171 162
172 armclk = clk_get(NULL, "armclk"); 163 policy->clk = clk_get(NULL, "armclk");
173 if (IS_ERR(armclk)) { 164 if (IS_ERR(policy->clk)) {
174 pr_err("Unable to obtain ARMCLK: %ld\n", 165 pr_err("Unable to obtain ARMCLK: %ld\n",
175 PTR_ERR(armclk)); 166 PTR_ERR(policy->clk));
176 return PTR_ERR(armclk); 167 return PTR_ERR(policy->clk);
177 } 168 }
178 169
179#ifdef CONFIG_REGULATOR 170#ifdef CONFIG_REGULATOR
@@ -193,7 +184,7 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
193 unsigned long r; 184 unsigned long r;
194 185
195 /* Check for frequencies we can generate */ 186 /* Check for frequencies we can generate */
196 r = clk_round_rate(armclk, freq->frequency * 1000); 187 r = clk_round_rate(policy->clk, freq->frequency * 1000);
197 r /= 1000; 188 r /= 1000;
198 if (r != freq->frequency) { 189 if (r != freq->frequency) {
199 pr_debug("%dkHz unsupported by clock\n", 190 pr_debug("%dkHz unsupported by clock\n",
@@ -203,7 +194,7 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
203 194
204 /* If we have no regulator then assume startup 195 /* If we have no regulator then assume startup
205 * frequency is the maximum we can support. */ 196 * frequency is the maximum we can support. */
206 if (!vddarm && freq->frequency > s3c64xx_cpufreq_get_speed(0)) 197 if (!vddarm && freq->frequency > clk_get_rate(policy->clk) / 1000)
207 freq->frequency = CPUFREQ_ENTRY_INVALID; 198 freq->frequency = CPUFREQ_ENTRY_INVALID;
208 199
209 freq++; 200 freq++;
@@ -219,7 +210,7 @@ static int s3c64xx_cpufreq_driver_init(struct cpufreq_policy *policy)
219 pr_err("Failed to configure frequency table: %d\n", 210 pr_err("Failed to configure frequency table: %d\n",
220 ret); 211 ret);
221 regulator_put(vddarm); 212 regulator_put(vddarm);
222 clk_put(armclk); 213 clk_put(policy->clk);
223 } 214 }
224 215
225 return ret; 216 return ret;
@@ -229,7 +220,7 @@ static struct cpufreq_driver s3c64xx_cpufreq_driver = {
229 .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK, 220 .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK,
230 .verify = cpufreq_generic_frequency_table_verify, 221 .verify = cpufreq_generic_frequency_table_verify,
231 .target_index = s3c64xx_cpufreq_set_target, 222 .target_index = s3c64xx_cpufreq_set_target,
232 .get = s3c64xx_cpufreq_get_speed, 223 .get = cpufreq_generic_get,
233 .init = s3c64xx_cpufreq_driver_init, 224 .init = s3c64xx_cpufreq_driver_init,
234 .name = "s3c", 225 .name = "s3c",
235}; 226};