blob: c6a39aa3412dd77e3fa3dc28ca8648c22b88724a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Wang Huan8ce6bec2014-09-05 13:52:34 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Wang Huan8ce6bec2014-09-05 13:52:34 +08004 */
5
6#include <common.h>
Simon Glass370382c2019-11-14 12:57:35 -07007#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Simon Glassf5c208d2019-11-14 12:57:20 -070010#include <vsprintf.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080011#include <asm/arch/clock.h>
12#include <asm/io.h>
13#include <asm/arch/immap_ls102xa.h>
Minghuan Lian6c9afed2015-01-21 17:29:17 +080014#include <asm/cache.h>
15#include <asm/system.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080016#include <tsec.h>
17#include <netdev.h>
18#include <fsl_esdhc.h>
Fabio Estevam0af008c2015-10-03 14:21:00 -030019#include <config.h>
20#include <fsl_wdog.h>
Simon Glassdbd79542020-05-10 11:40:11 -060021#include <linux/delay.h>
Wang Huan8ce6bec2014-09-05 13:52:34 +080022
chenhui zhao0c789872014-10-22 18:20:22 +080023#include "fsl_epu.h"
24
chenhui zhao9a378cb2015-01-23 15:53:53 +080025#define DCSR_RCPM2_BLOCK_OFFSET 0x223000
26#define DCSR_RCPM2_CPMFSMCR0 0x400
27#define DCSR_RCPM2_CPMFSMSR0 0x404
28#define DCSR_RCPM2_CPMFSMCR1 0x414
29#define DCSR_RCPM2_CPMFSMSR1 0x418
30#define CPMFSMSR_FSM_STATE_MASK 0x7f
31
Wang Huan8ce6bec2014-09-05 13:52:34 +080032DECLARE_GLOBAL_DATA_PTR;
33
Trevor Woerner43ec7e02019-05-03 09:41:00 -040034#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Minghuan Lian6c9afed2015-01-21 17:29:17 +080035
36/*
37 * Bit[1] of the descriptor indicates the descriptor type,
38 * and bit[0] indicates whether the descriptor is valid.
39 */
40#define PMD_TYPE_TABLE 0x3
41#define PMD_TYPE_SECT 0x1
42
43/* AttrIndx[2:0] */
44#define PMD_ATTRINDX(t) ((t) << 2)
45
46/* Section */
47#define PMD_SECT_AF (1 << 10)
48
49#define BLOCK_SIZE_L1 (1UL << 30)
50#define BLOCK_SIZE_L2 (1UL << 21)
51
52/* TTBCR flags */
53#define TTBCR_EAE (1 << 31)
54#define TTBCR_T0SZ(x) ((x) << 0)
55#define TTBCR_T1SZ(x) ((x) << 16)
56#define TTBCR_USING_TTBR0 (TTBCR_T0SZ(0) | TTBCR_T1SZ(0))
57#define TTBCR_IRGN0_NC (0 << 8)
58#define TTBCR_IRGN0_WBWA (1 << 8)
59#define TTBCR_IRGN0_WT (2 << 8)
60#define TTBCR_IRGN0_WBNWA (3 << 8)
61#define TTBCR_IRGN0_MASK (3 << 8)
62#define TTBCR_ORGN0_NC (0 << 10)
63#define TTBCR_ORGN0_WBWA (1 << 10)
64#define TTBCR_ORGN0_WT (2 << 10)
65#define TTBCR_ORGN0_WBNWA (3 << 10)
66#define TTBCR_ORGN0_MASK (3 << 10)
67#define TTBCR_SHARED_NON (0 << 12)
68#define TTBCR_SHARED_OUTER (2 << 12)
69#define TTBCR_SHARED_INNER (3 << 12)
70#define TTBCR_EPD0 (0 << 7)
71#define TTBCR (TTBCR_SHARED_NON | \
72 TTBCR_ORGN0_NC | \
73 TTBCR_IRGN0_NC | \
74 TTBCR_USING_TTBR0 | \
75 TTBCR_EAE)
76
77/*
78 * Memory region attributes for LPAE (defined in pgtable):
79 *
80 * n = AttrIndx[2:0]
81 *
82 * n MAIR
83 * UNCACHED 000 00000000
84 * BUFFERABLE 001 01000100
85 * DEV_WC 001 01000100
86 * WRITETHROUGH 010 10101010
87 * WRITEBACK 011 11101110
88 * DEV_CACHED 011 11101110
89 * DEV_SHARED 100 00000100
90 * DEV_NONSHARED 100 00000100
91 * unused 101
92 * unused 110
93 * WRITEALLOC 111 11111111
94 */
95#define MT_MAIR0 0xeeaa4400
96#define MT_MAIR1 0xff000004
97#define MT_STRONLY_ORDER 0
98#define MT_NORMAL_NC 1
99#define MT_DEVICE_MEM 4
100#define MT_NORMAL 7
101
102/* The phy_addr must be aligned to 4KB */
103static inline void set_pgtable(u32 *page_table, u32 index, u32 phy_addr)
104{
105 u32 value = phy_addr | PMD_TYPE_TABLE;
106
107 page_table[2 * index] = value;
108 page_table[2 * index + 1] = 0;
109}
110
111/* The phy_addr must be aligned to 4KB */
112static inline void set_pgsection(u32 *page_table, u32 index, u64 phy_addr,
113 u32 memory_type)
114{
115 u64 value;
116
117 value = phy_addr | PMD_TYPE_SECT | PMD_SECT_AF;
118 value |= PMD_ATTRINDX(memory_type);
119 page_table[2 * index] = value & 0xFFFFFFFF;
120 page_table[2 * index + 1] = (value >> 32) & 0xFFFFFFFF;
121}
122
123/*
124 * Start MMU after DDR is available, we create MMU table in DRAM.
125 * The base address of TTLB is gd->arch.tlb_addr. We use two
126 * levels of translation tables here to cover 40-bit address space.
127 *
128 * The TTLBs are located at PHY 2G~4G.
129 *
130 * VA mapping:
131 *
132 * ------- <---- 0GB
133 * | |
134 * | |
135 * |-------| <---- 0x24000000
136 * |///////| ===> 192MB VA map for PCIe1 with offset 0x40_0000_0000
137 * |-------| <---- 0x300000000
138 * | |
139 * |-------| <---- 0x34000000
140 * |///////| ===> 192MB VA map for PCIe2 with offset 0x48_0000_0000
141 * |-------| <---- 0x40000000
142 * | |
143 * |-------| <---- 0x80000000 DDR0 space start
144 * |\\\\\\\|
145 *.|\\\\\\\| ===> 2GB VA map for 2GB DDR0 Memory space
146 * |\\\\\\\|
147 * ------- <---- 4GB DDR0 space end
148 */
149static void mmu_setup(void)
150{
151 u32 *level0_table = (u32 *)gd->arch.tlb_addr;
152 u32 *level1_table = (u32 *)(gd->arch.tlb_addr + 0x1000);
153 u64 va_start = 0;
154 u32 reg;
155 int i;
156
157 /* Level 0 Table 2-3 are used to map DDR */
158 set_pgsection(level0_table, 3, 3 * BLOCK_SIZE_L1, MT_NORMAL);
159 set_pgsection(level0_table, 2, 2 * BLOCK_SIZE_L1, MT_NORMAL);
160 /* Level 0 Table 1 is used to map device */
161 set_pgsection(level0_table, 1, 1 * BLOCK_SIZE_L1, MT_DEVICE_MEM);
162 /* Level 0 Table 0 is used to map device including PCIe MEM */
163 set_pgtable(level0_table, 0, (u32)level1_table);
164
165 /* Level 1 has 512 entries */
166 for (i = 0; i < 512; i++) {
167 /* Mapping for PCIe 1 */
168 if (va_start >= CONFIG_SYS_PCIE1_VIRT_ADDR &&
169 va_start < (CONFIG_SYS_PCIE1_VIRT_ADDR +
170 CONFIG_SYS_PCIE_MMAP_SIZE))
171 set_pgsection(level1_table, i,
172 CONFIG_SYS_PCIE1_PHYS_BASE + va_start,
173 MT_DEVICE_MEM);
174 /* Mapping for PCIe 2 */
175 else if (va_start >= CONFIG_SYS_PCIE2_VIRT_ADDR &&
176 va_start < (CONFIG_SYS_PCIE2_VIRT_ADDR +
177 CONFIG_SYS_PCIE_MMAP_SIZE))
178 set_pgsection(level1_table, i,
179 CONFIG_SYS_PCIE2_PHYS_BASE + va_start,
180 MT_DEVICE_MEM);
181 else
182 set_pgsection(level1_table, i,
183 va_start,
184 MT_DEVICE_MEM);
185 va_start += BLOCK_SIZE_L2;
186 }
187
188 asm volatile("dsb sy;isb");
189 asm volatile("mcr p15, 0, %0, c2, c0, 2" /* Write RT to TTBCR */
190 : : "r" (TTBCR) : "memory");
191 asm volatile("mcrr p15, 0, %0, %1, c2" /* TTBR 0 */
192 : : "r" ((u32)level0_table), "r" (0) : "memory");
193 asm volatile("mcr p15, 0, %0, c10, c2, 0" /* write MAIR 0 */
194 : : "r" (MT_MAIR0) : "memory");
195 asm volatile("mcr p15, 0, %0, c10, c2, 1" /* write MAIR 1 */
196 : : "r" (MT_MAIR1) : "memory");
197
198 /* Set the access control to all-supervisor */
199 asm volatile("mcr p15, 0, %0, c3, c0, 0"
200 : : "r" (~0));
201
202 /* Enable the mmu */
203 reg = get_cr();
204 set_cr(reg | CR_M);
205}
206
207/*
208 * This function is called from lib/board.c. It recreates MMU
209 * table in main memory. MMU and i/d-cache are enabled here.
210 */
211void enable_caches(void)
212{
213 /* Invalidate all TLB */
214 mmu_page_table_flush(gd->arch.tlb_addr,
215 gd->arch.tlb_addr + gd->arch.tlb_size);
216 /* Set up and enable mmu */
217 mmu_setup();
218
219 /* Invalidate & Enable d-cache */
220 invalidate_dcache_all();
221 set_cr(get_cr() | CR_C);
222}
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400223#endif /* #if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) */
Minghuan Lian6c9afed2015-01-21 17:29:17 +0800224
Shengzhou Liubf5aee92015-11-20 15:52:02 +0800225
226uint get_svr(void)
227{
228 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
229
230 return in_be32(&gur->svr);
231}
232
Wang Huan8ce6bec2014-09-05 13:52:34 +0800233#if defined(CONFIG_DISPLAY_CPUINFO)
234int print_cpuinfo(void)
235{
236 char buf1[32], buf2[32];
237 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
238 unsigned int svr, major, minor, ver, i;
239
240 svr = in_be32(&gur->svr);
241 major = SVR_MAJ(svr);
242 minor = SVR_MIN(svr);
243
244 puts("CPU: Freescale LayerScape ");
245
246 ver = SVR_SOC_VER(svr);
247 switch (ver) {
248 case SOC_VER_SLS1020:
249 puts("SLS1020");
250 break;
251 case SOC_VER_LS1020:
252 puts("LS1020");
253 break;
254 case SOC_VER_LS1021:
255 puts("LS1021");
256 break;
257 case SOC_VER_LS1022:
258 puts("LS1022");
259 break;
260 default:
261 puts("Unknown");
262 break;
263 }
264
265 if (IS_E_PROCESSOR(svr) && (ver != SOC_VER_SLS1020))
266 puts("E");
267
268 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
269
270 puts("Clock Configuration:");
271
272 printf("\n CPU0(ARMV7):%-4s MHz, ", strmhz(buf1, gd->cpu_clk));
273 printf("\n Bus:%-4s MHz, ", strmhz(buf1, gd->bus_clk));
274 printf("DDR:%-4s MHz (%s MT/s data rate), ",
275 strmhz(buf1, gd->mem_clk/2), strmhz(buf2, gd->mem_clk));
276 puts("\n");
277
278 /* Display the RCW, so that no one gets confused as to what RCW
279 * we're actually using for this boot.
280 */
281 puts("Reset Configuration Word (RCW):");
282 for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
283 u32 rcw = in_be32(&gur->rcwsr[i]);
284
285 if ((i % 4) == 0)
286 printf("\n %08x:", i * 4);
287 printf(" %08x", rcw);
288 }
289 puts("\n");
290
291 return 0;
292}
293#endif
294
Wang Huan8ce6bec2014-09-05 13:52:34 +0800295#ifdef CONFIG_FSL_ESDHC
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900296int cpu_mmc_init(struct bd_info *bis)
Wang Huan8ce6bec2014-09-05 13:52:34 +0800297{
298 return fsl_esdhc_mmc_init(bis);
299}
300#endif
301
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900302int cpu_eth_init(struct bd_info *bis)
Wang Huan8ce6bec2014-09-05 13:52:34 +0800303{
Bin Meng19c04602019-07-19 00:29:59 +0300304#if defined(CONFIG_TSEC_ENET) && !defined(CONFIG_DM_ETH)
Wang Huan8ce6bec2014-09-05 13:52:34 +0800305 tsec_standard_init(bis);
306#endif
307
308 return 0;
309}
chenhui zhao0c789872014-10-22 18:20:22 +0800310
311int arch_cpu_init(void)
312{
313 void *epu_base = (void *)(CONFIG_SYS_DCSRBAR + EPU_BLOCK_OFFSET);
chenhui zhao9a378cb2015-01-23 15:53:53 +0800314 void *rcpm2_base =
315 (void *)(CONFIG_SYS_DCSRBAR + DCSR_RCPM2_BLOCK_OFFSET);
horia.geanta@freescale.comcc0619c2015-10-15 14:21:31 +0300316 struct ccsr_scfg *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
chenhui zhao9a378cb2015-01-23 15:53:53 +0800317 u32 state;
318
Hou Zhiqiang49713762021-02-05 15:45:12 +0800319 icache_enable();
320
chenhui zhao9a378cb2015-01-23 15:53:53 +0800321 /*
322 * The RCPM FSM state may not be reset after power-on.
323 * So, reset them.
324 */
325 state = in_be32(rcpm2_base + DCSR_RCPM2_CPMFSMSR0) &
326 CPMFSMSR_FSM_STATE_MASK;
327 if (state != 0) {
328 out_be32(rcpm2_base + DCSR_RCPM2_CPMFSMCR0, 0x80);
329 out_be32(rcpm2_base + DCSR_RCPM2_CPMFSMCR0, 0x0);
330 }
331
332 state = in_be32(rcpm2_base + DCSR_RCPM2_CPMFSMSR1) &
333 CPMFSMSR_FSM_STATE_MASK;
334 if (state != 0) {
335 out_be32(rcpm2_base + DCSR_RCPM2_CPMFSMCR1, 0x80);
336 out_be32(rcpm2_base + DCSR_RCPM2_CPMFSMCR1, 0x0);
337 }
chenhui zhao0c789872014-10-22 18:20:22 +0800338
339 /*
340 * After wakeup from deep sleep, Clear EPU registers
341 * as early as possible to prevent from possible issue.
342 * It's also safe to clear at normal boot.
343 */
344 fsl_epu_clean(epu_base);
345
horia.geanta@freescale.comcc0619c2015-10-15 14:21:31 +0300346 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SEC_RD_WR);
347
chenhui zhao0c789872014-10-22 18:20:22 +0800348 return 0;
349}
Xiubo Lib73446d2014-11-21 17:40:56 +0800350
Jan Kiszkaac31b5a2015-04-21 07:18:24 +0200351#ifdef CONFIG_ARMV7_NONSEC
Xiubo Lib73446d2014-11-21 17:40:56 +0800352/* Set the address at which the secondary core starts from.*/
353void smp_set_core_boot_addr(unsigned long addr, int corenr)
354{
355 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
356
357 out_be32(&gur->scratchrw[0], addr);
358}
359
360/* Release the secondary core from holdoff state and kick it */
361void smp_kick_all_cpus(void)
362{
363 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
364
365 out_be32(&gur->brrl, 0x2);
Wang Dongsheng0b5034c2015-06-18 18:32:58 +0800366
367 /*
368 * LS1 STANDBYWFE is not captured outside the ARM module in the soc.
369 * So add a delay to wait bootrom execute WFE.
370 */
371 udelay(1);
372
373 asm volatile("sev");
Xiubo Lib73446d2014-11-21 17:40:56 +0800374}
375#endif
Fabio Estevam0af008c2015-10-03 14:21:00 -0300376
377void reset_cpu(ulong addr)
378{
379 struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
380
381 clrbits_be16(&wdog->wcr, WCR_SRS);
382
383 while (1) {
384 /*
385 * Let the watchdog trigger
386 */
387 }
388}
Alison Wangd285ef72015-08-04 09:55:37 +0800389
390void arch_preboot_os(void)
391{
392 unsigned long ctrl;
393
394 /* Disable PL1 Physical Timer */
395 asm("mrc p15, 0, %0, c14, c2, 1" : "=r" (ctrl));
396 ctrl &= ~ARCH_TIMER_CTRL_ENABLE;
397 asm("mcr p15, 0, %0, c14, c2, 1" : : "r" (ctrl));
398}