1 // SPDX-License-Identifier: GPL-2.0+
3 * drivers/net/phy/broadcom.c
5 * Broadcom BCM5411, BCM5421 and BCM5461 Gigabit Ethernet
8 * Copyright (c) 2006 Maciej W. Rozycki
10 * Inspired by code written by Amy Fong.
13 #include "bcm-phy-lib.h"
14 #include <linux/delay.h>
15 #include <linux/module.h>
16 #include <linux/phy.h>
17 #include <linux/pm_wakeup.h>
18 #include <linux/brcmphy.h>
20 #include <linux/interrupt.h>
21 #include <linux/irq.h>
22 #include <linux/gpio/consumer.h>
24 #define BRCM_PHY_MODEL(phydev) \
25 ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
27 #define BRCM_PHY_REV(phydev) \
28 ((phydev)->drv->phy_id & ~((phydev)->drv->phy_id_mask))
30 MODULE_DESCRIPTION("Broadcom PHY driver");
31 MODULE_AUTHOR("Maciej W. Rozycki");
32 MODULE_LICENSE("GPL");
34 struct bcm54xx_phy_priv {
36 struct bcm_ptp_private *ptp;
38 bool wake_irq_enabled;
41 static bool bcm54xx_phy_can_wakeup(struct phy_device *phydev)
43 struct bcm54xx_phy_priv *priv = phydev->priv;
45 return phy_interrupt_is_valid(phydev) || priv->wake_irq >= 0;
48 static int bcm54xx_config_clock_delay(struct phy_device *phydev)
52 /* handling PHY's internal RX clock delay */
53 val = bcm54xx_auxctl_read(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC);
54 val |= MII_BCM54XX_AUXCTL_MISC_WREN;
55 if (phydev->interface == PHY_INTERFACE_MODE_RGMII ||
56 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
57 /* Disable RGMII RXC-RXD skew */
58 val &= ~MII_BCM54XX_AUXCTL_SHDWSEL_MISC_RGMII_SKEW_EN;
60 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
61 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
62 /* Enable RGMII RXC-RXD skew */
63 val |= MII_BCM54XX_AUXCTL_SHDWSEL_MISC_RGMII_SKEW_EN;
65 rc = bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC,
70 /* handling PHY's internal TX clock delay */
71 val = bcm_phy_read_shadow(phydev, BCM54810_SHD_CLK_CTL);
72 if (phydev->interface == PHY_INTERFACE_MODE_RGMII ||
73 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
74 /* Disable internal TX clock delay */
75 val &= ~BCM54810_SHD_CLK_CTL_GTXCLK_EN;
77 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
78 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
79 /* Enable internal TX clock delay */
80 val |= BCM54810_SHD_CLK_CTL_GTXCLK_EN;
82 rc = bcm_phy_write_shadow(phydev, BCM54810_SHD_CLK_CTL, val);
89 static int bcm54210e_config_init(struct phy_device *phydev)
93 bcm54xx_config_clock_delay(phydev);
95 if (phydev->dev_flags & PHY_BRCM_EN_MASTER_MODE) {
96 val = phy_read(phydev, MII_CTRL1000);
97 val |= CTL1000_AS_MASTER | CTL1000_ENABLE_MASTER;
98 phy_write(phydev, MII_CTRL1000, val);
104 static int bcm54612e_config_init(struct phy_device *phydev)
108 bcm54xx_config_clock_delay(phydev);
110 /* Enable CLK125 MUX on LED4 if ref clock is enabled. */
111 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) {
114 reg = bcm_phy_read_exp(phydev, BCM54612E_EXP_SPARE0);
115 err = bcm_phy_write_exp(phydev, BCM54612E_EXP_SPARE0,
116 BCM54612E_LED4_CLK125OUT_EN | reg);
125 static int bcm54616s_config_init(struct phy_device *phydev)
129 if (phydev->interface != PHY_INTERFACE_MODE_SGMII &&
130 phydev->interface != PHY_INTERFACE_MODE_1000BASEX)
133 /* Ensure proper interface mode is selected. */
134 /* Disable RGMII mode */
135 val = bcm54xx_auxctl_read(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC);
138 val &= ~MII_BCM54XX_AUXCTL_SHDWSEL_MISC_RGMII_EN;
139 val |= MII_BCM54XX_AUXCTL_MISC_WREN;
140 rc = bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC,
145 /* Select 1000BASE-X register set (primary SerDes) */
146 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE);
149 val |= BCM54XX_SHD_MODE_1000BX;
150 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val);
154 /* Power down SerDes interface */
155 rc = phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN);
159 /* Select proper interface mode */
160 val &= ~BCM54XX_SHD_INTF_SEL_MASK;
161 val |= phydev->interface == PHY_INTERFACE_MODE_SGMII ?
162 BCM54XX_SHD_INTF_SEL_SGMII :
163 BCM54XX_SHD_INTF_SEL_GBIC;
164 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val);
168 /* Power up SerDes interface */
169 rc = phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);
173 /* Select copper register set */
174 val &= ~BCM54XX_SHD_MODE_1000BX;
175 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val);
179 /* Power up copper interface */
180 return phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN);
183 /* Needs SMDSP clock enabled via bcm54xx_phydsp_config() */
184 static int bcm50610_a0_workaround(struct phy_device *phydev)
188 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_AADJ1CH0,
189 MII_BCM54XX_EXP_AADJ1CH0_SWP_ABCD_OEN |
190 MII_BCM54XX_EXP_AADJ1CH0_SWSEL_THPF);
194 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_AADJ1CH3,
195 MII_BCM54XX_EXP_AADJ1CH3_ADCCKADJ);
199 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP75,
200 MII_BCM54XX_EXP_EXP75_VDACCTRL);
204 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP96,
205 MII_BCM54XX_EXP_EXP96_MYST);
209 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP97,
210 MII_BCM54XX_EXP_EXP97_MYST);
215 static int bcm54xx_phydsp_config(struct phy_device *phydev)
219 /* Enable the SMDSP clock */
220 err = bcm54xx_auxctl_write(phydev,
221 MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
222 MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA |
223 MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
227 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
228 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) {
229 /* Clear bit 9 to fix a phy interop issue. */
230 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP08,
231 MII_BCM54XX_EXP_EXP08_RJCT_2MHZ);
235 if (phydev->drv->phy_id == PHY_ID_BCM50610) {
236 err = bcm50610_a0_workaround(phydev);
242 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) {
245 val = bcm_phy_read_exp(phydev, MII_BCM54XX_EXP_EXP75);
249 val |= MII_BCM54XX_EXP_EXP75_CM_OSC;
250 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP75, val);
254 /* Disable the SMDSP clock */
255 err2 = bcm54xx_auxctl_write(phydev,
256 MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
257 MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
259 /* Return the first error reported. */
260 return err ? err : err2;
263 static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev)
267 bool clk125en = true;
269 /* Abort if we are using an untested phy. */
270 if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM57780 &&
271 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 &&
272 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M &&
273 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54210E &&
274 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54810 &&
275 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54811)
278 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_SCR3);
284 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
285 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
286 BRCM_PHY_REV(phydev) >= 0x3) {
288 * Here, bit 0 _disables_ CLK125 when set.
289 * This bit is set by default.
293 if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) {
294 if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54811) {
295 /* Here, bit 0 _enables_ CLK125 when set */
296 val &= ~BCM54XX_SHD_SCR3_DEF_CLK125;
302 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
303 val &= ~BCM54XX_SHD_SCR3_DLLAPD_DIS;
305 val |= BCM54XX_SHD_SCR3_DLLAPD_DIS;
307 if (phydev->dev_flags & PHY_BRCM_DIS_TXCRXC_NOENRGY) {
308 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54210E ||
309 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54810 ||
310 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54811)
311 val |= BCM54XX_SHD_SCR3_RXCTXC_DIS;
313 val |= BCM54XX_SHD_SCR3_TRDDAPD;
317 bcm_phy_write_shadow(phydev, BCM54XX_SHD_SCR3, val);
319 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_APD);
325 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
326 val |= BCM54XX_SHD_APD_EN;
328 val &= ~BCM54XX_SHD_APD_EN;
331 bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, val);
334 static void bcm54xx_ptp_stop(struct phy_device *phydev)
336 struct bcm54xx_phy_priv *priv = phydev->priv;
339 bcm_ptp_stop(priv->ptp);
342 static void bcm54xx_ptp_config_init(struct phy_device *phydev)
344 struct bcm54xx_phy_priv *priv = phydev->priv;
347 bcm_ptp_config_init(phydev);
350 static int bcm54xx_config_init(struct phy_device *phydev)
354 reg = phy_read(phydev, MII_BCM54XX_ECR);
358 /* Mask interrupts globally. */
359 reg |= MII_BCM54XX_ECR_IM;
360 err = phy_write(phydev, MII_BCM54XX_ECR, reg);
364 /* Unmask events we are interested in. */
365 reg = ~(MII_BCM54XX_INT_DUPLEX |
366 MII_BCM54XX_INT_SPEED |
367 MII_BCM54XX_INT_LINK);
368 err = phy_write(phydev, MII_BCM54XX_IMR, reg);
372 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
373 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
374 (phydev->dev_flags & PHY_BRCM_CLEAR_RGMII_MODE))
375 bcm_phy_write_shadow(phydev, BCM54XX_SHD_RGMII_MODE, 0);
377 bcm54xx_adjust_rxrefclk(phydev);
379 switch (BRCM_PHY_MODEL(phydev)) {
380 case PHY_ID_BCM50610:
381 case PHY_ID_BCM50610M:
382 err = bcm54xx_config_clock_delay(phydev);
384 case PHY_ID_BCM54210E:
385 err = bcm54210e_config_init(phydev);
387 case PHY_ID_BCM54612E:
388 err = bcm54612e_config_init(phydev);
390 case PHY_ID_BCM54616S:
391 err = bcm54616s_config_init(phydev);
393 case PHY_ID_BCM54810:
394 /* For BCM54810, we need to disable BroadR-Reach function */
395 val = bcm_phy_read_exp(phydev,
396 BCM54810_EXP_BROADREACH_LRE_MISC_CTL);
397 val &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
398 err = bcm_phy_write_exp(phydev,
399 BCM54810_EXP_BROADREACH_LRE_MISC_CTL,
406 bcm54xx_phydsp_config(phydev);
408 /* For non-SFP setups, encode link speed into LED1 and LED3 pair
410 * Also flash these two LEDs on activity. This means configuring
411 * them for MULTICOLOR and encoding link/activity into them.
412 * Don't do this for devices on an SFP module, since some of these
413 * use the LED outputs to control the SFP LOS signal, and changing
414 * these settings will cause LOS to malfunction.
416 if (!phy_on_sfp(phydev)) {
417 val = BCM54XX_SHD_LEDS1_LED1(BCM_LED_SRC_MULTICOLOR1) |
418 BCM54XX_SHD_LEDS1_LED3(BCM_LED_SRC_MULTICOLOR1);
419 bcm_phy_write_shadow(phydev, BCM54XX_SHD_LEDS1, val);
421 val = BCM_LED_MULTICOLOR_IN_PHASE |
422 BCM54XX_SHD_LEDS1_LED1(BCM_LED_MULTICOLOR_LINK_ACT) |
423 BCM54XX_SHD_LEDS1_LED3(BCM_LED_MULTICOLOR_LINK_ACT);
424 bcm_phy_write_exp(phydev, BCM_EXP_MULTICOLOR, val);
427 bcm54xx_ptp_config_init(phydev);
429 /* Acknowledge any left over interrupt and charge the device for
432 err = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS);
437 pm_wakeup_event(&phydev->mdio.dev, 0);
442 static int bcm54xx_iddq_set(struct phy_device *phydev, bool enable)
446 if (!(phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND))
449 ret = bcm_phy_read_exp(phydev, BCM54XX_TOP_MISC_IDDQ_CTRL);
454 ret |= BCM54XX_TOP_MISC_IDDQ_SR | BCM54XX_TOP_MISC_IDDQ_LP;
456 ret &= ~(BCM54XX_TOP_MISC_IDDQ_SR | BCM54XX_TOP_MISC_IDDQ_LP);
458 ret = bcm_phy_write_exp(phydev, BCM54XX_TOP_MISC_IDDQ_CTRL, ret);
463 static int bcm54xx_set_wakeup_irq(struct phy_device *phydev, bool state)
465 struct bcm54xx_phy_priv *priv = phydev->priv;
468 if (!bcm54xx_phy_can_wakeup(phydev))
471 if (priv->wake_irq_enabled != state) {
473 ret = enable_irq_wake(priv->wake_irq);
475 ret = disable_irq_wake(priv->wake_irq);
476 priv->wake_irq_enabled = state;
482 static int bcm54xx_suspend(struct phy_device *phydev)
486 bcm54xx_ptp_stop(phydev);
488 /* Acknowledge any Wake-on-LAN interrupt prior to suspend */
489 ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS);
493 if (phydev->wol_enabled)
494 return bcm54xx_set_wakeup_irq(phydev, true);
496 /* We cannot use a read/modify/write here otherwise the PHY gets into
497 * a bad state where its LEDs keep flashing, thus defeating the purpose
500 ret = phy_write(phydev, MII_BMCR, BMCR_PDOWN);
504 return bcm54xx_iddq_set(phydev, true);
507 static int bcm54xx_resume(struct phy_device *phydev)
511 if (phydev->wol_enabled) {
512 ret = bcm54xx_set_wakeup_irq(phydev, false);
517 ret = bcm54xx_iddq_set(phydev, false);
521 /* Writes to register other than BMCR would be ignored
522 * unless we clear the PDOWN bit first
524 ret = genphy_resume(phydev);
528 /* Upon exiting power down, the PHY remains in an internal reset state
533 /* Issue a soft reset after clearing the power down bit
534 * and before doing any other configuration.
536 if (phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND) {
537 ret = genphy_soft_reset(phydev);
542 return bcm54xx_config_init(phydev);
545 static int bcm54811_config_init(struct phy_device *phydev)
549 /* Disable BroadR-Reach function. */
550 reg = bcm_phy_read_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL);
551 reg &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
552 err = bcm_phy_write_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL,
557 err = bcm54xx_config_init(phydev);
559 /* Enable CLK125 MUX on LED4 if ref clock is enabled. */
560 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) {
561 reg = bcm_phy_read_exp(phydev, BCM54612E_EXP_SPARE0);
562 err = bcm_phy_write_exp(phydev, BCM54612E_EXP_SPARE0,
563 BCM54612E_LED4_CLK125OUT_EN | reg);
571 static int bcm5481_config_aneg(struct phy_device *phydev)
573 struct device_node *np = phydev->mdio.dev.of_node;
577 ret = genphy_config_aneg(phydev);
579 /* Then we can set up the delay. */
580 bcm54xx_config_clock_delay(phydev);
582 if (of_property_read_bool(np, "enet-phy-lane-swap")) {
583 /* Lane Swap - Undocumented register...magic! */
584 ret = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0x9,
593 struct bcm54616s_phy_priv {
597 static int bcm54616s_probe(struct phy_device *phydev)
599 struct bcm54616s_phy_priv *priv;
602 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
608 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE);
612 /* The PHY is strapped in RGMII-fiber mode when INTERF_SEL[1:0]
613 * is 01b, and the link between PHY and its link partner can be
614 * either 1000Base-X or 100Base-FX.
615 * RGMII-1000Base-X is properly supported, but RGMII-100Base-FX
616 * support is still missing as of now.
618 if ((val & BCM54XX_SHD_INTF_SEL_MASK) == BCM54XX_SHD_INTF_SEL_RGMII) {
619 val = bcm_phy_read_shadow(phydev, BCM54616S_SHD_100FX_CTRL);
623 /* Bit 0 of the SerDes 100-FX Control register, when set
624 * to 1, sets the MII/RGMII -> 100BASE-FX configuration.
625 * When this bit is set to 0, it sets the GMII/RGMII ->
626 * 1000BASE-X configuration.
628 if (!(val & BCM54616S_100FX_MODE))
629 priv->mode_1000bx_en = true;
631 phydev->port = PORT_FIBRE;
637 static int bcm54616s_config_aneg(struct phy_device *phydev)
639 struct bcm54616s_phy_priv *priv = phydev->priv;
643 if (priv->mode_1000bx_en)
644 ret = genphy_c37_config_aneg(phydev);
646 ret = genphy_config_aneg(phydev);
648 /* Then we can set up the delay. */
649 bcm54xx_config_clock_delay(phydev);
654 static int bcm54616s_read_status(struct phy_device *phydev)
656 struct bcm54616s_phy_priv *priv = phydev->priv;
659 if (priv->mode_1000bx_en)
660 err = genphy_c37_read_status(phydev);
662 err = genphy_read_status(phydev);
667 static int brcm_fet_config_init(struct phy_device *phydev)
669 int reg, err, err2, brcmtest;
671 /* Reset the PHY to bring it to a known state. */
672 err = phy_write(phydev, MII_BMCR, BMCR_RESET);
676 /* The datasheet indicates the PHY needs up to 1us to complete a reset,
677 * build some slack here.
679 usleep_range(1000, 2000);
681 /* The PHY requires 65 MDC clock cycles to complete a write operation
682 * and turnaround the line properly.
684 * We ignore -EIO here as the MDIO controller (e.g.: mdio-bcm-unimac)
685 * may flag the lack of turn-around as a read failure. This is
686 * particularly true with this combination since the MDIO controller
687 * only used 64 MDC cycles. This is not a critical failure in this
688 * specific case and it has no functional impact otherwise, so we let
689 * that one go through. If there is a genuine bus error, the next read
690 * of MII_BRCM_FET_INTREG will error out.
692 err = phy_read(phydev, MII_BMCR);
693 if (err < 0 && err != -EIO)
696 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
700 /* Unmask events we are interested in and mask interrupts globally. */
701 reg = MII_BRCM_FET_IR_DUPLEX_EN |
702 MII_BRCM_FET_IR_SPEED_EN |
703 MII_BRCM_FET_IR_LINK_EN |
704 MII_BRCM_FET_IR_ENABLE |
705 MII_BRCM_FET_IR_MASK;
707 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
711 /* Enable shadow register access */
712 brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST);
716 reg = brcmtest | MII_BRCM_FET_BT_SRE;
718 err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
722 /* Set the LED mode */
723 reg = phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4);
729 reg &= ~MII_BRCM_FET_SHDW_AM4_LED_MASK;
730 reg |= MII_BRCM_FET_SHDW_AM4_LED_MODE1;
732 err = phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg);
736 /* Enable auto MDIX */
737 err = phy_set_bits(phydev, MII_BRCM_FET_SHDW_MISCCTRL,
738 MII_BRCM_FET_SHDW_MC_FAME);
742 if (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE) {
743 /* Enable auto power down */
744 err = phy_set_bits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2,
745 MII_BRCM_FET_SHDW_AS2_APDE);
749 /* Disable shadow register access */
750 err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest);
757 static int brcm_fet_ack_interrupt(struct phy_device *phydev)
761 /* Clear pending interrupts. */
762 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
769 static int brcm_fet_config_intr(struct phy_device *phydev)
773 reg = phy_read(phydev, MII_BRCM_FET_INTREG);
777 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) {
778 err = brcm_fet_ack_interrupt(phydev);
782 reg &= ~MII_BRCM_FET_IR_MASK;
783 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
785 reg |= MII_BRCM_FET_IR_MASK;
786 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
790 err = brcm_fet_ack_interrupt(phydev);
796 static irqreturn_t brcm_fet_handle_interrupt(struct phy_device *phydev)
800 irq_status = phy_read(phydev, MII_BRCM_FET_INTREG);
801 if (irq_status < 0) {
809 phy_trigger_machine(phydev);
814 static int brcm_fet_suspend(struct phy_device *phydev)
816 int reg, err, err2, brcmtest;
818 /* We cannot use a read/modify/write here otherwise the PHY continues
819 * to drive LEDs which defeats the purpose of low power mode.
821 err = phy_write(phydev, MII_BMCR, BMCR_PDOWN);
825 /* Enable shadow register access */
826 brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST);
830 reg = brcmtest | MII_BRCM_FET_BT_SRE;
832 err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
836 /* Set standby mode */
837 err = phy_modify(phydev, MII_BRCM_FET_SHDW_AUXMODE4,
838 MII_BRCM_FET_SHDW_AM4_STANDBY,
839 MII_BRCM_FET_SHDW_AM4_STANDBY);
841 /* Disable shadow register access */
842 err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest);
849 static void bcm54xx_phy_get_wol(struct phy_device *phydev,
850 struct ethtool_wolinfo *wol)
852 /* We cannot wake-up if we do not have a dedicated PHY interrupt line
853 * or an out of band GPIO descriptor for wake-up. Zeroing
854 * wol->supported allows the caller (MAC driver) to play through and
855 * offer its own Wake-on-LAN scheme if available.
857 if (!bcm54xx_phy_can_wakeup(phydev)) {
862 bcm_phy_get_wol(phydev, wol);
865 static int bcm54xx_phy_set_wol(struct phy_device *phydev,
866 struct ethtool_wolinfo *wol)
870 /* We cannot wake-up if we do not have a dedicated PHY interrupt line
871 * or an out of band GPIO descriptor for wake-up. Returning -EOPNOTSUPP
872 * allows the caller (MAC driver) to play through and offer its own
873 * Wake-on-LAN scheme if available.
875 if (!bcm54xx_phy_can_wakeup(phydev))
878 ret = bcm_phy_set_wol(phydev, wol);
885 static int bcm54xx_phy_probe(struct phy_device *phydev)
887 struct bcm54xx_phy_priv *priv;
888 struct gpio_desc *wakeup_gpio;
891 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
895 priv->wake_irq = -ENXIO;
899 priv->stats = devm_kcalloc(&phydev->mdio.dev,
900 bcm_phy_get_sset_count(phydev), sizeof(u64),
905 priv->ptp = bcm_ptp_probe(phydev);
906 if (IS_ERR(priv->ptp))
907 return PTR_ERR(priv->ptp);
909 /* We cannot utilize the _optional variant here since we want to know
910 * whether the GPIO descriptor exists or not to advertise Wake-on-LAN
913 wakeup_gpio = devm_gpiod_get(&phydev->mdio.dev, "wakeup", GPIOD_IN);
914 if (PTR_ERR(wakeup_gpio) == -EPROBE_DEFER)
915 return PTR_ERR(wakeup_gpio);
917 if (!IS_ERR(wakeup_gpio)) {
918 priv->wake_irq = gpiod_to_irq(wakeup_gpio);
920 /* Dummy interrupt handler which is not enabled but is provided
921 * in order for the interrupt descriptor to be fully set-up.
923 ret = devm_request_irq(&phydev->mdio.dev, priv->wake_irq,
925 IRQF_TRIGGER_LOW | IRQF_NO_AUTOEN,
926 dev_name(&phydev->mdio.dev), phydev);
931 /* If we do not have a main interrupt or a side-band wake-up interrupt,
932 * then the device cannot be marked as wake-up capable.
934 if (!bcm54xx_phy_can_wakeup(phydev))
937 return device_init_wakeup(&phydev->mdio.dev, true);
940 static void bcm54xx_get_stats(struct phy_device *phydev,
941 struct ethtool_stats *stats, u64 *data)
943 struct bcm54xx_phy_priv *priv = phydev->priv;
945 bcm_phy_get_stats(phydev, priv->stats, stats, data);
948 static void bcm54xx_link_change_notify(struct phy_device *phydev)
950 u16 mask = MII_BCM54XX_EXP_EXP08_EARLY_DAC_WAKE |
951 MII_BCM54XX_EXP_EXP08_FORCE_DAC_WAKE;
954 if (phydev->state != PHY_RUNNING)
957 /* Don't change the DAC wake settings if auto power down
960 if (!(phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
963 ret = bcm_phy_read_exp(phydev, MII_BCM54XX_EXP_EXP08);
967 /* Enable/disable 10BaseT auto and forced early DAC wake depending
968 * on the negotiated speed, those settings should only be done
971 if (phydev->speed == SPEED_10)
975 bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP08, ret);
978 static struct phy_driver broadcom_drivers[] = {
980 .phy_id = PHY_ID_BCM5411,
981 .phy_id_mask = 0xfffffff0,
982 .name = "Broadcom BCM5411",
983 /* PHY_GBIT_FEATURES */
984 .get_sset_count = bcm_phy_get_sset_count,
985 .get_strings = bcm_phy_get_strings,
986 .get_stats = bcm54xx_get_stats,
987 .probe = bcm54xx_phy_probe,
988 .config_init = bcm54xx_config_init,
989 .config_intr = bcm_phy_config_intr,
990 .handle_interrupt = bcm_phy_handle_interrupt,
991 .link_change_notify = bcm54xx_link_change_notify,
993 .phy_id = PHY_ID_BCM5421,
994 .phy_id_mask = 0xfffffff0,
995 .name = "Broadcom BCM5421",
996 /* PHY_GBIT_FEATURES */
997 .get_sset_count = bcm_phy_get_sset_count,
998 .get_strings = bcm_phy_get_strings,
999 .get_stats = bcm54xx_get_stats,
1000 .probe = bcm54xx_phy_probe,
1001 .config_init = bcm54xx_config_init,
1002 .config_intr = bcm_phy_config_intr,
1003 .handle_interrupt = bcm_phy_handle_interrupt,
1004 .link_change_notify = bcm54xx_link_change_notify,
1006 .phy_id = PHY_ID_BCM54210E,
1007 .phy_id_mask = 0xfffffff0,
1008 .name = "Broadcom BCM54210E",
1009 /* PHY_GBIT_FEATURES */
1010 .flags = PHY_ALWAYS_CALL_SUSPEND,
1011 .get_sset_count = bcm_phy_get_sset_count,
1012 .get_strings = bcm_phy_get_strings,
1013 .get_stats = bcm54xx_get_stats,
1014 .probe = bcm54xx_phy_probe,
1015 .config_init = bcm54xx_config_init,
1016 .config_intr = bcm_phy_config_intr,
1017 .handle_interrupt = bcm_phy_handle_interrupt,
1018 .link_change_notify = bcm54xx_link_change_notify,
1019 .suspend = bcm54xx_suspend,
1020 .resume = bcm54xx_resume,
1021 .get_wol = bcm54xx_phy_get_wol,
1022 .set_wol = bcm54xx_phy_set_wol,
1023 .led_brightness_set = bcm_phy_led_brightness_set,
1025 .phy_id = PHY_ID_BCM5461,
1026 .phy_id_mask = 0xfffffff0,
1027 .name = "Broadcom BCM5461",
1028 /* PHY_GBIT_FEATURES */
1029 .get_sset_count = bcm_phy_get_sset_count,
1030 .get_strings = bcm_phy_get_strings,
1031 .get_stats = bcm54xx_get_stats,
1032 .probe = bcm54xx_phy_probe,
1033 .config_init = bcm54xx_config_init,
1034 .config_intr = bcm_phy_config_intr,
1035 .handle_interrupt = bcm_phy_handle_interrupt,
1036 .link_change_notify = bcm54xx_link_change_notify,
1037 .led_brightness_set = bcm_phy_led_brightness_set,
1039 .phy_id = PHY_ID_BCM54612E,
1040 .phy_id_mask = 0xfffffff0,
1041 .name = "Broadcom BCM54612E",
1042 /* PHY_GBIT_FEATURES */
1043 .get_sset_count = bcm_phy_get_sset_count,
1044 .get_strings = bcm_phy_get_strings,
1045 .get_stats = bcm54xx_get_stats,
1046 .probe = bcm54xx_phy_probe,
1047 .config_init = bcm54xx_config_init,
1048 .config_intr = bcm_phy_config_intr,
1049 .handle_interrupt = bcm_phy_handle_interrupt,
1050 .link_change_notify = bcm54xx_link_change_notify,
1051 .led_brightness_set = bcm_phy_led_brightness_set,
1053 .phy_id = PHY_ID_BCM54616S,
1054 .phy_id_mask = 0xfffffff0,
1055 .name = "Broadcom BCM54616S",
1056 /* PHY_GBIT_FEATURES */
1057 .soft_reset = genphy_soft_reset,
1058 .config_init = bcm54xx_config_init,
1059 .config_aneg = bcm54616s_config_aneg,
1060 .config_intr = bcm_phy_config_intr,
1061 .handle_interrupt = bcm_phy_handle_interrupt,
1062 .read_status = bcm54616s_read_status,
1063 .probe = bcm54616s_probe,
1064 .link_change_notify = bcm54xx_link_change_notify,
1065 .led_brightness_set = bcm_phy_led_brightness_set,
1067 .phy_id = PHY_ID_BCM5464,
1068 .phy_id_mask = 0xfffffff0,
1069 .name = "Broadcom BCM5464",
1070 /* PHY_GBIT_FEATURES */
1071 .get_sset_count = bcm_phy_get_sset_count,
1072 .get_strings = bcm_phy_get_strings,
1073 .get_stats = bcm54xx_get_stats,
1074 .probe = bcm54xx_phy_probe,
1075 .config_init = bcm54xx_config_init,
1076 .config_intr = bcm_phy_config_intr,
1077 .handle_interrupt = bcm_phy_handle_interrupt,
1078 .suspend = genphy_suspend,
1079 .resume = genphy_resume,
1080 .link_change_notify = bcm54xx_link_change_notify,
1081 .led_brightness_set = bcm_phy_led_brightness_set,
1083 .phy_id = PHY_ID_BCM5481,
1084 .phy_id_mask = 0xfffffff0,
1085 .name = "Broadcom BCM5481",
1086 /* PHY_GBIT_FEATURES */
1087 .get_sset_count = bcm_phy_get_sset_count,
1088 .get_strings = bcm_phy_get_strings,
1089 .get_stats = bcm54xx_get_stats,
1090 .probe = bcm54xx_phy_probe,
1091 .config_init = bcm54xx_config_init,
1092 .config_aneg = bcm5481_config_aneg,
1093 .config_intr = bcm_phy_config_intr,
1094 .handle_interrupt = bcm_phy_handle_interrupt,
1095 .link_change_notify = bcm54xx_link_change_notify,
1096 .led_brightness_set = bcm_phy_led_brightness_set,
1098 .phy_id = PHY_ID_BCM54810,
1099 .phy_id_mask = 0xfffffff0,
1100 .name = "Broadcom BCM54810",
1101 /* PHY_GBIT_FEATURES */
1102 .get_sset_count = bcm_phy_get_sset_count,
1103 .get_strings = bcm_phy_get_strings,
1104 .get_stats = bcm54xx_get_stats,
1105 .probe = bcm54xx_phy_probe,
1106 .config_init = bcm54xx_config_init,
1107 .config_aneg = bcm5481_config_aneg,
1108 .config_intr = bcm_phy_config_intr,
1109 .handle_interrupt = bcm_phy_handle_interrupt,
1110 .suspend = bcm54xx_suspend,
1111 .resume = bcm54xx_resume,
1112 .link_change_notify = bcm54xx_link_change_notify,
1113 .led_brightness_set = bcm_phy_led_brightness_set,
1115 .phy_id = PHY_ID_BCM54811,
1116 .phy_id_mask = 0xfffffff0,
1117 .name = "Broadcom BCM54811",
1118 /* PHY_GBIT_FEATURES */
1119 .get_sset_count = bcm_phy_get_sset_count,
1120 .get_strings = bcm_phy_get_strings,
1121 .get_stats = bcm54xx_get_stats,
1122 .probe = bcm54xx_phy_probe,
1123 .config_init = bcm54811_config_init,
1124 .config_aneg = bcm5481_config_aneg,
1125 .config_intr = bcm_phy_config_intr,
1126 .handle_interrupt = bcm_phy_handle_interrupt,
1127 .suspend = bcm54xx_suspend,
1128 .resume = bcm54xx_resume,
1129 .link_change_notify = bcm54xx_link_change_notify,
1130 .led_brightness_set = bcm_phy_led_brightness_set,
1132 .phy_id = PHY_ID_BCM5482,
1133 .phy_id_mask = 0xfffffff0,
1134 .name = "Broadcom BCM5482",
1135 /* PHY_GBIT_FEATURES */
1136 .get_sset_count = bcm_phy_get_sset_count,
1137 .get_strings = bcm_phy_get_strings,
1138 .get_stats = bcm54xx_get_stats,
1139 .probe = bcm54xx_phy_probe,
1140 .config_init = bcm54xx_config_init,
1141 .config_intr = bcm_phy_config_intr,
1142 .handle_interrupt = bcm_phy_handle_interrupt,
1143 .link_change_notify = bcm54xx_link_change_notify,
1144 .led_brightness_set = bcm_phy_led_brightness_set,
1146 .phy_id = PHY_ID_BCM50610,
1147 .phy_id_mask = 0xfffffff0,
1148 .name = "Broadcom BCM50610",
1149 /* PHY_GBIT_FEATURES */
1150 .get_sset_count = bcm_phy_get_sset_count,
1151 .get_strings = bcm_phy_get_strings,
1152 .get_stats = bcm54xx_get_stats,
1153 .probe = bcm54xx_phy_probe,
1154 .config_init = bcm54xx_config_init,
1155 .config_intr = bcm_phy_config_intr,
1156 .handle_interrupt = bcm_phy_handle_interrupt,
1157 .link_change_notify = bcm54xx_link_change_notify,
1158 .suspend = bcm54xx_suspend,
1159 .resume = bcm54xx_resume,
1160 .led_brightness_set = bcm_phy_led_brightness_set,
1162 .phy_id = PHY_ID_BCM50610M,
1163 .phy_id_mask = 0xfffffff0,
1164 .name = "Broadcom BCM50610M",
1165 /* PHY_GBIT_FEATURES */
1166 .get_sset_count = bcm_phy_get_sset_count,
1167 .get_strings = bcm_phy_get_strings,
1168 .get_stats = bcm54xx_get_stats,
1169 .probe = bcm54xx_phy_probe,
1170 .config_init = bcm54xx_config_init,
1171 .config_intr = bcm_phy_config_intr,
1172 .handle_interrupt = bcm_phy_handle_interrupt,
1173 .link_change_notify = bcm54xx_link_change_notify,
1174 .suspend = bcm54xx_suspend,
1175 .resume = bcm54xx_resume,
1176 .led_brightness_set = bcm_phy_led_brightness_set,
1178 .phy_id = PHY_ID_BCM57780,
1179 .phy_id_mask = 0xfffffff0,
1180 .name = "Broadcom BCM57780",
1181 /* PHY_GBIT_FEATURES */
1182 .get_sset_count = bcm_phy_get_sset_count,
1183 .get_strings = bcm_phy_get_strings,
1184 .get_stats = bcm54xx_get_stats,
1185 .probe = bcm54xx_phy_probe,
1186 .config_init = bcm54xx_config_init,
1187 .config_intr = bcm_phy_config_intr,
1188 .handle_interrupt = bcm_phy_handle_interrupt,
1189 .link_change_notify = bcm54xx_link_change_notify,
1190 .led_brightness_set = bcm_phy_led_brightness_set,
1192 .phy_id = PHY_ID_BCMAC131,
1193 .phy_id_mask = 0xfffffff0,
1194 .name = "Broadcom BCMAC131",
1195 /* PHY_BASIC_FEATURES */
1196 .config_init = brcm_fet_config_init,
1197 .config_intr = brcm_fet_config_intr,
1198 .handle_interrupt = brcm_fet_handle_interrupt,
1199 .suspend = brcm_fet_suspend,
1200 .resume = brcm_fet_config_init,
1202 .phy_id = PHY_ID_BCM5241,
1203 .phy_id_mask = 0xfffffff0,
1204 .name = "Broadcom BCM5241",
1205 /* PHY_BASIC_FEATURES */
1206 .config_init = brcm_fet_config_init,
1207 .config_intr = brcm_fet_config_intr,
1208 .handle_interrupt = brcm_fet_handle_interrupt,
1209 .suspend = brcm_fet_suspend,
1210 .resume = brcm_fet_config_init,
1212 .phy_id = PHY_ID_BCM5395,
1213 .phy_id_mask = 0xfffffff0,
1214 .name = "Broadcom BCM5395",
1215 .flags = PHY_IS_INTERNAL,
1216 /* PHY_GBIT_FEATURES */
1217 .get_sset_count = bcm_phy_get_sset_count,
1218 .get_strings = bcm_phy_get_strings,
1219 .get_stats = bcm54xx_get_stats,
1220 .probe = bcm54xx_phy_probe,
1221 .link_change_notify = bcm54xx_link_change_notify,
1222 .led_brightness_set = bcm_phy_led_brightness_set,
1224 .phy_id = PHY_ID_BCM53125,
1225 .phy_id_mask = 0xfffffff0,
1226 .name = "Broadcom BCM53125",
1227 .flags = PHY_IS_INTERNAL,
1228 /* PHY_GBIT_FEATURES */
1229 .get_sset_count = bcm_phy_get_sset_count,
1230 .get_strings = bcm_phy_get_strings,
1231 .get_stats = bcm54xx_get_stats,
1232 .probe = bcm54xx_phy_probe,
1233 .config_init = bcm54xx_config_init,
1234 .config_intr = bcm_phy_config_intr,
1235 .handle_interrupt = bcm_phy_handle_interrupt,
1236 .link_change_notify = bcm54xx_link_change_notify,
1237 .led_brightness_set = bcm_phy_led_brightness_set,
1239 .phy_id = PHY_ID_BCM53128,
1240 .phy_id_mask = 0xfffffff0,
1241 .name = "Broadcom BCM53128",
1242 .flags = PHY_IS_INTERNAL,
1243 /* PHY_GBIT_FEATURES */
1244 .get_sset_count = bcm_phy_get_sset_count,
1245 .get_strings = bcm_phy_get_strings,
1246 .get_stats = bcm54xx_get_stats,
1247 .probe = bcm54xx_phy_probe,
1248 .config_init = bcm54xx_config_init,
1249 .config_intr = bcm_phy_config_intr,
1250 .handle_interrupt = bcm_phy_handle_interrupt,
1251 .link_change_notify = bcm54xx_link_change_notify,
1252 .led_brightness_set = bcm_phy_led_brightness_set,
1254 .phy_id = PHY_ID_BCM89610,
1255 .phy_id_mask = 0xfffffff0,
1256 .name = "Broadcom BCM89610",
1257 /* PHY_GBIT_FEATURES */
1258 .get_sset_count = bcm_phy_get_sset_count,
1259 .get_strings = bcm_phy_get_strings,
1260 .get_stats = bcm54xx_get_stats,
1261 .probe = bcm54xx_phy_probe,
1262 .config_init = bcm54xx_config_init,
1263 .config_intr = bcm_phy_config_intr,
1264 .handle_interrupt = bcm_phy_handle_interrupt,
1265 .link_change_notify = bcm54xx_link_change_notify,
1268 module_phy_driver(broadcom_drivers);
1270 static struct mdio_device_id __maybe_unused broadcom_tbl[] = {
1271 { PHY_ID_BCM5411, 0xfffffff0 },
1272 { PHY_ID_BCM5421, 0xfffffff0 },
1273 { PHY_ID_BCM54210E, 0xfffffff0 },
1274 { PHY_ID_BCM5461, 0xfffffff0 },
1275 { PHY_ID_BCM54612E, 0xfffffff0 },
1276 { PHY_ID_BCM54616S, 0xfffffff0 },
1277 { PHY_ID_BCM5464, 0xfffffff0 },
1278 { PHY_ID_BCM5481, 0xfffffff0 },
1279 { PHY_ID_BCM54810, 0xfffffff0 },
1280 { PHY_ID_BCM54811, 0xfffffff0 },
1281 { PHY_ID_BCM5482, 0xfffffff0 },
1282 { PHY_ID_BCM50610, 0xfffffff0 },
1283 { PHY_ID_BCM50610M, 0xfffffff0 },
1284 { PHY_ID_BCM57780, 0xfffffff0 },
1285 { PHY_ID_BCMAC131, 0xfffffff0 },
1286 { PHY_ID_BCM5241, 0xfffffff0 },
1287 { PHY_ID_BCM5395, 0xfffffff0 },
1288 { PHY_ID_BCM53125, 0xfffffff0 },
1289 { PHY_ID_BCM53128, 0xfffffff0 },
1290 { PHY_ID_BCM89610, 0xfffffff0 },
1294 MODULE_DEVICE_TABLE(mdio, broadcom_tbl);