2 * elanfreq: cpufreq driver for the AMD ELAN family
4 * (c) Copyright 2002 Robert Schwebel <r.schwebel@pengutronix.de>
6 * Parts of this code are (c) Sven Geggus <sven@geggus.net>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * 2002-02-13: - initial revision for 2.4.18-pre9 by Robert Schwebel
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
23 #include <linux/delay.h>
24 #include <linux/cpufreq.h>
27 #include <linux/timex.h>
30 #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */
31 #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */
33 /* Module parameter */
36 struct s_elan_multiplier
{
37 int clock
; /* frequency in kHz */
38 int val40h
; /* PMU Force Mode register */
39 int val80h
; /* CPU Clock Speed Register */
43 * It is important that the frequencies
44 * are listed in ascending order here!
46 static struct s_elan_multiplier elan_multiplier
[] = {
57 static struct cpufreq_frequency_table elanfreq_table
[] = {
66 {0, CPUFREQ_TABLE_END
},
71 * elanfreq_get_cpu_frequency: determine current cpu speed
73 * Finds out at which frequency the CPU of the Elan SOC runs
74 * at the moment. Frequencies from 1 to 33 MHz are generated
75 * the normal way, 66 and 99 MHz are called "Hyperspeed Mode"
76 * and have the rest of the chip running with 33 MHz.
79 static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu
)
81 u8 clockspeed_reg
; /* Clock Speed Register */
84 outb_p(0x80, REG_CSCIR
);
85 clockspeed_reg
= inb_p(REG_CSCDR
);
88 if ((clockspeed_reg
& 0xE0) == 0xE0)
91 /* Are we in CPU clock multiplied mode (66/99 MHz)? */
92 if ((clockspeed_reg
& 0xE0) == 0xC0) {
93 if ((clockspeed_reg
& 0x01) == 0)
99 /* 33 MHz is not 32 MHz... */
100 if ((clockspeed_reg
& 0xE0) == 0xA0)
103 return (1<<((clockspeed_reg
& 0xE0) >> 5)) * 1000;
108 * elanfreq_set_cpu_frequency: Change the CPU core frequency
110 * @freq: frequency in kHz
112 * This function takes a frequency value and changes the CPU frequency
113 * according to this. Note that the frequency has to be checked by
114 * elanfreq_validatespeed() for correctness!
116 * There is no return value.
119 static void elanfreq_set_cpu_state(unsigned int state
)
121 struct cpufreq_freqs freqs
;
123 freqs
.old
= elanfreq_get_cpu_frequency(0);
124 freqs
.new = elan_multiplier
[state
].clock
;
125 freqs
.cpu
= 0; /* elanfreq.c is UP only driver */
127 cpufreq_notify_transition(&freqs
, CPUFREQ_PRECHANGE
);
129 printk(KERN_INFO
"elanfreq: attempting to set frequency to %i kHz\n",
130 elan_multiplier
[state
].clock
);
134 * Access to the Elan's internal registers is indexed via
135 * 0x22: Chip Setup & Control Register Index Register (CSCI)
136 * 0x23: Chip Setup & Control Register Data Register (CSCD)
141 * 0x40 is the Power Management Unit's Force Mode Register.
142 * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency)
146 outb_p(0x40, REG_CSCIR
); /* Disable hyperspeed mode */
147 outb_p(0x00, REG_CSCDR
);
148 local_irq_enable(); /* wait till internal pipelines and */
149 udelay(1000); /* buffers have cleaned up */
153 /* now, set the CPU clock speed register (0x80) */
154 outb_p(0x80, REG_CSCIR
);
155 outb_p(elan_multiplier
[state
].val80h
, REG_CSCDR
);
157 /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */
158 outb_p(0x40, REG_CSCIR
);
159 outb_p(elan_multiplier
[state
].val40h
, REG_CSCDR
);
163 cpufreq_notify_transition(&freqs
, CPUFREQ_POSTCHANGE
);
168 * elanfreq_validatespeed: test if frequency range is valid
169 * @policy: the policy to validate
171 * This function checks if a given frequency range in kHz is valid
172 * for the hardware supported by the driver.
175 static int elanfreq_verify(struct cpufreq_policy
*policy
)
177 return cpufreq_frequency_table_verify(policy
, &elanfreq_table
[0]);
180 static int elanfreq_target(struct cpufreq_policy
*policy
,
181 unsigned int target_freq
,
182 unsigned int relation
)
184 unsigned int newstate
= 0;
186 if (cpufreq_frequency_table_target(policy
, &elanfreq_table
[0],
187 target_freq
, relation
, &newstate
))
190 elanfreq_set_cpu_state(newstate
);
197 * Module init and exit code
200 static int elanfreq_cpu_init(struct cpufreq_policy
*policy
)
202 struct cpuinfo_x86
*c
= &cpu_data(0);
206 /* capability check */
207 if ((c
->x86_vendor
!= X86_VENDOR_AMD
) ||
208 (c
->x86
!= 4) || (c
->x86_model
!= 10))
213 max_freq
= elanfreq_get_cpu_frequency(0);
216 for (i
= 0; (elanfreq_table
[i
].frequency
!= CPUFREQ_TABLE_END
); i
++) {
217 if (elanfreq_table
[i
].frequency
> max_freq
)
218 elanfreq_table
[i
].frequency
= CPUFREQ_ENTRY_INVALID
;
221 /* cpuinfo and default policy values */
222 policy
->cpuinfo
.transition_latency
= CPUFREQ_ETERNAL
;
223 policy
->cur
= elanfreq_get_cpu_frequency(0);
225 result
= cpufreq_frequency_table_cpuinfo(policy
, elanfreq_table
);
229 cpufreq_frequency_table_get_attr(elanfreq_table
, policy
->cpu
);
234 static int elanfreq_cpu_exit(struct cpufreq_policy
*policy
)
236 cpufreq_frequency_table_put_attr(policy
->cpu
);
243 * elanfreq_setup - elanfreq command line parameter parsing
245 * elanfreq command line parameter. Use:
247 * to set the maximum CPU frequency to 66 MHz. Note that in
248 * case you do not give this boot parameter, the maximum
249 * frequency will fall back to _current_ CPU frequency which
250 * might be lower. If you build this as a module, use the
251 * max_freq module parameter instead.
253 static int __init
elanfreq_setup(char *str
)
255 max_freq
= simple_strtoul(str
, &str
, 0);
256 printk(KERN_WARNING
"You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n");
259 __setup("elanfreq=", elanfreq_setup
);
263 static struct freq_attr
*elanfreq_attr
[] = {
264 &cpufreq_freq_attr_scaling_available_freqs
,
269 static struct cpufreq_driver elanfreq_driver
= {
270 .get
= elanfreq_get_cpu_frequency
,
271 .verify
= elanfreq_verify
,
272 .target
= elanfreq_target
,
273 .init
= elanfreq_cpu_init
,
274 .exit
= elanfreq_cpu_exit
,
276 .owner
= THIS_MODULE
,
277 .attr
= elanfreq_attr
,
281 static int __init
elanfreq_init(void)
283 struct cpuinfo_x86
*c
= &cpu_data(0);
285 /* Test if we have the right hardware */
286 if ((c
->x86_vendor
!= X86_VENDOR_AMD
) ||
287 (c
->x86
!= 4) || (c
->x86_model
!= 10)) {
288 printk(KERN_INFO
"elanfreq: error: no Elan processor found!\n");
291 return cpufreq_register_driver(&elanfreq_driver
);
295 static void __exit
elanfreq_exit(void)
297 cpufreq_unregister_driver(&elanfreq_driver
);
301 module_param(max_freq
, int, 0444);
303 MODULE_LICENSE("GPL");
304 MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, "
305 "Sven Geggus <sven@geggus.net>");
306 MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs");
308 module_init(elanfreq_init
);
309 module_exit(elanfreq_exit
);