Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
Biwen Li | b41f6ba | 2020-07-02 11:13:03 +0800 | [diff] [blame] | 4 | * Copyright 2019-2020 NXP |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame^] | 8 | #include <clock_legacy.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 9 | #include <i2c.h> |
| 10 | #include <fdt_support.h> |
Simon Glass | 0e0ac20 | 2017-04-06 12:47:04 -0600 | [diff] [blame] | 11 | #include <fsl_ddr_sdram.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/clock.h> |
| 17 | #include <asm/arch/fsl_serdes.h> |
Hou Zhiqiang | 09fd945 | 2017-04-14 14:48:21 +0800 | [diff] [blame] | 18 | #include <asm/arch/ppa.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 19 | #include <asm/arch/fdt.h> |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 20 | #include <asm/arch/mmu.h> |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 21 | #include <asm/arch/cpu.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 22 | #include <asm/arch/soc.h> |
Laurentiu Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 23 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 24 | #include <ahci.h> |
| 25 | #include <hwconfig.h> |
| 26 | #include <mmc.h> |
| 27 | #include <scsi.h> |
| 28 | #include <fm_eth.h> |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 29 | #include <fsl_esdhc.h> |
| 30 | #include <fsl_ifc.h> |
| 31 | #include <spl.h> |
Stephen Carlson | 7ee444a | 2021-06-22 16:39:31 -0700 | [diff] [blame] | 32 | #include "../common/i2c_mux.h" |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 33 | |
| 34 | #include "../common/qixis.h" |
| 35 | #include "ls1043aqds_qixis.h" |
| 36 | |
| 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
| 39 | enum { |
| 40 | MUX_TYPE_GPIO, |
| 41 | }; |
| 42 | |
| 43 | /* LS1043AQDS serdes mux */ |
| 44 | #define CFG_SD_MUX1_SLOT2 0x0 /* SLOT2 TX/RX0 */ |
| 45 | #define CFG_SD_MUX1_SLOT1 0x1 /* SLOT1 TX/RX1 */ |
| 46 | #define CFG_SD_MUX2_SLOT3 0x0 /* SLOT3 TX/RX0 */ |
| 47 | #define CFG_SD_MUX2_SLOT1 0x1 /* SLOT1 TX/RX2 */ |
| 48 | #define CFG_SD_MUX3_SLOT4 0x0 /* SLOT4 TX/RX0 */ |
| 49 | #define CFG_SD_MUX3_MUX4 0x1 /* MUX4 */ |
| 50 | #define CFG_SD_MUX4_SLOT3 0x0 /* SLOT3 TX/RX1 */ |
| 51 | #define CFG_SD_MUX4_SLOT1 0x1 /* SLOT1 TX/RX3 */ |
Shaohui Xie | db1ab38 | 2016-01-21 17:14:53 +0800 | [diff] [blame] | 52 | #define CFG_UART_MUX_MASK 0x6 |
| 53 | #define CFG_UART_MUX_SHIFT 1 |
| 54 | #define CFG_LPUART_EN 0x1 |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 55 | |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 56 | #ifdef CONFIG_TFABOOT |
| 57 | struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = { |
| 58 | { |
| 59 | "nor0", |
| 60 | CONFIG_SYS_NOR0_CSPR, |
| 61 | CONFIG_SYS_NOR0_CSPR_EXT, |
| 62 | CONFIG_SYS_NOR_AMASK, |
| 63 | CONFIG_SYS_NOR_CSOR, |
| 64 | { |
| 65 | CONFIG_SYS_NOR_FTIM0, |
| 66 | CONFIG_SYS_NOR_FTIM1, |
| 67 | CONFIG_SYS_NOR_FTIM2, |
| 68 | CONFIG_SYS_NOR_FTIM3 |
| 69 | }, |
| 70 | |
| 71 | }, |
| 72 | { |
| 73 | "nor1", |
| 74 | CONFIG_SYS_NOR1_CSPR, |
| 75 | CONFIG_SYS_NOR1_CSPR_EXT, |
| 76 | CONFIG_SYS_NOR_AMASK, |
| 77 | CONFIG_SYS_NOR_CSOR, |
| 78 | { |
| 79 | CONFIG_SYS_NOR_FTIM0, |
| 80 | CONFIG_SYS_NOR_FTIM1, |
| 81 | CONFIG_SYS_NOR_FTIM2, |
| 82 | CONFIG_SYS_NOR_FTIM3 |
| 83 | }, |
| 84 | }, |
| 85 | { |
| 86 | "nand", |
| 87 | CONFIG_SYS_NAND_CSPR, |
| 88 | CONFIG_SYS_NAND_CSPR_EXT, |
| 89 | CONFIG_SYS_NAND_AMASK, |
| 90 | CONFIG_SYS_NAND_CSOR, |
| 91 | { |
| 92 | CONFIG_SYS_NAND_FTIM0, |
| 93 | CONFIG_SYS_NAND_FTIM1, |
| 94 | CONFIG_SYS_NAND_FTIM2, |
| 95 | CONFIG_SYS_NAND_FTIM3 |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | "fpga", |
| 100 | CONFIG_SYS_FPGA_CSPR, |
| 101 | CONFIG_SYS_FPGA_CSPR_EXT, |
| 102 | CONFIG_SYS_FPGA_AMASK, |
| 103 | CONFIG_SYS_FPGA_CSOR, |
| 104 | { |
| 105 | CONFIG_SYS_FPGA_FTIM0, |
| 106 | CONFIG_SYS_FPGA_FTIM1, |
| 107 | CONFIG_SYS_FPGA_FTIM2, |
| 108 | CONFIG_SYS_FPGA_FTIM3 |
| 109 | }, |
| 110 | } |
| 111 | }; |
| 112 | |
| 113 | struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = { |
| 114 | { |
| 115 | "nand", |
| 116 | CONFIG_SYS_NAND_CSPR, |
| 117 | CONFIG_SYS_NAND_CSPR_EXT, |
| 118 | CONFIG_SYS_NAND_AMASK, |
| 119 | CONFIG_SYS_NAND_CSOR, |
| 120 | { |
| 121 | CONFIG_SYS_NAND_FTIM0, |
| 122 | CONFIG_SYS_NAND_FTIM1, |
| 123 | CONFIG_SYS_NAND_FTIM2, |
| 124 | CONFIG_SYS_NAND_FTIM3 |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | "nor0", |
| 129 | CONFIG_SYS_NOR0_CSPR, |
| 130 | CONFIG_SYS_NOR0_CSPR_EXT, |
| 131 | CONFIG_SYS_NOR_AMASK, |
| 132 | CONFIG_SYS_NOR_CSOR, |
| 133 | { |
| 134 | CONFIG_SYS_NOR_FTIM0, |
| 135 | CONFIG_SYS_NOR_FTIM1, |
| 136 | CONFIG_SYS_NOR_FTIM2, |
| 137 | CONFIG_SYS_NOR_FTIM3 |
| 138 | }, |
| 139 | }, |
| 140 | { |
| 141 | "nor1", |
| 142 | CONFIG_SYS_NOR1_CSPR, |
| 143 | CONFIG_SYS_NOR1_CSPR_EXT, |
| 144 | CONFIG_SYS_NOR_AMASK, |
| 145 | CONFIG_SYS_NOR_CSOR, |
| 146 | { |
| 147 | CONFIG_SYS_NOR_FTIM0, |
| 148 | CONFIG_SYS_NOR_FTIM1, |
| 149 | CONFIG_SYS_NOR_FTIM2, |
| 150 | CONFIG_SYS_NOR_FTIM3 |
| 151 | }, |
| 152 | }, |
| 153 | { |
| 154 | "fpga", |
| 155 | CONFIG_SYS_FPGA_CSPR, |
| 156 | CONFIG_SYS_FPGA_CSPR_EXT, |
| 157 | CONFIG_SYS_FPGA_AMASK, |
| 158 | CONFIG_SYS_FPGA_CSOR, |
| 159 | { |
| 160 | CONFIG_SYS_FPGA_FTIM0, |
| 161 | CONFIG_SYS_FPGA_FTIM1, |
| 162 | CONFIG_SYS_FPGA_FTIM2, |
| 163 | CONFIG_SYS_FPGA_FTIM3 |
| 164 | }, |
| 165 | } |
| 166 | }; |
| 167 | |
| 168 | void ifc_cfg_boot_info(struct ifc_regs_info *regs_info) |
| 169 | { |
| 170 | enum boot_src src = get_boot_src(); |
| 171 | |
| 172 | if (src == BOOT_SOURCE_IFC_NAND) |
| 173 | regs_info->regs = ifc_cfg_nand_boot; |
| 174 | else |
| 175 | regs_info->regs = ifc_cfg_nor_boot; |
| 176 | regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT; |
| 177 | } |
| 178 | #endif |
| 179 | |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 180 | int checkboard(void) |
| 181 | { |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 182 | #ifdef CONFIG_TFABOOT |
| 183 | enum boot_src src = get_boot_src(); |
| 184 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 185 | char buf[64]; |
Qianyu Gong | 68d7520 | 2016-06-13 11:20:30 +0800 | [diff] [blame] | 186 | #ifndef CONFIG_SD_BOOT |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 187 | u8 sw; |
| 188 | #endif |
| 189 | |
| 190 | puts("Board: LS1043AQDS, boot from "); |
| 191 | |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 192 | #ifdef CONFIG_TFABOOT |
| 193 | if (src == BOOT_SOURCE_SD_MMC) |
| 194 | puts("SD\n"); |
| 195 | else { |
| 196 | #endif |
| 197 | |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 198 | #ifdef CONFIG_SD_BOOT |
| 199 | puts("SD\n"); |
| 200 | #else |
| 201 | sw = QIXIS_READ(brdcfg[0]); |
| 202 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 203 | |
| 204 | if (sw < 0x8) |
| 205 | printf("vBank: %d\n", sw); |
| 206 | else if (sw == 0x8) |
| 207 | puts("PromJet\n"); |
| 208 | else if (sw == 0x9) |
| 209 | puts("NAND\n"); |
Qianyu Gong | 68d7520 | 2016-06-13 11:20:30 +0800 | [diff] [blame] | 210 | else if (sw == 0xF) |
| 211 | printf("QSPI\n"); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 212 | else |
| 213 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 214 | #endif |
| 215 | |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 216 | #ifdef CONFIG_TFABOOT |
| 217 | } |
| 218 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 219 | printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n", |
| 220 | QIXIS_READ(id), QIXIS_READ(arch)); |
| 221 | |
| 222 | printf("FPGA: v%d (%s), build %d\n", |
| 223 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 224 | (int)qixis_read_minor()); |
| 225 | |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | bool if_board_diff_clk(void) |
| 230 | { |
| 231 | u8 diff_conf = QIXIS_READ(brdcfg[11]); |
| 232 | |
| 233 | return diff_conf & 0x40; |
| 234 | } |
| 235 | |
| 236 | unsigned long get_board_sys_clk(void) |
| 237 | { |
| 238 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 239 | |
| 240 | switch (sysclk_conf & 0x0f) { |
| 241 | case QIXIS_SYSCLK_64: |
| 242 | return 64000000; |
| 243 | case QIXIS_SYSCLK_83: |
| 244 | return 83333333; |
| 245 | case QIXIS_SYSCLK_100: |
| 246 | return 100000000; |
| 247 | case QIXIS_SYSCLK_125: |
| 248 | return 125000000; |
| 249 | case QIXIS_SYSCLK_133: |
| 250 | return 133333333; |
| 251 | case QIXIS_SYSCLK_150: |
| 252 | return 150000000; |
| 253 | case QIXIS_SYSCLK_160: |
| 254 | return 160000000; |
| 255 | case QIXIS_SYSCLK_166: |
| 256 | return 166666666; |
| 257 | } |
| 258 | |
| 259 | return 66666666; |
| 260 | } |
| 261 | |
| 262 | unsigned long get_board_ddr_clk(void) |
| 263 | { |
| 264 | u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); |
| 265 | |
| 266 | if (if_board_diff_clk()) |
| 267 | return get_board_sys_clk(); |
| 268 | switch ((ddrclk_conf & 0x30) >> 4) { |
| 269 | case QIXIS_DDRCLK_100: |
| 270 | return 100000000; |
| 271 | case QIXIS_DDRCLK_125: |
| 272 | return 125000000; |
| 273 | case QIXIS_DDRCLK_133: |
| 274 | return 133333333; |
| 275 | } |
| 276 | |
| 277 | return 66666666; |
| 278 | } |
| 279 | |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 280 | int dram_init(void) |
| 281 | { |
| 282 | /* |
| 283 | * When resuming from deep sleep, the I2C channel may not be |
| 284 | * in the default channel. So, switch to the default channel |
| 285 | * before accessing DDR SPD. |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 286 | * |
| 287 | * PCA9547 mount on I2C1 bus |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 288 | */ |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 289 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0); |
Simon Glass | 0e0ac20 | 2017-04-06 12:47:04 -0600 | [diff] [blame] | 290 | fsl_initdram(); |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 291 | #if (!defined(CONFIG_SPL) && !defined(CONFIG_TFABOOT)) || \ |
| 292 | defined(CONFIG_SPL_BUILD) |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 293 | /* This will break-before-make MMU for DDR */ |
| 294 | update_early_mmu_table(); |
| 295 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | int i2c_multiplexer_select_vid_channel(u8 channel) |
| 301 | { |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 302 | return select_i2c_ch_pca9547(channel, 0); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void board_retimer_init(void) |
| 306 | { |
| 307 | u8 reg; |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 308 | int bus_num = 0; |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 309 | |
| 310 | /* Retimer is connected to I2C1_CH7_CH5 */ |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 311 | select_i2c_ch_pca9547(I2C_MUX_CH7, bus_num); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 312 | reg = I2C_MUX_CH5; |
Igor Opaniuk | f7c9176 | 2021-02-09 13:52:45 +0200 | [diff] [blame] | 313 | #if CONFIG_IS_ENABLED(DM_I2C) |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 314 | struct udevice *dev; |
| 315 | int ret; |
| 316 | |
| 317 | ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_SEC, |
| 318 | 1, &dev); |
| 319 | if (ret) { |
| 320 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 321 | bus_num); |
| 322 | return; |
| 323 | } |
| 324 | dm_i2c_write(dev, 0, ®, 1); |
| 325 | |
| 326 | /* Access to Control/Shared register */ |
| 327 | ret = i2c_get_chip_for_busnum(bus_num, I2C_RETIMER_ADDR, |
| 328 | 1, &dev); |
| 329 | if (ret) { |
| 330 | printf("%s: Cannot find udev for a bus %d\n", __func__, |
| 331 | bus_num); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | reg = 0x0; |
| 336 | dm_i2c_write(dev, 0xff, ®, 1); |
| 337 | |
| 338 | /* Read device revision and ID */ |
| 339 | dm_i2c_read(dev, 1, ®, 1); |
| 340 | debug("Retimer version id = 0x%x\n", reg); |
| 341 | |
| 342 | /* Enable Broadcast. All writes target all channel register sets */ |
| 343 | reg = 0x0c; |
| 344 | dm_i2c_write(dev, 0xff, ®, 1); |
| 345 | |
| 346 | /* Reset Channel Registers */ |
| 347 | dm_i2c_read(dev, 0, ®, 1); |
| 348 | reg |= 0x4; |
| 349 | dm_i2c_write(dev, 0, ®, 1); |
| 350 | |
| 351 | /* Enable override divider select and Enable Override Output Mux */ |
| 352 | dm_i2c_read(dev, 9, ®, 1); |
| 353 | reg |= 0x24; |
| 354 | dm_i2c_write(dev, 9, ®, 1); |
| 355 | |
| 356 | /* Select VCO Divider to full rate (000) */ |
| 357 | dm_i2c_read(dev, 0x18, ®, 1); |
| 358 | reg &= 0x8f; |
| 359 | dm_i2c_write(dev, 0x18, ®, 1); |
| 360 | |
| 361 | /* Selects active PFD MUX Input as Re-timed Data (001) */ |
| 362 | dm_i2c_read(dev, 0x1e, ®, 1); |
| 363 | reg &= 0x3f; |
| 364 | reg |= 0x20; |
| 365 | dm_i2c_write(dev, 0x1e, ®, 1); |
| 366 | |
| 367 | /* Set data rate as 10.3125 Gbps */ |
| 368 | reg = 0x0; |
| 369 | dm_i2c_write(dev, 0x60, ®, 1); |
| 370 | reg = 0xb2; |
| 371 | dm_i2c_write(dev, 0x61, ®, 1); |
| 372 | reg = 0x90; |
| 373 | dm_i2c_write(dev, 0x62, ®, 1); |
| 374 | reg = 0xb3; |
| 375 | dm_i2c_write(dev, 0x63, ®, 1); |
| 376 | reg = 0xcd; |
| 377 | dm_i2c_write(dev, 0x64, ®, 1); |
| 378 | #else |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 379 | i2c_write(I2C_MUX_PCA_ADDR_SEC, 0, 1, ®, 1); |
| 380 | |
| 381 | /* Access to Control/Shared register */ |
| 382 | reg = 0x0; |
| 383 | i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1); |
| 384 | |
| 385 | /* Read device revision and ID */ |
| 386 | i2c_read(I2C_RETIMER_ADDR, 1, 1, ®, 1); |
| 387 | debug("Retimer version id = 0x%x\n", reg); |
| 388 | |
| 389 | /* Enable Broadcast. All writes target all channel register sets */ |
| 390 | reg = 0x0c; |
| 391 | i2c_write(I2C_RETIMER_ADDR, 0xff, 1, ®, 1); |
| 392 | |
| 393 | /* Reset Channel Registers */ |
| 394 | i2c_read(I2C_RETIMER_ADDR, 0, 1, ®, 1); |
| 395 | reg |= 0x4; |
| 396 | i2c_write(I2C_RETIMER_ADDR, 0, 1, ®, 1); |
| 397 | |
| 398 | /* Enable override divider select and Enable Override Output Mux */ |
| 399 | i2c_read(I2C_RETIMER_ADDR, 9, 1, ®, 1); |
| 400 | reg |= 0x24; |
| 401 | i2c_write(I2C_RETIMER_ADDR, 9, 1, ®, 1); |
| 402 | |
| 403 | /* Select VCO Divider to full rate (000) */ |
| 404 | i2c_read(I2C_RETIMER_ADDR, 0x18, 1, ®, 1); |
| 405 | reg &= 0x8f; |
| 406 | i2c_write(I2C_RETIMER_ADDR, 0x18, 1, ®, 1); |
| 407 | |
| 408 | /* Selects active PFD MUX Input as Re-timed Data (001) */ |
| 409 | i2c_read(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1); |
| 410 | reg &= 0x3f; |
| 411 | reg |= 0x20; |
| 412 | i2c_write(I2C_RETIMER_ADDR, 0x1e, 1, ®, 1); |
| 413 | |
| 414 | /* Set data rate as 10.3125 Gbps */ |
| 415 | reg = 0x0; |
| 416 | i2c_write(I2C_RETIMER_ADDR, 0x60, 1, ®, 1); |
| 417 | reg = 0xb2; |
| 418 | i2c_write(I2C_RETIMER_ADDR, 0x61, 1, ®, 1); |
| 419 | reg = 0x90; |
| 420 | i2c_write(I2C_RETIMER_ADDR, 0x62, 1, ®, 1); |
| 421 | reg = 0xb3; |
| 422 | i2c_write(I2C_RETIMER_ADDR, 0x63, 1, ®, 1); |
| 423 | reg = 0xcd; |
| 424 | i2c_write(I2C_RETIMER_ADDR, 0x64, 1, ®, 1); |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 425 | #endif |
Wenbin Song | bc7a4fd | 2016-03-09 13:38:24 +0800 | [diff] [blame] | 426 | |
| 427 | /* Return the default channel */ |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 428 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, bus_num); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | int board_early_init_f(void) |
| 432 | { |
Biwen Li | b41f6ba | 2020-07-02 11:13:03 +0800 | [diff] [blame] | 433 | u32 __iomem *cntcr = (u32 *)CONFIG_SYS_FSL_TIMER_ADDR; |
Qianyu Gong | 8d3d5c4 | 2016-02-16 13:12:53 +0800 | [diff] [blame] | 434 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
| 435 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 436 | u32 usb_pwrfault; |
| 437 | #endif |
Shaohui Xie | db1ab38 | 2016-01-21 17:14:53 +0800 | [diff] [blame] | 438 | #ifdef CONFIG_LPUART |
| 439 | u8 uart; |
| 440 | #endif |
Qianyu Gong | a92f213 | 2016-06-13 11:20:31 +0800 | [diff] [blame] | 441 | |
Biwen Li | b41f6ba | 2020-07-02 11:13:03 +0800 | [diff] [blame] | 442 | /* |
| 443 | * Enable secure system counter for timer |
| 444 | */ |
| 445 | out_le32(cntcr, 0x1); |
| 446 | |
Tom Rini | 714482a | 2021-08-18 23:12:25 -0400 | [diff] [blame] | 447 | #if defined(CONFIG_SYS_I2C_EARLY_INIT) |
Qianyu Gong | a92f213 | 2016-06-13 11:20:31 +0800 | [diff] [blame] | 448 | i2c_early_init_f(); |
| 449 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 450 | fsl_lsch2_early_init_f(); |
Qianyu Gong | 8d3d5c4 | 2016-02-16 13:12:53 +0800 | [diff] [blame] | 451 | |
| 452 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
| 453 | out_be32(&scfg->rcwpmuxcr0, 0x3333); |
| 454 | out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1); |
| 455 | usb_pwrfault = |
Shaohui Xie | b8c4fc9 | 2016-05-30 14:26:55 +0800 | [diff] [blame] | 456 | (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB3_SHIFT) | |
| 457 | (SCFG_USBPWRFAULT_DEDICATED << SCFG_USBPWRFAULT_USB2_SHIFT) | |
Qianyu Gong | 8d3d5c4 | 2016-02-16 13:12:53 +0800 | [diff] [blame] | 458 | (SCFG_USBPWRFAULT_SHARED << SCFG_USBPWRFAULT_USB1_SHIFT); |
| 459 | out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault); |
| 460 | #endif |
| 461 | |
Shaohui Xie | db1ab38 | 2016-01-21 17:14:53 +0800 | [diff] [blame] | 462 | #ifdef CONFIG_LPUART |
| 463 | /* We use lpuart0 as system console */ |
| 464 | uart = QIXIS_READ(brdcfg[14]); |
| 465 | uart &= ~CFG_UART_MUX_MASK; |
| 466 | uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT; |
| 467 | QIXIS_WRITE(brdcfg[14], uart); |
| 468 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
| 473 | #ifdef CONFIG_FSL_DEEP_SLEEP |
| 474 | /* determine if it is a warm boot */ |
| 475 | bool is_warm_boot(void) |
| 476 | { |
| 477 | #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3) |
| 478 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 479 | |
| 480 | if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR) |
| 481 | return 1; |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | int config_board_mux(int ctrl_type) |
| 488 | { |
| 489 | u8 reg14; |
| 490 | |
| 491 | reg14 = QIXIS_READ(brdcfg[14]); |
| 492 | |
| 493 | switch (ctrl_type) { |
| 494 | case MUX_TYPE_GPIO: |
| 495 | reg14 = (reg14 & (~0x30)) | 0x20; |
| 496 | break; |
| 497 | default: |
| 498 | puts("Unsupported mux interface type\n"); |
| 499 | return -1; |
| 500 | } |
| 501 | |
| 502 | QIXIS_WRITE(brdcfg[14], reg14); |
| 503 | |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | int config_serdes_mux(void) |
| 508 | { |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | |
| 513 | #ifdef CONFIG_MISC_INIT_R |
| 514 | int misc_init_r(void) |
| 515 | { |
| 516 | if (hwconfig("gpio")) |
| 517 | config_board_mux(MUX_TYPE_GPIO); |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | #endif |
| 522 | |
| 523 | int board_init(void) |
| 524 | { |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 525 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 526 | erratum_a010315(); |
| 527 | #endif |
| 528 | |
Biwen Li | 014460b | 2020-02-05 22:02:16 +0800 | [diff] [blame] | 529 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 530 | board_retimer_init(); |
| 531 | |
| 532 | #ifdef CONFIG_SYS_FSL_SERDES |
| 533 | config_serdes_mux(); |
| 534 | #endif |
| 535 | |
Hou Zhiqiang | 09fd945 | 2017-04-14 14:48:21 +0800 | [diff] [blame] | 536 | #ifdef CONFIG_FSL_LS_PPA |
| 537 | ppa_init(); |
| 538 | #endif |
| 539 | |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 544 | int ft_board_setup(void *blob, struct bd_info *bd) |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 545 | { |
Shaohui Xie | 16f15fa | 2016-01-04 11:03:44 +0800 | [diff] [blame] | 546 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 547 | u64 size[CONFIG_NR_DRAM_BANKS]; |
Qianyu Gong | d2c492a | 2016-07-21 12:39:27 +0800 | [diff] [blame] | 548 | u8 reg; |
Shaohui Xie | 16f15fa | 2016-01-04 11:03:44 +0800 | [diff] [blame] | 549 | |
| 550 | /* fixup DT for the two DDR banks */ |
| 551 | base[0] = gd->bd->bi_dram[0].start; |
| 552 | size[0] = gd->bd->bi_dram[0].size; |
| 553 | base[1] = gd->bd->bi_dram[1].start; |
| 554 | size[1] = gd->bd->bi_dram[1].size; |
| 555 | |
| 556 | fdt_fixup_memory_banks(blob, base, size, 2); |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 557 | ft_cpu_setup(blob, bd); |
| 558 | |
| 559 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | 7084851 | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 560 | #ifndef CONFIG_DM_ETH |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 561 | fdt_fixup_fman_ethernet(blob); |
Madalin Bucur | 7084851 | 2020-04-30 15:59:58 +0300 | [diff] [blame] | 562 | #endif |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 563 | fdt_fixup_board_enet(blob); |
| 564 | #endif |
Qianyu Gong | d2c492a | 2016-07-21 12:39:27 +0800 | [diff] [blame] | 565 | |
Laurentiu Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 566 | fdt_fixup_icid(blob); |
| 567 | |
Qianyu Gong | d2c492a | 2016-07-21 12:39:27 +0800 | [diff] [blame] | 568 | reg = QIXIS_READ(brdcfg[0]); |
| 569 | reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 570 | |
| 571 | /* Disable IFC if QSPI is enabled */ |
| 572 | if (reg == 0xF) |
| 573 | do_fixup_by_compat(blob, "fsl,ifc", |
| 574 | "status", "disabled", 8 + 1, 1); |
| 575 | |
Shaohui Xie | dd33567 | 2015-11-11 17:58:37 +0800 | [diff] [blame] | 576 | return 0; |
| 577 | } |
| 578 | #endif |
| 579 | |
| 580 | u8 flash_read8(void *addr) |
| 581 | { |
| 582 | return __raw_readb(addr + 1); |
| 583 | } |
| 584 | |
| 585 | void flash_write16(u16 val, void *addr) |
| 586 | { |
| 587 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 588 | |
| 589 | __raw_writew(shftval, addr); |
| 590 | } |
| 591 | |
| 592 | u16 flash_read16(void *addr) |
| 593 | { |
| 594 | u16 val = __raw_readw(addr); |
| 595 | |
| 596 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 597 | } |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 598 | |
Tom Rini | 0543c43 | 2019-11-18 20:02:08 -0500 | [diff] [blame] | 599 | #if defined(CONFIG_TFABOOT) && defined(CONFIG_ENV_IS_IN_SPI_FLASH) |
Rajesh Bhagat | 90bde11 | 2018-11-05 18:02:48 +0000 | [diff] [blame] | 600 | void *env_sf_get_env_addr(void) |
| 601 | { |
| 602 | return (void *)(CONFIG_SYS_FSL_QSPI_BASE + CONFIG_ENV_OFFSET); |
| 603 | } |
| 604 | #endif |