]>
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 | ||
c4df606c | 52 | static bool suspend_device_irq(struct irq_desc *desc, int irq) |
8df2e02c | 53 | { |
5417de22 | 54 | if (!desc->action || desc->no_suspend_depth) |
c4df606c | 55 | return false; |
8df2e02c TG |
56 | |
57 | desc->istate |= IRQS_SUSPENDED; | |
58 | __disable_irq(desc, irq); | |
092fadd5 TG |
59 | |
60 | /* | |
61 | * Hardware which has no wakeup source configuration facility | |
62 | * requires that the non wakeup interrupts are masked at the | |
63 | * chip level. The chip implementation indicates that with | |
64 | * IRQCHIP_MASK_ON_SUSPEND. | |
65 | */ | |
66 | if (irq_desc_get_chip(desc)->flags & IRQCHIP_MASK_ON_SUSPEND) | |
67 | mask_irq(desc); | |
c4df606c | 68 | return true; |
8df2e02c TG |
69 | } |
70 | ||
0a0c5168 RW |
71 | /** |
72 | * suspend_device_irqs - disable all currently enabled interrupt lines | |
73 | * | |
8df2e02c TG |
74 | * During system-wide suspend or hibernation device drivers need to be |
75 | * prevented from receiving interrupts and this function is provided | |
76 | * for this purpose. | |
77 | * | |
78 | * So we disable all interrupts and mark them IRQS_SUSPENDED except | |
79 | * for those which are unused and those which are marked as not | |
80 | * suspendable via an interrupt request with the flag IRQF_NO_SUSPEND | |
81 | * set. | |
0a0c5168 RW |
82 | */ |
83 | void suspend_device_irqs(void) | |
84 | { | |
85 | struct irq_desc *desc; | |
86 | int irq; | |
87 | ||
88 | for_each_irq_desc(irq, desc) { | |
89 | unsigned long flags; | |
c4df606c | 90 | bool sync; |
0a0c5168 | 91 | |
239007b8 | 92 | raw_spin_lock_irqsave(&desc->lock, flags); |
c4df606c | 93 | sync = suspend_device_irq(desc, irq); |
239007b8 | 94 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
0a0c5168 | 95 | |
c4df606c | 96 | if (sync) |
0a0c5168 | 97 | synchronize_irq(irq); |
c4df606c | 98 | } |
0a0c5168 RW |
99 | } |
100 | EXPORT_SYMBOL_GPL(suspend_device_irqs); | |
101 | ||
8df2e02c TG |
102 | static void resume_irq(struct irq_desc *desc, int irq) |
103 | { | |
104 | if (desc->istate & IRQS_SUSPENDED) | |
105 | goto resume; | |
106 | ||
5417de22 TG |
107 | /* Force resume the interrupt? */ |
108 | if (!desc->force_resume_depth) | |
8df2e02c TG |
109 | return; |
110 | ||
111 | /* Pretend that it got disabled ! */ | |
112 | desc->depth++; | |
113 | resume: | |
114 | desc->istate &= ~IRQS_SUSPENDED; | |
115 | __enable_irq(desc, irq); | |
116 | } | |
117 | ||
9bab0b7f | 118 | static void resume_irqs(bool want_early) |
0a0c5168 RW |
119 | { |
120 | struct irq_desc *desc; | |
121 | int irq; | |
122 | ||
123 | for_each_irq_desc(irq, desc) { | |
124 | unsigned long flags; | |
9bab0b7f IC |
125 | bool is_early = desc->action && |
126 | desc->action->flags & IRQF_EARLY_RESUME; | |
127 | ||
ac01810c | 128 | if (!is_early && want_early) |
9bab0b7f | 129 | continue; |
0a0c5168 | 130 | |
239007b8 | 131 | raw_spin_lock_irqsave(&desc->lock, flags); |
8df2e02c | 132 | resume_irq(desc, irq); |
239007b8 | 133 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
0a0c5168 RW |
134 | } |
135 | } | |
9bab0b7f IC |
136 | |
137 | /** | |
138 | * irq_pm_syscore_ops - enable interrupt lines early | |
139 | * | |
140 | * Enable all interrupt lines with %IRQF_EARLY_RESUME set. | |
141 | */ | |
142 | static void irq_pm_syscore_resume(void) | |
143 | { | |
144 | resume_irqs(true); | |
145 | } | |
146 | ||
147 | static struct syscore_ops irq_pm_syscore_ops = { | |
148 | .resume = irq_pm_syscore_resume, | |
149 | }; | |
150 | ||
151 | static int __init irq_pm_init_ops(void) | |
152 | { | |
153 | register_syscore_ops(&irq_pm_syscore_ops); | |
154 | return 0; | |
155 | } | |
156 | ||
157 | device_initcall(irq_pm_init_ops); | |
158 | ||
159 | /** | |
160 | * resume_device_irqs - enable interrupt lines disabled by suspend_device_irqs() | |
161 | * | |
162 | * Enable all non-%IRQF_EARLY_RESUME interrupt lines previously | |
163 | * disabled by suspend_device_irqs() that have the IRQS_SUSPENDED flag | |
164 | * set as well as those with %IRQF_FORCE_RESUME. | |
165 | */ | |
166 | void resume_device_irqs(void) | |
167 | { | |
168 | resume_irqs(false); | |
169 | } | |
0a0c5168 RW |
170 | EXPORT_SYMBOL_GPL(resume_device_irqs); |
171 | ||
172 | /** | |
173 | * check_wakeup_irqs - check if any wake-up interrupts are pending | |
174 | */ | |
175 | int check_wakeup_irqs(void) | |
176 | { | |
177 | struct irq_desc *desc; | |
178 | int irq; | |
179 | ||
d209a699 | 180 | for_each_irq_desc(irq, desc) { |
9c6079aa TG |
181 | /* |
182 | * Only interrupts which are marked as wakeup source | |
183 | * and have not been disabled before the suspend check | |
184 | * can abort suspend. | |
185 | */ | |
d209a699 | 186 | if (irqd_is_wakeup_set(&desc->irq_data)) { |
9c6079aa | 187 | if (desc->depth == 1 && desc->istate & IRQS_PENDING) |
d209a699 | 188 | return -EBUSY; |
d209a699 | 189 | } |
d209a699 | 190 | } |
0a0c5168 RW |
191 | |
192 | return 0; | |
193 | } |