longhaul.c 20 KB

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