Skip to content

Commit

Permalink
Merge branch 'stmmac-devvm_stmmac_probe_config_dt-conversion'
Browse files Browse the repository at this point in the history
Jisheng Zhang says:

====================
stmmac: convert to devm_stmmac_probe_config_dt

Russell pointed out there's a new devm_stmmac_probe_config_dt()
helper now when reviewing my starfive gmac error handling patch[1].
After greping the code, this nice helper was introduced by Bartosz in
[2], I think it's time to convert all dwmac users to this helper and
finally complete the TODO in [2] "but once all users of the old
stmmac_pltfr_remove() are converted to the devres helper, it will be
renamed back to stmmac_pltfr_remove() and the no_dt function removed."

Link: https://lore.kernel.org/netdev/ZOtWmedBsa6wQQ6+@shell.armlinux.org.uk/ [1]
Link: https://lore.kernel.org/all/20230623100417.93592-1-brgl@bgdev.pl/  [2]

Since v1:
 - rebase on new net-next
 - add make stmmac_{probe|remove}_config_dt static as suggested by Russell.
====================

Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Sep 18, 2023
2 parents e8535bf + b2504f6 commit a5ea265
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 317 deletions.
10 changes: 2 additions & 8 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-anarion.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static int anarion_dwmac_probe(struct platform_device *pdev)
if (IS_ERR(gmac))
return PTR_ERR(gmac);

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);

Expand All @@ -124,13 +124,7 @@ static int anarion_dwmac_probe(struct platform_device *pdev)
anarion_gmac_init(pdev, gmac);
plat_dat->bsp_priv = gmac;

ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (ret) {
stmmac_remove_config_dt(pdev, plat_dat);
return ret;
}

return 0;
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
}

static const struct of_device_id anarion_dwmac_match[] = {
Expand Down
15 changes: 3 additions & 12 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-dwc-qos-eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,14 @@ static int dwc_eth_dwmac_probe(struct platform_device *pdev)
if (IS_ERR(stmmac_res.addr))
return PTR_ERR(stmmac_res.addr);

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);

ret = data->probe(pdev, plat_dat, &stmmac_res);
if (ret < 0) {
dev_err_probe(&pdev->dev, ret, "failed to probe subdriver\n");

goto remove_config;
return ret;
}

ret = dwc_eth_dwmac_config_dt(pdev, plat_dat);
Expand All @@ -458,25 +457,17 @@ static int dwc_eth_dwmac_probe(struct platform_device *pdev)

remove:
data->remove(pdev);
remove_config:
stmmac_remove_config_dt(pdev, plat_dat);

return ret;
}

static void dwc_eth_dwmac_remove(struct platform_device *pdev)
{
struct net_device *ndev = platform_get_drvdata(pdev);
struct stmmac_priv *priv = netdev_priv(ndev);
const struct dwc_eth_dwmac_data *data;

data = device_get_match_data(&pdev->dev);
const struct dwc_eth_dwmac_data *data = device_get_match_data(&pdev->dev);

stmmac_dvr_remove(&pdev->dev);

data->remove(pdev);

stmmac_remove_config_dt(pdev, priv->plat);
}

static const struct of_device_id dwc_eth_dwmac_match[] = {
Expand Down
15 changes: 2 additions & 13 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static int dwmac_generic_probe(struct platform_device *pdev)
return ret;

if (pdev->dev.of_node) {
plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat)) {
dev_err(&pdev->dev, "dt configuration failed\n");
return PTR_ERR(plat_dat);
Expand All @@ -46,17 +46,7 @@ static int dwmac_generic_probe(struct platform_device *pdev)
plat_dat->unicast_filter_entries = 1;
}

ret = stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
if (ret)
goto err_remove_config_dt;

return 0;

err_remove_config_dt:
if (pdev->dev.of_node)
stmmac_remove_config_dt(pdev, plat_dat);

return ret;
return devm_stmmac_pltfr_probe(pdev, plat_dat, &stmmac_res);
}

