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