xref: /openbmc/u-boot/board/freescale/t4qds/eth.c (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2ee52b188SYork Sun /*
3ee52b188SYork Sun  * Copyright 2012 Freescale Semiconductor, Inc.
4ee52b188SYork Sun  */
5ee52b188SYork Sun 
6ee52b188SYork Sun #include <common.h>
7ee52b188SYork Sun #include <command.h>
8ee52b188SYork Sun #include <netdev.h>
9ee52b188SYork Sun #include <asm/mmu.h>
10ee52b188SYork Sun #include <asm/processor.h>
11ee52b188SYork Sun #include <asm/cache.h>
12ee52b188SYork Sun #include <asm/immap_85xx.h>
13ee52b188SYork Sun #include <asm/fsl_law.h>
145614e71bSYork Sun #include <fsl_ddr_sdram.h>
15ee52b188SYork Sun #include <asm/fsl_serdes.h>
16ee52b188SYork Sun #include <asm/fsl_portals.h>
17ee52b188SYork Sun #include <asm/fsl_liodn.h>
18ee52b188SYork Sun #include <malloc.h>
19ee52b188SYork Sun #include <fm_eth.h>
20ee52b188SYork Sun #include <fsl_mdio.h>
21ee52b188SYork Sun #include <miiphy.h>
22ee52b188SYork Sun #include <phy.h>
238225b2fdSShaohui Xie #include <fsl_dtsec.h>
24ee52b188SYork Sun #include <asm/fsl_serdes.h>
259bf499acSShaohui Xie #include <hwconfig.h>
26ee52b188SYork Sun #include "../common/qixis.h"
27ee52b188SYork Sun #include "../common/fman.h"
28ee52b188SYork Sun 
29ee52b188SYork Sun #include "t4240qds_qixis.h"
30ee52b188SYork Sun 
31ee52b188SYork Sun #define EMI_NONE	0xFFFFFFFF
32ee52b188SYork Sun #define EMI1_RGMII	0
33ee52b188SYork Sun #define EMI1_SLOT1	1
34ee52b188SYork Sun #define EMI1_SLOT2	2
35ee52b188SYork Sun #define EMI1_SLOT3	3
36ee52b188SYork Sun #define EMI1_SLOT4	4
37ee52b188SYork Sun #define EMI1_SLOT5	5
38ee52b188SYork Sun #define EMI1_SLOT7	7
3995927808SShengzhou Liu #define EMI2		8
40ee52b188SYork Sun /* Slot6 and Slot8 do not have EMI connections */
41ee52b188SYork Sun 
42ee52b188SYork Sun static int mdio_mux[NUM_FM_PORTS];
43ee52b188SYork Sun 
44ee52b188SYork Sun static const char *mdio_names[] = {
45ee52b188SYork Sun 	"T4240QDS_MDIO0",
46ee52b188SYork Sun 	"T4240QDS_MDIO1",
47ee52b188SYork Sun 	"T4240QDS_MDIO2",
48ee52b188SYork Sun 	"T4240QDS_MDIO3",
49ee52b188SYork Sun 	"T4240QDS_MDIO4",
50ee52b188SYork Sun 	"T4240QDS_MDIO5",
51ee52b188SYork Sun 	"NULL",
52ee52b188SYork Sun 	"T4240QDS_MDIO7",
53ee52b188SYork Sun 	"T4240QDS_10GC",
54ee52b188SYork Sun };
55ee52b188SYork Sun 
56ee52b188SYork Sun static u8 lane_to_slot_fsm1[] = {1, 1, 1, 1, 2, 2, 2, 2};
57ee52b188SYork Sun static u8 lane_to_slot_fsm2[] = {3, 3, 3, 3, 4, 4, 4, 4};
5804bccc3aSShaohui Xie static u8 slot_qsgmii_phyaddr[5][4] = {
5904bccc3aSShaohui Xie 	{0, 0, 0, 0},/* not used, to make index match slot No. */
6004bccc3aSShaohui Xie 	{0, 1, 2, 3},
6104bccc3aSShaohui Xie 	{4, 5, 6, 7},
6204bccc3aSShaohui Xie 	{8, 9, 0xa, 0xb},
6304bccc3aSShaohui Xie 	{0xc, 0xd, 0xe, 0xf},
6404bccc3aSShaohui Xie };
65f63d638dSShaohui Xie static u8 qsgmiiphy_fix[NUM_FM_PORTS] = {0};
66ee52b188SYork Sun 
t4240qds_mdio_name_for_muxval(u8 muxval)67ee52b188SYork Sun static const char *t4240qds_mdio_name_for_muxval(u8 muxval)
68ee52b188SYork Sun {
69ee52b188SYork Sun 	return mdio_names[muxval];
70ee52b188SYork Sun }
71ee52b188SYork Sun 
mii_dev_for_muxval(u8 muxval)72ee52b188SYork Sun struct mii_dev *mii_dev_for_muxval(u8 muxval)
73ee52b188SYork Sun {
74ee52b188SYork Sun 	struct mii_dev *bus;
75ee52b188SYork Sun 	const char *name = t4240qds_mdio_name_for_muxval(muxval);
76ee52b188SYork Sun 
77ee52b188SYork Sun 	if (!name) {
78ee52b188SYork Sun 		printf("No bus for muxval %x\n", muxval);
79ee52b188SYork Sun 		return NULL;
80ee52b188SYork Sun 	}
81ee52b188SYork Sun 
82ee52b188SYork Sun 	bus = miiphy_get_dev_by_name(name);
83ee52b188SYork Sun 
84ee52b188SYork Sun 	if (!bus) {
85ee52b188SYork Sun 		printf("No bus by name %s\n", name);
86ee52b188SYork Sun 		return NULL;
87ee52b188SYork Sun 	}
88ee52b188SYork Sun 
89ee52b188SYork Sun 	return bus;
90ee52b188SYork Sun }
91ee52b188SYork Sun 
92ee52b188SYork Sun struct t4240qds_mdio {
93ee52b188SYork Sun 	u8 muxval;
94ee52b188SYork Sun 	struct mii_dev *realbus;
95ee52b188SYork Sun };
96ee52b188SYork Sun 
t4240qds_mux_mdio(u8 muxval)97ee52b188SYork Sun static void t4240qds_mux_mdio(u8 muxval)
98ee52b188SYork Sun {
99ee52b188SYork Sun 	u8 brdcfg4;
100ee52b188SYork Sun 	if ((muxval < 6) || (muxval == 7)) {
101ee52b188SYork Sun 		brdcfg4 = QIXIS_READ(brdcfg[4]);
102ee52b188SYork Sun 		brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
103ee52b188SYork Sun 		brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
104ee52b188SYork Sun 		QIXIS_WRITE(brdcfg[4], brdcfg4);
105ee52b188SYork Sun 	}
106ee52b188SYork Sun }
107ee52b188SYork Sun 
t4240qds_mdio_read(struct mii_dev * bus,int addr,int devad,int regnum)108ee52b188SYork Sun static int t4240qds_mdio_read(struct mii_dev *bus, int addr, int devad,
109ee52b188SYork Sun 				int regnum)
110ee52b188SYork Sun {
111ee52b188SYork Sun 	struct t4240qds_mdio *priv = bus->priv;
112ee52b188SYork Sun 
113ee52b188SYork Sun 	t4240qds_mux_mdio(priv->muxval);
114ee52b188SYork Sun 
115ee52b188SYork Sun 	return priv->realbus->read(priv->realbus, addr, devad, regnum);
116ee52b188SYork Sun }
117ee52b188SYork Sun 
t4240qds_mdio_write(struct mii_dev * bus,int addr,int devad,int regnum,u16 value)118ee52b188SYork Sun static int t4240qds_mdio_write(struct mii_dev *bus, int addr, int devad,
119ee52b188SYork Sun 				int regnum, u16 value)
120ee52b188SYork Sun {
121ee52b188SYork Sun 	struct t4240qds_mdio *priv = bus->priv;
122ee52b188SYork Sun 
123ee52b188SYork Sun 	t4240qds_mux_mdio(priv->muxval);
124ee52b188SYork Sun 
125ee52b188SYork Sun 	return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
126ee52b188SYork Sun }
127ee52b188SYork Sun 
t4240qds_mdio_reset(struct mii_dev * bus)128ee52b188SYork Sun static int t4240qds_mdio_reset(struct mii_dev *bus)
129ee52b188SYork Sun {
130ee52b188SYork Sun 	struct t4240qds_mdio *priv = bus->priv;
131ee52b188SYork Sun 
132ee52b188SYork Sun 	return priv->realbus->reset(priv->realbus);
133ee52b188SYork Sun }
134ee52b188SYork Sun 
t4240qds_mdio_init(char * realbusname,u8 muxval)135ee52b188SYork Sun static int t4240qds_mdio_init(char *realbusname, u8 muxval)
136ee52b188SYork Sun {
137ee52b188SYork Sun 	struct t4240qds_mdio *pmdio;
138ee52b188SYork Sun 	struct mii_dev *bus = mdio_alloc();
139ee52b188SYork Sun 
140ee52b188SYork Sun 	if (!bus) {
141ee52b188SYork Sun 		printf("Failed to allocate T4240QDS MDIO bus\n");
142ee52b188SYork Sun 		return -1;
143ee52b188SYork Sun 	}
144ee52b188SYork Sun 
145ee52b188SYork Sun 	pmdio = malloc(sizeof(*pmdio));
146ee52b188SYork Sun 	if (!pmdio) {
147ee52b188SYork Sun 		printf("Failed to allocate T4240QDS private data\n");
148ee52b188SYork Sun 		free(bus);
149ee52b188SYork Sun 		return -1;
150ee52b188SYork Sun 	}
151ee52b188SYork Sun 
152ee52b188SYork Sun 	bus->read = t4240qds_mdio_read;
153ee52b188SYork Sun 	bus->write = t4240qds_mdio_write;
154ee52b188SYork Sun 	bus->reset = t4240qds_mdio_reset;
155192bc694SBen Whitten 	strcpy(bus->name, t4240qds_mdio_name_for_muxval(muxval));
156ee52b188SYork Sun 
157ee52b188SYork Sun 	pmdio->realbus = miiphy_get_dev_by_name(realbusname);
158ee52b188SYork Sun 
159ee52b188SYork Sun 	if (!pmdio->realbus) {
160ee52b188SYork Sun 		printf("No bus with name %s\n", realbusname);
161ee52b188SYork Sun 		free(bus);
162ee52b188SYork Sun 		free(pmdio);
163ee52b188SYork Sun 		return -1;
164ee52b188SYork Sun 	}
165ee52b188SYork Sun 
166ee52b188SYork Sun 	pmdio->muxval = muxval;
167ee52b188SYork Sun 	bus->priv = pmdio;
168ee52b188SYork Sun 
169ee52b188SYork Sun 	return mdio_register(bus);
170ee52b188SYork Sun }
171ee52b188SYork Sun 
board_ft_fman_fixup_port(void * blob,char * prop,phys_addr_t pa,enum fm_port port,int offset)172ee52b188SYork Sun void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
173ee52b188SYork Sun 				enum fm_port port, int offset)
174ee52b188SYork Sun {
1751c68d01eSShaohui Xie 	int interface = fm_info_get_enet_if(port);
1769bf499acSShaohui Xie 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
1779bf499acSShaohui Xie 	u32 prtcl2 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
1789bf499acSShaohui Xie 
1799bf499acSShaohui Xie 	prtcl2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
1801c68d01eSShaohui Xie 
1811c68d01eSShaohui Xie 	if (interface == PHY_INTERFACE_MODE_SGMII ||
1821c68d01eSShaohui Xie 	    interface == PHY_INTERFACE_MODE_QSGMII) {
18395927808SShengzhou Liu 		switch (port) {
184f63d638dSShaohui Xie 		case FM1_DTSEC1:
185f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
186f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
187f63d638dSShaohui Xie 						   "sgmii_phy21");
188f63d638dSShaohui Xie 			break;
189f63d638dSShaohui Xie 		case FM1_DTSEC2:
190f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
191f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
192f63d638dSShaohui Xie 						   "sgmii_phy22");
193f63d638dSShaohui Xie 			break;
194f63d638dSShaohui Xie 		case FM1_DTSEC3:
195f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
196f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
197f63d638dSShaohui Xie 						   "sgmii_phy23");
198f63d638dSShaohui Xie 			break;
199f63d638dSShaohui Xie 		case FM1_DTSEC4:
200f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
201f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
202f63d638dSShaohui Xie 						   "sgmii_phy24");
203f63d638dSShaohui Xie 			break;
204f63d638dSShaohui Xie 		case FM1_DTSEC6:
205f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
206f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
207f63d638dSShaohui Xie 						   "sgmii_phy12");
208f63d638dSShaohui Xie 			break;
20995927808SShengzhou Liu 		case FM1_DTSEC9:
210f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
211f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
212f63d638dSShaohui Xie 						   "sgmii_phy14");
213f63d638dSShaohui Xie 			else
214f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
215f63d638dSShaohui Xie 						   "phy_sgmii4");
21695927808SShengzhou Liu 			break;
21795927808SShengzhou Liu 		case FM1_DTSEC10:
218f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
219f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
220f63d638dSShaohui Xie 						   "sgmii_phy13");
221f63d638dSShaohui Xie 			else
222f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
223f63d638dSShaohui Xie 						   "phy_sgmii3");
224f63d638dSShaohui Xie 			break;
225f63d638dSShaohui Xie 		case FM2_DTSEC1:
226f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
227f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
228f63d638dSShaohui Xie 						   "sgmii_phy41");
229f63d638dSShaohui Xie 			break;
230f63d638dSShaohui Xie 		case FM2_DTSEC2:
231f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
232f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
233f63d638dSShaohui Xie 						   "sgmii_phy42");
234f63d638dSShaohui Xie 			break;
235f63d638dSShaohui Xie 		case FM2_DTSEC3:
236f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
237f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
238f63d638dSShaohui Xie 						   "sgmii_phy43");
239f63d638dSShaohui Xie 			break;
240f63d638dSShaohui Xie 		case FM2_DTSEC4:
241f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
242f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
243f63d638dSShaohui Xie 						   "sgmii_phy44");
244f63d638dSShaohui Xie 			break;
245f63d638dSShaohui Xie 		case FM2_DTSEC6:
246f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
247f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
248f63d638dSShaohui Xie 						   "sgmii_phy32");
24995927808SShengzhou Liu 			break;
25095927808SShengzhou Liu 		case FM2_DTSEC9:
251f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
252f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
253f63d638dSShaohui Xie 						   "sgmii_phy34");
254f63d638dSShaohui Xie 			else
255f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
256f63d638dSShaohui Xie 						   "phy_sgmii12");
25795927808SShengzhou Liu 			break;
25895927808SShengzhou Liu 		case FM2_DTSEC10:
259f63d638dSShaohui Xie 			if (qsgmiiphy_fix[port])
260f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
261f63d638dSShaohui Xie 						   "sgmii_phy33");
262f63d638dSShaohui Xie 			else
263f63d638dSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
264f63d638dSShaohui Xie 						   "phy_sgmii11");
26595927808SShengzhou Liu 			break;
26695927808SShengzhou Liu 		default:
26795927808SShengzhou Liu 			break;
26895927808SShengzhou Liu 		}
2699bf499acSShaohui Xie 	} else if (interface == PHY_INTERFACE_MODE_XGMII &&
2709bf499acSShaohui Xie 		  ((prtcl2 == 55) || (prtcl2 == 57))) {
2719bf499acSShaohui Xie 		/*
2729bf499acSShaohui Xie 		 * if the 10G is XFI, check hwconfig to see what is the
2739bf499acSShaohui Xie 		 * media type, there are two types, fiber or copper,
2749bf499acSShaohui Xie 		 * fix the dtb accordingly.
2759bf499acSShaohui Xie 		 */
2769bf499acSShaohui Xie 		int media_type = 0;
2779bf499acSShaohui Xie 		struct fixed_link f_link;
2789bf499acSShaohui Xie 		char lane_mode[20] = {"10GBASE-KR"};
2799bf499acSShaohui Xie 		char buf[32] = "serdes-2,";
2809bf499acSShaohui Xie 		int off;
2819bf499acSShaohui Xie 
2829bf499acSShaohui Xie 		switch (port) {
2839bf499acSShaohui Xie 		case FM1_10GEC1:
2849bf499acSShaohui Xie 			if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g1")) {
2859bf499acSShaohui Xie 				media_type = 1;
2869bf499acSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
2879bf499acSShaohui Xie 						   "phy_xfi1");
2889bf499acSShaohui Xie 				sprintf(buf, "%s%s%s", buf, "lane-a,",
2899bf499acSShaohui Xie 					(char *)lane_mode);
2909bf499acSShaohui Xie 			}
2919bf499acSShaohui Xie 			break;
2929bf499acSShaohui Xie 		case FM1_10GEC2:
2939bf499acSShaohui Xie 			if (hwconfig_sub("fsl_10gkr_copper", "fm1_10g2")) {
2949bf499acSShaohui Xie 				media_type = 1;
2959bf499acSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
2969bf499acSShaohui Xie 						   "phy_xfi2");
2979bf499acSShaohui Xie 				sprintf(buf, "%s%s%s", buf, "lane-b,",
2989bf499acSShaohui Xie 					(char *)lane_mode);
2999bf499acSShaohui Xie 			}
3009bf499acSShaohui Xie 			break;
3019bf499acSShaohui Xie 		case FM2_10GEC1:
3029bf499acSShaohui Xie 			if (hwconfig_sub("fsl_10gkr_copper", "fm2_10g1")) {
3039bf499acSShaohui Xie 				media_type = 1;
3049bf499acSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
3059bf499acSShaohui Xie 						   "phy_xfi3");
3069bf499acSShaohui Xie 				sprintf(buf, "%s%s%s", buf, "lane-d,",
3079bf499acSShaohui Xie 					(char *)lane_mode);
3089bf499acSShaohui Xie 			}
3099bf499acSShaohui Xie 			break;
3109bf499acSShaohui Xie 		case FM2_10GEC2:
3119bf499acSShaohui Xie 			if (hwconfig_sub("fsl_10gkr_copper", "fm2_10g2")) {
3129bf499acSShaohui Xie 				media_type = 1;
3139bf499acSShaohui Xie 				fdt_set_phy_handle(blob, prop, pa,
3149bf499acSShaohui Xie 						   "phy_xfi4");
3159bf499acSShaohui Xie 				sprintf(buf, "%s%s%s", buf, "lane-c,",
3169bf499acSShaohui Xie 					(char *)lane_mode);
3179bf499acSShaohui Xie 			}
3189bf499acSShaohui Xie 			break;
3199bf499acSShaohui Xie 		default:
3209bf499acSShaohui Xie 			return;
3219bf499acSShaohui Xie 		}
3229bf499acSShaohui Xie 
3239bf499acSShaohui Xie 		if (!media_type) {
3249bf499acSShaohui Xie 			/* fixed-link is used for XFI fiber cable */
3259bf499acSShaohui Xie 			fdt_delprop(blob, offset, "phy-handle");
3269bf499acSShaohui Xie 			f_link.phy_id = port;
3279bf499acSShaohui Xie 			f_link.duplex = 1;
3289bf499acSShaohui Xie 			f_link.link_speed = 10000;
3299bf499acSShaohui Xie 			f_link.pause = 0;
3309bf499acSShaohui Xie 			f_link.asym_pause = 0;
3319bf499acSShaohui Xie 			fdt_setprop(blob, offset, "fixed-link", &f_link,
3329bf499acSShaohui Xie 				    sizeof(f_link));
3339bf499acSShaohui Xie 		} else {
3349bf499acSShaohui Xie 			/* set property for copper cable */
3359bf499acSShaohui Xie 			off = fdt_node_offset_by_compat_reg(blob,
3369bf499acSShaohui Xie 					"fsl,fman-memac-mdio", pa + 0x1000);
3379bf499acSShaohui Xie 			fdt_setprop_string(blob, off, "lane-instance", buf);
3389bf499acSShaohui Xie 		}
33995927808SShengzhou Liu 	}
340ee52b188SYork Sun }
341ee52b188SYork Sun 
fdt_fixup_board_enet(void * fdt)342ee52b188SYork Sun void fdt_fixup_board_enet(void *fdt)
343ee52b188SYork Sun {
34495927808SShengzhou Liu 	int i;
34595927808SShengzhou Liu 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
34695927808SShengzhou Liu 	u32 prtcl2 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
34795927808SShengzhou Liu 
34895927808SShengzhou Liu 	prtcl2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
34995927808SShengzhou Liu 	for (i = FM1_DTSEC1; i < NUM_FM_PORTS; i++) {
35095927808SShengzhou Liu 		switch (fm_info_get_enet_if(i)) {
35195927808SShengzhou Liu 		case PHY_INTERFACE_MODE_SGMII:
3521c68d01eSShaohui Xie 		case PHY_INTERFACE_MODE_QSGMII:
35395927808SShengzhou Liu 			switch (mdio_mux[i]) {
35495927808SShengzhou Liu 			case EMI1_SLOT1:
35595927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi1_slot1");
35695927808SShengzhou Liu 				break;
35795927808SShengzhou Liu 			case EMI1_SLOT2:
35895927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi1_slot2");
35995927808SShengzhou Liu 				break;
36095927808SShengzhou Liu 			case EMI1_SLOT3:
36195927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi1_slot3");
36295927808SShengzhou Liu 				break;
36395927808SShengzhou Liu 			case EMI1_SLOT4:
36495927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi1_slot4");
36595927808SShengzhou Liu 				break;
36695927808SShengzhou Liu 			default:
36795927808SShengzhou Liu 				break;
36895927808SShengzhou Liu 			}
36995927808SShengzhou Liu 			break;
37095927808SShengzhou Liu 		case PHY_INTERFACE_MODE_XGMII:
37195927808SShengzhou Liu 			/* check if it's XFI interface for 10g */
3729bf499acSShaohui Xie 			if ((prtcl2 == 55) || (prtcl2 == 57)) {
3739bf499acSShaohui Xie 				if (i == FM1_10GEC1 && hwconfig_sub(
3749bf499acSShaohui Xie 					"fsl_10gkr_copper", "fm1_10g1"))
3759bf499acSShaohui Xie 					fdt_status_okay_by_alias(
3769bf499acSShaohui Xie 					fdt, "xfi_pcs_mdio1");
3779bf499acSShaohui Xie 				if (i == FM1_10GEC2 && hwconfig_sub(
3789bf499acSShaohui Xie 					"fsl_10gkr_copper", "fm1_10g2"))
3799bf499acSShaohui Xie 					fdt_status_okay_by_alias(
3809bf499acSShaohui Xie 					fdt, "xfi_pcs_mdio2");
3819bf499acSShaohui Xie 				if (i == FM2_10GEC1 && hwconfig_sub(
3829bf499acSShaohui Xie 					"fsl_10gkr_copper", "fm2_10g1"))
3839bf499acSShaohui Xie 					fdt_status_okay_by_alias(
3849bf499acSShaohui Xie 					fdt, "xfi_pcs_mdio3");
3859bf499acSShaohui Xie 				if (i == FM2_10GEC2 && hwconfig_sub(
3869bf499acSShaohui Xie 					"fsl_10gkr_copper", "fm2_10g2"))
3879bf499acSShaohui Xie 					fdt_status_okay_by_alias(
3889bf499acSShaohui Xie 					fdt, "xfi_pcs_mdio4");
38995927808SShengzhou Liu 				break;
39095927808SShengzhou Liu 			}
39195927808SShengzhou Liu 			switch (i) {
39295927808SShengzhou Liu 			case FM1_10GEC1:
39395927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi2_xauislot1");
39495927808SShengzhou Liu 				break;
39595927808SShengzhou Liu 			case FM1_10GEC2:
39695927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi2_xauislot2");
39795927808SShengzhou Liu 				break;
39895927808SShengzhou Liu 			case FM2_10GEC1:
39995927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi2_xauislot3");
40095927808SShengzhou Liu 				break;
40195927808SShengzhou Liu 			case FM2_10GEC2:
40295927808SShengzhou Liu 				fdt_status_okay_by_alias(fdt, "emi2_xauislot4");
40395927808SShengzhou Liu 				break;
40495927808SShengzhou Liu 			default:
40595927808SShengzhou Liu 				break;
40695927808SShengzhou Liu 			}
40795927808SShengzhou Liu 			break;
40895927808SShengzhou Liu 		default:
40995927808SShengzhou Liu 			break;
41095927808SShengzhou Liu 		}
41195927808SShengzhou Liu 	}
412ee52b188SYork Sun }
413ee52b188SYork Sun 
initialize_qsgmiiphy_fix(void)414f63d638dSShaohui Xie static void initialize_qsgmiiphy_fix(void)
415f63d638dSShaohui Xie {
416f63d638dSShaohui Xie 	int i;
417f63d638dSShaohui Xie 	unsigned short reg;
418f63d638dSShaohui Xie 
419f63d638dSShaohui Xie 	for (i = 1; i <= 4; i++) {
420f63d638dSShaohui Xie 		/*
421f63d638dSShaohui Xie 		 * Try to read if a SGMII card is used, we do it slot by slot.
422f63d638dSShaohui Xie 		 * if a SGMII PHY address is valid on a slot, then we mark
423f63d638dSShaohui Xie 		 * all ports on the slot, then fix the PHY address for the
424f63d638dSShaohui Xie 		 * marked port when doing dtb fixup.
425f63d638dSShaohui Xie 		 */
426f63d638dSShaohui Xie 		if (miiphy_read(mdio_names[i],
427f63d638dSShaohui Xie 				SGMII_CARD_PORT1_PHY_ADDR, MII_PHYSID2, &reg) != 0) {
428f63d638dSShaohui Xie 			debug("Slot%d PHY ID register 2 read failed\n", i);
429f63d638dSShaohui Xie 			continue;
430f63d638dSShaohui Xie 		}
431f63d638dSShaohui Xie 
432f63d638dSShaohui Xie 		debug("Slot%d MII_PHYSID2 @ 0x1c= 0x%04x\n", i, reg);
433f63d638dSShaohui Xie 
434f63d638dSShaohui Xie 		if (reg == 0xFFFF) {
435f63d638dSShaohui Xie 			/* No physical device present at this address */
436f63d638dSShaohui Xie 			continue;
437f63d638dSShaohui Xie 		}
438f63d638dSShaohui Xie 
439f63d638dSShaohui Xie 		switch (i) {
440f63d638dSShaohui Xie 		case 1:
441f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC5] = 1;
442f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC6] = 1;
443f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC9] = 1;
444f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC10] = 1;
445037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[1][0] =  SGMII_CARD_PORT1_PHY_ADDR;
446037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[1][1] =  SGMII_CARD_PORT2_PHY_ADDR;
447037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[1][2] =  SGMII_CARD_PORT3_PHY_ADDR;
448037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[1][3] =  SGMII_CARD_PORT4_PHY_ADDR;
449f63d638dSShaohui Xie 			break;
450f63d638dSShaohui Xie 		case 2:
451f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC1] = 1;
452f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC2] = 1;
453f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC3] = 1;
454f63d638dSShaohui Xie 			qsgmiiphy_fix[FM1_DTSEC4] = 1;
455037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[2][0] =  SGMII_CARD_PORT1_PHY_ADDR;
456037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[2][1] =  SGMII_CARD_PORT2_PHY_ADDR;
457037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[2][2] =  SGMII_CARD_PORT3_PHY_ADDR;
458037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[2][3] =  SGMII_CARD_PORT4_PHY_ADDR;
459f63d638dSShaohui Xie 			break;
460f63d638dSShaohui Xie 		case 3:
461f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC5] = 1;
462f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC6] = 1;
463f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC9] = 1;
464f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC10] = 1;
465037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[3][0] =  SGMII_CARD_PORT1_PHY_ADDR;
466037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[3][1] =  SGMII_CARD_PORT2_PHY_ADDR;
467037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[3][2] =  SGMII_CARD_PORT3_PHY_ADDR;
468037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[3][3] =  SGMII_CARD_PORT4_PHY_ADDR;
469f63d638dSShaohui Xie 			break;
470f63d638dSShaohui Xie 		case 4:
471f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC1] = 1;
472f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC2] = 1;
473f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC3] = 1;
474f63d638dSShaohui Xie 			qsgmiiphy_fix[FM2_DTSEC4] = 1;
475037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[4][0] =  SGMII_CARD_PORT1_PHY_ADDR;
476037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[4][1] =  SGMII_CARD_PORT2_PHY_ADDR;
477037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[4][2] =  SGMII_CARD_PORT3_PHY_ADDR;
478037e19b8SShengzhou Liu 			slot_qsgmii_phyaddr[4][3] =  SGMII_CARD_PORT4_PHY_ADDR;
479f63d638dSShaohui Xie 			break;
480f63d638dSShaohui Xie 		default:
481f63d638dSShaohui Xie 			break;
482f63d638dSShaohui Xie 		}
483f63d638dSShaohui Xie 	}
484f63d638dSShaohui Xie }
485f63d638dSShaohui Xie 
board_eth_init(bd_t * bis)486ee52b188SYork Sun int board_eth_init(bd_t *bis)
487ee52b188SYork Sun {
488ee52b188SYork Sun #if defined(CONFIG_FMAN_ENET)
4891c68d01eSShaohui Xie 	int i, idx, lane, slot, interface;
490ee52b188SYork Sun 	struct memac_mdio_info dtsec_mdio_info;
491ee52b188SYork Sun 	struct memac_mdio_info tgec_mdio_info;
492ee52b188SYork Sun 	ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
493ee52b188SYork Sun 	u32 srds_prtcl_s1, srds_prtcl_s2;
494ee52b188SYork Sun 
495ee52b188SYork Sun 	srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
496ee52b188SYork Sun 					FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
497ee52b188SYork Sun 	srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
498ee52b188SYork Sun 	srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
499ee52b188SYork Sun 					FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
500ee52b188SYork Sun 	srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
501ee52b188SYork Sun 
502ee52b188SYork Sun 	/* Initialize the mdio_mux array so we can recognize empty elements */
503ee52b188SYork Sun 	for (i = 0; i < NUM_FM_PORTS; i++)
504ee52b188SYork Sun 		mdio_mux[i] = EMI_NONE;
505ee52b188SYork Sun 
506ee52b188SYork Sun 	dtsec_mdio_info.regs =
507ee52b188SYork Sun 		(struct memac_mdio_controller *)CONFIG_SYS_FM2_DTSEC_MDIO_ADDR;
508ee52b188SYork Sun 
509ee52b188SYork Sun 	dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
510ee52b188SYork Sun 
511ee52b188SYork Sun 	/* Register the 1G MDIO bus */
512ee52b188SYork Sun 	fm_memac_mdio_init(bis, &dtsec_mdio_info);
513ee52b188SYork Sun 
514ee52b188SYork Sun 	tgec_mdio_info.regs =
515ee52b188SYork Sun 		(struct memac_mdio_controller *)CONFIG_SYS_FM2_TGEC_MDIO_ADDR;
516ee52b188SYork Sun 	tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
517ee52b188SYork Sun 
518ee52b188SYork Sun 	/* Register the 10G MDIO bus */
519ee52b188SYork Sun 	fm_memac_mdio_init(bis, &tgec_mdio_info);
520ee52b188SYork Sun 
521ee52b188SYork Sun 	/* Register the muxing front-ends to the MDIO buses */
522ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
523ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
524ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
525ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
526ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
527ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
528ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT7);
529ee52b188SYork Sun 	t4240qds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2);
530ee52b188SYork Sun 
531037e19b8SShengzhou Liu 	initialize_qsgmiiphy_fix();
532ee52b188SYork Sun 
533ee52b188SYork Sun 	switch (srds_prtcl_s1) {
534ee52b188SYork Sun 	case 1:
535ee52b188SYork Sun 	case 2:
536ee52b188SYork Sun 	case 4:
537ee52b188SYork Sun 		/* XAUI/HiGig in Slot1 and Slot2 */
538ee52b188SYork Sun 		fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
539ee52b188SYork Sun 		fm_info_set_phy_address(FM1_10GEC2, FM1_10GEC2_PHY_ADDR);
540ee52b188SYork Sun 		break;
54194752f60SShaohui Xie 	case 27:
542ee52b188SYork Sun 	case 28:
54394752f60SShaohui Xie 	case 35:
544ee52b188SYork Sun 	case 36:
545ee52b188SYork Sun 		/* SGMII in Slot1 and Slot2 */
54604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC1, slot_qsgmii_phyaddr[2][0]);
54704bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC2, slot_qsgmii_phyaddr[2][1]);
54804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC3, slot_qsgmii_phyaddr[2][2]);
54904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC4, slot_qsgmii_phyaddr[2][3]);
55004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC5, slot_qsgmii_phyaddr[1][0]);
55104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC6, slot_qsgmii_phyaddr[1][1]);
5529bf499acSShaohui Xie 		if ((srds_prtcl_s2 != 55) && (srds_prtcl_s2 != 57)) {
553ee52b188SYork Sun 			fm_info_set_phy_address(FM1_DTSEC9,
55404bccc3aSShaohui Xie 						slot_qsgmii_phyaddr[1][3]);
555ee52b188SYork Sun 			fm_info_set_phy_address(FM1_DTSEC10,
55604bccc3aSShaohui Xie 						slot_qsgmii_phyaddr[1][2]);
557ee52b188SYork Sun 		}
558ee52b188SYork Sun 		break;
55994752f60SShaohui Xie 	case 37:
560ee52b188SYork Sun 	case 38:
56104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC1, slot_qsgmii_phyaddr[2][0]);
56204bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC2, slot_qsgmii_phyaddr[2][1]);
56304bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC3, slot_qsgmii_phyaddr[2][2]);
56404bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC4, slot_qsgmii_phyaddr[2][3]);
56504bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC5, slot_qsgmii_phyaddr[1][0]);
56604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC6, slot_qsgmii_phyaddr[1][1]);
5679bf499acSShaohui Xie 		if ((srds_prtcl_s2 != 55) && (srds_prtcl_s2 != 57)) {
568ee52b188SYork Sun 			fm_info_set_phy_address(FM1_DTSEC9,
56904bccc3aSShaohui Xie 						slot_qsgmii_phyaddr[1][2]);
5701c68d01eSShaohui Xie 			fm_info_set_phy_address(FM1_DTSEC10,
5711c68d01eSShaohui Xie 						slot_qsgmii_phyaddr[1][3]);
572ee52b188SYork Sun 		}
573ee52b188SYork Sun 		break;
57494752f60SShaohui Xie 	case 39:
575ee52b188SYork Sun 	case 40:
57694752f60SShaohui Xie 	case 45:
577ee52b188SYork Sun 	case 46:
57894752f60SShaohui Xie 	case 47:
579ee52b188SYork Sun 	case 48:
58004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC5, slot_qsgmii_phyaddr[1][0]);
58104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC6, slot_qsgmii_phyaddr[1][1]);
5829bf499acSShaohui Xie 		if ((srds_prtcl_s2 != 55) && (srds_prtcl_s2 != 57)) {
583ee52b188SYork Sun 			fm_info_set_phy_address(FM1_DTSEC10,
58404bccc3aSShaohui Xie 						slot_qsgmii_phyaddr[1][2]);
5851c68d01eSShaohui Xie 			fm_info_set_phy_address(FM1_DTSEC9,
5861c68d01eSShaohui Xie 						slot_qsgmii_phyaddr[1][3]);
587ee52b188SYork Sun 		}
58804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC1, slot_qsgmii_phyaddr[2][0]);
58904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC2, slot_qsgmii_phyaddr[2][1]);
59004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC3, slot_qsgmii_phyaddr[2][2]);
59104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM1_DTSEC4, slot_qsgmii_phyaddr[2][3]);
592ee52b188SYork Sun 		break;
593ee52b188SYork Sun 	default:
594ee52b188SYork Sun 		puts("Invalid SerDes1 protocol for T4240QDS\n");
595ee52b188SYork Sun 		break;
596ee52b188SYork Sun 	}
597ee52b188SYork Sun 
598ee52b188SYork Sun 	for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
59995927808SShengzhou Liu 		idx = i - FM1_DTSEC1;
6001c68d01eSShaohui Xie 		interface = fm_info_get_enet_if(i);
6011c68d01eSShaohui Xie 		switch (interface) {
602ee52b188SYork Sun 		case PHY_INTERFACE_MODE_SGMII:
6031c68d01eSShaohui Xie 		case PHY_INTERFACE_MODE_QSGMII:
6041c68d01eSShaohui Xie 			if (interface == PHY_INTERFACE_MODE_QSGMII) {
6051c68d01eSShaohui Xie 				if (idx <= 3)
6061c68d01eSShaohui Xie 					lane = serdes_get_first_lane(FSL_SRDS_1,
6071c68d01eSShaohui Xie 							QSGMII_FM1_A);
6081c68d01eSShaohui Xie 				else
6091c68d01eSShaohui Xie 					lane = serdes_get_first_lane(FSL_SRDS_1,
6101c68d01eSShaohui Xie 							QSGMII_FM1_B);
6111c68d01eSShaohui Xie 				if (lane < 0)
6121c68d01eSShaohui Xie 					break;
6131c68d01eSShaohui Xie 				slot = lane_to_slot_fsm1[lane];
6141c68d01eSShaohui Xie 				debug("FM1@DTSEC%u expects QSGMII in slot %u\n",
6151c68d01eSShaohui Xie 				      idx + 1, slot);
6161c68d01eSShaohui Xie 			} else {
617ee52b188SYork Sun 				lane = serdes_get_first_lane(FSL_SRDS_1,
618ee52b188SYork Sun 						SGMII_FM1_DTSEC1 + idx);
619ee52b188SYork Sun 				if (lane < 0)
620ee52b188SYork Sun 					break;
621ee52b188SYork Sun 				slot = lane_to_slot_fsm1[lane];
622ee52b188SYork Sun 				debug("FM1@DTSEC%u expects SGMII in slot %u\n",
623ee52b188SYork Sun 				      idx + 1, slot);
6241c68d01eSShaohui Xie 			}
625ee52b188SYork Sun 			if (QIXIS_READ(present2) & (1 << (slot - 1)))
626ee52b188SYork Sun 				fm_disable_port(i);
627ee52b188SYork Sun 			switch (slot) {
628ee52b188SYork Sun 			case 1:
629ee52b188SYork Sun 				mdio_mux[i] = EMI1_SLOT1;
630ee52b188SYork Sun 				fm_info_set_mdio(i,
631ee52b188SYork Sun 					mii_dev_for_muxval(mdio_mux[i]));
632ee52b188SYork Sun 				break;
633ee52b188SYork Sun 			case 2:
634ee52b188SYork Sun 				mdio_mux[i] = EMI1_SLOT2;
635ee52b188SYork Sun 				fm_info_set_mdio(i,
636ee52b188SYork Sun 					mii_dev_for_muxval(mdio_mux[i]));
637ee52b188SYork Sun 				break;
638ee52b188SYork Sun 			};
639ee52b188SYork Sun 			break;
640ee52b188SYork Sun 		case PHY_INTERFACE_MODE_RGMII:
641ee52b188SYork Sun 			/* FM1 DTSEC5 routes to RGMII with EC2 */
642ee52b188SYork Sun 			debug("FM1@DTSEC%u is RGMII at address %u\n",
643ee52b188SYork Sun 				idx + 1, 2);
644ee52b188SYork Sun 			if (i == FM1_DTSEC5)
645ee52b188SYork Sun 				fm_info_set_phy_address(i, 2);
646ee52b188SYork Sun 			mdio_mux[i] = EMI1_RGMII;
647ee52b188SYork Sun 			fm_info_set_mdio(i,
648ee52b188SYork Sun 				mii_dev_for_muxval(mdio_mux[i]));
649ee52b188SYork Sun 			break;
650ee52b188SYork Sun 		default:
651ee52b188SYork Sun 			break;
652ee52b188SYork Sun 		}
653ee52b188SYork Sun 	}
654ee52b188SYork Sun 
655ee52b188SYork Sun 	for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
65695927808SShengzhou Liu 		idx = i - FM1_10GEC1;
657ee52b188SYork Sun 		switch (fm_info_get_enet_if(i)) {
658ee52b188SYork Sun 		case PHY_INTERFACE_MODE_XGMII:
6599bf499acSShaohui Xie 			if ((srds_prtcl_s2 == 55) || (srds_prtcl_s2 == 57)) {
660a187559eSBin Meng 				/* A fake PHY address to make U-Boot happy */
6619bf499acSShaohui Xie 				fm_info_set_phy_address(i, i);
6629bf499acSShaohui Xie 			} else {
66395927808SShengzhou Liu 				lane = serdes_get_first_lane(FSL_SRDS_1,
66495927808SShengzhou Liu 						XAUI_FM1_MAC9 + idx);
66595927808SShengzhou Liu 				if (lane < 0)
66695927808SShengzhou Liu 					break;
66795927808SShengzhou Liu 				slot = lane_to_slot_fsm1[lane];
66895927808SShengzhou Liu 				if (QIXIS_READ(present2) & (1 << (slot - 1)))
66995927808SShengzhou Liu 					fm_disable_port(i);
6709bf499acSShaohui Xie 			}
671ee52b188SYork Sun 			mdio_mux[i] = EMI2;
672ee52b188SYork Sun 			fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
673ee52b188SYork Sun 			break;
674ee52b188SYork Sun 		default:
675ee52b188SYork Sun 			break;
676ee52b188SYork Sun 		}
677ee52b188SYork Sun 	}
678ee52b188SYork Sun 
679ee52b188SYork Sun #if (CONFIG_SYS_NUM_FMAN == 2)
680ee52b188SYork Sun 	switch (srds_prtcl_s2) {
681ee52b188SYork Sun 	case 1:
682ee52b188SYork Sun 	case 2:
683ee52b188SYork Sun 	case 4:
684ee52b188SYork Sun 		/* XAUI/HiGig in Slot3 and Slot4 */
685ee52b188SYork Sun 		fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
686ee52b188SYork Sun 		fm_info_set_phy_address(FM2_10GEC2, FM2_10GEC2_PHY_ADDR);
687ee52b188SYork Sun 		break;
68894752f60SShaohui Xie 	case 6:
689ee52b188SYork Sun 	case 7:
69094752f60SShaohui Xie 	case 12:
691ee52b188SYork Sun 	case 13:
692ee52b188SYork Sun 	case 14:
69394752f60SShaohui Xie 	case 15:
694ee52b188SYork Sun 	case 16:
69594752f60SShaohui Xie 	case 21:
696ee52b188SYork Sun 	case 22:
697ee52b188SYork Sun 	case 23:
69894752f60SShaohui Xie 	case 24:
699ee52b188SYork Sun 	case 25:
700ee52b188SYork Sun 	case 26:
701ee52b188SYork Sun 		/* XAUI/HiGig in Slot3, SGMII in Slot4 */
702ee52b188SYork Sun 		fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
70304bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
70404bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
70504bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
70604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
707ee52b188SYork Sun 		break;
70894752f60SShaohui Xie 	case 27:
709ee52b188SYork Sun 	case 28:
71094752f60SShaohui Xie 	case 35:
711ee52b188SYork Sun 	case 36:
712ee52b188SYork Sun 		/* SGMII in Slot3 and Slot4 */
71304bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
71404bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
71504bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
71604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
71704bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC5, slot_qsgmii_phyaddr[3][0]);
71804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC6, slot_qsgmii_phyaddr[3][1]);
71904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC9, slot_qsgmii_phyaddr[3][3]);
72004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC10, slot_qsgmii_phyaddr[3][2]);
721ee52b188SYork Sun 		break;
72294752f60SShaohui Xie 	case 37:
723ee52b188SYork Sun 	case 38:
724ee52b188SYork Sun 		/* QSGMII in Slot3 and Slot4 */
72504bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
72604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
72704bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
72804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
72904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC5, slot_qsgmii_phyaddr[3][0]);
73004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC6, slot_qsgmii_phyaddr[3][1]);
7311c68d01eSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC9, slot_qsgmii_phyaddr[3][2]);
7321c68d01eSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC10, slot_qsgmii_phyaddr[3][3]);
733ee52b188SYork Sun 		break;
73494752f60SShaohui Xie 	case 39:
735ee52b188SYork Sun 	case 40:
73694752f60SShaohui Xie 	case 45:
737ee52b188SYork Sun 	case 46:
73894752f60SShaohui Xie 	case 47:
739ee52b188SYork Sun 	case 48:
740ee52b188SYork Sun 		/* SGMII in Slot3 */
74104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC5, slot_qsgmii_phyaddr[3][0]);
74204bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC6, slot_qsgmii_phyaddr[3][1]);
74304bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC9, slot_qsgmii_phyaddr[3][3]);
74404bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC10, slot_qsgmii_phyaddr[3][2]);
745ee52b188SYork Sun 		/* QSGMII in Slot4 */
74604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
74704bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
74804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
74904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
750ee52b188SYork Sun 		break;
75194752f60SShaohui Xie 	case 49:
752ee52b188SYork Sun 	case 50:
75394752f60SShaohui Xie 	case 51:
754ee52b188SYork Sun 	case 52:
75594752f60SShaohui Xie 	case 53:
756ee52b188SYork Sun 	case 54:
757ee52b188SYork Sun 		fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
75804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
75904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
76004bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
76104bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
762ee52b188SYork Sun 		break;
7639bf499acSShaohui Xie 	case 55:
764ee52b188SYork Sun 	case 57:
765ee52b188SYork Sun 		/* XFI in Slot3, SGMII in Slot4 */
76604bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC1, slot_qsgmii_phyaddr[4][0]);
76704bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC2, slot_qsgmii_phyaddr[4][1]);
76804bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC3, slot_qsgmii_phyaddr[4][2]);
76904bccc3aSShaohui Xie 		fm_info_set_phy_address(FM2_DTSEC4, slot_qsgmii_phyaddr[4][3]);
770ee52b188SYork Sun 		break;
771ee52b188SYork Sun 	default:
772ee52b188SYork Sun 		puts("Invalid SerDes2 protocol for T4240QDS\n");
773ee52b188SYork Sun 		break;
774ee52b188SYork Sun 	}
775ee52b188SYork Sun 
776ee52b188SYork Sun 	for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
77795927808SShengzhou Liu 		idx = i - FM2_DTSEC1;
7781c68d01eSShaohui Xie 		interface = fm_info_get_enet_if(i);
7791c68d01eSShaohui Xie 		switch (interface) {
780ee52b188SYork Sun 		case PHY_INTERFACE_MODE_SGMII:
7811c68d01eSShaohui Xie 		case PHY_INTERFACE_MODE_QSGMII:
7821c68d01eSShaohui Xie 			if (interface == PHY_INTERFACE_MODE_QSGMII) {
7831c68d01eSShaohui Xie 				if (idx <= 3)
7841c68d01eSShaohui Xie 					lane = serdes_get_first_lane(FSL_SRDS_2,
7851c68d01eSShaohui Xie 							QSGMII_FM2_A);
7861c68d01eSShaohui Xie 				else
7871c68d01eSShaohui Xie 					lane = serdes_get_first_lane(FSL_SRDS_2,
7881c68d01eSShaohui Xie 							QSGMII_FM2_B);
7891c68d01eSShaohui Xie 				if (lane < 0)
7901c68d01eSShaohui Xie 					break;
7911c68d01eSShaohui Xie 				slot = lane_to_slot_fsm2[lane];
7921c68d01eSShaohui Xie 				debug("FM2@DTSEC%u expects QSGMII in slot %u\n",
7931c68d01eSShaohui Xie 				      idx + 1, slot);
7941c68d01eSShaohui Xie 			} else {
795ee52b188SYork Sun 				lane = serdes_get_first_lane(FSL_SRDS_2,
796ee52b188SYork Sun 						SGMII_FM2_DTSEC1 + idx);
797ee52b188SYork Sun 				if (lane < 0)
798ee52b188SYork Sun 					break;
799ee52b188SYork Sun 				slot = lane_to_slot_fsm2[lane];
800ee52b188SYork Sun 				debug("FM2@DTSEC%u expects SGMII in slot %u\n",
801ee52b188SYork Sun 				      idx + 1, slot);
8021c68d01eSShaohui Xie 			}
803ee52b188SYork Sun 			if (QIXIS_READ(present2) & (1 << (slot - 1)))
804ee52b188SYork Sun 				fm_disable_port(i);
805ee52b188SYork Sun 			switch (slot) {
806ee52b188SYork Sun 			case 3:
807ee52b188SYork Sun 				mdio_mux[i] = EMI1_SLOT3;
808ee52b188SYork Sun 				fm_info_set_mdio(i,
809ee52b188SYork Sun 					mii_dev_for_muxval(mdio_mux[i]));
810ee52b188SYork Sun 				break;
811ee52b188SYork Sun 			case 4:
812ee52b188SYork Sun 				mdio_mux[i] = EMI1_SLOT4;
813ee52b188SYork Sun 				fm_info_set_mdio(i,
814ee52b188SYork Sun 					mii_dev_for_muxval(mdio_mux[i]));
815ee52b188SYork Sun 				break;
816ee52b188SYork Sun 			};
817ee52b188SYork Sun 			break;
818ee52b188SYork Sun 		case PHY_INTERFACE_MODE_RGMII:
819ee52b188SYork Sun 			/*
820ee52b188SYork Sun 			 * If DTSEC5 is RGMII, then it's routed via via EC1 to
821ee52b188SYork Sun 			 * the first on-board RGMII port.  If DTSEC6 is RGMII,
822ee52b188SYork Sun 			 * then it's routed via via EC2 to the second on-board
823ee52b188SYork Sun 			 * RGMII port.
824ee52b188SYork Sun 			 */
825ee52b188SYork Sun 			debug("FM2@DTSEC%u is RGMII at address %u\n",
826ee52b188SYork Sun 				idx + 1, i == FM2_DTSEC5 ? 1 : 2);
827ee52b188SYork Sun 			fm_info_set_phy_address(i, i == FM2_DTSEC5 ? 1 : 2);
828ee52b188SYork Sun 			mdio_mux[i] = EMI1_RGMII;
829ee52b188SYork Sun 			fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
830ee52b188SYork Sun 			break;
831ee52b188SYork Sun 		default:
832ee52b188SYork Sun 			break;
833ee52b188SYork Sun 		}
834ee52b188SYork Sun 	}
835ee52b188SYork Sun 
836ee52b188SYork Sun 	for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
83795927808SShengzhou Liu 		idx = i - FM2_10GEC1;
838ee52b188SYork Sun 		switch (fm_info_get_enet_if(i)) {
839ee52b188SYork Sun 		case PHY_INTERFACE_MODE_XGMII:
8409bf499acSShaohui Xie 			if ((srds_prtcl_s2 == 55) || (srds_prtcl_s2 == 57)) {
841a187559eSBin Meng 				/* A fake PHY address to make U-Boot happy */
8429bf499acSShaohui Xie 				fm_info_set_phy_address(i, i);
8439bf499acSShaohui Xie 			} else {
84495927808SShengzhou Liu 				lane = serdes_get_first_lane(FSL_SRDS_2,
84595927808SShengzhou Liu 						XAUI_FM2_MAC9 + idx);
84695927808SShengzhou Liu 				if (lane < 0)
84795927808SShengzhou Liu 					break;
84895927808SShengzhou Liu 				slot = lane_to_slot_fsm2[lane];
84995927808SShengzhou Liu 				if (QIXIS_READ(present2) & (1 << (slot - 1)))
85095927808SShengzhou Liu 					fm_disable_port(i);
8519bf499acSShaohui Xie 			}
852ee52b188SYork Sun 			mdio_mux[i] = EMI2;
853ee52b188SYork Sun 			fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
854ee52b188SYork Sun 			break;
855ee52b188SYork Sun 		default:
856ee52b188SYork Sun 			break;
857ee52b188SYork Sun 		}
858ee52b188SYork Sun 	}
859ee52b188SYork Sun #endif /* CONFIG_SYS_NUM_FMAN */
860ee52b188SYork Sun 
861ee52b188SYork Sun 	cpu_eth_init(bis);
862ee52b188SYork Sun #endif /* CONFIG_FMAN_ENET */
863ee52b188SYork Sun 
864ee52b188SYork Sun 	return pci_eth_init(bis);
865ee52b188SYork Sun }
866