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>
33 #include "../common/vid.h"
34 #include "../common/qixis.h"
35 #include "ls1046aqds_qixis.h"
37 DECLARE_GLOBAL_DATA_PTR;
39 #ifdef CONFIG_SYS_I2C_EARLY_INIT
40 void i2c_early_init_f(void);
44 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
48 CONFIG_SYS_NOR0_CSPR_EXT,
62 CONFIG_SYS_NOR1_CSPR_EXT,
75 CONFIG_SYS_NAND_CSPR_EXT,
76 CONFIG_SYS_NAND_AMASK,
79 CONFIG_SYS_NAND_FTIM0,
80 CONFIG_SYS_NAND_FTIM1,
81 CONFIG_SYS_NAND_FTIM2,
88 CONFIG_SYS_FPGA_CSPR_EXT,
89 CONFIG_SYS_FPGA_AMASK,
92 CONFIG_SYS_FPGA_FTIM0,
93 CONFIG_SYS_FPGA_FTIM1,
94 CONFIG_SYS_FPGA_FTIM2,
100 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
103 CONFIG_SYS_NAND_CSPR,
104 CONFIG_SYS_NAND_CSPR_EXT,
105 CONFIG_SYS_NAND_AMASK,
106 CONFIG_SYS_NAND_CSOR,
108 CONFIG_SYS_NAND_FTIM0,
109 CONFIG_SYS_NAND_FTIM1,
110 CONFIG_SYS_NAND_FTIM2,
111 CONFIG_SYS_NAND_FTIM3
116 CONFIG_SYS_NOR0_CSPR,
117 CONFIG_SYS_NOR0_CSPR_EXT,
118 CONFIG_SYS_NOR_AMASK,
121 CONFIG_SYS_NOR_FTIM0,
122 CONFIG_SYS_NOR_FTIM1,
123 CONFIG_SYS_NOR_FTIM2,
129 CONFIG_SYS_NOR1_CSPR,
130 CONFIG_SYS_NOR1_CSPR_EXT,
131 CONFIG_SYS_NOR_AMASK,
134 CONFIG_SYS_NOR_FTIM0,
135 CONFIG_SYS_NOR_FTIM1,
136 CONFIG_SYS_NOR_FTIM2,
142 CONFIG_SYS_FPGA_CSPR,
143 CONFIG_SYS_FPGA_CSPR_EXT,
144 CONFIG_SYS_FPGA_AMASK,
145 CONFIG_SYS_FPGA_CSOR,
147 CONFIG_SYS_FPGA_FTIM0,
148 CONFIG_SYS_FPGA_FTIM1,
149 CONFIG_SYS_FPGA_FTIM2,
150 CONFIG_SYS_FPGA_FTIM3
155 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
157 enum boot_src src = get_boot_src();
159 if (src == BOOT_SOURCE_IFC_NAND)
160 regs_info->regs = ifc_cfg_nand_boot;
162 regs_info->regs = ifc_cfg_nor_boot;
163 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
174 #ifdef CONFIG_TFABOOT
175 enum boot_src src = get_boot_src();
178 #ifndef CONFIG_SD_BOOT
182 puts("Board: LS1046AQDS, boot from ");
184 #ifdef CONFIG_TFABOOT
185 if (src == BOOT_SOURCE_SD_MMC)
190 #ifdef CONFIG_SD_BOOT
193 sw = QIXIS_READ(brdcfg[0]);
194 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
197 printf("vBank: %d\n", sw);
205 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
208 #ifdef CONFIG_TFABOOT
211 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
212 QIXIS_READ(id), QIXIS_READ(arch));
214 printf("FPGA: v%d (%s), build %d\n",
215 (int)QIXIS_READ(scver), qixis_read_tag(buf),
216 (int)qixis_read_minor());
221 bool if_board_diff_clk(void)
223 u8 diff_conf = QIXIS_READ(brdcfg[11]);
225 return diff_conf & 0x40;
228 unsigned long get_board_sys_clk(void)
230 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
232 switch (sysclk_conf & 0x0f) {
233 case QIXIS_SYSCLK_64:
235 case QIXIS_SYSCLK_83:
237 case QIXIS_SYSCLK_100:
239 case QIXIS_SYSCLK_125:
241 case QIXIS_SYSCLK_133:
243 case QIXIS_SYSCLK_150:
245 case QIXIS_SYSCLK_160:
247 case QIXIS_SYSCLK_166:
254 unsigned long get_board_ddr_clk(void)
256 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
258 if (if_board_diff_clk())
259 return get_board_sys_clk();
260 switch ((ddrclk_conf & 0x30) >> 4) {
261 case QIXIS_DDRCLK_100:
263 case QIXIS_DDRCLK_125:
265 case QIXIS_DDRCLK_133:
273 u32 get_lpuart_clk(void)
279 int select_i2c_ch_pca9547(u8 ch, int bus_num)
285 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
288 printf("%s: Cannot find udev for a bus %d\n", __func__,
292 ret = dm_i2c_write(dev, 0, &ch, 1);
294 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
297 puts("PCA: failed to select proper channel\n");
307 * When resuming from deep sleep, the I2C channel may not be
308 * in the default channel. So, switch to the default channel
309 * before accessing DDR SPD.
311 * PCA9547 mount on I2C1 bus
313 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
315 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
316 defined(CONFIG_SPL_BUILD)
317 /* This will break-before-make MMU for DDR */
318 update_early_mmu_table();
324 int i2c_multiplexer_select_vid_channel(u8 channel)
326 return select_i2c_ch_pca9547(channel, 0);
329 int board_early_init_f(void)
331 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
332 #ifdef CONFIG_HAS_FSL_XHCI_USB
333 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
341 * Enable secure system counter for timer
343 out_le32(cntcr, 0x1);
345 #ifdef CONFIG_SYS_I2C_EARLY_INIT
348 fsl_lsch2_early_init_f();
350 #ifdef CONFIG_HAS_FSL_XHCI_USB
351 out_be32(&scfg->rcwpmuxcr0, 0x3333);
352 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
353 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
354 SCFG_USBPWRFAULT_USB3_SHIFT) |
355 (SCFG_USBPWRFAULT_DEDICATED <<
356 SCFG_USBPWRFAULT_USB2_SHIFT) |
357 (SCFG_USBPWRFAULT_SHARED <<
358 SCFG_USBPWRFAULT_USB1_SHIFT);
359 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
363 /* We use lpuart0 as system console */
364 uart = QIXIS_READ(brdcfg[14]);
365 uart &= ~CFG_UART_MUX_MASK;
366 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
367 QIXIS_WRITE(brdcfg[14], uart);
373 #ifdef CONFIG_FSL_DEEP_SLEEP
374 /* determine if it is a warm boot */
375 bool is_warm_boot(void)
377 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
378 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
380 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
387 int config_board_mux(int ctrl_type)
391 reg14 = QIXIS_READ(brdcfg[14]);
395 reg14 = (reg14 & (~0x6)) | 0x2;
398 puts("Unsupported mux interface type\n");
402 QIXIS_WRITE(brdcfg[14], reg14);
407 int config_serdes_mux(void)
412 #ifdef CONFIG_MISC_INIT_R
413 int misc_init_r(void)
415 if (hwconfig("gpio"))
416 config_board_mux(MUX_TYPE_GPIO);
424 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
426 #ifdef CONFIG_SYS_FSL_SERDES
431 printf("Warning: Adjusting core voltage failed.\n");
433 #ifdef CONFIG_FSL_LS_PPA
437 #ifdef CONFIG_NXP_ESBC
439 * In case of Secure Boot, the IBR configures the SMMU
440 * to allow only Secure transactions.
441 * SMMU must be reset in bypass mode.
442 * Set the ClientPD bit and Clear the USFCFG Bit
445 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
446 out_le32(SMMU_SCR0, val);
447 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
448 out_le32(SMMU_NSCR0, val);
451 #ifdef CONFIG_FSL_CAAM
458 #ifdef CONFIG_OF_BOARD_SETUP
459 int ft_board_setup(void *blob, struct bd_info *bd)
461 u64 base[CONFIG_NR_DRAM_BANKS];
462 u64 size[CONFIG_NR_DRAM_BANKS];
465 /* fixup DT for the two DDR banks */
466 base[0] = gd->bd->bi_dram[0].start;
467 size[0] = gd->bd->bi_dram[0].size;
468 base[1] = gd->bd->bi_dram[1].start;
469 size[1] = gd->bd->bi_dram[1].size;
471 fdt_fixup_memory_banks(blob, base, size, 2);
472 ft_cpu_setup(blob, bd);
474 #ifdef CONFIG_SYS_DPAA_FMAN
475 #ifndef CONFIG_DM_ETH
476 fdt_fixup_fman_ethernet(blob);
478 fdt_fixup_board_enet(blob);
481 fdt_fixup_icid(blob);
483 reg = QIXIS_READ(brdcfg[0]);
484 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
486 /* Disable IFC if QSPI is enabled */
488 do_fixup_by_compat(blob, "fsl,ifc",
489 "status", "disabled", 8 + 1, 1);
495 u8 flash_read8(void *addr)
497 return __raw_readb(addr + 1);
500 void flash_write16(u16 val, void *addr)
502 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
504 __raw_writew(shftval, addr);
507 u16 flash_read16(void *addr)
509 u16 val = __raw_readw(addr);
511 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
514 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
515 void *env_sf_get_env_addr(void)
517 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);