2 * Copyright 2013 Freescale Semiconductor, Inc.
4 * Shengzhou Liu <Shengzhou.Liu@freescale.com>
6 * SPDX-License-Identifier: GPL-2.0+
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_portals.h>
18 #include <asm/fsl_liodn.h>
24 #include <asm/fsl_dtsec.h>
25 #include <asm/fsl_serdes.h>
26 #include "../common/qixis.h"
27 #include "../common/fman.h"
28 #include "t2080qds_qixis.h"
30 #define EMI_NONE 0xFFFFFFFF
40 static int mdio_mux[NUM_FM_PORTS];
42 static const char * const mdio_names[] = {
43 "T2080QDS_MDIO_RGMII1",
44 "T2080QDS_MDIO_RGMII2",
45 "T2080QDS_MDIO_SLOT1",
46 "T2080QDS_MDIO_SLOT3",
47 "T2080QDS_MDIO_SLOT4",
48 "T2080QDS_MDIO_SLOT5",
49 "T2080QDS_MDIO_SLOT2",
53 /* Map SerDes1 8 lanes to default slot, will be initialized dynamically */
54 static u8 lane_to_slot[] = {3, 3, 3, 3, 1, 1, 1, 1};
56 static const char *T2080qds_mdio_name_for_muxval(u8 muxval)
58 return mdio_names[muxval];
61 struct mii_dev *mii_dev_for_muxval(u8 muxval)
64 const char *name = T2080qds_mdio_name_for_muxval(muxval);
67 printf("No bus for muxval %x\n", muxval);
71 bus = miiphy_get_dev_by_name(name);
74 printf("No bus by name %s\n", name);
81 struct T2080qds_mdio {
83 struct mii_dev *realbus;
86 static void T2080qds_mux_mdio(u8 muxval)
90 brdcfg4 = QIXIS_READ(brdcfg[4]);
91 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
92 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
93 QIXIS_WRITE(brdcfg[4], brdcfg4);
97 static int T2080qds_mdio_read(struct mii_dev *bus, int addr, int devad,
100 struct T2080qds_mdio *priv = bus->priv;
102 T2080qds_mux_mdio(priv->muxval);
104 return priv->realbus->read(priv->realbus, addr, devad, regnum);
107 static int T2080qds_mdio_write(struct mii_dev *bus, int addr, int devad,
108 int regnum, u16 value)
110 struct T2080qds_mdio *priv = bus->priv;
112 T2080qds_mux_mdio(priv->muxval);
114 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
117 static int T2080qds_mdio_reset(struct mii_dev *bus)
119 struct T2080qds_mdio *priv = bus->priv;
121 return priv->realbus->reset(priv->realbus);
124 static int T2080qds_mdio_init(char *realbusname, u8 muxval)
126 struct T2080qds_mdio *pmdio;
127 struct mii_dev *bus = mdio_alloc();
130 printf("Failed to allocate T2080QDS MDIO bus\n");
134 pmdio = malloc(sizeof(*pmdio));
136 printf("Failed to allocate T2080QDS private data\n");
141 bus->read = T2080qds_mdio_read;
142 bus->write = T2080qds_mdio_write;
143 bus->reset = T2080qds_mdio_reset;
144 sprintf(bus->name, T2080qds_mdio_name_for_muxval(muxval));
146 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
148 if (!pmdio->realbus) {
149 printf("No bus with name %s\n", realbusname);
155 pmdio->muxval = muxval;
158 return mdio_register(bus);
161 void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
162 enum fm_port port, int offset)
166 struct fixed_link f_link;
167 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
168 u32 srds_s1 = in_be32(&gur->rcwsr[4]) &
169 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
171 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
173 if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
174 phy = fm_info_get_phy_address(port);
180 sprintf(alias, "phy_sgmii_s3_%x", phy);
181 fdt_set_phy_handle(fdt, compat, addr, alias);
182 fdt_status_okay_by_alias(fdt, "emi1_slot3");
186 if (mdio_mux[port] == EMI1_SLOT1) {
187 sprintf(alias, "phy_sgmii_s1_%x", phy);
188 fdt_set_phy_handle(fdt, compat, addr, alias);
189 fdt_status_okay_by_alias(fdt, "emi1_slot1");
190 } else if (mdio_mux[port] == EMI1_SLOT2) {
191 sprintf(alias, "phy_sgmii_s2_%x", phy);
192 fdt_set_phy_handle(fdt, compat, addr, alias);
193 fdt_status_okay_by_alias(fdt, "emi1_slot2");
200 } else if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_XGMII) {
202 case 0x66: /* XFI interface */
207 f_link.phy_id = port;
209 f_link.link_speed = 10000;
211 f_link.asym_pause = 0;
213 fdt_delprop(fdt, offset, "phy-handle");
214 fdt_setprop(fdt, offset, "fixed-link", &f_link,
223 void fdt_fixup_board_enet(void *fdt)
229 * This function reads RCW to check if Serdes1{E,F,G,H} is configured
230 * as slot 1/2/3 and update the lane_to_slot[] array accordingly
232 static void initialize_lane_to_slot(void)
234 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
235 u32 srds_s1 = in_be32(&gur->rcwsr[4]) &
236 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
238 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
272 int board_eth_init(bd_t *bis)
274 #if defined(CONFIG_FMAN_ENET)
275 int i, idx, lane, slot, interface;
276 struct memac_mdio_info dtsec_mdio_info;
277 struct memac_mdio_info tgec_mdio_info;
278 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
279 u32 rcwsr13 = in_be32(&gur->rcwsr[13]);
282 srds_s1 = in_be32(&gur->rcwsr[4]) &
283 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
284 srds_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
286 initialize_lane_to_slot();
288 /* Initialize the mdio_mux array so we can recognize empty elements */
289 for (i = 0; i < NUM_FM_PORTS; i++)
290 mdio_mux[i] = EMI_NONE;
292 dtsec_mdio_info.regs =
293 (struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
295 dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
297 /* Register the 1G MDIO bus */
298 fm_memac_mdio_init(bis, &dtsec_mdio_info);
300 tgec_mdio_info.regs =
301 (struct memac_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
302 tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
304 /* Register the 10G MDIO bus */
305 fm_memac_mdio_init(bis, &tgec_mdio_info);
307 /* Register the muxing front-ends to the MDIO buses */
308 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII1);
309 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII2);
310 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
311 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
312 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
313 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
314 T2080qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
315 T2080qds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2);
317 /* Set the two on-board RGMII PHY address */
318 fm_info_set_phy_address(FM1_DTSEC3, RGMII_PHY1_ADDR);
319 if ((rcwsr13 & FSL_CORENET_RCWSR13_EC2) ==
320 FSL_CORENET_RCWSR13_EC2_DTSEC4_RGMII)
321 fm_info_set_phy_address(FM1_DTSEC4, RGMII_PHY2_ADDR);
323 fm_info_set_phy_address(FM1_DTSEC10, RGMII_PHY2_ADDR);
331 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
332 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
333 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
334 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
336 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
337 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
342 /* XAUI/HiGig in Slot3 */
343 fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
345 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
346 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT4_PHY_ADDR);
350 * XFI does not need a PHY to work, but to avoid U-boot use
351 * default PHY address which is zero to a MAC when it found
352 * a MAC has no PHY address, we give a PHY address to XFI
353 * MAC, and should not use a real XAUI PHY address, since
354 * MDIO can access it successfully, and then MDIO thinks
355 * the XAUI card is used for the XFI MAC, which will cause
358 fm_info_set_phy_address(FM1_10GEC1, 4);
359 fm_info_set_phy_address(FM1_10GEC2, 5);
360 fm_info_set_phy_address(FM1_10GEC3, 6);
361 fm_info_set_phy_address(FM1_10GEC4, 7);
364 fm_info_set_phy_address(FM1_10GEC1, 4);
365 fm_info_set_phy_address(FM1_10GEC2, 5);
366 fm_info_set_phy_address(FM1_10GEC3, 6);
367 fm_info_set_phy_address(FM1_10GEC4, 7);
369 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
370 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
375 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
376 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
380 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
381 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
383 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
384 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
392 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
393 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
394 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
395 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
397 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
398 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
404 fm_info_set_phy_address(FM1_DTSEC9, SGMII_CARD_PORT1_PHY_ADDR);
405 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
406 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
407 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
413 fm_info_set_phy_address(FM1_DTSEC10, SGMII_CARD_PORT2_PHY_ADDR);
414 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT3_PHY_ADDR);
415 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT4_PHY_ADDR);
417 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT3_PHY_ADDR);
418 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
421 puts("Invalid SerDes1 protocol for T2080QDS\n");
425 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
426 idx = i - FM1_DTSEC1;
427 interface = fm_info_get_enet_if(i);
429 case PHY_INTERFACE_MODE_SGMII:
430 lane = serdes_get_first_lane(FSL_SRDS_1,
431 SGMII_FM1_DTSEC1 + idx);
434 slot = lane_to_slot[lane];
435 debug("FM1@DTSEC%u expects SGMII in slot %u\n",
437 if (QIXIS_READ(present2) & (1 << (slot - 1)))
442 mdio_mux[i] = EMI1_SLOT1;
443 fm_info_set_mdio(i, mii_dev_for_muxval(
447 mdio_mux[i] = EMI1_SLOT2;
448 fm_info_set_mdio(i, mii_dev_for_muxval(
453 case PHY_INTERFACE_MODE_RGMII:
455 mdio_mux[i] = EMI1_RGMII1;
456 else if (i == FM1_DTSEC4 || FM1_DTSEC10)
457 mdio_mux[i] = EMI1_RGMII2;
458 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
465 for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
466 idx = i - FM1_10GEC1;
467 switch (fm_info_get_enet_if(i)) {
468 case PHY_INTERFACE_MODE_XGMII:
469 if (srds_s1 == 0x51) {
470 lane = serdes_get_first_lane(FSL_SRDS_1,
471 XAUI_FM1_MAC9 + idx);
472 } else if ((srds_s1 == 0x5f) || (srds_s1 == 0x65)) {
473 lane = serdes_get_first_lane(FSL_SRDS_1,
474 HIGIG_FM1_MAC9 + idx);
476 if (i == FM1_10GEC1 || i == FM1_10GEC2)
477 lane = serdes_get_first_lane(FSL_SRDS_1,
480 lane = serdes_get_first_lane(FSL_SRDS_1,
487 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
489 if ((srds_s1 == 0x66) || (srds_s1 == 0x6b) ||
490 (srds_s1 == 0x6c) || (srds_s1 == 0x6d) ||
492 /* As XFI is in cage intead of a slot, so
493 * ensure doesn't disable the corresponding port
498 slot = lane_to_slot[lane];
499 if (QIXIS_READ(present2) & (1 << (slot - 1)))
508 #endif /* CONFIG_FMAN_ENET */
510 return pci_eth_init(bis);