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 <env_internal.h>
20 #include <asm/arch/soc.h>
23 #include <asm/arch/ppa.h>
24 #include <asm/arch-fsl-layerscape/fsl_icid.h>
27 #include "../common/qixis.h"
28 #include "ls2080aqds_qixis.h"
29 #include "../common/vid.h"
31 #define PIN_MUX_SEL_SDHC 0x00
32 #define PIN_MUX_SEL_DSPI 0x0a
33 #define SCFG_QSPICLKCTRL_DIV_20 (5 << 27)
35 #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
37 DECLARE_GLOBAL_DATA_PTR;
44 unsigned long long get_qixis_addr(void)
46 unsigned long long addr;
48 if (gd->flags & GD_FLG_RELOC)
49 addr = QIXIS_BASE_PHYS;
51 addr = QIXIS_BASE_PHYS_EARLY;
54 * IFC address under 256MB is mapped to 0x30000000, any address above
55 * is mapped to 0x5_10000000 up to 4GB.
57 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
66 static const char *const freq[] = {"100", "125", "156.25",
71 printf("Board: %s-QDS, ", buf);
73 sw = QIXIS_READ(arch);
74 printf("Board Arch: V%d, ", sw >> 4);
75 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
77 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
79 sw = QIXIS_READ(brdcfg[0]);
80 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
83 printf("vBank: %d\n", sw);
93 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
95 printf("FPGA: v%d (%s), build %d",
96 (int)QIXIS_READ(scver), qixis_read_tag(buf),
97 (int)qixis_read_minor());
98 /* the timestamp string contains "\n" at the end */
99 printf(" on %s", qixis_read_time(buf));
102 * Display the actual SERDES reference clocks as configured by the
103 * dip switches on the board. Note that the SWx registers could
104 * technically be set to force the reference clocks to match the
105 * values that the SERDES expects (or vice versa). For now, however,
106 * we just display both values and hope the user notices when they
109 puts("SERDES1 Reference : ");
110 sw = QIXIS_READ(brdcfg[2]);
111 clock = (sw >> 6) & 3;
112 printf("Clock1 = %sMHz ", freq[clock]);
113 clock = (sw >> 4) & 3;
114 printf("Clock2 = %sMHz", freq[clock]);
116 puts("\nSERDES2 Reference : ");
117 clock = (sw >> 2) & 3;
118 printf("Clock1 = %sMHz ", freq[clock]);
119 clock = (sw >> 0) & 3;
120 printf("Clock2 = %sMHz\n", freq[clock]);
125 unsigned long get_board_sys_clk(void)
127 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
129 switch (sysclk_conf & 0x0F) {
130 case QIXIS_SYSCLK_83:
132 case QIXIS_SYSCLK_100:
134 case QIXIS_SYSCLK_125:
136 case QIXIS_SYSCLK_133:
138 case QIXIS_SYSCLK_150:
140 case QIXIS_SYSCLK_160:
142 case QIXIS_SYSCLK_166:
148 unsigned long get_board_ddr_clk(void)
150 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
152 switch ((ddrclk_conf & 0x30) >> 4) {
153 case QIXIS_DDRCLK_100:
155 case QIXIS_DDRCLK_125:
157 case QIXIS_DDRCLK_133:
163 int select_i2c_ch_pca9547(u8 ch)
169 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
171 ret = dm_i2c_write(dev, 0, &ch, 1);
174 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
177 puts("PCA: failed to select proper channel\n");
184 int config_board_mux(int ctrl_type)
188 reg5 = QIXIS_READ(brdcfg[5]);
192 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
195 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
198 printf("Wrong mux interface type\n");
202 QIXIS_WRITE(brdcfg[5], reg5);
210 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
213 init_final_memctl_regs();
215 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
217 env_hwconfig = env_get("hwconfig");
219 if (hwconfig_f("dspi", env_hwconfig) &&
220 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
221 config_board_mux(MUX_TYPE_DSPI);
223 config_board_mux(MUX_TYPE_SDHC);
225 #if defined(CONFIG_MTD_RAW_NAND) && defined(CONFIG_FSL_QSPI)
226 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
228 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
229 QIXIS_WRITE(brdcfg[9],
230 (QIXIS_READ(brdcfg[9]) & 0xf8) |
231 FSL_QIXIS_BRDCFG9_QSPI);
234 #ifdef CONFIG_ENV_IS_NOWHERE
235 gd->env_addr = (ulong)&default_environment[0];
237 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
239 #ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
241 rtc_enable_32khz_output(0, CONFIG_SYS_I2C_RTC_ADDR);
243 rtc_enable_32khz_output();
247 #ifdef CONFIG_FSL_CAAM
251 #ifdef CONFIG_FSL_LS_PPA
255 #if !defined(CONFIG_SYS_EARLY_PCI_INIT) && defined(CONFIG_DM_ETH)
262 int board_early_init_f(void)
264 #ifdef CONFIG_SYS_I2C_EARLY_INIT
267 fsl_lsch3_early_init_f();
268 #ifdef CONFIG_FSL_QSPI
269 /* input clk: 1/2 platform clk, output: input/20 */
270 out_le32(SCFG_BASE + SCFG_QSPICLKCTLR, SCFG_QSPICLKCTRL_DIV_20);
275 int misc_init_r(void)
278 printf("Warning: Adjusting core voltage failed.\n");
283 void detail_board_ddr_info(void)
286 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
288 #ifdef CONFIG_SYS_FSL_HAS_DP_DDR
289 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
291 print_size(gd->bd->bi_dram[2].size, "");
292 print_ddr_info(CONFIG_DP_DDR_CTRL);
297 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
298 void fdt_fixup_board_enet(void *fdt)
302 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
305 offset = fdt_path_offset(fdt, "/fsl-mc");
308 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
313 if (get_mc_boot_status() == 0 &&
314 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0))
315 fdt_status_okay(fdt, offset);
317 fdt_status_fail(fdt, offset);
320 void board_quiesce_devices(void)
322 fsl_mc_ldpaa_exit(gd->bd);
326 #ifdef CONFIG_OF_BOARD_SETUP
327 int ft_board_setup(void *blob, bd_t *bd)
329 u64 base[CONFIG_NR_DRAM_BANKS];
330 u64 size[CONFIG_NR_DRAM_BANKS];
332 ft_cpu_setup(blob, bd);
334 /* fixup DT for the two GPP DDR banks */
335 base[0] = gd->bd->bi_dram[0].start;
336 size[0] = gd->bd->bi_dram[0].size;
337 base[1] = gd->bd->bi_dram[1].start;
338 size[1] = gd->bd->bi_dram[1].size;
340 #ifdef CONFIG_RESV_RAM
341 /* reduce size if reserved memory is within this bank */
342 if (gd->arch.resv_ram >= base[0] &&
343 gd->arch.resv_ram < base[0] + size[0])
344 size[0] = gd->arch.resv_ram - base[0];
345 else if (gd->arch.resv_ram >= base[1] &&
346 gd->arch.resv_ram < base[1] + size[1])
347 size[1] = gd->arch.resv_ram - base[1];
350 fdt_fixup_memory_banks(blob, base, size, 2);
352 fdt_fsl_mc_fixup_iommu_map_entry(blob);
354 fsl_fdt_fixup_dr_usb(blob, bd);
356 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
357 fdt_fixup_board_enet(blob);
360 fdt_fixup_icid(blob);
366 void qixis_dump_switch(void)
370 QIXIS_WRITE(cms[0], 0x00);
371 nr_of_cfgsw = QIXIS_READ(cms[1]);
373 puts("DIP switch settings dump:\n");
374 for (i = 1; i <= nr_of_cfgsw; i++) {
375 QIXIS_WRITE(cms[0], i);
376 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));