clock.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. /* Tegra2 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. /* The PLLs supported by the hardware */
  34. enum clock_id {
  35. CLOCK_ID_FIRST,
  36. CLOCK_ID_CGENERAL = CLOCK_ID_FIRST,
  37. CLOCK_ID_MEMORY,
  38. CLOCK_ID_PERIPH,
  39. CLOCK_ID_AUDIO,
  40. CLOCK_ID_USB,
  41. CLOCK_ID_DISPLAY,
  42. /* now the simple ones */
  43. CLOCK_ID_FIRST_SIMPLE,
  44. CLOCK_ID_XCPU = CLOCK_ID_FIRST_SIMPLE,
  45. CLOCK_ID_EPCI,
  46. CLOCK_ID_SFROM32KHZ,
  47. CLOCK_ID_COUNT,
  48. };
  49. /* The clocks supported by the hardware */
  50. enum periph_id {
  51. PERIPH_ID_FIRST,
  52. /* Low word: 31:0 */
  53. PERIPH_ID_CPU = PERIPH_ID_FIRST,
  54. PERIPH_ID_RESERVED1,
  55. PERIPH_ID_RESERVED2,
  56. PERIPH_ID_AC97,
  57. PERIPH_ID_RTC,
  58. PERIPH_ID_TMR,
  59. PERIPH_ID_UART1,
  60. PERIPH_ID_UART2,
  61. /* 8 */
  62. PERIPH_ID_GPIO,
  63. PERIPH_ID_SDMMC2,
  64. PERIPH_ID_SPDIF,
  65. PERIPH_ID_I2S1,
  66. PERIPH_ID_I2C1,
  67. PERIPH_ID_NDFLASH,
  68. PERIPH_ID_SDMMC1,
  69. PERIPH_ID_SDMMC4,
  70. /* 16 */
  71. PERIPH_ID_TWC,
  72. PERIPH_ID_PWM,
  73. PERIPH_ID_I2S2,
  74. PERIPH_ID_EPP,
  75. PERIPH_ID_VI,
  76. PERIPH_ID_2D,
  77. PERIPH_ID_USBD,
  78. PERIPH_ID_ISP,
  79. /* 24 */
  80. PERIPH_ID_3D,
  81. PERIPH_ID_IDE,
  82. PERIPH_ID_DISP2,
  83. PERIPH_ID_DISP1,
  84. PERIPH_ID_HOST1X,
  85. PERIPH_ID_VCP,
  86. PERIPH_ID_RESERVED30,
  87. PERIPH_ID_CACHE2,
  88. /* Middle word: 63:32 */
  89. PERIPH_ID_MEM,
  90. PERIPH_ID_AHBDMA,
  91. PERIPH_ID_APBDMA,
  92. PERIPH_ID_RESERVED35,
  93. PERIPH_ID_KBC,
  94. PERIPH_ID_STAT_MON,
  95. PERIPH_ID_PMC,
  96. PERIPH_ID_FUSE,
  97. /* 40 */
  98. PERIPH_ID_KFUSE,
  99. PERIPH_ID_SBC1,
  100. PERIPH_ID_SNOR,
  101. PERIPH_ID_SPI1,
  102. PERIPH_ID_SBC2,
  103. PERIPH_ID_XIO,
  104. PERIPH_ID_SBC3,
  105. PERIPH_ID_DVC_I2C,
  106. /* 48 */
  107. PERIPH_ID_DSI,
  108. PERIPH_ID_TVO,
  109. PERIPH_ID_MIPI,
  110. PERIPH_ID_HDMI,
  111. PERIPH_ID_CSI,
  112. PERIPH_ID_TVDAC,
  113. PERIPH_ID_I2C2,
  114. PERIPH_ID_UART3,
  115. /* 56 */
  116. PERIPH_ID_RESERVED56,
  117. PERIPH_ID_EMC,
  118. PERIPH_ID_USB2,
  119. PERIPH_ID_USB3,
  120. PERIPH_ID_MPE,
  121. PERIPH_ID_VDE,
  122. PERIPH_ID_BSEA,
  123. PERIPH_ID_BSEV,
  124. /* Upper word 95:64 */
  125. PERIPH_ID_SPEEDO,
  126. PERIPH_ID_UART4,
  127. PERIPH_ID_UART5,
  128. PERIPH_ID_I2C3,
  129. PERIPH_ID_SBC4,
  130. PERIPH_ID_SDMMC3,
  131. PERIPH_ID_PCIE,
  132. PERIPH_ID_OWR,
  133. /* 72 */
  134. PERIPH_ID_AFI,
  135. PERIPH_ID_CORESIGHT,
  136. PERIPH_ID_RESERVED74,
  137. PERIPH_ID_AVPUCQ,
  138. PERIPH_ID_RESERVED76,
  139. PERIPH_ID_RESERVED77,
  140. PERIPH_ID_RESERVED78,
  141. PERIPH_ID_RESERVED79,
  142. /* 80 */
  143. PERIPH_ID_RESERVED80,
  144. PERIPH_ID_RESERVED81,
  145. PERIPH_ID_RESERVED82,
  146. PERIPH_ID_RESERVED83,
  147. PERIPH_ID_IRAMA,
  148. PERIPH_ID_IRAMB,
  149. PERIPH_ID_IRAMC,
  150. PERIPH_ID_IRAMD,
  151. /* 88 */
  152. PERIPH_ID_CRAM2,
  153. PERIPH_ID_COUNT,
  154. };
  155. /* Converts a clock number to a clock register: 0=L, 1=H, 2=U */
  156. #define PERIPH_REG(id) ((id) >> 5)
  157. /* Mask value for a clock (within PERIPH_REG(id)) */
  158. #define PERIPH_MASK(id) (1 << ((id) & 0x1f))
  159. /* return 1 if a PLL ID is in range */
  160. #define clock_id_isvalid(id) ((id) >= CLOCK_ID_FIRST && (id) < CLOCK_ID_COUNT)
  161. /* return 1 if a peripheral ID is in range */
  162. #define clock_periph_id_isvalid(id) ((id) >= PERIPH_ID_FIRST && \
  163. (id) < PERIPH_ID_COUNT)
  164. /* PLL stabilization delay in usec */
  165. #define CLOCK_PLL_STABLE_DELAY_US 300
  166. /* return the current oscillator clock frequency */
  167. enum clock_osc_freq clock_get_osc_freq(void);
  168. /**
  169. * Start PLL using the provided configuration parameters.
  170. *
  171. * @param id clock id
  172. * @param divm input divider
  173. * @param divn feedback divider
  174. * @param divp post divider 2^n
  175. * @param cpcon charge pump setup control
  176. * @param lfcon loop filter setup control
  177. *
  178. * @returns monotonic time in us that the PLL will be stable
  179. */
  180. unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
  181. u32 divp, u32 cpcon, u32 lfcon);
  182. /*
  183. * Enable a clock
  184. *
  185. * @param id clock id
  186. */
  187. void clock_enable(enum periph_id clkid);
  188. /*
  189. * Set whether a clock is enabled or disabled.
  190. *
  191. * @param id clock id
  192. * @param enable 1 to enable, 0 to disable
  193. */
  194. void clock_set_enable(enum periph_id clkid, int enable);
  195. /**
  196. * Reset a peripheral. This puts it in reset, waits for a delay, then takes
  197. * it out of reset and waits for th delay again.
  198. *
  199. * @param periph_id peripheral to reset
  200. * @param us_delay time to delay in microseconds
  201. */
  202. void reset_periph(enum periph_id periph_id, int us_delay);
  203. /**
  204. * Put a peripheral into or out of reset.
  205. *
  206. * @param periph_id peripheral to reset
  207. * @param enable 1 to put into reset, 0 to take out of reset
  208. */
  209. void reset_set_enable(enum periph_id periph_id, int enable);
  210. /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
  211. enum crc_reset_id {
  212. /* Things we can hold in reset for each CPU */
  213. crc_rst_cpu = 1,
  214. crc_rst_de = 1 << 2, /* What is de? */
  215. crc_rst_watchdog = 1 << 3,
  216. crc_rst_debug = 1 << 4,
  217. };
  218. /**
  219. * Put parts of the CPU complex into or out of reset.\
  220. *
  221. * @param cpu cpu number (0 or 1 on Tegra2)
  222. * @param which which parts of the complex to affect (OR of crc_reset_id)
  223. * @param reset 1 to assert reset, 0 to de-assert
  224. */
  225. void reset_cmplx_set_enable(int cpu, int which, int reset);
  226. #endif