1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2015 Freescale Semiconductor, Inc.
4 * Copyright 2019-2020 NXP
9 #include <fdt_support.h>
10 #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>
28 #include <fsl_esdhc.h>
32 #include "../common/qixis.h"
33 #include "ls1043aqds_qixis.h"
35 DECLARE_GLOBAL_DATA_PTR;
41 /* LS1043AQDS serdes mux */
42 #define CFG_SD_MUX1_SLOT2 0x0 /* SLOT2 TX/RX0 */
43 #define CFG_SD_MUX1_SLOT1 0x1 /* SLOT1 TX/RX1 */
44 #define CFG_SD_MUX2_SLOT3 0x0 /* SLOT3 TX/RX0 */
45 #define CFG_SD_MUX2_SLOT1 0x1 /* SLOT1 TX/RX2 */
46 #define CFG_SD_MUX3_SLOT4 0x0 /* SLOT4 TX/RX0 */
47 #define CFG_SD_MUX3_MUX4 0x1 /* MUX4 */
48 #define CFG_SD_MUX4_SLOT3 0x0 /* SLOT3 TX/RX1 */
49 #define CFG_SD_MUX4_SLOT1 0x1 /* SLOT1 TX/RX3 */
50 #define CFG_UART_MUX_MASK 0x6
51 #define CFG_UART_MUX_SHIFT 1
52 #define CFG_LPUART_EN 0x1
54 #ifdef CONFIG_SYS_I2C_EARLY_INIT
55 void i2c_early_init_f(void);
59 struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
63 CONFIG_SYS_NOR0_CSPR_EXT,
77 CONFIG_SYS_NOR1_CSPR_EXT,
90 CONFIG_SYS_NAND_CSPR_EXT,
91 CONFIG_SYS_NAND_AMASK,
94 CONFIG_SYS_NAND_FTIM0,
95 CONFIG_SYS_NAND_FTIM1,
96 CONFIG_SYS_NAND_FTIM2,
102 CONFIG_SYS_FPGA_CSPR,
103 CONFIG_SYS_FPGA_CSPR_EXT,
104 CONFIG_SYS_FPGA_AMASK,
105 CONFIG_SYS_FPGA_CSOR,
107 CONFIG_SYS_FPGA_FTIM0,
108 CONFIG_SYS_FPGA_FTIM1,
109 CONFIG_SYS_FPGA_FTIM2,
110 CONFIG_SYS_FPGA_FTIM3
115 struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
118 CONFIG_SYS_NAND_CSPR,
119 CONFIG_SYS_NAND_CSPR_EXT,
120 CONFIG_SYS_NAND_AMASK,
121 CONFIG_SYS_NAND_CSOR,
123 CONFIG_SYS_NAND_FTIM0,
124 CONFIG_SYS_NAND_FTIM1,
125 CONFIG_SYS_NAND_FTIM2,
126 CONFIG_SYS_NAND_FTIM3
131 CONFIG_SYS_NOR0_CSPR,
132 CONFIG_SYS_NOR0_CSPR_EXT,
133 CONFIG_SYS_NOR_AMASK,
136 CONFIG_SYS_NOR_FTIM0,
137 CONFIG_SYS_NOR_FTIM1,
138 CONFIG_SYS_NOR_FTIM2,
144 CONFIG_SYS_NOR1_CSPR,
145 CONFIG_SYS_NOR1_CSPR_EXT,
146 CONFIG_SYS_NOR_AMASK,
149 CONFIG_SYS_NOR_FTIM0,
150 CONFIG_SYS_NOR_FTIM1,
151 CONFIG_SYS_NOR_FTIM2,
157 CONFIG_SYS_FPGA_CSPR,
158 CONFIG_SYS_FPGA_CSPR_EXT,
159 CONFIG_SYS_FPGA_AMASK,
160 CONFIG_SYS_FPGA_CSOR,
162 CONFIG_SYS_FPGA_FTIM0,
163 CONFIG_SYS_FPGA_FTIM1,
164 CONFIG_SYS_FPGA_FTIM2,
165 CONFIG_SYS_FPGA_FTIM3
170 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
172 enum boot_src src = get_boot_src();
174 if (src == BOOT_SOURCE_IFC_NAND)
175 regs_info->regs = ifc_cfg_nand_boot;
177 regs_info->regs = ifc_cfg_nor_boot;
178 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
184 #ifdef CONFIG_TFABOOT
185 enum boot_src src = get_boot_src();
188 #ifndef CONFIG_SD_BOOT
192 puts("Board: LS1043AQDS, boot from ");
194 #ifdef CONFIG_TFABOOT
195 if (src == BOOT_SOURCE_SD_MMC)
200 #ifdef CONFIG_SD_BOOT
203 sw = QIXIS_READ(brdcfg[0]);
204 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
207 printf("vBank: %d\n", sw);
215 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
218 #ifdef CONFIG_TFABOOT
221 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
222 QIXIS_READ(id), QIXIS_READ(arch));
224 printf("FPGA: v%d (%s), build %d\n",
225 (int)QIXIS_READ(scver), qixis_read_tag(buf),
226 (int)qixis_read_minor());
231 bool if_board_diff_clk(void)
233 u8 diff_conf = QIXIS_READ(brdcfg[11]);
235 return diff_conf & 0x40;
238 unsigned long get_board_sys_clk(void)
240 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
242 switch (sysclk_conf & 0x0f) {
243 case QIXIS_SYSCLK_64:
245 case QIXIS_SYSCLK_83:
247 case QIXIS_SYSCLK_100:
249 case QIXIS_SYSCLK_125:
251 case QIXIS_SYSCLK_133:
253 case QIXIS_SYSCLK_150:
255 case QIXIS_SYSCLK_160:
257 case QIXIS_SYSCLK_166:
264 unsigned long get_board_ddr_clk(void)
266 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
268 if (if_board_diff_clk())
269 return get_board_sys_clk();
270 switch ((ddrclk_conf & 0x30) >> 4) {
271 case QIXIS_DDRCLK_100:
273 case QIXIS_DDRCLK_125:
275 case QIXIS_DDRCLK_133:
282 int select_i2c_ch_pca9547(u8 ch, int bus_num)
289 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
292 printf("%s: Cannot find udev for a bus %d\n", __func__,
296 ret = dm_i2c_write(dev, 0, &ch, 1);
298 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
301 puts("PCA: failed to select proper channel\n");
311 * When resuming from deep sleep, the I2C channel may not be
312 * in the default channel. So, switch to the default channel
313 * before accessing DDR SPD.
315 * PCA9547 mount on I2C1 bus
317 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
319 #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \
320 defined(CONFIG_SPL_BUILD)
321 /* This will break-before-make MMU for DDR */
322 update_early_mmu_table();
328 int i2c_multiplexer_select_vid_channel(u8 channel)
330 return select_i2c_ch_pca9547(channel, 0);
333 void board_retimer_init(void)
338 /* Retimer is connected to I2C1_CH7_CH5 */
339 select_i2c_ch_pca9547(I2C_MUX_CH7, bus_num);
345 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_SEC,
348 printf("%s: Cannot find udev for a bus %d\n", __func__,
352 dm_i2c_write(dev, 0, ®, 1);
354 /* Access to Control/Shared register */
355 ret = i2c_get_chip_for_busnum(bus_num, I2C_RETIMER_ADDR,
358 printf("%s: Cannot find udev for a bus %d\n", __func__,
364 dm_i2c_write(dev, 0xff, ®, 1);
366 /* Read device revision and ID */
367 dm_i2c_read(dev, 1, ®, 1);
368 debug("Retimer version id = 0x%x\n", reg);
370 /* Enable Broadcast. All writes target all channel register sets */
372 dm_i2c_write(dev, 0xff, ®, 1);
374 /* Reset Channel Registers */
375 dm_i2c_read(dev, 0, ®, 1);
377 dm_i2c_write(dev, 0, ®, 1);
379 /* Enable override divider select and Enable Override Output Mux */
380 dm_i2c_read(dev, 9, ®, 1);
382 dm_i2c_write(dev, 9, ®, 1);
384 /* Select VCO Divider to full rate (000) */
385 dm_i2c_read(dev, 0x18, ®, 1);
387 dm_i2c_write(dev, 0x18, ®, 1);
389 /* Selects active PFD MUX Input as Re-timed Data (001) */
390 dm_i2c_read(dev, 0x1e, ®, 1);
393 dm_i2c_write(dev, 0x1e, ®, 1);
395 /* Set data rate as 10.3125 Gbps */
397 dm_i2c_write(dev, 0x60, ®, 1);
399 dm_i2c_write(dev, 0x61, ®, 1);
401 dm_i2c_write(dev, 0x62, ®, 1);
403 dm_i2c_write(dev, 0x63, ®, 1);
405 dm_i2c_write(dev, 0x64, ®, 1);
407 i2c_write(I2C_MUX_PCA_ADDR_SEC, 0, 1, ®, 1);
409 /* Access to Control/Shared register */
411 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
413 /* Read device revision and ID */
414 i2c_read(I2C_RETIMER_ADDR, 1, 1, ®, 1);
415 debug("Retimer version id = 0x%x\n", reg);
417 /* Enable Broadcast. All writes target all channel register sets */
419 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
421 /* Reset Channel Registers */
422 i2c_read(I2C_RETIMER_ADDR, 0, 1, ®, 1);
424 i2c_write(I2C_RETIMER_ADDR, 0, 1, ®, 1);
426 /* Enable override divider select and Enable Override Output Mux */
427 i2c_read(I2C_RETIMER_ADDR, 9, 1, ®, 1);
429 i2c_write(I2C_RETIMER_ADDR, 9, 1, ®, 1);
431 /* Select VCO Divider to full rate (000) */
432 i2c_read(I2C_RETIMER_ADDR, 0x18, 1, ®, 1);
434 i2c_write(I2C_RETIMER_ADDR, 0x18, 1, ®, 1);
436 /* Selects active PFD MUX Input as Re-timed Data (001) */
437 i2c_read(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1);
440 i2c_write(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1);
442 /* Set data rate as 10.3125 Gbps */
444 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, ®, 1);
446 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, ®, 1);
448 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, ®, 1);
450 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, ®, 1);
452 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, ®, 1);
455 /* Return the default channel */
456 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, bus_num);
459 int board_early_init_f(void)
461 u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR;
462 #ifdef CONFIG_HAS_FSL_XHCI_USB
463 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
471 * Enable secure system counter for timer
473 out_le32(cntcr, 0x1);
475 #ifdef CONFIG_SYS_I2C_EARLY_INIT
478 fsl_lsch2_early_init_f();
480 #ifdef CONFIG_HAS_FSL_XHCI_USB
481 out_be32(&scfg->rcwpmuxcr0, 0x3333);
482 out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
484 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB3_SHIFT) |
485 (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB2_SHIFT) |
486 (SCFG_USBPWRFAULT_SHARED << SCFG_USBPWRFAULT_USB1_SHIFT);
487 out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
491 /* We use lpuart0 as system console */
492 uart = QIXIS_READ(brdcfg[14]);
493 uart &= ~CFG_UART_MUX_MASK;
494 uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
495 QIXIS_WRITE(brdcfg[14], uart);
501 #ifdef CONFIG_FSL_DEEP_SLEEP
502 /* determine if it is a warm boot */
503 bool is_warm_boot(void)
505 #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
506 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
508 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
515 int config_board_mux(int ctrl_type)
519 reg14 = QIXIS_READ(brdcfg[14]);
523 reg14 = (reg14 & (~0x30)) | 0x20;
526 puts("Unsupported mux interface type\n");
530 QIXIS_WRITE(brdcfg[14], reg14);
535 int config_serdes_mux(void)
541 #ifdef CONFIG_MISC_INIT_R
542 int misc_init_r(void)
544 if (hwconfig("gpio"))
545 config_board_mux(MUX_TYPE_GPIO);
553 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
557 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
558 board_retimer_init();
560 #ifdef CONFIG_SYS_FSL_SERDES
564 #ifdef CONFIG_FSL_LS_PPA
571 #ifdef CONFIG_OF_BOARD_SETUP
572 int ft_board_setup(void *blob, struct bd_info *bd)
574 u64 base[CONFIG_NR_DRAM_BANKS];
575 u64 size[CONFIG_NR_DRAM_BANKS];
578 /* fixup DT for the two DDR banks */
579 base[0] = gd->bd->bi_dram[0].start;
580 size[0] = gd->bd->bi_dram[0].size;
581 base[1] = gd->bd->bi_dram[1].start;
582 size[1] = gd->bd->bi_dram[1].size;
584 fdt_fixup_memory_banks(blob, base, size, 2);
585 ft_cpu_setup(blob, bd);
587 #ifdef CONFIG_SYS_DPAA_FMAN
588 #ifndef CONFIG_DM_ETH
589 fdt_fixup_fman_ethernet(blob);
591 fdt_fixup_board_enet(blob);
594 fdt_fixup_icid(blob);
596 reg = QIXIS_READ(brdcfg[0]);
597 reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
599 /* Disable IFC if QSPI is enabled */
601 do_fixup_by_compat(blob, "fsl,ifc",
602 "status", "disabled", 8 + 1, 1);
608 u8 flash_read8(void *addr)
610 return __raw_readb(addr + 1);
613 void flash_write16(u16 val, void *addr)
615 u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
617 __raw_writew(shftval, addr);
620 u16 flash_read16(void *addr)
622 u16 val = __raw_readw(addr);
624 return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
627 #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH)
628 void *env_sf_get_env_addr(void)
630 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);