Skip to content

Commit

Permalink
sc92031: use generic power management
Browse files Browse the repository at this point in the history
Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vaibhav Gupta authored and David S. Miller committed Jul 31, 2020
1 parent bbf1b94 commit bfc6c18
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions drivers/net/ethernet/silan/sc92031.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,15 +1499,13 @@ static void sc92031_remove(struct pci_dev *pdev)
pci_disable_device(pdev);
}

static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused sc92031_suspend(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct net_device *dev = dev_get_drvdata(dev_d);
struct sc92031_priv *priv = netdev_priv(dev);

pci_save_state(pdev);

if (!netif_running(dev))
goto out;
return 0;

netif_device_detach(dev);

Expand All @@ -1521,22 +1519,16 @@ static int sc92031_suspend(struct pci_dev *pdev, pm_message_t state)

spin_unlock_bh(&priv->lock);

out:
pci_set_power_state(pdev, pci_choose_state(pdev, state));

return 0;
}

static int sc92031_resume(struct pci_dev *pdev)
static int __maybe_unused sc92031_resume(struct device *dev_d)
{
struct net_device *dev = pci_get_drvdata(pdev);
struct net_device *dev = dev_get_drvdata(dev_d);
struct sc92031_priv *priv = netdev_priv(dev);

pci_restore_state(pdev);
pci_set_power_state(pdev, PCI_D0);

if (!netif_running(dev))
goto out;
return 0;

/* Interrupts already disabled by sc92031_suspend */
spin_lock_bh(&priv->lock);
Expand All @@ -1553,7 +1545,6 @@ static int sc92031_resume(struct pci_dev *pdev)
else
netif_tx_disable(dev);

out:
return 0;
}

Expand All @@ -1565,13 +1556,14 @@ static const struct pci_device_id sc92031_pci_device_id_table[] = {
};
MODULE_DEVICE_TABLE(pci, sc92031_pci_device_id_table);

static SIMPLE_DEV_PM_OPS(sc92031_pm_ops, sc92031_suspend, sc92031_resume);

static struct pci_driver sc92031_pci_driver = {
.name = SC92031_NAME,
.id_table = sc92031_pci_device_id_table,
.probe = sc92031_probe,
.remove = sc92031_remove,
.suspend = sc92031_suspend,
.resume = sc92031_resume,
.driver.pm = &sc92031_pm_ops,
};

module_pci_driver(sc92031_pci_driver);
Expand Down

0 comments on commit bfc6c18

Please sign in to comment.