Skip to content

Commit c4e5e22

Browse files
VARoDeKstorulf
authored andcommitted
memstick: jmb38x_ms: 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. This driver makes use of PCI helper functions like pci_save/restore_state(), pci_enable/disable_device(), pci_set_power_state() and pci_set_master() 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 to_pci_dev() and dev_get_drvdata() to get "struct pci_dev*" variable and drv data. Compile-tested only. Signed-off-by: Vaibhav Gupta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent adc40a5 commit c4e5e22

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

drivers/memstick/host/jmb38x_ms.c

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -793,11 +793,10 @@ static int jmb38x_ms_pmos(struct pci_dev *pdev, int flag)
793793
return 0;
794794
}
795795

796-
#ifdef CONFIG_PM
797-
798-
static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
796+
static int __maybe_unused jmb38x_ms_suspend(struct device *dev)
799797
{
800-
struct jmb38x_ms *jm = pci_get_drvdata(dev);
798+
struct jmb38x_ms *jm = dev_get_drvdata(dev);
799+
801800
int cnt;
802801

803802
for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
@@ -806,26 +805,17 @@ static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
806805
memstick_suspend_host(jm->hosts[cnt]);
807806
}
808807

809-
pci_save_state(dev);
810-
pci_enable_wake(dev, pci_choose_state(dev, state), 0);
811-
pci_disable_device(dev);
812-
pci_set_power_state(dev, pci_choose_state(dev, state));
808+
device_wakeup_disable(dev);
809+
813810
return 0;
814811
}
815812

816-
static int jmb38x_ms_resume(struct pci_dev *dev)
813+
static int __maybe_unused jmb38x_ms_resume(struct device *dev)
817814
{
818-
struct jmb38x_ms *jm = pci_get_drvdata(dev);
815+
struct jmb38x_ms *jm = dev_get_drvdata(dev);
819816
int rc;
820817

821-
pci_set_power_state(dev, PCI_D0);
822-
pci_restore_state(dev);
823-
rc = pci_enable_device(dev);
824-
if (rc)
825-
return rc;
826-
pci_set_master(dev);
827-
828-
jmb38x_ms_pmos(dev, 1);
818+
jmb38x_ms_pmos(to_pci_dev(dev), 1);
829819

830820
for (rc = 0; rc < jm->host_cnt; ++rc) {
831821
if (!jm->hosts[rc])
@@ -837,13 +827,6 @@ static int jmb38x_ms_resume(struct pci_dev *dev)
837827
return 0;
838828
}
839829

840-
#else
841-
842-
#define jmb38x_ms_suspend NULL
843-
#define jmb38x_ms_resume NULL
844-
845-
#endif /* CONFIG_PM */
846-
847830
static int jmb38x_ms_count_slots(struct pci_dev *pdev)
848831
{
849832
int cnt, rc = 0;
@@ -1030,13 +1013,14 @@ static struct pci_device_id jmb38x_ms_id_tbl [] = {
10301013
{ }
10311014
};
10321015

1016+
static SIMPLE_DEV_PM_OPS(jmb38x_ms_pm_ops, jmb38x_ms_suspend, jmb38x_ms_resume);
1017+
10331018
static struct pci_driver jmb38x_ms_driver = {
10341019
.name = DRIVER_NAME,
10351020
.id_table = jmb38x_ms_id_tbl,
10361021
.probe = jmb38x_ms_probe,
10371022
.remove = jmb38x_ms_remove,
1038-
.suspend = jmb38x_ms_suspend,
1039-
.resume = jmb38x_ms_resume
1023+
.driver.pm = &jmb38x_ms_pm_ops,
10401024
};
10411025

10421026
module_pci_driver(jmb38x_ms_driver);

0 commit comments

Comments
 (0)