2 * arch/ppc/syslib/ppc4xx_pic.c
4 * Interrupt controller driver for PowerPC 4xx-based processors.
6 * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
7 * Copyright (c) 2004, 2005 Zultys Technologies
9 * Based on original code by
10 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
11 * Armin Custer <akuster@mvista.com>
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
18 #include <linux/config.h>
19 #include <linux/init.h>
20 #include <linux/sched.h>
21 #include <linux/signal.h>
22 #include <linux/stddef.h>
24 #include <asm/processor.h>
25 #include <asm/system.h>
27 #include <asm/ppc4xx_pic.h>
29 /* See comment in include/arch-ppc/ppc4xx_pic.h
30 * for more info about these two variables
32 extern struct ppc4xx_uic_settings ppc4xx_core_uic_cfg
[NR_UICS
]
33 __attribute__ ((weak
));
34 extern unsigned char ppc4xx_uic_ext_irq_cfg
[] __attribute__ ((weak
));
36 #define IRQ_MASK_UIC0(irq) (1 << (31 - (irq)))
37 #define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
38 #define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
39 #define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
41 #define UIC_HANDLERS(n) \
42 static void ppc4xx_uic##n##_enable(unsigned int irq) \
44 u32 mask = IRQ_MASK_UIC##n(irq); \
45 if (irq_desc[irq].status & IRQ_LEVEL) \
46 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
47 ppc_cached_irq_mask[n] |= mask; \
48 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
51 static void ppc4xx_uic##n##_disable(unsigned int irq) \
53 ppc_cached_irq_mask[n] &= ~IRQ_MASK_UIC##n(irq); \
54 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
58 static void ppc4xx_uic##n##_ack(unsigned int irq) \
60 u32 mask = IRQ_MASK_UIC##n(irq); \
61 ppc_cached_irq_mask[n] &= ~mask; \
62 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
63 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
67 static void ppc4xx_uic##n##_end(unsigned int irq) \
69 unsigned int status = irq_desc[irq].status; \
70 u32 mask = IRQ_MASK_UIC##n(irq); \
71 if (status & IRQ_LEVEL) { \
72 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
75 if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { \
76 ppc_cached_irq_mask[n] |= mask; \
77 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
81 #define DECLARE_UIC(n) \
83 .typename = "UIC"#n, \
84 .enable = ppc4xx_uic##n##_enable, \
85 .disable = ppc4xx_uic##n##_disable, \
86 .ack = ppc4xx_uic##n##_ack, \
87 .end = ppc4xx_uic##n##_end, \
91 #define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
92 #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
93 #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
98 static int ppc4xx_pic_get_irq(struct pt_regs
*regs
)
100 u32 uicb
= mfdcr(DCRN_UIC_MSR(UICB
));
101 if (uicb
& UICB_UIC0NC
)
102 return 32 - ffs(mfdcr(DCRN_UIC_MSR(UIC0
)));
103 else if (uicb
& UICB_UIC1NC
)
104 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1
)));
105 else if (uicb
& UICB_UIC2NC
)
106 return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2
)));
111 static void __init
ppc4xx_pic_impl_init(void)
113 /* Configure Base UIC */
114 mtdcr(DCRN_UIC_CR(UICB
), 0);
115 mtdcr(DCRN_UIC_TR(UICB
), 0);
116 mtdcr(DCRN_UIC_PR(UICB
), 0xffffffff);
117 mtdcr(DCRN_UIC_SR(UICB
), 0xffffffff);
118 mtdcr(DCRN_UIC_ER(UICB
), UICB_UIC0NC
| UICB_UIC1NC
| UICB_UIC2NC
);
122 #define ACK_UIC0_PARENT
123 #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
127 static int ppc4xx_pic_get_irq(struct pt_regs
*regs
)
129 u32 uic0
= mfdcr(DCRN_UIC_MSR(UIC0
));
130 if (uic0
& UIC0_UIC1NC
)
131 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1
)));
133 return uic0
? 32 - ffs(uic0
) : -1;
136 static void __init
ppc4xx_pic_impl_init(void)
138 /* Enable cascade interrupt in UIC0 */
139 ppc_cached_irq_mask
[0] |= UIC0_UIC1NC
;
140 mtdcr(DCRN_UIC_SR(UIC0
), UIC0_UIC1NC
);
141 mtdcr(DCRN_UIC_ER(UIC0
), ppc_cached_irq_mask
[0]);
145 #define ACK_UIC0_PARENT
148 static int ppc4xx_pic_get_irq(struct pt_regs
*regs
)
150 u32 uic0
= mfdcr(DCRN_UIC_MSR(UIC0
));
151 return uic0
? 32 - ffs(uic0
) : -1;
154 static inline void ppc4xx_pic_impl_init(void)
159 static struct ppc4xx_uic_impl
{
160 struct hw_interrupt_type decl
;
161 int base
; /* Base DCR number */
163 { .decl
= DECLARE_UIC(0), .base
= UIC0
},
165 { .decl
= DECLARE_UIC(1), .base
= UIC1
},
167 { .decl
= DECLARE_UIC(2), .base
= UIC2
},
172 static inline int is_level_sensitive(int irq
)
174 u32 tr
= mfdcr(DCRN_UIC_TR(__uic
[irq
>> 5].base
));
175 return (tr
& IRQ_MASK_UICx(irq
)) == 0;
178 void __init
ppc4xx_pic_init(void)
181 unsigned char *eirqs
= ppc4xx_uic_ext_irq_cfg
;
183 for (i
= 0; i
< NR_UICS
; ++i
) {
184 int base
= __uic
[i
].base
;
186 /* Disable everything by default */
187 ppc_cached_irq_mask
[i
] = 0;
188 mtdcr(DCRN_UIC_ER(base
), 0);
190 /* We don't use critical interrupts */
191 mtdcr(DCRN_UIC_CR(base
), 0);
193 /* Configure polarity and triggering */
194 if (ppc4xx_core_uic_cfg
) {
195 struct ppc4xx_uic_settings
*p
= ppc4xx_core_uic_cfg
+ i
;
196 u32 mask
= p
->ext_irq_mask
;
197 u32 pr
= mfdcr(DCRN_UIC_PR(base
)) & mask
;
198 u32 tr
= mfdcr(DCRN_UIC_TR(base
)) & mask
;
200 /* "Fixed" interrupts (on-chip devices) */
201 pr
|= p
->polarity
& ~mask
;
202 tr
|= p
->triggering
& ~mask
;
204 /* Merge external IRQs settings if board port
211 /* Extract current external IRQ mask */
212 u32 eirq_mask
= 1 << __ilog2(mask
);
214 if (!(*eirqs
& IRQ_SENSE_LEVEL
))
217 if (*eirqs
& IRQ_POLARITY_POSITIVE
)
224 mtdcr(DCRN_UIC_PR(base
), pr
);
225 mtdcr(DCRN_UIC_TR(base
), tr
);
228 /* ACK any pending interrupts to prevent false
229 * triggering after first enable
231 mtdcr(DCRN_UIC_SR(base
), 0xffffffff);
234 /* Perform optional implementation specific setup
235 * (e.g. enable cascade interrupts for multi-UIC configurations)
237 ppc4xx_pic_impl_init();
239 /* Attach low-level handlers */
240 for (i
= 0; i
< (NR_UICS
<< 5); ++i
) {
241 irq_desc
[i
].handler
= &__uic
[i
>> 5].decl
;
242 if (is_level_sensitive(i
))
243 irq_desc
[i
].status
|= IRQ_LEVEL
;
246 ppc_md
.get_irq
= ppc4xx_pic_get_irq
;