]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/i386/kernel/cpu/cpufreq/longhaul.c
[CPUFREQ] Longhaul - Initialise later.
[linux-2.6-omap-h63xx.git] / arch / i386 / kernel / cpu / cpufreq / longhaul.c
1 /*
2  *  (C) 2001-2004  Dave Jones. <davej@codemonkey.org.uk>
3  *  (C) 2002  Padraig Brady. <padraig@antefacto.com>
4  *
5  *  Licensed under the terms of the GNU GPL License version 2.
6  *  Based upon datasheets & sample CPUs kindly provided by VIA.
7  *
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 the same as v1, but adds voltage scaling.
12  *   Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C)
13  *   voltage scaling support has currently been disabled in this driver
14  *   until we have code that gets it right.
15  *  Version 3 of longhaul got renamed to Powersaver and redesigned
16  *   to use the POWERSAVER MSR at 0x110a.
17  *   It is present in Ezra-T (C5M), Nehemiah (C5X) and above.
18  *   It's pretty much the same feature wise to longhaul v2, though
19  *   there is provision for scaling FSB too, but this doesn't work
20  *   too well in practice so we don't even try to use this.
21  *
22  *  BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
23  */
24
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/moduleparam.h>
28 #include <linux/init.h>
29 #include <linux/cpufreq.h>
30 #include <linux/slab.h>
31 #include <linux/string.h>
32
33 #include <asm/msr.h>
34 #include <asm/timex.h>
35 #include <asm/io.h>
36 #include <asm/acpi.h>
37 #include <linux/acpi.h>
38 #include <acpi/processor.h>
39
40 #include "longhaul.h"
41
42 #define PFX "longhaul: "
43
44 #define TYPE_LONGHAUL_V1        1
45 #define TYPE_LONGHAUL_V2        2
46 #define TYPE_POWERSAVER         3
47
48 #define CPU_SAMUEL      1
49 #define CPU_SAMUEL2     2
50 #define CPU_EZRA        3
51 #define CPU_EZRA_T      4
52 #define CPU_NEHEMIAH    5
53
54 static int cpu_model;
55 static unsigned int numscales=16, numvscales;
56 static unsigned int fsb;
57 static int minvid, maxvid;
58 static unsigned int minmult, maxmult;
59 static int can_scale_voltage;
60 static int vrmrev;
61 static struct acpi_processor *pr = NULL;
62 static struct acpi_processor_cx *cx = NULL;
63
64 /* Module parameters */
65 static int dont_scale_voltage;
66
67
68 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longhaul", msg)
69
70
71 /* Clock ratios multiplied by 10 */
72 static int clock_ratio[32];
73 static int eblcr_table[32];
74 static int voltage_table[32];
75 static unsigned int highest_speed, lowest_speed; /* kHz */
76 static int longhaul_version;
77 static struct cpufreq_frequency_table *longhaul_table;
78
79 #ifdef CONFIG_CPU_FREQ_DEBUG
80 static char speedbuffer[8];
81
82 static char *print_speed(int speed)
83 {
84         if (speed < 1000) {
85                 snprintf(speedbuffer, sizeof(speedbuffer),"%dMHz", speed);
86                 return speedbuffer;
87         }
88
89         if (speed%1000 == 0)
90                 snprintf(speedbuffer, sizeof(speedbuffer),
91                         "%dGHz", speed/1000);
92         else
93                 snprintf(speedbuffer, sizeof(speedbuffer),
94                         "%d.%dGHz", speed/1000, (speed%1000)/100);
95
96         return speedbuffer;
97 }
98 #endif
99
100
101 static unsigned int calc_speed(int mult)
102 {
103         int khz;
104         khz = (mult/10)*fsb;
105         if (mult%10)
106                 khz += fsb/2;
107         khz *= 1000;
108         return khz;
109 }
110
111
112 static int longhaul_get_cpu_mult(void)
113 {
114         unsigned long invalue=0,lo, hi;
115
116         rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi);
117         invalue = (lo & (1<<22|1<<23|1<<24|1<<25)) >>22;
118         if (longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) {
119                 if (lo & (1<<27))
120                         invalue+=16;
121         }
122         return eblcr_table[invalue];
123 }
124
125 /* For processor with BCR2 MSR */
126
127 static void do_longhaul1(int cx_address, unsigned int clock_ratio_index)
128 {
129         union msr_bcr2 bcr2;
130         u32 t;
131
132         rdmsrl(MSR_VIA_BCR2, bcr2.val);
133         /* Enable software clock multiplier */
134         bcr2.bits.ESOFTBF = 1;
135         bcr2.bits.CLOCKMUL = clock_ratio_index;
136
137         /* Sync to timer tick */
138         safe_halt();
139         ACPI_FLUSH_CPU_CACHE();
140         /* Change frequency on next halt or sleep */
141         wrmsrl(MSR_VIA_BCR2, bcr2.val);
142         /* Invoke C3 */
143         inb(cx_address);
144         /* Dummy op - must do something useless after P_LVL3 read */
145         t = inl(acpi_fadt.xpm_tmr_blk.address);
146
147         /* Disable software clock multiplier */
148         local_irq_disable();
149         rdmsrl(MSR_VIA_BCR2, bcr2.val);
150         bcr2.bits.ESOFTBF = 0;
151         wrmsrl(MSR_VIA_BCR2, bcr2.val);
152 }
153
154 /* For processor with Longhaul MSR */
155
156 static void do_powersaver(int cx_address, unsigned int clock_ratio_index)
157 {
158         union msr_longhaul longhaul;
159         u32 t;
160
161         rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);
162         longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
163         longhaul.bits.SoftBusRatio = clock_ratio_index & 0xf;
164         longhaul.bits.SoftBusRatio4 = (clock_ratio_index & 0x10) >> 4;
165
166         /* Sync to timer tick */
167         safe_halt();
168         ACPI_FLUSH_CPU_CACHE();
169         /* Change frequency on next halt or sleep */
170         wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
171         /* Invoke C3 */
172         inb(cx_address);
173         /* Dummy op - must do something useless after P_LVL3 read */
174         t = inl(acpi_fadt.xpm_tmr_blk.address);
175
176         /* Disable bus ratio bit */
177         local_irq_disable();
178         longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
179         longhaul.bits.EnableSoftBusRatio = 0;
180         longhaul.bits.EnableSoftBSEL = 0;
181         longhaul.bits.EnableSoftVID = 0;
182         wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
183 }
184
185 /**
186  * longhaul_set_cpu_frequency()
187  * @clock_ratio_index : bitpattern of the new multiplier.
188  *
189  * Sets a new clock ratio.
190  */
191
192 static void longhaul_setstate(unsigned int clock_ratio_index)
193 {
194         int speed, mult;
195         struct cpufreq_freqs freqs;
196         static unsigned int old_ratio=-1;
197         unsigned long flags;
198         unsigned int pic1_mask, pic2_mask;
199
200         if (old_ratio == clock_ratio_index)
201                 return;
202         old_ratio = clock_ratio_index;
203
204         mult = clock_ratio[clock_ratio_index];
205         if (mult == -1)
206                 return;
207
208         speed = calc_speed(mult);
209         if ((speed > highest_speed) || (speed < lowest_speed))
210                 return;
211
212         freqs.old = calc_speed(longhaul_get_cpu_mult());
213         freqs.new = speed;
214         freqs.cpu = 0; /* longhaul.c is UP only driver */
215
216         cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
217
218         dprintk ("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
219                         fsb, mult/10, mult%10, print_speed(speed/1000));
220
221         preempt_disable();
222         local_irq_save(flags);
223
224         pic2_mask = inb(0xA1);
225         pic1_mask = inb(0x21);  /* works on C3. save mask. */
226         outb(0xFF,0xA1);        /* Overkill */
227         outb(0xFE,0x21);        /* TMR0 only */
228
229         /* Disable bus master arbitration */
230         if (pr->flags.bm_check) {
231                 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1,
232                                   ACPI_MTX_DO_NOT_LOCK);
233         }
234
235         switch (longhaul_version) {
236
237         /*
238          * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B])
239          * Software controlled multipliers only.
240          *
241          * *NB* Until we get voltage scaling working v1 & v2 are the same code.
242          * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5b] and Ezra [C5C]
243          */
244         case TYPE_LONGHAUL_V1:
245         case TYPE_LONGHAUL_V2:
246                 do_longhaul1(cx->address, clock_ratio_index);
247                 break;
248
249         /*
250          * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N])
251          * We can scale voltage with this too, but that's currently
252          * disabled until we come up with a decent 'match freq to voltage'
253          * algorithm.
254          * When we add voltage scaling, we will also need to do the
255          * voltage/freq setting in order depending on the direction
256          * of scaling (like we do in powernow-k7.c)
257          * Nehemiah can do FSB scaling too, but this has never been proven
258          * to work in practice.
259          */
260         case TYPE_POWERSAVER:
261                 do_powersaver(cx->address, clock_ratio_index);
262                 break;
263         }
264
265         /* Enable bus master arbitration */
266         if (pr->flags.bm_check) {
267                 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0,
268                                   ACPI_MTX_DO_NOT_LOCK);
269         }
270
271         outb(pic2_mask,0xA1);   /* restore mask */
272         outb(pic1_mask,0x21);
273
274         local_irq_restore(flags);
275         preempt_enable();
276
277         cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
278 }
279
280 /*
281  * Centaur decided to make life a little more tricky.
282  * Only longhaul v1 is allowed to read EBLCR BSEL[0:1].
283  * Samuel2 and above have to try and guess what the FSB is.
284  * We do this by assuming we booted at maximum multiplier, and interpolate
285  * between that value multiplied by possible FSBs and cpu_mhz which
286  * was calculated at boot time. Really ugly, but no other way to do this.
287  */
288
289 #define ROUNDING        0xf
290
291 static int _guess(int guess)
292 {
293         int target;
294
295         target = ((maxmult/10)*guess);
296         if (maxmult%10 != 0)
297                 target += (guess/2);
298         target += ROUNDING/2;
299         target &= ~ROUNDING;
300         return target;
301 }
302
303
304 static int guess_fsb(void)
305 {
306         int speed = (cpu_khz/1000);
307         int i;
308         int speeds[3] = { 66, 100, 133 };
309
310         speed += ROUNDING/2;
311         speed &= ~ROUNDING;
312
313         for (i=0; i<3; i++) {
314                 if (_guess(speeds[i]) == speed)
315                         return speeds[i];
316         }
317         return 0;
318 }
319
320
321 static int __init longhaul_get_ranges(void)
322 {
323         unsigned long invalue;
324         unsigned int multipliers[32]= {
325                 50,30,40,100,55,35,45,95,90,70,80,60,120,75,85,65,
326                 -1,110,120,-1,135,115,125,105,130,150,160,140,-1,155,-1,145 };
327         unsigned int j, k = 0;
328         union msr_longhaul longhaul;
329         unsigned long lo, hi;
330         unsigned int eblcr_fsb_table_v1[] = { 66, 133, 100, -1 };
331         unsigned int eblcr_fsb_table_v2[] = { 133, 100, -1, 66 };
332
333         switch (longhaul_version) {
334         case TYPE_LONGHAUL_V1:
335         case TYPE_LONGHAUL_V2:
336                 /* Ugh, Longhaul v1 didn't have the min/max MSRs.
337                    Assume min=3.0x & max = whatever we booted at. */
338                 minmult = 30;
339                 maxmult = longhaul_get_cpu_mult();
340                 rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi);
341                 invalue = (lo & (1<<18|1<<19)) >>18;
342                 if (cpu_model==CPU_SAMUEL || cpu_model==CPU_SAMUEL2)
343                         fsb = eblcr_fsb_table_v1[invalue];
344                 else
345                         fsb = guess_fsb();
346                 break;
347
348         case TYPE_POWERSAVER:
349                 /* Ezra-T */
350                 if (cpu_model==CPU_EZRA_T) {
351                         rdmsrl (MSR_VIA_LONGHAUL, longhaul.val);
352                         invalue = longhaul.bits.MaxMHzBR;
353                         if (longhaul.bits.MaxMHzBR4)
354                                 invalue += 16;
355                         maxmult=multipliers[invalue];
356
357                         invalue = longhaul.bits.MinMHzBR;
358                         if (longhaul.bits.MinMHzBR4 == 1)
359                                 minmult = 30;
360                         else
361                                 minmult = multipliers[invalue];
362                         fsb = eblcr_fsb_table_v2[longhaul.bits.MaxMHzFSB];
363                         break;
364                 }
365
366                 /* Nehemiah */
367                 if (cpu_model==CPU_NEHEMIAH) {
368                         rdmsrl (MSR_VIA_LONGHAUL, longhaul.val);
369
370                         /*
371                          * TODO: This code works, but raises a lot of questions.
372                          * - Some Nehemiah's seem to have broken Min/MaxMHzBR's.
373                          *   We get around this by using a hardcoded multiplier of 4.0x
374                          *   for the minimimum speed, and the speed we booted up at for the max.
375                          *   This is done in longhaul_get_cpu_mult() by reading the EBLCR register.
376                          * - According to some VIA documentation EBLCR is only
377                          *   in pre-Nehemiah C3s. How this still works is a mystery.
378                          *   We're possibly using something undocumented and unsupported,
379                          *   But it works, so we don't grumble.
380                          */
381                         minmult=40;
382                         maxmult=longhaul_get_cpu_mult();
383
384                         /* Starting with the 1.2GHz parts, theres a 200MHz bus. */
385                         if ((cpu_khz/1000) > 1200)
386                                 fsb = 200;
387                         else
388                                 fsb = eblcr_fsb_table_v2[longhaul.bits.MaxMHzFSB];
389                         break;
390                 }
391         }
392
393         dprintk ("MinMult:%d.%dx MaxMult:%d.%dx\n",
394                  minmult/10, minmult%10, maxmult/10, maxmult%10);
395
396         if (fsb == -1) {
397                 printk (KERN_INFO PFX "Invalid (reserved) FSB!\n");
398                 return -EINVAL;
399         }
400
401         highest_speed = calc_speed(maxmult);
402         lowest_speed = calc_speed(minmult);
403         dprintk ("FSB:%dMHz  Lowest speed: %s   Highest speed:%s\n", fsb,
404                  print_speed(lowest_speed/1000), 
405                  print_speed(highest_speed/1000));
406
407         if (lowest_speed == highest_speed) {
408                 printk (KERN_INFO PFX "highestspeed == lowest, aborting.\n");
409                 return -EINVAL;
410         }
411         if (lowest_speed > highest_speed) {
412                 printk (KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
413                         lowest_speed, highest_speed);
414                 return -EINVAL;
415         }
416
417         longhaul_table = kmalloc((numscales + 1) * sizeof(struct cpufreq_frequency_table), GFP_KERNEL);
418         if(!longhaul_table)
419                 return -ENOMEM;
420
421         for (j=0; j < numscales; j++) {
422                 unsigned int ratio;
423                 ratio = clock_ratio[j];
424                 if (ratio == -1)
425                         continue;
426                 if (ratio > maxmult || ratio < minmult)
427                         continue;
428                 longhaul_table[k].frequency = calc_speed(ratio);
429                 longhaul_table[k].index = j;
430                 k++;
431         }
432
433         longhaul_table[k].frequency = CPUFREQ_TABLE_END;
434         if (!k) {
435                 kfree (longhaul_table);
436                 return -EINVAL;
437         }
438
439         return 0;
440 }
441
442
443 static void __init longhaul_setup_voltagescaling(void)
444 {
445         union msr_longhaul longhaul;
446
447         rdmsrl (MSR_VIA_LONGHAUL, longhaul.val);
448
449         if (!(longhaul.bits.RevisionID & 1))
450                 return;
451
452         minvid = longhaul.bits.MinimumVID;
453         maxvid = longhaul.bits.MaximumVID;
454         vrmrev = longhaul.bits.VRMRev;
455
456         if (minvid == 0 || maxvid == 0) {
457                 printk (KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
458                                         "Voltage scaling disabled.\n",
459                                         minvid/1000, minvid%1000, maxvid/1000, maxvid%1000);
460                 return;
461         }
462
463         if (minvid == maxvid) {
464                 printk (KERN_INFO PFX "Claims to support voltage scaling but min & max are "
465                                 "both %d.%03d. Voltage scaling disabled\n",
466                                 maxvid/1000, maxvid%1000);
467                 return;
468         }
469
470         if (vrmrev==0) {
471                 dprintk ("VRM 8.5\n");
472                 memcpy (voltage_table, vrm85scales, sizeof(voltage_table));
473                 numvscales = (voltage_table[maxvid]-voltage_table[minvid])/25;
474         } else {
475                 dprintk ("Mobile VRM\n");
476                 memcpy (voltage_table, mobilevrmscales, sizeof(voltage_table));
477                 numvscales = (voltage_table[maxvid]-voltage_table[minvid])/5;
478         }
479
480         /* Current voltage isn't readable at first, so we need to
481            set it to a known value. The spec says to use maxvid */
482         longhaul.bits.RevisionKey = longhaul.bits.RevisionID;   /* FIXME: This is bad. */
483         longhaul.bits.EnableSoftVID = 1;
484         longhaul.bits.SoftVID = maxvid;
485         wrmsrl (MSR_VIA_LONGHAUL, longhaul.val);
486
487         minvid = voltage_table[minvid];
488         maxvid = voltage_table[maxvid];
489
490         dprintk ("Min VID=%d.%03d Max VID=%d.%03d, %d possible voltage scales\n",
491                 maxvid/1000, maxvid%1000, minvid/1000, minvid%1000, numvscales);
492
493         can_scale_voltage = 1;
494 }
495
496
497 static int longhaul_verify(struct cpufreq_policy *policy)
498 {
499         return cpufreq_frequency_table_verify(policy, longhaul_table);
500 }
501
502
503 static int longhaul_target(struct cpufreq_policy *policy,
504                             unsigned int target_freq, unsigned int relation)
505 {
506         unsigned int table_index = 0;
507         unsigned int new_clock_ratio = 0;
508
509         if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, relation, &table_index))
510                 return -EINVAL;
511
512         new_clock_ratio = longhaul_table[table_index].index & 0xFF;
513
514         longhaul_setstate(new_clock_ratio);
515
516         return 0;
517 }
518
519
520 static unsigned int longhaul_get(unsigned int cpu)
521 {
522         if (cpu)
523                 return 0;
524         return calc_speed(longhaul_get_cpu_mult());
525 }
526
527 acpi_status longhaul_walk_callback(acpi_handle obj_handle,
528                                   u32 nesting_level,
529                                   void *context, void **return_value)
530 {
531         struct acpi_device *d;
532
533         if ( acpi_bus_get_device(obj_handle, &d) ) {
534                 return 0;
535         }
536         *return_value = (void *)acpi_driver_data(d);
537         return 1;
538 }
539
540 static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
541 {
542         struct cpuinfo_x86 *c = cpu_data;
543         char *cpuname=NULL;
544         int ret;
545
546         /* Check ACPI support for C3 state */
547         acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
548                          &longhaul_walk_callback, NULL, (void *)&pr);
549         if (pr == NULL) goto err_acpi;
550
551         cx = &pr->power.states[ACPI_STATE_C3];
552         if (cx == NULL || cx->latency > 1000) goto err_acpi;
553
554         /* Now check what we have on this motherboard */
555         switch (c->x86_model) {
556         case 6:
557                 cpu_model = CPU_SAMUEL;
558                 cpuname = "C3 'Samuel' [C5A]";
559                 longhaul_version = TYPE_LONGHAUL_V1;
560                 memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
561                 memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr));
562                 break;
563
564         case 7:
565                 longhaul_version = TYPE_LONGHAUL_V1;
566                 switch (c->x86_mask) {
567                 case 0:
568                         cpu_model = CPU_SAMUEL2;
569                         cpuname = "C3 'Samuel 2' [C5B]";
570                         /* Note, this is not a typo, early Samuel2's had Samuel1 ratios. */
571                         memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
572                         memcpy (eblcr_table, samuel2_eblcr, sizeof(samuel2_eblcr));
573                         break;
574                 case 1 ... 15:
575                         if (c->x86_mask < 8) {
576                                 cpu_model = CPU_SAMUEL2;
577                                 cpuname = "C3 'Samuel 2' [C5B]";
578                         } else {
579                                 cpu_model = CPU_EZRA;
580                                 cpuname = "C3 'Ezra' [C5C]";
581                         }
582                         memcpy (clock_ratio, ezra_clock_ratio, sizeof(ezra_clock_ratio));
583                         memcpy (eblcr_table, ezra_eblcr, sizeof(ezra_eblcr));
584                         break;
585                 }
586                 break;
587
588         case 8:
589                 cpu_model = CPU_EZRA_T;
590                 cpuname = "C3 'Ezra-T' [C5M]";
591                 longhaul_version = TYPE_POWERSAVER;
592                 numscales=32;
593                 memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio));
594                 memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr));
595                 break;
596
597         case 9:
598                 cpu_model = CPU_NEHEMIAH;
599                 longhaul_version = TYPE_POWERSAVER;
600                 numscales=32;
601                 switch (c->x86_mask) {
602                 case 0 ... 1:
603                         cpuname = "C3 'Nehemiah A' [C5N]";
604                         memcpy (clock_ratio, nehemiah_a_clock_ratio, sizeof(nehemiah_a_clock_ratio));
605                         memcpy (eblcr_table, nehemiah_a_eblcr, sizeof(nehemiah_a_eblcr));
606                         break;
607                 case 2 ... 4:
608                         cpuname = "C3 'Nehemiah B' [C5N]";
609                         memcpy (clock_ratio, nehemiah_b_clock_ratio, sizeof(nehemiah_b_clock_ratio));
610                         memcpy (eblcr_table, nehemiah_b_eblcr, sizeof(nehemiah_b_eblcr));
611                         break;
612                 case 5 ... 15:
613                         cpuname = "C3 'Nehemiah C' [C5N]";
614                         memcpy (clock_ratio, nehemiah_c_clock_ratio, sizeof(nehemiah_c_clock_ratio));
615                         memcpy (eblcr_table, nehemiah_c_eblcr, sizeof(nehemiah_c_eblcr));
616                         break;
617                 }
618                 break;
619
620         default:
621                 cpuname = "Unknown";
622                 break;
623         }
624
625         printk (KERN_INFO PFX "VIA %s CPU detected.  ", cpuname);
626         switch (longhaul_version) {
627         case TYPE_LONGHAUL_V1:
628         case TYPE_LONGHAUL_V2:
629                 printk ("Longhaul v%d supported.\n", longhaul_version);
630                 break;
631         case TYPE_POWERSAVER:
632                 printk ("Powersaver supported.\n");
633                 break;
634         };
635
636         ret = longhaul_get_ranges();
637         if (ret != 0)
638                 return ret;
639
640         if ((longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) &&
641                  (dont_scale_voltage==0))
642                 longhaul_setup_voltagescaling();
643
644         policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
645         policy->cpuinfo.transition_latency = 200000;    /* nsec */
646         policy->cur = calc_speed(longhaul_get_cpu_mult());
647
648         ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table);
649         if (ret)
650                 return ret;
651
652         cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu);
653
654         return 0;
655
656 err_acpi:
657         printk(KERN_ERR PFX "No ACPI support for CPU frequency changes.\n");
658         return -ENODEV;
659 }
660
661 static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy)
662 {
663         cpufreq_frequency_table_put_attr(policy->cpu);
664         return 0;
665 }
666
667 static struct freq_attr* longhaul_attr[] = {
668         &cpufreq_freq_attr_scaling_available_freqs,
669         NULL,
670 };
671
672 static struct cpufreq_driver longhaul_driver = {
673         .verify = longhaul_verify,
674         .target = longhaul_target,
675         .get    = longhaul_get,
676         .init   = longhaul_cpu_init,
677         .exit   = __devexit_p(longhaul_cpu_exit),
678         .name   = "longhaul",
679         .owner  = THIS_MODULE,
680         .attr   = longhaul_attr,
681 };
682
683
684 static int __init longhaul_init(void)
685 {
686         struct cpuinfo_x86 *c = cpu_data;
687
688         if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6)
689                 return -ENODEV;
690
691 #ifdef CONFIG_SMP
692         if (num_online_cpus() > 1) {
693                 return -ENODEV;
694                 printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n");
695         }
696 #endif
697 #ifdef CONFIG_X86_IO_APIC
698         if (cpu_has_apic) {
699                 printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n");
700                 return -ENODEV;
701         }
702 #endif
703         switch (c->x86_model) {
704         case 6 ... 9:
705                 return cpufreq_register_driver(&longhaul_driver);
706         default:
707                 printk (KERN_INFO PFX "Unknown VIA CPU. Contact davej@codemonkey.org.uk\n");
708         }
709
710         return -ENODEV;
711 }
712
713
714 static void __exit longhaul_exit(void)
715 {
716         int i;
717
718         for (i=0; i < numscales; i++) {
719                 if (clock_ratio[i] == maxmult) {
720                         longhaul_setstate(i);
721                         break;
722                 }
723         }
724
725         cpufreq_unregister_driver(&longhaul_driver);
726         kfree(longhaul_table);
727 }
728
729 module_param (dont_scale_voltage, int, 0644);
730 MODULE_PARM_DESC(dont_scale_voltage, "Don't scale voltage of processor");
731
732 MODULE_AUTHOR ("Dave Jones <davej@codemonkey.org.uk>");
733 MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors.");
734 MODULE_LICENSE ("GPL");
735
736 late_initcall(longhaul_init);
737 module_exit(longhaul_exit);
738