pmac32-cpufreq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2002 - 2005 Benjamin Herrenschmidt <benh@kernel.crashing.org>
  4. * Copyright (C) 2004 John Steele Scott <toojays@toojays.net>
  5. *
  6. * TODO: Need a big cleanup here. Basically, we need to have different
  7. * cpufreq_driver structures for the different type of HW instead of the
  8. * current mess. We also need to better deal with the detection of the
  9. * type of machine.
  10. */
  11. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/errno.h>
  15. #include <linux/kernel.h>
  16. #include <linux/delay.h>
  17. #include <linux/sched.h>
  18. #include <linux/adb.h>
  19. #include <linux/pmu.h>
  20. #include <linux/cpufreq.h>
  21. #include <linux/init.h>
  22. #include <linux/device.h>
  23. #include <linux/hardirq.h>
  24. #include <linux/of.h>
  25. #include <linux/of_address.h>
  26. #include <asm/machdep.h>
  27. #include <asm/irq.h>
  28. #include <asm/pmac_feature.h>
  29. #include <asm/mmu_context.h>
  30. #include <asm/sections.h>
  31. #include <asm/cputable.h>
  32. #include <asm/time.h>
  33. #include <asm/mpic.h>
  34. #include <asm/keylargo.h>
  35. #include <asm/switch_to.h>
  36. /* WARNING !!! This will cause calibrate_delay() to be called,
  37. * but this is an __init function ! So you MUST go edit
  38. * init/main.c to make it non-init before enabling DEBUG_FREQ
  39. */
  40. #undef DEBUG_FREQ
  41. extern void low_choose_7447a_dfs(int dfs);
  42. extern void low_choose_750fx_pll(int pll);
  43. extern void low_sleep_handler(void);
  44. /*
  45. * Currently, PowerMac cpufreq supports only high & low frequencies
  46. * that are set by the firmware
  47. */
  48. static unsigned int low_freq;
  49. static unsigned int hi_freq;
  50. static unsigned int cur_freq;
  51. static unsigned int sleep_freq;
  52. static unsigned long transition_latency;
  53. /*
  54. * Different models uses different mechanisms to switch the frequency
  55. */
  56. static int (*set_speed_proc)(int low_speed);
  57. static unsigned int (*get_speed_proc)(void);
  58. /*
  59. * Some definitions used by the various speedprocs
  60. */
  61. static u32 voltage_gpio;
  62. static u32 frequency_gpio;
  63. static u32 slew_done_gpio;
  64. static int no_schedule;
  65. static int has_cpu_l2lve;
  66. static int is_pmu_based;
  67. /* There are only two frequency states for each processor. Values
  68. * are in kHz for the time being.
  69. */
  70. #define CPUFREQ_HIGH 0
  71. #define CPUFREQ_LOW 1
  72. static struct cpufreq_frequency_table pmac_cpu_freqs[] = {
  73. {0, CPUFREQ_HIGH, 0},
  74. {0, CPUFREQ_LOW, 0},
  75. {0, 0, CPUFREQ_TABLE_END},
  76. };
  77. static inline void local_delay(unsigned long ms)
  78. {
  79. if (no_schedule)
  80. mdelay(ms);
  81. else
  82. msleep(ms);
  83. }
  84. #ifdef DEBUG_FREQ
  85. static inline void debug_calc_bogomips(void)
  86. {
  87. /* This will cause a recalc of bogomips and display the
  88. * result. We backup/restore the value to avoid affecting the
  89. * core cpufreq framework's own calculation.
  90. */
  91. unsigned long save_lpj = loops_per_jiffy;
  92. calibrate_delay();
  93. loops_per_jiffy = save_lpj;
  94. }
  95. #endif /* DEBUG_FREQ */
  96. /* Switch CPU speed under 750FX CPU control
  97. */
  98. static int cpu_750fx_cpu_speed(int low_speed)
  99. {
  100. u32 hid2;
  101. if (low_speed == 0) {
  102. /* ramping up, set voltage first */
  103. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
  104. /* Make sure we sleep for at least 1ms */
  105. local_delay(10);
  106. /* tweak L2 for high voltage */
  107. if (has_cpu_l2lve) {
  108. hid2 = mfspr(SPRN_HID2_750FX);
  109. hid2 &= ~0x2000;
  110. mtspr(SPRN_HID2_750FX, hid2);
  111. }
  112. }
  113. #ifdef CONFIG_PPC_BOOK3S_32
  114. low_choose_750fx_pll(low_speed);
  115. #endif
  116. if (low_speed == 1) {
  117. /* tweak L2 for low voltage */
  118. if (has_cpu_l2lve) {
  119. hid2 = mfspr(SPRN_HID2_750FX);
  120. hid2 |= 0x2000;
  121. mtspr(SPRN_HID2_750FX, hid2);
  122. }
  123. /* ramping down, set voltage last */
  124. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
  125. local_delay(10);
  126. }
  127. return 0;
  128. }
  129. static unsigned int cpu_750fx_get_cpu_speed(void)
  130. {
  131. if (mfspr(SPRN_HID1) & HID1_PS)
  132. return low_freq;
  133. else
  134. return hi_freq;
  135. }
  136. /* Switch CPU speed using DFS */
  137. static int dfs_set_cpu_speed(int low_speed)
  138. {
  139. if (low_speed == 0) {
  140. /* ramping up, set voltage first */
  141. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
  142. /* Make sure we sleep for at least 1ms */
  143. local_delay(1);
  144. }
  145. /* set frequency */
  146. #ifdef CONFIG_PPC_BOOK3S_32
  147. low_choose_7447a_dfs(low_speed);
  148. #endif
  149. udelay(100);
  150. if (low_speed == 1) {
  151. /* ramping down, set voltage last */
  152. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
  153. local_delay(1);
  154. }
  155. return 0;
  156. }
  157. static unsigned int dfs_get_cpu_speed(void)
  158. {
  159. if (mfspr(SPRN_HID1) & HID1_DFS)
  160. return low_freq;
  161. else
  162. return hi_freq;
  163. }
  164. /* Switch CPU speed using slewing GPIOs
  165. */
  166. static int gpios_set_cpu_speed(int low_speed)
  167. {
  168. int gpio, timeout = 0;
  169. /* If ramping up, set voltage first */
  170. if (low_speed == 0) {
  171. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x05);
  172. /* Delay is way too big but it's ok, we schedule */
  173. local_delay(10);
  174. }
  175. /* Set frequency */
  176. gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0);
  177. if (low_speed == ((gpio & 0x01) == 0))
  178. goto skip;
  179. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, frequency_gpio,
  180. low_speed ? 0x04 : 0x05);
  181. udelay(200);
  182. do {
  183. if (++timeout > 100)
  184. break;
  185. local_delay(1);
  186. gpio = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, slew_done_gpio, 0);
  187. } while((gpio & 0x02) == 0);
  188. skip:
  189. /* If ramping down, set voltage last */
  190. if (low_speed == 1) {
  191. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, voltage_gpio, 0x04);
  192. /* Delay is way too big but it's ok, we schedule */
  193. local_delay(10);
  194. }
  195. #ifdef DEBUG_FREQ
  196. debug_calc_bogomips();
  197. #endif
  198. return 0;
  199. }
  200. /* Switch CPU speed under PMU control
  201. */
  202. static int pmu_set_cpu_speed(int low_speed)
  203. {
  204. struct adb_request req;
  205. unsigned long save_l2cr;
  206. unsigned long save_l3cr;
  207. unsigned int pic_prio;
  208. unsigned long flags;
  209. preempt_disable();
  210. #ifdef DEBUG_FREQ
  211. printk(KERN_DEBUG "HID1, before: %x\n", mfspr(SPRN_HID1));
  212. #endif
  213. pmu_suspend();
  214. /* Disable all interrupt sources on openpic */
  215. pic_prio = mpic_cpu_get_priority();
  216. mpic_cpu_set_priority(0xf);
  217. /* Make sure the decrementer won't interrupt us */
  218. asm volatile("mtdec %0" : : "r" (0x7fffffff));
  219. /* Make sure any pending DEC interrupt occurring while we did
  220. * the above didn't re-enable the DEC */
  221. mb();
  222. asm volatile("mtdec %0" : : "r" (0x7fffffff));
  223. /* We can now disable MSR_EE */
  224. local_irq_save(flags);
  225. /* Giveup the FPU & vec */
  226. enable_kernel_fp();
  227. #ifdef CONFIG_ALTIVEC
  228. if (cpu_has_feature(CPU_FTR_ALTIVEC))
  229. enable_kernel_altivec();
  230. #endif /* CONFIG_ALTIVEC */
  231. /* Save & disable L2 and L3 caches */
  232. save_l3cr = _get_L3CR(); /* (returns -1 if not available) */
  233. save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
  234. /* Send the new speed command. My assumption is that this command
  235. * will cause PLL_CFG[0..3] to be changed next time CPU goes to sleep
  236. */
  237. pmu_request(&req, NULL, 6, PMU_CPU_SPEED, 'W', 'O', 'O', 'F', low_speed);
  238. while (!req.complete)
  239. pmu_poll();
  240. /* Prepare the northbridge for the speed transition */
  241. pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,1);
  242. /* Call low level code to backup CPU state and recover from
  243. * hardware reset
  244. */
  245. low_sleep_handler();
  246. /* Restore the northbridge */
  247. pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,1,0);
  248. /* Restore L2 cache */
  249. if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
  250. _set_L2CR(save_l2cr);
  251. /* Restore L3 cache */
  252. if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0)
  253. _set_L3CR(save_l3cr);
  254. /* Restore userland MMU context */
  255. switch_mmu_context(NULL, current->active_mm, NULL);
  256. #ifdef DEBUG_FREQ
  257. printk(KERN_DEBUG "HID1, after: %x\n", mfspr(SPRN_HID1));
  258. #endif
  259. /* Restore low level PMU operations */
  260. pmu_unlock();
  261. /*
  262. * Restore decrementer; we'll take a decrementer interrupt
  263. * as soon as interrupts are re-enabled and the generic
  264. * clockevents code will reprogram it with the right value.
  265. */
  266. set_dec(1);
  267. /* Restore interrupts */
  268. mpic_cpu_set_priority(pic_prio);
  269. /* Let interrupts flow again ... */
  270. local_irq_restore(flags);
  271. #ifdef DEBUG_FREQ
  272. debug_calc_bogomips();
  273. #endif
  274. pmu_resume();
  275. preempt_enable();
  276. return 0;
  277. }
  278. static int do_set_cpu_speed(struct cpufreq_policy *policy, int speed_mode)
  279. {
  280. unsigned long l3cr;
  281. static unsigned long prev_l3cr;
  282. if (speed_mode == CPUFREQ_LOW &&
  283. cpu_has_feature(CPU_FTR_L3CR)) {
  284. l3cr = _get_L3CR();
  285. if (l3cr & L3CR_L3E) {
  286. prev_l3cr = l3cr;
  287. _set_L3CR(0);
  288. }
  289. }
  290. set_speed_proc(speed_mode == CPUFREQ_LOW);
  291. if (speed_mode == CPUFREQ_HIGH &&
  292. cpu_has_feature(CPU_FTR_L3CR)) {
  293. l3cr = _get_L3CR();
  294. if ((prev_l3cr & L3CR_L3E) && l3cr != prev_l3cr)
  295. _set_L3CR(prev_l3cr);
  296. }
  297. cur_freq = (speed_mode == CPUFREQ_HIGH) ? hi_freq : low_freq;
  298. return 0;
  299. }
  300. static unsigned int pmac_cpufreq_get_speed(unsigned int cpu)
  301. {
  302. return cur_freq;
  303. }
  304. static int pmac_cpufreq_target( struct cpufreq_policy *policy,
  305. unsigned int index)
  306. {
  307. int rc;
  308. rc = do_set_cpu_speed(policy, index);
  309. ppc_proc_freq = cur_freq * 1000ul;
  310. return rc;
  311. }
  312. static int pmac_cpufreq_cpu_init(struct cpufreq_policy *policy)
  313. {
  314. cpufreq_generic_init(policy, pmac_cpu_freqs, transition_latency);
  315. return 0;
  316. }
  317. static u32 read_gpio(struct device_node *np)
  318. {
  319. u64 offset;
  320. if (of_property_read_reg(np, 0, &offset, NULL) < 0)
  321. return 0;
  322. /* That works for all keylargos but shall be fixed properly
  323. * some day... The problem is that it seems we can't rely
  324. * on the "reg" property of the GPIO nodes, they are either
  325. * relative to the base of KeyLargo or to the base of the
  326. * GPIO space, and the device-tree doesn't help.
  327. */
  328. if (offset < KEYLARGO_GPIO_LEVELS0)
  329. offset += KEYLARGO_GPIO_LEVELS0;
  330. return offset;
  331. }
  332. static int pmac_cpufreq_suspend(struct cpufreq_policy *policy)
  333. {
  334. /* Ok, this could be made a bit smarter, but let's be robust for now. We
  335. * always force a speed change to high speed before sleep, to make sure
  336. * we have appropriate voltage and/or bus speed for the wakeup process,
  337. * and to make sure our loops_per_jiffies are "good enough", that is will
  338. * not cause too short delays if we sleep in low speed and wake in high
  339. * speed..
  340. */
  341. no_schedule = 1;
  342. sleep_freq = cur_freq;
  343. if (cur_freq == low_freq && !is_pmu_based)
  344. do_set_cpu_speed(policy, CPUFREQ_HIGH);
  345. return 0;
  346. }
  347. static int pmac_cpufreq_resume(struct cpufreq_policy *policy)
  348. {
  349. /* If we resume, first check if we have a get() function */
  350. if (get_speed_proc)
  351. cur_freq = get_speed_proc();
  352. else
  353. cur_freq = 0;
  354. /* We don't, hrm... we don't really know our speed here, best
  355. * is that we force a switch to whatever it was, which is
  356. * probably high speed due to our suspend() routine
  357. */
  358. do_set_cpu_speed(policy, sleep_freq == low_freq ?
  359. CPUFREQ_LOW : CPUFREQ_HIGH);
  360. ppc_proc_freq = cur_freq * 1000ul;
  361. no_schedule = 0;
  362. return 0;
  363. }
  364. static struct cpufreq_driver pmac_cpufreq_driver = {
  365. .verify = cpufreq_generic_frequency_table_verify,
  366. .target_index = pmac_cpufreq_target,
  367. .get = pmac_cpufreq_get_speed,
  368. .init = pmac_cpufreq_cpu_init,
  369. .suspend = pmac_cpufreq_suspend,
  370. .resume = pmac_cpufreq_resume,
  371. .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING,
  372. .attr = cpufreq_generic_attr,
  373. .name = "powermac",
  374. };
  375. static int pmac_cpufreq_init_MacRISC3(struct device_node *cpunode)
  376. {
  377. struct device_node *volt_gpio_np = of_find_node_by_name(NULL,
  378. "voltage-gpio");
  379. struct device_node *freq_gpio_np = of_find_node_by_name(NULL,
  380. "frequency-gpio");
  381. struct device_node *slew_done_gpio_np = of_find_node_by_name(NULL,
  382. "slewing-done");
  383. const u32 *value;
  384. /*
  385. * Check to see if it's GPIO driven or PMU only
  386. *
  387. * The way we extract the GPIO address is slightly hackish, but it
  388. * works well enough for now. We need to abstract the whole GPIO
  389. * stuff sooner or later anyway
  390. */
  391. if (volt_gpio_np)
  392. voltage_gpio = read_gpio(volt_gpio_np);
  393. if (freq_gpio_np)
  394. frequency_gpio = read_gpio(freq_gpio_np);
  395. if (slew_done_gpio_np)
  396. slew_done_gpio = read_gpio(slew_done_gpio_np);
  397. of_node_put(volt_gpio_np);
  398. of_node_put(freq_gpio_np);
  399. of_node_put(slew_done_gpio_np);
  400. /* If we use the frequency GPIOs, calculate the min/max speeds based
  401. * on the bus frequencies
  402. */
  403. if (frequency_gpio && slew_done_gpio) {
  404. int lenp, rc;
  405. const u32 *freqs, *ratio;
  406. freqs = of_get_property(cpunode, "bus-frequencies", &lenp);
  407. lenp /= sizeof(u32);
  408. if (freqs == NULL || lenp != 2) {
  409. pr_err("bus-frequencies incorrect or missing\n");
  410. return 1;
  411. }
  412. ratio = of_get_property(cpunode, "processor-to-bus-ratio*2",
  413. NULL);
  414. if (ratio == NULL) {
  415. pr_err("processor-to-bus-ratio*2 missing\n");
  416. return 1;
  417. }
  418. /* Get the min/max bus frequencies */
  419. low_freq = min(freqs[0], freqs[1]);
  420. hi_freq = max(freqs[0], freqs[1]);
  421. /* Grrrr.. It _seems_ that the device-tree is lying on the low bus
  422. * frequency, it claims it to be around 84Mhz on some models while
  423. * it appears to be approx. 101Mhz on all. Let's hack around here...
  424. * fortunately, we don't need to be too precise
  425. */
  426. if (low_freq < 98000000)
  427. low_freq = 101000000;
  428. /* Convert those to CPU core clocks */
  429. low_freq = (low_freq * (*ratio)) / 2000;
  430. hi_freq = (hi_freq * (*ratio)) / 2000;
  431. /* Now we get the frequencies, we read the GPIO to see what is out current
  432. * speed
  433. */
  434. rc = pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, frequency_gpio, 0);
  435. cur_freq = (rc & 0x01) ? hi_freq : low_freq;
  436. set_speed_proc = gpios_set_cpu_speed;
  437. return 1;
  438. }
  439. /* If we use the PMU, look for the min & max frequencies in the
  440. * device-tree
  441. */
  442. value = of_get_property(cpunode, "min-clock-frequency", NULL);
  443. if (!value)
  444. return 1;
  445. low_freq = (*value) / 1000;
  446. /* The PowerBook G4 12" (PowerBook6,1) has an error in the device-tree
  447. * here */
  448. if (low_freq < 100000)
  449. low_freq *= 10;
  450. value = of_get_property(cpunode, "max-clock-frequency", NULL);
  451. if (!value)
  452. return 1;
  453. hi_freq = (*value) / 1000;
  454. set_speed_proc = pmu_set_cpu_speed;
  455. is_pmu_based = 1;
  456. return 0;
  457. }
  458. static int pmac_cpufreq_init_7447A(struct device_node *cpunode)
  459. {
  460. struct device_node *volt_gpio_np;
  461. if (!of_property_read_bool(cpunode, "dynamic-power-step"))
  462. return 1;
  463. volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
  464. if (volt_gpio_np)
  465. voltage_gpio = read_gpio(volt_gpio_np);
  466. of_node_put(volt_gpio_np);
  467. if (!voltage_gpio){
  468. pr_err("missing cpu-vcore-select gpio\n");
  469. return 1;
  470. }
  471. /* OF only reports the high frequency */
  472. hi_freq = cur_freq;
  473. low_freq = cur_freq/2;
  474. /* Read actual frequency from CPU */
  475. cur_freq = dfs_get_cpu_speed();
  476. set_speed_proc = dfs_set_cpu_speed;
  477. get_speed_proc = dfs_get_cpu_speed;
  478. return 0;
  479. }
  480. static int pmac_cpufreq_init_750FX(struct device_node *cpunode)
  481. {
  482. struct device_node *volt_gpio_np;
  483. u32 pvr;
  484. const u32 *value;
  485. if (!of_property_read_bool(cpunode, "dynamic-power-step"))
  486. return 1;
  487. hi_freq = cur_freq;
  488. value = of_get_property(cpunode, "reduced-clock-frequency", NULL);
  489. if (!value)
  490. return 1;
  491. low_freq = (*value) / 1000;
  492. volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
  493. if (volt_gpio_np)
  494. voltage_gpio = read_gpio(volt_gpio_np);
  495. of_node_put(volt_gpio_np);
  496. pvr = mfspr(SPRN_PVR);
  497. has_cpu_l2lve = !((pvr & 0xf00) == 0x100);
  498. set_speed_proc = cpu_750fx_cpu_speed;
  499. get_speed_proc = cpu_750fx_get_cpu_speed;
  500. cur_freq = cpu_750fx_get_cpu_speed();
  501. return 0;
  502. }
  503. /* Currently, we support the following machines:
  504. *
  505. * - Titanium PowerBook 1Ghz (PMU based, 667Mhz & 1Ghz)
  506. * - Titanium PowerBook 800 (PMU based, 667Mhz & 800Mhz)
  507. * - Titanium PowerBook 400 (PMU based, 300Mhz & 400Mhz)
  508. * - Titanium PowerBook 500 (PMU based, 300Mhz & 500Mhz)
  509. * - iBook2 500/600 (PMU based, 400Mhz & 500/600Mhz)
  510. * - iBook2 700 (CPU based, 400Mhz & 700Mhz, support low voltage)
  511. * - Recent MacRISC3 laptops
  512. * - All new machines with 7447A CPUs
  513. */
  514. static int __init pmac_cpufreq_setup(void)
  515. {
  516. struct device_node *cpunode;
  517. const u32 *value;
  518. if (strstr(boot_command_line, "nocpufreq"))
  519. return 0;
  520. /* Get first CPU node */
  521. cpunode = of_cpu_device_node_get(0);
  522. if (!cpunode)
  523. goto out;
  524. /* Get current cpu clock freq */
  525. value = of_get_property(cpunode, "clock-frequency", NULL);
  526. if (!value)
  527. goto out;
  528. cur_freq = (*value) / 1000;
  529. /* Check for 7447A based MacRISC3 */
  530. if (of_machine_is_compatible("MacRISC3") &&
  531. of_property_read_bool(cpunode, "dynamic-power-step") &&
  532. PVR_VER(mfspr(SPRN_PVR)) == 0x8003) {
  533. pmac_cpufreq_init_7447A(cpunode);
  534. /* Allow dynamic switching */
  535. transition_latency = 8000000;
  536. pmac_cpufreq_driver.flags &= ~CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING;
  537. /* Check for other MacRISC3 machines */
  538. } else if (of_machine_is_compatible("PowerBook3,4") ||
  539. of_machine_is_compatible("PowerBook3,5") ||
  540. of_machine_is_compatible("MacRISC3")) {
  541. pmac_cpufreq_init_MacRISC3(cpunode);
  542. /* Else check for iBook2 500/600 */
  543. } else if (of_machine_is_compatible("PowerBook4,1")) {
  544. hi_freq = cur_freq;
  545. low_freq = 400000;
  546. set_speed_proc = pmu_set_cpu_speed;
  547. is_pmu_based = 1;
  548. }
  549. /* Else check for TiPb 550 */
  550. else if (of_machine_is_compatible("PowerBook3,3") && cur_freq == 550000) {
  551. hi_freq = cur_freq;
  552. low_freq = 500000;
  553. set_speed_proc = pmu_set_cpu_speed;
  554. is_pmu_based = 1;
  555. }
  556. /* Else check for TiPb 400 & 500 */
  557. else if (of_machine_is_compatible("PowerBook3,2")) {
  558. /* We only know about the 400 MHz and the 500Mhz model
  559. * they both have 300 MHz as low frequency
  560. */
  561. if (cur_freq < 350000 || cur_freq > 550000)
  562. goto out;
  563. hi_freq = cur_freq;
  564. low_freq = 300000;
  565. set_speed_proc = pmu_set_cpu_speed;
  566. is_pmu_based = 1;
  567. }
  568. /* Else check for 750FX */
  569. else if (PVR_VER(mfspr(SPRN_PVR)) == 0x7000)
  570. pmac_cpufreq_init_750FX(cpunode);
  571. out:
  572. of_node_put(cpunode);
  573. if (set_speed_proc == NULL)
  574. return -ENODEV;
  575. pmac_cpu_freqs[CPUFREQ_LOW].frequency = low_freq;
  576. pmac_cpu_freqs[CPUFREQ_HIGH].frequency = hi_freq;
  577. ppc_proc_freq = cur_freq * 1000ul;
  578. pr_info("Registering PowerMac CPU frequency driver\n");
  579. pr_info("Low: %d Mhz, High: %d Mhz, Boot: %d Mhz\n",
  580. low_freq/1000, hi_freq/1000, cur_freq/1000);
  581. return cpufreq_register_driver(&pmac_cpufreq_driver);
  582. }
  583. module_init(pmac_cpufreq_setup);