This commit was manufactured by cvs2svn to create tag
[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 <source@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/ocp.h>
47 #include <asm/mv64x60.h>
48
49
50 /* ========================== forward declaration ========================== */
51
52 static void gt64260_unmask_irq(unsigned int);
53 static void gt64260_mask_irq(unsigned int);
54
55 /* ========================== local declarations =========================== */
56
57 struct hw_interrupt_type gt64260_pic = {
58         " GT64260_PIC ",                /* typename */
59         NULL,                           /* startup */
60         NULL,                           /* shutdown */
61         gt64260_unmask_irq,             /* enable */
62         gt64260_mask_irq,               /* disable */
63         gt64260_mask_irq,               /* ack */
64         NULL,                           /* end */
65         NULL                            /* set_affinity */
66 };
67
68 u32 gt64260_irq_base = 0;      /* GT64260 handles the next 96 IRQs from here */
69
70 static mv64x60_handle_t base_bh;
71 static mv64x60_handle_t ic_bh;
72
73 /* gt64260_init_irq()
74  *
75  *  This function initializes the interrupt controller. It assigns
76  *  all interrupts from IRQ0 to IRQ95 to the gt64260 interrupt controller.
77  *
78  * Input Variable(s):
79  *  None.
80  *
81  * Outpu. Variable(s):
82  *  None.
83  *
84  * Returns:
85  *  void
86  *
87  * Note:
88  *  We register all GPP inputs as interrupt source, but disable them.
89  */
90
91 __init void
92 gt64260_init_irq(void)
93 {
94         struct ocp_def  *def;
95         int i;
96
97 /* XXXX extract reg base, irq base from ocp */
98 /* XXXX rewrite read/write macros to not use 'bh'?? */
99 /* XXXX Have to use ocp b/c can pass arg to this routine */
100
101         if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: enter", 0x0);
102
103         if ((def = ocp_get_one_device(OCP_VENDOR_MARVELL, OCP_FUNC_HB,
104                                         OCP_ANY_INDEX)) == NULL) {
105                 /* XXXX SCREAM */
106                 return;
107         }
108         base_bh.v_base = (u32)ioremap(def->paddr, 0x10000); /* XXXX */
109
110         if ((def = ocp_get_one_device(OCP_VENDOR_MARVELL, OCP_FUNC_PIC,
111                                         OCP_ANY_INDEX)) == NULL) {
112                 /* XXXX SCREAM */
113                 return;
114         }
115         ic_bh.v_base = (u32)ioremap(def->paddr, 0x1000); /* XXXX */
116
117         ppc_cached_irq_mask[0] = 0;
118         ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
119         ppc_cached_irq_mask[2] = 0;
120
121         /* disable all interrupts and clear current interrupts */
122         mv64x60_write(&base_bh, MV64x60_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
123         mv64x60_write(&base_bh, MV64x60_GPP_INTR_CAUSE,0);
124         mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_LO, ppc_cached_irq_mask[0]);
125         mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_HI, ppc_cached_irq_mask[1]);
126
127         /* use the gt64260 for all (possible) interrupt sources */
128         for( i = gt64260_irq_base;  i < (gt64260_irq_base + 96);  i++ )  {
129                 irq_desc[i].handler = &gt64260_pic;
130         }
131
132         if ( ppc_md.progress ) ppc_md.progress("gt64260_init_irq: exit", 0x0);
133 }
134
135
136 /*
137  * gt64260_get_irq()
138  *
139  *  This function returns the lowest interrupt number of all interrupts that
140  *  are currently asserted.
141  *
142  * Input Variable(s):
143  *  struct pt_regs*     not used
144  *
145  * Output Variable(s):
146  *  None.
147  *
148  * Returns:
149  *  int <interrupt number> or -2 (bogus interrupt)
150  *
151  */
152 int
153 gt64260_get_irq(struct pt_regs *regs)
154 {
155         int irq;
156         int irq_gpp;
157
158         irq = mv64x60_read(&ic_bh, GT64260_IC_MAIN_CAUSE_LO);
159         irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
160
161         if (irq == -1) {
162                 irq = mv64x60_read(&ic_bh, GT64260_IC_MAIN_CAUSE_HI);
163                 irq = __ilog2((irq & 0x0f000db7) & ppc_cached_irq_mask[1]);
164
165                 if (irq == -1) {
166                         irq = -2;   /* bogus interrupt, should never happen */
167                 } else {
168                         if (irq >= 24) {
169                                 irq_gpp = mv64x60_read(&base_bh, MV64x60_GPP_INTR_CAUSE);
170                                 irq_gpp = __ilog2(irq_gpp &
171                                                   ppc_cached_irq_mask[2]);
172
173                                 if (irq_gpp == -1) {
174                                         irq = -2;
175                                 } else {
176                                         irq = irq_gpp + 64;
177                                         mv64x60_write(&base_bh, MV64x60_GPP_INTR_CAUSE, ~(1<<(irq-64)));
178                                 }
179                         } else {
180                                 irq += 32;
181                         }
182                 }
183         }
184
185         if( irq < 0 )  {
186                 return( irq );
187         } else  {
188                 return( gt64260_irq_base + irq );
189         }
190 }
191
192 /* gt64260_unmask_irq()
193  *
194  *  This function enables an interrupt.
195  *
196  * Input Variable(s):
197  *  unsigned int        interrupt number (IRQ0...IRQ95).
198  *
199  * Output Variable(s):
200  *  None.
201  *
202  * Returns:
203  *  void
204  */
205
206 static void
207 gt64260_unmask_irq(unsigned int irq)
208 {
209         /* XXXX
210         printk("XXXX: *** unmask irq: %d\n", irq);
211         */
212         irq -= gt64260_irq_base;
213         if (irq > 31) {
214                 if (irq > 63) {
215                         /* unmask GPP irq */
216                         mv64x60_write(&base_bh, MV64x60_GPP_INTR_MASK,
217                                      ppc_cached_irq_mask[2] |= (1<<(irq-64)));
218                 } else {
219                         /* mask high interrupt register */
220                         mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_HI,
221                                      ppc_cached_irq_mask[1] |= (1<<(irq-32)));
222                 }
223         } else {
224                 /* mask low interrupt register */
225                 mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_LO,
226                              ppc_cached_irq_mask[0] |= (1<<irq));
227         }
228 }
229
230
231 /* gt64260_mask_irq()
232  *
233  *  This funktion disables the requested interrupt.
234  *
235  * Input Variable(s):
236  *  unsigned int        interrupt number (IRQ0...IRQ95).
237  *
238  * Output Variable(s):
239  *  None.
240  *
241  * Returns:
242  *  void
243  */
244
245 static void
246 gt64260_mask_irq(unsigned int irq)
247 {
248         /* XXXX
249         printk("XXXX: *** mask irq: %d\n", irq);
250         */
251         irq -= gt64260_irq_base;
252         if (irq > 31) {
253                 if (irq > 63) {
254                         /* mask GPP irq */
255                         mv64x60_write(&base_bh, MV64x60_GPP_INTR_MASK,
256                                      ppc_cached_irq_mask[2] &= ~(1<<(irq-64)));
257                 } else {
258                         /* mask high interrupt register */
259                         mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_HI,
260                                      ppc_cached_irq_mask[1] &= ~(1<<(irq-32)));
261                 }
262         } else {
263                 /* mask low interrupt register */
264                 mv64x60_write(&ic_bh, GT64260_IC_CPU_INTR_MASK_LO,
265                              ppc_cached_irq_mask[0] &= ~(1<<irq));
266         }
267
268         if (irq == 36) { /* Seems necessary for SDMA interrupts */
269                 udelay(1);
270         }
271 }