Re: [PATCH v3] net: phy: broadcom: add support for BCM5221 phy
From: Russell King (Oracle)
Date: Thu Oct 05 2023 - 10:09:19 EST
On Thu, Sep 28, 2023 at 08:59:49PM +0200, Giulio Benetti wrote:
> + /* Read to clear status bits */
> reg = phy_read(phydev, MII_BRCM_FET_INTREG);
> if (reg < 0)
> return reg;
>
> /* Unmask events we are interested in and mask interrupts globally. */
> - reg = MII_BRCM_FET_IR_DUPLEX_EN |
> - MII_BRCM_FET_IR_SPEED_EN |
> - MII_BRCM_FET_IR_LINK_EN |
> - MII_BRCM_FET_IR_ENABLE |
> - MII_BRCM_FET_IR_MASK;
Note this style of formatting, where MII_BRCM_xxx line up with the
first...
> + if (phydev->phy_id == PHY_ID_BCM5221)
> + reg = MII_BRCM_FET_IR_ENABLE |
> + MII_BRCM_FET_IR_MASK;
That should be repeated here.
> + else
> + reg = MII_BRCM_FET_IR_DUPLEX_EN |
> + MII_BRCM_FET_IR_SPEED_EN |
> + MII_BRCM_FET_IR_LINK_EN |
> + MII_BRCM_FET_IR_ENABLE |
> + MII_BRCM_FET_IR_MASK;
and here.
>
> err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
> if (err < 0)
> @@ -726,42 +731,50 @@ static int brcm_fet_config_init(struct phy_device *phydev)
>
> reg = brcmtest | MII_BRCM_FET_BT_SRE;
>
> - err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
> - if (err < 0)
> - return err;
> + phy_lock_mdio_bus(phydev);
>
> - /* Set the LED mode */
> - reg = phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4);
> - if (reg < 0) {
> - err = reg;
> - goto done;
> + err = __phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
> + if (err < 0) {
> + phy_unlock_mdio_bus(phydev);
> + return err;
> }
>
> - reg &= ~MII_BRCM_FET_SHDW_AM4_LED_MASK;
> - reg |= MII_BRCM_FET_SHDW_AM4_LED_MODE1;
> + if (phydev->phy_id != PHY_ID_BCM5221) {
> + /* Set the LED mode */
> + reg = __phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4);
> + if (reg < 0) {
> + err = reg;
> + goto done;
> + }
>
> - err = phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg);
> - if (err < 0)
> - goto done;
> + reg &= ~MII_BRCM_FET_SHDW_AM4_LED_MASK;
> + reg |= MII_BRCM_FET_SHDW_AM4_LED_MODE1;
>
> - /* Enable auto MDIX */
> - err = phy_set_bits(phydev, MII_BRCM_FET_SHDW_MISCCTRL,
> - MII_BRCM_FET_SHDW_MC_FAME);
> - if (err < 0)
> - goto done;
> + err = __phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg);
I think this can be simplified to:
err = __phy_modify(phydev, MII_BRCM_FET_SHDW_AUXMODE4,
MII_BRCM_FET_SHDW_AM4_LED_MASK,
MII_BRCM_FET_SHDW_AM4_LED_MODE1);
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!