public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Heiko Stuebner <heiko@sntech.de>,
	Jakub Kicinski <kuba@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com, netdev@vger.kernel.org,
	Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net-next v2 17/22] net: stmmac: rk: introduce flags indicating support for RGMII/RMII
Date: Mon, 26 Jan 2026 11:46:25 +0000	[thread overview]
Message-ID: <E1vkL33-00000005utm-0Ge0@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <aXdTi4ViCkhhXvFI@shell.armlinux.org.uk>

Introduce two boolean flags into struct rk_priv_data indicating
whether RGMII and/or RMII is supported for this instance. Use these
to configure the supported_interfaces mask for phylink, validate the
interface mode. Initialise these from equivalent flags in the
rk_gmac_ops or depending on the presence of the ops->set_to_rgmii and
ops->set_to_mii methods. Finally, make ops->set_to_* optional.

This will allow us to get rid of empty set_to_rmii() methods.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
 .../net/ethernet/stmicro/stmmac/dwmac-rk.c    | 35 +++++++++++++------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index 9211260a86ff..ad6093f9d9eb 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -53,6 +53,8 @@ struct rk_gmac_ops {
 
 	bool gmac_grf_reg_in_php;
 	bool clock_grf_reg_in_php;
+	bool supports_rgmii;
+	bool supports_rmii;
 	bool php_grf_required;
 	bool regs_valid;
 	u32 regs[];
@@ -86,6 +88,8 @@ struct rk_priv_data {
 	bool clk_enabled;
 	bool clock_input;
 	bool integrated_phy;
+	bool supports_rgmii;
+	bool supports_rmii;
 
 	struct clk_bulk_data *clks;
 	int num_clks;
@@ -1415,6 +1419,9 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
 	bsp_priv->clock_grf_reg = ops->clock_grf_reg;
 	bsp_priv->clock = ops->clock;
 
+	bsp_priv->supports_rgmii = ops->supports_rgmii || !!ops->set_to_rgmii;
+	bsp_priv->supports_rmii = ops->supports_rmii || !!ops->set_to_rmii;
+
 	if (ops->init) {
 		ret = ops->init(bsp_priv);
 		if (ret) {
@@ -1433,11 +1440,11 @@ static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv)
 	case PHY_INTERFACE_MODE_RGMII_ID:
 	case PHY_INTERFACE_MODE_RGMII_RXID:
 	case PHY_INTERFACE_MODE_RGMII_TXID:
-		if (!bsp_priv->ops->set_to_rgmii)
+		if (!bsp_priv->supports_rgmii)
 			return -EINVAL;
 		break;
 	case PHY_INTERFACE_MODE_RMII:
-		if (!bsp_priv->ops->set_to_rmii)
+		if (!bsp_priv->supports_rmii)
 			return -EINVAL;
 		break;
 	default:
@@ -1486,24 +1493,32 @@ static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
 	switch (bsp_priv->phy_iface) {
 	case PHY_INTERFACE_MODE_RGMII:
 		dev_info(dev, "init for RGMII\n");
-		bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay,
-					    bsp_priv->rx_delay);
+		if (bsp_priv->ops->set_to_rgmii)
+			bsp_priv->ops->set_to_rgmii(bsp_priv,
+						    bsp_priv->tx_delay,
+						    bsp_priv->rx_delay);
 		break;
 	case PHY_INTERFACE_MODE_RGMII_ID:
 		dev_info(dev, "init for RGMII_ID\n");
-		bsp_priv->ops->set_to_rgmii(bsp_priv, 0, 0);
+		if (bsp_priv->ops->set_to_rgmii)
+			bsp_priv->ops->set_to_rgmii(bsp_priv, 0, 0);
 		break;
 	case PHY_INTERFACE_MODE_RGMII_RXID:
 		dev_info(dev, "init for RGMII_RXID\n");
-		bsp_priv->ops->set_to_rgmii(bsp_priv, bsp_priv->tx_delay, 0);
+		if (bsp_priv->ops->set_to_rgmii)
+			bsp_priv->ops->set_to_rgmii(bsp_priv,
+						    bsp_priv->tx_delay, 0);
 		break;
 	case PHY_INTERFACE_MODE_RGMII_TXID:
 		dev_info(dev, "init for RGMII_TXID\n");
-		bsp_priv->ops->set_to_rgmii(bsp_priv, 0, bsp_priv->rx_delay);
+		if (bsp_priv->ops->set_to_rgmii)
+			bsp_priv->ops->set_to_rgmii(bsp_priv,
+						    0, bsp_priv->rx_delay);
 		break;
 	case PHY_INTERFACE_MODE_RMII:
 		dev_info(dev, "init for RMII\n");
-		bsp_priv->ops->set_to_rmii(bsp_priv);
+		if (bsp_priv->ops->set_to_rmii)
+			bsp_priv->ops->set_to_rmii(bsp_priv);
 		break;
 	default:
 		dev_err(dev, "NO interface defined!\n");
@@ -1539,10 +1554,10 @@ static void rk_get_interfaces(struct stmmac_priv *priv, void *bsp_priv,
 {
 	struct rk_priv_data *rk = bsp_priv;
 
-	if (rk->ops->set_to_rgmii)
+	if (rk->supports_rgmii)
 		phy_interface_set_rgmii(interfaces);
 
-	if (rk->ops->set_to_rmii)
+	if (rk->supports_rmii)
 		__set_bit(PHY_INTERFACE_MODE_RMII, interfaces);
 }
 
-- 
2.47.3


  parent reply	other threads:[~2026-01-26 11:46 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 11:44 [PATCH net-next v2 00/22] net: stmmac: rk: simplify per-SoC configuration Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 01/22] net: stmmac: rk: avoid phy_power_on() Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 02/22] net: stmmac: rk: get rid of rk_phy_power_ctl() Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 03/22] net: stmmac: rk: convert rk3328 to use bsp_priv->id Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 04/22] net: stmmac: rk: group MACPHY register offset and fields together Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 05/22] net: stmmac: rk: add GMAC_CLK_xx constants, simplify RGMII definitions Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 06/22] net: stmmac: rk: add SoC specific ->init() method Russell King (Oracle)
