1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2015 Freescale Semiconductor
14 #include <fdt_support.h>
15 #include <linux/libfdt.h>
16 #include <fsl-mc/fsl_mc.h>
17 #include <environment.h>
18 #include <efi_loader.h>
20 #include <asm/arch/mmu.h>
21 #include <asm/arch/soc.h>
22 #include <asm/arch/ppa.h>
25 #ifdef CONFIG_FSL_QIXIS
26 #include "../common/qixis.h"
27 #include "ls2080ardb_qixis.h"
29 #include "../common/vid.h"
31 #define PIN_MUX_SEL_SDHC 0x00
32 #define PIN_MUX_SEL_DSPI 0x0a
34 #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
35 DECLARE_GLOBAL_DATA_PTR;
42 unsigned long long get_qixis_addr(void)
44 unsigned long long addr;
46 if (gd->flags & GD_FLG_RELOC)
47 addr = QIXIS_BASE_PHYS;
49 addr = QIXIS_BASE_PHYS_EARLY;
52 * IFC address under 256MB is mapped to 0x30000000, any address above
53 * is mapped to 0x5_10000000 up to 4GB.
55 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
62 #ifdef CONFIG_FSL_QIXIS
68 printf("Board: %s-RDB, ", buf);
70 #ifdef CONFIG_TARGET_LS2081ARDB
71 #ifdef CONFIG_FSL_QIXIS
72 sw = QIXIS_READ(arch);
73 printf("Board version: %c, ", (sw & 0xf) + 'A');
75 sw = QIXIS_READ(brdcfg[0]);
76 sw = (sw >> QIXIS_QMAP_SHIFT) & QIXIS_QMAP_MASK;
79 puts("boot from QSPI DEV#0\n");
80 puts("QSPI_CSA_1 mapped to QSPI DEV#1\n");
83 puts("boot from QSPI DEV#1\n");
84 puts("QSPI_CSA_1 mapped to QSPI DEV#0\n");
87 puts("boot from QSPI EMU\n");
88 puts("QSPI_CSA_1 mapped to QSPI DEV#0\n");
91 puts("boot from QSPI EMU\n");
92 puts("QSPI_CSA_1 mapped to QSPI DEV#1\n");
95 puts("boot from QSPI DEV#0\n");
96 puts("QSPI_CSA_1 mapped to QSPI EMU\n");
99 printf("invalid setting of SW%u\n", sw);
102 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
104 puts("SERDES1 Reference : ");
105 printf("Clock1 = 100MHz ");
106 printf("Clock2 = 161.13MHz");
108 #ifdef CONFIG_FSL_QIXIS
109 sw = QIXIS_READ(arch);
110 printf("Board Arch: V%d, ", sw >> 4);
111 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
113 sw = QIXIS_READ(brdcfg[0]);
114 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
117 printf("vBank: %d\n", sw);
121 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
123 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
125 puts("SERDES1 Reference : ");
126 printf("Clock1 = 156.25MHz ");
127 printf("Clock2 = 156.25MHz");
130 puts("\nSERDES2 Reference : ");
131 printf("Clock1 = 100MHz ");
132 printf("Clock2 = 100MHz\n");
137 unsigned long get_board_sys_clk(void)
139 #ifdef CONFIG_FSL_QIXIS
140 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
142 switch (sysclk_conf & 0x0F) {
143 case QIXIS_SYSCLK_83:
145 case QIXIS_SYSCLK_100:
147 case QIXIS_SYSCLK_125:
149 case QIXIS_SYSCLK_133:
151 case QIXIS_SYSCLK_150:
153 case QIXIS_SYSCLK_160:
155 case QIXIS_SYSCLK_166:
162 int select_i2c_ch_pca9547(u8 ch)
166 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
168 puts("PCA: failed to select proper channel\n");
175 int i2c_multiplexer_select_vid_channel(u8 channel)
177 return select_i2c_ch_pca9547(channel);
180 int config_board_mux(int ctrl_type)
182 #ifdef CONFIG_FSL_QIXIS
185 reg5 = QIXIS_READ(brdcfg[5]);
189 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
192 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
195 printf("Wrong mux interface type\n");
199 QIXIS_WRITE(brdcfg[5], reg5);
206 #ifdef CONFIG_FSL_MC_ENET
207 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
210 init_final_memctl_regs();
212 #ifdef CONFIG_ENV_IS_NOWHERE
213 gd->env_addr = (ulong)&default_environment[0];
215 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
217 #ifdef CONFIG_FSL_QIXIS
218 QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET_EN);
221 #ifdef CONFIG_FSL_CAAM
224 #ifdef CONFIG_FSL_LS_PPA
228 #ifdef CONFIG_FSL_MC_ENET
229 /* invert AQR405 IRQ pins polarity */
230 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR405_IRQ_MASK);
232 #ifdef CONFIG_FSL_CAAM
239 int board_early_init_f(void)
241 #ifdef CONFIG_SYS_I2C_EARLY_INIT
244 fsl_lsch3_early_init_f();
248 int misc_init_r(void)
251 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
253 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
254 u32 svr = gur_in32(&gur->svr);
256 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
258 env_hwconfig = env_get("hwconfig");
260 if (hwconfig_f("dspi", env_hwconfig) &&
261 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
262 config_board_mux(MUX_TYPE_DSPI);
264 config_board_mux(MUX_TYPE_SDHC);
267 * LS2081ARDB RevF board has smart voltage translator
268 * which needs to be programmed to enable high speed SD interface
269 * by setting GPIO4_10 output to zero
271 #ifdef CONFIG_TARGET_LS2081ARDB
272 out_le32(GPIO4_GPDIR_ADDR, (1 << 21 |
273 in_le32(GPIO4_GPDIR_ADDR)));
274 out_le32(GPIO4_GPDAT_ADDR, (~(1 << 21) &
275 in_le32(GPIO4_GPDAT_ADDR)));
277 if (hwconfig("sdhc"))
278 config_board_mux(MUX_TYPE_SDHC);
281 printf("Warning: Adjusting core voltage failed.\n");
283 * Default value of board env is based on filename which is
284 * ls2080ardb. Modify board env for other supported SoCs
286 if ((SVR_SOC_VER(svr) == SVR_LS2088A) ||
287 (SVR_SOC_VER(svr) == SVR_LS2048A))
288 env_set("board", "ls2088ardb");
289 else if ((SVR_SOC_VER(svr) == SVR_LS2081A) ||
290 (SVR_SOC_VER(svr) == SVR_LS2041A))
291 env_set("board", "ls2081ardb");
296 void detail_board_ddr_info(void)
299 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
301 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
302 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
304 print_size(gd->bd->bi_dram[2].size, "");
305 print_ddr_info(CONFIG_DP_DDR_CTRL);
310 #if defined(CONFIG_ARCH_MISC_INIT)
311 int arch_misc_init(void)
317 #ifdef CONFIG_FSL_MC_ENET
318 void fdt_fixup_board_enet(void *fdt)
322 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
325 offset = fdt_path_offset(fdt, "/fsl-mc");
328 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
333 if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0))
334 fdt_status_okay(fdt, offset);
336 fdt_status_fail(fdt, offset);
339 void board_quiesce_devices(void)
341 fsl_mc_ldpaa_exit(gd->bd);
345 #ifdef CONFIG_OF_BOARD_SETUP
346 void fsl_fdt_fixup_flash(void *fdt)
351 * IFC and QSPI are muxed on board.
352 * So disable IFC node in dts if QSPI is enabled or
353 * disable QSPI node in dts in case QSPI is not enabled.
355 #ifdef CONFIG_FSL_QSPI
356 offset = fdt_path_offset(fdt, "/soc/ifc");
359 offset = fdt_path_offset(fdt, "/ifc");
361 offset = fdt_path_offset(fdt, "/soc/quadspi");
364 offset = fdt_path_offset(fdt, "/quadspi");
369 fdt_status_disabled(fdt, offset);
372 int ft_board_setup(void *blob, bd_t *bd)
374 u64 base[CONFIG_NR_DRAM_BANKS];
375 u64 size[CONFIG_NR_DRAM_BANKS];
377 ft_cpu_setup(blob, bd);
379 /* fixup DT for the two GPP DDR banks */
380 base[0] = gd->bd->bi_dram[0].start;
381 size[0] = gd->bd->bi_dram[0].size;
382 base[1] = gd->bd->bi_dram[1].start;
383 size[1] = gd->bd->bi_dram[1].size;
385 #ifdef CONFIG_RESV_RAM
386 /* reduce size if reserved memory is within this bank */
387 if (gd->arch.resv_ram >= base[0] &&
388 gd->arch.resv_ram < base[0] + size[0])
389 size[0] = gd->arch.resv_ram - base[0];
390 else if (gd->arch.resv_ram >= base[1] &&
391 gd->arch.resv_ram < base[1] + size[1])
392 size[1] = gd->arch.resv_ram - base[1];
395 fdt_fixup_memory_banks(blob, base, size, 2);
397 fdt_fsl_mc_fixup_iommu_map_entry(blob);
399 fsl_fdt_fixup_dr_usb(blob, bd);
401 fsl_fdt_fixup_flash(blob);
403 #ifdef CONFIG_FSL_MC_ENET
404 fdt_fixup_board_enet(blob);
411 void qixis_dump_switch(void)
413 #ifdef CONFIG_FSL_QIXIS
416 QIXIS_WRITE(cms[0], 0x00);
417 nr_of_cfgsw = QIXIS_READ(cms[1]);
419 puts("DIP switch settings dump:\n");
420 for (i = 1; i <= nr_of_cfgsw; i++) {
421 QIXIS_WRITE(cms[0], i);
422 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
428 * Board rev C and earlier has duplicated I2C addresses for 2nd controller.
429 * Both slots has 0x54, resulting 2nd slot unusable.
431 void update_spd_address(unsigned int ctrl_num,
435 #ifndef CONFIG_TARGET_LS2081ARDB
436 #ifdef CONFIG_FSL_QIXIS
439 sw = QIXIS_READ(arch);
440 if ((sw & 0xf) < 0x3) {
441 if (ctrl_num == 1 && slot == 0)
442 *addr = SPD_EEPROM_ADDRESS4;
443 else if (ctrl_num == 1 && slot == 1)
444 *addr = SPD_EEPROM_ADDRESS3;