Lines Matching +full:mdio +full:- +full:bus
1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * Lynx PCS MDIO helpers
6 #include <linux/mdio.h>
8 #include <linux/pcs-lynx.h>
25 struct mdio_device *mdio; member
36 #define lynx_to_phylink_pcs(lynx) (&(lynx)->pcs)
41 struct mii_bus *bus = pcs->bus; in lynx_pcs_get_state_usxgmii() local
42 int addr = pcs->addr; in lynx_pcs_get_state_usxgmii()
45 status = mdiobus_c45_read(bus, addr, MDIO_MMD_VEND2, MII_BMSR); in lynx_pcs_get_state_usxgmii()
49 state->link = !!(status & MDIO_STAT1_LSTATUS); in lynx_pcs_get_state_usxgmii()
50 state->an_complete = !!(status & MDIO_AN_STAT1_COMPLETE); in lynx_pcs_get_state_usxgmii()
51 if (!state->link || !state->an_complete) in lynx_pcs_get_state_usxgmii()
54 lpa = mdiobus_c45_read(bus, addr, MDIO_MMD_VEND2, MII_LPA); in lynx_pcs_get_state_usxgmii()
68 state->link = false; in lynx_pcs_get_state_2500basex()
72 state->link = !!(bmsr & BMSR_LSTATUS); in lynx_pcs_get_state_2500basex()
73 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); in lynx_pcs_get_state_2500basex()
74 if (!state->link) in lynx_pcs_get_state_2500basex()
77 state->speed = SPEED_2500; in lynx_pcs_get_state_2500basex()
78 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; in lynx_pcs_get_state_2500basex()
79 state->duplex = DUPLEX_FULL; in lynx_pcs_get_state_2500basex()
87 switch (state->interface) { in lynx_pcs_get_state()
91 phylink_mii_c22_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
94 lynx_pcs_get_state_2500basex(lynx->mdio, state); in lynx_pcs_get_state()
97 lynx_pcs_get_state_usxgmii(lynx->mdio, state); in lynx_pcs_get_state()
100 phylink_mii_c45_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
106 dev_dbg(&lynx->mdio->dev, in lynx_pcs_get_state()
108 phy_modes(state->interface), in lynx_pcs_get_state()
109 phy_speed_to_str(state->speed), in lynx_pcs_get_state()
110 phy_duplex_to_str(state->duplex), in lynx_pcs_get_state()
111 state->link, state->an_complete); in lynx_pcs_get_state()
155 struct mii_bus *bus = pcs->bus; in lynx_pcs_config_usxgmii() local
156 int addr = pcs->addr; in lynx_pcs_config_usxgmii()
159 dev_err(&pcs->dev, "USXGMII only supports in-band AN for now\n"); in lynx_pcs_config_usxgmii()
160 return -EOPNOTSUPP; in lynx_pcs_config_usxgmii()
164 return mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_ADVERTISE, in lynx_pcs_config_usxgmii()
180 return lynx_pcs_config_giga(lynx->mdio, ifmode, advertising, in lynx_pcs_config()
184 dev_err(&lynx->mdio->dev, in lynx_pcs_config()
186 return -EOPNOTSUPP; in lynx_pcs_config()
190 return lynx_pcs_config_usxgmii(lynx->mdio, advertising, in lynx_pcs_config()
196 return -EOPNOTSUPP; in lynx_pcs_config()
206 phylink_mii_c22_pcs_an_restart(lynx->mdio); in lynx_pcs_an_restart()
216 * when not operating on in-band mode in lynx_pcs_link_up_sgmii()
238 dev_err(&pcs->dev, "Invalid PCS speed %d\n", speed); in lynx_pcs_link_up_sgmii()
248 /* 2500Base-X is SerDes protocol 7 on Felix and 6 on ENETC. It is a SerDes lane
250 * auto-negotiation of any link parameters. Electrically it is compatible with
254 * - Downgrading the link speed by duplicating symbols
255 * - Auto-negotiation
260 * AN, we call this PHY interface type 2500Base-X. In case a PHY negotiates a
261 * lower link speed on line side, the system-side interface remains fixed at
271 dev_err(&pcs->dev, "AN not supported for 2500BaseX\n"); in lynx_pcs_link_up_2500basex()
293 lynx_pcs_link_up_sgmii(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
296 lynx_pcs_link_up_2500basex(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
299 /* At the moment, only in-band AN is supported for USXGMII in lynx_pcs_link_up()
315 static struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio) in lynx_pcs_create() argument
321 return ERR_PTR(-ENOMEM); in lynx_pcs_create()
323 mdio_device_get(mdio); in lynx_pcs_create()
324 lynx->mdio = mdio; in lynx_pcs_create()
325 lynx->pcs.ops = &lynx_pcs_phylink_ops; in lynx_pcs_create()
326 lynx->pcs.neg_mode = true; in lynx_pcs_create()
327 lynx->pcs.poll = true; in lynx_pcs_create()
332 struct phylink_pcs *lynx_pcs_create_mdiodev(struct mii_bus *bus, int addr) in lynx_pcs_create_mdiodev() argument
334 struct mdio_device *mdio; in lynx_pcs_create_mdiodev() local
337 mdio = mdio_device_create(bus, addr); in lynx_pcs_create_mdiodev()
338 if (IS_ERR(mdio)) in lynx_pcs_create_mdiodev()
339 return ERR_CAST(mdio); in lynx_pcs_create_mdiodev()
341 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_mdiodev()
344 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_mdiodev()
347 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_mdiodev()
349 mdio_device_put(mdio); in lynx_pcs_create_mdiodev()
360 * -ENODEV if the fwnode is marked unavailable
361 * -EPROBE_DEFER if we fail to find the device
362 * -ENOMEM if we fail to allocate memory
367 struct mdio_device *mdio; in lynx_pcs_create_fwnode() local
371 return ERR_PTR(-ENODEV); in lynx_pcs_create_fwnode()
373 mdio = fwnode_mdio_find_device(node); in lynx_pcs_create_fwnode()
374 if (!mdio) in lynx_pcs_create_fwnode()
375 return ERR_PTR(-EPROBE_DEFER); in lynx_pcs_create_fwnode()
377 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_fwnode()
380 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_fwnode()
383 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_fwnode()
385 mdio_device_put(mdio); in lynx_pcs_create_fwnode()
395 mdio_device_put(lynx->mdio); in lynx_pcs_destroy()