2 * Shared interrupt handling code for IPR and INTC2 types of IRQs.
4 * Copyright (C) 2007, 2008 Magnus Damm
6 * Based on intc2.c and ipr.c
8 * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
9 * Copyright (C) 2000 Kazumoto Kojima
10 * Copyright (C) 2001 David J. Mckay (david.mckay@st.com)
11 * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
12 * Copyright (C) 2005, 2006 Paul Mundt
14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file "COPYING" in the main directory of this archive
18 #include <linux/init.h>
19 #include <linux/irq.h>
20 #include <linux/module.h>
22 #include <linux/interrupt.h>
23 #include <linux/sh_intc.h>
24 #include <linux/sysdev.h>
25 #include <linux/list.h>
26 #include <linux/topology.h>
28 #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
29 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
30 ((addr_e) << 16) | ((addr_d << 24)))
32 #define _INTC_SHIFT(h) (h & 0x1f)
33 #define _INTC_WIDTH(h) ((h >> 5) & 0xf)
34 #define _INTC_FN(h) ((h >> 9) & 0xf)
35 #define _INTC_MODE(h) ((h >> 13) & 0x7)
36 #define _INTC_ADDR_E(h) ((h >> 16) & 0xff)
37 #define _INTC_ADDR_D(h) ((h >> 24) & 0xff)
39 struct intc_handle_int
{
44 struct intc_desc_int
{
45 struct list_head list
;
46 struct sys_device sysdev
;
53 struct intc_handle_int
*prio
;
55 struct intc_handle_int
*sense
;
56 unsigned int nr_sense
;
60 static LIST_HEAD(intc_list
);
63 #define IS_SMP(x) x.smp
64 #define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
65 #define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
68 #define INTC_REG(d, x, c) (d->reg[(x)])
69 #define SMP_NR(d, x) 1
72 static unsigned int intc_prio_level
[NR_IRQS
]; /* for now */
73 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
74 static unsigned long ack_handle
[NR_IRQS
];
77 static inline struct intc_desc_int
*get_intc_desc(unsigned int irq
)
79 struct irq_chip
*chip
= get_irq_chip(irq
);
80 return container_of(chip
, struct intc_desc_int
, chip
);
83 static inline unsigned int set_field(unsigned int value
,
84 unsigned int field_value
,
87 unsigned int width
= _INTC_WIDTH(handle
);
88 unsigned int shift
= _INTC_SHIFT(handle
);
90 value
&= ~(((1 << width
) - 1) << shift
);
91 value
|= field_value
<< shift
;
95 static void write_8(unsigned long addr
, unsigned long h
, unsigned long data
)
97 __raw_writeb(set_field(0, data
, h
), addr
);
98 (void)__raw_readb(addr
); /* Defeat write posting */
101 static void write_16(unsigned long addr
, unsigned long h
, unsigned long data
)
103 __raw_writew(set_field(0, data
, h
), addr
);
104 (void)__raw_readw(addr
); /* Defeat write posting */
107 static void write_32(unsigned long addr
, unsigned long h
, unsigned long data
)
109 __raw_writel(set_field(0, data
, h
), addr
);
110 (void)__raw_readl(addr
); /* Defeat write posting */
113 static void modify_8(unsigned long addr
, unsigned long h
, unsigned long data
)
116 local_irq_save(flags
);
117 __raw_writeb(set_field(__raw_readb(addr
), data
, h
), addr
);
118 (void)__raw_readb(addr
); /* Defeat write posting */
119 local_irq_restore(flags
);
122 static void modify_16(unsigned long addr
, unsigned long h
, unsigned long data
)
125 local_irq_save(flags
);
126 __raw_writew(set_field(__raw_readw(addr
), data
, h
), addr
);
127 (void)__raw_readw(addr
); /* Defeat write posting */
128 local_irq_restore(flags
);
131 static void modify_32(unsigned long addr
, unsigned long h
, unsigned long data
)
134 local_irq_save(flags
);
135 __raw_writel(set_field(__raw_readl(addr
), data
, h
), addr
);
136 (void)__raw_readl(addr
); /* Defeat write posting */
137 local_irq_restore(flags
);
140 enum { REG_FN_ERR
= 0, REG_FN_WRITE_BASE
= 1, REG_FN_MODIFY_BASE
= 5 };
142 static void (*intc_reg_fns
[])(unsigned long addr
,
144 unsigned long data
) = {
145 [REG_FN_WRITE_BASE
+ 0] = write_8
,
146 [REG_FN_WRITE_BASE
+ 1] = write_16
,
147 [REG_FN_WRITE_BASE
+ 3] = write_32
,
148 [REG_FN_MODIFY_BASE
+ 0] = modify_8
,
149 [REG_FN_MODIFY_BASE
+ 1] = modify_16
,
150 [REG_FN_MODIFY_BASE
+ 3] = modify_32
,
153 enum { MODE_ENABLE_REG
= 0, /* Bit(s) set -> interrupt enabled */
154 MODE_MASK_REG
, /* Bit(s) set -> interrupt disabled */
155 MODE_DUAL_REG
, /* Two registers, set bit to enable / disable */
156 MODE_PRIO_REG
, /* Priority value written to enable interrupt */
157 MODE_PCLR_REG
, /* Above plus all bits set to disable interrupt */
160 static void intc_mode_field(unsigned long addr
,
161 unsigned long handle
,
162 void (*fn
)(unsigned long,
167 fn(addr
, handle
, ((1 << _INTC_WIDTH(handle
)) - 1));
170 static void intc_mode_zero(unsigned long addr
,
171 unsigned long handle
,
172 void (*fn
)(unsigned long,
180 static void intc_mode_prio(unsigned long addr
,
181 unsigned long handle
,
182 void (*fn
)(unsigned long,
187 fn(addr
, handle
, intc_prio_level
[irq
]);
190 static void (*intc_enable_fns
[])(unsigned long addr
,
191 unsigned long handle
,
192 void (*fn
)(unsigned long,
195 unsigned int irq
) = {
196 [MODE_ENABLE_REG
] = intc_mode_field
,
197 [MODE_MASK_REG
] = intc_mode_zero
,
198 [MODE_DUAL_REG
] = intc_mode_field
,
199 [MODE_PRIO_REG
] = intc_mode_prio
,
200 [MODE_PCLR_REG
] = intc_mode_prio
,
203 static void (*intc_disable_fns
[])(unsigned long addr
,
204 unsigned long handle
,
205 void (*fn
)(unsigned long,
208 unsigned int irq
) = {
209 [MODE_ENABLE_REG
] = intc_mode_zero
,
210 [MODE_MASK_REG
] = intc_mode_field
,
211 [MODE_DUAL_REG
] = intc_mode_field
,
212 [MODE_PRIO_REG
] = intc_mode_zero
,
213 [MODE_PCLR_REG
] = intc_mode_field
,
216 static inline void _intc_enable(unsigned int irq
, unsigned long handle
)
218 struct intc_desc_int
*d
= get_intc_desc(irq
);
222 for (cpu
= 0; cpu
< SMP_NR(d
, _INTC_ADDR_E(handle
)); cpu
++) {
223 addr
= INTC_REG(d
, _INTC_ADDR_E(handle
), cpu
);
224 intc_enable_fns
[_INTC_MODE(handle
)](addr
, handle
, intc_reg_fns\
225 [_INTC_FN(handle
)], irq
);
229 static void intc_enable(unsigned int irq
)
231 _intc_enable(irq
, (unsigned long)get_irq_chip_data(irq
));
234 static void intc_disable(unsigned int irq
)
236 struct intc_desc_int
*d
= get_intc_desc(irq
);
237 unsigned long handle
= (unsigned long) get_irq_chip_data(irq
);
241 for (cpu
= 0; cpu
< SMP_NR(d
, _INTC_ADDR_D(handle
)); cpu
++) {
242 addr
= INTC_REG(d
, _INTC_ADDR_D(handle
), cpu
);
243 intc_disable_fns
[_INTC_MODE(handle
)](addr
, handle
,intc_reg_fns\
244 [_INTC_FN(handle
)], irq
);
248 static int intc_set_wake(unsigned int irq
, unsigned int on
)
250 return 0; /* allow wakeup, but setup hardware in intc_suspend() */
253 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
254 static void intc_mask_ack(unsigned int irq
)
256 struct intc_desc_int
*d
= get_intc_desc(irq
);
257 unsigned long handle
= ack_handle
[irq
];
262 /* read register and write zero only to the assocaited bit */
265 addr
= INTC_REG(d
, _INTC_ADDR_D(handle
), 0);
266 switch (_INTC_FN(handle
)) {
267 case REG_FN_MODIFY_BASE
+ 0: /* 8bit */
269 __raw_writeb(0xff ^ set_field(0, 1, handle
), addr
);
271 case REG_FN_MODIFY_BASE
+ 1: /* 16bit */
273 __raw_writew(0xffff ^ set_field(0, 1, handle
), addr
);
275 case REG_FN_MODIFY_BASE
+ 3: /* 32bit */
277 __raw_writel(0xffffffff ^ set_field(0, 1, handle
), addr
);
287 static struct intc_handle_int
*intc_find_irq(struct intc_handle_int
*hp
,
293 /* this doesn't scale well, but...
295 * this function should only be used for cerain uncommon
296 * operations such as intc_set_priority() and intc_set_sense()
297 * and in those rare cases performance doesn't matter that much.
298 * keeping the memory footprint low is more important.
300 * one rather simple way to speed this up and still keep the
301 * memory footprint down is to make sure the array is sorted
302 * and then perform a bisect to lookup the irq.
305 for (i
= 0; i
< nr_hp
; i
++) {
306 if ((hp
+ i
)->irq
!= irq
)
315 int intc_set_priority(unsigned int irq
, unsigned int prio
)
317 struct intc_desc_int
*d
= get_intc_desc(irq
);
318 struct intc_handle_int
*ihp
;
320 if (!intc_prio_level
[irq
] || prio
<= 1)
323 ihp
= intc_find_irq(d
->prio
, d
->nr_prio
, irq
);
325 if (prio
>= (1 << _INTC_WIDTH(ihp
->handle
)))
328 intc_prio_level
[irq
] = prio
;
331 * only set secondary masking method directly
332 * primary masking method is using intc_prio_level[irq]
333 * priority level will be set during next enable()
336 if (_INTC_FN(ihp
->handle
) != REG_FN_ERR
)
337 _intc_enable(irq
, ihp
->handle
);
342 #define VALID(x) (x | 0x80)
344 static unsigned char intc_irq_sense_table
[IRQ_TYPE_SENSE_MASK
+ 1] = {
345 [IRQ_TYPE_EDGE_FALLING
] = VALID(0),
346 [IRQ_TYPE_EDGE_RISING
] = VALID(1),
347 [IRQ_TYPE_LEVEL_LOW
] = VALID(2),
348 /* SH7706, SH7707 and SH7709 do not support high level triggered */
349 #if !defined(CONFIG_CPU_SUBTYPE_SH7706) && \
350 !defined(CONFIG_CPU_SUBTYPE_SH7707) && \
351 !defined(CONFIG_CPU_SUBTYPE_SH7709)
352 [IRQ_TYPE_LEVEL_HIGH
] = VALID(3),
356 static int intc_set_sense(unsigned int irq
, unsigned int type
)
358 struct intc_desc_int
*d
= get_intc_desc(irq
);
359 unsigned char value
= intc_irq_sense_table
[type
& IRQ_TYPE_SENSE_MASK
];
360 struct intc_handle_int
*ihp
;
366 ihp
= intc_find_irq(d
->sense
, d
->nr_sense
, irq
);
368 addr
= INTC_REG(d
, _INTC_ADDR_E(ihp
->handle
), 0);
369 intc_reg_fns
[_INTC_FN(ihp
->handle
)](addr
, ihp
->handle
, value
);
374 static unsigned int __init
intc_get_reg(struct intc_desc_int
*d
,
375 unsigned long address
)
379 for (k
= 0; k
< d
->nr_reg
; k
++) {
380 if (d
->reg
[k
] == address
)
388 static intc_enum __init
intc_grp_id(struct intc_desc
*desc
,
391 struct intc_group
*g
= desc
->groups
;
394 for (i
= 0; g
&& enum_id
&& i
< desc
->nr_groups
; i
++) {
395 g
= desc
->groups
+ i
;
397 for (j
= 0; g
->enum_ids
[j
]; j
++) {
398 if (g
->enum_ids
[j
] != enum_id
)
408 static unsigned int __init
intc_mask_data(struct intc_desc
*desc
,
409 struct intc_desc_int
*d
,
410 intc_enum enum_id
, int do_grps
)
412 struct intc_mask_reg
*mr
= desc
->mask_regs
;
413 unsigned int i
, j
, fn
, mode
;
414 unsigned long reg_e
, reg_d
;
416 for (i
= 0; mr
&& enum_id
&& i
< desc
->nr_mask_regs
; i
++) {
417 mr
= desc
->mask_regs
+ i
;
419 for (j
= 0; j
< ARRAY_SIZE(mr
->enum_ids
); j
++) {
420 if (mr
->enum_ids
[j
] != enum_id
)
423 if (mr
->set_reg
&& mr
->clr_reg
) {
424 fn
= REG_FN_WRITE_BASE
;
425 mode
= MODE_DUAL_REG
;
429 fn
= REG_FN_MODIFY_BASE
;
431 mode
= MODE_ENABLE_REG
;
435 mode
= MODE_MASK_REG
;
441 fn
+= (mr
->reg_width
>> 3) - 1;
442 return _INTC_MK(fn
, mode
,
443 intc_get_reg(d
, reg_e
),
444 intc_get_reg(d
, reg_d
),
446 (mr
->reg_width
- 1) - j
);
451 return intc_mask_data(desc
, d
, intc_grp_id(desc
, enum_id
), 0);
456 static unsigned int __init
intc_prio_data(struct intc_desc
*desc
,
457 struct intc_desc_int
*d
,
458 intc_enum enum_id
, int do_grps
)
460 struct intc_prio_reg
*pr
= desc
->prio_regs
;
461 unsigned int i
, j
, fn
, mode
, bit
;
462 unsigned long reg_e
, reg_d
;
464 for (i
= 0; pr
&& enum_id
&& i
< desc
->nr_prio_regs
; i
++) {
465 pr
= desc
->prio_regs
+ i
;
467 for (j
= 0; j
< ARRAY_SIZE(pr
->enum_ids
); j
++) {
468 if (pr
->enum_ids
[j
] != enum_id
)
471 if (pr
->set_reg
&& pr
->clr_reg
) {
472 fn
= REG_FN_WRITE_BASE
;
473 mode
= MODE_PCLR_REG
;
477 fn
= REG_FN_MODIFY_BASE
;
478 mode
= MODE_PRIO_REG
;
485 fn
+= (pr
->reg_width
>> 3) - 1;
487 BUG_ON((j
+ 1) * pr
->field_width
> pr
->reg_width
);
489 bit
= pr
->reg_width
- ((j
+ 1) * pr
->field_width
);
491 return _INTC_MK(fn
, mode
,
492 intc_get_reg(d
, reg_e
),
493 intc_get_reg(d
, reg_d
),
494 pr
->field_width
, bit
);
499 return intc_prio_data(desc
, d
, intc_grp_id(desc
, enum_id
), 0);
504 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
505 static unsigned int __init
intc_ack_data(struct intc_desc
*desc
,
506 struct intc_desc_int
*d
,
509 struct intc_mask_reg
*mr
= desc
->ack_regs
;
510 unsigned int i
, j
, fn
, mode
;
511 unsigned long reg_e
, reg_d
;
513 for (i
= 0; mr
&& enum_id
&& i
< desc
->nr_ack_regs
; i
++) {
514 mr
= desc
->ack_regs
+ i
;
516 for (j
= 0; j
< ARRAY_SIZE(mr
->enum_ids
); j
++) {
517 if (mr
->enum_ids
[j
] != enum_id
)
520 fn
= REG_FN_MODIFY_BASE
;
521 mode
= MODE_ENABLE_REG
;
525 fn
+= (mr
->reg_width
>> 3) - 1;
526 return _INTC_MK(fn
, mode
,
527 intc_get_reg(d
, reg_e
),
528 intc_get_reg(d
, reg_d
),
530 (mr
->reg_width
- 1) - j
);
538 static unsigned int __init
intc_sense_data(struct intc_desc
*desc
,
539 struct intc_desc_int
*d
,
542 struct intc_sense_reg
*sr
= desc
->sense_regs
;
543 unsigned int i
, j
, fn
, bit
;
545 for (i
= 0; sr
&& enum_id
&& i
< desc
->nr_sense_regs
; i
++) {
546 sr
= desc
->sense_regs
+ i
;
548 for (j
= 0; j
< ARRAY_SIZE(sr
->enum_ids
); j
++) {
549 if (sr
->enum_ids
[j
] != enum_id
)
552 fn
= REG_FN_MODIFY_BASE
;
553 fn
+= (sr
->reg_width
>> 3) - 1;
555 BUG_ON((j
+ 1) * sr
->field_width
> sr
->reg_width
);
557 bit
= sr
->reg_width
- ((j
+ 1) * sr
->field_width
);
559 return _INTC_MK(fn
, 0, intc_get_reg(d
, sr
->reg
),
560 0, sr
->field_width
, bit
);
567 static void __init
intc_register_irq(struct intc_desc
*desc
,
568 struct intc_desc_int
*d
,
572 struct intc_handle_int
*hp
;
573 unsigned int data
[2], primary
;
575 /* Prefer single interrupt source bitmap over other combinations:
576 * 1. bitmap, single interrupt source
577 * 2. priority, single interrupt source
578 * 3. bitmap, multiple interrupt sources (groups)
579 * 4. priority, multiple interrupt sources (groups)
582 data
[0] = intc_mask_data(desc
, d
, enum_id
, 0);
583 data
[1] = intc_prio_data(desc
, d
, enum_id
, 0);
586 if (!data
[0] && data
[1])
589 if (!data
[0] && !data
[1])
590 pr_warning("intc: missing unique irq mask for "
591 "irq %d (vect 0x%04x)\n", irq
, irq2evt(irq
));
593 data
[0] = data
[0] ? data
[0] : intc_mask_data(desc
, d
, enum_id
, 1);
594 data
[1] = data
[1] ? data
[1] : intc_prio_data(desc
, d
, enum_id
, 1);
599 BUG_ON(!data
[primary
]); /* must have primary masking method */
601 disable_irq_nosync(irq
);
602 set_irq_chip_and_handler_name(irq
, &d
->chip
,
603 handle_level_irq
, "level");
604 set_irq_chip_data(irq
, (void *)data
[primary
]);
606 /* set priority level
607 * - this needs to be at least 2 for 5-bit priorities on 7780
609 intc_prio_level
[irq
] = 2;
611 /* enable secondary masking method if present */
613 _intc_enable(irq
, data
[!primary
]);
615 /* add irq to d->prio list if priority is available */
617 hp
= d
->prio
+ d
->nr_prio
;
619 hp
->handle
= data
[1];
623 * only secondary priority should access registers, so
624 * set _INTC_FN(h) = REG_FN_ERR for intc_set_priority()
627 hp
->handle
&= ~_INTC_MK(0x0f, 0, 0, 0, 0, 0);
628 hp
->handle
|= _INTC_MK(REG_FN_ERR
, 0, 0, 0, 0, 0);
633 /* add irq to d->sense list if sense is available */
634 data
[0] = intc_sense_data(desc
, d
, enum_id
);
636 (d
->sense
+ d
->nr_sense
)->irq
= irq
;
637 (d
->sense
+ d
->nr_sense
)->handle
= data
[0];
641 /* irq should be disabled by default */
644 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
646 ack_handle
[irq
] = intc_ack_data(desc
, d
, enum_id
);
650 static unsigned int __init
save_reg(struct intc_desc_int
*d
,
666 static void intc_redirect_irq(unsigned int irq
, struct irq_desc
*desc
)
668 generic_handle_irq((unsigned int)get_irq_data(irq
));
671 void __init
register_intc_controller(struct intc_desc
*desc
)
673 unsigned int i
, k
, smp
;
674 struct intc_desc_int
*d
;
676 d
= kzalloc(sizeof(*d
), GFP_NOWAIT
);
678 INIT_LIST_HEAD(&d
->list
);
679 list_add(&d
->list
, &intc_list
);
681 d
->nr_reg
= desc
->mask_regs
? desc
->nr_mask_regs
* 2 : 0;
682 d
->nr_reg
+= desc
->prio_regs
? desc
->nr_prio_regs
* 2 : 0;
683 d
->nr_reg
+= desc
->sense_regs
? desc
->nr_sense_regs
: 0;
685 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
686 d
->nr_reg
+= desc
->ack_regs
? desc
->nr_ack_regs
: 0;
688 d
->reg
= kzalloc(d
->nr_reg
* sizeof(*d
->reg
), GFP_NOWAIT
);
690 d
->smp
= kzalloc(d
->nr_reg
* sizeof(*d
->smp
), GFP_NOWAIT
);
694 if (desc
->mask_regs
) {
695 for (i
= 0; i
< desc
->nr_mask_regs
; i
++) {
696 smp
= IS_SMP(desc
->mask_regs
[i
]);
697 k
+= save_reg(d
, k
, desc
->mask_regs
[i
].set_reg
, smp
);
698 k
+= save_reg(d
, k
, desc
->mask_regs
[i
].clr_reg
, smp
);
702 if (desc
->prio_regs
) {
703 d
->prio
= kzalloc(desc
->nr_vectors
* sizeof(*d
->prio
), GFP_NOWAIT
);
705 for (i
= 0; i
< desc
->nr_prio_regs
; i
++) {
706 smp
= IS_SMP(desc
->prio_regs
[i
]);
707 k
+= save_reg(d
, k
, desc
->prio_regs
[i
].set_reg
, smp
);
708 k
+= save_reg(d
, k
, desc
->prio_regs
[i
].clr_reg
, smp
);
712 if (desc
->sense_regs
) {
713 d
->sense
= kzalloc(desc
->nr_vectors
* sizeof(*d
->sense
), GFP_NOWAIT
);
715 for (i
= 0; i
< desc
->nr_sense_regs
; i
++) {
716 k
+= save_reg(d
, k
, desc
->sense_regs
[i
].reg
, 0);
720 d
->chip
.name
= desc
->name
;
721 d
->chip
.mask
= intc_disable
;
722 d
->chip
.unmask
= intc_enable
;
723 d
->chip
.mask_ack
= intc_disable
;
724 d
->chip
.enable
= intc_enable
;
725 d
->chip
.disable
= intc_disable
;
726 d
->chip
.shutdown
= intc_disable
;
727 d
->chip
.set_type
= intc_set_sense
;
728 d
->chip
.set_wake
= intc_set_wake
;
730 #if defined(CONFIG_CPU_SH3) || defined(CONFIG_CPU_SH4A)
731 if (desc
->ack_regs
) {
732 for (i
= 0; i
< desc
->nr_ack_regs
; i
++)
733 k
+= save_reg(d
, k
, desc
->ack_regs
[i
].set_reg
, 0);
735 d
->chip
.mask_ack
= intc_mask_ack
;
739 BUG_ON(k
> 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
741 /* register the vectors one by one */
742 for (i
= 0; i
< desc
->nr_vectors
; i
++) {
743 struct intc_vect
*vect
= desc
->vectors
+ i
;
744 unsigned int irq
= evt2irq(vect
->vect
);
745 struct irq_desc
*irq_desc
;
750 irq_desc
= irq_to_desc_alloc_node(irq
, numa_node_id());
751 if (unlikely(!irq_desc
)) {
752 pr_info("can't get irq_desc for %d\n", irq
);
756 intc_register_irq(desc
, d
, vect
->enum_id
, irq
);
758 for (k
= i
+ 1; k
< desc
->nr_vectors
; k
++) {
759 struct intc_vect
*vect2
= desc
->vectors
+ k
;
760 unsigned int irq2
= evt2irq(vect2
->vect
);
762 if (vect
->enum_id
!= vect2
->enum_id
)
766 * In the case of multi-evt handling and sparse
767 * IRQ support, each vector still needs to have
768 * its own backing irq_desc.
770 irq_desc
= irq_to_desc_alloc_node(irq2
, numa_node_id());
771 if (unlikely(!irq_desc
)) {
772 pr_info("can't get irq_desc for %d\n", irq2
);
778 /* redirect this interrupts to the first one */
779 set_irq_chip_and_handler_name(irq2
, &d
->chip
,
780 intc_redirect_irq
, "redirect");
781 set_irq_data(irq2
, (void *)irq
);
786 static int intc_suspend(struct sys_device
*dev
, pm_message_t state
)
788 struct intc_desc_int
*d
;
789 struct irq_desc
*desc
;
792 /* get intc controller associated with this sysdev */
793 d
= container_of(dev
, struct intc_desc_int
, sysdev
);
795 switch (state
.event
) {
797 if (d
->state
.event
!= PM_EVENT_FREEZE
)
799 for_each_irq_desc(irq
, desc
) {
800 if (desc
->chip
!= &d
->chip
)
802 if (desc
->status
& IRQ_DISABLED
)
808 case PM_EVENT_FREEZE
:
809 /* nothing has to be done */
811 case PM_EVENT_SUSPEND
:
812 /* enable wakeup irqs belonging to this intc controller */
813 for_each_irq_desc(irq
, desc
) {
814 if ((desc
->status
& IRQ_WAKEUP
) && (desc
->chip
== &d
->chip
))
824 static int intc_resume(struct sys_device
*dev
)
826 return intc_suspend(dev
, PMSG_ON
);
829 static struct sysdev_class intc_sysdev_class
= {
831 .suspend
= intc_suspend
,
832 .resume
= intc_resume
,
835 /* register this intc as sysdev to allow suspend/resume */
836 static int __init
register_intc_sysdevs(void)
838 struct intc_desc_int
*d
;
842 error
= sysdev_class_register(&intc_sysdev_class
);
844 list_for_each_entry(d
, &intc_list
, list
) {
846 d
->sysdev
.cls
= &intc_sysdev_class
;
847 error
= sysdev_register(&d
->sysdev
);
855 pr_warning("intc: sysdev registration error\n");
860 device_initcall(register_intc_sysdevs
);