pmac64-cpufreq.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <[email protected]>
  4. * and Markus Demleitner <[email protected]>
  5. *
  6. * This driver adds basic cpufreq support for SMU & 970FX based G5 Macs,
  7. * that is iMac G5 and latest single CPU desktop.
  8. */
  9. #undef DEBUG
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/errno.h>
  14. #include <linux/kernel.h>
  15. #include <linux/delay.h>
  16. #include <linux/sched.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/init.h>
  19. #include <linux/completion.h>
  20. #include <linux/mutex.h>
  21. #include <linux/of_device.h>
  22. #include <asm/machdep.h>
  23. #include <asm/irq.h>
  24. #include <asm/sections.h>
  25. #include <asm/cputable.h>
  26. #include <asm/time.h>
  27. #include <asm/smu.h>
  28. #include <asm/pmac_pfunc.h>
  29. #define DBG(fmt...) pr_debug(fmt)
  30. /* see 970FX user manual */
  31. #define SCOM_PCR 0x0aa001 /* PCR scom addr */
  32. #define PCR_HILO_SELECT 0x80000000U /* 1 = PCR, 0 = PCRH */
  33. #define PCR_SPEED_FULL 0x00000000U /* 1:1 speed value */
  34. #define PCR_SPEED_HALF 0x00020000U /* 1:2 speed value */
  35. #define PCR_SPEED_QUARTER 0x00040000U /* 1:4 speed value */
  36. #define PCR_SPEED_MASK 0x000e0000U /* speed mask */
  37. #define PCR_SPEED_SHIFT 17
  38. #define PCR_FREQ_REQ_VALID 0x00010000U /* freq request valid */
  39. #define PCR_VOLT_REQ_VALID 0x00008000U /* volt request valid */
  40. #define PCR_TARGET_TIME_MASK 0x00006000U /* target time */
  41. #define PCR_STATLAT_MASK 0x00001f00U /* STATLAT value */
  42. #define PCR_SNOOPLAT_MASK 0x000000f0U /* SNOOPLAT value */
  43. #define PCR_SNOOPACC_MASK 0x0000000fU /* SNOOPACC value */
  44. #define SCOM_PSR 0x408001 /* PSR scom addr */
  45. /* warning: PSR is a 64 bits register */
  46. #define PSR_CMD_RECEIVED 0x2000000000000000U /* command received */
  47. #define PSR_CMD_COMPLETED 0x1000000000000000U /* command completed */
  48. #define PSR_CUR_SPEED_MASK 0x0300000000000000U /* current speed */
  49. #define PSR_CUR_SPEED_SHIFT (56)
  50. /*
  51. * The G5 only supports two frequencies (Quarter speed is not supported)
  52. */
  53. #define CPUFREQ_HIGH 0
  54. #define CPUFREQ_LOW 1
  55. static struct cpufreq_frequency_table g5_cpu_freqs[] = {
  56. {0, CPUFREQ_HIGH, 0},
  57. {0, CPUFREQ_LOW, 0},
  58. {0, 0, CPUFREQ_TABLE_END},
  59. };
  60. /* Power mode data is an array of the 32 bits PCR values to use for
  61. * the various frequencies, retrieved from the device-tree
  62. */
  63. static int g5_pmode_cur;
  64. static void (*g5_switch_volt)(int speed_mode);
  65. static int (*g5_switch_freq)(int speed_mode);
  66. static int (*g5_query_freq)(void);
  67. static unsigned long transition_latency;
  68. #ifdef CONFIG_PMAC_SMU
  69. static const u32 *g5_pmode_data;
  70. static int g5_pmode_max;
  71. static struct smu_sdbp_fvt *g5_fvt_table; /* table of op. points */
  72. static int g5_fvt_count; /* number of op. points */
  73. static int g5_fvt_cur; /* current op. point */
  74. /*
  75. * SMU based voltage switching for Neo2 platforms
  76. */
  77. static void g5_smu_switch_volt(int speed_mode)
  78. {
  79. struct smu_simple_cmd cmd;
  80. DECLARE_COMPLETION_ONSTACK(comp);
  81. smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 8, smu_done_complete,
  82. &comp, 'V', 'S', 'L', 'E', 'W',
  83. 0xff, g5_fvt_cur+1, speed_mode);
  84. wait_for_completion(&comp);
  85. }
  86. /*
  87. * Platform function based voltage/vdnap switching for Neo2
  88. */
  89. static struct pmf_function *pfunc_set_vdnap0;
  90. static struct pmf_function *pfunc_vdnap0_complete;
  91. static void g5_vdnap_switch_volt(int speed_mode)
  92. {
  93. struct pmf_args args;
  94. u32 slew, done = 0;
  95. unsigned long timeout;
  96. slew = (speed_mode == CPUFREQ_LOW) ? 1 : 0;
  97. args.count = 1;
  98. args.u[0].p = &slew;
  99. pmf_call_one(pfunc_set_vdnap0, &args);
  100. /* It's an irq GPIO so we should be able to just block here,
  101. * I'll do that later after I've properly tested the IRQ code for
  102. * platform functions
  103. */
  104. timeout = jiffies + HZ/10;
  105. while(!time_after(jiffies, timeout)) {
  106. args.count = 1;
  107. args.u[0].p = &done;
  108. pmf_call_one(pfunc_vdnap0_complete, &args);
  109. if (done)
  110. break;
  111. usleep_range(1000, 1000);
  112. }
  113. if (done == 0)
  114. pr_warn("Timeout in clock slewing !\n");
  115. }
  116. /*
  117. * SCOM based frequency switching for 970FX rev3
  118. */
  119. static int g5_scom_switch_freq(int speed_mode)
  120. {
  121. unsigned long flags;
  122. int to;
  123. /* If frequency is going up, first ramp up the voltage */
  124. if (speed_mode < g5_pmode_cur)
  125. g5_switch_volt(speed_mode);
  126. local_irq_save(flags);
  127. /* Clear PCR high */
  128. scom970_write(SCOM_PCR, 0);
  129. /* Clear PCR low */
  130. scom970_write(SCOM_PCR, PCR_HILO_SELECT | 0);
  131. /* Set PCR low */
  132. scom970_write(SCOM_PCR, PCR_HILO_SELECT |
  133. g5_pmode_data[speed_mode]);
  134. /* Wait for completion */
  135. for (to = 0; to < 10; to++) {
  136. unsigned long psr = scom970_read(SCOM_PSR);
  137. if ((psr & PSR_CMD_RECEIVED) == 0 &&
  138. (((psr >> PSR_CUR_SPEED_SHIFT) ^
  139. (g5_pmode_data[speed_mode] >> PCR_SPEED_SHIFT)) & 0x3)
  140. == 0)
  141. break;
  142. if (psr & PSR_CMD_COMPLETED)
  143. break;
  144. udelay(100);
  145. }
  146. local_irq_restore(flags);
  147. /* If frequency is going down, last ramp the voltage */
  148. if (speed_mode > g5_pmode_cur)
  149. g5_switch_volt(speed_mode);
  150. g5_pmode_cur = speed_mode;
  151. ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
  152. return 0;
  153. }
  154. static int g5_scom_query_freq(void)
  155. {
  156. unsigned long psr = scom970_read(SCOM_PSR);
  157. int i;
  158. for (i = 0; i <= g5_pmode_max; i++)
  159. if ((((psr >> PSR_CUR_SPEED_SHIFT) ^
  160. (g5_pmode_data[i] >> PCR_SPEED_SHIFT)) & 0x3) == 0)
  161. break;
  162. return i;
  163. }
  164. /*
  165. * Fake voltage switching for platforms with missing support
  166. */
  167. static void g5_dummy_switch_volt(int speed_mode)
  168. {
  169. }
  170. #endif /* CONFIG_PMAC_SMU */
  171. /*
  172. * Platform function based voltage switching for PowerMac7,2 & 7,3
  173. */
  174. static struct pmf_function *pfunc_cpu0_volt_high;
  175. static struct pmf_function *pfunc_cpu0_volt_low;
  176. static struct pmf_function *pfunc_cpu1_volt_high;
  177. static struct pmf_function *pfunc_cpu1_volt_low;
  178. static void g5_pfunc_switch_volt(int speed_mode)
  179. {
  180. if (speed_mode == CPUFREQ_HIGH) {
  181. if (pfunc_cpu0_volt_high)
  182. pmf_call_one(pfunc_cpu0_volt_high, NULL);
  183. if (pfunc_cpu1_volt_high)
  184. pmf_call_one(pfunc_cpu1_volt_high, NULL);
  185. } else {
  186. if (pfunc_cpu0_volt_low)
  187. pmf_call_one(pfunc_cpu0_volt_low, NULL);
  188. if (pfunc_cpu1_volt_low)
  189. pmf_call_one(pfunc_cpu1_volt_low, NULL);
  190. }
  191. usleep_range(10000, 10000); /* should be faster , to fix */
  192. }
  193. /*
  194. * Platform function based frequency switching for PowerMac7,2 & 7,3
  195. */
  196. static struct pmf_function *pfunc_cpu_setfreq_high;
  197. static struct pmf_function *pfunc_cpu_setfreq_low;
  198. static struct pmf_function *pfunc_cpu_getfreq;
  199. static struct pmf_function *pfunc_slewing_done;
  200. static int g5_pfunc_switch_freq(int speed_mode)
  201. {
  202. struct pmf_args args;
  203. u32 done = 0;
  204. unsigned long timeout;
  205. int rc;
  206. DBG("g5_pfunc_switch_freq(%d)\n", speed_mode);
  207. /* If frequency is going up, first ramp up the voltage */
  208. if (speed_mode < g5_pmode_cur)
  209. g5_switch_volt(speed_mode);
  210. /* Do it */
  211. if (speed_mode == CPUFREQ_HIGH)
  212. rc = pmf_call_one(pfunc_cpu_setfreq_high, NULL);
  213. else
  214. rc = pmf_call_one(pfunc_cpu_setfreq_low, NULL);
  215. if (rc)
  216. pr_warn("pfunc switch error %d\n", rc);
  217. /* It's an irq GPIO so we should be able to just block here,
  218. * I'll do that later after I've properly tested the IRQ code for
  219. * platform functions
  220. */
  221. timeout = jiffies + HZ/10;
  222. while(!time_after(jiffies, timeout)) {
  223. args.count = 1;
  224. args.u[0].p = &done;
  225. pmf_call_one(pfunc_slewing_done, &args);
  226. if (done)
  227. break;
  228. usleep_range(500, 500);
  229. }
  230. if (done == 0)
  231. pr_warn("Timeout in clock slewing !\n");
  232. /* If frequency is going down, last ramp the voltage */
  233. if (speed_mode > g5_pmode_cur)
  234. g5_switch_volt(speed_mode);
  235. g5_pmode_cur = speed_mode;
  236. ppc_proc_freq = g5_cpu_freqs[speed_mode].frequency * 1000ul;
  237. return 0;
  238. }
  239. static int g5_pfunc_query_freq(void)
  240. {
  241. struct pmf_args args;
  242. u32 val = 0;
  243. args.count = 1;
  244. args.u[0].p = &val;
  245. pmf_call_one(pfunc_cpu_getfreq, &args);
  246. return val ? CPUFREQ_HIGH : CPUFREQ_LOW;
  247. }
  248. /*
  249. * Common interface to the cpufreq core
  250. */
  251. static int g5_cpufreq_target(struct cpufreq_policy *policy, unsigned int index)
  252. {
  253. return g5_switch_freq(index);
  254. }
  255. static unsigned int g5_cpufreq_get_speed(unsigned int cpu)
  256. {
  257. return g5_cpu_freqs[g5_pmode_cur].frequency;
  258. }
  259. static int g5_cpufreq_cpu_init(struct cpufreq_policy *policy)
  260. {
  261. cpufreq_generic_init(policy, g5_cpu_freqs, transition_latency);
  262. return 0;
  263. }
  264. static struct cpufreq_driver g5_cpufreq_driver = {
  265. .name = "powermac",
  266. .flags = CPUFREQ_CONST_LOOPS,
  267. .init = g5_cpufreq_cpu_init,
  268. .verify = cpufreq_generic_frequency_table_verify,
  269. .target_index = g5_cpufreq_target,
  270. .get = g5_cpufreq_get_speed,
  271. .attr = cpufreq_generic_attr,
  272. };
  273. #ifdef CONFIG_PMAC_SMU
  274. static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
  275. {
  276. unsigned int psize, ssize;
  277. unsigned long max_freq;
  278. char *freq_method, *volt_method;
  279. const u32 *valp;
  280. u32 pvr_hi;
  281. int use_volts_vdnap = 0;
  282. int use_volts_smu = 0;
  283. int rc = -ENODEV;
  284. /* Check supported platforms */
  285. if (of_machine_is_compatible("PowerMac8,1") ||
  286. of_machine_is_compatible("PowerMac8,2") ||
  287. of_machine_is_compatible("PowerMac9,1") ||
  288. of_machine_is_compatible("PowerMac12,1"))
  289. use_volts_smu = 1;
  290. else if (of_machine_is_compatible("PowerMac11,2"))
  291. use_volts_vdnap = 1;
  292. else
  293. return -ENODEV;
  294. /* Check 970FX for now */
  295. valp = of_get_property(cpunode, "cpu-version", NULL);
  296. if (!valp) {
  297. DBG("No cpu-version property !\n");
  298. goto bail_noprops;
  299. }
  300. pvr_hi = (*valp) >> 16;
  301. if (pvr_hi != 0x3c && pvr_hi != 0x44) {
  302. pr_err("Unsupported CPU version\n");
  303. goto bail_noprops;
  304. }
  305. /* Look for the powertune data in the device-tree */
  306. g5_pmode_data = of_get_property(cpunode, "power-mode-data",&psize);
  307. if (!g5_pmode_data) {
  308. DBG("No power-mode-data !\n");
  309. goto bail_noprops;
  310. }
  311. g5_pmode_max = psize / sizeof(u32) - 1;
  312. if (use_volts_smu) {
  313. const struct smu_sdbp_header *shdr;
  314. /* Look for the FVT table */
  315. shdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
  316. if (!shdr)
  317. goto bail_noprops;
  318. g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
  319. ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
  320. g5_fvt_count = ssize / sizeof(*g5_fvt_table);
  321. g5_fvt_cur = 0;
  322. /* Sanity checking */
  323. if (g5_fvt_count < 1 || g5_pmode_max < 1)
  324. goto bail_noprops;
  325. g5_switch_volt = g5_smu_switch_volt;
  326. volt_method = "SMU";
  327. } else if (use_volts_vdnap) {
  328. struct device_node *root;
  329. root = of_find_node_by_path("/");
  330. if (root == NULL) {
  331. pr_err("Can't find root of device tree\n");
  332. goto bail_noprops;
  333. }
  334. pfunc_set_vdnap0 = pmf_find_function(root, "set-vdnap0");
  335. pfunc_vdnap0_complete =
  336. pmf_find_function(root, "slewing-done");
  337. of_node_put(root);
  338. if (pfunc_set_vdnap0 == NULL ||
  339. pfunc_vdnap0_complete == NULL) {
  340. pr_err("Can't find required platform function\n");
  341. goto bail_noprops;
  342. }
  343. g5_switch_volt = g5_vdnap_switch_volt;
  344. volt_method = "GPIO";
  345. } else {
  346. g5_switch_volt = g5_dummy_switch_volt;
  347. volt_method = "none";
  348. }
  349. /*
  350. * From what I see, clock-frequency is always the maximal frequency.
  351. * The current driver can not slew sysclk yet, so we really only deal
  352. * with powertune steps for now. We also only implement full freq and
  353. * half freq in this version. So far, I haven't yet seen a machine
  354. * supporting anything else.
  355. */
  356. valp = of_get_property(cpunode, "clock-frequency", NULL);
  357. if (!valp)
  358. return -ENODEV;
  359. max_freq = (*valp)/1000;
  360. g5_cpu_freqs[0].frequency = max_freq;
  361. g5_cpu_freqs[1].frequency = max_freq/2;
  362. /* Set callbacks */
  363. transition_latency = 12000;
  364. g5_switch_freq = g5_scom_switch_freq;
  365. g5_query_freq = g5_scom_query_freq;
  366. freq_method = "SCOM";
  367. /* Force apply current frequency to make sure everything is in
  368. * sync (voltage is right for example). Firmware may leave us with
  369. * a strange setting ...
  370. */
  371. g5_switch_volt(CPUFREQ_HIGH);
  372. msleep(10);
  373. g5_pmode_cur = -1;
  374. g5_switch_freq(g5_query_freq());
  375. pr_info("Registering G5 CPU frequency driver\n");
  376. pr_info("Frequency method: %s, Voltage method: %s\n",
  377. freq_method, volt_method);
  378. pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
  379. g5_cpu_freqs[1].frequency/1000,
  380. g5_cpu_freqs[0].frequency/1000,
  381. g5_cpu_freqs[g5_pmode_cur].frequency/1000);
  382. rc = cpufreq_register_driver(&g5_cpufreq_driver);
  383. /* We keep the CPU node on hold... hopefully, Apple G5 don't have
  384. * hotplug CPU with a dynamic device-tree ...
  385. */
  386. return rc;
  387. bail_noprops:
  388. of_node_put(cpunode);
  389. return rc;
  390. }
  391. #endif /* CONFIG_PMAC_SMU */
  392. static int __init g5_pm72_cpufreq_init(struct device_node *cpunode)
  393. {
  394. struct device_node *cpuid = NULL, *hwclock = NULL;
  395. const u8 *eeprom = NULL;
  396. const u32 *valp;
  397. u64 max_freq, min_freq, ih, il;
  398. int has_volt = 1, rc = 0;
  399. DBG("cpufreq: Initializing for PowerMac7,2, PowerMac7,3 and"
  400. " RackMac3,1...\n");
  401. /* Lookup the cpuid eeprom node */
  402. cpuid = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/cpuid@a0");
  403. if (cpuid != NULL)
  404. eeprom = of_get_property(cpuid, "cpuid", NULL);
  405. if (eeprom == NULL) {
  406. pr_err("Can't find cpuid EEPROM !\n");
  407. rc = -ENODEV;
  408. goto bail;
  409. }
  410. /* Lookup the i2c hwclock */
  411. for_each_node_by_name(hwclock, "i2c-hwclock") {
  412. const char *loc = of_get_property(hwclock,
  413. "hwctrl-location", NULL);
  414. if (loc == NULL)
  415. continue;
  416. if (strcmp(loc, "CPU CLOCK"))
  417. continue;
  418. if (!of_get_property(hwclock, "platform-get-frequency", NULL))
  419. continue;
  420. break;
  421. }
  422. if (hwclock == NULL) {
  423. pr_err("Can't find i2c clock chip !\n");
  424. rc = -ENODEV;
  425. goto bail;
  426. }
  427. DBG("cpufreq: i2c clock chip found: %pOF\n", hwclock);
  428. /* Now get all the platform functions */
  429. pfunc_cpu_getfreq =
  430. pmf_find_function(hwclock, "get-frequency");
  431. pfunc_cpu_setfreq_high =
  432. pmf_find_function(hwclock, "set-frequency-high");
  433. pfunc_cpu_setfreq_low =
  434. pmf_find_function(hwclock, "set-frequency-low");
  435. pfunc_slewing_done =
  436. pmf_find_function(hwclock, "slewing-done");
  437. pfunc_cpu0_volt_high =
  438. pmf_find_function(hwclock, "set-voltage-high-0");
  439. pfunc_cpu0_volt_low =
  440. pmf_find_function(hwclock, "set-voltage-low-0");
  441. pfunc_cpu1_volt_high =
  442. pmf_find_function(hwclock, "set-voltage-high-1");
  443. pfunc_cpu1_volt_low =
  444. pmf_find_function(hwclock, "set-voltage-low-1");
  445. /* Check we have minimum requirements */
  446. if (pfunc_cpu_getfreq == NULL || pfunc_cpu_setfreq_high == NULL ||
  447. pfunc_cpu_setfreq_low == NULL || pfunc_slewing_done == NULL) {
  448. pr_err("Can't find platform functions !\n");
  449. rc = -ENODEV;
  450. goto bail;
  451. }
  452. /* Check that we have complete sets */
  453. if (pfunc_cpu0_volt_high == NULL || pfunc_cpu0_volt_low == NULL) {
  454. pmf_put_function(pfunc_cpu0_volt_high);
  455. pmf_put_function(pfunc_cpu0_volt_low);
  456. pfunc_cpu0_volt_high = pfunc_cpu0_volt_low = NULL;
  457. has_volt = 0;
  458. }
  459. if (!has_volt ||
  460. pfunc_cpu1_volt_high == NULL || pfunc_cpu1_volt_low == NULL) {
  461. pmf_put_function(pfunc_cpu1_volt_high);
  462. pmf_put_function(pfunc_cpu1_volt_low);
  463. pfunc_cpu1_volt_high = pfunc_cpu1_volt_low = NULL;
  464. }
  465. /* Note: The device tree also contains a "platform-set-values"
  466. * function for which I haven't quite figured out the usage. It
  467. * might have to be called on init and/or wakeup, I'm not too sure
  468. * but things seem to work fine without it so far ...
  469. */
  470. /* Get max frequency from device-tree */
  471. valp = of_get_property(cpunode, "clock-frequency", NULL);
  472. if (!valp) {
  473. pr_err("Can't find CPU frequency !\n");
  474. rc = -ENODEV;
  475. goto bail;
  476. }
  477. max_freq = (*valp)/1000;
  478. /* Now calculate reduced frequency by using the cpuid input freq
  479. * ratio. This requires 64 bits math unless we are willing to lose
  480. * some precision
  481. */
  482. ih = *((u32 *)(eeprom + 0x10));
  483. il = *((u32 *)(eeprom + 0x20));
  484. /* Check for machines with no useful settings */
  485. if (il == ih) {
  486. pr_warn("No low frequency mode available on this model !\n");
  487. rc = -ENODEV;
  488. goto bail;
  489. }
  490. min_freq = 0;
  491. if (ih != 0 && il != 0)
  492. min_freq = (max_freq * il) / ih;
  493. /* Sanity check */
  494. if (min_freq >= max_freq || min_freq < 1000) {
  495. pr_err("Can't calculate low frequency !\n");
  496. rc = -ENXIO;
  497. goto bail;
  498. }
  499. g5_cpu_freqs[0].frequency = max_freq;
  500. g5_cpu_freqs[1].frequency = min_freq;
  501. /* Based on a measurement on Xserve G5, rounded up. */
  502. transition_latency = 10 * NSEC_PER_MSEC;
  503. /* Set callbacks */
  504. g5_switch_volt = g5_pfunc_switch_volt;
  505. g5_switch_freq = g5_pfunc_switch_freq;
  506. g5_query_freq = g5_pfunc_query_freq;
  507. /* Force apply current frequency to make sure everything is in
  508. * sync (voltage is right for example). Firmware may leave us with
  509. * a strange setting ...
  510. */
  511. g5_switch_volt(CPUFREQ_HIGH);
  512. msleep(10);
  513. g5_pmode_cur = -1;
  514. g5_switch_freq(g5_query_freq());
  515. pr_info("Registering G5 CPU frequency driver\n");
  516. pr_info("Frequency method: i2c/pfunc, Voltage method: %s\n",
  517. has_volt ? "i2c/pfunc" : "none");
  518. pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
  519. g5_cpu_freqs[1].frequency/1000,
  520. g5_cpu_freqs[0].frequency/1000,
  521. g5_cpu_freqs[g5_pmode_cur].frequency/1000);
  522. rc = cpufreq_register_driver(&g5_cpufreq_driver);
  523. bail:
  524. if (rc != 0) {
  525. pmf_put_function(pfunc_cpu_getfreq);
  526. pmf_put_function(pfunc_cpu_setfreq_high);
  527. pmf_put_function(pfunc_cpu_setfreq_low);
  528. pmf_put_function(pfunc_slewing_done);
  529. pmf_put_function(pfunc_cpu0_volt_high);
  530. pmf_put_function(pfunc_cpu0_volt_low);
  531. pmf_put_function(pfunc_cpu1_volt_high);
  532. pmf_put_function(pfunc_cpu1_volt_low);
  533. }
  534. of_node_put(hwclock);
  535. of_node_put(cpuid);
  536. of_node_put(cpunode);
  537. return rc;
  538. }
  539. static int __init g5_cpufreq_init(void)
  540. {
  541. struct device_node *cpunode;
  542. int rc = 0;
  543. /* Get first CPU node */
  544. cpunode = of_cpu_device_node_get(0);
  545. if (cpunode == NULL) {
  546. pr_err("Can't find any CPU node\n");
  547. return -ENODEV;
  548. }
  549. if (of_machine_is_compatible("PowerMac7,2") ||
  550. of_machine_is_compatible("PowerMac7,3") ||
  551. of_machine_is_compatible("RackMac3,1"))
  552. rc = g5_pm72_cpufreq_init(cpunode);
  553. #ifdef CONFIG_PMAC_SMU
  554. else
  555. rc = g5_neo2_cpufreq_init(cpunode);
  556. #endif /* CONFIG_PMAC_SMU */
  557. return rc;
  558. }
  559. module_init(g5_cpufreq_init);
  560. MODULE_LICENSE("GPL");