public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Damato <jdamato@fastly.com>
To: Michael Klein <michael@fossekall.de>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RESEND net-next v5 2/4] net: phy: realtek: Clean up RTL8211E ExtPage access
Date: Mon, 7 Apr 2025 19:56:14 -0700	[thread overview]
Message-ID: <Z_SQTi-uKk4wqRcL@LQ3V64L9R2> (raw)
In-Reply-To: <20250407182155.14925-3-michael@fossekall.de>

On Mon, Apr 07, 2025 at 08:21:41PM +0200, Michael Klein wrote:
> - Factor out RTL8211E extension page access code to
>   rtl8211e_modify_ext_page() and clean up rtl8211e_config_init()
> 
> Signed-off-by: Michael Klein <michael@fossekall.de>
> ---
>  drivers/net/phy/realtek/realtek_main.c | 38 +++++++++++++++-----------
>  1 file changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
> index b27c0f995e56..e60c18551a4e 100644
> --- a/drivers/net/phy/realtek/realtek_main.c
> +++ b/drivers/net/phy/realtek/realtek_main.c
> @@ -37,9 +37,11 @@
>  
>  #define RTL821x_INSR				0x13
>  
> -#define RTL821x_EXT_PAGE_SELECT			0x1e
>  #define RTL821x_PAGE_SELECT			0x1f
>  
> +#define RTL8211E_EXT_PAGE_SELECT		0x1e
> +#define RTL8211E_SET_EXT_PAGE			0x07
> +
>  #define RTL8211E_CTRL_DELAY			BIT(13)
>  #define RTL8211E_TX_DELAY			BIT(12)
>  #define RTL8211E_RX_DELAY			BIT(11)
> @@ -135,6 +137,21 @@ static int rtl821x_write_page(struct phy_device *phydev, int page)
>  	return __phy_write(phydev, RTL821x_PAGE_SELECT, page);
>  }
>  
> +static int rtl8211e_modify_ext_page(struct phy_device *phydev, u16 ext_page,
> +				    u32 regnum, u16 mask, u16 set)
> +{
> +	int oldpage, ret = 0;
> +
> +	oldpage = phy_select_page(phydev, RTL8211E_SET_EXT_PAGE);
> +	if (oldpage >= 0) {
> +		ret = __phy_write(phydev, RTL8211E_EXT_PAGE_SELECT, ext_page);
> +		if (ret == 0)
> +			ret = __phy_modify(phydev, regnum, mask, set);
> +	}
> +
> +	return phy_restore_page(phydev, oldpage, ret);
> +}
> +
>  static int rtl821x_probe(struct phy_device *phydev)
>  {
>  	struct device *dev = &phydev->mdio.dev;
> @@ -607,7 +624,9 @@ static int rtl8211f_led_hw_control_set(struct phy_device *phydev, u8 index,
>  
>  static int rtl8211e_config_init(struct phy_device *phydev)
>  {
> -	int ret = 0, oldpage;
> +	const u16 delay_mask = RTL8211E_CTRL_DELAY |
> +			       RTL8211E_TX_DELAY |
> +			       RTL8211E_RX_DELAY;
>  	u16 val;
>  
>  	/* enable TX/RX delay for rgmii-* modes, and disable them for rgmii. */
> @@ -637,20 +656,7 @@ static int rtl8211e_config_init(struct phy_device *phydev)
>  	 * 12 = RX Delay, 11 = TX Delay
>  	 * 10:0 = Test && debug settings reserved by realtek
>  	 */
> -	oldpage = phy_select_page(phydev, 0x7);
> -	if (oldpage < 0)
> -		goto err_restore_page;
> -
> -	ret = __phy_write(phydev, RTL821x_EXT_PAGE_SELECT, 0xa4);
> -	if (ret)
> -		goto err_restore_page;
> -
> -	ret = __phy_modify(phydev, 0x1c, RTL8211E_CTRL_DELAY
> -			   | RTL8211E_TX_DELAY | RTL8211E_RX_DELAY,
> -			   val);
> -
> -err_restore_page:
> -	return phy_restore_page(phydev, oldpage, ret);
> +	return rtl8211e_modify_ext_page(phydev, 0xa4, 0x1c, delay_mask, val);
>  }

Seems good to add RTL8211E_SET_EXT_PAGE to remove a constant from
the code. Any reason to avoid adding constants for 0xa4 and 0x1c ?

  reply	other threads:[~2025-04-08  2:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-07 18:21 [RESEND net-next v5 0/4] net: phy: realtek: Add support for PHY LEDs on Michael Klein
2025-04-07 18:21 ` [RESEND net-next v5 1/4] net: phy: realtek: Group RTL82* macro definitions Michael Klein
2025-04-08  2:52   ` Joe Damato
2025-04-08 12:17     ` Andrew Lunn
2025-04-08 14:27       ` Russell King (Oracle)
2025-04-10 22:05       ` Michael Klein
2025-04-07 18:21 ` [RESEND net-next v5 2/4] net: phy: realtek: Clean up RTL8211E ExtPage access Michael Klein
2025-04-08  2:56   ` Joe Damato [this message]
2025-04-08 18:47     ` Michael Klein
2025-04-08 19:21       ` Andrew Lunn
2025-04-07 18:21 ` [RESEND net-next v5 3/4] net: phy: realtek: use __set_bit() in rtl8211f_led_hw_control_get() Michael Klein
2025-04-07 18:21 ` [RESEND net-next v5 4/4] net: phy: realtek: Add support for PHY LEDs on RTL8211E Michael Klein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z_SQTi-uKk4wqRcL@LQ3V64L9R2 \
    --to=jdamato@fastly.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=michael@fossekall.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox