Commit bb808945 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki Committed by Jesse Barnes

PCI PM: Rearrange code in pci-driver.c

Rename two functions and rearrange code in drivers/pci/pci-driver.c
so that it's easier to follow.  In particular, separate invocations
of the legacy callbacks from the rest of the new callbacks' code.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 73410429
...@@ -318,7 +318,7 @@ static void pci_device_shutdown(struct device *dev) ...@@ -318,7 +318,7 @@ static void pci_device_shutdown(struct device *dev)
* Default "suspend" method for devices that have no driver provided suspend, * Default "suspend" method for devices that have no driver provided suspend,
* or not even a driver at all (second part). * or not even a driver at all (second part).
*/ */
static void pci_default_pm_suspend_late(struct pci_dev *pci_dev) static void pci_pm_set_unknown_state(struct pci_dev *pci_dev)
{ {
/* /*
* mark its power state as "unknown", since we don't know if * mark its power state as "unknown", since we don't know if
...@@ -332,7 +332,7 @@ static void pci_default_pm_suspend_late(struct pci_dev *pci_dev) ...@@ -332,7 +332,7 @@ static void pci_default_pm_suspend_late(struct pci_dev *pci_dev)
* Default "resume" method for devices that have no driver provided resume, * Default "resume" method for devices that have no driver provided resume,
* or not even a driver at all (second part). * or not even a driver at all (second part).
*/ */
static int pci_default_pm_resume_late(struct pci_dev *pci_dev) static int pci_pm_reenable_device(struct pci_dev *pci_dev)
{ {
int retval; int retval;
...@@ -363,7 +363,7 @@ static int pci_legacy_suspend(struct device *dev, pm_message_t state) ...@@ -363,7 +363,7 @@ static int pci_legacy_suspend(struct device *dev, pm_message_t state)
* This is for compatibility with existing code with legacy PM * This is for compatibility with existing code with legacy PM
* support. * support.
*/ */
pci_default_pm_suspend_late(pci_dev); pci_pm_set_unknown_state(pci_dev);
} }
return i; return i;
} }
...@@ -392,7 +392,7 @@ static int pci_legacy_resume(struct device *dev) ...@@ -392,7 +392,7 @@ static int pci_legacy_resume(struct device *dev)
} else { } else {
/* restore the PCI config space */ /* restore the PCI config space */
pci_restore_state(pci_dev); pci_restore_state(pci_dev);
error = pci_default_pm_resume_late(pci_dev); error = pci_pm_reenable_device(pci_dev);
} }
return error; return error;
} }
...@@ -459,7 +459,7 @@ static int pci_pm_default_resume(struct pci_dev *pci_dev) ...@@ -459,7 +459,7 @@ static int pci_pm_default_resume(struct pci_dev *pci_dev)
if (!pci_is_bridge(pci_dev)) if (!pci_is_bridge(pci_dev))
pci_enable_wake(pci_dev, PCI_D0, false); pci_enable_wake(pci_dev, PCI_D0, false);
return pci_default_pm_resume_late(pci_dev); return pci_pm_reenable_device(pci_dev);
} }
static void pci_pm_default_suspend_generic(struct pci_dev *pci_dev) static void pci_pm_default_suspend_generic(struct pci_dev *pci_dev)
...@@ -484,9 +484,17 @@ static void pci_pm_default_suspend(struct pci_dev *pci_dev) ...@@ -484,9 +484,17 @@ static void pci_pm_default_suspend(struct pci_dev *pci_dev)
static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev) static bool pci_has_legacy_pm_support(struct pci_dev *pci_dev)
{ {
struct pci_driver *drv = pci_dev->driver; struct pci_driver *drv = pci_dev->driver;
bool ret = drv && (drv->suspend || drv->suspend_late || drv->resume
return drv && (drv->suspend || drv->suspend_late || drv->resume
|| drv->resume_early); || drv->resume_early);
/*
* Legacy PM support is used by default, so warn if the new framework is
* supported as well. Drivers are supposed to support either the
* former, or the latter, but not both at the same time.
*/
WARN_ON(ret && drv->driver.pm);
return ret;
} }
/* New power management framework */ /* New power management framework */
...@@ -518,17 +526,21 @@ static int pci_pm_suspend(struct device *dev) ...@@ -518,17 +526,21 @@ static int pci_pm_suspend(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_SUSPEND);
goto Exit;
}
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->suspend) { if (drv->pm->suspend) {
error = drv->pm->suspend(dev); error = drv->pm->suspend(dev);
suspend_report_result(drv->pm->suspend, error); suspend_report_result(drv->pm->suspend, error);
} }
} else if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_SUSPEND);
} else { } else {
pci_pm_default_suspend(pci_dev); pci_pm_default_suspend(pci_dev);
} }
Exit:
pci_fixup_device(pci_fixup_suspend, pci_dev); pci_fixup_device(pci_fixup_suspend, pci_dev);
return error; return error;
...@@ -540,15 +552,16 @@ static int pci_pm_suspend_noirq(struct device *dev) ...@@ -540,15 +552,16 @@ static int pci_pm_suspend_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_suspend_late(dev, PMSG_SUSPEND);
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->suspend_noirq) { if (drv->pm->suspend_noirq) {
error = drv->pm->suspend_noirq(dev); error = drv->pm->suspend_noirq(dev);
suspend_report_result(drv->pm->suspend_noirq, error); suspend_report_result(drv->pm->suspend_noirq, error);
} }
} else if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend_late(dev, PMSG_SUSPEND);
} else { } else {
pci_default_pm_suspend_late(pci_dev); pci_pm_set_unknown_state(pci_dev);
} }
return error; return error;
...@@ -560,14 +573,16 @@ static int pci_pm_resume(struct device *dev) ...@@ -560,14 +573,16 @@ static int pci_pm_resume(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
return pci_legacy_resume(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
pci_fixup_device(pci_fixup_resume, pci_dev); pci_fixup_device(pci_fixup_resume, pci_dev);
if (drv->pm->resume) if (drv->pm->resume)
error = drv->pm->resume(dev); error = drv->pm->resume(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
error = pci_legacy_resume(dev);
} else { } else {
error = pci_pm_default_resume(pci_dev); error = pci_pm_default_resume(pci_dev);
} }
...@@ -581,14 +596,16 @@ static int pci_pm_resume_noirq(struct device *dev) ...@@ -581,14 +596,16 @@ static int pci_pm_resume_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, pci_dev);
return pci_legacy_resume_early(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
pci_fixup_device(pci_fixup_resume_early, pci_dev); pci_fixup_device(pci_fixup_resume_early, pci_dev);
if (drv->pm->resume_noirq) if (drv->pm->resume_noirq)
error = drv->pm->resume_noirq(dev); error = drv->pm->resume_noirq(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, pci_dev);
error = pci_legacy_resume_early(dev);
} else { } else {
pci_pm_default_resume_noirq(pci_dev); pci_pm_default_resume_noirq(pci_dev);
} }
...@@ -613,14 +630,17 @@ static int pci_pm_freeze(struct device *dev) ...@@ -613,14 +630,17 @@ static int pci_pm_freeze(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_FREEZE);
pci_fixup_device(pci_fixup_suspend, pci_dev);
return error;
}
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->freeze) { if (drv->pm->freeze) {
error = drv->pm->freeze(dev); error = drv->pm->freeze(dev);
suspend_report_result(drv->pm->freeze, error); suspend_report_result(drv->pm->freeze, error);
} }
} else if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_FREEZE);
pci_fixup_device(pci_fixup_suspend, pci_dev);
} else { } else {
pci_pm_default_suspend_generic(pci_dev); pci_pm_default_suspend_generic(pci_dev);
} }
...@@ -634,15 +654,16 @@ static int pci_pm_freeze_noirq(struct device *dev) ...@@ -634,15 +654,16 @@ static int pci_pm_freeze_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev))
return pci_legacy_suspend_late(dev, PMSG_FREEZE);
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->freeze_noirq) { if (drv->pm->freeze_noirq) {
error = drv->pm->freeze_noirq(dev); error = drv->pm->freeze_noirq(dev);
suspend_report_result(drv->pm->freeze_noirq, error); suspend_report_result(drv->pm->freeze_noirq, error);
} }
} else if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend_late(dev, PMSG_FREEZE);
} else { } else {
pci_default_pm_suspend_late(pci_dev); pci_pm_set_unknown_state(pci_dev);
} }
return error; return error;
...@@ -654,14 +675,16 @@ static int pci_pm_thaw(struct device *dev) ...@@ -654,14 +675,16 @@ static int pci_pm_thaw(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
return pci_legacy_resume(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->thaw) if (drv->pm->thaw)
error = drv->pm->thaw(dev); error = drv->pm->thaw(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
error = pci_legacy_resume(dev);
} else { } else {
pci_default_pm_resume_late(pci_dev); pci_pm_reenable_device(pci_dev);
} }
return error; return error;
...@@ -673,12 +696,14 @@ static int pci_pm_thaw_noirq(struct device *dev) ...@@ -673,12 +696,14 @@ static int pci_pm_thaw_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev));
return pci_legacy_resume_early(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->thaw_noirq) if (drv->pm->thaw_noirq)
error = drv->pm->thaw_noirq(dev); error = drv->pm->thaw_noirq(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, to_pci_dev(dev));
error = pci_legacy_resume_early(dev);
} else { } else {
pci_update_current_state(pci_dev, PCI_D0); pci_update_current_state(pci_dev, PCI_D0);
} }
...@@ -692,17 +717,21 @@ static int pci_pm_poweroff(struct device *dev) ...@@ -692,17 +717,21 @@ static int pci_pm_poweroff(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
goto Exit;
}
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->poweroff) { if (drv->pm->poweroff) {
error = drv->pm->poweroff(dev); error = drv->pm->poweroff(dev);
suspend_report_result(drv->pm->poweroff, error); suspend_report_result(drv->pm->poweroff, error);
} }
} else if (pci_has_legacy_pm_support(pci_dev)) {
error = pci_legacy_suspend(dev, PMSG_HIBERNATE);
} else { } else {
pci_pm_default_suspend(pci_dev); pci_pm_default_suspend(pci_dev);
} }
Exit:
pci_fixup_device(pci_fixup_suspend, pci_dev); pci_fixup_device(pci_fixup_suspend, pci_dev);
return error; return error;
...@@ -713,13 +742,14 @@ static int pci_pm_poweroff_noirq(struct device *dev) ...@@ -713,13 +742,14 @@ static int pci_pm_poweroff_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(to_pci_dev(dev)))
return pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
if (drv && drv->pm) { if (drv && drv->pm) {
if (drv->pm->poweroff_noirq) { if (drv->pm->poweroff_noirq) {
error = drv->pm->poweroff_noirq(dev); error = drv->pm->poweroff_noirq(dev);
suspend_report_result(drv->pm->poweroff_noirq, error); suspend_report_result(drv->pm->poweroff_noirq, error);
} }
} else if (pci_has_legacy_pm_support(to_pci_dev(dev))) {
error = pci_legacy_suspend_late(dev, PMSG_HIBERNATE);
} }
return error; return error;
...@@ -731,14 +761,16 @@ static int pci_pm_restore(struct device *dev) ...@@ -731,14 +761,16 @@ static int pci_pm_restore(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
return pci_legacy_resume(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
pci_fixup_device(pci_fixup_resume, pci_dev); pci_fixup_device(pci_fixup_resume, pci_dev);
if (drv->pm->restore) if (drv->pm->restore)
error = drv->pm->restore(dev); error = drv->pm->restore(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume, pci_dev);
error = pci_legacy_resume(dev);
} else { } else {
error = pci_pm_default_resume(pci_dev); error = pci_pm_default_resume(pci_dev);
} }
...@@ -752,14 +784,16 @@ static int pci_pm_restore_noirq(struct device *dev) ...@@ -752,14 +784,16 @@ static int pci_pm_restore_noirq(struct device *dev)
struct device_driver *drv = dev->driver; struct device_driver *drv = dev->driver;
int error = 0; int error = 0;
if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, pci_dev);
return pci_legacy_resume_early(dev);
}
if (drv && drv->pm) { if (drv && drv->pm) {
pci_fixup_device(pci_fixup_resume_early, pci_dev); pci_fixup_device(pci_fixup_resume_early, pci_dev);
if (drv->pm->restore_noirq) if (drv->pm->restore_noirq)
error = drv->pm->restore_noirq(dev); error = drv->pm->restore_noirq(dev);
} else if (pci_has_legacy_pm_support(pci_dev)) {
pci_fixup_device(pci_fixup_resume_early, pci_dev);
error = pci_legacy_resume_early(dev);
} else { } else {
pci_pm_default_resume_noirq(pci_dev); pci_pm_default_resume_noirq(pci_dev);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment