]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv8/fsl-layerscape/soc.c
fsl-layerscape: Consolidate registers space defination for CCI-400 bus
[u-boot] / arch / arm / cpu / armv8 / fsl-layerscape / soc.c
1 /*
2  * Copyright 2014-2015 Freescale Semiconductor
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <fsl_immap.h>
9 #include <fsl_ifc.h>
10 #include <ahci.h>
11 #include <scsi.h>
12 #include <asm/arch/fsl_serdes.h>
13 #include <asm/arch/soc.h>
14 #include <asm/io.h>
15 #include <asm/global_data.h>
16 #include <asm/arch-fsl-layerscape/config.h>
17 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
18 #include <fsl_csu.h>
19 #endif
20 #ifdef CONFIG_SYS_FSL_DDR
21 #include <fsl_ddr_sdram.h>
22 #include <fsl_ddr.h>
23 #endif
24 #ifdef CONFIG_CHAIN_OF_TRUST
25 #include <fsl_validate.h>
26 #endif
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 bool soc_has_dp_ddr(void)
31 {
32         struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
33         u32 svr = gur_in32(&gur->svr);
34
35         /* LS2085A, LS2088A, LS2048A has DP_DDR */
36         if ((SVR_SOC_VER(svr) == SVR_LS2085A) ||
37             (SVR_SOC_VER(svr) == SVR_LS2088A) ||
38             (SVR_SOC_VER(svr) == SVR_LS2048A))
39                 return true;
40
41         return false;
42 }
43
44 bool soc_has_aiop(void)
45 {
46         struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
47         u32 svr = gur_in32(&gur->svr);
48
49         /* LS2085A has AIOP */
50         if (SVR_SOC_VER(svr) == SVR_LS2085A)
51                 return true;
52
53         return false;
54 }
55
56 #if defined(CONFIG_FSL_LSCH3)
57 /*
58  * This erratum requires setting a value to eddrtqcr1 to
59  * optimal the DDR performance.
60  */
61 static void erratum_a008336(void)
62 {
63 #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
64         u32 *eddrtqcr1;
65
66 #ifdef CONFIG_SYS_FSL_DCSR_DDR_ADDR
67         eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
68         if (fsl_ddr_get_version(0) == 0x50200)
69                 out_le32(eddrtqcr1, 0x63b30002);
70 #endif
71 #ifdef CONFIG_SYS_FSL_DCSR_DDR2_ADDR
72         eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
73         if (fsl_ddr_get_version(0) == 0x50200)
74                 out_le32(eddrtqcr1, 0x63b30002);
75 #endif
76 #endif
77 }
78
79 /*
80  * This erratum requires a register write before being Memory
81  * controller 3 being enabled.
82  */
83 static void erratum_a008514(void)
84 {
85 #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
86         u32 *eddrtqcr1;
87
88 #ifdef CONFIG_SYS_FSL_DCSR_DDR3_ADDR
89         eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
90         out_le32(eddrtqcr1, 0x63b20002);
91 #endif
92 #endif
93 }
94 #ifdef CONFIG_SYS_FSL_ERRATUM_A009635
95 #define PLATFORM_CYCLE_ENV_VAR  "a009635_interval_val"
96
97 static unsigned long get_internval_val_mhz(void)
98 {
99         char *interval = env_get(PLATFORM_CYCLE_ENV_VAR);
100         /*
101          *  interval is the number of platform cycles(MHz) between
102          *  wake up events generated by EPU.
103          */
104         ulong interval_mhz = get_bus_freq(0) / (1000 * 1000);
105
106         if (interval)
107                 interval_mhz = simple_strtoul(interval, NULL, 10);
108
109         return interval_mhz;
110 }
111
112 void erratum_a009635(void)
113 {
114         u32 val;
115         unsigned long interval_mhz = get_internval_val_mhz();
116
117         if (!interval_mhz)
118                 return;
119
120         val = in_le32(DCSR_CGACRE5);
121         writel(val | 0x00000200, DCSR_CGACRE5);
122
123         val = in_le32(EPU_EPCMPR5);
124         writel(interval_mhz, EPU_EPCMPR5);
125         val = in_le32(EPU_EPCCR5);
126         writel(val | 0x82820000, EPU_EPCCR5);
127         val = in_le32(EPU_EPSMCR5);
128         writel(val | 0x002f0000, EPU_EPSMCR5);
129         val = in_le32(EPU_EPECR5);
130         writel(val | 0x20000000, EPU_EPECR5);
131         val = in_le32(EPU_EPGCR);
132         writel(val | 0x80000000, EPU_EPGCR);
133 }
134 #endif  /* CONFIG_SYS_FSL_ERRATUM_A009635 */
135
136 static void erratum_rcw_src(void)
137 {
138 #if defined(CONFIG_SPL) && defined(CONFIG_NAND_BOOT)
139         u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
140         u32 __iomem *dcfg_dcsr = (u32 __iomem *)DCFG_DCSR_BASE;
141         u32 val;
142
143         val = in_le32(dcfg_ccsr + DCFG_PORSR1 / 4);
144         val &= ~DCFG_PORSR1_RCW_SRC;
145         val |= DCFG_PORSR1_RCW_SRC_NOR;
146         out_le32(dcfg_dcsr + DCFG_DCSR_PORCR1 / 4, val);
147 #endif
148 }
149
150 #define I2C_DEBUG_REG 0x6
151 #define I2C_GLITCH_EN 0x8
152 /*
153  * This erratum requires setting glitch_en bit to enable
154  * digital glitch filter to improve clock stability.
155  */
156 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
157 static void erratum_a009203(void)
158 {
159         u8 __iomem *ptr;
160 #ifdef CONFIG_SYS_I2C
161 #ifdef I2C1_BASE_ADDR
162         ptr = (u8 __iomem *)(I2C1_BASE_ADDR + I2C_DEBUG_REG);
163
164         writeb(I2C_GLITCH_EN, ptr);
165 #endif
166 #ifdef I2C2_BASE_ADDR
167         ptr = (u8 __iomem *)(I2C2_BASE_ADDR + I2C_DEBUG_REG);
168
169         writeb(I2C_GLITCH_EN, ptr);
170 #endif
171 #ifdef I2C3_BASE_ADDR
172         ptr = (u8 __iomem *)(I2C3_BASE_ADDR + I2C_DEBUG_REG);
173
174         writeb(I2C_GLITCH_EN, ptr);
175 #endif
176 #ifdef I2C4_BASE_ADDR
177         ptr = (u8 __iomem *)(I2C4_BASE_ADDR + I2C_DEBUG_REG);
178
179         writeb(I2C_GLITCH_EN, ptr);
180 #endif
181 #endif
182 }
183 #endif
184
185 void bypass_smmu(void)
186 {
187         u32 val;
188         val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
189         out_le32(SMMU_SCR0, val);
190         val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
191         out_le32(SMMU_NSCR0, val);
192 }
193 void fsl_lsch3_early_init_f(void)
194 {
195         erratum_rcw_src();
196         init_early_memctl_regs();       /* tighten IFC timing */
197 #ifdef CONFIG_SYS_FSL_ERRATUM_A009203
198         erratum_a009203();
199 #endif
200         erratum_a008514();
201         erratum_a008336();
202 #ifdef CONFIG_CHAIN_OF_TRUST
203         /* In case of Secure Boot, the IBR configures the SMMU
204         * to allow only Secure transactions.
205         * SMMU must be reset in bypass mode.
206         * Set the ClientPD bit and Clear the USFCFG Bit
207         */
208         if (fsl_check_boot_mode_secure() == 1)
209                 bypass_smmu();
210 #endif
211 }
212
213 #ifdef CONFIG_SCSI_AHCI_PLAT
214 int sata_init(void)
215 {
216         struct ccsr_ahci __iomem *ccsr_ahci;
217
218         ccsr_ahci  = (void *)CONFIG_SYS_SATA2;
219         out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
220         out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
221         out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
222
223         ccsr_ahci  = (void *)CONFIG_SYS_SATA1;
224         out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
225         out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
226         out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
227
228         ahci_init((void __iomem *)CONFIG_SYS_SATA1);
229         scsi_scan(false);
230
231         return 0;
232 }
233 #endif
234
235 #elif defined(CONFIG_FSL_LSCH2)
236 #ifdef CONFIG_SCSI_AHCI_PLAT
237 int sata_init(void)
238 {
239         struct ccsr_ahci __iomem *ccsr_ahci = (void *)CONFIG_SYS_SATA;
240
241         /* Disable SATA ECC */
242         out_le32((void *)CONFIG_SYS_DCSR_DCFG_ADDR + 0x520, 0x80000000);
243         out_le32(&ccsr_ahci->ppcfg, AHCI_PORT_PHY_1_CFG);
244         out_le32(&ccsr_ahci->ptc, AHCI_PORT_TRANS_CFG);
245         out_le32(&ccsr_ahci->axicc, AHCI_PORT_AXICC_CFG);
246
247         ahci_init((void __iomem *)CONFIG_SYS_SATA);
248         scsi_scan(false);
249
250         return 0;
251 }
252 #endif
253
254 static void erratum_a009929(void)
255 {
256 #ifdef CONFIG_SYS_FSL_ERRATUM_A009929
257         struct ccsr_gur *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
258         u32 __iomem *dcsr_cop_ccp = (void *)CONFIG_SYS_DCSR_COP_CCP_ADDR;
259         u32 rstrqmr1 = gur_in32(&gur->rstrqmr1);
260
261         rstrqmr1 |= 0x00000400;
262         gur_out32(&gur->rstrqmr1, rstrqmr1);
263         writel(0x01000000, dcsr_cop_ccp);
264 #endif
265 }
266
267 /*
268  * This erratum requires setting a value to eddrtqcr1 to optimal
269  * the DDR performance. The eddrtqcr1 register is in SCFG space
270  * of LS1043A and the offset is 0x157_020c.
271  */
272 #if defined(CONFIG_SYS_FSL_ERRATUM_A009660) \
273         && defined(CONFIG_SYS_FSL_ERRATUM_A008514)
274 #error A009660 and A008514 can not be both enabled.
275 #endif
276
277 static void erratum_a009660(void)
278 {
279 #ifdef CONFIG_SYS_FSL_ERRATUM_A009660
280         u32 *eddrtqcr1 = (void *)CONFIG_SYS_FSL_SCFG_ADDR + 0x20c;
281         out_be32(eddrtqcr1, 0x63b20042);
282 #endif
283 }
284
285 static void erratum_a008850_early(void)
286 {
287 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
288         /* part 1 of 2 */
289         struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
290                                                 CONFIG_SYS_CCI400_OFFSET);
291         struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
292
293         /* Skip if running at lower exception level */
294         if (current_el() < 3)
295                 return;
296
297         /* disables propagation of barrier transactions to DDRC from CCI400 */
298         out_le32(&cci->ctrl_ord, CCI400_CTRLORD_TERM_BARRIER);
299
300         /* disable the re-ordering in DDRC */
301         ddr_out32(&ddr->eor, DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
302 #endif
303 }
304
305 void erratum_a008850_post(void)
306 {
307 #ifdef CONFIG_SYS_FSL_ERRATUM_A008850
308         /* part 2 of 2 */
309         struct ccsr_cci400 __iomem *cci = (void *)(CONFIG_SYS_IMMR +
310                                                 CONFIG_SYS_CCI400_OFFSET);
311         struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
312         u32 tmp;
313
314         /* Skip if running at lower exception level */
315         if (current_el() < 3)
316                 return;
317
318         /* enable propagation of barrier transactions to DDRC from CCI400 */
319         out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
320
321         /* enable the re-ordering in DDRC */
322         tmp = ddr_in32(&ddr->eor);
323         tmp &= ~(DDR_EOR_RD_REOD_DIS | DDR_EOR_WD_REOD_DIS);
324         ddr_out32(&ddr->eor, tmp);
325 #endif
326 }
327
328 #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
329 void erratum_a010315(void)
330 {
331         int i;
332
333         for (i = PCIE1; i <= PCIE4; i++)
334                 if (!is_serdes_configured(i)) {
335                         debug("PCIe%d: disabled all R/W permission!\n", i);
336                         set_pcie_ns_access(i, 0);
337                 }
338 }
339 #endif
340
341 static void erratum_a010539(void)
342 {
343 #if defined(CONFIG_SYS_FSL_ERRATUM_A010539) && defined(CONFIG_QSPI_BOOT)
344         struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
345         u32 porsr1;
346
347         porsr1 = in_be32(&gur->porsr1);
348         porsr1 &= ~FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK;
349         out_be32((void *)(CONFIG_SYS_DCSR_DCFG_ADDR + DCFG_DCSR_PORCR1),
350                  porsr1);
351 #endif
352 }
353
354 /* Get VDD in the unit mV from voltage ID */
355 int get_core_volt_from_fuse(void)
356 {
357         struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
358         int vdd;
359         u32 fusesr;
360         u8 vid;
361
362         fusesr = in_be32(&gur->dcfg_fusesr);
363         debug("%s: fusesr = 0x%x\n", __func__, fusesr);
364         vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_ALTVID_SHIFT) &
365                 FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK;
366         if ((vid == 0) || (vid == FSL_CHASSIS2_DCFG_FUSESR_ALTVID_MASK)) {
367                 vid = (fusesr >> FSL_CHASSIS2_DCFG_FUSESR_VID_SHIFT) &
368                         FSL_CHASSIS2_DCFG_FUSESR_VID_MASK;
369         }
370         debug("%s: VID = 0x%x\n", __func__, vid);
371         switch (vid) {
372         case 0x00: /* VID isn't supported */
373                 vdd = -EINVAL;
374                 debug("%s: The VID feature is not supported\n", __func__);
375                 break;
376         case 0x08: /* 0.9V silicon */
377                 vdd = 900;
378                 break;
379         case 0x10: /* 1.0V silicon */
380                 vdd = 1000;
381                 break;
382         default:  /* Other core voltage */
383                 vdd = -EINVAL;
384                 printf("%s: The VID(%x) isn't supported\n", __func__, vid);
385                 break;
386         }
387         debug("%s: The required minimum volt of CORE is %dmV\n", __func__, vdd);
388
389         return vdd;
390 }
391
392 __weak int board_switch_core_volt(u32 vdd)
393 {
394         return 0;
395 }
396
397 static int setup_core_volt(u32 vdd)
398 {
399         return board_setup_core_volt(vdd);
400 }
401
402 #ifdef CONFIG_SYS_FSL_DDR
403 static void ddr_enable_0v9_volt(bool en)
404 {
405         struct ccsr_ddr __iomem *ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
406         u32 tmp;
407
408         tmp = ddr_in32(&ddr->ddr_cdr1);
409
410         if (en)
411                 tmp |= DDR_CDR1_V0PT9_EN;
412         else
413                 tmp &= ~DDR_CDR1_V0PT9_EN;
414
415         ddr_out32(&ddr->ddr_cdr1, tmp);
416 }
417 #endif
418
419 int setup_chip_volt(void)
420 {
421         int vdd;
422
423         vdd = get_core_volt_from_fuse();
424         /* Nothing to do for silicons doesn't support VID */
425         if (vdd < 0)
426                 return vdd;
427
428         if (setup_core_volt(vdd))
429                 printf("%s: Switch core VDD to %dmV failed\n", __func__, vdd);
430 #ifdef CONFIG_SYS_HAS_SERDES
431         if (setup_serdes_volt(vdd))
432                 printf("%s: Switch SVDD to %dmV failed\n", __func__, vdd);
433 #endif
434
435 #ifdef CONFIG_SYS_FSL_DDR
436         if (vdd == 900)
437                 ddr_enable_0v9_volt(true);
438 #endif
439
440         return 0;
441 }
442
443 void fsl_lsch2_early_init_f(void)
444 {
445         struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR +
446                                         CONFIG_SYS_CCI400_OFFSET);
447         struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
448
449 #ifdef CONFIG_LAYERSCAPE_NS_ACCESS
450         enable_layerscape_ns_access();
451 #endif
452
453 #ifdef CONFIG_FSL_IFC
454         init_early_memctl_regs();       /* tighten IFC timing */
455 #endif
456
457 #if defined(CONFIG_FSL_QSPI) && !defined(CONFIG_QSPI_BOOT)
458         out_be32(&scfg->qspi_cfg, SCFG_QSPI_CLKSEL);
459 #endif
460         /* Make SEC reads and writes snoopable */
461         setbits_be32(&scfg->snpcnfgcr, SCFG_SNPCNFGCR_SECRDSNP |
462                      SCFG_SNPCNFGCR_SECWRSNP |
463                      SCFG_SNPCNFGCR_SATARDSNP |
464                      SCFG_SNPCNFGCR_SATAWRSNP);
465
466         /*
467          * Enable snoop requests and DVM message requests for
468          * Slave insterface S4 (A53 core cluster)
469          */
470         if (current_el() == 3) {
471                 out_le32(&cci->slave[4].snoop_ctrl,
472                          CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
473         }
474
475         /* Erratum */
476         erratum_a008850_early(); /* part 1 of 2 */
477         erratum_a009929();
478         erratum_a009660();
479         erratum_a010539();
480 }
481 #endif
482
483 #ifdef CONFIG_QSPI_AHB_INIT
484 /* Enable 4bytes address support and fast read */
485 int qspi_ahb_init(void)
486 {
487         u32 *qspi_lut, lut_key, *qspi_key;
488
489         qspi_key = (void *)SYS_FSL_QSPI_ADDR + 0x300;
490         qspi_lut = (void *)SYS_FSL_QSPI_ADDR + 0x310;
491
492         lut_key = in_be32(qspi_key);
493
494         if (lut_key == 0x5af05af0) {
495                 /* That means the register is BE */
496                 out_be32(qspi_key, 0x5af05af0);
497                 /* Unlock the lut table */
498                 out_be32(qspi_key + 1, 0x00000002);
499                 out_be32(qspi_lut, 0x0820040c);
500                 out_be32(qspi_lut + 1, 0x1c080c08);
501                 out_be32(qspi_lut + 2, 0x00002400);
502                 /* Lock the lut table */
503                 out_be32(qspi_key, 0x5af05af0);
504                 out_be32(qspi_key + 1, 0x00000001);
505         } else {
506                 /* That means the register is LE */
507                 out_le32(qspi_key, 0x5af05af0);
508                 /* Unlock the lut table */
509                 out_le32(qspi_key + 1, 0x00000002);
510                 out_le32(qspi_lut, 0x0820040c);
511                 out_le32(qspi_lut + 1, 0x1c080c08);
512                 out_le32(qspi_lut + 2, 0x00002400);
513                 /* Lock the lut table */
514                 out_le32(qspi_key, 0x5af05af0);
515                 out_le32(qspi_key + 1, 0x00000001);
516         }
517
518         return 0;
519 }
520 #endif
521
522 #ifdef CONFIG_BOARD_LATE_INIT
523 int board_late_init(void)
524 {
525 #ifdef CONFIG_SCSI_AHCI_PLAT
526         sata_init();
527 #endif
528 #ifdef CONFIG_CHAIN_OF_TRUST
529         fsl_setenv_chain_of_trust();
530 #endif
531 #ifdef CONFIG_QSPI_AHB_INIT
532         qspi_ahb_init();
533 #endif
534
535         return 0;
536 }
537 #endif