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