1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
4 * Copyright 2019-2020 NXP
9 #include <fdt_support.h>
10 #include <fsl_ddr_sdram.h>
12 #include <asm/global_data.h>
14 #include <asm/arch/clock.h>
15 #include <asm/arch/fsl_serdes.h>
16 #include <asm/arch/ppa.h>
17 #include <asm/arch/fdt.h>
18 #include <asm/arch/mmu.h>
19 #include <asm/arch/cpu.h>
20 #include <asm/arch/soc.h>
21 #include <asm/arch-fsl-layerscape/fsl_icid.h>
28 #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;
40 #ifdef CONFIG_SYS_I2C_EARLY_INIT
41 void i2c_early_init_f(void);
45 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
49 CONFIG_SYS_NOR0_CSPR_EXT,
63 CONFIG_SYS_NOR1_CSPR_EXT,
76 CONFIG_SYS_NAND_CSPR_EXT,
77 CONFIG_SYS_NAND_AMASK,
80 CONFIG_SYS_NAND_FTIM0,
81 CONFIG_SYS_NAND_FTIM1,
82 CONFIG_SYS_NAND_FTIM2,
89 CONFIG_SYS_FPGA_CSPR_EXT,
90 CONFIG_SYS_FPGA_AMASK,
93 CONFIG_SYS_FPGA_FTIM0,
94 CONFIG_SYS_FPGA_FTIM1,
95 CONFIG_SYS_FPGA_FTIM2,
101 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
104 CONFIG_SYS_NAND_CSPR,
105 CONFIG_SYS_NAND_CSPR_EXT,
106 CONFIG_SYS_NAND_AMASK,
107 CONFIG_SYS_NAND_CSOR,
109 CONFIG_SYS_NAND_FTIM0,
110 CONFIG_SYS_NAND_FTIM1,
111 CONFIG_SYS_NAND_FTIM2,
112 CONFIG_SYS_NAND_FTIM3
117 CONFIG_SYS_NOR0_CSPR,
118 CONFIG_SYS_NOR0_CSPR_EXT,
119 CONFIG_SYS_NOR_AMASK,
122 CONFIG_SYS_NOR_FTIM0,
123 CONFIG_SYS_NOR_FTIM1,
124 CONFIG_SYS_NOR_FTIM2,
130 CONFIG_SYS_NOR1_CSPR,
131 CONFIG_SYS_NOR1_CSPR_EXT,
132 CONFIG_SYS_NOR_AMASK,
135 CONFIG_SYS_NOR_FTIM0,
136 CONFIG_SYS_NOR_FTIM1,
137 CONFIG_SYS_NOR_FTIM2,
143 CONFIG_SYS_FPGA_CSPR,
144 CONFIG_SYS_FPGA_CSPR_EXT,
145 CONFIG_SYS_FPGA_AMASK,
146 CONFIG_SYS_FPGA_CSOR,
148 CONFIG_SYS_FPGA_FTIM0,
149 CONFIG_SYS_FPGA_FTIM1,
150 CONFIG_SYS_FPGA_FTIM2,
151 CONFIG_SYS_FPGA_FTIM3
156 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
158 enum boot_src src = get_boot_src();
160 if (src == BOOT_SOURCE_IFC_NAND)
161 regs_info->regs = ifc_cfg_nand_boot;
163 regs_info->regs = ifc_cfg_nor_boot;
164 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
175 #ifdef CONFIG_TFABOOT
176 enum boot_src src = get_boot_src();
179 #ifndef CONFIG_SD_BOOT
183 puts("Board: LS1046AQDS, boot from ");
185 #ifdef CONFIG_TFABOOT
186 if (src == BOOT_SOURCE_SD_MMC)
191 #ifdef CONFIG_SD_BOOT
194 sw = QIXIS_READ(brdcfg[0]);
195 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
198 printf("vBank: %d\n", sw);
206 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
209 #ifdef CONFIG_TFABOOT
212 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
213 QIXIS_READ(id), QIXIS_READ(arch));
215 printf("FPGA: v%d (%s), build %d\n",
216 (int)QIXIS_READ(scver), qixis_read_tag(buf),
217 (int)qixis_read_minor());
222 bool if_board_diff_clk(void)
224 u8 diff_conf = QIXIS_READ(brdcfg[11]);
226 return diff_conf & 0x40;
229 unsigned long get_board_sys_clk(void)
231 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
233 switch (sysclk_conf & 0x0f) {
234 case QIXIS_SYSCLK_64:
236 case QIXIS_SYSCLK_83:
238 case QIXIS_SYSCLK_100:
240 case QIXIS_SYSCLK_125:
242 case QIXIS_SYSCLK_133:
244 case QIXIS_SYSCLK_150:
246 case QIXIS_SYSCLK_160:
248 case QIXIS_SYSCLK_166:
255 unsigned long get_board_ddr_clk(void)
257 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
259 if (if_board_diff_clk())
260 return get_board_sys_clk();
261 switch ((ddrclk_conf & 0x30) >> 4) {
262 case QIXIS_DDRCLK_100:
264 case QIXIS_DDRCLK_125:
266 case QIXIS_DDRCLK_133:
274 u32 get_lpuart_clk(void)
283 * When resuming from deep sleep, the I2C channel may not be
284 * in the default channel. So, switch to the default channel
285 * before accessing DDR SPD.
287 * PCA9547 mount on I2C1 bus
289 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
291 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
292 defined(CONFIG_SPL_BUILD)
293 /* This will break-before-make MMU for DDR */
294 update_early_mmu_table();
300 int i2c_multiplexer_select_vid_channel(u8 channel)
302 return select_i2c_ch_pca9547(channel, 0);
305 int board_early_init_f(void)
307 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
308 #ifdef CONFIG_HAS_FSL_XHCI_USB
309 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
317 * Enable secure system counter for timer
319 out_le32(cntcr, 0x1);
321 #ifdef CONFIG_SYS_I2C_EARLY_INIT
324 fsl_lsch2_early_init_f();
326 #ifdef CONFIG_HAS_FSL_XHCI_USB
327 out_be32(&scfg->rcwpmuxcr0, 0x3333);
328 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
329 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
330 SCFG_USBPWRFAULT_USB3_SHIFT) |
331 (SCFG_USBPWRFAULT_DEDICATED <<
332 SCFG_USBPWRFAULT_USB2_SHIFT) |
333 (SCFG_USBPWRFAULT_SHARED <<
334 SCFG_USBPWRFAULT_USB1_SHIFT);
335 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
339 /* We use lpuart0 as system console */
340 uart = QIXIS_READ(brdcfg[14]);
341 uart &= ~CFG_UART_MUX_MASK;
342 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
343 QIXIS_WRITE(brdcfg[14], uart);
349 #ifdef CONFIG_FSL_DEEP_SLEEP
350 /* determine if it is a warm boot */
351 bool is_warm_boot(void)
353 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
354 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
356 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
363 int config_board_mux(int ctrl_type)
367 reg14 = QIXIS_READ(brdcfg[14]);
371 reg14 = (reg14 & (~0x6)) | 0x2;
374 puts("Unsupported mux interface type\n");
378 QIXIS_WRITE(brdcfg[14], reg14);
383 int config_serdes_mux(void)
388 #ifdef CONFIG_MISC_INIT_R
389 int misc_init_r(void)
391 if (hwconfig("gpio"))
392 config_board_mux(MUX_TYPE_GPIO);
400 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
402 #ifdef CONFIG_SYS_FSL_SERDES
407 printf("Warning: Adjusting core voltage failed.\n");
409 #ifdef CONFIG_FSL_LS_PPA
413 #ifdef CONFIG_NXP_ESBC
415 * In case of Secure Boot, the IBR configures the SMMU
416 * to allow only Secure transactions.
417 * SMMU must be reset in bypass mode.
418 * Set the ClientPD bit and Clear the USFCFG Bit
421 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
422 out_le32(SMMU_SCR0, val);
423 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
424 out_le32(SMMU_NSCR0, val);
427 #ifdef CONFIG_FSL_CAAM
434 #ifdef CONFIG_OF_BOARD_SETUP
435 int ft_board_setup(void *blob, struct bd_info *bd)
437 u64 base[CONFIG_NR_DRAM_BANKS];
438 u64 size[CONFIG_NR_DRAM_BANKS];
441 /* fixup DT for the two DDR banks */
442 base[0] = gd->bd->bi_dram[0].start;
443 size[0] = gd->bd->bi_dram[0].size;
444 base[1] = gd->bd->bi_dram[1].start;
445 size[1] = gd->bd->bi_dram[1].size;
447 fdt_fixup_memory_banks(blob, base, size, 2);
448 ft_cpu_setup(blob, bd);
450 #ifdef CONFIG_SYS_DPAA_FMAN
451 #ifndef CONFIG_DM_ETH
452 fdt_fixup_fman_ethernet(blob);
454 fdt_fixup_board_enet(blob);
457 fdt_fixup_icid(blob);
459 reg = QIXIS_READ(brdcfg[0]);
460 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
462 /* Disable IFC if QSPI is enabled */
464 do_fixup_by_compat(blob, "fsl,ifc",
465 "status", "disabled", 8 + 1, 1);
471 u8 flash_read8(void *addr)
473 return __raw_readb(addr + 1);
476 void flash_write16(u16 val, void *addr)
478 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
480 __raw_writew(shftval, addr);
483 u16 flash_read16(void *addr)
485 u16 val = __raw_readw(addr);
487 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
490 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
491 void *env_sf_get_env_addr(void)
493 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);