Re: [PATCH v3] net: phy: add driver for Motorcomm yt8511 phy
From: Peter Geis <hidden>
Date: 2021-05-14 14:09:50
Also in:
lkml, netdev
On Fri, May 14, 2021 at 9:09 AM Russell King (Oracle) [off-list ref] wrote:
Hi! On Fri, May 14, 2021 at 07:58:26AM -0400, Peter Geis wrote:quoted
+ /* set rgmii delay mode */ + val = __phy_read(phydev, YT8511_PAGE); + + switch (phydev->interface) { + case PHY_INTERFACE_MODE_RGMII: + val &= ~(YT8511_DELAY_RX | YT8511_DELAY_TX); + break; + case PHY_INTERFACE_MODE_RGMII_ID: + val |= YT8511_DELAY_RX | YT8511_DELAY_TX; + break; + case PHY_INTERFACE_MODE_RGMII_RXID: + val &= ~(YT8511_DELAY_TX); + val |= YT8511_DELAY_RX; + break; + case PHY_INTERFACE_MODE_RGMII_TXID: + val &= ~(YT8511_DELAY_RX); + val |= YT8511_DELAY_TX; + break; + default: /* leave everything alone in other modes */ + break; + } + + ret = __phy_write(phydev, YT8511_PAGE, val); + if (ret < 0) + goto err_restore_page;Another way of writing the above is to set "val" to be the value of the YT8511_DELAY_RX and YT8511_DELAY_TX bits, and then do: ret = __phy_modify(phydev, YT8511_PAGE, (YT8511_DELAY_RX | YT8511_DELAY_TX), val); if (ret < 0) goto err_restore_page; which moves the read-modify-write out of the driver into core code and makes the driver code smaller. It also handles your missing error check on __phy_read() above - would you want the above code to attempt to write a -ve error number back to this register? I suspect not!
That makes sense, thanks! I was thinking about how to use __phy_modify with a functional mask, but it didn't click until I had already sent it in. Also thanks for catching handling that ret on the read!
-- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
_______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip