longhaul.c 20 KB

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