longhaul.c 19 KB

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