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>
26 #include <asm/cpu_device_id.h>
28 #include <linux/timex.h>
31 #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */
32 #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */
34 /* Module parameter */
37 struct s_elan_multiplier
{
38 int clock
; /* frequency in kHz */
39 int val40h
; /* PMU Force Mode register */
40 int val80h
; /* CPU Clock Speed Register */
44 * It is important that the frequencies
45 * are listed in ascending order here!
47 static struct s_elan_multiplier elan_multiplier
[] = {
58 static struct cpufreq_frequency_table elanfreq_table
[] = {
67 {0, CPUFREQ_TABLE_END
},
72 * elanfreq_get_cpu_frequency: determine current cpu speed
74 * Finds out at which frequency the CPU of the Elan SOC runs
75 * at the moment. Frequencies from 1 to 33 MHz are generated
76 * the normal way, 66 and 99 MHz are called "Hyperspeed Mode"
77 * and have the rest of the chip running with 33 MHz.
80 static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu
)
82 u8 clockspeed_reg
; /* Clock Speed Register */
85 outb_p(0x80, REG_CSCIR
);
86 clockspeed_reg
= inb_p(REG_CSCDR
);
89 if ((clockspeed_reg
& 0xE0) == 0xE0)
92 /* Are we in CPU clock multiplied mode (66/99 MHz)? */
93 if ((clockspeed_reg
& 0xE0) == 0xC0) {
94 if ((clockspeed_reg
& 0x01) == 0)
100 /* 33 MHz is not 32 MHz... */
101 if ((clockspeed_reg
& 0xE0) == 0xA0)
104 return (1<<((clockspeed_reg
& 0xE0) >> 5)) * 1000;
109 * elanfreq_set_cpu_frequency: Change the CPU core frequency
111 * @freq: frequency in kHz
113 * This function takes a frequency value and changes the CPU frequency
114 * according to this. Note that the frequency has to be checked by
115 * elanfreq_validatespeed() for correctness!
117 * There is no return value.
120 static void elanfreq_set_cpu_state(struct cpufreq_policy
*policy
,
123 struct cpufreq_freqs freqs
;
125 freqs
.old
= elanfreq_get_cpu_frequency(0);
126 freqs
.new = elan_multiplier
[state
].clock
;
128 cpufreq_notify_transition(policy
, &freqs
, CPUFREQ_PRECHANGE
);
130 printk(KERN_INFO
"elanfreq: attempting to set frequency to %i kHz\n",
131 elan_multiplier
[state
].clock
);
135 * Access to the Elan's internal registers is indexed via
136 * 0x22: Chip Setup & Control Register Index Register (CSCI)
137 * 0x23: Chip Setup & Control Register Data Register (CSCD)
142 * 0x40 is the Power Management Unit's Force Mode Register.
143 * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency)
147 outb_p(0x40, REG_CSCIR
); /* Disable hyperspeed mode */
148 outb_p(0x00, REG_CSCDR
);
149 local_irq_enable(); /* wait till internal pipelines and */
150 udelay(1000); /* buffers have cleaned up */
154 /* now, set the CPU clock speed register (0x80) */
155 outb_p(0x80, REG_CSCIR
);
156 outb_p(elan_multiplier
[state
].val80h
, REG_CSCDR
);
158 /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */
159 outb_p(0x40, REG_CSCIR
);
160 outb_p(elan_multiplier
[state
].val40h
, REG_CSCDR
);
164 cpufreq_notify_transition(policy
, &freqs
, CPUFREQ_POSTCHANGE
);
168 static int elanfreq_target(struct cpufreq_policy
*policy
,
169 unsigned int target_freq
,
170 unsigned int relation
)
172 unsigned int newstate
= 0;
174 if (cpufreq_frequency_table_target(policy
, &elanfreq_table
[0],
175 target_freq
, relation
, &newstate
))
178 elanfreq_set_cpu_state(policy
, newstate
);
185 * Module init and exit code
188 static int elanfreq_cpu_init(struct cpufreq_policy
*policy
)
190 struct cpuinfo_x86
*c
= &cpu_data(0);
193 /* capability check */
194 if ((c
->x86_vendor
!= X86_VENDOR_AMD
) ||
195 (c
->x86
!= 4) || (c
->x86_model
!= 10))
200 max_freq
= elanfreq_get_cpu_frequency(0);
203 for (i
= 0; (elanfreq_table
[i
].frequency
!= CPUFREQ_TABLE_END
); i
++) {
204 if (elanfreq_table
[i
].frequency
> max_freq
)
205 elanfreq_table
[i
].frequency
= CPUFREQ_ENTRY_INVALID
;
208 /* cpuinfo and default policy values */
209 policy
->cpuinfo
.transition_latency
= CPUFREQ_ETERNAL
;
211 return cpufreq_table_validate_and_show(policy
, elanfreq_table
);
217 * elanfreq_setup - elanfreq command line parameter parsing
219 * elanfreq command line parameter. Use:
221 * to set the maximum CPU frequency to 66 MHz. Note that in
222 * case you do not give this boot parameter, the maximum
223 * frequency will fall back to _current_ CPU frequency which
224 * might be lower. If you build this as a module, use the
225 * max_freq module parameter instead.
227 static int __init
elanfreq_setup(char *str
)
229 max_freq
= simple_strtoul(str
, &str
, 0);
230 printk(KERN_WARNING
"You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n");
233 __setup("elanfreq=", elanfreq_setup
);
237 static struct cpufreq_driver elanfreq_driver
= {
238 .get
= elanfreq_get_cpu_frequency
,
239 .verify
= cpufreq_generic_frequency_table_verify
,
240 .target
= elanfreq_target
,
241 .init
= elanfreq_cpu_init
,
242 .exit
= cpufreq_generic_exit
,
244 .attr
= cpufreq_generic_attr
,
247 static const struct x86_cpu_id elan_id
[] = {
248 { X86_VENDOR_AMD
, 4, 10, },
251 MODULE_DEVICE_TABLE(x86cpu
, elan_id
);
253 static int __init
elanfreq_init(void)
255 if (!x86_match_cpu(elan_id
))
257 return cpufreq_register_driver(&elanfreq_driver
);
261 static void __exit
elanfreq_exit(void)
263 cpufreq_unregister_driver(&elanfreq_driver
);
267 module_param(max_freq
, int, 0444);
269 MODULE_LICENSE("GPL");
270 MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, "
271 "Sven Geggus <sven@geggus.net>");
272 MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs");
274 module_init(elanfreq_init
);
275 module_exit(elanfreq_exit
);