longhaul.c 18 KB

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