lkml.org 
[lkml]   [2021]   [May]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH v3] net: phy: add driver for Motorcomm yt8511 phy
On Fri, May 14, 2021 at 9:09 AM Russell King (Oracle)
<linux@armlinux.org.uk> wrote:
>
> 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!

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!

\
 
 \ /
  Last update: 2021-05-14 16:10    [W:0.097 / U:1.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site