Merge branch 'bcm63xx_enet-small-fixes-and-cleanups'

Jonas Gorski says:

====================
bcm63xx_enet: small fixes and cleanups

This patch set fixes a few theoretical issues and cleans up the code a
bit. It also adds a bit more managed function usage to simplify clock
and iomem usage.

Based on net-next.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David S. Miller 2017-10-01 23:05:11 -07:00
commit ed36edf870
2 changed files with 28 additions and 51 deletions

View File

@ -1062,7 +1062,8 @@ static int bcm_enet_open(struct net_device *dev)
val = enet_readl(priv, ENET_CTL_REG); val = enet_readl(priv, ENET_CTL_REG);
val |= ENET_CTL_ENABLE_MASK; val |= ENET_CTL_ENABLE_MASK;
enet_writel(priv, val, ENET_CTL_REG); enet_writel(priv, val, ENET_CTL_REG);
enet_dma_writel(priv, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG); if (priv->dma_has_sram)
enet_dma_writel(priv, ENETDMA_CFG_EN_MASK, ENETDMA_CFG_REG);
enet_dmac_writel(priv, priv->dma_chan_en_mask, enet_dmac_writel(priv, priv->dma_chan_en_mask,
ENETDMAC_CHANCFG, priv->rx_chan); ENETDMAC_CHANCFG, priv->rx_chan);
@ -1721,10 +1722,8 @@ static int bcm_enet_probe(struct platform_device *pdev)
const char *clk_name; const char *clk_name;
int i, ret; int i, ret;
/* stop if shared driver failed, assume driver->probe will be
* called in the same order we register devices (correct ?) */
if (!bcm_enet_shared_base[0]) if (!bcm_enet_shared_base[0])
return -ENODEV; return -EPROBE_DEFER;
res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1); res_irq_rx = platform_get_resource(pdev, IORESOURCE_IRQ, 1);
@ -1768,12 +1767,14 @@ static int bcm_enet_probe(struct platform_device *pdev)
clk_name = "enet1"; clk_name = "enet1";
} }
priv->mac_clk = clk_get(&pdev->dev, clk_name); priv->mac_clk = devm_clk_get(&pdev->dev, clk_name);
if (IS_ERR(priv->mac_clk)) { if (IS_ERR(priv->mac_clk)) {
ret = PTR_ERR(priv->mac_clk); ret = PTR_ERR(priv->mac_clk);
goto out; goto out;
} }
clk_prepare_enable(priv->mac_clk); ret = clk_prepare_enable(priv->mac_clk);
if (ret)
goto out;
/* initialize default and fetch platform data */ /* initialize default and fetch platform data */
priv->rx_ring_size = BCMENET_DEF_RX_DESC; priv->rx_ring_size = BCMENET_DEF_RX_DESC;
@ -1801,13 +1802,15 @@ static int bcm_enet_probe(struct platform_device *pdev)
if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) { if (priv->mac_id == 0 && priv->has_phy && !priv->use_external_mii) {
/* using internal PHY, enable clock */ /* using internal PHY, enable clock */
priv->phy_clk = clk_get(&pdev->dev, "ephy"); priv->phy_clk = devm_clk_get(&pdev->dev, "ephy");
if (IS_ERR(priv->phy_clk)) { if (IS_ERR(priv->phy_clk)) {
ret = PTR_ERR(priv->phy_clk); ret = PTR_ERR(priv->phy_clk);
priv->phy_clk = NULL; priv->phy_clk = NULL;
goto out_put_clk_mac; goto out_disable_clk_mac;
} }
clk_prepare_enable(priv->phy_clk); ret = clk_prepare_enable(priv->phy_clk);
if (ret)
goto out_disable_clk_mac;
} }
/* do minimal hardware init to be able to probe mii bus */ /* do minimal hardware init to be able to probe mii bus */
@ -1900,14 +1903,10 @@ static int bcm_enet_probe(struct platform_device *pdev)
out_uninit_hw: out_uninit_hw:
/* turn off mdc clock */ /* turn off mdc clock */
enet_writel(priv, 0, ENET_MIISC_REG); enet_writel(priv, 0, ENET_MIISC_REG);
if (priv->phy_clk) { clk_disable_unprepare(priv->phy_clk);
clk_disable_unprepare(priv->phy_clk);
clk_put(priv->phy_clk);
}
out_put_clk_mac: out_disable_clk_mac:
clk_disable_unprepare(priv->mac_clk); clk_disable_unprepare(priv->mac_clk);
clk_put(priv->mac_clk);
out: out:
free_netdev(dev); free_netdev(dev);
return ret; return ret;
@ -1943,12 +1942,8 @@ static int bcm_enet_remove(struct platform_device *pdev)
} }
/* disable hw block clocks */ /* disable hw block clocks */
if (priv->phy_clk) { clk_disable_unprepare(priv->phy_clk);
clk_disable_unprepare(priv->phy_clk);
clk_put(priv->phy_clk);
}
clk_disable_unprepare(priv->mac_clk); clk_disable_unprepare(priv->mac_clk);
clk_put(priv->mac_clk);
free_netdev(dev); free_netdev(dev);
return 0; return 0;
@ -2688,11 +2683,8 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
struct resource *res_mem; struct resource *res_mem;
int ret, irq_rx, irq_tx; int ret, irq_rx, irq_tx;
/* stop if shared driver failed, assume driver->probe will be
* called in the same order we register devices (correct ?)
*/
if (!bcm_enet_shared_base[0]) if (!bcm_enet_shared_base[0])
return -ENODEV; return -EPROBE_DEFER;
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
irq_rx = platform_get_irq(pdev, 0); irq_rx = platform_get_irq(pdev, 0);
@ -2731,24 +2723,20 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
if (ret) if (ret)
goto out; goto out;
if (!request_mem_region(res_mem->start, resource_size(res_mem), priv->base = devm_ioremap_resource(&pdev->dev, res_mem);
"bcm63xx_enetsw")) { if (IS_ERR(priv->base)) {
ret = -EBUSY; ret = PTR_ERR(priv->base);
goto out; goto out;
} }
priv->base = ioremap(res_mem->start, resource_size(res_mem)); priv->mac_clk = devm_clk_get(&pdev->dev, "enetsw");
if (priv->base == NULL) {
ret = -ENOMEM;
goto out_release_mem;
}
priv->mac_clk = clk_get(&pdev->dev, "enetsw");
if (IS_ERR(priv->mac_clk)) { if (IS_ERR(priv->mac_clk)) {
ret = PTR_ERR(priv->mac_clk); ret = PTR_ERR(priv->mac_clk);
goto out_unmap; goto out;
} }
clk_enable(priv->mac_clk); ret = clk_prepare_enable(priv->mac_clk);
if (ret)
goto out;
priv->rx_chan = 0; priv->rx_chan = 0;
priv->tx_chan = 1; priv->tx_chan = 1;
@ -2769,7 +2757,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
ret = register_netdev(dev); ret = register_netdev(dev);
if (ret) if (ret)
goto out_put_clk; goto out_disable_clk;
netif_carrier_off(dev); netif_carrier_off(dev);
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
@ -2778,14 +2766,8 @@ static int bcm_enetsw_probe(struct platform_device *pdev)
return 0; return 0;
out_put_clk: out_disable_clk:
clk_put(priv->mac_clk); clk_disable_unprepare(priv->mac_clk);
out_unmap:
iounmap(priv->base);
out_release_mem:
release_mem_region(res_mem->start, resource_size(res_mem));
out: out:
free_netdev(dev); free_netdev(dev);
return ret; return ret;
@ -2797,17 +2779,13 @@ static int bcm_enetsw_remove(struct platform_device *pdev)
{ {
struct bcm_enet_priv *priv; struct bcm_enet_priv *priv;
struct net_device *dev; struct net_device *dev;
struct resource *res;
/* stop netdevice */ /* stop netdevice */
dev = platform_get_drvdata(pdev); dev = platform_get_drvdata(pdev);
priv = netdev_priv(dev); priv = netdev_priv(dev);
unregister_netdev(dev); unregister_netdev(dev);
/* release device resources */ clk_disable_unprepare(priv->mac_clk);
iounmap(priv->base);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
free_netdev(dev); free_netdev(dev);
return 0; return 0;

View File

@ -8,7 +8,6 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <bcm63xx_regs.h> #include <bcm63xx_regs.h>
#include <bcm63xx_irq.h>
#include <bcm63xx_io.h> #include <bcm63xx_io.h>
#include <bcm63xx_iudma.h> #include <bcm63xx_iudma.h>