Lines Matching +full:reset +full:- +full:phy +full:- +full:on +full:- +full:wake

1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/net/phy/broadcom.c
8 * Broadcom BCM54810, BCM54811 BroadR-Reach transceivers.
15 #include "bcm-phy-lib.h"
18 #include <linux/phy.h>
27 ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
30 ((phydev)->drv->phy_id & ~((phydev)->drv->phy_id_mask))
32 MODULE_DESCRIPTION("Broadcom PHY driver");
44 /* Link modes for BCM58411 PHY */
57 /* Long-Distance Signaling (BroadR-Reach mode aneg) relevant linkmode bits */
68 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_phy_can_wakeup()
70 return phy_interrupt_is_valid(phydev) || priv->wake_irq >= 0; in bcm54xx_phy_can_wakeup()
77 /* handling PHY's internal RX clock delay */ in bcm54xx_config_clock_delay()
80 if (phydev->interface == PHY_INTERFACE_MODE_RGMII || in bcm54xx_config_clock_delay()
81 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { in bcm54xx_config_clock_delay()
82 /* Disable RGMII RXC-RXD skew */ in bcm54xx_config_clock_delay()
85 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in bcm54xx_config_clock_delay()
86 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { in bcm54xx_config_clock_delay()
87 /* Enable RGMII RXC-RXD skew */ in bcm54xx_config_clock_delay()
95 /* handling PHY's internal TX clock delay */ in bcm54xx_config_clock_delay()
97 if (phydev->interface == PHY_INTERFACE_MODE_RGMII || in bcm54xx_config_clock_delay()
98 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { in bcm54xx_config_clock_delay()
102 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in bcm54xx_config_clock_delay()
103 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { in bcm54xx_config_clock_delay()
120 if (phydev->dev_flags & PHY_BRCM_EN_MASTER_MODE) { in bcm54210e_config_init()
135 /* Enable CLK125 MUX on LED4 if ref clock is enabled. */ in bcm54612e_config_init()
136 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) { in bcm54612e_config_init()
154 if (phydev->interface != PHY_INTERFACE_MODE_SGMII && in bcm54616s_config_init()
155 phydev->interface != PHY_INTERFACE_MODE_1000BASEX) in bcm54616s_config_init()
170 /* Select 1000BASE-X register set (primary SerDes) */ in bcm54616s_config_init()
186 val |= phydev->interface == PHY_INTERFACE_MODE_SGMII ? in bcm54616s_config_init()
254 /* Clear bit 9 to fix a phy interop issue. */ in bcm54xx_phydsp_config()
260 if (phydev->drv->phy_id == PHY_ID_BCM50610) { in bcm54xx_phydsp_config()
294 /* Abort if we are using an untested phy. */ in bcm54xx_adjust_rxrefclk()
318 if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) { in bcm54xx_adjust_rxrefclk()
327 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_adjust_rxrefclk()
332 if (phydev->dev_flags & PHY_BRCM_DIS_TXCRXC_NOENRGY) { in bcm54xx_adjust_rxrefclk()
350 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_adjust_rxrefclk()
361 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_ptp_stop()
363 if (priv->ptp) in bcm54xx_ptp_stop()
364 bcm_ptp_stop(priv->ptp); in bcm54xx_ptp_stop()
369 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_ptp_config_init()
371 if (priv->ptp) in bcm54xx_ptp_config_init()
375 static int bcm5481x_set_brrmode(struct phy_device *phydev, bool on) in bcm5481x_set_brrmode() argument
386 if (on) in bcm5481x_set_brrmode()
397 * on/off, thus set the override in bcm5481x_set_brrmode()
400 if (!on) in bcm5481x_set_brrmode()
409 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54811_config_init()
412 /* Enable CLK125 MUX on LED4 if ref clock is enabled. */ in bcm54811_config_init()
413 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) { in bcm54811_config_init()
423 /* With BCM54811, BroadR-Reach implies no autoneg */ in bcm54811_config_init()
424 if (priv->brr_mode) in bcm54811_config_init()
425 phydev->autoneg = 0; in bcm54811_config_init()
427 return bcm5481x_set_brrmode(phydev, priv->brr_mode); in bcm54811_config_init()
454 (phydev->dev_flags & PHY_BRCM_CLEAR_RGMII_MODE)) in bcm54xx_config_init()
474 /* For BCM54810, we need to disable BroadR-Reach function */ in bcm54xx_config_init()
491 /* For non-SFP setups, encode link speed into LED1 and LED3 pair in bcm54xx_config_init()
493 * Also flash these two LEDs on activity. This means configuring in bcm54xx_config_init()
495 * Don't do this for devices on an SFP module, since some of these in bcm54xx_config_init()
513 * wake-up. in bcm54xx_config_init()
520 pm_wakeup_event(&phydev->mdio.dev, 0); in bcm54xx_config_init()
529 if (!(phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND)) in bcm54xx_iddq_set()
548 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_set_wakeup_irq()
554 if (priv->wake_irq_enabled != state) { in bcm54xx_set_wakeup_irq()
556 ret = enable_irq_wake(priv->wake_irq); in bcm54xx_set_wakeup_irq()
558 ret = disable_irq_wake(priv->wake_irq); in bcm54xx_set_wakeup_irq()
559 priv->wake_irq_enabled = state; in bcm54xx_set_wakeup_irq()
571 /* Acknowledge any Wake-on-LAN interrupt prior to suspend */ in bcm54xx_suspend()
576 if (phydev->wol_enabled) in bcm54xx_suspend()
579 /* We cannot use a read/modify/write here otherwise the PHY gets into in bcm54xx_suspend()
594 if (phydev->wol_enabled) { in bcm54xx_resume()
611 /* Upon exiting power down, the PHY remains in an internal reset state in bcm54xx_resume()
616 /* Issue a soft reset after clearing the power down bit in bcm54xx_resume()
619 if (phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND) { in bcm54xx_resume()
630 return -EOPNOTSUPP; in bcm54810_read_mmd()
636 return -EOPNOTSUPP; in bcm54810_write_mmd()
641 * bcm5481x_read_abilities - read PHY abilities from LRESR or Clause 22
642 * (BMSR) registers, based on whether the PHY is in BroadR-Reach or IEEE mode
645 * Description: Reads the PHY's abilities and populates phydev->supported
647 * the brr mode setting of the PHY as read from the device tree.
649 * not only the link modes differ, but also the auto-negotiation and
650 * master-slave setup is controlled differently.
652 * Returns: 0 on success, < 0 on failure
656 struct device_node *np = phydev->mdio.dev.of_node; in bcm5481x_read_abilities()
657 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm5481x_read_abilities()
661 linkmode_clear_bit(bcm54811_linkmodes[i], phydev->supported); in bcm5481x_read_abilities()
663 priv->brr_mode = of_property_read_bool(np, "brr-mode"); in bcm5481x_read_abilities()
665 /* Set BroadR-Reach mode as configured in the DT. */ in bcm5481x_read_abilities()
666 err = bcm5481x_set_brrmode(phydev, priv->brr_mode); in bcm5481x_read_abilities()
670 if (priv->brr_mode) { in bcm5481x_read_abilities()
673 phydev->supported); in bcm5481x_read_abilities()
680 phydev->supported, in bcm5481x_read_abilities()
683 phydev->supported, in bcm5481x_read_abilities()
686 phydev->supported, in bcm5481x_read_abilities()
696 struct device_node *np = phydev->mdio.dev.of_node; in bcm5481x_config_delay_swap()
701 if (of_property_read_bool(np, "enet-phy-lane-swap")) { in bcm5481x_config_delay_swap()
702 /* Lane Swap - Undocumented register...magic! */ in bcm5481x_config_delay_swap()
715 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm5481_config_aneg()
719 if (priv->brr_mode) in bcm5481_config_aneg()
733 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54811_config_aneg()
737 if (priv->brr_mode) { in bcm54811_config_aneg()
739 phydev->autoneg = 0; in bcm54811_config_aneg()
761 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in bcm54616s_probe()
763 return -ENOMEM; in bcm54616s_probe()
765 phydev->priv = priv; in bcm54616s_probe()
771 /* The PHY is strapped in RGMII-fiber mode when INTERF_SEL[1:0] in bcm54616s_probe()
772 * is 01b, and the link between PHY and its link partner can be in bcm54616s_probe()
773 * either 1000Base-X or 100Base-FX. in bcm54616s_probe()
774 * RGMII-1000Base-X is properly supported, but RGMII-100Base-FX in bcm54616s_probe()
782 /* Bit 0 of the SerDes 100-FX Control register, when set in bcm54616s_probe()
783 * to 1, sets the MII/RGMII -> 100BASE-FX configuration. in bcm54616s_probe()
784 * When this bit is set to 0, it sets the GMII/RGMII -> in bcm54616s_probe()
785 * 1000BASE-X configuration. in bcm54616s_probe()
788 priv->mode_1000bx_en = true; in bcm54616s_probe()
790 phydev->port = PORT_FIBRE; in bcm54616s_probe()
798 struct bcm54616s_phy_priv *priv = phydev->priv; in bcm54616s_config_aneg()
802 if (priv->mode_1000bx_en) in bcm54616s_config_aneg()
815 struct bcm54616s_phy_priv *priv = phydev->priv; in bcm54616s_read_status()
819 if (priv->mode_1000bx_en) in bcm54616s_read_status()
831 /* Reset the PHY to bring it to a known state. */ in brcm_fet_config_init()
836 /* The datasheet indicates the PHY needs up to 1us to complete a reset, in brcm_fet_config_init()
841 /* The PHY requires 65 MDC clock cycles to complete a write operation in brcm_fet_config_init()
844 * We ignore -EIO here as the MDIO controller (e.g.: mdio-bcm-unimac) in brcm_fet_config_init()
845 * may flag the lack of turn-around as a read failure. This is in brcm_fet_config_init()
853 if (err < 0 && err != -EIO) in brcm_fet_config_init()
862 if (phydev->phy_id == PHY_ID_BCM5221) in brcm_fet_config_init()
891 if (phydev->phy_id != PHY_ID_BCM5221) { in brcm_fet_config_init()
912 if (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE) { in brcm_fet_config_init()
949 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in brcm_fet_config_intr()
990 /* We cannot use a read/modify/write here otherwise the PHY continues in brcm_fet_suspend()
1012 if (phydev->phy_id == PHY_ID_BCM5221) in brcm_fet_suspend()
1039 switch (phydev->mdix_ctrl) { in bcm5221_config_aneg()
1069 phydev->mdix_ctrl = ETH_TP_MDI_X; in bcm5221_read_status()
1071 phydev->mdix_ctrl = ETH_TP_MDI; in bcm5221_read_status()
1073 phydev->mdix_ctrl = ETH_TP_MDI_AUTO; in bcm5221_read_status()
1077 phydev->mdix = ETH_TP_MDI_X; in bcm5221_read_status()
1079 phydev->mdix = ETH_TP_MDI; in bcm5221_read_status()
1087 /* We cannot wake-up if we do not have a dedicated PHY interrupt line in bcm54xx_phy_get_wol()
1088 * or an out of band GPIO descriptor for wake-up. Zeroing in bcm54xx_phy_get_wol()
1089 * wol->supported allows the caller (MAC driver) to play through and in bcm54xx_phy_get_wol()
1090 * offer its own Wake-on-LAN scheme if available. in bcm54xx_phy_get_wol()
1093 wol->supported = 0; in bcm54xx_phy_get_wol()
1105 /* We cannot wake-up if we do not have a dedicated PHY interrupt line in bcm54xx_phy_set_wol()
1106 * or an out of band GPIO descriptor for wake-up. Returning -EOPNOTSUPP in bcm54xx_phy_set_wol()
1108 * Wake-on-LAN scheme if available. in bcm54xx_phy_set_wol()
1111 return -EOPNOTSUPP; in bcm54xx_phy_set_wol()
1126 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in bcm54xx_phy_probe()
1128 return -ENOMEM; in bcm54xx_phy_probe()
1130 priv->wake_irq = -ENXIO; in bcm54xx_phy_probe()
1132 phydev->priv = priv; in bcm54xx_phy_probe()
1134 priv->stats = devm_kcalloc(&phydev->mdio.dev, in bcm54xx_phy_probe()
1137 if (!priv->stats) in bcm54xx_phy_probe()
1138 return -ENOMEM; in bcm54xx_phy_probe()
1140 priv->ptp = bcm_ptp_probe(phydev); in bcm54xx_phy_probe()
1141 if (IS_ERR(priv->ptp)) in bcm54xx_phy_probe()
1142 return PTR_ERR(priv->ptp); in bcm54xx_phy_probe()
1145 * whether the GPIO descriptor exists or not to advertise Wake-on-LAN in bcm54xx_phy_probe()
1148 wakeup_gpio = devm_gpiod_get(&phydev->mdio.dev, "wakeup", GPIOD_IN); in bcm54xx_phy_probe()
1149 if (PTR_ERR(wakeup_gpio) == -EPROBE_DEFER) in bcm54xx_phy_probe()
1153 priv->wake_irq = gpiod_to_irq(wakeup_gpio); in bcm54xx_phy_probe()
1156 * in order for the interrupt descriptor to be fully set-up. in bcm54xx_phy_probe()
1158 ret = devm_request_irq(&phydev->mdio.dev, priv->wake_irq, in bcm54xx_phy_probe()
1161 dev_name(&phydev->mdio.dev), phydev); in bcm54xx_phy_probe()
1166 /* If we do not have a main interrupt or a side-band wake-up interrupt, in bcm54xx_phy_probe()
1167 * then the device cannot be marked as wake-up capable. in bcm54xx_phy_probe()
1172 return device_init_wakeup(&phydev->mdio.dev, true); in bcm54xx_phy_probe()
1178 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_get_stats()
1180 bcm_phy_get_stats(phydev, priv->stats, stats, data); in bcm54xx_get_stats()
1189 if (phydev->state != PHY_RUNNING) in bcm54xx_link_change_notify()
1192 /* Don't change the DAC wake settings if auto power down in bcm54xx_link_change_notify()
1195 if (!(phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_link_change_notify()
1202 /* Enable/disable 10BaseT auto and forced early DAC wake depending in bcm54xx_link_change_notify()
1203 * on the negotiated speed, those settings should only be done in bcm54xx_link_change_notify()
1206 if (phydev->speed == SPEED_10) in bcm54xx_link_change_notify()
1218 /* In BroadR-Reach mode we are always capable of master-slave in lre_read_master_slave()
1221 phydev->master_slave_get = MASTER_SLAVE_CFG_UNKNOWN; in lre_read_master_slave()
1222 phydev->master_slave_state = MASTER_SLAVE_STATE_UNKNOWN; in lre_read_master_slave()
1244 phydev->master_slave_get = cfg; in lre_read_master_slave()
1245 phydev->master_slave_state = state; in lre_read_master_slave()
1250 /* Read LDS Link Partner Ability in BroadR-Reach mode */
1255 if (phydev->autoneg != AUTONEG_ENABLE) { in lre_read_lpa()
1256 if (!phydev->autoneg_complete) { in lre_read_lpa()
1257 /* aneg not yet done, reset all relevant bits */ in lre_read_lpa()
1260 phydev->lp_advertising); in lre_read_lpa()
1265 /* Long-Distance Signaling Link Partner Ability */ in lre_read_lpa()
1271 phydev->lp_advertising, in lre_read_lpa()
1274 phydev->lp_advertising, in lre_read_lpa()
1277 phydev->lp_advertising, in lre_read_lpa()
1280 phydev->lp_advertising, in lre_read_lpa()
1283 linkmode_zero(phydev->lp_advertising); in lre_read_lpa()
1296 phydev->duplex = DUPLEX_FULL; in lre_read_status_fixed()
1299 phydev->speed = SPEED_100; in lre_read_status_fixed()
1301 phydev->speed = SPEED_10; in lre_read_status_fixed()
1307 * lre_update_link - update link status in @phydev
1309 * Return: 0 on success, < 0 on error
1311 * Description: Update the value in phydev->link to reflect the
1314 * This is a genphy_update_link modified to work on LRE registers
1315 * of BroadR-Reach PHY
1332 * drops can be detected. Do not double-read the status in lre_update_link()
1336 if (!phy_polling_mode(phydev) || !phydev->link) { in lre_update_link()
1349 phydev->link = status & LRESR_LSTATUS ? 1 : 0; in lre_update_link()
1350 phydev->autoneg_complete = status & LRESR_LDSCOMPLETE ? 1 : 0; in lre_update_link()
1353 * bit has been reset, but "link up" bit not yet. in lre_update_link()
1355 if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete) in lre_update_link()
1356 phydev->link = 0; in lre_update_link()
1366 int err, old_link = phydev->link; in bcm54811_lre_read_status()
1373 /* why bother the PHY if nothing can have changed */ in bcm54811_lre_read_status()
1374 if (phydev->autoneg == in bcm54811_lre_read_status()
1375 AUTONEG_ENABLE && old_link && phydev->link) in bcm54811_lre_read_status()
1378 phydev->speed = SPEED_UNKNOWN; in bcm54811_lre_read_status()
1379 phydev->duplex = DUPLEX_UNKNOWN; in bcm54811_lre_read_status()
1380 phydev->pause = 0; in bcm54811_lre_read_status()
1381 phydev->asym_pause = 0; in bcm54811_lre_read_status()
1392 if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) in bcm54811_lre_read_status()
1394 else if (phydev->autoneg == AUTONEG_DISABLE) in bcm54811_lre_read_status()
1402 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54811_read_status()
1404 if (priv->brr_mode) in bcm54811_read_status()