Thread (10 messages) 10 messages, 4 authors, 2021-05-14

Re: [PATCH v3] net: phy: add driver for Motorcomm yt8511 phy

From: "Russell King (Oracle)" <linux@armlinux.org.uk>
Date: 2021-05-14 13:09:19
Also in: linux-rockchip, lkml

Hi!

On Fri, May 14, 2021 at 07:58:26AM -0400, Peter Geis wrote:
+	/* 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!

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help