Commit 1e30b8d7 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Jakub Kicinski

net: smsc911x: Make Runtime PM handling more fine-grained

Currently the smsc911x driver has mininal power management: during
driver probe, the device is powered up, and during driver remove, it is
powered down.

Improve power management by making it more fine-grained:
  1. Power the device down when driver probe is finished,
  2. Power the device (down) when it is opened (closed),
  3. Make sure the device is powered during PHY access.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20210118150857.796943-1-geert+renesas@glider.beSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent eaaf6112
...@@ -557,6 +557,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx) ...@@ -557,6 +557,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
unsigned int addr; unsigned int addr;
int i, reg; int i, reg;
pm_runtime_get_sync(bus->parent);
spin_lock_irqsave(&pdata->mac_lock, flags); spin_lock_irqsave(&pdata->mac_lock, flags);
/* Confirm MII not busy */ /* Confirm MII not busy */
...@@ -582,6 +583,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx) ...@@ -582,6 +583,7 @@ static int smsc911x_mii_read(struct mii_bus *bus, int phyaddr, int regidx)
out: out:
spin_unlock_irqrestore(&pdata->mac_lock, flags); spin_unlock_irqrestore(&pdata->mac_lock, flags);
pm_runtime_put(bus->parent);
return reg; return reg;
} }
...@@ -594,6 +596,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx, ...@@ -594,6 +596,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
unsigned int addr; unsigned int addr;
int i, reg; int i, reg;
pm_runtime_get_sync(bus->parent);
spin_lock_irqsave(&pdata->mac_lock, flags); spin_lock_irqsave(&pdata->mac_lock, flags);
/* Confirm MII not busy */ /* Confirm MII not busy */
...@@ -623,6 +626,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx, ...@@ -623,6 +626,7 @@ static int smsc911x_mii_write(struct mii_bus *bus, int phyaddr, int regidx,
out: out:
spin_unlock_irqrestore(&pdata->mac_lock, flags); spin_unlock_irqrestore(&pdata->mac_lock, flags);
pm_runtime_put(bus->parent);
return reg; return reg;
} }
...@@ -1589,6 +1593,8 @@ static int smsc911x_open(struct net_device *dev) ...@@ -1589,6 +1593,8 @@ static int smsc911x_open(struct net_device *dev)
int retval; int retval;
int irq_flags; int irq_flags;
pm_runtime_get_sync(dev->dev.parent);
/* find and start the given phy */ /* find and start the given phy */
if (!dev->phydev) { if (!dev->phydev) {
retval = smsc911x_mii_probe(dev); retval = smsc911x_mii_probe(dev);
...@@ -1735,6 +1741,7 @@ static int smsc911x_open(struct net_device *dev) ...@@ -1735,6 +1741,7 @@ static int smsc911x_open(struct net_device *dev)
phy_disconnect(dev->phydev); phy_disconnect(dev->phydev);
dev->phydev = NULL; dev->phydev = NULL;
out: out:
pm_runtime_put(dev->dev.parent);
return retval; return retval;
} }
...@@ -1766,6 +1773,7 @@ static int smsc911x_stop(struct net_device *dev) ...@@ -1766,6 +1773,7 @@ static int smsc911x_stop(struct net_device *dev)
dev->phydev = NULL; dev->phydev = NULL;
} }
netif_carrier_off(dev); netif_carrier_off(dev);
pm_runtime_put(dev->dev.parent);
SMSC_TRACE(pdata, ifdown, "Interface stopped"); SMSC_TRACE(pdata, ifdown, "Interface stopped");
return 0; return 0;
...@@ -2334,7 +2342,6 @@ static int smsc911x_drv_remove(struct platform_device *pdev) ...@@ -2334,7 +2342,6 @@ static int smsc911x_drv_remove(struct platform_device *pdev)
free_netdev(dev); free_netdev(dev);
pm_runtime_put(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
return 0; return 0;
...@@ -2540,6 +2547,7 @@ static int smsc911x_drv_probe(struct platform_device *pdev) ...@@ -2540,6 +2547,7 @@ static int smsc911x_drv_probe(struct platform_device *pdev)
} }
spin_unlock_irq(&pdata->mac_lock); spin_unlock_irq(&pdata->mac_lock);
pm_runtime_put(&pdev->dev);
netdev_info(dev, "MAC Address: %pM\n", dev->dev_addr); netdev_info(dev, "MAC Address: %pM\n", dev->dev_addr);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment