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> |
| 8 | #include <fsl_ifc.h> |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 9 | #include <ahci.h> |
| 10 | #include <scsi.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 11 | #include <asm/arch/soc.h> |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 12 | #include <asm/io.h> |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 14 | #include <asm/arch-fsl-layerscape/config.h> |
Prabhakar Kushwaha | d169ebe | 2016-06-03 18:41:31 +0530 | [diff] [blame] | 15 | #ifdef CONFIG_SYS_FSL_DDR |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 16 | #include <fsl_ddr_sdram.h> |
| 17 | #include <fsl_ddr.h> |
Prabhakar Kushwaha | d169ebe | 2016-06-03 18:41:31 +0530 | [diff] [blame] | 18 | #endif |
Aneesh Bansal | 39d5b3b | 2016-01-22 16:37:26 +0530 | [diff] [blame] | 19 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 20 | #include <fsl_validate.h> |
| 21 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
Scott Wood | ae1df32 | 2015-03-20 19:28:13 -0700 | [diff] [blame] | 24 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 25 | bool soc_has_dp_ddr(void) |
| 26 | { |
| 27 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 28 | u32 svr = gur_in32(&gur->svr); |
| 29 | |
| 30 | /* LS2085A has DP_DDR */ |
Prabhakar Kushwaha | ac7f242 | 2016-06-24 13:48:13 +0530 | [diff] [blame] | 31 | if (SVR_SOC_VER(svr) == SVR_LS2085A) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 32 | return true; |
| 33 | |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | bool soc_has_aiop(void) |
| 38 | { |
| 39 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 40 | u32 svr = gur_in32(&gur->svr); |
| 41 | |
| 42 | /* LS2085A has AIOP */ |
Prabhakar Kushwaha | ac7f242 | 2016-06-24 13:48:13 +0530 | [diff] [blame] | 43 | if (SVR_SOC_VER(svr) == SVR_LS2085A) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 44 | return true; |
| 45 | |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | #ifdef CONFIG_LS2080A |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 50 | /* |
| 51 | * This erratum requires setting a value to eddrtqcr1 to |
| 52 | * optimal the DDR performance. |
| 53 | */ |
| 54 | static void erratum_a008336(void) |
| 55 | { |
| 56 | u32 *eddrtqcr1; |
| 57 | |
| 58 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008336 |
| 59 | #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR |
| 60 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame^] | 61 | if (fsl_ddr_get_version(0) == 0x50200) |
| 62 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 63 | #endif |
| 64 | #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR |
| 65 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame^] | 66 | if (fsl_ddr_get_version(0) == 0x50200) |
| 67 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 68 | #endif |
| 69 | #endif |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * This erratum requires a register write before being Memory |
| 74 | * controller 3 being enabled. |
| 75 | */ |
| 76 | static void erratum_a008514(void) |
| 77 | { |
| 78 | u32 *eddrtqcr1; |
| 79 | |
| 80 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008514 |
| 81 | #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR |
| 82 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800; |
| 83 | out_le32(eddrtqcr1, 0x63b20002); |
| 84 | #endif |
| 85 | #endif |
| 86 | } |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 87 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
| 88 | #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val" |
| 89 | |
| 90 | static unsigned long get_internval_val_mhz(void) |
| 91 | { |
| 92 | char *interval = getenv(PLATFORM_CYCLE_ENV_VAR); |
| 93 | /* |
| 94 | * interval is the number of platform cycles(MHz) between |
| 95 | * wake up events generated by EPU. |
| 96 | */ |
| 97 | ulong interval_mhz = get_bus_freq(0) / (1000 * 1000); |
| 98 | |
| 99 | if (interval) |
| 100 | interval_mhz = simple_strtoul(interval, NULL, 10); |
| 101 | |
| 102 | return interval_mhz; |
| 103 | } |
| 104 | |
| 105 | void erratum_a009635(void) |
| 106 | { |
| 107 | u32 val; |
| 108 | unsigned long interval_mhz = get_internval_val_mhz(); |
| 109 | |
| 110 | if (!interval_mhz) |
| 111 | return; |
| 112 | |
| 113 | val = in_le32(DCSR_CGACRE5); |
| 114 | writel(val | 0x00000200, DCSR_CGACRE5); |
| 115 | |
| 116 | val = in_le32(EPU_EPCMPR5); |
| 117 | writel(interval_mhz, EPU_EPCMPR5); |
| 118 | val = in_le32(EPU_EPCCR5); |
| 119 | writel(val | 0x82820000, EPU_EPCCR5); |
| 120 | val = in_le32(EPU_EPSMCR5); |
| 121 | writel(val | 0x002f0000, EPU_EPSMCR5); |
| 122 | val = in_le32(EPU_EPECR5); |
| 123 | writel(val | 0x20000000, EPU_EPECR5); |
| 124 | val = in_le32(EPU_EPGCR); |
| 125 | writel(val | 0x80000000, EPU_EPGCR); |
| 126 | } |
| 127 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */ |
| 128 | |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 129 | static void erratum_rcw_src(void) |
| 130 | { |
| 131 | #if defined(CONFIG_SPL) |
| 132 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
| 133 | u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE; |
| 134 | u32 val; |
| 135 | |
| 136 | val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4); |
| 137 | val &= ~DCFG_PORSR1_RCW_SRC; |
| 138 | val |= DCFG_PORSR1_RCW_SRC_NOR; |
| 139 | out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val); |
| 140 | #endif |
| 141 | } |
| 142 | |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 143 | #define I2C_DEBUG_REG 0x6 |
| 144 | #define I2C_GLITCH_EN 0x8 |
| 145 | /* |
| 146 | * This erratum requires setting glitch_en bit to enable |
| 147 | * digital glitch filter to improve clock stability. |
| 148 | */ |
| 149 | static void erratum_a009203(void) |
| 150 | { |
| 151 | u8 __iomem *ptr; |
| 152 | #ifdef CONFIG_SYS_I2C |
| 153 | #ifdef I2C1_BASE_ADDR |
| 154 | ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG); |
| 155 | |
| 156 | writeb(I2C_GLITCH_EN, ptr); |
| 157 | #endif |
| 158 | #ifdef I2C2_BASE_ADDR |
| 159 | ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG); |
| 160 | |
| 161 | writeb(I2C_GLITCH_EN, ptr); |
| 162 | #endif |
| 163 | #ifdef I2C3_BASE_ADDR |
| 164 | ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG); |
| 165 | |
| 166 | writeb(I2C_GLITCH_EN, ptr); |
| 167 | #endif |
| 168 | #ifdef I2C4_BASE_ADDR |
| 169 | ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG); |
| 170 | |
| 171 | writeb(I2C_GLITCH_EN, ptr); |
| 172 | #endif |
| 173 | #endif |
| 174 | } |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 175 | void bypass_smmu(void) |
| 176 | { |
| 177 | u32 val; |
| 178 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 179 | out_le32(SMMU_SCR0, val); |
| 180 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 181 | out_le32(SMMU_NSCR0, val); |
| 182 | } |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 183 | void fsl_lsch3_early_init_f(void) |
| 184 | { |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 185 | erratum_rcw_src(); |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 186 | init_early_memctl_regs(); /* tighten IFC timing */ |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 187 | erratum_a009203(); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 188 | erratum_a008514(); |
| 189 | erratum_a008336(); |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 190 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 191 | /* In case of Secure Boot, the IBR configures the SMMU |
| 192 | * to allow only Secure transactions. |
| 193 | * SMMU must be reset in bypass mode. |
| 194 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 195 | */ |
| 196 | if (fsl_check_boot_mode_secure() == 1) |
| 197 | bypass_smmu(); |
| 198 | #endif |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 199 | } |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 200 | |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 201 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 202 | int sata_init(void) |
| 203 | { |
| 204 | struct ccsr_ahci __iomem *ccsr_ahci; |
| 205 | |
| 206 | ccsr_ahci = (void *)CONFIG_SYS_SATA2; |
| 207 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 208 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 209 | |
| 210 | ccsr_ahci = (void *)CONFIG_SYS_SATA1; |
| 211 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 212 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 213 | |
| 214 | ahci_init((void __iomem *)CONFIG_SYS_SATA1); |
| 215 | scsi_scan(0); |
| 216 | |
| 217 | return 0; |
| 218 | } |
| 219 | #endif |
| 220 | |
Prabhakar Kushwaha | 1966d01 | 2016-06-03 18:41:27 +0530 | [diff] [blame] | 221 | #elif defined(CONFIG_FSL_LSCH2) |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 222 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 223 | int sata_init(void) |
| 224 | { |
| 225 | struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA; |
| 226 | |
| 227 | out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG); |
| 228 | out_le32(&ccsr_ahci->pp2c, AHCI_PORT_PHY_2_CFG); |
| 229 | out_le32(&ccsr_ahci->pp3c, AHCI_PORT_PHY_3_CFG); |
| 230 | out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG); |
| 231 | |
| 232 | ahci_init((void __iomem *)CONFIG_SYS_SATA); |
| 233 | scsi_scan(0); |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | #endif |
| 238 | |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 239 | static void erratum_a009929(void) |
| 240 | { |
| 241 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009929 |
| 242 | struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 243 | u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR; |
| 244 | u32 rstrqmr1 = gur_in32(&gur->rstrqmr1); |
| 245 | |
| 246 | rstrqmr1 |= 0x00000400; |
| 247 | gur_out32(&gur->rstrqmr1, rstrqmr1); |
| 248 | writel(0x01000000, dcsr_cop_ccp); |
| 249 | #endif |
| 250 | } |
| 251 | |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 252 | /* |
| 253 | * This erratum requires setting a value to eddrtqcr1 to optimal |
| 254 | * the DDR performance. The eddrtqcr1 register is in SCFG space |
| 255 | * of LS1043A and the offset is 0x157_020c. |
| 256 | */ |
| 257 | #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \ |
| 258 | && defined(CONFIG_SYS_FSL_ERRATUM_A008514) |
| 259 | #error A009660 and A008514 can not be both enabled. |
| 260 | #endif |
| 261 | |
| 262 | static void erratum_a009660(void) |
| 263 | { |
| 264 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009660 |
| 265 | u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c; |
| 266 | out_be32(eddrtqcr1, 0x63b20042); |
| 267 | #endif |
| 268 | } |
| 269 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 270 | static void erratum_a008850_early(void) |
| 271 | { |
| 272 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 273 | /* part 1 of 2 */ |
| 274 | struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR; |
| 275 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 276 | |
| 277 | /* disables propagation of barrier transactions to DDRC from CCI400 */ |
| 278 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER); |
| 279 | |
| 280 | /* disable the re-ordering in DDRC */ |
| 281 | ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 282 | #endif |
| 283 | } |
| 284 | |
| 285 | void erratum_a008850_post(void) |
| 286 | { |
| 287 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 288 | /* part 2 of 2 */ |
| 289 | struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR; |
| 290 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 291 | u32 tmp; |
| 292 | |
| 293 | /* enable propagation of barrier transactions to DDRC from CCI400 */ |
| 294 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
| 295 | |
| 296 | /* enable the re-ordering in DDRC */ |
| 297 | tmp = ddr_in32(&ddr->eor); |
| 298 | tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 299 | ddr_out32(&ddr->eor, tmp); |
| 300 | #endif |
| 301 | } |
| 302 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 303 | void fsl_lsch2_early_init_f(void) |
| 304 | { |
| 305 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR; |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 306 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 307 | |
| 308 | #ifdef CONFIG_FSL_IFC |
| 309 | init_early_memctl_regs(); /* tighten IFC timing */ |
| 310 | #endif |
| 311 | |
Qianyu Gong | 5ab2d0a | 2016-03-16 18:01:52 +0800 | [diff] [blame] | 312 | #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT) |
Gong Qianyu | 760df89 | 2016-01-25 15:16:06 +0800 | [diff] [blame] | 313 | out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL); |
| 314 | #endif |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 315 | /* Make SEC reads and writes snoopable */ |
| 316 | setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP | |
| 317 | SCFG_SNPCNFGCR_SECWRSNP); |
| 318 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 319 | /* |
| 320 | * Enable snoop requests and DVM message requests for |
| 321 | * Slave insterface S4 (A53 core cluster) |
| 322 | */ |
| 323 | out_le32(&cci->slave[4].snoop_ctrl, |
| 324 | CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN); |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 325 | |
| 326 | /* Erratum */ |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 327 | erratum_a008850_early(); /* part 1 of 2 */ |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 328 | erratum_a009929(); |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 329 | erratum_a009660(); |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 330 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 331 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 332 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 333 | #ifdef CONFIG_BOARD_LATE_INIT |
| 334 | int board_late_init(void) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 335 | { |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 336 | #ifdef CONFIG_SCSI_AHCI_PLAT |
| 337 | sata_init(); |
| 338 | #endif |
Aneesh Bansal | 39d5b3b | 2016-01-22 16:37:26 +0530 | [diff] [blame] | 339 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 340 | fsl_setenv_chain_of_trust(); |
| 341 | #endif |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 342 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 343 | return 0; |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 344 | } |
| 345 | #endif |