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
10 * .. used to be loosely based on bvme6000ints.c
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/seq_file.h>
20 #include <linux/interrupt.h>
21 #include <linux/hardirq.h>
24 #include <asm/ptrace.h>
25 #include <asm/system.h>
27 #include <asm/traps.h>
29 #include <asm/q40_master.h>
30 #include <asm/q40ints.h>
33 * Q40 IRQs are defined as follows:
34 * 3,4,5,6,7,10,11,14,15 : ISA dev IRQs
37 * 33 : frame int (50/200 Hz periodic timer)
38 * 34 : sample int (10/20 KHz periodic timer)
42 extern int ints_inited;
45 irqreturn_t q40_irq2_handler (int, void *, struct pt_regs *fp);
48 static irqreturn_t q40_defhand (int irq, void *dev_id, struct pt_regs *fp);
51 #define DEVNAME_SIZE 24
53 static struct q40_irq_node {
54 irqreturn_t (*handler)(int, void *, struct pt_regs *);
57 /* struct q40_irq_node *next;*/
58 char devname[DEVNAME_SIZE];
61 } irq_tab[Q40_IRQ_MAX+1];
63 short unsigned q40_ablecount[Q40_IRQ_MAX+1];
66 * void q40_init_IRQ (void)
72 * This function is called during kernel startup to initialize
73 * the q40 IRQ handling routines.
76 static int disabled=0;
78 void q40_init_IRQ (void)
83 for (i = 0; i <= Q40_IRQ_MAX; i++) {
84 irq_tab[i].handler = q40_defhand;
86 irq_tab[i].dev_id = NULL;
87 /* irq_tab[i].next = NULL;*/
88 irq_tab[i].devname[0] = 0;
91 q40_ablecount[i]=0; /* all enabled */
94 /* setup handler for ISA ints */
95 cpu_request_irq(IRQ_AUTO_2, q40_irq2_handler, 0,
96 "q40 ISA and master chip", NULL);
98 /* now enable some ints.. */
99 master_outb(1,EXT_ENABLE_REG); /* ISA IRQ 5-15 */
101 /* make sure keyboard IRQ is disabled */
102 master_outb(0,KEY_IRQ_ENABLE_REG);
105 int q40_request_irq(unsigned int irq,
106 irqreturn_t (*handler)(int, void *, struct pt_regs *),
107 unsigned long flags, const char *devname, void *dev_id)
109 /*printk("q40_request_irq %d, %s\n",irq,devname);*/
111 if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
112 printk("%s: Incorrect IRQ %d from %s\n", __FUNCTION__, irq, devname);
116 /* test for ISA ints not implemented by HW */
119 case 1: case 2: case 8: case 9:
121 printk("%s: ISA IRQ %d from %s not implemented by HW\n", __FUNCTION__, irq, devname);
124 printk("warning IRQ 10 and 11 not distinguishable\n");
130 if (irq<Q40_IRQ_SAMPLE)
132 if (irq_tab[irq].dev_id != NULL)
134 printk("%s: IRQ %d from %s is not replaceable\n",
135 __FUNCTION__, irq, irq_tab[irq].devname);
138 /*printk("IRQ %d set to handler %p\n",irq,handler);*/
141 printk("WARNING: dev_id == NULL in request_irq\n");
144 irq_tab[irq].handler = handler;
145 irq_tab[irq].flags = flags;
146 irq_tab[irq].dev_id = dev_id;
147 strlcpy(irq_tab[irq].devname,devname,sizeof(irq_tab[irq].devname));
148 irq_tab[irq].state = 0;
152 /* Q40_IRQ_SAMPLE :somewhat special actions required here ..*/
153 cpu_request_irq(4, handler, flags, devname, dev_id);
154 cpu_request_irq(6, handler, flags, devname, dev_id);
159 void q40_free_irq(unsigned int irq, void *dev_id)
161 if (irq > Q40_IRQ_MAX || (irq>15 && irq<32)) {
162 printk("%s: Incorrect IRQ %d, dev_id %x \n", __FUNCTION__, irq, (unsigned)dev_id);
166 /* test for ISA ints not implemented by HW */
169 case 1: case 2: case 8: case 9:
171 printk("%s: ISA IRQ %d from %x invalid\n", __FUNCTION__, irq, (unsigned)dev_id);
178 if (irq<Q40_IRQ_SAMPLE)
180 if (irq_tab[irq].dev_id != dev_id)
181 printk("%s: Removing probably wrong IRQ %d from %s\n",
182 __FUNCTION__, irq, irq_tab[irq].devname);
184 irq_tab[irq].handler = q40_defhand;
185 irq_tab[irq].flags = 0;
186 irq_tab[irq].dev_id = NULL;
187 /* irq_tab[irq].devname = NULL; */
188 /* do not reset state !! */
191 { /* == Q40_IRQ_SAMPLE */
192 cpu_free_irq(4, dev_id);
193 cpu_free_irq(6, dev_id);
198 irqreturn_t q40_process_int (int level, struct pt_regs *fp)
200 printk("unexpected interrupt vec=%x, pc=%lx, d0=%lx, d0_orig=%lx, d1=%lx, d2=%lx\n",
201 level, fp->pc, fp->d0, fp->orig_d0, fp->d1, fp->d2);
202 printk("\tIIRQ_REG = %x, EIRQ_REG = %x\n",master_inb(IIRQ_REG),master_inb(EIRQ_REG));
207 * this stuff doesn't really belong here..
210 int ql_ticks; /* 200Hz ticks since last jiffie */
211 static int sound_ticks;
215 void q40_mksound(unsigned int hz, unsigned int ticks)
217 /* for now ignore hz, except that hz==0 switches off sound */
218 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
229 /* sound itself is done in q40_timer_int */
230 if (sound_ticks == 0) sound_ticks=1000; /* pretty long beep */
231 sound_ticks=ticks<<1;
234 static irqreturn_t (*q40_timer_routine)(int, void *, struct pt_regs *);
236 static irqreturn_t q40_timer_int (int irq, void * dev, struct pt_regs * regs)
238 ql_ticks = ql_ticks ? 0 : 1;
241 unsigned char sval=(sound_ticks & 1) ? 128-SVOL : 128+SVOL;
248 q40_timer_routine(irq, dev, regs);
252 void q40_sched_init (irqreturn_t (*timer_routine)(int, void *, struct pt_regs *))
256 q40_timer_routine = timer_routine;
257 timer_irq=Q40_IRQ_FRAME;
259 if (request_irq(timer_irq, q40_timer_int, 0,
260 "timer", q40_timer_int))
261 panic ("Couldn't register timer int");
263 master_outb(-1,FRAME_CLEAR_REG);
264 master_outb( 1,FRAME_RATE_REG);
269 * tables to translate bits into IRQ numbers
270 * it is a good idea to order the entries by priority
274 struct IRQ_TABLE{ unsigned mask; int irq ;};
276 static struct IRQ_TABLE iirqs[]={
277 {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
278 {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
281 static struct IRQ_TABLE eirqs[] = {
282 { .mask = Q40_IRQ3_MASK, .irq = 3 }, /* ser 1 */
283 { .mask = Q40_IRQ4_MASK, .irq = 4 }, /* ser 2 */
284 { .mask = Q40_IRQ14_MASK, .irq = 14 }, /* IDE 1 */
285 { .mask = Q40_IRQ15_MASK, .irq = 15 }, /* IDE 2 */
286 { .mask = Q40_IRQ6_MASK, .irq = 6 }, /* floppy, handled elsewhere */
287 { .mask = Q40_IRQ7_MASK, .irq = 7 }, /* par */
288 { .mask = Q40_IRQ5_MASK, .irq = 5 },
289 { .mask = Q40_IRQ10_MASK, .irq = 10 },
293 /* complain only this many times about spurious ints : */
294 static int ccleirq=60; /* ISA dev IRQ's*/
295 /*static int cclirq=60;*/ /* internal */
297 /* FIXME: add shared ints,mask,unmask,probing.... */
299 #define IRQ_INPROGRESS 1
300 /*static unsigned short saved_mask;*/
301 //static int do_tint=0;
304 /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
306 static int mext_disabled=0; /* ext irq disabled by master chip? */
307 static int aliased_irq=0; /* how many times inside handler ?*/
310 /* got level 2 interrupt, dispatch to ISA or keyboard/timer IRQs */
311 irqreturn_t q40_irq2_handler (int vec, void *devname, struct pt_regs *fp)
317 mir=master_inb(IIRQ_REG);
318 if (mir&Q40_IRQ_FRAME_MASK) {
319 irq_tab[Q40_IRQ_FRAME].count++;
320 irq_tab[Q40_IRQ_FRAME].handler(Q40_IRQ_FRAME,irq_tab[Q40_IRQ_FRAME].dev_id,fp);
321 master_outb(-1,FRAME_CLEAR_REG);
323 if ((mir&Q40_IRQ_SER_MASK) || (mir&Q40_IRQ_EXT_MASK)) {
324 mer=master_inb(EIRQ_REG);
325 for (i=0; eirqs[i].mask; i++) {
326 if (mer&(eirqs[i].mask)) {
329 * There is a little mess wrt which IRQ really caused this irq request. The
330 * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
331 * are read - which is long after the request came in. In theory IRQs should
332 * not just go away but they occassionally do
334 if (irq>4 && irq<=15 && mext_disabled) {
338 if (irq_tab[irq].handler == q40_defhand ) {
339 printk("handler for IRQ %d not defined\n",irq);
340 continue; /* ignore uninited INTs :-( */
342 if ( irq_tab[irq].state & IRQ_INPROGRESS ) {
343 /* some handlers do local_irq_enable() for irq latency reasons, */
344 /* however reentering an active irq handler is not permitted */
345 #ifdef IP_USE_DISABLE
346 /* in theory this is the better way to do it because it still */
347 /* lets through eg the serial irqs, unfortunately it crashes */
351 /*printk("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",irq,disabled ? "already" : "not yet"); */
352 fp->sr = (((fp->sr) & (~0x700))+0x200);
357 irq_tab[irq].count++;
358 irq_tab[irq].state |= IRQ_INPROGRESS;
359 irq_tab[irq].handler(irq,irq_tab[irq].dev_id,fp);
360 irq_tab[irq].state &= ~IRQ_INPROGRESS;
362 /* naively enable everything, if that fails than */
363 /* this function will be reentered immediately thus */
364 /* getting another chance to disable the IRQ */
367 #ifdef IP_USE_DISABLE
373 /*printk("reenabling irq %d\n",irq); */
376 // used to do 'goto repeat;' here, this delayed bh processing too long
380 if (mer && ccleirq>0 && !aliased_irq)
381 printk("ISA interrupt from unknown source? EIRQ_REG = %x\n",mer),ccleirq--;
384 mir=master_inb(IIRQ_REG);
385 /* should test whether keyboard irq is really enabled, doing it in defhand */
386 if (mir&Q40_IRQ_KEYB_MASK) {
387 irq_tab[Q40_IRQ_KEYBOARD].count++;
388 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)
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-" : " " ,
402 irq_tab[i].devname[0] ? irq_tab[i].devname : "?",
403 irq_tab[i].handler == q40_defhand ?
404 " (now unassigned)" : "");
410 static irqreturn_t q40_defhand (int irq, void *dev_id, struct pt_regs *fp)
412 if (irq!=Q40_IRQ_KEYBOARD)
413 printk ("Unknown q40 interrupt %d\n", irq);
414 else master_outb(-1,KEYBOARD_UNLOCK_REG);
419 void q40_enable_irq (unsigned int irq)
421 if ( irq>=5 && irq<=15 )
425 printk("q40_enable_irq : nested disable/enable\n");
426 if (mext_disabled==0)
427 master_outb(1,EXT_ENABLE_REG);
432 void q40_disable_irq (unsigned int irq)
434 /* disable ISA iqs : only do something if the driver has been
435 * verified to be Q40 "compatible" - right now IDE, NE2K
436 * Any driver should not attempt to sleep across disable_irq !!
439 if ( irq>=5 && irq<=15 ) {
440 master_outb(0,EXT_ENABLE_REG);
442 if (mext_disabled>1) printk("disable_irq nesting count %d\n",mext_disabled);
446 unsigned long q40_probe_irq_on (void)
448 printk("irq probing not working - reconfigure the driver to avoid this\n");
451 int q40_probe_irq_off (unsigned long irqs)
457 * 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"