2 * Copyright 2011-2012 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/compiler.h>
13 #include <asm/processor.h>
14 #include <asm/errno.h>
15 #include <asm/cache.h>
16 #include <asm/immap_85xx.h>
17 #include <asm/fsl_law.h>
18 #include <asm/fsl_serdes.h>
19 #include <asm/fsl_portals.h>
20 #include <asm/fsl_liodn.h>
23 #include "../common/qixis.h"
24 #include "../common/vsc3316_3308.h"
25 #include "../common/idt8t49n222a_serdes_clk.h"
27 #include "b4860qds_qixis.h"
28 #include "b4860qds_crossbar_con.h"
30 #define CLK_MUX_SEL_MASK 0x4
31 #define ETH_PHY_CLK_OUT 0x4
34 DECLARE_GLOBAL_DATA_PTR;
40 struct cpu_type *cpu = gd->arch.cpu;
41 static const char *const freq[] = {"100", "125", "156.25", "161.13",
42 "122.88", "122.88", "122.88"};
45 printf("Board: %sQDS, ", cpu->name);
46 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
47 QIXIS_READ(id), QIXIS_READ(arch));
49 sw = QIXIS_READ(brdcfg[0]);
50 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
53 printf("vBank: %d\n", sw);
54 else if (sw >= 0x8 && sw <= 0xE)
57 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
59 printf("FPGA: v%d (%s), build %d",
60 (int)QIXIS_READ(scver), qixis_read_tag(buf),
61 (int)qixis_read_minor());
62 /* the timestamp string contains "\n" at the end */
63 printf(" on %s", qixis_read_time(buf));
66 * Display the actual SERDES reference clocks as configured by the
67 * dip switches on the board. Note that the SWx registers could
68 * technically be set to force the reference clocks to match the
69 * values that the SERDES expects (or vice versa). For now, however,
70 * we just display both values and hope the user notices when they
73 puts("SERDES Reference Clocks: ");
74 sw = QIXIS_READ(brdcfg[2]);
75 clock = (sw >> 5) & 7;
76 printf("Bank1=%sMHz ", freq[clock]);
77 sw = QIXIS_READ(brdcfg[4]);
78 clock = (sw >> 6) & 3;
79 printf("Bank2=%sMHz\n", freq[clock]);
84 int select_i2c_ch_pca(u8 ch)
88 /* Selecting proper channel via PCA*/
89 ret = i2c_write(I2C_MUX_PCA_ADDR, 0x0, 1, &ch, 1);
91 printf("PCA: failed to select proper channel.\n");
98 int configure_vsc3316_3308(void)
100 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
101 unsigned int num_vsc16_con, num_vsc08_con;
102 u32 serdes1_prtcl, serdes2_prtcl;
105 serdes1_prtcl = in_be32(&gur->rcwsr[4]) &
106 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
107 if (!serdes1_prtcl) {
108 printf("SERDES1 is not enabled\n");
111 serdes1_prtcl >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
112 debug("Using SERDES1 Protocol: 0x%x:\n", serdes1_prtcl);
114 serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
115 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
116 if (!serdes2_prtcl) {
117 printf("SERDES2 is not enabled\n");
120 serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
121 debug("Using SERDES2 Protocol: 0x%x:\n", serdes2_prtcl);
123 switch (serdes1_prtcl) {
133 * Lanes: C,D,E,F,G,H: CPRI
135 debug("Configuring crossbar to use onboard SGMII PHYs:"
136 "srds_prctl:%x\n", serdes1_prtcl);
137 num_vsc16_con = NUM_CON_VSC3316;
138 /* Configure VSC3316 crossbar switch */
139 ret = select_i2c_ch_pca(I2C_CH_VSC3316);
141 ret = vsc3316_config(VSC3316_TX_ADDRESS,
142 vsc16_tx_4sfp_sgmii_12_56,
146 ret = vsc3316_config(VSC3316_RX_ADDRESS,
147 vsc16_rx_4sfp_sgmii_12_56,
180 * Lanes: E,F,G,H: CPRI
182 debug("Configuring crossbar for Aurora, SGMII 3 and 4,"
183 " and CPRI. srds_prctl:%x\n", serdes1_prtcl);
184 num_vsc16_con = NUM_CON_VSC3316;
185 /* Configure VSC3316 crossbar switch */
186 ret = select_i2c_ch_pca(I2C_CH_VSC3316);
188 ret = vsc3316_config(VSC3316_TX_ADDRESS,
189 vsc16_tx_sfp_sgmii_aurora,
193 ret = vsc3316_config(VSC3316_RX_ADDRESS,
194 vsc16_rx_sfp_sgmii_aurora,
203 #ifdef CONFIG_PPC_B4420
209 * Lanes: A,B,C,D: SGMII
210 * Lanes: E,F,G,H: CPRI
212 debug("Configuring crossbar to use onboard SGMII PHYs:"
213 "srds_prctl:%x\n", serdes1_prtcl);
214 num_vsc16_con = NUM_CON_VSC3316;
215 /* Configure VSC3316 crossbar switch */
216 ret = select_i2c_ch_pca(I2C_CH_VSC3316);
218 ret = vsc3316_config(VSC3316_TX_ADDRESS,
219 vsc16_tx_sgmii_lane_cd, num_vsc16_con);
222 ret = vsc3316_config(VSC3316_RX_ADDRESS,
223 vsc16_rx_sgmii_lane_cd, num_vsc16_con);
236 num_vsc16_con = NUM_CON_VSC3316;
237 /* Configure VSC3316 crossbar switch */
238 ret = select_i2c_ch_pca(I2C_CH_VSC3316);
240 ret = vsc3316_config(VSC3316_TX_ADDRESS,
241 vsc16_tx_sfp, num_vsc16_con);
244 ret = vsc3316_config(VSC3316_RX_ADDRESS,
245 vsc16_rx_sfp, num_vsc16_con);
253 printf("WARNING:VSC crossbars programming not supported for:%x"
254 " SerDes1 Protocol.\n", serdes1_prtcl);
258 switch (serdes2_prtcl) {
267 num_vsc08_con = NUM_CON_VSC3308;
268 /* Configure VSC3308 crossbar switch */
269 ret = select_i2c_ch_pca(I2C_CH_VSC3308);
271 ret = vsc3308_config(VSC3308_TX_ADDRESS,
272 vsc08_tx_amc, num_vsc08_con);
275 ret = vsc3308_config(VSC3308_RX_ADDRESS,
276 vsc08_rx_amc, num_vsc08_con);
284 printf("WARNING:VSC crossbars programming not supported for: %x"
285 " SerDes2 Protocol.\n", serdes2_prtcl);
292 int config_serdes1_refclks(void)
294 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
295 serdes_corenet_t *srds_regs =
296 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
297 u32 serdes1_prtcl, lane;
298 unsigned int flag_sgmii_aurora_prtcl = 0;
302 serdes1_prtcl = in_be32(&gur->rcwsr[4]) &
303 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
304 if (!serdes1_prtcl) {
305 printf("SERDES1 is not enabled\n");
308 serdes1_prtcl >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
309 debug("Using SERDES1 Protocol: 0x%x:\n", serdes1_prtcl);
311 /* To prevent generation of reset request from SerDes
312 * while changing the refclks, By setting SRDS_RST_MSK bit,
313 * SerDes reset event cannot cause a reset request
315 setbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
317 /* Reconfigure IDT idt8t49n222a device for CPRI to work
318 * For this SerDes1's Refclk1 and refclk2 need to be set
321 switch (serdes1_prtcl) {
345 debug("Configuring idt8t49n222a for CPRI SerDes clks:"
346 " for srds_prctl:%x\n", serdes1_prtcl);
347 ret = select_i2c_ch_pca(I2C_CH_IDT);
349 ret = set_serdes_refclk(IDT_SERDES1_ADDRESS, 1,
350 SERDES_REFCLK_122_88,
351 SERDES_REFCLK_122_88, 0);
353 printf("IDT8T49N222A configuration failed.\n");
356 debug("IDT8T49N222A configured.\n");
360 select_i2c_ch_pca(I2C_CH_DEFAULT);
362 /* Change SerDes1's Refclk1 to 125MHz for on board
363 * SGMIIs or Aurora to work
365 for (lane = 0; lane < SRDS_MAX_LANES; lane++) {
366 enum srds_prtcl lane_prtcl = serdes_get_prtcl
367 (0, serdes1_prtcl, lane);
368 switch (lane_prtcl) {
369 case SGMII_FM1_DTSEC1:
370 case SGMII_FM1_DTSEC2:
371 case SGMII_FM1_DTSEC3:
372 case SGMII_FM1_DTSEC4:
373 case SGMII_FM1_DTSEC5:
374 case SGMII_FM1_DTSEC6:
376 flag_sgmii_aurora_prtcl++;
383 if (flag_sgmii_aurora_prtcl)
384 QIXIS_WRITE(brdcfg[4], QIXIS_SRDS1CLK_125);
386 /* Steps For SerDes PLLs reset and reconfiguration after
387 * changing SerDes's refclks
389 for (i = 0; i < PLL_NUM; i++) {
390 debug("For PLL%d reset and reconfiguration after"
391 " changing refclks\n", i+1);
392 clrbits_be32(&srds_regs->bank[i].rstctl,
393 SRDS_RSTCTL_SDRST_B);
395 clrbits_be32(&srds_regs->bank[i].rstctl,
396 (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B));
398 setbits_be32(&srds_regs->bank[i].rstctl,
400 setbits_be32(&srds_regs->bank[i].rstctl,
401 (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
402 | SRDS_RSTCTL_SDRST_B));
406 printf("WARNING:IDT8T49N222A configuration not"
407 " supported for:%x SerDes1 Protocol.\n",
412 /* Clearing SRDS_RST_MSK bit as now
413 * SerDes reset event can cause a reset request
415 clrbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
419 int config_serdes2_refclks(void)
421 ccsr_gur_t *gur = (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
422 serdes_corenet_t *srds2_regs =
423 (void *)CONFIG_SYS_FSL_CORENET_SERDES2_ADDR;
428 serdes2_prtcl = in_be32(&gur->rcwsr[4]) &
429 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
430 if (!serdes2_prtcl) {
431 debug("SERDES2 is not enabled\n");
434 serdes2_prtcl >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
435 debug("Using SERDES2 Protocol: 0x%x:\n", serdes2_prtcl);
437 /* To prevent generation of reset request from SerDes
438 * while changing the refclks, By setting SRDS_RST_MSK bit,
439 * SerDes reset event cannot cause a reset request
441 setbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
443 /* Reconfigure IDT idt8t49n222a device for PCIe SATA to work
444 * For this SerDes2's Refclk1 need to be set to 100MHz
446 switch (serdes2_prtcl) {
450 debug("Configuring IDT for PCIe SATA for srds_prctl:%x\n",
452 ret = select_i2c_ch_pca(I2C_CH_IDT);
454 ret = set_serdes_refclk(IDT_SERDES2_ADDRESS, 2,
456 SERDES_REFCLK_100, 0);
458 printf("IDT8T49N222A configuration failed.\n");
461 debug("IDT8T49N222A configured.\n");
465 select_i2c_ch_pca(I2C_CH_DEFAULT);
467 /* Steps For SerDes PLLs reset and reconfiguration after
468 * changing SerDes's refclks
470 for (i = 0; i < PLL_NUM; i++) {
471 clrbits_be32(&srds2_regs->bank[i].rstctl,
472 SRDS_RSTCTL_SDRST_B);
474 clrbits_be32(&srds2_regs->bank[i].rstctl,
475 (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B));
477 setbits_be32(&srds2_regs->bank[i].rstctl,
479 setbits_be32(&srds2_regs->bank[i].rstctl,
480 (SRDS_RSTCTL_SDEN | SRDS_RSTCTL_PLLRST_B
481 | SRDS_RSTCTL_SDRST_B));
485 printf("IDT configuration not supported for:%x S2 Protocol.\n",
490 /* Clearing SRDS_RST_MSK bit as now
491 * SerDes reset event can cause a reset request
493 clrbits_be32(&gur->rstrqmr1, FSL_CORENET_RSTRQMR1_SRDS_RST_MSK);
497 int board_early_init_r(void)
499 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
500 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
504 * Remap Boot flash + PROMJET region to caching-inhibited
505 * so that flash can be erased properly.
508 /* Flush d-cache and invalidate i-cache of any FLASH data */
512 /* invalidate existing TLB entry for flash + promjet */
513 disable_tlb(flash_esel);
515 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
516 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
517 0, flash_esel, BOOKE_PAGESZ_256M, 1);
520 #ifdef CONFIG_SYS_DPAA_QBMAN
523 /* SerDes1 refclks need to be set again, as default clks
524 * are not suitable for CPRI and onboard SGMIIs to work
526 * This function will set SerDes1's Refclk1 and refclk2
527 * as per SerDes1 protocols
529 if (config_serdes1_refclks())
530 printf("SerDes1 Refclks couldn't set properly.\n");
532 printf("SerDes1 Refclks have been set.\n");
534 /* SerDes2 refclks need to be set again, as default clks
535 * are not suitable for PCIe SATA to work
536 * This function will set SerDes2's Refclk1 and refclk2
537 * for SerDes2 protocols having PCIe in them
538 * for PCIe SATA to work
540 ret = config_serdes2_refclks();
542 printf("SerDes2 Refclks have been set.\n");
543 else if (ret == -ENODEV)
544 printf("SerDes disable, Refclks couldn't change.\n");
546 printf("SerDes2 Refclk reconfiguring failed.\n");
548 /* Configure VSC3316 and VSC3308 crossbar switches */
549 if (configure_vsc3316_3308())
550 printf("VSC:failed to configure VSC3316/3308.\n");
552 printf("VSC:VSC3316/3308 successfully configured.\n");
554 select_i2c_ch_pca(I2C_CH_DEFAULT);
559 unsigned long get_board_sys_clk(void)
561 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
563 switch ((sysclk_conf & 0x0C) >> 2) {
574 unsigned long get_board_ddr_clk(void)
576 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
578 switch (ddrclk_conf & 0x03) {
589 static int serdes_refclock(u8 sw, u8 sdclk)
596 brdcfg4 = QIXIS_READ(brdcfg[4]);
597 if ((brdcfg4 & CLK_MUX_SEL_MASK) == ETH_PHY_CLK_OUT)
598 return SRDS_PLLCR0_RFCK_SEL_125;
600 clock = (sw >> 5) & 7;
602 clock = (sw >> 6) & 3;
606 ret = SRDS_PLLCR0_RFCK_SEL_100;
609 ret = SRDS_PLLCR0_RFCK_SEL_125;
612 ret = SRDS_PLLCR0_RFCK_SEL_156_25;
615 ret = SRDS_PLLCR0_RFCK_SEL_161_13;
620 ret = SRDS_PLLCR0_RFCK_SEL_122_88;
630 #define NUM_SRDS_BANKS 2
632 int misc_init_r(void)
635 serdes_corenet_t *srds_regs =
636 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
637 u32 actual[NUM_SRDS_BANKS];
641 sw = QIXIS_READ(brdcfg[2]);
642 clock = serdes_refclock(sw, 1);
646 printf("Warning: SDREFCLK1 switch setting is unsupported\n");
648 sw = QIXIS_READ(brdcfg[4]);
649 clock = serdes_refclock(sw, 2);
653 printf("Warning: SDREFCLK2 switch setting unsupported\n");
655 for (i = 0; i < NUM_SRDS_BANKS; i++) {
656 u32 pllcr0 = srds_regs->bank[i].pllcr0;
657 u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
658 if (expected != actual[i]) {
659 printf("Warning: SERDES bank %u expects reference clock"
660 " %sMHz, but actual is %sMHz\n", i + 1,
661 serdes_clock_to_string(expected),
662 serdes_clock_to_string(actual[i]));
669 void ft_board_setup(void *blob, bd_t *bd)
674 ft_cpu_setup(blob, bd);
676 base = getenv_bootm_low();
677 size = getenv_bootm_size();
679 fdt_fixup_memory(blob, (u64)base, (u64)size);
682 pci_of_setup(blob, bd);
685 fdt_fixup_liodn(blob);
687 #ifdef CONFIG_HAS_FSL_DR_USB
688 fdt_fixup_dr_usb(blob, bd);
691 #ifdef CONFIG_SYS_DPAA_FMAN
692 fdt_fixup_fman_ethernet(blob);
693 fdt_fixup_board_enet(blob);
698 * Dump board switch settings.
699 * The bits that cannot be read/sampled via some FPGA or some
700 * registers, they will be displayed as
701 * underscore in binary format. mask[] has those bits.
702 * Some bits are calculated differently than the actual switches
703 * if booting with overriding by FPGA.
705 void qixis_dump_switch(void)
711 * Any bit with 1 means that bit cannot be reverse engineered.
712 * It will be displayed as _ in binary format.
714 static const u8 mask[] = {0x07, 0, 0, 0xff, 0};
716 u8 brdcfg[16], dutcfg[16];
718 for (i = 0; i < 16; i++) {
719 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
720 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
723 sw[0] = ((brdcfg[0] & 0x0f) << 4) | \
725 sw[1] = ((dutcfg[1] & 0x01) << 7) | \
726 ((dutcfg[2] & 0x07) << 4) | \
727 ((dutcfg[6] & 0x10) >> 1) | \
728 ((dutcfg[6] & 0x80) >> 5) | \
729 ((dutcfg[1] & 0x40) >> 5) | \
733 sw[4] = ((brdcfg[1] & 0x30) << 2) | \
734 ((brdcfg[1] & 0xc0) >> 2) | \
737 puts("DIP switch settings:\n");
738 for (i = 0; i < 5; i++) {
739 printf("SW%d = 0b%s (0x%02x)\n",
740 i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);