blob: 7df12550868696191d20c9a6b54bb05edb7b0de6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shaohui Xie085ac1c2016-09-07 17:56:14 +08002/*
3 * Copyright 2016 Freescale Semiconductor, Inc.
Gaurav Jain476c6392022-03-24 11:50:35 +05304 * Copyright 2019-2021 NXP
Shaohui Xie085ac1c2016-09-07 17:56:14 +08005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
Tom Rini8c70baa2021-12-14 13:36:40 -05008#include <clock_legacy.h>
Shaohui Xie085ac1c2016-09-07 17:56:14 +08009#include <i2c.h>
10#include <fdt_support.h>
Simon Glass0e0ac202017-04-06 12:47:04 -060011#include <fsl_ddr_sdram.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Shaohui Xie085ac1c2016-09-07 17:56:14 +080014#include <asm/io.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/fsl_serdes.h>
17#include <asm/arch/fdt.h>
York Sun729f2d12017-03-06 09:02:34 -080018#include <asm/arch/mmu.h>
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000019#include <asm/arch/cpu.h>
Shaohui Xie085ac1c2016-09-07 17:56:14 +080020#include <asm/arch/soc.h>
Laurentiu Tudor512d13e2018-08-09 15:19:46 +030021#include <asm/arch-fsl-layerscape/fsl_icid.h>
Shaohui Xie085ac1c2016-09-07 17:56:14 +080022#include <ahci.h>
23#include <hwconfig.h>
24#include <mmc.h>
25#include <scsi.h>
26#include <fm_eth.h>
27#include <fsl_csu.h>
28#include <fsl_esdhc.h>
29#include <fsl_ifc.h>
30#include <spl.h>
Stephen Carlson6fa03882021-06-22 16:40:27 -070031#include "../common/i2c_mux.h"
Shaohui Xie085ac1c2016-09-07 17:56:14 +080032
33#include "../common/vid.h"
34#include "../common/qixis.h"
35#include "ls1046aqds_qixis.h"
36
37DECLARE_GLOBAL_DATA_PTR;
38
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000039#ifdef CONFIG_TFABOOT
40struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
41 {
42 "nor0",
Tom Rini6a5dccc2022-11-16 13:10:41 -050043 CFG_SYS_NOR0_CSPR,
44 CFG_SYS_NOR0_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -050045 CFG_SYS_NOR_AMASK,
46 CFG_SYS_NOR_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000047 {
Tom Rini7b577ba2022-11-16 13:10:25 -050048 CFG_SYS_NOR_FTIM0,
49 CFG_SYS_NOR_FTIM1,
50 CFG_SYS_NOR_FTIM2,
51 CFG_SYS_NOR_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000052 },
53
54 },
55 {
56 "nor1",
Tom Rini6a5dccc2022-11-16 13:10:41 -050057 CFG_SYS_NOR1_CSPR,
58 CFG_SYS_NOR1_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -050059 CFG_SYS_NOR_AMASK,
60 CFG_SYS_NOR_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000061 {
Tom Rini7b577ba2022-11-16 13:10:25 -050062 CFG_SYS_NOR_FTIM0,
63 CFG_SYS_NOR_FTIM1,
64 CFG_SYS_NOR_FTIM2,
65 CFG_SYS_NOR_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000066 },
67 },
68 {
69 "nand",
Tom Rinib4213492022-11-12 17:36:51 -050070 CFG_SYS_NAND_CSPR,
71 CFG_SYS_NAND_CSPR_EXT,
72 CFG_SYS_NAND_AMASK,
73 CFG_SYS_NAND_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000074 {
Tom Rinib4213492022-11-12 17:36:51 -050075 CFG_SYS_NAND_FTIM0,
76 CFG_SYS_NAND_FTIM1,
77 CFG_SYS_NAND_FTIM2,
78 CFG_SYS_NAND_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000079 },
80 },
81 {
82 "fpga",
Tom Rini6a5dccc2022-11-16 13:10:41 -050083 CFG_SYS_FPGA_CSPR,
84 CFG_SYS_FPGA_CSPR_EXT,
85 CFG_SYS_FPGA_AMASK,
86 CFG_SYS_FPGA_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000087 {
Tom Rini6a5dccc2022-11-16 13:10:41 -050088 CFG_SYS_FPGA_FTIM0,
89 CFG_SYS_FPGA_FTIM1,
90 CFG_SYS_FPGA_FTIM2,
91 CFG_SYS_FPGA_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +000092 },
93 }
94};
95
96struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
97 {
98 "nand",
Tom Rinib4213492022-11-12 17:36:51 -050099 CFG_SYS_NAND_CSPR,
100 CFG_SYS_NAND_CSPR_EXT,
101 CFG_SYS_NAND_AMASK,
102 CFG_SYS_NAND_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000103 {
Tom Rinib4213492022-11-12 17:36:51 -0500104 CFG_SYS_NAND_FTIM0,
105 CFG_SYS_NAND_FTIM1,
106 CFG_SYS_NAND_FTIM2,
107 CFG_SYS_NAND_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000108 },
109 },
110 {
111 "nor0",
Tom Rini6a5dccc2022-11-16 13:10:41 -0500112 CFG_SYS_NOR0_CSPR,
113 CFG_SYS_NOR0_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -0500114 CFG_SYS_NOR_AMASK,
115 CFG_SYS_NOR_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000116 {
Tom Rini7b577ba2022-11-16 13:10:25 -0500117 CFG_SYS_NOR_FTIM0,
118 CFG_SYS_NOR_FTIM1,
119 CFG_SYS_NOR_FTIM2,
120 CFG_SYS_NOR_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000121 },
122 },
123 {
124 "nor1",
Tom Rini6a5dccc2022-11-16 13:10:41 -0500125 CFG_SYS_NOR1_CSPR,
126 CFG_SYS_NOR1_CSPR_EXT,
Tom Rini7b577ba2022-11-16 13:10:25 -0500127 CFG_SYS_NOR_AMASK,
128 CFG_SYS_NOR_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000129 {
Tom Rini7b577ba2022-11-16 13:10:25 -0500130 CFG_SYS_NOR_FTIM0,
131 CFG_SYS_NOR_FTIM1,
132 CFG_SYS_NOR_FTIM2,
133 CFG_SYS_NOR_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000134 },
135 },
136 {
137 "fpga",
Tom Rini6a5dccc2022-11-16 13:10:41 -0500138 CFG_SYS_FPGA_CSPR,
139 CFG_SYS_FPGA_CSPR_EXT,
140 CFG_SYS_FPGA_AMASK,
141 CFG_SYS_FPGA_CSOR,
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000142 {
Tom Rini6a5dccc2022-11-16 13:10:41 -0500143 CFG_SYS_FPGA_FTIM0,
144 CFG_SYS_FPGA_FTIM1,
145 CFG_SYS_FPGA_FTIM2,
146 CFG_SYS_FPGA_FTIM3
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000147 },
148 }
149};
150
151void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
152{
153 enum boot_src src = get_boot_src();
154
155 if (src == BOOT_SOURCE_IFC_NAND)
156 regs_info->regs = ifc_cfg_nand_boot;
157 else
158 regs_info->regs = ifc_cfg_nor_boot;
159 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
160}
161
162#endif
163
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800164enum {
165 MUX_TYPE_GPIO,
166};
167
168int checkboard(void)
169{
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000170#ifdef CONFIG_TFABOOT
171 enum boot_src src = get_boot_src();
172#endif
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800173 char buf[64];
174#ifndef CONFIG_SD_BOOT
175 u8 sw;
176#endif
177
178 puts("Board: LS1046AQDS, boot from ");
179
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000180#ifdef CONFIG_TFABOOT
181 if (src == BOOT_SOURCE_SD_MMC)
182 puts("SD\n");
183 else {
184#endif
185
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800186#ifdef CONFIG_SD_BOOT
187 puts("SD\n");
188#else
189 sw = QIXIS_READ(brdcfg[0]);
190 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
191
192 if (sw < 0x8)
193 printf("vBank: %d\n", sw);
194 else if (sw == 0x8)
195 puts("PromJet\n");
196 else if (sw == 0x9)
197 puts("NAND\n");
198 else if (sw == 0xF)
199 printf("QSPI\n");
200 else
201 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
202#endif
203
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000204#ifdef CONFIG_TFABOOT
205 }
206#endif
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800207 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
208 QIXIS_READ(id), QIXIS_READ(arch));
209
210 printf("FPGA: v%d (%s), build %d\n",
211 (int)QIXIS_READ(scver), qixis_read_tag(buf),
212 (int)qixis_read_minor());
213
214 return 0;
215}
216
217bool if_board_diff_clk(void)
218{
219 u8 diff_conf = QIXIS_READ(brdcfg[11]);
220
221 return diff_conf & 0x40;
222}
223
224unsigned long get_board_sys_clk(void)
225{
226 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
227
228 switch (sysclk_conf & 0x0f) {
229 case QIXIS_SYSCLK_64:
230 return 64000000;
231 case QIXIS_SYSCLK_83:
232 return 83333333;
233 case QIXIS_SYSCLK_100:
234 return 100000000;
235 case QIXIS_SYSCLK_125:
236 return 125000000;
237 case QIXIS_SYSCLK_133:
238 return 133333333;
239 case QIXIS_SYSCLK_150:
240 return 150000000;
241 case QIXIS_SYSCLK_160:
242 return 160000000;
243 case QIXIS_SYSCLK_166:
244 return 166666666;
245 }
246
247 return 66666666;
248}
249
250unsigned long get_board_ddr_clk(void)
251{
252 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
253
254 if (if_board_diff_clk())
255 return get_board_sys_clk();
256 switch ((ddrclk_conf & 0x30) >> 4) {
257 case QIXIS_DDRCLK_100:
258 return 100000000;
259 case QIXIS_DDRCLK_125:
260 return 125000000;
261 case QIXIS_DDRCLK_133:
262 return 133333333;
263 }
264
265 return 66666666;
266}
267
Shaohui Xie56007a02016-10-28 14:24:02 +0800268#ifdef CONFIG_LPUART
269u32 get_lpuart_clk(void)
270{
271 return gd->bus_clk;
272}
273#endif
274
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800275int dram_init(void)
276{
277 /*
278 * When resuming from deep sleep, the I2C channel may not be
279 * in the default channel. So, switch to the default channel
280 * before accessing DDR SPD.
Biwen Lif0018f52020-02-05 22:02:17 +0800281 *
282 * PCA9547 mount on I2C1 bus
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800283 */
Biwen Lif0018f52020-02-05 22:02:17 +0800284 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Simon Glass0e0ac202017-04-06 12:47:04 -0600285 fsl_initdram();
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000286#if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
Simon Glass49c24a82024-09-29 19:49:47 -0600287 defined(CONFIG_XPL_BUILD)
York Sun729f2d12017-03-06 09:02:34 -0800288 /* This will break-before-make MMU for DDR */
289 update_early_mmu_table();
290#endif
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800291
292 return 0;
293}
294
295int i2c_multiplexer_select_vid_channel(u8 channel)
296{
Biwen Lif0018f52020-02-05 22:02:17 +0800297 return select_i2c_ch_pca9547(channel, 0);
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800298}
299
300int board_early_init_f(void)
301{
Tom Rini376b88a2022-10-28 20:27:13 -0400302 u32 __iomem *cntcr = (u32 *)CFG_SYS_FSL_TIMER_ADDR;
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800303#ifdef CONFIG_HAS_FSL_XHCI_USB
Tom Rini376b88a2022-10-28 20:27:13 -0400304 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_FSL_SCFG_ADDR;
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800305 u32 usb_pwrfault;
306#endif
Shaohui Xie56007a02016-10-28 14:24:02 +0800307#ifdef CONFIG_LPUART
308 u8 uart;
309#endif
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800310
Biwen Liffd5a3c2020-07-02 11:13:01 +0800311 /*
312 * Enable secure system counter for timer
313 */
314 out_le32(cntcr, 0x1);
315
Tom Rini714482a2021-08-18 23:12:25 -0400316#if defined(CONFIG_SYS_I2C_EARLY_INIT)
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800317 i2c_early_init_f();
318#endif
319 fsl_lsch2_early_init_f();
320
321#ifdef CONFIG_HAS_FSL_XHCI_USB
322 out_be32(&scfg->rcwpmuxcr0, 0x3333);
323 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
324 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
325 SCFG_USBPWRFAULT_USB3_SHIFT) |
326 (SCFG_USBPWRFAULT_DEDICATED <<
327 SCFG_USBPWRFAULT_USB2_SHIFT) |
328 (SCFG_USBPWRFAULT_SHARED <<
329 SCFG_USBPWRFAULT_USB1_SHIFT);
330 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
331#endif
332
Shaohui Xie56007a02016-10-28 14:24:02 +0800333#ifdef CONFIG_LPUART
334 /* We use lpuart0 as system console */
335 uart = QIXIS_READ(brdcfg[14]);
336 uart &= ~CFG_UART_MUX_MASK;
337 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
338 QIXIS_WRITE(brdcfg[14], uart);
339#endif
340
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800341 return 0;
342}
343
344#ifdef CONFIG_FSL_DEEP_SLEEP
345/* determine if it is a warm boot */
346bool is_warm_boot(void)
347{
348#define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
Tom Rini376b88a2022-10-28 20:27:13 -0400349 struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800350
351 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
352 return 1;
353
354 return 0;
355}
356#endif
357
358int config_board_mux(int ctrl_type)
359{
360 u8 reg14;
361
362 reg14 = QIXIS_READ(brdcfg[14]);
363
364 switch (ctrl_type) {
365 case MUX_TYPE_GPIO:
366 reg14 = (reg14 & (~0x6)) | 0x2;
367 break;
368 default:
369 puts("Unsupported mux interface type\n");
370 return -1;
371 }
372
373 QIXIS_WRITE(brdcfg[14], reg14);
374
375 return 0;
376}
377
378int config_serdes_mux(void)
379{
380 return 0;
381}
382
383#ifdef CONFIG_MISC_INIT_R
384int misc_init_r(void)
385{
386 if (hwconfig("gpio"))
387 config_board_mux(MUX_TYPE_GPIO);
388
389 return 0;
390}
391#endif
392
393int board_init(void)
394{
Biwen Lif0018f52020-02-05 22:02:17 +0800395 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800396
Tom Rini376b88a2022-10-28 20:27:13 -0400397#ifdef CFG_SYS_FSL_SERDES
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800398 config_serdes_mux();
399#endif
400
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800401 if (adjust_vdd(0))
402 printf("Warning: Adjusting core voltage failed.\n");
403
Udit Agarwal22ec2382019-11-07 16:11:32 +0000404#ifdef CONFIG_NXP_ESBC
Sumit Gargca697012017-03-23 13:48:17 +0530405 /*
406 * In case of Secure Boot, the IBR configures the SMMU
407 * to allow only Secure transactions.
408 * SMMU must be reset in bypass mode.
409 * Set the ClientPD bit and Clear the USFCFG Bit
410 */
411 u32 val;
412 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
413 out_le32(SMMU_SCR0, val);
414 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
415 out_le32(SMMU_NSCR0, val);
416#endif
417
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800418 return 0;
419}
420
421#ifdef CONFIG_OF_BOARD_SETUP
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900422int ft_board_setup(void *blob, struct bd_info *bd)
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800423{
424 u64 base[CONFIG_NR_DRAM_BANKS];
425 u64 size[CONFIG_NR_DRAM_BANKS];
426 u8 reg;
427
428 /* fixup DT for the two DDR banks */
429 base[0] = gd->bd->bi_dram[0].start;
430 size[0] = gd->bd->bi_dram[0].size;
431 base[1] = gd->bd->bi_dram[1].start;
432 size[1] = gd->bd->bi_dram[1].size;
433
434 fdt_fixup_memory_banks(blob, base, size, 2);
435 ft_cpu_setup(blob, bd);
436
Tom Rini78064072022-08-09 10:16:22 -0400437#ifdef CONFIG_FMAN_ENET
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800438 fdt_fixup_board_enet(blob);
439#endif
440
Laurentiu Tudor512d13e2018-08-09 15:19:46 +0300441 fdt_fixup_icid(blob);
442
Shaohui Xie085ac1c2016-09-07 17:56:14 +0800443 reg = QIXIS_READ(brdcfg[0]);
444 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
445
446 /* Disable IFC if QSPI is enabled */
447 if (reg == 0xF)
448 do_fixup_by_compat(blob, "fsl,ifc",
449 "status", "disabled", 8 + 1, 1);
450
451 return 0;
452}
453#endif
454
455u8 flash_read8(void *addr)
456{
457 return __raw_readb(addr + 1);
458}
459
460void flash_write16(u16 val, void *addr)
461{
462 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
463
464 __raw_writew(shftval, addr);
465}
466
467u16 flash_read16(void *addr)
468{
469 u16 val = __raw_readw(addr);
470
471 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
472}
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000473
Tom Rini0543c432019-11-18 20:02:08 -0500474#if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000475void *env_sf_get_env_addr(void)
476{
Tom Rini376b88a2022-10-28 20:27:13 -0400477 return (void *)(CFG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);
Rajesh Bhagat9af0a0b2018-11-05 18:02:40 +0000478}
479#endif