Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rt2x00: pci: use generic power management

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

authored by

Vaibhav Gupta and committed by
Kalle Valo
560a218d c83e2a6e

+19 -46
+1 -2
drivers/net/wireless/ralink/rt2x00/rt2400pci.c
··· 1834 1834 .id_table = rt2400pci_device_table, 1835 1835 .probe = rt2400pci_probe, 1836 1836 .remove = rt2x00pci_remove, 1837 - .suspend = rt2x00pci_suspend, 1838 - .resume = rt2x00pci_resume, 1837 + .driver.pm = &rt2x00pci_pm_ops, 1839 1838 }; 1840 1839 1841 1840 module_pci_driver(rt2400pci_driver);
+1 -2
drivers/net/wireless/ralink/rt2x00/rt2500pci.c
··· 2132 2132 .id_table = rt2500pci_device_table, 2133 2133 .probe = rt2500pci_probe, 2134 2134 .remove = rt2x00pci_remove, 2135 - .suspend = rt2x00pci_suspend, 2136 - .resume = rt2x00pci_resume, 2135 + .driver.pm = &rt2x00pci_pm_ops, 2137 2136 }; 2138 2137 2139 2138 module_pci_driver(rt2500pci_driver);
+1 -2
drivers/net/wireless/ralink/rt2x00/rt2800pci.c
··· 455 455 .id_table = rt2800pci_device_table, 456 456 .probe = rt2800pci_probe, 457 457 .remove = rt2x00pci_remove, 458 - .suspend = rt2x00pci_suspend, 459 - .resume = rt2x00pci_resume, 458 + .driver.pm = &rt2x00pci_pm_ops, 460 459 }; 461 460 462 461 module_pci_driver(rt2800pci_driver);
+2 -3
drivers/net/wireless/ralink/rt2x00/rt2x00.h
··· 1487 1487 */ 1488 1488 int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev); 1489 1489 void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev); 1490 - #ifdef CONFIG_PM 1491 - int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state); 1490 + 1491 + int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev); 1492 1492 int rt2x00lib_resume(struct rt2x00_dev *rt2x00dev); 1493 - #endif /* CONFIG_PM */ 1494 1493 1495 1494 #endif /* RT2X00_H */
+1 -3
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c
··· 1556 1556 /* 1557 1557 * Device state handlers 1558 1558 */ 1559 - #ifdef CONFIG_PM 1560 - int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev, pm_message_t state) 1559 + int rt2x00lib_suspend(struct rt2x00_dev *rt2x00dev) 1561 1560 { 1562 1561 rt2x00_dbg(rt2x00dev, "Going to sleep\n"); 1563 1562 ··· 1613 1614 return 0; 1614 1615 } 1615 1616 EXPORT_SYMBOL_GPL(rt2x00lib_resume); 1616 - #endif /* CONFIG_PM */ 1617 1617 1618 1618 /* 1619 1619 * rt2x00lib module information.
+8 -23
drivers/net/wireless/ralink/rt2x00/rt2x00pci.c
··· 169 169 } 170 170 EXPORT_SYMBOL_GPL(rt2x00pci_remove); 171 171 172 - #ifdef CONFIG_PM 173 - int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state) 172 + static int __maybe_unused rt2x00pci_suspend(struct device *dev) 174 173 { 175 - struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); 174 + struct ieee80211_hw *hw = dev_get_drvdata(dev); 176 175 struct rt2x00_dev *rt2x00dev = hw->priv; 177 - int retval; 178 176 179 - retval = rt2x00lib_suspend(rt2x00dev, state); 180 - if (retval) 181 - return retval; 182 - 183 - pci_save_state(pci_dev); 184 - pci_disable_device(pci_dev); 185 - return pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)); 177 + return rt2x00lib_suspend(rt2x00dev); 186 178 } 187 - EXPORT_SYMBOL_GPL(rt2x00pci_suspend); 188 179 189 - int rt2x00pci_resume(struct pci_dev *pci_dev) 180 + static int __maybe_unused rt2x00pci_resume(struct device *dev) 190 181 { 191 - struct ieee80211_hw *hw = pci_get_drvdata(pci_dev); 182 + struct ieee80211_hw *hw = dev_get_drvdata(dev); 192 183 struct rt2x00_dev *rt2x00dev = hw->priv; 193 184 194 - if (pci_set_power_state(pci_dev, PCI_D0) || 195 - pci_enable_device(pci_dev)) { 196 - rt2x00_err(rt2x00dev, "Failed to resume device\n"); 197 - return -EIO; 198 - } 199 - 200 - pci_restore_state(pci_dev); 201 185 return rt2x00lib_resume(rt2x00dev); 202 186 } 203 - EXPORT_SYMBOL_GPL(rt2x00pci_resume); 204 - #endif /* CONFIG_PM */ 187 + 188 + SIMPLE_DEV_PM_OPS(rt2x00pci_pm_ops, rt2x00pci_suspend, rt2x00pci_resume); 189 + EXPORT_SYMBOL_GPL(rt2x00pci_pm_ops); 205 190 206 191 /* 207 192 * rt2x00pci module information.
+2 -7
drivers/net/wireless/ralink/rt2x00/rt2x00pci.h
··· 21 21 */ 22 22 int rt2x00pci_probe(struct pci_dev *pci_dev, const struct rt2x00_ops *ops); 23 23 void rt2x00pci_remove(struct pci_dev *pci_dev); 24 - #ifdef CONFIG_PM 25 - int rt2x00pci_suspend(struct pci_dev *pci_dev, pm_message_t state); 26 - int rt2x00pci_resume(struct pci_dev *pci_dev); 27 - #else 28 - #define rt2x00pci_suspend NULL 29 - #define rt2x00pci_resume NULL 30 - #endif /* CONFIG_PM */ 24 + 25 + extern const struct dev_pm_ops rt2x00pci_pm_ops; 31 26 32 27 #endif /* RT2X00PCI_H */
+1 -1
drivers/net/wireless/ralink/rt2x00/rt2x00soc.c
··· 130 130 struct ieee80211_hw *hw = platform_get_drvdata(pdev); 131 131 struct rt2x00_dev *rt2x00dev = hw->priv; 132 132 133 - return rt2x00lib_suspend(rt2x00dev, state); 133 + return rt2x00lib_suspend(rt2x00dev); 134 134 } 135 135 EXPORT_SYMBOL_GPL(rt2x00soc_suspend); 136 136
+1 -1
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c
··· 886 886 struct ieee80211_hw *hw = usb_get_intfdata(usb_intf); 887 887 struct rt2x00_dev *rt2x00dev = hw->priv; 888 888 889 - return rt2x00lib_suspend(rt2x00dev, state); 889 + return rt2x00lib_suspend(rt2x00dev); 890 890 } 891 891 EXPORT_SYMBOL_GPL(rt2x00usb_suspend); 892 892
+1 -2
drivers/net/wireless/ralink/rt2x00/rt61pci.c
··· 3009 3009 .id_table = rt61pci_device_table, 3010 3010 .probe = rt61pci_probe, 3011 3011 .remove = rt2x00pci_remove, 3012 - .suspend = rt2x00pci_suspend, 3013 - .resume = rt2x00pci_resume, 3012 + .driver.pm = &rt2x00pci_pm_ops, 3014 3013 }; 3015 3014 3016 3015 module_pci_driver(rt61pci_driver);