]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/ppc/syslib/xilinx_pic.c
Linux-2.6.12-rc2
[mirror_ubuntu-artful-kernel.git] / arch / ppc / syslib / xilinx_pic.c
1 /*
2 * arch/ppc/syslib/xilinx_pic.c
3 *
4 * Interrupt controller driver for Xilinx Virtex-II Pro.
5 *
6 * Author: MontaVista Software, Inc.
7 * source@mvista.com
8 *
9 * 2002-2004 (c) MontaVista Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
12 * or implied.
13 */
14
15 #include <linux/init.h>
16 #include <linux/irq.h>
17 #include <asm/io.h>
18 #include <asm/xparameters.h>
19 #include <asm/ibm4xx.h>
20
21 /* No one else should require these constants, so define them locally here. */
22 #define ISR 0 /* Interrupt Status Register */
23 #define IPR 1 /* Interrupt Pending Register */
24 #define IER 2 /* Interrupt Enable Register */
25 #define IAR 3 /* Interrupt Acknowledge Register */
26 #define SIE 4 /* Set Interrupt Enable bits */
27 #define CIE 5 /* Clear Interrupt Enable bits */
28 #define IVR 6 /* Interrupt Vector Register */
29 #define MER 7 /* Master Enable Register */
30
31 #if XPAR_XINTC_USE_DCR == 0
32 static volatile u32 *intc;
33 #define intc_out_be32(addr, mask) out_be32((addr), (mask))
34 #define intc_in_be32(addr) in_be32((addr))
35 #else
36 #define intc XPAR_INTC_0_BASEADDR
37 #define intc_out_be32(addr, mask) mtdcr((addr), (mask))
38 #define intc_in_be32(addr) mfdcr((addr))
39 #endif
40
41 static void
42 xilinx_intc_enable(unsigned int irq)
43 {
44 unsigned long mask = (0x00000001 << (irq & 31));
45 pr_debug("enable: %d\n", irq);
46 intc_out_be32(intc + SIE, mask);
47 }
48
49 static void
50 xilinx_intc_disable(unsigned int irq)
51 {
52 unsigned long mask = (0x00000001 << (irq & 31));
53 pr_debug("disable: %d\n", irq);
54 intc_out_be32(intc + CIE, mask);
55 }
56
57 static void
58 xilinx_intc_disable_and_ack(unsigned int irq)
59 {
60 unsigned long mask = (0x00000001 << (irq & 31));
61 pr_debug("disable_and_ack: %d\n", irq);
62 intc_out_be32(intc + CIE, mask);
63 if (!(irq_desc[irq].status & IRQ_LEVEL))
64 intc_out_be32(intc + IAR, mask); /* ack edge triggered intr */
65 }
66
67 static void
68 xilinx_intc_end(unsigned int irq)
69 {
70 unsigned long mask = (0x00000001 << (irq & 31));
71
72 pr_debug("end: %d\n", irq);
73 if (!(irq_desc[irq].status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
74 intc_out_be32(intc + SIE, mask);
75 /* ack level sensitive intr */
76 if (irq_desc[irq].status & IRQ_LEVEL)
77 intc_out_be32(intc + IAR, mask);
78 }
79 }
80
81 static struct hw_interrupt_type xilinx_intc = {
82 "Xilinx Interrupt Controller",
83 NULL,
84 NULL,
85 xilinx_intc_enable,
86 xilinx_intc_disable,
87 xilinx_intc_disable_and_ack,
88 xilinx_intc_end,
89 0
90 };
91
92 int
93 xilinx_pic_get_irq(struct pt_regs *regs)
94 {
95 int irq;
96
97 /*
98 * NOTE: This function is the one that needs to be improved in
99 * order to handle multiple interrupt controllers. It currently
100 * is hardcoded to check for interrupts only on the first INTC.
101 */
102
103 irq = intc_in_be32(intc + IVR);
104 if (irq != -1)
105 irq = irq;
106
107 pr_debug("get_irq: %d\n", irq);
108
109 return (irq);
110 }
111
112 void __init
113 ppc4xx_pic_init(void)
114 {
115 int i;
116
117 /*
118 * NOTE: The assumption here is that NR_IRQS is 32 or less
119 * (NR_IRQS is 32 for PowerPC 405 cores by default).
120 */
121 #if (NR_IRQS > 32)
122 #error NR_IRQS > 32 not supported
123 #endif
124
125 #if XPAR_XINTC_USE_DCR == 0
126 intc = ioremap(XPAR_INTC_0_BASEADDR, 32);
127
128 printk(KERN_INFO "Xilinx INTC #0 at 0x%08lX mapped to 0x%08lX\n",
129 (unsigned long) XPAR_INTC_0_BASEADDR, (unsigned long) intc);
130 #else
131 printk(KERN_INFO "Xilinx INTC #0 at 0x%08lX (DCR)\n",
132 (unsigned long) XPAR_INTC_0_BASEADDR);
133 #endif
134
135 /*
136 * Disable all external interrupts until they are
137 * explicity requested.
138 */
139 intc_out_be32(intc + IER, 0);
140
141 /* Acknowledge any pending interrupts just in case. */
142 intc_out_be32(intc + IAR, ~(u32) 0);
143
144 /* Turn on the Master Enable. */
145 intc_out_be32(intc + MER, 0x3UL);
146
147 ppc_md.get_irq = xilinx_pic_get_irq;
148
149 for (i = 0; i < NR_IRQS; ++i) {
150 irq_desc[i].handler = &xilinx_intc;
151
152 if (XPAR_INTC_0_KIND_OF_INTR & (0x00000001 << i))
153 irq_desc[i].status &= ~IRQ_LEVEL;
154 else
155 irq_desc[i].status |= IRQ_LEVEL;
156 }
157 }