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