Skip to content

Commit 31bc72d

Browse files
ffainellidavem330
authored andcommitted
net: systemport: fetch and use clock resources
We disable clocks shortly after probing the device to save as much power as possible in case the interface is never used. When bcm_sysport_open() is invoked, clocks are enabled, and disabled in bcm_sysport_stop(). A similar scheme is applied to the suspend/resume functions. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent af89606 commit 31bc72d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

drivers/net/ethernet/broadcom/bcmsysport.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/phy.h>
2121
#include <linux/phy_fixed.h>
2222
#include <net/dsa.h>
23+
#include <linux/clk.h>
2324
#include <net/ip.h>
2425
#include <net/ipv6.h>
2526

@@ -186,6 +187,11 @@ static int bcm_sysport_set_features(struct net_device *dev,
186187
netdev_features_t features)
187188
{
188189
struct bcm_sysport_priv *priv = netdev_priv(dev);
190+
int ret;
191+
192+
ret = clk_prepare_enable(priv->clk);
193+
if (ret)
194+
return ret;
189195

190196
/* Read CRC forward */
191197
if (!priv->is_lite)
@@ -197,6 +203,8 @@ static int bcm_sysport_set_features(struct net_device *dev,
197203
bcm_sysport_set_rx_csum(dev, features);
198204
bcm_sysport_set_tx_csum(dev, features);
199205

206+
clk_disable_unprepare(priv->clk);
207+
200208
return 0;
201209
}
202210

@@ -1940,6 +1948,8 @@ static int bcm_sysport_open(struct net_device *dev)
19401948
unsigned int i;
19411949
int ret;
19421950

1951+
clk_prepare_enable(priv->clk);
1952+
19431953
/* Reset UniMAC */
19441954
umac_reset(priv);
19451955

@@ -1970,7 +1980,8 @@ static int bcm_sysport_open(struct net_device *dev)
19701980
0, priv->phy_interface);
19711981
if (!phydev) {
19721982
netdev_err(dev, "could not attach to PHY\n");
1973-
return -ENODEV;
1983+
ret = -ENODEV;
1984+
goto out_clk_disable;
19741985
}
19751986

19761987
/* Reset house keeping link status */
@@ -2048,6 +2059,8 @@ static int bcm_sysport_open(struct net_device *dev)
20482059
free_irq(priv->irq0, dev);
20492060
out_phy_disconnect:
20502061
phy_disconnect(phydev);
2062+
out_clk_disable:
2063+
clk_disable_unprepare(priv->clk);
20512064
return ret;
20522065
}
20532066

@@ -2106,6 +2119,8 @@ static int bcm_sysport_stop(struct net_device *dev)
21062119
/* Disconnect from PHY */
21072120
phy_disconnect(dev->phydev);
21082121

2122+
clk_disable_unprepare(priv->clk);
2123+
21092124
return 0;
21102125
}
21112126

@@ -2487,6 +2502,10 @@ static int bcm_sysport_probe(struct platform_device *pdev)
24872502
/* Initialize private members */
24882503
priv = netdev_priv(dev);
24892504

2505+
priv->clk = devm_clk_get_optional(&pdev->dev, "sw_sysport");
2506+
if (IS_ERR(priv->clk))
2507+
return PTR_ERR(priv->clk);
2508+
24902509
/* Allocate number of TX rings */
24912510
priv->tx_rings = devm_kcalloc(&pdev->dev, txq,
24922511
sizeof(struct bcm_sysport_tx_ring),
@@ -2588,6 +2607,8 @@ static int bcm_sysport_probe(struct platform_device *pdev)
25882607
goto err_deregister_notifier;
25892608
}
25902609

2610+
clk_prepare_enable(priv->clk);
2611+
25912612
priv->rev = topctrl_readl(priv, REV_CNTL) & REV_MASK;
25922613
dev_info(&pdev->dev,
25932614
"Broadcom SYSTEMPORT%s " REV_FMT
@@ -2596,6 +2617,8 @@ static int bcm_sysport_probe(struct platform_device *pdev)
25962617
(priv->rev >> 8) & 0xff, priv->rev & 0xff,
25972618
priv->irq0, priv->irq1, txq, rxq);
25982619

2620+
clk_disable_unprepare(priv->clk);
2621+
25992622
return 0;
26002623

26012624
err_deregister_notifier:
@@ -2752,6 +2775,8 @@ static int __maybe_unused bcm_sysport_suspend(struct device *d)
27522775
if (device_may_wakeup(d) && priv->wolopts)
27532776
ret = bcm_sysport_suspend_to_wol(priv);
27542777

2778+
clk_disable_unprepare(priv->clk);
2779+
27552780
return ret;
27562781
}
27572782

@@ -2765,6 +2790,8 @@ static int __maybe_unused bcm_sysport_resume(struct device *d)
27652790
if (!netif_running(dev))
27662791
return 0;
27672792

2793+
clk_prepare_enable(priv->clk);
2794+
27682795
umac_reset(priv);
27692796

27702797
/* Disable the UniMAC RX/TX */
@@ -2844,6 +2871,7 @@ static int __maybe_unused bcm_sysport_resume(struct device *d)
28442871
out_free_tx_rings:
28452872
for (i = 0; i < dev->num_tx_queues; i++)
28462873
bcm_sysport_fini_tx_ring(priv, i);
2874+
clk_disable_unprepare(priv->clk);
28472875
return ret;
28482876
}
28492877

drivers/net/ethernet/broadcom/bcmsysport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ struct bcm_sysport_priv {
770770
u32 wolopts;
771771
u8 sopass[SOPASS_MAX];
772772
unsigned int wol_irq_disabled:1;
773+
struct clk *clk;
773774

774775
/* MIB related fields */
775776
struct bcm_sysport_mib mib;

0 commit comments

Comments
 (0)