sysctl_clk.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /* Copyright (c) 2023, Canaan Bright Sight Co., Ltd
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * 1. Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * 2. Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. *
  11. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  12. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  13. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  16. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  18. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  19. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  23. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #ifndef __SYSCTL_CLK_H__
  26. #define __SYSCTL_CLK_H__
  27. #include <stdint.h>
  28. #include <stdbool.h>
  29. /* See TRM 2.2.4 Table 2-2-9 */
  30. typedef struct sysctl_clk {
  31. volatile uint32_t cpu0_clk_cfg; /* 0x00 */
  32. volatile uint32_t reserved_0; /* 0x04 */
  33. volatile uint32_t reserved_1; /* 0x08 */
  34. volatile uint32_t reserved_2; /* 0x0c */
  35. volatile uint32_t pmu_clk_cfg; /* 0x10 */
  36. volatile uint32_t reserved0[1]; /* 0x14 */
  37. volatile uint32_t hs_clken_cfg; /* 0x18 */
  38. volatile uint32_t hs_sdclk_cfg; /* 0x1c */
  39. volatile uint32_t hs_spi_cfg; /* 0x20 */
  40. volatile uint32_t ls_clken_cfg0; /* 0x24 */
  41. volatile uint32_t ls_clken_cfg1; /* 0x28 */
  42. volatile uint32_t uart_i2c_clkdiv_cfg; /* 0x2c */
  43. volatile uint32_t ls_clkdiv_cfg; /* 0x30 */
  44. volatile uint32_t reserved_3; /* 0x34 */
  45. volatile uint32_t reserved_4; /* 0x38 */
  46. volatile uint32_t reserved_5; /* 0x3c */
  47. volatile uint32_t reserved_6; /* 0x40 */
  48. volatile uint32_t reserved_7; /* 0x44 */
  49. volatile uint32_t reserved1[2]; /* 0x48 0x4c */
  50. volatile uint32_t sysctl_clken_cfg; /* 0x50 */
  51. volatile uint32_t timer_clk_cfg; /* 0x54 */
  52. volatile uint32_t sysctl_clk_div_cfg; /* 0x58 */
  53. volatile uint32_t shrm_clk_cfg; /* 0x5c */
  54. volatile uint32_t ddr_clk_cfg; /* 0x60 */
  55. volatile uint32_t reserved_8; /* 0x64 */
  56. volatile uint32_t reserved_9; /* 0x68 */
  57. volatile uint32_t reserved_10; /* 0x6c */
  58. volatile uint32_t reserved_11; /* 0x70 */
  59. volatile uint32_t reserved_12; /* 0x74 */
  60. volatile uint32_t reserved_13; /* 0x78 */
  61. volatile uint32_t reserved2[1]; /* 0x7c */
  62. volatile uint32_t sec_clk_div; /* 0x80 */
  63. volatile uint32_t reserved3[31]; /* 0x84 0x88 0x8c 0x90 0x94 0x98 0x9c 0xa0-0xac 0xb0-0xbc 0xc0-0xcc 0xd0-0xdc 0xe0-0xec 0xf0-0xfc*/
  64. volatile uint32_t usb_test_clk_div; /* 0x100 */
  65. volatile uint32_t dphy_test_clk_div; /* 0x104 */
  66. volatile uint32_t spi2axi_clk_div; /* 0x108 */
  67. } sysctl_clk_t;
  68. /*
  69. * Clock Tree and clock node table
  70. *
  71. * Abbreviations:
  72. * - D: DIV
  73. * - G: GATE
  74. * - M: MUX
  75. * - fD: fraDIV
  76. */
  77. typedef enum {
  78. /*
  79. * First level is sysctl_boot / sysctrl_root module, which
  80. * is composed of osc24m, pll[0|1|2|3], pll[0|1|2|3]_[div2|div3|div4] (pllx
  81. * outputs 4 signals, namely pllx, div2, div3, and div4).
  82. * Plus timerx_pulse_in, which is an external pulse input through the soc
  83. * pin (pinmux) as a source of timer clock.
  84. *
  85. * - osc24m: fixed-clock
  86. * - pll[0|1|2|3]: clock generated by PLL
  87. * - pll[0|1|2|3]_[div2|div3|div4]: fixed-clock
  88. * - timerx_pulse_in: fixed-clock, maxsize is 1MHz
  89. *
  90. * osc24m ---+--> pll0 ---+--------> pll0 ------->+
  91. * | +--(D2)--> pll0_div2 -->|
  92. * | +--(D3)--> pll0_div3 -->|
  93. * | +--(D4)--> pll0_div4 -->|
  94. * | |
  95. * +--> pll1 ---+--------> pll1 ------->|
  96. * | +--(D2)--> pll1_div2 -->|
  97. * | +--(D3)--> pll1_div3 -->|
  98. * | +--(D4)--> pll1_div4 -->|
  99. * | +--> sysctl_clock
  100. * +--> pll2 ---+--------> pll2 ------->|
  101. * | +--(D2)--> pll2_div2 -->|
  102. * | +--(D3)--> pll2_div3 -->|
  103. * | +--(D4)--> pll2_div4 -->|
  104. * | |
  105. * +--> pll3 ---+--------> pll3 ------->|
  106. * | +--(D2)--> pll3_div2 -->|
  107. * | +--(D3)--> pll3_div3 -->|
  108. * | +--(D4)--> pll3_div4 -->|
  109. * | |
  110. * +----------------------------------->+
  111. * |
  112. * timerx_pulse_in ------------------------------>+
  113. */
  114. SYSCTL_CLK_ROOT_OSC_IN = 0, /* 24M */
  115. SYSCTL_CLK_ROOT_TIMERX_PULSE_IN, /* 50M */
  116. SYSCTL_CLK_ROOT_PLL0, /* 1.6G */
  117. SYSCTL_CLK_ROOT_PLL0_DIV_2, /* 800M */
  118. SYSCTL_CLK_ROOT_PLL0_DIV_3, /* 533M */
  119. SYSCTL_CLK_ROOT_PLL0_DIV_4, /* 400M */
  120. SYSCTL_CLK_ROOT_PLL1, /* 2.376G */
  121. SYSCTL_CLK_ROOT_PLL1_DIV_2, /* 1.188G */
  122. SYSCTL_CLK_ROOT_PLL1_DIV_3, /* 792M */
  123. SYSCTL_CLK_ROOT_PLL1_DIV_4, /* 594M */
  124. SYSCTL_CLK_ROOT_PLL2, /* 2.667G */
  125. SYSCTL_CLK_ROOT_PLL2_DIV_2, /* 1.3335G */
  126. SYSCTL_CLK_ROOT_PLL2_DIV_3, /* 889M */
  127. SYSCTL_CLK_ROOT_PLL2_DIV_4, /* 666.75M */
  128. SYSCTL_CLK_ROOT_PLL3, /* 1.6G */
  129. SYSCTL_CLK_ROOT_PLL3_DIV_2, /* 800M */
  130. SYSCTL_CLK_ROOT_PLL3_DIV_3, /* 533M */
  131. SYSCTL_CLK_ROOT_PLL3_DIV_4, /* 400M */
  132. SYSCTL_CLK_ROOT_MAX,
  133. /*
  134. * Second level is sysctl_clock module, which is composed of several clock sub-trees
  135. * - CPU0: aclk/pliclk/pclk
  136. * - pmu system: pclk
  137. * - HS (High Speed) system: hs/sdx/ssix/usbx
  138. * - LS (Low Speed) system : ls/uartx/i2cx/gpio/pwm/jamlinkx/audio/adc/codec
  139. * - System Control (such as wdt, timer, iomux, mailbox): sysctl/wdtx/timer/iomux/mailbox/hdi/stc/ts
  140. * - Timer: timerx
  141. * - shrm (share memory) system: shrm/decompress/gsdma/nonai2d/pdma
  142. * - sec (security) system: aclk/fixclk/pclk
  143. * - usb test mode: clk480/clk100
  144. * - dphy dft mode clock: dphy_test_clk
  145. * - spi2axi clock: aclk
  146. */
  147. /*
  148. * cpu0 clock tree:
  149. *
  150. * pll0_div2 --(DG)--> cpu0_src --+--(DG)--> cpu0_plic
  151. * |--(D)---> cpu0_aclk
  152. * +--(G)---> cpu0_noc_ddrcp4
  153. * pll0_div4 --(DG)--> cpu0_pclk
  154. */
  155. /* root node: pll0_div2 */
  156. SYSCTL_CLK_CPU0_SRC, /* cpu0 core,defualt 800MHz ---> select pll0_div_2 */
  157. SYSCTL_CLK_CPU0_PLIC, /* cpu0 plic clk,400MHz */
  158. SYSCTL_CLK_CPU0_ACLK, /* cpu0 axi clk,400MHz */
  159. SYSCTL_CLK_CPU0_NOC_DDRCP4, /* ddrc axi4clk & noc AXI clock,400MHz */
  160. /* root node: pll0_div4 */
  161. SYSCTL_CLK_CPU0_PCLK, /* cpu0 apb pclk,200MHz */
  162. /*
  163. * pmu system clock tree:
  164. *
  165. * osc24m -->(G)--> pmu_pclk
  166. *
  167. * - pmu_pclk: pmu apb clk gate
  168. */
  169. SYSCTL_CLK_PMU_PCLK,
  170. /*
  171. * High-Speed system clock tree
  172. *
  173. * pll0_div4 --+--(D)--> hs_hclk_high_src --+--(G)----> hs_hclk_high_gate
  174. * | |
  175. * | +--(DG)--> hs_hclk_src --+--(G)--> sd0_ahb_gate
  176. * | |--(G)--> sd1_ahb_gate
  177. * | |--(G)--> ssi1_ahb_gate
  178. * | |--(G)--> ssi2_ahb_gate
  179. * | |--(G)--> usb0_ahb_gate
  180. * | +--(G)--> usb1_ahb_gate
  181. * |
  182. * +--(DG)--> ssi0_axi
  183. * |--(DG)--> ssi1
  184. * |--(DG)--> ssi2
  185. * +--(DG)--> qspi_axi_src --+--(G)--> ssi1_aclk_gate
  186. * | |
  187. * | +--(G)--> ssi2_aclk_gate
  188. * |
  189. * +--(DG)--> sd_card_src --+--(G)--> sd0_card_gate
  190. * |
  191. * +--(G)--> sd1_card_gate
  192. *
  193. * pll0_div2 --\
  194. * (M)--(G)--> ssi0
  195. * pll2_div4 --/
  196. *
  197. *
  198. * pll2_div4 --(DG)--> sd_axi_src --+--(G)--> sd0_axi_gate
  199. * |--(G)--> sd1_axi_gate
  200. * |--(G)--> sd0_base_gate
  201. * +--(G)--> sd1_base_gate
  202. *
  203. *
  204. *
  205. * osc24m -----------------------------------------\
  206. * (M)--+--(G)--> usb0_ref_gate
  207. * pll0 --(D)--> pll0_div16 --(D)--> usb_ref_50m --/ |
  208. * +--(G)--> usb1_ref_gate
  209. *
  210. *
  211. * osc24m --(DG)--> sd_timer_src --+--(G)--> sd0_timer_gate
  212. * |
  213. * +--(G)--> sd1_timer_gate
  214. */
  215. /* root node: pll0_div4, through hs_hclk_high_src */
  216. SYSCTL_CLK_HS_HCLK_HIGH_SRC,
  217. SYSCTL_CLK_HS_HCLK_HIGH_GATE,
  218. SYSCTL_CLK_HS_HCLK_SRC,
  219. SYSCTL_CLK_SD0_AHB_GATE,
  220. SYSCTL_CLK_SD1_AHB_GATE,
  221. SYSCTL_CLK_USB0_AHB_GATE,
  222. SYSCTL_CLK_USB1_AHB_GATE,
  223. SYSCTL_CLK_SSI1_AHB_GATE,
  224. SYSCTL_CLK_SSI2_AHB_GATE,
  225. /* root node: pll0_div4 */
  226. SYSCTL_CLK_SSI0_AXI,
  227. SYSCTL_CLK_SSI1,
  228. SYSCTL_CLK_SSI2,
  229. SYSCTL_CLK_QSPI_AXI_SRC,
  230. SYSCTL_CLK_SSI1_ACLK_GATE,
  231. SYSCTL_CLK_SSI2_ACLK_GATE,
  232. /*root node: pll0_div4, through sd_card_src */
  233. SYSCTL_CLK_SD_CARD_SRC,
  234. SYSCTL_CLK_SD0_CARD_GATE,
  235. SYSCTL_CLK_SD1_CARD_GATE,
  236. /* root node: pll0_div2 MUX pll2_div4 */
  237. SYSCTL_CLK_SSI0, /* ospi core clk */
  238. /* root node: pll2_div4 */
  239. SYSCTL_CLK_SD_AXI_SRC,
  240. SYSCTL_CLK_SD0_AXI_GATE,
  241. SYSCTL_CLK_SD1_AXI_GATE,
  242. SYSCTL_CLK_SD0_BASE_GATE,
  243. SYSCTL_CLK_SD1_BASE_GATE,
  244. /* root node: pll0_div16 */
  245. SYSCTL_CLK_PLL0_DIV16,
  246. SYSCTL_CLK_USB_REF_50M, /* usbx reference clk */
  247. SYSCTL_CLK_USB0_REF_GATE,
  248. SYSCTL_CLK_USB1_REF_GATE,
  249. /* root node: osc24m */
  250. SYSCTL_CLK_SD_TIMER_SRC,
  251. SYSCTL_CLK_SD0_TIMER_GATE,
  252. SYSCTL_CLK_SD1_TIMER_GATE,
  253. /* Low-Speed system clock tree
  254. *
  255. * pll0_div4 --(DG)--+--> ls_apb_src --+--(G) --> uart0_apb_gate
  256. * | +--(G) --> uart1_apb_gate
  257. * | +--(G) --> uart2_apb_gate
  258. * | +--(G) --> uart3_apb_gate
  259. * | +--(G) --> uart4_apb_gate
  260. * | +--(G) --> i2c0_apb_gate
  261. * | +--(G) --> i2c1_apb_gate
  262. * | +--(G) --> i2c2_apb_gate
  263. * | +--(G) --> i2c3_apb_gate
  264. * | +--(G) --> i2c4_apb_gate
  265. * | +--(G) --> gpio_apb_gate
  266. * | +--(G) --> pwm_apb_gate
  267. * | +--(G) --> jamlink0_apb_gate
  268. * | +--(G) --> jamlink1_apb_gate
  269. * | +--(G) --> jamlink2_apb_gate
  270. * | +--(G) --> jamlink3_apb_gate
  271. * | +--(G) --> audio_apb_gate
  272. * | +--(G) --> adc_apb_gate
  273. * | +--(G) --> codec_apb_gate
  274. * |
  275. * +--(DG)--> i2c0_core
  276. * +--(DG)--> i2c1_core
  277. * +--(DG)--> i2c2_core
  278. * +--(DG)--> i2c3_core
  279. * +--(DG)--> i2c4_core
  280. * +--(DG)--> codec_adc
  281. * +--(DG)--> codec_dac
  282. * +--(DG)--> audio_dev
  283. * +--(DG)--> pdm
  284. * +--(DG)--> adc
  285. *
  286. * pll0 --(D)--> pll0_div16 --+--(DG)--> uart0_core
  287. * +--(DG)--> uart1_core
  288. * +--(DG)--> uart2_core
  289. * +--(DG)--> uart3_core
  290. * +--(DG)--> uart4_core
  291. *
  292. * pll0 --(D)--> pll0_div16 --(D)--> jamlink_CO_div --+--(G)--> jamlink0_CO_gate
  293. * +--(G)--> jamlink1_CO_gate
  294. * +--(G)--> jamlink2_CO_gate
  295. * +--(G)--> jamlink3_CO_gate
  296. *
  297. * osc24m --(DG)--> gpio_debounce
  298. */
  299. /* root node: pll0_div4, through ls_apb_src */
  300. SYSCTL_CLK_LS_APB_SRC,
  301. SYSCTL_CLK_UART0_APB_GATE,
  302. SYSCTL_CLK_UART1_APB_GATE,
  303. SYSCTL_CLK_UART2_APB_GATE,
  304. SYSCTL_CLK_UART3_APB_GATE,
  305. SYSCTL_CLK_UART4_APB_GATE,
  306. SYSCTL_CLK_I2C0_APB_GATE,
  307. SYSCTL_CLK_I2C1_APB_GATE,
  308. SYSCTL_CLK_I2C2_APB_GATE,
  309. SYSCTL_CLK_I2C3_APB_GATE,
  310. SYSCTL_CLK_I2C4_APB_GATE,
  311. SYSCTL_CLK_GPIO_APB_GATE,
  312. SYSCTL_CLK_PWM_APB_GATE,
  313. SYSCTL_CLK_JAMLINK0_APB_GATE,
  314. SYSCTL_CLK_JAMLINK1_APB_GATE,
  315. SYSCTL_CLK_JAMLINK2_APB_GATE,
  316. SYSCTL_CLK_JAMLINK3_APB_GATE,
  317. SYSCTL_CLK_AUDIO_APB_GATE,
  318. SYSCTL_CLK_ADC_APB_GATE,
  319. SYSCTL_CLK_CODEC_APB_GATE,
  320. /* root node: pll0_div4 */
  321. SYSCTL_CLK_I2C0_CORE,
  322. SYSCTL_CLK_I2C1_CORE,
  323. SYSCTL_CLK_I2C2_CORE,
  324. SYSCTL_CLK_I2C3_CORE,
  325. SYSCTL_CLK_I2C4_CORE,
  326. SYSCTL_CLK_CODEC_ADC,
  327. SYSCTL_CLK_CODEC_DAC,
  328. SYSCTL_CLK_AUDIO_DEV,
  329. SYSCTL_CLK_PDM,
  330. SYSCTL_CLK_ADC,
  331. /* root node: pll0_div16 */
  332. SYSCTL_CLK_UART0_CORE,
  333. SYSCTL_CLK_UART1_CORE,
  334. SYSCTL_CLK_UART2_CORE,
  335. SYSCTL_CLK_UART3_CORE,
  336. SYSCTL_CLK_UART4_CORE,
  337. /* root node: pll0_div16, through jamlink_CO_div */
  338. SYSCTL_CLK_JAMLINK_CO_DIV,
  339. SYSCTL_CLK_JAMLINK0_CO_GATE,
  340. SYSCTL_CLK_JAMLINK1_CO_GATE,
  341. SYSCTL_CLK_JAMLINK2_CO_GATE,
  342. SYSCTL_CLK_JAMLINK3_CO_GATE,
  343. /* root node: osc24m */
  344. SYSCTL_CLK_GOIP_DEBOUNCE,
  345. /*
  346. * System Control clock tree
  347. *
  348. * pll0_div16 --> sysctl_apb_src --+--(G)--> wdt0_apb_gate
  349. * +--(G)--> wdt1_apb_gate
  350. * +--(G)--> timer_apb_gate
  351. * +--(G)--> iomux_apb_gate
  352. * +--(G)--> mailbox_apb_gate
  353. *
  354. * pll0_div4 --(DG)--> hdi_core
  355. *
  356. * pll1_div4 --(DG)--> timestamp
  357. *
  358. * osc24m --(D)--> temp_sensor
  359. *
  360. * osc24m --+--(DG)--> wdt0
  361. * |
  362. * +--(DG)--> wdt1
  363. */
  364. /* root node: pll0_div16, through sysctl_apb_src */
  365. SYSCTL_CLK_SYSCTRL_APB_SRC,
  366. SYSCTL_CLK_WDT0_APB_GATE,
  367. SYSCTL_CLK_WDT1_APB_GATE,
  368. SYSCTL_CLK_TIMER_APB_GATE,
  369. SYSCTL_CLK_IOMUX_APB_GATE,
  370. SYSCTL_CLK_MAILBOX_APB_GATE,
  371. /* root node: pll0_div4 */
  372. SYSCTL_CLK_HDI_CORE,
  373. /* root node: pll1_div4 */
  374. SYSCTL_CLK_TIMESTAMP,
  375. /* root node: osc24m */
  376. SYSCTL_CLK_TEMP_SENSOR,
  377. /* root node: osc24m */
  378. SYSCTL_CLK_WDT0,
  379. SYSCTL_CLK_WDT1,
  380. /*
  381. * timer clock tree
  382. *
  383. * pll0_div16 --(D)--> timer0_src --\
  384. * (M)--(G)-->timer0
  385. * timerx_pulse_in -----------------/
  386. *
  387. * pll0_div16 --(D)--> timer1_src --\
  388. * (M)--(G)-->timer1
  389. * timerx_pulse_in -----------------/
  390. *
  391. * pll0_div16 --(D)--> timer2_src --\
  392. * (M)--(G)-->timer2
  393. * timerx_pulse_in -----------------/
  394. *
  395. * pll0_div16 --(D)--> timer3_src --\
  396. * (M)--(G)-->timer3
  397. * timerx_pulse_in -----------------/
  398. *
  399. * pll0_div16 --(D)--> timer4_src --\
  400. * (M)--(G)-->timer4
  401. * timerx_pulse_in -----------------/
  402. *
  403. * pll0_div16 --(D)--> timer5_src --\
  404. * (M)--(G)-->timer5
  405. * timerx_pulse_in -----------------/
  406. */
  407. /* root node: pll0_div16 & timerx_pulse_in */
  408. SYSCTL_CLK_TIMERX_PULSE_IN,
  409. SYSCTL_CLK_TIMER0_SRC,
  410. SYSCTL_CLK_TIMER0,
  411. SYSCTL_CLK_TIMER1_SRC,
  412. SYSCTL_CLK_TIMER1,
  413. SYSCTL_CLK_TIMER2_SRC,
  414. SYSCTL_CLK_TIMER2,
  415. SYSCTL_CLK_TIMER3_SRC,
  416. SYSCTL_CLK_TIMER3,
  417. SYSCTL_CLK_TIMER4_SRC,
  418. SYSCTL_CLK_TIMER4,
  419. SYSCTL_CLK_TIMER5_SRC,
  420. SYSCTL_CLK_TIMER5,
  421. /*
  422. * shrm system clock tree
  423. *
  424. * pll0_div2 --\
  425. * (M)--(G)--> shrm_src --+--(D)--> shrm_div2 --(G)--> shrm_axi_slave
  426. * pll3_div2 --/ |
  427. * +--(G)--> decompress_axi
  428. *
  429. * pll0_div4 -->(DG)--> shrm_apb
  430. *
  431. * pll0_div4 -->(G)--> shrm_axi_src --+--(G)--> gsdma_axi_gate
  432. * +--(G)--> nonai2d_axi_gate
  433. * +--(G)--> peri_dma_axi_gate
  434. */
  435. /* root node: pll0_div2 & pll3_div2 */
  436. SYSCTL_CLK_SHRM_SRC,
  437. SYSCTL_CLK_SHRM_DIV2,
  438. SYSCTL_CLK_SHRM_AXIS_SLAVE,
  439. SYSCTL_CLK_DECOMPRESS_AXI,
  440. /* root node: pll0_div4 */
  441. SYSCTL_CLK_SHRM_APB,
  442. /* root node: pll0_div4, through shrm_axi_src */
  443. SYSCTL_CLK_SHRM_AXI_SRC,
  444. SYSCTL_CLK_GSDMA_AXI_GATE,
  445. SYSCTL_CLK_NONAI2D_AXI_GATE,
  446. SYSCTL_CLK_PERI_DMA_AXI_GATE,
  447. /*
  448. * Security system clock tree
  449. *
  450. * pll0_div4 --(DG)--> sec_apb
  451. *
  452. * pll1_div4 --+--(DG)--> sec_fix
  453. * |
  454. * +--(DG)--> sec_axi
  455. */
  456. /* root node: pll0_div4 */
  457. SYSCTL_CLK_SEC_APB,
  458. /* root node: pll1_div4 */
  459. SYSCTL_CLK_SEC_FIX,
  460. SYSCTL_CLK_SEC_AXI,
  461. /*
  462. * usb test mode clock tree
  463. *
  464. * pll1 --(DG)--> usb_480m
  465. *
  466. * pll0_div4 --(DG)--> usb_100m
  467. */
  468. /* root node: pll1 */
  469. SYSCTL_CLK_USB_480M,
  470. /* root node: pll0_div4 */
  471. SYSCTL_CLK_USB_100M,
  472. /*
  473. * dphy dft mode clock tree
  474. *
  475. * pll0 --(DG)--> dphy_dft_mode
  476. */
  477. /* root node: pll0 */
  478. SYSCTL_CLK_DPHY_DFT_MODE,
  479. /*
  480. * spi2axi clock tree
  481. *
  482. * pll0_div4 --(DG)--> spi2axi_axi
  483. */
  484. /* root node: pll0_div4 */
  485. SYSCTL_CLK_SPI2AXI_AXI,
  486. SYSCTL_CLK_NODE_MAX,
  487. } sysctl_clk_node_e;
  488. #define SYSCTL_READ_ENABLE (1 << 0)
  489. #define SYSCTL_READ_DISABLE (0 << 0)
  490. #define SYSCTL_WRITE_ENABLE (1 << 1)
  491. #define SYSCTL_WRITE_DISABLE (0 << 1)
  492. /*
  493. * API for root clock. 24M, PLL0-3, these 5 clocks are root clocks
  494. * It is assumed here that the big core has read and write permissions to the
  495. * root clock, so the properties of clk are not judged in these APIs,
  496. * because these APIs are only for the root clock.
  497. */
  498. /*
  499. * Get the bypass status of the PLL.
  500. * If it is bypas, the PLL output is 24M OSC clock.
  501. */
  502. bool sysctl_boot_get_root_clk_bypass(sysctl_clk_node_e clk);
  503. void sysctl_boot_set_root_clk_bypass(sysctl_clk_node_e clk, bool enable);
  504. /* Enable pll, enable 24M clock&pll */
  505. bool sysctl_boot_get_root_clk_en(sysctl_clk_node_e clk);
  506. void sysctl_boot_set_root_clk_en(sysctl_clk_node_e clk, bool enable);
  507. /* Get the phase-locked loop lock status */
  508. bool sysctl_boot_get_root_clk_lock(sysctl_clk_node_e clk);
  509. /* Get the root clock frequency */
  510. uint32_t sysctl_boot_get_root_clk_freq(sysctl_clk_node_e clk);
  511. /*
  512. * Set the PLL clock frequency
  513. * The formula for setting the PLL clock frequency is:
  514. * pll_out_freq = (double)OSC_CLOCK_FREQ_24M * (double)(fbdiv+1) / (double)(refdiv+1) / (double)(outdiv+1)
  515. */
  516. bool sysctl_boot_set_root_clk_freq(sysctl_clk_node_e clk, uint32_t fbdiv, uint32_t refdiv, uint32_t outdiv, uint32_t bwadj);
  517. /*
  518. * API for trunk and leaf nodes in the clock tree, i.e. clocks other than the five root clocks.
  519. */
  520. /*
  521. * Set the leaf node clock source on the clock tree.
  522. * Please set it according to the clock tree.
  523. * Many clock nodes have only one clock source, so the setting will return false.
  524. */
  525. bool sysctl_clk_set_leaf_parent(sysctl_clk_node_e leaf, sysctl_clk_node_e parent);
  526. /* Get the clock source of the leaf node in the clock tree */
  527. sysctl_clk_node_e sysctl_clk_get_leaf_parent(sysctl_clk_node_e leaf);
  528. /*
  529. * Set the clock node enable.
  530. * Note: only set the enable of this clock node, and do not set the enable of
  531. * the upstream clock.
  532. * Difference from Linux kernel: Linux kernel clock framework will automatically
  533. * set the enable of the upstream clock. The test code does not have kernel
  534. * framework, so only the enable of the clock of this node is set.
  535. */
  536. void sysctl_clk_set_leaf_en(sysctl_clk_node_e leaf, bool enable);
  537. /* Get the enable status of this clock node */
  538. bool sysctl_clk_get_leaf_en(sysctl_clk_node_e leaf);
  539. /* Set the frequency division factor of this clock node */
  540. bool sysctl_clk_set_leaf_div(sysctl_clk_node_e leaf, uint32_t numerator, uint32_t denominator);
  541. /* Get the frequency division coefficient of this clock node */
  542. double sysctl_clk_get_leaf_div(sysctl_clk_node_e leaf);
  543. /*
  544. * Calculate clock freqency.
  545. * This API searches the entire clock path, calculates the frequency division
  546. * at each level starting from the clock source, and finally obtains the
  547. * current clock frequency.
  548. */
  549. uint32_t sysctl_clk_get_leaf_freq(sysctl_clk_node_e leaf);
  550. #endif /* __SYSCTL_CLK_H__ */