提交 93b31f48 编写于 作者: C Cyrille Pitchen 提交者: David S. Miller

net/macb: unify clock management

Most of the functions from the Common Clk Framework handle NULL pointer as
input argument.

Since the TX clock is optional, we now set tx_clk to NULL value
instead of ERR_PTR(-ENOENT) when this clock is not available. This simplifies
the clock management and avoid the need to test tx_clk value.
Signed-off-by: NCyrille Pitchen <cyrille.pitchen@atmel.com>
Acked-by: NBoris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: NAlexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 a8487489
...@@ -213,6 +213,9 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev) ...@@ -213,6 +213,9 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
{ {
long ferr, rate, rate_rounded; long ferr, rate, rate_rounded;
if (!clk)
return;
switch (speed) { switch (speed) {
case SPEED_10: case SPEED_10:
rate = 2500000; rate = 2500000;
...@@ -292,8 +295,7 @@ static void macb_handle_link_change(struct net_device *dev) ...@@ -292,8 +295,7 @@ static void macb_handle_link_change(struct net_device *dev)
spin_unlock_irqrestore(&bp->lock, flags); spin_unlock_irqrestore(&bp->lock, flags);
if (!IS_ERR(bp->tx_clk)) macb_set_tx_clk(bp->tx_clk, phydev->speed, dev);
macb_set_tx_clk(bp->tx_clk, phydev->speed, dev);
if (status_change) { if (status_change) {
if (phydev->link) { if (phydev->link) {
...@@ -2264,6 +2266,8 @@ static int macb_probe(struct platform_device *pdev) ...@@ -2264,6 +2266,8 @@ static int macb_probe(struct platform_device *pdev)
} }
tx_clk = devm_clk_get(&pdev->dev, "tx_clk"); tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
if (IS_ERR(tx_clk))
tx_clk = NULL;
err = clk_prepare_enable(pclk); err = clk_prepare_enable(pclk);
if (err) { if (err) {
...@@ -2277,13 +2281,10 @@ static int macb_probe(struct platform_device *pdev) ...@@ -2277,13 +2281,10 @@ static int macb_probe(struct platform_device *pdev)
goto err_out_disable_pclk; goto err_out_disable_pclk;
} }
if (!IS_ERR(tx_clk)) { err = clk_prepare_enable(tx_clk);
err = clk_prepare_enable(tx_clk); if (err) {
if (err) { dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err);
dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", goto err_out_disable_hclk;
err);
goto err_out_disable_hclk;
}
} }
err = -ENOMEM; err = -ENOMEM;
...@@ -2455,8 +2456,7 @@ static int macb_probe(struct platform_device *pdev) ...@@ -2455,8 +2456,7 @@ static int macb_probe(struct platform_device *pdev)
err_out_free_netdev: err_out_free_netdev:
free_netdev(dev); free_netdev(dev);
err_out_disable_clocks: err_out_disable_clocks:
if (!IS_ERR(tx_clk)) clk_disable_unprepare(tx_clk);
clk_disable_unprepare(tx_clk);
err_out_disable_hclk: err_out_disable_hclk:
clk_disable_unprepare(hclk); clk_disable_unprepare(hclk);
err_out_disable_pclk: err_out_disable_pclk:
...@@ -2480,8 +2480,7 @@ static int macb_remove(struct platform_device *pdev) ...@@ -2480,8 +2480,7 @@ static int macb_remove(struct platform_device *pdev)
kfree(bp->mii_bus->irq); kfree(bp->mii_bus->irq);
mdiobus_free(bp->mii_bus); mdiobus_free(bp->mii_bus);
unregister_netdev(dev); unregister_netdev(dev);
if (!IS_ERR(bp->tx_clk)) clk_disable_unprepare(bp->tx_clk);
clk_disable_unprepare(bp->tx_clk);
clk_disable_unprepare(bp->hclk); clk_disable_unprepare(bp->hclk);
clk_disable_unprepare(bp->pclk); clk_disable_unprepare(bp->pclk);
free_netdev(dev); free_netdev(dev);
...@@ -2499,8 +2498,7 @@ static int __maybe_unused macb_suspend(struct device *dev) ...@@ -2499,8 +2498,7 @@ static int __maybe_unused macb_suspend(struct device *dev)
netif_carrier_off(netdev); netif_carrier_off(netdev);
netif_device_detach(netdev); netif_device_detach(netdev);
if (!IS_ERR(bp->tx_clk)) clk_disable_unprepare(bp->tx_clk);
clk_disable_unprepare(bp->tx_clk);
clk_disable_unprepare(bp->hclk); clk_disable_unprepare(bp->hclk);
clk_disable_unprepare(bp->pclk); clk_disable_unprepare(bp->pclk);
...@@ -2515,8 +2513,7 @@ static int __maybe_unused macb_resume(struct device *dev) ...@@ -2515,8 +2513,7 @@ static int __maybe_unused macb_resume(struct device *dev)
clk_prepare_enable(bp->pclk); clk_prepare_enable(bp->pclk);
clk_prepare_enable(bp->hclk); clk_prepare_enable(bp->hclk);
if (!IS_ERR(bp->tx_clk)) clk_prepare_enable(bp->tx_clk);
clk_prepare_enable(bp->tx_clk);
netif_device_attach(netdev); netif_device_attach(netdev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册