34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/sched.h>
56 static unsigned int pxa27x_maxfreq;
59 "(typically 624=>pxa270, 416=>pxa271, 520=>pxa272)");
73 static unsigned int sdram_rows;
75 #define CCLKCFG_TURBO 0x1
76 #define CCLKCFG_FCS 0x2
77 #define CCLKCFG_HALFTURBO 0x4
78 #define CCLKCFG_FASTBUS 0x8
79 #define MDREFR_DB2_MASK (MDREFR_K2DB2 | MDREFR_K1DB2)
80 #define MDREFR_DRI_MASK 0xFFF
82 #define MDCNFG_DRAC2(mdcnfg) (((mdcnfg) >> 21) & 0x3)
83 #define MDCNFG_DRAC0(mdcnfg) (((mdcnfg) >> 5) & 0x3)
89 #define CCLKCFG CCLKCFG_TURBO | CCLKCFG_FCS
94 { 99500, 99500, 0x121, 1,
CCLKCFG, -1, -1},
95 {132700, 132700, 0x123, 1,
CCLKCFG, -1, -1},
96 {199100, 99500, 0x141, 0,
CCLKCFG, -1, -1},
97 {265400, 132700, 0x143, 1,
CCLKCFG, -1, -1},
98 {331800, 165900, 0x145, 1,
CCLKCFG, -1, -1},
99 {398100, 99500, 0x161, 0,
CCLKCFG, -1, -1},
106 { 99500, 99500, 0x121, 1,
CCLKCFG, -1, -1},
107 {199100, 99500, 0x221, 0,
CCLKCFG, -1, -1},
108 {298500, 99500, 0x321, 0,
CCLKCFG, -1, -1},
109 {298600, 99500, 0x1c1, 0,
CCLKCFG, -1, -1},
110 {398100, 99500, 0x241, 0,
CCLKCFG, -1, -1},
113 #define NUM_PXA25x_RUN_FREQS ARRAY_SIZE(pxa255_run_freqs)
114 #define NUM_PXA25x_TURBO_FREQS ARRAY_SIZE(pxa255_turbo_freqs)
121 static unsigned int pxa255_turbo_table;
123 MODULE_PARM_DESC(pxa255_turbo_table,
"Selects the frequency table (0 = run table, !0 = turbo table)");
151 #define PXA27x_CCCR(A, L, N2) (A << 25 | N2 << 7 | L)
152 #define CCLKCFG2(B, HT, T) \
154 ((B) ? CCLKCFG_FASTBUS : 0) | \
155 ((HT) ? CCLKCFG_HALFTURBO : 0) | \
156 ((T) ? CCLKCFG_TURBO : 0))
159 {104000, 104000,
PXA27x_CCCR(1, 8, 2), 0,
CCLKCFG2(1, 0, 1), 900000, 1705000 },
160 {156000, 104000,
PXA27x_CCCR(1, 8, 3), 0,
CCLKCFG2(1, 0, 1), 1000000, 1705000 },
161 {208000, 208000,
PXA27x_CCCR(0, 16, 2), 1,
CCLKCFG2(0, 0, 1), 1180000, 1705000 },
162 {312000, 208000,
PXA27x_CCCR(1, 16, 3), 1,
CCLKCFG2(1, 0, 1), 1250000, 1705000 },
163 {416000, 208000,
PXA27x_CCCR(1, 16, 4), 1,
CCLKCFG2(1, 0, 1), 1350000, 1705000 },
164 {520000, 208000,
PXA27x_CCCR(1, 16, 5), 1,
CCLKCFG2(1, 0, 1), 1450000, 1705000 },
165 {624000, 208000,
PXA27x_CCCR(1, 16, 6), 1,
CCLKCFG2(1, 0, 1), 1550000, 1705000 }
168 #define NUM_PXA27x_FREQS ARRAY_SIZE(pxa27x_freqs)
174 #ifdef CONFIG_REGULATOR
176 static int pxa_cpufreq_change_voltage(
pxa_freqs_t *pxa_freq)
184 vmin = pxa_freq->
vmin;
185 vmax = pxa_freq->
vmax;
186 if ((vmin == -1) || (vmax == -1))
191 pr_err(
"cpufreq: Failed to set vcc_core in [%dmV..%dmV]\n",
196 static __init void pxa_cpufreq_init_voltages(
void)
199 if (IS_ERR(vcc_core)) {
200 pr_info(
"cpufreq: Didn't find vcc_core regulator\n");
203 pr_info(
"cpufreq: Found vcc_core regulator\n");
207 static int pxa_cpufreq_change_voltage(
pxa_freqs_t *pxa_freq)
212 static __init void pxa_cpufreq_init_voltages(
void) { }
219 if (!pxa255_turbo_table) {
220 *pxa_freqs = pxa255_run_freqs;
221 *freq_table = pxa255_run_freq_table;
223 *pxa_freqs = pxa255_turbo_freqs;
224 *freq_table = pxa255_turbo_freq_table;
228 *pxa_freqs = pxa27x_freqs;
229 *freq_table = pxa27x_freq_table;
233 static void pxa27x_guess_max_freq(
void)
235 if (!pxa27x_maxfreq) {
236 pxa27x_maxfreq = 416000;
238 "(pxa27x_maxfreq), assuming pxa271 with %dkHz maxfreq\n",
241 pxa27x_maxfreq *= 1000;
245 static void init_sdram_rows(
void)
248 unsigned int drac2 = 0, drac0 = 0;
256 sdram_rows = 1 << (11 +
max(drac0, drac2));
259 static u32 mdrefr_dri(
unsigned int freq)
273 find_freq_tables(&pxa_freqs_table, &pxa_freqs);
277 pr_debug(
"Verified CPU policy: %dKhz min to %dKhz max\n",
278 policy->
min, policy->
max);
283 static unsigned int pxa_cpufreq_get(
unsigned int cpu)
289 unsigned int target_freq,
290 unsigned int relation)
297 unsigned int new_freq_cpu, new_freq_mem;
298 unsigned int unused, preset_mdrefr, postset_mdrefr, cclkcfg;
302 find_freq_tables(&pxa_freqs_table, &pxa_freq_settings);
306 target_freq, relation, &idx)) {
310 new_freq_cpu = pxa_freq_settings[
idx].
khz;
311 new_freq_mem = pxa_freq_settings[
idx].
membus;
312 freqs.old = policy->
cur;
313 freqs.new = new_freq_cpu;
314 freqs.cpu = policy->
cpu;
317 pr_debug(
"Changing CPU frequency to %d Mhz, (SDRAM %d Mhz)\n",
318 freqs.new / 1000, (pxa_freq_settings[idx].
div2) ?
319 (new_freq_mem / 2000) : (new_freq_mem / 1000));
321 if (vcc_core && freqs.new > freqs.old)
322 ret = pxa_cpufreq_change_voltage(&pxa_freq_settings[idx]);
338 preset_mdrefr = (preset_mdrefr & ~MDREFR_DRI_MASK);
339 preset_mdrefr |= mdrefr_dri(new_freq_mem);
342 (postset_mdrefr & ~MDREFR_DRI_MASK) | mdrefr_dri(new_freq_mem);
348 if (pxa_freq_settings[idx].
div2) {
362 ldr r4, [%1] /* load MDREFR */ \n\
366 str %3, [%1] /* preset the MDREFR */ \n\
367 mcr p14, 0, %2, c6, c0, 0 /* set CCLKCFG[FCS] */ \n\
368 str %4, [%1] /* postset the MDREFR */ \n\
375 :
"r" (
MDREFR),
"r" (cclkcfg),
376 "r" (preset_mdrefr),
"r" (postset_mdrefr)
396 if (vcc_core && freqs.new < freqs.old)
397 ret = pxa_cpufreq_change_voltage(&pxa_freq_settings[idx]);
411 pxa27x_guess_max_freq();
413 pxa_cpufreq_init_voltages();
418 policy->
cpuinfo.transition_latency = 1000;
424 pxa255_run_freq_table[
i].frequency = pxa255_run_freqs[
i].
khz;
425 pxa255_run_freq_table[
i].index =
i;
431 pxa255_turbo_freq_table[
i].frequency =
432 pxa255_turbo_freqs[
i].
khz;
433 pxa255_turbo_freq_table[
i].index =
i;
437 pxa255_turbo_table = !!pxa255_turbo_table;
441 freq = pxa27x_freqs[
i].
khz;
442 if (freq > pxa27x_maxfreq)
444 pxa27x_freq_table[
i].frequency =
freq;
445 pxa27x_freq_table[
i].index =
i;
447 pxa27x_freq_table[
i].index =
i;
455 find_freq_tables(&pxa255_freq_table, &pxa255_freqs);
456 pr_info(
"PXA255 cpufreq using %s frequency table\n",
457 pxa255_turbo_table ?
"turbo" :
"run");
469 .verify = pxa_verify_policy,
470 .target = pxa_set_target,
471 .init = pxa_cpufreq_init,
472 .get = pxa_cpufreq_get,
476 static int __init pxa_cpu_init(
void)
484 static void __exit pxa_cpu_exit(
void)