clock.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * See file CREDITS for list of people who contributed to this
  4. * project.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  19. * MA 02111-1307 USA
  20. */
  21. /* Tegra clock control functions */
  22. #ifndef _CLOCK_H
  23. #define _CLOCK_H
  24. /* Set of oscillator frequencies supported in the internal API. */
  25. enum clock_osc_freq {
  26. /* All in MHz, so 13_0 is 13.0MHz */
  27. CLOCK_OSC_FREQ_13_0,
  28. CLOCK_OSC_FREQ_19_2,
  29. CLOCK_OSC_FREQ_12_0,
  30. CLOCK_OSC_FREQ_26_0,
  31. CLOCK_OSC_FREQ_COUNT,
  32. };
  33. #include <asm/arch/clock-tables.h>
  34. /* PLL stabilization delay in usec */
  35. #define CLOCK_PLL_STABLE_DELAY_US 300
  36. /* return the current oscillator clock frequency */
  37. enum clock_osc_freq clock_get_osc_freq(void);
  38. /**
  39. * Start PLL using the provided configuration parameters.
  40. *
  41. * @param id clock id
  42. * @param divm input divider
  43. * @param divn feedback divider
  44. * @param divp post divider 2^n
  45. * @param cpcon charge pump setup control
  46. * @param lfcon loop filter setup control
  47. *
  48. * @returns monotonic time in us that the PLL will be stable
  49. */
  50. unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
  51. u32 divp, u32 cpcon, u32 lfcon);
  52. /**
  53. * Read low-level parameters of a PLL.
  54. *
  55. * @param id clock id to read (note: USB is not supported)
  56. * @param divm returns input divider
  57. * @param divn returns feedback divider
  58. * @param divp returns post divider 2^n
  59. * @param cpcon returns charge pump setup control
  60. * @param lfcon returns loop filter setup control
  61. *
  62. * @returns 0 if ok, -1 on error (invalid clock id)
  63. */
  64. int clock_ll_read_pll(enum clock_id clkid, u32 *divm, u32 *divn,
  65. u32 *divp, u32 *cpcon, u32 *lfcon);
  66. /*
  67. * Enable a clock
  68. *
  69. * @param id clock id
  70. */
  71. void clock_enable(enum periph_id clkid);
  72. /*
  73. * Disable a clock
  74. *
  75. * @param id clock id
  76. */
  77. void clock_disable(enum periph_id clkid);
  78. /*
  79. * Set whether a clock is enabled or disabled.
  80. *
  81. * @param id clock id
  82. * @param enable 1 to enable, 0 to disable
  83. */
  84. void clock_set_enable(enum periph_id clkid, int enable);
  85. /**
  86. * Reset a peripheral. This puts it in reset, waits for a delay, then takes
  87. * it out of reset and waits for th delay again.
  88. *
  89. * @param periph_id peripheral to reset
  90. * @param us_delay time to delay in microseconds
  91. */
  92. void reset_periph(enum periph_id periph_id, int us_delay);
  93. /**
  94. * Put a peripheral into or out of reset.
  95. *
  96. * @param periph_id peripheral to reset
  97. * @param enable 1 to put into reset, 0 to take out of reset
  98. */
  99. void reset_set_enable(enum periph_id periph_id, int enable);
  100. /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
  101. enum crc_reset_id {
  102. /* Things we can hold in reset for each CPU */
  103. crc_rst_cpu = 1,
  104. crc_rst_de = 1 << 2, /* What is de? */
  105. crc_rst_watchdog = 1 << 3,
  106. crc_rst_debug = 1 << 4,
  107. };
  108. /**
  109. * Put parts of the CPU complex into or out of reset.\
  110. *
  111. * @param cpu cpu number (0 or 1 on Tegra2)
  112. * @param which which parts of the complex to affect (OR of crc_reset_id)
  113. * @param reset 1 to assert reset, 0 to de-assert
  114. */
  115. void reset_cmplx_set_enable(int cpu, int which, int reset);
  116. /**
  117. * Set the source for a peripheral clock. This plus the divisor sets the
  118. * clock rate. You need to look up the datasheet to see the meaning of the
  119. * source parameter as it changes for each peripheral.
  120. *
  121. * Warning: This function is only for use pre-relocation. Please use
  122. * clock_start_periph_pll() instead.
  123. *
  124. * @param periph_id peripheral to adjust
  125. * @param source source clock (0, 1, 2 or 3)
  126. */
  127. void clock_ll_set_source(enum periph_id periph_id, unsigned source);
  128. /**
  129. * Set the source and divisor for a peripheral clock. This sets the
  130. * clock rate. You need to look up the datasheet to see the meaning of the
  131. * source parameter as it changes for each peripheral.
  132. *
  133. * Warning: This function is only for use pre-relocation. Please use
  134. * clock_start_periph_pll() instead.
  135. *
  136. * @param periph_id peripheral to adjust
  137. * @param source source clock (0, 1, 2 or 3)
  138. * @param divisor divisor value to use
  139. */
  140. void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
  141. unsigned divisor);
  142. /**
  143. * Start a peripheral PLL clock at the given rate. This also resets the
  144. * peripheral.
  145. *
  146. * @param periph_id peripheral to start
  147. * @param parent PLL id of required parent clock
  148. * @param rate Required clock rate in Hz
  149. * @return rate selected in Hz, or -1U if something went wrong
  150. */
  151. unsigned clock_start_periph_pll(enum periph_id periph_id,
  152. enum clock_id parent, unsigned rate);
  153. /**
  154. * Returns the rate of a peripheral clock in Hz. Since the caller almost
  155. * certainly knows the parent clock (having just set it) we require that
  156. * this be passed in so we don't need to work it out.
  157. *
  158. * @param periph_id peripheral to start
  159. * @param parent PLL id of parent clock (used to calculate rate, you
  160. * must know this!)
  161. * @return clock rate of peripheral in Hz
  162. */
  163. unsigned long clock_get_periph_rate(enum periph_id periph_id,
  164. enum clock_id parent);
  165. /**
  166. * Adjust peripheral PLL clock to the given rate. This does not reset the
  167. * peripheral. If a second stage divisor is not available, pass NULL for
  168. * extra_div. If it is available, then this parameter will return the
  169. * divisor selected (which will be a power of 2 from 1 to 256).
  170. *
  171. * @param periph_id peripheral to start
  172. * @param parent PLL id of required parent clock
  173. * @param rate Required clock rate in Hz
  174. * @param extra_div value for the second-stage divisor (NULL if one is
  175. not available)
  176. * @return rate selected in Hz, or -1U if something went wrong
  177. */
  178. unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
  179. enum clock_id parent, unsigned rate, int *extra_div);
  180. /**
  181. * Returns the clock rate of a specified clock, in Hz.
  182. *
  183. * @param parent PLL id of clock to check
  184. * @return rate of clock in Hz
  185. */
  186. unsigned clock_get_rate(enum clock_id clkid);
  187. /**
  188. * Start up a UART using low-level calls
  189. *
  190. * Prior to relocation clock_start_periph_pll() cannot be called. This
  191. * function provides a way to set up a UART using low-level calls which
  192. * do not require BSS.
  193. *
  194. * @param periph_id Peripheral ID of UART to enable (e,g, PERIPH_ID_UART1)
  195. */
  196. void clock_ll_start_uart(enum periph_id periph_id);
  197. /**
  198. * Decode a peripheral ID from a device tree node.
  199. *
  200. * This works by looking up the peripheral's 'clocks' node and reading out
  201. * the second cell, which is the clock number / peripheral ID.
  202. *
  203. * @param blob FDT blob to use
  204. * @param node Node to look at
  205. * @return peripheral ID, or PERIPH_ID_NONE if none
  206. */
  207. enum periph_id clock_decode_periph_id(const void *blob, int node);
  208. /**
  209. * Checks if the oscillator bypass is enabled (XOBP bit)
  210. *
  211. * @return 1 if bypass is enabled, 0 if not
  212. */
  213. int clock_get_osc_bypass(void);
  214. /*
  215. * Checks that clocks are valid and prints a warning if not
  216. *
  217. * @return 0 if ok, -1 on error
  218. */
  219. int clock_verify(void);
  220. /* Initialize the clocks */
  221. void clock_init(void);
  222. /* Initialize the PLLs */
  223. void clock_early_init(void);
  224. #endif /* _CLOCK_H_ */