pmac64-cpufreq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
  4. * and Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
  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.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. };
  272. #ifdef CONFIG_PMAC_SMU
  273. static int __init g5_neo2_cpufreq_init(struct device_node *cpunode)
  274. {
  275. unsigned int psize, ssize;
  276. unsigned long max_freq;
  277. char *freq_method, *volt_method;
  278. const u32 *valp;
  279. u32 pvr_hi;
  280. int use_volts_vdnap = 0;
  281. int use_volts_smu = 0;
  282. int rc = -ENODEV;
  283. /* Check supported platforms */
  284. if (of_machine_is_compatible("PowerMac8,1") ||
  285. of_machine_is_compatible("PowerMac8,2") ||
  286. of_machine_is_compatible("PowerMac9,1") ||
  287. of_machine_is_compatible("PowerMac12,1"))
  288. use_volts_smu = 1;
  289. else if (of_machine_is_compatible("PowerMac11,2"))
  290. use_volts_vdnap = 1;
  291. else
  292. return -ENODEV;
  293. /* Check 970FX for now */
  294. valp = of_get_property(cpunode, "cpu-version", NULL);
  295. if (!valp) {
  296. DBG("No cpu-version property !\n");
  297. goto bail_noprops;
  298. }
  299. pvr_hi = (*valp) >> 16;
  300. if (pvr_hi != 0x3c && pvr_hi != 0x44) {
  301. pr_err("Unsupported CPU version\n");
  302. goto bail_noprops;
  303. }
  304. /* Look for the powertune data in the device-tree */
  305. g5_pmode_data = of_get_property(cpunode, "power-mode-data",&psize);
  306. if (!g5_pmode_data) {
  307. DBG("No power-mode-data !\n");
  308. goto bail_noprops;
  309. }
  310. g5_pmode_max = psize / sizeof(u32) - 1;
  311. if (use_volts_smu) {
  312. const struct smu_sdbp_header *shdr;
  313. /* Look for the FVT table */
  314. shdr = smu_get_sdb_partition(SMU_SDB_FVT_ID, NULL);
  315. if (!shdr)
  316. goto bail_noprops;
  317. g5_fvt_table = (struct smu_sdbp_fvt *)&shdr[1];
  318. ssize = (shdr->len * sizeof(u32)) - sizeof(*shdr);
  319. g5_fvt_count = ssize / sizeof(*g5_fvt_table);
  320. g5_fvt_cur = 0;
  321. /* Sanity checking */
  322. if (g5_fvt_count < 1 || g5_pmode_max < 1)
  323. goto bail_noprops;
  324. g5_switch_volt = g5_smu_switch_volt;
  325. volt_method = "SMU";
  326. } else if (use_volts_vdnap) {
  327. struct device_node *root;
  328. root = of_find_node_by_path("/");
  329. if (root == NULL) {
  330. pr_err("Can't find root of device tree\n");
  331. goto bail_noprops;
  332. }
  333. pfunc_set_vdnap0 = pmf_find_function(root, "set-vdnap0");
  334. pfunc_vdnap0_complete =
  335. pmf_find_function(root, "slewing-done");
  336. of_node_put(root);
  337. if (pfunc_set_vdnap0 == NULL ||
  338. pfunc_vdnap0_complete == NULL) {
  339. pr_err("Can't find required platform function\n");
  340. goto bail_noprops;
  341. }
  342. g5_switch_volt = g5_vdnap_switch_volt;
  343. volt_method = "GPIO";
  344. } else {
  345. g5_switch_volt = g5_dummy_switch_volt;
  346. volt_method = "none";
  347. }
  348. /*
  349. * From what I see, clock-frequency is always the maximal frequency.
  350. * The current driver can not slew sysclk yet, so we really only deal
  351. * with powertune steps for now. We also only implement full freq and
  352. * half freq in this version. So far, I haven't yet seen a machine
  353. * supporting anything else.
  354. */
  355. valp = of_get_property(cpunode, "clock-frequency", NULL);
  356. if (!valp)
  357. return -ENODEV;
  358. max_freq = (*valp)/1000;
  359. g5_cpu_freqs[0].frequency = max_freq;
  360. g5_cpu_freqs[1].frequency = max_freq/2;
  361. /* Set callbacks */
  362. transition_latency = 12000;
  363. g5_switch_freq = g5_scom_switch_freq;
  364. g5_query_freq = g5_scom_query_freq;
  365. freq_method = "SCOM";
  366. /* Force apply current frequency to make sure everything is in
  367. * sync (voltage is right for example). Firmware may leave us with
  368. * a strange setting ...
  369. */
  370. g5_switch_volt(CPUFREQ_HIGH);
  371. msleep(10);
  372. g5_pmode_cur = -1;
  373. g5_switch_freq(g5_query_freq());
  374. pr_info("Registering G5 CPU frequency driver\n");
  375. pr_info("Frequency method: %s, Voltage method: %s\n",
  376. freq_method, volt_method);
  377. pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
  378. g5_cpu_freqs[1].frequency/1000,
  379. g5_cpu_freqs[0].frequency/1000,
  380. g5_cpu_freqs[g5_pmode_cur].frequency/1000);
  381. rc = cpufreq_register_driver(&g5_cpufreq_driver);
  382. /* We keep the CPU node on hold... hopefully, Apple G5 don't have
  383. * hotplug CPU with a dynamic device-tree ...
  384. */
  385. return rc;
  386. bail_noprops:
  387. of_node_put(cpunode);
  388. return rc;
  389. }
  390. #endif /* CONFIG_PMAC_SMU */
  391. static int __init g5_pm72_cpufreq_init(struct device_node *cpunode)
  392. {
  393. struct device_node *cpuid = NULL, *hwclock = NULL;
  394. const u8 *eeprom = NULL;
  395. const u32 *valp;
  396. u64 max_freq, min_freq, ih, il;
  397. int has_volt = 1, rc = 0;
  398. DBG("cpufreq: Initializing for PowerMac7,2, PowerMac7,3 and"
  399. " RackMac3,1...\n");
  400. /* Lookup the cpuid eeprom node */
  401. cpuid = of_find_node_by_path("/u3@0,f8000000/i2c@f8001000/cpuid@a0");
  402. if (cpuid != NULL)
  403. eeprom = of_get_property(cpuid, "cpuid", NULL);
  404. if (eeprom == NULL) {
  405. pr_err("Can't find cpuid EEPROM !\n");
  406. rc = -ENODEV;
  407. goto bail;
  408. }
  409. /* Lookup the i2c hwclock */
  410. for_each_node_by_name(hwclock, "i2c-hwclock") {
  411. const char *loc = of_get_property(hwclock,
  412. "hwctrl-location", NULL);
  413. if (loc == NULL)
  414. continue;
  415. if (strcmp(loc, "CPU CLOCK"))
  416. continue;
  417. if (!of_property_present(hwclock, "platform-get-frequency"))
  418. continue;
  419. break;
  420. }
  421. if (hwclock == NULL) {
  422. pr_err("Can't find i2c clock chip !\n");
  423. rc = -ENODEV;
  424. goto bail;
  425. }
  426. DBG("cpufreq: i2c clock chip found: %pOF\n", hwclock);
  427. /* Now get all the platform functions */
  428. pfunc_cpu_getfreq =
  429. pmf_find_function(hwclock, "get-frequency");
  430. pfunc_cpu_setfreq_high =
  431. pmf_find_function(hwclock, "set-frequency-high");
  432. pfunc_cpu_setfreq_low =
  433. pmf_find_function(hwclock, "set-frequency-low");
  434. pfunc_slewing_done =
  435. pmf_find_function(hwclock, "slewing-done");
  436. pfunc_cpu0_volt_high =
  437. pmf_find_function(hwclock, "set-voltage-high-0");
  438. pfunc_cpu0_volt_low =
  439. pmf_find_function(hwclock, "set-voltage-low-0");
  440. pfunc_cpu1_volt_high =
  441. pmf_find_function(hwclock, "set-voltage-high-1");
  442. pfunc_cpu1_volt_low =
  443. pmf_find_function(hwclock, "set-voltage-low-1");
  444. /* Check we have minimum requirements */
  445. if (pfunc_cpu_getfreq == NULL || pfunc_cpu_setfreq_high == NULL ||
  446. pfunc_cpu_setfreq_low == NULL || pfunc_slewing_done == NULL) {
  447. pr_err("Can't find platform functions !\n");
  448. rc = -ENODEV;
  449. goto bail;
  450. }
  451. /* Check that we have complete sets */
  452. if (pfunc_cpu0_volt_high == NULL || pfunc_cpu0_volt_low == NULL) {
  453. pmf_put_function(pfunc_cpu0_volt_high);
  454. pmf_put_function(pfunc_cpu0_volt_low);
  455. pfunc_cpu0_volt_high = pfunc_cpu0_volt_low = NULL;
  456. has_volt = 0;
  457. }
  458. if (!has_volt ||
  459. pfunc_cpu1_volt_high == NULL || pfunc_cpu1_volt_low == NULL) {
  460. pmf_put_function(pfunc_cpu1_volt_high);
  461. pmf_put_function(pfunc_cpu1_volt_low);
  462. pfunc_cpu1_volt_high = pfunc_cpu1_volt_low = NULL;
  463. }
  464. /* Note: The device tree also contains a "platform-set-values"
  465. * function for which I haven't quite figured out the usage. It
  466. * might have to be called on init and/or wakeup, I'm not too sure
  467. * but things seem to work fine without it so far ...
  468. */
  469. /* Get max frequency from device-tree */
  470. valp = of_get_property(cpunode, "clock-frequency", NULL);
  471. if (!valp) {
  472. pr_err("Can't find CPU frequency !\n");
  473. rc = -ENODEV;
  474. goto bail;
  475. }
  476. max_freq = (*valp)/1000;
  477. /* Now calculate reduced frequency by using the cpuid input freq
  478. * ratio. This requires 64 bits math unless we are willing to lose
  479. * some precision
  480. */
  481. ih = *((u32 *)(eeprom + 0x10));
  482. il = *((u32 *)(eeprom + 0x20));
  483. /* Check for machines with no useful settings */
  484. if (il == ih) {
  485. pr_warn("No low frequency mode available on this model !\n");
  486. rc = -ENODEV;
  487. goto bail;
  488. }
  489. min_freq = 0;
  490. if (ih != 0 && il != 0)
  491. min_freq = (max_freq * il) / ih;
  492. /* Sanity check */
  493. if (min_freq >= max_freq || min_freq < 1000) {
  494. pr_err("Can't calculate low frequency !\n");
  495. rc = -ENXIO;
  496. goto bail;
  497. }
  498. g5_cpu_freqs[0].frequency = max_freq;
  499. g5_cpu_freqs[1].frequency = min_freq;
  500. /* Based on a measurement on Xserve G5, rounded up. */
  501. transition_latency = 10 * NSEC_PER_MSEC;
  502. /* Set callbacks */
  503. g5_switch_volt = g5_pfunc_switch_volt;
  504. g5_switch_freq = g5_pfunc_switch_freq;
  505. g5_query_freq = g5_pfunc_query_freq;
  506. /* Force apply current frequency to make sure everything is in
  507. * sync (voltage is right for example). Firmware may leave us with
  508. * a strange setting ...
  509. */
  510. g5_switch_volt(CPUFREQ_HIGH);
  511. msleep(10);
  512. g5_pmode_cur = -1;
  513. g5_switch_freq(g5_query_freq());
  514. pr_info("Registering G5 CPU frequency driver\n");
  515. pr_info("Frequency method: i2c/pfunc, Voltage method: %s\n",
  516. has_volt ? "i2c/pfunc" : "none");
  517. pr_info("Low: %d Mhz, High: %d Mhz, Cur: %d MHz\n",
  518. g5_cpu_freqs[1].frequency/1000,
  519. g5_cpu_freqs[0].frequency/1000,
  520. g5_cpu_freqs[g5_pmode_cur].frequency/1000);
  521. rc = cpufreq_register_driver(&g5_cpufreq_driver);
  522. bail:
  523. if (rc != 0) {
  524. pmf_put_function(pfunc_cpu_getfreq);
  525. pmf_put_function(pfunc_cpu_setfreq_high);
  526. pmf_put_function(pfunc_cpu_setfreq_low);
  527. pmf_put_function(pfunc_slewing_done);
  528. pmf_put_function(pfunc_cpu0_volt_high);
  529. pmf_put_function(pfunc_cpu0_volt_low);
  530. pmf_put_function(pfunc_cpu1_volt_high);
  531. pmf_put_function(pfunc_cpu1_volt_low);
  532. }
  533. of_node_put(hwclock);
  534. of_node_put(cpuid);
  535. of_node_put(cpunode);
  536. return rc;
  537. }
  538. static int __init g5_cpufreq_init(void)
  539. {
  540. struct device_node *cpunode;
  541. int rc = 0;
  542. /* Get first CPU node */
  543. cpunode = of_cpu_device_node_get(0);
  544. if (cpunode == NULL) {
  545. pr_err("Can't find any CPU node\n");
  546. return -ENODEV;
  547. }
  548. if (of_machine_is_compatible("PowerMac7,2") ||
  549. of_machine_is_compatible("PowerMac7,3") ||
  550. of_machine_is_compatible("RackMac3,1"))
  551. rc = g5_pm72_cpufreq_init(cpunode);
  552. #ifdef CONFIG_PMAC_SMU
  553. else
  554. rc = g5_neo2_cpufreq_init(cpunode);
  555. #endif /* CONFIG_PMAC_SMU */
  556. return rc;
  557. }
  558. module_init(g5_cpufreq_init);
  559. MODULE_DESCRIPTION("cpufreq driver for SMU & 970FX based G5 Macs");
  560. MODULE_LICENSE("GPL");