Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Xiaowei Bao | 3a13e29 | 2020-01-08 14:29:54 +0800 | [diff] [blame] | 3 | * Copyright 2018-2020 NXP |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 7 | #include <clock_legacy.h> |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <dm/platform_data/serial_pl01x.h> |
| 10 | #include <i2c.h> |
| 11 | #include <malloc.h> |
| 12 | #include <errno.h> |
| 13 | #include <netdev.h> |
| 14 | #include <fsl_ddr.h> |
| 15 | #include <fsl_sec.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <fdt_support.h> |
| 18 | #include <linux/libfdt.h> |
| 19 | #include <fsl-mc/fsl_mc.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 20 | #include <env_internal.h> |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 21 | #include <efi_loader.h> |
| 22 | #include <asm/arch/mmu.h> |
| 23 | #include <hwconfig.h> |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 24 | #include <asm/arch/clock.h> |
| 25 | #include <asm/arch/config.h> |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 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> |
Laurentiu Tudor | 7085d07 | 2019-10-18 09:01:55 +0000 | [diff] [blame] | 31 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 32 | |
Meenakshi Aggarwal | 936a68d | 2018-11-30 22:32:12 +0530 | [diff] [blame] | 33 | #ifdef CONFIG_EMC2305 |
| 34 | #include "../common/emc2305.h" |
| 35 | #endif |
| 36 | |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 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 */ |
| 48 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
| 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, |
| 56 | #else |
| 57 | #error "Unsupported console index value." |
| 58 | #endif |
| 59 | .type = TYPE_PL011, |
| 60 | }; |
| 61 | |
| 62 | U_BOOT_DEVICE(nxp_serial0) = { |
| 63 | .name = "serial_pl01x", |
| 64 | .platdata = &serial0, |
| 65 | }; |
| 66 | |
| 67 | static struct pl01x_serial_platdata serial1 = { |
| 68 | .base = CONFIG_SYS_SERIAL1, |
| 69 | .type = TYPE_PL011, |
| 70 | }; |
| 71 | |
| 72 | U_BOOT_DEVICE(nxp_serial1) = { |
| 73 | .name = "serial_pl01x", |
| 74 | .platdata = &serial1, |
| 75 | }; |
| 76 | |
| 77 | int select_i2c_ch_pca9547(u8 ch) |
| 78 | { |
| 79 | int ret; |
| 80 | |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 81 | #ifndef CONFIG_DM_I2C |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 82 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
Chuanhua Han | 37c2c5e | 2019-07-10 21:00:20 +0800 | [diff] [blame] | 83 | #else |
| 84 | struct udevice *dev; |
| 85 | |
| 86 | ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev); |
| 87 | if (!ret) |
| 88 | ret = dm_i2c_write(dev, 0, &ch, 1); |
| 89 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 90 | if (ret) { |
| 91 | puts("PCA: failed to select proper channel\n"); |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static void uart_get_clock(void) |
| 99 | { |
| 100 | serial0.clock = get_serial_clock(); |
| 101 | serial1.clock = get_serial_clock(); |
| 102 | } |
| 103 | |
| 104 | int board_early_init_f(void) |
| 105 | { |
| 106 | #ifdef CONFIG_SYS_I2C_EARLY_INIT |
| 107 | i2c_early_init_f(); |
| 108 | #endif |
| 109 | /* get required clock for UART IP */ |
| 110 | uart_get_clock(); |
| 111 | |
Meenakshi Aggarwal | 936a68d | 2018-11-30 22:32:12 +0530 | [diff] [blame] | 112 | #ifdef CONFIG_EMC2305 |
| 113 | select_i2c_ch_pca9547(I2C_MUX_CH_EMC2305); |
| 114 | emc2305_init(); |
| 115 | set_fan_speed(I2C_EMC2305_PWM); |
| 116 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 117 | #endif |
| 118 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 119 | fsl_lsch3_early_init_f(); |
| 120 | return 0; |
| 121 | } |
| 122 | |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 123 | #ifdef CONFIG_OF_BOARD_FIXUP |
| 124 | int board_fix_fdt(void *fdt) |
| 125 | { |
| 126 | char *reg_names, *reg_name; |
| 127 | int names_len, old_name_len, new_name_len, remaining_names_len; |
| 128 | struct str_map { |
| 129 | char *old_str; |
| 130 | char *new_str; |
| 131 | } reg_names_map[] = { |
Pankaj Bansal | 58ace21 | 2019-11-20 09:12:47 +0000 | [diff] [blame] | 132 | { "ccsr", "dbi" }, |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 133 | { "pf_ctrl", "ctrl" } |
| 134 | }; |
Pankaj Bansal | 844e0ed | 2020-01-15 05:57:00 +0000 | [diff] [blame] | 135 | int off = -1, i = 0; |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 136 | |
| 137 | if (IS_SVR_REV(get_svr(), 1, 0)) |
| 138 | return 0; |
| 139 | |
| 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); |
| 144 | |
| 145 | reg_names = (char *)fdt_getprop(fdt, off, "reg-names", |
| 146 | &names_len); |
| 147 | if (!reg_names) |
| 148 | continue; |
| 149 | |
| 150 | reg_name = reg_names; |
| 151 | remaining_names_len = names_len - (reg_name - reg_names); |
Pankaj Bansal | 844e0ed | 2020-01-15 05:57:00 +0000 | [diff] [blame] | 152 | while ((i < ARRAY_SIZE(reg_names_map)) && remaining_names_len) { |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 153 | old_name_len = strlen(reg_names_map[i].old_str); |
| 154 | new_name_len = strlen(reg_names_map[i].new_str); |
| 155 | if (memcmp(reg_name, reg_names_map[i].old_str, |
| 156 | old_name_len) == 0) { |
| 157 | /* first only leave required bytes for new_str |
| 158 | * and copy rest of the string after it |
| 159 | */ |
| 160 | memcpy(reg_name + new_name_len, |
| 161 | reg_name + old_name_len, |
| 162 | remaining_names_len - old_name_len); |
| 163 | /* Now copy new_str */ |
| 164 | memcpy(reg_name, reg_names_map[i].new_str, |
| 165 | new_name_len); |
| 166 | names_len -= old_name_len; |
| 167 | names_len += new_name_len; |
Pankaj Bansal | 844e0ed | 2020-01-15 05:57:00 +0000 | [diff] [blame] | 168 | i++; |
Pankaj Bansal | c6b6ba6 | 2019-08-17 01:07:32 +0000 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | reg_name = memchr(reg_name, '\0', remaining_names_len); |
| 172 | if (!reg_name) |
| 173 | break; |
| 174 | |
| 175 | reg_name += 1; |
| 176 | |
| 177 | remaining_names_len = names_len - |
| 178 | (reg_name - reg_names); |
| 179 | } |
| 180 | |
| 181 | fdt_setprop(fdt, off, "reg-names", reg_names, names_len); |
| 182 | off = fdt_node_offset_by_compatible(fdt, off, |
| 183 | "fsl,lx2160a-pcie"); |
| 184 | } |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | #endif |
| 189 | |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 190 | #if defined(CONFIG_TARGET_LX2160AQDS) |
| 191 | void esdhc_dspi_status_fixup(void *blob) |
| 192 | { |
| 193 | const char esdhc0_path[] = "/soc/esdhc@2140000"; |
| 194 | const char esdhc1_path[] = "/soc/esdhc@2150000"; |
Xiaowei Bao | 3a13e29 | 2020-01-08 14:29:54 +0800 | [diff] [blame] | 195 | const char dspi0_path[] = "/soc/spi@2100000"; |
| 196 | const char dspi1_path[] = "/soc/spi@2110000"; |
| 197 | const char dspi2_path[] = "/soc/spi@2120000"; |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 198 | |
| 199 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 200 | u32 sdhc1_base_pmux; |
| 201 | u32 sdhc2_base_pmux; |
| 202 | u32 iic5_pmux; |
| 203 | |
| 204 | /* Check RCW field sdhc1_base_pmux to enable/disable |
| 205 | * esdhc0/dspi0 DT node |
| 206 | */ |
| 207 | sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1]) |
| 208 | & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK; |
| 209 | sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT; |
| 210 | |
| 211 | if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) { |
| 212 | do_fixup_by_path(blob, dspi0_path, "status", "okay", |
| 213 | sizeof("okay"), 1); |
| 214 | do_fixup_by_path(blob, esdhc0_path, "status", "disabled", |
| 215 | sizeof("disabled"), 1); |
| 216 | } else { |
| 217 | do_fixup_by_path(blob, esdhc0_path, "status", "okay", |
| 218 | sizeof("okay"), 1); |
| 219 | do_fixup_by_path(blob, dspi0_path, "status", "disabled", |
| 220 | sizeof("disabled"), 1); |
| 221 | } |
| 222 | |
| 223 | /* Check RCW field sdhc2_base_pmux to enable/disable |
| 224 | * esdhc1/dspi1 DT node |
| 225 | */ |
| 226 | sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1]) |
| 227 | & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK; |
| 228 | sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT; |
| 229 | |
| 230 | if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) { |
| 231 | do_fixup_by_path(blob, dspi1_path, "status", "okay", |
| 232 | sizeof("okay"), 1); |
| 233 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 234 | sizeof("disabled"), 1); |
| 235 | } else { |
| 236 | do_fixup_by_path(blob, esdhc1_path, "status", "okay", |
| 237 | sizeof("okay"), 1); |
| 238 | do_fixup_by_path(blob, dspi1_path, "status", "disabled", |
| 239 | sizeof("disabled"), 1); |
| 240 | } |
| 241 | |
| 242 | /* Check RCW field IIC5 to enable dspi2 DT node */ |
| 243 | iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1]) |
| 244 | & FSL_CHASSIS3_IIC5_PMUX_MASK; |
| 245 | iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT; |
| 246 | |
Xiaowei Bao | 3a13e29 | 2020-01-08 14:29:54 +0800 | [diff] [blame] | 247 | if (iic5_pmux == IIC5_PMUX_SPI3) |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 248 | do_fixup_by_path(blob, dspi2_path, "status", "okay", |
| 249 | sizeof("okay"), 1); |
Xiaowei Bao | 3a13e29 | 2020-01-08 14:29:54 +0800 | [diff] [blame] | 250 | else |
| 251 | do_fixup_by_path(blob, dspi2_path, "status", "disabled", |
| 252 | sizeof("disabled"), 1); |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 253 | } |
| 254 | #endif |
| 255 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 256 | int esdhc_status_fixup(void *blob, const char *compat) |
| 257 | { |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 258 | #if defined(CONFIG_TARGET_LX2160AQDS) |
| 259 | /* Enable esdhc and dspi DT nodes based on RCW fields */ |
| 260 | esdhc_dspi_status_fixup(blob); |
| 261 | #else |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 262 | /* Enable both esdhc DT nodes for LX2160ARDB */ |
| 263 | do_fixup_by_compat(blob, compat, "status", "okay", |
| 264 | sizeof("okay"), 1); |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 265 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | #if defined(CONFIG_VID) |
| 270 | int i2c_multiplexer_select_vid_channel(u8 channel) |
| 271 | { |
| 272 | return select_i2c_ch_pca9547(channel); |
| 273 | } |
| 274 | |
Priyanka Jain | e94c324 | 2019-02-04 06:32:36 +0000 | [diff] [blame] | 275 | int init_func_vid(void) |
| 276 | { |
| 277 | if (adjust_vdd(0) < 0) |
| 278 | printf("core voltage not adjusted\n"); |
| 279 | |
| 280 | return 0; |
| 281 | } |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 282 | #endif |
| 283 | |
| 284 | int checkboard(void) |
| 285 | { |
| 286 | enum boot_src src = get_boot_src(); |
| 287 | char buf[64]; |
| 288 | u8 sw; |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 289 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 290 | int clock; |
| 291 | static const char *const freq[] = {"100", "125", "156.25", |
| 292 | "161.13", "322.26", "", "", "", |
| 293 | "", "", "", "", "", "", "", |
| 294 | "100 separate SSCG"}; |
| 295 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 296 | |
| 297 | cpu_name(buf); |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 298 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 299 | printf("Board: %s-QDS, ", buf); |
| 300 | #else |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 301 | printf("Board: %s-RDB, ", buf); |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 302 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 303 | |
| 304 | sw = QIXIS_READ(arch); |
| 305 | printf("Board version: %c, boot from ", (sw & 0xf) - 1 + 'A'); |
| 306 | |
| 307 | if (src == BOOT_SOURCE_SD_MMC) { |
| 308 | puts("SD\n"); |
Meenakshi Aggarwal | 74bd499 | 2020-01-23 17:55:10 +0530 | [diff] [blame^] | 309 | } else if (src == BOOT_SOURCE_SD_MMC2) { |
| 310 | puts("eMMC\n"); |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 311 | } else { |
| 312 | sw = QIXIS_READ(brdcfg[0]); |
| 313 | sw = (sw >> QIXIS_XMAP_SHIFT) & QIXIS_XMAP_MASK; |
| 314 | switch (sw) { |
| 315 | case 0: |
| 316 | case 4: |
| 317 | puts("FlexSPI DEV#0\n"); |
| 318 | break; |
| 319 | case 1: |
| 320 | puts("FlexSPI DEV#1\n"); |
| 321 | break; |
| 322 | case 2: |
| 323 | case 3: |
| 324 | puts("FlexSPI EMU\n"); |
| 325 | break; |
| 326 | default: |
| 327 | printf("invalid setting, xmap: %d\n", sw); |
| 328 | break; |
| 329 | } |
| 330 | } |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 331 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 332 | printf("FPGA: v%d (%s), build %d", |
| 333 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 334 | (int)qixis_read_minor()); |
| 335 | /* the timestamp string contains "\n" at the end */ |
| 336 | printf(" on %s", qixis_read_time(buf)); |
| 337 | |
| 338 | puts("SERDES1 Reference : "); |
| 339 | sw = QIXIS_READ(brdcfg[2]); |
| 340 | clock = sw >> 4; |
| 341 | printf("Clock1 = %sMHz ", freq[clock]); |
| 342 | clock = sw & 0x0f; |
| 343 | printf("Clock2 = %sMHz", freq[clock]); |
| 344 | |
| 345 | sw = QIXIS_READ(brdcfg[3]); |
| 346 | puts("\nSERDES2 Reference : "); |
| 347 | clock = sw >> 4; |
| 348 | printf("Clock1 = %sMHz ", freq[clock]); |
| 349 | clock = sw & 0x0f; |
| 350 | printf("Clock2 = %sMHz", freq[clock]); |
| 351 | |
| 352 | sw = QIXIS_READ(brdcfg[12]); |
| 353 | puts("\nSERDES3 Reference : "); |
| 354 | clock = sw >> 4; |
| 355 | printf("Clock1 = %sMHz Clock2 = %sMHz\n", freq[clock], freq[clock]); |
| 356 | #else |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 357 | printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata)); |
| 358 | |
| 359 | puts("SERDES1 Reference: Clock1 = 161.13MHz Clock2 = 161.13MHz\n"); |
| 360 | puts("SERDES2 Reference: Clock1 = 100MHz Clock2 = 100MHz\n"); |
Meenakshi Aggarwal | 06f4388 | 2019-09-04 16:39:56 +0530 | [diff] [blame] | 361 | puts("SERDES3 Reference: Clock1 = 100MHz Clock2 = 100MHz\n"); |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 362 | #endif |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 367 | /* |
| 368 | * implementation of CONFIG_ESDHC_DETECT_QUIRK Macro. |
| 369 | */ |
| 370 | u8 qixis_esdhc_detect_quirk(void) |
| 371 | { |
| 372 | /* for LX2160AQDS res1[1] @ offset 0x1A is SDHC1 Control/Status (SDHC1) |
| 373 | * SDHC1 Card ID: |
| 374 | * Specifies the type of card installed in the SDHC1 adapter slot. |
| 375 | * 000= (reserved) |
| 376 | * 001= eMMC V4.5 adapter is installed. |
| 377 | * 010= SD/MMC 3.3V adapter is installed. |
| 378 | * 011= eMMC V4.4 adapter is installed. |
| 379 | * 100= eMMC V5.0 adapter is installed. |
| 380 | * 101= MMC card/Legacy (3.3V) adapter is installed. |
| 381 | * 110= SDCard V2/V3 adapter installed. |
| 382 | * 111= no adapter is installed. |
| 383 | */ |
| 384 | return ((QIXIS_READ(res1[1]) & QIXIS_SDID_MASK) != |
| 385 | QIXIS_ESDHC_NO_ADAPTER); |
| 386 | } |
| 387 | |
| 388 | int config_board_mux(void) |
| 389 | { |
| 390 | u8 reg11, reg5, reg13; |
| 391 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 392 | u32 sdhc1_base_pmux; |
| 393 | u32 sdhc2_base_pmux; |
| 394 | u32 iic5_pmux; |
| 395 | |
| 396 | /* Routes {I2C2_SCL, I2C2_SDA} to SDHC1 as {SDHC1_CD_B, SDHC1_WP}. |
| 397 | * Routes {I2C3_SCL, I2C3_SDA} to CAN transceiver as {CAN1_TX,CAN1_RX}. |
| 398 | * Routes {I2C4_SCL, I2C4_SDA} to CAN transceiver as {CAN2_TX,CAN2_RX}. |
| 399 | * Qixis and remote systems are isolated from the I2C1 bus. |
| 400 | * Processor connections are still available. |
| 401 | * SPI2 CS2_B controls EN25S64 SPI memory device. |
| 402 | * SPI3 CS2_B controls EN25S64 SPI memory device. |
| 403 | * EC2 connects to PHY #2 using RGMII protocol. |
| 404 | * CLK_OUT connects to FPGA for clock measurement. |
| 405 | */ |
| 406 | |
| 407 | reg5 = QIXIS_READ(brdcfg[5]); |
| 408 | reg5 = CFG_MUX_I2C_SDHC(reg5, 0x40); |
| 409 | QIXIS_WRITE(brdcfg[5], reg5); |
| 410 | |
| 411 | /* Check RCW field sdhc1_base_pmux |
| 412 | * esdhc0 : sdhc1_base_pmux = 0 |
| 413 | * dspi0 : sdhc1_base_pmux = 2 |
| 414 | */ |
| 415 | sdhc1_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1]) |
| 416 | & FSL_CHASSIS3_SDHC1_BASE_PMUX_MASK; |
| 417 | sdhc1_base_pmux >>= FSL_CHASSIS3_SDHC1_BASE_PMUX_SHIFT; |
| 418 | |
| 419 | if (sdhc1_base_pmux == SDHC1_BASE_PMUX_DSPI) { |
| 420 | reg11 = QIXIS_READ(brdcfg[11]); |
| 421 | reg11 = SET_CFG_MUX1_SDHC1_DSPI(reg11, 0x40); |
| 422 | QIXIS_WRITE(brdcfg[11], reg11); |
| 423 | } else { |
| 424 | /* - Routes {SDHC1_CMD, SDHC1_CLK } to SDHC1 adapter slot. |
| 425 | * {SDHC1_DAT3, SDHC1_DAT2} to SDHC1 adapter slot. |
| 426 | * {SDHC1_DAT1, SDHC1_DAT0} to SDHC1 adapter slot. |
| 427 | */ |
| 428 | reg11 = QIXIS_READ(brdcfg[11]); |
| 429 | reg11 = SET_CFG_MUX1_SDHC1_SDHC(reg11); |
| 430 | QIXIS_WRITE(brdcfg[11], reg11); |
| 431 | } |
| 432 | |
| 433 | /* Check RCW field sdhc2_base_pmux |
| 434 | * esdhc1 : sdhc2_base_pmux = 0 (default) |
| 435 | * dspi1 : sdhc2_base_pmux = 2 |
| 436 | */ |
| 437 | sdhc2_base_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR13_REGSR - 1]) |
| 438 | & FSL_CHASSIS3_SDHC2_BASE_PMUX_MASK; |
| 439 | sdhc2_base_pmux >>= FSL_CHASSIS3_SDHC2_BASE_PMUX_SHIFT; |
| 440 | |
| 441 | if (sdhc2_base_pmux == SDHC2_BASE_PMUX_DSPI) { |
| 442 | reg13 = QIXIS_READ(brdcfg[13]); |
| 443 | reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x01); |
| 444 | QIXIS_WRITE(brdcfg[13], reg13); |
| 445 | } else { |
| 446 | reg13 = QIXIS_READ(brdcfg[13]); |
| 447 | reg13 = SET_CFG_MUX_SDHC2_DSPI(reg13, 0x00); |
| 448 | QIXIS_WRITE(brdcfg[13], reg13); |
| 449 | } |
| 450 | |
| 451 | /* Check RCW field IIC5 to enable dspi2 DT nodei |
| 452 | * dspi2: IIC5 = 3 |
| 453 | */ |
| 454 | iic5_pmux = gur_in32(&gur->rcwsr[FSL_CHASSIS3_RCWSR12_REGSR - 1]) |
| 455 | & FSL_CHASSIS3_IIC5_PMUX_MASK; |
| 456 | iic5_pmux >>= FSL_CHASSIS3_IIC5_PMUX_SHIFT; |
| 457 | |
| 458 | if (iic5_pmux == IIC5_PMUX_SPI3) { |
| 459 | /* - Routes {SDHC1_DAT4} to SPI3 devices as {SPI3_M_CS0_B}. */ |
| 460 | reg11 = QIXIS_READ(brdcfg[11]); |
| 461 | reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x10); |
| 462 | QIXIS_WRITE(brdcfg[11], reg11); |
| 463 | |
| 464 | /* - Routes {SDHC1_DAT5, SDHC1_DAT6} nowhere. |
| 465 | * {SDHC1_DAT7, SDHC1_DS } to {nothing, SPI3_M0_CLK }. |
| 466 | * {I2C5_SCL, I2C5_SDA } to {SPI3_M0_MOSI, SPI3_M0_MISO}. |
| 467 | */ |
| 468 | reg11 = QIXIS_READ(brdcfg[11]); |
| 469 | reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x01); |
| 470 | QIXIS_WRITE(brdcfg[11], reg11); |
| 471 | } else { |
| 472 | /* Routes {SDHC1_DAT4} to SDHC1 adapter slot */ |
| 473 | reg11 = QIXIS_READ(brdcfg[11]); |
| 474 | reg11 = SET_CFG_MUX2_SDHC1_SPI(reg11, 0x00); |
| 475 | QIXIS_WRITE(brdcfg[11], reg11); |
| 476 | |
| 477 | /* - Routes {SDHC1_DAT5, SDHC1_DAT6} to SDHC1 adapter slot. |
| 478 | * {SDHC1_DAT7, SDHC1_DS } to SDHC1 adapter slot. |
| 479 | * {I2C5_SCL, I2C5_SDA } to SDHC1 adapter slot. |
| 480 | */ |
| 481 | reg11 = QIXIS_READ(brdcfg[11]); |
| 482 | reg11 = SET_CFG_MUX3_SDHC1_SPI(reg11, 0x00); |
| 483 | QIXIS_WRITE(brdcfg[11], reg11); |
| 484 | } |
| 485 | |
| 486 | return 0; |
| 487 | } |
Pankaj Bansal | 504472c | 2019-07-17 09:34:34 +0000 | [diff] [blame] | 488 | #elif defined(CONFIG_TARGET_LX2160ARDB) |
| 489 | int config_board_mux(void) |
| 490 | { |
| 491 | u8 brdcfg; |
| 492 | |
| 493 | brdcfg = QIXIS_READ(brdcfg[4]); |
| 494 | /* The BRDCFG4 register controls general board configuration. |
| 495 | *|-------------------------------------------| |
| 496 | *|Field | Function | |
| 497 | *|-------------------------------------------| |
| 498 | *|5 | CAN I/O Enable (net CFG_CAN_EN_B):| |
| 499 | *|CAN_EN | 0= CAN transceivers are disabled. | |
| 500 | *| | 1= CAN transceivers are enabled. | |
| 501 | *|-------------------------------------------| |
| 502 | */ |
| 503 | brdcfg |= BIT_MASK(5); |
| 504 | QIXIS_WRITE(brdcfg[4], brdcfg); |
| 505 | |
| 506 | return 0; |
| 507 | } |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 508 | #else |
| 509 | int config_board_mux(void) |
| 510 | { |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 511 | return 0; |
| 512 | } |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 513 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 514 | |
| 515 | unsigned long get_board_sys_clk(void) |
| 516 | { |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 517 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 518 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 519 | |
| 520 | switch (sysclk_conf & 0x03) { |
| 521 | case QIXIS_SYSCLK_100: |
| 522 | return 100000000; |
| 523 | case QIXIS_SYSCLK_125: |
| 524 | return 125000000; |
| 525 | case QIXIS_SYSCLK_133: |
| 526 | return 133333333; |
| 527 | } |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 528 | return 100000000; |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 529 | #else |
| 530 | return 100000000; |
| 531 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | unsigned long get_board_ddr_clk(void) |
| 535 | { |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 536 | #ifdef CONFIG_TARGET_LX2160AQDS |
| 537 | u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); |
| 538 | |
| 539 | switch ((ddrclk_conf & 0x30) >> 4) { |
| 540 | case QIXIS_DDRCLK_100: |
| 541 | return 100000000; |
| 542 | case QIXIS_DDRCLK_125: |
| 543 | return 125000000; |
| 544 | case QIXIS_DDRCLK_133: |
| 545 | return 133333333; |
| 546 | } |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 547 | return 100000000; |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 548 | #else |
| 549 | return 100000000; |
| 550 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | int board_init(void) |
| 554 | { |
Florin Chiculita | d90d506 | 2019-04-22 11:57:47 +0300 | [diff] [blame] | 555 | #if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB) |
| 556 | u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE; |
| 557 | #endif |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 558 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 559 | gd->env_addr = (ulong)&default_environment[0]; |
| 560 | #endif |
| 561 | |
| 562 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 563 | |
Florin Chiculita | d90d506 | 2019-04-22 11:57:47 +0300 | [diff] [blame] | 564 | #if defined(CONFIG_FSL_MC_ENET) && defined(CONFIG_TARGET_LX2160ARDB) |
| 565 | /* invert AQR107 IRQ pins polarity */ |
| 566 | out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR107_IRQ_MASK); |
| 567 | #endif |
| 568 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 569 | #ifdef CONFIG_FSL_CAAM |
| 570 | sec_init(); |
| 571 | #endif |
| 572 | |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | void detail_board_ddr_info(void) |
| 577 | { |
| 578 | int i; |
| 579 | u64 ddr_size = 0; |
| 580 | |
| 581 | puts("\nDDR "); |
| 582 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) |
| 583 | ddr_size += gd->bd->bi_dram[i].size; |
| 584 | print_size(ddr_size, ""); |
| 585 | print_ddr_info(0); |
| 586 | } |
| 587 | |
Alex Marginean | b4f8023 | 2020-01-11 01:05:36 +0200 | [diff] [blame] | 588 | #ifdef CONFIG_MISC_INIT_R |
| 589 | int misc_init_r(void) |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 590 | { |
Pankaj Bansal | 338baa3 | 2019-02-08 10:29:58 +0000 | [diff] [blame] | 591 | config_board_mux(); |
| 592 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | #endif |
| 596 | |
| 597 | #ifdef CONFIG_FSL_MC_ENET |
| 598 | extern int fdt_fixup_board_phy(void *fdt); |
| 599 | |
| 600 | void fdt_fixup_board_enet(void *fdt) |
| 601 | { |
| 602 | int offset; |
| 603 | |
| 604 | offset = fdt_path_offset(fdt, "/soc/fsl-mc"); |
| 605 | |
| 606 | if (offset < 0) |
| 607 | offset = fdt_path_offset(fdt, "/fsl-mc"); |
| 608 | |
| 609 | if (offset < 0) { |
| 610 | printf("%s: fsl-mc node not found in device tree (error %d)\n", |
| 611 | __func__, offset); |
| 612 | return; |
| 613 | } |
| 614 | |
Mian Yousaf Kaukab | c387c01 | 2019-05-23 10:57:33 +0200 | [diff] [blame] | 615 | if (get_mc_boot_status() == 0 && |
| 616 | (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) { |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 617 | fdt_status_okay(fdt, offset); |
| 618 | fdt_fixup_board_phy(fdt); |
| 619 | } else { |
| 620 | fdt_status_fail(fdt, offset); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | void board_quiesce_devices(void) |
| 625 | { |
| 626 | fsl_mc_ldpaa_exit(gd->bd); |
| 627 | } |
| 628 | #endif |
| 629 | |
| 630 | #ifdef CONFIG_OF_BOARD_SETUP |
| 631 | |
| 632 | int ft_board_setup(void *blob, bd_t *bd) |
| 633 | { |
| 634 | int i; |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 635 | u16 mc_memory_bank = 0; |
| 636 | |
| 637 | u64 *base; |
| 638 | u64 *size; |
| 639 | u64 mc_memory_base = 0; |
| 640 | u64 mc_memory_size = 0; |
| 641 | u16 total_memory_banks; |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 642 | |
| 643 | ft_cpu_setup(blob, bd); |
| 644 | |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 645 | fdt_fixup_mc_ddr(&mc_memory_base, &mc_memory_size); |
| 646 | |
| 647 | if (mc_memory_base != 0) |
| 648 | mc_memory_bank++; |
| 649 | |
| 650 | total_memory_banks = CONFIG_NR_DRAM_BANKS + mc_memory_bank; |
| 651 | |
| 652 | base = calloc(total_memory_banks, sizeof(u64)); |
| 653 | size = calloc(total_memory_banks, sizeof(u64)); |
| 654 | |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 655 | /* fixup DT for the three GPP DDR banks */ |
| 656 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 657 | base[i] = gd->bd->bi_dram[i].start; |
| 658 | size[i] = gd->bd->bi_dram[i].size; |
| 659 | } |
| 660 | |
| 661 | #ifdef CONFIG_RESV_RAM |
| 662 | /* reduce size if reserved memory is within this bank */ |
| 663 | if (gd->arch.resv_ram >= base[0] && |
| 664 | gd->arch.resv_ram < base[0] + size[0]) |
| 665 | size[0] = gd->arch.resv_ram - base[0]; |
| 666 | else if (gd->arch.resv_ram >= base[1] && |
| 667 | gd->arch.resv_ram < base[1] + size[1]) |
| 668 | size[1] = gd->arch.resv_ram - base[1]; |
| 669 | else if (gd->arch.resv_ram >= base[2] && |
| 670 | gd->arch.resv_ram < base[2] + size[2]) |
| 671 | size[2] = gd->arch.resv_ram - base[2]; |
| 672 | #endif |
| 673 | |
Meenakshi Aggarwal | d67ae48 | 2019-05-23 15:13:43 +0530 | [diff] [blame] | 674 | if (mc_memory_base != 0) { |
| 675 | for (i = 0; i <= total_memory_banks; i++) { |
| 676 | if (base[i] == 0 && size[i] == 0) { |
| 677 | base[i] = mc_memory_base; |
| 678 | size[i] = mc_memory_size; |
| 679 | break; |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | fdt_fixup_memory_banks(blob, base, size, total_memory_banks); |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 685 | |
| 686 | #ifdef CONFIG_USB |
| 687 | fsl_fdt_fixup_dr_usb(blob, bd); |
| 688 | #endif |
| 689 | |
| 690 | #ifdef CONFIG_FSL_MC_ENET |
| 691 | fdt_fsl_mc_fixup_iommu_map_entry(blob); |
| 692 | fdt_fixup_board_enet(blob); |
| 693 | #endif |
Laurentiu Tudor | 7085d07 | 2019-10-18 09:01:55 +0000 | [diff] [blame] | 694 | fdt_fixup_icid(blob); |
Priyanka Jain | fd45ca0 | 2018-11-28 13:04:27 +0000 | [diff] [blame] | 695 | |
| 696 | return 0; |
| 697 | } |
| 698 | #endif |
| 699 | |
| 700 | void qixis_dump_switch(void) |
| 701 | { |
| 702 | int i, nr_of_cfgsw; |
| 703 | |
| 704 | QIXIS_WRITE(cms[0], 0x00); |
| 705 | nr_of_cfgsw = QIXIS_READ(cms[1]); |
| 706 | |
| 707 | puts("DIP switch settings dump:\n"); |
| 708 | for (i = 1; i <= nr_of_cfgsw; i++) { |
| 709 | QIXIS_WRITE(cms[0], i); |
| 710 | printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1])); |
| 711 | } |
| 712 | } |