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