longhaul.c 21 KB

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