1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2018-2020 NXP
7 #include <clock_legacy.h>
9 #include <dm/platform_data/serial_pl01x.h>
17 #include <fdt_support.h>
18 #include <linux/libfdt.h>
19 #include <fsl-mc/fsl_mc.h>
20 #include <env_internal.h>
21 #include <efi_loader.h>
22 #include <asm/arch/mmu.h>
24 #include <asm/arch/clock.h>
25 #include <asm/arch/config.h>
26 #include <asm/arch/fsl_serdes.h>
27 #include <asm/arch/soc.h>
28 #include "../common/qixis.h"
29 #include "../common/vid.h"
30 #include <fsl_immap.h>
31 #include <asm/arch-fsl-layerscape/fsl_icid.h>
34 #include "../common/emc2305.h"
37 #ifdef CONFIG_TARGET_LX2160AQDS
38 #define CFG_MUX_I2C_SDHC(reg, value) ((reg & 0x3f) | value)
39 #define SET_CFG_MUX1_SDHC1_SDHC(reg) (reg & 0x3f)
40 #define SET_CFG_MUX2_SDHC1_SPI(reg, value) ((reg & 0xcf) | value)
41 #define SET_CFG_MUX3_SDHC1_SPI(reg, value) ((reg & 0xf8) | value)
42 #define SET_CFG_MUX_SDHC2_DSPI(reg, value) ((reg & 0xf8) | value)
43 #define SET_CFG_MUX1_SDHC1_DSPI(reg, value) ((reg & 0x3f) | value)
44 #define SDHC1_BASE_PMUX_DSPI 2
45 #define SDHC2_BASE_PMUX_DSPI 2
46 #define IIC5_PMUX_SPI3 3
47 #endif /* CONFIG_TARGET_LX2160AQDS */
49 DECLARE_GLOBAL_DATA_PTR;
51 static struct pl01x_serial_platdata serial0 = {
52 #if CONFIG_CONS_INDEX == 0
53 .base = CONFIG_SYS_SERIAL0,
54 #elif CONFIG_CONS_INDEX == 1
55 .base = CONFIG_SYS_SERIAL1,
57 #error "Unsupported console index value."
62 U_BOOT_DEVICE(nxp_serial0) = {
63 .name = "serial_pl01x",
67 static struct pl01x_serial_platdata serial1 = {
68 .base = CONFIG_SYS_SERIAL1,
72 U_BOOT_DEVICE(nxp_serial1) = {
73 .name = "serial_pl01x",
77 int select_i2c_ch_pca9547(u8 ch)
82 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
86 ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
88 ret = dm_i2c_write(dev, 0, &ch, 1);
91 puts("PCA: failed to select proper channel\n");
98 static void uart_get_clock(void)
100 serial0.clock = get_serial_clock();
101 serial1.clock = get_serial_clock();
104 int board_early_init_f(void)
106 #ifdef CONFIG_SYS_I2C_EARLY_INIT
109 /* get required clock for UART IP */
112 #ifdef CONFIG_EMC2305
113 select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305);
115 set_fan_speed(I2C_EMC2305_PWM);
116 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
119 fsl_lsch3_early_init_f();
123 #ifdef CONFIG_OF_BOARD_FIXUP
124 int board_fix_fdt(void *fdt)
126 char *reg_names, *reg_name;
127 int names_len, old_name_len, new_name_len, remaining_names_len;
131 } reg_names_map[] = {
133 { "pf_ctrl", "ctrl" }
137 if (IS_SVR_REV(get_svr(), 1, 0))
140 off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
141 while (off != -FDT_ERR_NOTFOUND) {
142 fdt_setprop(fdt, off, "compatible", "fsl,ls-pcie",
143 strlen("fsl,ls-pcie") + 1);
145 reg_names = (char *)fdt_getprop(fdt, off, "reg-names",
150 reg_name = reg_names;
151 remaining_names_len = names_len - (reg_name - reg_names);
153 while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) {
154 old_name_len = strlen(reg_names_map[i].old_str);
155 new_name_len = strlen(reg_names_map[i].new_str);
156 if (memcmp(reg_name, reg_names_map[i].old_str,
157 old_name_len) == 0) {
158 /* first only leave required bytes for new_str
159 * and copy rest of the string after it
161 memcpy(reg_name + new_name_len,
162 reg_name + old_name_len,
163 remaining_names_len - old_name_len);
164 /* Now copy new_str */
165 memcpy(reg_name, reg_names_map[i].new_str,
167 names_len -= old_name_len;
168 names_len += new_name_len;
172 reg_name = memchr(reg_name, '\0', remaining_names_len);
178 remaining_names_len = names_len -
179 (reg_name - reg_names);
182 fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
183 off = fdt_node_offset_by_compatible(fdt, off,
191 #if defined(CONFIG_TARGET_LX2160AQDS)
192 void esdhc_dspi_status_fixup(void *blob)
194 const char esdhc0_path[] = "/soc/esdhc@2140000";
195 const char esdhc1_path[] = "/soc/esdhc@2150000";
196 const char dspi0_path[] = "/soc/spi@2100000";
197 const char dspi1_path[] = "/soc/spi@2110000";
198 const char dspi2_path[] = "/soc/spi@2120000";
200 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
205 /* Check RCW field sdhc1_base_pmux to enable/disable
206 * esdhc0/dspi0 DT node
208 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
209 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
210 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
212 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
213 do_fixup_by_path(blob, dspi0_path, "status", "okay",
215 do_fixup_by_path(blob, esdhc0_path, "status", "disabled",
216 sizeof("disabled"), 1);
218 do_fixup_by_path(blob, esdhc0_path, "status", "okay",
220 do_fixup_by_path(blob, dspi0_path, "status", "disabled",
221 sizeof("disabled"), 1);
224 /* Check RCW field sdhc2_base_pmux to enable/disable
225 * esdhc1/dspi1 DT node
227 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
228 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
229 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
231 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
232 do_fixup_by_path(blob, dspi1_path, "status", "okay",
234 do_fixup_by_path(blob, esdhc1_path, "status", "disabled",
235 sizeof("disabled"), 1);
237 do_fixup_by_path(blob, esdhc1_path, "status", "okay",
239 do_fixup_by_path(blob, dspi1_path, "status", "disabled",
240 sizeof("disabled"), 1);
243 /* Check RCW field IIC5 to enable dspi2 DT node */
244 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
245 & FSL_CHASSIS3_IIC5_PMUX_MASK;
246 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
248 if (iic5_pmux == IIC5_PMUX_SPI3)
249 do_fixup_by_path(blob, dspi2_path, "status", "okay",
252 do_fixup_by_path(blob, dspi2_path, "status", "disabled",
253 sizeof("disabled"), 1);
257 int esdhc_status_fixup(void *blob, const char *compat)
259 #if defined(CONFIG_TARGET_LX2160AQDS)
260 /* Enable esdhc and dspi DT nodes based on RCW fields */
261 esdhc_dspi_status_fixup(blob);
263 /* Enable both esdhc DT nodes for LX2160ARDB */
264 do_fixup_by_compat(blob, compat, "status", "okay",
270 #if defined(CONFIG_VID)
271 int i2c_multiplexer_select_vid_channel(u8 channel)
273 return select_i2c_ch_pca9547(channel);
276 int init_func_vid(void)
280 if (IS_SVR_REV(get_svr(), 1, 0))
281 set_vid = adjust_vdd(800);
283 set_vid = adjust_vdd(0);
286 printf("core voltage not adjusted\n");
294 enum boot_src src = get_boot_src();
297 #ifdef CONFIG_TARGET_LX2160AQDS
299 static const char *const freq[] = {"100", "125", "156.25",
300 "161.13", "322.26", "", "", "",
301 "", "", "", "", "", "", "",
302 "100 separate SSCG"};
306 #ifdef CONFIG_TARGET_LX2160AQDS
307 printf("Board: %s-QDS, ", buf);
309 printf("Board: %s-RDB, ", buf);
312 sw = QIXIS_READ(arch);
313 printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A');
315 if (src == BOOT_SOURCE_SD_MMC) {
317 } else if (src == BOOT_SOURCE_SD_MMC2) {
320 sw = QIXIS_READ(brdcfg[0]);
321 sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK;
325 puts("FlexSPI DEV#0\n");
328 puts("FlexSPI DEV#1\n");
332 puts("FlexSPI EMU\n");
335 printf("invalid setting, xmap: %d\n", sw);
339 #ifdef CONFIG_TARGET_LX2160AQDS
340 printf("FPGA: v%d (%s), build %d",
341 (int)QIXIS_READ(scver), qixis_read_tag(buf),
342 (int)qixis_read_minor());
343 /* the timestamp string contains "\n" at the end */
344 printf(" on %s", qixis_read_time(buf));
346 puts("SERDES1 Reference : ");
347 sw = QIXIS_READ(brdcfg[2]);
349 printf("Clock1 = %sMHz ", freq[clock]);
351 printf("Clock2 = %sMHz", freq[clock]);
353 sw = QIXIS_READ(brdcfg[3]);
354 puts("\nSERDES2 Reference : ");
356 printf("Clock1 = %sMHz ", freq[clock]);
358 printf("Clock2 = %sMHz", freq[clock]);
360 sw = QIXIS_READ(brdcfg[12]);
361 puts("\nSERDES3 Reference : ");
363 printf("Clock1 = %sMHz Clock2 = %sMHz\n", freq[clock], freq[clock]);
365 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
367 puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n");
368 puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
369 puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz\n");
374 #ifdef CONFIG_TARGET_LX2160AQDS
376 * implementation of CONFIG_ESDHC_DETECT_QUIRK Macro.
378 u8 qixis_esdhc_detect_quirk(void)
380 /* for LX2160AQDS res1[1] @ offset 0x1A is SDHC1 Control/Status (SDHC1)
382 * Specifies the type of card installed in the SDHC1 adapter slot.
384 * 001= eMMC V4.5 adapter is installed.
385 * 010= SD/MMC 3.3V adapter is installed.
386 * 011= eMMC V4.4 adapter is installed.
387 * 100= eMMC V5.0 adapter is installed.
388 * 101= MMC card/Legacy (3.3V) adapter is installed.
389 * 110= SDCard V2/V3 adapter installed.
390 * 111= no adapter is installed.
392 return ((QIXIS_READ(res1[1]) & QIXIS_SDID_MASK) !=
393 QIXIS_ESDHC_NO_ADAPTER);
396 int config_board_mux(void)
398 u8 reg11, reg5, reg13;
399 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
404 /* Routes {I2C2_SCL, I2C2_SDA} to SDHC1 as {SDHC1_CD_B, SDHC1_WP}.
405 * Routes {I2C3_SCL, I2C3_SDA} to CAN transceiver as {CAN1_TX,CAN1_RX}.
406 * Routes {I2C4_SCL, I2C4_SDA} to CAN transceiver as {CAN2_TX,CAN2_RX}.
407 * Qixis and remote systems are isolated from the I2C1 bus.
408 * Processor connections are still available.
409 * SPI2 CS2_B controls EN25S64 SPI memory device.
410 * SPI3 CS2_B controls EN25S64 SPI memory device.
411 * EC2 connects to PHY #2 using RGMII protocol.
412 * CLK_OUT connects to FPGA for clock measurement.
415 reg5 = QIXIS_READ(brdcfg[5]);
416 reg5 = CFG_MUX_I2C_SDHC(reg5, 0x40);
417 QIXIS_WRITE(brdcfg[5], reg5);
419 /* Check RCW field sdhc1_base_pmux
420 * esdhc0 : sdhc1_base_pmux = 0
421 * dspi0 : sdhc1_base_pmux = 2
423 sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
424 & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK;
425 sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT;
427 if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) {
428 reg11 = QIXIS_READ(brdcfg[11]);
429 reg11 = SET_CFG_MUX1_SDHC1_DSPI(reg11, 0x40);
430 QIXIS_WRITE(brdcfg[11], reg11);
432 /* - Routes {SDHC1_CMD, SDHC1_CLK } to SDHC1 adapter slot.
433 * {SDHC1_DAT3, SDHC1_DAT2} to SDHC1 adapter slot.
434 * {SDHC1_DAT1, SDHC1_DAT0} to SDHC1 adapter slot.
436 reg11 = QIXIS_READ(brdcfg[11]);
437 reg11 = SET_CFG_MUX1_SDHC1_SDHC(reg11);
438 QIXIS_WRITE(brdcfg[11], reg11);
441 /* Check RCW field sdhc2_base_pmux
442 * esdhc1 : sdhc2_base_pmux = 0 (default)
443 * dspi1 : sdhc2_base_pmux = 2
445 sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1])
446 & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK;
447 sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT;
449 if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) {
450 reg13 = QIXIS_READ(brdcfg[13]);
451 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x01);
452 QIXIS_WRITE(brdcfg[13], reg13);
454 reg13 = QIXIS_READ(brdcfg[13]);
455 reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x00);
456 QIXIS_WRITE(brdcfg[13], reg13);
459 /* Check RCW field IIC5 to enable dspi2 DT nodei
462 iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1])
463 & FSL_CHASSIS3_IIC5_PMUX_MASK;
464 iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT;
466 if (iic5_pmux == IIC5_PMUX_SPI3) {
467 /* - Routes {SDHC1_DAT4} to SPI3 devices as {SPI3_M_CS0_B}. */
468 reg11 = QIXIS_READ(brdcfg[11]);
469 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x10);
470 QIXIS_WRITE(brdcfg[11], reg11);
472 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} nowhere.
473 * {SDHC1_DAT7, SDHC1_DS } to {nothing, SPI3_M0_CLK }.
474 * {I2C5_SCL, I2C5_SDA } to {SPI3_M0_MOSI, SPI3_M0_MISO}.
476 reg11 = QIXIS_READ(brdcfg[11]);
477 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x01);
478 QIXIS_WRITE(brdcfg[11], reg11);
481 * If {SDHC1_DAT4} has been configured to route to SDHC1_VS,
483 * Otherwise route {SDHC1_DAT4} to SDHC1 adapter slot.
485 reg11 = QIXIS_READ(brdcfg[11]);
486 if ((reg11 & 0x30) != 0x30) {
487 reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x00);
488 QIXIS_WRITE(brdcfg[11], reg11);
491 /* - Routes {SDHC1_DAT5, SDHC1_DAT6} to SDHC1 adapter slot.
492 * {SDHC1_DAT7, SDHC1_DS } to SDHC1 adapter slot.
493 * {I2C5_SCL, I2C5_SDA } to SDHC1 adapter slot.
495 reg11 = QIXIS_READ(brdcfg[11]);
496 reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x00);
497 QIXIS_WRITE(brdcfg[11], reg11);
502 #elif defined(CONFIG_TARGET_LX2160ARDB)
503 int config_board_mux(void)
507 brdcfg = QIXIS_READ(brdcfg[4]);
508 /* The BRDCFG4 register controls general board configuration.
509 *|-------------------------------------------|
511 *|-------------------------------------------|
512 *|5 | CAN I/O Enable (net CFG_CAN_EN_B):|
513 *|CAN_EN | 0= CAN transceivers are disabled. |
514 *| | 1= CAN transceivers are enabled. |
515 *|-------------------------------------------|
517 brdcfg |= BIT_MASK(5);
518 QIXIS_WRITE(brdcfg[4], brdcfg);
523 int config_board_mux(void)
529 unsigned long get_board_sys_clk(void)
531 #ifdef CONFIG_TARGET_LX2160AQDS
532 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
534 switch (sysclk_conf & 0x03) {
535 case QIXIS_SYSCLK_100:
537 case QIXIS_SYSCLK_125:
539 case QIXIS_SYSCLK_133:
548 unsigned long get_board_ddr_clk(void)
550 #ifdef CONFIG_TARGET_LX2160AQDS
551 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
553 switch ((ddrclk_conf & 0x30) >> 4) {
554 case QIXIS_DDRCLK_100:
556 case QIXIS_DDRCLK_125:
558 case QIXIS_DDRCLK_133:
569 #if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
570 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
572 #ifdef CONFIG_ENV_IS_NOWHERE
573 gd->env_addr = (ulong)&default_environment[0];
576 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
578 #if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB)
579 /* invert AQR107 IRQ pins polarity */
580 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR107_IRQ_MASK);
583 #ifdef CONFIG_FSL_CAAM
590 void detail_board_ddr_info(void)
596 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++)
597 ddr_size += gd->bd->bi_dram[i].size;
598 print_size(ddr_size, "");
602 #ifdef CONFIG_MISC_INIT_R
603 int misc_init_r(void)
611 #ifdef CONFIG_FSL_MC_ENET
612 extern int fdt_fixup_board_phy(void *fdt);
614 void fdt_fixup_board_enet(void *fdt)
618 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
621 offset = fdt_path_offset(fdt, "/fsl-mc");
624 printf("%s: fsl-mc node not found in device tree (error %d)\n",
629 if (get_mc_boot_status() == 0 &&
630 (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) {
631 fdt_status_okay(fdt, offset);
632 fdt_fixup_board_phy(fdt);
634 fdt_status_fail(fdt, offset);
638 void board_quiesce_devices(void)
640 fsl_mc_ldpaa_exit(gd->bd);
644 #ifdef CONFIG_OF_BOARD_SETUP
645 int ft_board_setup(void *blob, bd_t *bd)
648 u16 mc_memory_bank = 0;
652 u64 mc_memory_base = 0;
653 u64 mc_memory_size = 0;
654 u16 total_memory_banks;
656 ft_cpu_setup(blob, bd);
658 fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size);
660 if (mc_memory_base != 0)
663 total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank;
665 base = calloc(total_memory_banks, sizeof(u64));
666 size = calloc(total_memory_banks, sizeof(u64));
668 /* fixup DT for the three GPP DDR banks */
669 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
670 base[i] = gd->bd->bi_dram[i].start;
671 size[i] = gd->bd->bi_dram[i].size;
674 #ifdef CONFIG_RESV_RAM
675 /* reduce size if reserved memory is within this bank */
676 if (gd->arch.resv_ram >= base[0] &&
677 gd->arch.resv_ram < base[0] + size[0])
678 size[0] = gd->arch.resv_ram - base[0];
679 else if (gd->arch.resv_ram >= base[1] &&
680 gd->arch.resv_ram < base[1] + size[1])
681 size[1] = gd->arch.resv_ram - base[1];
682 else if (gd->arch.resv_ram >= base[2] &&
683 gd->arch.resv_ram < base[2] + size[2])
684 size[2] = gd->arch.resv_ram - base[2];
687 if (mc_memory_base != 0) {
688 for (i = 0; i <= total_memory_banks; i++) {
689 if (base[i] == 0 && size[i] == 0) {
690 base[i] = mc_memory_base;
691 size[i] = mc_memory_size;
697 fdt_fixup_memory_banks(blob, base, size, total_memory_banks);
700 fsl_fdt_fixup_dr_usb(blob, bd);
703 #ifdef CONFIG_FSL_MC_ENET
704 fdt_fsl_mc_fixup_iommu_map_entry(blob);
705 fdt_fixup_board_enet(blob);
707 fdt_fixup_icid(blob);
713 void qixis_dump_switch(void)
717 QIXIS_WRITE(cms[0], 0x00);
718 nr_of_cfgsw = QIXIS_READ(cms[1]);
720 puts("DIP switch settings dump:\n");
721 for (i = 1; i <= nr_of_cfgsw; i++) {
722 QIXIS_WRITE(cms[0], i);
723 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));