Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 2 | /* |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 3 | * Copyright 2014-2015 Freescale Semiconductor |
Pankit Garg | d6bd678 | 2019-05-30 12:04:15 +0000 | [diff] [blame^] | 4 | * Copyright 2019 NXP |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 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> |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 10 | #include <asm/arch/fsl_serdes.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> |
Ran Wang | 4e7cdcf | 2018-08-10 15:00:00 +0800 | [diff] [blame] | 15 | #include <asm/arch-fsl-layerscape/ns_access.h> |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 16 | #include <asm/arch-fsl-layerscape/fsl_icid.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> |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 28 | #ifdef CONFIG_TFABOOT |
| 29 | #include <environment.h> |
| 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 32 | |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 33 | bool soc_has_dp_ddr(void) |
| 34 | { |
| 35 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 36 | u32 svr = gur_in32(&gur->svr); |
| 37 | |
Priyanka Jain | 4a6f173 | 2016-11-17 12:29:55 +0530 | [diff] [blame] | 38 | /* LS2085A, LS2088A, LS2048A has DP_DDR */ |
| 39 | if ((SVR_SOC_VER(svr) == SVR_LS2085A) || |
| 40 | (SVR_SOC_VER(svr) == SVR_LS2088A) || |
| 41 | (SVR_SOC_VER(svr) == SVR_LS2048A)) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 42 | return true; |
| 43 | |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | bool soc_has_aiop(void) |
| 48 | { |
| 49 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 50 | u32 svr = gur_in32(&gur->svr); |
| 51 | |
| 52 | /* LS2085A has AIOP */ |
Prabhakar Kushwaha | ac7f242 | 2016-06-24 13:48:13 +0530 | [diff] [blame] | 53 | if (SVR_SOC_VER(svr) == SVR_LS2085A) |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 54 | return true; |
| 55 | |
| 56 | return false; |
| 57 | } |
| 58 | |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 59 | static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset) |
| 60 | { |
| 61 | scfg_clrsetbits32(scfg + offset / 4, |
| 62 | 0xF << 6, |
| 63 | SCFG_USB_TXVREFTUNE << 6); |
| 64 | } |
| 65 | |
| 66 | static void erratum_a009008(void) |
| 67 | { |
| 68 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009008 |
| 69 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 70 | |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 71 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 72 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 73 | set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 74 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 75 | set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2); |
| 76 | set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 77 | #endif |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 78 | #elif defined(CONFIG_ARCH_LS2080A) |
| 79 | set_usb_txvreftune(scfg, SCFG_USB3PRM1CR); |
| 80 | #endif |
| 81 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */ |
| 82 | } |
| 83 | |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 84 | static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset) |
| 85 | { |
| 86 | scfg_clrbits32(scfg + offset / 4, |
| 87 | SCFG_USB_SQRXTUNE_MASK << 23); |
| 88 | } |
| 89 | |
| 90 | static void erratum_a009798(void) |
| 91 | { |
| 92 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009798 |
| 93 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
| 94 | |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 95 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 96 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 97 | set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 98 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 99 | set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2); |
| 100 | set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 101 | #endif |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 102 | #elif defined(CONFIG_ARCH_LS2080A) |
| 103 | set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR); |
| 104 | #endif |
| 105 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */ |
| 106 | } |
| 107 | |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 108 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 109 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 110 | static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset) |
| 111 | { |
| 112 | scfg_clrsetbits32(scfg + offset / 4, |
| 113 | 0x7F << 9, |
| 114 | SCFG_USB_PCSTXSWINGFULL << 9); |
| 115 | } |
| 116 | #endif |
| 117 | |
| 118 | static void erratum_a008997(void) |
| 119 | { |
| 120 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008997 |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 121 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 122 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 123 | u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE; |
| 124 | |
| 125 | set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 126 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 127 | set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2); |
| 128 | set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3); |
| 129 | #endif |
Ran Wang | e118acb | 2019-05-14 17:34:56 +0800 | [diff] [blame] | 130 | #elif defined(CONFIG_ARCH_LS1028A) |
| 131 | clrsetbits_le32(DCSR_BASE + DCSR_USB_IOCR1, |
| 132 | 0x7F << 11, |
| 133 | DCSR_USB_PCSTXSWINGFULL << 11); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 134 | #endif |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 135 | #endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */ |
| 136 | } |
| 137 | |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 138 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 139 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 140 | |
| 141 | #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \ |
| 142 | out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \ |
| 143 | out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \ |
| 144 | out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \ |
| 145 | out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4) |
| 146 | |
Yinbo Zhu | 5c3767e | 2019-05-14 17:34:57 +0800 | [diff] [blame] | 147 | #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \ |
| 148 | defined(CONFIG_ARCH_LS1028A) |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 149 | |
| 150 | #define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \ |
| 151 | out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \ |
| 152 | out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \ |
| 153 | out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \ |
| 154 | out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4) |
| 155 | |
| 156 | #endif |
| 157 | |
| 158 | static void erratum_a009007(void) |
| 159 | { |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 160 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \ |
| 161 | defined(CONFIG_ARCH_LS1012A) |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 162 | void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1; |
| 163 | |
| 164 | PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 165 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 166 | usb_phy = (void __iomem *)SCFG_USB_PHY2; |
| 167 | PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy); |
| 168 | |
| 169 | usb_phy = (void __iomem *)SCFG_USB_PHY3; |
| 170 | PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy); |
Ran Wang | 02dc77b | 2017-11-13 16:14:48 +0800 | [diff] [blame] | 171 | #endif |
Yinbo Zhu | 5c3767e | 2019-05-14 17:34:57 +0800 | [diff] [blame] | 172 | #elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A) || \ |
| 173 | defined(CONFIG_ARCH_LS1028A) |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 174 | void __iomem *dcsr = (void __iomem *)DCSR_BASE; |
| 175 | |
| 176 | PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1); |
| 177 | PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2); |
| 178 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */ |
| 179 | } |
| 180 | |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 181 | #if defined(CONFIG_FSL_LSCH3) |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 182 | /* |
| 183 | * This erratum requires setting a value to eddrtqcr1 to |
| 184 | * optimal the DDR performance. |
| 185 | */ |
| 186 | static void erratum_a008336(void) |
| 187 | { |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 188 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008336 |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 189 | u32 *eddrtqcr1; |
| 190 | |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 191 | #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR |
| 192 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame] | 193 | if (fsl_ddr_get_version(0) == 0x50200) |
| 194 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 195 | #endif |
| 196 | #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR |
| 197 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800; |
Shengzhou Liu | 7beb0c4 | 2016-08-26 18:30:38 +0800 | [diff] [blame] | 198 | if (fsl_ddr_get_version(0) == 0x50200) |
| 199 | out_le32(eddrtqcr1, 0x63b30002); |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 200 | #endif |
| 201 | #endif |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * This erratum requires a register write before being Memory |
| 206 | * controller 3 being enabled. |
| 207 | */ |
| 208 | static void erratum_a008514(void) |
| 209 | { |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 210 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008514 |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 211 | u32 *eddrtqcr1; |
| 212 | |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 213 | #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR |
| 214 | eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800; |
| 215 | out_le32(eddrtqcr1, 0x63b20002); |
| 216 | #endif |
| 217 | #endif |
| 218 | } |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 219 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009635 |
| 220 | #define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val" |
| 221 | |
| 222 | static unsigned long get_internval_val_mhz(void) |
| 223 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 224 | char *interval = env_get(PLATFORM_CYCLE_ENV_VAR); |
Prabhakar Kushwaha | 22cfe96 | 2015-11-05 12:00:14 +0530 | [diff] [blame] | 225 | /* |
| 226 | * interval is the number of platform cycles(MHz) between |
| 227 | * wake up events generated by EPU. |
| 228 | */ |
| 229 | ulong interval_mhz = get_bus_freq(0) / (1000 * 1000); |
| 230 | |
| 231 | if (interval) |
| 232 | interval_mhz = simple_strtoul(interval, NULL, 10); |
| 233 | |
| 234 | return interval_mhz; |
| 235 | } |
| 236 | |
| 237 | void erratum_a009635(void) |
| 238 | { |
| 239 | u32 val; |
| 240 | unsigned long interval_mhz = get_internval_val_mhz(); |
| 241 | |
| 242 | if (!interval_mhz) |
| 243 | return; |
| 244 | |
| 245 | val = in_le32(DCSR_CGACRE5); |
| 246 | writel(val | 0x00000200, DCSR_CGACRE5); |
| 247 | |
| 248 | val = in_le32(EPU_EPCMPR5); |
| 249 | writel(interval_mhz, EPU_EPCMPR5); |
| 250 | val = in_le32(EPU_EPCCR5); |
| 251 | writel(val | 0x82820000, EPU_EPCCR5); |
| 252 | val = in_le32(EPU_EPSMCR5); |
| 253 | writel(val | 0x002f0000, EPU_EPSMCR5); |
| 254 | val = in_le32(EPU_EPECR5); |
| 255 | writel(val | 0x20000000, EPU_EPECR5); |
| 256 | val = in_le32(EPU_EPGCR); |
| 257 | writel(val | 0x80000000, EPU_EPGCR); |
| 258 | } |
| 259 | #endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */ |
| 260 | |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 261 | static void erratum_rcw_src(void) |
| 262 | { |
Santan Kumar | 9913648 | 2017-05-05 15:42:28 +0530 | [diff] [blame] | 263 | #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 264 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
| 265 | u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE; |
| 266 | u32 val; |
| 267 | |
| 268 | val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4); |
| 269 | val &= ~DCFG_PORSR1_RCW_SRC; |
| 270 | val |= DCFG_PORSR1_RCW_SRC_NOR; |
| 271 | out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val); |
| 272 | #endif |
| 273 | } |
| 274 | |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 275 | #define I2C_DEBUG_REG 0x6 |
| 276 | #define I2C_GLITCH_EN 0x8 |
| 277 | /* |
| 278 | * This erratum requires setting glitch_en bit to enable |
| 279 | * digital glitch filter to improve clock stability. |
| 280 | */ |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 281 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009203 |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 282 | static void erratum_a009203(void) |
| 283 | { |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 284 | #ifdef CONFIG_SYS_I2C |
Sriram Dash | afa125b | 2017-09-04 15:45:02 +0530 | [diff] [blame] | 285 | u8 __iomem *ptr; |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 286 | #ifdef I2C1_BASE_ADDR |
| 287 | ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG); |
| 288 | |
| 289 | writeb(I2C_GLITCH_EN, ptr); |
| 290 | #endif |
| 291 | #ifdef I2C2_BASE_ADDR |
| 292 | ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG); |
| 293 | |
| 294 | writeb(I2C_GLITCH_EN, ptr); |
| 295 | #endif |
| 296 | #ifdef I2C3_BASE_ADDR |
| 297 | ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG); |
| 298 | |
| 299 | writeb(I2C_GLITCH_EN, ptr); |
| 300 | #endif |
| 301 | #ifdef I2C4_BASE_ADDR |
| 302 | ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG); |
| 303 | |
| 304 | writeb(I2C_GLITCH_EN, ptr); |
| 305 | #endif |
| 306 | #endif |
| 307 | } |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 308 | #endif |
Shengzhou Liu | a3117ee | 2016-11-11 18:11:05 +0800 | [diff] [blame] | 309 | |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 310 | void bypass_smmu(void) |
| 311 | { |
| 312 | u32 val; |
| 313 | val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 314 | out_le32(SMMU_SCR0, val); |
| 315 | val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); |
| 316 | out_le32(SMMU_NSCR0, val); |
| 317 | } |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 318 | void fsl_lsch3_early_init_f(void) |
| 319 | { |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 320 | erratum_rcw_src(); |
Sriram Dash | 36a4a34 | 2017-09-04 15:44:05 +0530 | [diff] [blame] | 321 | #ifdef CONFIG_FSL_IFC |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 322 | init_early_memctl_regs(); /* tighten IFC timing */ |
Sriram Dash | 36a4a34 | 2017-09-04 15:44:05 +0530 | [diff] [blame] | 323 | #endif |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 324 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009203 |
York Sun | 0404a39 | 2015-03-23 10:41:35 -0700 | [diff] [blame] | 325 | erratum_a009203(); |
Ashish kumar | 3b52a23 | 2017-02-23 16:03:57 +0530 | [diff] [blame] | 326 | #endif |
Yao Yuan | fae8805 | 2015-12-05 14:59:14 +0800 | [diff] [blame] | 327 | erratum_a008514(); |
| 328 | erratum_a008336(); |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 329 | erratum_a009008(); |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 330 | erratum_a009798(); |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 331 | erratum_a008997(); |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 332 | erratum_a009007(); |
Saksham Jain | 5d8ffe1 | 2016-03-23 16:24:40 +0530 | [diff] [blame] | 333 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 334 | /* In case of Secure Boot, the IBR configures the SMMU |
| 335 | * to allow only Secure transactions. |
| 336 | * SMMU must be reset in bypass mode. |
| 337 | * Set the ClientPD bit and Clear the USFCFG Bit |
| 338 | */ |
| 339 | if (fsl_check_boot_mode_secure() == 1) |
| 340 | bypass_smmu(); |
| 341 | #endif |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 342 | } |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 343 | |
Rajesh Bhagat | 814e077 | 2018-01-17 16:13:00 +0530 | [diff] [blame] | 344 | /* Get VDD in the unit mV from voltage ID */ |
| 345 | int get_core_volt_from_fuse(void) |
| 346 | { |
| 347 | struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 348 | int vdd; |
| 349 | u32 fusesr; |
| 350 | u8 vid; |
| 351 | |
| 352 | /* get the voltage ID from fuse status register */ |
| 353 | fusesr = in_le32(&gur->dcfg_fusesr); |
| 354 | debug("%s: fusesr = 0x%x\n", __func__, fusesr); |
| 355 | vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_ALTVID_SHIFT) & |
| 356 | FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK; |
| 357 | if ((vid == 0) || (vid == FSL_CHASSIS3_DCFG_FUSESR_ALTVID_MASK)) { |
| 358 | vid = (fusesr >> FSL_CHASSIS3_DCFG_FUSESR_VID_SHIFT) & |
| 359 | FSL_CHASSIS3_DCFG_FUSESR_VID_MASK; |
| 360 | } |
| 361 | debug("%s: VID = 0x%x\n", __func__, vid); |
| 362 | switch (vid) { |
| 363 | case 0x00: /* VID isn't supported */ |
| 364 | vdd = -EINVAL; |
| 365 | debug("%s: The VID feature is not supported\n", __func__); |
| 366 | break; |
| 367 | case 0x08: /* 0.9V silicon */ |
| 368 | vdd = 900; |
| 369 | break; |
| 370 | case 0x10: /* 1.0V silicon */ |
| 371 | vdd = 1000; |
| 372 | break; |
| 373 | default: /* Other core voltage */ |
| 374 | vdd = -EINVAL; |
| 375 | debug("%s: The VID(%x) isn't supported\n", __func__, vid); |
| 376 | break; |
| 377 | } |
| 378 | debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd); |
| 379 | |
| 380 | return vdd; |
| 381 | } |
| 382 | |
Prabhakar Kushwaha | 1966d01 | 2016-06-03 18:41:27 +0530 | [diff] [blame] | 383 | #elif defined(CONFIG_FSL_LSCH2) |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 384 | |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 385 | static void erratum_a009929(void) |
| 386 | { |
| 387 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009929 |
| 388 | struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR; |
| 389 | u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR; |
| 390 | u32 rstrqmr1 = gur_in32(&gur->rstrqmr1); |
| 391 | |
| 392 | rstrqmr1 |= 0x00000400; |
| 393 | gur_out32(&gur->rstrqmr1, rstrqmr1); |
| 394 | writel(0x01000000, dcsr_cop_ccp); |
| 395 | #endif |
| 396 | } |
| 397 | |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 398 | /* |
| 399 | * This erratum requires setting a value to eddrtqcr1 to optimal |
| 400 | * the DDR performance. The eddrtqcr1 register is in SCFG space |
| 401 | * of LS1043A and the offset is 0x157_020c. |
| 402 | */ |
| 403 | #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \ |
| 404 | && defined(CONFIG_SYS_FSL_ERRATUM_A008514) |
| 405 | #error A009660 and A008514 can not be both enabled. |
| 406 | #endif |
| 407 | |
| 408 | static void erratum_a009660(void) |
| 409 | { |
| 410 | #ifdef CONFIG_SYS_FSL_ERRATUM_A009660 |
| 411 | u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c; |
| 412 | out_be32(eddrtqcr1, 0x63b20042); |
| 413 | #endif |
| 414 | } |
| 415 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 416 | static void erratum_a008850_early(void) |
| 417 | { |
| 418 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 419 | /* part 1 of 2 */ |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 420 | struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR + |
| 421 | CONFIG_SYS_CCI400_OFFSET); |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 422 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 423 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 424 | /* Skip if running at lower exception level */ |
| 425 | if (current_el() < 3) |
| 426 | return; |
| 427 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 428 | /* disables propagation of barrier transactions to DDRC from CCI400 */ |
| 429 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER); |
| 430 | |
| 431 | /* disable the re-ordering in DDRC */ |
| 432 | ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 433 | #endif |
| 434 | } |
| 435 | |
| 436 | void erratum_a008850_post(void) |
| 437 | { |
| 438 | #ifdef CONFIG_SYS_FSL_ERRATUM_A008850 |
| 439 | /* part 2 of 2 */ |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 440 | struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR + |
| 441 | CONFIG_SYS_CCI400_OFFSET); |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 442 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 443 | u32 tmp; |
| 444 | |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 445 | /* Skip if running at lower exception level */ |
| 446 | if (current_el() < 3) |
| 447 | return; |
| 448 | |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 449 | /* enable propagation of barrier transactions to DDRC from CCI400 */ |
| 450 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
| 451 | |
| 452 | /* enable the re-ordering in DDRC */ |
| 453 | tmp = ddr_in32(&ddr->eor); |
| 454 | tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS); |
| 455 | ddr_out32(&ddr->eor, tmp); |
| 456 | #endif |
| 457 | } |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 458 | |
| 459 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 460 | void erratum_a010315(void) |
| 461 | { |
| 462 | int i; |
| 463 | |
| 464 | for (i = PCIE1; i <= PCIE4; i++) |
| 465 | if (!is_serdes_configured(i)) { |
| 466 | debug("PCIe%d: disabled all R/W permission!\n", i); |
| 467 | set_pcie_ns_access(i, 0); |
| 468 | } |
| 469 | } |
| 470 | #endif |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 471 | |
Hou Zhiqiang | c06b30a | 2016-09-29 12:42:44 +0800 | [diff] [blame] | 472 | static void erratum_a010539(void) |
| 473 | { |
| 474 | #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT) |
| 475 | struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 476 | u32 porsr1; |
| 477 | |
| 478 | porsr1 = in_be32(&gur->porsr1); |
| 479 | porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK; |
| 480 | out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1), |
| 481 | porsr1); |
Hou Zhiqiang | 653793a | 2018-04-25 14:25:42 +0800 | [diff] [blame] | 482 | out_be32((void *)(CONFIG_SYS_FSL_SCFG_ADDR + 0x1a8), 0xffffffff); |
Hou Zhiqiang | c06b30a | 2016-09-29 12:42:44 +0800 | [diff] [blame] | 483 | #endif |
| 484 | } |
| 485 | |
Hou Zhiqiang | 4ad5999 | 2016-12-09 16:09:00 +0800 | [diff] [blame] | 486 | /* Get VDD in the unit mV from voltage ID */ |
| 487 | int get_core_volt_from_fuse(void) |
| 488 | { |
| 489 | struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR); |
| 490 | int vdd; |
| 491 | u32 fusesr; |
| 492 | u8 vid; |
| 493 | |
| 494 | fusesr = in_be32(&gur->dcfg_fusesr); |
| 495 | debug("%s: fusesr = 0x%x\n", __func__, fusesr); |
| 496 | vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) & |
| 497 | FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK; |
| 498 | if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) { |
| 499 | vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) & |
| 500 | FSL_CHASSIS2_DCFG_FUSESR_VID_MASK; |
| 501 | } |
| 502 | debug("%s: VID = 0x%x\n", __func__, vid); |
| 503 | switch (vid) { |
| 504 | case 0x00: /* VID isn't supported */ |
| 505 | vdd = -EINVAL; |
| 506 | debug("%s: The VID feature is not supported\n", __func__); |
| 507 | break; |
| 508 | case 0x08: /* 0.9V silicon */ |
| 509 | vdd = 900; |
| 510 | break; |
| 511 | case 0x10: /* 1.0V silicon */ |
| 512 | vdd = 1000; |
| 513 | break; |
| 514 | default: /* Other core voltage */ |
| 515 | vdd = -EINVAL; |
| 516 | printf("%s: The VID(%x) isn't supported\n", __func__, vid); |
| 517 | break; |
| 518 | } |
| 519 | debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd); |
| 520 | |
| 521 | return vdd; |
| 522 | } |
| 523 | |
| 524 | __weak int board_switch_core_volt(u32 vdd) |
| 525 | { |
| 526 | return 0; |
| 527 | } |
| 528 | |
| 529 | static int setup_core_volt(u32 vdd) |
| 530 | { |
| 531 | return board_setup_core_volt(vdd); |
| 532 | } |
| 533 | |
| 534 | #ifdef CONFIG_SYS_FSL_DDR |
| 535 | static void ddr_enable_0v9_volt(bool en) |
| 536 | { |
| 537 | struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 538 | u32 tmp; |
| 539 | |
| 540 | tmp = ddr_in32(&ddr->ddr_cdr1); |
| 541 | |
| 542 | if (en) |
| 543 | tmp |= DDR_CDR1_V0PT9_EN; |
| 544 | else |
| 545 | tmp &= ~DDR_CDR1_V0PT9_EN; |
| 546 | |
| 547 | ddr_out32(&ddr->ddr_cdr1, tmp); |
| 548 | } |
| 549 | #endif |
| 550 | |
| 551 | int setup_chip_volt(void) |
| 552 | { |
| 553 | int vdd; |
| 554 | |
| 555 | vdd = get_core_volt_from_fuse(); |
| 556 | /* Nothing to do for silicons doesn't support VID */ |
| 557 | if (vdd < 0) |
| 558 | return vdd; |
| 559 | |
| 560 | if (setup_core_volt(vdd)) |
| 561 | printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd); |
| 562 | #ifdef CONFIG_SYS_HAS_SERDES |
| 563 | if (setup_serdes_volt(vdd)) |
| 564 | printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd); |
| 565 | #endif |
| 566 | |
| 567 | #ifdef CONFIG_SYS_FSL_DDR |
| 568 | if (vdd == 900) |
| 569 | ddr_enable_0v9_volt(true); |
| 570 | #endif |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
Calvin Johnson | 6d6ef01 | 2018-03-08 15:30:33 +0530 | [diff] [blame] | 575 | #ifdef CONFIG_FSL_PFE |
| 576 | void init_pfe_scfg_dcfg_regs(void) |
| 577 | { |
| 578 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
| 579 | u32 ecccr2; |
| 580 | |
| 581 | out_be32(&scfg->pfeasbcr, |
| 582 | in_be32(&scfg->pfeasbcr) | SCFG_PFEASBCR_AWCACHE0); |
| 583 | out_be32(&scfg->pfebsbcr, |
| 584 | in_be32(&scfg->pfebsbcr) | SCFG_PFEASBCR_AWCACHE0); |
| 585 | |
| 586 | /* CCI-400 QoS settings for PFE */ |
| 587 | out_be32(&scfg->wr_qos1, (unsigned int)(SCFG_WR_QOS1_PFE1_QOS |
| 588 | | SCFG_WR_QOS1_PFE2_QOS)); |
| 589 | out_be32(&scfg->rd_qos1, (unsigned int)(SCFG_RD_QOS1_PFE1_QOS |
| 590 | | SCFG_RD_QOS1_PFE2_QOS)); |
| 591 | |
| 592 | ecccr2 = in_be32(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2); |
| 593 | out_be32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_ECCCR2, |
| 594 | ecccr2 | (unsigned int)DISABLE_PFE_ECC); |
| 595 | } |
| 596 | #endif |
| 597 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 598 | void fsl_lsch2_early_init_f(void) |
| 599 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 600 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 601 | CONFIG_SYS_CCI400_OFFSET); |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 602 | struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR; |
Pankit Garg | 41bde72 | 2019-05-29 12:12:36 +0000 | [diff] [blame] | 603 | #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT) |
| 604 | enum boot_src src; |
| 605 | #endif |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 606 | |
Hou Zhiqiang | 5ac9a5c | 2016-08-02 19:03:23 +0800 | [diff] [blame] | 607 | #ifdef CONFIG_LAYERSCAPE_NS_ACCESS |
| 608 | enable_layerscape_ns_access(); |
| 609 | #endif |
| 610 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 611 | #ifdef CONFIG_FSL_IFC |
| 612 | init_early_memctl_regs(); /* tighten IFC timing */ |
| 613 | #endif |
| 614 | |
Pankit Garg | 41bde72 | 2019-05-29 12:12:36 +0000 | [diff] [blame] | 615 | #if defined(CONFIG_FSL_QSPI) && defined(CONFIG_TFABOOT) |
| 616 | src = get_boot_src(); |
| 617 | if (src != BOOT_SOURCE_QSPI_NOR) |
| 618 | out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL); |
| 619 | #else |
Qianyu Gong | 5ab2d0a | 2016-03-16 18:01:52 +0800 | [diff] [blame] | 620 | #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT) |
Gong Qianyu | 760df89 | 2016-01-25 15:16:06 +0800 | [diff] [blame] | 621 | out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL); |
| 622 | #endif |
Pankit Garg | 41bde72 | 2019-05-29 12:12:36 +0000 | [diff] [blame] | 623 | #endif |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 624 | /* Make SEC reads and writes snoopable */ |
| 625 | setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP | |
Tang Yuantian | 2945ae0 | 2016-08-08 15:07:20 +0800 | [diff] [blame] | 626 | SCFG_SNPCNFGCR_SECWRSNP | |
| 627 | SCFG_SNPCNFGCR_SATARDSNP | |
| 628 | SCFG_SNPCNFGCR_SATAWRSNP); |
Aneesh Bansal | 13d984d | 2015-12-08 13:54:27 +0530 | [diff] [blame] | 629 | |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 630 | /* |
| 631 | * Enable snoop requests and DVM message requests for |
| 632 | * Slave insterface S4 (A53 core cluster) |
| 633 | */ |
York Sun | e6b871e | 2017-05-15 08:51:59 -0700 | [diff] [blame] | 634 | if (current_el() == 3) { |
| 635 | out_le32(&cci->slave[4].snoop_ctrl, |
| 636 | CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN); |
| 637 | } |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 638 | |
Ran Wang | 4e7cdcf | 2018-08-10 15:00:00 +0800 | [diff] [blame] | 639 | /* |
| 640 | * Program Central Security Unit (CSU) to grant access |
| 641 | * permission for USB 2.0 controller |
| 642 | */ |
| 643 | #if defined(CONFIG_ARCH_LS1012A) && defined(CONFIG_USB_EHCI_FSL) |
| 644 | if (current_el() == 3) |
| 645 | set_devices_ns_access(CSU_CSLX_USB_2, CSU_ALL_RW); |
| 646 | #endif |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 647 | /* Erratum */ |
Shengzhou Liu | ddf060b | 2016-04-07 16:22:21 +0800 | [diff] [blame] | 648 | erratum_a008850_early(); /* part 1 of 2 */ |
Mingkai Hu | 8beb075 | 2015-12-07 16:58:54 +0800 | [diff] [blame] | 649 | erratum_a009929(); |
Mingkai Hu | 172081c | 2016-02-02 11:28:03 +0800 | [diff] [blame] | 650 | erratum_a009660(); |
Hou Zhiqiang | c06b30a | 2016-09-29 12:42:44 +0800 | [diff] [blame] | 651 | erratum_a010539(); |
Ran Wang | b358b7b | 2017-09-04 18:46:48 +0800 | [diff] [blame] | 652 | erratum_a009008(); |
Ran Wang | 9e8fabc | 2017-09-04 18:46:49 +0800 | [diff] [blame] | 653 | erratum_a009798(); |
Ran Wang | e64f747 | 2017-09-04 18:46:50 +0800 | [diff] [blame] | 654 | erratum_a008997(); |
Ran Wang | 3ba6948 | 2017-09-04 18:46:51 +0800 | [diff] [blame] | 655 | erratum_a009007(); |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 656 | |
Laurentiu Tudor | 22012d5 | 2018-08-27 17:33:59 +0300 | [diff] [blame] | 657 | #if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) |
Laurentiu Tudor | 512d13e | 2018-08-09 15:19:46 +0300 | [diff] [blame] | 658 | set_icids(); |
| 659 | #endif |
Mingkai Hu | e4e93ea | 2015-10-26 19:47:51 +0800 | [diff] [blame] | 660 | } |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 661 | #endif |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 662 | |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 663 | #ifdef CONFIG_QSPI_AHB_INIT |
| 664 | /* Enable 4bytes address support and fast read */ |
| 665 | int qspi_ahb_init(void) |
| 666 | { |
| 667 | u32 *qspi_lut, lut_key, *qspi_key; |
| 668 | |
| 669 | qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300; |
| 670 | qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310; |
| 671 | |
| 672 | lut_key = in_be32(qspi_key); |
| 673 | |
| 674 | if (lut_key == 0x5af05af0) { |
| 675 | /* That means the register is BE */ |
| 676 | out_be32(qspi_key, 0x5af05af0); |
| 677 | /* Unlock the lut table */ |
| 678 | out_be32(qspi_key + 1, 0x00000002); |
| 679 | out_be32(qspi_lut, 0x0820040c); |
| 680 | out_be32(qspi_lut + 1, 0x1c080c08); |
| 681 | out_be32(qspi_lut + 2, 0x00002400); |
| 682 | /* Lock the lut table */ |
| 683 | out_be32(qspi_key, 0x5af05af0); |
| 684 | out_be32(qspi_key + 1, 0x00000001); |
| 685 | } else { |
| 686 | /* That means the register is LE */ |
| 687 | out_le32(qspi_key, 0x5af05af0); |
| 688 | /* Unlock the lut table */ |
| 689 | out_le32(qspi_key + 1, 0x00000002); |
| 690 | out_le32(qspi_lut, 0x0820040c); |
| 691 | out_le32(qspi_lut + 1, 0x1c080c08); |
| 692 | out_le32(qspi_lut + 2, 0x00002400); |
| 693 | /* Lock the lut table */ |
| 694 | out_le32(qspi_key, 0x5af05af0); |
| 695 | out_le32(qspi_key + 1, 0x00000001); |
| 696 | } |
| 697 | |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | #endif |
| 701 | |
| 702 | #ifdef CONFIG_TFABOOT |
Rajesh Bhagat | 5b73c90 | 2018-12-27 04:37:49 +0000 | [diff] [blame] | 703 | #define MAX_BOOTCMD_SIZE 512 |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 704 | |
| 705 | int fsl_setenv_bootcmd(void) |
| 706 | { |
| 707 | int ret; |
| 708 | enum boot_src src = get_boot_src(); |
| 709 | char bootcmd_str[MAX_BOOTCMD_SIZE]; |
| 710 | |
| 711 | switch (src) { |
| 712 | #ifdef IFC_NOR_BOOTCOMMAND |
| 713 | case BOOT_SOURCE_IFC_NOR: |
| 714 | sprintf(bootcmd_str, IFC_NOR_BOOTCOMMAND); |
| 715 | break; |
| 716 | #endif |
| 717 | #ifdef QSPI_NOR_BOOTCOMMAND |
| 718 | case BOOT_SOURCE_QSPI_NOR: |
| 719 | sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND); |
| 720 | break; |
| 721 | #endif |
| 722 | #ifdef XSPI_NOR_BOOTCOMMAND |
| 723 | case BOOT_SOURCE_XSPI_NOR: |
| 724 | sprintf(bootcmd_str, XSPI_NOR_BOOTCOMMAND); |
| 725 | break; |
| 726 | #endif |
| 727 | #ifdef IFC_NAND_BOOTCOMMAND |
| 728 | case BOOT_SOURCE_IFC_NAND: |
| 729 | sprintf(bootcmd_str, IFC_NAND_BOOTCOMMAND); |
| 730 | break; |
| 731 | #endif |
| 732 | #ifdef QSPI_NAND_BOOTCOMMAND |
| 733 | case BOOT_SOURCE_QSPI_NAND: |
| 734 | sprintf(bootcmd_str, QSPI_NAND_BOOTCOMMAND); |
| 735 | break; |
| 736 | #endif |
| 737 | #ifdef XSPI_NAND_BOOTCOMMAND |
| 738 | case BOOT_SOURCE_XSPI_NAND: |
| 739 | sprintf(bootcmd_str, XSPI_NAND_BOOTCOMMAND); |
| 740 | break; |
| 741 | #endif |
| 742 | #ifdef SD_BOOTCOMMAND |
| 743 | case BOOT_SOURCE_SD_MMC: |
| 744 | sprintf(bootcmd_str, SD_BOOTCOMMAND); |
| 745 | break; |
| 746 | #endif |
| 747 | #ifdef SD2_BOOTCOMMAND |
| 748 | case BOOT_SOURCE_SD_MMC2: |
| 749 | sprintf(bootcmd_str, SD2_BOOTCOMMAND); |
| 750 | break; |
| 751 | #endif |
| 752 | default: |
| 753 | #ifdef QSPI_NOR_BOOTCOMMAND |
| 754 | sprintf(bootcmd_str, QSPI_NOR_BOOTCOMMAND); |
| 755 | #endif |
| 756 | break; |
| 757 | } |
| 758 | |
| 759 | ret = env_set("bootcmd", bootcmd_str); |
| 760 | if (ret) { |
| 761 | printf("Failed to set bootcmd: ret = %d\n", ret); |
| 762 | return ret; |
| 763 | } |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 764 | return 0; |
| 765 | } |
Pankit Garg | 82fcc46 | 2018-11-05 18:02:31 +0000 | [diff] [blame] | 766 | |
| 767 | int fsl_setenv_mcinitcmd(void) |
| 768 | { |
| 769 | int ret = 0; |
| 770 | enum boot_src src = get_boot_src(); |
| 771 | |
| 772 | switch (src) { |
| 773 | #ifdef IFC_MC_INIT_CMD |
| 774 | case BOOT_SOURCE_IFC_NAND: |
| 775 | case BOOT_SOURCE_IFC_NOR: |
| 776 | ret = env_set("mcinitcmd", IFC_MC_INIT_CMD); |
| 777 | break; |
| 778 | #endif |
| 779 | #ifdef QSPI_MC_INIT_CMD |
| 780 | case BOOT_SOURCE_QSPI_NAND: |
| 781 | case BOOT_SOURCE_QSPI_NOR: |
| 782 | ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD); |
| 783 | break; |
| 784 | #endif |
| 785 | #ifdef XSPI_MC_INIT_CMD |
| 786 | case BOOT_SOURCE_XSPI_NAND: |
| 787 | case BOOT_SOURCE_XSPI_NOR: |
| 788 | ret = env_set("mcinitcmd", XSPI_MC_INIT_CMD); |
| 789 | break; |
| 790 | #endif |
| 791 | #ifdef SD_MC_INIT_CMD |
| 792 | case BOOT_SOURCE_SD_MMC: |
| 793 | ret = env_set("mcinitcmd", SD_MC_INIT_CMD); |
| 794 | break; |
| 795 | #endif |
| 796 | #ifdef SD2_MC_INIT_CMD |
| 797 | case BOOT_SOURCE_SD_MMC2: |
| 798 | ret = env_set("mcinitcmd", SD2_MC_INIT_CMD); |
| 799 | break; |
| 800 | #endif |
| 801 | default: |
| 802 | #ifdef QSPI_MC_INIT_CMD |
| 803 | ret = env_set("mcinitcmd", QSPI_MC_INIT_CMD); |
| 804 | #endif |
| 805 | break; |
| 806 | } |
| 807 | |
| 808 | if (ret) { |
| 809 | printf("Failed to set mcinitcmd: ret = %d\n", ret); |
| 810 | return ret; |
| 811 | } |
| 812 | return 0; |
| 813 | } |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 814 | #endif |
| 815 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 816 | #ifdef CONFIG_BOARD_LATE_INIT |
| 817 | int board_late_init(void) |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 818 | { |
Aneesh Bansal | 39d5b3b | 2016-01-22 16:37:26 +0530 | [diff] [blame] | 819 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 820 | fsl_setenv_chain_of_trust(); |
| 821 | #endif |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 822 | #ifdef CONFIG_TFABOOT |
| 823 | /* |
| 824 | * check if gd->env_addr is default_environment; then setenv bootcmd |
Pankit Garg | 82fcc46 | 2018-11-05 18:02:31 +0000 | [diff] [blame] | 825 | * and mcinitcmd. |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 826 | */ |
Pankit Garg | d6bd678 | 2019-05-30 12:04:15 +0000 | [diff] [blame^] | 827 | #if !defined(CONFIG_ENV_ADDR) || defined(ENV_IS_EMBEDDED) |
| 828 | if (gd->env_addr == (ulong)&default_environment[0]) { |
| 829 | #else |
Pankit Garg | 82fcc46 | 2018-11-05 18:02:31 +0000 | [diff] [blame] | 830 | if (gd->env_addr + gd->reloc_off == (ulong)&default_environment[0]) { |
Pankit Garg | d6bd678 | 2019-05-30 12:04:15 +0000 | [diff] [blame^] | 831 | #endif |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 832 | fsl_setenv_bootcmd(); |
Pankit Garg | 82fcc46 | 2018-11-05 18:02:31 +0000 | [diff] [blame] | 833 | fsl_setenv_mcinitcmd(); |
| 834 | } |
Rajesh Bhagat | 5b73c90 | 2018-12-27 04:37:49 +0000 | [diff] [blame] | 835 | |
| 836 | /* |
| 837 | * If the boot mode is secure, default environment is not present then |
| 838 | * setenv command needs to be run by default |
| 839 | */ |
| 840 | #ifdef CONFIG_CHAIN_OF_TRUST |
| 841 | if ((fsl_check_boot_mode_secure() == 1)) { |
| 842 | fsl_setenv_bootcmd(); |
| 843 | fsl_setenv_mcinitcmd(); |
| 844 | } |
| 845 | #endif |
Pankit Garg | bdbf84f | 2018-11-05 18:01:52 +0000 | [diff] [blame] | 846 | #endif |
Yuan Yao | 52ae4fd | 2016-12-01 10:13:52 +0800 | [diff] [blame] | 847 | #ifdef CONFIG_QSPI_AHB_INIT |
| 848 | qspi_ahb_init(); |
| 849 | #endif |
Tang Yuantian | 57894be | 2015-12-09 15:32:18 +0800 | [diff] [blame] | 850 | |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 851 | return 0; |
Scott Wood | 8e728cd | 2015-03-24 13:25:02 -0700 | [diff] [blame] | 852 | } |
| 853 | #endif |