blob: aa6a1849d4d351353d5ecd0a12e2aec45a3df491 [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>
8#include <fsl_ifc.h>
Tang Yuantian57894be2015-12-09 15:32:18 +08009#include <ahci.h>
10#include <scsi.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080011#include <asm/arch/fsl_serdes.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080012#include <asm/arch/soc.h>
Scott Woodae1df322015-03-20 19:28:13 -070013#include <asm/io.h>
Scott Wood8e728cd2015-03-24 13:25:02 -070014#include <asm/global_data.h>
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053015#include <asm/arch-fsl-layerscape/config.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080016#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +080017#include <fsl_csu.h>
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +080018#endif
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053019#ifdef CONFIG_SYS_FSL_DDR
Shengzhou Liuddf060b2016-04-07 16:22:21 +080020#include <fsl_ddr_sdram.h>
21#include <fsl_ddr.h>
Prabhakar Kushwahad169ebe2016-06-03 18:41:31 +053022#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +053023#ifdef CONFIG_CHAIN_OF_TRUST
24#include <fsl_validate.h>
25#endif
Scott Wood8e728cd2015-03-24 13:25:02 -070026
27DECLARE_GLOBAL_DATA_PTR;
Scott Woodae1df322015-03-20 19:28:13 -070028
York Suncbe8e1c2016-04-04 11:41:26 -070029bool soc_has_dp_ddr(void)
30{
31 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
32 u32 svr = gur_in32(&gur->svr);
33
34 /* LS2085A has DP_DDR */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053035 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070036 return true;
37
38 return false;
39}
40
41bool soc_has_aiop(void)
42{
43 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
44 u32 svr = gur_in32(&gur->svr);
45
46 /* LS2085A has AIOP */
Prabhakar Kushwahaac7f2422016-06-24 13:48:13 +053047 if (SVR_SOC_VER(svr) == SVR_LS2085A)
York Suncbe8e1c2016-04-04 11:41:26 -070048 return true;
49
50 return false;
51}
52
53#ifdef CONFIG_LS2080A
Yao Yuanfae88052015-12-05 14:59:14 +080054/*
55 * This erratum requires setting a value to eddrtqcr1 to
56 * optimal the DDR performance.
57 */
58static void erratum_a008336(void)
59{
60 u32 *eddrtqcr1;
61
62#ifdef CONFIG_SYS_FSL_ERRATUM_A008336
63#ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
64 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080065 if (fsl_ddr_get_version(0) == 0x50200)
66 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080067#endif
68#ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
69 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
Shengzhou Liu7beb0c42016-08-26 18:30:38 +080070 if (fsl_ddr_get_version(0) == 0x50200)
71 out_le32(eddrtqcr1, 0x63b30002);
Yao Yuanfae88052015-12-05 14:59:14 +080072#endif
73#endif
74}
75
76/*
77 * This erratum requires a register write before being Memory
78 * controller 3 being enabled.
79 */
80static void erratum_a008514(void)
81{
82 u32 *eddrtqcr1;
83
84#ifdef CONFIG_SYS_FSL_ERRATUM_A008514
85#ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
86 eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
87 out_le32(eddrtqcr1, 0x63b20002);
88#endif
89#endif
90}
Prabhakar Kushwaha22cfe962015-11-05 12:00:14 +053091#ifdef CONFIG_SYS_FSL_ERRATUM_A009635
92#define PLATFORM_CYCLE_ENV_VAR "a009635_interval_val"
93
94static unsigned long get_internval_val_mhz(void)
95{
96 char *interval = getenv(PLATFORM_CYCLE_ENV_VAR);
97 /*
98 * interval is the number of platform cycles(MHz) between
99 * wake up events generated by EPU.
100 */
101 ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
102
103 if (interval)
104 interval_mhz = simple_strtoul(interval, NULL, 10);
105
106 return interval_mhz;
107}
108
109void erratum_a009635(void)
110{
111 u32 val;
112 unsigned long interval_mhz = get_internval_val_mhz();
113
114 if (!interval_mhz)
115 return;
116
117 val = in_le32(DCSR_CGACRE5);
118 writel(val | 0x00000200, DCSR_CGACRE5);
119
120 val = in_le32(EPU_EPCMPR5);
121 writel(interval_mhz, EPU_EPCMPR5);
122 val = in_le32(EPU_EPCCR5);
123 writel(val | 0x82820000, EPU_EPCCR5);
124 val = in_le32(EPU_EPSMCR5);
125 writel(val | 0x002f0000, EPU_EPSMCR5);
126 val = in_le32(EPU_EPECR5);
127 writel(val | 0x20000000, EPU_EPECR5);
128 val = in_le32(EPU_EPGCR);
129 writel(val | 0x80000000, EPU_EPGCR);
130}
131#endif /* CONFIG_SYS_FSL_ERRATUM_A009635 */
132
Scott Wood8e728cd2015-03-24 13:25:02 -0700133static void erratum_rcw_src(void)
134{
135#if defined(CONFIG_SPL)
136 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
137 u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
138 u32 val;
139
140 val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
141 val &= ~DCFG_PORSR1_RCW_SRC;
142 val |= DCFG_PORSR1_RCW_SRC_NOR;
143 out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
144#endif
145}
146
York Sun0404a392015-03-23 10:41:35 -0700147#define I2C_DEBUG_REG 0x6
148#define I2C_GLITCH_EN 0x8
149/*
150 * This erratum requires setting glitch_en bit to enable
151 * digital glitch filter to improve clock stability.
152 */
153static void erratum_a009203(void)
154{
155 u8 __iomem *ptr;
156#ifdef CONFIG_SYS_I2C
157#ifdef I2C1_BASE_ADDR
158 ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
159
160 writeb(I2C_GLITCH_EN, ptr);
161#endif
162#ifdef I2C2_BASE_ADDR
163 ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
164
165 writeb(I2C_GLITCH_EN, ptr);
166#endif
167#ifdef I2C3_BASE_ADDR
168 ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
169
170 writeb(I2C_GLITCH_EN, ptr);
171#endif
172#ifdef I2C4_BASE_ADDR
173 ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
174
175 writeb(I2C_GLITCH_EN, ptr);
176#endif
177#endif
178}
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530179void bypass_smmu(void)
180{
181 u32 val;
182 val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
183 out_le32(SMMU_SCR0, val);
184 val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
185 out_le32(SMMU_NSCR0, val);
186}
Scott Woodf64c98c2015-03-20 19:28:12 -0700187void fsl_lsch3_early_init_f(void)
188{
Scott Wood8e728cd2015-03-24 13:25:02 -0700189 erratum_rcw_src();
Scott Woodf64c98c2015-03-20 19:28:12 -0700190 init_early_memctl_regs(); /* tighten IFC timing */
York Sun0404a392015-03-23 10:41:35 -0700191 erratum_a009203();
Yao Yuanfae88052015-12-05 14:59:14 +0800192 erratum_a008514();
193 erratum_a008336();
Saksham Jain5d8ffe12016-03-23 16:24:40 +0530194#ifdef CONFIG_CHAIN_OF_TRUST
195 /* In case of Secure Boot, the IBR configures the SMMU
196 * to allow only Secure transactions.
197 * SMMU must be reset in bypass mode.
198 * Set the ClientPD bit and Clear the USFCFG Bit
199 */
200 if (fsl_check_boot_mode_secure() == 1)
201 bypass_smmu();
202#endif
Scott Woodf64c98c2015-03-20 19:28:12 -0700203}
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800204
Tang Yuantian57894be2015-12-09 15:32:18 +0800205#ifdef CONFIG_SCSI_AHCI_PLAT
206int sata_init(void)
207{
208 struct ccsr_ahci __iomem *ccsr_ahci;
209
210 ccsr_ahci = (void *)CONFIG_SYS_SATA2;
211 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
212 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
213
214 ccsr_ahci = (void *)CONFIG_SYS_SATA1;
215 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
216 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
217
218 ahci_init((void __iomem *)CONFIG_SYS_SATA1);
219 scsi_scan(0);
220
221 return 0;
222}
223#endif
224
Prabhakar Kushwaha1966d012016-06-03 18:41:27 +0530225#elif defined(CONFIG_FSL_LSCH2)
Tang Yuantian57894be2015-12-09 15:32:18 +0800226#ifdef CONFIG_SCSI_AHCI_PLAT
227int sata_init(void)
228{
229 struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
230
York Sunbad49842016-09-26 08:09:24 -0700231#ifdef CONFIG_ARCH_LS1046A
Shaohui Xieed81e2b2016-09-07 17:56:12 +0800232 /* Disable SATA ECC */
233 out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
234#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800235 out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800236 out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
Tang Yuantian2945ae02016-08-08 15:07:20 +0800237 out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
Tang Yuantian57894be2015-12-09 15:32:18 +0800238
239 ahci_init((void __iomem *)CONFIG_SYS_SATA);
240 scsi_scan(0);
241
242 return 0;
243}
244#endif
245
Mingkai Hu8beb0752015-12-07 16:58:54 +0800246static void erratum_a009929(void)
247{
248#ifdef CONFIG_SYS_FSL_ERRATUM_A009929
249 struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
250 u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
251 u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
252
253 rstrqmr1 |= 0x00000400;
254 gur_out32(&gur->rstrqmr1, rstrqmr1);
255 writel(0x01000000, dcsr_cop_ccp);
256#endif
257}
258
Mingkai Hu172081c2016-02-02 11:28:03 +0800259/*
260 * This erratum requires setting a value to eddrtqcr1 to optimal
261 * the DDR performance. The eddrtqcr1 register is in SCFG space
262 * of LS1043A and the offset is 0x157_020c.
263 */
264#if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
265 && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
266#error A009660 and A008514 can not be both enabled.
267#endif
268
269static void erratum_a009660(void)
270{
271#ifdef CONFIG_SYS_FSL_ERRATUM_A009660
272 u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
273 out_be32(eddrtqcr1, 0x63b20042);
274#endif
275}
276
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800277static void erratum_a008850_early(void)
278{
279#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
280 /* part 1 of 2 */
281 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
282 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
283
284 /* disables propagation of barrier transactions to DDRC from CCI400 */
285 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
286
287 /* disable the re-ordering in DDRC */
288 ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
289#endif
290}
291
292void erratum_a008850_post(void)
293{
294#ifdef CONFIG_SYS_FSL_ERRATUM_A008850
295 /* part 2 of 2 */
296 struct ccsr_cci400 __iomem *cci = (void *)CONFIG_SYS_CCI400_ADDR;
297 struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
298 u32 tmp;
299
300 /* enable propagation of barrier transactions to DDRC from CCI400 */
301 out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
302
303 /* enable the re-ordering in DDRC */
304 tmp = ddr_in32(&ddr->eor);
305 tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
306 ddr_out32(&ddr->eor, tmp);
307#endif
308}
Hou Zhiqiang4b23ca82016-08-02 19:03:27 +0800309
310#ifdef CONFIG_SYS_FSL_ERRATUM_A010315
311void erratum_a010315(void)
312{
313 int i;
314
315 for (i = PCIE1; i <= PCIE4; i++)
316 if (!is_serdes_configured(i)) {
317 debug("PCIe%d: disabled all R/W permission!\n", i);
318 set_pcie_ns_access(i, 0);
319 }
320}
321#endif
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800322
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800323void fsl_lsch2_early_init_f(void)
324{
325 struct ccsr_cci400 *cci = (struct ccsr_cci400 *)CONFIG_SYS_CCI400_ADDR;
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530326 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800327
Hou Zhiqiang5ac9a5c2016-08-02 19:03:23 +0800328#ifdef CONFIG_LAYERSCAPE_NS_ACCESS
329 enable_layerscape_ns_access();
330#endif
331
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800332#ifdef CONFIG_FSL_IFC
333 init_early_memctl_regs(); /* tighten IFC timing */
334#endif
335
Qianyu Gong5ab2d0a2016-03-16 18:01:52 +0800336#if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
Gong Qianyu760df892016-01-25 15:16:06 +0800337 out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
338#endif
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530339 /* Make SEC reads and writes snoopable */
340 setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
Tang Yuantian2945ae02016-08-08 15:07:20 +0800341 SCFG_SNPCNFGCR_SECWRSNP |
342 SCFG_SNPCNFGCR_SATARDSNP |
343 SCFG_SNPCNFGCR_SATAWRSNP);
Aneesh Bansal13d984d2015-12-08 13:54:27 +0530344
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800345 /*
346 * Enable snoop requests and DVM message requests for
347 * Slave insterface S4 (A53 core cluster)
348 */
349 out_le32(&cci->slave[4].snoop_ctrl,
350 CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
Mingkai Hu8beb0752015-12-07 16:58:54 +0800351
352 /* Erratum */
Shengzhou Liuddf060b2016-04-07 16:22:21 +0800353 erratum_a008850_early(); /* part 1 of 2 */
Mingkai Hu8beb0752015-12-07 16:58:54 +0800354 erratum_a009929();
Mingkai Hu172081c2016-02-02 11:28:03 +0800355 erratum_a009660();
Mingkai Hue4e93ea2015-10-26 19:47:51 +0800356}
Mingkai Hu0e58b512015-10-26 19:47:50 +0800357#endif
Scott Wood8e728cd2015-03-24 13:25:02 -0700358
Mingkai Hu0e58b512015-10-26 19:47:50 +0800359#ifdef CONFIG_BOARD_LATE_INIT
360int board_late_init(void)
Scott Wood8e728cd2015-03-24 13:25:02 -0700361{
Tang Yuantian57894be2015-12-09 15:32:18 +0800362#ifdef CONFIG_SCSI_AHCI_PLAT
363 sata_init();
364#endif
Aneesh Bansal39d5b3b2016-01-22 16:37:26 +0530365#ifdef CONFIG_CHAIN_OF_TRUST
366 fsl_setenv_chain_of_trust();
367#endif
Tang Yuantian57894be2015-12-09 15:32:18 +0800368
Mingkai Hu0e58b512015-10-26 19:47:50 +0800369 return 0;
Scott Wood8e728cd2015-03-24 13:25:02 -0700370}
371#endif