clock.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. /* These are the base clocks (inputs to the Tegra SOC) */
  48. CLOCK_ID_32KHZ,
  49. CLOCK_ID_OSC,
  50. CLOCK_ID_COUNT, /* number of clocks */
  51. CLOCK_ID_NONE = -1,
  52. };
  53. /* The clocks supported by the hardware */
  54. enum periph_id {
  55. PERIPH_ID_FIRST,
  56. /* Low word: 31:0 */
  57. PERIPH_ID_CPU = PERIPH_ID_FIRST,
  58. PERIPH_ID_RESERVED1,
  59. PERIPH_ID_RESERVED2,
  60. PERIPH_ID_AC97,
  61. PERIPH_ID_RTC,
  62. PERIPH_ID_TMR,
  63. PERIPH_ID_UART1,
  64. PERIPH_ID_UART2,
  65. /* 8 */
  66. PERIPH_ID_GPIO,
  67. PERIPH_ID_SDMMC2,
  68. PERIPH_ID_SPDIF,
  69. PERIPH_ID_I2S1,
  70. PERIPH_ID_I2C1,
  71. PERIPH_ID_NDFLASH,
  72. PERIPH_ID_SDMMC1,
  73. PERIPH_ID_SDMMC4,
  74. /* 16 */
  75. PERIPH_ID_TWC,
  76. PERIPH_ID_PWM,
  77. PERIPH_ID_I2S2,
  78. PERIPH_ID_EPP,
  79. PERIPH_ID_VI,
  80. PERIPH_ID_2D,
  81. PERIPH_ID_USBD,
  82. PERIPH_ID_ISP,
  83. /* 24 */
  84. PERIPH_ID_3D,
  85. PERIPH_ID_IDE,
  86. PERIPH_ID_DISP2,
  87. PERIPH_ID_DISP1,
  88. PERIPH_ID_HOST1X,
  89. PERIPH_ID_VCP,
  90. PERIPH_ID_RESERVED30,
  91. PERIPH_ID_CACHE2,
  92. /* Middle word: 63:32 */
  93. PERIPH_ID_MEM,
  94. PERIPH_ID_AHBDMA,
  95. PERIPH_ID_APBDMA,
  96. PERIPH_ID_RESERVED35,
  97. PERIPH_ID_KBC,
  98. PERIPH_ID_STAT_MON,
  99. PERIPH_ID_PMC,
  100. PERIPH_ID_FUSE,
  101. /* 40 */
  102. PERIPH_ID_KFUSE,
  103. PERIPH_ID_SBC1,
  104. PERIPH_ID_SNOR,
  105. PERIPH_ID_SPI1,
  106. PERIPH_ID_SBC2,
  107. PERIPH_ID_XIO,
  108. PERIPH_ID_SBC3,
  109. PERIPH_ID_DVC_I2C,
  110. /* 48 */
  111. PERIPH_ID_DSI,
  112. PERIPH_ID_TVO,
  113. PERIPH_ID_MIPI,
  114. PERIPH_ID_HDMI,
  115. PERIPH_ID_CSI,
  116. PERIPH_ID_TVDAC,
  117. PERIPH_ID_I2C2,
  118. PERIPH_ID_UART3,
  119. /* 56 */
  120. PERIPH_ID_RESERVED56,
  121. PERIPH_ID_EMC,
  122. PERIPH_ID_USB2,
  123. PERIPH_ID_USB3,
  124. PERIPH_ID_MPE,
  125. PERIPH_ID_VDE,
  126. PERIPH_ID_BSEA,
  127. PERIPH_ID_BSEV,
  128. /* Upper word 95:64 */
  129. PERIPH_ID_SPEEDO,
  130. PERIPH_ID_UART4,
  131. PERIPH_ID_UART5,
  132. PERIPH_ID_I2C3,
  133. PERIPH_ID_SBC4,
  134. PERIPH_ID_SDMMC3,
  135. PERIPH_ID_PCIE,
  136. PERIPH_ID_OWR,
  137. /* 72 */
  138. PERIPH_ID_AFI,
  139. PERIPH_ID_CORESIGHT,
  140. PERIPH_ID_RESERVED74,
  141. PERIPH_ID_AVPUCQ,
  142. PERIPH_ID_RESERVED76,
  143. PERIPH_ID_RESERVED77,
  144. PERIPH_ID_RESERVED78,
  145. PERIPH_ID_RESERVED79,
  146. /* 80 */
  147. PERIPH_ID_RESERVED80,
  148. PERIPH_ID_RESERVED81,
  149. PERIPH_ID_RESERVED82,
  150. PERIPH_ID_RESERVED83,
  151. PERIPH_ID_IRAMA,
  152. PERIPH_ID_IRAMB,
  153. PERIPH_ID_IRAMC,
  154. PERIPH_ID_IRAMD,
  155. /* 88 */
  156. PERIPH_ID_CRAM2,
  157. PERIPH_ID_COUNT,
  158. };
  159. /* Converts a clock number to a clock register: 0=L, 1=H, 2=U */
  160. #define PERIPH_REG(id) ((id) >> 5)
  161. /* Mask value for a clock (within PERIPH_REG(id)) */
  162. #define PERIPH_MASK(id) (1 << ((id) & 0x1f))
  163. /* return 1 if a PLL ID is in range */
  164. #define clock_id_isvalid(id) ((id) >= CLOCK_ID_FIRST && (id) < CLOCK_ID_COUNT)
  165. /* PLL stabilization delay in usec */
  166. #define CLOCK_PLL_STABLE_DELAY_US 300
  167. /* return the current oscillator clock frequency */
  168. enum clock_osc_freq clock_get_osc_freq(void);
  169. /**
  170. * Start PLL using the provided configuration parameters.
  171. *
  172. * @param id clock id
  173. * @param divm input divider
  174. * @param divn feedback divider
  175. * @param divp post divider 2^n
  176. * @param cpcon charge pump setup control
  177. * @param lfcon loop filter setup control
  178. *
  179. * @returns monotonic time in us that the PLL will be stable
  180. */
  181. unsigned long clock_start_pll(enum clock_id id, u32 divm, u32 divn,
  182. u32 divp, u32 cpcon, u32 lfcon);
  183. /*
  184. * Enable a clock
  185. *
  186. * @param id clock id
  187. */
  188. void clock_enable(enum periph_id clkid);
  189. /*
  190. * Disable a clock
  191. *
  192. * @param id clock id
  193. */
  194. void clock_disable(enum periph_id clkid);
  195. /*
  196. * Set whether a clock is enabled or disabled.
  197. *
  198. * @param id clock id
  199. * @param enable 1 to enable, 0 to disable
  200. */
  201. void clock_set_enable(enum periph_id clkid, int enable);
  202. /**
  203. * Reset a peripheral. This puts it in reset, waits for a delay, then takes
  204. * it out of reset and waits for th delay again.
  205. *
  206. * @param periph_id peripheral to reset
  207. * @param us_delay time to delay in microseconds
  208. */
  209. void reset_periph(enum periph_id periph_id, int us_delay);
  210. /**
  211. * Put a peripheral into or out of reset.
  212. *
  213. * @param periph_id peripheral to reset
  214. * @param enable 1 to put into reset, 0 to take out of reset
  215. */
  216. void reset_set_enable(enum periph_id periph_id, int enable);
  217. /* CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET/CLR_0 */
  218. enum crc_reset_id {
  219. /* Things we can hold in reset for each CPU */
  220. crc_rst_cpu = 1,
  221. crc_rst_de = 1 << 2, /* What is de? */
  222. crc_rst_watchdog = 1 << 3,
  223. crc_rst_debug = 1 << 4,
  224. };
  225. /**
  226. * Put parts of the CPU complex into or out of reset.\
  227. *
  228. * @param cpu cpu number (0 or 1 on Tegra2)
  229. * @param which which parts of the complex to affect (OR of crc_reset_id)
  230. * @param reset 1 to assert reset, 0 to de-assert
  231. */
  232. void reset_cmplx_set_enable(int cpu, int which, int reset);
  233. /**
  234. * Set the source for a peripheral clock. This plus the divisor sets the
  235. * clock rate. You need to look up the datasheet to see the meaning of the
  236. * source parameter as it changes for each peripheral.
  237. *
  238. * Warning: This function is only for use pre-relocation. Please use
  239. * clock_start_periph_pll() instead.
  240. *
  241. * @param periph_id peripheral to adjust
  242. * @param source source clock (0, 1, 2 or 3)
  243. */
  244. void clock_ll_set_source(enum periph_id periph_id, unsigned source);
  245. /**
  246. * Set the source and divisor for a peripheral clock. This sets the
  247. * clock rate. You need to look up the datasheet to see the meaning of the
  248. * source parameter as it changes for each peripheral.
  249. *
  250. * Warning: This function is only for use pre-relocation. Please use
  251. * clock_start_periph_pll() instead.
  252. *
  253. * @param periph_id peripheral to adjust
  254. * @param source source clock (0, 1, 2 or 3)
  255. * @param divisor divisor value to use
  256. */
  257. void clock_ll_set_source_divisor(enum periph_id periph_id, unsigned source,
  258. unsigned divisor);
  259. /**
  260. * Start a peripheral PLL clock at the given rate. This also resets the
  261. * peripheral.
  262. *
  263. * @param periph_id peripheral to start
  264. * @param parent PLL id of required parent clock
  265. * @param rate Required clock rate in Hz
  266. * @return rate selected in Hz, or -1U if something went wrong
  267. */
  268. unsigned clock_start_periph_pll(enum periph_id periph_id,
  269. enum clock_id parent, unsigned rate);
  270. /**
  271. * Returns the rate of a peripheral clock in Hz. Since the caller almost
  272. * certainly knows the parent clock (having just set it) we require that
  273. * this be passed in so we don't need to work it out.
  274. *
  275. * @param periph_id peripheral to start
  276. * @param parent PLL id of parent clock (used to calculate rate, you
  277. * must know this!)
  278. * @return clock rate of peripheral in Hz
  279. */
  280. unsigned long clock_get_periph_rate(enum periph_id periph_id,
  281. enum clock_id parent);
  282. /**
  283. * Adjust peripheral PLL clock to the given rate. This does not reset the
  284. * peripheral. If a second stage divisor is not available, pass NULL for
  285. * extra_div. If it is available, then this parameter will return the
  286. * divisor selected (which will be a power of 2 from 1 to 256).
  287. *
  288. * @param periph_id peripheral to start
  289. * @param parent PLL id of required parent clock
  290. * @param rate Required clock rate in Hz
  291. * @param extra_div value for the second-stage divisor (NULL if one is
  292. not available)
  293. * @return rate selected in Hz, or -1U if something went wrong
  294. */
  295. unsigned clock_adjust_periph_pll_div(enum periph_id periph_id,
  296. enum clock_id parent, unsigned rate, int *extra_div);
  297. /**
  298. * Returns the clock rate of a specified clock, in Hz.
  299. *
  300. * @param parent PLL id of clock to check
  301. * @return rate of clock in Hz
  302. */
  303. unsigned clock_get_rate(enum clock_id clkid);
  304. /*
  305. * Checks that clocks are valid and prints a warning if not
  306. *
  307. * @return 0 if ok, -1 on error
  308. */
  309. int clock_verify(void);
  310. /* Initialize the clocks */
  311. void clock_init(void);
  312. /* Initialize the PLLs */
  313. void clock_early_init(void);
  314. #endif