Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 1 | /* |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 2 | * Copyright 2014-2015 Freescale Semiconductor |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame^] | 8 | #include <fsl_immap.h> |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 9 | #include <fsl_ifc.h> |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 10 | #include <ahci.h> |
| 11 | #include <scsi.h> |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 12 | #include <asm/arch/fsl_serdes.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 13 | #include <asm/arch/soc.h> |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 14 | #include <asm/io.h> |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 16 | #include <asm/arch-fsl-layerscape/config.h> |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 17 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
Hou Zhiqiang | 5ac9a5c | 2016-08-02 19:03:23 +0800 | [diff] [blame] | 18 | #include <fsl_csu.h> |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 19 | #endif |
Prabhakar Kushwaha | d169ebe | 2016-06-03 18:41:31 +0530 | [diff] [blame] | 20 | #ifdef CONFIG_SYS_FSL_DDR |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 21 | #include <fsl_ddr_sdram.h> |
| 22 | #include <fsl_ddr.h> |
Prabhakar Kushwaha | d169ebe | 2016-06-03 18:41:31 +0530 | [diff] [blame] | 23 | #endif |
Aneesh Bansal | 39d5b3b | 2016-01-22 16:37:26 +0530 | [diff] [blame] | 24 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 25 | #include <fsl_validate.h> |
| 26 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 29 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 30 | bool soc_has_dp_ddr(void) |
| 31 | { |
| 32 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 33 | u32 svr = gur_in32(&gur->svr); |
| 34 | |
Priyanka Jain | 4a6f173 | 2016-11-17 12:29:55 +0530 | [diff] [blame] | 35 | /* LS2085A, LS2088A, LS2048A has DP_DDR */ |
| 36 | if ((SVR_SOC_VER(svr) == SVR_LS2085A) || |
| 37 | (SVR_SOC_VER(svr) == SVR_LS2088A) || |
| 38 | (SVR_SOC_VER(svr) == SVR_LS2048A)) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 39 | return true; |
| 40 | |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | bool soc_has_aiop(void) |
| 45 | { |
| 46 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 47 | u32 svr = gur_in32(&gur->svr); |
| 48 | |
| 49 | /* LS2085A has AIOP */ |
Prabhakar Kushwaha | ac7f242 | 2016-06-24 13:48:13 +0530 | [diff] [blame] | 50 | if (SVR_SOC_VER(svr) == SVR_LS2085A) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 51 | return true; |
| 52 | |
| 53 | return false; |
| 54 | } |
| 55 | |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 56 | #if defined(CONFIG_FSL_LSCH3) |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 57 | /* |
| 58 | * This erratum requires setting a value to eddrtqcr1 to |
| 59 | * optimal the DDR performance. |
| 60 | */ |
| 61 | static void erratum_a008336(void) |
| 62 | { |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 63 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008336 |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 64 | u32 *eddrtqcr1; |
| 65 | |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 66 | #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR |
| 67 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame] | 68 | if (fsl_ddr_get_version(0) == 0x50200) |
| 69 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 70 | #endif |
| 71 | #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR |
| 72 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame] | 73 | if (fsl_ddr_get_version(0) == 0x50200) |
| 74 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 75 | #endif |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * This erratum requires a register write before being Memory |
| 81 | * controller 3 being enabled. |
| 82 | */ |
| 83 | static void erratum_a008514(void) |
| 84 | { |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 85 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008514 |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 86 | u32 *eddrtqcr1; |
| 87 | |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR |
| 89 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800; |
| 90 | out_le32(eddrtqcr1, 0x63b20002); |
| 91 | #endif |
| 92 | #endif |
| 93 | } |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 94 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
| 95 | #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val" |
| 96 | |
| 97 | static unsigned long get_internval_val_mhz(void) |
| 98 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 99 | char *interval = env_get(PLATFORM_CYCLE_ENV_VAR); |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 100 | /* |
| 101 | * interval is the number of platform cycles(MHz) between |
| 102 | * wake up events generated by EPU. |
| 103 | */ |
| 104 | ulong interval_mhz = get_bus_freq(0) / (1000 * 1000); |
| 105 | |
| 106 | if (interval) |
| 107 | interval_mhz = simple_strtoul(interval, NULL, 10); |
| 108 | |
| 109 | return interval_mhz; |
| 110 | } |
| 111 | |
| 112 | void erratum_a009635(void) |
| 113 | { |
| 114 | u32 val; |
| 115 | unsigned long interval_mhz = get_internval_val_mhz(); |
| 116 | |
| 117 | if (!interval_mhz) |
| 118 | return; |
| 119 | |
| 120 | val = in_le32(DCSR_CGACRE5); |
| 121 | writel(val | 0x00000200, DCSR_CGACRE5); |
| 122 | |
| 123 | val = in_le32(EPU_EPCMPR5); |
| 124 | writel(interval_mhz, EPU_EPCMPR5); |
| 125 | val = in_le32(EPU_EPCCR5); |
| 126 | writel(val | 0x82820000, EPU_EPCCR5); |
| 127 | val = in_le32(EPU_EPSMCR5); |
| 128 | writel(val | 0x002f0000, EPU_EPSMCR5); |
| 129 | val = in_le32(EPU_EPECR5); |
| 130 | writel(val | 0x20000000, EPU_EPECR5); |
| 131 | val = in_le32(EPU_EPGCR); |
| 132 | writel(val | 0x80000000, EPU_EPGCR); |
| 133 | } |
| 134 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */ |
| 135 | |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 136 | static void erratum_rcw_src(void) |
| 137 | { |
Santan Kumar | 9913648 | 2017-05-05 15:42:28 +0530 | [diff] [blame] | 138 | #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 139 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
| 140 | u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE; |
| 141 | u32 val; |
| 142 | |
| 143 | val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4); |
| 144 | val &= ~DCFG_PORSR1_RCW_SRC; |
| 145 | val |= DCFG_PORSR1_RCW_SRC_NOR; |
| 146 | out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val); |
| 147 | #endif |
| 148 | } |
| 149 | |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 150 | #define I2C_DEBUG_REG 0x6 |
| 151 | #define I2C_GLITCH_EN 0x8 |
| 152 | /* |
| 153 | * This erratum requires setting glitch_en bit to enable |
| 154 | * digital glitch filter to improve clock stability. |
| 155 | */ |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 156 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009203 |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 157 | static void erratum_a009203(void) |
| 158 | { |
| 159 | u8 __iomem *ptr; |
| 160 | #ifdef CONFIG_SYS_I2C |
| 161 | #ifdef I2C1_BASE_ADDR |
| 162 | ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG); |
| 163 | |
| 164 | writeb(I2C_GLITCH_EN, ptr); |
| 165 | #endif |
| 166 | #ifdef I2C2_BASE_ADDR |
| 167 | ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG); |
| 168 | |
| 169 | writeb(I2C_GLITCH_EN, ptr); |
| 170 | #endif |
| 171 | #ifdef I2C3_BASE_ADDR |
| 172 | ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG); |
| 173 | |
| 174 | writeb(I2C_GLITCH_EN, ptr); |
| 175 | #endif |
| 176 | #ifdef I2C4_BASE_ADDR |
| 177 | ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG); |
| 178 | |
| 179 | writeb(I2C_GLITCH_EN, ptr); |
| 180 | #endif |
| 181 | #endif |
| 182 | } |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 183 | #endif |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 184 | |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 185 | void bypass_smmu(void) |
| 186 | { |
| 187 | u32 val; |
| 188 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 189 | out_le32(SMMU_SCR0, val); |
| 190 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 191 | out_le32(SMMU_NSCR0, val); |
| 192 | } |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 193 | void fsl_lsch3_early_init_f(void) |
| 194 | { |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 195 | erratum_rcw_src(); |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 196 | init_early_memctl_regs(); /* tighten IFC timing */ |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 197 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009203 |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 198 | erratum_a009203(); |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 199 | #endif |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 200 | erratum_a008514(); |
| 201 | erratum_a008336(); |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 202 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 203 | /* In case of Secure Boot, the IBR configures the SMMU |
| 204 | * to allow only Secure transactions. |
| 205 | * SMMU must be reset in bypass mode. |
| 206 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 207 | */ |
| 208 | if (fsl_check_boot_mode_secure() == 1) |
| 209 | bypass_smmu(); |
| 210 | #endif |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 211 | } |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 212 | |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 213 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 214 | int sata_init(void) |
| 215 | { |
| 216 | struct ccsr_ahci __iomem *ccsr_ahci; |
| 217 | |
| 218 | ccsr_ahci = (void *)CONFIG_SYS_SATA2; |
| 219 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 220 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
Tang Yuantian | ab9c831 | 2016-12-01 17:06:58 +0800 | [diff] [blame] | 221 | out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 222 | |
| 223 | ccsr_ahci = (void *)CONFIG_SYS_SATA1; |
| 224 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 225 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
Tang Yuantian | ab9c831 | 2016-12-01 17:06:58 +0800 | [diff] [blame] | 226 | out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 227 | |
| 228 | ahci_init((void __iomem *)CONFIG_SYS_SATA1); |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 229 | scsi_scan(false); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 230 | |
| 231 | return 0; |
| 232 | } |
| 233 | #endif |
| 234 | |
Prabhakar Kushwaha | 1966d01 | 2016-06-03 18:41:27 +0530 | [diff] [blame] | 235 | #elif defined(CONFIG_FSL_LSCH2) |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 236 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 237 | int sata_init(void) |
| 238 | { |
| 239 | struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA; |
| 240 | |
Shaohui Xie | ed81e2b | 2016-09-07 17:56:12 +0800 | [diff] [blame] | 241 | /* Disable SATA ECC */ |
| 242 | out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 243 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 244 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
Tang Yuantian | 2945ae0 | 2016-08-08 15:07:20 +0800 | [diff] [blame] | 245 | out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 246 | |
| 247 | ahci_init((void __iomem *)CONFIG_SYS_SATA); |
Simon Glass | 4822873 | 2017-06-14 21:28:41 -0600 | [diff] [blame] | 248 | scsi_scan(false); |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | #endif |
| 253 | |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 254 | static void erratum_a009929(void) |
| 255 | { |
| 256 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009929 |
| 257 | struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 258 | u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR; |
| 259 | u32 rstrqmr1 = gur_in32(&gur->rstrqmr1); |
| 260 | |
| 261 | rstrqmr1 |= 0x00000400; |
| 262 | gur_out32(&gur->rstrqmr1, rstrqmr1); |
| 263 | writel(0x01000000, dcsr_cop_ccp); |
| 264 | #endif |
| 265 | } |
| 266 | |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 267 | /* |
| 268 | * This erratum requires setting a value to eddrtqcr1 to optimal |
| 269 | * the DDR performance. The eddrtqcr1 register is in SCFG space |
| 270 | * of LS1043A and the offset is 0x157_020c. |
| 271 | */ |
| 272 | #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \ |
| 273 | && defined(CONFIG_SYS_FSL_ERRATUM_A008514) |
| 274 | #error A009660 and A008514 can not be both enabled. |
| 275 | #endif |
| 276 | |
| 277 | static void erratum_a009660(void) |
| 278 | { |
| 279 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009660 |
| 280 | u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c; |
| 281 | out_be32(eddrtqcr1, 0x63b20042); |
| 282 | #endif |
| 283 | } |
| 284 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 285 | static void erratum_a008850_early(void) |
| 286 | { |
| 287 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 288 | /* part 1 of 2 */ |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame^] | 289 | struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR + |
| 290 | CONFIG_SYS_CCI400_OFFSET); |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 291 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 292 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 293 | /* Skip if running at lower exception level */ |
| 294 | if (current_el() < 3) |
| 295 | return; |
| 296 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 297 | /* disables propagation of barrier transactions to DDRC from CCI400 */ |
| 298 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER); |
| 299 | |
| 300 | /* disable the re-ordering in DDRC */ |
| 301 | ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 302 | #endif |
| 303 | } |
| 304 | |
| 305 | void erratum_a008850_post(void) |
| 306 | { |
| 307 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 308 | /* part 2 of 2 */ |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame^] | 309 | struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR + |
| 310 | CONFIG_SYS_CCI400_OFFSET); |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 311 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 312 | u32 tmp; |
| 313 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 314 | /* Skip if running at lower exception level */ |
| 315 | if (current_el() < 3) |
| 316 | return; |
| 317 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 318 | /* enable propagation of barrier transactions to DDRC from CCI400 */ |
| 319 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
| 320 | |
| 321 | /* enable the re-ordering in DDRC */ |
| 322 | tmp = ddr_in32(&ddr->eor); |
| 323 | tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 324 | ddr_out32(&ddr->eor, tmp); |
| 325 | #endif |
| 326 | } |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 327 | |
| 328 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 329 | void erratum_a010315(void) |
| 330 | { |
| 331 | int i; |
| 332 | |
| 333 | for (i = PCIE1; i <= PCIE4; i++) |
| 334 | if (!is_serdes_configured(i)) { |
| 335 | debug("PCIe%d: disabled all R/W permission!\n", i); |
| 336 | set_pcie_ns_access(i, 0); |
| 337 | } |
| 338 | } |
| 339 | #endif |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 340 | |
Hou Zhiqiang | c06b30a | 2016-09-29 12:42:44 +0800 | [diff] [blame] | 341 | static void erratum_a010539(void) |
| 342 | { |
| 343 | #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT) |
| 344 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 345 | u32 porsr1; |
| 346 | |
| 347 | porsr1 = in_be32(&gur->porsr1); |
| 348 | porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK; |
| 349 | out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1), |
| 350 | porsr1); |
| 351 | #endif |
| 352 | } |
| 353 | |
Hou Zhiqiang | 4ad5999 | 2016-12-09 16:09:00 +0800 | [diff] [blame] | 354 | /* Get VDD in the unit mV from voltage ID */ |
| 355 | int get_core_volt_from_fuse(void) |
| 356 | { |
| 357 | struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 358 | int vdd; |
| 359 | u32 fusesr; |
| 360 | u8 vid; |
| 361 | |
| 362 | fusesr = in_be32(&gur->dcfg_fusesr); |
| 363 | debug("%s: fusesr = 0x%x\n", __func__, fusesr); |
| 364 | vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) & |
| 365 | FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK; |
| 366 | if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) { |
| 367 | vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) & |
| 368 | FSL_CHASSIS2_DCFG_FUSESR_VID_MASK; |
| 369 | } |
| 370 | debug("%s: VID = 0x%x\n", __func__, vid); |
| 371 | switch (vid) { |
| 372 | case 0x00: /* VID isn't supported */ |
| 373 | vdd = -EINVAL; |
| 374 | debug("%s: The VID feature is not supported\n", __func__); |
| 375 | break; |
| 376 | case 0x08: /* 0.9V silicon */ |
| 377 | vdd = 900; |
| 378 | break; |
| 379 | case 0x10: /* 1.0V silicon */ |
| 380 | vdd = 1000; |
| 381 | break; |
| 382 | default: /* Other core voltage */ |
| 383 | vdd = -EINVAL; |
| 384 | printf("%s: The VID(%x) isn't supported\n", __func__, vid); |
| 385 | break; |
| 386 | } |
| 387 | debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd); |
| 388 | |
| 389 | return vdd; |
| 390 | } |
| 391 | |
| 392 | __weak int board_switch_core_volt(u32 vdd) |
| 393 | { |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int setup_core_volt(u32 vdd) |
| 398 | { |
| 399 | return board_setup_core_volt(vdd); |
| 400 | } |
| 401 | |
| 402 | #ifdef CONFIG_SYS_FSL_DDR |
| 403 | static void ddr_enable_0v9_volt(bool en) |
| 404 | { |
| 405 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 406 | u32 tmp; |
| 407 | |
| 408 | tmp = ddr_in32(&ddr->ddr_cdr1); |
| 409 | |
| 410 | if (en) |
| 411 | tmp |= DDR_CDR1_V0PT9_EN; |
| 412 | else |
| 413 | tmp &= ~DDR_CDR1_V0PT9_EN; |
| 414 | |
| 415 | ddr_out32(&ddr->ddr_cdr1, tmp); |
| 416 | } |
| 417 | #endif |
| 418 | |
| 419 | int setup_chip_volt(void) |
| 420 | { |
| 421 | int vdd; |
| 422 | |
| 423 | vdd = get_core_volt_from_fuse(); |
| 424 | /* Nothing to do for silicons doesn't support VID */ |
| 425 | if (vdd < 0) |
| 426 | return vdd; |
| 427 | |
| 428 | if (setup_core_volt(vdd)) |
| 429 | printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd); |
| 430 | #ifdef CONFIG_SYS_HAS_SERDES |
| 431 | if (setup_serdes_volt(vdd)) |
| 432 | printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd); |
| 433 | #endif |
| 434 | |
| 435 | #ifdef CONFIG_SYS_FSL_DDR |
| 436 | if (vdd == 900) |
| 437 | ddr_enable_0v9_volt(true); |
| 438 | #endif |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 443 | void fsl_lsch2_early_init_f(void) |
| 444 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame^] | 445 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 446 | CONFIG_SYS_CCI400_OFFSET); |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 447 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 448 | |
Hou Zhiqiang | 5ac9a5c | 2016-08-02 19:03:23 +0800 | [diff] [blame] | 449 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 450 | enable_layerscape_ns_access(); |
| 451 | #endif |
| 452 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 453 | #ifdef CONFIG_FSL_IFC |
| 454 | init_early_memctl_regs(); /* tighten IFC timing */ |
| 455 | #endif |
| 456 | |
Qianyu Gong | 5ab2d0a | 2016-03-16 18:01:52 +0800 | [diff] [blame] | 457 | #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT) |
Gong Qianyu | 760df89 | 2016-01-25 15:16:06 +0800 | [diff] [blame] | 458 | out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL); |
| 459 | #endif |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 460 | /* Make SEC reads and writes snoopable */ |
| 461 | setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP | |
Tang Yuantian | 2945ae0 | 2016-08-08 15:07:20 +0800 | [diff] [blame] | 462 | SCFG_SNPCNFGCR_SECWRSNP | |
| 463 | SCFG_SNPCNFGCR_SATARDSNP | |
| 464 | SCFG_SNPCNFGCR_SATAWRSNP); |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 465 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 466 | /* |
| 467 | * Enable snoop requests and DVM message requests for |
| 468 | * Slave insterface S4 (A53 core cluster) |
| 469 | */ |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 470 | if (current_el() == 3) { |
| 471 | out_le32(&cci->slave[4].snoop_ctrl, |
| 472 | CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN); |
| 473 | } |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 474 | |
| 475 | /* Erratum */ |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 476 | erratum_a008850_early(); /* part 1 of 2 */ |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 477 | erratum_a009929(); |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 478 | erratum_a009660(); |
Hou Zhiqiang | c06b30a | 2016-09-29 12:42:44 +0800 | [diff] [blame] | 479 | erratum_a010539(); |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 480 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 481 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 482 | |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 483 | #ifdef CONFIG_QSPI_AHB_INIT |
| 484 | /* Enable 4bytes address support and fast read */ |
| 485 | int qspi_ahb_init(void) |
| 486 | { |
| 487 | u32 *qspi_lut, lut_key, *qspi_key; |
| 488 | |
| 489 | qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300; |
| 490 | qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310; |
| 491 | |
| 492 | lut_key = in_be32(qspi_key); |
| 493 | |
| 494 | if (lut_key == 0x5af05af0) { |
| 495 | /* That means the register is BE */ |
| 496 | out_be32(qspi_key, 0x5af05af0); |
| 497 | /* Unlock the lut table */ |
| 498 | out_be32(qspi_key + 1, 0x00000002); |
| 499 | out_be32(qspi_lut, 0x0820040c); |
| 500 | out_be32(qspi_lut + 1, 0x1c080c08); |
| 501 | out_be32(qspi_lut + 2, 0x00002400); |
| 502 | /* Lock the lut table */ |
| 503 | out_be32(qspi_key, 0x5af05af0); |
| 504 | out_be32(qspi_key + 1, 0x00000001); |
| 505 | } else { |
| 506 | /* That means the register is LE */ |
| 507 | out_le32(qspi_key, 0x5af05af0); |
| 508 | /* Unlock the lut table */ |
| 509 | out_le32(qspi_key + 1, 0x00000002); |
| 510 | out_le32(qspi_lut, 0x0820040c); |
| 511 | out_le32(qspi_lut + 1, 0x1c080c08); |
| 512 | out_le32(qspi_lut + 2, 0x00002400); |
| 513 | /* Lock the lut table */ |
| 514 | out_le32(qspi_key, 0x5af05af0); |
| 515 | out_le32(qspi_key + 1, 0x00000001); |
| 516 | } |
| 517 | |
| 518 | return 0; |
| 519 | } |
| 520 | #endif |
| 521 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 522 | #ifdef CONFIG_BOARD_LATE_INIT |
| 523 | int board_late_init(void) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 524 | { |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 525 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 526 | sata_init(); |
| 527 | #endif |
Aneesh Bansal | 39d5b3b | 2016-01-22 16:37:26 +0530 | [diff] [blame] | 528 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 529 | fsl_setenv_chain_of_trust(); |
| 530 | #endif |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 531 | #ifdef CONFIG_QSPI_AHB_INIT |
| 532 | qspi_ahb_init(); |
| 533 | #endif |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 534 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 535 | return 0; |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 536 | } |
| 537 | #endif |