static const struct of_device_id dwmac_generic_match[] = {
Expand All @@ -77,7 +67,6 @@ MODULE_DEVICE_TABLE(of, dwmac_generic_match);

static struct platform_driver dwmac_generic_driver = {
.probe = dwmac_generic_probe,
.remove_new = stmmac_pltfr_remove,
.driver = {
.name = STMMAC_RESOURCE_NAME,
.pm = &stmmac_pltfr_pm_ops,
Expand Down
13 changes: 4 additions & 9 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,14 @@ static int imx_dwmac_probe(struct platform_device *pdev)
if (!dwmac)
return -ENOMEM;

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);

data = of_device_get_match_data(&pdev->dev);
if (!data) {
dev_err(&pdev->dev, "failed to get match data\n");
ret = -EINVAL;
goto err_match_data;
return -EINVAL;
}

dwmac->ops = data;
Expand All @@ -348,7 +347,7 @@ static int imx_dwmac_probe(struct platform_device *pdev)
ret = imx_dwmac_parse_dt(dwmac, &pdev->dev);
if (ret) {
dev_err(&pdev->dev, "failed to parse OF data\n");
goto err_parse_dt;
return ret;
}

if (data->flags & STMMAC_FLAG_HWTSTAMP_CORRECT_LATENCY)
Expand All @@ -365,7 +364,7 @@ static int imx_dwmac_probe(struct platform_device *pdev)

ret = imx_dwmac_clks_config(dwmac, true);
if (ret)
goto err_clks_config;
return ret;

ret = imx_dwmac_init(pdev, dwmac);
if (ret)
Expand All @@ -385,10 +384,6 @@ static int imx_dwmac_probe(struct platform_device *pdev)
imx_dwmac_exit(pdev, plat_dat->bsp_priv);
err_dwmac_init:
imx_dwmac_clks_config(dwmac, false);
err_clks_config:
err_parse_dt:
err_match_data:
stmmac_remove_config_dt(pdev, plat_dat);
return ret;
}

Expand Down
33 changes: 9 additions & 24 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-ingenic.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,29 +241,25 @@ static int ingenic_mac_probe(struct platform_device *pdev)
if (ret)
return ret;

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);

mac = devm_kzalloc(&pdev->dev, sizeof(*mac), GFP_KERNEL);
if (!mac) {
ret = -ENOMEM;
goto err_remove_config_dt;
}
if (!mac)
return -ENOMEM;

data = of_device_get_match_data(&pdev->dev);
if (!data) {
dev_err(&pdev->dev, "No of match data provided\n");
ret = -EINVAL;
goto err_remove_config_dt;
return -EINVAL;
}

/* Get MAC PHY control register */
mac->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "mode-reg");
if (IS_ERR(mac->regmap)) {
dev_err(&pdev->dev, "%s: Failed to get syscon regmap\n", __func__);
ret = PTR_ERR(mac->regmap);
goto err_remove_config_dt;
return PTR_ERR(mac->regmap);
}

if (!of_property_read_u32(pdev->dev.of_node, "tx-clk-delay-ps", &tx_delay_ps)) {
Expand All @@ -272,8 +268,7 @@ static int ingenic_mac_probe(struct platform_device *pdev)
mac->tx_delay = tx_delay_ps * 1000;
} else {
dev_err(&pdev->dev, "Invalid TX clock delay: %dps\n", tx_delay_ps);
ret = -EINVAL;
goto err_remove_config_dt;
return -EINVAL;
}
}

Expand All @@ -283,8 +278,7 @@ static int ingenic_mac_probe(struct platform_device *pdev)
mac->rx_delay = rx_delay_ps * 1000;
} else {
dev_err(&pdev->dev, "Invalid RX clock delay: %dps\n", rx_delay_ps);
ret = -EINVAL;
goto err_remove_config_dt;
return -EINVAL;
}
}

Expand All @@ -295,18 +289,9 @@ static int ingenic_mac_probe(struct platform_device *pdev)

