longhaul.c 18 KB

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