clock34xx.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * OMAP3-specific clock framework functions
  3. *
  4. * Copyright (C) 2007 Texas Instruments, Inc.
  5. * Copyright (C) 2007 Nokia Corporation
  6. *
  7. * Written by Paul Walmsley
  8. *
  9. * Parts of this code are based on code written by
  10. * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #undef DEBUG
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/device.h>
  20. #include <linux/list.h>
  21. #include <linux/errno.h>
  22. #include <linux/delay.h>
  23. #include <linux/clk.h>
  24. #include <linux/io.h>
  25. #include <asm/arch/clock.h>
  26. #include <asm/arch/sram.h>
  27. #include <asm/div64.h>
  28. #include <asm/bitops.h>
  29. #include "memory.h"
  30. #include "clock.h"
  31. #include "clock34xx.h"
  32. #include "prm.h"
  33. #include "prm-regbits-34xx.h"
  34. #include "cm.h"
  35. #include "cm-regbits-34xx.h"
  36. /* CM_CLKEN_PLL*.EN* bit values */
  37. #define DPLL_LOCKED 0x7
  38. /**
  39. * omap3_dpll_recalc - recalculate DPLL rate
  40. * @clk: DPLL struct clk
  41. *
  42. * Recalculate and propagate the DPLL rate.
  43. */
  44. static void omap3_dpll_recalc(struct clk *clk)
  45. {
  46. clk->rate = omap2_get_dpll_rate(clk);
  47. propagate_rate(clk);
  48. }
  49. /**
  50. * omap3_clkoutx2_recalc - recalculate DPLL X2 output virtual clock rate
  51. * @clk: DPLL output struct clk
  52. *
  53. * Using parent clock DPLL data, look up DPLL state. If locked, set our
  54. * rate to the dpll_clk * 2; otherwise, just use dpll_clk.
  55. */
  56. static void omap3_clkoutx2_recalc(struct clk *clk)
  57. {
  58. const struct dpll_data *dd;
  59. u32 v;
  60. struct clk *pclk;
  61. /* Walk up the parents of clk, looking for a DPLL */
  62. pclk = clk->parent;
  63. while (pclk && !pclk->dpll_data)
  64. pclk = pclk->parent;
  65. /* clk does not have a DPLL as a parent? */
  66. WARN_ON(!pclk);
  67. dd = pclk->dpll_data;
  68. WARN_ON(!dd->control_reg || !dd->enable_mask);
  69. v = __raw_readl(dd->control_reg) & dd->enable_mask;
  70. v >>= __ffs(dd->enable_mask);
  71. if (v != DPLL_LOCKED)
  72. clk->rate = clk->parent->rate;
  73. else
  74. clk->rate = clk->parent->rate * 2;
  75. if (clk->flags & RATE_PROPAGATES)
  76. propagate_rate(clk);
  77. }
  78. /*
  79. * As it is structured now, this will prevent an OMAP2/3 multiboot
  80. * kernel from compiling. This will need further attention.
  81. */
  82. #if defined(CONFIG_ARCH_OMAP3)
  83. static struct clk_functions omap2_clk_functions = {
  84. .clk_enable = omap2_clk_enable,
  85. .clk_disable = omap2_clk_disable,
  86. .clk_round_rate = omap2_clk_round_rate,
  87. .clk_set_rate = omap2_clk_set_rate,
  88. .clk_set_parent = omap2_clk_set_parent,
  89. .clk_disable_unused = omap2_clk_disable_unused,
  90. };
  91. /*
  92. * Set clocks for bypass mode for reboot to work.
  93. */
  94. void omap2_clk_prepare_for_reboot(void)
  95. {
  96. /* REVISIT: Not ready for 343x */
  97. #if 0
  98. u32 rate;
  99. if (vclk == NULL || sclk == NULL)
  100. return;
  101. rate = clk_get_rate(sclk);
  102. clk_set_rate(vclk, rate);
  103. #endif
  104. }
  105. /* REVISIT: Move this init stuff out into clock.c */
  106. /*
  107. * Switch the MPU rate if specified on cmdline.
  108. * We cannot do this early until cmdline is parsed.
  109. */
  110. static int __init omap2_clk_arch_init(void)
  111. {
  112. if (!mpurate)
  113. return -EINVAL;
  114. /* REVISIT: not yet ready for 343x */
  115. #if 0
  116. if (omap2_select_table_rate(&virt_prcm_set, mpurate))
  117. printk(KERN_ERR "Could not find matching MPU rate\n");
  118. #endif
  119. recalculate_root_clocks();
  120. printk(KERN_INFO "Switched to new clocking rate (Crystal/DPLL3/MPU): "
  121. "%ld.%01ld/%ld/%ld MHz\n",
  122. (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
  123. (core_ck.rate / 1000000), (dpll1_fck.rate / 1000000)) ;
  124. return 0;
  125. }
  126. arch_initcall(omap2_clk_arch_init);
  127. int __init omap2_clk_init(void)
  128. {
  129. /* struct prcm_config *prcm; */
  130. struct clk **clkp;
  131. /* u32 clkrate; */
  132. u32 cpu_clkflg;
  133. /* REVISIT: Ultimately this will be used for multiboot */
  134. #if 0
  135. if (cpu_is_omap242x()) {
  136. cpu_mask = RATE_IN_242X;
  137. cpu_clkflg = CLOCK_IN_OMAP242X;
  138. clkp = onchip_24xx_clks;
  139. } else if (cpu_is_omap2430()) {
  140. cpu_mask = RATE_IN_243X;
  141. cpu_clkflg = CLOCK_IN_OMAP243X;
  142. clkp = onchip_24xx_clks;
  143. }
  144. #endif
  145. if (cpu_is_omap34xx()) {
  146. cpu_mask = RATE_IN_343X;
  147. cpu_clkflg = CLOCK_IN_OMAP343X;
  148. clkp = onchip_34xx_clks;
  149. /*
  150. * Update this if there are further clock changes between ES2
  151. * and production parts
  152. */
  153. if (is_sil_rev_equal_to(OMAP3430_REV_ES1_0)) {
  154. /* No 3430ES1-only rates exist, so no RATE_IN_3430ES1 */
  155. cpu_clkflg |= CLOCK_IN_OMAP3430ES1;
  156. } else {
  157. cpu_mask |= RATE_IN_3430ES2;
  158. cpu_clkflg |= CLOCK_IN_OMAP3430ES2;
  159. }
  160. }
  161. clk_init(&omap2_clk_functions);
  162. for (clkp = onchip_34xx_clks;
  163. clkp < onchip_34xx_clks + ARRAY_SIZE(onchip_34xx_clks);
  164. clkp++) {
  165. if ((*clkp)->flags & cpu_clkflg)
  166. clk_register(*clkp);
  167. }
  168. /* REVISIT: Not yet ready for OMAP3 */
  169. #if 0
  170. /* Check the MPU rate set by bootloader */
  171. clkrate = omap2_get_dpll_rate_24xx(&dpll_ck);
  172. for (prcm = rate_table; prcm->mpu_speed; prcm++) {
  173. if (!(prcm->flags & cpu_mask))
  174. continue;
  175. if (prcm->xtal_speed != sys_ck.rate)
  176. continue;
  177. if (prcm->dpll_speed <= clkrate)
  178. break;
  179. }
  180. curr_prcm_set = prcm;
  181. #endif
  182. recalculate_root_clocks();
  183. printk(KERN_INFO "Clocking rate (Crystal/DPLL/ARM core): "
  184. "%ld.%01ld/%ld/%ld MHz\n",
  185. (osc_sys_ck.rate / 1000000), (osc_sys_ck.rate / 100000) % 10,
  186. (core_ck.rate / 1000000), (arm_fck.rate / 1000000));
  187. /*
  188. * Only enable those clocks we will need, let the drivers
  189. * enable other clocks as necessary
  190. */
  191. clk_enable_init_clocks();
  192. /* Avoid sleeping during omap2_clk_prepare_for_reboot() */
  193. /* REVISIT: not yet ready for 343x */
  194. #if 0
  195. vclk = clk_get(NULL, "virt_prcm_set");
  196. sclk = clk_get(NULL, "sys_ck");
  197. #endif
  198. return 0;
  199. }
  200. #endif