powernow-k7.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /*
  2. * AMD K7 Powernow driver.
  3. * (C) 2003 Dave Jones on behalf of SuSE Labs.
  4. * (C) 2003-2004 Dave Jones <davej@redhat.com>
  5. *
  6. * Licensed under the terms of the GNU GPL License version 2.
  7. * Based upon datasheets & sample CPUs kindly provided by AMD.
  8. *
  9. * Errata 5:
  10. * CPU may fail to execute a FID/VID change in presence of interrupt.
  11. * - We cli/sti on stepping A0 CPUs around the FID/VID transition.
  12. * Errata 15:
  13. * CPU with half frequency multipliers may hang upon wakeup from disconnect.
  14. * - We disable half multipliers if ACPI is used on A0 stepping CPUs.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/init.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/slab.h>
  22. #include <linux/string.h>
  23. #include <linux/dmi.h>
  24. #include <linux/timex.h>
  25. #include <linux/io.h>
  26. #include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */
  27. #include <asm/msr.h>
  28. #include <asm/system.h>
  29. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  30. #include <linux/acpi.h>
  31. #include <acpi/processor.h>
  32. #endif
  33. #include "powernow-k7.h"
  34. #define PFX "powernow: "
  35. struct psb_s {
  36. u8 signature[10];
  37. u8 tableversion;
  38. u8 flags;
  39. u16 settlingtime;
  40. u8 reserved1;
  41. u8 numpst;
  42. };
  43. struct pst_s {
  44. u32 cpuid;
  45. u8 fsbspeed;
  46. u8 maxfid;
  47. u8 startvid;
  48. u8 numpstates;
  49. };
  50. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  51. union powernow_acpi_control_t {
  52. struct {
  53. unsigned long fid:5,
  54. vid:5,
  55. sgtc:20,
  56. res1:2;
  57. } bits;
  58. unsigned long val;
  59. };
  60. #endif
  61. #ifdef CONFIG_CPU_FREQ_DEBUG
  62. /* divide by 1000 to get VCore voltage in V. */
  63. static const int mobile_vid_table[32] = {
  64. 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650,
  65. 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0,
  66. 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100,
  67. 1075, 1050, 1025, 1000, 975, 950, 925, 0,
  68. };
  69. #endif
  70. /* divide by 10 to get FID. */
  71. static const int fid_codes[32] = {
  72. 110, 115, 120, 125, 50, 55, 60, 65,
  73. 70, 75, 80, 85, 90, 95, 100, 105,
  74. 30, 190, 40, 200, 130, 135, 140, 210,
  75. 150, 225, 160, 165, 170, 180, -1, -1,
  76. };
  77. /* This parameter is used in order to force ACPI instead of legacy method for
  78. * configuration purpose.
  79. */
  80. static int acpi_force;
  81. static struct cpufreq_frequency_table *powernow_table;
  82. static unsigned int can_scale_bus;
  83. static unsigned int can_scale_vid;
  84. static unsigned int minimum_speed = -1;
  85. static unsigned int maximum_speed;
  86. static unsigned int number_scales;
  87. static unsigned int fsb;
  88. static unsigned int latency;
  89. static char have_a0;
  90. #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
  91. "powernow-k7", msg)
  92. static int check_fsb(unsigned int fsbspeed)
  93. {
  94. int delta;
  95. unsigned int f = fsb / 1000;
  96. delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed;
  97. return delta < 5;
  98. }
  99. static int check_powernow(void)
  100. {
  101. struct cpuinfo_x86 *c = &cpu_data(0);
  102. unsigned int maxei, eax, ebx, ecx, edx;
  103. if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) {
  104. #ifdef MODULE
  105. printk(KERN_INFO PFX "This module only works with "
  106. "AMD K7 CPUs\n");
  107. #endif
  108. return 0;
  109. }
  110. /* Get maximum capabilities */
  111. maxei = cpuid_eax(0x80000000);
  112. if (maxei < 0x80000007) { /* Any powernow info ? */
  113. #ifdef MODULE
  114. printk(KERN_INFO PFX "No powernow capabilities detected\n");
  115. #endif
  116. return 0;
  117. }
  118. if ((c->x86_model == 6) && (c->x86_mask == 0)) {
  119. printk(KERN_INFO PFX "K7 660[A0] core detected, "
  120. "enabling errata workarounds\n");
  121. have_a0 = 1;
  122. }
  123. cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
  124. /* Check we can actually do something before we say anything.*/
  125. if (!(edx & (1 << 1 | 1 << 2)))
  126. return 0;
  127. printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: ");
  128. if (edx & 1 << 1) {
  129. printk("frequency");
  130. can_scale_bus = 1;
  131. }
  132. if ((edx & (1 << 1 | 1 << 2)) == 0x6)
  133. printk(" and ");
  134. if (edx & 1 << 2) {
  135. printk("voltage");
  136. can_scale_vid = 1;
  137. }
  138. printk(".\n");
  139. return 1;
  140. }
  141. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  142. static void invalidate_entry(unsigned int entry)
  143. {
  144. powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
  145. }
  146. #endif
  147. static int get_ranges(unsigned char *pst)
  148. {
  149. unsigned int j;
  150. unsigned int speed;
  151. u8 fid, vid;
  152. powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
  153. (number_scales + 1)), GFP_KERNEL);
  154. if (!powernow_table)
  155. return -ENOMEM;
  156. for (j = 0 ; j < number_scales; j++) {
  157. fid = *pst++;
  158. powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
  159. powernow_table[j].index = fid; /* lower 8 bits */
  160. speed = powernow_table[j].frequency;
  161. if ((fid_codes[fid] % 10) == 5) {
  162. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  163. if (have_a0 == 1)
  164. invalidate_entry(j);
  165. #endif
  166. }
  167. if (speed < minimum_speed)
  168. minimum_speed = speed;
  169. if (speed > maximum_speed)
  170. maximum_speed = speed;
  171. vid = *pst++;
  172. powernow_table[j].index |= (vid << 8); /* upper 8 bits */
  173. dprintk(" FID: 0x%x (%d.%dx [%dMHz]) "
  174. "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
  175. fid_codes[fid] % 10, speed/1000, vid,
  176. mobile_vid_table[vid]/1000,
  177. mobile_vid_table[vid]%1000);
  178. }
  179. powernow_table[number_scales].frequency = CPUFREQ_TABLE_END;
  180. powernow_table[number_scales].index = 0;
  181. return 0;
  182. }
  183. static void change_FID(int fid)
  184. {
  185. union msr_fidvidctl fidvidctl;
  186. rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
  187. if (fidvidctl.bits.FID != fid) {
  188. fidvidctl.bits.SGTC = latency;
  189. fidvidctl.bits.FID = fid;
  190. fidvidctl.bits.VIDC = 0;
  191. fidvidctl.bits.FIDC = 1;
  192. wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
  193. }
  194. }
  195. static void change_VID(int vid)
  196. {
  197. union msr_fidvidctl fidvidctl;
  198. rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
  199. if (fidvidctl.bits.VID != vid) {
  200. fidvidctl.bits.SGTC = latency;
  201. fidvidctl.bits.VID = vid;
  202. fidvidctl.bits.FIDC = 0;
  203. fidvidctl.bits.VIDC = 1;
  204. wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
  205. }
  206. }
  207. static void change_speed(unsigned int index)
  208. {
  209. u8 fid, vid;
  210. struct cpufreq_freqs freqs;
  211. union msr_fidvidstatus fidvidstatus;
  212. int cfid;
  213. /* fid are the lower 8 bits of the index we stored into
  214. * the cpufreq frequency table in powernow_decode_bios,
  215. * vid are the upper 8 bits.
  216. */
  217. fid = powernow_table[index].index & 0xFF;
  218. vid = (powernow_table[index].index & 0xFF00) >> 8;
  219. freqs.cpu = 0;
  220. rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
  221. cfid = fidvidstatus.bits.CFID;
  222. freqs.old = fsb * fid_codes[cfid] / 10;
  223. freqs.new = powernow_table[index].frequency;
  224. cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
  225. /* Now do the magic poking into the MSRs. */
  226. if (have_a0 == 1) /* A0 errata 5 */
  227. local_irq_disable();
  228. if (freqs.old > freqs.new) {
  229. /* Going down, so change FID first */
  230. change_FID(fid);
  231. change_VID(vid);
  232. } else {
  233. /* Going up, so change VID first */
  234. change_VID(vid);
  235. change_FID(fid);
  236. }
  237. if (have_a0 == 1)
  238. local_irq_enable();
  239. cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
  240. }
  241. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  242. static struct acpi_processor_performance *acpi_processor_perf;
  243. static int powernow_acpi_init(void)
  244. {
  245. int i;
  246. int retval = 0;
  247. union powernow_acpi_control_t pc;
  248. if (acpi_processor_perf != NULL && powernow_table != NULL) {
  249. retval = -EINVAL;
  250. goto err0;
  251. }
  252. acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance),
  253. GFP_KERNEL);
  254. if (!acpi_processor_perf) {
  255. retval = -ENOMEM;
  256. goto err0;
  257. }
  258. if (!zalloc_cpumask_var(&acpi_processor_perf->shared_cpu_map,
  259. GFP_KERNEL)) {
  260. retval = -ENOMEM;
  261. goto err05;
  262. }
  263. if (acpi_processor_register_performance(acpi_processor_perf, 0)) {
  264. retval = -EIO;
  265. goto err1;
  266. }
  267. if (acpi_processor_perf->control_register.space_id !=
  268. ACPI_ADR_SPACE_FIXED_HARDWARE) {
  269. retval = -ENODEV;
  270. goto err2;
  271. }
  272. if (acpi_processor_perf->status_register.space_id !=
  273. ACPI_ADR_SPACE_FIXED_HARDWARE) {
  274. retval = -ENODEV;
  275. goto err2;
  276. }
  277. number_scales = acpi_processor_perf->state_count;
  278. if (number_scales < 2) {
  279. retval = -ENODEV;
  280. goto err2;
  281. }
  282. powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
  283. (number_scales + 1)), GFP_KERNEL);
  284. if (!powernow_table) {
  285. retval = -ENOMEM;
  286. goto err2;
  287. }
  288. pc.val = (unsigned long) acpi_processor_perf->states[0].control;
  289. for (i = 0; i < number_scales; i++) {
  290. u8 fid, vid;
  291. struct acpi_processor_px *state =
  292. &acpi_processor_perf->states[i];
  293. unsigned int speed, speed_mhz;
  294. pc.val = (unsigned long) state->control;
  295. dprintk("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n",
  296. i,
  297. (u32) state->core_frequency,
  298. (u32) state->power,
  299. (u32) state->transition_latency,
  300. (u32) state->control,
  301. pc.bits.sgtc);
  302. vid = pc.bits.vid;
  303. fid = pc.bits.fid;
  304. powernow_table[i].frequency = fsb * fid_codes[fid] / 10;
  305. powernow_table[i].index = fid; /* lower 8 bits */
  306. powernow_table[i].index |= (vid << 8); /* upper 8 bits */
  307. speed = powernow_table[i].frequency;
  308. speed_mhz = speed / 1000;
  309. /* processor_perflib will multiply the MHz value by 1000 to
  310. * get a KHz value (e.g. 1266000). However, powernow-k7 works
  311. * with true KHz values (e.g. 1266768). To ensure that all
  312. * powernow frequencies are available, we must ensure that
  313. * ACPI doesn't restrict them, so we round up the MHz value
  314. * to ensure that perflib's computed KHz value is greater than
  315. * or equal to powernow's KHz value.
  316. */
  317. if (speed % 1000 > 0)
  318. speed_mhz++;
  319. if ((fid_codes[fid] % 10) == 5) {
  320. if (have_a0 == 1)
  321. invalidate_entry(i);
  322. }
  323. dprintk(" FID: 0x%x (%d.%dx [%dMHz]) "
  324. "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
  325. fid_codes[fid] % 10, speed_mhz, vid,
  326. mobile_vid_table[vid]/1000,
  327. mobile_vid_table[vid]%1000);
  328. if (state->core_frequency != speed_mhz) {
  329. state->core_frequency = speed_mhz;
  330. dprintk(" Corrected ACPI frequency to %d\n",
  331. speed_mhz);
  332. }
  333. if (latency < pc.bits.sgtc)
  334. latency = pc.bits.sgtc;
  335. if (speed < minimum_speed)
  336. minimum_speed = speed;
  337. if (speed > maximum_speed)
  338. maximum_speed = speed;
  339. }
  340. powernow_table[i].frequency = CPUFREQ_TABLE_END;
  341. powernow_table[i].index = 0;
  342. /* notify BIOS that we exist */
  343. acpi_processor_notify_smm(THIS_MODULE);
  344. return 0;
  345. err2:
  346. acpi_processor_unregister_performance(acpi_processor_perf, 0);
  347. err1:
  348. free_cpumask_var(acpi_processor_perf->shared_cpu_map);
  349. err05:
  350. kfree(acpi_processor_perf);
  351. err0:
  352. printk(KERN_WARNING PFX "ACPI perflib can not be used on "
  353. "this platform\n");
  354. acpi_processor_perf = NULL;
  355. return retval;
  356. }
  357. #else
  358. static int powernow_acpi_init(void)
  359. {
  360. printk(KERN_INFO PFX "no support for ACPI processor found."
  361. " Please recompile your kernel with ACPI processor\n");
  362. return -EINVAL;
  363. }
  364. #endif
  365. static void print_pst_entry(struct pst_s *pst, unsigned int j)
  366. {
  367. dprintk("PST:%d (@%p)\n", j, pst);
  368. dprintk(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n",
  369. pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid);
  370. }
  371. static int powernow_decode_bios(int maxfid, int startvid)
  372. {
  373. struct psb_s *psb;
  374. struct pst_s *pst;
  375. unsigned int i, j;
  376. unsigned char *p;
  377. unsigned int etuple;
  378. unsigned int ret;
  379. etuple = cpuid_eax(0x80000001);
  380. for (i = 0xC0000; i < 0xffff0 ; i += 16) {
  381. p = phys_to_virt(i);
  382. if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
  383. dprintk("Found PSB header at %p\n", p);
  384. psb = (struct psb_s *) p;
  385. dprintk("Table version: 0x%x\n", psb->tableversion);
  386. if (psb->tableversion != 0x12) {
  387. printk(KERN_INFO PFX "Sorry, only v1.2 tables"
  388. " supported right now\n");
  389. return -ENODEV;
  390. }
  391. dprintk("Flags: 0x%x\n", psb->flags);
  392. if ((psb->flags & 1) == 0)
  393. dprintk("Mobile voltage regulator\n");
  394. else
  395. dprintk("Desktop voltage regulator\n");
  396. latency = psb->settlingtime;
  397. if (latency < 100) {
  398. printk(KERN_INFO PFX "BIOS set settling time "
  399. "to %d microseconds. "
  400. "Should be at least 100. "
  401. "Correcting.\n", latency);
  402. latency = 100;
  403. }
  404. dprintk("Settling Time: %d microseconds.\n",
  405. psb->settlingtime);
  406. dprintk("Has %d PST tables. (Only dumping ones "
  407. "relevant to this CPU).\n",
  408. psb->numpst);
  409. p += sizeof(struct psb_s);
  410. pst = (struct pst_s *) p;
  411. for (j = 0; j < psb->numpst; j++) {
  412. pst = (struct pst_s *) p;
  413. number_scales = pst->numpstates;
  414. if ((etuple == pst->cpuid) &&
  415. check_fsb(pst->fsbspeed) &&
  416. (maxfid == pst->maxfid) &&
  417. (startvid == pst->startvid)) {
  418. print_pst_entry(pst, j);
  419. p = (char *)pst + sizeof(struct pst_s);
  420. ret = get_ranges(p);
  421. return ret;
  422. } else {
  423. unsigned int k;
  424. p = (char *)pst + sizeof(struct pst_s);
  425. for (k = 0; k < number_scales; k++)
  426. p += 2;
  427. }
  428. }
  429. printk(KERN_INFO PFX "No PST tables match this cpuid "
  430. "(0x%x)\n", etuple);
  431. printk(KERN_INFO PFX "This is indicative of a broken "
  432. "BIOS.\n");
  433. return -EINVAL;
  434. }
  435. p++;
  436. }
  437. return -ENODEV;
  438. }
  439. static int powernow_target(struct cpufreq_policy *policy,
  440. unsigned int target_freq,
  441. unsigned int relation)
  442. {
  443. unsigned int newstate;
  444. if (cpufreq_frequency_table_target(policy, powernow_table, target_freq,
  445. relation, &newstate))
  446. return -EINVAL;
  447. change_speed(newstate);
  448. return 0;
  449. }
  450. static int powernow_verify(struct cpufreq_policy *policy)
  451. {
  452. return cpufreq_frequency_table_verify(policy, powernow_table);
  453. }
  454. /*
  455. * We use the fact that the bus frequency is somehow
  456. * a multiple of 100000/3 khz, then we compute sgtc according
  457. * to this multiple.
  458. * That way, we match more how AMD thinks all of that work.
  459. * We will then get the same kind of behaviour already tested under
  460. * the "well-known" other OS.
  461. */
  462. static int __init fixup_sgtc(void)
  463. {
  464. unsigned int sgtc;
  465. unsigned int m;
  466. m = fsb / 3333;
  467. if ((m % 10) >= 5)
  468. m += 5;
  469. m /= 10;
  470. sgtc = 100 * m * latency;
  471. sgtc = sgtc / 3;
  472. if (sgtc > 0xfffff) {
  473. printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc);
  474. sgtc = 0xfffff;
  475. }
  476. return sgtc;
  477. }
  478. static unsigned int powernow_get(unsigned int cpu)
  479. {
  480. union msr_fidvidstatus fidvidstatus;
  481. unsigned int cfid;
  482. if (cpu)
  483. return 0;
  484. rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
  485. cfid = fidvidstatus.bits.CFID;
  486. return fsb * fid_codes[cfid] / 10;
  487. }
  488. static int __init acer_cpufreq_pst(const struct dmi_system_id *d)
  489. {
  490. printk(KERN_WARNING PFX
  491. "%s laptop with broken PST tables in BIOS detected.\n",
  492. d->ident);
  493. printk(KERN_WARNING PFX
  494. "You need to downgrade to 3A21 (09/09/2002), or try a newer "
  495. "BIOS than 3A71 (01/20/2003)\n");
  496. printk(KERN_WARNING PFX
  497. "cpufreq scaling has been disabled as a result of this.\n");
  498. return 0;
  499. }
  500. /*
  501. * Some Athlon laptops have really fucked PST tables.
  502. * A BIOS update is all that can save them.
  503. * Mention this, and disable cpufreq.
  504. */
  505. static struct dmi_system_id __initdata powernow_dmi_table[] = {
  506. {
  507. .callback = acer_cpufreq_pst,
  508. .ident = "Acer Aspire",
  509. .matches = {
  510. DMI_MATCH(DMI_SYS_VENDOR, "Insyde Software"),
  511. DMI_MATCH(DMI_BIOS_VERSION, "3A71"),
  512. },
  513. },
  514. { }
  515. };
  516. static int __init powernow_cpu_init(struct cpufreq_policy *policy)
  517. {
  518. union msr_fidvidstatus fidvidstatus;
  519. int result;
  520. if (policy->cpu != 0)
  521. return -ENODEV;
  522. rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
  523. recalibrate_cpu_khz();
  524. fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.CFID];
  525. if (!fsb) {
  526. printk(KERN_WARNING PFX "can not determine bus frequency\n");
  527. return -EINVAL;
  528. }
  529. dprintk("FSB: %3dMHz\n", fsb/1000);
  530. if (dmi_check_system(powernow_dmi_table) || acpi_force) {
  531. printk(KERN_INFO PFX "PSB/PST known to be broken. "
  532. "Trying ACPI instead\n");
  533. result = powernow_acpi_init();
  534. } else {
  535. result = powernow_decode_bios(fidvidstatus.bits.MFID,
  536. fidvidstatus.bits.SVID);
  537. if (result) {
  538. printk(KERN_INFO PFX "Trying ACPI perflib\n");
  539. maximum_speed = 0;
  540. minimum_speed = -1;
  541. latency = 0;
  542. result = powernow_acpi_init();
  543. if (result) {
  544. printk(KERN_INFO PFX
  545. "ACPI and legacy methods failed\n");
  546. }
  547. } else {
  548. /* SGTC use the bus clock as timer */
  549. latency = fixup_sgtc();
  550. printk(KERN_INFO PFX "SGTC: %d\n", latency);
  551. }
  552. }
  553. if (result)
  554. return result;
  555. printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
  556. minimum_speed/1000, maximum_speed/1000);
  557. policy->cpuinfo.transition_latency =
  558. cpufreq_scale(2000000UL, fsb, latency);
  559. policy->cur = powernow_get(0);
  560. cpufreq_frequency_table_get_attr(powernow_table, policy->cpu);
  561. return cpufreq_frequency_table_cpuinfo(policy, powernow_table);
  562. }
  563. static int powernow_cpu_exit(struct cpufreq_policy *policy)
  564. {
  565. cpufreq_frequency_table_put_attr(policy->cpu);
  566. #ifdef CONFIG_X86_POWERNOW_K7_ACPI
  567. if (acpi_processor_perf) {
  568. acpi_processor_unregister_performance(acpi_processor_perf, 0);
  569. free_cpumask_var(acpi_processor_perf->shared_cpu_map);
  570. kfree(acpi_processor_perf);
  571. }
  572. #endif
  573. kfree(powernow_table);
  574. return 0;
  575. }
  576. static struct freq_attr *powernow_table_attr[] = {
  577. &cpufreq_freq_attr_scaling_available_freqs,
  578. NULL,
  579. };
  580. static struct cpufreq_driver powernow_driver = {
  581. .verify = powernow_verify,
  582. .target = powernow_target,
  583. .get = powernow_get,
  584. .init = powernow_cpu_init,
  585. .exit = powernow_cpu_exit,
  586. .name = "powernow-k7",
  587. .owner = THIS_MODULE,
  588. .attr = powernow_table_attr,
  589. };
  590. static int __init powernow_init(void)
  591. {
  592. if (check_powernow() == 0)
  593. return -ENODEV;
  594. return cpufreq_register_driver(&powernow_driver);
  595. }
  596. static void __exit powernow_exit(void)
  597. {
  598. cpufreq_unregister_driver(&powernow_driver);
  599. }
  600. module_param(acpi_force, int, 0444);
  601. MODULE_PARM_DESC(acpi_force, "Force ACPI to be used.");
  602. MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
  603. MODULE_DESCRIPTION("Powernow driver for AMD K7 processors.");
  604. MODULE_LICENSE("GPL");
  605. late_initcall(powernow_init);
  606. module_exit(powernow_exit);