From: Ezequiel Garcia <ezequiel@collabora.com>
To: netdev@vger.kernel.org, linux-rockchip@lists.infradead.org
Cc: Jose Abreu <joabreu@synopsys.com>,
Heiko Stuebner <heiko@sntech.de>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Peter Geis <pgwipeout@gmail.com>,
David Wu <david.wu@rock-chips.com>,
kernel@collabora.com, Ezequiel Garcia <ezequiel@collabora.com>
Subject: [PATCH net-next 2/3] net: stmmac: dwmac-rk: Check platform-specific ops
Date: Tue, 13 Apr 2021 18:02:34 -0300 [thread overview]
Message-ID: <20210413210235.489467-3-ezequiel@collabora.com> (raw)
In-Reply-To: <20210413210235.489467-1-ezequiel@collabora.com>
From: David Wu <david.wu@rock-chips.com>
Add a check for non-null struct rk_gmac_ops for the
configured PHY interface mode, failing if unsupported.
Signed-off-by: David Wu <david.wu@rock-chips.com>
[Ezequiel: Refactor so it fails if unsupported]
Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
---
.../net/ethernet/stmicro/stmmac/dwmac-rk.c | 31 +++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
index c432a9592489..d2637d83899e 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-rk.c
@@ -1294,11 +1294,36 @@ static struct rk_priv_data *rk_gmac_setup(struct platform_device *pdev,
return bsp_priv;
}
+static int rk_gmac_check_ops(struct rk_priv_data *bsp_priv)
+{
+ switch (bsp_priv->phy_iface) {
+ case PHY_INTERFACE_MODE_RGMII:
+ 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)
+ return -EINVAL;
+ break;
+ case PHY_INTERFACE_MODE_RMII:
+ if (!bsp_priv->ops->set_to_rmii)
+ return -EINVAL;
+ break;
+ default:
+ dev_err(&bsp_priv->pdev->dev,
+ "unsupported interface %d", bsp_priv->phy_iface);
+ }
+ return 0;
+}
+
static int rk_gmac_powerup(struct rk_priv_data *bsp_priv)
{
int ret;
struct device *dev = &bsp_priv->pdev->dev;
+ ret = rk_gmac_check_ops(bsp_priv);
+ if (ret)
+ return ret;
+
ret = gmac_clk_enable(bsp_priv, true);
if (ret)
return ret;
@@ -1369,10 +1394,12 @@ static void rk_fix_speed(void *priv, unsigned int speed)
case PHY_INTERFACE_MODE_RGMII_ID:
case PHY_INTERFACE_MODE_RGMII_RXID:
case PHY_INTERFACE_MODE_RGMII_TXID:
- bsp_priv->ops->set_rgmii_speed(bsp_priv, speed);
+ if (bsp_priv->ops->set_rgmii_speed)
+ bsp_priv->ops->set_rgmii_speed(bsp_priv, speed);
break;
case PHY_INTERFACE_MODE_RMII:
- bsp_priv->ops->set_rmii_speed(bsp_priv, speed);
+ if (bsp_priv->ops->set_rmii_speed)
+ bsp_priv->ops->set_rmii_speed(bsp_priv, speed);
break;
default:
dev_err(dev, "unsupported interface %d", bsp_priv->phy_iface);
--
2.30.0
next prev parent reply other threads:[~2021-04-13 21:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 21:02 [PATCH net-next 0/3] net: stmmac: RK3566/RK3568 Ezequiel Garcia
2021-04-13 21:02 ` [PATCH net-next 1/3] net: stmmac: Don't set has_gmac if has_gmac4 is set Ezequiel Garcia
2021-04-13 21:02 ` Ezequiel Garcia [this message]
2021-04-13 21:02 ` [PATCH net-next 3/3] net: stmmac: Add RK3566/RK3568 SoC support Ezequiel Garcia
2021-04-13 22:51 ` Peter Geis
[not found] ` <1412-60762b80-423-d9eaa5@27901112>
2021-04-14 11:03 ` Peter Geis
2021-04-14 11:15 ` Heiko Stübner
2021-04-14 13:48 ` Ezequiel Garcia
2021-04-14 16:33 ` Chen-Yu Tsai
2021-04-14 16:35 ` Heiko Stübner
2021-04-14 16:44 ` Ezequiel Garcia
2021-04-14 13:48 ` Ezequiel Garcia
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=20210413210235.489467-3-ezequiel@collabora.com \
--to=ezequiel@collabora.com \
--cc=davem@davemloft.net \
--cc=david.wu@rock-chips.com \
--cc=heiko@sntech.de \
--cc=joabreu@synopsys.com \
--cc=kernel@collabora.com \
--cc=kuba@kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=pgwipeout@gmail.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;
as well as URLs for NNTP newsgroup(s).