2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/arch/fsl_serdes.h>
11 #include <asm/arch-fsl-lsch3/immap_lsch3.h>
15 #include <fsl-mc/ldpaa_wriop.h>
17 #include "../common/qixis.h"
19 #include "ls2085aqds_qixis.h"
22 #ifdef CONFIG_FSL_MC_ENET
23 /* - In LS2085A there are only 16 SERDES lanes, spread across 2 SERDES banks.
24 * Bank 1 -> Lanes A, B, C, D, E, F, G, H
25 * Bank 2 -> Lanes A,B, C, D, E, F, G, H
28 /* Mapping of 16 SERDES lanes to LS2085A QDS board slots. A value of '0' here
29 * means that the mapping must be determined dynamically, or that the lane
30 * maps to something other than a board slot.
33 static u8 lane_to_slot_fsm2[] = {
34 0, 0, 0, 0, 0, 0, 0, 0
37 /* On the Vitesse VSC8234XHG SGMII riser card there are 4 SGMII PHYs
40 static int riser_phy_addr[] = {
41 SGMII_CARD_PORT1_PHY_ADDR,
42 SGMII_CARD_PORT2_PHY_ADDR,
43 SGMII_CARD_PORT3_PHY_ADDR,
44 SGMII_CARD_PORT4_PHY_ADDR,
47 /* Slot2 does not have EMI connections */
48 #define EMI_NONE 0xFFFFFFFF
58 static const char * const mdio_names[] = {
65 DEFAULT_WRIOP_MDIO2_NAME,
68 struct ls2085a_qds_mdio {
70 struct mii_dev *realbus;
73 static const char *ls2085a_qds_mdio_name_for_muxval(u8 muxval)
75 return mdio_names[muxval];
78 struct mii_dev *mii_dev_for_muxval(u8 muxval)
81 const char *name = ls2085a_qds_mdio_name_for_muxval(muxval);
84 printf("No bus for muxval %x\n", muxval);
88 bus = miiphy_get_dev_by_name(name);
91 printf("No bus by name %s\n", name);
98 static void ls2085a_qds_enable_SFP_TX(u8 muxval)
102 brdcfg9 = QIXIS_READ(brdcfg[9]);
103 brdcfg9 &= ~BRDCFG9_SFPTX_MASK;
104 brdcfg9 |= (muxval << BRDCFG9_SFPTX_SHIFT);
105 QIXIS_WRITE(brdcfg[9], brdcfg9);
108 static void ls2085a_qds_mux_mdio(u8 muxval)
113 brdcfg4 = QIXIS_READ(brdcfg[4]);
114 brdcfg4 &= ~BRDCFG4_EMISEL_MASK;
115 brdcfg4 |= (muxval << BRDCFG4_EMISEL_SHIFT);
116 QIXIS_WRITE(brdcfg[4], brdcfg4);
120 static int ls2085a_qds_mdio_read(struct mii_dev *bus, int addr,
121 int devad, int regnum)
123 struct ls2085a_qds_mdio *priv = bus->priv;
125 ls2085a_qds_mux_mdio(priv->muxval);
127 return priv->realbus->read(priv->realbus, addr, devad, regnum);
130 static int ls2085a_qds_mdio_write(struct mii_dev *bus, int addr, int devad,
131 int regnum, u16 value)
133 struct ls2085a_qds_mdio *priv = bus->priv;
135 ls2085a_qds_mux_mdio(priv->muxval);
137 return priv->realbus->write(priv->realbus, addr, devad, regnum, value);
140 static int ls2085a_qds_mdio_reset(struct mii_dev *bus)
142 struct ls2085a_qds_mdio *priv = bus->priv;
144 return priv->realbus->reset(priv->realbus);
147 static int ls2085a_qds_mdio_init(char *realbusname, u8 muxval)
149 struct ls2085a_qds_mdio *pmdio;
150 struct mii_dev *bus = mdio_alloc();
153 printf("Failed to allocate ls2085a_qds MDIO bus\n");
157 pmdio = malloc(sizeof(*pmdio));
159 printf("Failed to allocate ls2085a_qds private data\n");
164 bus->read = ls2085a_qds_mdio_read;
165 bus->write = ls2085a_qds_mdio_write;
166 bus->reset = ls2085a_qds_mdio_reset;
167 sprintf(bus->name, ls2085a_qds_mdio_name_for_muxval(muxval));
169 pmdio->realbus = miiphy_get_dev_by_name(realbusname);
171 if (!pmdio->realbus) {
172 printf("No bus with name %s\n", realbusname);
178 pmdio->muxval = muxval;
181 return mdio_register(bus);
185 * Initialize the dpmac_info array.
188 static void initialize_dpmac_to_slot(void)
190 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
191 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
192 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
193 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
194 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
195 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
196 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
199 switch (serdes1_prtcl) {
201 printf("qds: WRIOP: Supported SerDes Protocol 0x%02x\n",
205 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
210 switch (serdes2_prtcl) {
213 printf("qds: WRIOP: Supported SerDes Protocol 0x%02x\n",
215 lane_to_slot_fsm2[0] = EMI1_SLOT4;
216 lane_to_slot_fsm2[1] = EMI1_SLOT4;
217 lane_to_slot_fsm2[2] = EMI1_SLOT4;
218 lane_to_slot_fsm2[3] = EMI1_SLOT4;
219 /* No MDIO physical connection */
220 lane_to_slot_fsm2[4] = EMI1_SLOT6;
221 lane_to_slot_fsm2[5] = EMI1_SLOT6;
222 lane_to_slot_fsm2[6] = EMI1_SLOT6;
223 lane_to_slot_fsm2[7] = EMI1_SLOT6;
226 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
232 void ls2085a_handle_phy_interface_sgmii(int dpmac_id)
236 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
237 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
238 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
239 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
240 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
241 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
242 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
244 switch (serdes1_prtcl) {
247 switch (serdes2_prtcl) {
250 lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
252 slot = lane_to_slot_fsm2[lane];
260 /* Slot housing a SGMII riser card? */
261 wriop_set_phy_address(dpmac_id,
262 riser_phy_addr[dpmac_id - 9]);
263 dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
264 bus = mii_dev_for_muxval(EMI1_SLOT4);
265 wriop_set_mdio(dpmac_id, bus);
266 dpmac_info[dpmac_id].phydev = phy_connect(
267 dpmac_info[dpmac_id].bus,
268 dpmac_info[dpmac_id].phy_addr,
270 dpmac_info[dpmac_id].enet_if);
271 phy_config(dpmac_info[dpmac_id].phydev);
276 /* Slot housing a SGMII riser card? */
277 wriop_set_phy_address(dpmac_id,
278 riser_phy_addr[dpmac_id - 13]);
279 dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
280 bus = mii_dev_for_muxval(EMI1_SLOT6);
281 wriop_set_mdio(dpmac_id, bus);
286 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
291 void ls2085a_handle_phy_interface_xsgmii(int i)
293 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
294 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
295 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
296 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
298 switch (serdes1_prtcl) {
301 * XFI does not need a PHY to work, but to avoid U-boot use
302 * default PHY address which is zero to a MAC when it found
303 * a MAC has no PHY address, we give a PHY address to XFI
304 * MAC, and should not use a real XAUI PHY address, since
305 * MDIO can access it successfully, and then MDIO thinks
306 * the XAUI card is used for the XFI MAC, which will cause
309 wriop_set_phy_address(i, i + 4);
310 ls2085a_qds_enable_SFP_TX(SFP_TX);
314 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
321 int board_eth_init(bd_t *bis)
324 #ifdef CONFIG_FSL_MC_ENET
325 struct memac_mdio_info *memac_mdio0_info;
326 struct memac_mdio_info *memac_mdio1_info;
329 initialize_dpmac_to_slot();
331 memac_mdio0_info = (struct memac_mdio_info *)malloc(
332 sizeof(struct memac_mdio_info));
333 memac_mdio0_info->regs =
334 (struct memac_mdio_controller *)
335 CONFIG_SYS_FSL_WRIOP1_MDIO1;
336 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
338 /* Register the real MDIO1 bus */
339 fm_memac_mdio_init(bis, memac_mdio0_info);
341 memac_mdio1_info = (struct memac_mdio_info *)malloc(
342 sizeof(struct memac_mdio_info));
343 memac_mdio1_info->regs =
344 (struct memac_mdio_controller *)
345 CONFIG_SYS_FSL_WRIOP1_MDIO2;
346 memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
348 /* Register the real MDIO2 bus */
349 fm_memac_mdio_init(bis, memac_mdio1_info);
351 /* Register the muxing front-ends to the MDIO buses */
352 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
353 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
354 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
355 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
356 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
357 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
359 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
361 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
362 switch (wriop_get_enet_if(i)) {
363 case PHY_INTERFACE_MODE_QSGMII:
365 case PHY_INTERFACE_MODE_SGMII:
366 ls2085a_handle_phy_interface_sgmii(i);
368 case PHY_INTERFACE_MODE_XGMII:
369 ls2085a_handle_phy_interface_xsgmii(i);
376 error = cpu_eth_init(bis);
378 error = pci_eth_init(bis);