blob: c811e994d04dbb9b712908910f0f77d708e770fa [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
York Sun7288c2c2015-03-20 19:28:23 -07002/*
3 * Copyright 2015 Freescale Semiconductor
York Sun7288c2c2015-03-20 19:28:23 -07004 */
5#include <common.h>
6#include <malloc.h>
7#include <errno.h>
8#include <netdev.h>
9#include <fsl_ifc.h>
10#include <fsl_ddr.h>
11#include <asm/io.h>
12#include <fdt_support.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090013#include <linux/libfdt.h>
York Sun7288c2c2015-03-20 19:28:23 -070014#include <fsl-mc/fsl_mc.h>
15#include <environment.h>
16#include <i2c.h>
Priyanka Jain7fb79e62015-06-29 15:39:40 +053017#include <rtc.h>
Mingkai Hu9f3183d2015-10-26 19:47:50 +080018#include <asm/arch/soc.h>
Haikun Wange71a9802015-06-26 19:58:12 +080019#include <hwconfig.h>
Saksham Jainfcfdb6d2016-03-23 16:24:35 +053020#include <fsl_sec.h>
Santan Kumar54ad7b52017-03-07 11:21:03 +053021#include <asm/arch/ppa.h>
22
York Sun7288c2c2015-03-20 19:28:23 -070023
24#include "../common/qixis.h"
Prabhakar Kushwaha44937212015-11-09 16:42:07 +053025#include "ls2080aqds_qixis.h"
Priyanka Jain35cc1002017-01-19 11:12:28 +053026#include "../common/vid.h"
York Sun7288c2c2015-03-20 19:28:23 -070027
Haikun Wange71a9802015-06-26 19:58:12 +080028#define PIN_MUX_SEL_SDHC 0x00
29#define PIN_MUX_SEL_DSPI 0x0a
Yuan Yao916d9f02016-06-08 18:24:52 +080030#define SCFG_QSPICLKCTRL_DIV_20 (5 << 27)
Haikun Wange71a9802015-06-26 19:58:12 +080031
32#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
33
York Sun7288c2c2015-03-20 19:28:23 -070034DECLARE_GLOBAL_DATA_PTR;
35
Haikun Wange71a9802015-06-26 19:58:12 +080036enum {
37 MUX_TYPE_SDHC,
38 MUX_TYPE_DSPI,
39};
40
York Sun7288c2c2015-03-20 19:28:23 -070041unsigned long long get_qixis_addr(void)
42{
43 unsigned long long addr;
44
45 if (gd->flags & GD_FLG_RELOC)
46 addr = QIXIS_BASE_PHYS;
47 else
48 addr = QIXIS_BASE_PHYS_EARLY;
49
50 /*
51 * IFC address under 256MB is mapped to 0x30000000, any address above
52 * is mapped to 0x5_10000000 up to 4GB.
53 */
54 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
55
56 return addr;
57}
58
59int checkboard(void)
60{
61 char buf[64];
62 u8 sw;
63 static const char *const freq[] = {"100", "125", "156.25",
64 "100 separate SSCG"};
65 int clock;
66
Prabhakar Kushwahaff1b8e32015-05-28 14:54:07 +053067 cpu_name(buf);
68 printf("Board: %s-QDS, ", buf);
69
York Sun7288c2c2015-03-20 19:28:23 -070070 sw = QIXIS_READ(arch);
York Sun7288c2c2015-03-20 19:28:23 -070071 printf("Board Arch: V%d, ", sw >> 4);
72 printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1);
73
Prabhakar Kushwahaff1b8e32015-05-28 14:54:07 +053074 memset((u8 *)buf, 0x00, ARRAY_SIZE(buf));
75
York Sun7288c2c2015-03-20 19:28:23 -070076 sw = QIXIS_READ(brdcfg[0]);
77 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
78
79 if (sw < 0x8)
80 printf("vBank: %d\n", sw);
81 else if (sw == 0x8)
82 puts("PromJet\n");
83 else if (sw == 0x9)
84 puts("NAND\n");
Yuan Yaoa646f662016-06-08 18:25:00 +080085 else if (sw == 0xf)
86 puts("QSPI\n");
York Sun7288c2c2015-03-20 19:28:23 -070087 else if (sw == 0x15)
88 printf("IFCCard\n");
89 else
90 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
91
92 printf("FPGA: v%d (%s), build %d",
93 (int)QIXIS_READ(scver), qixis_read_tag(buf),
94 (int)qixis_read_minor());
95 /* the timestamp string contains "\n" at the end */
96 printf(" on %s", qixis_read_time(buf));
97
98 /*
99 * Display the actual SERDES reference clocks as configured by the
100 * dip switches on the board. Note that the SWx registers could
101 * technically be set to force the reference clocks to match the
102 * values that the SERDES expects (or vice versa). For now, however,
103 * we just display both values and hope the user notices when they
104 * don't match.
105 */
106 puts("SERDES1 Reference : ");
107 sw = QIXIS_READ(brdcfg[2]);
108 clock = (sw >> 6) & 3;
109 printf("Clock1 = %sMHz ", freq[clock]);
110 clock = (sw >> 4) & 3;
111 printf("Clock2 = %sMHz", freq[clock]);
112
113 puts("\nSERDES2 Reference : ");
114 clock = (sw >> 2) & 3;
115 printf("Clock1 = %sMHz ", freq[clock]);
116 clock = (sw >> 0) & 3;
117 printf("Clock2 = %sMHz\n", freq[clock]);
118
119 return 0;
120}
121
122unsigned long get_board_sys_clk(void)
123{
124 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
125
126 switch (sysclk_conf & 0x0F) {
127 case QIXIS_SYSCLK_83:
128 return 83333333;
129 case QIXIS_SYSCLK_100:
130 return 100000000;
131 case QIXIS_SYSCLK_125:
132 return 125000000;
133 case QIXIS_SYSCLK_133:
134 return 133333333;
135 case QIXIS_SYSCLK_150:
136 return 150000000;
137 case QIXIS_SYSCLK_160:
138 return 160000000;
139 case QIXIS_SYSCLK_166:
140 return 166666666;
141 }
142 return 66666666;
143}
144
145unsigned long get_board_ddr_clk(void)
146{
147 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
148
149 switch ((ddrclk_conf & 0x30) >> 4) {
150 case QIXIS_DDRCLK_100:
151 return 100000000;
152 case QIXIS_DDRCLK_125:
153 return 125000000;
154 case QIXIS_DDRCLK_133:
155 return 133333333;
156 }
157 return 66666666;
158}
159
160int select_i2c_ch_pca9547(u8 ch)
161{
162 int ret;
163
164 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
165 if (ret) {
166 puts("PCA: failed to select proper channel\n");
167 return ret;
168 }
169
170 return 0;
171}
172
Haikun Wange71a9802015-06-26 19:58:12 +0800173int config_board_mux(int ctrl_type)
174{
175 u8 reg5;
176
177 reg5 = QIXIS_READ(brdcfg[5]);
178
179 switch (ctrl_type) {
180 case MUX_TYPE_SDHC:
181 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
182 break;
183 case MUX_TYPE_DSPI:
184 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
185 break;
186 default:
187 printf("Wrong mux interface type\n");
188 return -1;
189 }
190
191 QIXIS_WRITE(brdcfg[5], reg5);
192
193 return 0;
194}
195
York Sun7288c2c2015-03-20 19:28:23 -0700196int board_init(void)
197{
Haikun Wange71a9802015-06-26 19:58:12 +0800198 char *env_hwconfig;
199 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
200 u32 val;
201
York Sun7288c2c2015-03-20 19:28:23 -0700202 init_final_memctl_regs();
203
Haikun Wange71a9802015-06-26 19:58:12 +0800204 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
205
Simon Glass00caae62017-08-03 12:22:12 -0600206 env_hwconfig = env_get("hwconfig");
Haikun Wange71a9802015-06-26 19:58:12 +0800207
208 if (hwconfig_f("dspi", env_hwconfig) &&
209 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
210 config_board_mux(MUX_TYPE_DSPI);
211 else
212 config_board_mux(MUX_TYPE_SDHC);
213
Yuan Yao453418f2016-06-08 18:24:57 +0800214#if defined(CONFIG_NAND) && defined(CONFIG_FSL_QSPI)
215 val = in_le32(dcfg_ccsr + DCFG_RCWSR15 / 4);
216
217 if (DCFG_RCWSR15_IFCGRPABASE_QSPI == (val & (u32)0x3))
218 QIXIS_WRITE(brdcfg[9],
219 (QIXIS_READ(brdcfg[9]) & 0xf8) |
220 FSL_QIXIS_BRDCFG9_QSPI);
221#endif
222
York Sun7288c2c2015-03-20 19:28:23 -0700223#ifdef CONFIG_ENV_IS_NOWHERE
224 gd->env_addr = (ulong)&default_environment[0];
225#endif
226 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
Priyanka Jain7fb79e62015-06-29 15:39:40 +0530227 rtc_enable_32khz_output();
Udit Agarwal15e7c682017-08-16 07:13:29 -0400228#ifdef CONFIG_FSL_CAAM
229 sec_init();
230#endif
Santan Kumar54ad7b52017-03-07 11:21:03 +0530231
232#ifdef CONFIG_FSL_LS_PPA
233 ppa_init();
234#endif
235
York Sun7288c2c2015-03-20 19:28:23 -0700236 return 0;
237}
238
239int board_early_init_f(void)
240{
Yuan Yao8c77ef82016-06-08 18:24:54 +0800241#ifdef CONFIG_SYS_I2C_EARLY_INIT
242 i2c_early_init_f();
243#endif
York Sun7288c2c2015-03-20 19:28:23 -0700244 fsl_lsch3_early_init_f();
Yuan Yao916d9f02016-06-08 18:24:52 +0800245#ifdef CONFIG_FSL_QSPI
246 /* input clk: 1/2 platform clk, output: input/20 */
247 out_le32(SCFG_BASE + SCFG_QSPICLKCTLR, SCFG_QSPICLKCTRL_DIV_20);
248#endif
York Sun7288c2c2015-03-20 19:28:23 -0700249 return 0;
250}
251
Priyanka Jain35cc1002017-01-19 11:12:28 +0530252int misc_init_r(void)
253{
254 if (adjust_vdd(0))
255 printf("Warning: Adjusting core voltage failed.\n");
256
257 return 0;
258}
259
York Sun7288c2c2015-03-20 19:28:23 -0700260void detail_board_ddr_info(void)
261{
262 puts("\nDDR ");
263 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
264 print_ddr_info(0);
Prabhakar Kushwaha44937212015-11-09 16:42:07 +0530265#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Sun3c1d2182016-04-04 11:41:26 -0700266 if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) {
York Sun7288c2c2015-03-20 19:28:23 -0700267 puts("\nDP-DDR ");
268 print_size(gd->bd->bi_dram[2].size, "");
269 print_ddr_info(CONFIG_DP_DDR_CTRL);
270 }
Prabhakar Kushwaha44937212015-11-09 16:42:07 +0530271#endif
York Sun7288c2c2015-03-20 19:28:23 -0700272}
273
York Sun7288c2c2015-03-20 19:28:23 -0700274#if defined(CONFIG_ARCH_MISC_INIT)
275int arch_misc_init(void)
276{
York Sun7288c2c2015-03-20 19:28:23 -0700277 return 0;
278}
279#endif
280
Santan Kumar1f55a932017-05-05 15:42:29 +0530281#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun7288c2c2015-03-20 19:28:23 -0700282void fdt_fixup_board_enet(void *fdt)
283{
284 int offset;
285
Stuart Yodere91f1de2016-03-02 16:37:13 -0600286 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sun7288c2c2015-03-20 19:28:23 -0700287
288 if (offset < 0)
Stuart Yodere91f1de2016-03-02 16:37:13 -0600289 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sun7288c2c2015-03-20 19:28:23 -0700290
291 if (offset < 0) {
292 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
293 __func__, offset);
294 return;
295 }
296
Yogesh Gaur70a131e2017-12-07 11:10:14 +0530297 if ((get_mc_boot_status() == 0) && (get_dpl_apply_status() == 0))
York Sun7288c2c2015-03-20 19:28:23 -0700298 fdt_status_okay(fdt, offset);
299 else
300 fdt_status_fail(fdt, offset);
301}
Alexander Grafb7b84102016-11-17 01:02:57 +0100302
303void board_quiesce_devices(void)
304{
305 fsl_mc_ldpaa_exit(gd->bd);
306}
York Sun7288c2c2015-03-20 19:28:23 -0700307#endif
308
309#ifdef CONFIG_OF_BOARD_SETUP
310int ft_board_setup(void *blob, bd_t *bd)
311{
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530312 u64 base[CONFIG_NR_DRAM_BANKS];
313 u64 size[CONFIG_NR_DRAM_BANKS];
York Sun7288c2c2015-03-20 19:28:23 -0700314
315 ft_cpu_setup(blob, bd);
316
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530317 /* fixup DT for the two GPP DDR banks */
318 base[0] = gd->bd->bi_dram[0].start;
319 size[0] = gd->bd->bi_dram[0].size;
320 base[1] = gd->bd->bi_dram[1].start;
321 size[1] = gd->bd->bi_dram[1].size;
322
York Sun36cc0de2017-03-06 09:02:28 -0800323#ifdef CONFIG_RESV_RAM
324 /* reduce size if reserved memory is within this bank */
325 if (gd->arch.resv_ram >= base[0] &&
326 gd->arch.resv_ram < base[0] + size[0])
327 size[0] = gd->arch.resv_ram - base[0];
328 else if (gd->arch.resv_ram >= base[1] &&
329 gd->arch.resv_ram < base[1] + size[1])
330 size[1] = gd->arch.resv_ram - base[1];
331#endif
332
Bhupesh Sharmaa2dc8182015-05-28 14:54:10 +0530333 fdt_fixup_memory_banks(blob, base, size, 2);
York Sun7288c2c2015-03-20 19:28:23 -0700334
Sriram Dasha5c289b2016-09-16 17:12:15 +0530335 fsl_fdt_fixup_dr_usb(blob, bd);
Sriram Dashef53b8c2016-06-13 09:58:36 +0530336
Santan Kumar1f55a932017-05-05 15:42:29 +0530337#if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
York Sun7288c2c2015-03-20 19:28:23 -0700338 fdt_fixup_board_enet(blob);
York Sun7288c2c2015-03-20 19:28:23 -0700339#endif
340
341 return 0;
342}
343#endif
344
345void qixis_dump_switch(void)
346{
347 int i, nr_of_cfgsw;
348
349 QIXIS_WRITE(cms[0], 0x00);
350 nr_of_cfgsw = QIXIS_READ(cms[1]);
351
352 puts("DIP switch settings dump:\n");
353 for (i = 1; i <= nr_of_cfgsw; i++) {
354 QIXIS_WRITE(cms[0], i);
355 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
356 }
357}