longhaul.c 20 KB

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