rt2x00: pci: use generic power management
authorVaibhav Gupta <vaibhavgupta40@gmail.com>
Fri, 17 Jul 2020 11:09:29 +0000 (16:39 +0530)
committerKalle Valo <kvalo@codeaurora.org>
Sun, 2 Aug 2020 15:13:45 +0000 (18:13 +0300)
Drivers using legacy PM have to manage PCI states and device's PM states
themselves. They also need to take care of configuration registers.

With improved and powerful support of generic PM, PCI Core takes care of
above mentioned, device-independent, jobs.

The callbacks make use of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device() and
pci_set_power_state() to do required operations. In generic mode, they are
no longer needed.

Change function parameter in both .suspend() and .resume() to
"struct device*" type. Use dev_get_drvdata() to get drv data.

The .suspend() callback is invoking rt2x00lib_suspend() which needs to be
modified as generic rt2x00pci_suspend() has no pm_message_t type argument,
passed to it, which is required by it according to its declaration.
Although this variable remained unused in the function body. Hence, remove
it from the function definition & declaration.

rt2x00lib_suspend() is also invoked by rt2x00usb_suspend() and
rt2x00soc_suspend(). Thus, modify the functional call accordingly in their
function body.

Earlier, .suspend() & .resume() were exported and were used by the
following drivers:
    - drivers/net/wireless/ralink/rt2x00/rt2400pci.c
    - drivers/net/wireless/ralink/rt2x00/rt2500pci.c
    - drivers/net/wireless/ralink/rt2x00/rt2800pci.c
    - drivers/net/wireless/ralink/rt2x00/rt61pci.c

Now, we only need to bind "struct dev_pm_ops" variable to
"struct pci_driver". Thus, make the callbacks static. Declare an
"extern const struct dev_pm_ops" variable and bind PM callbacks to it. Now,
export the variable instead and use it in respective drivers.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20200717110928.454867-1-vaibhavgupta40@gmail.com
drivers/net/wireless/ralink/rt2x00/rt2400pci.c
drivers/net/wireless/ralink/rt2x00/rt2500pci.c
drivers/net/wireless/ralink/rt2x00/rt2800pci.c
drivers/net/wireless/ralink/rt2x00/rt2x00.h
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
drivers/net/wireless/ralink/rt2x00/rt2x00pci.c
drivers/net/wireless/ralink/rt2x00/rt2x00pci.h
drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
drivers/net/wireless/ralink/rt2x00/rt61pci.c

index 4d44509e2ce377003aac4f04705c740347f5ffbe..c1ac933349d13a19c6f0aca6595c2c519846bcfe 100644 (file)
@@ -1834,8 +1834,7 @@ static struct pci_driver rt2400pci_driver = {
        .id_table       = rt2400pci_device_table,
        .probe          = rt2400pci_probe,
        .remove         = rt2x00pci_remove,
-       .suspend        = rt2x00pci_suspend,
-       .resume         = rt2x00pci_resume,
+       .driver.pm      = &rt2x00pci_pm_ops,
 };
 
 module_pci_driver(rt2400pci_driver);
index 4620990a94cf22ff713ac5cfef3f6bb00704b721..0859adebd86080809ae1bd0b93565c1bad784e4d 100644 (file)
@@ -2132,8 +2132,7 @@ static struct pci_driver rt2500pci_driver = {
        .id_table       = rt2500pci_device_table,
        .probe          = rt2500pci_probe,
        .remove         = rt2x00pci_remove,
-       .suspend        = rt2x00pci_suspend,
-       .resume         = rt2x00pci_resume,
+       .driver.pm      = &rt2x00pci_pm_ops,
 };
 
 module_pci_driver(rt2500pci_driver);
index 3868c07672bdfdcd57215917c39a720c6a815343..9a33baaa61843927972f2a65874264583f74a470 100644 (file)
@@ -455,8 +455,7 @@ static struct pci_driver rt2800pci_driver = {
        .id_table       = rt2800pci_device_table,
        .probe          = rt2800pci_probe,
        .remove         = rt2x00pci_remove,
-       .suspend        = rt2x00pci_suspend,
-       .resume         = rt2x00pci_resume,
+       .driver.pm      = &rt2x00pci_pm_ops,
 };
 
 module_pci_driver(rt2800pci_driver);
index ea8a34ecae14f25f1f667a84df5ff82fc057d98b..ecc60d8cbb012a03e0be5fd57d4ea3eed71a4add 100644 (file)
@@ -1487,9 +1487,8 @@ bool rt2x00mac_tx_frames_pending(struct ieee80211_hw *hw);
  */
 int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev);
 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev);
-#ifdef CONFIG_PM
-int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state);
+
+int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev);
 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev);
-#endif /* CONFIG_PM */
 
 #endif /* RT2X00_H */
index 7f9e43a4f805c164e0349bedff64e3980730d59c..8c6d3099b19d404d6d8407e8ee3f6de38b921b19 100644 (file)
@@ -1556,8 +1556,7 @@ EXPORT_SYMBOL_GPL(rt2x00lib_remove_dev);
 /*
  * Device state handlers
  */
