longhaul.c 19 KB

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