ret = ingenic_mac_init(plat_dat);
if (ret)
goto err_remove_config_dt;

ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (ret)
goto err_remove_config_dt;

return 0;

err_remove_config_dt:
stmmac_remove_config_dt(pdev, plat_dat);
return ret;

return ret;
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
}

#ifdef CONFIG_PM_SLEEP
Expand Down
25 changes: 8 additions & 17 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-intel-plat.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,15 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
if (ret)
return ret;

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat)) {
dev_err(&pdev->dev, "dt configuration failed\n");
return PTR_ERR(plat_dat);
}

dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
if (!dwmac) {
ret = -ENOMEM;
goto err_remove_config_dt;
}
if (!dwmac)
return -ENOMEM;

dwmac->dev = &pdev->dev;
dwmac->tx_clk = NULL;
Expand All @@ -110,10 +108,8 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
/* Enable TX clock */
if (dwmac->data->tx_clk_en) {
dwmac->tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
if (IS_ERR(dwmac->tx_clk)) {
ret = PTR_ERR(dwmac->tx_clk);
goto err_remove_config_dt;
}
if (IS_ERR(dwmac->tx_clk))
return PTR_ERR(dwmac->tx_clk);

clk_prepare_enable(dwmac->tx_clk);

Expand All @@ -126,7 +122,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev,
"Failed to set tx_clk\n");
goto err_remove_config_dt;
return ret;
}
}
}
Expand All @@ -140,7 +136,7 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
if (ret) {
dev_err(&pdev->dev,
"Failed to set clk_ptp_ref\n");
goto err_remove_config_dt;
return ret;
}
}
}
Expand All @@ -158,15 +154,10 @@ static int intel_eth_plat_probe(struct platform_device *pdev)
ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (ret) {
clk_disable_unprepare(dwmac->tx_clk);
goto err_remove_config_dt;
return ret;
}

return 0;

err_remove_config_dt:
stmmac_remove_config_dt(pdev, plat_dat);

return ret;
}

static void intel_eth_plat_remove(struct platform_device *pdev)
Expand Down
27 changes: 8 additions & 19 deletions drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,22 +384,20 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
if (val)
return val;

plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
if (IS_ERR(plat_dat))
return PTR_ERR(plat_dat);

gmac = devm_kzalloc(dev, sizeof(*gmac), GFP_KERNEL);
if (!gmac) {
err = -ENOMEM;
goto err_remove_config_dt;
}
if (!gmac)
return -ENOMEM;

gmac->pdev = pdev;

err = ipq806x_gmac_of_parse(gmac);
if (err) {
dev_err(dev, "device tree parsing error\n");
goto err_remove_config_dt;
return err;
}

regmap_write(gmac->qsgmii_csr, QSGMII_PCS_CAL_LCKDT_CTL,
Expand Down Expand Up @@ -459,11 +457,11 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
if (gmac->phy_mode == PHY_INTERFACE_MODE_SGMII) {
err = ipq806x_gmac_configure_qsgmii_params(gmac);
if (err)
goto err_remove_config_dt;
return err;

err = ipq806x_gmac_configure_qsgmii_pcs_speed(gmac);
if (err)
goto err_remove_config_dt;
return err;
}

plat_dat->has_gmac = true;
Expand All @@ -473,21 +471,12 @@ static int ipq806x_gmac_probe(struct platform_device *pdev)
plat_dat->tx_fifo_size = 8192;
plat_dat->rx_fifo_size = 8192;

err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (err)
goto err_remove_config_dt;

return 0;
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);

err_unsupported_phy:
dev_err(&pdev->dev, "Unsupported PHY mode: \"%s\"\n",
phy_modes(gmac->phy_mode));
err = -EINVAL;

err_remove_config_dt:
stmmac_remove_config_dt(pdev, plat_dat);

return err;
return -EINVAL;
}

static const struct of_device_id ipq806x_gmac_dwmac_match[] = {
Expand Down
Loading

0 comments on commit a5ea265

Please sign in to comment.