Lines Matching refs:phydev

24 #define BRCM_PHY_MODEL(phydev) \  argument
25 ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
27 #define BRCM_PHY_REV(phydev) \ argument
28 ((phydev)->drv->phy_id & ~((phydev)->drv->phy_id_mask))
41 static bool bcm54xx_phy_can_wakeup(struct phy_device *phydev) in bcm54xx_phy_can_wakeup() argument
43 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_phy_can_wakeup()
45 return phy_interrupt_is_valid(phydev) || priv->wake_irq >= 0; in bcm54xx_phy_can_wakeup()
48 static int bcm54xx_config_clock_delay(struct phy_device *phydev) in bcm54xx_config_clock_delay() argument
53 val = bcm54xx_auxctl_read(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC); in bcm54xx_config_clock_delay()
55 if (phydev->interface == PHY_INTERFACE_MODE_RGMII || in bcm54xx_config_clock_delay()
56 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { in bcm54xx_config_clock_delay()
60 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in bcm54xx_config_clock_delay()
61 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { in bcm54xx_config_clock_delay()
65 rc = bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC, in bcm54xx_config_clock_delay()
71 val = bcm_phy_read_shadow(phydev, BCM54810_SHD_CLK_CTL); in bcm54xx_config_clock_delay()
72 if (phydev->interface == PHY_INTERFACE_MODE_RGMII || in bcm54xx_config_clock_delay()
73 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { in bcm54xx_config_clock_delay()
77 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || in bcm54xx_config_clock_delay()
78 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { in bcm54xx_config_clock_delay()
82 rc = bcm_phy_write_shadow(phydev, BCM54810_SHD_CLK_CTL, val); in bcm54xx_config_clock_delay()
89 static int bcm54210e_config_init(struct phy_device *phydev) in bcm54210e_config_init() argument
93 bcm54xx_config_clock_delay(phydev); in bcm54210e_config_init()
95 if (phydev->dev_flags & PHY_BRCM_EN_MASTER_MODE) { in bcm54210e_config_init()
96 val = phy_read(phydev, MII_CTRL1000); in bcm54210e_config_init()
98 phy_write(phydev, MII_CTRL1000, val); in bcm54210e_config_init()
104 static int bcm54612e_config_init(struct phy_device *phydev) in bcm54612e_config_init() argument
108 bcm54xx_config_clock_delay(phydev); in bcm54612e_config_init()
111 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) { in bcm54612e_config_init()
114 reg = bcm_phy_read_exp(phydev, BCM54612E_EXP_SPARE0); in bcm54612e_config_init()
115 err = bcm_phy_write_exp(phydev, BCM54612E_EXP_SPARE0, in bcm54612e_config_init()
125 static int bcm54616s_config_init(struct phy_device *phydev) in bcm54616s_config_init() argument
129 if (phydev->interface != PHY_INTERFACE_MODE_SGMII && in bcm54616s_config_init()
130 phydev->interface != PHY_INTERFACE_MODE_1000BASEX) in bcm54616s_config_init()
135 val = bcm54xx_auxctl_read(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC); in bcm54616s_config_init()
140 rc = bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC, in bcm54616s_config_init()
146 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE); in bcm54616s_config_init()
150 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val); in bcm54616s_config_init()
155 rc = phy_set_bits(phydev, MII_BMCR, BMCR_PDOWN); in bcm54616s_config_init()
161 val |= phydev->interface == PHY_INTERFACE_MODE_SGMII ? in bcm54616s_config_init()
164 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val); in bcm54616s_config_init()
169 rc = phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN); in bcm54616s_config_init()
175 rc = bcm_phy_write_shadow(phydev, BCM54XX_SHD_MODE, val); in bcm54616s_config_init()
180 return phy_clear_bits(phydev, MII_BMCR, BMCR_PDOWN); in bcm54616s_config_init()
184 static int bcm50610_a0_workaround(struct phy_device *phydev) in bcm50610_a0_workaround() argument
188 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_AADJ1CH0, in bcm50610_a0_workaround()
194 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_AADJ1CH3, in bcm50610_a0_workaround()
199 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP75, in bcm50610_a0_workaround()
204 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP96, in bcm50610_a0_workaround()
209 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP97, in bcm50610_a0_workaround()
215 static int bcm54xx_phydsp_config(struct phy_device *phydev) in bcm54xx_phydsp_config() argument
220 err = bcm54xx_auxctl_write(phydev, in bcm54xx_phydsp_config()
227 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 || in bcm54xx_phydsp_config()
228 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) { in bcm54xx_phydsp_config()
230 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP08, in bcm54xx_phydsp_config()
235 if (phydev->drv->phy_id == PHY_ID_BCM50610) { in bcm54xx_phydsp_config()
236 err = bcm50610_a0_workaround(phydev); in bcm54xx_phydsp_config()
242 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) { in bcm54xx_phydsp_config()
245 val = bcm_phy_read_exp(phydev, MII_BCM54XX_EXP_EXP75); in bcm54xx_phydsp_config()
250 err = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP75, val); in bcm54xx_phydsp_config()
255 err2 = bcm54xx_auxctl_write(phydev, in bcm54xx_phydsp_config()
263 static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev) in bcm54xx_adjust_rxrefclk() argument
270 if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM57780 && in bcm54xx_adjust_rxrefclk()
271 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 && in bcm54xx_adjust_rxrefclk()
272 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M && in bcm54xx_adjust_rxrefclk()
273 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54210E && in bcm54xx_adjust_rxrefclk()
274 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54810 && in bcm54xx_adjust_rxrefclk()
275 BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54811) in bcm54xx_adjust_rxrefclk()
278 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_SCR3); in bcm54xx_adjust_rxrefclk()
284 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 || in bcm54xx_adjust_rxrefclk()
285 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) && in bcm54xx_adjust_rxrefclk()
286 BRCM_PHY_REV(phydev) >= 0x3) { in bcm54xx_adjust_rxrefclk()
293 if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) { in bcm54xx_adjust_rxrefclk()
294 if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM54811) { in bcm54xx_adjust_rxrefclk()
302 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_adjust_rxrefclk()
307 if (phydev->dev_flags & PHY_BRCM_DIS_TXCRXC_NOENRGY) { in bcm54xx_adjust_rxrefclk()
308 if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54210E || in bcm54xx_adjust_rxrefclk()
309 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54810 || in bcm54xx_adjust_rxrefclk()
310 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54811) in bcm54xx_adjust_rxrefclk()
317 bcm_phy_write_shadow(phydev, BCM54XX_SHD_SCR3, val); in bcm54xx_adjust_rxrefclk()
319 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_APD); in bcm54xx_adjust_rxrefclk()
325 if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_adjust_rxrefclk()
331 bcm_phy_write_shadow(phydev, BCM54XX_SHD_APD, val); in bcm54xx_adjust_rxrefclk()
334 static void bcm54xx_ptp_stop(struct phy_device *phydev) in bcm54xx_ptp_stop() argument
336 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_ptp_stop()
342 static void bcm54xx_ptp_config_init(struct phy_device *phydev) in bcm54xx_ptp_config_init() argument
344 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_ptp_config_init()
347 bcm_ptp_config_init(phydev); in bcm54xx_ptp_config_init()
350 static int bcm54xx_config_init(struct phy_device *phydev) in bcm54xx_config_init() argument
354 reg = phy_read(phydev, MII_BCM54XX_ECR); in bcm54xx_config_init()
360 err = phy_write(phydev, MII_BCM54XX_ECR, reg); in bcm54xx_config_init()
368 err = phy_write(phydev, MII_BCM54XX_IMR, reg); in bcm54xx_config_init()
372 if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 || in bcm54xx_config_init()
373 BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) && in bcm54xx_config_init()
374 (phydev->dev_flags & PHY_BRCM_CLEAR_RGMII_MODE)) in bcm54xx_config_init()
375 bcm_phy_write_shadow(phydev, BCM54XX_SHD_RGMII_MODE, 0); in bcm54xx_config_init()
377 bcm54xx_adjust_rxrefclk(phydev); in bcm54xx_config_init()
379 switch (BRCM_PHY_MODEL(phydev)) { in bcm54xx_config_init()
382 err = bcm54xx_config_clock_delay(phydev); in bcm54xx_config_init()
385 err = bcm54210e_config_init(phydev); in bcm54xx_config_init()
388 err = bcm54612e_config_init(phydev); in bcm54xx_config_init()
391 err = bcm54616s_config_init(phydev); in bcm54xx_config_init()
395 val = bcm_phy_read_exp(phydev, in bcm54xx_config_init()
398 err = bcm_phy_write_exp(phydev, in bcm54xx_config_init()
406 bcm54xx_phydsp_config(phydev); in bcm54xx_config_init()
416 if (!phy_on_sfp(phydev)) { in bcm54xx_config_init()
419 bcm_phy_write_shadow(phydev, BCM54XX_SHD_LEDS1, val); in bcm54xx_config_init()
424 bcm_phy_write_exp(phydev, BCM_EXP_MULTICOLOR, val); in bcm54xx_config_init()
427 bcm54xx_ptp_config_init(phydev); in bcm54xx_config_init()
432 err = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS); in bcm54xx_config_init()
437 pm_wakeup_event(&phydev->mdio.dev, 0); in bcm54xx_config_init()
442 static int bcm54xx_iddq_set(struct phy_device *phydev, bool enable) in bcm54xx_iddq_set() argument
446 if (!(phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND)) in bcm54xx_iddq_set()
449 ret = bcm_phy_read_exp(phydev, BCM54XX_TOP_MISC_IDDQ_CTRL); in bcm54xx_iddq_set()
458 ret = bcm_phy_write_exp(phydev, BCM54XX_TOP_MISC_IDDQ_CTRL, ret); in bcm54xx_iddq_set()
463 static int bcm54xx_set_wakeup_irq(struct phy_device *phydev, bool state) in bcm54xx_set_wakeup_irq() argument
465 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_set_wakeup_irq()
468 if (!bcm54xx_phy_can_wakeup(phydev)) in bcm54xx_set_wakeup_irq()
482 static int bcm54xx_suspend(struct phy_device *phydev) in bcm54xx_suspend() argument
486 bcm54xx_ptp_stop(phydev); in bcm54xx_suspend()
489 ret = bcm_phy_read_exp(phydev, BCM54XX_WOL_INT_STATUS); in bcm54xx_suspend()
493 if (phydev->wol_enabled) in bcm54xx_suspend()
494 return bcm54xx_set_wakeup_irq(phydev, true); in bcm54xx_suspend()
500 ret = phy_write(phydev, MII_BMCR, BMCR_PDOWN); in bcm54xx_suspend()
504 return bcm54xx_iddq_set(phydev, true); in bcm54xx_suspend()
507 static int bcm54xx_resume(struct phy_device *phydev) in bcm54xx_resume() argument
511 if (phydev->wol_enabled) { in bcm54xx_resume()
512 ret = bcm54xx_set_wakeup_irq(phydev, false); in bcm54xx_resume()
517 ret = bcm54xx_iddq_set(phydev, false); in bcm54xx_resume()
524 ret = genphy_resume(phydev); in bcm54xx_resume()
536 if (phydev->dev_flags & PHY_BRCM_IDDQ_SUSPEND) { in bcm54xx_resume()
537 ret = genphy_soft_reset(phydev); in bcm54xx_resume()
542 return bcm54xx_config_init(phydev); in bcm54xx_resume()
545 static int bcm54810_read_mmd(struct phy_device *phydev, int devnum, u16 regnum) in bcm54810_read_mmd() argument
550 static int bcm54810_write_mmd(struct phy_device *phydev, int devnum, u16 regnum, in bcm54810_write_mmd() argument
556 static int bcm54811_config_init(struct phy_device *phydev) in bcm54811_config_init() argument
561 reg = bcm_phy_read_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL); in bcm54811_config_init()
563 err = bcm_phy_write_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL, in bcm54811_config_init()
568 err = bcm54xx_config_init(phydev); in bcm54811_config_init()
571 if (!(phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED)) { in bcm54811_config_init()
572 reg = bcm_phy_read_exp(phydev, BCM54612E_EXP_SPARE0); in bcm54811_config_init()
573 err = bcm_phy_write_exp(phydev, BCM54612E_EXP_SPARE0, in bcm54811_config_init()
582 static int bcm5481_config_aneg(struct phy_device *phydev) in bcm5481_config_aneg() argument
584 struct device_node *np = phydev->mdio.dev.of_node; in bcm5481_config_aneg()
588 ret = genphy_config_aneg(phydev); in bcm5481_config_aneg()
591 bcm54xx_config_clock_delay(phydev); in bcm5481_config_aneg()
595 ret = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0x9, in bcm5481_config_aneg()
608 static int bcm54616s_probe(struct phy_device *phydev) in bcm54616s_probe() argument
613 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in bcm54616s_probe()
617 phydev->priv = priv; in bcm54616s_probe()
619 val = bcm_phy_read_shadow(phydev, BCM54XX_SHD_MODE); in bcm54616s_probe()
630 val = bcm_phy_read_shadow(phydev, BCM54616S_SHD_100FX_CTRL); in bcm54616s_probe()
642 phydev->port = PORT_FIBRE; in bcm54616s_probe()
648 static int bcm54616s_config_aneg(struct phy_device *phydev) in bcm54616s_config_aneg() argument
650 struct bcm54616s_phy_priv *priv = phydev->priv; in bcm54616s_config_aneg()
655 ret = genphy_c37_config_aneg(phydev); in bcm54616s_config_aneg()
657 ret = genphy_config_aneg(phydev); in bcm54616s_config_aneg()
660 bcm54xx_config_clock_delay(phydev); in bcm54616s_config_aneg()
665 static int bcm54616s_read_status(struct phy_device *phydev) in bcm54616s_read_status() argument
667 struct bcm54616s_phy_priv *priv = phydev->priv; in bcm54616s_read_status()
671 err = genphy_c37_read_status(phydev); in bcm54616s_read_status()
673 err = genphy_read_status(phydev); in bcm54616s_read_status()
678 static int brcm_fet_config_init(struct phy_device *phydev) in brcm_fet_config_init() argument
683 err = phy_write(phydev, MII_BMCR, BMCR_RESET); in brcm_fet_config_init()
703 err = phy_read(phydev, MII_BMCR); in brcm_fet_config_init()
707 reg = phy_read(phydev, MII_BRCM_FET_INTREG); in brcm_fet_config_init()
718 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg); in brcm_fet_config_init()
723 brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST); in brcm_fet_config_init()
729 err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg); in brcm_fet_config_init()
734 reg = phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4); in brcm_fet_config_init()
743 err = phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg); in brcm_fet_config_init()
748 err = phy_set_bits(phydev, MII_BRCM_FET_SHDW_MISCCTRL, in brcm_fet_config_init()
753 if (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE) { in brcm_fet_config_init()
755 err = phy_set_bits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2, in brcm_fet_config_init()
761 err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest); in brcm_fet_config_init()
768 static int brcm_fet_ack_interrupt(struct phy_device *phydev) in brcm_fet_ack_interrupt() argument
773 reg = phy_read(phydev, MII_BRCM_FET_INTREG); in brcm_fet_ack_interrupt()
780 static int brcm_fet_config_intr(struct phy_device *phydev) in brcm_fet_config_intr() argument
784 reg = phy_read(phydev, MII_BRCM_FET_INTREG); in brcm_fet_config_intr()
788 if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { in brcm_fet_config_intr()
789 err = brcm_fet_ack_interrupt(phydev); in brcm_fet_config_intr()
794 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg); in brcm_fet_config_intr()
797 err = phy_write(phydev, MII_BRCM_FET_INTREG, reg); in brcm_fet_config_intr()
801 err = brcm_fet_ack_interrupt(phydev); in brcm_fet_config_intr()
807 static irqreturn_t brcm_fet_handle_interrupt(struct phy_device *phydev) in brcm_fet_handle_interrupt() argument
811 irq_status = phy_read(phydev, MII_BRCM_FET_INTREG); in brcm_fet_handle_interrupt()
813 phy_error(phydev); in brcm_fet_handle_interrupt()
820 phy_trigger_machine(phydev); in brcm_fet_handle_interrupt()
825 static int brcm_fet_suspend(struct phy_device *phydev) in brcm_fet_suspend() argument
832 err = phy_write(phydev, MII_BMCR, BMCR_PDOWN); in brcm_fet_suspend()
837 brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST); in brcm_fet_suspend()
843 err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg); in brcm_fet_suspend()
848 err = phy_modify(phydev, MII_BRCM_FET_SHDW_AUXMODE4, in brcm_fet_suspend()
853 err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest); in brcm_fet_suspend()
860 static void bcm54xx_phy_get_wol(struct phy_device *phydev, in bcm54xx_phy_get_wol() argument
868 if (!bcm54xx_phy_can_wakeup(phydev)) { in bcm54xx_phy_get_wol()
873 bcm_phy_get_wol(phydev, wol); in bcm54xx_phy_get_wol()
876 static int bcm54xx_phy_set_wol(struct phy_device *phydev, in bcm54xx_phy_set_wol() argument
886 if (!bcm54xx_phy_can_wakeup(phydev)) in bcm54xx_phy_set_wol()
889 ret = bcm_phy_set_wol(phydev, wol); in bcm54xx_phy_set_wol()
896 static int bcm54xx_phy_probe(struct phy_device *phydev) in bcm54xx_phy_probe() argument
902 priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL); in bcm54xx_phy_probe()
908 phydev->priv = priv; in bcm54xx_phy_probe()
910 priv->stats = devm_kcalloc(&phydev->mdio.dev, in bcm54xx_phy_probe()
911 bcm_phy_get_sset_count(phydev), sizeof(u64), in bcm54xx_phy_probe()
916 priv->ptp = bcm_ptp_probe(phydev); in bcm54xx_phy_probe()
924 wakeup_gpio = devm_gpiod_get(&phydev->mdio.dev, "wakeup", GPIOD_IN); in bcm54xx_phy_probe()
934 ret = devm_request_irq(&phydev->mdio.dev, priv->wake_irq, in bcm54xx_phy_probe()
937 dev_name(&phydev->mdio.dev), phydev); in bcm54xx_phy_probe()
945 if (!bcm54xx_phy_can_wakeup(phydev)) in bcm54xx_phy_probe()
948 return device_init_wakeup(&phydev->mdio.dev, true); in bcm54xx_phy_probe()
951 static void bcm54xx_get_stats(struct phy_device *phydev, in bcm54xx_get_stats() argument
954 struct bcm54xx_phy_priv *priv = phydev->priv; in bcm54xx_get_stats()
956 bcm_phy_get_stats(phydev, priv->stats, stats, data); in bcm54xx_get_stats()
959 static void bcm54xx_link_change_notify(struct phy_device *phydev) in bcm54xx_link_change_notify() argument
965 if (phydev->state != PHY_RUNNING) in bcm54xx_link_change_notify()
971 if (!(phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE)) in bcm54xx_link_change_notify()
974 ret = bcm_phy_read_exp(phydev, MII_BCM54XX_EXP_EXP08); in bcm54xx_link_change_notify()
982 if (phydev->speed == SPEED_10) in bcm54xx_link_change_notify()
986 bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_EXP08, ret); in bcm54xx_link_change_notify()