]>
Commit | Line | Data |
---|---|---|
0a0c5168 RW |
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> | |
9bab0b7f | 12 | #include <linux/syscore_ops.h> |
0a0c5168 RW |
13 | |
14 | #include "internals.h" | |
15 | ||
cab303be TG |
16 | /* |
17 | * Called from __setup_irq() with desc->lock held after @action has | |
18 | * been installed in the action chain. | |
19 | */ | |
20 | void irq_pm_install_action(struct irq_desc *desc, struct irqaction *action) | |
21 | { | |
22 | desc->nr_actions++; | |
23 | ||
24 | if (action->flags & IRQF_FORCE_RESUME) | |
25 | desc->force_resume_depth++; | |
26 | ||
27 | WARN_ON_ONCE(desc->force_resume_depth && | |
28 | desc->force_resume_depth != desc->nr_actions); | |
29 | ||
30 | if (action->flags & IRQF_NO_SUSPEND) | |
31 | desc->no_suspend_depth++; | |
32 | ||
33 | WARN_ON_ONCE(desc->no_suspend_depth && | |
34 | desc->no_suspend_depth != desc->nr_actions); | |
35 | } | |
36 | ||
37 | /* | |
38 | * Called from __free_irq() with desc->lock held after @action has | |
39 | * been removed from the action chain. | |
40 | */ | |
41 | void irq_pm_remove_action(struct irq_desc *desc, struct irqaction *action) | |
42 | { | |
43 | desc->nr_actions--; | |
44 | ||
45 | if (action->flags & IRQF_FORCE_RESUME) | |
46 | desc->force_resume_depth--; | |
47 | ||
48 | if (action->flags & IRQF_NO_SUSPEND) | |
49 | desc->no_suspend_depth--; | |
50 | } | |
51 | ||
8df2e02c TG |
52 | static void suspend_device_irq(struct irq_desc *desc, int irq) |
53 | { | |
5417de22 | 54 | if (!desc->action || desc->no_suspend_depth) |
8df2e02c TG |
55 | return; |
56 | ||
57 | desc->istate |= IRQS_SUSPENDED; | |
58 | __disable_irq(desc, irq); | |
59 | } | |
60 | ||
0a0c5168 RW |
61 | /** |
62 | * suspend_device_irqs - disable all currently enabled interrupt lines | |
63 | * | |
8df2e02c TG |
64 | * During system-wide suspend or hibernation device drivers need to be |
65 | * prevented from receiving interrupts and this function is provided | |
66 | * for this purpose. | |
67 | * | |
68 | * So we disable all interrupts and mark them IRQS_SUSPENDED except | |
69 | * for those which are unused and those which are marked as not | |
70 | * suspendable via an interrupt request with the flag IRQF_NO_SUSPEND | |
71 | * set. | |
0a0c5168 RW |
72 | */ |
73 | void suspend_device_irqs(void) | |
74 | { | |
75 | struct irq_desc *desc; | |
76 | int irq; | |
77 | ||
78 | for_each_irq_desc(irq, desc) { | |
79 | unsigned long flags; | |
80 | ||
239007b8 | 81 | raw_spin_lock_irqsave(&desc->lock, flags); |
8df2e02c | 82 | suspend_device_irq(desc, irq); |
239007b8 | 83 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
0a0c5168 RW |
84 | } |
85 | ||
86 | for_each_irq_desc(irq, desc) | |
c531e836 | 87 | if (desc->istate & IRQS_SUSPENDED) |
0a0c5168 RW |
88 | synchronize_irq(irq); |
89 | } | |
90 | EXPORT_SYMBOL_GPL(suspend_device_irqs); | |
91 | ||
8df2e02c TG |
92 | static void resume_irq(struct irq_desc *desc, int irq) |
93 | { | |
94 | if (desc->istate & IRQS_SUSPENDED) | |
95 | goto resume; | |
96 | ||
5417de22 TG |
97 | /* Force resume the interrupt? */ |
98 | if (!desc->force_resume_depth) | |
8df2e02c TG |
99 | return; |
100 | ||
101 | /* Pretend that it got disabled ! */ | |
102 | desc->depth++; | |
103 | resume: | |
104 | desc->istate &= ~IRQS_SUSPENDED; | |
105 | __enable_irq(desc, irq); | |
106 | } | |
107 | ||
9bab0b7f | 108 | static void resume_irqs(bool want_early) |
0a0c5168 RW |
109 | { |
110 | struct irq_desc *desc; | |
111 | int irq; | |
112 | ||
113 | for_each_irq_desc(irq, desc) { | |
114 | unsigned long flags; | |
9bab0b7f IC |
115 | bool is_early = desc->action && |
116 | desc->action->flags & IRQF_EARLY_RESUME; | |
117 | ||
ac01810c | 118 | if (!is_early && want_early) |
9bab0b7f | 119 | continue; |
0a0c5168 | 120 | |
239007b8 | 121 | raw_spin_lock_irqsave(&desc->lock, flags); |
8df2e02c | 122 | resume_irq(desc, irq); |
239007b8 | 123 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
0a0c5168 RW |
124 | } |
125 | } | |
9bab0b7f IC |
126 | |
127 | /** | |
128 | * irq_pm_syscore_ops - enable interrupt lines early | |
129 | * | |
130 | * Enable all interrupt lines with %IRQF_EARLY_RESUME set. | |
131 | */ | |
132 | static void irq_pm_syscore_resume(void) | |
133 | { | |
134 | resume_irqs(true); | |
135 | } | |
136 | ||
137 | static struct syscore_ops irq_pm_syscore_ops = { | |
138 | .resume = irq_pm_syscore_resume, | |
139 | }; | |
140 | ||
141 | static int __init irq_pm_init_ops(void) | |
142 | { | |
143 | register_syscore_ops(&irq_pm_syscore_ops); | |
144 | return 0; | |
145 | } | |
146 | ||
147 | device_initcall(irq_pm_init_ops); | |
148 | ||
149 | /** | |
150 | * resume_device_irqs - enable interrupt lines disabled by suspend_device_irqs() | |
151 | * | |
152 | * Enable all non-%IRQF_EARLY_RESUME interrupt lines previously | |
153 | * disabled by suspend_device_irqs() that have the IRQS_SUSPENDED flag | |
154 | * set as well as those with %IRQF_FORCE_RESUME. | |
155 | */ | |
156 | void resume_device_irqs(void) | |
157 | { | |
158 | resume_irqs(false); | |
159 | } | |
0a0c5168 RW |
160 | EXPORT_SYMBOL_GPL(resume_device_irqs); |
161 | ||
162 | /** | |
163 | * check_wakeup_irqs - check if any wake-up interrupts are pending | |
164 | */ | |
165 | int check_wakeup_irqs(void) | |
166 | { | |
167 | struct irq_desc *desc; | |
168 | int irq; | |
169 | ||
d209a699 | 170 | for_each_irq_desc(irq, desc) { |
9c6079aa TG |
171 | /* |
172 | * Only interrupts which are marked as wakeup source | |
173 | * and have not been disabled before the suspend check | |
174 | * can abort suspend. | |
175 | */ | |
d209a699 | 176 | if (irqd_is_wakeup_set(&desc->irq_data)) { |
9c6079aa | 177 | if (desc->depth == 1 && desc->istate & IRQS_PENDING) |
d209a699 TG |
178 | return -EBUSY; |
179 | continue; | |
180 | } | |
181 | /* | |
182 | * Check the non wakeup interrupts whether they need | |
183 | * to be masked before finally going into suspend | |
184 | * state. That's for hardware which has no wakeup | |
185 | * source configuration facility. The chip | |
186 | * implementation indicates that with | |
187 | * IRQCHIP_MASK_ON_SUSPEND. | |
188 | */ | |
189 | if (desc->istate & IRQS_SUSPENDED && | |
190 | irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND) | |
191 | mask_irq(desc); | |
192 | } | |
0a0c5168 RW |
193 | |
194 | return 0; | |
195 | } |