1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
4 * Copyright 2019-2021 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>
32 #include "../common/i2c_mux.h"
34 #include "../common/vid.h"
35 #include "../common/qixis.h"
36 #include "ls1046aqds_qixis.h"
38 DECLARE_GLOBAL_DATA_PTR;
41 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
45 CONFIG_SYS_NOR0_CSPR_EXT,
59 CONFIG_SYS_NOR1_CSPR_EXT,
72 CONFIG_SYS_NAND_CSPR_EXT,
73 CONFIG_SYS_NAND_AMASK,
76 CONFIG_SYS_NAND_FTIM0,
77 CONFIG_SYS_NAND_FTIM1,
78 CONFIG_SYS_NAND_FTIM2,
85 CONFIG_SYS_FPGA_CSPR_EXT,
86 CONFIG_SYS_FPGA_AMASK,
89 CONFIG_SYS_FPGA_FTIM0,
90 CONFIG_SYS_FPGA_FTIM1,
91 CONFIG_SYS_FPGA_FTIM2,
97 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
100 CONFIG_SYS_NAND_CSPR,
101 CONFIG_SYS_NAND_CSPR_EXT,
102 CONFIG_SYS_NAND_AMASK,
103 CONFIG_SYS_NAND_CSOR,
105 CONFIG_SYS_NAND_FTIM0,
106 CONFIG_SYS_NAND_FTIM1,
107 CONFIG_SYS_NAND_FTIM2,
108 CONFIG_SYS_NAND_FTIM3
113 CONFIG_SYS_NOR0_CSPR,
114 CONFIG_SYS_NOR0_CSPR_EXT,
115 CONFIG_SYS_NOR_AMASK,
118 CONFIG_SYS_NOR_FTIM0,
119 CONFIG_SYS_NOR_FTIM1,
120 CONFIG_SYS_NOR_FTIM2,
126 CONFIG_SYS_NOR1_CSPR,
127 CONFIG_SYS_NOR1_CSPR_EXT,
128 CONFIG_SYS_NOR_AMASK,
131 CONFIG_SYS_NOR_FTIM0,
132 CONFIG_SYS_NOR_FTIM1,
133 CONFIG_SYS_NOR_FTIM2,
139 CONFIG_SYS_FPGA_CSPR,
140 CONFIG_SYS_FPGA_CSPR_EXT,
141 CONFIG_SYS_FPGA_AMASK,
142 CONFIG_SYS_FPGA_CSOR,
144 CONFIG_SYS_FPGA_FTIM0,
145 CONFIG_SYS_FPGA_FTIM1,
146 CONFIG_SYS_FPGA_FTIM2,
147 CONFIG_SYS_FPGA_FTIM3
152 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
154 enum boot_src src = get_boot_src();
156 if (src == BOOT_SOURCE_IFC_NAND)
157 regs_info->regs = ifc_cfg_nand_boot;
159 regs_info->regs = ifc_cfg_nor_boot;
160 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
171 #ifdef CONFIG_TFABOOT
172 enum boot_src src = get_boot_src();
175 #ifndef CONFIG_SD_BOOT
179 puts("Board: LS1046AQDS, boot from ");
181 #ifdef CONFIG_TFABOOT
182 if (src == BOOT_SOURCE_SD_MMC)
187 #ifdef CONFIG_SD_BOOT
190 sw = QIXIS_READ(brdcfg[0]);
191 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
194 printf("vBank: %d\n", sw);
202 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
205 #ifdef CONFIG_TFABOOT
208 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
209 QIXIS_READ(id), QIXIS_READ(arch));
211 printf("FPGA: v%d (%s), build %d\n",
212 (int)QIXIS_READ(scver), qixis_read_tag(buf),
213 (int)qixis_read_minor());
218 bool if_board_diff_clk(void)
220 u8 diff_conf = QIXIS_READ(brdcfg[11]);
222 return diff_conf & 0x40;
225 unsigned long get_board_sys_clk(void)
227 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
229 switch (sysclk_conf & 0x0f) {
230 case QIXIS_SYSCLK_64:
232 case QIXIS_SYSCLK_83:
234 case QIXIS_SYSCLK_100:
236 case QIXIS_SYSCLK_125:
238 case QIXIS_SYSCLK_133:
240 case QIXIS_SYSCLK_150:
242 case QIXIS_SYSCLK_160:
244 case QIXIS_SYSCLK_166:
251 unsigned long get_board_ddr_clk(void)
253 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
255 if (if_board_diff_clk())
256 return get_board_sys_clk();
257 switch ((ddrclk_conf & 0x30) >> 4) {
258 case QIXIS_DDRCLK_100:
260 case QIXIS_DDRCLK_125:
262 case QIXIS_DDRCLK_133:
270 u32 get_lpuart_clk(void)
279 * When resuming from deep sleep, the I2C channel may not be
280 * in the default channel. So, switch to the default channel
281 * before accessing DDR SPD.
283 * PCA9547 mount on I2C1 bus
285 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
287 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
288 defined(CONFIG_SPL_BUILD)
289 /* This will break-before-make MMU for DDR */
290 update_early_mmu_table();
296 int i2c_multiplexer_select_vid_channel(u8 channel)
298 return select_i2c_ch_pca9547(channel, 0);
301 int board_early_init_f(void)
303 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
304 #ifdef CONFIG_HAS_FSL_XHCI_USB
305 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
313 * Enable secure system counter for timer
315 out_le32(cntcr, 0x1);
317 #if defined(CONFIG_SYS_I2C_EARLY_INIT)
320 fsl_lsch2_early_init_f();
322 #ifdef CONFIG_HAS_FSL_XHCI_USB
323 out_be32(&scfg->rcwpmuxcr0, 0x3333);
324 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
325 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
326 SCFG_USBPWRFAULT_USB3_SHIFT) |
327 (SCFG_USBPWRFAULT_DEDICATED <<
328 SCFG_USBPWRFAULT_USB2_SHIFT) |
329 (SCFG_USBPWRFAULT_SHARED <<
330 SCFG_USBPWRFAULT_USB1_SHIFT);
331 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
335 /* We use lpuart0 as system console */
336 uart = QIXIS_READ(brdcfg[14]);
337 uart &= ~CFG_UART_MUX_MASK;
338 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
339 QIXIS_WRITE(brdcfg[14], uart);
345 #ifdef CONFIG_FSL_DEEP_SLEEP
346 /* determine if it is a warm boot */
347 bool is_warm_boot(void)
349 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
350 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
352 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
359 int config_board_mux(int ctrl_type)
363 reg14 = QIXIS_READ(brdcfg[14]);
367 reg14 = (reg14 & (~0x6)) | 0x2;
370 puts("Unsupported mux interface type\n");
374 QIXIS_WRITE(brdcfg[14], reg14);
379 int config_serdes_mux(void)
384 #ifdef CONFIG_MISC_INIT_R
385 int misc_init_r(void)
387 if (hwconfig("gpio"))
388 config_board_mux(MUX_TYPE_GPIO);
396 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
398 #ifdef CONFIG_SYS_FSL_SERDES
403 printf("Warning: Adjusting core voltage failed.\n");
405 #ifdef CONFIG_FSL_LS_PPA
409 #ifdef CONFIG_NXP_ESBC
411 * In case of Secure Boot, the IBR configures the SMMU
412 * to allow only Secure transactions.
413 * SMMU must be reset in bypass mode.
414 * Set the ClientPD bit and Clear the USFCFG Bit
417 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
418 out_le32(SMMU_SCR0, val);
419 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
420 out_le32(SMMU_NSCR0, val);
426 #ifdef CONFIG_OF_BOARD_SETUP
427 int ft_board_setup(void *blob, struct bd_info *bd)
429 u64 base[CONFIG_NR_DRAM_BANKS];
430 u64 size[CONFIG_NR_DRAM_BANKS];
433 /* fixup DT for the two DDR banks */
434 base[0] = gd->bd->bi_dram[0].start;
435 size[0] = gd->bd->bi_dram[0].size;
436 base[1] = gd->bd->bi_dram[1].start;
437 size[1] = gd->bd->bi_dram[1].size;
439 fdt_fixup_memory_banks(blob, base, size, 2);
440 ft_cpu_setup(blob, bd);
442 #ifdef CONFIG_SYS_DPAA_FMAN
443 #ifndef CONFIG_DM_ETH
444 fdt_fixup_fman_ethernet(blob);
446 fdt_fixup_board_enet(blob);
449 fdt_fixup_icid(blob);
451 reg = QIXIS_READ(brdcfg[0]);
452 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
454 /* Disable IFC if QSPI is enabled */
456 do_fixup_by_compat(blob, "fsl,ifc",
457 "status", "disabled", 8 + 1, 1);
463 u8 flash_read8(void *addr)
465 return __raw_readb(addr + 1);
468 void flash_write16(u16 val, void *addr)
470 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
472 __raw_writew(shftval, addr);
475 u16 flash_read16(void *addr)
477 u16 val = __raw_readw(addr);
479 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
482 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
483 void *env_sf_get_env_addr(void)
485 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);