1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2013 Freescale Semiconductor, Inc.
7 * The RGMII PHYs are provided by the two on-board PHY connected to
8 * dTSEC instances 4 and 5. The SGMII PHYs are provided by one on-board
9 * PHY or by the standard four-port SGMII riser card (VSC).
13 #include <fdt_support.h>
16 #include <asm/fsl_serdes.h>
17 #include <asm/immap_85xx.h>
21 #include <fsl_dtsec.h>
24 #include "../common/fman.h"
25 #include "../common/qixis.h"
27 #include "t1040qds_qixis.h"
29 #ifdef CONFIG_FMAN_ENET
30 /* - In T1040 there are only 8 SERDES lanes, spread across 2 SERDES banks.
31 * Bank 1 -> Lanes A, B, C, D
32 * Bank 2 -> Lanes E, F, G, H
35 /* Mapping of 8 SERDES lanes to T1040 QDS board slots. A value of '0' here
36 * means that the mapping must be determined dynamically, or that the lane
37 * maps to something other than a board slot.
39 static u8 lane_to_slot[] = {
40 0, 0, 0, 0, 0, 0, 0, 0
43 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
46 static int riser_phy_addr[] = {
47 CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR,
48 CONFIG_SYS_FM1_DTSEC2_RISER_PHY_ADDR,
49 CONFIG_SYS_FM1_DTSEC3_RISER_PHY_ADDR,
50 CONFIG_SYS_FM1_DTSEC4_RISER_PHY_ADDR,
53 /* Slot2 does not have EMI connections */
54 #define EMI_NONE 0xFFFFFFFF
65 static int mdio_mux[NUM_FM_PORTS];
67 static const char * const mdio_names[] = {
78 struct t1040_qds_mdio {
80 struct mii_dev *realbus;
83 static const char *t1040_qds_mdio_name_for_muxval(u8 muxval)
85 return mdio_names[muxval];
88 struct mii_dev *mii_dev_for_muxval(u8 muxval)
91 const char *name = t1040_qds_mdio_name_for_muxval(muxval);
94 printf("No bus for muxval %x\n", muxval);
98 bus = miiphy_get_dev_by_name(name);
101 printf("No bus by name %s\n", name);
108 static void t1040_qds_mux_mdio(u8 muxval)
112 brdcfg4 = QIXIS_READ(brdcfg[4]);
113 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
114 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
115 QIXIS_WRITE(brdcfg[4], brdcfg4);
119 static int t1040_qds_mdio_read(struct mii_dev *bus, int addr, int devad,
122 struct t1040_qds_mdio *priv = bus->priv;
124 t1040_qds_mux_mdio(priv->muxval);
126 return priv->realbus->read(priv->realbus, addr, devad, regnum);
129 static int t1040_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
130 int regnum, u16 value)
132 struct t1040_qds_mdio *priv = bus->priv;
134 t1040_qds_mux_mdio(priv->muxval);
136 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
139 static int t1040_qds_mdio_reset(struct mii_dev *bus)
141 struct t1040_qds_mdio *priv = bus->priv;
143 return priv->realbus->reset(priv->realbus);
146 static int t1040_qds_mdio_init(char *realbusname, u8 muxval)
148 struct t1040_qds_mdio *pmdio;
149 struct mii_dev *bus = mdio_alloc();
152 printf("Failed to allocate t1040_qds MDIO bus\n");
156 pmdio = malloc(sizeof(*pmdio));
158 printf("Failed to allocate t1040_qds private data\n");
163 bus->read = t1040_qds_mdio_read;
164 bus->write = t1040_qds_mdio_write;
165 bus->reset = t1040_qds_mdio_reset;
166 strcpy(bus->name, t1040_qds_mdio_name_for_muxval(muxval));
168 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
170 if (!pmdio->realbus) {
171 printf("No bus with name %s\n", realbusname);
177 pmdio->muxval = muxval;
180 return mdio_register(bus);
184 * Initialize the lane_to_slot[] array.
186 * On the T1040QDS board the mapping is controlled by ?? register.
188 static void initialize_lane_to_slot(void)
190 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
191 int serdes1_prtcl = (in_be32(&gur->rcwsr[4]) &
192 FSL_CORENET2_RCWSR4_SRDS1_PRTCL)
193 >> FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
195 QIXIS_WRITE(cms[0], 0x07);
197 switch (serdes1_prtcl) {
261 printf("qds: Fman: Unsupported SerDes Protocol 0x%02x\n",
268 * Given the following ...
270 * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
271 * compatible string and 'addr' physical address)
275 * ... update the phy-handle property of the Ethernet node to point to the
276 * right PHY. This assumes that we already know the PHY for each port.
278 * The offset of the Fman Ethernet node is also passed in for convenience, but
279 * it is not used, and we recalculate the offset anyway.
281 * Note that what we call "Fman ports" (enum fm_port) is really an Fman MAC.
282 * Inside the Fman, "ports" are things that connect to MACs. We only call them
283 * ports in U-Boot because on previous Ethernet devices (e.g. Gianfar), MACs
284 * and ports are the same thing.
287 void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
288 enum fm_port port, int offset)
290 phy_interface_t intf = fm_info_get_enet_if(port);
293 /* The RGMII PHY is identified by the MAC connected to it */
294 if (intf == PHY_INTERFACE_MODE_RGMII) {
295 sprintf(phy, "rgmii_phy%u", port == FM1_DTSEC4 ? 1 : 2);
296 fdt_set_phy_handle(fdt, compat, addr, phy);
299 /* The SGMII PHY is identified by the MAC connected to it */
300 if (intf == PHY_INTERFACE_MODE_SGMII) {
301 int lane = serdes_get_first_lane(FSL_SRDS_1, SGMII_FM1_DTSEC1
306 slot = lane_to_slot[lane];
308 /* Slot housing a SGMII riser card */
309 sprintf(phy, "phy_s%x_%02x", slot,
310 (fm_info_get_phy_address(port - FM1_DTSEC1)-
311 CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR + 1));
312 fdt_set_phy_handle(fdt, compat, addr, phy);
317 void fdt_fixup_board_enet(void *fdt)
321 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
322 idx = i - FM1_DTSEC1;
323 switch (fm_info_get_enet_if(i)) {
324 case PHY_INTERFACE_MODE_SGMII:
325 lane = serdes_get_first_lane(FSL_SRDS_1,
326 SGMII_FM1_DTSEC1 + idx);
330 switch (mdio_mux[i]) {
332 fdt_status_okay_by_alias(fdt, "emi1_slot3");
335 fdt_status_okay_by_alias(fdt, "emi1_slot5");
338 fdt_status_okay_by_alias(fdt, "emi1_slot6");
341 fdt_status_okay_by_alias(fdt, "emi1_slot7");
345 case PHY_INTERFACE_MODE_RGMII:
347 fdt_status_okay_by_alias(fdt, "emi1_rgmii0");
350 fdt_status_okay_by_alias(fdt, "emi1_rgmii1");
357 #endif /* #ifdef CONFIG_FMAN_ENET */
359 static void set_brdcfg9_for_gtx_clk(void)
362 brdcfg9 = QIXIS_READ(brdcfg[9]);
363 /* Initializing EPHY2 clock to RGMII mode */
364 brdcfg9 &= ~(BRDCFG9_EPHY2_MASK);
365 brdcfg9 |= (BRDCFG9_EPHY2_VAL);
366 QIXIS_WRITE(brdcfg[9], brdcfg9);
369 void t1040_handle_phy_interface_sgmii(int i)
372 idx = i - FM1_DTSEC1;
373 lane = serdes_get_first_lane(FSL_SRDS_1,
374 SGMII_FM1_DTSEC1 + idx);
378 slot = lane_to_slot[lane];
382 mdio_mux[i] = EMI1_SLOT1;
383 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
387 fm_info_set_phy_address(i, riser_phy_addr[0]);
389 fm_info_set_phy_address(i, riser_phy_addr[1]);
391 mdio_mux[i] = EMI1_SLOT3;
393 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
396 mdio_mux[i] = EMI1_SLOT4;
397 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
400 /* Slot housing a SGMII riser card? */
401 fm_info_set_phy_address(i, riser_phy_addr[0]);
402 mdio_mux[i] = EMI1_SLOT5;
403 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
406 /* Slot housing a SGMII riser card? */
407 fm_info_set_phy_address(i, riser_phy_addr[0]);
408 mdio_mux[i] = EMI1_SLOT6;
409 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
413 fm_info_set_phy_address(i, riser_phy_addr[0]);
415 fm_info_set_phy_address(i, riser_phy_addr[1]);
417 fm_info_set_phy_address(i, riser_phy_addr[2]);
419 fm_info_set_phy_address(i, riser_phy_addr[3]);
421 mdio_mux[i] = EMI1_SLOT7;
422 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
427 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
429 void t1040_handle_phy_interface_rgmii(int i)
431 fm_info_set_phy_address(i, i == FM1_DTSEC5 ?
432 CONFIG_SYS_FM1_DTSEC5_PHY_ADDR :
433 CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
434 mdio_mux[i] = (i == FM1_DTSEC5) ? EMI1_RGMII1 :
436 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
439 int board_eth_init(bd_t *bis)
441 #ifdef CONFIG_FMAN_ENET
442 struct memac_mdio_info memac_mdio_info;
444 #ifdef CONFIG_VSC9953
447 phy_interface_t phy_int;
451 printf("Initializing Fman\n");
452 set_brdcfg9_for_gtx_clk();
454 initialize_lane_to_slot();
456 /* Initialize the mdio_mux array so we can recognize empty elements */
457 for (i = 0; i < NUM_FM_PORTS; i++)
458 mdio_mux[i] = EMI_NONE;
460 memac_mdio_info.regs =
461 (struct memac_mdio_controller *)CONFIG_SYS_FM1_DTSEC_MDIO_ADDR;
462 memac_mdio_info.name = DEFAULT_FM_MDIO_NAME;
464 /* Register the real 1G MDIO bus */
465 fm_memac_mdio_init(bis, &memac_mdio_info);
467 /* Register the muxing front-ends to the MDIO buses */
468 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII0);
469 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII1);
470 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
471 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
472 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
473 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
474 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT6);
475 t1040_qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT7);
478 * Program on board RGMII PHY addresses. If the SGMII Riser
479 * card used, we'll override the PHY address later. For any DTSEC that
480 * is RGMII, we'll also override its PHY address later. We assume that
481 * DTSEC4 and DTSEC5 are used for RGMII.
483 fm_info_set_phy_address(FM1_DTSEC4, CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
484 fm_info_set_phy_address(FM1_DTSEC5, CONFIG_SYS_FM1_DTSEC5_PHY_ADDR);
486 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
487 switch (fm_info_get_enet_if(i)) {
488 case PHY_INTERFACE_MODE_QSGMII:
489 fm_info_set_mdio(i, NULL);
491 case PHY_INTERFACE_MODE_SGMII:
492 t1040_handle_phy_interface_sgmii(i);
495 case PHY_INTERFACE_MODE_RGMII:
496 /* Only DTSEC4 and DTSEC5 can be routed to RGMII */
497 t1040_handle_phy_interface_rgmii(i);
504 #ifdef CONFIG_VSC9953
505 for (i = 0; i < VSC9953_MAX_PORTS; i++) {
508 phy_int = PHY_INTERFACE_MODE_NONE;
514 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_SW1_A);
515 /* PHYs connected over QSGMII */
517 phy_addr = CONFIG_SYS_FM1_QSGMII21_PHY_ADDR +
519 phy_int = PHY_INTERFACE_MODE_QSGMII;
522 lane = serdes_get_first_lane(FSL_SRDS_1,
528 /* PHYs connected over QSGMII */
529 if (i != 3 || lane_to_slot[lane] == 7)
530 phy_addr = CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR
533 phy_addr = CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR;
534 phy_int = PHY_INTERFACE_MODE_SGMII;
540 lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_SW1_B);
541 /* PHYs connected over QSGMII */
543 phy_addr = CONFIG_SYS_FM1_QSGMII11_PHY_ADDR +
545 phy_int = PHY_INTERFACE_MODE_QSGMII;
548 lane = serdes_get_first_lane(FSL_SRDS_1,
550 /* PHYs connected over SGMII */
552 phy_addr = CONFIG_SYS_FM1_DTSEC1_RISER_PHY_ADDR
554 phy_int = PHY_INTERFACE_MODE_SGMII;
558 if (serdes_get_first_lane(FSL_SRDS_1,
559 SGMII_FM1_DTSEC1) < 0)
560 /* FM1@DTSEC1 is connected to SW1@PORT8 */
561 vsc9953_port_enable(i);
564 if (serdes_get_first_lane(FSL_SRDS_1,
565 SGMII_FM1_DTSEC2) < 0) {
566 /* Enable L2 On MAC2 using SCFG */
567 struct ccsr_scfg *scfg = (struct ccsr_scfg *)
568 CONFIG_SYS_MPC85xx_SCFG;
570 out_be32(&scfg->esgmiiselcr,
571 in_be32(&scfg->esgmiiselcr) |
573 vsc9953_port_enable(i);
579 bus = mii_dev_for_muxval(lane_to_slot[lane]);
580 vsc9953_port_info_set_mdio(i, bus);
581 vsc9953_port_enable(i);
583 vsc9953_port_info_set_phy_address(i, phy_addr);
584 vsc9953_port_info_set_phy_int(i, phy_int);
591 return pci_eth_init(bis);