2 * (C) 2001-2004 Dave Jones. <davej@redhat.com>
3 * (C) 2002 Padraig Brady. <padraig@antefacto.com>
5 * Licensed under the terms of the GNU GPL License version 2.
6 * Based upon datasheets & sample CPUs kindly provided by VIA.
8 * VIA have currently 3 different versions of Longhaul.
9 * Version 1 (Longhaul) uses the BCR2 MSR at 0x1147.
10 * It is present only in Samuel 1 (C5A), Samuel 2 (C5B) stepping 0.
11 * Version 2 of longhaul is backward compatible with v1, but adds
12 * LONGHAUL MSR for purpose of both frequency and voltage scaling.
13 * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C).
14 * Version 3 of longhaul got renamed to Powersaver and redesigned
15 * to use only the POWERSAVER MSR at 0x110a.
16 * It is present in Ezra-T (C5M), Nehemiah (C5X) and above.
17 * It's pretty much the same feature wise to longhaul v2, though
18 * there is provision for scaling FSB too, but this doesn't work
19 * too well in practice so we don't even try to use this.
21 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/init.h>
28 #include <linux/cpufreq.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32 #include <linux/delay.h>
33 #include <linux/timex.h>
35 #include <linux/acpi.h>
38 #include <asm/cpu_device_id.h>
39 #include <acpi/processor.h>
43 #define PFX "longhaul: "
45 #define TYPE_LONGHAUL_V1 1
46 #define TYPE_LONGHAUL_V2 2
47 #define TYPE_POWERSAVER 3
53 #define CPU_NEHEMIAH 5
54 #define CPU_NEHEMIAH_C 6
57 #define USE_ACPI_C3 (1 << 1)
58 #define USE_NORTHBRIDGE (1 << 2)
61 static unsigned int numscales = 16;
62 static unsigned int fsb;
64 static const struct mV_pos *vrm_mV_table;
65 static const unsigned char *mV_vrm_table;
67 static unsigned int highest_speed, lowest_speed; /* kHz */
68 static unsigned int minmult, maxmult;
69 static int can_scale_voltage;
70 static struct acpi_processor *pr;
71 static struct acpi_processor_cx *cx;
72 static u32 acpi_regs_addr;
73 static u8 longhaul_flags;
74 static unsigned int longhaul_index;
76 /* Module parameters */
77 static int scale_voltage;
78 static int disable_acpi_c3;
79 static int revid_errata;
82 /* Clock ratios multiplied by 10 */
85 static int longhaul_version;
86 static struct cpufreq_frequency_table *longhaul_table;
88 static char speedbuffer[8];
90 static char *print_speed(int speed)
93 snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed);
98 snprintf(speedbuffer, sizeof(speedbuffer),
101 snprintf(speedbuffer, sizeof(speedbuffer),
102 "%d.%dGHz", speed/1000, (speed%1000)/100);
108 static unsigned int calc_speed(int mult)
119 static int longhaul_get_cpu_mult(void)
121 unsigned long invalue = 0, lo, hi;
123 rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
124 invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
125 if (longhaul_version == TYPE_LONGHAUL_V2 ||
126 longhaul_version == TYPE_POWERSAVER) {
130 return eblcr[invalue];
133 /* For processor with BCR2 MSR */
135 static void do_longhaul1(unsigned int mults_index)
139 rdmsrl(MSR_VIA_BCR2, bcr2.val);
140 /* Enable software clock multiplier */
141 bcr2.bits.ESOFTBF = 1;
142 bcr2.bits.CLOCKMUL = mults_index & 0xff;
144 /* Sync to timer tick */
146 /* Change frequency on next halt or sleep */
147 wrmsrl(MSR_VIA_BCR2, bcr2.val);
148 /* Invoke transition */
149 ACPI_FLUSH_CPU_CACHE();
152 /* Disable software clock multiplier */
154 rdmsrl(MSR_VIA_BCR2, bcr2.val);
155 bcr2.bits.ESOFTBF = 0;
156 wrmsrl(MSR_VIA_BCR2, bcr2.val);
159 /* For processor with Longhaul MSR */
161 static void do_powersaver(int cx_address, unsigned int mults_index,
164 union msr_longhaul longhaul;
167 rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);
168 /* Setup new frequency */
170 longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
172 longhaul.bits.RevisionKey = 0;
173 longhaul.bits.SoftBusRatio = mults_index & 0xf;
174 longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4;
175 /* Setup new voltage */
176 if (can_scale_voltage)
177 longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f;
178 /* Sync to timer tick */
180 /* Raise voltage if necessary */
181 if (can_scale_voltage && dir) {
182 longhaul.bits.EnableSoftVID = 1;
183 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
186 ACPI_FLUSH_CPU_CACHE();
189 ACPI_FLUSH_CPU_CACHE();
192 /* Dummy op - must do something useless after P_LVL3
194 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
196 longhaul.bits.EnableSoftVID = 0;
197 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
200 /* Change frequency on next halt or sleep */
201 longhaul.bits.EnableSoftBusRatio = 1;
202 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
204 ACPI_FLUSH_CPU_CACHE();
207 ACPI_FLUSH_CPU_CACHE();
210 /* Dummy op - must do something useless after P_LVL3 read */
211 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
213 /* Disable bus ratio bit */
214 longhaul.bits.EnableSoftBusRatio = 0;
215 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
217 /* Reduce voltage if necessary */
218 if (can_scale_voltage && !dir) {
219 longhaul.bits.EnableSoftVID = 1;
220 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
223 ACPI_FLUSH_CPU_CACHE();
226 ACPI_FLUSH_CPU_CACHE();
229 /* Dummy op - must do something useless after P_LVL3
231 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
233 longhaul.bits.EnableSoftVID = 0;
234 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
239 * longhaul_set_cpu_frequency()
240 * @mults_index : bitpattern of the new multiplier.
242 * Sets a new clock ratio.
245 static void longhaul_setstate(unsigned int table_index)
247 unsigned int mults_index;
249 struct cpufreq_freqs freqs;
251 unsigned int pic1_mask, pic2_mask;
253 u32 bm_timeout = 1000;
254 unsigned int dir = 0;
256 mults_index = longhaul_table[table_index].index;
257 /* Safety precautions */
258 mult = mults[mults_index & 0x1f];
261 speed = calc_speed(mult);
262 if ((speed > highest_speed) || (speed < lowest_speed))
264 /* Voltage transition before frequency transition? */
265 if (can_scale_voltage && longhaul_index < table_index)
268 freqs.old = calc_speed(longhaul_get_cpu_mult());
270 freqs.cpu = 0; /* longhaul.c is UP only driver */
272 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
274 pr_debug("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
275 fsb, mult/10, mult%10, print_speed(speed/1000));
278 local_irq_save(flags);
280 pic2_mask = inb(0xA1);
281 pic1_mask = inb(0x21); /* works on C3. save mask. */
282 outb(0xFF, 0xA1); /* Overkill */
283 outb(0xFE, 0x21); /* TMR0 only */
285 /* Wait while PCI bus is busy. */
286 if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE
287 || ((pr != NULL) && pr->flags.bm_control))) {
288 bm_status = inw(acpi_regs_addr);
290 while (bm_status && bm_timeout) {
291 outw(1 << 4, acpi_regs_addr);
293 bm_status = inw(acpi_regs_addr);
298 if (longhaul_flags & USE_NORTHBRIDGE) {
299 /* Disable AGP and PCI arbiters */
301 } else if ((pr != NULL) && pr->flags.bm_control) {
302 /* Disable bus master arbitration */
303 acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1);
305 switch (longhaul_version) {
308 * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B])
309 * Software controlled multipliers only.
311 case TYPE_LONGHAUL_V1:
312 do_longhaul1(mults_index);
316 * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C]
318 * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N])
319 * Nehemiah can do FSB scaling too, but this has never been proven
320 * to work in practice.
322 case TYPE_LONGHAUL_V2:
323 case TYPE_POWERSAVER:
324 if (longhaul_flags & USE_ACPI_C3) {
325 /* Don't allow wakeup */
326 acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
327 do_powersaver(cx->address, mults_index, dir);
329 do_powersaver(0, mults_index, dir);
334 if (longhaul_flags & USE_NORTHBRIDGE) {
335 /* Enable arbiters */
337 } else if ((pr != NULL) && pr->flags.bm_control) {
338 /* Enable bus master arbitration */
339 acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0);
341 outb(pic2_mask, 0xA1); /* restore mask */
342 outb(pic1_mask, 0x21);
344 local_irq_restore(flags);
347 freqs.new = calc_speed(longhaul_get_cpu_mult());
348 /* Check if requested frequency is set. */
349 if (unlikely(freqs.new != speed)) {
350 printk(KERN_INFO PFX "Failed to set requested frequency!\n");
351 /* Revision ID = 1 but processor is expecting revision key
352 * equal to 0. Jumpers at the bottom of processor will change
353 * multiplier and FSB, but will not change bits in Longhaul
354 * MSR nor enable voltage scaling. */
356 printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" "
362 /* Why ACPI C3 sometimes doesn't work is a mystery for me.
363 * But it does happen. Processor is entering ACPI C3 state,
364 * but it doesn't change frequency. I tried poking various
365 * bits in northbridge registers, but without success. */
366 if (longhaul_flags & USE_ACPI_C3) {
367 printk(KERN_INFO PFX "Disabling ACPI C3 support.\n");
368 longhaul_flags &= ~USE_ACPI_C3;
370 printk(KERN_INFO PFX "Disabling \"Ignore "
371 "Revision ID\" option.\n");
377 /* This shouldn't happen. Longhaul ver. 2 was reported not
378 * working on processors without voltage scaling, but with
379 * RevID = 1. RevID errata will make things right. Just
380 * to be 100% sure. */
381 if (longhaul_version == TYPE_LONGHAUL_V2) {
382 printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n");
383 longhaul_version = TYPE_LONGHAUL_V1;
388 /* Report true CPU frequency */
389 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
392 printk(KERN_INFO PFX "Warning: Timeout while waiting for "
397 * Centaur decided to make life a little more tricky.
398 * Only longhaul v1 is allowed to read EBLCR BSEL[0:1].
399 * Samuel2 and above have to try and guess what the FSB is.
400 * We do this by assuming we booted at maximum multiplier, and interpolate
401 * between that value multiplied by possible FSBs and cpu_mhz which
402 * was calculated at boot time. Really ugly, but no other way to do this.
407 static int guess_fsb(int mult)
409 int speed = cpu_khz / 1000;
411 int speeds[] = { 666, 1000, 1333, 2000 };
414 for (i = 0; i < 4; i++) {
415 f_max = ((speeds[i] * mult) + 50) / 100;
416 f_max += (ROUNDING / 2);
417 f_min = f_max - ROUNDING;
418 if ((speed <= f_max) && (speed >= f_min))
419 return speeds[i] / 10;
425 static int __cpuinit longhaul_get_ranges(void)
427 unsigned int i, j, k = 0;
431 /* Get current frequency */
432 mult = longhaul_get_cpu_mult();
434 printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n");
437 fsb = guess_fsb(mult);
439 printk(KERN_INFO PFX "Invalid (reserved) FSB!\n");
442 /* Get max multiplier - as we always did.
443 * Longhaul MSR is useful only when voltage scaling is enabled.
444 * C3 is booting at max anyway. */
446 /* Get min multiplier */
459 pr_debug("MinMult:%d.%dx MaxMult:%d.%dx\n",
460 minmult/10, minmult%10, maxmult/10, maxmult%10);
462 highest_speed = calc_speed(maxmult);
463 lowest_speed = calc_speed(minmult);
464 pr_debug("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb,
465 print_speed(lowest_speed/1000),
466 print_speed(highest_speed/1000));
468 if (lowest_speed == highest_speed) {
469 printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n");
472 if (lowest_speed > highest_speed) {
473 printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
474 lowest_speed, highest_speed);
478 longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table),
483 for (j = 0; j < numscales; j++) {
487 if (ratio > maxmult || ratio < minmult)
489 longhaul_table[k].frequency = calc_speed(ratio);
490 longhaul_table[k].index = j;
494 kfree(longhaul_table);
498 for (j = 0; j < k - 1; j++) {
499 unsigned int min_f, min_i;
500 min_f = longhaul_table[j].frequency;
502 for (i = j + 1; i < k; i++) {
503 if (longhaul_table[i].frequency < min_f) {
504 min_f = longhaul_table[i].frequency;
509 swap(longhaul_table[j].frequency,
510 longhaul_table[min_i].frequency);
511 swap(longhaul_table[j].index,
512 longhaul_table[min_i].index);
516 longhaul_table[k].frequency = CPUFREQ_TABLE_END;
518 /* Find index we are running on */
519 for (j = 0; j < k; j++) {
520 if (mults[longhaul_table[j].index & 0x1f] == mult) {
529 static void __cpuinit longhaul_setup_voltagescaling(void)
531 union msr_longhaul longhaul;
532 struct mV_pos minvid, maxvid, vid;
533 unsigned int j, speed, pos, kHz_step, numvscales;
536 rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);
537 if (!(longhaul.bits.RevisionID & 1)) {
538 printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n");
542 if (!longhaul.bits.VRMRev) {
543 printk(KERN_INFO PFX "VRM 8.5\n");
544 vrm_mV_table = &vrm85_mV[0];
545 mV_vrm_table = &mV_vrm85[0];
547 printk(KERN_INFO PFX "Mobile VRM\n");
548 if (cpu_model < CPU_NEHEMIAH)
550 vrm_mV_table = &mobilevrm_mV[0];
551 mV_vrm_table = &mV_mobilevrm[0];
554 minvid = vrm_mV_table[longhaul.bits.MinimumVID];
555 maxvid = vrm_mV_table[longhaul.bits.MaximumVID];
557 if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) {
558 printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
559 "Voltage scaling disabled.\n",
560 minvid.mV/1000, minvid.mV%1000,
561 maxvid.mV/1000, maxvid.mV%1000);
565 if (minvid.mV == maxvid.mV) {
566 printk(KERN_INFO PFX "Claims to support voltage scaling but "
567 "min & max are both %d.%03d. "
568 "Voltage scaling disabled\n",
569 maxvid.mV/1000, maxvid.mV%1000);
573 /* How many voltage steps*/
574 numvscales = maxvid.pos - minvid.pos + 1;
578 "%d possible voltage scales\n",
579 maxvid.mV/1000, maxvid.mV%1000,
580 minvid.mV/1000, minvid.mV%1000,
583 /* Calculate max frequency at min voltage */
584 j = longhaul.bits.MinMHzBR;
585 if (longhaul.bits.MinMHzBR4)
587 min_vid_speed = eblcr[j];
588 if (min_vid_speed == -1)
590 switch (longhaul.bits.MinMHzFSB) {
592 min_vid_speed *= 13333;
595 min_vid_speed *= 10000;
598 min_vid_speed *= 6666;
604 if (min_vid_speed >= highest_speed)
606 /* Calculate kHz for one voltage step */
607 kHz_step = (highest_speed - min_vid_speed) / numvscales;
610 while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) {
611 speed = longhaul_table[j].frequency;
612 if (speed > min_vid_speed)
613 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
616 longhaul_table[j].index |= mV_vrm_table[pos] << 8;
617 vid = vrm_mV_table[mV_vrm_table[pos]];
618 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
623 can_scale_voltage = 1;
624 printk(KERN_INFO PFX "Voltage scaling enabled.\n");
628 static int longhaul_verify(struct cpufreq_policy *policy)
630 return cpufreq_frequency_table_verify(policy, longhaul_table);
634 static int longhaul_target(struct cpufreq_policy *policy,
635 unsigned int target_freq, unsigned int relation)
637 unsigned int table_index = 0;
639 unsigned int dir = 0;
642 if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq,
643 relation, &table_index))
646 /* Don't set same frequency again */
647 if (longhaul_index == table_index)
650 if (!can_scale_voltage)
651 longhaul_setstate(table_index);
653 /* On test system voltage transitions exceeding single
654 * step up or down were turning motherboard off. Both
655 * "ondemand" and "userspace" are unsafe. C7 is doing
656 * this in hardware, C3 is old and we need to do this
659 current_vid = (longhaul_table[longhaul_index].index >> 8);
661 if (table_index > longhaul_index)
663 while (i != table_index) {
664 vid = (longhaul_table[i].index >> 8) & 0x1f;
665 if (vid != current_vid) {
666 longhaul_setstate(i);
675 longhaul_setstate(table_index);
677 longhaul_index = table_index;
682 static unsigned int longhaul_get(unsigned int cpu)
686 return calc_speed(longhaul_get_cpu_mult());
689 static acpi_status longhaul_walk_callback(acpi_handle obj_handle,
691 void *context, void **return_value)
693 struct acpi_device *d;
695 if (acpi_bus_get_device(obj_handle, &d))
698 *return_value = acpi_driver_data(d);
702 /* VIA don't support PM2 reg, but have something similar */
703 static int enable_arbiter_disable(void)
710 /* Find PLE133 host bridge */
712 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0,
714 /* Find PM133/VT8605 host bridge */
716 dev = pci_get_device(PCI_VENDOR_ID_VIA,
717 PCI_DEVICE_ID_VIA_8605_0, NULL);
718 /* Find CLE266 host bridge */
721 dev = pci_get_device(PCI_VENDOR_ID_VIA,
722 PCI_DEVICE_ID_VIA_862X_0, NULL);
723 /* Find CN400 V-Link host bridge */
725 dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL);
728 /* Enable access to port 0x22 */
729 pci_read_config_byte(dev, reg, &pci_cmd);
730 if (!(pci_cmd & 1<<7)) {
732 pci_write_config_byte(dev, reg, pci_cmd);
733 pci_read_config_byte(dev, reg, &pci_cmd);
734 if (!(pci_cmd & 1<<7)) {
736 "Can't enable access to port 0x22.\n");
746 static int longhaul_setup_southbridge(void)
751 /* Find VT8235 southbridge */
752 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL);
754 /* Find VT8237 southbridge */
755 dev = pci_get_device(PCI_VENDOR_ID_VIA,
756 PCI_DEVICE_ID_VIA_8237, NULL);
758 /* Set transition time to max */
759 pci_read_config_byte(dev, 0xec, &pci_cmd);
760 pci_cmd &= ~(1 << 2);
761 pci_write_config_byte(dev, 0xec, pci_cmd);
762 pci_read_config_byte(dev, 0xe4, &pci_cmd);
763 pci_cmd &= ~(1 << 7);
764 pci_write_config_byte(dev, 0xe4, pci_cmd);
765 pci_read_config_byte(dev, 0xe5, &pci_cmd);
767 pci_write_config_byte(dev, 0xe5, pci_cmd);
768 /* Get address of ACPI registers block*/
769 pci_read_config_byte(dev, 0x81, &pci_cmd);
770 if (pci_cmd & 1 << 7) {
771 pci_read_config_dword(dev, 0x88, &acpi_regs_addr);
772 acpi_regs_addr &= 0xff00;
773 printk(KERN_INFO PFX "ACPI I/O at 0x%x\n",
783 static int __cpuinit longhaul_cpu_init(struct cpufreq_policy *policy)
785 struct cpuinfo_x86 *c = &cpu_data(0);
786 char *cpuname = NULL;
790 /* Check what we have on this motherboard */
791 switch (c->x86_model) {
793 cpu_model = CPU_SAMUEL;
794 cpuname = "C3 'Samuel' [C5A]";
795 longhaul_version = TYPE_LONGHAUL_V1;
796 memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
797 memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr));
801 switch (c->x86_mask) {
803 longhaul_version = TYPE_LONGHAUL_V1;
804 cpu_model = CPU_SAMUEL2;
805 cpuname = "C3 'Samuel 2' [C5B]";
806 /* Note, this is not a typo, early Samuel2's had
808 memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
809 memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr));
812 longhaul_version = TYPE_LONGHAUL_V2;
813 if (c->x86_mask < 8) {
814 cpu_model = CPU_SAMUEL2;
815 cpuname = "C3 'Samuel 2' [C5B]";
817 cpu_model = CPU_EZRA;
818 cpuname = "C3 'Ezra' [C5C]";
820 memcpy(mults, ezra_mults, sizeof(ezra_mults));
821 memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr));
827 cpu_model = CPU_EZRA_T;
828 cpuname = "C3 'Ezra-T' [C5M]";
829 longhaul_version = TYPE_POWERSAVER;
831 memcpy(mults, ezrat_mults, sizeof(ezrat_mults));
832 memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr));
836 longhaul_version = TYPE_POWERSAVER;
838 memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults));
839 memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr));
840 switch (c->x86_mask) {
842 cpu_model = CPU_NEHEMIAH;
843 cpuname = "C3 'Nehemiah A' [C5XLOE]";
846 cpu_model = CPU_NEHEMIAH;
847 cpuname = "C3 'Nehemiah B' [C5XLOH]";
850 cpu_model = CPU_NEHEMIAH_C;
851 cpuname = "C3 'Nehemiah C' [C5P]";
860 /* Check Longhaul ver. 2 */
861 if (longhaul_version == TYPE_LONGHAUL_V2) {
862 rdmsr(MSR_VIA_LONGHAUL, lo, hi);
863 if (lo == 0 && hi == 0)
864 /* Looks like MSR isn't present */
865 longhaul_version = TYPE_LONGHAUL_V1;
868 printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname);
869 switch (longhaul_version) {
870 case TYPE_LONGHAUL_V1:
871 case TYPE_LONGHAUL_V2:
872 printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version);
874 case TYPE_POWERSAVER:
875 printk(KERN_CONT "Powersaver supported.\n");
880 longhaul_setup_southbridge();
882 /* Find ACPI data for processor */
883 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
884 ACPI_UINT32_MAX, &longhaul_walk_callback, NULL,
887 /* Check ACPI support for C3 state */
888 if (pr != NULL && longhaul_version == TYPE_POWERSAVER) {
889 cx = &pr->power.states[ACPI_STATE_C3];
890 if (cx->address > 0 && cx->latency <= 1000)
891 longhaul_flags |= USE_ACPI_C3;
893 /* Disable if it isn't working */
895 longhaul_flags &= ~USE_ACPI_C3;
896 /* Check if northbridge is friendly */
897 if (enable_arbiter_disable())
898 longhaul_flags |= USE_NORTHBRIDGE;
900 /* Check ACPI support for bus master arbiter disable */
901 if (!(longhaul_flags & USE_ACPI_C3
902 || longhaul_flags & USE_NORTHBRIDGE)
903 && ((pr == NULL) || !(pr->flags.bm_control))) {
905 "No ACPI support. Unsupported northbridge.\n");
909 if (longhaul_flags & USE_NORTHBRIDGE)
910 printk(KERN_INFO PFX "Using northbridge support.\n");
911 if (longhaul_flags & USE_ACPI_C3)
912 printk(KERN_INFO PFX "Using ACPI support.\n");
914 ret = longhaul_get_ranges();
918 if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0))
919 longhaul_setup_voltagescaling();
921 policy->cpuinfo.transition_latency = 200000; /* nsec */
922 policy->cur = calc_speed(longhaul_get_cpu_mult());
924 ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table);
928 cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu);
933 static int longhaul_cpu_exit(struct cpufreq_policy *policy)
935 cpufreq_frequency_table_put_attr(policy->cpu);
939 static struct freq_attr *longhaul_attr[] = {
940 &cpufreq_freq_attr_scaling_available_freqs,
944 static struct cpufreq_driver longhaul_driver = {
945 .verify = longhaul_verify,
946 .target = longhaul_target,
948 .init = longhaul_cpu_init,
949 .exit = longhaul_cpu_exit,
951 .owner = THIS_MODULE,
952 .attr = longhaul_attr,
955 static const struct x86_cpu_id longhaul_id[] = {
956 { X86_VENDOR_CENTAUR, 6 },
959 MODULE_DEVICE_TABLE(x86cpu, longhaul_id);
961 static int __init longhaul_init(void)
963 struct cpuinfo_x86 *c = &cpu_data(0);
965 if (!x86_match_cpu(longhaul_id))
969 printk(KERN_ERR PFX "Option \"enable\" not set. Aborting.\n");
973 if (num_online_cpus() > 1) {
974 printk(KERN_ERR PFX "More than 1 CPU detected, "
975 "longhaul disabled.\n");
979 #ifdef CONFIG_X86_IO_APIC
981 printk(KERN_ERR PFX "APIC detected. Longhaul is currently "
982 "broken in this configuration.\n");
986 switch (c->x86_model) {
988 return cpufreq_register_driver(&longhaul_driver);
990 printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n");
999 static void __exit longhaul_exit(void)
1003 for (i = 0; i < numscales; i++) {
1004 if (mults[i] == maxmult) {
1005 longhaul_setstate(i);
1010 cpufreq_unregister_driver(&longhaul_driver);
1011 kfree(longhaul_table);
1014 /* Even if BIOS is exporting ACPI C3 state, and it is used
1015 * with success when CPU is idle, this state doesn't
1016 * trigger frequency transition in some cases. */
1017 module_param(disable_acpi_c3, int, 0644);
1018 MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support");
1019 /* Change CPU voltage with frequency. Very useful to save
1020 * power, but most VIA C3 processors aren't supporting it. */
1021 module_param(scale_voltage, int, 0644);
1022 MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
1023 /* Force revision key to 0 for processors which doesn't
1024 * support voltage scaling, but are introducing itself as
1026 module_param(revid_errata, int, 0644);
1027 MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID");
1028 /* By default driver is disabled to prevent incompatible
1030 module_param(enable, int, 0644);
1031 MODULE_PARM_DESC(enable, "Enable driver");
1033 MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
1034 MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors.");
1035 MODULE_LICENSE("GPL");
1037 late_initcall(longhaul_init);
1038 module_exit(longhaul_exit);