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) {
214 printf("qds: WRIOP: Supported SerDes Protocol 0x%02x\n",
216 lane_to_slot_fsm2[0] = EMI1_SLOT4;
217 lane_to_slot_fsm2[1] = EMI1_SLOT4;
218 lane_to_slot_fsm2[2] = EMI1_SLOT4;
219 lane_to_slot_fsm2[3] = EMI1_SLOT4;
220 /* No MDIO physical connection */
221 lane_to_slot_fsm2[4] = EMI1_SLOT6;
222 lane_to_slot_fsm2[5] = EMI1_SLOT6;
223 lane_to_slot_fsm2[6] = EMI1_SLOT6;
224 lane_to_slot_fsm2[7] = EMI1_SLOT6;
227 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
233 void ls2085a_handle_phy_interface_sgmii(int dpmac_id)
237 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
238 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
239 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
240 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
241 int serdes2_prtcl = (in_le32(&gur->rcwsr[28]) &
242 FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK)
243 >> FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
245 switch (serdes1_prtcl) {
248 switch (serdes2_prtcl) {
252 lane = serdes_get_first_lane(FSL_SRDS_2, SGMII9 +
254 slot = lane_to_slot_fsm2[lane];
262 /* Slot housing a SGMII riser card? */
263 wriop_set_phy_address(dpmac_id,
264 riser_phy_addr[dpmac_id - 9]);
265 dpmac_info[dpmac_id].board_mux = EMI1_SLOT4;
266 bus = mii_dev_for_muxval(EMI1_SLOT4);
267 wriop_set_mdio(dpmac_id, bus);
268 dpmac_info[dpmac_id].phydev = phy_connect(
269 dpmac_info[dpmac_id].bus,
270 dpmac_info[dpmac_id].phy_addr,
272 dpmac_info[dpmac_id].enet_if);
273 phy_config(dpmac_info[dpmac_id].phydev);
278 /* Slot housing a SGMII riser card? */
279 wriop_set_phy_address(dpmac_id,
280 riser_phy_addr[dpmac_id - 13]);
281 dpmac_info[dpmac_id].board_mux = EMI1_SLOT6;
282 bus = mii_dev_for_muxval(EMI1_SLOT6);
283 wriop_set_mdio(dpmac_id, bus);
288 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
293 void ls2085a_handle_phy_interface_xsgmii(int i)
295 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
296 int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
297 FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
298 >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
300 switch (serdes1_prtcl) {
303 * XFI does not need a PHY to work, but to avoid U-boot use
304 * default PHY address which is zero to a MAC when it found
305 * a MAC has no PHY address, we give a PHY address to XFI
306 * MAC, and should not use a real XAUI PHY address, since
307 * MDIO can access it successfully, and then MDIO thinks
308 * the XAUI card is used for the XFI MAC, which will cause
311 wriop_set_phy_address(i, i + 4);
312 ls2085a_qds_enable_SFP_TX(SFP_TX);
316 printf("qds: WRIOP: Unsupported SerDes Protocol 0x%02x\n",
323 int board_eth_init(bd_t *bis)
326 #ifdef CONFIG_FSL_MC_ENET
327 struct memac_mdio_info *memac_mdio0_info;
328 struct memac_mdio_info *memac_mdio1_info;
331 initialize_dpmac_to_slot();
333 memac_mdio0_info = (struct memac_mdio_info *)malloc(
334 sizeof(struct memac_mdio_info));
335 memac_mdio0_info->regs =
336 (struct memac_mdio_controller *)
337 CONFIG_SYS_FSL_WRIOP1_MDIO1;
338 memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
340 /* Register the real MDIO1 bus */
341 fm_memac_mdio_init(bis, memac_mdio0_info);
343 memac_mdio1_info = (struct memac_mdio_info *)malloc(
344 sizeof(struct memac_mdio_info));
345 memac_mdio1_info->regs =
346 (struct memac_mdio_controller *)
347 CONFIG_SYS_FSL_WRIOP1_MDIO2;
348 memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
350 /* Register the real MDIO2 bus */
351 fm_memac_mdio_init(bis, memac_mdio1_info);
353 /* Register the muxing front-ends to the MDIO buses */
354 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT1);
355 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT2);
356 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT3);
357 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT4);
358 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT5);
359 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO1_NAME, EMI1_SLOT6);
361 ls2085a_qds_mdio_init(DEFAULT_WRIOP_MDIO2_NAME, EMI2);
363 for (i = WRIOP1_DPMAC1; i < NUM_WRIOP_PORTS; i++) {
364 switch (wriop_get_enet_if(i)) {
365 case PHY_INTERFACE_MODE_QSGMII:
367 case PHY_INTERFACE_MODE_SGMII:
368 ls2085a_handle_phy_interface_sgmii(i);
370 case PHY_INTERFACE_MODE_XGMII:
371 ls2085a_handle_phy_interface_xsgmii(i);
378 error = cpu_eth_init(bis);
380 error = pci_eth_init(bis);