1 /*
2  * Copyright 2015 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <netdev.h>
9 #include <asm/io.h>
10 #include <asm/arch/fsl_serdes.h>
11 #include <hwconfig.h>
12 #include <fsl_mdio.h>
13 #include <malloc.h>
14 #include <fm_eth.h>
15 #include <i2c.h>
16 #include <miiphy.h>
17 #include <fsl-mc/ldpaa_wriop.h>
18 
19 #include "../common/qixis.h"
20 
21 #include "ls2080aqds_qixis.h"
22 
23 
24 #ifdef CONFIG_FSL_MC_ENET
25  /* - In LS2080A there are only 16 SERDES lanes, spread across 2 SERDES banks.
26  *   Bank 1 -> Lanes A, B, C, D, E, F, G, H
27  *   Bank 2 -> Lanes A,B, C, D, E, F, G, H
28  */
29 
30  /* Mapping of 16 SERDES lanes to LS2080A QDS board slots. A value of '0' here
31   * means that the mapping must be determined dynamically, or that the lane
32   * maps to something other than a board slot.
33   */
34 
35 static u8 lane_to_slot_fsm1[] = {
36 	0, 0, 0, 0, 0, 0, 0, 0
37 };
38 
39 static u8 lane_to_slot_fsm2[] = {
40 	0, 0, 0, 0, 0, 0, 0, 0
41 };
42 
43 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
44  * housed.
45  */
46 
47 static int xqsgii_riser_phy_addr[] = {
48 	XQSGMII_CARD_PHY1_PORT0_ADDR,
49 	XQSGMII_CARD_PHY2_PORT0_ADDR,
50 	XQSGMII_CARD_PHY3_PORT0_ADDR,
51 	XQSGMII_CARD_PHY4_PORT0_ADDR,
52 	XQSGMII_CARD_PHY3_PORT2_ADDR,
53 	XQSGMII_CARD_PHY1_PORT2_ADDR,
54 	XQSGMII_CARD_PHY4_PORT2_ADDR,
55 	XQSGMII_CARD_PHY2_PORT2_ADDR,
56 };
57 
58 static int sgmii_riser_phy_addr[] = {
59 	SGMII_CARD_PORT1_PHY_ADDR,
60 	SGMII_CARD_PORT2_PHY_ADDR,
61 	SGMII_CARD_PORT3_PHY_ADDR,
62 	SGMII_CARD_PORT4_PHY_ADDR,
63 };
64 
65 /* Slot2 does not have EMI connections */
66 #define EMI_NONE	0xFFFFFFFF
67 #define EMI1_SLOT1	0
68 #define EMI1_SLOT2	1
69 #define EMI1_SLOT3	2
70 #define EMI1_SLOT4	3
71 #define EMI1_SLOT5	4
72 #define EMI1_SLOT6	5
73 #define EMI2		6
74 #define SFP_TX		0
75 
76 static const char * const mdio_names[] = {
77 	"LS2080A_QDS_MDIO0",
78 	"LS2080A_QDS_MDIO1",
79 	"LS2080A_QDS_MDIO2",
80 	"LS2080A_QDS_MDIO3",
81 	"LS2080A_QDS_MDIO4",
82 	"LS2080A_QDS_MDIO5",
83 	DEFAULT_WRIOP_MDIO2_NAME,
84 };
85 
86 struct ls2080a_qds_mdio {
87 	u8 muxval;
88 	struct mii_dev *realbus;
89 };
90 
91 static void sgmii_configure_repeater(int serdes_port)
92 {
93 	struct mii_dev *bus;
94 	uint8_t a = 0xf;
95 	int i, j, ret;
96 	int dpmac_id = 0, dpmac, mii_bus = 0;
97 	unsigned short value;
98 	char dev[2][20] = {"LS2080A_QDS_MDIO0", "LS2080A_QDS_MDIO3"};
99 	uint8_t i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5f, 0x60};
100 
101 	uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
102 	uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
103 	uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
104 	uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
105 
106 	int *riser_phy_addr = &xqsgii_riser_phy_addr[0];
107 
108 	/* Set I2c to Slot 1 */
109 	i2c_write(0x77, 0, 0, &a, 1);
110 
111 	for (dpmac = 0; dpmac < 8; dpmac++) {
112 		/* Check the PHY status */
113 		switch (serdes_port) {
114 		case 1:
115 			mii_bus = 0;
116 			dpmac_id = dpmac + 1;
117 			break;
118 		case 2:
119 			mii_bus = 1;
120 			dpmac_id = dpmac + 9;
121 			a = 0xb;
122 			i2c_write(0x76, 0, 0, &a, 1);
123 			break;
124 		}
125 
126 		ret = miiphy_set_current_dev(dev[mii_bus]);
127 		if (ret > 0)
128 			goto error;
129 
130 		bus = mdio_get_current_dev();
131 		debug("Reading from bus %s\n", bus->name);
132 
133 		ret = miiphy_write(dev[mii_bus], riser_phy_addr[dpmac], 0x1f,
134 				   3);
135 		if (ret > 0)
136 			goto error;
137 
138 		mdelay(10);
139 		ret = miiphy_read(dev[mii_bus], riser_phy_addr[dpmac], 0x11,
140 				  &value);
141 		if (ret > 0)
142 			goto error;
143 
144 		mdelay(10);
145 
146 		if ((value & 0xfff) == 0x40f) {
147 			printf("DPMAC %d:PHY is ..... Configured\n", dpmac_id);
148 			continue;
149 		}
150 
151 		for (i = 0; i < 4; i++) {
152 			for (j = 0; j < 4; j++) {
153 				a = 0x18;
154 				i2c_write(i2c_addr[dpmac], 6, 1, &a, 1);
155 				a = 0x38;
156 				i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
157 				a = 0x4;
158 				i2c_write(i2c_addr[dpmac], 8, 1, &a, 1);
159 
160 				i2c_write(i2c_addr[dpmac], 0xf, 1,
161 					  &ch_a_eq[i], 1);
162 				i2c_write(i2c_addr[dpmac], 0x11, 1,
163 					  &ch_a_ctl2[j], 1);
164 
165 				i2c_write(i2c_addr[dpmac], 0x16, 1,
166 					  &ch_b_eq[i], 1);
167 				i2c_write(i2c_addr[dpmac], 0x18, 1,
168 					  &ch_b_ctl2[j], 1);
169 
170 				a = 0x14;
171 				i2c_write(i2c_addr[dpmac], 0x23, 1, &a, 1);
172 				a = 0xb5;
173 				i2c_write(i2c_addr[dpmac], 0x2d, 1, &a, 1);
174 				a = 0x20;
175 				i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
176 				mdelay(100);
177 				ret = miiphy_read(dev[mii_bus],
178 						  riser_phy_addr[dpmac],
179 						  0x11, &value);
180 				if (ret > 0)
181 					goto error;
182 
183 				mdelay(1);
184 				ret = miiphy_read(dev[mii_bus],
185 						  riser_phy_addr[dpmac],
186 						  0x11, &value);
187 				if (ret > 0)
188 					goto error;
189 				mdelay(10);
190 
191 				if ((value & 0xfff) == 0x40f) {
192 					printf("DPMAC %d :PHY is configured ",
193 					       dpmac_id);
194 					printf("after setting repeater 0x%x\n",
195 					       value);
196 					i = 5;
197 					j = 5;
198 				} else
199 					printf("DPMAC %d :PHY is failed to ",
200 					       dpmac_id);
201 					printf("configure the repeater 0x%x\n",
202 					       value);
203 				}
204 		}
205 	}
206 error:
207 	if (ret)
208 		printf("DPMAC %d ..... FAILED to configure PHY\n", dpmac_id);
209 	return;
210 }
211 
212 static void qsgmii_configure_repeater(int dpmac)
213 {
214 	uint8_t a = 0xf;
215 	int i, j;
216 	int i2c_phy_addr = 0;
217 	int phy_addr = 0;
218 	int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
219 
220 	uint8_t ch_a_eq[] = {0x1, 0x2, 0x3, 0x7};
221 	uint8_t ch_a_ctl2[] = {0x81, 0x82, 0x83, 0x84};
222 	uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
223 	uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
224 
225 	const char *dev = "LS2080A_QDS_MDIO0";
226 	int ret = 0;
227 	unsigned short value;
228 
229 	/* Set I2c to Slot 1 */
230 	i2c_write(0x77, 0, 0, &a, 1);
231 
232 	switch (dpmac) {
233 	case 1:
234 	case 2:
235 	case 3:
236 	case 4:
237 		i2c_phy_addr = i2c_addr[0];
238 		phy_addr = 0;
239 		break;
240 
241 	case 5:
242 	case 6:
243 	case 7:
244 	case 8:
245 		i2c_phy_addr = i2c_addr[1];
246 		phy_addr = 4;
247 		break;
248 
249 	case 9:
250 	case 10:
251 	case 11:
252 	case 12:
253 		i2c_phy_addr = i2c_addr[2];
254 		phy_addr = 8;
255 		break;
256 
257 	case 13:
258 	case 14:
259 	case 15:
260 	case 16:
261 		i2c_phy_addr = i2c_addr[3];
262 		phy_addr = 0xc;
263 		break;
264 	}
265 
266 	/* Check the PHY status */
267 	ret = miiphy_set_current_dev(dev);
268 	ret = miiphy_write(dev, phy_addr, 0x1f, 3);
269 	mdelay(10);
270 	ret = miiphy_read(dev, phy_addr, 0x11, &value);
271 	mdelay(10);
272 	ret = miiphy_read(dev, phy_addr, 0x11, &value);
273 	mdelay(10);
274 	if ((value & 0xf) == 0xf) {
275 		printf("DPMAC %d :PHY is ..... Configured\n", dpmac);
276 		return;
277 	}
278 
279 	for (i = 0; i < 4; i++) {
280 		for (j = 0; j < 4; j++) {
281 			a = 0x18;
282 			i2c_write(i2c_phy_addr, 6, 1, &a, 1);
283 			a = 0x38;
284 			i2c_write(i2c_phy_addr, 4, 1, &a, 1);
285 			a = 0x4;
286 			i2c_write(i2c_phy_addr, 8, 1, &a, 1);
287 
288 			i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1);
289 			i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1);
290 
291 			i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1);
292 			i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1);
293 
294 			a = 0x14;
295 			i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
296 			a = 0xb5;
297 			i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
298 			a = 0x20;
299 			i2c_write(i2c_phy_addr, 4, 1, &a, 1);
300 			mdelay(100);
301 			ret = miiphy_read(dev, phy_addr, 0x11, &value);
302 			if (ret > 0)
303 				goto error;
304 			mdelay(1);
305 			ret = miiphy_read(dev, phy_addr, 0x11, &value);
306 			if (ret > 0)
307 				goto error;
308 			mdelay(10);
309 			if ((value & 0xf) == 0xf) {
310 				printf("DPMAC %d :PHY is ..... Configured\n",
311 				       dpmac);
312 				return;
313 			}
314 		}
315 	}
316 error:
317 	printf("DPMAC %d :PHY ..... FAILED to configure PHY\n", dpmac);
318 	return;
319 }
320 
321 static const char *ls2080a_qds_mdio_name_for_muxval(u8 muxval)
322 {
323 	return mdio_names[muxval];
324 }
325 
326 struct mii_dev *mii_dev_for_muxval(u8 muxval)
327 {
328 	struct mii_dev *bus;
329 	const char *name = ls2080a_qds_mdio_name_for_muxval(muxval);
330 
331 	if (!name) {
332 		printf("No bus for muxval %x\n", muxval);
333 		return NULL;
334 	}
335 
336 	bus = miiphy_get_dev_by_name(name);
337 
338 	if (!bus) {
339 		printf("No bus by name %s\n", name);
340 		return NULL;
341 	}
342 
343 	return bus;
344 }
345 
346 static void ls2080a_qds_enable_SFP_TX(u8 muxval)
347 {
348 	u8 brdcfg9;
349 
350 	brdcfg9 = QIXIS_READ(brdcfg[9]);
351 	brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
352 	brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
353 	QIXIS_WRITE(brdcfg[9], brdcfg9);
354 }
355 
356 static void ls2080a_qds_mux_mdio(u8 muxval)
357 {
358 	u8 brdcfg4;
359 
360 	if (muxval <= 5) {
361 		brdcfg4 = QIXIS_READ(brdcfg[4]);
362 		brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
363 		brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
364 		QIXIS_WRITE(brdcfg[4], brdcfg4);
365 	}
366 }
367 
368 static int ls2080a_qds_mdio_read(struct mii_dev *bus, int addr,
369 				 int devad, int regnum)
370 {
371 	struct ls2080a_qds_mdio *priv = bus->priv;
372 
373 	ls2080a_qds_mux_mdio(priv->muxval);
374 
375 	return priv->realbus->read(priv->realbus, addr, devad, regnum);
376 }
377 
378 static int ls2080a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
379 				  int regnum, u16 value)
380 {
381 	struct ls2080a_qds_mdio *priv = bus->priv;
382 
383 	ls2080a_qds_mux_mdio(priv->muxval);
384 
385 	return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
386 }
387 
388 static int ls2080a_qds_mdio_reset(struct mii_dev *bus)
389 {
390 	struct ls2080a_qds_mdio *priv = bus->priv;
391 
392 	return priv->realbus->reset(priv->realbus);
393 }
394 
395 static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
396 {
397 	struct ls2080a_qds_mdio *pmdio;
398 	struct mii_dev *bus = mdio_alloc();
399 
400 	if (!bus) {
401 		printf("Failed to allocate ls2080a_qds MDIO bus\n");
402 		return -1;
403 	}
404 
405 	pmdio = malloc(sizeof(*pmdio));
406 	if (!pmdio) {
407 		printf("Failed to allocate ls2080a_qds private data\n");
408 		free(bus);
409 		return -1;
410 	}
411 
412 	bus->read = ls2080a_qds_mdio_read;
413 	bus->write = ls2080a_qds_mdio_write;
414 	bus->reset = ls2080a_qds_mdio_reset;
415 	strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));
416 
417 	pmdio->realbus = miiphy_get_dev_by_name(realbusname);
418 
419 	if (!pmdio->realbus) {
420 		printf("No bus with name %s\n", realbusname);
421 		free(bus);
422 		free(pmdio);
423 		return -1;
424 	}
425 
426 	pmdio->muxval = muxval;
427 	bus->priv = pmdio;
428 
429 	return mdio_register(bus);
430 }
431 
432 /*
433  * Initialize the dpmac_info array.
434  *
435  */
436 static void initialize_dpmac_to_slot(void)
437 {
438 	struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
439 	int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
440 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
441 		>> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
442 	int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
443 				FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
444 		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
445 
446 	char *env_hwconfig;
447 	env_hwconfig = getenv("hwconfig");
448 
449 	switch (serdes1_prtcl) {
450 	case 0x07:
451 	case 0x09:
452 	case 0x33:
453 		printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
454 		       serdes1_prtcl);
455 		lane_to_slot_fsm1[0] = EMI1_SLOT1;
456 		lane_to_slot_fsm1[1] = EMI1_SLOT1;
457 		lane_to_slot_fsm1[2] = EMI1_SLOT1;
458 		lane_to_slot_fsm1[3] = EMI1_SLOT1;
459 		if (hwconfig_f("xqsgmii", env_hwconfig)) {
460 			lane_to_slot_fsm1[4] = EMI1_SLOT1;
461 			lane_to_slot_fsm1[5] = EMI1_SLOT1;
462 			lane_to_slot_fsm1[6] = EMI1_SLOT1;
463 			lane_to_slot_fsm1[7] = EMI1_SLOT1;
464 		} else {
465 			lane_to_slot_fsm1[4] = EMI1_SLOT2;
466 			lane_to_slot_fsm1[5] = EMI1_SLOT2;
467 			lane_to_slot_fsm1[6] = EMI1_SLOT2;
468 			lane_to_slot_fsm1[7] = EMI1_SLOT2;
469 		}
470 		break;
471 
472 	case 0x2A:
473 		printf("qds: WRIOP: Supported SerDes1 Protocol 0x%02x\n",
474 		       serdes1_prtcl);
475 		break;
476 	default:
477 		printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
478 		       __func__, serdes1_prtcl);
479 		break;
480 	}
481 
482 	switch (serdes2_prtcl) {
483 	case 0x07:
484 	case 0x08:
485 	case 0x09:
486 	case 0x49:
487 		printf("qds: WRIOP: Supported SerDes2 Protocol 0x%02x\n",
488 		       serdes2_prtcl);
489 		lane_to_slot_fsm2[0] = EMI1_SLOT4;
490 		lane_to_slot_fsm2[1] = EMI1_SLOT4;
491 		lane_to_slot_fsm2[2] = EMI1_SLOT4;
492 		lane_to_slot_fsm2[3] = EMI1_SLOT4;
493 
494 		if (hwconfig_f("xqsgmii", env_hwconfig)) {
495 			lane_to_slot_fsm2[4] = EMI1_SLOT4;
496 			lane_to_slot_fsm2[5] = EMI1_SLOT4;
497 			lane_to_slot_fsm2[6] = EMI1_SLOT4;
498 			lane_to_slot_fsm2[7] = EMI1_SLOT4;
499 		} else {
500 			/* No MDIO physical connection */
501 			lane_to_slot_fsm2[4] = EMI1_SLOT6;
502 			lane_to_slot_fsm2[5] = EMI1_SLOT6;
503 			lane_to_slot_fsm2[6] = EMI1_SLOT6;
504 			lane_to_slot_fsm2[7] = EMI1_SLOT6;
505 		}
506 		break;
507 	default:
508 		printf(" %s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
509 		       __func__ , serdes2_prtcl);
510 		break;
511 	}
512 }
513 
514 void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
515 {
516 	int lane, slot;
517 	struct mii_dev *bus;
518 	struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
519 	int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
520 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
521 		>> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
522 	int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
523 				FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
524 		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
525 
526 	int *riser_phy_addr;
527 	char *env_hwconfig = getenv("hwconfig");
528 
529 	if (hwconfig_f("xqsgmii", env_hwconfig))
530 		riser_phy_addr = &xqsgii_riser_phy_addr[0];
531 	else
532 		riser_phy_addr = &sgmii_riser_phy_addr[0];
533 
534 	if (dpmac_id > WRIOP1_DPMAC9)
535 		goto serdes2;
536 
537 	switch (serdes1_prtcl) {
538 	case 0x07:
539 
540 		lane = serdes_get_first_lane(FSL_SRDS_1, SGMII1 + dpmac_id);
541 		slot = lane_to_slot_fsm1[lane];
542 
543 		switch (++slot) {
544 		case 1:
545 			/* Slot housing a SGMII riser card? */
546 			wriop_set_phy_address(dpmac_id,
547 					      riser_phy_addr[dpmac_id - 1]);
548 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
549 			bus = mii_dev_for_muxval(EMI1_SLOT1);
550 			wriop_set_mdio(dpmac_id, bus);
551 			break;
552 		case 2:
553 			/* Slot housing a SGMII riser card? */
554 			wriop_set_phy_address(dpmac_id,
555 					      riser_phy_addr[dpmac_id - 1]);
556 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT2;
557 			bus = mii_dev_for_muxval(EMI1_SLOT2);
558 			wriop_set_mdio(dpmac_id, bus);
559 			break;
560 		case 3:
561 			break;
562 		case 4:
563 			break;
564 		case 5:
565 			break;
566 		case 6:
567 			break;
568 		}
569 	break;
570 	default:
571 		printf("%s qds: WRIOP: Unsupported SerDes1 Protocol 0x%02x\n",
572 		       __func__ , serdes1_prtcl);
573 	break;
574 	}
575 
576 serdes2:
577 	switch (serdes2_prtcl) {
578 	case 0x07:
579 	case 0x08:
580 	case 0x49:
581 		lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
582 							(dpmac_id - 9));
583 		slot = lane_to_slot_fsm2[lane];
584 
585 		switch (++slot) {
586 		case 1:
587 			break;
588 		case 3:
589 			break;
590 		case 4:
591 			/* Slot housing a SGMII riser card? */
592 			wriop_set_phy_address(dpmac_id,
593 					      riser_phy_addr[dpmac_id - 9]);
594 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
595 			bus = mii_dev_for_muxval(EMI1_SLOT4);
596 			wriop_set_mdio(dpmac_id, bus);
597 		break;
598 		case 5:
599 		break;
600 		case 6:
601 			/* Slot housing a SGMII riser card? */
602 			wriop_set_phy_address(dpmac_id,
603 					      riser_phy_addr[dpmac_id - 13]);
604 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
605 			bus = mii_dev_for_muxval(EMI1_SLOT6);
606 			wriop_set_mdio(dpmac_id, bus);
607 		break;
608 	}
609 	break;
610 	default:
611 		printf("%s qds: WRIOP: Unsupported SerDes2 Protocol 0x%02x\n",
612 		       __func__, serdes2_prtcl);
613 	break;
614 	}
615 }
616 
617 void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
618 {
619 	int lane = 0, slot;
620 	struct mii_dev *bus;
621 	struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
622 	int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
623 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
624 		>> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
625 
626 	switch (serdes1_prtcl) {
627 	case 0x33:
628 		switch (dpmac_id) {
629 		case 1:
630 		case 2:
631 		case 3:
632 		case 4:
633 			lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_A);
634 		break;
635 		case 5:
636 		case 6:
637 		case 7:
638 		case 8:
639 			lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_B);
640 		break;
641 		case 9:
642 		case 10:
643 		case 11:
644 		case 12:
645 			lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_C);
646 		break;
647 		case 13:
648 		case 14:
649 		case 15:
650 		case 16:
651 			lane = serdes_get_first_lane(FSL_SRDS_1, QSGMII_D);
652 		break;
653 	}
654 
655 		slot = lane_to_slot_fsm1[lane];
656 
657 		switch (++slot) {
658 		case 1:
659 			/* Slot housing a QSGMII riser card? */
660 			wriop_set_phy_address(dpmac_id, dpmac_id - 1);
661 			dpmac_info[dpmac_id].board_mux = EMI1_SLOT1;
662 			bus = mii_dev_for_muxval(EMI1_SLOT1);
663 			wriop_set_mdio(dpmac_id, bus);
664 			break;
665 		case 3:
666 			break;
667 		case 4:
668 			break;
669 		case 5:
670 		break;
671 		case 6:
672 			break;
673 	}
674 	break;
675 	default:
676 		printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
677 		       serdes1_prtcl);
678 	break;
679 	}
680 
681 	qsgmii_configure_repeater(dpmac_id);
682 }
683 
684 void ls2080a_handle_phy_interface_xsgmii(int i)
685 {
686 	struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
687 	int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
688 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
689 		>> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
690 
691 	switch (serdes1_prtcl) {
692 	case 0x2A:
693 		/*
694 		 * XFI does not need a PHY to work, but to avoid U-Boot use
695 		 * default PHY address which is zero to a MAC when it found
696 		 * a MAC has no PHY address, we give a PHY address to XFI
697 		 * MAC, and should not use a real XAUI PHY address, since
698 		 * MDIO can access it successfully, and then MDIO thinks
699 		 * the XAUI card is used for the XFI MAC, which will cause
700 		 * error.
701 		 */
702 		wriop_set_phy_address(i, i + 4);
703 		ls2080a_qds_enable_SFP_TX(SFP_TX);
704 
705 		break;
706 	default:
707 		printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
708 		       serdes1_prtcl);
709 		break;
710 	}
711 }
712 #endif
713 
714 int board_eth_init(bd_t *bis)
715 {
716 	int error;
717 #ifdef CONFIG_FSL_MC_ENET
718 	struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
719 	int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
720 				FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
721 		>> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
722 	int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
723 				FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
724 		>> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
725 
726 	struct memac_mdio_info *memac_mdio0_info;
727 	struct memac_mdio_info *memac_mdio1_info;
728 	unsigned int i;
729 	char *env_hwconfig;
730 
731 	env_hwconfig = getenv("hwconfig");
732 
733 	initialize_dpmac_to_slot();
734 
735 	memac_mdio0_info = (struct memac_mdio_info *)malloc(
736 					sizeof(struct memac_mdio_info));
737 	memac_mdio0_info->regs =
738 		(struct memac_mdio_controller *)
739 					CONFIG_SYS_FSL_WRIOP1_MDIO1;
740 	memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
741 
742 	/* Register the real MDIO1 bus */
743 	fm_memac_mdio_init(bis, memac_mdio0_info);
744 
745 	memac_mdio1_info = (struct memac_mdio_info *)malloc(
746 					sizeof(struct memac_mdio_info));
747 	memac_mdio1_info->regs =
748 		(struct memac_mdio_controller *)
749 					CONFIG_SYS_FSL_WRIOP1_MDIO2;
750 	memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
751 
752 	/* Register the real MDIO2 bus */
753 	fm_memac_mdio_init(bis, memac_mdio1_info);
754 
755 	/* Register the muxing front-ends to the MDIO buses */
756 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
757 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
758 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
759 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
760 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
761 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
762 
763 	ls2080a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
764 
765 	for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
766 		switch (wriop_get_enet_if(i)) {
767 		case PHY_INTERFACE_MODE_QSGMII:
768 			ls2080a_handle_phy_interface_qsgmii(i);
769 			break;
770 		case PHY_INTERFACE_MODE_SGMII:
771 			ls2080a_handle_phy_interface_sgmii(i);
772 			break;
773 		case PHY_INTERFACE_MODE_XGMII:
774 			ls2080a_handle_phy_interface_xsgmii(i);
775 			break;
776 		default:
777 			break;
778 
779 		if (i == 16)
780 			i = NUM_WRIOP_PORTS;
781 		}
782 	}
783 
784 	error = cpu_eth_init(bis);
785 
786 	if (hwconfig_f("xqsgmii", env_hwconfig)) {
787 		if (serdes1_prtcl == 0x7)
788 			sgmii_configure_repeater(1);
789 		if (serdes2_prtcl == 0x7 || serdes2_prtcl == 0x8 ||
790 		    serdes2_prtcl == 0x49)
791 			sgmii_configure_repeater(2);
792 	}
793 #endif
794 	error = pci_eth_init(bis);
795 	return error;
796 }
797 
798 #ifdef CONFIG_FSL_MC_ENET
799 
800 #endif
801