blob: 18869d8c1df579e2a62be3855e272125c3a75a3a [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.
Camelia Grozaa1c46992022-07-28 17:28:11 +03004 * Copyright 2021-2022 NXP
Mingkai Hueee86ff2015-10-26 19:47:52 +08005 */
6
7#include <common.h>
8#include <i2c.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080011#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/fsl_serdes.h>
14#include <asm/arch/soc.h>
Laurentiu Tudor22012d52018-08-27 17:33:59 +030015#include <asm/arch-fsl-layerscape/fsl_icid.h>
Simon Glasse3ee2fb2016-02-22 22:55:43 -070016#include <fdt_support.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080017#include <hwconfig.h>
18#include <ahci.h>
Yangbo Luda6121b2015-10-26 19:47:55 +080019#include <mmc.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080020#include <scsi.h>
Shaohui Xie04643262015-10-26 19:47:54 +080021#include <fm_eth.h>
Mingkai Hueee86ff2015-10-26 19:47:52 +080022#include <fsl_esdhc.h>
23#include <fsl_ifc.h>
24#include "cpld.h"
Zhao Qiang0be9be82016-02-05 10:04:17 +080025#ifdef CONFIG_U_QE
26#include <fsl_qe.h>
27#endif
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",
Tom Rini7b577ba2022-11-16 13:10:25 -050035 CFG_SYS_NOR_CSPR,
36 CFG_SYS_NOR_CSPR_EXT,
37 CFG_SYS_NOR_AMASK,
38 CFG_SYS_NOR_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000039 {
Tom Rini7b577ba2022-11-16 13:10:25 -050040 CFG_SYS_NOR_FTIM0,
41 CFG_SYS_NOR_FTIM1,
42 CFG_SYS_NOR_FTIM2,
43 CFG_SYS_NOR_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000044 },
45
46 },
47 {
48 "nand",
Tom Rinib4213492022-11-12 17:36:51 -050049 CFG_SYS_NAND_CSPR,
50 CFG_SYS_NAND_CSPR_EXT,
51 CFG_SYS_NAND_AMASK,
52 CFG_SYS_NAND_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000053 {
Tom Rinib4213492022-11-12 17:36:51 -050054 CFG_SYS_NAND_FTIM0,
55 CFG_SYS_NAND_FTIM1,
56 CFG_SYS_NAND_FTIM2,
57 CFG_SYS_NAND_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000058 },
59 },
60 {
61 "cpld",
Tom Rini6a5dccc2022-11-16 13:10:41 -050062 CFG_SYS_CPLD_CSPR,
63 CFG_SYS_CPLD_CSPR_EXT,
64 CFG_SYS_CPLD_AMASK,
65 CFG_SYS_CPLD_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000066 {
Tom Rini6a5dccc2022-11-16 13:10:41 -050067 CFG_SYS_CPLD_FTIM0,
68 CFG_SYS_CPLD_FTIM1,
69 CFG_SYS_CPLD_FTIM2,
70 CFG_SYS_CPLD_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000071 },
72 }
73};
74
75struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
76 {
77 "nand",
Tom Rinib4213492022-11-12 17:36:51 -050078 CFG_SYS_NAND_CSPR,
79 CFG_SYS_NAND_CSPR_EXT,
80 CFG_SYS_NAND_AMASK,
81 CFG_SYS_NAND_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000082 {
Tom Rinib4213492022-11-12 17:36:51 -050083 CFG_SYS_NAND_FTIM0,
84 CFG_SYS_NAND_FTIM1,
85 CFG_SYS_NAND_FTIM2,
86 CFG_SYS_NAND_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000087 },
88 },
89 {
90 "nor",
Tom Rini7b577ba2022-11-16 13:10:25 -050091 CFG_SYS_NOR_CSPR,
92 CFG_SYS_NOR_CSPR_EXT,
93 CFG_SYS_NOR_AMASK,
94 CFG_SYS_NOR_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +000095 {
Tom Rini7b577ba2022-11-16 13:10:25 -050096 CFG_SYS_NOR_FTIM0,
97 CFG_SYS_NOR_FTIM1,
98 CFG_SYS_NOR_FTIM2,
99 CFG_SYS_NOR_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000100 },
101 },
102 {
103 "cpld",
Tom Rini6a5dccc2022-11-16 13:10:41 -0500104 CFG_SYS_CPLD_CSPR,
105 CFG_SYS_CPLD_CSPR_EXT,
106 CFG_SYS_CPLD_AMASK,
107 CFG_SYS_CPLD_CSOR,
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000108 {
Tom Rini6a5dccc2022-11-16 13:10:41 -0500109 CFG_SYS_CPLD_FTIM0,
110 CFG_SYS_CPLD_FTIM1,
111 CFG_SYS_CPLD_FTIM2,
112 CFG_SYS_CPLD_FTIM3
Rajesh Bhagatb89aed42018-11-05 18:02:44 +0000113 },
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));
Wei Lu795e8062022-09-26 16:18:49 +0800169 else if ((cfg_rcw_src == 0x106) || (cfg_rcw_src == 0x118))
Mingkai Hueee86ff2015-10-26 19:47:52 +0800170 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{
Tom Rini376b88a2022-10-28 20:27:13 -0400190 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
Shaohui Xie9f4d0112016-04-29 22:07:21 +0800191
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
Martin Schiller532d3212021-11-23 07:28:00 +0100213#if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
214 pci_init();
215#endif
216
Zhao Qiang0be9be82016-02-05 10:04:17 +0800217#ifdef CONFIG_U_QE
218 u_qe_init();
219#endif
Shaohui Xie9f4d0112016-04-29 22:07:21 +0800220 /* invert AQR105 IRQ pins polarity */
221 out_be32(&scfg->intpcr, AQR105_IRQ_MASK);
Zhao Qiang0be9be82016-02-05 10:04:17 +0800222
Mingkai Hueee86ff2015-10-26 19:47:52 +0800223 return 0;
224}
225
226int config_board_mux(void)
227{
Tom Rini376b88a2022-10-28 20:27:13 -0400228 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
Zhao Qiang085d2672016-02-05 10:04:18 +0800229 u32 usb_pwrfault;
230
Zhao Qiang510e7922016-02-05 10:04:19 +0800231 if (hwconfig("qe-hdlc")) {
232 out_be32(&scfg->rcwpmuxcr0,
233 (in_be32(&scfg->rcwpmuxcr0) & ~0xff00) | 0x6600);
234 printf("Assign to qe-hdlc clk, rcwpmuxcr0=%x\n",
235 in_be32(&scfg->rcwpmuxcr0));
236 } else {
Zhao Qiang085d2672016-02-05 10:04:18 +0800237#ifdef CONFIG_HAS_FSL_XHCI_USB
Zhao Qiang510e7922016-02-05 10:04:19 +0800238 out_be32(&scfg->rcwpmuxcr0, 0x3333);
239 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
240 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
241 SCFG_USBPWRFAULT_USB3_SHIFT) |
242 (SCFG_USBPWRFAULT_DEDICATED <<
243 SCFG_USBPWRFAULT_USB2_SHIFT) |
244 (SCFG_USBPWRFAULT_SHARED <<
245 SCFG_USBPWRFAULT_USB1_SHIFT);
246 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
Zhao Qiang085d2672016-02-05 10:04:18 +0800247#endif
Zhao Qiang510e7922016-02-05 10:04:19 +0800248 }
Mingkai Hueee86ff2015-10-26 19:47:52 +0800249 return 0;
250}
251
252#if defined(CONFIG_MISC_INIT_R)
253int misc_init_r(void)
254{
255 config_board_mux();
Mingkai Hueee86ff2015-10-26 19:47:52 +0800256 return 0;
257}
258#endif
259
Zhao Qiang510e7922016-02-05 10:04:19 +0800260void fdt_del_qe(void *blob)
261{
262 int nodeoff = 0;
263
264 while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
265 "fsl,qe")) >= 0) {
266 fdt_del_node(blob, nodeoff);
267 }
268}
269
Camelia Grozaa1c46992022-07-28 17:28:11 +0300270/* Update the address of the Aquantia PHY on the MDIO bus for boards revision
271 * v7.0 and up. Also rename the PHY node to align with the address change.
272 */
273void fdt_fixup_phy_addr(void *blob)
274{
275 const char phy_path[] =
276 "/soc/fman@1a00000/mdio@fd000/ethernet-phy@1";
277 int ret, offset, new_addr = AQR113C_PHY_ADDR;
278 char new_name[] = "ethernet-phy@00";
279
280 if (CPLD_READ(pcba_ver) < 0x7)
281 return;
282
283 offset = fdt_path_offset(blob, phy_path);
284 if (offset < 0) {
285 printf("ethernet-phy@1 node not found in the dts\n");
286 return;
287 }
288
289 ret = fdt_setprop_u32(blob, offset, "reg", new_addr);
290 if (ret < 0) {
291 printf("Unable to set 'reg' for node ethernet-phy@1: %s\n",
292 fdt_strerror(ret));
293 return;
294 }
295
296 sprintf(new_name, "ethernet-phy@%x", new_addr);
297 ret = fdt_set_name(blob, offset, new_name);
298 if (ret < 0)
299 printf("Unable to rename node ethernet-phy@1: %s\n",
300 fdt_strerror(ret));
301}
302
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900303int ft_board_setup(void *blob, struct bd_info *bd)
Mingkai Hueee86ff2015-10-26 19:47:52 +0800304{
Shaohui Xief6c83952015-11-23 15:23:48 +0800305 u64 base[CONFIG_NR_DRAM_BANKS];
306 u64 size[CONFIG_NR_DRAM_BANKS];
307
308 /* fixup DT for the two DDR banks */
309 base[0] = gd->bd->bi_dram[0].start;
310 size[0] = gd->bd->bi_dram[0].size;
311 base[1] = gd->bd->bi_dram[1].start;
312 size[1] = gd->bd->bi_dram[1].size;
313
314 fdt_fixup_memory_banks(blob, base, size, 2);
Mingkai Hueee86ff2015-10-26 19:47:52 +0800315 ft_cpu_setup(blob, bd);
316
Shaohui Xie04643262015-10-26 19:47:54 +0800317#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300318#ifndef CONFIG_DM_ETH
Shaohui Xie04643262015-10-26 19:47:54 +0800319 fdt_fixup_fman_ethernet(blob);
320#endif
Camelia Grozaa1c46992022-07-28 17:28:11 +0300321 fdt_fixup_phy_addr(blob);
Madalin Bucurb76b0a62020-04-23 16:25:19 +0300322#endif
Zhao Qiang510e7922016-02-05 10:04:19 +0800323
Laurentiu Tudor22012d52018-08-27 17:33:59 +0300324 fdt_fixup_icid(blob);
325
Zhao Qiang510e7922016-02-05 10:04:19 +0800326 /*
327 * qe-hdlc and usb multi-use the pins,
328 * when set hwconfig to qe-hdlc, delete usb node.
329 */
330 if (hwconfig("qe-hdlc"))
331#ifdef CONFIG_HAS_FSL_XHCI_USB
332 fdt_del_node_and_alias(blob, "usb1");
333#endif
334 /*
335 * qe just support qe-uart and qe-hdlc,
336 * if qe-uart and qe-hdlc are not set in hwconfig,
337 * delete qe node.
338 */
339 if (!hwconfig("qe-uart") && !hwconfig("qe-hdlc"))
340 fdt_del_qe(blob);
341
Mingkai Hueee86ff2015-10-26 19:47:52 +0800342 return 0;
343}
344
Wei Lu795e8062022-09-26 16:18:49 +0800345void nand_fixup(void)
346{
347 u32 csor = 0;
348
349 if (CPLD_READ(pcba_ver) < 0x7)
350 return;
351
352 /* Change NAND Flash PGS/SPRZ configuration */
Tom Rinib4213492022-11-12 17:36:51 -0500353 csor = CFG_SYS_NAND_CSOR;
Wei Lu795e8062022-09-26 16:18:49 +0800354 if ((csor & CSOR_NAND_PGS_MASK) == CSOR_NAND_PGS_2K)
355 csor = (csor & ~(CSOR_NAND_PGS_MASK)) | CSOR_NAND_PGS_4K;
356
357 if ((csor & CSOR_NAND_SPRZ_MASK) == CSOR_NAND_SPRZ_64)
358 csor = (csor & ~(CSOR_NAND_SPRZ_MASK)) | CSOR_NAND_SPRZ_224;
359
360 if (IS_ENABLED(CONFIG_TFABOOT)) {
361 u8 cfg_rcw_src1, cfg_rcw_src2;
362 u16 cfg_rcw_src;
363
364 cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1);
365 cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2);
366 cpld_rev_bit(&cfg_rcw_src1);
367 cfg_rcw_src = cfg_rcw_src1;
368 cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2;
369
370 if (cfg_rcw_src == 0x25)
371 set_ifc_csor(IFC_CS1, csor);
372 else if (cfg_rcw_src == 0x118)
373 set_ifc_csor(IFC_CS0, csor);
374 else
375 printf("Invalid setting\n");
376 } else {
377 if (IS_ENABLED(CONFIG_NAND_BOOT))
378 set_ifc_csor(IFC_CS0, csor);
379 else
380 set_ifc_csor(IFC_CS1, csor);
381 }
382}
383
Camelia Grozaa1c46992022-07-28 17:28:11 +0300384#if IS_ENABLED(CONFIG_OF_BOARD_FIXUP)
385int board_fix_fdt(void *blob)
386{
Wei Lu795e8062022-09-26 16:18:49 +0800387 /* nand driver fix up */
388 nand_fixup();
389
390 /* fdt fix up */
Camelia Grozaa1c46992022-07-28 17:28:11 +0300391 fdt_fixup_phy_addr(blob);
Wei Lu795e8062022-09-26 16:18:49 +0800392
Camelia Grozaa1c46992022-07-28 17:28:11 +0300393 return 0;
394}
395#endif
396
Mingkai Hueee86ff2015-10-26 19:47:52 +0800397u8 flash_read8(void *addr)
398{
399 return __raw_readb(addr + 1);
400}
401
402void flash_write16(u16 val, void *addr)
403{
404 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
405
406 __raw_writew(shftval, addr);
407}
408
409u16 flash_read16(void *addr)
410{
411 u16 val = __raw_readw(addr);
412
413 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
414}
Sumit Garg2a2857b2017-03-30 09:52:38 +0530415
416#endif