| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 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 |  | 
 | 9 | #include <linux/irq.h> | 
 | 10 | #include <linux/module.h> | 
 | 11 | #include <linux/interrupt.h> | 
| Ian Campbell | 9bab0b7 | 2011-10-03 15:37:00 +0100 | [diff] [blame] | 12 | #include <linux/syscore_ops.h> | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 13 |  | 
 | 14 | #include "internals.h" | 
 | 15 |  | 
 | 16 | /** | 
 | 17 |  * suspend_device_irqs - disable all currently enabled interrupt lines | 
 | 18 |  * | 
| Rafael J. Wysocki | c71320d | 2009-07-05 00:22:34 +0200 | [diff] [blame] | 19 |  * During system-wide suspend or hibernation device drivers need to be prevented | 
 | 20 |  * from receiving interrupts and this function is provided for this purpose. | 
 | 21 |  * It marks all interrupt lines in use, except for the timer ones, as disabled | 
| Thomas Gleixner | c531e83 | 2011-02-08 12:44:58 +0100 | [diff] [blame] | 22 |  * and sets the IRQS_SUSPENDED flag for each of them. | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 23 |  */ | 
 | 24 | void suspend_device_irqs(void) | 
 | 25 | { | 
 | 26 | 	struct irq_desc *desc; | 
 | 27 | 	int irq; | 
 | 28 |  | 
 | 29 | 	for_each_irq_desc(irq, desc) { | 
 | 30 | 		unsigned long flags; | 
 | 31 |  | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 32 | 		raw_spin_lock_irqsave(&desc->lock, flags); | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 33 | 		__disable_irq(desc, irq, true); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 34 | 		raw_spin_unlock_irqrestore(&desc->lock, flags); | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 35 | 	} | 
 | 36 |  | 
 | 37 | 	for_each_irq_desc(irq, desc) | 
| Thomas Gleixner | c531e83 | 2011-02-08 12:44:58 +0100 | [diff] [blame] | 38 | 		if (desc->istate & IRQS_SUSPENDED) | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 39 | 			synchronize_irq(irq); | 
 | 40 | } | 
 | 41 | EXPORT_SYMBOL_GPL(suspend_device_irqs); | 
 | 42 |  | 
| Ian Campbell | 9bab0b7 | 2011-10-03 15:37:00 +0100 | [diff] [blame] | 43 | static void resume_irqs(bool want_early) | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 44 | { | 
 | 45 | 	struct irq_desc *desc; | 
 | 46 | 	int irq; | 
 | 47 |  | 
 | 48 | 	for_each_irq_desc(irq, desc) { | 
 | 49 | 		unsigned long flags; | 
| Ian Campbell | 9bab0b7 | 2011-10-03 15:37:00 +0100 | [diff] [blame] | 50 | 		bool is_early = desc->action && | 
 | 51 | 			desc->action->flags & IRQF_EARLY_RESUME; | 
 | 52 |  | 
 | 53 | 		if (is_early != want_early) | 
 | 54 | 			continue; | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 55 |  | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 56 | 		raw_spin_lock_irqsave(&desc->lock, flags); | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 57 | 		__enable_irq(desc, irq, true); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 58 | 		raw_spin_unlock_irqrestore(&desc->lock, flags); | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 59 | 	} | 
 | 60 | } | 
| Ian Campbell | 9bab0b7 | 2011-10-03 15:37:00 +0100 | [diff] [blame] | 61 |  | 
 | 62 | /** | 
 | 63 |  * irq_pm_syscore_ops - enable interrupt lines early | 
 | 64 |  * | 
 | 65 |  * Enable all interrupt lines with %IRQF_EARLY_RESUME set. | 
 | 66 |  */ | 
 | 67 | static void irq_pm_syscore_resume(void) | 
 | 68 | { | 
 | 69 | 	resume_irqs(true); | 
 | 70 | } | 
 | 71 |  | 
 | 72 | static struct syscore_ops irq_pm_syscore_ops = { | 
 | 73 | 	.resume		= irq_pm_syscore_resume, | 
 | 74 | }; | 
 | 75 |  | 
 | 76 | static int __init irq_pm_init_ops(void) | 
 | 77 | { | 
 | 78 | 	register_syscore_ops(&irq_pm_syscore_ops); | 
 | 79 | 	return 0; | 
 | 80 | } | 
 | 81 |  | 
 | 82 | device_initcall(irq_pm_init_ops); | 
 | 83 |  | 
 | 84 | /** | 
 | 85 |  * resume_device_irqs - enable interrupt lines disabled by suspend_device_irqs() | 
 | 86 |  * | 
 | 87 |  * Enable all non-%IRQF_EARLY_RESUME interrupt lines previously | 
 | 88 |  * disabled by suspend_device_irqs() that have the IRQS_SUSPENDED flag | 
 | 89 |  * set as well as those with %IRQF_FORCE_RESUME. | 
 | 90 |  */ | 
 | 91 | void resume_device_irqs(void) | 
 | 92 | { | 
 | 93 | 	resume_irqs(false); | 
 | 94 | } | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 95 | EXPORT_SYMBOL_GPL(resume_device_irqs); | 
 | 96 |  | 
 | 97 | /** | 
 | 98 |  * check_wakeup_irqs - check if any wake-up interrupts are pending | 
 | 99 |  */ | 
 | 100 | int check_wakeup_irqs(void) | 
 | 101 | { | 
 | 102 | 	struct irq_desc *desc; | 
 | 103 | 	int irq; | 
 | 104 |  | 
| Thomas Gleixner | d209a69 | 2011-03-11 21:22:14 +0100 | [diff] [blame] | 105 | 	for_each_irq_desc(irq, desc) { | 
 | 106 | 		if (irqd_is_wakeup_set(&desc->irq_data)) { | 
 | 107 | 			if (desc->istate & IRQS_PENDING) | 
 | 108 | 				return -EBUSY; | 
 | 109 | 			continue; | 
 | 110 | 		} | 
 | 111 | 		/* | 
 | 112 | 		 * Check the non wakeup interrupts whether they need | 
 | 113 | 		 * to be masked before finally going into suspend | 
 | 114 | 		 * state. That's for hardware which has no wakeup | 
 | 115 | 		 * source configuration facility. The chip | 
 | 116 | 		 * implementation indicates that with | 
 | 117 | 		 * IRQCHIP_MASK_ON_SUSPEND. | 
 | 118 | 		 */ | 
 | 119 | 		if (desc->istate & IRQS_SUSPENDED && | 
 | 120 | 		    irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND) | 
 | 121 | 			mask_irq(desc); | 
 | 122 | 	} | 
| Rafael J. Wysocki | 0a0c516 | 2009-03-16 22:33:49 +0100 | [diff] [blame] | 123 |  | 
 | 124 | 	return 0; | 
 | 125 | } |