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