blob: ec5470e48ca304268a0ecf1e86755263f9713b2a [file] [log] [blame]
Tony Xief6118cc2016-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#include <arch_helpers.h>
Xing Zheng5e1e48f2017-02-24 14:47:51 +080032#include <assert.h>
Tony Xief6118cc2016-01-15 17:17:32 +080033#include <debug.h>
34#include <delay_timer.h>
Derek Basehoreff461d02016-10-20 20:46:43 -070035#include <dfs.h>
36#include <dram.h>
Tony Xief6118cc2016-01-15 17:17:32 +080037#include <mmio.h>
Xing Zheng93280b72016-10-26 21:25:26 +080038#include <m0_ctl.h>
Tony Xief6118cc2016-01-15 17:17:32 +080039#include <platform_def.h>
40#include <plat_private.h>
41#include <rk3399_def.h>
Xing Zheng22a98712017-02-24 14:56:41 +080042#include <secure.h>
Tony Xief6118cc2016-01-15 17:17:32 +080043#include <soc.h>
44
45/* Table of regions to map using the MMU. */
46const mmap_region_t plat_rk_mmap[] = {
Xing Zhengb4bcc1d2017-02-24 16:26:11 +080047 MAP_REGION_FLAT(DEV_RNG0_BASE, DEV_RNG0_SIZE,
Tony Xie42e113e2016-07-16 11:16:51 +080048 MT_DEVICE | MT_RW | MT_SECURE),
Caesar Wang5339d182016-10-27 01:13:34 +080049 MAP_REGION_FLAT(PMUSRAM_BASE, PMUSRAM_SIZE,
50 MT_MEMORY | MT_RW | MT_SECURE),
Tony Xie42e113e2016-07-16 11:16:51 +080051
Tony Xief6118cc2016-01-15 17:17:32 +080052 { 0 }
53};
54
55/* The RockChip power domain tree descriptor */
56const unsigned char rockchip_power_domain_tree_desc[] = {
57 /* No of root nodes */
58 PLATFORM_SYSTEM_COUNT,
59 /* No of children for the root node */
60 PLATFORM_CLUSTER_COUNT,
61 /* No of children for the first cluster node */
62 PLATFORM_CLUSTER0_CORE_COUNT,
63 /* No of children for the second cluster node */
64 PLATFORM_CLUSTER1_CORE_COUNT
65};
66
Xing Zheng22a98712017-02-24 14:56:41 +080067/* sleep data for pll suspend */
68static struct deepsleep_data_s slp_data;
Xing Zheng5e1e48f2017-02-24 14:47:51 +080069
Tony Xief6118cc2016-01-15 17:17:32 +080070static void set_pll_slow_mode(uint32_t pll_id)
71{
72 if (pll_id == PPLL_ID)
73 mmio_write_32(PMUCRU_BASE + PMUCRU_PPLL_CON(3), PLL_SLOW_MODE);
74 else
75 mmio_write_32((CRU_BASE +
76 CRU_PLL_CON(pll_id, 3)), PLL_SLOW_MODE);
77}
78
79static void set_pll_normal_mode(uint32_t pll_id)
80{
81 if (pll_id == PPLL_ID)
82 mmio_write_32(PMUCRU_BASE + PMUCRU_PPLL_CON(3), PLL_NOMAL_MODE);
83 else
84 mmio_write_32(CRU_BASE +
85 CRU_PLL_CON(pll_id, 3), PLL_NOMAL_MODE);
86}
87
88static void set_pll_bypass(uint32_t pll_id)
89{
90 if (pll_id == PPLL_ID)
91 mmio_write_32(PMUCRU_BASE +
92 PMUCRU_PPLL_CON(3), PLL_BYPASS_MODE);
93 else
94 mmio_write_32(CRU_BASE +
95 CRU_PLL_CON(pll_id, 3), PLL_BYPASS_MODE);
96}
97
98static void _pll_suspend(uint32_t pll_id)
99{
100 set_pll_slow_mode(pll_id);
101 set_pll_bypass(pll_id);
102}
103
Caesar Wang5339d182016-10-27 01:13:34 +0800104/**
105 * disable_dvfs_plls - To suspend the specific PLLs
106 *
107 * When we close the center logic, the DPLL will be closed,
108 * so we need to keep the ABPLL and switch to it to supply
109 * clock for DDR during suspend, then we should not close
110 * the ABPLL and exclude ABPLL_ID.
111 */
Caesar Wanged6b9a52016-08-11 02:11:45 +0800112void disable_dvfs_plls(void)
113{
114 _pll_suspend(CPLL_ID);
115 _pll_suspend(NPLL_ID);
116 _pll_suspend(VPLL_ID);
117 _pll_suspend(GPLL_ID);
Caesar Wanged6b9a52016-08-11 02:11:45 +0800118 _pll_suspend(ALPLL_ID);
119}
120
Caesar Wang5339d182016-10-27 01:13:34 +0800121/**
122 * disable_nodvfs_plls - To suspend the PPLL
123 */
Caesar Wanged6b9a52016-08-11 02:11:45 +0800124void disable_nodvfs_plls(void)
125{
126 _pll_suspend(PPLL_ID);
127}
128
Caesar Wang5339d182016-10-27 01:13:34 +0800129/**
130 * restore_pll - Copy PLL settings from memory to a PLL.
131 *
132 * This will copy PLL settings from an array in memory to the memory mapped
133 * registers for a PLL.
134 *
135 * Note that: above the PLL exclude PPLL.
136 *
137 * pll_id: One of the values from enum plls_id
138 * src: Pointer to the array of values to restore from
139 */
140static void restore_pll(int pll_id, uint32_t *src)
141{
142 /* Nice to have PLL off while configuring */
143 mmio_write_32((CRU_BASE + CRU_PLL_CON(pll_id, 3)), PLL_SLOW_MODE);
144
145 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 0), src[0] | REG_SOC_WMSK);
146 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 1), src[1] | REG_SOC_WMSK);
147 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 2), src[2]);
148 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 4), src[4] | REG_SOC_WMSK);
149 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 5), src[5] | REG_SOC_WMSK);
150
151 /* Do PLL_CON3 since that will enable things */
152 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 3), src[3] | REG_SOC_WMSK);
153
154 /* Wait for PLL lock done */
155 while ((mmio_read_32(CRU_BASE + CRU_PLL_CON(pll_id, 2)) &
156 0x80000000) == 0x0)
157 ;
158}
159
160/**
161 * save_pll - Copy PLL settings a PLL to memory
162 *
163 * This will copy PLL settings from the memory mapped registers for a PLL to
164 * an array in memory.
165 *
166 * Note that: above the PLL exclude PPLL.
167 *
168 * pll_id: One of the values from enum plls_id
169 * src: Pointer to the array of values to save to.
170 */
171static void save_pll(uint32_t *dst, int pll_id)
172{
173 int i;
174
175 for (i = 0; i < PLL_CON_COUNT; i++)
176 dst[i] = mmio_read_32(CRU_BASE + CRU_PLL_CON(pll_id, i));
177}
178
179/**
180 * prepare_abpll_for_ddrctrl - Copy DPLL settings to ABPLL
181 *
182 * This will copy DPLL settings from the memory mapped registers for a PLL to
183 * an array in memory.
184 */
185void prepare_abpll_for_ddrctrl(void)
186{
187 save_pll(slp_data.plls_con[ABPLL_ID], ABPLL_ID);
188 save_pll(slp_data.plls_con[DPLL_ID], DPLL_ID);
189
190 restore_pll(ABPLL_ID, slp_data.plls_con[DPLL_ID]);
191}
192
193void restore_abpll(void)
194{
195 restore_pll(ABPLL_ID, slp_data.plls_con[ABPLL_ID]);
196}
197
198void restore_dpll(void)
199{
200 restore_pll(DPLL_ID, slp_data.plls_con[DPLL_ID]);
201}
202
Tony Xie42e113e2016-07-16 11:16:51 +0800203void clk_gate_con_save(void)
204{
205 uint32_t i = 0;
206
207 for (i = 0; i < PMUCRU_GATE_COUNT; i++)
208 slp_data.pmucru_gate_con[i] =
209 mmio_read_32(PMUCRU_BASE + PMUCRU_GATE_CON(i));
210
211 for (i = 0; i < CRU_GATE_COUNT; i++)
212 slp_data.cru_gate_con[i] =
213 mmio_read_32(CRU_BASE + CRU_GATE_CON(i));
214}
215
216void clk_gate_con_disable(void)
217{
218 uint32_t i;
219
220 for (i = 0; i < PMUCRU_GATE_COUNT; i++)
221 mmio_write_32(PMUCRU_BASE + PMUCRU_GATE_CON(i), REG_SOC_WMSK);
222
223 for (i = 0; i < CRU_GATE_COUNT; i++)
224 mmio_write_32(CRU_BASE + CRU_GATE_CON(i), REG_SOC_WMSK);
225}
226
227void clk_gate_con_restore(void)
228{
229 uint32_t i;
230
231 for (i = 0; i < PMUCRU_GATE_COUNT; i++)
232 mmio_write_32(PMUCRU_BASE + PMUCRU_GATE_CON(i),
233 REG_SOC_WMSK | slp_data.pmucru_gate_con[i]);
234
235 for (i = 0; i < CRU_GATE_COUNT; i++)
236 mmio_write_32(CRU_BASE + CRU_GATE_CON(i),
237 REG_SOC_WMSK | slp_data.cru_gate_con[i]);
238}
239
Tony Xief6118cc2016-01-15 17:17:32 +0800240static void set_plls_nobypass(uint32_t pll_id)
241{
242 if (pll_id == PPLL_ID)
243 mmio_write_32(PMUCRU_BASE + PMUCRU_PPLL_CON(3),
244 PLL_NO_BYPASS_MODE);
245 else
246 mmio_write_32(CRU_BASE + CRU_PLL_CON(pll_id, 3),
247 PLL_NO_BYPASS_MODE);
248}
249
Caesar Wanged6b9a52016-08-11 02:11:45 +0800250static void _pll_resume(uint32_t pll_id)
251{
252 set_plls_nobypass(pll_id);
253 set_pll_normal_mode(pll_id);
254}
255
Caesar Wang5339d182016-10-27 01:13:34 +0800256/**
257 * enable_dvfs_plls - To resume the specific PLLs
258 *
259 * Please see the comment at the disable_dvfs_plls()
260 * we don't suspend the ABPLL, so don't need resume
261 * it too.
262 */
Caesar Wanged6b9a52016-08-11 02:11:45 +0800263void enable_dvfs_plls(void)
Tony Xief6118cc2016-01-15 17:17:32 +0800264{
Caesar Wanged6b9a52016-08-11 02:11:45 +0800265 _pll_resume(ALPLL_ID);
Caesar Wanged6b9a52016-08-11 02:11:45 +0800266 _pll_resume(GPLL_ID);
267 _pll_resume(VPLL_ID);
268 _pll_resume(NPLL_ID);
269 _pll_resume(CPLL_ID);
270}
Tony Xief6118cc2016-01-15 17:17:32 +0800271
Caesar Wang5339d182016-10-27 01:13:34 +0800272/**
273 * enable_nodvfs_plls - To resume the PPLL
274 */
Caesar Wanged6b9a52016-08-11 02:11:45 +0800275void enable_nodvfs_plls(void)
276{
277 _pll_resume(PPLL_ID);
Tony Xief6118cc2016-01-15 17:17:32 +0800278}
279
280void soc_global_soft_reset_init(void)
281{
282 mmio_write_32(PMUCRU_BASE + CRU_PMU_RSTHOLD_CON(1),
283 CRU_PMU_SGRF_RST_RLS);
Caesar Wang59e41b52016-04-10 14:11:07 +0800284
285 mmio_clrbits_32(CRU_BASE + CRU_GLB_RST_CON,
286 CRU_PMU_WDTRST_MSK | CRU_PMU_FIRST_SFTRST_MSK);
Tony Xief6118cc2016-01-15 17:17:32 +0800287}
288
Xing Zheng22a98712017-02-24 14:56:41 +0800289void __dead2 soc_global_soft_reset(void)
Tony Xief6118cc2016-01-15 17:17:32 +0800290{
Tony Xief6118cc2016-01-15 17:17:32 +0800291 set_pll_slow_mode(VPLL_ID);
292 set_pll_slow_mode(NPLL_ID);
293 set_pll_slow_mode(GPLL_ID);
294 set_pll_slow_mode(CPLL_ID);
295 set_pll_slow_mode(PPLL_ID);
296 set_pll_slow_mode(ABPLL_ID);
297 set_pll_slow_mode(ALPLL_ID);
Caesar Wang59e41b52016-04-10 14:11:07 +0800298
299 dsb();
300
Tony Xief6118cc2016-01-15 17:17:32 +0800301 mmio_write_32(CRU_BASE + CRU_GLB_SRST_FST, GLB_SRST_FST_CFG_VAL);
302
303 /*
304 * Maybe the HW needs some times to reset the system,
305 * so we do not hope the core to excute valid codes.
306 */
307 while (1)
Tony Xie42e113e2016-07-16 11:16:51 +0800308 ;
Tony Xief6118cc2016-01-15 17:17:32 +0800309}
310
311void plat_rockchip_soc_init(void)
312{
313 secure_timer_init();
Xing Zheng22a98712017-02-24 14:56:41 +0800314 secure_sgrf_init();
Xing Zheng5e1e48f2017-02-24 14:47:51 +0800315 secure_sgrf_ddr_rgn_init();
Tony Xief6118cc2016-01-15 17:17:32 +0800316 soc_global_soft_reset_init();
Caesar Wang038f6aa2016-05-25 19:21:43 +0800317 plat_rockchip_gpio_init();
Xing Zheng93280b72016-10-26 21:25:26 +0800318 m0_init();
Caesar Wanga8456902016-10-27 01:12:34 +0800319 dram_init();
Derek Basehoreff461d02016-10-20 20:46:43 -0700320 dram_dfs_init();
Tony Xief6118cc2016-01-15 17:17:32 +0800321}