Skip to content

Commit 93b31f4

Browse files
Cyrille Pitchendavem330
authored andcommitted
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: Cyrille Pitchen <[email protected]> Acked-by: Boris Brezillon <[email protected]> Acked-by: Alexandre Belloni <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a848748 commit 93b31f4

File tree

1 file changed

+14
-17
lines changed
  • drivers/net/ethernet/cadence

1 file changed

+14
-17
lines changed

drivers/net/ethernet/cadence/macb.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
213213
{
214214
long ferr, rate, rate_rounded;
215215

216+
if (!clk)
217+
return;
218+
216219
switch (speed) {
217220
case SPEED_10:
218221
rate = 2500000;
@@ -292,8 +295,7 @@ static void macb_handle_link_change(struct net_device *dev)
292295

293296
spin_unlock_irqrestore(&bp->lock, flags);
294297

295-
if (!IS_ERR(bp->tx_clk))
296-
macb_set_tx_clk(bp->tx_clk, phydev->speed, dev);
298+
macb_set_tx_clk(bp->tx_clk, phydev->speed, dev);
297299

298300
if (status_change) {
299301
if (phydev->link) {
@@ -2264,6 +2266,8 @@ static int macb_probe(struct platform_device *pdev)
22642266
}
22652267

22662268
tx_clk = devm_clk_get(&pdev->dev, "tx_clk");
2269+
if (IS_ERR(tx_clk))
2270+
tx_clk = NULL;
22672271

22682272
err = clk_prepare_enable(pclk);
22692273
if (err) {
@@ -2277,13 +2281,10 @@ static int macb_probe(struct platform_device *pdev)
22772281
goto err_out_disable_pclk;
22782282
}
22792283

2280-
if (!IS_ERR(tx_clk)) {
2281-
err = clk_prepare_enable(tx_clk);
2282-
if (err) {
2283-
dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n",
2284-
err);
2285-
goto err_out_disable_hclk;
2286-
}
2284+
err = clk_prepare_enable(tx_clk);
2285+
if (err) {
2286+
dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err);
2287+
goto err_out_disable_hclk;
22872288
}
22882289

22892290
err = -ENOMEM;
@@ -2455,8 +2456,7 @@ static int macb_probe(struct platform_device *pdev)
24552456
err_out_free_netdev:
24562457
free_netdev(dev);
24572458
err_out_disable_clocks:
2458-
if (!IS_ERR(tx_clk))
2459-
clk_disable_unprepare(tx_clk);
2459+
clk_disable_unprepare(tx_clk);
24602460
err_out_disable_hclk:
24612461
clk_disable_unprepare(hclk);
24622462
err_out_disable_pclk:
@@ -2480,8 +2480,7 @@ static int macb_remove(struct platform_device *pdev)
24802480
kfree(bp->mii_bus->irq);
24812481
mdiobus_free(bp->mii_bus);
24822482
unregister_netdev(dev);
2483-
if (!IS_ERR(bp->tx_clk))
2484-
clk_disable_unprepare(bp->tx_clk);
2483+
clk_disable_unprepare(bp->tx_clk);
24852484
clk_disable_unprepare(bp->hclk);
24862485
clk_disable_unprepare(bp->pclk);
24872486
free_netdev(dev);
@@ -2499,8 +2498,7 @@ static int __maybe_unused macb_suspend(struct device *dev)
24992498
netif_carrier_off(netdev);
25002499
netif_device_detach(netdev);
25012500

2502-
if (!IS_ERR(bp->tx_clk))
2503-
clk_disable_unprepare(bp->tx_clk);
2501+
clk_disable_unprepare(bp->tx_clk);
25042502
clk_disable_unprepare(bp->hclk);
25052503
clk_disable_unprepare(bp->pclk);
25062504

@@ -2515,8 +2513,7 @@ static int __maybe_unused macb_resume(struct device *dev)
25152513

25162514
clk_prepare_enable(bp->pclk);
25172515
clk_prepare_enable(bp->hclk);
2518-
if (!IS_ERR(bp->tx_clk))
2519-
clk_prepare_enable(bp->tx_clk);
2516+
clk_prepare_enable(bp->tx_clk);
25202517

25212518
netif_device_attach(netdev);
25222519

0 commit comments

Comments
 (0)