Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <i2c.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame^] | 8 | #include <init.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
| 12 | #include <asm/arch/soc.h> |
Laurentiu Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 13 | #include <asm/arch-fsl-layerscape/fsl_icid.h> |
Simon Glass | e3ee2fb | 2016-02-22 22:55:43 -0700 | [diff] [blame] | 14 | #include <fdt_support.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 15 | #include <hwconfig.h> |
| 16 | #include <ahci.h> |
Yangbo Lu | da6121b | 2015-10-26 19:47:55 +0800 | [diff] [blame] | 17 | #include <mmc.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 18 | #include <scsi.h> |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 19 | #include <fm_eth.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 20 | #include <fsl_esdhc.h> |
| 21 | #include <fsl_ifc.h> |
Aneesh Bansal | b3e9820 | 2015-12-08 13:54:29 +0530 | [diff] [blame] | 22 | #include <fsl_sec.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 23 | #include "cpld.h" |
Zhao Qiang | 0be9be8 | 2016-02-05 10:04:17 +0800 | [diff] [blame] | 24 | #ifdef CONFIG_U_QE |
| 25 | #include <fsl_qe.h> |
| 26 | #endif |
Hou Zhiqiang | f97e602 | 2016-06-28 20:18:17 +0800 | [diff] [blame] | 27 | #include <asm/arch/ppa.h> |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Rajesh Bhagat | b89aed4 | 2018-11-05 18:02:44 +0000 | [diff] [blame] | 31 | #ifdef CONFIG_TFABOOT |
| 32 | struct ifc_regs ifc_cfg_nor_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = { |
| 33 | { |
| 34 | "nor", |
| 35 | CONFIG_SYS_NOR_CSPR, |
| 36 | CONFIG_SYS_NOR_CSPR_EXT, |
| 37 | CONFIG_SYS_NOR_AMASK, |
| 38 | CONFIG_SYS_NOR_CSOR, |
| 39 | { |
| 40 | CONFIG_SYS_NOR_FTIM0, |
| 41 | CONFIG_SYS_NOR_FTIM1, |
| 42 | CONFIG_SYS_NOR_FTIM2, |
| 43 | CONFIG_SYS_NOR_FTIM3 |
| 44 | }, |
| 45 | |
| 46 | }, |
| 47 | { |
| 48 | "nand", |
| 49 | CONFIG_SYS_NAND_CSPR, |
| 50 | CONFIG_SYS_NAND_CSPR_EXT, |
| 51 | CONFIG_SYS_NAND_AMASK, |
| 52 | CONFIG_SYS_NAND_CSOR, |
| 53 | { |
| 54 | CONFIG_SYS_NAND_FTIM0, |
| 55 | CONFIG_SYS_NAND_FTIM1, |
| 56 | CONFIG_SYS_NAND_FTIM2, |
| 57 | CONFIG_SYS_NAND_FTIM3 |
| 58 | }, |
| 59 | }, |
| 60 | { |
| 61 | "cpld", |
| 62 | CONFIG_SYS_CPLD_CSPR, |
| 63 | CONFIG_SYS_CPLD_CSPR_EXT, |
| 64 | CONFIG_SYS_CPLD_AMASK, |
| 65 | CONFIG_SYS_CPLD_CSOR, |
| 66 | { |
| 67 | CONFIG_SYS_CPLD_FTIM0, |
| 68 | CONFIG_SYS_CPLD_FTIM1, |
| 69 | CONFIG_SYS_CPLD_FTIM2, |
| 70 | CONFIG_SYS_CPLD_FTIM3 |
| 71 | }, |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | struct ifc_regs ifc_cfg_nand_boot[CONFIG_SYS_FSL_IFC_BANK_COUNT] = { |
| 76 | { |
| 77 | "nand", |
| 78 | CONFIG_SYS_NAND_CSPR, |
| 79 | CONFIG_SYS_NAND_CSPR_EXT, |
| 80 | CONFIG_SYS_NAND_AMASK, |
| 81 | CONFIG_SYS_NAND_CSOR, |
| 82 | { |
| 83 | CONFIG_SYS_NAND_FTIM0, |
| 84 | CONFIG_SYS_NAND_FTIM1, |
| 85 | CONFIG_SYS_NAND_FTIM2, |
| 86 | CONFIG_SYS_NAND_FTIM3 |
| 87 | }, |
| 88 | }, |
| 89 | { |
| 90 | "nor", |
| 91 | CONFIG_SYS_NOR_CSPR, |
| 92 | CONFIG_SYS_NOR_CSPR_EXT, |
| 93 | CONFIG_SYS_NOR_AMASK, |
| 94 | CONFIG_SYS_NOR_CSOR, |
| 95 | { |
| 96 | CONFIG_SYS_NOR_FTIM0, |
| 97 | CONFIG_SYS_NOR_FTIM1, |
| 98 | CONFIG_SYS_NOR_FTIM2, |
| 99 | CONFIG_SYS_NOR_FTIM3 |
| 100 | }, |
| 101 | }, |
| 102 | { |
| 103 | "cpld", |
| 104 | CONFIG_SYS_CPLD_CSPR, |
| 105 | CONFIG_SYS_CPLD_CSPR_EXT, |
| 106 | CONFIG_SYS_CPLD_AMASK, |
| 107 | CONFIG_SYS_CPLD_CSOR, |
| 108 | { |
| 109 | CONFIG_SYS_CPLD_FTIM0, |
| 110 | CONFIG_SYS_CPLD_FTIM1, |
| 111 | CONFIG_SYS_CPLD_FTIM2, |
| 112 | CONFIG_SYS_CPLD_FTIM3 |
| 113 | }, |
| 114 | } |
| 115 | }; |
| 116 | |
| 117 | void ifc_cfg_boot_info(struct ifc_regs_info *regs_info) |
| 118 | { |
| 119 | enum boot_src src = get_boot_src(); |
| 120 | |
| 121 | if (src == BOOT_SOURCE_IFC_NAND) |
| 122 | regs_info->regs = ifc_cfg_nand_boot; |
| 123 | else |
| 124 | regs_info->regs = ifc_cfg_nor_boot; |
| 125 | regs_info->cs_size = CONFIG_SYS_FSL_IFC_BANK_COUNT; |
| 126 | } |
| 127 | |
| 128 | #endif |
Sumit Garg | 2a2857b | 2017-03-30 09:52:38 +0530 | [diff] [blame] | 129 | int board_early_init_f(void) |
| 130 | { |
| 131 | fsl_lsch2_early_init_f(); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | #ifndef CONFIG_SPL_BUILD |
| 137 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 138 | int checkboard(void) |
| 139 | { |
Rajesh Bhagat | b89aed4 | 2018-11-05 18:02:44 +0000 | [diff] [blame] | 140 | #ifdef CONFIG_TFABOOT |
| 141 | enum boot_src src = get_boot_src(); |
| 142 | #endif |
Qianyu Gong | e54d134 | 2016-04-26 12:51:43 +0800 | [diff] [blame] | 143 | static const char *freq[2] = {"100.00MHZ", "156.25MHZ"}; |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 144 | #ifndef CONFIG_SD_BOOT |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 145 | u8 cfg_rcw_src1, cfg_rcw_src2; |
Qianyu Gong | e54d134 | 2016-04-26 12:51:43 +0800 | [diff] [blame] | 146 | u16 cfg_rcw_src; |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 147 | #endif |
Qianyu Gong | e54d134 | 2016-04-26 12:51:43 +0800 | [diff] [blame] | 148 | u8 sd1refclk_sel; |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 149 | |
| 150 | printf("Board: LS1043ARDB, boot from "); |
| 151 | |
Rajesh Bhagat | b89aed4 | 2018-11-05 18:02:44 +0000 | [diff] [blame] | 152 | #ifdef CONFIG_TFABOOT |
| 153 | if (src == BOOT_SOURCE_SD_MMC) |
| 154 | puts("SD\n"); |
| 155 | else { |
| 156 | #endif |
| 157 | |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 158 | #ifdef CONFIG_SD_BOOT |
| 159 | puts("SD\n"); |
| 160 | #else |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 161 | cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1); |
| 162 | cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2); |
| 163 | cpld_rev_bit(&cfg_rcw_src1); |
| 164 | cfg_rcw_src = cfg_rcw_src1; |
| 165 | cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2; |
| 166 | |
| 167 | if (cfg_rcw_src == 0x25) |
| 168 | printf("vBank %d\n", CPLD_READ(vbank)); |
| 169 | else if (cfg_rcw_src == 0x106) |
| 170 | puts("NAND\n"); |
| 171 | else |
| 172 | printf("Invalid setting of SW4\n"); |
Gong Qianyu | f671f6c | 2015-10-26 19:47:56 +0800 | [diff] [blame] | 173 | #endif |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 174 | |
Rajesh Bhagat | b89aed4 | 2018-11-05 18:02:44 +0000 | [diff] [blame] | 175 | #ifdef CONFIG_TFABOOT |
| 176 | } |
| 177 | #endif |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 178 | printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver), |
| 179 | CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver)); |
| 180 | |
| 181 | puts("SERDES Reference Clocks:\n"); |
| 182 | sd1refclk_sel = CPLD_READ(sd1refclk_sel); |
| 183 | printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 188 | int board_init(void) |
| 189 | { |
Shaohui Xie | 9f4d011 | 2016-04-29 22:07:21 +0800 | [diff] [blame] | 190 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 191 | |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 192 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 193 | erratum_a010315(); |
| 194 | #endif |
| 195 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 196 | #ifdef CONFIG_FSL_IFC |
| 197 | init_final_memctl_regs(); |
| 198 | #endif |
| 199 | |
Udit Agarwal | 22ec238 | 2019-11-07 16:11:32 +0000 | [diff] [blame] | 200 | #ifdef CONFIG_NXP_ESBC |
Sumit Garg | f469d27 | 2016-09-01 12:56:43 -0400 | [diff] [blame] | 201 | /* In case of Secure Boot, the IBR configures the SMMU |
| 202 | * to allow only Secure transactions. |
| 203 | * SMMU must be reset in bypass mode. |
| 204 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 205 | */ |
| 206 | u32 val; |
| 207 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 208 | out_le32(SMMU_SCR0, val); |
| 209 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 210 | out_le32(SMMU_NSCR0, val); |
| 211 | #endif |
| 212 | |
| 213 | #ifdef CONFIG_FSL_CAAM |
| 214 | sec_init(); |
| 215 | #endif |
| 216 | |
Hou Zhiqiang | f97e602 | 2016-06-28 20:18:17 +0800 | [diff] [blame] | 217 | #ifdef CONFIG_FSL_LS_PPA |
| 218 | ppa_init(); |
| 219 | #endif |
| 220 | |
Zhao Qiang | 0be9be8 | 2016-02-05 10:04:17 +0800 | [diff] [blame] | 221 | #ifdef CONFIG_U_QE |
| 222 | u_qe_init(); |
| 223 | #endif |
Shaohui Xie | 9f4d011 | 2016-04-29 22:07:21 +0800 | [diff] [blame] | 224 | /* invert AQR105 IRQ pins polarity */ |
| 225 | out_be32(&scfg->intpcr, AQR105_IRQ_MASK); |
Zhao Qiang | 0be9be8 | 2016-02-05 10:04:17 +0800 | [diff] [blame] | 226 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | int config_board_mux(void) |
| 231 | { |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 232 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 233 | u32 usb_pwrfault; |
| 234 | |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 235 | if (hwconfig("qe-hdlc")) { |
| 236 | out_be32(&scfg->rcwpmuxcr0, |
| 237 | (in_be32(&scfg->rcwpmuxcr0) & ~0xff00) | 0x6600); |
| 238 | printf("Assign to qe-hdlc clk, rcwpmuxcr0=%x\n", |
| 239 | in_be32(&scfg->rcwpmuxcr0)); |
| 240 | } else { |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 241 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 242 | out_be32(&scfg->rcwpmuxcr0, 0x3333); |
| 243 | out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1); |
| 244 | usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED << |
| 245 | SCFG_USBPWRFAULT_USB3_SHIFT) | |
| 246 | (SCFG_USBPWRFAULT_DEDICATED << |
| 247 | SCFG_USBPWRFAULT_USB2_SHIFT) | |
| 248 | (SCFG_USBPWRFAULT_SHARED << |
| 249 | SCFG_USBPWRFAULT_USB1_SHIFT); |
| 250 | out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault); |
Zhao Qiang | 085d267 | 2016-02-05 10:04:18 +0800 | [diff] [blame] | 251 | #endif |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 252 | } |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 253 | return 0; |
| 254 | } |
| 255 | |
| 256 | #if defined(CONFIG_MISC_INIT_R) |
| 257 | int misc_init_r(void) |
| 258 | { |
| 259 | config_board_mux(); |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | #endif |
| 263 | |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 264 | void fdt_del_qe(void *blob) |
| 265 | { |
| 266 | int nodeoff = 0; |
| 267 | |
| 268 | while ((nodeoff = fdt_node_offset_by_compatible(blob, 0, |
| 269 | "fsl,qe")) >= 0) { |
| 270 | fdt_del_node(blob, nodeoff); |
| 271 | } |
| 272 | } |
| 273 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 274 | int ft_board_setup(void *blob, bd_t *bd) |
| 275 | { |
Shaohui Xie | f6c8395 | 2015-11-23 15:23:48 +0800 | [diff] [blame] | 276 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 277 | u64 size[CONFIG_NR_DRAM_BANKS]; |
| 278 | |
| 279 | /* fixup DT for the two DDR banks */ |
| 280 | base[0] = gd->bd->bi_dram[0].start; |
| 281 | size[0] = gd->bd->bi_dram[0].size; |
| 282 | base[1] = gd->bd->bi_dram[1].start; |
| 283 | size[1] = gd->bd->bi_dram[1].size; |
| 284 | |
| 285 | fdt_fixup_memory_banks(blob, base, size, 2); |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 286 | ft_cpu_setup(blob, bd); |
| 287 | |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 288 | #ifdef CONFIG_SYS_DPAA_FMAN |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 289 | #ifndef CONFIG_DM_ETH |
Shaohui Xie | 0464326 | 2015-10-26 19:47:54 +0800 | [diff] [blame] | 290 | fdt_fixup_fman_ethernet(blob); |
| 291 | #endif |
Madalin Bucur | b76b0a6 | 2020-04-23 16:25:19 +0300 | [diff] [blame] | 292 | #endif |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 293 | |
Laurentiu Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 294 | fdt_fixup_icid(blob); |
| 295 | |
Zhao Qiang | 510e792 | 2016-02-05 10:04:19 +0800 | [diff] [blame] | 296 | /* |
| 297 | * qe-hdlc and usb multi-use the pins, |
| 298 | * when set hwconfig to qe-hdlc, delete usb node. |
| 299 | */ |
| 300 | if (hwconfig("qe-hdlc")) |
| 301 | #ifdef CONFIG_HAS_FSL_XHCI_USB |
| 302 | fdt_del_node_and_alias(blob, "usb1"); |
| 303 | #endif |
| 304 | /* |
| 305 | * qe just support qe-uart and qe-hdlc, |
| 306 | * if qe-uart and qe-hdlc are not set in hwconfig, |
| 307 | * delete qe node. |
| 308 | */ |
| 309 | if (!hwconfig("qe-uart") && !hwconfig("qe-hdlc")) |
| 310 | fdt_del_qe(blob); |
| 311 | |
Mingkai Hu | eee86ff | 2015-10-26 19:47:52 +0800 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | u8 flash_read8(void *addr) |
| 316 | { |
| 317 | return __raw_readb(addr + 1); |
| 318 | } |
| 319 | |
| 320 | void flash_write16(u16 val, void *addr) |
| 321 | { |
| 322 | u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00)); |
| 323 | |
| 324 | __raw_writew(shftval, addr); |
| 325 | } |
| 326 | |
| 327 | u16 flash_read16(void *addr) |
| 328 | { |
| 329 | u16 val = __raw_readw(addr); |
| 330 | |
| 331 | return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00); |
| 332 | } |
Sumit Garg | 2a2857b | 2017-03-30 09:52:38 +0530 | [diff] [blame] | 333 | |
| 334 | #endif |