blob: 03da025b71f3d922ad58d57deac77854ae5aab82 [file] [log] [blame]
Tony Xie6fba6e02016-01-15 17:17:32 +08001/*
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
Masahiro Yamada152c8c12016-12-05 14:28:59 +090034#include <utils.h>
35
Tony Xie6fba6e02016-01-15 17:17:32 +080036#define GLB_SRST_FST_CFG_VAL 0xfdb9
37#define GLB_SRST_SND_CFG_VAL 0xeca8
38
Tony Xie9ec78bd2016-07-16 11:16:51 +080039#define PMUCRU_PPLL_CON(n) ((n) * 4)
40#define CRU_PLL_CON(pll_id, n) ((pll_id) * 0x20 + (n) * 4)
Tony Xie6fba6e02016-01-15 17:17:32 +080041#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
Caesar Wangfe877772016-08-25 08:37:42 +080053#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
Tony Xie9ec78bd2016-07-16 11:16:51 +080059#define PLL_SLOW_MODE BITS_WITH_WMASK(SLOW_MODE,\
Caesar Wangf47a25d2016-04-10 14:11:07 +080060 PLL_MODE_MSK, PLL_MODE_SHIFT)
Tony Xie9ec78bd2016-07-16 11:16:51 +080061
62#define PLL_NOMAL_MODE BITS_WITH_WMASK(NORMAL_MODE,\
Caesar Wangf47a25d2016-04-10 14:11:07 +080063 PLL_MODE_MSK, PLL_MODE_SHIFT)
Tony Xie6fba6e02016-01-15 17:17:32 +080064
Tony Xie9ec78bd2016-07-16 11:16:51 +080065#define PLL_BYPASS_MODE BIT_WITH_WMSK(PLL_BYPASS_SHIFT)
66#define PLL_NO_BYPASS_MODE WMSK_BIT(PLL_BYPASS_SHIFT)
67
Tony Xie6fba6e02016-01-15 17:17:32 +080068#define PLL_CON_COUNT 0x06
Caesar Wanga1dccdd2016-10-20 14:14:45 -070069#define CRU_CLKSEL_COUNT 108
Caesar Wang4d5d98c2016-09-27 18:19:30 -070070#define CRU_CLKSEL_CON(n) (0x100 + (n) * 4)
Tony Xie6fba6e02016-01-15 17:17:32 +080071
72#define PMUCRU_CLKSEL_CONUT 0x06
73#define PMUCRU_CLKSEL_OFFSET 0x080
74#define REG_SIZE 0x04
75#define REG_SOC_WMSK 0xffff0000
Caesar Wang9901dcf2016-05-25 19:21:43 +080076#define CLK_GATE_MASK 0x01
77
Caesar Wanga14e0912016-11-04 21:13:01 +080078#define SGRF_SOC_COUNT 0x17
Tony Xie9ec78bd2016-07-16 11:16:51 +080079#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
Tony Xie6fba6e02016-01-15 17:17:32 +080084enum 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
Tony Xie9ec78bd2016-07-16 11:16:51 +080096#define CLST_L_CPUS_MSK (0xf)
97#define CLST_B_CPUS_MSK (0x3)
98
Tony Xie6fba6e02016-01-15 17:17:32 +080099enum pll_work_mode {
100 SLOW_MODE = 0x00,
101 NORMAL_MODE = 0x01,
102 DEEP_SLOW_MODE = 0x02,
103};
104
105enum 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
Xing Zheng977001a2016-10-26 21:25:26 +0800111struct pll_div {
112 uint32_t mhz;
113 uint32_t refdiv;
114 uint32_t fbdiv;
115 uint32_t postdiv1;
116 uint32_t postdiv2;
117 uint32_t frac;
118 uint32_t freq;
119};
120
Tony Xie6fba6e02016-01-15 17:17:32 +0800121struct deepsleep_data_s {
122 uint32_t plls_con[END_PLL_ID][PLL_CON_COUNT];
123 uint32_t pmucru_clksel_con[PMUCRU_CLKSEL_CONUT];
124 uint32_t cru_clksel_con[CRU_CLKSEL_COUNT];
Tony Xie9ec78bd2016-07-16 11:16:51 +0800125 uint32_t cru_gate_con[CRU_GATE_COUNT];
126 uint32_t pmucru_gate_con[PMUCRU_GATE_COUNT];
Caesar Wanga14e0912016-11-04 21:13:01 +0800127 uint32_t sgrf_con[SGRF_SOC_COUNT];
Tony Xie6fba6e02016-01-15 17:17:32 +0800128};
129
Caesar Wangfe877772016-08-25 08:37:42 +0800130/**************************************************
131 * pmugrf reg, offset
132 **************************************************/
133#define PMUGRF_OSREG(n) (0x300 + (n) * 4)
134
135/**************************************************
136 * DCF reg, offset
137 **************************************************/
138#define DCF_DCF_CTRL 0x0
139#define DCF_DCF_ADDR 0x8
140#define DCF_DCF_ISR 0xc
141#define DCF_DCF_TOSET 0x14
142#define DCF_DCF_TOCMD 0x18
143#define DCF_DCF_CMD_CFG 0x1c
144
145/* DCF_DCF_ISR */
146#define DCF_TIMEOUT (1 << 2)
147#define DCF_ERR (1 << 1)
148#define DCF_DONE (1 << 0)
149
150/* DCF_DCF_CTRL */
151#define DCF_VOP_HW_EN (1 << 2)
152#define DCF_STOP (1 << 1)
153#define DCF_START (1 << 0)
154
Caesar Wangf47a25d2016-04-10 14:11:07 +0800155#define CYCL_24M_CNT_US(us) (24 * us)
156#define CYCL_24M_CNT_MS(ms) (ms * CYCL_24M_CNT_US(1000))
Tony Xie9ec78bd2016-07-16 11:16:51 +0800157#define CYCL_32K_CNT_MS(ms) (ms * 32)
Caesar Wangf47a25d2016-04-10 14:11:07 +0800158
Tony Xie6fba6e02016-01-15 17:17:32 +0800159/**************************************************
160 * secure timer
161 **************************************************/
162
163/* chanal0~5 */
164#define STIMER0_CHN_BASE(n) (STIME_BASE + 0x20 * (n))
165/* chanal6~11 */
166#define STIMER1_CHN_BASE(n) (STIME_BASE + 0x8000 + 0x20 * (n))
167
168 /* low 32 bits */
169#define TIMER_END_COUNT0 0x00
170 /* high 32 bits */
171#define TIMER_END_COUNT1 0x04
172
173#define TIMER_CURRENT_VALUE0 0x08
174#define TIMER_CURRENT_VALUE1 0x0C
175
176 /* low 32 bits */
177#define TIMER_INIT_COUNT0 0x10
178 /* high 32 bits */
179#define TIMER_INIT_COUNT1 0x14
180
181#define TIMER_INTSTATUS 0x18
182#define TIMER_CONTROL_REG 0x1c
183
184#define TIMER_EN 0x1
185
186#define TIMER_FMODE (0x0 << 1)
187#define TIMER_RMODE (0x1 << 1)
188
189/**************************************************
Caesar Wanga14e0912016-11-04 21:13:01 +0800190 * secure WDT
191 **************************************************/
192#define WDT_CM0_EN 0x0
193#define WDT_CM0_DIS 0x1
194#define WDT_CA53_EN 0x0
195#define WDT_CA53_DIS 0x1
196
197#define PCLK_WDT_CA53_GATE_SHIFT 8
198#define PCLK_WDT_CM0_GATE_SHIFT 10
199
200#define WDT_CA53_1BIT_MASK 0x1
201#define WDT_CM0_1BIT_MASK 0x1
202
203/**************************************************
Tony Xie6fba6e02016-01-15 17:17:32 +0800204 * cru reg, offset
205 **************************************************/
206#define CRU_SOFTRST_CON(n) (0x400 + (n) * 4)
207
208#define CRU_DMAC0_RST BIT_WITH_WMSK(3)
209 /* reset release*/
210#define CRU_DMAC0_RST_RLS WMSK_BIT(3)
211
212#define CRU_DMAC1_RST BIT_WITH_WMSK(4)
213 /* reset release*/
214#define CRU_DMAC1_RST_RLS WMSK_BIT(4)
215
216#define CRU_GLB_RST_CON 0x0510
217#define CRU_GLB_SRST_FST 0x0500
218#define CRU_GLB_SRST_SND 0x0504
219
Caesar Wang9901dcf2016-05-25 19:21:43 +0800220#define CRU_CLKGATE_CON(n) (0x300 + n * 4)
221#define PCLK_GPIO2_GATE_SHIFT 3
222#define PCLK_GPIO3_GATE_SHIFT 4
223#define PCLK_GPIO4_GATE_SHIFT 5
224
Tony Xie6fba6e02016-01-15 17:17:32 +0800225/**************************************************
226 * pmu cru reg, offset
227 **************************************************/
228#define CRU_PMU_RSTHOLD_CON(n) (0x120 + n * 4)
229/* reset hold*/
230#define CRU_PMU_SGRF_RST_HOLD BIT_WITH_WMSK(6)
231/* reset hold release*/
232#define CRU_PMU_SGRF_RST_RLS WMSK_BIT(6)
Caesar Wangf47a25d2016-04-10 14:11:07 +0800233
234#define CRU_PMU_WDTRST_MSK (0x1 << 4)
235#define CRU_PMU_WDTRST_EN 0x0
236
237#define CRU_PMU_FIRST_SFTRST_MSK (0x3 << 2)
238#define CRU_PMU_FIRST_SFTRST_EN 0x0
239
Caesar Wang9901dcf2016-05-25 19:21:43 +0800240#define CRU_PMU_CLKGATE_CON(n) (0x100 + n * 4)
241#define PCLK_GPIO0_GATE_SHIFT 3
242#define PCLK_GPIO1_GATE_SHIFT 4
243
Tony Xie6fba6e02016-01-15 17:17:32 +0800244/**************************************************
245 * sgrf reg, offset
246 **************************************************/
247#define SGRF_SOC_CON0_1(n) (0xc000 + (n) * 4)
248#define SGRF_SOC_CON3_7(n) (0xe00c + ((n) - 3) * 4)
249#define SGRF_SOC_CON8_15(n) (0x8020 + ((n) - 8) * 4)
250#define SGRF_PMU_SLV_CON0_1(n) (0xc240 + ((n) - 0) * 4)
251#define SGRF_SLV_SECURE_CON0_4(n) (0xe3c0 + ((n) - 0) * 4)
252#define SGRF_DDRRGN_CON0_16(n) ((n) * 4)
253#define SGRF_DDRRGN_CON20_34(n) (0x50 + ((n) - 20) * 4)
254
255/* security config for master */
256#define SGRF_SOC_CON_WMSK 0xffff0000
257/* All of master in ns */
258#define SGRF_SOC_ALLMST_NS 0xffff
259
260/* security config for slave */
261#define SGRF_SLV_S_WMSK 0xffff0000
262#define SGRF_SLV_S_ALL_NS 0x0
263
264/* security config pmu slave ip */
265/* All of slaves is ns */
266#define SGRF_PMU_SLV_S_NS BIT_WITH_WMSK(0)
267/* slaves secure attr is configed */
268#define SGRF_PMU_SLV_S_CFGED WMSK_BIT(0)
269#define SGRF_PMU_SLV_CRYPTO1_NS WMSK_BIT(1)
270
271#define SGRF_PMUSRAM_S BIT(8)
272
273#define SGRF_PMU_SLV_CON1_CFG (SGRF_SLV_S_WMSK | \
274 SGRF_PMUSRAM_S)
275/* ddr region */
Xing Zheng941c7142017-02-24 14:47:51 +0800276#define SGRF_DDR_RGN_0_16_WMSK 0x0fff /* DDR RGN 0~16 size mask */
277
Caesar Wang2831bc32016-10-27 01:13:16 +0800278#define SGRF_DDR_RGN_DPLL_CLK BIT_WITH_WMSK(15) /* DDR PLL output clock */
279#define SGRF_DDR_RGN_RTC_CLK BIT_WITH_WMSK(14) /* 32K clock for DDR PLL */
Tony Xie6fba6e02016-01-15 17:17:32 +0800280#define SGRF_DDR_RGN_BYPS BIT_WITH_WMSK(9) /* All of ddr rgn is ns */
Xing Zheng941c7142017-02-24 14:47:51 +0800281/* All security of the DDR RGNs are not bypass */
282#define SGRF_DDR_RGN_NO_BYPS WMSK_BIT(9)
Tony Xie6fba6e02016-01-15 17:17:32 +0800283
284/* The MST access the ddr rgn n with secure attribution */
285#define SGRF_L_MST_S_DDR_RGN(n) BIT_WITH_WMSK((n))
286/* bits[16:8]*/
287#define SGRF_H_MST_S_DDR_RGN(n) BIT_WITH_WMSK((n) + 8)
288
289/* dmac to periph s or ns*/
290#define SGRF_DMAC_CFG_S 0xffff0000
291
292#define DMAC1_RGN_NS 0xff000000
293#define DMAC0_RGN_NS 0x00ff0000
294
295#define DMAC0_BOOT_CFG_NS 0xfffffff8
296#define DMAC0_BOOT_PERIPH_NS 0xffff0fff
297#define DMAC0_BOOT_ADDR_NS 0xffff0000
298
299#define DMAC1_BOOT_CFG_NS 0xffff0008
300#define DMAC1_BOOT_PERIPH_L_NS 0xffff0fff
301#define DMAC1_BOOT_ADDR_NS 0xffff0000
302#define DMAC1_BOOT_PERIPH_H_NS 0xffffffff
303#define DMAC1_BOOT_IRQ_NS 0xffffffff
304
305#define CPU_BOOT_ADDR_WMASK 0xffff0000
306#define CPU_BOOT_ADDR_ALIGN 16
307
Caesar Wang5d3b1062016-08-11 02:11:45 +0800308#define GRF_IOMUX_2BIT_MASK 0x3
309#define GRF_IOMUX_GPIO 0x0
310
311#define GRF_GPIO4C2_IOMUX_SHIFT 4
312#define GRF_GPIO4C2_IOMUX_PWM 0x1
313#define GRF_GPIO4C6_IOMUX_SHIFT 12
314#define GRF_GPIO4C6_IOMUX_PWM 0x1
315
316#define PWM_CNT(n) (0x0000 + 0x10 * (n))
317#define PWM_PERIOD_HPR(n) (0x0004 + 0x10 * (n))
318#define PWM_DUTY_LPR(n) (0x0008 + 0x10 * (n))
319#define PWM_CTRL(n) (0x000c + 0x10 * (n))
320
321#define PWM_DISABLE (0 << 0)
322#define PWM_ENABLE (1 << 0)
323
Caesar Wangfe877772016-08-25 08:37:42 +0800324/* grf reg offset */
325#define GRF_DDRC0_CON0 0xe380
326#define GRF_DDRC0_CON1 0xe384
327#define GRF_DDRC1_CON0 0xe388
328#define GRF_DDRC1_CON1 0xe38c
Xing Zheng977001a2016-10-26 21:25:26 +0800329#define GRF_SOC_CON_BASE 0xe200
330#define GRF_SOC_CON(n) (GRF_SOC_CON_BASE + (n) * 4)
Caesar Wangfe877772016-08-25 08:37:42 +0800331
Caesar Wang7ac52002016-10-12 01:47:51 +0800332#define PMUCRU_CLKSEL_CON0 0x0080
333#define PMUCRU_CLKGATE_CON2 0x0108
334#define PMUCRU_SOFTRST_CON0 0x0110
335#define PMUCRU_GATEDIS_CON0 0x0130
336
337#define SGRF_SOC_CON6 0x0e018
338#define SGRF_PERILP_CON0 0x08100
339#define SGRF_PERILP_CON(n) (SGRF_PERILP_CON0 + (n) * 4)
340#define SGRF_PMU_CON0 0x0c100
341#define SGRF_PMU_CON(n) (SGRF_PMU_CON0 + (n) * 4)
342#define PMUCRU_SOFTRST_CON(n) (PMUCRU_SOFTRST_CON0 + (n) * 4)
343
Tony Xie6fba6e02016-01-15 17:17:32 +0800344/*
345 * When system reset in running state, we want the cpus to be reboot
346 * from maskrom (system reboot),
347 * the pmusgrf reset-hold bits needs to be released.
348 * When system wake up from system deep suspend, some soc will be reset
349 * when waked up,
350 * we want the bootcpu to be reboot from pmusram,
351 * the pmusgrf reset-hold bits needs to be held.
352 */
353static inline void pmu_sgrf_rst_hld_release(void)
354{
355 mmio_write_32(PMUCRU_BASE + CRU_PMU_RSTHOLD_CON(1),
356 CRU_PMU_SGRF_RST_RLS);
357}
358
359static inline void pmu_sgrf_rst_hld(void)
360{
361 mmio_write_32(PMUCRU_BASE + CRU_PMU_RSTHOLD_CON(1),
362 CRU_PMU_SGRF_RST_HOLD);
363}
364
365/* funciton*/
366void __dead2 soc_global_soft_reset(void);
Caesar Wanga14e0912016-11-04 21:13:01 +0800367void secure_watchdog_disable();
368void secure_watchdog_restore();
Caesar Wang5d3b1062016-08-11 02:11:45 +0800369void disable_dvfs_plls(void);
370void disable_nodvfs_plls(void);
Caesar Wang5d3b1062016-08-11 02:11:45 +0800371void enable_dvfs_plls(void);
372void enable_nodvfs_plls(void);
Caesar Wang4c127e62016-10-27 01:13:34 +0800373void prepare_abpll_for_ddrctrl(void);
374void restore_abpll(void);
375void restore_dpll(void);
Tony Xie9ec78bd2016-07-16 11:16:51 +0800376void clk_gate_con_save(void);
377void clk_gate_con_disable(void);
378void clk_gate_con_restore(void);
Caesar Wang4c127e62016-10-27 01:13:34 +0800379void sgrf_init(void);
Tony Xie6fba6e02016-01-15 17:17:32 +0800380#endif /* __SOC_H__ */