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