longhaul.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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 ezra_t_multipliers[32]= {
  267. 90, 30, 40, 100, 55, 35, 45, 95,
  268. 50, 70, 80, 60, 120, 75, 85, 65,
  269. -1, 110, 120, -1, 135, 115, 125, 105,
  270. 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=ezra_t_multipliers[invalue];
  298. invalue = longhaul.bits.MinMHzBR;
  299. if (longhaul.bits.MinMHzBR4 == 1)
  300. minmult = 30;
  301. else
  302. minmult = ezra_t_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 acpi_status longhaul_walk_callback(acpi_handle obj_handle,
  435. u32 nesting_level,
  436. void *context, void **return_value)
  437. {
  438. struct acpi_device *d;
  439. if ( acpi_bus_get_device(obj_handle, &d) ) {
  440. return 0;
  441. }
  442. *return_value = (void *)acpi_driver_data(d);
  443. return 1;
  444. }
  445. static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
  446. {
  447. struct cpuinfo_x86 *c = cpu_data;
  448. char *cpuname=NULL;
  449. int ret;
  450. /* Check ACPI support for C3 state */
  451. acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX,
  452. &longhaul_walk_callback, NULL, (void *)&pr);
  453. if (pr == NULL) goto err_acpi;
  454. cx = &pr->power.states[ACPI_STATE_C3];
  455. if (cx->address == 0 || cx->latency > 1000) goto err_acpi;
  456. /* Now check what we have on this motherboard */
  457. switch (c->x86_model) {
  458. case 6:
  459. cpu_model = CPU_SAMUEL;
  460. cpuname = "C3 'Samuel' [C5A]";
  461. longhaul_version = TYPE_LONGHAUL_V1;
  462. memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
  463. memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr));
  464. break;
  465. case 7:
  466. longhaul_version = TYPE_LONGHAUL_V1;
  467. switch (c->x86_mask) {
  468. case 0:
  469. cpu_model = CPU_SAMUEL2;
  470. cpuname = "C3 'Samuel 2' [C5B]";
  471. /* Note, this is not a typo, early Samuel2's had Samuel1 ratios. */
  472. memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
  473. memcpy (eblcr_table, samuel2_eblcr, sizeof(samuel2_eblcr));
  474. break;
  475. case 1 ... 15:
  476. if (c->x86_mask < 8) {
  477. cpu_model = CPU_SAMUEL2;
  478. cpuname = "C3 'Samuel 2' [C5B]";
  479. } else {
  480. cpu_model = CPU_EZRA;
  481. cpuname = "C3 'Ezra' [C5C]";
  482. }
  483. memcpy (clock_ratio, ezra_clock_ratio, sizeof(ezra_clock_ratio));
  484. memcpy (eblcr_table, ezra_eblcr, sizeof(ezra_eblcr));
  485. break;
  486. }
  487. break;
  488. case 8:
  489. cpu_model = CPU_EZRA_T;
  490. cpuname = "C3 'Ezra-T' [C5M]";
  491. longhaul_version = TYPE_POWERSAVER;
  492. numscales=32;
  493. memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio));
  494. memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr));
  495. break;
  496. case 9:
  497. cpu_model = CPU_NEHEMIAH;
  498. longhaul_version = TYPE_POWERSAVER;
  499. numscales=32;
  500. switch (c->x86_mask) {
  501. case 0 ... 1:
  502. cpuname = "C3 'Nehemiah A' [C5N]";
  503. memcpy (clock_ratio, nehemiah_a_clock_ratio, sizeof(nehemiah_a_clock_ratio));
  504. memcpy (eblcr_table, nehemiah_a_eblcr, sizeof(nehemiah_a_eblcr));
  505. break;
  506. case 2 ... 4:
  507. cpuname = "C3 'Nehemiah B' [C5N]";
  508. memcpy (clock_ratio, nehemiah_b_clock_ratio, sizeof(nehemiah_b_clock_ratio));
  509. memcpy (eblcr_table, nehemiah_b_eblcr, sizeof(nehemiah_b_eblcr));
  510. break;
  511. case 5 ... 15:
  512. cpuname = "C3 'Nehemiah C' [C5N]";
  513. memcpy (clock_ratio, nehemiah_c_clock_ratio, sizeof(nehemiah_c_clock_ratio));
  514. memcpy (eblcr_table, nehemiah_c_eblcr, sizeof(nehemiah_c_eblcr));
  515. break;
  516. }
  517. break;
  518. default:
  519. cpuname = "Unknown";
  520. break;
  521. }
  522. printk (KERN_INFO PFX "VIA %s CPU detected. ", cpuname);
  523. switch (longhaul_version) {
  524. case TYPE_LONGHAUL_V1:
  525. case TYPE_LONGHAUL_V2:
  526. printk ("Longhaul v%d supported.\n", longhaul_version);
  527. break;
  528. case TYPE_POWERSAVER:
  529. printk ("Powersaver supported.\n");
  530. break;
  531. };
  532. ret = longhaul_get_ranges();
  533. if (ret != 0)
  534. return ret;
  535. if ((longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) &&
  536. (dont_scale_voltage==0))
  537. longhaul_setup_voltagescaling();
  538. policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
  539. policy->cpuinfo.transition_latency = 200000; /* nsec */
  540. policy->cur = calc_speed(longhaul_get_cpu_mult());
  541. ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table);
  542. if (ret)
  543. return ret;
  544. cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu);
  545. return 0;
  546. err_acpi:
  547. printk(KERN_ERR PFX "No ACPI support for CPU frequency changes.\n");
  548. return -ENODEV;
  549. }
  550. static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy)
  551. {
  552. cpufreq_frequency_table_put_attr(policy->cpu);
  553. return 0;
  554. }
  555. static struct freq_attr* longhaul_attr[] = {
  556. &cpufreq_freq_attr_scaling_available_freqs,
  557. NULL,
  558. };
  559. static struct cpufreq_driver longhaul_driver = {
  560. .verify = longhaul_verify,
  561. .target = longhaul_target,
  562. .get = longhaul_get,
  563. .init = longhaul_cpu_init,
  564. .exit = __devexit_p(longhaul_cpu_exit),
  565. .name = "longhaul",
  566. .owner = THIS_MODULE,
  567. .attr = longhaul_attr,
  568. };
  569. static int __init longhaul_init(void)
  570. {
  571. struct cpuinfo_x86 *c = cpu_data;
  572. if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6)
  573. return -ENODEV;
  574. #ifdef CONFIG_SMP
  575. if (num_online_cpus() > 1) {
  576. return -ENODEV;
  577. printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n");
  578. }
  579. #endif
  580. #ifdef CONFIG_X86_IO_APIC
  581. if (cpu_has_apic) {
  582. printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n");
  583. return -ENODEV;
  584. }
  585. #endif
  586. switch (c->x86_model) {
  587. case 6 ... 9:
  588. return cpufreq_register_driver(&longhaul_driver);
  589. default:
  590. printk (KERN_INFO PFX "Unknown VIA CPU. Contact davej@codemonkey.org.uk\n");
  591. }
  592. return -ENODEV;
  593. }
  594. static void __exit longhaul_exit(void)
  595. {
  596. int i;
  597. for (i=0; i < numscales; i++) {
  598. if (clock_ratio[i] == maxmult) {
  599. longhaul_setstate(i);
  600. break;
  601. }
  602. }
  603. cpufreq_unregister_driver(&longhaul_driver);
  604. kfree(longhaul_table);
  605. }
  606. module_param (dont_scale_voltage, int, 0644);
  607. MODULE_PARM_DESC(dont_scale_voltage, "Don't scale voltage of processor");
  608. MODULE_AUTHOR ("Dave Jones <davej@codemonkey.org.uk>");
  609. MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors.");
  610. MODULE_LICENSE ("GPL");
  611. late_initcall(longhaul_init);
  612. module_exit(longhaul_exit);