drv_clock.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-02-08 RT-Thread the first version
  9. */
  10. #ifndef __DRV_CLOCK_H__
  11. #define __DRV_CLOCK_H__
  12. /* PLL state */
  13. #define PLL_ENBALE (0x1)
  14. #define PLL_STABLE (0x2)
  15. /* Clock source selection */
  16. #define CLK_LOSC_SRC (0x00)
  17. #define CLK_OSC24M_SRC (0x01)
  18. #define CLK_PLL_SRC (0x02)
  19. #define PRE_DIV_SRC (0x03)
  20. /* */
  21. #define TCON_PLL_VIDEO_X1 (0x000)
  22. #define TCON_PLL_VIDEO_X2 (0x002)
  23. #define PLL_CPU_ENABLE_STATE (0x1<<31)
  24. #define PLL_CPU_HAS_BEEN_STABLE (0x1<<28)
  25. #define PLL_CPU_DIV_P(reg) ((reg>>16)&0x3)
  26. #define PLL_CPU_FACTOR_N(reg) ((reg>>8)&0x1f)
  27. #define PLL_CPU_FACTOR_K(reg) ((reg>>4)&0x3)
  28. #define PLL_CPU_FACTOR_M(reg) ((reg)&0x3)
  29. #define PLL_AUDIO_ENABLE_STATE (0x1<<31)
  30. #define PLL_AUDIO_HAS_BEEN_STABLE (0x1<<28)
  31. #define PLL_AUDIO_FACTOR_N(reg) ((reg>>8)&0x7f)
  32. #define PLL_AUDIO_PREDIV_M(reg) ((reg)&0x1f)
  33. #define PLL_VIDEO_ENABLE_STATE (0x1<<31)
  34. #define PLL_VIDEO_MODE (0x1<<30)
  35. #define PLL_VIDEO_HAS_BEEN_STABLE (0x1<<28)
  36. #define PLL_VIDEO_FRAC_CLK_OUT (0x1<<25)
  37. #define PLL_VIDEO_MODE_SEL (0x1<<24)
  38. #define PLL_VIDEO_SDM_EN (0x1<<20)
  39. #define PLL_VIDEO_FACTOR_N(reg) ((reg>>8)&0x7f)
  40. #define PLL_VIDEO_PREDIV_M(reg) (reg&0xf)
  41. #define PLL_VE_ENABLE_STATE (0x1<<31)
  42. #define PLL_VE_HAS_BEEN_STABLE (0x1<<28)
  43. #define PLL_VE_FRAC_CLK_OUT (0x1<<25)
  44. #define PLL_VE_MODE_SEL (0x1<<24)
  45. #define PLL_VE_FACTOR_N(reg) ((reg>>8)&0x7f)
  46. #define PLL_VE_PREDIV_M(reg) (reg&0xf)
  47. #define PLL_DDR_ENABLE_STATE (0x1<<31)
  48. #define PLL_DDR_HAS_BEEN_STABLE (0x1<<28)
  49. #define SDRAM_SIGMA_DELTA_EN (0x1<<24)
  50. #define PLL_DDR_CFG_UPDATE (0x1<<20)
  51. #define PLL_DDR_FACTOR_N(reg) ((reg>>8)&0x1f)
  52. #define PLL_DDR_FACTOR_K(reg) ((reg>>4)&0x3)
  53. #define PLL_DDR_FACTOR_M(reg) ((reg)&0x3)
  54. #define PLL_PERIPH_ENABLE_STATE (0x1<<31)
  55. #define PLL_PERIPH_HAS_BEEN_STABLE (0x1<<28)
  56. #define PLL_PERIPH_24M_OUT_EN (0x1<<18)
  57. #define PLL_PERIPH_24M_POST_DIV(reg) ((reg>>16)&0x3)
  58. #define PLL_PERIPH_FACTOR_N(reg) ((reg>>8)&0x1f)
  59. #define PLL_PERIPH_FACTOR_K(reg) ((reg>>4)&0x3)
  60. #define PLL_PERIPH_FACTOR_M(reg) (reg&0x3)
  61. #define HCLKC_DIV(reg) ((reg>>16)&0x3)
  62. #define AHB_SRC_SEL(reg) ((reg>>12)&0x3)
  63. #define AHB_CLK_DIV(reg) ((reg>>4)&0x3)
  64. #define AHB_PRE_DIV(reg) ((reg>>6)&0x3)
  65. #define APH_CLK_PATIO(reg) ((reg>>8)&0x3)
  66. #define CCM_MMC_CTRL_OSCM24 (0x00)
  67. #define CCM_MMC_CTRL_PLL_PERIPH (0x01)
  68. #define CCU_BASE_ADDR (0x01C20000)
  69. #define _24MHZ_ (24000000U)
  70. #define _32KHZ_ (32000U)
  71. /* GATE */
  72. #define BUS_GATE_OFFSET_BIT (12)
  73. enum bus_gate
  74. {
  75. USB_OTG_GATING = (0x18 | (0x0 << BUS_GATE_OFFSET_BIT)),
  76. SPI1_GATING = (0x15 | (0x0 << BUS_GATE_OFFSET_BIT)),
  77. SPI0_GATING = (0x14 | (0x0 << BUS_GATE_OFFSET_BIT)),
  78. SDRAM_GATING = (0x0E | (0x0 << BUS_GATE_OFFSET_BIT)),
  79. SD1_GATING = (0x09 | (0x0 << BUS_GATE_OFFSET_BIT)),
  80. SD0_GATING = (0x08 | (0x0 << BUS_GATE_OFFSET_BIT)),
  81. DMA_GATING = (0x06 | (0x0 << BUS_GATE_OFFSET_BIT)),
  82. DEFE_GATING = (0x0E | (0x1 << BUS_GATE_OFFSET_BIT)),
  83. DEBE_GATING = (0x0C | (0x1 << BUS_GATE_OFFSET_BIT)),
  84. TVE_GATING = (0x0A | (0x1 << BUS_GATE_OFFSET_BIT)),
  85. TVD_GATING = (0x09 | (0x1 << BUS_GATE_OFFSET_BIT)),
  86. CSI_GATING = (0x08 | (0x1 << BUS_GATE_OFFSET_BIT)),
  87. DEINTERLACE_GATING = (0x05 | (0x1 << BUS_GATE_OFFSET_BIT)),
  88. LCD_GATING = (0x04 | (0x1 << BUS_GATE_OFFSET_BIT)),
  89. VE_GATING = (0x00 | (0x1 << BUS_GATE_OFFSET_BIT)),
  90. UART2_GATING = (0x16 | (0x2 << BUS_GATE_OFFSET_BIT)),
  91. UART1_GATING = (0x15 | (0x2 << BUS_GATE_OFFSET_BIT)),
  92. UART0_GATING = (0x14 | (0x2 << BUS_GATE_OFFSET_BIT)),
  93. TWI2_GATING = (0x12 | (0x2 << BUS_GATE_OFFSET_BIT)),
  94. TWI1_GATING = (0x11 | (0x2 << BUS_GATE_OFFSET_BIT)),
  95. TWI0_GATING = (0x10 | (0x2 << BUS_GATE_OFFSET_BIT)),
  96. DAUDIO_GATING = (0x0C | (0x2 << BUS_GATE_OFFSET_BIT)),
  97. RSB_GATING = (0x03 | (0x2 << BUS_GATE_OFFSET_BIT)),
  98. CIR_GATING = (0x02 | (0x2 << BUS_GATE_OFFSET_BIT)),
  99. OWA_GATING = (0x01 | (0x2 << BUS_GATE_OFFSET_BIT)),
  100. AUDIO_CODEC_GATING = (0x00 | (0x2 << BUS_GATE_OFFSET_BIT)),
  101. };
  102. enum dram_gate
  103. {
  104. BE_GATING_DRAM = 26,
  105. FE_GATING_DRAM = 24,
  106. TVD_GATING_DRAM = 3,
  107. DEINTERLACE_GATING_DRAM = 2,
  108. CSI_GATING_DRAM = 1,
  109. VE_GATING_DRAM = 0
  110. };
  111. enum mmc_clk_id
  112. {
  113. SDMMC0,
  114. SDMMC1,
  115. };
  116. struct tina_ccu
  117. {
  118. volatile rt_uint32_t pll_cpu_ctrl; /* 0x000 */
  119. volatile rt_uint32_t reserved0;
  120. volatile rt_uint32_t pll_audio_ctrl; /* 0x008 */
  121. volatile rt_uint32_t reserved1;
  122. volatile rt_uint32_t pll_video_ctrl; /* 0x010 */
  123. volatile rt_uint32_t reserved2;
  124. volatile rt_uint32_t pll_ve_ctrl; /* 0x018 */
  125. volatile rt_uint32_t reserved3;
  126. volatile rt_uint32_t pll_ddr_ctrl; /* 0x020 */
  127. volatile rt_uint32_t reserved4;
  128. volatile rt_uint32_t pll_periph_ctrl; /* 0x028 */
  129. volatile rt_uint32_t reserved5[9];
  130. volatile rt_uint32_t cpu_clk_src; /* 0x050 */
  131. volatile rt_uint32_t ahb_apb_hclkc_cfg; /* 0x054 */
  132. volatile rt_uint32_t reserved6[2];
  133. volatile rt_uint32_t bus_clk_gating0; /* 0x060 */
  134. volatile rt_uint32_t bus_clk_gating1; /* 0x064 */
  135. volatile rt_uint32_t bus_clk_gating2; /* 0x068 */
  136. volatile rt_uint32_t reserved7[7];
  137. volatile rt_uint32_t sdmmc0_clk; /* 0x088 */
  138. volatile rt_uint32_t sdmmc1_clk; /* 0x08C */
  139. volatile rt_uint32_t reserved8[8];
  140. volatile rt_uint32_t daudio_clk; /* 0x0B0 */
  141. volatile rt_uint32_t owa_clk; /* 0x0B4 */
  142. volatile rt_uint32_t cir_clk; /* 0x0B8 */
  143. volatile rt_uint32_t reserved9[4];
  144. volatile rt_uint32_t usbphy_clk; /* 0x0CC */
  145. volatile rt_uint32_t reserved10[12];
  146. volatile rt_uint32_t dram_gating; /* 0x100 */
  147. volatile rt_uint32_t be_clk; /* 0x104 */
  148. volatile rt_uint32_t reserved11;
  149. volatile rt_uint32_t fe_clk; /* 0x10C */
  150. volatile rt_uint32_t reserved12[2];
  151. volatile rt_uint32_t tcon_clk; /* 0x118*/
  152. volatile rt_uint32_t di_clk; /* 0x11C */
  153. volatile rt_uint32_t tve_clk; /* 0x120 */
  154. volatile rt_uint32_t tvd_clk; /* 0x124 */
  155. volatile rt_uint32_t reserved13[3];
  156. volatile rt_uint32_t csi_clk; /* 0x134 */
  157. volatile rt_uint32_t reserved14;
  158. volatile rt_uint32_t ve_clk; /* 0x13C */
  159. volatile rt_uint32_t audio_codec_clk; /* 0x140 */
  160. volatile rt_uint32_t avs_clk; /* 0x144 */
  161. volatile rt_uint32_t reserved15[46];
  162. volatile rt_uint32_t pll_stable_time0; /* 0x200 */
  163. volatile rt_uint32_t pll_stable_time1; /* 0x204 */
  164. volatile rt_uint32_t reserved16[6];
  165. volatile rt_uint32_t pll_cpu_bias; /* 0x220 */
  166. volatile rt_uint32_t pll_audio_bias; /* 0x224 */
  167. volatile rt_uint32_t pll_video_bias; /* 0x228 */
  168. volatile rt_uint32_t pll_ve_bias; /* 0x22C */
  169. volatile rt_uint32_t pll_ddr_bias; /* 0x230 */
  170. volatile rt_uint32_t pll_periph_bias; /* 0x234 */
  171. volatile rt_uint32_t reserved17[6];
  172. volatile rt_uint32_t pll_cpu_tun; /* 0x250 */
  173. volatile rt_uint32_t reserved18[3];
  174. volatile rt_uint32_t pll_ddr_tun; /* 0x260 */
  175. volatile rt_uint32_t reserved19[8];
  176. volatile rt_uint32_t pll_audio_pat_ctrl; /* 0x284 */
  177. volatile rt_uint32_t pll_video_pat_ctrl; /* 0x288 */
  178. volatile rt_uint32_t reserved20;
  179. volatile rt_uint32_t pll_ddr_pat_ctrl; /* 0x290 */
  180. volatile rt_uint32_t reserved21[11];
  181. volatile rt_uint32_t bus_soft_rst0; /* 0x2C0 */
  182. volatile rt_uint32_t bus_soft_rst1; /* 0x2C4 */
  183. volatile rt_uint32_t reserved22[2];
  184. volatile rt_uint32_t bus_soft_rst2; /* 0x2D0 */
  185. };
  186. typedef struct tina_ccu *tina_ccu_t;
  187. #define CCU ((tina_ccu_t) CCU_BASE_ADDR)
  188. int cpu_get_pll_clk(void);
  189. int audio_get_pll_clk(void);
  190. int video_get_pll_clk(void);
  191. int ve_get_pll_clk(void);
  192. int ddr_get_pll_clk(void);
  193. int periph_get_pll_clk(void);
  194. int cpu_get_clk(void);
  195. int ahb_get_clk(void);
  196. int apb_get_clk(void);
  197. rt_err_t cpu_set_pll_clk(int clk);
  198. rt_err_t audio_set_pll_clk(int clk);
  199. rt_err_t video_set_pll_clk(int clk);
  200. rt_err_t ve_set_pll_clk(int clk);
  201. rt_err_t periph_set_pll_clk(int clk);
  202. rt_err_t cpu_set_clk(int clk);
  203. rt_err_t bus_gate_clk_enalbe(enum bus_gate bus);
  204. rt_err_t bus_gate_clk_disalbe(enum bus_gate bus);
  205. rt_err_t bus_software_reset_enalbe(enum bus_gate bus);
  206. rt_err_t bus_software_reset_disalbe(enum bus_gate bus);
  207. rt_err_t dram_gate_clk_enable(enum dram_gate dram_gate);
  208. rt_err_t dram_gate_clk_disable(enum dram_gate dram_gate);
  209. rt_err_t mmc_set_clk(enum mmc_clk_id clk_id, int hz);
  210. #endif