2 * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium
3 * M (part of the Centrino chipset).
5 * Despite the "SpeedStep" in the name, this is almost entirely unlike
6 * traditional SpeedStep.
8 * Modelled on speedstep.c
10 * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org>
12 * WARNING WARNING WARNING
14 * This driver manipulates the PERF_CTL MSR, which is only somewhat
15 * documented. While it seems to work on my laptop, it has not been
16 * tested anywhere else, and it may not work for you, do strange
17 * things or simply crash.
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/cpufreq.h>
26 #include <asm/processor.h>
27 #include <asm/cpufeature.h>
29 #define PFX "speedstep-centrino: "
30 #define MAINTAINER "Jeremy Fitzhardinge <jeremy@goop.org>"
32 /*#define CENTRINO_DEBUG*/
35 #define dprintk(msg...) printk(msg)
37 #define dprintk(msg...) do { } while(0)
42 const char *model_name
;
43 unsigned max_freq
; /* max clock in kHz */
45 struct cpufreq_frequency_table
*op_points
; /* clock/voltage pairs */
48 /* Operating points for current CPU */
49 static const struct cpu_model
*centrino_model
;
51 /* Computes the correct form for IA32_PERF_CTL MSR for a particular
52 frequency/voltage operating point; frequency in MHz, volts in mV.
53 This is stored as "index" in the structure. */
56 .frequency = (mhz) * 1000, \
57 .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \
61 * These voltage tables were derived from the Intel Pentium M
62 * datasheet, document 25261202.pdf, Table 5. I have verified they
63 * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium
67 /* Ultra Low Voltage Intel Pentium M processor 900MHz */
68 static struct cpufreq_frequency_table op_900
[] =
73 { .frequency
= CPUFREQ_TABLE_END
}
76 /* Low Voltage Intel Pentium M processor 1.10GHz */
77 static struct cpufreq_frequency_table op_1100
[] =
84 { .frequency
= CPUFREQ_TABLE_END
}
88 /* Low Voltage Intel Pentium M processor 1.20GHz */
89 static struct cpufreq_frequency_table op_1200
[] =
97 { .frequency
= CPUFREQ_TABLE_END
}
100 /* Intel Pentium M processor 1.30GHz */
101 static struct cpufreq_frequency_table op_1300
[] =
108 { .frequency
= CPUFREQ_TABLE_END
}
111 /* Intel Pentium M processor 1.40GHz */
112 static struct cpufreq_frequency_table op_1400
[] =
119 { .frequency
= CPUFREQ_TABLE_END
}
122 /* Intel Pentium M processor 1.50GHz */
123 static struct cpufreq_frequency_table op_1500
[] =
131 { .frequency
= CPUFREQ_TABLE_END
}
134 /* Intel Pentium M processor 1.60GHz */
135 static struct cpufreq_frequency_table op_1600
[] =
143 { .frequency
= CPUFREQ_TABLE_END
}
146 /* Intel Pentium M processor 1.70GHz */
147 static struct cpufreq_frequency_table op_1700
[] =
155 { .frequency
= CPUFREQ_TABLE_END
}
160 { "Intel(R) Pentium(R) M processor " #max "MHz", (max)*1000, op_##max }
162 /* CPU models, their operating frequency range, and freq/voltage
164 static const struct cpu_model models
[] =
178 /* Extract clock in kHz from PERF_CTL value */
179 static unsigned extract_clock(unsigned msr
)
181 msr
= (msr
>> 8) & 0xff;
185 /* Return the current CPU frequency in kHz */
186 static unsigned get_cur_freq(void)
190 rdmsr(MSR_IA32_PERF_STATUS
, l
, h
);
191 return extract_clock(l
);
194 static int centrino_cpu_init(struct cpufreq_policy
*policy
)
198 if (policy
->cpu
!= 0 || centrino_model
== NULL
)
201 freq
= get_cur_freq();
203 policy
->policy
= (freq
== centrino_model
->max_freq
) ?
204 CPUFREQ_POLICY_PERFORMANCE
:
205 CPUFREQ_POLICY_POWERSAVE
;
206 policy
->cpuinfo
.transition_latency
= 10; /* 10uS transition latency */
209 dprintk(KERN_INFO PFX
"centrino_cpu_init: policy=%d cur=%dkHz\n",
210 policy
->policy
, policy
->cur
);
212 return cpufreq_frequency_table_cpuinfo(policy
, centrino_model
->op_points
);
216 * centrino_verify - verifies a new CPUFreq policy
219 * Limit must be within this model's frequency range at least one
222 static int centrino_verify (struct cpufreq_policy
*policy
)
224 return cpufreq_frequency_table_verify(policy
, centrino_model
->op_points
);
228 * centrino_setpolicy - set a new CPUFreq policy
229 * @policy: new policy
231 * Sets a new CPUFreq policy.
233 static int centrino_target (struct cpufreq_policy
*policy
,
234 unsigned int target_freq
,
235 unsigned int relation
)
237 unsigned int newstate
= 0;
238 unsigned int msr
, oldmsr
, h
;
239 struct cpufreq_freqs freqs
;
241 if (centrino_model
== NULL
)
244 if (cpufreq_frequency_table_target(policy
, centrino_model
->op_points
, target_freq
,
245 relation
, &newstate
))
248 msr
= centrino_model
->op_points
[newstate
].index
;
249 rdmsr(MSR_IA32_PERF_CTL
, oldmsr
, h
);
251 if (msr
== (oldmsr
& 0xffff))
254 /* Hm, old frequency can either be the last value we put in
255 PERF_CTL, or whatever it is now. The trouble is that TM2
256 can change it behind our back, which means we never get to
257 see the speed change. Reading back the current speed would
258 tell us something happened, but it may leave the things on
259 the notifier chain confused; we therefore stick to using
260 the last programmed speed rather than the current speed for
263 TODO: work out how the TCC interrupts work, and try to
264 catch the CPU changing things under us.
267 freqs
.old
= extract_clock(oldmsr
);
268 freqs
.new = extract_clock(msr
);
270 dprintk(KERN_INFO PFX
"target=%dkHz old=%d new=%d msr=%04x\n",
271 target_freq
, freqs
.old
, freqs
.new, msr
);
273 cpufreq_notify_transition(&freqs
, CPUFREQ_PRECHANGE
);
275 /* all but 16 LSB are "reserved", so treat them with
281 wrmsr(MSR_IA32_PERF_CTL
, oldmsr
, h
);
283 cpufreq_notify_transition(&freqs
, CPUFREQ_POSTCHANGE
);
288 static struct cpufreq_driver centrino_driver
= {
289 .name
= "centrino", /* should be speedstep-centrino,
290 but there's a 16 char limit */
291 .init
= centrino_cpu_init
,
292 .verify
= centrino_verify
,
293 .target
= centrino_target
,
294 .owner
= THIS_MODULE
,
299 * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver
301 * Initializes the Enhanced SpeedStep support. Returns -ENODEV on
302 * unsupported devices, -ENOENT if there's no voltage table for this
303 * particular CPU model, -EINVAL on problems during initiatization,
304 * and zero on success.
306 * This is quite picky. Not only does the CPU have to advertise the
307 * "est" flag in the cpuid capability flags, we look for a specific
308 * CPU model and stepping, and we need to have the exact model name in
309 * our voltage tables. That is, be paranoid about not releasing
310 * someone's valuable magic smoke.
312 static int __init
centrino_init(void)
314 struct cpuinfo_x86
*cpu
= cpu_data
;
315 const struct cpu_model
*model
;
318 if (!cpu_has(cpu
, X86_FEATURE_EST
))
321 /* Only Intel Pentium M stepping 5 for now - add new CPUs as
322 they appear after making sure they use PERF_CTL in the same
324 if (cpu
->x86_vendor
!= X86_VENDOR_INTEL
||
326 cpu
->x86_model
!= 9 ||
327 cpu
->x86_mask
!= 5) {
328 printk(KERN_INFO PFX
"found unsupported CPU with Enhanced SpeedStep: "
329 "send /proc/cpuinfo to " MAINTAINER
"\n");
333 /* Check to see if Enhanced SpeedStep is enabled, and try to
335 rdmsr(MSR_IA32_MISC_ENABLE
, l
, h
);
337 if (!(l
& (1<<16))) {
339 wrmsr(MSR_IA32_MISC_ENABLE
, l
, h
);
341 /* check to see if it stuck */
342 rdmsr(MSR_IA32_MISC_ENABLE
, l
, h
);
343 if (!(l
& (1<<16))) {
344 printk(KERN_INFO PFX
"couldn't enable Enhanced SpeedStep\n");
349 for(model
= models
; model
->model_name
!= NULL
; model
++)
350 if (strcmp(cpu
->x86_model_id
, model
->model_name
) == 0)
352 if (model
->model_name
== NULL
) {
353 printk(KERN_INFO PFX
"no support for CPU model \"%s\": "
354 "send /proc/cpuinfo to " MAINTAINER
"\n",
359 centrino_model
= model
;
361 printk(KERN_INFO PFX
"found \"%s\": max frequency: %dkHz\n",
362 model
->model_name
, model
->max_freq
);
364 return cpufreq_register_driver(¢rino_driver
);
367 static void __exit
centrino_exit(void)
369 cpufreq_unregister_driver(¢rino_driver
);
372 MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>");
373 MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors.");
374 MODULE_LICENSE ("GPL");
376 module_init(centrino_init
);
377 module_exit(centrino_exit
);