blob: 4d980e1eefcc38f443a86154ab7f57a0fac08240 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liu07886942013-11-22 17:39:11 +08002/*
3 * Copyright 2009-2013 Freescale Semiconductor, Inc.
Biwen Li07b3dcf2020-05-01 20:04:19 +08004 * Copyright 2020 NXP
Shengzhou Liu07886942013-11-22 17:39:11 +08005 */
6
7#include <common.h>
8#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070010#include <fdt_support.h>
Shengzhou Liu07886942013-11-22 17:39:11 +080011#include <i2c.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Shengzhou Liu07886942013-11-22 17:39:11 +080015#include <netdev.h>
16#include <linux/compiler.h>
17#include <asm/mmu.h>
18#include <asm/processor.h>
19#include <asm/immap_85xx.h>
20#include <asm/fsl_law.h>
21#include <asm/fsl_serdes.h>
Shengzhou Liu07886942013-11-22 17:39:11 +080022#include <asm/fsl_liodn.h>
23#include <fm_eth.h>
24
25#include "../common/qixis.h"
26#include "../common/vsc3316_3308.h"
Ying Zhang8876a512014-10-31 18:06:18 +080027#include "../common/vid.h"
Shengzhou Liu031228a2014-02-21 13:16:19 +080028#include "t208xqds.h"
29#include "t208xqds_qixis.h"
Shengzhou Liu07886942013-11-22 17:39:11 +080030
31DECLARE_GLOBAL_DATA_PTR;
32
33int checkboard(void)
34{
35 char buf[64];
36 u8 sw;
37 struct cpu_type *cpu = gd->arch.cpu;
38 static const char *freq[4] = {
39 "100.00MHZ(from 8T49N222A)", "125.00MHz",
40 "156.25MHZ", "100.00MHz"
41 };
42
43 printf("Board: %sQDS, ", cpu->name);
44 sw = QIXIS_READ(arch);
45 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4);
46 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1);
47
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080048#ifdef CONFIG_SDCARD
49 puts("SD/MMC\n");
50#elif CONFIG_SPIFLASH
51 puts("SPI\n");
52#else
Shengzhou Liu07886942013-11-22 17:39:11 +080053 sw = QIXIS_READ(brdcfg[0]);
54 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
55
56 if (sw < 0x8)
57 printf("vBank%d\n", sw);
58 else if (sw == 0x8)
59 puts("Promjet\n");
60 else if (sw == 0x9)
61 puts("NAND\n");
62 else
63 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080064#endif
Shengzhou Liu07886942013-11-22 17:39:11 +080065
66 printf("FPGA: v%d (%s), build %d", (int)QIXIS_READ(scver),
67 qixis_read_tag(buf), (int)qixis_read_minor());
68 /* the timestamp string contains "\n" at the end */
69 printf(" on %s", qixis_read_time(buf));
70
71 puts("SERDES Reference Clocks:\n");
72 sw = QIXIS_READ(brdcfg[2]);
73 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[sw >> 6],
74 freq[(sw >> 4) & 0x3]);
75 printf("SD2_CLK1=%s, SD2_CLK2=%s\n", freq[(sw & 0xf) >> 2],
76 freq[sw & 0x3]);
77
78 return 0;
79}
80
Biwen Li07b3dcf2020-05-01 20:04:19 +080081int select_i2c_ch_pca9547(u8 ch, int bus_num)
Shengzhou Liu07886942013-11-22 17:39:11 +080082{
83 int ret;
84
Biwen Li07b3dcf2020-05-01 20:04:19 +080085#ifdef CONFIG_DM_I2C
86 struct udevice *dev;
87
88 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
89 if (ret) {
90 printf("%s: Cannot find udev for a bus %d\n", __func__,
91 bus_num);
92 return ret;
93 }
94 ret = dm_i2c_write(dev, 0, &ch, 1);
95#else
Shengzhou Liu07886942013-11-22 17:39:11 +080096 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li07b3dcf2020-05-01 20:04:19 +080097#endif
Shengzhou Liu07886942013-11-22 17:39:11 +080098 if (ret) {
99 puts("PCA: failed to select proper channel\n");
100 return ret;
101 }
102
103 return 0;
104}
105
Ying Zhang8876a512014-10-31 18:06:18 +0800106int i2c_multiplexer_select_vid_channel(u8 channel)
107{
Biwen Li07b3dcf2020-05-01 20:04:19 +0800108 return select_i2c_ch_pca9547(channel, 0);
Ying Zhang8876a512014-10-31 18:06:18 +0800109}
110
Shengzhou Liu07886942013-11-22 17:39:11 +0800111int brd_mux_lane_to_slot(void)
112{
113 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Shengzhou Liu031228a2014-02-21 13:16:19 +0800114 u32 srds_prtcl_s1;
Shengzhou Liu07886942013-11-22 17:39:11 +0800115
116 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
117 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
118 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
York Sunc68b12d2016-12-28 08:43:36 -0800119#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu031228a2014-02-21 13:16:19 +0800120 u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
Shengzhou Liu07886942013-11-22 17:39:11 +0800121 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
122 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shengzhou Liu031228a2014-02-21 13:16:19 +0800123#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800124
125 switch (srds_prtcl_s1) {
126 case 0:
127 /* SerDes1 is not enabled */
128 break;
York Sunc68b12d2016-12-28 08:43:36 -0800129#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800130 case 0x1b:
Shengzhou Liu07886942013-11-22 17:39:11 +0800131 case 0x1c:
Shengzhou Liu07886942013-11-22 17:39:11 +0800132 case 0xa2:
Shengzhou Liu07886942013-11-22 17:39:11 +0800133 /* SD1(A:D) => SLOT3 SGMII
134 * SD1(G:H) => SLOT1 SGMII
135 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800136 QIXIS_WRITE(brdcfg[12], 0x1a);
137 break;
138 case 0x94:
139 case 0x95:
140 /* SD1(A:B) => SLOT3 SGMII@1.25bps
141 * SD1(C:D) => SFP Module, SGMII@3.125bps
142 * SD1(E:H) => SLOT1 SGMII@1.25bps
143 */
144 case 0x96:
145 /* SD1(A:B) => SLOT3 SGMII@1.25bps
146 * SD1(C) => SFP Module, SGMII@3.125bps
147 * SD1(D) => SFP Module, SGMII@1.25bps
148 * SD1(E:H) => SLOT1 PCIe4 x4
149 */
150 QIXIS_WRITE(brdcfg[12], 0x3a);
Shengzhou Liu07886942013-11-22 17:39:11 +0800151 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800152 case 0x50:
Shengzhou Liu07886942013-11-22 17:39:11 +0800153 case 0x51:
154 /* SD1(A:D) => SLOT3 XAUI
155 * SD1(E) => SLOT1 PCIe4
156 * SD1(F:H) => SLOT2 SGMII
157 */
158 QIXIS_WRITE(brdcfg[12], 0x15);
159 break;
160 case 0x66:
161 case 0x67:
162 /* SD1(A:D) => XFI cage
163 * SD1(E:H) => SLOT1 PCIe4
164 */
165 QIXIS_WRITE(brdcfg[12], 0xfe);
166 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800167 case 0x6a:
Shengzhou Liu07886942013-11-22 17:39:11 +0800168 case 0x6b:
169 /* SD1(A:D) => XFI cage
170 * SD1(E) => SLOT1 PCIe4
171 * SD1(F:H) => SLOT2 SGMII
172 */
173 QIXIS_WRITE(brdcfg[12], 0xf1);
174 break;
175 case 0x6c:
176 case 0x6d:
177 /* SD1(A:B) => XFI cage
178 * SD1(C:D) => SLOT3 SGMII
179 * SD1(E:H) => SLOT1 PCIe4
180 */
181 QIXIS_WRITE(brdcfg[12], 0xda);
182 break;
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800183 case 0x6e:
184 /* SD1(A:B) => SFP Module, XFI
185 * SD1(C:D) => SLOT3 SGMII
186 * SD1(E:F) => SLOT1 PCIe4 x2
187 * SD1(G:H) => SLOT2 SGMII
188 */
189 QIXIS_WRITE(brdcfg[12], 0xd9);
190 break;
191 case 0xda:
192 /* SD1(A:H) => SLOT3 PCIe3 x8
193 */
194 QIXIS_WRITE(brdcfg[12], 0x0);
195 break;
196 case 0xc8:
197 /* SD1(A) => SLOT3 PCIe3 x1
198 * SD1(B) => SFP Module, SGMII@1.25bps
199 * SD1(C:D) => SFP Module, SGMII@3.125bps
200 * SD1(E:F) => SLOT1 PCIe4 x2
201 * SD1(G:H) => SLOT2 SGMII
202 */
203 QIXIS_WRITE(brdcfg[12], 0x79);
204 break;
205 case 0xab:
206 /* SD1(A:D) => SLOT3 PCIe3 x4
207 * SD1(E:H) => SLOT1 PCIe4 x4
208 */
209 QIXIS_WRITE(brdcfg[12], 0x1a);
210 break;
York Sun99eb6072016-12-28 08:43:38 -0800211#elif defined(CONFIG_TARGET_T2081QDS)
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800212 case 0x50:
Shengzhou Liu031228a2014-02-21 13:16:19 +0800213 case 0x51:
214 /* SD1(A:D) => SLOT2 XAUI
215 * SD1(E) => SLOT1 PCIe4 x1
216 * SD1(F:H) => SLOT3 SGMII
217 */
218 QIXIS_WRITE(brdcfg[12], 0x98);
219 QIXIS_WRITE(brdcfg[13], 0x70);
220 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800221 case 0x6a:
Shengzhou Liu031228a2014-02-21 13:16:19 +0800222 case 0x6b:
223 /* SD1(A:D) => XFI SFP Module
224 * SD1(E) => SLOT1 PCIe4 x1
225 * SD1(F:H) => SLOT3 SGMII
226 */
227 QIXIS_WRITE(brdcfg[12], 0x80);
228 QIXIS_WRITE(brdcfg[13], 0x70);
229 break;
230 case 0x6c:
Shengzhou Liu031228a2014-02-21 13:16:19 +0800231 case 0x6d:
232 /* SD1(A:B) => XFI SFP Module
233 * SD1(C:D) => SLOT2 SGMII
234 * SD1(E:H) => SLOT1 PCIe4 x4
235 */
236 QIXIS_WRITE(brdcfg[12], 0xe8);
237 QIXIS_WRITE(brdcfg[13], 0x0);
238 break;
239 case 0xaa:
240 case 0xab:
241 /* SD1(A:D) => SLOT2 PCIe3 x4
242 * SD1(F:H) => SLOT1 SGMI4 x4
243 */
244 QIXIS_WRITE(brdcfg[12], 0xf8);
245 QIXIS_WRITE(brdcfg[13], 0x0);
246 break;
247 case 0xca:
248 case 0xcb:
249 /* SD1(A) => SLOT2 PCIe3 x1
250 * SD1(B) => SLOT7 SGMII
251 * SD1(C) => SLOT6 SGMII
252 * SD1(D) => SLOT5 SGMII
253 * SD1(E) => SLOT1 PCIe4 x1
254 * SD1(F:H) => SLOT3 SGMII
255 */
256 QIXIS_WRITE(brdcfg[12], 0x80);
257 QIXIS_WRITE(brdcfg[13], 0x70);
258 break;
259 case 0xde:
260 case 0xdf:
261 /* SD1(A:D) => SLOT2 PCIe3 x4
262 * SD1(E) => SLOT1 PCIe4 x1
263 * SD1(F) => SLOT4 PCIe1 x1
264 * SD1(G) => SLOT3 PCIe2 x1
265 * SD1(H) => SLOT7 SGMII
266 */
267 QIXIS_WRITE(brdcfg[12], 0x98);
268 QIXIS_WRITE(brdcfg[13], 0x25);
269 break;
270 case 0xf2:
271 /* SD1(A) => SLOT2 PCIe3 x1
272 * SD1(B:D) => SLOT7 SGMII
273 * SD1(E) => SLOT1 PCIe4 x1
274 * SD1(F) => SLOT4 PCIe1 x1
275 * SD1(G) => SLOT3 PCIe2 x1
276 * SD1(H) => SLOT7 SGMII
277 */
278 QIXIS_WRITE(brdcfg[12], 0x81);
279 QIXIS_WRITE(brdcfg[13], 0xa5);
280 break;
281#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800282 default:
283 printf("WARNING: unsupported for SerDes1 Protocol %d\n",
284 srds_prtcl_s1);
285 return -1;
286 }
287
York Sunc68b12d2016-12-28 08:43:36 -0800288#ifdef CONFIG_TARGET_T2080QDS
Shengzhou Liu07886942013-11-22 17:39:11 +0800289 switch (srds_prtcl_s2) {
290 case 0:
291 /* SerDes2 is not enabled */
292 break;
293 case 0x01:
294 case 0x02:
295 /* SD2(A:H) => SLOT4 PCIe1 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800296 QIXIS_WRITE(brdcfg[13], 0x10);
Shengzhou Liu07886942013-11-22 17:39:11 +0800297 break;
298 case 0x15:
299 case 0x16:
300 /*
301 * SD2(A:D) => SLOT4 PCIe1
302 * SD2(E:F) => SLOT5 PCIe2
303 * SD2(G:H) => SATA1,SATA2
304 */
305 QIXIS_WRITE(brdcfg[13], 0xb0);
306 break;
307 case 0x18:
308 /*
309 * SD2(A:D) => SLOT4 PCIe1
310 * SD2(E:F) => SLOT5 Aurora
311 * SD2(G:H) => SATA1,SATA2
312 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800313 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800314 break;
315 case 0x1f:
316 /*
317 * SD2(A:D) => SLOT4 PCIe1
318 * SD2(E:H) => SLOT5 PCIe2
319 */
320 QIXIS_WRITE(brdcfg[13], 0xa0);
321 break;
322 case 0x29:
323 case 0x2d:
324 case 0x2e:
325 /*
326 * SD2(A:D) => SLOT4 SRIO2
327 * SD2(E:H) => SLOT5 SRIO1
328 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800329 QIXIS_WRITE(brdcfg[13], 0xa0);
330 break;
331 case 0x36:
332 /*
333 * SD2(A:D) => SLOT4 SRIO2
334 * SD2(E:F) => Aurora
335 * SD2(G:H) => SATA1,SATA2
336 */
337 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800338 break;
339 default:
340 printf("WARNING: unsupported for SerDes2 Protocol %d\n",
341 srds_prtcl_s2);
342 return -1;
343 }
Shengzhou Liu031228a2014-02-21 13:16:19 +0800344#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800345 return 0;
346}
347
348int board_early_init_r(void)
349{
350 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700351 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Shengzhou Liu07886942013-11-22 17:39:11 +0800352
353 /*
354 * Remap Boot flash + PROMJET region to caching-inhibited
355 * so that flash can be erased properly.
356 */
357
358 /* Flush d-cache and invalidate i-cache of any FLASH data */
359 flush_dcache();
360 invalidate_icache();
361
York Sun220c3462014-06-24 21:16:20 -0700362 if (flash_esel == -1) {
363 /* very unlikely unless something is messed up */
364 puts("Error: Could not find TLB for FLASH BASE\n");
365 flash_esel = 2; /* give our best effort to continue */
366 } else {
367 /* invalidate existing TLB entry for flash + promjet */
368 disable_tlb(flash_esel);
369 }
Shengzhou Liu07886942013-11-22 17:39:11 +0800370
371 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
372 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
373 0, flash_esel, BOOKE_PAGESZ_256M, 1);
374
Shengzhou Liu07886942013-11-22 17:39:11 +0800375 /* Disable remote I2C connection to qixis fpga */
376 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
377
Ying Zhang8876a512014-10-31 18:06:18 +0800378 /*
379 * Adjust core voltage according to voltage ID
380 * This function changes I2C mux to channel 2.
381 */
382 if (adjust_vdd(0))
383 printf("Warning: Adjusting core voltage failed.\n");
384
Shengzhou Liu07886942013-11-22 17:39:11 +0800385 brd_mux_lane_to_slot();
Biwen Li07b3dcf2020-05-01 20:04:19 +0800386 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Shengzhou Liu07886942013-11-22 17:39:11 +0800387
388 return 0;
389}
390
391unsigned long get_board_sys_clk(void)
392{
393 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
394#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
395 /* use accurate clock measurement */
396 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
397 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
398 u32 val;
399
400 val = freq * base;
401 if (val) {
402 debug("SYS Clock measurement is: %d\n", val);
403 return val;
404 } else {
405 printf("Warning: SYS clock measurement is invalid, ");
406 printf("using value from brdcfg1.\n");
407 }
408#endif
409
410 switch (sysclk_conf & 0x0F) {
411 case QIXIS_SYSCLK_83:
412 return 83333333;
413 case QIXIS_SYSCLK_100:
414 return 100000000;
415 case QIXIS_SYSCLK_125:
416 return 125000000;
417 case QIXIS_SYSCLK_133:
418 return 133333333;
419 case QIXIS_SYSCLK_150:
420 return 150000000;
421 case QIXIS_SYSCLK_160:
422 return 160000000;
423 case QIXIS_SYSCLK_166:
424 return 166666666;
425 }
426 return 66666666;
427}
428
429unsigned long get_board_ddr_clk(void)
430{
431 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
432#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
433 /* use accurate clock measurement */
434 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
435 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
436 u32 val;
437
438 val = freq * base;
439 if (val) {
440 debug("DDR Clock measurement is: %d\n", val);
441 return val;
442 } else {
443 printf("Warning: DDR clock measurement is invalid, ");
444 printf("using value from brdcfg1.\n");
445 }
446#endif
447
448 switch ((ddrclk_conf & 0x30) >> 4) {
449 case QIXIS_DDRCLK_100:
450 return 100000000;
451 case QIXIS_DDRCLK_125:
452 return 125000000;
453 case QIXIS_DDRCLK_133:
454 return 133333333;
455 }
456 return 66666666;
457}
458
459int misc_init_r(void)
460{
461 return 0;
462}
463
Simon Glass2aec3cc2014-10-23 18:58:47 -0600464int ft_board_setup(void *blob, bd_t *bd)
Shengzhou Liu07886942013-11-22 17:39:11 +0800465{
466 phys_addr_t base;
467 phys_size_t size;
468
469 ft_cpu_setup(blob, bd);
470
Simon Glassda1a1342017-08-03 12:22:15 -0600471 base = env_get_bootm_low();
472 size = env_get_bootm_size();
Shengzhou Liu07886942013-11-22 17:39:11 +0800473
474 fdt_fixup_memory(blob, (u64)base, (u64)size);
475
476#ifdef CONFIG_PCI
477 pci_of_setup(blob, bd);
478#endif
479
480 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530481 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu07886942013-11-22 17:39:11 +0800482
483#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300484#ifndef CONFIG_DM_ETH
Shengzhou Liu07886942013-11-22 17:39:11 +0800485 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300486#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800487 fdt_fixup_board_enet(blob);
488#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600489
490 return 0;
Shengzhou Liu07886942013-11-22 17:39:11 +0800491}