Skip to content

Commit c5eb119

Browse files
jhnikulabjorn-helgaas
authored andcommitted
PCI / PM: Allow runtime PM without callback functions
a9c8088 ("i2c: i801: Don't restore config registers on runtime PM") nullified the runtime PM suspend/resume callback pointers while keeping the runtime PM enabled. This caused the SMBus PCI device to stay in D0 with /sys/devices/.../power/runtime_status showing "error" when the runtime PM framework attempted to autosuspend the device. This is due to PCI bus runtime PM, which checks for driver runtime PM callbacks and returns -ENOSYS if they are not set. Since i2c-i801.c doesn't need to do anything device-specific for runtime PM, Jean Delvare proposed this be fixed in the PCI core rather than adding dummy runtime PM callback functions in the PCI drivers. Change pci_pm_runtime_suspend()/pci_pm_runtime_resume() so they allow changing the PCI device power state during runtime PM transitions even if the driver supplies no runtime PM callbacks. This fixes the runtime PM regression on i2c-i801.c. It is not obvious why the code previously required the runtime PM callbacks. The test has been there since the code was introduced by 6cbf821 ("PCI PM: Run-time callbacks for PCI bus type"). On the other hand, a similar change was done to generic runtime PM callbacks in 05aa55d ("PM / Runtime: Lenient generic runtime pm callbacks"). Fixes: a9c8088 ("i2c: i801: Don't restore config registers on runtime PM") Reported-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Reviewed-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Cc: stable@vger.kernel.org # v4.18+
1 parent 6510223 commit c5eb119

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

drivers/pci/pci-driver.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,30 +1251,29 @@ static int pci_pm_runtime_suspend(struct device *dev)
12511251
return 0;
12521252
}
12531253

1254-
if (!pm || !pm->runtime_suspend)
1255-
return -ENOSYS;
1256-
12571254
pci_dev->state_saved = false;
1258-
error = pm->runtime_suspend(dev);
1259-
if (error) {
1255+
if (pm && pm->runtime_suspend) {
1256+
error = pm->runtime_suspend(dev);
12601257
/*
12611258
* -EBUSY and -EAGAIN is used to request the runtime PM core
12621259
* to schedule a new suspend, so log the event only with debug
12631260
* log level.
12641261
*/
1265-
if (error == -EBUSY || error == -EAGAIN)
1262+
if (error == -EBUSY || error == -EAGAIN) {
12661263
dev_dbg(dev, "can't suspend now (%pf returned %d)\n",
12671264
pm->runtime_suspend, error);
1268-
else
1265+
return error;
1266+
} else if (error) {
12691267
dev_err(dev, "can't suspend (%pf returned %d)\n",
12701268
pm->runtime_suspend, error);
1271-
1272-
return error;
1269+
return error;
1270+
}
12731271
}
12741272

12751273
pci_fixup_device(pci_fixup_suspend, pci_dev);
12761274

1277-
if (!pci_dev->state_saved && pci_dev->current_state != PCI_D0
1275+
if (pm && pm->runtime_suspend
1276+
&& !pci_dev->state_saved && pci_dev->current_state != PCI_D0
12781277
&& pci_dev->current_state != PCI_UNKNOWN) {
12791278
WARN_ONCE(pci_dev->current_state != prev,
12801279
"PCI PM: State of device not saved by %pF\n",
@@ -1292,7 +1291,7 @@ static int pci_pm_runtime_suspend(struct device *dev)
12921291

12931292
static int pci_pm_runtime_resume(struct device *dev)
12941293
{
1295-
int rc;
1294+
int rc = 0;
12961295
struct pci_dev *pci_dev = to_pci_dev(dev);
12971296
const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
12981297

@@ -1306,14 +1305,12 @@ static int pci_pm_runtime_resume(struct device *dev)
13061305
if (!pci_dev->driver)
13071306
return 0;
13081307

1309-
if (!pm || !pm->runtime_resume)
1310-
return -ENOSYS;
1311-
13121308
pci_fixup_device(pci_fixup_resume_early, pci_dev);
13131309
pci_enable_wake(pci_dev, PCI_D0, false);
13141310
pci_fixup_device(pci_fixup_resume, pci_dev);
13151311

1316-
rc = pm->runtime_resume(dev);
1312+
if (pm && pm->runtime_resume)
1313+
rc = pm->runtime_resume(dev);
13171314

13181315
pci_dev->runtime_d3cold = false;
13191316

0 commit comments

Comments
 (0)