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)
62 struct mii_bus *bus = pcs->bus; in lynx_pcs_get_state_usxgmii() local
63 int addr = pcs->addr; in lynx_pcs_get_state_usxgmii()
66 status = mdiobus_c45_read(bus, addr, MDIO_MMD_VEND2, MII_BMSR); in lynx_pcs_get_state_usxgmii()
70 state->link = !!(status & MDIO_STAT1_LSTATUS); in lynx_pcs_get_state_usxgmii()
71 state->an_complete = !!(status & MDIO_AN_STAT1_COMPLETE); in lynx_pcs_get_state_usxgmii()
72 if (!state->link || !state->an_complete) in lynx_pcs_get_state_usxgmii()
75 lpa = mdiobus_c45_read(bus, addr, MDIO_MMD_VEND2, MII_LPA); in lynx_pcs_get_state_usxgmii()
89 state->link = false; in lynx_pcs_get_state_2500basex()
93 state->link = !!(bmsr & BMSR_LSTATUS); in lynx_pcs_get_state_2500basex()
94 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); in lynx_pcs_get_state_2500basex()
95 if (!state->link) in lynx_pcs_get_state_2500basex()
98 state->speed = SPEED_2500; in lynx_pcs_get_state_2500basex()
99 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; in lynx_pcs_get_state_2500basex()
100 state->duplex = DUPLEX_FULL; in lynx_pcs_get_state_2500basex()
108 switch (state->interface) { in lynx_pcs_get_state()
112 phylink_mii_c22_pcs_get_state(lynx->mdio, neg_mode, state); in lynx_pcs_get_state()
115 lynx_pcs_get_state_2500basex(lynx->mdio, state); in lynx_pcs_get_state()
118 lynx_pcs_get_state_usxgmii(lynx->mdio, state); in lynx_pcs_get_state()
121 phylink_mii_c45_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
127 dev_dbg(&lynx->mdio->dev, in lynx_pcs_get_state()
129 phy_modes(state->interface), in lynx_pcs_get_state()
130 phy_speed_to_str(state->speed), in lynx_pcs_get_state()
131 phy_duplex_to_str(state->duplex), in lynx_pcs_get_state()
132 state->link, state->an_complete); in lynx_pcs_get_state()
176 struct mii_bus *bus = pcs->bus; in lynx_pcs_config_usxgmii() local
177 int addr = pcs->addr; in lynx_pcs_config_usxgmii()
180 dev_err(&pcs->dev, "USXGMII only supports in-band AN for now\n"); in lynx_pcs_config_usxgmii()
181 return -EOPNOTSUPP; in lynx_pcs_config_usxgmii()
185 return mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_ADVERTISE, in lynx_pcs_config_usxgmii()
201 return lynx_pcs_config_giga(lynx->mdio, ifmode, advertising, in lynx_pcs_config()
205 dev_err(&lynx->mdio->dev, in lynx_pcs_config()
207 return -EOPNOTSUPP; in lynx_pcs_config()
211 return lynx_pcs_config_usxgmii(lynx->mdio, advertising, in lynx_pcs_config()
217 return -EOPNOTSUPP; in lynx_pcs_config()
227 phylink_mii_c22_pcs_an_restart(lynx->mdio); in lynx_pcs_an_restart()
237 * when not operating on in-band mode in lynx_pcs_link_up_sgmii()
259 dev_err(&pcs->dev, "Invalid PCS speed %d\n", speed); in lynx_pcs_link_up_sgmii()
269 /* 2500Base-X is SerDes protocol 7 on Felix and 6 on ENETC. It is a SerDes lane
271 * auto-negotiation of any link parameters. Electrically it is compatible with
275 * - Downgrading the link speed by duplicating symbols
276 * - Auto-negotiation
281 * AN, we call this PHY interface type 2500Base-X. In case a PHY negotiates a
282 * lower link speed on line side, the system-side interface remains fixed at
292 dev_err(&pcs->dev, "AN not supported for 2500BaseX\n"); in lynx_pcs_link_up_2500basex()
314 lynx_pcs_link_up_sgmii(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
317 lynx_pcs_link_up_2500basex(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
320 /* At the moment, only in-band AN is supported for USXGMII in lynx_pcs_link_up()
346 static struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio) in lynx_pcs_create() argument
353 return ERR_PTR(-ENOMEM); in lynx_pcs_create()
355 mdio_device_get(mdio); in lynx_pcs_create()
356 lynx->mdio = mdio; in lynx_pcs_create()
357 lynx->pcs.ops = &lynx_pcs_phylink_ops; in lynx_pcs_create()
358 lynx->pcs.neg_mode = true; in lynx_pcs_create()
359 lynx->pcs.poll = true; in lynx_pcs_create()
362 __set_bit(lynx_interfaces[i], lynx->pcs.supported_interfaces); in lynx_pcs_create()
367 struct phylink_pcs *lynx_pcs_create_mdiodev(struct mii_bus *bus, int addr) in lynx_pcs_create_mdiodev() argument
369 struct mdio_device *mdio; in lynx_pcs_create_mdiodev() local
372 mdio = mdio_device_create(bus, addr); in lynx_pcs_create_mdiodev()
373 if (IS_ERR(mdio)) in lynx_pcs_create_mdiodev()
374 return ERR_CAST(mdio); in lynx_pcs_create_mdiodev()
376 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_mdiodev()
379 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_mdiodev()
382 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_mdiodev()
384 mdio_device_put(mdio); in lynx_pcs_create_mdiodev()
395 * -ENODEV if the fwnode is marked unavailable
396 * -EPROBE_DEFER if we fail to find the device
397 * -ENOMEM if we fail to allocate memory
402 struct mdio_device *mdio; in lynx_pcs_create_fwnode() local
406 return ERR_PTR(-ENODEV); in lynx_pcs_create_fwnode()
408 mdio = fwnode_mdio_find_device(node); in lynx_pcs_create_fwnode()
409 if (!mdio) in lynx_pcs_create_fwnode()
410 return ERR_PTR(-EPROBE_DEFER); in lynx_pcs_create_fwnode()
412 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_fwnode()
415 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_fwnode()
418 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_fwnode()
420 mdio_device_put(mdio); in lynx_pcs_create_fwnode()
430 mdio_device_put(lynx->mdio); in lynx_pcs_destroy()