1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
4 * Copyright 2019-2020 NXP
8 #include <clock_legacy.h>
10 #include <fdt_support.h>
11 #include <fsl_ddr_sdram.h>
13 #include <asm/global_data.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/fsl_serdes.h>
17 #include <asm/arch/ppa.h>
18 #include <asm/arch/fdt.h>
19 #include <asm/arch/mmu.h>
20 #include <asm/arch/cpu.h>
21 #include <asm/arch/soc.h>
22 #include <asm/arch-fsl-layerscape/fsl_icid.h>
29 #include <fsl_esdhc.h>
33 #include "../common/i2c_mux.h"
35 #include "../common/vid.h"
36 #include "../common/qixis.h"
37 #include "ls1046aqds_qixis.h"
39 DECLARE_GLOBAL_DATA_PTR;
42 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
46 CONFIG_SYS_NOR0_CSPR_EXT,
60 CONFIG_SYS_NOR1_CSPR_EXT,
73 CONFIG_SYS_NAND_CSPR_EXT,
74 CONFIG_SYS_NAND_AMASK,
77 CONFIG_SYS_NAND_FTIM0,
78 CONFIG_SYS_NAND_FTIM1,
79 CONFIG_SYS_NAND_FTIM2,
86 CONFIG_SYS_FPGA_CSPR_EXT,
87 CONFIG_SYS_FPGA_AMASK,
90 CONFIG_SYS_FPGA_FTIM0,
91 CONFIG_SYS_FPGA_FTIM1,
92 CONFIG_SYS_FPGA_FTIM2,
98 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
101 CONFIG_SYS_NAND_CSPR,
102 CONFIG_SYS_NAND_CSPR_EXT,
103 CONFIG_SYS_NAND_AMASK,
104 CONFIG_SYS_NAND_CSOR,
106 CONFIG_SYS_NAND_FTIM0,
107 CONFIG_SYS_NAND_FTIM1,
108 CONFIG_SYS_NAND_FTIM2,
109 CONFIG_SYS_NAND_FTIM3
114 CONFIG_SYS_NOR0_CSPR,
115 CONFIG_SYS_NOR0_CSPR_EXT,
116 CONFIG_SYS_NOR_AMASK,
119 CONFIG_SYS_NOR_FTIM0,
120 CONFIG_SYS_NOR_FTIM1,
121 CONFIG_SYS_NOR_FTIM2,
127 CONFIG_SYS_NOR1_CSPR,
128 CONFIG_SYS_NOR1_CSPR_EXT,
129 CONFIG_SYS_NOR_AMASK,
132 CONFIG_SYS_NOR_FTIM0,
133 CONFIG_SYS_NOR_FTIM1,
134 CONFIG_SYS_NOR_FTIM2,
140 CONFIG_SYS_FPGA_CSPR,
141 CONFIG_SYS_FPGA_CSPR_EXT,
142 CONFIG_SYS_FPGA_AMASK,
143 CONFIG_SYS_FPGA_CSOR,
145 CONFIG_SYS_FPGA_FTIM0,
146 CONFIG_SYS_FPGA_FTIM1,
147 CONFIG_SYS_FPGA_FTIM2,
148 CONFIG_SYS_FPGA_FTIM3
153 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
155 enum boot_src src = get_boot_src();
157 if (src == BOOT_SOURCE_IFC_NAND)
158 regs_info->regs = ifc_cfg_nand_boot;
160 regs_info->regs = ifc_cfg_nor_boot;
161 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
172 #ifdef CONFIG_TFABOOT
173 enum boot_src src = get_boot_src();
176 #ifndef CONFIG_SD_BOOT
180 puts("Board: LS1046AQDS, boot from ");
182 #ifdef CONFIG_TFABOOT
183 if (src == BOOT_SOURCE_SD_MMC)
188 #ifdef CONFIG_SD_BOOT
191 sw = QIXIS_READ(brdcfg[0]);
192 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
195 printf("vBank: %d\n", sw);
203 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
206 #ifdef CONFIG_TFABOOT
209 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
210 QIXIS_READ(id), QIXIS_READ(arch));
212 printf("FPGA: v%d (%s), build %d\n",
213 (int)QIXIS_READ(scver), qixis_read_tag(buf),
214 (int)qixis_read_minor());
219 bool if_board_diff_clk(void)
221 u8 diff_conf = QIXIS_READ(brdcfg[11]);
223 return diff_conf & 0x40;
226 unsigned long get_board_sys_clk(void)
228 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
230 switch (sysclk_conf & 0x0f) {
231 case QIXIS_SYSCLK_64:
233 case QIXIS_SYSCLK_83:
235 case QIXIS_SYSCLK_100:
237 case QIXIS_SYSCLK_125:
239 case QIXIS_SYSCLK_133:
241 case QIXIS_SYSCLK_150:
243 case QIXIS_SYSCLK_160:
245 case QIXIS_SYSCLK_166:
252 unsigned long get_board_ddr_clk(void)
254 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
256 if (if_board_diff_clk())
257 return get_board_sys_clk();
258 switch ((ddrclk_conf & 0x30) >> 4) {
259 case QIXIS_DDRCLK_100:
261 case QIXIS_DDRCLK_125:
263 case QIXIS_DDRCLK_133:
271 u32 get_lpuart_clk(void)
280 * When resuming from deep sleep, the I2C channel may not be
281 * in the default channel. So, switch to the default channel
282 * before accessing DDR SPD.
284 * PCA9547 mount on I2C1 bus
286 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
288 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
289 defined(CONFIG_SPL_BUILD)
290 /* This will break-before-make MMU for DDR */
291 update_early_mmu_table();
297 int i2c_multiplexer_select_vid_channel(u8 channel)
299 return select_i2c_ch_pca9547(channel, 0);
302 int board_early_init_f(void)
304 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
305 #ifdef CONFIG_HAS_FSL_XHCI_USB
306 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
314 * Enable secure system counter for timer
316 out_le32(cntcr, 0x1);
318 #if defined(CONFIG_SYS_I2C_EARLY_INIT)
321 fsl_lsch2_early_init_f();
323 #ifdef CONFIG_HAS_FSL_XHCI_USB
324 out_be32(&scfg->rcwpmuxcr0, 0x3333);
325 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
326 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
327 SCFG_USBPWRFAULT_USB3_SHIFT) |
328 (SCFG_USBPWRFAULT_DEDICATED <<
329 SCFG_USBPWRFAULT_USB2_SHIFT) |
330 (SCFG_USBPWRFAULT_SHARED <<
331 SCFG_USBPWRFAULT_USB1_SHIFT);
332 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
336 /* We use lpuart0 as system console */
337 uart = QIXIS_READ(brdcfg[14]);
338 uart &= ~CFG_UART_MUX_MASK;
339 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
340 QIXIS_WRITE(brdcfg[14], uart);
346 #ifdef CONFIG_FSL_DEEP_SLEEP
347 /* determine if it is a warm boot */
348 bool is_warm_boot(void)
350 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
351 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
353 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
360 int config_board_mux(int ctrl_type)
364 reg14 = QIXIS_READ(brdcfg[14]);
368 reg14 = (reg14 & (~0x6)) | 0x2;
371 puts("Unsupported mux interface type\n");
375 QIXIS_WRITE(brdcfg[14], reg14);
380 int config_serdes_mux(void)
385 #ifdef CONFIG_MISC_INIT_R
386 int misc_init_r(void)
388 if (hwconfig("gpio"))
389 config_board_mux(MUX_TYPE_GPIO);
397 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
399 #ifdef CONFIG_SYS_FSL_SERDES
404 printf("Warning: Adjusting core voltage failed.\n");
406 #ifdef CONFIG_FSL_LS_PPA
410 #ifdef CONFIG_NXP_ESBC
412 * In case of Secure Boot, the IBR configures the SMMU
413 * to allow only Secure transactions.
414 * SMMU must be reset in bypass mode.
415 * Set the ClientPD bit and Clear the USFCFG Bit
418 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
419 out_le32(SMMU_SCR0, val);
420 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
421 out_le32(SMMU_NSCR0, val);
424 #ifdef CONFIG_FSL_CAAM
431 #ifdef CONFIG_OF_BOARD_SETUP
432 int ft_board_setup(void *blob, struct bd_info *bd)
434 u64 base[CONFIG_NR_DRAM_BANKS];
435 u64 size[CONFIG_NR_DRAM_BANKS];
438 /* fixup DT for the two DDR banks */
439 base[0] = gd->bd->bi_dram[0].start;
440 size[0] = gd->bd->bi_dram[0].size;
441 base[1] = gd->bd->bi_dram[1].start;
442 size[1] = gd->bd->bi_dram[1].size;
444 fdt_fixup_memory_banks(blob, base, size, 2);
445 ft_cpu_setup(blob, bd);
447 #ifdef CONFIG_SYS_DPAA_FMAN
448 #ifndef CONFIG_DM_ETH
449 fdt_fixup_fman_ethernet(blob);
451 fdt_fixup_board_enet(blob);
454 fdt_fixup_icid(blob);
456 reg = QIXIS_READ(brdcfg[0]);
457 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
459 /* Disable IFC if QSPI is enabled */
461 do_fixup_by_compat(blob, "fsl,ifc",
462 "status", "disabled", 8 + 1, 1);
468 u8 flash_read8(void *addr)
470 return __raw_readb(addr + 1);
473 void flash_write16(u16 val, void *addr)
475 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
477 __raw_writew(shftval, addr);
480 u16 flash_read16(void *addr)
482 u16 val = __raw_readw(addr);
484 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
487 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
488 void *env_sf_get_env_addr(void)
490 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);