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