aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/cpufreq/kirkwood-cpufreq.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 14:26:56 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-20 14:26:56 -0500
commit8793422fd9ac5037f5047f80473007301df3689f (patch)
treef5aa3b3a564f053e1b5604c45db80193abc734a4 /drivers/cpufreq/kirkwood-cpufreq.c
parentb3cdda2b4f541439ca4205793040aa2e1c852e3b (diff)
parent10baf04e95fbf7eb6089410220a547211dd2ffa7 (diff)
Merge tag 'pm+acpi-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
Pull ACPI and power management updates from Rafael Wysocki: - Rework of the ACPI namespace scanning code from Rafael J. Wysocki with contributions from Bjorn Helgaas, Jiang Liu, Mika Westerberg, Toshi Kani, and Yinghai Lu. - ACPI power resources handling and ACPI device PM update from Rafael J Wysocki. - ACPICA update to version 20130117 from Bob Moore and Lv Zheng with contributions from Aaron Lu, Chao Guan, Jesper Juhl, and Tim Gardner. - Support for Intel Lynxpoint LPSS from Mika Westerberg. - cpuidle update from Len Brown including Intel Haswell support, C1 state for intel_idle, removal of global pm_idle. - cpuidle fixes and cleanups from Daniel Lezcano. - cpufreq fixes and cleanups from Viresh Kumar and Fabio Baltieri with contributions from Stratos Karafotis and Rickard Andersson. - Intel P-states driver for Sandy Bridge processors from Dirk Brandewie. - cpufreq driver for Marvell Kirkwood SoCs from Andrew Lunn. - cpufreq fixes related to ordering issues between acpi-cpufreq and powernow-k8 from Borislav Petkov and Matthew Garrett. - cpufreq support for Calxeda Highbank processors from Mark Langsdorf and Rob Herring. - cpufreq driver for the Freescale i.MX6Q SoC and cpufreq-cpu0 update from Shawn Guo. - cpufreq Exynos fixes and cleanups from Jonghwan Choi, Sachin Kamat, and Inderpal Singh. - Support for "lightweight suspend" from Zhang Rui. - Removal of the deprecated power trace API from Paul Gortmaker. - Assorted updates from Andreas Fleig, Colin Ian King, Davidlohr Bueso, Joseph Salisbury, Kees Cook, Li Fei, Nishanth Menon, ShuoX Liu, Srinivas Pandruvada, Tejun Heo, Thomas Renninger, and Yasuaki Ishimatsu. * tag 'pm+acpi-3.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm: (267 commits) PM idle: remove global declaration of pm_idle unicore32 idle: delete stray pm_idle comment openrisc idle: delete pm_idle mn10300 idle: delete pm_idle microblaze idle: delete pm_idle m32r idle: delete pm_idle, and other dead idle code ia64 idle: delete pm_idle cris idle: delete idle and pm_idle ARM64 idle: delete pm_idle ARM idle: delete pm_idle blackfin idle: delete pm_idle sparc idle: rename pm_idle to sparc_idle sh idle: rename global pm_idle to static sh_idle x86 idle: rename global pm_idle to static x86_idle APM idle: register apm_cpu_idle via cpuidle cpufreq / intel_pstate: Add kernel command line option disable intel_pstate. cpufreq / intel_pstate: Change to disallow module build tools/power turbostat: display SMI count by default intel_idle: export both C1 and C1E ACPI / hotplug: Fix concurrency issues and memory leaks ...
Diffstat (limited to 'drivers/cpufreq/kirkwood-cpufreq.c')
-rw-r--r--drivers/cpufreq/kirkwood-cpufreq.c259
1 files changed, 259 insertions, 0 deletions
diff --git a/drivers/cpufreq/kirkwood-cpufreq.c b/drivers/cpufreq/kirkwood-cpufreq.c
new file mode 100644
index 000000000000..0e83e3c24f5b
--- /dev/null
+++ b/drivers/cpufreq/kirkwood-cpufreq.c
@@ -0,0 +1,259 @@
1/*
2 * kirkwood_freq.c: cpufreq driver for the Marvell kirkwood
3 *
4 * Copyright (C) 2013 Andrew Lunn <andrew@lunn.ch>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/clk.h>
15#include <linux/clk-provider.h>
16#include <linux/cpufreq.h>
17#include <linux/of.h>
18#include <linux/platform_device.h>
19#include <linux/io.h>
20#include <asm/proc-fns.h>
21
22#define CPU_SW_INT_BLK BIT(28)
23
24static struct priv
25{
26 struct clk *cpu_clk;
27 struct clk *ddr_clk;
28 struct clk *powersave_clk;
29 struct device *dev;
30 void __iomem *base;
31} priv;
32
33#define STATE_CPU_FREQ 0x01
34#define STATE_DDR_FREQ 0x02
35
36/*
37 * Kirkwood can swap the clock to the CPU between two clocks:
38 *
39 * - cpu clk
40 * - ddr clk
41 *
42 * The frequencies are set at runtime before registering this *
43 * table.
44 */
45static struct cpufreq_frequency_table kirkwood_freq_table[] = {
46 {STATE_CPU_FREQ, 0}, /* CPU uses cpuclk */
47 {STATE_DDR_FREQ, 0}, /* CPU uses ddrclk */
48 {0, CPUFREQ_TABLE_END},
49};
50
51static unsigned int kirkwood_cpufreq_get_cpu_frequency(unsigned int cpu)
52{
53 if (__clk_is_enabled(priv.powersave_clk))
54 return kirkwood_freq_table[1].frequency;
55 return kirkwood_freq_table[0].frequency;
56}
57
58static void kirkwood_cpufreq_set_cpu_state(unsigned int index)
59{
60 struct cpufreq_freqs freqs;
61 unsigned int state = kirkwood_freq_table[index].index;
62 unsigned long reg;
63
64 freqs.old = kirkwood_cpufreq_get_cpu_frequency(0);
65 freqs.new = kirkwood_freq_table[index].frequency;
66 freqs.cpu = 0; /* Kirkwood is UP */
67
68 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
69
70 dev_dbg(priv.dev, "Attempting to set frequency to %i KHz\n",
71 kirkwood_freq_table[index].frequency);
72 dev_dbg(priv.dev, "old frequency was %i KHz\n",
73 kirkwood_cpufreq_get_cpu_frequency(0));
74
75 if (freqs.old != freqs.new) {
76 local_irq_disable();
77
78 /* Disable interrupts to the CPU */
79 reg = readl_relaxed(priv.base);
80 reg |= CPU_SW_INT_BLK;
81 writel_relaxed(reg, priv.base);
82
83 switch (state) {
84 case STATE_CPU_FREQ:
85 clk_disable(priv.powersave_clk);
86 break;
87 case STATE_DDR_FREQ:
88 clk_enable(priv.powersave_clk);
89 break;
90 }
91
92 /* Wait-for-Interrupt, while the hardware changes frequency */
93 cpu_do_idle();
94
95 /* Enable interrupts to the CPU */
96 reg = readl_relaxed(priv.base);
97 reg &= ~CPU_SW_INT_BLK;
98 writel_relaxed(reg, priv.base);
99
100 local_irq_enable();
101 }
102 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
103};
104
105static int kirkwood_cpufreq_verify(struct cpufreq_policy *policy)
106{
107 return cpufreq_frequency_table_verify(policy, kirkwood_freq_table);
108}
109
110static int kirkwood_cpufreq_target(struct cpufreq_policy *policy,
111 unsigned int target_freq,
112 unsigned int relation)
113{
114 unsigned int index = 0;
115
116 if (cpufreq_frequency_table_target(policy, kirkwood_freq_table,
117 target_freq, relation, &index))
118 return -EINVAL;
119
120 kirkwood_cpufreq_set_cpu_state(index);
121
122 return 0;
123}
124
125/* Module init and exit code */
126static int kirkwood_cpufreq_cpu_init(struct cpufreq_policy *policy)
127{
128 int result;
129
130 /* cpuinfo and default policy values */
131 policy->cpuinfo.transition_latency = 5000; /* 5uS */
132 policy->cur = kirkwood_cpufreq_get_cpu_frequency(0);
133
134 result = cpufreq_frequency_table_cpuinfo(policy, kirkwood_freq_table);
135 if (result)
136 return result;
137
138 cpufreq_frequency_table_get_attr(kirkwood_freq_table, policy->cpu);
139
140 return 0;
141}
142
143static int kirkwood_cpufreq_cpu_exit(struct cpufreq_policy *policy)
144{
145 cpufreq_frequency_table_put_attr(policy->cpu);
146 return 0;
147}
148
149static struct freq_attr *kirkwood_cpufreq_attr[] = {
150 &cpufreq_freq_attr_scaling_available_freqs,
151 NULL,
152};
153
154static struct cpufreq_driver kirkwood_cpufreq_driver = {
155 .get = kirkwood_cpufreq_get_cpu_frequency,
156 .verify = kirkwood_cpufreq_verify,
157 .target = kirkwood_cpufreq_target,
158 .init = kirkwood_cpufreq_cpu_init,
159 .exit = kirkwood_cpufreq_cpu_exit,
160 .name = "kirkwood-cpufreq",
161 .owner = THIS_MODULE,
162 .attr = kirkwood_cpufreq_attr,
163};
164
165static int kirkwood_cpufreq_probe(struct platform_device *pdev)
166{
167 struct device_node *np;
168 struct resource *res;
169 int err;
170
171 priv.dev = &pdev->dev;
172
173 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
174 if (!res) {
175 dev_err(&pdev->dev, "Cannot get memory resource\n");
176 return -ENODEV;
177 }
178 priv.base = devm_request_and_ioremap(&pdev->dev, res);
179 if (!priv.base) {
180 dev_err(&pdev->dev, "Cannot ioremap\n");
181 return -EADDRNOTAVAIL;
182 }
183
184 np = of_find_node_by_path("/cpus/cpu@0");
185 if (!np)
186 return -ENODEV;
187
188 priv.cpu_clk = of_clk_get_by_name(np, "cpu_clk");
189 if (IS_ERR(priv.cpu_clk)) {
190 dev_err(priv.dev, "Unable to get cpuclk");
191 return PTR_ERR(priv.cpu_clk);
192 }
193
194 clk_prepare_enable(priv.cpu_clk);
195 kirkwood_freq_table[0].frequency = clk_get_rate(priv.cpu_clk) / 1000;
196
197 priv.ddr_clk = of_clk_get_by_name(np, "ddrclk");
198 if (IS_ERR(priv.ddr_clk)) {
199 dev_err(priv.dev, "Unable to get ddrclk");
200 err = PTR_ERR(priv.ddr_clk);
201 goto out_cpu;
202 }
203
204 clk_prepare_enable(priv.ddr_clk);
205 kirkwood_freq_table[1].frequency = clk_get_rate(priv.ddr_clk) / 1000;
206
207 priv.powersave_clk = of_clk_get_by_name(np, "powersave");
208 if (IS_ERR(priv.powersave_clk)) {
209 dev_err(priv.dev, "Unable to get powersave");
210 err = PTR_ERR(priv.powersave_clk);
211 goto out_ddr;
212 }
213 clk_prepare(priv.powersave_clk);
214
215 of_node_put(np);
216 np = NULL;
217
218 err = cpufreq_register_driver(&kirkwood_cpufreq_driver);
219 if (!err)
220 return 0;
221
222 dev_err(priv.dev, "Failed to register cpufreq driver");
223
224 clk_disable_unprepare(priv.powersave_clk);
225out_ddr:
226 clk_disable_unprepare(priv.ddr_clk);
227out_cpu:
228 clk_disable_unprepare(priv.cpu_clk);
229 of_node_put(np);
230
231 return err;
232}
233
234static int kirkwood_cpufreq_remove(struct platform_device *pdev)
235{
236 cpufreq_unregister_driver(&kirkwood_cpufreq_driver);
237
238 clk_disable_unprepare(priv.powersave_clk);
239 clk_disable_unprepare(priv.ddr_clk);
240 clk_disable_unprepare(priv.cpu_clk);
241
242 return 0;
243}
244
245static struct platform_driver kirkwood_cpufreq_platform_driver = {
246 .probe = kirkwood_cpufreq_probe,
247 .remove = kirkwood_cpufreq_remove,
248 .driver = {
249 .name = "kirkwood-cpufreq",
250 .owner = THIS_MODULE,
251 },
252};
253
254module_platform_driver(kirkwood_cpufreq_platform_driver);
255
256MODULE_LICENSE("GPL v2");
257MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch");
258MODULE_DESCRIPTION("cpufreq driver for Marvell's kirkwood CPU");
259MODULE_ALIAS("platform:kirkwood-cpufreq");