blob: e54672a80ba40caca299b2f49874d72813b4aa8d [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060016#include <asm/global_data.h>
Shengzhou Liu07886942013-11-22 17:39:11 +080017#include <linux/compiler.h>
18#include <asm/mmu.h>
19#include <asm/processor.h>
20#include <asm/immap_85xx.h>
21#include <asm/fsl_law.h>
22#include <asm/fsl_serdes.h>
Shengzhou Liu07886942013-11-22 17:39:11 +080023#include <asm/fsl_liodn.h>
24#include <fm_eth.h>
Stephen Carlson9107ef62021-06-22 16:43:48 -070025#include "../common/i2c_mux.h"
Shengzhou Liu07886942013-11-22 17:39:11 +080026
27#include "../common/qixis.h"
28#include "../common/vsc3316_3308.h"
Ying Zhang8876a512014-10-31 18:06:18 +080029#include "../common/vid.h"
Shengzhou Liu031228a2014-02-21 13:16:19 +080030#include "t208xqds.h"
31#include "t208xqds_qixis.h"
Shengzhou Liu07886942013-11-22 17:39:11 +080032
33DECLARE_GLOBAL_DATA_PTR;
34
35int checkboard(void)
36{
37 char buf[64];
38 u8 sw;
39 struct cpu_type *cpu = gd->arch.cpu;
40 static const char *freq[4] = {
41 "100.00MHZ(from 8T49N222A)", "125.00MHz",
42 "156.25MHZ", "100.00MHz"
43 };
44
45 printf("Board: %sQDS, ", cpu->name);
46 sw = QIXIS_READ(arch);
47 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4);
48 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1);
49
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080050#ifdef CONFIG_SDCARD
51 puts("SD/MMC\n");
52#elif CONFIG_SPIFLASH
53 puts("SPI\n");
54#else
Shengzhou Liu07886942013-11-22 17:39:11 +080055 sw = QIXIS_READ(brdcfg[0]);
56 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
57
58 if (sw < 0x8)
59 printf("vBank%d\n", sw);
60 else if (sw == 0x8)
61 puts("Promjet\n");
62 else if (sw == 0x9)
63 puts("NAND\n");
64 else
65 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080066#endif
Shengzhou Liu07886942013-11-22 17:39:11 +080067
68 printf("FPGA: v%d (%s), build %d", (int)QIXIS_READ(scver),
69 qixis_read_tag(buf), (int)qixis_read_minor());
70 /* the timestamp string contains "\n" at the end */
71 printf(" on %s", qixis_read_time(buf));
72
73 puts("SERDES Reference Clocks:\n");
74 sw = QIXIS_READ(brdcfg[2]);
75 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[sw >> 6],
76 freq[(sw >> 4) & 0x3]);
77 printf("SD2_CLK1=%s, SD2_CLK2=%s\n", freq[(sw & 0xf) >> 2],
78 freq[sw & 0x3]);
79
80 return 0;
81}
82
Ying Zhang8876a512014-10-31 18:06:18 +080083int i2c_multiplexer_select_vid_channel(u8 channel)
84{
Biwen Li07b3dcf2020-05-01 20:04:19 +080085 return select_i2c_ch_pca9547(channel, 0);
Ying Zhang8876a512014-10-31 18:06:18 +080086}
87
Shengzhou Liu07886942013-11-22 17:39:11 +080088int brd_mux_lane_to_slot(void)
89{
90 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Shengzhou Liu031228a2014-02-21 13:16:19 +080091 u32 srds_prtcl_s1;
Shengzhou Liu07886942013-11-22 17:39:11 +080092
93 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
94 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
95 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
York Sunc68b12d2016-12-28 08:43:36 -080096#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu031228a2014-02-21 13:16:19 +080097 u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
Shengzhou Liu07886942013-11-22 17:39:11 +080098 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
99 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shengzhou Liu031228a2014-02-21 13:16:19 +0800100#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800101
102 switch (srds_prtcl_s1) {
103 case 0:
104 /* SerDes1 is not enabled */
105 break;
York Sunc68b12d2016-12-28 08:43:36 -0800106#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800107 case 0x1b:
Shengzhou Liu07886942013-11-22 17:39:11 +0800108 case 0x1c:
Shengzhou Liu07886942013-11-22 17:39:11 +0800109 case 0xa2:
Shengzhou Liu07886942013-11-22 17:39:11 +0800110 /* SD1(A:D) => SLOT3 SGMII
111 * SD1(G:H) => SLOT1 SGMII
112 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800113 QIXIS_WRITE(brdcfg[12], 0x1a);
114 break;
115 case 0x94:
116 case 0x95:
117 /* SD1(A:B) => SLOT3 SGMII@1.25bps
118 * SD1(C:D) => SFP Module, SGMII@3.125bps
119 * SD1(E:H) => SLOT1 SGMII@1.25bps
120 */
121 case 0x96:
122 /* SD1(A:B) => SLOT3 SGMII@1.25bps
123 * SD1(C) => SFP Module, SGMII@3.125bps
124 * SD1(D) => SFP Module, SGMII@1.25bps
125 * SD1(E:H) => SLOT1 PCIe4 x4
126 */
127 QIXIS_WRITE(brdcfg[12], 0x3a);
Shengzhou Liu07886942013-11-22 17:39:11 +0800128 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800129 case 0x50:
Shengzhou Liu07886942013-11-22 17:39:11 +0800130 case 0x51:
131 /* SD1(A:D) => SLOT3 XAUI
132 * SD1(E) => SLOT1 PCIe4
133 * SD1(F:H) => SLOT2 SGMII
134 */
135 QIXIS_WRITE(brdcfg[12], 0x15);
136 break;
137 case 0x66:
138 case 0x67:
Vladimir Oltean6a6e4022021-09-18 15:32:34 +0300139 /* SD1(A:D) => 10GBase-R cage
Shengzhou Liu07886942013-11-22 17:39:11 +0800140 * SD1(E:H) => SLOT1 PCIe4
141 */
142 QIXIS_WRITE(brdcfg[12], 0xfe);
143 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800144 case 0x6a:
Shengzhou Liu07886942013-11-22 17:39:11 +0800145 case 0x6b:
Vladimir Oltean6a6e4022021-09-18 15:32:34 +0300146 /* SD1(A:D) => 10GBase-R cage
Shengzhou Liu07886942013-11-22 17:39:11 +0800147 * SD1(E) => SLOT1 PCIe4
148 * SD1(F:H) => SLOT2 SGMII
149 */
150 QIXIS_WRITE(brdcfg[12], 0xf1);
151 break;
152 case 0x6c:
153 case 0x6d:
Vladimir Oltean6a6e4022021-09-18 15:32:34 +0300154 /* SD1(A:B) => 10GBase-R cage
Shengzhou Liu07886942013-11-22 17:39:11 +0800155 * SD1(C:D) => SLOT3 SGMII
156 * SD1(E:H) => SLOT1 PCIe4
157 */
158 QIXIS_WRITE(brdcfg[12], 0xda);
159 break;
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800160 case 0x6e:
Vladimir Oltean6a6e4022021-09-18 15:32:34 +0300161 /* SD1(A:B) => SFP Module, 10GBase-R
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800162 * SD1(C:D) => SLOT3 SGMII
163 * SD1(E:F) => SLOT1 PCIe4 x2
164 * SD1(G:H) => SLOT2 SGMII
165 */
166 QIXIS_WRITE(brdcfg[12], 0xd9);
167 break;
168 case 0xda:
169 /* SD1(A:H) => SLOT3 PCIe3 x8
170 */
171 QIXIS_WRITE(brdcfg[12], 0x0);
172 break;
173 case 0xc8:
174 /* SD1(A) => SLOT3 PCIe3 x1
175 * SD1(B) => SFP Module, SGMII@1.25bps
176 * SD1(C:D) => SFP Module, SGMII@3.125bps
177 * SD1(E:F) => SLOT1 PCIe4 x2
178 * SD1(G:H) => SLOT2 SGMII
179 */
180 QIXIS_WRITE(brdcfg[12], 0x79);
181 break;
182 case 0xab:
183 /* SD1(A:D) => SLOT3 PCIe3 x4
184 * SD1(E:H) => SLOT1 PCIe4 x4
185 */
186 QIXIS_WRITE(brdcfg[12], 0x1a);
187 break;
Shengzhou Liu031228a2014-02-21 13:16:19 +0800188#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800189 default:
190 printf("WARNING: unsupported for SerDes1 Protocol %d\n",
191 srds_prtcl_s1);
192 return -1;
193 }
194
York Sunc68b12d2016-12-28 08:43:36 -0800195#ifdef CONFIG_TARGET_T2080QDS
Shengzhou Liu07886942013-11-22 17:39:11 +0800196 switch (srds_prtcl_s2) {
197 case 0:
198 /* SerDes2 is not enabled */
199 break;
200 case 0x01:
201 case 0x02:
202 /* SD2(A:H) => SLOT4 PCIe1 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800203 QIXIS_WRITE(brdcfg[13], 0x10);
Shengzhou Liu07886942013-11-22 17:39:11 +0800204 break;
205 case 0x15:
206 case 0x16:
207 /*
208 * SD2(A:D) => SLOT4 PCIe1
209 * SD2(E:F) => SLOT5 PCIe2
210 * SD2(G:H) => SATA1,SATA2
211 */
212 QIXIS_WRITE(brdcfg[13], 0xb0);
213 break;
214 case 0x18:
215 /*
216 * SD2(A:D) => SLOT4 PCIe1
217 * SD2(E:F) => SLOT5 Aurora
218 * SD2(G:H) => SATA1,SATA2
219 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800220 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800221 break;
222 case 0x1f:
223 /*
224 * SD2(A:D) => SLOT4 PCIe1
225 * SD2(E:H) => SLOT5 PCIe2
226 */
227 QIXIS_WRITE(brdcfg[13], 0xa0);
228 break;
229 case 0x29:
230 case 0x2d:
231 case 0x2e:
232 /*
233 * SD2(A:D) => SLOT4 SRIO2
234 * SD2(E:H) => SLOT5 SRIO1
235 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800236 QIXIS_WRITE(brdcfg[13], 0xa0);
237 break;
238 case 0x36:
239 /*
240 * SD2(A:D) => SLOT4 SRIO2
241 * SD2(E:F) => Aurora
242 * SD2(G:H) => SATA1,SATA2
243 */
244 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800245 break;
246 default:
247 printf("WARNING: unsupported for SerDes2 Protocol %d\n",
248 srds_prtcl_s2);
249 return -1;
250 }
Shengzhou Liu031228a2014-02-21 13:16:19 +0800251#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800252 return 0;
253}
254
Yangbo Luf9049b22020-06-17 18:08:58 +0800255static void esdhc_adapter_card_ident(void)
256{
257 u8 card_id, value;
258
259 card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
260
261 switch (card_id) {
262 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
263 value = QIXIS_READ(brdcfg[5]);
264 value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7);
265 QIXIS_WRITE(brdcfg[5], value);
266 break;
267 case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
268 value = QIXIS_READ(pwr_ctl[1]);
269 value |= QIXIS_EVDD_BY_SDHC_VS;
270 QIXIS_WRITE(pwr_ctl[1], value);
271 break;
272 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
273 value = QIXIS_READ(brdcfg[5]);
274 value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
275 QIXIS_WRITE(brdcfg[5], value);
276 break;
277 default:
278 break;
279 }
280}
281
Shengzhou Liu07886942013-11-22 17:39:11 +0800282int board_early_init_r(void)
283{
284 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700285 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Shengzhou Liu07886942013-11-22 17:39:11 +0800286
287 /*
288 * Remap Boot flash + PROMJET region to caching-inhibited
289 * so that flash can be erased properly.
290 */
291
292 /* Flush d-cache and invalidate i-cache of any FLASH data */
293 flush_dcache();
294 invalidate_icache();
295
York Sun220c3462014-06-24 21:16:20 -0700296 if (flash_esel == -1) {
297 /* very unlikely unless something is messed up */
298 puts("Error: Could not find TLB for FLASH BASE\n");
299 flash_esel = 2; /* give our best effort to continue */
300 } else {
301 /* invalidate existing TLB entry for flash + promjet */
302 disable_tlb(flash_esel);
303 }
Shengzhou Liu07886942013-11-22 17:39:11 +0800304
305 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
306 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
307 0, flash_esel, BOOKE_PAGESZ_256M, 1);
308
Shengzhou Liu07886942013-11-22 17:39:11 +0800309 /* Disable remote I2C connection to qixis fpga */
310 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
311
Ying Zhang8876a512014-10-31 18:06:18 +0800312 /*
313 * Adjust core voltage according to voltage ID
314 * This function changes I2C mux to channel 2.
315 */
316 if (adjust_vdd(0))
317 printf("Warning: Adjusting core voltage failed.\n");
318
Shengzhou Liu07886942013-11-22 17:39:11 +0800319 brd_mux_lane_to_slot();
Biwen Li07b3dcf2020-05-01 20:04:19 +0800320 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Yangbo Luf9049b22020-06-17 18:08:58 +0800321 esdhc_adapter_card_ident();
Shengzhou Liu07886942013-11-22 17:39:11 +0800322 return 0;
323}
324
325unsigned long get_board_sys_clk(void)
326{
327 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
328#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
329 /* use accurate clock measurement */
330 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
331 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
332 u32 val;
333
334 val = freq * base;
335 if (val) {
336 debug("SYS Clock measurement is: %d\n", val);
337 return val;
338 } else {
339 printf("Warning: SYS clock measurement is invalid, ");
340 printf("using value from brdcfg1.\n");
341 }
342#endif
343
344 switch (sysclk_conf & 0x0F) {
345 case QIXIS_SYSCLK_83:
346 return 83333333;
347 case QIXIS_SYSCLK_100:
348 return 100000000;
349 case QIXIS_SYSCLK_125:
350 return 125000000;
351 case QIXIS_SYSCLK_133:
352 return 133333333;
353 case QIXIS_SYSCLK_150:
354 return 150000000;
355 case QIXIS_SYSCLK_160:
356 return 160000000;
357 case QIXIS_SYSCLK_166:
358 return 166666666;
359 }
360 return 66666666;
361}
362
363unsigned long get_board_ddr_clk(void)
364{
365 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
366#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
367 /* use accurate clock measurement */
368 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
369 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
370 u32 val;
371
372 val = freq * base;
373 if (val) {
374 debug("DDR Clock measurement is: %d\n", val);
375 return val;
376 } else {
377 printf("Warning: DDR clock measurement is invalid, ");
378 printf("using value from brdcfg1.\n");
379 }
380#endif
381
382 switch ((ddrclk_conf & 0x30) >> 4) {
383 case QIXIS_DDRCLK_100:
384 return 100000000;
385 case QIXIS_DDRCLK_125:
386 return 125000000;
387 case QIXIS_DDRCLK_133:
388 return 133333333;
389 }
390 return 66666666;
391}
392
393int misc_init_r(void)
394{
395 return 0;
396}
397
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900398int ft_board_setup(void *blob, struct bd_info *bd)
Shengzhou Liu07886942013-11-22 17:39:11 +0800399{
400 phys_addr_t base;
401 phys_size_t size;
402
403 ft_cpu_setup(blob, bd);
404
Simon Glassda1a1342017-08-03 12:22:15 -0600405 base = env_get_bootm_low();
406 size = env_get_bootm_size();
Shengzhou Liu07886942013-11-22 17:39:11 +0800407
408 fdt_fixup_memory(blob, (u64)base, (u64)size);
409
410#ifdef CONFIG_PCI
411 pci_of_setup(blob, bd);
412#endif
413
414 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530415 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu07886942013-11-22 17:39:11 +0800416
417#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300418#ifndef CONFIG_DM_ETH
Shengzhou Liu07886942013-11-22 17:39:11 +0800419 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300420#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800421 fdt_fixup_board_enet(blob);
422#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600423
424 return 0;
Shengzhou Liu07886942013-11-22 17:39:11 +0800425}