cpufreq_32.c 18 KB

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