提交 37c80d15 编写于 作者: D David Wu 提交者: David S. Miller

net: stmmac: dwmac-rk: Check platform-specific ops

Add a check for non-null struct rk_gmac_ops for the
configured PHY interface mode, failing if unsupported.
Signed-off-by: NDavid Wu <david.wu@rock-chips.com>
[Ezequiel: Refactor so it fails if unsupported]
Signed-off-by: NEzequiel Garcia <ezequiel@collabora.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 d6b06251
......@@ -1342,11 +1342,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;
......@@ -1417,10 +1442,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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册