Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Alison Wang | d57211b | 2022-05-10 18:29:10 +0800 | [diff] [blame] | 3 | * Copyright 2019-2022 NXP |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 7 | #include <display_options.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 9 | #include <malloc.h> |
| 10 | #include <errno.h> |
| 11 | #include <fsl_ddr.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 12 | #include <net.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <hwconfig.h> |
| 16 | #include <fdt_support.h> |
| 17 | #include <linux/libfdt.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 18 | #include <env_internal.h> |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 19 | #include <asm/arch-fsl-layerscape/soc.h> |
Laurentiu Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 20 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 21 | #include <i2c.h> |
| 22 | #include <asm/arch/soc.h> |
| 23 | #ifdef CONFIG_FSL_LS_PPA |
| 24 | #include <asm/arch/ppa.h> |
| 25 | #endif |
| 26 | #include <fsl_immap.h> |
| 27 | #include <netdev.h> |
| 28 | |
| 29 | #include <fdtdec.h> |
| 30 | #include <miiphy.h> |
| 31 | #include "../common/qixis.h" |
Alex Marginean | 805b859 | 2019-12-10 16:55:39 +0200 | [diff] [blame] | 32 | #include "../drivers/net/fsl_enetc.h" |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 33 | |
| 34 | DECLARE_GLOBAL_DATA_PTR; |
| 35 | |
Yuantian Tang | 473bbc4 | 2019-04-10 16:43:35 +0800 | [diff] [blame] | 36 | int config_board_mux(void) |
| 37 | { |
Yuantian Tang | d46f65e | 2020-03-19 16:48:23 +0800 | [diff] [blame] | 38 | #ifndef CONFIG_LPUART |
Yuantian Tang | 473bbc4 | 2019-04-10 16:43:35 +0800 | [diff] [blame] | 39 | #if defined(CONFIG_TARGET_LS1028AQDS) && defined(CONFIG_FSL_QIXIS) |
| 40 | u8 reg; |
| 41 | |
| 42 | reg = QIXIS_READ(brdcfg[13]); |
| 43 | /* Field| Function |
| 44 | * 7-6 | Controls I2C3 routing (net CFG_MUX_I2C3): |
| 45 | * I2C3 | 10= Routes {SCL, SDA} to CAN1 transceiver as {TX, RX}. |
| 46 | * 5-4 | Controls I2C4 routing (net CFG_MUX_I2C4): |
| 47 | * I2C4 |11= Routes {SCL, SDA} to CAN2 transceiver as {TX, RX}. |
| 48 | */ |
| 49 | reg &= ~(0xf0); |
| 50 | reg |= 0xb0; |
| 51 | QIXIS_WRITE(brdcfg[13], reg); |
| 52 | |
| 53 | reg = QIXIS_READ(brdcfg[15]); |
| 54 | /* Field| Function |
| 55 | * 7 | Controls the CAN1 transceiver (net CFG_CAN1_STBY): |
| 56 | * CAN1 | 0= CAN #1 transceiver enabled |
| 57 | * 6 | Controls the CAN2 transceiver (net CFG_CAN2_STBY): |
| 58 | * CAN2 | 0= CAN #2 transceiver enabled |
| 59 | */ |
| 60 | reg &= ~(0xc0); |
| 61 | QIXIS_WRITE(brdcfg[15], reg); |
| 62 | #endif |
Yuantian Tang | d46f65e | 2020-03-19 16:48:23 +0800 | [diff] [blame] | 63 | #endif |
| 64 | |
Yuantian Tang | 473bbc4 | 2019-04-10 16:43:35 +0800 | [diff] [blame] | 65 | return 0; |
| 66 | } |
Yuantian Tang | d46f65e | 2020-03-19 16:48:23 +0800 | [diff] [blame] | 67 | |
| 68 | #ifdef CONFIG_LPUART |
| 69 | u32 get_lpuart_clk(void) |
| 70 | { |
| 71 | return gd->bus_clk / CONFIG_SYS_FSL_LPUART_CLK_DIV; |
| 72 | } |
| 73 | #endif |
Yuantian Tang | 473bbc4 | 2019-04-10 16:43:35 +0800 | [diff] [blame] | 74 | |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 75 | int board_init(void) |
| 76 | { |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 77 | #ifdef CONFIG_FSL_LS_PPA |
| 78 | ppa_init(); |
| 79 | #endif |
| 80 | |
| 81 | #ifndef CONFIG_SYS_EARLY_PCI_INIT |
| 82 | pci_init(); |
| 83 | #endif |
| 84 | |
| 85 | #if defined(CONFIG_TARGET_LS1028ARDB) |
| 86 | u8 val = I2C_MUX_CH_DEFAULT; |
| 87 | |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 88 | #if !CONFIG_IS_ENABLED(DM_I2C) |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 89 | i2c_write(I2C_MUX_PCA_ADDR_PRI, 0x0b, 1, &val, 1); |
Chuanhua Han | eaf4a7c | 2019-07-10 21:16:49 +0800 | [diff] [blame] | 90 | #else |
| 91 | struct udevice *dev; |
| 92 | |
| 93 | if (!i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev)) |
| 94 | dm_i2c_write(dev, 0x0b, &val, 1); |
| 95 | #endif |
Wen He | 41e63db | 2019-11-18 13:26:09 +0800 | [diff] [blame] | 96 | #endif |
| 97 | |
| 98 | #if defined(CONFIG_TARGET_LS1028ARDB) |
| 99 | u8 reg; |
Chuanhua Han | eaf4a7c | 2019-07-10 21:16:49 +0800 | [diff] [blame] | 100 | |
Wen He | 41e63db | 2019-11-18 13:26:09 +0800 | [diff] [blame] | 101 | reg = QIXIS_READ(brdcfg[4]); |
| 102 | /* |
| 103 | * Field | Function |
| 104 | * 3 | DisplayPort Power Enable (net DP_PWR_EN): |
| 105 | * DPPWR | 0= DP_PWR is enabled. |
| 106 | */ |
| 107 | reg &= ~(DP_PWD_EN_DEFAULT_MASK); |
| 108 | QIXIS_WRITE(brdcfg[4], reg); |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 109 | #endif |
| 110 | return 0; |
| 111 | } |
| 112 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 113 | int board_eth_init(struct bd_info *bis) |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 114 | { |
| 115 | return pci_eth_init(bis); |
| 116 | } |
| 117 | |
Alex Marginean | f57e45a | 2020-01-11 01:05:39 +0200 | [diff] [blame] | 118 | #ifdef CONFIG_MISC_INIT_R |
| 119 | int misc_init_r(void) |
Yuantian Tang | 473bbc4 | 2019-04-10 16:43:35 +0800 | [diff] [blame] | 120 | { |
| 121 | config_board_mux(); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | #endif |
| 126 | |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 127 | int board_early_init_f(void) |
| 128 | { |
Yuantian Tang | d46f65e | 2020-03-19 16:48:23 +0800 | [diff] [blame] | 129 | #ifdef CONFIG_LPUART |
| 130 | u8 uart; |
| 131 | #endif |
| 132 | |
Tom Rini | 714482a | 2021-08-18 23:12:25 -0400 | [diff] [blame] | 133 | #if defined(CONFIG_SYS_I2C_EARLY_INIT) && defined(CONFIG_SPL_BUILD) |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 134 | i2c_early_init_f(); |
| 135 | #endif |
| 136 | |
| 137 | fsl_lsch3_early_init_f(); |
Yuantian Tang | d46f65e | 2020-03-19 16:48:23 +0800 | [diff] [blame] | 138 | |
| 139 | #ifdef CONFIG_LPUART |
| 140 | /* |
| 141 | * Field| Function |
| 142 | * -------------------------------------------------------------- |
| 143 | * 7-6 | Controls I2C3 routing (net CFG_MUX_I2C3): |
| 144 | * I2C3 | 11= Routes {SCL, SDA} to LPUART1 header as {SOUT, SIN}. |
| 145 | * -------------------------------------------------------------- |
| 146 | * 5-4 | Controls I2C4 routing (net CFG_MUX_I2C4): |
| 147 | * I2C4 |11= Routes {SCL, SDA} to LPUART1 header as {CTS_B, RTS_B}. |
| 148 | */ |
| 149 | /* use lpuart0 as system console */ |
| 150 | uart = QIXIS_READ(brdcfg[13]); |
| 151 | uart &= ~CFG_LPUART_MUX_MASK; |
| 152 | uart |= CFG_LPUART_EN; |
| 153 | QIXIS_WRITE(brdcfg[13], uart); |
| 154 | #endif |
| 155 | |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | void detail_board_ddr_info(void) |
| 160 | { |
| 161 | puts("\nDDR "); |
| 162 | print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, ""); |
| 163 | print_ddr_info(0); |
| 164 | } |
| 165 | |
Yinbo Zhu | 96cd3d4 | 2020-04-14 17:24:48 +0800 | [diff] [blame] | 166 | int esdhc_status_fixup(void *blob, const char *compat) |
| 167 | { |
| 168 | void __iomem *dcfg_ccsr = (void __iomem *)DCFG_BASE; |
| 169 | char esdhc1_path[] = "/soc/mmc@2140000"; |
| 170 | char esdhc2_path[] = "/soc/mmc@2150000"; |
| 171 | char dspi1_path[] = "/soc/spi@2100000"; |
| 172 | char dspi2_path[] = "/soc/spi@2110000"; |
| 173 | u32 mux_sdhc1, mux_sdhc2; |
| 174 | u32 io = 0; |
| 175 | |
| 176 | /* |
| 177 | * The PMUX IO-expander for mux select is used to control |
| 178 | * the muxing of various onboard interfaces. |
| 179 | */ |
| 180 | |
| 181 | io = in_le32(dcfg_ccsr + DCFG_RCWSR12); |
| 182 | mux_sdhc1 = (io >> DCFG_RCWSR12_SDHC_SHIFT) & DCFG_RCWSR12_SDHC_MASK; |
| 183 | |
| 184 | /* Disable esdhc1/dspi1 if not selected. */ |
| 185 | if (mux_sdhc1 != 0) |
| 186 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 187 | sizeof("disabled"), 1); |
| 188 | if (mux_sdhc1 != 2) |
| 189 | do_fixup_by_path(blob, dspi1_path, "status", "disabled", |
| 190 | sizeof("disabled"), 1); |
| 191 | |
| 192 | io = in_le32(dcfg_ccsr + DCFG_RCWSR13); |
| 193 | mux_sdhc2 = (io >> DCFG_RCWSR13_SDHC_SHIFT) & DCFG_RCWSR13_SDHC_MASK; |
| 194 | |
| 195 | /* Disable esdhc2/dspi2 if not selected. */ |
| 196 | if (mux_sdhc2 != 0) |
| 197 | do_fixup_by_path(blob, esdhc2_path, "status", "disabled", |
| 198 | sizeof("disabled"), 1); |
| 199 | if (mux_sdhc2 != 2) |
| 200 | do_fixup_by_path(blob, dspi2_path, "status", "disabled", |
| 201 | sizeof("disabled"), 1); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 206 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 207 | int ft_board_setup(void *blob, struct bd_info *bd) |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 208 | { |
| 209 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 210 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 211 | |
| 212 | ft_cpu_setup(blob, bd); |
| 213 | |
| 214 | /* fixup DT for the two GPP DDR banks */ |
| 215 | base[0] = gd->bd->bi_dram[0].start; |
| 216 | size[0] = gd->bd->bi_dram[0].size; |
| 217 | base[1] = gd->bd->bi_dram[1].start; |
| 218 | size[1] = gd->bd->bi_dram[1].size; |
| 219 | |
| 220 | #ifdef CONFIG_RESV_RAM |
| 221 | /* reduce size if reserved memory is within this bank */ |
| 222 | if (gd->arch.resv_ram >= base[0] && |
| 223 | gd->arch.resv_ram < base[0] + size[0]) |
| 224 | size[0] = gd->arch.resv_ram - base[0]; |
| 225 | else if (gd->arch.resv_ram >= base[1] && |
| 226 | gd->arch.resv_ram < base[1] + size[1]) |
| 227 | size[1] = gd->arch.resv_ram - base[1]; |
| 228 | #endif |
| 229 | |
| 230 | fdt_fixup_memory_banks(blob, base, size, 2); |
| 231 | |
Laurentiu Tudor | 01dc547 | 2019-07-30 17:29:59 +0300 | [diff] [blame] | 232 | fdt_fixup_icid(blob); |
| 233 | |
Alex Marginean | 805b859 | 2019-12-10 16:55:39 +0200 | [diff] [blame] | 234 | #ifdef CONFIG_FSL_ENETC |
| 235 | fdt_fixup_enetc_mac(blob); |
| 236 | #endif |
| 237 | |
Yuantian Tang | 92f18ff | 2019-04-10 16:43:34 +0800 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | #endif |
| 241 | |
| 242 | #ifdef CONFIG_FSL_QIXIS |
| 243 | int checkboard(void) |
| 244 | { |
| 245 | #ifdef CONFIG_TFABOOT |
| 246 | enum boot_src src = get_boot_src(); |
| 247 | #endif |
| 248 | u8 sw; |
| 249 | |
| 250 | int clock; |
| 251 | char *board; |
| 252 | char buf[64] = {0}; |
| 253 | static const char *freq[6] = {"100.00", "125.00", "156.25", |
| 254 | "161.13", "322.26", "100.00 SS"}; |
| 255 | |
| 256 | cpu_name(buf); |
| 257 | /* find the board details */ |
| 258 | sw = QIXIS_READ(id); |
| 259 | |
| 260 | switch (sw) { |
| 261 | case 0x46: |
| 262 | board = "QDS"; |
| 263 | break; |
| 264 | case 0x47: |
| 265 | board = "RDB"; |
| 266 | break; |
| 267 | case 0x49: |
| 268 | board = "HSSI"; |
| 269 | break; |
| 270 | default: |
| 271 | board = "unknown"; |
| 272 | break; |
| 273 | } |
| 274 | |
| 275 | sw = QIXIS_READ(arch); |
| 276 | printf("Board: %s-%s, Version: %c, boot from ", |
| 277 | buf, board, (sw & 0xf) + 'A' - 1); |
| 278 | |
| 279 | sw = QIXIS_READ(brdcfg[0]); |
| 280 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 281 | |
| 282 | #ifdef CONFIG_TFABOOT |
| 283 | if (src == BOOT_SOURCE_SD_MMC) { |
| 284 | puts("SD\n"); |
| 285 | } else if (src == BOOT_SOURCE_SD_MMC2) { |
| 286 | puts("eMMC\n"); |
| 287 | } else { |
| 288 | #endif |
| 289 | #ifdef CONFIG_SD_BOOT |
| 290 | puts("SD\n"); |
| 291 | #elif defined(CONFIG_EMMC_BOOT) |
| 292 | puts("eMMC\n"); |
| 293 | #else |
| 294 | switch (sw) { |
| 295 | case 0: |
| 296 | case 4: |
| 297 | printf("NOR\n"); |
| 298 | break; |
| 299 | case 1: |
| 300 | printf("NAND\n"); |
| 301 | break; |
| 302 | default: |
| 303 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 304 | break; |
| 305 | } |
| 306 | #endif |
| 307 | #ifdef CONFIG_TFABOOT |
| 308 | } |
| 309 | #endif |
| 310 | |
| 311 | printf("FPGA: v%d (%s)\n", QIXIS_READ(scver), board); |
| 312 | puts("SERDES1 Reference : "); |
| 313 | |
| 314 | sw = QIXIS_READ(brdcfg[2]); |
| 315 | #ifdef CONFIG_TARGET_LS1028ARDB |
| 316 | clock = (sw >> 6) & 3; |
| 317 | #else |
| 318 | clock = (sw >> 4) & 0xf; |
| 319 | #endif |
| 320 | |
| 321 | printf("Clock1 = %sMHz ", freq[clock]); |
| 322 | #ifdef CONFIG_TARGET_LS1028ARDB |
| 323 | clock = (sw >> 4) & 3; |
| 324 | #else |
| 325 | clock = sw & 0xf; |
| 326 | #endif |
| 327 | printf("Clock2 = %sMHz\n", freq[clock]); |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | #endif |
Alison Wang | d57211b | 2022-05-10 18:29:10 +0800 | [diff] [blame] | 332 | |
| 333 | void *video_hw_init(void) |
| 334 | { |
| 335 | return NULL; |
| 336 | } |