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()
69 state->link = false; in lynx_pcs_get_state_2500basex()
73 state->link = !!(bmsr & BMSR_LSTATUS); in lynx_pcs_get_state_2500basex()
74 state->an_complete = !!(bmsr & BMSR_ANEGCOMPLETE); in lynx_pcs_get_state_2500basex()
75 if (!state->link) in lynx_pcs_get_state_2500basex()
78 state->speed = SPEED_2500; in lynx_pcs_get_state_2500basex()
79 state->pause |= MLO_PAUSE_TX | MLO_PAUSE_RX; in lynx_pcs_get_state_2500basex()
80 state->duplex = DUPLEX_FULL; in lynx_pcs_get_state_2500basex()
88 switch (state->interface) { in lynx_pcs_get_state()
92 phylink_mii_c22_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
95 lynx_pcs_get_state_2500basex(lynx->mdio, state); in lynx_pcs_get_state()
98 lynx_pcs_get_state_usxgmii(lynx->mdio, state); in lynx_pcs_get_state()
101 phylink_mii_c45_pcs_get_state(lynx->mdio, state); in lynx_pcs_get_state()
107 dev_dbg(&lynx->mdio->dev, in lynx_pcs_get_state()
109 phy_modes(state->interface), in lynx_pcs_get_state()
110 phy_speed_to_str(state->speed), in lynx_pcs_get_state()
111 phy_duplex_to_str(state->duplex), in lynx_pcs_get_state()
112 state->link, state->an_complete); in lynx_pcs_get_state()
156 struct mii_bus *bus = pcs->bus; in lynx_pcs_config_usxgmii() local
157 int addr = pcs->addr; in lynx_pcs_config_usxgmii()
160 dev_err(&pcs->dev, "USXGMII only supports in-band AN for now\n"); in lynx_pcs_config_usxgmii()
161 return -EOPNOTSUPP; in lynx_pcs_config_usxgmii()
165 return mdiobus_c45_write(bus, addr, MDIO_MMD_VEND2, MII_ADVERTISE, in lynx_pcs_config_usxgmii()
181 return lynx_pcs_config_giga(lynx->mdio, ifmode, advertising, in lynx_pcs_config()
185 dev_err(&lynx->mdio->dev, in lynx_pcs_config()
187 return -EOPNOTSUPP; in lynx_pcs_config()
191 return lynx_pcs_config_usxgmii(lynx->mdio, advertising, in lynx_pcs_config()
197 return -EOPNOTSUPP; in lynx_pcs_config()
207 phylink_mii_c22_pcs_an_restart(lynx->mdio); in lynx_pcs_an_restart()
217 * when not operating on in-band mode in lynx_pcs_link_up_sgmii()
239 dev_err(&pcs->dev, "Invalid PCS speed %d\n", speed); in lynx_pcs_link_up_sgmii()
249 /* 2500Base-X is SerDes protocol 7 on Felix and 6 on ENETC. It is a SerDes lane
251 * auto-negotiation of any link parameters. Electrically it is compatible with
255 * - Downgrading the link speed by duplicating symbols
256 * - Auto-negotiation
261 * AN, we call this PHY interface type 2500Base-X. In case a PHY negotiates a
262 * lower link speed on line side, the system-side interface remains fixed at
272 dev_err(&pcs->dev, "AN not supported for 2500BaseX\n"); in lynx_pcs_link_up_2500basex()
294 lynx_pcs_link_up_sgmii(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
297 lynx_pcs_link_up_2500basex(lynx->mdio, neg_mode, speed, duplex); in lynx_pcs_link_up()
300 /* At the moment, only in-band AN is supported for USXGMII in lynx_pcs_link_up()
316 static struct phylink_pcs *lynx_pcs_create(struct mdio_device *mdio) in lynx_pcs_create() argument
322 return ERR_PTR(-ENOMEM); in lynx_pcs_create()
324 mdio_device_get(mdio); in lynx_pcs_create()
325 lynx->mdio = mdio; in lynx_pcs_create()
326 lynx->pcs.ops = &lynx_pcs_phylink_ops; in lynx_pcs_create()
327 lynx->pcs.neg_mode = true; in lynx_pcs_create()
328 lynx->pcs.poll = true; in lynx_pcs_create()
333 struct phylink_pcs *lynx_pcs_create_mdiodev(struct mii_bus *bus, int addr) in lynx_pcs_create_mdiodev() argument
335 struct mdio_device *mdio; in lynx_pcs_create_mdiodev() local
338 mdio = mdio_device_create(bus, addr); in lynx_pcs_create_mdiodev()
339 if (IS_ERR(mdio)) in lynx_pcs_create_mdiodev()
340 return ERR_CAST(mdio); in lynx_pcs_create_mdiodev()
342 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_mdiodev()
345 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_mdiodev()
348 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_mdiodev()
350 mdio_device_put(mdio); in lynx_pcs_create_mdiodev()
361 * -ENODEV if the fwnode is marked unavailable
362 * -EPROBE_DEFER if we fail to find the device
363 * -ENOMEM if we fail to allocate memory
368 struct mdio_device *mdio; in lynx_pcs_create_fwnode() local
372 return ERR_PTR(-ENODEV); in lynx_pcs_create_fwnode()
374 mdio = fwnode_mdio_find_device(node); in lynx_pcs_create_fwnode()
375 if (!mdio) in lynx_pcs_create_fwnode()
376 return ERR_PTR(-EPROBE_DEFER); in lynx_pcs_create_fwnode()
378 pcs = lynx_pcs_create(mdio); in lynx_pcs_create_fwnode()
381 * successful. If lynx_create() fails, this will free the mdio in lynx_pcs_create_fwnode()
384 * lynx_destroy() to automatically free the mdio device. in lynx_pcs_create_fwnode()
386 mdio_device_put(mdio); in lynx_pcs_create_fwnode()
396 mdio_device_put(lynx->mdio); in lynx_pcs_destroy()