1 diff -Nurbw linux-2.6.17/arch/arm/Kconfig linux-2.6.17-patched/arch/arm/Kconfig
2 --- linux-2.6.17/arch/arm/Kconfig 2006-06-17 18:49:35.000000000 -0700
3 +++ linux-2.6.17-patched/arch/arm/Kconfig 2006-09-21 14:57:02.000000000 -0700
8 -if (ARCH_SA1100 || ARCH_INTEGRATOR || ARCH_OMAP1)
9 +if (ARCH_SA1100 || ARCH_INTEGRATOR || ARCH_OMAP1 || ARCH_PXA)
11 menu "CPU Frequency scaling"
19 + depends on CPU_FREQ && ARCH_PXA
21 + select CPU_FREQ_DEFAULT_GOV_USERSPACE
22 + select CPU_FREQ_TABLE
26 menu "Floating point emulation"
27 diff -Nurbw linux-2.6.17/arch/arm/mach-pxa/cpu-pxa.c linux-2.6.17-patched/arch/arm/mach-pxa/cpu-pxa.c
28 --- linux-2.6.17/arch/arm/mach-pxa/cpu-pxa.c 1969-12-31 16:00:00.000000000 -0800
29 +++ linux-2.6.17-patched/arch/arm/mach-pxa/cpu-pxa.c 2006-09-21 14:57:02.000000000 -0700
32 + * linux/arch/arm/mach-pxa/cpu-pxa.c
34 + * Copyright (C) 2002,2003 Intrinsyc Software
36 + * This program is free software; you can redistribute it and/or modify
37 + * it under the terms of the GNU General Public License as published by
38 + * the Free Software Foundation; either version 2 of the License, or
39 + * (at your option) any later version.
41 + * This program is distributed in the hope that it will be useful,
42 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 + * GNU General Public License for more details.
46 + * You should have received a copy of the GNU General Public License
47 + * along with this program; if not, write to the Free Software
48 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 + * 31-Jul-2002 : Initial version [FB]
52 + * 29-Jan-2003 : added PXA255 support [FB]
53 + * 20-Apr-2003 : ported to v2.5 (Dustin McIntire, Sensoria Corp.)
56 + * This driver may change the memory bus clock rate, but will not do any
57 + * platform specific access timing changes... for example if you have flash
58 + * memory connected to CS0, you will need to register a platform specific
59 + * notifier which will adjust the memory access strobes to maintain a
60 + * minimum strobe width.
64 +#include <linux/kernel.h>
65 +#include <linux/module.h>
66 +#include <linux/sched.h>
67 +#include <linux/init.h>
68 +#include <linux/cpufreq.h>
70 +#include <asm/hardware.h>
71 +#include <asm/arch/pxa-regs.h>
76 + static unsigned int freq_debug = DEBUG;
77 + module_param(freq_debug, int, 0);
78 + MODULE_PARM_DESC(freq_debug, "Set the debug messages to on=1/off=0");
80 + #define freq_debug 0
86 + unsigned int membus;
91 +/* Define the refresh period in mSec for the SDRAM and the number of rows */
92 +#define SDRAM_TREF 64 /* standard 64ms SDRAM */
93 +#define SDRAM_ROWS 2048 /* 64MB=8192 32MB=4096 */
94 +#define MDREFR_DRI(x) ((x*SDRAM_TREF)/(SDRAM_ROWS*32))
96 +#define CCLKCFG_TURBO 0x1
97 +#define CCLKCFG_FCS 0x2
98 +#define PXA25x_MIN_FREQ 99533
99 +#define PXA25x_MAX_FREQ 530842
100 +#define MDREFR_DB2_MASK (MDREFR_K2DB2 | MDREFR_K1DB2)
101 +#define MDREFR_DRI_MASK 0xFFF
104 +/* Use the run mode frequencies for the CPUFREQ_POLICY_PERFORMANCE policy */
105 +static pxa_freqs_t pxa255_run_freqs[] =
107 + /* CPU MEMBUS CCCR DIV2*/
108 + { 99533, 99533, 0x121, 1}, /* run= 99, turbo= 99, PXbus=50, SDRAM=50 */
109 + {132710, 132710, 0x123, 1}, /* run=133, turbo=133, PXbus=66, SDRAM=66 */
110 + {199066, 99533, 0x141, 0}, /* run=199, turbo=199, PXbus=99, SDRAM=99 */
111 + {265421, 132710, 0x143, 0}, /* run=265, turbo=265, PXbus=133, SDRAM=133 */
112 + {331776, 165888, 0x145, 1}, /* run=331, turbo=331, PXbus=166, SDRAM=83 */
113 + {398131, 99533, 0x161, 0}, /* run=398, turbo=398, PXbus=99, SDRAM=99 */
114 + {398131, 132710, 0x1c3, 0}, /* run=265, turbo=398, PXbus=133, SDRAM=133 */
115 + {530842, 132710, 0x163, 0}, /* run=531, turbo=531, PXbus=133, SDRAM=133 */
118 +#define NUM_RUN_FREQS (sizeof(pxa255_run_freqs)/sizeof(pxa_freqs_t))
120 +static struct cpufreq_frequency_table pxa255_run_freq_table[NUM_RUN_FREQS+1];
122 +/* Use the turbo mode frequencies for the CPUFREQ_POLICY_POWERSAVE policy */
123 +static pxa_freqs_t pxa255_turbo_freqs[] =
125 + /* CPU MEMBUS CCCR DIV2*/
126 + { 99533, 99533, 0x121, 1}, /* run=99, turbo= 99, PXbus=99, SDRAM=50 */
127 + {149299, 99533, 0x1a1, 0}, /* run=99, turbo=149, PXbus=99, SDRAM=99 */
128 + {199066, 99533, 0x221, 0}, /* run=99, turbo=199, PXbus=99, SDRAM=99 */
129 + {298598, 99533, 0x321, 0}, /* run=99, turbo=299, PXbus=99, SDRAM=99 */
130 + {398131, 99533, 0x241, 1}, /* run=199, turbo=398, PXbus=99, SDRAM=50 */
133 +#define NUM_TURBO_FREQS (sizeof(pxa255_turbo_freqs)/sizeof(pxa_freqs_t))
135 +static struct cpufreq_frequency_table pxa255_turbo_freq_table[NUM_TURBO_FREQS+1];
137 +extern unsigned get_clk_frequency_khz(int info);
139 +/* find a valid frequency point */
140 +static int pxa_verify_policy(struct cpufreq_policy *policy)
143 + struct cpufreq_frequency_table *pxa_freqs_table;
145 + if(policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
146 + pxa_freqs_table = pxa255_run_freq_table;
147 + } else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
148 + pxa_freqs_table = pxa255_turbo_freq_table;
150 + printk("CPU PXA: Unknown policy found. "
151 + "Using CPUFREQ_POLICY_PERFORMANCE\n");
152 + pxa_freqs_table = pxa255_run_freq_table;
154 + ret=cpufreq_frequency_table_verify(policy, pxa_freqs_table);
157 + printk("Verified CPU policy: %dKhz min to %dKhz max\n",
158 + policy->min, policy->max);
164 +static int pxa_set_target(struct cpufreq_policy *policy,
165 + unsigned int target_freq,
166 + unsigned int relation)
169 + cpumask_t cpus_allowed;
170 + int cpu = policy->cpu;
171 + struct cpufreq_freqs freqs;
172 + pxa_freqs_t *pxa_freq_settings;
173 + struct cpufreq_frequency_table *pxa_freqs_table;
174 + unsigned long flags;
175 + unsigned int unused;
176 + unsigned int preset_mdrefr, postset_mdrefr;
180 + * Save this threads cpus_allowed mask.
182 + cpus_allowed = current->cpus_allowed;
185 + * Bind to the specified CPU. When this call returns,
186 + * we should be running on the right CPU.
188 + set_cpus_allowed(current, cpumask_of_cpu(cpu));
189 + BUG_ON(cpu != smp_processor_id());
191 + /* Get the current policy */
192 + if(policy->policy == CPUFREQ_POLICY_PERFORMANCE) {
193 + pxa_freq_settings = pxa255_run_freqs;
194 + pxa_freqs_table = pxa255_run_freq_table;
195 + }else if (policy->policy == CPUFREQ_POLICY_POWERSAVE) {
196 + pxa_freq_settings = pxa255_turbo_freqs;
197 + pxa_freqs_table = pxa255_turbo_freq_table;
199 + printk("CPU PXA: Unknown policy found. "
200 + "Using CPUFREQ_POLICY_PERFORMANCE\n");
201 + pxa_freq_settings = pxa255_run_freqs;
202 + pxa_freqs_table = pxa255_run_freq_table;
205 + /* Lookup the next frequency */
206 + if (cpufreq_frequency_table_target(policy, pxa_freqs_table,
207 + target_freq, relation, &idx)) {
211 + freqs.old = policy->cur;
212 + freqs.new = pxa_freq_settings[idx].khz;
213 + freqs.cpu = policy->cpu;
215 + printk(KERN_INFO "Changing CPU frequency to %d Mhz, (SDRAM %d Mhz)\n",
216 + freqs.new/1000, (pxa_freq_settings[idx].div2) ?
217 + (pxa_freq_settings[idx].membus/2000) :
218 + (pxa_freq_settings[idx].membus/1000));
221 + ramstart = phys_to_virt(0xa0000000);
224 + * Tell everyone what we're about to do...
225 + * you should add a notify client with any platform specific
226 + * Vcc changing capability
228 + cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
230 + /* Calculate the next MDREFR. If we're slowing down the SDRAM clock
231 + * we need to preset the smaller DRI before the change. If we're speeding
232 + * up we need to set the larger DRI value after the change.
234 + preset_mdrefr = postset_mdrefr = MDREFR;
235 + if((MDREFR & MDREFR_DRI_MASK) > MDREFR_DRI(pxa_freq_settings[idx].membus)) {
236 + preset_mdrefr = (preset_mdrefr & ~MDREFR_DRI_MASK) |
237 + MDREFR_DRI(pxa_freq_settings[idx].membus);
239 + postset_mdrefr = (postset_mdrefr & ~MDREFR_DRI_MASK) |
240 + MDREFR_DRI(pxa_freq_settings[idx].membus);
242 + /* If we're dividing the memory clock by two for the SDRAM clock, this
243 + * must be set prior to the change. Clearing the divide must be done
244 + * after the change.
246 + if(pxa_freq_settings[idx].div2) {
247 + preset_mdrefr |= MDREFR_DB2_MASK;
248 + postset_mdrefr |= MDREFR_DB2_MASK;
250 + postset_mdrefr &= ~MDREFR_DB2_MASK;
253 + local_irq_save(flags);
255 + /* Set new the CCCR */
256 + CCCR = pxa_freq_settings[idx].cccr;
258 + __asm__ __volatile__(" \
259 + ldr r4, [%1] ; /* load MDREFR */ \
263 + str %4, [%1] ; /* preset the MDREFR */ \
264 + mcr p14, 0, %2, c6, c0, 0 ; /* set CCLKCFG[FCS] */ \
265 + str %5, [%1] ; /* postset the MDREFR */ \
272 + : "r" (&MDREFR), "r" (CCLKCFG_TURBO|CCLKCFG_FCS), "r" (ramstart), \
273 + "r" (preset_mdrefr), "r" (postset_mdrefr)
275 + local_irq_restore(flags);
278 + * Restore the CPUs allowed mask.
280 + set_cpus_allowed(current, cpus_allowed);
283 + * Tell everyone what we've just done...
284 + * you should add a notify client with any platform specific
285 + * SDRAM refresh timer adjustments
287 + cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
292 +static int pxa_cpufreq_init(struct cpufreq_policy *policy)
294 + cpumask_t cpus_allowed;
295 + unsigned int cpu = policy->cpu;
298 + cpus_allowed = current->cpus_allowed;
300 + set_cpus_allowed(current, cpumask_of_cpu(cpu));
301 + BUG_ON(cpu != smp_processor_id());
303 + /* set default policy and cpuinfo */
304 + policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
305 + policy->policy = CPUFREQ_POLICY_PERFORMANCE;
306 + policy->cpuinfo.max_freq = PXA25x_MAX_FREQ;
307 + policy->cpuinfo.min_freq = PXA25x_MIN_FREQ;
308 + policy->cpuinfo.transition_latency = 1000; /* FIXME: 1 ms, assumed */
309 + policy->cur = get_clk_frequency_khz(0); /* current freq */
310 + policy->min = policy->max = policy->cur;
312 + /* Generate the run cpufreq_frequency_table struct */
313 + for(i=0;i<NUM_RUN_FREQS;i++) {
314 + pxa255_run_freq_table[i].frequency = pxa255_run_freqs[i].khz;
315 + pxa255_run_freq_table[i].index = i;
317 + pxa255_run_freq_table[i].frequency = CPUFREQ_TABLE_END;
318 + /* Generate the turbo cpufreq_frequency_table struct */
319 + for(i=0;i<NUM_TURBO_FREQS;i++) {
320 + pxa255_turbo_freq_table[i].frequency = pxa255_turbo_freqs[i].khz;
321 + pxa255_turbo_freq_table[i].index = i;
323 + pxa255_turbo_freq_table[i].frequency = CPUFREQ_TABLE_END;
325 + set_cpus_allowed(current, cpus_allowed);
326 + printk(KERN_INFO "PXA CPU frequency change support initialized\n");
331 +static struct cpufreq_driver pxa_cpufreq_driver = {
332 + .verify = pxa_verify_policy,
333 + .target = pxa_set_target,
334 + .init = pxa_cpufreq_init,
338 +static int __init pxa_cpu_init(void)
340 + return cpufreq_register_driver(&pxa_cpufreq_driver);
343 +static void __exit pxa_cpu_exit(void)
345 + cpufreq_unregister_driver(&pxa_cpufreq_driver);
349 +MODULE_AUTHOR ("Intrinsyc Software Inc.");
350 +MODULE_DESCRIPTION ("CPU frequency changing driver for the PXA architecture");
351 +MODULE_LICENSE("GPL");
352 +module_init(pxa_cpu_init);
353 +module_exit(pxa_cpu_exit);
355 diff -Nurbw linux-2.6.17/arch/arm/mach-pxa/Makefile linux-2.6.17-patched/arch/arm/mach-pxa/Makefile
356 --- linux-2.6.17/arch/arm/mach-pxa/Makefile 2006-09-21 15:11:33.000000000 -0700
357 +++ linux-2.6.17-patched/arch/arm/mach-pxa/Makefile 2006-09-21 14:57:02.000000000 -0700
359 obj-$(CONFIG_PM) += pm.o sleep.o
360 obj-$(CONFIG_PXA_SSP) += ssp.o
361 +obj-$(CONFIG_CPU_FREQ) += cpu-pxa.o
363 ifeq ($(CONFIG_PXA27x),y)
364 obj-$(CONFIG_PM) += standby.o
365 diff -Nurbw linux-2.6.17/Documentation/cpu-freq/user-guide.txt linux-2.6.17-patched/Documentation/cpu-freq/user-guide.txt
366 --- linux-2.6.17/Documentation/cpu-freq/user-guide.txt 2006-06-17 18:49:35.000000000 -0700
367 +++ linux-2.6.17-patched/Documentation/cpu-freq/user-guide.txt 2006-09-21 14:57:02.000000000 -0700
371 1. Supported Architectures and Processors
378 1. Supported Architectures and Processors
379 =========================================
386 The following ARM processors are supported by cpufreq:
395 diff -Nurbw linux-2.6.17/drivers/cpufreq/Kconfig linux-2.6.17-patched/drivers/cpufreq/Kconfig
396 --- linux-2.6.17/drivers/cpufreq/Kconfig 2006-06-17 18:49:35.000000000 -0700
397 +++ linux-2.6.17-patched/drivers/cpufreq/Kconfig 2006-09-21 15:06:12.000000000 -0700
399 This will show detail CPU frequency translation table in sysfs file
402 -# Note that it is not currently possible to set the other governors (such as ondemand)
403 -# as the default, since if they fail to initialise, cpufreq will be
404 -# left in an undefined state.
407 prompt "Default CPUFreq governor"
408 - default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110
409 + default CPU_FREQ_DEFAULT_GOV_USERSPACE if CPU_FREQ_SA1100 || CPU_FREQ_SA1110 || CPU_FREQ_PXA
410 default CPU_FREQ_DEFAULT_GOV_PERFORMANCE
412 This option sets which CPUFreq governor shall be loaded at
414 the frequency statically to the highest frequency supported by
417 +config CPU_FREQ_DEFAULT_GOV_POWERSAVE
419 + select CPU_FREQ_GOV_POWERSAVE
421 + Use the CPUFreq governor 'powersave' as default. This sets
422 + the frequency statically to the lowest frequency supported by
425 config CPU_FREQ_DEFAULT_GOV_USERSPACE
427 select CPU_FREQ_GOV_USERSPACE
429 program shall be able to set the CPU dynamically without having
430 to enable the userspace governor manually.
432 +config CPU_FREQ_DEFAULT_GOV_ONDEMAND
434 + select CPU_FREQ_GOV_ONDEMAND
436 + Use the CPUFreq governor 'ondemand' as default. This sets
437 + the frequency dynamically based on CPU load, throttling up
438 + and down as necessary.
440 +config CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
441 + bool "conservative"
442 + select CPU_FREQ_GOV_CONSERVATIVE
444 + Use the CPUFreq governor 'conservative' as default. This sets
445 + the frequency dynamically based on CPU load, throttling up
446 + and down as necessary. The frequency is gracefully increased
447 + and decreased rather than jumping to 100% when speed is required.
451 config CPU_FREQ_GOV_PERFORMANCE
452 diff -Nurbw linux-2.6.17/include/linux/cpufreq.h linux-2.6.17-patched/include/linux/cpufreq.h
453 --- linux-2.6.17/include/linux/cpufreq.h 2006-06-17 18:49:35.000000000 -0700
454 +++ linux-2.6.17-patched/include/linux/cpufreq.h 2006-09-21 15:08:35.000000000 -0700
456 #ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE
457 extern struct cpufreq_governor cpufreq_gov_performance;
458 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_performance
459 +#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE)
460 +extern struct cpufreq_governor cpufreq_gov_powersave;
461 +#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_powersave
462 #elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE)
463 extern struct cpufreq_governor cpufreq_gov_userspace;
464 #define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_userspace
465 +#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND)
466 +extern struct cpufreq_governor cpufreq_gov_ondemand;
467 +#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_ondemand;
468 +#elif defined(CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE)
469 +extern struct cpufreq_governor cpufreq_gov_conservative;
470 +#define CPUFREQ_DEFAULT_GOVERNOR &cpufreq_gov_conservative;
474 diff -Nubrw --exclude='.*.o.cmd' linux-2.6.17/drivers/cpufreq/cpufreq_conservative.c linux-2.6.17-patched/drivers/cpufreq/cpufreq_conservative.c
475 --- linux-2.6.17/drivers/cpufreq/cpufreq_conservative.c 2006-09-21 15:26:46.000000000 -0700
476 +++ linux-2.6.17-patched/drivers/cpufreq/cpufreq_conservative.c 2006-06-17 18:49:35.000000000 -0700
481 -static struct cpufreq_governor cpufreq_gov_dbs = {
482 +struct cpufreq_governor cpufreq_gov_conservative = {
483 .name = "conservative",
484 .governor = cpufreq_governor_dbs,
485 .owner = THIS_MODULE,
488 static int __init cpufreq_gov_dbs_init(void)
490 - return cpufreq_register_governor(&cpufreq_gov_dbs);
491 + return cpufreq_register_governor(&cpufreq_gov_conservative);
494 static void __exit cpufreq_gov_dbs_exit(void)
496 /* Make sure that the scheduled work is indeed not running */
497 flush_scheduled_work();
499 - cpufreq_unregister_governor(&cpufreq_gov_dbs);
500 + cpufreq_unregister_governor(&cpufreq_gov_conservative);
504 diff -Nubrw --exclude='.*.o.cmd' linux-2.6.17/drivers/cpufreq/cpufreq_ondemand.c linux-2.6.17-patched/drivers/cpufreq/cpufreq_ondemand.c
505 --- linux-2.6.17/drivers/cpufreq/cpufreq_ondemand.c 2006-06-17 18:49:35.000000000 -0700
506 +++ linux-2.6.17-patched/drivers/cpufreq/cpufreq_ondemand.c 2006-09-27 14:00:15.000000000 -0700
511 -static struct cpufreq_governor cpufreq_gov_dbs = {
512 +struct cpufreq_governor cpufreq_gov_ondemand = {
514 .governor = cpufreq_governor_dbs,
515 .owner = THIS_MODULE,
518 static int __init cpufreq_gov_dbs_init(void)
520 - return cpufreq_register_governor(&cpufreq_gov_dbs);
521 + return cpufreq_register_governor(&cpufreq_gov_ondemand);
524 static void __exit cpufreq_gov_dbs_exit(void)
526 destroy_workqueue(dbs_workq);
529 - cpufreq_unregister_governor(&cpufreq_gov_dbs);
530 + cpufreq_unregister_governor(&cpufreq_gov_ondemand);