blob: ae57c0e31d73550d09a5f6d8c4b530c6e0347861 [file] [log] [blame]
Scott Woodf64c98c2015-03-20 19:28:12 -07001/*
Mingkai Hu0e58b512015-10-26 19:47:50 +08002 * Copyright 2014-2015 Freescale Semiconductor
Scott Woodf64c98c2015-03-20 19:28:12 -07003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Ashish Kumar11234062017-08-11 11:09:14 +05308#include <fsl_immap.h>
Scott Woodf64c98c2015-03-20 19:28:12 -07009#include <fsl_ifc.h>
Tang Yuantian57894be2015-12-09 15:32:18 +080010#include <ahci.h>
11#include <scsi.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080012#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080013#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070014#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070015#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053016#include <asm/arch-fsl-layerscape/config.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080017#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080018#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080019#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053020#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080021#include <fsl_ddr_sdram.h>
22#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053023#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053024#ifdef CONFIG_CHAIN_OF_TRUST
25#include <fsl_validate.h>
26#endif
Ashish Kumarb25faa22017-08-31 16:12:53 +053027#include <fsl_immap.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070028
29DECLARE_GLOBAL_DATA_PTR;
Scott Woodae1df322015-03-20 19:28:13 -070030
York Suncbe8e1c2016-04-04 11:41:26 -070031bool soc_has_dp_ddr(void)
32{
33 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
34 u32 svr = gur_in32(&gur->svr);
35
Priyanka Jain4a6f1732016-11-17 12:29:55 +053036 /* LS2085A, LS2088A, LS2048A has DP_DDR */
37 if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
38 (SVR_SOC_VER(svr) == SVR_LS2088A) ||
39 (SVR_SOC_VER(svr) == SVR_LS2048A))
York Suncbe8e1c2016-04-04 11:41:26 -070040 return true;
41
42 return false;
43}
44
45bool soc_has_aiop(void)
46{
47 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
48 u32 svr = gur_in32(&gur->svr);
49
50 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053051 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070052 return true;
53
54 return false;
55}
56
Ran Wangb358b7b2017-09-04 18:46:48 +080057static inline void set_usb_txvreftune(u32 __iomem *scfg, u32 offset)
58{
59 scfg_clrsetbits32(scfg + offset / 4,
60 0xF << 6,
61 SCFG_USB_TXVREFTUNE << 6);
62}
63
64static void erratum_a009008(void)
65{
66#ifdef CONFIG_SYS_FSL_ERRATUM_A009008
67 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
Ran Wang9e8fabc2017-09-04 18:46:49 +080068
Ran Wang02dc77b2017-11-13 16:14:48 +080069#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
70 defined(CONFIG_ARCH_LS1012A)
Ran Wangb358b7b2017-09-04 18:46:48 +080071 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080072#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wangb358b7b2017-09-04 18:46:48 +080073 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB2);
74 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080075#endif
Ran Wangb358b7b2017-09-04 18:46:48 +080076#elif defined(CONFIG_ARCH_LS2080A)
77 set_usb_txvreftune(scfg, SCFG_USB3PRM1CR);
78#endif
79#endif /* CONFIG_SYS_FSL_ERRATUM_A009008 */
80}
81
Ran Wang9e8fabc2017-09-04 18:46:49 +080082static inline void set_usb_sqrxtune(u32 __iomem *scfg, u32 offset)
83{
84 scfg_clrbits32(scfg + offset / 4,
85 SCFG_USB_SQRXTUNE_MASK << 23);
86}
87
88static void erratum_a009798(void)
89{
90#ifdef CONFIG_SYS_FSL_ERRATUM_A009798
91 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
92
Ran Wang02dc77b2017-11-13 16:14:48 +080093#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
94 defined(CONFIG_ARCH_LS1012A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080095 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +080096#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang9e8fabc2017-09-04 18:46:49 +080097 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB2);
98 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR_USB3);
Ran Wang02dc77b2017-11-13 16:14:48 +080099#endif
Ran Wang9e8fabc2017-09-04 18:46:49 +0800100#elif defined(CONFIG_ARCH_LS2080A)
101 set_usb_sqrxtune(scfg, SCFG_USB3PRM1CR);
102#endif
103#endif /* CONFIG_SYS_FSL_ERRATUM_A009798 */
104}
105
Ran Wang02dc77b2017-11-13 16:14:48 +0800106#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
107 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800108static inline void set_usb_pcstxswingfull(u32 __iomem *scfg, u32 offset)
109{
110 scfg_clrsetbits32(scfg + offset / 4,
111 0x7F << 9,
112 SCFG_USB_PCSTXSWINGFULL << 9);
113}
114#endif
115
116static void erratum_a008997(void)
117{
118#ifdef CONFIG_SYS_FSL_ERRATUM_A008997
Ran Wang02dc77b2017-11-13 16:14:48 +0800119#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
120 defined(CONFIG_ARCH_LS1012A)
Ran Wange64f7472017-09-04 18:46:50 +0800121 u32 __iomem *scfg = (u32 __iomem *)SCFG_BASE;
122
123 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB1);
Ran Wang02dc77b2017-11-13 16:14:48 +0800124#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wange64f7472017-09-04 18:46:50 +0800125 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB2);
126 set_usb_pcstxswingfull(scfg, SCFG_USB3PRM2CR_USB3);
127#endif
Ran Wang02dc77b2017-11-13 16:14:48 +0800128#endif
Ran Wange64f7472017-09-04 18:46:50 +0800129#endif /* CONFIG_SYS_FSL_ERRATUM_A008997 */
130}
131
Ran Wang02dc77b2017-11-13 16:14:48 +0800132#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
133 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800134
135#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
136 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
137 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
138 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
139 out_be16((phy) + SCFG_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
140
Ran Wangef277072017-09-22 15:21:34 +0800141#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
Ran Wang3ba69482017-09-04 18:46:51 +0800142
143#define PROGRAM_USB_PHY_RX_OVRD_IN_HI(phy) \
144 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_1); \
145 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_2); \
146 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_3); \
147 out_le16((phy) + DCSR_USB_PHY_RX_OVRD_IN_HI, USB_PHY_RX_EQ_VAL_4)
148
149#endif
150
151static void erratum_a009007(void)
152{
Ran Wang02dc77b2017-11-13 16:14:48 +0800153#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A) || \
154 defined(CONFIG_ARCH_LS1012A)
Ran Wang3ba69482017-09-04 18:46:51 +0800155 void __iomem *usb_phy = (void __iomem *)SCFG_USB_PHY1;
156
157 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800158#if defined(CONFIG_ARCH_LS1043A) || defined(CONFIG_ARCH_LS1046A)
Ran Wang3ba69482017-09-04 18:46:51 +0800159 usb_phy = (void __iomem *)SCFG_USB_PHY2;
160 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
161
162 usb_phy = (void __iomem *)SCFG_USB_PHY3;
163 PROGRAM_USB_PHY_RX_OVRD_IN_HI(usb_phy);
Ran Wang02dc77b2017-11-13 16:14:48 +0800164#endif
Ran Wangef277072017-09-22 15:21:34 +0800165#elif defined(CONFIG_ARCH_LS2080A) || defined(CONFIG_ARCH_LS1088A)
Ran Wang3ba69482017-09-04 18:46:51 +0800166 void __iomem *dcsr = (void __iomem *)DCSR_BASE;
167
168 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY1);
169 PROGRAM_USB_PHY_RX_OVRD_IN_HI(dcsr + DCSR_USB_PHY2);
170#endif /* CONFIG_SYS_FSL_ERRATUM_A009007 */
171}
172
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800173#if defined(CONFIG_FSL_LSCH3)
Yao Yuanfae88052015-12-05 14:59:14 +0800174/*
175 * This erratum requires setting a value to eddrtqcr1 to
176 * optimal the DDR performance.
177 */
178static void erratum_a008336(void)
179{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800180#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
Yao Yuanfae88052015-12-05 14:59:14 +0800181 u32 *eddrtqcr1;
182
Yao Yuanfae88052015-12-05 14:59:14 +0800183#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
184 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800185 if (fsl_ddr_get_version(0) == 0x50200)
186 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800187#endif
188#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
189 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +0800190 if (fsl_ddr_get_version(0) == 0x50200)
191 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +0800192#endif
193#endif
194}
195
196/*
197 * This erratum requires a register write before being Memory
198 * controller 3 being enabled.
199 */
200static void erratum_a008514(void)
201{
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800202#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
Yao Yuanfae88052015-12-05 14:59:14 +0800203 u32 *eddrtqcr1;
204
Yao Yuanfae88052015-12-05 14:59:14 +0800205#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
206 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
207 out_le32(eddrtqcr1, 0x63b20002);
208#endif
209#endif
210}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530211#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
212#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
213
214static unsigned long get_internval_val_mhz(void)
215{
Simon Glass64b723f2017-08-03 12:22:12 -0600216 char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +0530217 /*
218 * interval is the number of platform cycles(MHz) between
219 * wake up events generated by EPU.
220 */
221 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
222
223 if (interval)
224 interval_mhz = simple_strtoul(interval, NULL, 10);
225
226 return interval_mhz;
227}
228
229void erratum_a009635(void)
230{
231 u32 val;
232 unsigned long interval_mhz = get_internval_val_mhz();
233
234 if (!interval_mhz)
235 return;
236
237 val = in_le32(DCSR_CGACRE5);
238 writel(val | 0x00000200, DCSR_CGACRE5);
239
240 val = in_le32(EPU_EPCMPR5);
241 writel(interval_mhz, EPU_EPCMPR5);
242 val = in_le32(EPU_EPCCR5);
243 writel(val | 0x82820000, EPU_EPCCR5);
244 val = in_le32(EPU_EPSMCR5);
245 writel(val | 0x002f0000, EPU_EPSMCR5);
246 val = in_le32(EPU_EPECR5);
247 writel(val | 0x20000000, EPU_EPECR5);
248 val = in_le32(EPU_EPGCR);
249 writel(val | 0x80000000, EPU_EPGCR);
250}
251#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
252
Scott Wood8e728cd2015-03-24 13:25:02 -0700253static void erratum_rcw_src(void)
254{
Santan Kumar99136482017-05-05 15:42:28 +0530255#if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
Scott Wood8e728cd2015-03-24 13:25:02 -0700256 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
257 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
258 u32 val;
259
260 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
261 val &= ~DCFG_PORSR1_RCW_SRC;
262 val |= DCFG_PORSR1_RCW_SRC_NOR;
263 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
264#endif
265}
266
York Sun0404a392015-03-23 10:41:35 -0700267#define I2C_DEBUG_REG 0x6
268#define I2C_GLITCH_EN 0x8
269/*
270 * This erratum requires setting glitch_en bit to enable
271 * digital glitch filter to improve clock stability.
272 */
Ashish kumar3b52a232017-02-23 16:03:57 +0530273#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700274static void erratum_a009203(void)
275{
York Sun0404a392015-03-23 10:41:35 -0700276#ifdef CONFIG_SYS_I2C
Sriram Dashafa125b2017-09-04 15:45:02 +0530277 u8 __iomem *ptr;
York Sun0404a392015-03-23 10:41:35 -0700278#ifdef I2C1_BASE_ADDR
279 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
280
281 writeb(I2C_GLITCH_EN, ptr);
282#endif
283#ifdef I2C2_BASE_ADDR
284 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
285
286 writeb(I2C_GLITCH_EN, ptr);
287#endif
288#ifdef I2C3_BASE_ADDR
289 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
290
291 writeb(I2C_GLITCH_EN, ptr);
292#endif
293#ifdef I2C4_BASE_ADDR
294 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
295
296 writeb(I2C_GLITCH_EN, ptr);
297#endif
298#endif
299}
Ashish kumar3b52a232017-02-23 16:03:57 +0530300#endif
Shengzhou Liua3117ee2016-11-11 18:11:05 +0800301
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530302void bypass_smmu(void)
303{
304 u32 val;
305 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
306 out_le32(SMMU_SCR0, val);
307 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
308 out_le32(SMMU_NSCR0, val);
309}
Scott Woodf64c98c2015-03-20 19:28:12 -0700310void fsl_lsch3_early_init_f(void)
311{
Scott Wood8e728cd2015-03-24 13:25:02 -0700312 erratum_rcw_src();
Sriram Dash36a4a342017-09-04 15:44:05 +0530313#ifdef CONFIG_FSL_IFC
Scott Woodf64c98c2015-03-20 19:28:12 -0700314 init_early_memctl_regs(); /* tighten IFC timing */
Sriram Dash36a4a342017-09-04 15:44:05 +0530315#endif
Ashish kumar3b52a232017-02-23 16:03:57 +0530316#ifdef CONFIG_SYS_FSL_ERRATUM_A009203
York Sun0404a392015-03-23 10:41:35 -0700317 erratum_a009203();
Ashish kumar3b52a232017-02-23 16:03:57 +0530318#endif
Yao Yuanfae88052015-12-05 14:59:14 +0800319 erratum_a008514();
320 erratum_a008336();
Ran Wangb358b7b2017-09-04 18:46:48 +0800321 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800322 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800323 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800324 erratum_a009007();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530325#ifdef CONFIG_CHAIN_OF_TRUST
326 /* In case of Secure Boot, the IBR configures the SMMU
327 * to allow only Secure transactions.
328 * SMMU must be reset in bypass mode.
329 * Set the ClientPD bit and Clear the USFCFG Bit
330 */
331 if (fsl_check_boot_mode_secure() == 1)
332 bypass_smmu();
333#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700334}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800335
Tang Yuantian57894be2015-12-09 15:32:18 +0800336#ifdef CONFIG_SCSI_AHCI_PLAT
337int sata_init(void)
338{
339 struct ccsr_ahci __iomem *ccsr_ahci;
340
Ashish Kumar3eec5122017-08-18 10:54:35 +0530341#ifdef CONFIG_SYS_SATA2
Tang Yuantian57894be2015-12-09 15:32:18 +0800342 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
343 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
344 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800345 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Ashish Kumar3eec5122017-08-18 10:54:35 +0530346#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800347
Ashish Kumar3eec5122017-08-18 10:54:35 +0530348#ifdef CONFIG_SYS_SATA1
Tang Yuantian57894be2015-12-09 15:32:18 +0800349 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
350 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
351 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantianab9c8312016-12-01 17:06:58 +0800352 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800353
354 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
Simon Glass48228732017-06-14 21:28:41 -0600355 scsi_scan(false);
Ashish Kumar3eec5122017-08-18 10:54:35 +0530356#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800357
358 return 0;
359}
360#endif
361
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530362#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800363#ifdef CONFIG_SCSI_AHCI_PLAT
364int sata_init(void)
365{
366 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
367
Shaohui Xieed81e2b2016-09-07 17:56:12 +0800368 /* Disable SATA ECC */
369 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
Tang Yuantian57894be2015-12-09 15:32:18 +0800370 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800371 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantian2945ae02016-08-08 15:07:20 +0800372 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800373
374 ahci_init((void __iomem *)CONFIG_SYS_SATA);
Simon Glass48228732017-06-14 21:28:41 -0600375 scsi_scan(false);
Tang Yuantian57894be2015-12-09 15:32:18 +0800376
377 return 0;
378}
379#endif
380
Mingkai Hu8beb0752015-12-07 16:58:54 +0800381static void erratum_a009929(void)
382{
383#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
384 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
385 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
386 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
387
388 rstrqmr1 |= 0x00000400;
389 gur_out32(&gur->rstrqmr1, rstrqmr1);
390 writel(0x01000000, dcsr_cop_ccp);
391#endif
392}
393
Mingkai Hu172081c2016-02-02 11:28:03 +0800394/*
395 * This erratum requires setting a value to eddrtqcr1 to optimal
396 * the DDR performance. The eddrtqcr1 register is in SCFG space
397 * of LS1043A and the offset is 0x157_020c.
398 */
399#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
400 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
401#error A009660 and A008514 can not be both enabled.
402#endif
403
404static void erratum_a009660(void)
405{
406#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
407 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
408 out_be32(eddrtqcr1, 0x63b20042);
409#endif
410}
411
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800412static void erratum_a008850_early(void)
413{
414#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
415 /* part 1 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530416 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
417 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800418 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
419
York Sune6b871e2017-05-15 08:51:59 -0700420 /* Skip if running at lower exception level */
421 if (current_el() < 3)
422 return;
423
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800424 /* disables propagation of barrier transactions to DDRC from CCI400 */
425 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
426
427 /* disable the re-ordering in DDRC */
428 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
429#endif
430}
431
432void erratum_a008850_post(void)
433{
434#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
435 /* part 2 of 2 */
Ashish Kumar11234062017-08-11 11:09:14 +0530436 struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
437 CONFIG_SYS_CCI400_OFFSET);
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800438 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
439 u32 tmp;
440
York Sune6b871e2017-05-15 08:51:59 -0700441 /* Skip if running at lower exception level */
442 if (current_el() < 3)
443 return;
444
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800445 /* enable propagation of barrier transactions to DDRC from CCI400 */
446 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
447
448 /* enable the re-ordering in DDRC */
449 tmp = ddr_in32(&ddr->eor);
450 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
451 ddr_out32(&ddr->eor, tmp);
452#endif
453}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800454
455#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
456void erratum_a010315(void)
457{
458 int i;
459
460 for (i = PCIE1; i <= PCIE4; i++)
461 if (!is_serdes_configured(i)) {
462 debug("PCIe%d: disabled all R/W permission!\n", i);
463 set_pcie_ns_access(i, 0);
464 }
465}
466#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800467
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800468static void erratum_a010539(void)
469{
470#if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
471 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
472 u32 porsr1;
473
474 porsr1 = in_be32(&gur->porsr1);
475 porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
476 out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
477 porsr1);
478#endif
479}
480
Hou Zhiqiang4ad59992016-12-09 16:09:00 +0800481/* Get VDD in the unit mV from voltage ID */
482int get_core_volt_from_fuse(void)
483{
484 struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
485 int vdd;
486 u32 fusesr;
487 u8 vid;
488
489 fusesr = in_be32(&gur->dcfg_fusesr);
490 debug("%s: fusesr = 0x%x\n", __func__, fusesr);
491 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
492 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
493 if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
494 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
495 FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
496 }
497 debug("%s: VID = 0x%x\n", __func__, vid);
498 switch (vid) {
499 case 0x00: /* VID isn't supported */
500 vdd = -EINVAL;
501 debug("%s: The VID feature is not supported\n", __func__);
502 break;
503 case 0x08: /* 0.9V silicon */
504 vdd = 900;
505 break;
506 case 0x10: /* 1.0V silicon */
507 vdd = 1000;
508 break;
509 default: /* Other core voltage */
510 vdd = -EINVAL;
511 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
512 break;
513 }
514 debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
515
516 return vdd;
517}
518
519__weak int board_switch_core_volt(u32 vdd)
520{
521 return 0;
522}
523
524static int setup_core_volt(u32 vdd)
525{
526 return board_setup_core_volt(vdd);
527}
528
529#ifdef CONFIG_SYS_FSL_DDR
530static void ddr_enable_0v9_volt(bool en)
531{
532 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
533 u32 tmp;
534
535 tmp = ddr_in32(&ddr->ddr_cdr1);
536
537 if (en)
538 tmp |= DDR_CDR1_V0PT9_EN;
539 else
540 tmp &= ~DDR_CDR1_V0PT9_EN;
541
542 ddr_out32(&ddr->ddr_cdr1, tmp);
543}
544#endif
545
546int setup_chip_volt(void)
547{
548 int vdd;
549
550 vdd = get_core_volt_from_fuse();
551 /* Nothing to do for silicons doesn't support VID */
552 if (vdd < 0)
553 return vdd;
554
555 if (setup_core_volt(vdd))
556 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
557#ifdef CONFIG_SYS_HAS_SERDES
558 if (setup_serdes_volt(vdd))
559 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
560#endif
561
562#ifdef CONFIG_SYS_FSL_DDR
563 if (vdd == 900)
564 ddr_enable_0v9_volt(true);
565#endif
566
567 return 0;
568}
569
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800570void fsl_lsch2_early_init_f(void)
571{
Ashish Kumar11234062017-08-11 11:09:14 +0530572 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
573 CONFIG_SYS_CCI400_OFFSET);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530574 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800575
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800576#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
577 enable_layerscape_ns_access();
578#endif
579
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800580#ifdef CONFIG_FSL_IFC
581 init_early_memctl_regs(); /* tighten IFC timing */
582#endif
583
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800584#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800585 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
586#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530587 /* Make SEC reads and writes snoopable */
588 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800589 SCFG_SNPCNFGCR_SECWRSNP |
590 SCFG_SNPCNFGCR_SATARDSNP |
591 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530592
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800593 /*
594 * Enable snoop requests and DVM message requests for
595 * Slave insterface S4 (A53 core cluster)
596 */
York Sune6b871e2017-05-15 08:51:59 -0700597 if (current_el() == 3) {
598 out_le32(&cci->slave[4].snoop_ctrl,
599 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
600 }
Mingkai Hu8beb0752015-12-07 16:58:54 +0800601
602 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800603 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800604 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800605 erratum_a009660();
Hou Zhiqiangc06b30a2016-09-29 12:42:44 +0800606 erratum_a010539();
Ran Wangb358b7b2017-09-04 18:46:48 +0800607 erratum_a009008();
Ran Wang9e8fabc2017-09-04 18:46:49 +0800608 erratum_a009798();
Ran Wange64f7472017-09-04 18:46:50 +0800609 erratum_a008997();
Ran Wang3ba69482017-09-04 18:46:51 +0800610 erratum_a009007();
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800611}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800612#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700613
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800614#ifdef CONFIG_QSPI_AHB_INIT
615/* Enable 4bytes address support and fast read */
616int qspi_ahb_init(void)
617{
618 u32 *qspi_lut, lut_key, *qspi_key;
619
620 qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
621 qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
622
623 lut_key = in_be32(qspi_key);
624
625 if (lut_key == 0x5af05af0) {
626 /* That means the register is BE */
627 out_be32(qspi_key, 0x5af05af0);
628 /* Unlock the lut table */
629 out_be32(qspi_key + 1, 0x00000002);
630 out_be32(qspi_lut, 0x0820040c);
631 out_be32(qspi_lut + 1, 0x1c080c08);
632 out_be32(qspi_lut + 2, 0x00002400);
633 /* Lock the lut table */
634 out_be32(qspi_key, 0x5af05af0);
635 out_be32(qspi_key + 1, 0x00000001);
636 } else {
637 /* That means the register is LE */
638 out_le32(qspi_key, 0x5af05af0);
639 /* Unlock the lut table */
640 out_le32(qspi_key + 1, 0x00000002);
641 out_le32(qspi_lut, 0x0820040c);
642 out_le32(qspi_lut + 1, 0x1c080c08);
643 out_le32(qspi_lut + 2, 0x00002400);
644 /* Lock the lut table */
645 out_le32(qspi_key, 0x5af05af0);
646 out_le32(qspi_key + 1, 0x00000001);
647 }
648
649 return 0;
650}
651#endif
652
Mingkai Hu0e58b512015-10-26 19:47:50 +0800653#ifdef CONFIG_BOARD_LATE_INIT
654int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700655{
Tang Yuantian57894be2015-12-09 15:32:18 +0800656#ifdef CONFIG_SCSI_AHCI_PLAT
657 sata_init();
658#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530659#ifdef CONFIG_CHAIN_OF_TRUST
660 fsl_setenv_chain_of_trust();
661#endif
Yuan Yao52ae4fd2016-12-01 10:13:52 +0800662#ifdef CONFIG_QSPI_AHB_INIT
663 qspi_ahb_init();
664#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800665
Mingkai Hu0e58b512015-10-26 19:47:50 +0800666 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700667}
668#endif