1 /* 2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of ARM nor the names of its contributors may be used 15 * to endorse or promote products derived from this software without specific 16 * prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef __SOC_H__ 32 #define __SOC_H__ 33 34 #include <utils.h> 35 36 #define GLB_SRST_FST_CFG_VAL 0xfdb9 37 #define GLB_SRST_SND_CFG_VAL 0xeca8 38 39 #define PMUCRU_PPLL_CON(n) ((n) * 4) 40 #define CRU_PLL_CON(pll_id, n) ((pll_id) * 0x20 + (n) * 4) 41 #define PLL_MODE_MSK 0x03 42 #define PLL_MODE_SHIFT 0x08 43 #define PLL_BYPASS_MSK 0x01 44 #define PLL_BYPASS_SHIFT 0x01 45 #define PLL_PWRDN_MSK 0x01 46 #define PLL_PWRDN_SHIFT 0x0 47 #define PLL_BYPASS BIT(1) 48 #define PLL_PWRDN BIT(0) 49 50 #define NO_PLL_BYPASS (0x00) 51 #define NO_PLL_PWRDN (0x00) 52 53 #define FBDIV(n) ((0xfff << 16) | n) 54 #define POSTDIV2(n) ((0x7 << (12 + 16)) | (n << 12)) 55 #define POSTDIV1(n) ((0x7 << (8 + 16)) | (n << 8)) 56 #define REFDIV(n) ((0x3F << 16) | n) 57 #define PLL_LOCK(n) ((n >> 31) & 0x1) 58 59 #define PLL_SLOW_MODE BITS_WITH_WMASK(SLOW_MODE,\ 60 PLL_MODE_MSK, PLL_MODE_SHIFT) 61 62 #define PLL_NOMAL_MODE BITS_WITH_WMASK(NORMAL_MODE,\ 63 PLL_MODE_MSK, PLL_MODE_SHIFT) 64 65 #define PLL_BYPASS_MODE BIT_WITH_WMSK(PLL_BYPASS_SHIFT) 66 #define PLL_NO_BYPASS_MODE WMSK_BIT(PLL_BYPASS_SHIFT) 67 68 #define PLL_CON_COUNT 0x06 69 #define CRU_CLKSEL_COUNT 108 70 #define CRU_CLKSEL_CON(n) (0x100 + (n) * 4) 71 72 #define PMUCRU_CLKSEL_CONUT 0x06 73 #define PMUCRU_CLKSEL_OFFSET 0x080 74 #define REG_SIZE 0x04 75 #define REG_SOC_WMSK 0xffff0000 76 #define CLK_GATE_MASK 0x01 77 78 #define SGRF_SOC_COUNT 0x17 79 #define PMUCRU_GATE_COUNT 0x03 80 #define CRU_GATE_COUNT 0x23 81 #define PMUCRU_GATE_CON(n) (0x100 + (n) * 4) 82 #define CRU_GATE_CON(n) (0x300 + (n) * 4) 83 84 enum plls_id { 85 ALPLL_ID = 0, 86 ABPLL_ID, 87 DPLL_ID, 88 CPLL_ID, 89 GPLL_ID, 90 NPLL_ID, 91 VPLL_ID, 92 PPLL_ID, 93 END_PLL_ID, 94 }; 95 96 #define CLST_L_CPUS_MSK (0xf) 97 #define CLST_B_CPUS_MSK (0x3) 98 99 enum pll_work_mode { 100 SLOW_MODE = 0x00, 101 NORMAL_MODE = 0x01, 102 DEEP_SLOW_MODE = 0x02, 103 }; 104 105 enum glb_sft_reset { 106 PMU_RST_BY_FIRST_SFT, 107 PMU_RST_BY_SECOND_SFT = BIT(2), 108 PMU_RST_NOT_BY_SFT = BIT(3), 109 }; 110 111 struct deepsleep_data_s { 112 uint32_t plls_con[END_PLL_ID][PLL_CON_COUNT]; 113 uint32_t pmucru_clksel_con[PMUCRU_CLKSEL_CONUT]; 114 uint32_t cru_clksel_con[CRU_CLKSEL_COUNT]; 115 uint32_t cru_gate_con[CRU_GATE_COUNT]; 116 uint32_t pmucru_gate_con[PMUCRU_GATE_COUNT]; 117 uint32_t sgrf_con[SGRF_SOC_COUNT]; 118 }; 119 120 /************************************************** 121 * pmugrf reg, offset 122 **************************************************/ 123 #define PMUGRF_OSREG(n) (0x300 + (n) * 4) 124 125 /************************************************** 126 * DCF reg, offset 127 **************************************************/ 128 #define DCF_DCF_CTRL 0x0 129 #define DCF_DCF_ADDR 0x8 130 #define DCF_DCF_ISR 0xc 131 #define DCF_DCF_TOSET 0x14 132 #define DCF_DCF_TOCMD 0x18 133 #define DCF_DCF_CMD_CFG 0x1c 134 135 /* DCF_DCF_ISR */ 136 #define DCF_TIMEOUT (1 << 2) 137 #define DCF_ERR (1 << 1) 138 #define DCF_DONE (1 << 0) 139 140 /* DCF_DCF_CTRL */ 141 #define DCF_VOP_HW_EN (1 << 2) 142 #define DCF_STOP (1 << 1) 143 #define DCF_START (1 << 0) 144 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 /************************************************** 150 * secure timer 151 **************************************************/ 152 153 /* chanal0~5 */ 154 #define STIMER0_CHN_BASE(n) (STIME_BASE + 0x20 * (n)) 155 /* chanal6~11 */ 156 #define STIMER1_CHN_BASE(n) (STIME_BASE + 0x8000 + 0x20 * (n)) 157 158 /* low 32 bits */ 159 #define TIMER_END_COUNT0 0x00 160 /* high 32 bits */ 161 #define TIMER_END_COUNT1 0x04 162 163 #define TIMER_CURRENT_VALUE0 0x08 164 #define TIMER_CURRENT_VALUE1 0x0C 165 166 /* low 32 bits */ 167 #define TIMER_INIT_COUNT0 0x10 168 /* high 32 bits */ 169 #define TIMER_INIT_COUNT1 0x14 170 171 #define TIMER_INTSTATUS 0x18 172 #define TIMER_CONTROL_REG 0x1c 173 174 #define TIMER_EN 0x1 175 176 #define TIMER_FMODE (0x0 << 1) 177 #define TIMER_RMODE (0x1 << 1) 178 179 /************************************************** 180 * secure WDT 181 **************************************************/ 182 #define WDT_CM0_EN 0x0 183 #define WDT_CM0_DIS 0x1 184 #define WDT_CA53_EN 0x0 185 #define WDT_CA53_DIS 0x1 186 187 #define PCLK_WDT_CA53_GATE_SHIFT 8 188 #define PCLK_WDT_CM0_GATE_SHIFT 10 189 190 #define WDT_CA53_1BIT_MASK 0x1 191 #define WDT_CM0_1BIT_MASK 0x1 192 193 /************************************************** 194 * cru reg, offset 195 **************************************************/ 196 #define CRU_SOFTRST_CON(n) (0x400 + (n) * 4) 197 198 #define CRU_DMAC0_RST BIT_WITH_WMSK(3) 199 /* reset release*/ 200 #define CRU_DMAC0_RST_RLS WMSK_BIT(3) 201 202 #define CRU_DMAC1_RST BIT_WITH_WMSK(4) 203 /* reset release*/ 204 #define CRU_DMAC1_RST_RLS WMSK_BIT(4) 205 206 #define CRU_GLB_RST_CON 0x0510 207 #define CRU_GLB_SRST_FST 0x0500 208 #define CRU_GLB_SRST_SND 0x0504 209 210 #define CRU_CLKGATE_CON(n) (0x300 + n * 4) 211 #define PCLK_GPIO2_GATE_SHIFT 3 212 #define PCLK_GPIO3_GATE_SHIFT 4 213 #define PCLK_GPIO4_GATE_SHIFT 5 214 215 /************************************************** 216 * pmu cru reg, offset 217 **************************************************/ 218 #define CRU_PMU_RSTHOLD_CON(n) (0x120 + n * 4) 219 /* reset hold*/ 220 #define CRU_PMU_SGRF_RST_HOLD BIT_WITH_WMSK(6) 221 /* reset hold release*/ 222 #define CRU_PMU_SGRF_RST_RLS WMSK_BIT(6) 223 224 #define CRU_PMU_WDTRST_MSK (0x1 << 4) 225 #define CRU_PMU_WDTRST_EN 0x0 226 227 #define CRU_PMU_FIRST_SFTRST_MSK (0x3 << 2) 228 #define CRU_PMU_FIRST_SFTRST_EN 0x0 229 230 #define CRU_PMU_CLKGATE_CON(n) (0x100 + n * 4) 231 #define PCLK_GPIO0_GATE_SHIFT 3 232 #define PCLK_GPIO1_GATE_SHIFT 4 233 234 /************************************************** 235 * sgrf reg, offset 236 **************************************************/ 237 #define SGRF_SOC_CON0_1(n) (0xc000 + (n) * 4) 238 #define SGRF_SOC_CON3_7(n) (0xe00c + ((n) - 3) * 4) 239 #define SGRF_SOC_CON8_15(n) (0x8020 + ((n) - 8) * 4) 240 #define SGRF_PMU_SLV_CON0_1(n) (0xc240 + ((n) - 0) * 4) 241 #define SGRF_SLV_SECURE_CON0_4(n) (0xe3c0 + ((n) - 0) * 4) 242 #define SGRF_DDRRGN_CON0_16(n) ((n) * 4) 243 #define SGRF_DDRRGN_CON20_34(n) (0x50 + ((n) - 20) * 4) 244 245 /* security config for master */ 246 #define SGRF_SOC_CON_WMSK 0xffff0000 247 /* All of master in ns */ 248 #define SGRF_SOC_ALLMST_NS 0xffff 249 250 /* security config for slave */ 251 #define SGRF_SLV_S_WMSK 0xffff0000 252 #define SGRF_SLV_S_ALL_NS 0x0 253 254 /* security config pmu slave ip */ 255 /* All of slaves is ns */ 256 #define SGRF_PMU_SLV_S_NS BIT_WITH_WMSK(0) 257 /* slaves secure attr is configed */ 258 #define SGRF_PMU_SLV_S_CFGED WMSK_BIT(0) 259 #define SGRF_PMU_SLV_CRYPTO1_NS WMSK_BIT(1) 260 261 #define SGRF_PMUSRAM_S BIT(8) 262 263 #define SGRF_PMU_SLV_CON1_CFG (SGRF_SLV_S_WMSK | \ 264 SGRF_PMUSRAM_S) 265 /* ddr region */ 266 #define SGRF_DDR_RGN_DPLL_CLK BIT_WITH_WMSK(15) /* DDR PLL output clock */ 267 #define SGRF_DDR_RGN_RTC_CLK BIT_WITH_WMSK(14) /* 32K clock for DDR PLL */ 268 #define SGRF_DDR_RGN_BYPS BIT_WITH_WMSK(9) /* All of ddr rgn is ns */ 269 270 /* The MST access the ddr rgn n with secure attribution */ 271 #define SGRF_L_MST_S_DDR_RGN(n) BIT_WITH_WMSK((n)) 272 /* bits[16:8]*/ 273 #define SGRF_H_MST_S_DDR_RGN(n) BIT_WITH_WMSK((n) + 8) 274 275 /* dmac to periph s or ns*/ 276 #define SGRF_DMAC_CFG_S 0xffff0000 277 278 #define DMAC1_RGN_NS 0xff000000 279 #define DMAC0_RGN_NS 0x00ff0000 280 281 #define DMAC0_BOOT_CFG_NS 0xfffffff8 282 #define DMAC0_BOOT_PERIPH_NS 0xffff0fff 283 #define DMAC0_BOOT_ADDR_NS 0xffff0000 284 285 #define DMAC1_BOOT_CFG_NS 0xffff0008 286 #define DMAC1_BOOT_PERIPH_L_NS 0xffff0fff 287 #define DMAC1_BOOT_ADDR_NS 0xffff0000 288 #define DMAC1_BOOT_PERIPH_H_NS 0xffffffff 289 #define DMAC1_BOOT_IRQ_NS 0xffffffff 290 291 #define CPU_BOOT_ADDR_WMASK 0xffff0000 292 #define CPU_BOOT_ADDR_ALIGN 16 293 294 #define GRF_IOMUX_2BIT_MASK 0x3 295 #define GRF_IOMUX_GPIO 0x0 296 297 #define GRF_GPIO4C2_IOMUX_SHIFT 4 298 #define GRF_GPIO4C2_IOMUX_PWM 0x1 299 #define GRF_GPIO4C6_IOMUX_SHIFT 12 300 #define GRF_GPIO4C6_IOMUX_PWM 0x1 301 302 #define PWM_CNT(n) (0x0000 + 0x10 * (n)) 303 #define PWM_PERIOD_HPR(n) (0x0004 + 0x10 * (n)) 304 #define PWM_DUTY_LPR(n) (0x0008 + 0x10 * (n)) 305 #define PWM_CTRL(n) (0x000c + 0x10 * (n)) 306 307 #define PWM_DISABLE (0 << 0) 308 #define PWM_ENABLE (1 << 0) 309 310 /* grf reg offset */ 311 #define GRF_DDRC0_CON0 0xe380 312 #define GRF_DDRC0_CON1 0xe384 313 #define GRF_DDRC1_CON0 0xe388 314 #define GRF_DDRC1_CON1 0xe38c 315 316 #define PMUCRU_CLKSEL_CON0 0x0080 317 #define PMUCRU_CLKGATE_CON2 0x0108 318 #define PMUCRU_SOFTRST_CON0 0x0110 319 #define PMUCRU_GATEDIS_CON0 0x0130 320 321 #define SGRF_SOC_CON6 0x0e018 322 #define SGRF_PERILP_CON0 0x08100 323 #define SGRF_PERILP_CON(n) (SGRF_PERILP_CON0 + (n) * 4) 324 #define SGRF_PMU_CON0 0x0c100 325 #define SGRF_PMU_CON(n) (SGRF_PMU_CON0 + (n) * 4) 326 #define PMUCRU_SOFTRST_CON(n) (PMUCRU_SOFTRST_CON0 + (n) * 4) 327 328 /* 329 * When system reset in running state, we want the cpus to be reboot 330 * from maskrom (system reboot), 331 * the pmusgrf reset-hold bits needs to be released. 332 * When system wake up from system deep suspend, some soc will be reset 333 * when waked up, 334 * we want the bootcpu to be reboot from pmusram, 335 * the pmusgrf reset-hold bits needs to be held. 336 */ 337 static inline void pmu_sgrf_rst_hld_release(void) 338 { 339 mmio_write_32(PMUCRU_BASE + CRU_PMU_RSTHOLD_CON(1), 340 CRU_PMU_SGRF_RST_RLS); 341 } 342 343 static inline void pmu_sgrf_rst_hld(void) 344 { 345 mmio_write_32(PMUCRU_BASE + CRU_PMU_RSTHOLD_CON(1), 346 CRU_PMU_SGRF_RST_HOLD); 347 } 348 349 /* funciton*/ 350 void __dead2 soc_global_soft_reset(void); 351 void secure_watchdog_disable(); 352 void secure_watchdog_restore(); 353 void disable_dvfs_plls(void); 354 void disable_nodvfs_plls(void); 355 void enable_dvfs_plls(void); 356 void enable_nodvfs_plls(void); 357 void prepare_abpll_for_ddrctrl(void); 358 void restore_abpll(void); 359 void restore_dpll(void); 360 void clk_gate_con_save(void); 361 void clk_gate_con_disable(void); 362 void clk_gate_con_restore(void); 363 void sgrf_init(void); 364 #endif /* __SOC_H__ */ 365