cpufreq_32.c 18 KB

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