Merge with Linux 2.5.59.
[linux-2.6/linux-mips.git] / arch / m68k / q40 / q40ints.c
blob3c3a9fb357c314a1beaf3456f606876e3aa685e1
1 /*
2 * arch/m68k/q40/q40ints.c
4 * Copyright (C) 1999,2001 Richard Zidlicky
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
10 * .. used to be losely based on bvme6000ints.c
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/errno.h>
18 #include <linux/string.h>
19 #include <linux/sched.h>
20 #include <linux/seq_file.h>
21 #include <linux/interrupt.h>
23 #include <asm/rtc.h>
24 #include <asm/ptrace.h>
25 #include <asm/system.h>
26 #include <asm/irq.h>
27 #include <asm/hardirq.h>
28 #include <asm/traps.h>
30 #include <asm/q40_master.h>
31 #include <asm/q40ints.h>
33 /*
34 * Q40 IRQs are defined as follows:
35 * 3,4,5,6,7,10,11,14,15 : ISA dev IRQs
36 * 16-31: reserved
37 * 32 : keyboard int
38 * 33 : frame int (50/200 Hz periodic timer)
39 * 34 : sample int (10/20 KHz periodic timer)
43 extern int ints_inited;
46 void q40_irq2_handler (int, void *, struct pt_regs *fp);
49 extern void (*q40_sys_default_handler[]) (int, void *, struct pt_regs *);
51 static void q40_defhand (int irq, void *dev_id, struct pt_regs *fp);
52 static void sys_default_handler(int lev, void *dev_id, struct pt_regs *regs);
55 #define DEVNAME_SIZE 24
57 static struct q40_irq_node {
58 void (*handler)(int, void *, struct pt_regs *);
59 unsigned long flags;
60 void *dev_id;
61 /* struct q40_irq_node *next;*/
62 char devname[DEVNAME_SIZE];
63 unsigned count;
64 unsigned short state;
65 } irq_tab[Q40_IRQ_MAX+1];
67 short unsigned q40_ablecount[Q40_IRQ_MAX+1];
70 * void q40_init_IRQ (void)
72 * Parameters: None
74 * Returns: Nothing
76 * This function is called during kernel startup to initialize
77 * the q40 IRQ handling routines.
80 static int disabled=0;
82 void q40_init_IRQ (void)
84 int i;
86 disabled=0;
87 for (i = 0; i <= Q40_IRQ_MAX; i++) {
88 irq_tab[i].handler = q40_defhand;
89 irq_tab[i].flags = 0;
90 irq_tab[i].dev_id = NULL;
91 /* irq_tab[i].next = NULL;*/
92 irq_tab[i].devname[0] = 0;
93 irq_tab[i].count = 0;
94 irq_tab[i].state =0;
95 q40_ablecount[i]=0; /* all enabled */
98 /* setup handler for ISA ints */
99 sys_request_irq(IRQ2,q40_irq2_handler, 0, "q40 ISA and master chip", NULL);
101 /* now enable some ints.. */
102 master_outb(1,EXT_ENABLE_REG); /* ISA IRQ 5-15 */
104 /* make sure keyboard IRQ is disabled */
105 master_outb(0,KEY_IRQ_ENABLE_REG);
108 int q40_request_irq(unsigned int irq,
109 void (*handler)(int, void *, struct pt_regs *),
110 unsigned long flags, const char *devname, void *dev_id)
112 /*printk("q40_request_irq %d, %s\n",irq,devname);*/
114 if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
115 printk("%s: Incorrect IRQ %d from %s\n", __FUNCTION__, irq, devname);
116 return -ENXIO;
119 /* test for ISA ints not implemented by HW */
120 switch (irq)
122 case 1: case 2: case 8: case 9:
123 case 12: case 13:
124 printk("%s: ISA IRQ %d from %s not implemented by HW\n", __FUNCTION__, irq, devname);
125 return -ENXIO;
126 case 11:
127 printk("warning IRQ 10 and 11 not distinguishable\n");
128 irq=10;
129 default:
132 if (irq<Q40_IRQ_SAMPLE)
134 if (irq_tab[irq].dev_id != NULL)
136 printk("%s: IRQ %d from %s is not replaceable\n",
137 __FUNCTION__, irq, irq_tab[irq].devname);
138 return -EBUSY;
140 /*printk("IRQ %d set to handler %p\n",irq,handler);*/
141 if (dev_id==NULL)
143 printk("WARNING: dev_id == NULL in request_irq\n");
144 dev_id=(void*)1;
146 irq_tab[irq].handler = handler;
147 irq_tab[irq].flags = flags;
148 irq_tab[irq].dev_id = dev_id;
149 strncpy(irq_tab[irq].devname,devname,DEVNAME_SIZE);
150 irq_tab[irq].state = 0;
151 return 0;
153 else {
154 /* Q40_IRQ_SAMPLE :somewhat special actions required here ..*/
155 sys_request_irq(4,handler,flags,devname,dev_id);
156 sys_request_irq(6,handler,flags,devname,dev_id);
157 return 0;
161 void q40_free_irq(unsigned int irq, void *dev_id)
163 if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
164 printk("%s: Incorrect IRQ %d, dev_id %x \n", __FUNCTION__, irq, (unsigned)dev_id);
165 return;
168 /* test for ISA ints not implemented by HW */
169 switch (irq)
171 case 1: case 2: case 8: case 9:
172 case 12: case 13:
173 printk("%s: ISA IRQ %d from %x illegal\n", __FUNCTION__, irq, (unsigned)dev_id);
174 return;
175 case 11: irq=10;
176 default:
179 if (irq<Q40_IRQ_SAMPLE)
181 if (irq_tab[irq].dev_id != dev_id)
182 printk("%s: Removing probably wrong IRQ %d from %s\n",
183 __FUNCTION__, irq, irq_tab[irq].devname);
185 irq_tab[irq].handler = q40_defhand;
186 irq_tab[irq].flags = 0;
187 irq_tab[irq].dev_id = NULL;
188 /* irq_tab[irq].devname = NULL; */
189 /* do not reset state !! */
191 else
192 { /* == Q40_IRQ_SAMPLE */
193 sys_free_irq(4,dev_id);
194 sys_free_irq(6,dev_id);
199 void q40_process_int (int level, struct pt_regs *fp)
201 printk("unexpected interrupt %x\n",level);
205 * this stuff doesn't really belong here..
208 int ql_ticks; /* 200Hz ticks since last jiffie */
209 static int sound_ticks;
211 #define SVOL 45
213 void q40_mksound(unsigned int hz, unsigned int ticks)
215 /* for now ignore hz, except that hz==0 switches off sound */
216 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
217 if (hz==0)
219 if (sound_ticks)
220 sound_ticks=1;
222 *DAC_LEFT=128;
223 *DAC_RIGHT=128;
225 return;
227 /* sound itself is done in q40_timer_int */
228 if (sound_ticks == 0) sound_ticks=1000; /* pretty long beep */
229 sound_ticks=ticks<<1;
232 static void (*q40_timer_routine)(int, void *, struct pt_regs *);
234 static void q40_timer_int (int irq, void * dev, struct pt_regs * regs)
236 ql_ticks = ql_ticks ? 0 : 1;
237 if (sound_ticks)
239 unsigned char sval=(sound_ticks & 1) ? 128-SVOL : 128+SVOL;
240 sound_ticks--;
241 *DAC_LEFT=sval;
242 *DAC_RIGHT=sval;
245 if (ql_ticks) return;
247 q40_timer_routine(irq, dev, regs);
250 void q40_sched_init (void (*timer_routine)(int, void *, struct pt_regs *))
252 int timer_irq;
254 q40_timer_routine = timer_routine;
255 timer_irq=Q40_IRQ_FRAME;
257 if (request_irq(timer_irq, q40_timer_int, 0,
258 "timer", q40_timer_int))
259 panic ("Couldn't register timer int");
261 master_outb(-1,FRAME_CLEAR_REG);
262 master_outb( 1,FRAME_RATE_REG);
267 * tables to translate bits into IRQ numbers
268 * it is a good idea to order the entries by priority
272 struct IRQ_TABLE{ unsigned mask; int irq ;};
273 #if 0
274 static struct IRQ_TABLE iirqs[]={
275 {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
276 {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
277 {0,0}};
278 #endif
279 static struct IRQ_TABLE eirqs[]={
280 {Q40_IRQ3_MASK,3}, /* ser 1 */
281 {Q40_IRQ4_MASK,4}, /* ser 2 */
282 {Q40_IRQ14_MASK,14}, /* IDE 1 */
283 {Q40_IRQ15_MASK,15}, /* IDE 2 */
284 {Q40_IRQ6_MASK,6}, /* floppy, handled elsewhere */
285 {Q40_IRQ7_MASK,7}, /* par */
287 {Q40_IRQ5_MASK,5},
288 {Q40_IRQ10_MASK,10},
293 {0,0}};
295 /* complain only this many times about spurious ints : */
296 static int ccleirq=60; /* ISA dev IRQ's*/
297 /*static int cclirq=60;*/ /* internal */
299 /* FIXME: add shared ints,mask,unmask,probing.... */
301 #define IRQ_INPROGRESS 1
302 /*static unsigned short saved_mask;*/
303 //static int do_tint=0;
305 #define DEBUG_Q40INT
306 /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
308 static int mext_disabled=0; /* ext irq disabled by master chip? */
309 static int aliased_irq=0; /* how many times inside handler ?*/
312 /* got level 2 interrupt, dispatch to ISA or keyboard/timer IRQs */
313 void q40_irq2_handler (int vec, void *devname, struct pt_regs *fp)
315 unsigned mir, mer;
316 int irq,i;
318 repeat:
319 mir=master_inb(IIRQ_REG);
320 if (mir&Q40_IRQ_FRAME_MASK) {
321 irq_tab[Q40_IRQ_FRAME].count++;
322 irq_tab[Q40_IRQ_FRAME].handler(Q40_IRQ_FRAME,irq_tab[Q40_IRQ_FRAME].dev_id,fp);
323 master_outb(-1,FRAME_CLEAR_REG);
325 if ((mir&Q40_IRQ_SER_MASK) || (mir&Q40_IRQ_EXT_MASK)) {
326 mer=master_inb(EIRQ_REG);
327 for (i=0; eirqs[i].mask; i++) {
328 if (mer&(eirqs[i].mask)) {
329 irq=eirqs[i].irq;
331 * There is a little mess wrt which IRQ really caused this irq request. The
332 * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
333 * are read - which is long after the request came in. In theory IRQs should
334 * not just go away but they occassionally do
336 if (irq>4 && irq<=15 && mext_disabled) {
337 /*aliased_irq++;*/
338 goto iirq;
340 if (irq_tab[irq].handler == q40_defhand ) {
341 printk("handler for IRQ %d not defined\n",irq);
342 continue; /* ignore uninited INTs :-( */
344 if ( irq_tab[irq].state & IRQ_INPROGRESS ) {
345 /* some handlers do sti() for irq latency reasons, */
346 /* however reentering an active irq handler is not permitted */
347 #ifdef IP_USE_DISABLE
348 /* in theory this is the better way to do it because it still */
349 /* lets through eg the serial irqs, unfortunately it crashes */
350 disable_irq(irq);
351 disabled=1;
352 #else
353 /*printk("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",irq,disabled ? "already" : "not yet"); */
354 fp->sr = (((fp->sr) & (~0x700))+0x200);
355 disabled=1;
356 #endif
357 goto iirq;
359 irq_tab[irq].count++;
360 irq_tab[irq].state |= IRQ_INPROGRESS;
361 irq_tab[irq].handler(irq,irq_tab[irq].dev_id,fp);
362 irq_tab[irq].state &= ~IRQ_INPROGRESS;
364 /* naively enable everything, if that fails than */
365 /* this function will be reentered immediately thus */
366 /* getting another chance to disable the IRQ */
368 if ( disabled ) {
369 #ifdef IP_USE_DISABLE
370 if (irq>4){
371 disabled=0;
372 enable_irq(irq);}
373 #else
374 disabled=0;
375 /*printk("reenabling irq %d\n",irq); */
376 #endif
378 // used to do 'goto repeat;' her, this delayed bh processing too long
379 return;
382 if (mer && ccleirq>0 && !aliased_irq)
383 printk("ISA interrupt from unknown source? EIRQ_REG = %x\n",mer),ccleirq--;
385 iirq:
386 mir=master_inb(IIRQ_REG);
387 if (mir&Q40_IRQ_KEYB_MASK) {
388 irq_tab[Q40_IRQ_KEYBOARD].count++;
389 irq_tab[Q40_IRQ_KEYBOARD].handler(Q40_IRQ_KEYBOARD,irq_tab[Q40_IRQ_KEYBOARD].dev_id,fp);
393 int show_q40_interrupts (struct seq_file *p, void *v)
395 int i;
397 for (i = 0; i <= Q40_IRQ_MAX; i++) {
398 if (irq_tab[i].count)
399 seq_printf(p, "%sIRQ %02d: %8d %s%s\n",
400 (i<=15) ? "ISA-" : " " ,
401 i, irq_tab[i].count,
402 irq_tab[i].devname[0] ? irq_tab[i].devname : "?",
403 irq_tab[i].handler == q40_defhand ?
404 " (now unassigned)" : "");
406 return 0;
410 static void q40_defhand (int irq, void *dev_id, struct pt_regs *fp)
412 printk ("Unknown q40 interrupt 0x%02x\n", irq);
414 static void sys_default_handler(int lev, void *dev_id, struct pt_regs *regs)
416 printk ("Uninitialised interrupt level %d\n", lev);
419 void (*q40_sys_default_handler[SYS_IRQS]) (int, void *, struct pt_regs *) = {
420 sys_default_handler,sys_default_handler,sys_default_handler,sys_default_handler,
421 sys_default_handler,sys_default_handler,sys_default_handler,sys_default_handler
425 void q40_enable_irq (unsigned int irq)
427 if ( irq>=5 && irq<=15 )
429 mext_disabled--;
430 if (mext_disabled>0)
431 printk("q40_enable_irq : nested disable/enable\n");
432 if (mext_disabled==0)
433 master_outb(1,EXT_ENABLE_REG);
438 void q40_disable_irq (unsigned int irq)
440 /* disable ISA iqs : only do something if the driver has been
441 * verified to be Q40 "compatible" - right now IDE, NE2K
442 * Any driver should not attempt to sleep accross disable_irq !!
445 if ( irq>=5 && irq<=15 ) {
446 master_outb(0,EXT_ENABLE_REG);
447 mext_disabled++;
448 if (mext_disabled>1) printk("disable_irq nesting count %d\n",mext_disabled);
452 unsigned long q40_probe_irq_on (void)
454 printk("irq probing not working - reconfigure the driver to avoid this\n");
455 return -1;
457 int q40_probe_irq_off (unsigned long irqs)
459 return -1;
462 * Local variables:
463 * compile-command: "m68k-linux-gcc -D__KERNEL__ -I/home/rz/lx/linux-2.2.6/include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -ffixed-a2 -m68040 -c -o q40ints.o q40ints.c"
464 * End: