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