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