16 #include <linux/module.h>
17 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/kernel.h>
21 #include <linux/sched.h>
26 #include <linux/time.h>
29 #define DBG(fmt...) pr_debug(fmt)
33 #define SCOM_PCR 0x0aa001
35 #define PCR_HILO_SELECT 0x80000000U
36 #define PCR_SPEED_FULL 0x00000000U
37 #define PCR_SPEED_HALF 0x00020000U
38 #define PCR_SPEED_QUARTER 0x00040000U
39 #define PCR_SPEED_MASK 0x000e0000U
40 #define PCR_SPEED_SHIFT 17
41 #define PCR_FREQ_REQ_VALID 0x00010000U
42 #define PCR_VOLT_REQ_VALID 0x00008000U
43 #define PCR_TARGET_TIME_MASK 0x00006000U
44 #define PCR_STATLAT_MASK 0x00001f00U
45 #define PCR_SNOOPLAT_MASK 0x000000f0U
46 #define PCR_SNOOPACC_MASK 0x0000000fU
48 #define SCOM_PSR 0x408001
50 #define PSR_CMD_RECEIVED 0x2000000000000000U
51 #define PSR_CMD_COMPLETED 0x1000000000000000U
52 #define PSR_CUR_SPEED_MASK 0x0300000000000000U
53 #define PSR_CUR_SPEED_SHIFT (56)
58 #define CPUFREQ_HIGH 0
67 static struct freq_attr *maple_cpu_freqs_attr[] = {
75 static int maple_pmode_cur;
79 static const u32 *maple_pmode_data;
80 static int maple_pmode_max;
85 static int maple_scom_switch_freq(
int speed_mode)
98 maple_pmode_data[speed_mode]);
101 for (to = 0; to < 10; to++) {
116 maple_pmode_cur = speed_mode;
122 static int maple_scom_query_freq(
void)
124 unsigned long psr = scom970_read(
SCOM_PSR);
127 for (i = 0; i <= maple_pmode_max; i++)
144 unsigned int target_freq,
unsigned int relation)
146 unsigned int newstate = 0;
151 target_freq, relation, &newstate))
154 if (maple_pmode_cur == newstate)
159 freqs.old = maple_cpu_freqs[maple_pmode_cur].
frequency;
160 freqs.new = maple_cpu_freqs[newstate].
frequency;
164 rc = maple_scom_switch_freq(newstate);
172 static unsigned int maple_cpufreq_get_speed(
unsigned int cpu)
174 return maple_cpu_freqs[maple_pmode_cur].
frequency;
179 policy->
cpuinfo.transition_latency = 12000;
180 policy->
cur = maple_cpu_freqs[maple_scom_query_freq()].
frequency;
184 cpumask_copy(policy->
cpus, cpu_online_mask);
196 .init = maple_cpufreq_cpu_init,
197 .verify = maple_cpufreq_verify,
198 .target = maple_cpufreq_target,
199 .get = maple_cpufreq_get_speed,
200 .attr = maple_cpu_freqs_attr,
203 static int __init maple_cpufreq_init(
void)
208 unsigned long max_freq;
223 DBG(
"No /cpus node !\n");
231 if (reg ==
NULL || (*reg) != 0)
236 if (cpunode ==
NULL) {
244 if (pvr_hi != 0x3c && pvr_hi != 0x44) {
256 maple_pmode_data =
of_get_property(cpunode,
"power-mode-data", &psize);
257 if (!maple_pmode_data) {
258 DBG(
"No power-mode-data !\n");
261 maple_pmode_max = psize /
sizeof(
u32) - 1;
273 max_freq = (*valp)/1000;
275 maple_cpu_freqs[1].
frequency = max_freq/2;
282 maple_pmode_cur = -1;
283 maple_scom_switch_freq(maple_scom_query_freq());
289 maple_cpu_freqs[maple_pmode_cur].
frequency/1000);
293 of_node_put(cpunode);
299 of_node_put(cpunode);