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