blob: 683fe4458862b7494bd07caf51ce3b9015e9545a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
York Sune2b65ea2015-03-20 19:28:24 -07002/*
Priyanka Jain51934052017-04-25 10:12:31 +05303 * Copyright (C) 2017 NXP Semiconductors
York Sune2b65ea2015-03-20 19:28:24 -07004 * Copyright 2015 Freescale Semiconductor
York Sune2b65ea2015-03-20 19:28:24 -07005 */
6#include <common.h>
7#include <malloc.h>
8#include <errno.h>
9#include <netdev.h>
10#include <fsl_ifc.h>
11#include <fsl_ddr.h>
12#include <asm/io.h>
Yangbo Lu5a4d7442015-05-28 14:53:55 +053013#include <hwconfig.h>
York Sune2b65ea2015-03-20 19:28:24 -070014#include <fdt_support.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090015#include <linux/libfdt.h>
York Sune2b65ea2015-03-20 19:28:24 -070016#include <fsl-mc/fsl_mc.h>
17#include <environment.h>
Alexander Graf215b1fb2016-11-17 01:02:59 +010018#include <efi_loader.h>
York Sune2b65ea2015-03-20 19:28:24 -070019#include <i2c.h>
York Sun4961eaf2017-03-06 09:02:34 -080020#include <asm/arch/mmu.h>
Mingkai Hu9f3183d2015-10-26 19:47:50 +080021#include <asm/arch/soc.h>
Santan Kumar54ad7b52017-03-07 11:21:03 +053022#include <asm/arch/ppa.h>
Saksham Jainfcfdb6d2016-03-23 16:24:35 +053023#include <fsl_sec.h>
York Sune2b65ea2015-03-20 19:28:24 -070024
Priyanka Jaind1418c12017-04-28 10:41:34 +053025#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -070026#include "../common/qixis.h"
Prabhakar Kushwaha44937212015-11-09 16:42:07 +053027#include "ls2080ardb_qixis.h"
Priyanka Jaind1418c12017-04-28 10:41:34 +053028#endif
Rai Harnindered2530d2016-03-23 17:04:38 +053029#include "../common/vid.h"
York Sune2b65ea2015-03-20 19:28:24 -070030
Yangbo Lu5a4d7442015-05-28 14:53:55 +053031#define PIN_MUX_SEL_SDHC 0x00
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +080032#define PIN_MUX_SEL_DSPI 0x0a
Yangbo Lu5a4d7442015-05-28 14:53:55 +053033
34#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
York Sune2b65ea2015-03-20 19:28:24 -070035DECLARE_GLOBAL_DATA_PTR;
36
Yangbo Lu5a4d7442015-05-28 14:53:55 +053037enum {
38 MUX_TYPE_SDHC,
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +080039 MUX_TYPE_DSPI,
Yangbo Lu5a4d7442015-05-28 14:53:55 +053040};
41
York Sune2b65ea2015-03-20 19:28:24 -070042unsigned long long get_qixis_addr(void)
43{
44 unsigned long long addr;
45
46 if (gd->flags & GD_FLG_RELOC)
47 addr = QIXIS_BASE_PHYS;
48 else
49 addr = QIXIS_BASE_PHYS_EARLY;
50
51 /*
52 * IFC address under 256MB is mapped to 0x30000000, any address above
53 * is mapped to 0x5_10000000 up to 4GB.
54 */
55 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
56
57 return addr;
58}
59
60int checkboard(void)
61{
Priyanka Jaind1418c12017-04-28 10:41:34 +053062#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -070063 u8 sw;
Priyanka Jaind1418c12017-04-28 10:41:34 +053064#endif
Prabhakar Kushwahaff1b8e32015-05-28 14:54:07 +053065 char buf[15];
66
67 cpu_name(buf);
68 printf("Board: %s-RDB, ", buf);
York Sune2b65ea2015-03-20 19:28:24 -070069
Priyanka Jain3049a582017-04-27 15:08:07 +053070#ifdef CONFIG_TARGET_LS2081ARDB
71#ifdef CONFIG_FSL_QIXIS
72 sw = QIXIS_READ(arch);
Priyanka Jain3049a582017-04-27 15:08:07 +053073 printf("Board version: %c, ", (sw & 0xf) + 'A');
74
75 sw = QIXIS_READ(brdcfg[0]);
Priyanka Jainda28a032018-01-08 12:20:42 +053076 sw = (sw >> QIXIS_QMAP_SHIFT) & QIXIS_QMAP_MASK;
Priyanka Jain3049a582017-04-27 15:08:07 +053077 switch (sw) {
78 case 0:
79 puts("boot from QSPI DEV#0\n");
80 puts("QSPI_CSA_1 mapped to QSPI DEV#1\n");
81 break;
82 case 1:
83 puts("boot from QSPI DEV#1\n");
84 puts("QSPI_CSA_1 mapped to QSPI DEV#0\n");
85 break;
86 case 2:
87 puts("boot from QSPI EMU\n");
88 puts("QSPI_CSA_1 mapped to QSPI DEV#0\n");
89 break;
90 case 3:
91 puts("boot from QSPI EMU\n");
92 puts("QSPI_CSA_1 mapped to QSPI DEV#1\n");
93 break;
94 case 4:
95 puts("boot from QSPI DEV#0\n");
96 puts("QSPI_CSA_1 mapped to QSPI EMU\n");
97 break;
98 default:
99 printf("invalid setting of SW%u\n", sw);
100 break;
101 }
Priyanka Jainf436fbf2018-01-08 12:59:31 +0530102 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Priyanka Jain3049a582017-04-27 15:08:07 +0530103#endif
104 puts("SERDES1 Reference : ");
105 printf("Clock1 = 100MHz ");
106 printf("Clock2 = 161.13MHz");
107#else
Priyanka Jaind1418c12017-04-28 10:41:34 +0530108#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -0700109 sw = QIXIS_READ(arch);
York Sune2b65ea2015-03-20 19:28:24 -0700110 printf("Board Arch: V%d, ", sw >> 4);
Prabhakar Kushwaha27df54b2015-05-28 14:54:04 +0530111 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
York Sune2b65ea2015-03-20 19:28:24 -0700112
113 sw = QIXIS_READ(brdcfg[0]);
114 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
115
116 if (sw < 0x8)
117 printf("vBank: %d\n", sw);
118 else if (sw == 0x9)
119 puts("NAND\n");
120 else
121 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
122
123 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
Priyanka Jaind1418c12017-04-28 10:41:34 +0530124#endif
York Sune2b65ea2015-03-20 19:28:24 -0700125 puts("SERDES1 Reference : ");
126 printf("Clock1 = 156.25MHz ");
127 printf("Clock2 = 156.25MHz");
Priyanka Jain3049a582017-04-27 15:08:07 +0530128#endif
York Sune2b65ea2015-03-20 19:28:24 -0700129
130 puts("\nSERDES2 Reference : ");
131 printf("Clock1 = 100MHz ");
132 printf("Clock2 = 100MHz\n");
133
134 return 0;
135}
136
137unsigned long get_board_sys_clk(void)
138{
Priyanka Jaind1418c12017-04-28 10:41:34 +0530139#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -0700140 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
141
142 switch (sysclk_conf & 0x0F) {
143 case QIXIS_SYSCLK_83:
144 return 83333333;
145 case QIXIS_SYSCLK_100:
146 return 100000000;
147 case QIXIS_SYSCLK_125:
148 return 125000000;
149 case QIXIS_SYSCLK_133:
150 return 133333333;
151 case QIXIS_SYSCLK_150:
152 return 150000000;
153 case QIXIS_SYSCLK_160:
154 return 160000000;
155 case QIXIS_SYSCLK_166:
156 return 166666666;
157 }
Priyanka Jaind1418c12017-04-28 10:41:34 +0530158#endif
159 return 100000000;
York Sune2b65ea2015-03-20 19:28:24 -0700160}
161
162int select_i2c_ch_pca9547(u8 ch)
163{
164 int ret;
165
166 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
167 if (ret) {
168 puts("PCA: failed to select proper channel\n");
169 return ret;
170 }
171
172 return 0;
173}
174
Rai Harnindered2530d2016-03-23 17:04:38 +0530175int i2c_multiplexer_select_vid_channel(u8 channel)
176{
177 return select_i2c_ch_pca9547(channel);
178}
179
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +0800180int config_board_mux(int ctrl_type)
181{
Priyanka Jaind1418c12017-04-28 10:41:34 +0530182#ifdef CONFIG_FSL_QIXIS
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +0800183 u8 reg5;
184
185 reg5 = QIXIS_READ(brdcfg[5]);
186
187 switch (ctrl_type) {
188 case MUX_TYPE_SDHC:
189 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
190 break;
191 case MUX_TYPE_DSPI:
192 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
193 break;
194 default:
195 printf("Wrong mux interface type\n");
196 return -1;
197 }
198
199 QIXIS_WRITE(brdcfg[5], reg5);
Priyanka Jaind1418c12017-04-28 10:41:34 +0530200#endif
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +0800201 return 0;
202}
203
York Sune2b65ea2015-03-20 19:28:24 -0700204int board_init(void)
205{
York Sun931e8752016-05-26 13:59:03 -0700206#ifdef CONFIG_FSL_MC_ENET
Shaohui Xieabc7d0f2016-01-28 15:38:15 +0800207 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
York Sun931e8752016-05-26 13:59:03 -0700208#endif
Haikun.Wang@freescale.com5989df72015-06-26 19:58:24 +0800209
York Sune2b65ea2015-03-20 19:28:24 -0700210 init_final_memctl_regs();
211
212#ifdef CONFIG_ENV_IS_NOWHERE
213 gd->env_addr = (ulong)&default_environment[0];
214#endif
215 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
216
Priyanka Jaind1418c12017-04-28 10:41:34 +0530217#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -0700218 QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET_EN);
Priyanka Jaind1418c12017-04-28 10:41:34 +0530219#endif
Udit Agarwal15e7c682017-08-16 07:13:29 -0400220
221#ifdef CONFIG_FSL_CAAM
222 sec_init();
223#endif
Santan Kumar54ad7b52017-03-07 11:21:03 +0530224#ifdef CONFIG_FSL_LS_PPA
225 ppa_init();
226#endif
227
York Sun931e8752016-05-26 13:59:03 -0700228#ifdef CONFIG_FSL_MC_ENET
Shaohui Xieabc7d0f2016-01-28 15:38:15 +0800229 /* invert AQR405 IRQ pins polarity */
230 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR405_IRQ_MASK);
York Sun931e8752016-05-26 13:59:03 -0700231#endif
Udit Agarwala8c6fd42017-02-03 22:53:38 +0530232#ifdef CONFIG_FSL_CAAM
233 sec_init();
234#endif
Shaohui Xieabc7d0f2016-01-28 15:38:15 +0800235
York Sune2b65ea2015-03-20 19:28:24 -0700236 return 0;
237}
238
239int board_early_init_f(void)
240{
Priyanka Jain3049a582017-04-27 15:08:07 +0530241#ifdef CONFIG_SYS_I2C_EARLY_INIT
242 i2c_early_init_f();
243#endif
York Sune2b65ea2015-03-20 19:28:24 -0700244 fsl_lsch3_early_init_f();
245 return 0;
246}
247
Yangbo Lu5a4d7442015-05-28 14:53:55 +0530248int misc_init_r(void)
249{
Santan Kumar263536a2017-06-15 17:07:01 +0530250 char *env_hwconfig;
251 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
252 u32 val;
Priyanka Jainb5dfd472017-09-15 10:19:48 +0530253 struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR);
254 u32 svr = gur_in32(&gur->svr);
Santan Kumar263536a2017-06-15 17:07:01 +0530255
256 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
257
Simon Glass00caae62017-08-03 12:22:12 -0600258 env_hwconfig = env_get("hwconfig");
Santan Kumar263536a2017-06-15 17:07:01 +0530259
260 if (hwconfig_f("dspi", env_hwconfig) &&
261 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
262 config_board_mux(MUX_TYPE_DSPI);
263 else
264 config_board_mux(MUX_TYPE_SDHC);
265
Priyanka Jain3049a582017-04-27 15:08:07 +0530266 /*
Santan Kumar6cc914e2017-06-09 11:48:05 +0530267 * LS2081ARDB RevF board has smart voltage translator
Priyanka Jain51934052017-04-25 10:12:31 +0530268 * which needs to be programmed to enable high speed SD interface
269 * by setting GPIO4_10 output to zero
270 */
Santan Kumar6cc914e2017-06-09 11:48:05 +0530271#ifdef CONFIG_TARGET_LS2081ARDB
Priyanka Jain51934052017-04-25 10:12:31 +0530272 out_le32(GPIO4_GPDIR_ADDR, (1 << 21 |
273 in_le32(GPIO4_GPDIR_ADDR)));
274 out_le32(GPIO4_GPDAT_ADDR, (~(1 << 21) &
275 in_le32(GPIO4_GPDAT_ADDR)));
Priyanka Jain51934052017-04-25 10:12:31 +0530276#endif
Yangbo Lu5a4d7442015-05-28 14:53:55 +0530277 if (hwconfig("sdhc"))
278 config_board_mux(MUX_TYPE_SDHC);
279
Rai Harnindered2530d2016-03-23 17:04:38 +0530280 if (adjust_vdd(0))
281 printf("Warning: Adjusting core voltage failed.\n");
Priyanka Jainb5dfd472017-09-15 10:19:48 +0530282 /*
283 * Default value of board env is based on filename which is
284 * ls2080ardb. Modify board env for other supported SoCs
285 */
286 if ((SVR_SOC_VER(svr) == SVR_LS2088A) ||
287 (SVR_SOC_VER(svr) == SVR_LS2048A))
288 env_set("board", "ls2088ardb");
289 else if ((SVR_SOC_VER(svr) == SVR_LS2081A) ||
290 (SVR_SOC_VER(svr) == SVR_LS2041A))
291 env_set("board", "ls2081ardb");
Rai Harnindered2530d2016-03-23 17:04:38 +0530292
Yangbo Lu5a4d7442015-05-28 14:53:55 +0530293 return 0;
294}
295
York Sune2b65ea2015-03-20 19:28:24 -0700296void detail_board_ddr_info(void)
297{
298 puts("\nDDR ");
299 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
300 print_ddr_info(0);
Prabhakar Kushwaha44937212015-11-09 16:42:07 +0530301#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Sun3c1d2182016-04-04 11:41:26 -0700302 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
York Sune2b65ea2015-03-20 19:28:24 -0700303 puts("\nDP-DDR ");
304 print_size(gd->bd->bi_dram[2].size, "");
305 print_ddr_info(CONFIG_DP_DDR_CTRL);
306 }
Prabhakar Kushwaha44937212015-11-09 16:42:07 +0530307#endif
York Sune2b65ea2015-03-20 19:28:24 -0700308}
309
York Sune2b65ea2015-03-20 19:28:24 -0700310#if defined(CONFIG_ARCH_MISC_INIT)
311int arch_misc_init(void)
312{
York Sune2b65ea2015-03-20 19:28:24 -0700313 return 0;
314}
315#endif
316
York Sune2b65ea2015-03-20 19:28:24 -0700317#ifdef CONFIG_FSL_MC_ENET
318void fdt_fixup_board_enet(void *fdt)
319{
320 int offset;
321
Stuart Yodere91f1de2016-03-02 16:37:13 -0600322 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sune2b65ea2015-03-20 19:28:24 -0700323
324 if (offset < 0)
Stuart Yodere91f1de2016-03-02 16:37:13 -0600325 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sune2b65ea2015-03-20 19:28:24 -0700326
327 if (offset < 0) {
328 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
329 __func__, offset);
330 return;
331 }
332
Yogesh Gaur70a131e2017-12-07 11:10:14 +0530333 if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0))
York Sune2b65ea2015-03-20 19:28:24 -0700334 fdt_status_okay(fdt, offset);
335 else
336 fdt_status_fail(fdt, offset);
337}
Alexander Grafb7b84102016-11-17 01:02:57 +0100338
339void board_quiesce_devices(void)
340{
341 fsl_mc_ldpaa_exit(gd->bd);
342}
York Sune2b65ea2015-03-20 19:28:24 -0700343#endif
344
345#ifdef CONFIG_OF_BOARD_SETUP
Santan Kumar7794d9a2017-07-05 18:05:08 +0530346void fsl_fdt_fixup_flash(void *fdt)
347{
348 int offset;
349
350/*
351 * IFC and QSPI are muxed on board.
352 * So disable IFC node in dts if QSPI is enabled or
353 * disable QSPI node in dts in case QSPI is not enabled.
354 */
355#ifdef CONFIG_FSL_QSPI
356 offset = fdt_path_offset(fdt, "/soc/ifc");
357
358 if (offset < 0)
359 offset = fdt_path_offset(fdt, "/ifc");
360#else
361 offset = fdt_path_offset(fdt, "/soc/quadspi");
362
363 if (offset < 0)
364 offset = fdt_path_offset(fdt, "/quadspi");
365#endif
366 if (offset < 0)
367 return;
368
369 fdt_status_disabled(fdt, offset);
370}
371
York Sune2b65ea2015-03-20 19:28:24 -0700372int ft_board_setup(void *blob, bd_t *bd)
373{
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530374 u64 base[CONFIG_NR_DRAM_BANKS];
375 u64 size[CONFIG_NR_DRAM_BANKS];
York Sune2b65ea2015-03-20 19:28:24 -0700376
377 ft_cpu_setup(blob, bd);
378
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530379 /* fixup DT for the two GPP DDR banks */
380 base[0] = gd->bd->bi_dram[0].start;
381 size[0] = gd->bd->bi_dram[0].size;
382 base[1] = gd->bd->bi_dram[1].start;
383 size[1] = gd->bd->bi_dram[1].size;
384
York Sun36cc0de2017-03-06 09:02:28 -0800385#ifdef CONFIG_RESV_RAM
386 /* reduce size if reserved memory is within this bank */
387 if (gd->arch.resv_ram >= base[0] &&
388 gd->arch.resv_ram < base[0] + size[0])
389 size[0] = gd->arch.resv_ram - base[0];
390 else if (gd->arch.resv_ram >= base[1] &&
391 gd->arch.resv_ram < base[1] + size[1])
392 size[1] = gd->arch.resv_ram - base[1];
393#endif
394
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530395 fdt_fixup_memory_banks(blob, base, size, 2);
York Sune2b65ea2015-03-20 19:28:24 -0700396
Sriram Dasha5c289b2016-09-16 17:12:15 +0530397 fsl_fdt_fixup_dr_usb(blob, bd);
Sriram Dashef53b8c2016-06-13 09:58:36 +0530398
Santan Kumar7794d9a2017-07-05 18:05:08 +0530399 fsl_fdt_fixup_flash(blob);
400
York Sune2b65ea2015-03-20 19:28:24 -0700401#ifdef CONFIG_FSL_MC_ENET
402 fdt_fixup_board_enet(blob);
York Sune2b65ea2015-03-20 19:28:24 -0700403#endif
404
405 return 0;
406}
407#endif
408
409void qixis_dump_switch(void)
410{
Priyanka Jaind1418c12017-04-28 10:41:34 +0530411#ifdef CONFIG_FSL_QIXIS
York Sune2b65ea2015-03-20 19:28:24 -0700412 int i, nr_of_cfgsw;
413
414 QIXIS_WRITE(cms[0], 0x00);
415 nr_of_cfgsw = QIXIS_READ(cms[1]);
416
417 puts("DIP switch settings dump:\n");
418 for (i = 1; i <= nr_of_cfgsw; i++) {
419 QIXIS_WRITE(cms[0], i);
420 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
421 }
Priyanka Jaind1418c12017-04-28 10:41:34 +0530422#endif
York Sune2b65ea2015-03-20 19:28:24 -0700423}
York Sunfc7b3852015-05-28 14:54:09 +0530424
425/*
426 * Board rev C and earlier has duplicated I2C addresses for 2nd controller.
427 * Both slots has 0x54, resulting 2nd slot unusable.
428 */
429void update_spd_address(unsigned int ctrl_num,
430 unsigned int slot,
431 unsigned int *addr)
432{
Priyanka Jain3049a582017-04-27 15:08:07 +0530433#ifndef CONFIG_TARGET_LS2081ARDB
Priyanka Jaind1418c12017-04-28 10:41:34 +0530434#ifdef CONFIG_FSL_QIXIS
York Sunfc7b3852015-05-28 14:54:09 +0530435 u8 sw;
436
437 sw = QIXIS_READ(arch);
438 if ((sw & 0xf) < 0x3) {
439 if (ctrl_num == 1 && slot == 0)
440 *addr = SPD_EEPROM_ADDRESS4;
441 else if (ctrl_num == 1 && slot == 1)
442 *addr = SPD_EEPROM_ADDRESS3;
443 }
Priyanka Jaind1418c12017-04-28 10:41:34 +0530444#endif
Priyanka Jain3049a582017-04-27 15:08:07 +0530445#endif
York Sunfc7b3852015-05-28 14:54:09 +0530446}