ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ppc / syslib / gt64260_pic.c
1 /*
2  * arch/ppc/syslib/gt64260_pic.c
3  *
4  * Interrupt controller support for Galileo's GT64260.
5  *
6  * Author: Chris Zankel <chris@mvista.com>
7  * Modified by: Mark A. Greer <mgreer@mvista.com>
8  *
9  * Based on sources from Rabeeh Khoury / Galileo Technology
10  *
11  * 2001 (c) MontaVista, Software, Inc.  This file is licensed under
12  * the terms of the GNU General Public License version 2.  This program
13  * is licensed "as is" without any warranty of any kind, whether express
14  * or implied.
15  */
16
17 /*
18  * This file contains the specific functions to support the GT64260
19  * interrupt controller.
20  *
21  * The GT64260 has two main interrupt registers (high and low) that
22  * summarizes the interrupts generated by the units of the GT64260.
23  * Each bit is assigned to an interrupt number, where the low register
24  * are assigned from IRQ0 to IRQ31 and the high cause register
25  * from IRQ32 to IRQ63
26  * The GPP (General Purpose Port) interrupts are assigned from IRQ64 (GPP0)
27  * to IRQ95 (GPP31).
28  * get_irq() returns the lowest interrupt number that is currently asserted.
29  *
30  * Note:
31  *  - This driver does not initialize the GPP when used as an interrupt
32  *    input.
33  */
34
35 #include <linux/stddef.h>
36 #include <linux/init.h>
37 #include <linux/sched.h>
38 #include <linux/signal.h>
39 #include <linux/stddef.h>
40 #include <linux/delay.h>
41 #include <linux/irq.h>
42
43 #include <asm/io.h>
44 #include <asm/system.h>
45 #include <asm/irq.h>
46 #include <asm/gt64260.h>
47
48
49 /* ========================== forward declaration ========================== */
50
51 static void gt64260_unmask_irq(unsigned int);
52 static void gt64260_mask_irq(unsigned int);
53
54 /* ========================== local declarations =========================== */
55
56 struct hw_interrupt_type gt64260_pic = {
57         " GT64260_PIC ",                /* typename */
58         NULL,                           /* startup */
59         NULL,                           /* shutdown */
60         gt64260_unmask_irq,             /* enable */
61         gt64260_mask_irq,               /* disable */
62         gt64260_mask_irq,               /* ack */
63         NULL,                           /* end */
64         NULL                            /* set_affinity */
65 };
66
67 u32 gt64260_irq_base = 0;      /* GT64260 handles the next 96 IRQs from here */
68
69 /* gt64260_init_irq()
70  *
71  *  This function initializes the interrupt controller. It assigns
72  *  all interrupts from IRQ0 to IRQ95 to the gt64260 interrupt controller.
73  *
74  * Input Variable(s):
75  *  None.
76  *
77  * Outpu. Variable(s):
78  *  None.
79  *
80  * Returns:
81  *  void
82  *
83  * Note:
84  *  We register all GPP inputs as interrupt source, but disable them.
85  */
86
87 __init void
88 gt64260_init_irq(void)
89 {
90         int i;
91
92         if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: enter", 0x0);
93
94         ppc_cached_irq_mask[0] = 0;
95         ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
96         ppc_cached_irq_mask[2] = 0;
97
98         /* disable all interrupts and clear current interrupts */
99         gt_write(GT64260_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
100         gt_write(GT64260_GPP_INTR_CAUSE,0);
101         gt_write(GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
102         gt_write(GT64260_IC_CPU_INTR_MASK_HI, ppc_cached_irq_mask[1]);
103
104         /* use the gt64260 for all (possible) interrupt sources */
105         for( i = gt64260_irq_base;  i < (gt64260_irq_base + 96);  i++ )  {
106                 irq_desc[i].handler = &gt64260_pic;
107         }
108
109         if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: exit", 0x0);
110 }
111
112
113 /* gt64260_get_irq()
114  *
115  *  This function returns the lowest interrupt number of all interrupts that
116  *  are currently asserted.
117  *
118  * Input Variable(s):
119  *  struct pt_regs*     not used
120  *
121  * Output Variable(s):
122  *  None.
123  *
124  * Returns:
125  *  int <interrupt number> or -2 (bogus interrupt)
126  *
127  */
128 int
129 gt64260_get_irq(struct pt_regs *regs)
130 {
131         int irq;
132         int irq_gpp;
133
134         irq = gt_read(GT64260_IC_MAIN_CAUSE_LO);
135         irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
136
137         if (irq == -1) {
138                 irq = gt_read(GT64260_IC_MAIN_CAUSE_HI);
139                 irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
140
141                 if (irq == -1) {
142                         irq = -2;   /* bogus interrupt, should never happen */
143                 } else {
144                         if (irq >= 24) {
145                                 irq_gpp = gt_read(GT64260_GPP_INTR_CAUSE);
146                                 irq_gpp = __ilog2(irq_gpp &
147                                                   ppc_cached_irq_mask[2]);
148
149                                 if (irq_gpp == -1) {
150                                         irq = -2;
151                                 } else {
152                                         irq = irq_gpp + 64;
153                                         gt_write(GT64260_GPP_INTR_CAUSE, ~(1<<(irq-64)));
154                                 }
155                         } else {
156                                 irq += 32;
157                         }
158                 }
159         }
160
161         if( irq < 0 )  {
162                 return( irq );
163         } else  {
164                 return( gt64260_irq_base + irq );
165         }
166 }
167
168 /* gt64260_unmask_irq()
169  *
170  *  This function enables an interrupt.
171  *
172  * Input Variable(s):
173  *  unsigned int        interrupt number (IRQ0...IRQ95).
174  *
175  * Output Variable(s):
176  *  None.
177  *
178  * Returns:
179  *  void
180  */
181
182 static void
183 gt64260_unmask_irq(unsigned int irq)
184 {
185         irq -= gt64260_irq_base;
186         if (irq > 31) {
187                 if (irq > 63) {
188                         /* unmask GPP irq */
189                         gt_write(GT64260_GPP_INTR_MASK,
190                                      ppc_cached_irq_mask[2] |= (1<<(irq-64)));
191                 } else {
192                         /* mask high interrupt register */
193                         gt_write(GT64260_IC_CPU_INTR_MASK_HI,
194                                      ppc_cached_irq_mask[1] |= (1<<(irq-32)));
195                 }
196         } else {
197                 /* mask low interrupt register */
198                 gt_write(GT64260_IC_CPU_INTR_MASK_LO,
199                              ppc_cached_irq_mask[0] |= (1<<irq));
200         }
201 }
202
203
204 /* gt64260_mask_irq()
205  *
206  *  This funktion disables the requested interrupt.
207  *
208  * Input Variable(s):
209  *  unsigned int        interrupt number (IRQ0...IRQ95).
210  *
211  * Output Variable(s):
212  *  None.
213  *
214  * Returns:
215  *  void
216  */
217
218 static void
219 gt64260_mask_irq(unsigned int irq)
220 {
221         irq -= gt64260_irq_base;
222         if (irq > 31) {
223                 if (irq > 63) {
224                         /* mask GPP irq */
225                         gt_write(GT64260_GPP_INTR_MASK,
226                                      ppc_cached_irq_mask[2] &= ~(1<<(irq-64)));
227                 } else {
228                         /* mask high interrupt register */
229                         gt_write(GT64260_IC_CPU_INTR_MASK_HI,
230                                      ppc_cached_irq_mask[1] &= ~(1<<(irq-32)));
231                 }
232         } else {
233                 /* mask low interrupt register */
234                 gt_write(GT64260_IC_CPU_INTR_MASK_LO,
235                              ppc_cached_irq_mask[0] &= ~(1<<irq));
236         }
237
238         if (irq == 36) { /* Seems necessary for SDMA interrupts */
239                 udelay(1);
240         }
241 }