treewide: convert bd_t to struct bd_info by coccinelle
[platform/kernel/u-boot.git] / board / freescale / corenet_ds / eth_superhydra.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2009-2011 Freescale Semiconductor, Inc.
4  * Author: Srikanth Srinivasan <srikanth.srinivasan@freescale.com>
5  */
6
7 /*
8  * This file handles the board muxing between the Fman Ethernet MACs and
9  * the RGMII/SGMII/XGMII PHYs on a Freescale P5040 "Super Hydra" reference
10  * board. The RGMII PHYs are the two on-board 1Gb ports.  The SGMII PHYs are
11  * provided by the standard Freescale four-port SGMII riser card.  The 10Gb
12  * XGMII PHYs are provided via the XAUI riser card.  The P5040 has 2 FMans
13  * and 5 1G interfaces and 10G interface per FMan. Based on the options in
14  * the RCW, we could have upto 3 SGMII cards and 1 XAUI card at a time.
15  *
16  * Muxing is handled via the PIXIS BRDCFG1 register.  The EMI1 bits control
17  * muxing among the RGMII PHYs and the SGMII PHYs.  The value for RGMII is
18  * always the same (0).  The value for SGMII depends on which slot the riser is
19  * inserted in.  The EMI2 bits control muxing for the the XGMII.  Like SGMII,
20  * the value is based on which slot the XAUI is inserted in.
21  *
22  * The SERDES configuration is used to determine where the SGMII and XAUI cards
23  * exist, and also which Fman's MACs are routed to which PHYs.  So for a given
24  * Fman MAC, there is one and only PHY it connects to.  MACs cannot be routed
25  * to PHYs dynamically.
26  *
27  *
28  * This file also updates the device tree in three ways:
29  *
30  * 1) The status of each virtual MDIO node that is referenced by an Ethernet
31  *    node is set to "okay".
32  *
33  * 2) The phy-handle property of each active Ethernet MAC node is set to the
34  *    appropriate PHY node.
35  *
36  * 3) The "mux value" for each virtual MDIO node is set to the correct value,
37  *    if necessary.  Some virtual MDIO nodes do not have configurable mux
38  *    values, so those values are hard-coded in the DTS.  On the HYDRA board,
39  *    the virtual MDIO node for the SGMII card needs to be updated.
40  *
41  * For all this to work, the device tree needs to have the following:
42  *
43  * 1) An alias for each PHY node that an Ethernet node could be routed to.
44  *
45  * 2) An alias for each real and virtual MDIO node that is disabled by default
46  * and might need to be enabled, and also might need to have its mux-value
47  * updated.
48  */
49
50 #include <common.h>
51 #include <log.h>
52 #include <net.h>
53 #include <netdev.h>
54 #include <asm/fsl_serdes.h>
55 #include <fm_eth.h>
56 #include <fsl_mdio.h>
57 #include <malloc.h>
58 #include <fdt_support.h>
59 #include <fsl_dtsec.h>
60
61 #include "../common/ngpixis.h"
62 #include "../common/fman.h"
63
64 #ifdef CONFIG_FMAN_ENET
65
66 #define BRDCFG1_EMI1_SEL_MASK   0x70
67 #define BRDCFG1_EMI1_SEL_SLOT1  0x10
68 #define BRDCFG1_EMI1_SEL_SLOT2  0x20
69 #define BRDCFG1_EMI1_SEL_SLOT5  0x30
70 #define BRDCFG1_EMI1_SEL_SLOT6  0x40
71 #define BRDCFG1_EMI1_SEL_SLOT7  0x50
72 #define BRDCFG1_EMI1_SEL_SLOT3  0x60
73 #define BRDCFG1_EMI1_SEL_RGMII  0x00
74 #define BRDCFG1_EMI1_EN         0x08
75 #define BRDCFG1_EMI2_SEL_MASK   0x06
76 #define BRDCFG1_EMI2_SEL_SLOT1  0x00
77 #define BRDCFG1_EMI2_SEL_SLOT2  0x02
78
79 #define BRDCFG2_REG_GPIO_SEL    0x20
80
81 /* SGMII */
82 #define PHY_BASE_ADDR           0x00
83 #define REGNUM                  0x00
84 #define PORT_NUM_FM1            0x04
85 #define PORT_NUM_FM2            0x02
86
87 /*
88  * BRDCFG1 mask and value for each MAC
89  *
90  * This array contains the BRDCFG1 values (in mask/val format) that route the
91  * MDIO bus to a particular RGMII or SGMII PHY.
92  */
93 static struct {
94         u8 mask;
95         u8 val;
96 } mdio_mux[NUM_FM_PORTS];
97
98 /*
99  * Mapping of all 18 SERDES lanes to board slots. A value of '0' here means
100  * that the mapping must be determined dynamically, or that the lane maps to
101  * something other than a board slot
102  */
103 static u8 lane_to_slot[] = {
104         7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0
105 };
106
107 /*
108  * Set the board muxing for a given MAC
109  *
110  * The MDIO layer calls this function every time it wants to talk to a PHY.
111  */
112 void super_hydra_mux_mdio(u8 mask, u8 val)
113 {
114         clrsetbits_8(&pixis->brdcfg1, mask, val);
115 }
116
117 struct super_hydra_mdio {
118         u8 mask;
119         u8 val;
120         struct mii_dev *realbus;
121 };
122
123 static int super_hydra_mdio_read(struct mii_dev *bus, int addr, int devad,
124                                 int regnum)
125 {
126         struct super_hydra_mdio *priv = bus->priv;
127
128         super_hydra_mux_mdio(priv->mask, priv->val);
129
130         return priv->realbus->read(priv->realbus, addr, devad, regnum);
131 }
132
133 static int super_hydra_mdio_write(struct mii_dev *bus, int addr, int devad,
134                                 int regnum, u16 value)
135 {
136         struct super_hydra_mdio *priv = bus->priv;
137
138         super_hydra_mux_mdio(priv->mask, priv->val);
139
140         return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
141 }
142
143 static int super_hydra_mdio_reset(struct mii_dev *bus)
144 {
145         struct super_hydra_mdio *priv = bus->priv;
146
147         return priv->realbus->reset(priv->realbus);
148 }
149
150 static void super_hydra_mdio_set_mux(char *name, u8 mask, u8 val)
151 {
152         struct mii_dev *bus = miiphy_get_dev_by_name(name);
153         struct super_hydra_mdio *priv = bus->priv;
154
155         priv->mask = mask;
156         priv->val = val;
157 }
158
159 static int super_hydra_mdio_init(char *realbusname, char *fakebusname)
160 {
161         struct super_hydra_mdio *hmdio;
162         struct mii_dev *bus = mdio_alloc();
163
164         if (!bus) {
165                 printf("Failed to allocate Hydra MDIO bus\n");
166                 return -1;
167         }
168
169         hmdio = malloc(sizeof(*hmdio));
170         if (!hmdio) {
171                 printf("Failed to allocate Hydra private data\n");
172                 free(bus);
173                 return -1;
174         }
175
176         bus->read = super_hydra_mdio_read;
177         bus->write = super_hydra_mdio_write;
178         bus->reset = super_hydra_mdio_reset;
179         strcpy(bus->name, fakebusname);
180
181         hmdio->realbus = miiphy_get_dev_by_name(realbusname);
182
183         if (!hmdio->realbus) {
184                 printf("No bus with name %s\n", realbusname);
185                 free(bus);
186                 free(hmdio);
187                 return -1;
188         }
189
190         bus->priv = hmdio;
191
192         return mdio_register(bus);
193 }
194
195 /*
196  * Given the following ...
197  *
198  * 1) A pointer to an Fman Ethernet node (as identified by the 'compat'
199  * compatible string and 'addr' physical address)
200  *
201  * 2) An Fman port
202  *
203  * ... update the phy-handle property of the Ethernet node to point to the
204  * right PHY.  This assumes that we already know the PHY for each port.  That
205  * information is stored in mdio_mux[].
206  *
207  * The offset of the Fman Ethernet node is also passed in for convenience, but
208  * it is not used.
209  *
210  * Note that what we call "Fman ports" (enum fm_port) is really an Fman MAC.
211  * Inside the Fman, "ports" are things that connect to MACs.  We only call them
212  * ports in U-Boot because on previous Ethernet devices (e.g. Gianfar), MACs
213  * and ports are the same thing.
214  */
215 void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
216                               enum fm_port port, int offset)
217 {
218         enum srds_prtcl device;
219         int lane, slot, phy;
220         char alias[32];
221
222         /* RGMII and XGMII are already mapped correctly in the DTS */
223
224         if (fm_info_get_enet_if(port) == PHY_INTERFACE_MODE_SGMII) {
225                 device = serdes_device_from_fm_port(port);
226                 lane = serdes_get_first_lane(device);
227                 slot = lane_to_slot[lane];
228                 phy = fm_info_get_phy_address(port);
229
230                 sprintf(alias, "phy_sgmii_slot%u_%x", slot, phy);
231                 fdt_set_phy_handle(fdt, compat, addr, alias);
232         }
233 }
234
235 #define PIXIS_SW2_LANE_23_SEL           0x80
236 #define PIXIS_SW2_LANE_45_SEL           0x40
237 #define PIXIS_SW2_LANE_67_SEL_MASK      0x30
238 #define PIXIS_SW2_LANE_67_SEL_5         0x00
239 #define PIXIS_SW2_LANE_67_SEL_6         0x20
240 #define PIXIS_SW2_LANE_67_SEL_7         0x10
241 #define PIXIS_SW2_LANE_8_SEL            0x08
242 #define PIXIS_SW2_LANE_1617_SEL         0x04
243 #define PIXIS_SW11_LANE_9_SEL           0x04
244 /*
245  * Initialize the lane_to_slot[] array.
246  *
247  * On the P4080DS "Expedition" board, the mapping of SERDES lanes to board
248  * slots is hard-coded.  On the Hydra board, however, the mapping is controlled
249  * by board switch SW2, so the lane_to_slot[] array needs to be dynamically
250  * initialized.
251  */
252 static void initialize_lane_to_slot(void)
253 {
254         u8 sw2 = in_8(&PIXIS_SW(2));
255         /* SW11 appears in the programming model as SW9 */
256         u8 sw11 = in_8(&PIXIS_SW(9));
257
258         lane_to_slot[2] = (sw2 & PIXIS_SW2_LANE_23_SEL) ? 7 : 4;
259         lane_to_slot[3] = lane_to_slot[2];
260
261         lane_to_slot[4] = (sw2 & PIXIS_SW2_LANE_45_SEL) ? 7 : 6;
262         lane_to_slot[5] = lane_to_slot[4];
263
264         switch (sw2 & PIXIS_SW2_LANE_67_SEL_MASK) {
265         case PIXIS_SW2_LANE_67_SEL_5:
266                 lane_to_slot[6] = 5;
267                 break;
268         case PIXIS_SW2_LANE_67_SEL_6:
269                 lane_to_slot[6] = 6;
270                 break;
271         case PIXIS_SW2_LANE_67_SEL_7:
272                 lane_to_slot[6] = 7;
273                 break;
274         }
275         lane_to_slot[7] = lane_to_slot[6];
276
277         lane_to_slot[8] = (sw2 & PIXIS_SW2_LANE_8_SEL) ? 3 : 0;
278         lane_to_slot[9] = (sw11 & PIXIS_SW11_LANE_9_SEL) ? 0 : 3;
279
280         lane_to_slot[16] = (sw2 & PIXIS_SW2_LANE_1617_SEL) ? 1 : 0;
281         lane_to_slot[17] = lane_to_slot[16];
282 }
283
284 #endif /* #ifdef CONFIG_FMAN_ENET */
285
286 /*
287  * Configure the status for the virtual MDIO nodes
288  *
289  * Rather than create the virtual MDIO nodes from scratch for each active
290  * virtual MDIO, we expect the DTS to have the nodes defined already, and we
291  * only enable the ones that are actually active.
292  *
293  * We assume that the DTS already hard-codes the status for all the
294  * virtual MDIO nodes to "disabled", so all we need to do is enable the
295  * active ones.
296  */
297 void fdt_fixup_board_enet(void *fdt)
298 {
299 #ifdef CONFIG_FMAN_ENET
300         enum fm_port i;
301         int lane, slot;
302
303         for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
304                 int idx = i - FM1_DTSEC1;
305
306                 switch (fm_info_get_enet_if(i)) {
307                 case PHY_INTERFACE_MODE_SGMII:
308                         lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
309                         if (lane >= 0) {
310                                 char alias[32];
311
312                                 slot = lane_to_slot[lane];
313                                 sprintf(alias, "hydra_sg_slot%u", slot);
314                                 fdt_status_okay_by_alias(fdt, alias);
315                                 debug("Enabled MDIO node %s (slot %i)\n",
316                                       alias, slot);
317                         }
318                         break;
319                 case PHY_INTERFACE_MODE_RGMII:
320                         fdt_status_okay_by_alias(fdt, "hydra_rg");
321                         debug("Enabled MDIO node hydra_rg\n");
322                         break;
323                 default:
324                         break;
325                 }
326         }
327
328         lane = serdes_get_first_lane(XAUI_FM1);
329         if (lane >= 0) {
330                 char alias[32];
331
332                 slot = lane_to_slot[lane];
333                 sprintf(alias, "hydra_xg_slot%u", slot);
334                 fdt_status_okay_by_alias(fdt, alias);
335                 debug("Enabled MDIO node %s (slot %i)\n", alias, slot);
336         }
337
338 #if CONFIG_SYS_NUM_FMAN == 2
339         for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
340                 int idx = i - FM2_DTSEC1;
341
342                 switch (fm_info_get_enet_if(i)) {
343                 case PHY_INTERFACE_MODE_SGMII:
344                         lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
345                         if (lane >= 0) {
346                                 char alias[32];
347
348                                 slot = lane_to_slot[lane];
349                                 sprintf(alias, "hydra_sg_slot%u", slot);
350                                 fdt_status_okay_by_alias(fdt, alias);
351                                 debug("Enabled MDIO node %s (slot %i)\n",
352                                       alias, slot);
353                         }
354                         break;
355                 case PHY_INTERFACE_MODE_RGMII:
356                         fdt_status_okay_by_alias(fdt, "hydra_rg");
357                         debug("Enabled MDIO node hydra_rg\n");
358                         break;
359                 default:
360                         break;
361                 }
362         }
363
364         lane = serdes_get_first_lane(XAUI_FM2);
365         if (lane >= 0) {
366                 char alias[32];
367
368                 slot = lane_to_slot[lane];
369                 sprintf(alias, "hydra_xg_slot%u", slot);
370                 fdt_status_okay_by_alias(fdt, alias);
371                 debug("Enabled MDIO node %s (slot %i)\n", alias, slot);
372         }
373 #endif /* CONFIG_SYS_NUM_FMAN == 2 */
374 #endif /* CONFIG_FMAN_ENET */
375 }
376
377 /*
378  * Mapping of SerDes Protocol to MDIO MUX value and PHY address.
379  *
380  * Fman 1:
381  *       DTSEC1        |   DTSEC2        |   DTSEC3        |   DTSEC4
382  *       Mux     Phy   |   Mux     Phy   |   Mux     Phy   |   Mux     Phy
383  *       Value   Addr  |   Value   Addr  |   Value   Addr  |   Value   Addr
384  * 0x00  2       1c    |   2       1d    |   2       1e    |   2       1f
385  * 0x01                |                 |   6       1c    |
386  * 0x02                |                 |   3       1c    |   3       1d
387  * 0x03  2       1c    |   2       1d    |   2       1e    |   2       1f
388  * 0x04  2       1c    |   2       1d    |   2       1e    |   2       1f
389  * 0x05                |                 |   3       1c    |   3       1d
390  * 0x06  2       1c    |   2       1d    |   2       1e    |   2       1f
391  * 0x07                |                 |   6       1c    |
392  * 0x11  2       1c    |   2       1d    |   2       1e    |   2       1f
393  * 0x2a  2             |                 |   2       1e    |   2       1f
394  * 0x34  6       1c    |   6       1d    |   4       1e    |   4       1f
395  * 0x35                |                 |   3       1c    |   3       1d
396  * 0x36  6       1c    |   6       1d    |   4       1e    |   4       1f
397  *                     |                 |                 |
398  * Fman  2:            |                 |                 |
399  *       DTSEC1        |   DTSEC2        |   DTSEC3        |   DTSEC4
400  *       EMI1          |   EMI1          |   EMI1          |   EMI1
401  *       Mux     Phy   |   Mux     Phy   |   Mux     Phy   |   Mux     Phy
402  *       Value   Addr  |   Value   Addr  |   Value   Addr  |   Value   Addr
403  * 0x00                |                 |   6       1c    |   6       1d
404  * 0x01                |                 |                 |
405  * 0x02                |                 |   6       1c    |   6       1d
406  * 0x03  3       1c    |   3       1d    |   6       1c    |   6       1d
407  * 0x04  3       1c    |   3       1d    |   6       1c    |   6       1d
408  * 0x05                |                 |   6       1c    |   6       1d
409  * 0x06                |                 |   6       1c    |   6       1d
410  * 0x07                |                 |                 |
411  * 0x11                |                 |                 |
412  * 0x2a                |                 |                 |
413  * 0x34                |                 |                 |
414  * 0x35                |                 |                 |
415  * 0x36                |                 |                 |
416  */
417
418 int board_eth_init(struct bd_info *bis)
419 {
420 #ifdef CONFIG_FMAN_ENET
421         struct fsl_pq_mdio_info dtsec_mdio_info;
422         struct tgec_mdio_info tgec_mdio_info;
423         unsigned int i, slot;
424         int lane;
425         struct mii_dev *bus;
426         int qsgmii;
427         int phy_real_addr;
428         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
429         int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
430                                 FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
431
432         printf("Initializing Fman\n");
433
434         initialize_lane_to_slot();
435
436         /* We want to use the PIXIS to configure MUX routing, not GPIOs. */
437         setbits_8(&pixis->brdcfg2, BRDCFG2_REG_GPIO_SEL);
438
439         memset(mdio_mux, 0, sizeof(mdio_mux));
440
441         dtsec_mdio_info.regs =
442                 (struct tsec_mii_mng *)CONFIG_SYS_FM1_DTSEC1_MDIO_ADDR;
443         dtsec_mdio_info.name = DEFAULT_FM_MDIO_NAME;
444
445         /* Register the real 1G MDIO bus */
446         fsl_pq_mdio_init(bis, &dtsec_mdio_info);
447
448         tgec_mdio_info.regs =
449                 (struct tgec_mdio_controller *)CONFIG_SYS_FM1_TGEC_MDIO_ADDR;
450         tgec_mdio_info.name = DEFAULT_FM_TGEC_MDIO_NAME;
451
452         /* Register the real 10G MDIO bus */
453         fm_tgec_mdio_init(bis, &tgec_mdio_info);
454
455         /* Register the three virtual MDIO front-ends */
456         super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
457                                 "SUPER_HYDRA_RGMII_MDIO");
458         super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
459                                 "SUPER_HYDRA_FM1_SGMII_MDIO");
460         super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
461                                 "SUPER_HYDRA_FM2_SGMII_MDIO");
462         super_hydra_mdio_init(DEFAULT_FM_MDIO_NAME,
463                               "SUPER_HYDRA_FM3_SGMII_MDIO");
464         super_hydra_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME,
465                                 "SUPER_HYDRA_FM1_TGEC_MDIO");
466         super_hydra_mdio_init(DEFAULT_FM_TGEC_MDIO_NAME,
467                                 "SUPER_HYDRA_FM2_TGEC_MDIO");
468
469         /*
470          * Program the DTSEC PHY addresses assuming that they are all SGMII.
471          * For any DTSEC that's RGMII, we'll override its PHY address later.
472          * We assume that DTSEC5 is only used for RGMII.
473          */
474         fm_info_set_phy_address(FM1_DTSEC1, CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
475         fm_info_set_phy_address(FM1_DTSEC2, CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
476         fm_info_set_phy_address(FM1_10GEC1, CONFIG_SYS_FM2_10GEC1_PHY_ADDR);
477
478 #if (CONFIG_SYS_NUM_FMAN == 2)
479         fm_info_set_phy_address(FM2_DTSEC1, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
480         fm_info_set_phy_address(FM2_DTSEC2, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
481         fm_info_set_phy_address(FM2_DTSEC3, CONFIG_SYS_FM2_DTSEC1_PHY_ADDR);
482         fm_info_set_phy_address(FM2_DTSEC4, CONFIG_SYS_FM2_DTSEC2_PHY_ADDR);
483         fm_info_set_phy_address(FM2_10GEC1, CONFIG_SYS_FM1_10GEC1_PHY_ADDR);
484 #endif
485
486         switch (srds_prtcl) {
487         case 0:
488         case 3:
489         case 4:
490         case 6:
491         case 0x11:
492         case 0x2a:
493         case 0x34:
494         case 0x36:
495                 fm_info_set_phy_address(FM1_DTSEC3,
496                                         CONFIG_SYS_FM1_DTSEC3_PHY_ADDR);
497                 fm_info_set_phy_address(FM1_DTSEC4,
498                                         CONFIG_SYS_FM1_DTSEC4_PHY_ADDR);
499                 break;
500         case 1:
501         case 2:
502         case 5:
503         case 7:
504         case 0x35:
505                 fm_info_set_phy_address(FM1_DTSEC3,
506                                         CONFIG_SYS_FM1_DTSEC1_PHY_ADDR);
507                 fm_info_set_phy_address(FM1_DTSEC4,
508                                         CONFIG_SYS_FM1_DTSEC2_PHY_ADDR);
509                 break;
510         default:
511                 printf("Fman:  Unsupport SerDes Protocol 0x%02x\n", srds_prtcl);
512                 break;
513         }
514
515         for (i = FM1_DTSEC1; i < FM1_DTSEC1 + CONFIG_SYS_NUM_FM1_DTSEC; i++) {
516                 int idx = i - FM1_DTSEC1;
517
518                 switch (fm_info_get_enet_if(i)) {
519                 case PHY_INTERFACE_MODE_SGMII:
520                         lane = serdes_get_first_lane(SGMII_FM1_DTSEC1 + idx);
521                         if (lane < 0)
522                                 break;
523                         slot = lane_to_slot[lane];
524                         mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
525                         debug("FM1@DTSEC%u expects SGMII in slot %u\n",
526                               idx + 1, slot);
527                         switch (slot) {
528                         case 1:
529                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT1 |
530                                                 BRDCFG1_EMI1_EN;
531                                 break;
532                         case 2:
533                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT2 |
534                                                 BRDCFG1_EMI1_EN;
535                                 break;
536                         case 3:
537                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT3 |
538                                                 BRDCFG1_EMI1_EN;
539                                 break;
540                         case 5:
541                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT5 |
542                                                 BRDCFG1_EMI1_EN;
543                                 break;
544                         case 6:
545                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT6 |
546                                                 BRDCFG1_EMI1_EN;
547                                 break;
548                         case 7:
549                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT7 |
550                                                 BRDCFG1_EMI1_EN;
551                                 break;
552                         };
553
554                         super_hydra_mdio_set_mux("SUPER_HYDRA_FM1_SGMII_MDIO",
555                                         mdio_mux[i].mask, mdio_mux[i].val);
556                         fm_info_set_mdio(i,
557                         miiphy_get_dev_by_name("SUPER_HYDRA_FM1_SGMII_MDIO"));
558                         break;
559                 case PHY_INTERFACE_MODE_RGMII:
560                         /*
561                          * FM1 DTSEC5 is routed via EC1 to the first on-board
562                          * RGMII port. FM2 DTSEC5 is routed via EC2 to the
563                          * second on-board RGMII port. The other DTSECs cannot
564                          * be routed to RGMII.
565                          */
566                         debug("FM1@DTSEC%u is RGMII at address %u\n",
567                               idx + 1, 0);
568                         fm_info_set_phy_address(i, 0);
569                         mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
570                         mdio_mux[i].val  = BRDCFG1_EMI1_SEL_RGMII |
571                                            BRDCFG1_EMI1_EN;
572                         super_hydra_mdio_set_mux("SUPER_HYDRA_RGMII_MDIO",
573                                         mdio_mux[i].mask, mdio_mux[i].val);
574                         fm_info_set_mdio(i,
575                                 miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO"));
576                         break;
577                 case PHY_INTERFACE_MODE_NONE:
578                         fm_info_set_phy_address(i, 0);
579                         break;
580                 default:
581                         printf("Fman1: DTSEC%u set to unknown interface %i\n",
582                                idx + 1, fm_info_get_enet_if(i));
583                         fm_info_set_phy_address(i, 0);
584                         break;
585                 }
586         }
587
588         bus = miiphy_get_dev_by_name("SUPER_HYDRA_FM1_SGMII_MDIO");
589         qsgmii = is_qsgmii_riser_card(bus, PHY_BASE_ADDR, PORT_NUM_FM1, REGNUM);
590
591         if (qsgmii) {
592                 for (i = FM1_DTSEC1; i < FM1_DTSEC1 + PORT_NUM_FM1; i++) {
593                         if (fm_info_get_enet_if(i) ==
594                                         PHY_INTERFACE_MODE_SGMII) {
595                                 phy_real_addr = PHY_BASE_ADDR + i - FM1_DTSEC1;
596                                 fm_info_set_phy_address(i, phy_real_addr);
597                         }
598                 }
599                 switch (srds_prtcl) {
600                 case 0x00:
601                 case 0x03:
602                 case 0x04:
603                 case 0x06:
604                 case 0x11:
605                 case 0x2a:
606                 case 0x34:
607                 case 0x36:
608                         fm_info_set_phy_address(FM1_DTSEC3, PHY_BASE_ADDR + 2);
609                         fm_info_set_phy_address(FM1_DTSEC4, PHY_BASE_ADDR + 3);
610                         break;
611                 case 0x01:
612                 case 0x02:
613                 case 0x05:
614                 case 0x07:
615                 case 0x35:
616                         fm_info_set_phy_address(FM1_DTSEC3, PHY_BASE_ADDR + 0);
617                         fm_info_set_phy_address(FM1_DTSEC4, PHY_BASE_ADDR + 1);
618                         break;
619                 default:
620                         break;
621                 }
622         }
623
624         /*
625          * For 10G, we only support one XAUI card per Fman.  If present, then we
626          * force its routing and never touch those bits again, which removes the
627          * need for Linux to do any muxing.  This works because of the way
628          * BRDCFG1 is defined, but it's a bit hackish.
629          *
630          * The PHY address for the XAUI card depends on which slot it's in. The
631          * macros we use imply that the PHY address is based on which FM, but
632          * that's not true.  On the P4080DS, FM1 could only use XAUI in slot 5,
633          * and FM2 could only use a XAUI in slot 4.  On the Hydra board, we
634          * check the actual slot and just use the macros as-is, even though
635          * the P3041 and P5020 only have one Fman.
636          */
637         lane = serdes_get_first_lane(XAUI_FM1);
638         if (lane >= 0) {
639                 debug("FM1@TGEC1 expects XAUI in slot %u\n", lane_to_slot[lane]);
640                 mdio_mux[i].mask = BRDCFG1_EMI2_SEL_MASK;
641                 mdio_mux[i].val = BRDCFG1_EMI2_SEL_SLOT2;
642                 super_hydra_mdio_set_mux("SUPER_HYDRA_FM1_TGEC_MDIO",
643                                         mdio_mux[i].mask, mdio_mux[i].val);
644         }
645
646         fm_info_set_mdio(FM1_10GEC1,
647                         miiphy_get_dev_by_name("SUPER_HYDRA_FM1_TGEC_MDIO"));
648
649 #if (CONFIG_SYS_NUM_FMAN == 2)
650         for (i = FM2_DTSEC1; i < FM2_DTSEC1 + CONFIG_SYS_NUM_FM2_DTSEC; i++) {
651                 int idx = i - FM2_DTSEC1;
652
653                 switch (fm_info_get_enet_if(i)) {
654                 case PHY_INTERFACE_MODE_SGMII:
655                         lane = serdes_get_first_lane(SGMII_FM2_DTSEC1 + idx);
656                         if (lane < 0)
657                                 break;
658                         slot = lane_to_slot[lane];
659                         mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
660                         debug("FM2@DTSEC%u expects SGMII in slot %u\n",
661                               idx + 1, slot);
662                         switch (slot) {
663                         case 1:
664                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT1 |
665                                                 BRDCFG1_EMI1_EN;
666                                 break;
667                         case 2:
668                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT2 |
669                                                 BRDCFG1_EMI1_EN;
670                                 break;
671                         case 3:
672                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT3 |
673                                                 BRDCFG1_EMI1_EN;
674                                 break;
675                         case 5:
676                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT5 |
677                                                 BRDCFG1_EMI1_EN;
678                                 break;
679                         case 6:
680                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT6 |
681                                                 BRDCFG1_EMI1_EN;
682                                 break;
683                         case 7:
684                                 mdio_mux[i].val = BRDCFG1_EMI1_SEL_SLOT7 |
685                                                 BRDCFG1_EMI1_EN;
686                                 break;
687                         };
688
689                         if (i == FM2_DTSEC1 || i == FM2_DTSEC2) {
690                                 super_hydra_mdio_set_mux(
691                                                 "SUPER_HYDRA_FM3_SGMII_MDIO",
692                                                 mdio_mux[i].mask,
693                                                 mdio_mux[i].val);
694                                 fm_info_set_mdio(i, miiphy_get_dev_by_name(
695                                                 "SUPER_HYDRA_FM3_SGMII_MDIO"));
696                         } else {
697                                 super_hydra_mdio_set_mux(
698                                                 "SUPER_HYDRA_FM2_SGMII_MDIO",
699                                                 mdio_mux[i].mask,
700                                                 mdio_mux[i].val);
701                                 fm_info_set_mdio(i, miiphy_get_dev_by_name(
702                                                 "SUPER_HYDRA_FM2_SGMII_MDIO"));
703                         }
704
705                         break;
706                 case PHY_INTERFACE_MODE_RGMII:
707                         /*
708                          * FM1 DTSEC5 is routed via EC1 to the first on-board
709                          * RGMII port. FM2 DTSEC5 is routed via EC2 to the
710                          * second on-board RGMII port. The other DTSECs cannot
711                          * be routed to RGMII.
712                          */
713                         debug("FM2@DTSEC%u is RGMII at address %u\n",
714                               idx + 1, 1);
715                         fm_info_set_phy_address(i, 1);
716                         mdio_mux[i].mask = BRDCFG1_EMI1_SEL_MASK;
717                         mdio_mux[i].val  = BRDCFG1_EMI1_SEL_RGMII |
718                                         BRDCFG1_EMI1_EN;
719                         super_hydra_mdio_set_mux("SUPER_HYDRA_RGMII_MDIO",
720                                         mdio_mux[i].mask, mdio_mux[i].val);
721                         fm_info_set_mdio(i,
722                         miiphy_get_dev_by_name("SUPER_HYDRA_RGMII_MDIO"));
723                         break;
724                 case PHY_INTERFACE_MODE_NONE:
725                         fm_info_set_phy_address(i, 0);
726                         break;
727                 default:
728                         printf("Fman2: DTSEC%u set to unknown interface %i\n",
729                                 idx + 1, fm_info_get_enet_if(i));
730                         fm_info_set_phy_address(i, 0);
731                         break;
732                 }
733         }
734
735         bus = miiphy_get_dev_by_name("SUPER_HYDRA_FM2_SGMII_MDIO");
736         set_sgmii_phy(bus, FM2_DTSEC3, PORT_NUM_FM2, PHY_BASE_ADDR);
737         bus = miiphy_get_dev_by_name("SUPER_HYDRA_FM3_SGMII_MDIO");
738         set_sgmii_phy(bus, FM2_DTSEC1, PORT_NUM_FM2, PHY_BASE_ADDR);
739
740         /*
741          * For 10G, we only support one XAUI card per Fman.  If present, then we
742          * force its routing and never touch those bits again, which removes the
743          * need for Linux to do any muxing.  This works because of the way
744          * BRDCFG1 is defined, but it's a bit hackish.
745          *
746          * The PHY address for the XAUI card depends on which slot it's in. The
747          * macros we use imply that the PHY address is based on which FM, but
748          * that's not true.  On the P4080DS, FM1 could only use XAUI in slot 5,
749          * and FM2 could only use a XAUI in slot 4.  On the Hydra board, we
750          * check the actual slot and just use the macros as-is, even though
751          * the P3041 and P5020 only have one Fman.
752          */
753         lane = serdes_get_first_lane(XAUI_FM2);
754         if (lane >= 0) {
755                 debug("FM2@TGEC1 expects XAUI in slot %u\n", lane_to_slot[lane]);
756                 mdio_mux[i].mask = BRDCFG1_EMI2_SEL_MASK;
757                 mdio_mux[i].val = BRDCFG1_EMI2_SEL_SLOT1;
758                 super_hydra_mdio_set_mux("SUPER_HYDRA_FM2_TGEC_MDIO",
759                                         mdio_mux[i].mask, mdio_mux[i].val);
760         }
761
762         fm_info_set_mdio(FM2_10GEC1,
763                         miiphy_get_dev_by_name("SUPER_HYDRA_FM2_TGEC_MDIO"));
764
765 #endif
766
767         cpu_eth_init(bis);
768 #endif
769
770         return pci_eth_init(bis);
771 }