1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
9 #include <fdt_support.h>
10 #include <fsl_ddr_sdram.h>
12 #include <asm/arch/clock.h>
13 #include <asm/arch/fsl_serdes.h>
14 #include <asm/arch/ppa.h>
15 #include <asm/arch/fdt.h>
16 #include <asm/arch/mmu.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/soc.h>
19 #include <asm/arch-fsl-layerscape/fsl_icid.h>
26 #include <fsl_esdhc.h>
31 #include "../common/vid.h"
32 #include "../common/qixis.h"
33 #include "ls1046aqds_qixis.h"
35 DECLARE_GLOBAL_DATA_PTR;
38 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
42 CONFIG_SYS_NOR0_CSPR_EXT,
56 CONFIG_SYS_NOR1_CSPR_EXT,
69 CONFIG_SYS_NAND_CSPR_EXT,
70 CONFIG_SYS_NAND_AMASK,
73 CONFIG_SYS_NAND_FTIM0,
74 CONFIG_SYS_NAND_FTIM1,
75 CONFIG_SYS_NAND_FTIM2,
82 CONFIG_SYS_FPGA_CSPR_EXT,
83 CONFIG_SYS_FPGA_AMASK,
86 CONFIG_SYS_FPGA_FTIM0,
87 CONFIG_SYS_FPGA_FTIM1,
88 CONFIG_SYS_FPGA_FTIM2,
94 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
98 CONFIG_SYS_NAND_CSPR_EXT,
99 CONFIG_SYS_NAND_AMASK,
100 CONFIG_SYS_NAND_CSOR,
102 CONFIG_SYS_NAND_FTIM0,
103 CONFIG_SYS_NAND_FTIM1,
104 CONFIG_SYS_NAND_FTIM2,
105 CONFIG_SYS_NAND_FTIM3
110 CONFIG_SYS_NOR0_CSPR,
111 CONFIG_SYS_NOR0_CSPR_EXT,
112 CONFIG_SYS_NOR_AMASK,
115 CONFIG_SYS_NOR_FTIM0,
116 CONFIG_SYS_NOR_FTIM1,
117 CONFIG_SYS_NOR_FTIM2,
123 CONFIG_SYS_NOR1_CSPR,
124 CONFIG_SYS_NOR1_CSPR_EXT,
125 CONFIG_SYS_NOR_AMASK,
128 CONFIG_SYS_NOR_FTIM0,
129 CONFIG_SYS_NOR_FTIM1,
130 CONFIG_SYS_NOR_FTIM2,
136 CONFIG_SYS_FPGA_CSPR,
137 CONFIG_SYS_FPGA_CSPR_EXT,
138 CONFIG_SYS_FPGA_AMASK,
139 CONFIG_SYS_FPGA_CSOR,
141 CONFIG_SYS_FPGA_FTIM0,
142 CONFIG_SYS_FPGA_FTIM1,
143 CONFIG_SYS_FPGA_FTIM2,
144 CONFIG_SYS_FPGA_FTIM3
149 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
151 enum boot_src src = get_boot_src();
153 if (src == BOOT_SOURCE_IFC_NAND)
154 regs_info->regs = ifc_cfg_nand_boot;
156 regs_info->regs = ifc_cfg_nor_boot;
157 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
168 #ifdef CONFIG_TFABOOT
169 enum boot_src src = get_boot_src();
172 #ifndef CONFIG_SD_BOOT
176 puts("Board: LS1046AQDS, boot from ");
178 #ifdef CONFIG_TFABOOT
179 if (src == BOOT_SOURCE_SD_MMC)
184 #ifdef CONFIG_SD_BOOT
187 sw = QIXIS_READ(brdcfg[0]);
188 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
191 printf("vBank: %d\n", sw);
199 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
202 #ifdef CONFIG_TFABOOT
205 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
206 QIXIS_READ(id), QIXIS_READ(arch));
208 printf("FPGA: v%d (%s), build %d\n",
209 (int)QIXIS_READ(scver), qixis_read_tag(buf),
210 (int)qixis_read_minor());
215 bool if_board_diff_clk(void)
217 u8 diff_conf = QIXIS_READ(brdcfg[11]);
219 return diff_conf & 0x40;
222 unsigned long get_board_sys_clk(void)
224 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
226 switch (sysclk_conf & 0x0f) {
227 case QIXIS_SYSCLK_64:
229 case QIXIS_SYSCLK_83:
231 case QIXIS_SYSCLK_100:
233 case QIXIS_SYSCLK_125:
235 case QIXIS_SYSCLK_133:
237 case QIXIS_SYSCLK_150:
239 case QIXIS_SYSCLK_160:
241 case QIXIS_SYSCLK_166:
248 unsigned long get_board_ddr_clk(void)
250 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
252 if (if_board_diff_clk())
253 return get_board_sys_clk();
254 switch ((ddrclk_conf & 0x30) >> 4) {
255 case QIXIS_DDRCLK_100:
257 case QIXIS_DDRCLK_125:
259 case QIXIS_DDRCLK_133:
267 u32 get_lpuart_clk(void)
273 int select_i2c_ch_pca9547(u8 ch, int bus_num)
279 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
282 printf("%s: Cannot find udev for a bus %d\n", __func__,
286 ret = dm_i2c_write(dev, 0, &ch, 1);
288 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
291 puts("PCA: failed to select proper channel\n");
301 * When resuming from deep sleep, the I2C channel may not be
302 * in the default channel. So, switch to the default channel
303 * before accessing DDR SPD.
305 * PCA9547 mount on I2C1 bus
307 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
309 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
310 defined(CONFIG_SPL_BUILD)
311 /* This will break-before-make MMU for DDR */
312 update_early_mmu_table();
318 int i2c_multiplexer_select_vid_channel(u8 channel)
320 return select_i2c_ch_pca9547(channel, 0);
323 int board_early_init_f(void)
325 #ifdef CONFIG_HAS_FSL_XHCI_USB
326 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
333 #ifdef CONFIG_SYS_I2C
334 #ifdef CONFIG_SYS_I2C_EARLY_INIT
338 fsl_lsch2_early_init_f();
340 #ifdef CONFIG_HAS_FSL_XHCI_USB
341 out_be32(&scfg->rcwpmuxcr0, 0x3333);
342 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
343 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
344 SCFG_USBPWRFAULT_USB3_SHIFT) |
345 (SCFG_USBPWRFAULT_DEDICATED <<
346 SCFG_USBPWRFAULT_USB2_SHIFT) |
347 (SCFG_USBPWRFAULT_SHARED <<
348 SCFG_USBPWRFAULT_USB1_SHIFT);
349 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
353 /* We use lpuart0 as system console */
354 uart = QIXIS_READ(brdcfg[14]);
355 uart &= ~CFG_UART_MUX_MASK;
356 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
357 QIXIS_WRITE(brdcfg[14], uart);
363 #ifdef CONFIG_FSL_DEEP_SLEEP
364 /* determine if it is a warm boot */
365 bool is_warm_boot(void)
367 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
368 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
370 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
377 int config_board_mux(int ctrl_type)
381 reg14 = QIXIS_READ(brdcfg[14]);
385 reg14 = (reg14 & (~0x6)) | 0x2;
388 puts("Unsupported mux interface type\n");
392 QIXIS_WRITE(brdcfg[14], reg14);
397 int config_serdes_mux(void)
402 #ifdef CONFIG_MISC_INIT_R
403 int misc_init_r(void)
405 if (hwconfig("gpio"))
406 config_board_mux(MUX_TYPE_GPIO);
414 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
416 #ifdef CONFIG_SYS_FSL_SERDES
421 printf("Warning: Adjusting core voltage failed.\n");
423 #ifdef CONFIG_FSL_LS_PPA
427 #ifdef CONFIG_NXP_ESBC
429 * In case of Secure Boot, the IBR configures the SMMU
430 * to allow only Secure transactions.
431 * SMMU must be reset in bypass mode.
432 * Set the ClientPD bit and Clear the USFCFG Bit
435 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
436 out_le32(SMMU_SCR0, val);
437 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
438 out_le32(SMMU_NSCR0, val);
441 #ifdef CONFIG_FSL_CAAM
448 #ifdef CONFIG_OF_BOARD_SETUP
449 int ft_board_setup(void *blob, bd_t *bd)
451 u64 base[CONFIG_NR_DRAM_BANKS];
452 u64 size[CONFIG_NR_DRAM_BANKS];
455 /* fixup DT for the two DDR banks */
456 base[0] = gd->bd->bi_dram[0].start;
457 size[0] = gd->bd->bi_dram[0].size;
458 base[1] = gd->bd->bi_dram[1].start;
459 size[1] = gd->bd->bi_dram[1].size;
461 fdt_fixup_memory_banks(blob, base, size, 2);
462 ft_cpu_setup(blob, bd);
464 #ifdef CONFIG_SYS_DPAA_FMAN
465 #ifndef CONFIG_DM_ETH
466 fdt_fixup_fman_ethernet(blob);
468 fdt_fixup_board_enet(blob);
471 fdt_fixup_icid(blob);
473 reg = QIXIS_READ(brdcfg[0]);
474 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
476 /* Disable IFC if QSPI is enabled */
478 do_fixup_by_compat(blob, "fsl,ifc",
479 "status", "disabled", 8 + 1, 1);
485 u8 flash_read8(void *addr)
487 return __raw_readb(addr + 1);
490 void flash_write16(u16 val, void *addr)
492 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
494 __raw_writew(shftval, addr);
497 u16 flash_read16(void *addr)
499 u16 val = __raw_readw(addr);
501 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
504 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
505 void *env_sf_get_env_addr(void)
507 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);