blob: 0b5f26515a27aaacf001b2972158e4938ddf37a7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mingkai Hueee86ff2015-10-26 19:47:52 +08002/*
3 * Copyright 2015 Freescale Semiconductor, Inc.
Mingkai Hueee86ff2015-10-26 19:47:52 +08004 */
5
6#include <common.h>
7#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +08009#include <asm/io.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/fsl_serdes.h>
12#include <asm/arch/soc.h>
Laurentiu Tudor22012d52018-08-27 17:33:59 +030013#include <asm/arch-fsl-layerscape/fsl_icid.h>
Simon Glasse3ee2fb2016-02-22 22:55:43 -070014#include <fdt_support.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080015#include <hwconfig.h>
16#include <ahci.h>
Yangbo Luda6121b2015-10-26 19:47:55 +080017#include <mmc.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080018#include <scsi.h>
Shaohui Xie04643262015-10-26 19:47:54 +080019#include <fm_eth.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080020#include <fsl_esdhc.h>
21#include <fsl_ifc.h>
Aneesh Bansalb3e98202015-12-08 13:54:29 +053022#include <fsl_sec.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080023#include "cpld.h"
Zhao Qiang0be9be82016-02-05 10:04:17 +080024#ifdef CONFIG_U_QE
25#include <fsl_qe.h>
26#endif
Hou Zhiqiangf97e6022016-06-28 20:18:17 +080027#include <asm/arch/ppa.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080028
29DECLARE_GLOBAL_DATA_PTR;
30
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000031#ifdef CONFIG_TFABOOT
32struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
33 {
34 "nor",
35 CONFIG_SYS_NOR_CSPR,
36 CONFIG_SYS_NOR_CSPR_EXT,
37 CONFIG_SYS_NOR_AMASK,
38 CONFIG_SYS_NOR_CSOR,
39 {
40 CONFIG_SYS_NOR_FTIM0,
41 CONFIG_SYS_NOR_FTIM1,
42 CONFIG_SYS_NOR_FTIM2,
43 CONFIG_SYS_NOR_FTIM3
44 },
45
46 },
47 {
48 "nand",
49 CONFIG_SYS_NAND_CSPR,
50 CONFIG_SYS_NAND_CSPR_EXT,
51 CONFIG_SYS_NAND_AMASK,
52 CONFIG_SYS_NAND_CSOR,
53 {
54 CONFIG_SYS_NAND_FTIM0,
55 CONFIG_SYS_NAND_FTIM1,
56 CONFIG_SYS_NAND_FTIM2,
57 CONFIG_SYS_NAND_FTIM3
58 },
59 },
60 {
61 "cpld",
62 CONFIG_SYS_CPLD_CSPR,
63 CONFIG_SYS_CPLD_CSPR_EXT,
64 CONFIG_SYS_CPLD_AMASK,
65 CONFIG_SYS_CPLD_CSOR,
66 {
67 CONFIG_SYS_CPLD_FTIM0,
68 CONFIG_SYS_CPLD_FTIM1,
69 CONFIG_SYS_CPLD_FTIM2,
70 CONFIG_SYS_CPLD_FTIM3
71 },
72 }
73};
74
75struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
76 {
77 "nand",
78 CONFIG_SYS_NAND_CSPR,
79 CONFIG_SYS_NAND_CSPR_EXT,
80 CONFIG_SYS_NAND_AMASK,
81 CONFIG_SYS_NAND_CSOR,
82 {
83 CONFIG_SYS_NAND_FTIM0,
84 CONFIG_SYS_NAND_FTIM1,
85 CONFIG_SYS_NAND_FTIM2,
86 CONFIG_SYS_NAND_FTIM3
87 },
88 },
89 {
90 "nor",
91 CONFIG_SYS_NOR_CSPR,
92 CONFIG_SYS_NOR_CSPR_EXT,
93 CONFIG_SYS_NOR_AMASK,
94 CONFIG_SYS_NOR_CSOR,
95 {
96 CONFIG_SYS_NOR_FTIM0,
97 CONFIG_SYS_NOR_FTIM1,
98 CONFIG_SYS_NOR_FTIM2,
99 CONFIG_SYS_NOR_FTIM3
100 },
101 },
102 {
103 "cpld",
104 CONFIG_SYS_CPLD_CSPR,
105 CONFIG_SYS_CPLD_CSPR_EXT,
106 CONFIG_SYS_CPLD_AMASK,
107 CONFIG_SYS_CPLD_CSOR,
108 {
109 CONFIG_SYS_CPLD_FTIM0,
110 CONFIG_SYS_CPLD_FTIM1,
111 CONFIG_SYS_CPLD_FTIM2,
112 CONFIG_SYS_CPLD_FTIM3
113 },
114 }
115};
116
117void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
118{
119 enum boot_src src = get_boot_src();
120
121 if (src == BOOT_SOURCE_IFC_NAND)
122 regs_info->regs = ifc_cfg_nand_boot;
123 else
124 regs_info->regs = ifc_cfg_nor_boot;
125 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
126}
127
128#endif
Sumit Garg2a2857b2017-03-30 09:52:38 +0530129int board_early_init_f(void)
130{
131 fsl_lsch2_early_init_f();
132
133 return 0;
134}
135
136#ifndef CONFIG_SPL_BUILD
137
Mingkai Hueee86ff2015-10-26 19:47:52 +0800138int checkboard(void)
139{
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000140#ifdef CONFIG_TFABOOT
141 enum boot_src src = get_boot_src();
142#endif
Qianyu Gonge54d1342016-04-26 12:51:43 +0800143 static const char *freq[2] = {"100.00MHZ", "156.25MHZ"};
Gong Qianyuf671f6c2015-10-26 19:47:56 +0800144#ifndef CONFIG_SD_BOOT
Mingkai Hueee86ff2015-10-26 19:47:52 +0800145 u8 cfg_rcw_src1, cfg_rcw_src2;
Qianyu Gonge54d1342016-04-26 12:51:43 +0800146 u16 cfg_rcw_src;
Gong Qianyuf671f6c2015-10-26 19:47:56 +0800147#endif
Qianyu Gonge54d1342016-04-26 12:51:43 +0800148 u8 sd1refclk_sel;
Mingkai Hueee86ff2015-10-26 19:47:52 +0800149
150 printf("Board: LS1043ARDB, boot from ");
151
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000152#ifdef CONFIG_TFABOOT
153 if (src == BOOT_SOURCE_SD_MMC)
154 puts("SD\n");
155 else {
156#endif
157
Gong Qianyuf671f6c2015-10-26 19:47:56 +0800158#ifdef CONFIG_SD_BOOT
159 puts("SD\n");
160#else
Mingkai Hueee86ff2015-10-26 19:47:52 +0800161 cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1);
162 cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2);
163 cpld_rev_bit(&cfg_rcw_src1);
164 cfg_rcw_src = cfg_rcw_src1;
165 cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2;
166
167 if (cfg_rcw_src == 0x25)
168 printf("vBank %d\n", CPLD_READ(vbank));
169 else if (cfg_rcw_src == 0x106)
170 puts("NAND\n");
171 else
172 printf("Invalid setting of SW4\n");
Gong Qianyuf671f6c2015-10-26 19:47:56 +0800173#endif
Mingkai Hueee86ff2015-10-26 19:47:52 +0800174
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000175#ifdef CONFIG_TFABOOT
176 }
177#endif
Mingkai Hueee86ff2015-10-26 19:47:52 +0800178 printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver),
179 CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver));
180
181 puts("SERDES Reference Clocks:\n");
182 sd1refclk_sel = CPLD_READ(sd1refclk_sel);
183 printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]);
184
185 return 0;
186}
187
Mingkai Hueee86ff2015-10-26 19:47:52 +0800188int board_init(void)
189{
Shaohui Xie9f4d0112016-04-29 22:07:21 +0800190 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
191
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800192#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
193 erratum_a010315();
194#endif
195
Mingkai Hueee86ff2015-10-26 19:47:52 +0800196#ifdef CONFIG_FSL_IFC
197 init_final_memctl_regs();
198#endif
199
Udit Agarwal22ec2382019-11-07 16:11:32 +0000200#ifdef CONFIG_NXP_ESBC
Sumit Gargf469d272016-09-01 12:56:43 -0400201 /* In case of Secure Boot, the IBR configures the SMMU
202 * to allow only Secure transactions.
203 * SMMU must be reset in bypass mode.
204 * Set the ClientPD bit and Clear the USFCFG Bit
205 */
206 u32 val;
207 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
208 out_le32(SMMU_SCR0, val);
209 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
210 out_le32(SMMU_NSCR0, val);
211#endif
212
213#ifdef CONFIG_FSL_CAAM
214 sec_init();
215#endif
216
Hou Zhiqiangf97e6022016-06-28 20:18:17 +0800217#ifdef CONFIG_FSL_LS_PPA
218 ppa_init();
219#endif
220
Zhao Qiang0be9be82016-02-05 10:04:17 +0800221#ifdef CONFIG_U_QE
222 u_qe_init();
223#endif
Shaohui Xie9f4d0112016-04-29 22:07:21 +0800224 /* invert AQR105 IRQ pins polarity */
225 out_be32(&scfg->intpcr, AQR105_IRQ_MASK);
Zhao Qiang0be9be82016-02-05 10:04:17 +0800226
Mingkai Hueee86ff2015-10-26 19:47:52 +0800227 return 0;
228}
229
230int config_board_mux(void)
231{
Zhao Qiang085d2672016-02-05 10:04:18 +0800232 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
233 u32 usb_pwrfault;
234
Zhao Qiang510e7922016-02-05 10:04:19 +0800235 if (hwconfig("qe-hdlc")) {
236 out_be32(&scfg->rcwpmuxcr0,
237 (in_be32(&scfg->rcwpmuxcr0) & ~0xff00) | 0x6600);
238 printf("Assign to qe-hdlc clk, rcwpmuxcr0=%x\n",
239 in_be32(&scfg->rcwpmuxcr0));
240 } else {
Zhao Qiang085d2672016-02-05 10:04:18 +0800241#ifdef CONFIG_HAS_FSL_XHCI_USB
Zhao Qiang510e7922016-02-05 10:04:19 +0800242 out_be32(&scfg->rcwpmuxcr0, 0x3333);
243 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
244 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
245 SCFG_USBPWRFAULT_USB3_SHIFT) |
246 (SCFG_USBPWRFAULT_DEDICATED <<
247 SCFG_USBPWRFAULT_USB2_SHIFT) |
248 (SCFG_USBPWRFAULT_SHARED <<
249 SCFG_USBPWRFAULT_USB1_SHIFT);
250 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
Zhao Qiang085d2672016-02-05 10:04:18 +0800251#endif
Zhao Qiang510e7922016-02-05 10:04:19 +0800252 }
Mingkai Hueee86ff2015-10-26 19:47:52 +0800253 return 0;
254}
255
256#if defined(CONFIG_MISC_INIT_R)
257int misc_init_r(void)
258{
259 config_board_mux();
Mingkai Hueee86ff2015-10-26 19:47:52 +0800260 return 0;
261}
262#endif
263
Zhao Qiang510e7922016-02-05 10:04:19 +0800264void fdt_del_qe(void *blob)
265{
266 int nodeoff = 0;
267
268 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
269 "fsl,qe")) >= 0) {
270 fdt_del_node(blob, nodeoff);
271 }
272}
273
Mingkai Hueee86ff2015-10-26 19:47:52 +0800274int ft_board_setup(void *blob, bd_t *bd)
275{
Shaohui Xief6c83952015-11-23 15:23:48 +0800276 u64 base[CONFIG_NR_DRAM_BANKS];
277 u64 size[CONFIG_NR_DRAM_BANKS];
278
279 /* fixup DT for the two DDR banks */
280 base[0] = gd->bd->bi_dram[0].start;
281 size[0] = gd->bd->bi_dram[0].size;
282 base[1] = gd->bd->bi_dram[1].start;
283 size[1] = gd->bd->bi_dram[1].size;
284
285 fdt_fixup_memory_banks(blob, base, size, 2);
Mingkai Hueee86ff2015-10-26 19:47:52 +0800286 ft_cpu_setup(blob, bd);
287
Shaohui Xie04643262015-10-26 19:47:54 +0800288#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300289#ifndef CONFIG_DM_ETH
Shaohui Xie04643262015-10-26 19:47:54 +0800290 fdt_fixup_fman_ethernet(blob);
291#endif
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300292#endif
Zhao Qiang510e7922016-02-05 10:04:19 +0800293
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300294 fdt_fixup_icid(blob);
295
Zhao Qiang510e7922016-02-05 10:04:19 +0800296 /*
297 * qe-hdlc and usb multi-use the pins,
298 * when set hwconfig to qe-hdlc, delete usb node.
299 */
300 if (hwconfig("qe-hdlc"))
301#ifdef CONFIG_HAS_FSL_XHCI_USB
302 fdt_del_node_and_alias(blob, "usb1");
303#endif
304 /*
305 * qe just support qe-uart and qe-hdlc,
306 * if qe-uart and qe-hdlc are not set in hwconfig,
307 * delete qe node.
308 */
309 if (!hwconfig("qe-uart") && !hwconfig("qe-hdlc"))
310 fdt_del_qe(blob);
311
Mingkai Hueee86ff2015-10-26 19:47:52 +0800312 return 0;
313}
314
315u8 flash_read8(void *addr)
316{
317 return __raw_readb(addr + 1);
318}
319
320void flash_write16(u16 val, void *addr)
321{
322 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
323
324 __raw_writew(shftval, addr);
325}
326
327u16 flash_read16(void *addr)
328{
329 u16 val = __raw_readw(addr);
330
331 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
332}
Sumit Garg2a2857b2017-03-30 09:52:38 +0530333
334#endif