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