2026-01-26 14:34   ` Russell King (Oracle)
2026-01-27  0:51     ` Jakub Kicinski
2026-01-27  0:59       ` Russell King (Oracle)
2026-01-27  1:16         ` Jakub Kicinski
2026-01-27  1:55           ` Russell King (Oracle)
2026-01-27  2:54             ` Jakub Kicinski
2026-01-27  0:40   ` [net-next,v2,06/22] " Jakub Kicinski
2026-01-27  0:51     ` Russell King (Oracle)
2026-01-27 11:09       ` Russell King (Oracle)
2026-01-27 16:18         ` Jakub Kicinski
2026-01-27 16:42           ` Russell King (Oracle)
2026-01-27 18:38             ` Jakub Kicinski
2026-01-26 11:45 ` [PATCH net-next v2 07/22] net: stmmac: rk: convert to mask-based interface mode configuration Russell King (Oracle)
2026-01-27  0:40   ` [net-next,v2,07/22] " Jakub Kicinski
2026-01-27  0:53     ` Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 08/22] net: stmmac: rk: convert rk3588 to mask-based interface mode config Russell King (Oracle)
2026-01-26 22:19   ` kernel test robot
2026-01-27  0:41   ` [net-next,v2,08/22] " Jakub Kicinski
2026-01-26 11:45 ` [PATCH net-next v2 09/22] net: stmmac: rk: move speed GRF register offset to private data Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 10/22] net: stmmac: rk: convert rk3588 to rk_set_reg_speed() Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 11/22] net: stmmac: rk: remove rk3528 RMII clock initialisation Russell King (Oracle)
2026-01-26 11:45 ` [PATCH net-next v2 12/22] net: stmmac: rk: use rk_encode_wm16() for RGMII clocks Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 13/22] net: stmmac: rk: use rk_encode_wm16() for RMII speed Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 14/22] net: stmmac: rk: use rk_encode_wm16() for RMII clock Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 15/22] net: stmmac: rk: remove need for ->set_speed() method Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 16/22] net: stmmac: rk: convert px30 Russell King (Oracle)
2026-01-26 11:46 ` Russell King (Oracle) [this message]
2026-01-26 11:46 ` [PATCH net-next v2 18/22] net: stmmac: rk: replace empty set_to_rmii() with supports_rmii Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 19/22] net: stmmac: rk: rk3328: gmac2phy only supports RMII Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 20/22] net: stmmac: rk: rk3528: gmac0 " Russell King (Oracle)
2026-01-26 11:46 ` [PATCH net-next v2 21/22] net: stmmac: rk: use rk_encode_wm16() for clock selection Russell King (Oracle)
2026-01-27  0:41   ` [net-next,v2,21/22] " Jakub Kicinski
2026-01-26 11:46 ` [PATCH net-next v2 22/22] net: stmmac: rk: rk3506, rk3528 and kk3588 have rmii_mode in clock register Russell King (Oracle)
2026-01-27  0:41   ` [net-next,v2,22/22] " Jakub Kicinski
2026-01-27 19:00 ` [PATCH net-next v2 00/22] net: stmmac: rk: simplify per-SoC configuration patchwork-bot+netdevbpf

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=E1vkL33-00000005utm-0Ge0@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux.org.uk \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=heiko@sntech.de \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --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