Commit 4a865905 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PCI PM: Make pci_set_power_state() handle devices with no PM support

There is a problem with PCI devices without any PM support (either
native or through the platform) that pci_set_power_state() always
returns error code for them, even if they are being put into D0.
However, such devices are always in D0, so pci_set_power_state()
should return success when attempting to put such a device into D0.
It also should update the current_state field for these devices as
appropriate.  This modification is necessary so that the standard
configuration registers of these devices are successfully restored by
pci_restore_standard_config() during the "early" phase of resume.

In addition, pci_set_power_state() should check the value of
current_state before calling the platform to change the power state
of the device to avoid doing that unnecessarily.
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Acked-by: default avatarIngo Molnar <mingo@elte.hu>
Acked-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 46939f8b
...@@ -439,6 +439,10 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) ...@@ -439,6 +439,10 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state)
u16 pmcsr; u16 pmcsr;
bool need_restore = false; bool need_restore = false;
/* Check if we're already there */
if (dev->current_state == state)
return 0;
if (!dev->pm_cap) if (!dev->pm_cap)
return -EIO; return -EIO;
...@@ -449,10 +453,7 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state) ...@@ -449,10 +453,7 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state)
* Can enter D0 from any state, but if we can only go deeper * Can enter D0 from any state, but if we can only go deeper
* to sleep if we're already in a low power state * to sleep if we're already in a low power state
*/ */
if (dev->current_state == state) { if (state != PCI_D0 && dev->current_state <= PCI_D3cold
/* we're already there */
return 0;
} else if (state != PCI_D0 && dev->current_state <= PCI_D3cold
&& dev->current_state > state) { && dev->current_state > state) {
dev_err(&dev->dev, "invalid power transition " dev_err(&dev->dev, "invalid power transition "
"(from state %d to %d)\n", dev->current_state, state); "(from state %d to %d)\n", dev->current_state, state);
...@@ -570,12 +571,17 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state) ...@@ -570,12 +571,17 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
*/ */
return 0; return 0;
if (state == PCI_D0 && platform_pci_power_manageable(dev)) { /* Check if we're already there */
if (dev->current_state == state)
return 0;
if (state == PCI_D0) {
/* /*
* Allow the platform to change the state, for example via ACPI * Allow the platform to change the state, for example via ACPI
* _PR0, _PS0 and some such, but do not trust it. * _PR0, _PS0 and some such, but do not trust it.
*/ */
int ret = platform_pci_set_power_state(dev, PCI_D0); int ret = platform_pci_power_manageable(dev) ?
platform_pci_set_power_state(dev, PCI_D0) : 0;
if (!ret) if (!ret)
pci_update_current_state(dev, PCI_D0); pci_update_current_state(dev, PCI_D0);
} }
......
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