2 * Copyright 2012 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/processor.h>
28 #include <asm/cache.h>
29 #include <asm/immap_85xx.h>
30 #include <asm/fsl_law.h>
31 #include <asm/fsl_ddr_sdram.h>
32 #include <asm/fsl_serdes.h>
33 #include <asm/fsl_portals.h>
34 #include <asm/fsl_liodn.h>
40 #include <asm/fsl_dtsec.h>
41 #include <asm/fsl_serdes.h>
42 #include "../common/qixis.h"
43 #include "../common/fman.h"
45 #include "t4240qds_qixis.h"
47 #define EMI_NONE 0xFFFFFFFF
56 /* Slot6 and Slot8 do not have EMI connections */
58 static int mdio_mux[NUM_FM_PORTS];
60 static const char *mdio_names[] = {
72 static u8 lane_to_slot_fsm1[] = {1, 1, 1, 1, 2, 2, 2, 2};
73 static u8 lane_to_slot_fsm2[] = {3, 3, 3, 3, 4, 4, 4, 4};
75 static const char *t4240qds_mdio_name_for_muxval(u8 muxval)
77 return mdio_names[muxval];
80 struct mii_dev *mii_dev_for_muxval(u8 muxval)
83 const char *name = t4240qds_mdio_name_for_muxval(muxval);
86 printf("No bus for muxval %x\n", muxval);
90 bus = miiphy_get_dev_by_name(name);
93 printf("No bus by name %s\n", name);
100 struct t4240qds_mdio {
102 struct mii_dev *realbus;
105 static void t4240qds_mux_mdio(u8 muxval)
108 if ((muxval < 6) || (muxval == 7)) {
109 brdcfg4 = QIXIS_READ(brdcfg[4]);
110 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
111 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
112 QIXIS_WRITE(brdcfg[4], brdcfg4);
116 static int t4240qds_mdio_read(struct mii_dev *bus, int addr, int devad,
119 struct t4240qds_mdio *priv = bus->priv;
121 t4240qds_mux_mdio(priv->muxval);
123 return priv->realbus->read(priv->realbus, addr, devad, regnum);
126 static int t4240qds_mdio_write(struct mii_dev *bus, int addr, int devad,
127 int regnum, u16 value)
129 struct t4240qds_mdio *priv = bus->priv;
131 t4240qds_mux_mdio(priv->muxval);
133 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
136 static int t4240qds_mdio_reset(struct mii_dev *bus)
138 struct t4240qds_mdio *priv = bus->priv;
140 return priv->realbus->reset(priv->realbus);
143 static int t4240qds_mdio_init(char *realbusname, u8 muxval)
145 struct t4240qds_mdio *pmdio;
146 struct mii_dev *bus = mdio_alloc();
149 printf("Failed to allocate T4240QDS MDIO bus\n");
153 pmdio = malloc(sizeof(*pmdio));
155 printf("Failed to allocate T4240QDS private data\n");
160 bus->read = t4240qds_mdio_read;
161 bus->write = t4240qds_mdio_write;
162 bus->reset = t4240qds_mdio_reset;
163 sprintf(bus->name, t4240qds_mdio_name_for_muxval(muxval));
165 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
167 if (!pmdio->realbus) {
168 printf("No bus with name %s\n", realbusname);
174 pmdio->muxval = muxval;
177 return mdio_register(bus);
180 void board_ft_fman_fixup_port(void *blob, char * prop, phys_addr_t pa,
181 enum fm_port port, int offset)
183 if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
186 fdt_set_phy_handle(blob, prop, pa, "phy_sgmii4");
189 fdt_set_phy_handle(blob, prop, pa, "phy_sgmii3");
192 fdt_set_phy_handle(blob, prop, pa, "phy_sgmii12");
195 fdt_set_phy_handle(blob, prop, pa, "phy_sgmii11");
203 void fdt_fixup_board_enet(void *fdt)
206 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
207 u32 prtcl2 = in_be32(&gur->rcwsr[4]) & FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
209 prtcl2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
210 for (i = FM1_DTSEC1; i < NUM_FM_PORTS; i++) {
211 switch (fm_info_get_enet_if(i)) {
212 case PHY_INTERFACE_MODE_SGMII:
213 switch (mdio_mux[i]) {
215 fdt_status_okay_by_alias(fdt, "emi1_slot1");
218 fdt_status_okay_by_alias(fdt, "emi1_slot2");
221 fdt_status_okay_by_alias(fdt, "emi1_slot3");
224 fdt_status_okay_by_alias(fdt, "emi1_slot4");
230 case PHY_INTERFACE_MODE_XGMII:
231 /* check if it's XFI interface for 10g */
232 if ((prtcl2 == 56) || (prtcl2 == 57)) {
233 fdt_status_okay_by_alias(fdt, "emi2_xfislot3");
238 fdt_status_okay_by_alias(fdt, "emi2_xauislot1");
241 fdt_status_okay_by_alias(fdt, "emi2_xauislot2");
244 fdt_status_okay_by_alias(fdt, "emi2_xauislot3");
247 fdt_status_okay_by_alias(fdt, "emi2_xauislot4");
259 int board_eth_init(bd_t *bis)
261 #if defined(CONFIG_FMAN_ENET)
262 int i, idx, lane, slot;
263 struct memac_mdio_info dtsec_mdio_info;
264 struct memac_mdio_info tgec_mdio_info;
265 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
266 u32 srds_prtcl_s1, srds_prtcl_s2;
268 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
269 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
270 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
271 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
272 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
273 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
275 /* Initialize the mdio_mux array so we can recognize empty elements */
276 for (i = 0; i < NUM_FM_PORTS; i++)
277 mdio_mux[i] = EMI_NONE;
279 dtsec_mdio_info.regs =
280 (struct memac_mdio_controller *)CONFIG_SYS_FM2_DTSEC_MDIO_ADDR;
282 dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
284 /* Register the 1G MDIO bus */
285 fm_memac_mdio_init(bis, &dtsec_mdio_info);
287 tgec_mdio_info.regs =
288 (struct memac_mdio_controller *)CONFIG_SYS_FM2_TGEC_MDIO_ADDR;
289 tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
291 /* Register the 10G MDIO bus */
292 fm_memac_mdio_init(bis, &tgec_mdio_info);
294 /* Register the muxing front-ends to the MDIO buses */
295 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_RGMII);
296 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT1);
297 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT2);
298 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT3);
299 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT4);
300 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT5);
301 t4240qds_mdio_init(DEFAULT_FM_MDIO_NAME, EMI1_SLOT7);
302 t4240qds_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME, EMI2);
305 switch (srds_prtcl_s1) {
309 /* XAUI/HiGig in Slot1 and Slot2 */
310 fm_info_set_phy_address(FM1_10GEC1, FM1_10GEC1_PHY_ADDR);
311 fm_info_set_phy_address(FM1_10GEC2, FM1_10GEC2_PHY_ADDR);
315 /* SGMII in Slot1 and Slot2 */
316 fm_info_set_phy_address(FM1_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
317 fm_info_set_phy_address(FM1_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
318 fm_info_set_phy_address(FM1_DTSEC3, SGMII_CARD_PORT3_PHY_ADDR);
319 fm_info_set_phy_address(FM1_DTSEC4, SGMII_CARD_PORT4_PHY_ADDR);
320 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT1_PHY_ADDR);
321 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
322 if ((srds_prtcl_s2 != 56) && (srds_prtcl_s2 != 57)) {
323 fm_info_set_phy_address(FM1_DTSEC9,
324 SGMII_CARD_PORT4_PHY_ADDR);
325 fm_info_set_phy_address(FM1_DTSEC10,
326 SGMII_CARD_PORT3_PHY_ADDR);
330 fm_info_set_phy_address(FM1_DTSEC5, QSGMII_CARD_PHY_ADDR);
331 fm_info_set_phy_address(FM1_DTSEC6, QSGMII_CARD_PHY_ADDR);
332 if ((srds_prtcl_s2 != 56) && (srds_prtcl_s2 != 57)) {
333 fm_info_set_phy_address(FM1_DTSEC9,
334 QSGMII_CARD_PHY_ADDR);
335 fm_info_set_phy_address(FM1_DTSEC10,
336 QSGMII_CARD_PHY_ADDR);
342 fm_info_set_phy_address(FM1_DTSEC5, SGMII_CARD_PORT1_PHY_ADDR);
343 fm_info_set_phy_address(FM1_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
344 if ((srds_prtcl_s2 != 56) && (srds_prtcl_s2 != 57)) {
345 fm_info_set_phy_address(FM1_DTSEC10,
346 SGMII_CARD_PORT3_PHY_ADDR);
347 fm_info_set_phy_address(FM1_DTSEC9,
348 SGMII_CARD_PORT4_PHY_ADDR);
350 fm_info_set_phy_address(FM1_DTSEC1, QSGMII_CARD_PHY_ADDR);
351 fm_info_set_phy_address(FM1_DTSEC2, QSGMII_CARD_PHY_ADDR);
352 fm_info_set_phy_address(FM1_DTSEC3, QSGMII_CARD_PHY_ADDR);
353 fm_info_set_phy_address(FM1_DTSEC4, QSGMII_CARD_PHY_ADDR);
356 puts("Invalid SerDes1 protocol for T4240QDS\n");
360 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
361 idx = i - FM1_DTSEC1;
362 switch (fm_info_get_enet_if(i)) {
363 case PHY_INTERFACE_MODE_SGMII:
364 lane = serdes_get_first_lane(FSL_SRDS_1,
365 SGMII_FM1_DTSEC1 + idx);
368 slot = lane_to_slot_fsm1[lane];
369 debug("FM1@DTSEC%u expects SGMII in slot %u\n",
371 if (QIXIS_READ(present2) & (1 << (slot - 1)))
375 mdio_mux[i] = EMI1_SLOT1;
377 mii_dev_for_muxval(mdio_mux[i]));
380 mdio_mux[i] = EMI1_SLOT2;
382 mii_dev_for_muxval(mdio_mux[i]));
386 case PHY_INTERFACE_MODE_RGMII:
387 /* FM1 DTSEC5 routes to RGMII with EC2 */
388 debug("FM1@DTSEC%u is RGMII at address %u\n",
391 fm_info_set_phy_address(i, 2);
392 mdio_mux[i] = EMI1_RGMII;
394 mii_dev_for_muxval(mdio_mux[i]));
401 for (i = FM1_10GEC1; i < FM1_10GEC1 + CONFIG_SYS_NUM_FM1_10GEC; i++) {
402 idx = i - FM1_10GEC1;
403 switch (fm_info_get_enet_if(i)) {
404 case PHY_INTERFACE_MODE_XGMII:
405 lane = serdes_get_first_lane(FSL_SRDS_1,
406 XAUI_FM1_MAC9 + idx);
409 slot = lane_to_slot_fsm1[lane];
410 if (QIXIS_READ(present2) & (1 << (slot - 1)))
413 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
420 #if (CONFIG_SYS_NUM_FMAN == 2)
421 switch (srds_prtcl_s2) {
425 /* XAUI/HiGig in Slot3 and Slot4 */
426 fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
427 fm_info_set_phy_address(FM2_10GEC2, FM2_10GEC2_PHY_ADDR);
437 /* XAUI/HiGig in Slot3, SGMII in Slot4 */
438 fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
439 fm_info_set_phy_address(FM2_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
440 fm_info_set_phy_address(FM2_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
441 fm_info_set_phy_address(FM2_DTSEC3, SGMII_CARD_PORT3_PHY_ADDR);
442 fm_info_set_phy_address(FM2_DTSEC4, SGMII_CARD_PORT4_PHY_ADDR);
446 /* SGMII in Slot3 and Slot4 */
447 fm_info_set_phy_address(FM2_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
448 fm_info_set_phy_address(FM2_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
449 fm_info_set_phy_address(FM2_DTSEC3, SGMII_CARD_PORT3_PHY_ADDR);
450 fm_info_set_phy_address(FM2_DTSEC4, SGMII_CARD_PORT4_PHY_ADDR);
451 fm_info_set_phy_address(FM2_DTSEC5, SGMII_CARD_PORT1_PHY_ADDR);
452 fm_info_set_phy_address(FM2_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
453 fm_info_set_phy_address(FM2_DTSEC9, SGMII_CARD_PORT4_PHY_ADDR);
454 fm_info_set_phy_address(FM2_DTSEC10, SGMII_CARD_PORT3_PHY_ADDR);
457 /* QSGMII in Slot3 and Slot4 */
458 fm_info_set_phy_address(FM2_DTSEC1, QSGMII_CARD_PHY_ADDR);
459 fm_info_set_phy_address(FM2_DTSEC2, QSGMII_CARD_PHY_ADDR);
460 fm_info_set_phy_address(FM2_DTSEC3, QSGMII_CARD_PHY_ADDR);
461 fm_info_set_phy_address(FM2_DTSEC4, QSGMII_CARD_PHY_ADDR);
462 fm_info_set_phy_address(FM2_DTSEC5, QSGMII_CARD_PHY_ADDR);
463 fm_info_set_phy_address(FM2_DTSEC6, QSGMII_CARD_PHY_ADDR);
464 fm_info_set_phy_address(FM2_DTSEC9, QSGMII_CARD_PHY_ADDR);
465 fm_info_set_phy_address(FM2_DTSEC10, QSGMII_CARD_PHY_ADDR);
471 fm_info_set_phy_address(FM2_DTSEC5, SGMII_CARD_PORT1_PHY_ADDR);
472 fm_info_set_phy_address(FM2_DTSEC6, SGMII_CARD_PORT2_PHY_ADDR);
473 fm_info_set_phy_address(FM2_DTSEC9, SGMII_CARD_PORT4_PHY_ADDR);
474 fm_info_set_phy_address(FM2_DTSEC10, SGMII_CARD_PORT3_PHY_ADDR);
475 /* QSGMII in Slot4 */
476 fm_info_set_phy_address(FM2_DTSEC1, QSGMII_CARD_PHY_ADDR);
477 fm_info_set_phy_address(FM2_DTSEC2, QSGMII_CARD_PHY_ADDR);
478 fm_info_set_phy_address(FM2_DTSEC3, QSGMII_CARD_PHY_ADDR);
479 fm_info_set_phy_address(FM2_DTSEC4, QSGMII_CARD_PHY_ADDR);
484 fm_info_set_phy_address(FM2_10GEC1, FM2_10GEC1_PHY_ADDR);
485 fm_info_set_phy_address(FM2_DTSEC1, QSGMII_CARD_PHY_ADDR);
486 fm_info_set_phy_address(FM2_DTSEC2, QSGMII_CARD_PHY_ADDR);
487 fm_info_set_phy_address(FM2_DTSEC3, QSGMII_CARD_PHY_ADDR);
488 fm_info_set_phy_address(FM2_DTSEC4, QSGMII_CARD_PHY_ADDR);
492 /* XFI in Slot3, SGMII in Slot4 */
493 fm_info_set_phy_address(FM2_DTSEC1, SGMII_CARD_PORT1_PHY_ADDR);
494 fm_info_set_phy_address(FM2_DTSEC2, SGMII_CARD_PORT2_PHY_ADDR);
495 fm_info_set_phy_address(FM2_DTSEC3, SGMII_CARD_PORT3_PHY_ADDR);
496 fm_info_set_phy_address(FM2_DTSEC4, SGMII_CARD_PORT4_PHY_ADDR);
499 puts("Invalid SerDes2 protocol for T4240QDS\n");
503 for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
504 idx = i - FM2_DTSEC1;
505 switch (fm_info_get_enet_if(i)) {
506 case PHY_INTERFACE_MODE_SGMII:
507 lane = serdes_get_first_lane(FSL_SRDS_2,
508 SGMII_FM2_DTSEC1 + idx);
511 slot = lane_to_slot_fsm2[lane];
512 debug("FM2@DTSEC%u expects SGMII in slot %u\n",
514 if (QIXIS_READ(present2) & (1 << (slot - 1)))
518 mdio_mux[i] = EMI1_SLOT3;
520 mii_dev_for_muxval(mdio_mux[i]));
523 mdio_mux[i] = EMI1_SLOT4;
525 mii_dev_for_muxval(mdio_mux[i]));
529 case PHY_INTERFACE_MODE_RGMII:
531 * If DTSEC5 is RGMII, then it's routed via via EC1 to
532 * the first on-board RGMII port. If DTSEC6 is RGMII,
533 * then it's routed via via EC2 to the second on-board
536 debug("FM2@DTSEC%u is RGMII at address %u\n",
537 idx + 1, i == FM2_DTSEC5 ? 1 : 2);
538 fm_info_set_phy_address(i, i == FM2_DTSEC5 ? 1 : 2);
539 mdio_mux[i] = EMI1_RGMII;
540 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
547 for (i = FM2_10GEC1; i < FM2_10GEC1 + CONFIG_SYS_NUM_FM2_10GEC; i++) {
548 idx = i - FM2_10GEC1;
549 switch (fm_info_get_enet_if(i)) {
550 case PHY_INTERFACE_MODE_XGMII:
551 lane = serdes_get_first_lane(FSL_SRDS_2,
552 XAUI_FM2_MAC9 + idx);
555 slot = lane_to_slot_fsm2[lane];
556 if (QIXIS_READ(present2) & (1 << (slot - 1)))
559 fm_info_set_mdio(i, mii_dev_for_muxval(mdio_mux[i]));
565 #endif /* CONFIG_SYS_NUM_FMAN */
568 #endif /* CONFIG_FMAN_ENET */
570 return pci_eth_init(bis);