2 * Copyright 2009-2013 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/compiler.h>
13 #include <asm/processor.h>
14 #include <asm/immap_85xx.h>
15 #include <asm/fsl_law.h>
16 #include <asm/fsl_serdes.h>
17 #include <asm/fsl_liodn.h>
20 #include "../common/qixis.h"
21 #include "../common/vsc3316_3308.h"
22 #include "../common/vid.h"
24 #include "t208xqds_qixis.h"
26 DECLARE_GLOBAL_DATA_PTR;
32 struct cpu_type *cpu = gd->arch.cpu;
33 static const char *freq[4] = {
34 "100.00MHZ(from 8T49N222A)", "125.00MHz",
35 "156.25MHZ", "100.00MHz"
38 printf("Board: %sQDS, ", cpu->name);
39 sw = QIXIS_READ(arch);
40 printf("Sys ID: 0x%02x, Board Arch: V%d, ", QIXIS_READ(id), sw >> 4);
41 printf("Board Version: %c, boot from ", (sw & 0xf) + 'A' - 1);
48 sw = QIXIS_READ(brdcfg[0]);
49 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
52 printf("vBank%d\n", sw);
58 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
61 printf("FPGA: v%d (%s), build %d", (int)QIXIS_READ(scver),
62 qixis_read_tag(buf), (int)qixis_read_minor());
63 /* the timestamp string contains "\n" at the end */
64 printf(" on %s", qixis_read_time(buf));
66 puts("SERDES Reference Clocks:\n");
67 sw = QIXIS_READ(brdcfg[2]);
68 printf("SD1_CLK1=%s, SD1_CLK2=%s\n", freq[sw >> 6],
69 freq[(sw >> 4) & 0x3]);
70 printf("SD2_CLK1=%s, SD2_CLK2=%s\n", freq[(sw & 0xf) >> 2],
76 int select_i2c_ch_pca9547(u8 ch)
80 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
82 puts("PCA: failed to select proper channel\n");
89 int i2c_multiplexer_select_vid_channel(u8 channel)
91 return select_i2c_ch_pca9547(channel);
94 int brd_mux_lane_to_slot(void)
96 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
99 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
100 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
101 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
102 #if defined(CONFIG_TARGET_T2080QDS)
103 u32 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
104 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
105 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
108 switch (srds_prtcl_s1) {
110 /* SerDes1 is not enabled */
112 #if defined(CONFIG_TARGET_T2080QDS)
116 /* SD1(A:D) => SLOT3 SGMII
117 * SD1(G:H) => SLOT1 SGMII
119 QIXIS_WRITE(brdcfg[12], 0x1a);
123 /* SD1(A:B) => SLOT3 SGMII@1.25bps
124 * SD1(C:D) => SFP Module, SGMII@3.125bps
125 * SD1(E:H) => SLOT1 SGMII@1.25bps
128 /* SD1(A:B) => SLOT3 SGMII@1.25bps
129 * SD1(C) => SFP Module, SGMII@3.125bps
130 * SD1(D) => SFP Module, SGMII@1.25bps
131 * SD1(E:H) => SLOT1 PCIe4 x4
133 QIXIS_WRITE(brdcfg[12], 0x3a);
137 /* SD1(A:D) => SLOT3 XAUI
138 * SD1(E) => SLOT1 PCIe4
139 * SD1(F:H) => SLOT2 SGMII
141 QIXIS_WRITE(brdcfg[12], 0x15);
145 /* SD1(A:D) => XFI cage
146 * SD1(E:H) => SLOT1 PCIe4
148 QIXIS_WRITE(brdcfg[12], 0xfe);
152 /* SD1(A:D) => XFI cage
153 * SD1(E) => SLOT1 PCIe4
154 * SD1(F:H) => SLOT2 SGMII
156 QIXIS_WRITE(brdcfg[12], 0xf1);
160 /* SD1(A:B) => XFI cage
161 * SD1(C:D) => SLOT3 SGMII
162 * SD1(E:H) => SLOT1 PCIe4
164 QIXIS_WRITE(brdcfg[12], 0xda);
167 /* SD1(A:B) => SFP Module, XFI
168 * SD1(C:D) => SLOT3 SGMII
169 * SD1(E:F) => SLOT1 PCIe4 x2
170 * SD1(G:H) => SLOT2 SGMII
172 QIXIS_WRITE(brdcfg[12], 0xd9);
175 /* SD1(A:H) => SLOT3 PCIe3 x8
177 QIXIS_WRITE(brdcfg[12], 0x0);
180 /* SD1(A) => SLOT3 PCIe3 x1
181 * SD1(B) => SFP Module, SGMII@1.25bps
182 * SD1(C:D) => SFP Module, SGMII@3.125bps
183 * SD1(E:F) => SLOT1 PCIe4 x2
184 * SD1(G:H) => SLOT2 SGMII
186 QIXIS_WRITE(brdcfg[12], 0x79);
189 /* SD1(A:D) => SLOT3 PCIe3 x4
190 * SD1(E:H) => SLOT1 PCIe4 x4
192 QIXIS_WRITE(brdcfg[12], 0x1a);
194 #elif defined(CONFIG_TARGET_T2081QDS)
197 /* SD1(A:D) => SLOT2 XAUI
198 * SD1(E) => SLOT1 PCIe4 x1
199 * SD1(F:H) => SLOT3 SGMII
201 QIXIS_WRITE(brdcfg[12], 0x98);
202 QIXIS_WRITE(brdcfg[13], 0x70);
206 /* SD1(A:D) => XFI SFP Module
207 * SD1(E) => SLOT1 PCIe4 x1
208 * SD1(F:H) => SLOT3 SGMII
210 QIXIS_WRITE(brdcfg[12], 0x80);
211 QIXIS_WRITE(brdcfg[13], 0x70);
215 /* SD1(A:B) => XFI SFP Module
216 * SD1(C:D) => SLOT2 SGMII
217 * SD1(E:H) => SLOT1 PCIe4 x4
219 QIXIS_WRITE(brdcfg[12], 0xe8);
220 QIXIS_WRITE(brdcfg[13], 0x0);
224 /* SD1(A:D) => SLOT2 PCIe3 x4
225 * SD1(F:H) => SLOT1 SGMI4 x4
227 QIXIS_WRITE(brdcfg[12], 0xf8);
228 QIXIS_WRITE(brdcfg[13], 0x0);
232 /* SD1(A) => SLOT2 PCIe3 x1
233 * SD1(B) => SLOT7 SGMII
234 * SD1(C) => SLOT6 SGMII
235 * SD1(D) => SLOT5 SGMII
236 * SD1(E) => SLOT1 PCIe4 x1
237 * SD1(F:H) => SLOT3 SGMII
239 QIXIS_WRITE(brdcfg[12], 0x80);
240 QIXIS_WRITE(brdcfg[13], 0x70);
244 /* SD1(A:D) => SLOT2 PCIe3 x4
245 * SD1(E) => SLOT1 PCIe4 x1
246 * SD1(F) => SLOT4 PCIe1 x1
247 * SD1(G) => SLOT3 PCIe2 x1
248 * SD1(H) => SLOT7 SGMII
250 QIXIS_WRITE(brdcfg[12], 0x98);
251 QIXIS_WRITE(brdcfg[13], 0x25);
254 /* SD1(A) => SLOT2 PCIe3 x1
255 * SD1(B:D) => SLOT7 SGMII
256 * SD1(E) => SLOT1 PCIe4 x1
257 * SD1(F) => SLOT4 PCIe1 x1
258 * SD1(G) => SLOT3 PCIe2 x1
259 * SD1(H) => SLOT7 SGMII
261 QIXIS_WRITE(brdcfg[12], 0x81);
262 QIXIS_WRITE(brdcfg[13], 0xa5);
266 printf("WARNING: unsupported for SerDes1 Protocol %d\n",
271 #ifdef CONFIG_TARGET_T2080QDS
272 switch (srds_prtcl_s2) {
274 /* SerDes2 is not enabled */
278 /* SD2(A:H) => SLOT4 PCIe1 */
279 QIXIS_WRITE(brdcfg[13], 0x10);
284 * SD2(A:D) => SLOT4 PCIe1
285 * SD2(E:F) => SLOT5 PCIe2
286 * SD2(G:H) => SATA1,SATA2
288 QIXIS_WRITE(brdcfg[13], 0xb0);
292 * SD2(A:D) => SLOT4 PCIe1
293 * SD2(E:F) => SLOT5 Aurora
294 * SD2(G:H) => SATA1,SATA2
296 QIXIS_WRITE(brdcfg[13], 0x78);
300 * SD2(A:D) => SLOT4 PCIe1
301 * SD2(E:H) => SLOT5 PCIe2
303 QIXIS_WRITE(brdcfg[13], 0xa0);
309 * SD2(A:D) => SLOT4 SRIO2
310 * SD2(E:H) => SLOT5 SRIO1
312 QIXIS_WRITE(brdcfg[13], 0xa0);
316 * SD2(A:D) => SLOT4 SRIO2
318 * SD2(G:H) => SATA1,SATA2
320 QIXIS_WRITE(brdcfg[13], 0x78);
323 printf("WARNING: unsupported for SerDes2 Protocol %d\n",
331 int board_early_init_r(void)
333 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
334 int flash_esel = find_tlb_idx((void *)flashbase, 1);
337 * Remap Boot flash + PROMJET region to caching-inhibited
338 * so that flash can be erased properly.
341 /* Flush d-cache and invalidate i-cache of any FLASH data */
345 if (flash_esel == -1) {
346 /* very unlikely unless something is messed up */
347 puts("Error: Could not find TLB for FLASH BASE\n");
348 flash_esel = 2; /* give our best effort to continue */
350 /* invalidate existing TLB entry for flash + promjet */
351 disable_tlb(flash_esel);
354 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
355 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
356 0, flash_esel, BOOKE_PAGESZ_256M, 1);
358 /* Disable remote I2C connection to qixis fpga */
359 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
362 * Adjust core voltage according to voltage ID
363 * This function changes I2C mux to channel 2.
366 printf("Warning: Adjusting core voltage failed.\n");
368 brd_mux_lane_to_slot();
369 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
374 unsigned long get_board_sys_clk(void)
376 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
377 #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
378 /* use accurate clock measurement */
379 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
380 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
385 debug("SYS Clock measurement is: %d\n", val);
388 printf("Warning: SYS clock measurement is invalid, ");
389 printf("using value from brdcfg1.\n");
393 switch (sysclk_conf & 0x0F) {
394 case QIXIS_SYSCLK_83:
396 case QIXIS_SYSCLK_100:
398 case QIXIS_SYSCLK_125:
400 case QIXIS_SYSCLK_133:
402 case QIXIS_SYSCLK_150:
404 case QIXIS_SYSCLK_160:
406 case QIXIS_SYSCLK_166:
412 unsigned long get_board_ddr_clk(void)
414 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
415 #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
416 /* use accurate clock measurement */
417 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
418 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
423 debug("DDR Clock measurement is: %d\n", val);
426 printf("Warning: DDR clock measurement is invalid, ");
427 printf("using value from brdcfg1.\n");
431 switch ((ddrclk_conf & 0x30) >> 4) {
432 case QIXIS_DDRCLK_100:
434 case QIXIS_DDRCLK_125:
436 case QIXIS_DDRCLK_133:
442 int misc_init_r(void)
447 int ft_board_setup(void *blob, bd_t *bd)
452 ft_cpu_setup(blob, bd);
454 base = env_get_bootm_low();
455 size = env_get_bootm_size();
457 fdt_fixup_memory(blob, (u64)base, (u64)size);
460 pci_of_setup(blob, bd);
463 fdt_fixup_liodn(blob);
464 fsl_fdt_fixup_dr_usb(blob, bd);
466 #ifdef CONFIG_SYS_DPAA_FMAN
467 fdt_fixup_fman_ethernet(blob);
468 fdt_fixup_board_enet(blob);