blob: fd3217f24d42c5f82b4b896cf4762126579a761e [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>
25
26#include "../common/qixis.h"
27#include "../common/vsc3316_3308.h"
Ying Zhang8876a512014-10-31 18:06:18 +080028#include "../common/vid.h"
Shengzhou Liu031228a2014-02-21 13:16:19 +080029#include "t208xqds.h"
30#include "t208xqds_qixis.h"
Shengzhou Liu07886942013-11-22 17:39:11 +080031
32DECLARE_GLOBAL_DATA_PTR;
33
34int checkboard(void)
35{
36 char buf[64];
37 u8 sw;
38 struct cpu_type *cpu = gd->arch.cpu;
39 static const char *freq[4] = {
40 "100.00MHZ(from 8T49N222A)", "125.00MHz",
41 "156.25MHZ", "100.00MHz"
42 };
43
44 printf("Board: %sQDS, ", cpu->name);
45 sw = QIXIS_READ(arch);
46 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4);
47 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1);
48
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080049#ifdef CONFIG_SDCARD
50 puts("SD/MMC\n");
51#elif CONFIG_SPIFLASH
52 puts("SPI\n");
53#else
Shengzhou Liu07886942013-11-22 17:39:11 +080054 sw = QIXIS_READ(brdcfg[0]);
55 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
56
57 if (sw < 0x8)
58 printf("vBank%d\n", sw);
59 else if (sw == 0x8)
60 puts("Promjet\n");
61 else if (sw == 0x9)
62 puts("NAND\n");
63 else
64 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +080065#endif
Shengzhou Liu07886942013-11-22 17:39:11 +080066
67 printf("FPGA: v%d (%s), build %d", (int)QIXIS_READ(scver),
68 qixis_read_tag(buf), (int)qixis_read_minor());
69 /* the timestamp string contains "\n" at the end */
70 printf(" on %s", qixis_read_time(buf));
71
72 puts("SERDES Reference Clocks:\n");
73 sw = QIXIS_READ(brdcfg[2]);
74 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[sw >> 6],
75 freq[(sw >> 4) & 0x3]);
76 printf("SD2_CLK1=%s, SD2_CLK2=%s\n", freq[(sw & 0xf) >> 2],
77 freq[sw & 0x3]);
78
79 return 0;
80}
81
Biwen Li07b3dcf2020-05-01 20:04:19 +080082int select_i2c_ch_pca9547(u8 ch, int bus_num)
Shengzhou Liu07886942013-11-22 17:39:11 +080083{
84 int ret;
85
Igor Opaniukf7c91762021-02-09 13:52:45 +020086#if CONFIG_IS_ENABLED(DM_I2C)
Biwen Li07b3dcf2020-05-01 20:04:19 +080087 struct udevice *dev;
88
89 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
90 if (ret) {
91 printf("%s: Cannot find udev for a bus %d\n", __func__,
92 bus_num);
93 return ret;
94 }
95 ret = dm_i2c_write(dev, 0, &ch, 1);
96#else
Shengzhou Liu07886942013-11-22 17:39:11 +080097 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li07b3dcf2020-05-01 20:04:19 +080098#endif
Shengzhou Liu07886942013-11-22 17:39:11 +080099 if (ret) {
100 puts("PCA: failed to select proper channel\n");
101 return ret;
102 }
103
104 return 0;
105}
106
Ying Zhang8876a512014-10-31 18:06:18 +0800107int i2c_multiplexer_select_vid_channel(u8 channel)
108{
Biwen Li07b3dcf2020-05-01 20:04:19 +0800109 return select_i2c_ch_pca9547(channel, 0);
Ying Zhang8876a512014-10-31 18:06:18 +0800110}
111
Shengzhou Liu07886942013-11-22 17:39:11 +0800112int brd_mux_lane_to_slot(void)
113{
114 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Shengzhou Liu031228a2014-02-21 13:16:19 +0800115 u32 srds_prtcl_s1;
Shengzhou Liu07886942013-11-22 17:39:11 +0800116
117 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
118 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
119 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
York Sunc68b12d2016-12-28 08:43:36 -0800120#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu031228a2014-02-21 13:16:19 +0800121 u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
Shengzhou Liu07886942013-11-22 17:39:11 +0800122 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
123 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shengzhou Liu031228a2014-02-21 13:16:19 +0800124#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800125
126 switch (srds_prtcl_s1) {
127 case 0:
128 /* SerDes1 is not enabled */
129 break;
York Sunc68b12d2016-12-28 08:43:36 -0800130#if defined(CONFIG_TARGET_T2080QDS)
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800131 case 0x1b:
Shengzhou Liu07886942013-11-22 17:39:11 +0800132 case 0x1c:
Shengzhou Liu07886942013-11-22 17:39:11 +0800133 case 0xa2:
Shengzhou Liu07886942013-11-22 17:39:11 +0800134 /* SD1(A:D) => SLOT3 SGMII
135 * SD1(G:H) => SLOT1 SGMII
136 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800137 QIXIS_WRITE(brdcfg[12], 0x1a);
138 break;
139 case 0x94:
140 case 0x95:
141 /* SD1(A:B) => SLOT3 SGMII@1.25bps
142 * SD1(C:D) => SFP Module, SGMII@3.125bps
143 * SD1(E:H) => SLOT1 SGMII@1.25bps
144 */
145 case 0x96:
146 /* SD1(A:B) => SLOT3 SGMII@1.25bps
147 * SD1(C) => SFP Module, SGMII@3.125bps
148 * SD1(D) => SFP Module, SGMII@1.25bps
149 * SD1(E:H) => SLOT1 PCIe4 x4
150 */
151 QIXIS_WRITE(brdcfg[12], 0x3a);
Shengzhou Liu07886942013-11-22 17:39:11 +0800152 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800153 case 0x50:
Shengzhou Liu07886942013-11-22 17:39:11 +0800154 case 0x51:
155 /* SD1(A:D) => SLOT3 XAUI
156 * SD1(E) => SLOT1 PCIe4
157 * SD1(F:H) => SLOT2 SGMII
158 */
159 QIXIS_WRITE(brdcfg[12], 0x15);
160 break;
161 case 0x66:
162 case 0x67:
163 /* SD1(A:D) => XFI cage
164 * SD1(E:H) => SLOT1 PCIe4
165 */
166 QIXIS_WRITE(brdcfg[12], 0xfe);
167 break;
Shengzhou Liu03e2dc82014-05-15 19:24:11 +0800168 case 0x6a:
Shengzhou Liu07886942013-11-22 17:39:11 +0800169 case 0x6b:
170 /* SD1(A:D) => XFI cage
171 * SD1(E) => SLOT1 PCIe4
172 * SD1(F:H) => SLOT2 SGMII
173 */
174 QIXIS_WRITE(brdcfg[12], 0xf1);
175 break;
176 case 0x6c:
177 case 0x6d:
178 /* SD1(A:B) => XFI cage
179 * SD1(C:D) => SLOT3 SGMII
180 * SD1(E:H) => SLOT1 PCIe4
181 */
182 QIXIS_WRITE(brdcfg[12], 0xda);
183 break;
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800184 case 0x6e:
185 /* SD1(A:B) => SFP Module, XFI
186 * SD1(C:D) => SLOT3 SGMII
187 * SD1(E:F) => SLOT1 PCIe4 x2
188 * SD1(G:H) => SLOT2 SGMII
189 */
190 QIXIS_WRITE(brdcfg[12], 0xd9);
191 break;
192 case 0xda:
193 /* SD1(A:H) => SLOT3 PCIe3 x8
194 */
195 QIXIS_WRITE(brdcfg[12], 0x0);
196 break;
197 case 0xc8:
198 /* SD1(A) => SLOT3 PCIe3 x1
199 * SD1(B) => SFP Module, SGMII@1.25bps
200 * SD1(C:D) => SFP Module, SGMII@3.125bps
201 * SD1(E:F) => SLOT1 PCIe4 x2
202 * SD1(G:H) => SLOT2 SGMII
203 */
204 QIXIS_WRITE(brdcfg[12], 0x79);
205 break;
206 case 0xab:
207 /* SD1(A:D) => SLOT3 PCIe3 x4
208 * SD1(E:H) => SLOT1 PCIe4 x4
209 */
210 QIXIS_WRITE(brdcfg[12], 0x1a);
211 break;
Shengzhou Liu031228a2014-02-21 13:16:19 +0800212#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800213 default:
214 printf("WARNING: unsupported for SerDes1 Protocol %d\n",
215 srds_prtcl_s1);
216 return -1;
217 }
218
York Sunc68b12d2016-12-28 08:43:36 -0800219#ifdef CONFIG_TARGET_T2080QDS
Shengzhou Liu07886942013-11-22 17:39:11 +0800220 switch (srds_prtcl_s2) {
221 case 0:
222 /* SerDes2 is not enabled */
223 break;
224 case 0x01:
225 case 0x02:
226 /* SD2(A:H) => SLOT4 PCIe1 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800227 QIXIS_WRITE(brdcfg[13], 0x10);
Shengzhou Liu07886942013-11-22 17:39:11 +0800228 break;
229 case 0x15:
230 case 0x16:
231 /*
232 * SD2(A:D) => SLOT4 PCIe1
233 * SD2(E:F) => SLOT5 PCIe2
234 * SD2(G:H) => SATA1,SATA2
235 */
236 QIXIS_WRITE(brdcfg[13], 0xb0);
237 break;
238 case 0x18:
239 /*
240 * SD2(A:D) => SLOT4 PCIe1
241 * SD2(E:F) => SLOT5 Aurora
242 * SD2(G:H) => SATA1,SATA2
243 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800244 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800245 break;
246 case 0x1f:
247 /*
248 * SD2(A:D) => SLOT4 PCIe1
249 * SD2(E:H) => SLOT5 PCIe2
250 */
251 QIXIS_WRITE(brdcfg[13], 0xa0);
252 break;
253 case 0x29:
254 case 0x2d:
255 case 0x2e:
256 /*
257 * SD2(A:D) => SLOT4 SRIO2
258 * SD2(E:H) => SLOT5 SRIO1
259 */
Shengzhou Liu7fcbd1f2014-01-03 14:48:44 +0800260 QIXIS_WRITE(brdcfg[13], 0xa0);
261 break;
262 case 0x36:
263 /*
264 * SD2(A:D) => SLOT4 SRIO2
265 * SD2(E:F) => Aurora
266 * SD2(G:H) => SATA1,SATA2
267 */
268 QIXIS_WRITE(brdcfg[13], 0x78);
Shengzhou Liu07886942013-11-22 17:39:11 +0800269 break;
270 default:
271 printf("WARNING: unsupported for SerDes2 Protocol %d\n",
272 srds_prtcl_s2);
273 return -1;
274 }
Shengzhou Liu031228a2014-02-21 13:16:19 +0800275#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800276 return 0;
277}
278
Yangbo Luf9049b22020-06-17 18:08:58 +0800279static void esdhc_adapter_card_ident(void)
280{
281 u8 card_id, value;
282
283 card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
284
285 switch (card_id) {
286 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
287 value = QIXIS_READ(brdcfg[5]);
288 value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7);
289 QIXIS_WRITE(brdcfg[5], value);
290 break;
291 case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
292 value = QIXIS_READ(pwr_ctl[1]);
293 value |= QIXIS_EVDD_BY_SDHC_VS;
294 QIXIS_WRITE(pwr_ctl[1], value);
295 break;
296 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
297 value = QIXIS_READ(brdcfg[5]);
298 value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
299 QIXIS_WRITE(brdcfg[5], value);
300 break;
301 default:
302 break;
303 }
304}
305
Shengzhou Liu07886942013-11-22 17:39:11 +0800306int board_early_init_r(void)
307{
308 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700309 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Shengzhou Liu07886942013-11-22 17:39:11 +0800310
311 /*
312 * Remap Boot flash + PROMJET region to caching-inhibited
313 * so that flash can be erased properly.
314 */
315
316 /* Flush d-cache and invalidate i-cache of any FLASH data */
317 flush_dcache();
318 invalidate_icache();
319
York Sun220c3462014-06-24 21:16:20 -0700320 if (flash_esel == -1) {
321 /* very unlikely unless something is messed up */
322 puts("Error: Could not find TLB for FLASH BASE\n");
323 flash_esel = 2; /* give our best effort to continue */
324 } else {
325 /* invalidate existing TLB entry for flash + promjet */
326 disable_tlb(flash_esel);
327 }
Shengzhou Liu07886942013-11-22 17:39:11 +0800328
329 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
330 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
331 0, flash_esel, BOOKE_PAGESZ_256M, 1);
332
Shengzhou Liu07886942013-11-22 17:39:11 +0800333 /* Disable remote I2C connection to qixis fpga */
334 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
335
Ying Zhang8876a512014-10-31 18:06:18 +0800336 /*
337 * Adjust core voltage according to voltage ID
338 * This function changes I2C mux to channel 2.
339 */
340 if (adjust_vdd(0))
341 printf("Warning: Adjusting core voltage failed.\n");
342
Shengzhou Liu07886942013-11-22 17:39:11 +0800343 brd_mux_lane_to_slot();
Biwen Li07b3dcf2020-05-01 20:04:19 +0800344 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Yangbo Luf9049b22020-06-17 18:08:58 +0800345 esdhc_adapter_card_ident();
Shengzhou Liu07886942013-11-22 17:39:11 +0800346 return 0;
347}
348
349unsigned long get_board_sys_clk(void)
350{
351 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
352#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
353 /* use accurate clock measurement */
354 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
355 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
356 u32 val;
357
358 val = freq * base;
359 if (val) {
360 debug("SYS Clock measurement is: %d\n", val);
361 return val;
362 } else {
363 printf("Warning: SYS clock measurement is invalid, ");
364 printf("using value from brdcfg1.\n");
365 }
366#endif
367
368 switch (sysclk_conf & 0x0F) {
369 case QIXIS_SYSCLK_83:
370 return 83333333;
371 case QIXIS_SYSCLK_100:
372 return 100000000;
373 case QIXIS_SYSCLK_125:
374 return 125000000;
375 case QIXIS_SYSCLK_133:
376 return 133333333;
377 case QIXIS_SYSCLK_150:
378 return 150000000;
379 case QIXIS_SYSCLK_160:
380 return 160000000;
381 case QIXIS_SYSCLK_166:
382 return 166666666;
383 }
384 return 66666666;
385}
386
387unsigned long get_board_ddr_clk(void)
388{
389 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
390#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
391 /* use accurate clock measurement */
392 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
393 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
394 u32 val;
395
396 val = freq * base;
397 if (val) {
398 debug("DDR Clock measurement is: %d\n", val);
399 return val;
400 } else {
401 printf("Warning: DDR clock measurement is invalid, ");
402 printf("using value from brdcfg1.\n");
403 }
404#endif
405
406 switch ((ddrclk_conf & 0x30) >> 4) {
407 case QIXIS_DDRCLK_100:
408 return 100000000;
409 case QIXIS_DDRCLK_125:
410 return 125000000;
411 case QIXIS_DDRCLK_133:
412 return 133333333;
413 }
414 return 66666666;
415}
416
417int misc_init_r(void)
418{
419 return 0;
420}
421
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900422int ft_board_setup(void *blob, struct bd_info *bd)
Shengzhou Liu07886942013-11-22 17:39:11 +0800423{
424 phys_addr_t base;
425 phys_size_t size;
426
427 ft_cpu_setup(blob, bd);
428
Simon Glassda1a1342017-08-03 12:22:15 -0600429 base = env_get_bootm_low();
430 size = env_get_bootm_size();
Shengzhou Liu07886942013-11-22 17:39:11 +0800431
432 fdt_fixup_memory(blob, (u64)base, (u64)size);
433
434#ifdef CONFIG_PCI
435 pci_of_setup(blob, bd);
436#endif
437
438 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530439 fsl_fdt_fixup_dr_usb(blob, bd);
Shengzhou Liu07886942013-11-22 17:39:11 +0800440
441#ifdef CONFIG_SYS_DPAA_FMAN
Madalin Bucur70848512020-04-30 15:59:58 +0300442#ifndef CONFIG_DM_ETH
Shengzhou Liu07886942013-11-22 17:39:11 +0800443 fdt_fixup_fman_ethernet(blob);
Madalin Bucur70848512020-04-30 15:59:58 +0300444#endif
Shengzhou Liu07886942013-11-22 17:39:11 +0800445 fdt_fixup_board_enet(blob);
446#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600447
448 return 0;
Shengzhou Liu07886942013-11-22 17:39:11 +0800449}