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>
28 #include <asm/machdep.h>
30 /* See comment in include/arch-ppc/ppc4xx_pic.h
31 * for more info about these two variables
33 extern struct ppc4xx_uic_settings ppc4xx_core_uic_cfg[NR_UICS]
34 __attribute__ ((weak));
35 extern unsigned char ppc4xx_uic_ext_irq_cfg[] __attribute__ ((weak));
37 #define IRQ_MASK_UIC0(irq) (1 << (31 - (irq)))
38 #define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
39 #define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
40 #define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
41 #define IRQ_MASK_UIC3(irq) IRQ_MASK_UICx(irq)
43 #define UIC_HANDLERS(n) \
44 static void ppc4xx_uic##n##_enable(unsigned int irq) \
46 u32 mask = IRQ_MASK_UIC##n(irq); \
47 if (irq_desc[irq].status & IRQ_LEVEL) \
48 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
49 ppc_cached_irq_mask[n] |= mask; \
50 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
53 static void ppc4xx_uic##n##_disable(unsigned int irq) \
55 ppc_cached_irq_mask[n] &= ~IRQ_MASK_UIC##n(irq); \
56 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
60 static void ppc4xx_uic##n##_ack(unsigned int irq) \
62 u32 mask = IRQ_MASK_UIC##n(irq); \
63 ppc_cached_irq_mask[n] &= ~mask; \
64 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
65 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
69 static void ppc4xx_uic##n##_end(unsigned int irq) \
71 unsigned int status = irq_desc[irq].status; \
72 u32 mask = IRQ_MASK_UIC##n(irq); \
73 if (status & IRQ_LEVEL) { \
74 mtdcr(DCRN_UIC_SR(UIC##n), mask); \
77 if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { \
78 ppc_cached_irq_mask[n] |= mask; \
79 mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
83 #define DECLARE_UIC(n) \
85 .typename = "UIC"#n, \
86 .enable = ppc4xx_uic##n##_enable, \
87 .disable = ppc4xx_uic##n##_disable, \
88 .ack = ppc4xx_uic##n##_ack, \
89 .end = ppc4xx_uic##n##_end, \
93 #define ACK_UIC0_PARENT
94 #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
95 #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC2NC);
96 #define ACK_UIC3_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC3NC);
102 static int ppc4xx_pic_get_irq(struct pt_regs *regs)
104 u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
105 if (uic0 & UIC0_UIC1NC)
106 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
107 else if (uic0 & UIC0_UIC2NC)
108 return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
109 else if (uic0 & UIC0_UIC3NC)
110 return 128 - ffs(mfdcr(DCRN_UIC_MSR(UIC3)));
112 return uic0 ? 32 - ffs(uic0) : -1;
115 static void __init ppc4xx_pic_impl_init(void)
117 /* Enable cascade interrupts in UIC0 */
118 ppc_cached_irq_mask[0] |= UIC0_UIC1NC | UIC0_UIC2NC | UIC0_UIC3NC;
119 mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC | UIC0_UIC2NC | UIC0_UIC3NC);
120 mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
124 #define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
125 #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
126 #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
131 static int ppc4xx_pic_get_irq(struct pt_regs *regs)
133 u32 uicb = mfdcr(DCRN_UIC_MSR(UICB));
134 if (uicb & UICB_UIC0NC)
135 return 32 - ffs(mfdcr(DCRN_UIC_MSR(UIC0)));
136 else if (uicb & UICB_UIC1NC)
137 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
138 else if (uicb & UICB_UIC2NC)
139 return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
144 static void __init ppc4xx_pic_impl_init(void)
146 #if defined(CONFIG_440GX)
147 /* Disable 440GP compatibility mode if it was enabled in firmware */
148 SDR_WRITE(DCRN_SDR_MFR, SDR_READ(DCRN_SDR_MFR) & ~DCRN_SDR_MFR_PCM);
150 /* Configure Base UIC */
151 mtdcr(DCRN_UIC_CR(UICB), 0);
152 mtdcr(DCRN_UIC_TR(UICB), 0);
153 mtdcr(DCRN_UIC_PR(UICB), 0xffffffff);
154 mtdcr(DCRN_UIC_SR(UICB), 0xffffffff);
155 mtdcr(DCRN_UIC_ER(UICB), UICB_UIC0NC | UICB_UIC1NC | UICB_UIC2NC);
159 #define ACK_UIC0_PARENT
160 #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
164 static int ppc4xx_pic_get_irq(struct pt_regs *regs)
166 u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
167 if (uic0 & UIC0_UIC1NC)
168 return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
170 return uic0 ? 32 - ffs(uic0) : -1;
173 static void __init ppc4xx_pic_impl_init(void)
175 /* Enable cascade interrupt in UIC0 */
176 ppc_cached_irq_mask[0] |= UIC0_UIC1NC;
177 mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
178 mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
182 #define ACK_UIC0_PARENT
185 static int ppc4xx_pic_get_irq(struct pt_regs *regs)
187 u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
188 return uic0 ? 32 - ffs(uic0) : -1;
191 static inline void ppc4xx_pic_impl_init(void)
196 static struct ppc4xx_uic_impl {
197 struct hw_interrupt_type decl;
198 int base; /* Base DCR number */
200 { .decl = DECLARE_UIC(0), .base = UIC0 },
202 { .decl = DECLARE_UIC(1), .base = UIC1 },
204 { .decl = DECLARE_UIC(2), .base = UIC2 },
206 { .decl = DECLARE_UIC(3), .base = UIC3 },
212 static inline int is_level_sensitive(int irq)
214 u32 tr = mfdcr(DCRN_UIC_TR(__uic[irq >> 5].base));
215 return (tr & IRQ_MASK_UICx(irq)) == 0;
218 void __init ppc4xx_pic_init(void)
221 unsigned char *eirqs = ppc4xx_uic_ext_irq_cfg;
223 for (i = 0; i < NR_UICS; ++i) {
224 int base = __uic[i].base;
226 /* Disable everything by default */
227 ppc_cached_irq_mask[i] = 0;
228 mtdcr(DCRN_UIC_ER(base), 0);
230 /* We don't use critical interrupts */
231 mtdcr(DCRN_UIC_CR(base), 0);
233 /* Configure polarity and triggering */
234 if (ppc4xx_core_uic_cfg) {
235 struct ppc4xx_uic_settings *p = ppc4xx_core_uic_cfg + i;
236 u32 mask = p->ext_irq_mask;
237 u32 pr = mfdcr(DCRN_UIC_PR(base)) & mask;
238 u32 tr = mfdcr(DCRN_UIC_TR(base)) & mask;
240 /* "Fixed" interrupts (on-chip devices) */
241 pr |= p->polarity & ~mask;
242 tr |= p->triggering & ~mask;
244 /* Merge external IRQs settings if board port
251 /* Extract current external IRQ mask */
252 u32 eirq_mask = 1 << __ilog2(mask);
254 if (!(*eirqs & IRQ_SENSE_LEVEL))
257 if (*eirqs & IRQ_POLARITY_POSITIVE)
264 mtdcr(DCRN_UIC_PR(base), pr);
265 mtdcr(DCRN_UIC_TR(base), tr);
268 /* ACK any pending interrupts to prevent false
269 * triggering after first enable
271 mtdcr(DCRN_UIC_SR(base), 0xffffffff);
274 /* Perform optional implementation specific setup
275 * (e.g. enable cascade interrupts for multi-UIC configurations)
277 ppc4xx_pic_impl_init();
279 /* Attach low-level handlers */
280 for (i = 0; i < (NR_UICS << 5); ++i) {
281 irq_desc[i].handler = &__uic[i >> 5].decl;
282 if (is_level_sensitive(i))
283 irq_desc[i].status |= IRQ_LEVEL;
286 ppc_md.get_irq = ppc4xx_pic_get_irq;