blob: a746a8f54dae84383b62b145200dcc3fdf72c78a [file] [log] [blame]
Thomas Gleixner7d828062011-04-03 11:42:53 +02001/*
2 * Library implementing the most common irq chip callback functions
3 *
4 * Copyright (C) 2011, Thomas Gleixner
5 */
6#include <linux/io.h>
7#include <linux/irq.h>
8#include <linux/slab.h>
Paul Gortmaker6e5fdee2011-05-26 16:00:52 -04009#include <linux/export.h>
Thomas Gleixner088f40b2013-05-06 14:30:27 +000010#include <linux/irqdomain.h>
Thomas Gleixner7d828062011-04-03 11:42:53 +020011#include <linux/interrupt.h>
12#include <linux/kernel_stat.h>
Thomas Gleixnercfefd212011-04-15 22:36:08 +020013#include <linux/syscore_ops.h>
Thomas Gleixner7d828062011-04-03 11:42:53 +020014
15#include "internals.h"
16
Thomas Gleixnercfefd212011-04-15 22:36:08 +020017static LIST_HEAD(gc_list);
18static DEFINE_RAW_SPINLOCK(gc_lock);
19
Thomas Gleixner7d828062011-04-03 11:42:53 +020020/**
21 * irq_gc_noop - NOOP function
22 * @d: irq_data
23 */
24void irq_gc_noop(struct irq_data *d)
25{
26}
27
28/**
29 * irq_gc_mask_disable_reg - Mask chip via disable register
30 * @d: irq_data
31 *
32 * Chip has separate enable/disable registers instead of a single mask
33 * register.
34 */
35void irq_gc_mask_disable_reg(struct irq_data *d)
36{
37 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000038 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +000039 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +020040
41 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000042 irq_reg_writel(mask, gc->reg_base + ct->regs.disable);
Gerlando Falauto899f0e62013-05-06 14:30:19 +000043 *ct->mask_cache &= ~mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +020044 irq_gc_unlock(gc);
45}
46
47/**
48 * irq_gc_mask_set_mask_bit - Mask chip via setting bit in mask register
49 * @d: irq_data
50 *
51 * Chip has a single mask register. Values of this register are cached
52 * and protected by gc->lock
53 */
54void irq_gc_mask_set_bit(struct irq_data *d)
55{
56 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000057 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +000058 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +020059
60 irq_gc_lock(gc);
Gerlando Falauto899f0e62013-05-06 14:30:19 +000061 *ct->mask_cache |= mask;
62 irq_reg_writel(*ct->mask_cache, gc->reg_base + ct->regs.mask);
Thomas Gleixner7d828062011-04-03 11:42:53 +020063 irq_gc_unlock(gc);
64}
65
66/**
67 * irq_gc_mask_set_mask_bit - Mask chip via clearing bit in mask register
68 * @d: irq_data
69 *
70 * Chip has a single mask register. Values of this register are cached
71 * and protected by gc->lock
72 */
73void irq_gc_mask_clr_bit(struct irq_data *d)
74{
75 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000076 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +000077 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +020078
79 irq_gc_lock(gc);
Gerlando Falauto899f0e62013-05-06 14:30:19 +000080 *ct->mask_cache &= ~mask;
81 irq_reg_writel(*ct->mask_cache, gc->reg_base + ct->regs.mask);
Thomas Gleixner7d828062011-04-03 11:42:53 +020082 irq_gc_unlock(gc);
83}
84
85/**
86 * irq_gc_unmask_enable_reg - Unmask chip via enable register
87 * @d: irq_data
88 *
89 * Chip has separate enable/disable registers instead of a single mask
90 * register.
91 */
92void irq_gc_unmask_enable_reg(struct irq_data *d)
93{
94 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000095 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +000096 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +020097
98 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +000099 irq_reg_writel(mask, gc->reg_base + ct->regs.enable);
Gerlando Falauto899f0e62013-05-06 14:30:19 +0000100 *ct->mask_cache |= mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200101 irq_gc_unlock(gc);
102}
103
104/**
Simon Guinot659fb322011-07-06 12:41:31 -0400105 * irq_gc_ack_set_bit - Ack pending interrupt via setting bit
Thomas Gleixner7d828062011-04-03 11:42:53 +0200106 * @d: irq_data
107 */
Simon Guinot659fb322011-07-06 12:41:31 -0400108void irq_gc_ack_set_bit(struct irq_data *d)
Thomas Gleixner7d828062011-04-03 11:42:53 +0200109{
110 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000111 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000112 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200113
114 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000115 irq_reg_writel(mask, gc->reg_base + ct->regs.ack);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200116 irq_gc_unlock(gc);
117}
118
119/**
Simon Guinot659fb322011-07-06 12:41:31 -0400120 * irq_gc_ack_clr_bit - Ack pending interrupt via clearing bit
121 * @d: irq_data
122 */
123void irq_gc_ack_clr_bit(struct irq_data *d)
124{
125 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000126 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000127 u32 mask = ~d->mask;
Simon Guinot659fb322011-07-06 12:41:31 -0400128
129 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000130 irq_reg_writel(mask, gc->reg_base + ct->regs.ack);
Simon Guinot659fb322011-07-06 12:41:31 -0400131 irq_gc_unlock(gc);
132}
133
134/**
Thomas Gleixner7d828062011-04-03 11:42:53 +0200135 * irq_gc_mask_disable_reg_and_ack- Mask and ack pending interrupt
136 * @d: irq_data
137 */
138void irq_gc_mask_disable_reg_and_ack(struct irq_data *d)
139{
140 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000141 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000142 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200143
144 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000145 irq_reg_writel(mask, gc->reg_base + ct->regs.mask);
146 irq_reg_writel(mask, gc->reg_base + ct->regs.ack);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200147 irq_gc_unlock(gc);
148}
149
150/**
151 * irq_gc_eoi - EOI interrupt
152 * @d: irq_data
153 */
154void irq_gc_eoi(struct irq_data *d)
155{
156 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000157 struct irq_chip_type *ct = irq_data_get_chip_type(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000158 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200159
160 irq_gc_lock(gc);
Gerlando Falautocfeaa932013-05-06 14:30:17 +0000161 irq_reg_writel(mask, gc->reg_base + ct->regs.eoi);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200162 irq_gc_unlock(gc);
163}
164
165/**
166 * irq_gc_set_wake - Set/clr wake bit for an interrupt
167 * @d: irq_data
168 *
169 * For chips where the wake from suspend functionality is not
170 * configured in a separate register and the wakeup active state is
171 * just stored in a bitmask.
172 */
173int irq_gc_set_wake(struct irq_data *d, unsigned int on)
174{
175 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000176 u32 mask = d->mask;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200177
178 if (!(mask & gc->wake_enabled))
179 return -EINVAL;
180
181 irq_gc_lock(gc);
182 if (on)
183 gc->wake_active |= mask;
184 else
185 gc->wake_active &= ~mask;
186 irq_gc_unlock(gc);
187 return 0;
188}
189
Thomas Gleixner3528d822013-05-06 14:30:25 +0000190static void
191irq_init_generic_chip(struct irq_chip_generic *gc, const char *name,
192 int num_ct, unsigned int irq_base,
193 void __iomem *reg_base, irq_flow_handler_t handler)
194{
195 raw_spin_lock_init(&gc->lock);
196 gc->num_ct = num_ct;
197 gc->irq_base = irq_base;
198 gc->reg_base = reg_base;
199 gc->chip_types->chip.name = name;
200 gc->chip_types->handler = handler;
201}
202
Thomas Gleixner7d828062011-04-03 11:42:53 +0200203/**
204 * irq_alloc_generic_chip - Allocate a generic chip and initialize it
205 * @name: Name of the irq chip
206 * @num_ct: Number of irq_chip_type instances associated with this
207 * @irq_base: Interrupt base nr for this chip
208 * @reg_base: Register base address (virtual)
209 * @handler: Default flow handler associated with this chip
210 *
211 * Returns an initialized irq_chip_generic structure. The chip defaults
212 * to the primary (index 0) irq_chip_type and @handler
213 */
214struct irq_chip_generic *
215irq_alloc_generic_chip(const char *name, int num_ct, unsigned int irq_base,
216 void __iomem *reg_base, irq_flow_handler_t handler)
217{
218 struct irq_chip_generic *gc;
219 unsigned long sz = sizeof(*gc) + num_ct * sizeof(struct irq_chip_type);
220
221 gc = kzalloc(sz, GFP_KERNEL);
222 if (gc) {
Thomas Gleixner3528d822013-05-06 14:30:25 +0000223 irq_init_generic_chip(gc, name, num_ct, irq_base, reg_base,
224 handler);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200225 }
226 return gc;
227}
Nobuhiro Iwamatsu825de2e2011-10-17 11:08:46 +0900228EXPORT_SYMBOL_GPL(irq_alloc_generic_chip);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200229
Thomas Gleixner3528d822013-05-06 14:30:25 +0000230static void
231irq_gc_init_mask_cache(struct irq_chip_generic *gc, enum irq_gc_flags flags)
232{
233 struct irq_chip_type *ct = gc->chip_types;
234 u32 *mskptr = &gc->mask_cache, mskreg = ct->regs.mask;
235 int i;
236
237 for (i = 0; i < gc->num_ct; i++) {
238 if (flags & IRQ_GC_MASK_CACHE_PER_TYPE) {
239 mskptr = &ct[i].mask_cache_priv;
240 mskreg = ct[i].regs.mask;
241 }
242 ct[i].mask_cache = mskptr;
243 if (flags & IRQ_GC_INIT_MASK_CACHE)
244 *mskptr = irq_reg_readl(gc->reg_base + mskreg);
245 }
246}
247
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000248/**
249 * irq_alloc_domain_generic_chip - Allocate generic chips for an irq domain
250 * @d: irq domain for which to allocate chips
251 * @irqs_per_chip: Number of interrupts each chip handles
252 * @num_ct: Number of irq_chip_type instances associated with this
253 * @name: Name of the irq chip
254 * @handler: Default flow handler associated with these chips
255 * @clr: IRQ_* bits to clear in the mapping function
256 * @set: IRQ_* bits to set in the mapping function
James Hogan6fff8312013-06-18 15:08:33 +0100257 * @gcflags: Generic chip specific setup flags
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000258 */
259int irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
260 int num_ct, const char *name,
261 irq_flow_handler_t handler,
262 unsigned int clr, unsigned int set,
263 enum irq_gc_flags gcflags)
264{
265 struct irq_domain_chip_generic *dgc;
266 struct irq_chip_generic *gc;
267 int numchips, sz, i;
268 unsigned long flags;
269 void *tmp;
270
271 if (d->gc)
272 return -EBUSY;
273
274 if (d->revmap_type != IRQ_DOMAIN_MAP_LINEAR)
275 return -EINVAL;
276
277 numchips = d->revmap_data.linear.size / irqs_per_chip;
278 if (!numchips)
279 return -EINVAL;
280
281 /* Allocate a pointer, generic chip and chiptypes for each chip */
282 sz = sizeof(*dgc) + numchips * sizeof(gc);
283 sz += numchips * (sizeof(*gc) + num_ct * sizeof(struct irq_chip_type));
284
285 tmp = dgc = kzalloc(sz, GFP_KERNEL);
286 if (!dgc)
287 return -ENOMEM;
288 dgc->irqs_per_chip = irqs_per_chip;
289 dgc->num_chips = numchips;
290 dgc->irq_flags_to_set = set;
291 dgc->irq_flags_to_clear = clr;
292 dgc->gc_flags = gcflags;
293 d->gc = dgc;
294
295 /* Calc pointer to the first generic chip */
296 tmp += sizeof(*dgc) + numchips * sizeof(gc);
297 for (i = 0; i < numchips; i++) {
298 /* Store the pointer to the generic chip */
299 dgc->gc[i] = gc = tmp;
300 irq_init_generic_chip(gc, name, num_ct, i * irqs_per_chip,
301 NULL, handler);
302 gc->domain = d;
303 raw_spin_lock_irqsave(&gc_lock, flags);
304 list_add_tail(&gc->list, &gc_list);
305 raw_spin_unlock_irqrestore(&gc_lock, flags);
306 /* Calc pointer to the next generic chip */
307 tmp += sizeof(*gc) + num_ct * sizeof(struct irq_chip_type);
308 }
309 return 0;
310}
311EXPORT_SYMBOL_GPL(irq_alloc_domain_generic_chips);
312
313/**
314 * irq_get_domain_generic_chip - Get a pointer to the generic chip of a hw_irq
315 * @d: irq domain pointer
316 * @hw_irq: Hardware interrupt number
317 */
318struct irq_chip_generic *
319irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq)
320{
321 struct irq_domain_chip_generic *dgc = d->gc;
322 int idx;
323
324 if (!dgc)
325 return NULL;
326 idx = hw_irq / dgc->irqs_per_chip;
327 if (idx >= dgc->num_chips)
328 return NULL;
329 return dgc->gc[idx];
330}
331EXPORT_SYMBOL_GPL(irq_get_domain_generic_chip);
332
Thomas Gleixner7d828062011-04-03 11:42:53 +0200333/*
334 * Separate lockdep class for interrupt chip which can nest irq_desc
335 * lock.
336 */
337static struct lock_class_key irq_nested_lock_class;
338
339/**
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000340 * irq_map_generic_chip - Map a generic chip for an irq domain
341 */
342static int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
343 irq_hw_number_t hw_irq)
344{
345 struct irq_data *data = irq_get_irq_data(virq);
346 struct irq_domain_chip_generic *dgc = d->gc;
347 struct irq_chip_generic *gc;
348 struct irq_chip_type *ct;
349 struct irq_chip *chip;
350 unsigned long flags;
351 int idx;
352
353 if (!d->gc)
354 return -ENODEV;
355
356 idx = hw_irq / dgc->irqs_per_chip;
357 if (idx >= dgc->num_chips)
358 return -EINVAL;
359 gc = dgc->gc[idx];
360
361 idx = hw_irq % dgc->irqs_per_chip;
362
Grant Likelye8bd8342013-05-29 03:10:52 +0100363 if (test_bit(idx, &gc->unused))
364 return -ENOTSUPP;
365
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000366 if (test_bit(idx, &gc->installed))
367 return -EBUSY;
368
369 ct = gc->chip_types;
370 chip = &ct->chip;
371
372 /* We only init the cache for the first mapping of a generic chip */
373 if (!gc->installed) {
374 raw_spin_lock_irqsave(&gc->lock, flags);
375 irq_gc_init_mask_cache(gc, dgc->gc_flags);
376 raw_spin_unlock_irqrestore(&gc->lock, flags);
377 }
378
379 /* Mark the interrupt as installed */
380 set_bit(idx, &gc->installed);
381
382 if (dgc->gc_flags & IRQ_GC_INIT_NESTED_LOCK)
383 irq_set_lockdep_class(virq, &irq_nested_lock_class);
384
385 if (chip->irq_calc_mask)
386 chip->irq_calc_mask(data);
387 else
388 data->mask = 1 << idx;
389
390 irq_set_chip_and_handler(virq, chip, ct->handler);
391 irq_set_chip_data(virq, gc);
392 irq_modify_status(virq, dgc->irq_flags_to_clear, dgc->irq_flags_to_set);
393 return 0;
394}
395
396struct irq_domain_ops irq_generic_chip_ops = {
397 .map = irq_map_generic_chip,
398 .xlate = irq_domain_xlate_onetwocell,
399};
400EXPORT_SYMBOL_GPL(irq_generic_chip_ops);
401
402/**
Thomas Gleixner7d828062011-04-03 11:42:53 +0200403 * irq_setup_generic_chip - Setup a range of interrupts with a generic chip
404 * @gc: Generic irq chip holding all data
405 * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base
406 * @flags: Flags for initialization
407 * @clr: IRQ_* bits to clear
408 * @set: IRQ_* bits to set
409 *
410 * Set up max. 32 interrupts starting from gc->irq_base. Note, this
411 * initializes all interrupts to the primary irq_chip_type and its
412 * associated handler.
413 */
414void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
415 enum irq_gc_flags flags, unsigned int clr,
416 unsigned int set)
417{
418 struct irq_chip_type *ct = gc->chip_types;
Thomas Gleixnerd0051812013-05-06 14:30:24 +0000419 struct irq_chip *chip = &ct->chip;
Thomas Gleixner7d828062011-04-03 11:42:53 +0200420 unsigned int i;
421
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200422 raw_spin_lock(&gc_lock);
423 list_add_tail(&gc->list, &gc_list);
424 raw_spin_unlock(&gc_lock);
425
Thomas Gleixner3528d822013-05-06 14:30:25 +0000426 irq_gc_init_mask_cache(gc, flags);
Gerlando Falauto899f0e62013-05-06 14:30:19 +0000427
Thomas Gleixner7d828062011-04-03 11:42:53 +0200428 for (i = gc->irq_base; msk; msk >>= 1, i++) {
jhbird.choi@samsung.com1dd75f92011-07-21 15:29:14 +0900429 if (!(msk & 0x01))
Thomas Gleixner7d828062011-04-03 11:42:53 +0200430 continue;
431
432 if (flags & IRQ_GC_INIT_NESTED_LOCK)
433 irq_set_lockdep_class(i, &irq_nested_lock_class);
434
Thomas Gleixner966dc732013-05-06 14:30:22 +0000435 if (!(flags & IRQ_GC_NO_MASK)) {
436 struct irq_data *d = irq_get_irq_data(i);
437
Thomas Gleixnerd0051812013-05-06 14:30:24 +0000438 if (chip->irq_calc_mask)
439 chip->irq_calc_mask(d);
440 else
441 d->mask = 1 << (i - gc->irq_base);
Thomas Gleixner966dc732013-05-06 14:30:22 +0000442 }
Thomas Gleixnerd0051812013-05-06 14:30:24 +0000443 irq_set_chip_and_handler(i, chip, ct->handler);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200444 irq_set_chip_data(i, gc);
445 irq_modify_status(i, clr, set);
446 }
447 gc->irq_cnt = i - gc->irq_base;
448}
Nobuhiro Iwamatsu825de2e2011-10-17 11:08:46 +0900449EXPORT_SYMBOL_GPL(irq_setup_generic_chip);
Thomas Gleixner7d828062011-04-03 11:42:53 +0200450
451/**
452 * irq_setup_alt_chip - Switch to alternative chip
453 * @d: irq_data for this interrupt
454 * @type Flow type to be initialized
455 *
456 * Only to be called from chip->irq_set_type() callbacks.
457 */
458int irq_setup_alt_chip(struct irq_data *d, unsigned int type)
459{
460 struct irq_chip_generic *gc = irq_data_get_irq_chip_data(d);
461 struct irq_chip_type *ct = gc->chip_types;
462 unsigned int i;
463
464 for (i = 0; i < gc->num_ct; i++, ct++) {
465 if (ct->type & type) {
466 d->chip = &ct->chip;
467 irq_data_to_desc(d)->handle_irq = ct->handler;
468 return 0;
469 }
470 }
471 return -EINVAL;
472}
Nobuhiro Iwamatsu825de2e2011-10-17 11:08:46 +0900473EXPORT_SYMBOL_GPL(irq_setup_alt_chip);
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200474
475/**
476 * irq_remove_generic_chip - Remove a chip
477 * @gc: Generic irq chip holding all data
478 * @msk: Bitmask holding the irqs to initialize relative to gc->irq_base
479 * @clr: IRQ_* bits to clear
480 * @set: IRQ_* bits to set
481 *
482 * Remove up to 32 interrupts starting from gc->irq_base.
483 */
484void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
485 unsigned int clr, unsigned int set)
486{
487 unsigned int i = gc->irq_base;
488
489 raw_spin_lock(&gc_lock);
490 list_del(&gc->list);
491 raw_spin_unlock(&gc_lock);
492
493 for (; msk; msk >>= 1, i++) {
jhbird.choi@samsung.com1dd75f92011-07-21 15:29:14 +0900494 if (!(msk & 0x01))
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200495 continue;
496
497 /* Remove handler first. That will mask the irq line */
498 irq_set_handler(i, NULL);
499 irq_set_chip(i, &no_irq_chip);
500 irq_set_chip_data(i, NULL);
501 irq_modify_status(i, clr, set);
502 }
503}
Nobuhiro Iwamatsu825de2e2011-10-17 11:08:46 +0900504EXPORT_SYMBOL_GPL(irq_remove_generic_chip);
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200505
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000506static struct irq_data *irq_gc_get_irq_data(struct irq_chip_generic *gc)
507{
508 unsigned int virq;
509
510 if (!gc->domain)
511 return irq_get_irq_data(gc->irq_base);
512
513 /*
514 * We don't know which of the irqs has been actually
515 * installed. Use the first one.
516 */
517 if (!gc->installed)
518 return NULL;
519
520 virq = irq_find_mapping(gc->domain, gc->irq_base + __ffs(gc->installed));
521 return virq ? irq_get_irq_data(virq) : NULL;
522}
523
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200524#ifdef CONFIG_PM
525static int irq_gc_suspend(void)
526{
527 struct irq_chip_generic *gc;
528
529 list_for_each_entry(gc, &gc_list, list) {
530 struct irq_chip_type *ct = gc->chip_types;
531
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000532 if (ct->chip.irq_suspend) {
533 struct irq_data *data = irq_gc_get_irq_data(gc);
534
535 if (data)
536 ct->chip.irq_suspend(data);
537 }
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200538 }
539 return 0;
540}
541
542static void irq_gc_resume(void)
543{
544 struct irq_chip_generic *gc;
545
546 list_for_each_entry(gc, &gc_list, list) {
547 struct irq_chip_type *ct = gc->chip_types;
548
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000549 if (ct->chip.irq_resume) {
550 struct irq_data *data = irq_gc_get_irq_data(gc);
551
552 if (data)
553 ct->chip.irq_resume(data);
554 }
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200555 }
556}
557#else
558#define irq_gc_suspend NULL
559#define irq_gc_resume NULL
560#endif
561
562static void irq_gc_shutdown(void)
563{
564 struct irq_chip_generic *gc;
565
566 list_for_each_entry(gc, &gc_list, list) {
567 struct irq_chip_type *ct = gc->chip_types;
568
Thomas Gleixner088f40b2013-05-06 14:30:27 +0000569 if (ct->chip.irq_pm_shutdown) {
570 struct irq_data *data = irq_gc_get_irq_data(gc);
571
572 if (data)
573 ct->chip.irq_pm_shutdown(data);
574 }
Thomas Gleixnercfefd212011-04-15 22:36:08 +0200575 }
576}
577
578static struct syscore_ops irq_gc_syscore_ops = {
579 .suspend = irq_gc_suspend,
580 .resume = irq_gc_resume,
581 .shutdown = irq_gc_shutdown,
582};
583
584static int __init irq_gc_init_ops(void)
585{
586 register_syscore_ops(&irq_gc_syscore_ops);
587 return 0;
588}
589device_initcall(irq_gc_init_ops);