clock.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * linux/arch/arm/mach-omap2/clock.c
  3. *
  4. * Copyright (C) 2005-2008 Texas Instruments, Inc.
  5. * Copyright (C) 2004-2010 Nokia Corporation
  6. *
  7. * Contacts:
  8. * Richard Woodruff <r-woodruff2@ti.com>
  9. * Paul Walmsley
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #undef DEBUG
  16. #include <linux/kernel.h>
  17. #include <linux/export.h>
  18. #include <linux/list.h>
  19. #include <linux/errno.h>
  20. #include <linux/err.h>
  21. #include <linux/delay.h>
  22. #include <linux/clk.h>
  23. #include <linux/clk-provider.h>
  24. #include <linux/io.h>
  25. #include <linux/bitops.h>
  26. #include <linux/of_address.h>
  27. #include <asm/cpu.h>
  28. #include <trace/events/power.h>
  29. #include "soc.h"
  30. #include "clockdomain.h"
  31. #include "clock.h"
  32. #include "cm.h"
  33. #include "cm2xxx.h"
  34. #include "cm3xxx.h"
  35. #include "cm-regbits-24xx.h"
  36. #include "cm-regbits-34xx.h"
  37. #include "common.h"
  38. u16 cpu_mask;
  39. /* DPLL valid Fint frequency band limits - from 34xx TRM Section 4.7.6.2 */
  40. #define OMAP3430_DPLL_FINT_BAND1_MIN 750000
  41. #define OMAP3430_DPLL_FINT_BAND1_MAX 2100000
  42. #define OMAP3430_DPLL_FINT_BAND2_MIN 7500000
  43. #define OMAP3430_DPLL_FINT_BAND2_MAX 21000000
  44. /*
  45. * DPLL valid Fint frequency range for OMAP36xx and OMAP4xxx.
  46. * From device data manual section 4.3 "DPLL and DLL Specifications".
  47. */
  48. #define OMAP3PLUS_DPLL_FINT_MIN 32000
  49. #define OMAP3PLUS_DPLL_FINT_MAX 52000000
  50. static struct ti_clk_ll_ops omap_clk_ll_ops = {
  51. .clkdm_clk_enable = clkdm_clk_enable,
  52. .clkdm_clk_disable = clkdm_clk_disable,
  53. .cm_wait_module_ready = omap_cm_wait_module_ready,
  54. .cm_split_idlest_reg = cm_split_idlest_reg,
  55. };
  56. /**
  57. * omap2_clk_setup_ll_ops - setup clock driver low-level ops
  58. *
  59. * Sets up clock driver low-level platform ops. These are needed
  60. * for register accesses and various other misc platform operations.
  61. * Returns 0 on success, -EBUSY if low level ops have been registered
  62. * already.
  63. */
  64. int __init omap2_clk_setup_ll_ops(void)
  65. {
  66. return ti_clk_setup_ll_ops(&omap_clk_ll_ops);
  67. }
  68. /*
  69. * OMAP2+ specific clock functions
  70. */
  71. /* Private functions */
  72. /* Public functions */
  73. /**
  74. * omap2_init_clk_clkdm - look up a clockdomain name, store pointer in clk
  75. * @clk: OMAP clock struct ptr to use
  76. *
  77. * Convert a clockdomain name stored in a struct clk 'clk' into a
  78. * clockdomain pointer, and save it into the struct clk. Intended to be
  79. * called during clk_register(). No return value.
  80. */
  81. void omap2_init_clk_clkdm(struct clk_hw *hw)
  82. {
  83. struct clk_hw_omap *clk = to_clk_hw_omap(hw);
  84. struct clockdomain *clkdm;
  85. const char *clk_name;
  86. if (!clk->clkdm_name)
  87. return;
  88. clk_name = __clk_get_name(hw->clk);
  89. clkdm = clkdm_lookup(clk->clkdm_name);
  90. if (clkdm) {
  91. pr_debug("clock: associated clk %s to clkdm %s\n",
  92. clk_name, clk->clkdm_name);
  93. clk->clkdm = clkdm;
  94. } else {
  95. pr_debug("clock: could not associate clk %s to clkdm %s\n",
  96. clk_name, clk->clkdm_name);
  97. }
  98. }
  99. static int __initdata mpurate;
  100. /*
  101. * By default we use the rate set by the bootloader.
  102. * You can override this with mpurate= cmdline option.
  103. */
  104. static int __init omap_clk_setup(char *str)
  105. {
  106. get_option(&str, &mpurate);
  107. if (!mpurate)
  108. return 1;
  109. if (mpurate < 1000)
  110. mpurate *= 1000000;
  111. return 1;
  112. }
  113. __setup("mpurate=", omap_clk_setup);
  114. /**
  115. * omap2_clk_print_new_rates - print summary of current clock tree rates
  116. * @hfclkin_ck_name: clk name for the off-chip HF oscillator
  117. * @core_ck_name: clk name for the on-chip CORE_CLK
  118. * @mpu_ck_name: clk name for the ARM MPU clock
  119. *
  120. * Prints a short message to the console with the HFCLKIN oscillator
  121. * rate, the rate of the CORE clock, and the rate of the ARM MPU clock.
  122. * Called by the boot-time MPU rate switching code. XXX This is intended
  123. * to be handled by the OPP layer code in the near future and should be
  124. * removed from the clock code. No return value.
  125. */
  126. void __init omap2_clk_print_new_rates(const char *hfclkin_ck_name,
  127. const char *core_ck_name,
  128. const char *mpu_ck_name)
  129. {
  130. struct clk *hfclkin_ck, *core_ck, *mpu_ck;
  131. unsigned long hfclkin_rate;
  132. mpu_ck = clk_get(NULL, mpu_ck_name);
  133. if (WARN(IS_ERR(mpu_ck), "clock: failed to get %s.\n", mpu_ck_name))
  134. return;
  135. core_ck = clk_get(NULL, core_ck_name);
  136. if (WARN(IS_ERR(core_ck), "clock: failed to get %s.\n", core_ck_name))
  137. return;
  138. hfclkin_ck = clk_get(NULL, hfclkin_ck_name);
  139. if (WARN(IS_ERR(hfclkin_ck), "Failed to get %s.\n", hfclkin_ck_name))
  140. return;
  141. hfclkin_rate = clk_get_rate(hfclkin_ck);
  142. pr_info("Switched to new clocking rate (Crystal/Core/MPU): %ld.%01ld/%ld/%ld MHz\n",
  143. (hfclkin_rate / 1000000), ((hfclkin_rate / 100000) % 10),
  144. (clk_get_rate(core_ck) / 1000000),
  145. (clk_get_rate(mpu_ck) / 1000000));
  146. }
  147. /**
  148. * ti_clk_init_features - init clock features struct for the SoC
  149. *
  150. * Initializes the clock features struct based on the SoC type.
  151. */
  152. void __init ti_clk_init_features(void)
  153. {
  154. struct ti_clk_features features = { 0 };
  155. /* Fint setup for DPLLs */
  156. if (cpu_is_omap3430()) {
  157. features.fint_min = OMAP3430_DPLL_FINT_BAND1_MIN;
  158. features.fint_max = OMAP3430_DPLL_FINT_BAND2_MAX;
  159. features.fint_band1_max = OMAP3430_DPLL_FINT_BAND1_MAX;
  160. features.fint_band2_min = OMAP3430_DPLL_FINT_BAND2_MIN;
  161. } else {
  162. features.fint_min = OMAP3PLUS_DPLL_FINT_MIN;
  163. features.fint_max = OMAP3PLUS_DPLL_FINT_MAX;
  164. }
  165. /* Bypass value setup for DPLLs */
  166. if (cpu_is_omap24xx()) {
  167. features.dpll_bypass_vals |=
  168. (1 << OMAP2XXX_EN_DPLL_LPBYPASS) |
  169. (1 << OMAP2XXX_EN_DPLL_FRBYPASS);
  170. } else if (cpu_is_omap34xx()) {
  171. features.dpll_bypass_vals |=
  172. (1 << OMAP3XXX_EN_DPLL_LPBYPASS) |
  173. (1 << OMAP3XXX_EN_DPLL_FRBYPASS);
  174. } else if (soc_is_am33xx() || cpu_is_omap44xx() || soc_is_am43xx() ||
  175. soc_is_omap54xx() || soc_is_dra7xx()) {
  176. features.dpll_bypass_vals |=
  177. (1 << OMAP4XXX_EN_DPLL_LPBYPASS) |
  178. (1 << OMAP4XXX_EN_DPLL_FRBYPASS) |
  179. (1 << OMAP4XXX_EN_DPLL_MNBYPASS);
  180. }
  181. /* Jitter correction only available on OMAP343X */
  182. if (cpu_is_omap343x())
  183. features.flags |= TI_CLK_DPLL_HAS_FREQSEL;
  184. /* Idlest value for interface clocks.
  185. * 24xx uses 0 to indicate not ready, and 1 to indicate ready.
  186. * 34xx reverses this, just to keep us on our toes
  187. * AM35xx uses both, depending on the module.
  188. */
  189. if (cpu_is_omap24xx())
  190. features.cm_idlest_val = OMAP24XX_CM_IDLEST_VAL;
  191. else if (cpu_is_omap34xx())
  192. features.cm_idlest_val = OMAP34XX_CM_IDLEST_VAL;
  193. /* On OMAP3430 ES1.0, DPLL4 can't be re-programmed */
  194. if (omap_rev() == OMAP3430_REV_ES1_0)
  195. features.flags |= TI_CLK_DPLL4_DENY_REPROGRAM;
  196. /* Errata I810 for omap5 / dra7 */
  197. if (soc_is_omap54xx() || soc_is_dra7xx())
  198. features.flags |= TI_CLK_ERRATA_I810;
  199. ti_clk_setup_features(&features);
  200. }