sc92031: use generic power management

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>
This commit is contained in:
Vaibhav Gupta 2020-07-30 12:23:34 +05:30 committed by David S. Miller
parent bbf1b94a73
commit bfc6c183cb
1 changed files with 9 additions and 17 deletions

View File

@ -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);
@ -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);
@ -1553,7 +1545,6 @@ static int sc92031_resume(struct pci_dev *pdev)
else
netif_tx_disable(dev);
out:
return 0;
}
@ -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);