1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2016 Freescale Semiconductor, Inc.
9 #include <fdt_support.h>
10 #include <fsl_ddr_sdram.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/fsl_serdes.h>
15 #include <asm/arch/ppa.h>
16 #include <asm/arch/fdt.h>
17 #include <asm/arch/mmu.h>
18 #include <asm/arch/cpu.h>
19 #include <asm/arch/soc.h>
20 #include <asm/arch-fsl-layerscape/fsl_icid.h>
27 #include <fsl_esdhc.h>
32 #include "../common/vid.h"
33 #include "../common/qixis.h"
34 #include "ls1046aqds_qixis.h"
36 DECLARE_GLOBAL_DATA_PTR;
39 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
43 CONFIG_SYS_NOR0_CSPR_EXT,
57 CONFIG_SYS_NOR1_CSPR_EXT,
70 CONFIG_SYS_NAND_CSPR_EXT,
71 CONFIG_SYS_NAND_AMASK,
74 CONFIG_SYS_NAND_FTIM0,
75 CONFIG_SYS_NAND_FTIM1,
76 CONFIG_SYS_NAND_FTIM2,
83 CONFIG_SYS_FPGA_CSPR_EXT,
84 CONFIG_SYS_FPGA_AMASK,
87 CONFIG_SYS_FPGA_FTIM0,
88 CONFIG_SYS_FPGA_FTIM1,
89 CONFIG_SYS_FPGA_FTIM2,
95 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
99 CONFIG_SYS_NAND_CSPR_EXT,
100 CONFIG_SYS_NAND_AMASK,
101 CONFIG_SYS_NAND_CSOR,
103 CONFIG_SYS_NAND_FTIM0,
104 CONFIG_SYS_NAND_FTIM1,
105 CONFIG_SYS_NAND_FTIM2,
106 CONFIG_SYS_NAND_FTIM3
111 CONFIG_SYS_NOR0_CSPR,
112 CONFIG_SYS_NOR0_CSPR_EXT,
113 CONFIG_SYS_NOR_AMASK,
116 CONFIG_SYS_NOR_FTIM0,
117 CONFIG_SYS_NOR_FTIM1,
118 CONFIG_SYS_NOR_FTIM2,
124 CONFIG_SYS_NOR1_CSPR,
125 CONFIG_SYS_NOR1_CSPR_EXT,
126 CONFIG_SYS_NOR_AMASK,
129 CONFIG_SYS_NOR_FTIM0,
130 CONFIG_SYS_NOR_FTIM1,
131 CONFIG_SYS_NOR_FTIM2,
137 CONFIG_SYS_FPGA_CSPR,
138 CONFIG_SYS_FPGA_CSPR_EXT,
139 CONFIG_SYS_FPGA_AMASK,
140 CONFIG_SYS_FPGA_CSOR,
142 CONFIG_SYS_FPGA_FTIM0,
143 CONFIG_SYS_FPGA_FTIM1,
144 CONFIG_SYS_FPGA_FTIM2,
145 CONFIG_SYS_FPGA_FTIM3
150 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
152 enum boot_src src = get_boot_src();
154 if (src == BOOT_SOURCE_IFC_NAND)
155 regs_info->regs = ifc_cfg_nand_boot;
157 regs_info->regs = ifc_cfg_nor_boot;
158 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
169 #ifdef CONFIG_TFABOOT
170 enum boot_src src = get_boot_src();
173 #ifndef CONFIG_SD_BOOT
177 puts("Board: LS1046AQDS, boot from ");
179 #ifdef CONFIG_TFABOOT
180 if (src == BOOT_SOURCE_SD_MMC)
185 #ifdef CONFIG_SD_BOOT
188 sw = QIXIS_READ(brdcfg[0]);
189 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
192 printf("vBank: %d\n", sw);
200 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
203 #ifdef CONFIG_TFABOOT
206 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
207 QIXIS_READ(id), QIXIS_READ(arch));
209 printf("FPGA: v%d (%s), build %d\n",
210 (int)QIXIS_READ(scver), qixis_read_tag(buf),
211 (int)qixis_read_minor());
216 bool if_board_diff_clk(void)
218 u8 diff_conf = QIXIS_READ(brdcfg[11]);
220 return diff_conf & 0x40;
223 unsigned long get_board_sys_clk(void)
225 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
227 switch (sysclk_conf & 0x0f) {
228 case QIXIS_SYSCLK_64:
230 case QIXIS_SYSCLK_83:
232 case QIXIS_SYSCLK_100:
234 case QIXIS_SYSCLK_125:
236 case QIXIS_SYSCLK_133:
238 case QIXIS_SYSCLK_150:
240 case QIXIS_SYSCLK_160:
242 case QIXIS_SYSCLK_166:
249 unsigned long get_board_ddr_clk(void)
251 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
253 if (if_board_diff_clk())
254 return get_board_sys_clk();
255 switch ((ddrclk_conf & 0x30) >> 4) {
256 case QIXIS_DDRCLK_100:
258 case QIXIS_DDRCLK_125:
260 case QIXIS_DDRCLK_133:
268 u32 get_lpuart_clk(void)
274 int select_i2c_ch_pca9547(u8 ch, int bus_num)
280 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
283 printf("%s: Cannot find udev for a bus %d\n", __func__,
287 ret = dm_i2c_write(dev, 0, &ch, 1);
289 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
292 puts("PCA: failed to select proper channel\n");
302 * When resuming from deep sleep, the I2C channel may not be
303 * in the default channel. So, switch to the default channel
304 * before accessing DDR SPD.
306 * PCA9547 mount on I2C1 bus
308 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
310 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
311 defined(CONFIG_SPL_BUILD)
312 /* This will break-before-make MMU for DDR */
313 update_early_mmu_table();
319 int i2c_multiplexer_select_vid_channel(u8 channel)
321 return select_i2c_ch_pca9547(channel, 0);
324 int board_early_init_f(void)
326 #ifdef CONFIG_HAS_FSL_XHCI_USB
327 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
334 #ifdef CONFIG_SYS_I2C
335 #ifdef CONFIG_SYS_I2C_EARLY_INIT
339 fsl_lsch2_early_init_f();
341 #ifdef CONFIG_HAS_FSL_XHCI_USB
342 out_be32(&scfg->rcwpmuxcr0, 0x3333);
343 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
344 usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
345 SCFG_USBPWRFAULT_USB3_SHIFT) |
346 (SCFG_USBPWRFAULT_DEDICATED <<
347 SCFG_USBPWRFAULT_USB2_SHIFT) |
348 (SCFG_USBPWRFAULT_SHARED <<
349 SCFG_USBPWRFAULT_USB1_SHIFT);
350 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
354 /* We use lpuart0 as system console */
355 uart = QIXIS_READ(brdcfg[14]);
356 uart &= ~CFG_UART_MUX_MASK;
357 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
358 QIXIS_WRITE(brdcfg[14], uart);
364 #ifdef CONFIG_FSL_DEEP_SLEEP
365 /* determine if it is a warm boot */
366 bool is_warm_boot(void)
368 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
369 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
371 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
378 int config_board_mux(int ctrl_type)
382 reg14 = QIXIS_READ(brdcfg[14]);
386 reg14 = (reg14 & (~0x6)) | 0x2;
389 puts("Unsupported mux interface type\n");
393 QIXIS_WRITE(brdcfg[14], reg14);
398 int config_serdes_mux(void)
403 #ifdef CONFIG_MISC_INIT_R
404 int misc_init_r(void)
406 if (hwconfig("gpio"))
407 config_board_mux(MUX_TYPE_GPIO);
415 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
417 #ifdef CONFIG_SYS_FSL_SERDES
422 printf("Warning: Adjusting core voltage failed.\n");
424 #ifdef CONFIG_FSL_LS_PPA
428 #ifdef CONFIG_NXP_ESBC
430 * In case of Secure Boot, the IBR configures the SMMU
431 * to allow only Secure transactions.
432 * SMMU must be reset in bypass mode.
433 * Set the ClientPD bit and Clear the USFCFG Bit
436 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
437 out_le32(SMMU_SCR0, val);
438 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
439 out_le32(SMMU_NSCR0, val);
442 #ifdef CONFIG_FSL_CAAM
449 #ifdef CONFIG_OF_BOARD_SETUP
450 int ft_board_setup(void *blob, struct bd_info *bd)
452 u64 base[CONFIG_NR_DRAM_BANKS];
453 u64 size[CONFIG_NR_DRAM_BANKS];
456 /* fixup DT for the two DDR banks */
457 base[0] = gd->bd->bi_dram[0].start;
458 size[0] = gd->bd->bi_dram[0].size;
459 base[1] = gd->bd->bi_dram[1].start;
460 size[1] = gd->bd->bi_dram[1].size;
462 fdt_fixup_memory_banks(blob, base, size, 2);
463 ft_cpu_setup(blob, bd);
465 #ifdef CONFIG_SYS_DPAA_FMAN
466 #ifndef CONFIG_DM_ETH
467 fdt_fixup_fman_ethernet(blob);
469 fdt_fixup_board_enet(blob);
472 fdt_fixup_icid(blob);
474 reg = QIXIS_READ(brdcfg[0]);
475 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
477 /* Disable IFC if QSPI is enabled */
479 do_fixup_by_compat(blob, "fsl,ifc",
480 "status", "disabled", 8 + 1, 1);
486 u8 flash_read8(void *addr)
488 return __raw_readb(addr + 1);
491 void flash_write16(u16 val, void *addr)
493 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
495 __raw_writew(shftval, addr);
498 u16 flash_read16(void *addr)
500 u16 val = __raw_readw(addr);
502 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
505 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
506 void *env_sf_get_env_addr(void)
508 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);