Merge master.kernel.org:/pub/scm/linux/kernel/git/perex/alsa
[pandora-kernel.git] / arch / m68knommu / platform / 68360 / ints.c
1 /*
2  * linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file COPYING in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (c) 2000  Michael Leslie <mleslie@lineo.com>
9  * Copyright (c) 1996 Roman Zippel
10  * Copyright (c) 1999 D. Jeff Dionne <jeff@uclinux.org>
11  */
12
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/kernel_stat.h>
19 #include <linux/errno.h>
20
21 #include <asm/system.h>
22 #include <asm/irq.h>
23 #include <asm/irqnode.h>
24 #include <asm/traps.h>
25 #include <asm/io.h>
26 #include <asm/machdep.h>
27 #include <asm/setup.h>
28 #include <asm/m68360.h>
29
30 /* from quicc/commproc.c: */
31 extern QUICC *pquicc;
32 extern void cpm_interrupt_init(void);
33
34 #define INTERNAL_IRQS (96)
35
36 /* assembler routines */
37 asmlinkage void system_call(void);
38 asmlinkage void buserr(void);
39 asmlinkage void trap(void);
40 asmlinkage irqreturn_t bad_interrupt(void);
41 asmlinkage irqreturn_t inthandler(void);
42
43 extern void *_ramvec[];
44
45 /* The number of spurious interrupts */
46 volatile unsigned int num_spurious;
47 unsigned int local_irq_count[NR_CPUS];
48
49 /* irq node variables for the 32 (potential) on chip sources */
50 static irq_node_t int_irq_list[INTERNAL_IRQS];
51
52 static short int_irq_ablecount[INTERNAL_IRQS];
53
54 /*
55  * This function should be called during kernel startup to initialize
56  * IRQ handling routines.
57  */
58
59 void init_IRQ(void)
60 {
61         int i;
62         int vba = (CPM_VECTOR_BASE<<4);
63
64         /* set up the vectors */
65         _ramvec[2] = buserr;
66         _ramvec[3] = trap;
67         _ramvec[4] = trap;
68         _ramvec[5] = trap;
69         _ramvec[6] = trap;
70         _ramvec[7] = trap;
71         _ramvec[8] = trap;
72         _ramvec[9] = trap;
73         _ramvec[10] = trap;
74         _ramvec[11] = trap;
75         _ramvec[12] = trap;
76         _ramvec[13] = trap;
77         _ramvec[14] = trap;
78         _ramvec[15] = trap;
79
80         _ramvec[32] = system_call;
81         _ramvec[33] = trap;
82
83
84         cpm_interrupt_init();
85
86         /* set up CICR for vector base address and irq level */
87         /* irl = 4, hp = 1f - see MC68360UM p 7-377 */
88         pquicc->intr_cicr = 0x00e49f00 | vba;
89
90         /* CPM interrupt vectors: (p 7-376) */
91         _ramvec[vba+CPMVEC_ERROR]       = bad_interrupt; /* Error */
92         _ramvec[vba+CPMVEC_PIO_PC11]    = inthandler;   /* pio - pc11 */
93         _ramvec[vba+CPMVEC_PIO_PC10]    = inthandler;   /* pio - pc10 */
94         _ramvec[vba+CPMVEC_SMC2]        = inthandler;   /* smc2/pip */
95         _ramvec[vba+CPMVEC_SMC1]        = inthandler;   /* smc1 */
96         _ramvec[vba+CPMVEC_SPI]         = inthandler;   /* spi */
97         _ramvec[vba+CPMVEC_PIO_PC9]     = inthandler;   /* pio - pc9 */
98         _ramvec[vba+CPMVEC_TIMER4]      = inthandler;   /* timer 4 */
99         _ramvec[vba+CPMVEC_RESERVED1]   = inthandler;   /* reserved */
100         _ramvec[vba+CPMVEC_PIO_PC8]     = inthandler;   /* pio - pc8 */
101         _ramvec[vba+CPMVEC_PIO_PC7]     = inthandler;  /* pio - pc7 */
102         _ramvec[vba+CPMVEC_PIO_PC6]     = inthandler;  /* pio - pc6 */
103         _ramvec[vba+CPMVEC_TIMER3]      = inthandler;  /* timer 3 */
104         _ramvec[vba+CPMVEC_RISCTIMER]   = inthandler;  /* reserved */
105         _ramvec[vba+CPMVEC_PIO_PC5]     = inthandler;  /* pio - pc5 */
106         _ramvec[vba+CPMVEC_PIO_PC4]     = inthandler;  /* pio - pc4 */
107         _ramvec[vba+CPMVEC_RESERVED2]   = inthandler;  /* reserved */
108         _ramvec[vba+CPMVEC_RISCTIMER]   = inthandler;  /* timer table */
109         _ramvec[vba+CPMVEC_TIMER2]      = inthandler;  /* timer 2 */
110         _ramvec[vba+CPMVEC_RESERVED3]   = inthandler;  /* reserved */
111         _ramvec[vba+CPMVEC_IDMA2]       = inthandler;  /* idma 2 */
112         _ramvec[vba+CPMVEC_IDMA1]       = inthandler;  /* idma 1 */
113         _ramvec[vba+CPMVEC_SDMA_CB_ERR] = inthandler;  /* sdma channel bus error */
114         _ramvec[vba+CPMVEC_PIO_PC3]     = inthandler;  /* pio - pc3 */
115         _ramvec[vba+CPMVEC_PIO_PC2]     = inthandler;  /* pio - pc2 */
116         /* _ramvec[vba+CPMVEC_TIMER1]      = cpm_isr_timer1; */  /* timer 1 */
117         _ramvec[vba+CPMVEC_TIMER1]      = inthandler;  /* timer 1 */
118         _ramvec[vba+CPMVEC_PIO_PC1]     = inthandler;  /* pio - pc1 */
119         _ramvec[vba+CPMVEC_SCC4]        = inthandler;  /* scc 4 */
120         _ramvec[vba+CPMVEC_SCC3]        = inthandler;  /* scc 3 */
121         _ramvec[vba+CPMVEC_SCC2]        = inthandler;  /* scc 2 */
122         _ramvec[vba+CPMVEC_SCC1]        = inthandler;  /* scc 1 */
123         _ramvec[vba+CPMVEC_PIO_PC0]     = inthandler;  /* pio - pc0 */
124
125
126         /* turn off all CPM interrupts */
127         pquicc->intr_cimr = 0x00000000;
128
129         /* initialize handlers */
130         for (i = 0; i < INTERNAL_IRQS; i++) {
131                 int_irq_list[i].handler = NULL;
132                 int_irq_list[i].flags   = IRQ_FLG_STD;
133                 int_irq_list[i].dev_id  = NULL;
134                 int_irq_list[i].devname = NULL;
135         }
136 }
137
138 #if 0
139 void M68360_insert_irq(irq_node_t **list, irq_node_t *node)
140 {
141         unsigned long flags;
142         irq_node_t *cur;
143
144         if (!node->dev_id)
145                 printk(KERN_INFO "%s: Warning: dev_id of %s is zero\n",
146                        __FUNCTION__, node->devname);
147
148         local_irq_save(flags);
149
150         cur = *list;
151
152         while (cur) {
153                 list = &cur->next;
154                 cur = cur->next;
155         }
156
157         node->next = cur;
158         *list = node;
159
160         local_irq_restore(flags);
161 }
162
163 void M68360_delete_irq(irq_node_t **list, void *dev_id)
164 {
165         unsigned long flags;
166         irq_node_t *node;
167
168         local_irq_save(flags);
169
170         for (node = *list; node; list = &node->next, node = *list) {
171                 if (node->dev_id == dev_id) {
172                         *list = node->next;
173                         /* Mark it as free. */
174                         node->handler = NULL;
175                         local_irq_restore(flags);
176                         return;
177                 }
178         }
179         local_irq_restore(flags);
180         printk (KERN_INFO "%s: tried to remove invalid irq\n", __FUNCTION__);
181 }
182 #endif
183
184 int request_irq(
185         unsigned int irq,
186         irqreturn_t (*handler)(int, void *, struct pt_regs *),
187         unsigned long flags,
188         const char *devname,
189         void *dev_id)
190 {
191         int mask = (1<<irq);
192
193         irq += (CPM_VECTOR_BASE<<4);
194
195         if (irq >= INTERNAL_IRQS) {
196                 printk (KERN_ERR "%s: Unknown IRQ %d from %s\n", __FUNCTION__, irq, devname);
197                 return -ENXIO;
198         }
199
200         if (!(int_irq_list[irq].flags & IRQ_FLG_STD)) {
201                 if (int_irq_list[irq].flags & IRQ_FLG_LOCK) {
202                         printk(KERN_ERR "%s: IRQ %d from %s is not replaceable\n",
203                                __FUNCTION__, irq, int_irq_list[irq].devname);
204                         return -EBUSY;
205                 }
206                 if (flags & IRQ_FLG_REPLACE) {
207                         printk(KERN_ERR "%s: %s can't replace IRQ %d from %s\n",
208                                __FUNCTION__, devname, irq, int_irq_list[irq].devname);
209                         return -EBUSY;
210                 }
211         }
212         int_irq_list[irq].handler = handler;
213         int_irq_list[irq].flags   = flags;
214         int_irq_list[irq].dev_id  = dev_id;
215         int_irq_list[irq].devname = devname;
216
217         /* enable in the CIMR */
218         if (!int_irq_ablecount[irq])
219                 pquicc->intr_cimr |= mask;
220         /*      *(volatile unsigned long *)0xfffff304 &= ~(1<<irq); */
221
222         return 0;
223 }
224
225 EXPORT_SYMBOL(request_irq);
226
227 void free_irq(unsigned int irq, void *dev_id)
228 {
229         if (irq >= INTERNAL_IRQS) {
230                 printk (KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
231                 return;
232         }
233
234         if (int_irq_list[irq].dev_id != dev_id)
235                 printk(KERN_INFO "%s: removing probably wrong IRQ %d from %s\n",
236                        __FUNCTION__, irq, int_irq_list[irq].devname);
237         int_irq_list[irq].handler = NULL;
238         int_irq_list[irq].flags   = IRQ_FLG_STD;
239         int_irq_list[irq].dev_id  = NULL;
240         int_irq_list[irq].devname = NULL;
241
242         *(volatile unsigned long *)0xfffff304 |= 1<<irq;
243 }
244
245 EXPORT_SYMBOL(free_irq);
246
247 #if 0
248 /*
249  * Enable/disable a particular machine specific interrupt source.
250  * Note that this may affect other interrupts in case of a shared interrupt.
251  * This function should only be called for a _very_ short time to change some
252  * internal data, that may not be changed by the interrupt at the same time.
253  * int_(enable|disable)_irq calls may also be nested.
254  */
255 void M68360_enable_irq(unsigned int irq)
256 {
257         if (irq >= INTERNAL_IRQS) {
258                 printk(KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
259                 return;
260         }
261
262         if (--int_irq_ablecount[irq])
263                 return;
264
265         /* enable the interrupt */
266         *(volatile unsigned long *)0xfffff304 &= ~(1<<irq);
267 }
268
269 void M68360_disable_irq(unsigned int irq)
270 {
271         if (irq >= INTERNAL_IRQS) {
272                 printk(KERN_ERR "%s: Unknown IRQ %d\n", __FUNCTION__, irq);
273                 return;
274         }
275
276         if (int_irq_ablecount[irq]++)
277                 return;
278
279         /* disable the interrupt */
280         *(volatile unsigned long *)0xfffff304 |= 1<<irq;
281 }
282 #endif
283
284 int show_interrupts(struct seq_file *p, void *v)
285 {
286         int i = *(loff_t *) v;
287
288         if (i < NR_IRQS) {
289                 if (int_irq_list[i].devname) {
290                         seq_printf(p, "%3d: %10u ", i, kstat_cpu(0).irqs[i]);
291                         if (int_irq_list[i].flags & IRQ_FLG_LOCK)
292                                 seq_printf(p, "L ");
293                         else
294                                 seq_printf(p, "  ");
295                         seq_printf(p, "%s\n", int_irq_list[i].devname);
296                 }
297         }
298         if (i == NR_IRQS)
299                 seq_printf(p, "   : %10u   spurious\n", num_spurious);
300
301         return 0;
302 }
303
304 /* The 68k family did not have a good way to determine the source
305  * of interrupts until later in the family.  The EC000 core does
306  * not provide the vector number on the stack, we vector everything
307  * into one vector and look in the blasted mask register...
308  * This code is designed to be fast, almost constant time, not clean!
309  */
310 void process_int(int vec, struct pt_regs *fp)
311 {
312         int irq;
313         int mask;
314
315         /* unsigned long pend = *(volatile unsigned long *)0xfffff30c; */
316
317         /* irq = vec + (CPM_VECTOR_BASE<<4); */
318         irq = vec;
319
320         /* unsigned long pend = *(volatile unsigned long *)pquicc->intr_cipr; */
321
322         /* Bugger all that weirdness. For the moment, I seem to know where I came from;
323          * vec is passed from a specific ISR, so I'll use it. */
324
325         if (int_irq_list[irq].handler) {
326                 int_irq_list[irq].handler(irq , int_irq_list[irq].dev_id, fp);
327                 kstat_cpu(0).irqs[irq]++;
328                 pquicc->intr_cisr = (1 << vec); /* indicate that irq has been serviced */
329         } else {
330                 printk(KERN_ERR "unregistered interrupt %d!\nTurning it off in the CIMR...\n", irq);
331                 /* *(volatile unsigned long *)0xfffff304 |= mask; */
332                 pquicc->intr_cimr &= ~(1 << vec);
333                 num_spurious += 1;
334         }
335         return(IRQ_HANDLED);
336 }