hal_prcm.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /*
  2. *********************************************************************************************************
  3. * AR100 SYSTEM
  4. * AR100 Software System Develop Kits
  5. * clock control unit module
  6. *
  7. * (c) Copyright 2012-2016, Sunny China
  8. * All Rights Reserved
  9. *
  10. * File : prcm.h
  11. * By : Sunny
  12. * Version : v1.0
  13. * Date : 2012-4-28
  14. * Descript: clock control unit public header.
  15. * Update : date auther ver notes
  16. * 2012-4-28 14:48:38 Sunny 1.0 Create this file.
  17. *********************************************************************************************************
  18. */
  19. #ifndef __PRCM_H__
  20. #define __PRCM_H__
  21. #include <sunxi_hal_rtc.h>
  22. #include <sunxi_hal_common.h>
  23. /* the clock status of on-off */
  24. typedef enum ccu_clk_onoff {
  25. CCU_CLK_OFF = 0x0, /* clock off status */
  26. CCU_CLK_ON = 0x1, /* clock on status */
  27. } ccu_clk_onff_e;
  28. /* the clock status of reset */
  29. typedef enum ccu_clk_reset {
  30. CCU_CLK_RESET = 0x0, /* reset valid status */
  31. CCU_CLK_NRESET = 0x1, /* reset invalid status */
  32. } ccu_clk_reset_e;
  33. /* command for call-back function of clock change */
  34. typedef enum ccu_clk_cmd {
  35. CCU_CLK_CLKCHG_REQ = 0x0, /* command for notify that clock will change */
  36. CCU_CLK_CLKCHG_DONE, /* command for notify that clock change finish */
  37. } ccu_clk_cmd_e;
  38. /* command for call-back function of 24M hosc on-off */
  39. typedef enum ccu_hosc_cmd {
  40. CCU_HOSC_ON_READY_NOTIFY = 0x0, /* command for notify that 24mhosc power-on already */
  41. CCU_HOSC_WILL_OFF_NOTIFY, /* command for notify that 24mhosc will off */
  42. } ccu_hosc_cmd_e;
  43. /* the state of power-off gating */
  44. typedef enum poweroff_gating_state {
  45. CCU_POWEROFF_GATING_INVALID = 0x0,
  46. CCU_POWEROFF_GATING_VALID = 0x1,
  47. } poweroff_gating_state_e;
  48. /* source clocks ID */
  49. typedef enum ccu_src_clk {
  50. CCU_SYS_CLK_NONE = 0x0, /* invalid source clock id */
  51. CCU_SYS_CLK_LOSC, /* LOSC, 33/50/67:32768Hz, 73:16MHz/512=31250 */
  52. CCU_SYS_CLK_IOSC, /* InternalOSC, 33/50/67:700KHZ, 73:16MHz */
  53. CCU_SYS_CLK_HOSC, /* HOSC, 24MHZ clock */
  54. CCU_SYS_CLK_AXI, /* AXI clock */
  55. CCU_SYS_CLK_16M, /* 16M for the backdoor */
  56. CCU_SYS_CLK_PLL1, /* PLL1 clock */
  57. CCU_SYS_CLK_PLL2, /* PLL2 clock */
  58. CCU_SYS_CLK_PLL3, /* PLL3 clock */
  59. CCU_SYS_CLK_PLL4, /* PLL4 clock */
  60. CCU_SYS_CLK_PLL5, /* PLL5 clock */
  61. CCU_SYS_CLK_PLL6, /* PLL6 clock */
  62. CCU_SYS_CLK_PLL7, /* PLL7 clock */
  63. CCU_SYS_CLK_PLL8, /* PLL8 clock */
  64. CCU_SYS_CLK_PLL9, /* PLL9 clock */
  65. CCU_SYS_CLK_PLL10, /* PLL10 clock */
  66. CCU_SYS_CLK_PLL11, /* PLL10 clock */
  67. CCU_SYS_CLK_AUDIO0, /* AUDIO0 clock */
  68. CCU_SYS_CLK_AUDIO1, /* AUDIO1 clock */
  69. CCU_SYS_CLK_CPUS, /* cpus clock */
  70. CCU_SYS_CLK_C0, /* cluster0 clock */
  71. CCU_SYS_CLK_C1, /* cluster1 clock */
  72. CCU_SYS_CLK_DDR0, /* ddr0 clock */
  73. CCU_SYS_CLK_DDR1, /* ddr1 clock */
  74. CCU_SYS_CLK_PERI0, /* peri0 clock */
  75. CCU_SYS_CLK_PERI1, /* peri1 clock */
  76. CCU_SYS_CLK_AXI0, /* AXI0 clock */
  77. CCU_SYS_CLK_AXI1, /* AXI0 clock */
  78. CCU_SYS_CLK_AHB0, /* AHB0 clock */
  79. CCU_SYS_CLK_AHB1, /* AHB1 clock */
  80. CCU_SYS_CLK_AHB2, /* AHB2 clock */
  81. CCU_SYS_CLK_APB0, /* APB0 clock */
  82. CCU_SYS_CLK_APB1, /* APB1 clock */
  83. CCU_SYS_CLK_APB2, /* APB2 clock */
  84. CCU_SYS_CLK_AHB3, /* AHB3 clock */
  85. CCU_SYS_CLK_PSI, /* PSI clock */
  86. CCU_SYS_CLK_AHBS, /* AHBS clock */
  87. CCU_SYS_CLK_APBS1, /* APBS1 clock */
  88. CCU_SYS_CLK_APBS2, /* APBS2 clock */
  89. } ccu_sys_clk_e;
  90. /* module clocks ID */
  91. typedef enum ccu_mod_clk {
  92. CCU_MOD_CLK_NONE,
  93. CCU_MOD_CLK_CPUS,
  94. CCU_MOD_CLK_AHB0,
  95. CCU_MOD_CLK_APB0,
  96. CCU_MOD_CLK_C0,
  97. CCU_MOD_CLK_C1,
  98. CCU_MOD_CLK_CPU0,
  99. CCU_MOD_CLK_CPU1,
  100. CCU_MOD_CLK_CPU2,
  101. CCU_MOD_CLK_CPU3,
  102. CCU_MOD_CLK_AHB1,
  103. CCU_MOD_CLK_AHB2,
  104. CCU_MOD_CLK_APB1,
  105. CCU_MOD_CLK_APB2,
  106. CCU_MOD_CLK_DMA,
  107. CCU_MOD_CLK_SDRAM,
  108. CCU_MOD_CLK_SPINLOCK,
  109. CCU_MOD_CLK_MSGBOX,
  110. CCU_MOD_CLK_MSGBOX0,
  111. CCU_MOD_CLK_MSGBOX1,
  112. CCU_MOD_CLK_MSGBOXR,
  113. CCU_MOD_CLK_AHB1_SS,
  114. CCU_MOD_CLK_AXI,
  115. CCU_MOD_CLK_AXI0,
  116. CCU_MOD_CLK_AXI1,
  117. CCU_MOD_CLK_R_DMA,
  118. CCU_MOD_CLK_R_DMA_MCLK,
  119. CCU_MOD_CLK_R_ONEWIRE_SP,
  120. CCU_MOD_CLK_R_CIR_SP,
  121. CCU_MOD_CLK_R_TH,
  122. CCU_MOD_CLK_R_ONEWIRE,
  123. CCU_MOD_CLK_R_UART,
  124. CCU_MOD_CLK_R_UART1,
  125. CCU_MOD_CLK_R_UART2,
  126. CCU_MOD_CLK_R_UART3,
  127. CCU_MOD_CLK_R_UART4,
  128. CCU_MOD_CLK_R_TIMER0_1,
  129. CCU_MOD_CLK_R_P2WI,
  130. CCU_MOD_CLK_R_RSB,
  131. CCU_MOD_CLK_R_TWI,
  132. CCU_MOD_CLK_R_TWI0,
  133. CCU_MOD_CLK_R_TWI1,
  134. CCU_MOD_CLK_R_TWI2,
  135. CCU_MOD_CLK_R_CIR,
  136. CCU_MOD_CLK_R_PIO,
  137. CCU_MOD_CLK_R_VM,
  138. CCU_MOD_CLK_R_THS,
  139. CCU_MOD_CLK_R_LRADC,
  140. CCU_MOD_CLK_R_CAN,
  141. CCU_MOD_CLK_R_LPSD,
  142. CCU_MOD_CLK_R_MAD,
  143. CCU_MOD_CLK_R_MAD_SRAM,
  144. CCU_MOD_CLK_R_MAD_CFG,
  145. CCU_MOD_CLK_R_AC_ADC,
  146. CCU_MOD_CLK_R_AC_DAC,
  147. CCU_MOD_CLK_R_AUDIO_CODEC,
  148. CCU_MOD_CLK_R_DMIC,
  149. CCU_MOD_CLK_R_I2S0,
  150. CCU_MOD_CLK_R_I2S0_ASRC,
  151. CCU_MOD_CLK_R_I2S1,
  152. CCU_MOD_CLK_VDD_SYS,
  153. CCU_MOD_CLK_CCI400,
  154. CCU_MOD_CLK_PSI,
  155. CCU_MOD_CLK_AHB3,
  156. CCU_MOD_CLK_AHBS,
  157. CCU_MOD_CLK_APBS1,
  158. CCU_MOD_CLK_APBS2,
  159. CCU_MOD_CLK_R_RTC,
  160. CCU_MOD_CLK_R_CPUSCFG,
  161. CCU_MOD_CLK_R_PRCM,
  162. CCU_MOD_CLK_R_WDG,
  163. CCU_MOD_CLK_R_TWD,
  164. CCU_MOD_CLK_R_PWM,
  165. CCU_MOD_CLK_R_SPI,
  166. CCU_MOD_CLK_R_INTC,
  167. CCU_MOD_CLK_CPU_APB,
  168. } ccu_mod_clk_e;
  169. /* the power control modules */
  170. typedef enum power_control_module {
  171. /* cpux power controls */
  172. PWRCTL_C0CPUX,
  173. PWRCTL_C0CPU0,
  174. PWRCTL_C0CPU1,
  175. PWRCTL_C0CPU2,
  176. PWRCTL_C0CPU3,
  177. PWRCTL_C1CPUX,
  178. PWRCTL_C1CPU0,
  179. PWRCTL_C1CPU1,
  180. PWRCTL_C1CPU2,
  181. PWRCTL_C1CPU3,
  182. /* vdd-sys power controls */
  183. PWRCTL_VDD_CPUX_GPIO_PAD_HOLD,
  184. PWRCTL_VDD_CPUS,
  185. PWRCTL_VDD_AVCC_A,
  186. PWRCTL_VCC_PLL,
  187. PWRCTL_VCC_PLL_LOW_VOLT,
  188. /* gpu power control */
  189. PWRCTL_GPU,
  190. PWRCTL_SYS2VDD_USB3,
  191. PWRCTL_SYS2VDD_USB0,
  192. } power_control_module_e;
  193. /*
  194. *********************************************************************************************************
  195. * INITIALIZE CCU
  196. *
  197. * Description: initialize clock control unit.
  198. *
  199. * Arguments : none.
  200. *
  201. * Returns : OK if initialize ccu succeeded, others if failed.
  202. *********************************************************************************************************
  203. */
  204. s32 ccu_init(void);
  205. /*
  206. *********************************************************************************************************
  207. * EXIT CCU
  208. *
  209. * Description: exit clock control unit.
  210. *
  211. * Arguments : none.
  212. *
  213. * Returns : OK if exit ccu succeeded, others if failed.
  214. *********************************************************************************************************
  215. */
  216. s32 ccu_exit(void);
  217. void ccu_iosc_freq_update(void);
  218. /*
  219. *********************************************************************************************************
  220. * SET SOURCE FREQUENCY
  221. *
  222. * Description: set the frequency of a specific source clock.
  223. *
  224. * Arguments : sclk : the source clock ID which we want to set frequency.
  225. * freq : the frequency which we want to set.
  226. *
  227. * Returns : OK if set source frequency succeeded, others if failed.
  228. *********************************************************************************************************
  229. */
  230. s32 ccu_set_sclk_freq(u32 sclk, u32 freq);
  231. /*
  232. *********************************************************************************************************
  233. * GET SOURCE FREQUENCY
  234. *
  235. * Description: get the frequency of a specific source clock.
  236. *
  237. * Arguments : sclk : the source clock ID which we want to get frequency.
  238. *
  239. * Returns : frequency of the specific source clock.
  240. *********************************************************************************************************
  241. */
  242. u32 ccu_get_sclk_freq(u32 sclk);
  243. s32 ccu_set_sclk_onoff(u32 sclk, s32 onoff);
  244. /*
  245. *********************************************************************************************************
  246. * REGISTER MODULE CB
  247. *
  248. * Description: register call-back for module clock, when the source frequency
  249. * of the module clock changed, it will use this call-back to notify
  250. * module driver.
  251. *
  252. * Arguments : mclk : the module clock ID which we want to register call-back.
  253. * pcb : the call-back which we want to register.
  254. *
  255. * Returns : OK if register call-back succeeded, others if failed.
  256. *********************************************************************************************************
  257. */
  258. s32 ccu_reg_mclk_cb(u32 mclk, __pNotifier_t pcb);
  259. /*
  260. *********************************************************************************************************
  261. * UNREGISTER MODULE CB
  262. *
  263. * Description: unregister call-back for module clock.
  264. *
  265. * Arguments : mclk : the module clock ID which we want to unregister call-back.
  266. * pcb : the call-back which we want to unregister.
  267. *
  268. * Returns : OK if unregister call-back succeeded, others if failed.
  269. *********************************************************************************************************
  270. */
  271. s32 ccu_unreg_mclk_cb(u32 mclk, __pNotifier_t pcb);
  272. /*
  273. *********************************************************************************************************
  274. * SET SOURCE OF MODULE CLOCK
  275. *
  276. * Description: set the source of a specific module clock.
  277. *
  278. * Arguments : mclk : the module clock ID which we want to set source.
  279. * sclk : the source clock ID whick we want to set as source.
  280. *
  281. * Returns : OK if set source succeeded, others if failed.
  282. *********************************************************************************************************
  283. */
  284. s32 ccu_set_mclk_src(u32 mclk, u32 sclk);
  285. /*
  286. *********************************************************************************************************
  287. * GET SOURCE OF MODULE CLOCK
  288. *
  289. * Description: get the source of a specific module clock.
  290. *
  291. * Arguments : mclk : the module clock ID which we want to get source.
  292. *
  293. * Returns : the source clock ID of source clock.
  294. *********************************************************************************************************
  295. */
  296. s32 ccu_get_mclk_src(u32 mclk);
  297. /*
  298. *********************************************************************************************************
  299. * SET DIVIDER OF MODULE CLOCK
  300. *
  301. * Description: set the divider of a specific module clock.
  302. *
  303. * Arguments : mclk : the module clock ID which we want to set divider.
  304. * div : the divider whick we want to set as source.
  305. *
  306. * Returns : OK if set divider succeeded, others if failed.
  307. *********************************************************************************************************
  308. */
  309. s32 ccu_set_mclk_div(u32 mclk, u32 div);
  310. /*
  311. *********************************************************************************************************
  312. * GET DIVIDER OF MODULE CLOCK
  313. *
  314. * Description: get the divider of a specific module clock.
  315. *
  316. * Arguments : mclk : the module clock ID which we want to get divider.
  317. *
  318. * Returns : the divider of the specific module clock.
  319. *********************************************************************************************************
  320. */
  321. s32 ccu_get_mclk_div(u32 mclk);
  322. /*
  323. *********************************************************************************************************
  324. * SET ON-OFF STATUS OF MODULE CLOCK
  325. *
  326. * Description: set the on-off status of a specific module clock.
  327. *
  328. * Arguments : mclk : the module clock ID which we want to set on-off status.
  329. * onoff : the on-off status which we want to set, the detail please
  330. * refer to the clock status of on-off.
  331. *
  332. * Returns : OK if set module clock on-off status succeeded, others if failed.
  333. *********************************************************************************************************
  334. */
  335. s32 ccu_set_mclk_onoff(u32 mclk, s32 onoff);
  336. /*
  337. *********************************************************************************************************
  338. * SET RESET STATUS OF MODULE CLOCK
  339. *
  340. * Description: set the reset status of a specific module clock.
  341. *
  342. * Arguments : mclk : the module clock ID which we want to set reset status.
  343. * reset : the reset status which we want to set, the detail please
  344. * refer to the clock status of reset.
  345. *
  346. * Returns : OK if set module clock reset status succeeded, others if failed.
  347. *********************************************************************************************************
  348. */
  349. s32 ccu_set_mclk_reset(u32 mclk, s32 reset);
  350. /*
  351. *********************************************************************************************************
  352. * SET POWER OFF STATUS OF HWMODULE
  353. *
  354. * Description: set the power off gating status of a specific module.
  355. *
  356. * Arguments : module : the module ID which we want to set power off gating status.
  357. * status : the power off status which we want to set, the detail please
  358. * refer to the status of power-off gating.
  359. *
  360. * Returns : OK if set module power off gating status succeeded, others if failed.
  361. *********************************************************************************************************
  362. */
  363. s32 ccu_set_poweroff_gating_state(s32 module, s32 state);
  364. /*
  365. *********************************************************************************************************
  366. * RESET MODULE
  367. *
  368. * Description: reset a specific module.
  369. *
  370. * Arguments : module : the module clock ID which we want to reset.
  371. *
  372. * Returns : OK if reset module succeeded, others if failed.
  373. *********************************************************************************************************
  374. */
  375. s32 ccu_reset_module(u32 mclk);
  376. s32 ccu_24mhosc_disable(void);
  377. s32 ccu_24mhosc_enable(void);
  378. s32 ccu_24mhosc_reg_cb(__pNotifier_t pcb);
  379. s32 is_hosc_lock(void);
  380. static inline void save_state_flag(u32 value)
  381. {
  382. // hal_writel(value, RTC_RECORD_REG);
  383. }
  384. extern u32 iosc_freq;
  385. extern u32 losc_freq;
  386. void osc_freq_init(void);
  387. void osc_freq_filter(void);
  388. #endif /* __PRCM_H__ */