diff options
| author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-09-01 07:49:16 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2014-09-01 07:49:16 -0400 |
| commit | 76cde7e495904064d612cf3eb4bf6d9e76ff8191 (patch) | |
| tree | b244a8a7555e551474623ccc8b80132a1bcf1588 | |
| parent | 5613570b133a294355d35fa66162afe7607a8abb (diff) | |
PCI / PM: Make PCIe PME interrupts wake up from suspend-to-idle
To make PCIe PME interrupts wake up the system from suspend to idle,
make the PME driver use enable_irq_wake() on the IRQ during system
suspend (if there are any wakeup devices below the given PCIe port)
without disabling PME interrupts. This way, an interrupt will still
trigger if a wakeup event happens and the system will be woken up (or
system suspend in progress will be aborted) by means of the new
mechanics introduced previously.
This change allows Wake-on-LAN to be used for wakeup from
suspend-to-idle on my MSI Wind tesbed netbook.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
| -rw-r--r-- | drivers/pci/pcie/pme.c | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/drivers/pci/pcie/pme.c b/drivers/pci/pcie/pme.c index 82e06a86cd77..a9f9c46e5022 100644 --- a/drivers/pci/pcie/pme.c +++ b/drivers/pci/pcie/pme.c | |||
| @@ -41,11 +41,17 @@ static int __init pcie_pme_setup(char *str) | |||
| 41 | } | 41 | } |
| 42 | __setup("pcie_pme=", pcie_pme_setup); | 42 | __setup("pcie_pme=", pcie_pme_setup); |
| 43 | 43 | ||
| 44 | enum pme_suspend_level { | ||
| 45 | PME_SUSPEND_NONE = 0, | ||
| 46 | PME_SUSPEND_WAKEUP, | ||
| 47 | PME_SUSPEND_NOIRQ, | ||
| 48 | }; | ||
| 49 | |||
| 44 | struct pcie_pme_service_data { | 50 | struct pcie_pme_service_data { |
| 45 | spinlock_t lock; | 51 | spinlock_t lock; |
| 46 | struct pcie_device *srv; | 52 | struct pcie_device *srv; |
| 47 | struct work_struct work; | 53 | struct work_struct work; |
| 48 | bool noirq; /* Don't enable the PME interrupt used by this service. */ | 54 | enum pme_suspend_level suspend_level; |
| 49 | }; | 55 | }; |
| 50 | 56 | ||
| 51 | /** | 57 | /** |
| @@ -223,7 +229,7 @@ static void pcie_pme_work_fn(struct work_struct *work) | |||
| 223 | spin_lock_irq(&data->lock); | 229 | spin_lock_irq(&data->lock); |
| 224 | 230 | ||
| 225 | for (;;) { | 231 | for (;;) { |
| 226 | if (data->noirq) | 232 | if (data->suspend_level != PME_SUSPEND_NONE) |
| 227 | break; | 233 | break; |
| 228 | 234 | ||
| 229 | pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); | 235 | pcie_capability_read_dword(port, PCI_EXP_RTSTA, &rtsta); |
| @@ -250,7 +256,7 @@ static void pcie_pme_work_fn(struct work_struct *work) | |||
| 250 | spin_lock_irq(&data->lock); | 256 | spin_lock_irq(&data->lock); |
| 251 | } | 257 | } |
| 252 | 258 | ||
| 253 | if (!data->noirq) | 259 | if (data->suspend_level == PME_SUSPEND_NONE) |
| 254 | pcie_pme_interrupt_enable(port, true); | 260 | pcie_pme_interrupt_enable(port, true); |
| 255 | 261 | ||
| 256 | spin_unlock_irq(&data->lock); | 262 | spin_unlock_irq(&data->lock); |
| @@ -367,6 +373,21 @@ static int pcie_pme_probe(struct pcie_device *srv) | |||
| 367 | return ret; | 373 | return ret; |
| 368 | } | 374 | } |
| 369 | 375 | ||
| 376 | static bool pcie_pme_check_wakeup(struct pci_bus *bus) | ||
| 377 | { | ||
| 378 | struct pci_dev *dev; | ||
| 379 | |||
| 380 | if (!bus) | ||
| 381 | return false; | ||
| 382 | |||
| 383 | list_for_each_entry(dev, &bus->devices, bus_list) | ||
| 384 | if (device_may_wakeup(&dev->dev) | ||
| 385 | || pcie_pme_check_wakeup(dev->subordinate)) | ||
| 386 | return true; | ||
| 387 | |||
| 388 | return false; | ||
| 389 | } | ||
| 390 | |||
| 370 | /** | 391 | /** |
| 371 | * pcie_pme_suspend - Suspend PCIe PME service device. | 392 | * pcie_pme_suspend - Suspend PCIe PME service device. |
| 372 | * @srv: PCIe service device to suspend. | 393 | * @srv: PCIe service device to suspend. |
| @@ -375,11 +396,26 @@ static int pcie_pme_suspend(struct pcie_device *srv) | |||
| 375 | { | 396 | { |
| 376 | struct pcie_pme_service_data *data = get_service_data(srv); | 397 | struct pcie_pme_service_data *data = get_service_data(srv); |
| 377 | struct pci_dev *port = srv->port; | 398 | struct pci_dev *port = srv->port; |
| 399 | bool wakeup; | ||
| 378 | 400 | ||
| 401 | if (device_may_wakeup(&port->dev)) { | ||
| 402 | wakeup = true; | ||
| 403 | } else { | ||
| 404 | down_read(&pci_bus_sem); | ||
| 405 | wakeup = pcie_pme_check_wakeup(port->subordinate); | ||
| 406 | up_read(&pci_bus_sem); | ||
| 407 | } | ||
| 379 | spin_lock_irq(&data->lock); | 408 | spin_lock_irq(&data->lock); |
| 380 | pcie_pme_interrupt_enable(port, false); | 409 | if (wakeup) { |
| 381 | pcie_clear_root_pme_status(port); | 410 | enable_irq_wake(srv->irq); |
| 382 | data->noirq = true; | 411 | data->suspend_level = PME_SUSPEND_WAKEUP; |
| 412 | } else { | ||
| 413 | struct pci_dev *port = srv->port; | ||
| 414 | |||
| 415 | pcie_pme_interrupt_enable(port, false); | ||
| 416 | pcie_clear_root_pme_status(port); | ||
| 417 | data->suspend_level = PME_SUSPEND_NOIRQ; | ||
| 418 | } | ||
| 383 | spin_unlock_irq(&data->lock); | 419 | spin_unlock_irq(&data->lock); |
| 384 | 420 | ||
| 385 | synchronize_irq(srv->irq); | 421 | synchronize_irq(srv->irq); |
| @@ -394,12 +430,17 @@ static int pcie_pme_suspend(struct pcie_device *srv) | |||
| 394 | static int pcie_pme_resume(struct pcie_device *srv) | 430 | static int pcie_pme_resume(struct pcie_device *srv) |
| 395 | { | 431 | { |
| 396 | struct pcie_pme_service_data *data = get_service_data(srv); | 432 | struct pcie_pme_service_data *data = get_service_data(srv); |
| 397 | struct pci_dev *port = srv->port; | ||
| 398 | 433 | ||
| 399 | spin_lock_irq(&data->lock); | 434 | spin_lock_irq(&data->lock); |
| 400 | data->noirq = false; | 435 | if (data->suspend_level == PME_SUSPEND_NOIRQ) { |
| 401 | pcie_clear_root_pme_status(port); | 436 | struct pci_dev *port = srv->port; |
| 402 | pcie_pme_interrupt_enable(port, true); | 437 | |
| 438 | pcie_clear_root_pme_status(port); | ||
| 439 | pcie_pme_interrupt_enable(port, true); | ||
| 440 | } else { | ||
| 441 | disable_irq_wake(srv->irq); | ||
| 442 | } | ||
| 443 | data->suspend_level = PME_SUSPEND_NONE; | ||
| 403 | spin_unlock_irq(&data->lock); | 444 | spin_unlock_irq(&data->lock); |
| 404 | 445 | ||
| 405 | return 0; | 446 | return 0; |
