1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2017-2018 NXP
14 #include <fdt_support.h>
15 #include <linux/libfdt.h>
16 #include <fsl-mc/fsl_mc.h>
17 #include <environment.h>
18 #include <asm/arch-fsl-layerscape/soc.h>
19 #include <asm/arch/ppa.h>
21 #include <asm/arch/fsl_serdes.h>
22 #include <asm/arch/soc.h>
24 #include "../common/qixis.h"
25 #include "ls1088a_qixis.h"
26 #include "../common/vid.h"
27 #include <fsl_immap.h>
29 DECLARE_GLOBAL_DATA_PTR;
31 #ifdef CONFIG_TARGET_LS1088AQDS
33 struct ifc_regs ifc_cfg_ifc_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
36 CONFIG_SYS_NOR0_CSPR_EARLY,
37 CONFIG_SYS_NOR0_CSPR_EXT,
52 CONFIG_SYS_NOR1_CSPR_EARLY,
53 CONFIG_SYS_NOR0_CSPR_EXT,
54 CONFIG_SYS_NOR_AMASK_EARLY,
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,
97 struct ifc_regs ifc_cfg_qspi_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = {
100 CONFIG_SYS_NAND_CSPR,
101 CONFIG_SYS_NAND_CSPR_EXT,
102 CONFIG_SYS_NAND_AMASK,
103 CONFIG_SYS_NAND_CSOR,
105 CONFIG_SYS_NAND_FTIM0,
106 CONFIG_SYS_NAND_FTIM1,
107 CONFIG_SYS_NAND_FTIM2,
108 CONFIG_SYS_NAND_FTIM3
116 CONFIG_SYS_FPGA_CSPR,
117 CONFIG_SYS_FPGA_CSPR_EXT,
119 CONFIG_SYS_FPGA_CSOR,
132 void ifc_cfg_boot_info(struct ifc_regs_info *regs_info)
134 enum boot_src src = get_boot_src();
136 if (src == BOOT_SOURCE_QSPI_NOR)
137 regs_info->regs = ifc_cfg_qspi_nor_boot;
139 regs_info->regs = ifc_cfg_ifc_nor_boot;
141 regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT;
143 #endif /* CONFIG_TFABOOT */
144 #endif /* CONFIG_TARGET_LS1088AQDS */
146 int board_early_init_f(void)
148 #if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_TARGET_LS1088AQDS)
151 fsl_lsch3_early_init_f();
155 #ifdef CONFIG_FSL_QIXIS
156 unsigned long long get_qixis_addr(void)
158 unsigned long long addr;
160 if (gd->flags & GD_FLG_RELOC)
161 addr = QIXIS_BASE_PHYS;
163 addr = QIXIS_BASE_PHYS_EARLY;
166 * IFC address under 256MB is mapped to 0x30000000, any address above
167 * is mapped to 0x5_10000000 up to 4GB.
169 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
175 #if defined(CONFIG_VID)
176 int init_func_vid(void)
178 if (adjust_vdd(0) < 0)
179 printf("core voltage not adjusted\n");
185 int is_pb_board(void)
189 board_id = QIXIS_READ(id);
190 if (board_id == LS1088ARDB_PB_BOARD)
196 int fixup_ls1088ardb_pb_banner(void *fdt)
198 fdt_setprop_string(fdt, 0, "model", "LS1088ARDB-PB Board");
203 #if !defined(CONFIG_SPL_BUILD)
206 #ifdef CONFIG_TFABOOT
207 enum boot_src src = get_boot_src();
211 static const char *const freq[] = {"100", "125", "156.25",
212 "100 separate SSCG"};
215 #ifdef CONFIG_TARGET_LS1088AQDS
216 printf("Board: LS1088A-QDS, ");
219 printf("Board: LS1088ARDB-PB, ");
221 printf("Board: LS1088A-RDB, ");
224 sw = QIXIS_READ(arch);
225 printf("Board Arch: V%d, ", sw >> 4);
227 #ifdef CONFIG_TARGET_LS1088AQDS
228 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
230 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
233 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
235 sw = QIXIS_READ(brdcfg[0]);
236 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
238 #ifdef CONFIG_TFABOOT
239 if (src == BOOT_SOURCE_SD_MMC)
242 #ifdef CONFIG_SD_BOOT
245 #endif /* CONFIG_TFABOOT */
247 #ifdef CONFIG_TARGET_LS1088AQDS
256 printf("vBank: %d\n", sw);
269 sw = QIXIS_READ(brdcfg[0]);
270 sw = (sw & QIXIS_QMAP_MASK) >> QIXIS_QMAP_SHIFT;
271 if (sw == 0 || sw == 4)
280 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
284 #ifdef CONFIG_TARGET_LS1088AQDS
285 printf("FPGA: v%d (%s), build %d",
286 (int)QIXIS_READ(scver), qixis_read_tag(buf),
287 (int)qixis_read_minor());
288 /* the timestamp string contains "\n" at the end */
289 printf(" on %s", qixis_read_time(buf));
291 printf("CPLD: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
295 * Display the actual SERDES reference clocks as configured by the
296 * dip switches on the board. Note that the SWx registers could
297 * technically be set to force the reference clocks to match the
298 * values that the SERDES expects (or vice versa). For now, however,
299 * we just display both values and hope the user notices when they
302 puts("SERDES1 Reference : ");
303 sw = QIXIS_READ(brdcfg[2]);
304 clock = (sw >> 6) & 3;
305 printf("Clock1 = %sMHz ", freq[clock]);
306 clock = (sw >> 4) & 3;
307 printf("Clock2 = %sMHz", freq[clock]);
309 puts("\nSERDES2 Reference : ");
310 clock = (sw >> 2) & 3;
311 printf("Clock1 = %sMHz ", freq[clock]);
312 clock = (sw >> 0) & 3;
313 printf("Clock2 = %sMHz\n", freq[clock]);
319 bool if_board_diff_clk(void)
321 #ifdef CONFIG_TARGET_LS1088AQDS
322 u8 diff_conf = QIXIS_READ(brdcfg[11]);
323 return diff_conf & 0x40;
325 u8 diff_conf = QIXIS_READ(dutcfg[11]);
326 return diff_conf & 0x80;
330 unsigned long get_board_sys_clk(void)
332 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
334 switch (sysclk_conf & 0x0f) {
335 case QIXIS_SYSCLK_83:
337 case QIXIS_SYSCLK_100:
339 case QIXIS_SYSCLK_125:
341 case QIXIS_SYSCLK_133:
343 case QIXIS_SYSCLK_150:
345 case QIXIS_SYSCLK_160:
347 case QIXIS_SYSCLK_166:
354 unsigned long get_board_ddr_clk(void)
356 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
358 if (if_board_diff_clk())
359 return get_board_sys_clk();
360 switch ((ddrclk_conf & 0x30) >> 4) {
361 case QIXIS_DDRCLK_100:
363 case QIXIS_DDRCLK_125:
365 case QIXIS_DDRCLK_133:
372 int select_i2c_ch_pca9547(u8 ch)
376 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
378 puts("PCA: failed to select proper channel\n");
385 #if !defined(CONFIG_SPL_BUILD)
386 void board_retimer_init(void)
390 /* Retimer is connected to I2C1_CH5 */
391 select_i2c_ch_pca9547(I2C_MUX_CH5);
393 /* Access to Control/Shared register */
395 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
397 /* Read device revision and ID */
398 i2c_read(I2C_RETIMER_ADDR, 1, 1, ®, 1);
399 debug("Retimer version id = 0x%x\n", reg);
401 /* Enable Broadcast. All writes target all channel register sets */
403 i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1);
405 /* Reset Channel Registers */
406 i2c_read(I2C_RETIMER_ADDR, 0, 1, ®, 1);
408 i2c_write(I2C_RETIMER_ADDR, 0, 1, ®, 1);
410 /* Set data rate as 10.3125 Gbps */
412 i2c_write(I2C_RETIMER_ADDR, 0x60, 1, ®, 1);
414 i2c_write(I2C_RETIMER_ADDR, 0x61, 1, ®, 1);
416 i2c_write(I2C_RETIMER_ADDR, 0x62, 1, ®, 1);
418 i2c_write(I2C_RETIMER_ADDR, 0x63, 1, ®, 1);
420 i2c_write(I2C_RETIMER_ADDR, 0x64, 1, ®, 1);
422 /* Select VCO Divider to full rate (000) */
423 i2c_read(I2C_RETIMER_ADDR, 0x2F, 1, ®, 1);
426 i2c_write(I2C_RETIMER_ADDR, 0x2F, 1, ®, 1);
428 #ifdef CONFIG_TARGET_LS1088AQDS
429 /* Retimer is connected to I2C1_CH5 */
430 select_i2c_ch_pca9547(I2C_MUX_CH5);
432 /* Access to Control/Shared register */
434 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, ®, 1);
436 /* Read device revision and ID */
437 i2c_read(I2C_RETIMER_ADDR2, 1, 1, ®, 1);
438 debug("Retimer version id = 0x%x\n", reg);
440 /* Enable Broadcast. All writes target all channel register sets */
442 i2c_write(I2C_RETIMER_ADDR2, 0xff, 1, ®, 1);
444 /* Reset Channel Registers */
445 i2c_read(I2C_RETIMER_ADDR2, 0, 1, ®, 1);
447 i2c_write(I2C_RETIMER_ADDR2, 0, 1, ®, 1);
449 /* Set data rate as 10.3125 Gbps */
451 i2c_write(I2C_RETIMER_ADDR2, 0x60, 1, ®, 1);
453 i2c_write(I2C_RETIMER_ADDR2, 0x61, 1, ®, 1);
455 i2c_write(I2C_RETIMER_ADDR2, 0x62, 1, ®, 1);
457 i2c_write(I2C_RETIMER_ADDR2, 0x63, 1, ®, 1);
459 i2c_write(I2C_RETIMER_ADDR2, 0x64, 1, ®, 1);
461 /* Select VCO Divider to full rate (000) */
462 i2c_read(I2C_RETIMER_ADDR2, 0x2F, 1, ®, 1);
465 i2c_write(I2C_RETIMER_ADDR2, 0x2F, 1, ®, 1);
467 /*return the default channel*/
468 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
471 #ifdef CONFIG_MISC_INIT_R
472 int misc_init_r(void)
474 #ifdef CONFIG_TARGET_LS1088ARDB
477 if (hwconfig("esdhc-force-sd")) {
478 brdcfg5 = QIXIS_READ(brdcfg[5]);
479 brdcfg5 &= ~BRDCFG5_SPISDHC_MASK;
480 brdcfg5 |= BRDCFG5_FORCE_SD;
481 QIXIS_WRITE(brdcfg[5], brdcfg5);
489 int i2c_multiplexer_select_vid_channel(u8 channel)
491 return select_i2c_ch_pca9547(channel);
494 #ifdef CONFIG_TARGET_LS1088AQDS
495 /* read the current value(SVDD) of the LTM Regulator Voltage */
496 int get_serdes_volt(void)
499 u8 chan = PWM_CHANNEL0;
501 /* Select the PAGE 0 using PMBus commands PAGE for VDD */
502 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
503 PMBUS_CMD_PAGE, 1, &chan, 1);
505 printf("VID: failed to select VDD Page 0\n");
509 /* Read the output voltage using PMBus command READ_VOUT */
510 ret = i2c_read(I2C_SVDD_MONITOR_ADDR,
511 PMBUS_CMD_READ_VOUT, 1, (void *)&vcode, 2);
513 printf("VID: failed to read the volatge\n");
520 int set_serdes_volt(int svdd)
523 u8 buff[5] = {0x04, PWM_CHANNEL0, PMBUS_CMD_VOUT_COMMAND,
524 svdd & 0xFF, (svdd & 0xFF00) >> 8};
526 /* Write the desired voltage code to the SVDD regulator */
527 ret = i2c_write(I2C_SVDD_MONITOR_ADDR,
528 PMBUS_CMD_PAGE_PLUS_WRITE, 1, (void *)&buff, 5);
530 printf("VID: I2C failed to write to the volatge regulator\n");
534 /* Wait for the volatge to get to the desired value */
536 vdd_last = get_serdes_volt();
538 printf("VID: Couldn't read sensor abort VID adjust\n");
541 } while (vdd_last != svdd);
546 int get_serdes_volt(void)
551 int set_serdes_volt(int svdd)
556 printf("SVDD changing of RDB\n");
558 /* Read the BRDCFG54 via CLPD */
559 ret = i2c_read(CONFIG_SYS_I2C_FPGA_ADDR,
560 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
562 printf("VID: I2C failed to read the CPLD BRDCFG4\n");
566 brdcfg4 = brdcfg4 | 0x08;
568 /* Write to the BRDCFG4 */
569 ret = i2c_write(CONFIG_SYS_I2C_FPGA_ADDR,
570 QIXIS_BRDCFG4_OFFSET, 1, (void *)&brdcfg4, 1);
572 debug("VID: I2C failed to set the SVDD CPLD BRDCFG4\n");
576 /* Wait for the volatge to get to the desired value */
583 /* this function disables the SERDES, changes the SVDD Voltage and enables it*/
584 int board_adjust_vdd(int vdd)
588 debug("%s: vdd = %d\n", __func__, vdd);
590 /* Special settings to be performed when voltage is 900mV */
592 ret = setup_serdes_volt(vdd);
602 #if !defined(CONFIG_SPL_BUILD)
605 init_final_memctl_regs();
606 #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
607 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
610 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
611 board_retimer_init();
613 #ifdef CONFIG_ENV_IS_NOWHERE
614 gd->env_addr = (ulong)&default_environment[0];
617 #if defined(CONFIG_TARGET_LS1088ARDB) && defined(CONFIG_FSL_MC_ENET)
618 /* invert AQR105 IRQ pins polarity */
619 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR105_IRQ_MASK);
622 #ifdef CONFIG_FSL_CAAM
625 #ifdef CONFIG_FSL_LS_PPA
631 void detail_board_ddr_info(void)
634 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
638 #if defined(CONFIG_ARCH_MISC_INIT)
639 int arch_misc_init(void)
645 #ifdef CONFIG_FSL_MC_ENET
646 void board_quiesce_devices(void)
648 fsl_mc_ldpaa_exit(gd->bd);
651 void fdt_fixup_board_enet(void *fdt)
655 offset = fdt_path_offset(fdt, "/fsl-mc");
658 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
661 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
666 if (get_mc_boot_status() == 0 &&
667 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
668 fdt_status_okay(fdt, offset);
670 fdt_status_fail(fdt, offset);
674 #ifdef CONFIG_OF_BOARD_SETUP
675 void fsl_fdt_fixup_flash(void *fdt)
678 #ifdef CONFIG_TFABOOT
679 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
684 * IFC-NOR and QSPI are muxed on SoC.
685 * So disable IFC node in dts if QSPI is enabled or
686 * disable QSPI node in dts in case QSPI is not enabled.
689 #ifdef CONFIG_TFABOOT
690 enum boot_src src = get_boot_src();
691 bool disable_ifc = false;
694 case BOOT_SOURCE_IFC_NOR:
697 case BOOT_SOURCE_QSPI_NOR:
701 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
702 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
708 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
711 offset = fdt_path_offset(fdt, "/ifc/nor");
713 offset = fdt_path_offset(fdt, "/soc/quadspi");
716 offset = fdt_path_offset(fdt, "/quadspi");
720 #ifdef CONFIG_FSL_QSPI
721 offset = fdt_path_offset(fdt, "/soc/ifc/nor");
724 offset = fdt_path_offset(fdt, "/ifc/nor");
726 offset = fdt_path_offset(fdt, "/soc/quadspi");
729 offset = fdt_path_offset(fdt, "/quadspi");
735 fdt_status_disabled(fdt, offset);
738 int ft_board_setup(void *blob, bd_t *bd)
741 u64 base[CONFIG_NR_DRAM_BANKS];
742 u64 size[CONFIG_NR_DRAM_BANKS];
744 ft_cpu_setup(blob, bd);
746 /* fixup DT for the two GPP DDR banks */
747 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
748 base[i] = gd->bd->bi_dram[i].start;
749 size[i] = gd->bd->bi_dram[i].size;
752 #ifdef CONFIG_RESV_RAM
753 /* reduce size if reserved memory is within this bank */
754 if (gd->arch.resv_ram >= base[0] &&
755 gd->arch.resv_ram < base[0] + size[0])
756 size[0] = gd->arch.resv_ram - base[0];
757 else if (gd->arch.resv_ram >= base[1] &&
758 gd->arch.resv_ram < base[1] + size[1])
759 size[1] = gd->arch.resv_ram - base[1];
762 fdt_fixup_memory_banks(blob, base, size, CONFIG_NR_DRAM_BANKS);
764 fdt_fsl_mc_fixup_iommu_map_entry(blob);
766 fsl_fdt_fixup_flash(blob);
768 #ifdef CONFIG_FSL_MC_ENET
769 fdt_fixup_board_enet(blob);
772 fixup_ls1088ardb_pb_banner(blob);
777 #endif /* defined(CONFIG_SPL_BUILD) */
779 #ifdef CONFIG_TFABOOT
780 #ifdef CONFIG_MTD_NOR_FLASH
781 int is_flash_available(void)
783 char *env_hwconfig = env_get("hwconfig");
784 enum boot_src src = get_boot_src();
785 int is_nor_flash_available = 1;
788 case BOOT_SOURCE_IFC_NOR:
789 is_nor_flash_available = 1;
791 case BOOT_SOURCE_QSPI_NOR:
792 is_nor_flash_available = 0;
795 * In Case of SD boot,if qspi is defined in env_hwconfig
796 * disable nor flash probe.
799 if (hwconfig_f("qspi", env_hwconfig))
800 is_nor_flash_available = 0;
803 return is_nor_flash_available;
807 void *env_sf_get_env_addr(void)
809 return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET);