longhaul.c 19 KB

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