soc.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (c) 2016-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef SOC_H
  7. #define SOC_H
  8. #include <lib/utils.h>
  9. #define GLB_SRST_FST_CFG_VAL 0xfdb9
  10. #define GLB_SRST_SND_CFG_VAL 0xeca8
  11. #define PMUCRU_PPLL_CON(n) ((n) * 4)
  12. #define CRU_PLL_CON(pll_id, n) ((pll_id) * 0x20 + (n) * 4)
  13. #define PLL_MODE_MSK 0x03
  14. #define PLL_MODE_SHIFT 0x08
  15. #define PLL_BYPASS_MSK 0x01
  16. #define PLL_BYPASS_SHIFT 0x01
  17. #define PLL_PWRDN_MSK 0x01
  18. #define PLL_PWRDN_SHIFT 0x0
  19. #define PLL_BYPASS BIT(1)
  20. #define PLL_PWRDN BIT(0)
  21. #define NO_PLL_BYPASS (0x00)
  22. #define NO_PLL_PWRDN (0x00)
  23. #define FBDIV(n) ((0xfff << 16) | n)
  24. #define POSTDIV2(n) ((0x7 << (12 + 16)) | (n << 12))
  25. #define POSTDIV1(n) ((0x7 << (8 + 16)) | (n << 8))
  26. #define REFDIV(n) ((0x3F << 16) | n)
  27. #define PLL_LOCK(n) ((n >> 31) & 0x1)
  28. #define PLL_SLOW_MODE BITS_WITH_WMASK(SLOW_MODE,\
  29. PLL_MODE_MSK, PLL_MODE_SHIFT)
  30. #define PLL_NOMAL_MODE BITS_WITH_WMASK(NORMAL_MODE,\
  31. PLL_MODE_MSK, PLL_MODE_SHIFT)
  32. #define PLL_BYPASS_MODE BIT_WITH_WMSK(PLL_BYPASS_SHIFT)
  33. #define PLL_NO_BYPASS_MODE WMSK_BIT(PLL_BYPASS_SHIFT)
  34. #define PLL_CON_COUNT 0x06
  35. #define CRU_CLKSEL_COUNT 108
  36. #define CRU_CLKSEL_CON(n) (0x100 + (n) * 4)
  37. #define PMUCRU_CLKSEL_CONUT 0x06
  38. #define PMUCRU_CLKSEL_OFFSET 0x080
  39. #define REG_SIZE 0x04
  40. #define REG_SOC_WMSK 0xffff0000
  41. #define CLK_GATE_MASK 0x01
  42. #define PMUCRU_GATE_COUNT 0x03
  43. #define CRU_GATE_COUNT 0x23
  44. #define PMUCRU_GATE_CON(n) (0x100 + (n) * 4)
  45. #define CRU_GATE_CON(n) (0x300 + (n) * 4)
  46. #define PMUCRU_RSTNHOLD_CON0 0x120
  47. enum {
  48. PRESETN_NOC_PMU_HOLD = 1,
  49. PRESETN_INTMEM_PMU_HOLD,
  50. HRESETN_CM0S_PMU_HOLD,
  51. HRESETN_CM0S_NOC_PMU_HOLD,
  52. DRESETN_CM0S_PMU_HOLD,
  53. POESETN_CM0S_PMU_HOLD,
  54. PRESETN_SPI3_HOLD,
  55. RESETN_SPI3_HOLD,
  56. PRESETN_TIMER_PMU_0_1_HOLD,
  57. RESETN_TIMER_PMU_0_HOLD,
  58. RESETN_TIMER_PMU_1_HOLD,
  59. PRESETN_UART_M0_PMU_HOLD,
  60. RESETN_UART_M0_PMU_HOLD,
  61. PRESETN_WDT_PMU_HOLD
  62. };
  63. #define PMUCRU_RSTNHOLD_CON1 0x124
  64. enum {
  65. PRESETN_I2C0_HOLD,
  66. PRESETN_I2C4_HOLD,
  67. PRESETN_I2C8_HOLD,
  68. PRESETN_MAILBOX_PMU_HOLD,
  69. PRESETN_RKPWM_PMU_HOLD,
  70. PRESETN_PMUGRF_HOLD,
  71. PRESETN_SGRF_HOLD,
  72. PRESETN_GPIO0_HOLD,
  73. PRESETN_GPIO1_HOLD,
  74. PRESETN_CRU_PMU_HOLD,
  75. PRESETN_INTR_ARB_HOLD,
  76. PRESETN_PVTM_PMU_HOLD,
  77. RESETN_I2C0_HOLD,
  78. RESETN_I2C4_HOLD,
  79. RESETN_I2C8_HOLD
  80. };
  81. enum plls_id {
  82. ALPLL_ID = 0,
  83. ABPLL_ID,
  84. DPLL_ID,
  85. CPLL_ID,
  86. GPLL_ID,
  87. NPLL_ID,
  88. VPLL_ID,
  89. PPLL_ID,
  90. END_PLL_ID,
  91. };
  92. #define CLST_L_CPUS_MSK (0xf)
  93. #define CLST_B_CPUS_MSK (0x3)
  94. enum pll_work_mode {
  95. SLOW_MODE = 0x00,
  96. NORMAL_MODE = 0x01,
  97. DEEP_SLOW_MODE = 0x02,
  98. };
  99. enum glb_sft_reset {
  100. PMU_RST_BY_FIRST_SFT,
  101. PMU_RST_BY_SECOND_SFT = BIT(2),
  102. PMU_RST_NOT_BY_SFT = BIT(3),
  103. };
  104. struct pll_div {
  105. uint32_t mhz;
  106. uint32_t refdiv;
  107. uint32_t fbdiv;
  108. uint32_t postdiv1;
  109. uint32_t postdiv2;
  110. uint32_t frac;
  111. uint32_t freq;
  112. };
  113. struct deepsleep_data_s {
  114. uint32_t plls_con[END_PLL_ID][PLL_CON_COUNT];
  115. uint32_t cru_gate_con[CRU_GATE_COUNT];
  116. uint32_t pmucru_gate_con[PMUCRU_GATE_COUNT];
  117. };
  118. struct pmu_sleep_data {
  119. uint32_t pmucru_rstnhold_con0;
  120. uint32_t pmucru_rstnhold_con1;
  121. };
  122. /**************************************************
  123. * pmugrf reg, offset
  124. **************************************************/
  125. #define PMUGRF_OSREG(n) (0x300 + (n) * 4)
  126. #define PMUGRF_GPIO0A_P 0x040
  127. #define PMUGRF_GPIO1A_P 0x050
  128. /**************************************************
  129. * DCF reg, offset
  130. **************************************************/
  131. #define DCF_DCF_CTRL 0x0
  132. #define DCF_DCF_ADDR 0x8
  133. #define DCF_DCF_ISR 0xc
  134. #define DCF_DCF_TOSET 0x14
  135. #define DCF_DCF_TOCMD 0x18
  136. #define DCF_DCF_CMD_CFG 0x1c
  137. /* DCF_DCF_ISR */
  138. #define DCF_TIMEOUT (1 << 2)
  139. #define DCF_ERR (1 << 1)
  140. #define DCF_DONE (1 << 0)
  141. /* DCF_DCF_CTRL */
  142. #define DCF_VOP_HW_EN (1 << 2)
  143. #define DCF_STOP (1 << 1)
  144. #define DCF_START (1 << 0)
  145. #define CYCL_24M_CNT_US(us) (24 * us)
  146. #define CYCL_24M_CNT_MS(ms) (ms * CYCL_24M_CNT_US(1000))
  147. #define CYCL_32K_CNT_MS(ms) (ms * 32)
  148. /**************************************************
  149. * cru reg, offset
  150. **************************************************/
  151. #define CRU_SOFTRST_CON(n) (0x400 + (n) * 4)
  152. #define CRU_DMAC0_RST BIT_WITH_WMSK(3)
  153. /* reset release*/
  154. #define CRU_DMAC0_RST_RLS WMSK_BIT(3)
  155. #define CRU_DMAC1_RST BIT_WITH_WMSK(4)
  156. /* reset release*/
  157. #define CRU_DMAC1_RST_RLS WMSK_BIT(4)
  158. #define CRU_GLB_RST_CON 0x0510
  159. #define CRU_GLB_SRST_FST 0x0500
  160. #define CRU_GLB_SRST_SND 0x0504
  161. #define CRU_CLKGATE_CON(n) (0x300 + n * 4)
  162. #define PCLK_GPIO2_GATE_SHIFT 3
  163. #define PCLK_GPIO3_GATE_SHIFT 4
  164. #define PCLK_GPIO4_GATE_SHIFT 5
  165. /**************************************************
  166. * pmu cru reg, offset
  167. **************************************************/
  168. #define CRU_PMU_RSTHOLD_CON(n) (0x120 + n * 4)
  169. /* reset hold*/
  170. #define CRU_PMU_SGRF_RST_HOLD BIT_WITH_WMSK(6)
  171. /* reset hold release*/
  172. #define CRU_PMU_SGRF_RST_RLS WMSK_BIT(6)
  173. #define CRU_PMU_WDTRST_MSK (0x1 << 4)
  174. #define CRU_PMU_WDTRST_EN 0x0
  175. #define CRU_PMU_FIRST_SFTRST_MSK (0x3 << 2)
  176. #define CRU_PMU_FIRST_SFTRST_EN 0x0
  177. #define CRU_PMU_CLKGATE_CON(n) (0x100 + n * 4)
  178. #define PCLK_GPIO0_GATE_SHIFT 3
  179. #define PCLK_GPIO1_GATE_SHIFT 4
  180. #define CPU_BOOT_ADDR_WMASK 0xffff0000
  181. #define CPU_BOOT_ADDR_ALIGN 16
  182. #define GRF_IOMUX_2BIT_MASK 0x3
  183. #define GRF_IOMUX_GPIO 0x0
  184. #define GRF_GPIO4C2_IOMUX_SHIFT 4
  185. #define GRF_GPIO4C2_IOMUX_PWM 0x1
  186. #define GRF_GPIO4C6_IOMUX_SHIFT 12
  187. #define GRF_GPIO4C6_IOMUX_PWM 0x1
  188. #define PWM_CNT(n) (0x0000 + 0x10 * (n))
  189. #define PWM_PERIOD_HPR(n) (0x0004 + 0x10 * (n))
  190. #define PWM_DUTY_LPR(n) (0x0008 + 0x10 * (n))
  191. #define PWM_CTRL(n) (0x000c + 0x10 * (n))
  192. #define PWM_DISABLE (0 << 0)
  193. #define PWM_ENABLE (1 << 0)
  194. /* grf reg offset */
  195. #define GRF_USBPHY0_CTRL0 0x4480
  196. #define GRF_USBPHY0_CTRL2 0x4488
  197. #define GRF_USBPHY0_CTRL3 0x448c
  198. #define GRF_USBPHY0_CTRL12 0x44b0
  199. #define GRF_USBPHY0_CTRL13 0x44b4
  200. #define GRF_USBPHY0_CTRL15 0x44bc
  201. #define GRF_USBPHY0_CTRL16 0x44c0
  202. #define GRF_USBPHY1_CTRL0 0x4500
  203. #define GRF_USBPHY1_CTRL2 0x4508
  204. #define GRF_USBPHY1_CTRL3 0x450c
  205. #define GRF_USBPHY1_CTRL12 0x4530
  206. #define GRF_USBPHY1_CTRL13 0x4534
  207. #define GRF_USBPHY1_CTRL15 0x453c
  208. #define GRF_USBPHY1_CTRL16 0x4540
  209. #define GRF_GPIO2A_IOMUX 0xe000
  210. #define GRF_GPIO2A_P 0xe040
  211. #define GRF_GPIO3A_P 0xe050
  212. #define GRF_GPIO4A_P 0xe060
  213. #define GRF_GPIO2D_HE 0xe18c
  214. #define GRF_DDRC0_CON0 0xe380
  215. #define GRF_DDRC0_CON1 0xe384
  216. #define GRF_DDRC1_CON0 0xe388
  217. #define GRF_DDRC1_CON1 0xe38c
  218. #define GRF_SOC_CON_BASE 0xe200
  219. #define GRF_SOC_CON(n) (GRF_SOC_CON_BASE + (n) * 4)
  220. #define GRF_IO_VSEL 0xe640
  221. #define CRU_CLKSEL_CON0 0x0100
  222. #define CRU_CLKSEL_CON6 0x0118
  223. #define CRU_SDIO0_CON1 0x058c
  224. #define PMUCRU_CLKSEL_CON0 0x0080
  225. #define PMUCRU_CLKGATE_CON2 0x0108
  226. #define PMUCRU_SOFTRST_CON0 0x0110
  227. #define PMUCRU_GATEDIS_CON0 0x0130
  228. #define PMUCRU_SOFTRST_CON(n) (PMUCRU_SOFTRST_CON0 + (n) * 4)
  229. /* export related and operating SoC APIs */
  230. void __dead2 soc_global_soft_reset(void);
  231. void disable_dvfs_plls(void);
  232. void disable_nodvfs_plls(void);
  233. void enable_dvfs_plls(void);
  234. void enable_nodvfs_plls(void);
  235. void prepare_abpll_for_ddrctrl(void);
  236. void restore_abpll(void);
  237. void clk_gate_con_save(void);
  238. void clk_gate_con_disable(void);
  239. void clk_gate_con_restore(void);
  240. void set_pmu_rsthold(void);
  241. void pmu_sgrf_rst_hld(void);
  242. __pmusramfunc void pmu_sgrf_rst_hld_release(void);
  243. __pmusramfunc void restore_pmu_rsthold(void);
  244. #endif /* SOC_H */