pm.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * linux/kernel/irq/pm.c
  3. *
  4. * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
  5. *
  6. * This file contains power management functions related to interrupts.
  7. */
  8. #include <linux/irq.h>
  9. #include <linux/module.h>
  10. #include <linux/interrupt.h>
  11. #include "internals.h"
  12. /**
  13. * suspend_device_irqs - disable all currently enabled interrupt lines
  14. *
  15. * During system-wide suspend or hibernation device drivers need to be prevented
  16. * from receiving interrupts and this function is provided for this purpose.
  17. * It marks all interrupt lines in use, except for the timer ones, as disabled
  18. * and sets the IRQS_SUSPENDED flag for each of them.
  19. */
  20. void suspend_device_irqs(void)
  21. {
  22. struct irq_desc *desc;
  23. int irq;
  24. for_each_irq_desc(irq, desc) {
  25. unsigned long flags;
  26. raw_spin_lock_irqsave(&desc->lock, flags);
  27. __disable_irq(desc, irq, true);
  28. raw_spin_unlock_irqrestore(&desc->lock, flags);
  29. }
  30. for_each_irq_desc(irq, desc)
  31. if (desc->istate & IRQS_SUSPENDED)
  32. synchronize_irq(irq);
  33. }
  34. EXPORT_SYMBOL_GPL(suspend_device_irqs);
  35. /**
  36. * resume_device_irqs - enable interrupt lines disabled by suspend_device_irqs()
  37. *
  38. * Enable all interrupt lines previously disabled by suspend_device_irqs() that
  39. * have the IRQS_SUSPENDED flag set.
  40. */
  41. void resume_device_irqs(void)
  42. {
  43. struct irq_desc *desc;
  44. int irq;
  45. for_each_irq_desc(irq, desc) {
  46. unsigned long flags;
  47. raw_spin_lock_irqsave(&desc->lock, flags);
  48. __enable_irq(desc, irq, true);
  49. raw_spin_unlock_irqrestore(&desc->lock, flags);
  50. }
  51. }
  52. EXPORT_SYMBOL_GPL(resume_device_irqs);
  53. /**
  54. * check_wakeup_irqs - check if any wake-up interrupts are pending
  55. */
  56. int check_wakeup_irqs(void)
  57. {
  58. struct irq_desc *desc;
  59. int irq;
  60. for_each_irq_desc(irq, desc) {
  61. if (irqd_is_wakeup_set(&desc->irq_data)) {
  62. if (desc->istate & IRQS_PENDING)
  63. return -EBUSY;
  64. continue;
  65. }
  66. /*
  67. * Check the non wakeup interrupts whether they need
  68. * to be masked before finally going into suspend
  69. * state. That's for hardware which has no wakeup
  70. * source configuration facility. The chip
  71. * implementation indicates that with
  72. * IRQCHIP_MASK_ON_SUSPEND.
  73. */
  74. if (desc->istate & IRQS_SUSPENDED &&
  75. irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND)
  76. mask_irq(desc);
  77. }
  78. return 0;
  79. }