9 #include <linux/kernel.h>
10 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/timex.h>
23 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
28 #define EPS_BRAND_C7M 0
29 #define EPS_BRAND_C7 1
30 #define EPS_BRAND_EDEN 2
31 #define EPS_BRAND_C3 3
32 #define EPS_BRAND_C7D 4
36 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
45 static int freq_failsafe_off;
46 static int voltage_failsafe_off;
47 static int set_max_voltage;
49 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
50 static int ignore_acpi_limit;
55 static int eps_acpi_init(
void)
59 if (!eps_acpi_cpu_perf)
64 kfree(eps_acpi_cpu_perf);
65 eps_acpi_cpu_perf =
NULL;
71 kfree(eps_acpi_cpu_perf);
72 eps_acpi_cpu_perf =
NULL;
80 if (eps_acpi_cpu_perf) {
83 kfree(eps_acpi_cpu_perf);
84 eps_acpi_cpu_perf =
NULL;
90 static unsigned int eps_get(
unsigned int cpu)
97 centaur = eps_cpu[
cpu];
103 return centaur->
fsb * ((lo >> 8) & 0xff);
115 freqs.old = eps_get(cpu);
116 freqs.new = centaur->
fsb * ((dest_state >> 8) & 0xff);
123 while (lo & ((1 << 16) | (1 << 17))) {
144 }
while (lo & ((1 << 16) | (1 << 17)));
149 freqs.new = centaur->
fsb * ((lo >> 8) & 0xff);
153 u8 current_multiplier, current_voltage;
157 current_voltage = lo & 0xff;
159 current_voltage * 16 + 700);
160 current_multiplier = (lo >> 8) & 0xff;
170 unsigned int target_freq,
171 unsigned int relation)
174 unsigned int newstate = 0;
175 unsigned int cpu = policy->
cpu;
176 unsigned int dest_state;
181 centaur = eps_cpu[
cpu];
192 dest_state = centaur->
freq_table[newstate].index & 0xffff;
193 ret = eps_set_state(centaur, cpu, dest_state);
210 u8 current_multiplier, current_voltage;
211 u8 max_multiplier, max_voltage;
212 u8 min_multiplier, min_voltage;
218 int k,
step, voltage;
221 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
225 if (policy->
cpu != 0)
233 rdmsr(0x1153, lo, hi);
234 brand = (((lo >> 2) ^ lo) >> 18) & 3;
238 rdmsr(0x1154, lo, hi);
239 brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff;
269 if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) {
277 current_voltage = lo & 0xff;
279 current_voltage * 16 + 700);
280 current_multiplier = (lo >> 8) & 0xff;
281 printk(
KERN_INFO "eps: Current multiplier = %d\n", current_multiplier);
284 max_voltage = hi & 0xff;
286 max_voltage * 16 + 700);
287 max_multiplier = (hi >> 8) & 0xff;
289 min_voltage = (hi >> 16) & 0xff;
291 min_voltage * 16 + 700);
292 min_multiplier = (hi >> 24) & 0xff;
296 if (current_multiplier == 0 || max_multiplier == 0
297 || min_multiplier == 0)
299 if (current_multiplier > max_multiplier
300 || max_multiplier <= min_multiplier)
302 if (current_voltage > 0x1f || max_voltage > 0x1f)
304 if (max_voltage < min_voltage
305 || current_voltage < min_voltage
306 || current_voltage > max_voltage)
310 if (!freq_failsafe_off && max_multiplier != current_multiplier) {
312 "frequency then its maximum. Aborting.\n");
314 "to disable this check.\n");
317 if (!voltage_failsafe_off && max_voltage != current_voltage) {
319 "voltage then its maximum. Aborting.\n");
321 "option to disable this check.\n");
326 fsb =
cpu_khz / current_multiplier;
328 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
330 if (!ignore_acpi_limit && !eps_acpi_init()) {
334 (limit%1000000)/10000);
335 eps_acpi_exit(policy);
337 if (limit && max_multiplier * fsb > limit) {
351 v = (set_max_voltage - 700) / 16;
353 if (v >= min_voltage && v <= max_voltage) {
362 states = max_multiplier - min_multiplier + 1;
372 eps_cpu[0] = centaur;
376 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
377 centaur->bios_limit =
limit;
383 f_table[0].
frequency = fsb * min_multiplier;
384 f_table[0].
index = (min_multiplier << 8) | min_voltage;
385 f_table[1].
frequency = fsb * max_multiplier;
386 f_table[1].
index = (max_multiplier << 8) | max_voltage;
390 step = ((max_voltage - min_voltage) * 256)
391 / (max_multiplier - min_multiplier);
392 for (i = min_multiplier; i <= max_multiplier; i++) {
393 voltage = (k *
step) / 256 + min_voltage;
395 f_table[
k].
index = (i << 8) | voltage;
401 policy->
cpuinfo.transition_latency = 140000;
402 policy->
cur = fsb * current_multiplier;
416 unsigned int cpu = policy->
cpu;
431 .verify = eps_verify,
432 .target = eps_target,
433 .init = eps_cpu_init,
434 .exit = eps_cpu_exit,
436 .name =
"e_powersaver",
444 static const struct x86_cpu_id eps_cpu_id[] = {
450 static int __init eps_init(
void)
459 static void __exit eps_exit(
void)
467 MODULE_PARM_DESC(freq_failsafe_off,
"Disable current vs max frequency check");
469 MODULE_PARM_DESC(voltage_failsafe_off,
"Disable current vs max voltage check");
470 #if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
472 MODULE_PARM_DESC(ignore_acpi_limit,
"Don't check ACPI's processor speed limit");
475 MODULE_PARM_DESC(set_max_voltage,
"Set maximum CPU voltage (mV) C7-M only");