-#ifdef CONFIG_PM
-int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state)
+int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev)
 {
        rt2x00_dbg(rt2x00dev, "Going to sleep\n");
 
@@ -1614,7 +1613,6 @@ int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev)
        return 0;
 }
 EXPORT_SYMBOL_GPL(rt2x00lib_resume);
-#endif /* CONFIG_PM */
 
 /*
  * rt2x00lib module information.
index 7f9baa94c7c8fcb793771af0d1d8d7c4fe4335de..cabeef0dde45d5a46f4f519976ac08d46fdd6105 100644 (file)
@@ -169,39 +169,24 @@ void rt2x00pci_remove(struct pci_dev *pci_dev)
 }
 EXPORT_SYMBOL_GPL(rt2x00pci_remove);
 
-#ifdef CONFIG_PM
-int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state)
+static int __maybe_unused rt2x00pci_suspend(struct device *dev)
 {
-       struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
+       struct ieee80211_hw *hw = dev_get_drvdata(dev);
        struct rt2x00_dev *rt2x00dev = hw->priv;
-       int retval;
-
-       retval = rt2x00lib_suspend(rt2x00dev, state);
-       if (retval)
-               return retval;
 
-       pci_save_state(pci_dev);
-       pci_disable_device(pci_dev);
-       return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
+       return rt2x00lib_suspend(rt2x00dev);
 }
-EXPORT_SYMBOL_GPL(rt2x00pci_suspend);
 
-int rt2x00pci_resume(struct pci_dev *pci_dev)
+static int __maybe_unused rt2x00pci_resume(struct device *dev)
 {
-       struct ieee80211_hw *hw = pci_get_drvdata(pci_dev);
+       struct ieee80211_hw *hw = dev_get_drvdata(dev);
        struct rt2x00_dev *rt2x00dev = hw->priv;
 
-       if (pci_set_power_state(pci_dev, PCI_D0) ||
-           pci_enable_device(pci_dev)) {
-               rt2x00_err(rt2x00dev, "Failed to resume device\n");
-               return -EIO;
-       }
-
-       pci_restore_state(pci_dev);
        return rt2x00lib_resume(rt2x00dev);
 }
-EXPORT_SYMBOL_GPL(rt2x00pci_resume);
-#endif /* CONFIG_PM */
+
+SIMPLE_DEV_PM_OPS(rt2x00pci_pm_ops, rt2x00pci_suspend, rt2x00pci_resume);
+EXPORT_SYMBOL_GPL(rt2x00pci_pm_ops);
 
 /*
  * rt2x00pci module information.
index fd955ccaa1e6c254fd86508ee5b220ff1ea99629..27f7b2bd26ea7e89d8074e397f356de1699d5bda 100644 (file)
  */
 int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops);
 void rt2x00pci_remove(struct pci_dev *pci_dev);
-#ifdef CONFIG_PM
-int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state);
-int rt2x00pci_resume(struct pci_dev *pci_dev);
-#else
-#define rt2x00pci_suspend      NULL
-#define rt2x00pci_resume       NULL
-#endif /* CONFIG_PM */
+
+extern const struct dev_pm_ops rt2x00pci_pm_ops;
 
 #endif /* RT2X00PCI_H */
index 596b8a4329462db1c33d0ce0cb5e1ddd455547fb..eface610178d2e6621fa5efd2162538221559840 100644 (file)
@@ -130,7 +130,7 @@ int rt2x00soc_suspend(struct platform_device *pdev, pm_message_t state)
        struct ieee80211_hw *hw = platform_get_drvdata(pdev);
        struct rt2x00_dev *rt2x00dev = hw->priv;
 
-       return rt2x00lib_suspend(rt2x00dev, state);
+       return rt2x00lib_suspend(rt2x00dev);
 }
 EXPORT_SYMBOL_GPL(rt2x00soc_suspend);
 
index 92e9e023c3499c8adaf7b7bf7223316896c3f9dc..e4473a5512415241d012f973862e12d122b3845e 100644 (file)
@@ -886,7 +886,7 @@ int rt2x00usb_suspend(struct usb_interface *usb_intf, pm_message_t state)
        struct ieee80211_hw *hw = usb_get_intfdata(usb_intf);
        struct rt2x00_dev *rt2x00dev = hw->priv;
 
-       return rt2x00lib_suspend(rt2x00dev, state);
+       return rt2x00lib_suspend(rt2x00dev);
 }
 EXPORT_SYMBOL_GPL(rt2x00usb_suspend);
 
index d83288bef2fc4fa3b69f075d0b4d438f157ec37b..eefce76fc99b3cfebf1fa2a92cd5ff007bc5d3cc 100644 (file)
@@ -3009,8 +3009,7 @@ static struct pci_driver rt61pci_driver = {
        .id_table       = rt61pci_device_table,
        .probe          = rt61pci_probe,
        .remove         = rt2x00pci_remove,
-       .suspend        = rt2x00pci_suspend,
-       .resume         = rt2x00pci_resume,
+       .driver.pm      = &rt2x00pci_pm_ops,
 };
 
 module_pci_driver(rt61pci_driver);