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
);
49 static irqreturn_t
default_handler(int lev
, void *dev_id
, struct pt_regs
*regs
);
52 #define DEVNAME_SIZE 24
54 static struct q40_irq_node
{
55 irqreturn_t (*handler
)(int, void *, struct pt_regs
*);
58 /* struct q40_irq_node *next;*/
59 char devname
[DEVNAME_SIZE
];
62 } irq_tab
[Q40_IRQ_MAX
+1];
64 short unsigned q40_ablecount
[Q40_IRQ_MAX
+1];
67 * void q40_init_IRQ (void)
73 * This function is called during kernel startup to initialize
74 * the q40 IRQ handling routines.
77 static int disabled
=0;
79 void q40_init_IRQ (void)
84 for (i
= 0; i
<= Q40_IRQ_MAX
; i
++) {
85 irq_tab
[i
].handler
= q40_defhand
;
87 irq_tab
[i
].dev_id
= NULL
;
88 /* irq_tab[i].next = NULL;*/
89 irq_tab
[i
].devname
[0] = 0;
92 q40_ablecount
[i
]=0; /* all enabled */
95 /* setup handler for ISA ints */
96 cpu_request_irq(IRQ2
, q40_irq2_handler
, 0, "q40 ISA and master chip",
99 /* now enable some ints.. */
100 master_outb(1,EXT_ENABLE_REG
); /* ISA IRQ 5-15 */
102 /* make sure keyboard IRQ is disabled */
103 master_outb(0,KEY_IRQ_ENABLE_REG
);
106 int q40_request_irq(unsigned int irq
,
107 irqreturn_t (*handler
)(int, void *, struct pt_regs
*),
108 unsigned long flags
, const char *devname
, void *dev_id
)
110 /*printk("q40_request_irq %d, %s\n",irq,devname);*/
112 if (irq
> Q40_IRQ_MAX
|| (irq
>15 && irq
<32)) {
113 printk("%s: Incorrect IRQ %d from %s\n", __FUNCTION__
, irq
, devname
);
117 /* test for ISA ints not implemented by HW */
120 case 1: case 2: case 8: case 9:
122 printk("%s: ISA IRQ %d from %s not implemented by HW\n", __FUNCTION__
, irq
, devname
);
125 printk("warning IRQ 10 and 11 not distinguishable\n");
131 if (irq
<Q40_IRQ_SAMPLE
)
133 if (irq_tab
[irq
].dev_id
!= NULL
)
135 printk("%s: IRQ %d from %s is not replaceable\n",
136 __FUNCTION__
, irq
, irq_tab
[irq
].devname
);
139 /*printk("IRQ %d set to handler %p\n",irq,handler);*/
142 printk("WARNING: dev_id == NULL in request_irq\n");
145 irq_tab
[irq
].handler
= handler
;
146 irq_tab
[irq
].flags
= flags
;
147 irq_tab
[irq
].dev_id
= dev_id
;
148 strlcpy(irq_tab
[irq
].devname
,devname
,sizeof(irq_tab
[irq
].devname
));
149 irq_tab
[irq
].state
= 0;
153 /* Q40_IRQ_SAMPLE :somewhat special actions required here ..*/
154 cpu_request_irq(4, handler
, flags
, devname
, dev_id
);
155 cpu_request_irq(6, handler
, flags
, devname
, dev_id
);
160 void q40_free_irq(unsigned int irq
, void *dev_id
)
162 if (irq
> Q40_IRQ_MAX
|| (irq
>15 && irq
<32)) {
163 printk("%s: Incorrect IRQ %d, dev_id %x \n", __FUNCTION__
, irq
, (unsigned)dev_id
);
167 /* test for ISA ints not implemented by HW */
170 case 1: case 2: case 8: case 9:
172 printk("%s: ISA IRQ %d from %x invalid\n", __FUNCTION__
, irq
, (unsigned)dev_id
);
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 !! */
192 { /* == Q40_IRQ_SAMPLE */
193 cpu_free_irq(4, dev_id
);
194 cpu_free_irq(6, dev_id
);
199 irqreturn_t
q40_process_int (int level
, struct pt_regs
*fp
)
201 printk("unexpected interrupt vec=%x, pc=%lx, d0=%lx, d0_orig=%lx, d1=%lx, d2=%lx\n",
202 level
, fp
->pc
, fp
->d0
, fp
->orig_d0
, fp
->d1
, fp
->d2
);
203 printk("\tIIRQ_REG = %x, EIRQ_REG = %x\n",master_inb(IIRQ_REG
),master_inb(EIRQ_REG
));
208 * this stuff doesn't really belong here..
211 int ql_ticks
; /* 200Hz ticks since last jiffie */
212 static int sound_ticks
;
216 void q40_mksound(unsigned int hz
, unsigned int ticks
)
218 /* for now ignore hz, except that hz==0 switches off sound */
219 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
230 /* sound itself is done in q40_timer_int */
231 if (sound_ticks
== 0) sound_ticks
=1000; /* pretty long beep */
232 sound_ticks
=ticks
<<1;
235 static irqreturn_t (*q40_timer_routine
)(int, void *, struct pt_regs
*);
237 static irqreturn_t
q40_timer_int (int irq
, void * dev
, struct pt_regs
* regs
)
239 ql_ticks
= ql_ticks
? 0 : 1;
242 unsigned char sval
=(sound_ticks
& 1) ? 128-SVOL
: 128+SVOL
;
249 q40_timer_routine(irq
, dev
, regs
);
253 void q40_sched_init (irqreturn_t (*timer_routine
)(int, void *, struct pt_regs
*))
257 q40_timer_routine
= timer_routine
;
258 timer_irq
=Q40_IRQ_FRAME
;
260 if (request_irq(timer_irq
, q40_timer_int
, 0,
261 "timer", q40_timer_int
))
262 panic ("Couldn't register timer int");
264 master_outb(-1,FRAME_CLEAR_REG
);
265 master_outb( 1,FRAME_RATE_REG
);
270 * tables to translate bits into IRQ numbers
271 * it is a good idea to order the entries by priority
275 struct IRQ_TABLE
{ unsigned mask
; int irq
;};
277 static struct IRQ_TABLE iirqs
[]={
278 {Q40_IRQ_FRAME_MASK
,Q40_IRQ_FRAME
},
279 {Q40_IRQ_KEYB_MASK
,Q40_IRQ_KEYBOARD
},
282 static struct IRQ_TABLE eirqs
[] = {
283 { .mask
= Q40_IRQ3_MASK
, .irq
= 3 }, /* ser 1 */
284 { .mask
= Q40_IRQ4_MASK
, .irq
= 4 }, /* ser 2 */
285 { .mask
= Q40_IRQ14_MASK
, .irq
= 14 }, /* IDE 1 */
286 { .mask
= Q40_IRQ15_MASK
, .irq
= 15 }, /* IDE 2 */
287 { .mask
= Q40_IRQ6_MASK
, .irq
= 6 }, /* floppy, handled elsewhere */
288 { .mask
= Q40_IRQ7_MASK
, .irq
= 7 }, /* par */
289 { .mask
= Q40_IRQ5_MASK
, .irq
= 5 },
290 { .mask
= Q40_IRQ10_MASK
, .irq
= 10 },
294 /* complain only this many times about spurious ints : */
295 static int ccleirq
=60; /* ISA dev IRQ's*/
296 /*static int cclirq=60;*/ /* internal */
298 /* FIXME: add shared ints,mask,unmask,probing.... */
300 #define IRQ_INPROGRESS 1
301 /*static unsigned short saved_mask;*/
302 //static int do_tint=0;
305 /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
307 static int mext_disabled
=0; /* ext irq disabled by master chip? */
308 static int aliased_irq
=0; /* how many times inside handler ?*/
311 /* got level 2 interrupt, dispatch to ISA or keyboard/timer IRQs */
312 irqreturn_t
q40_irq2_handler (int vec
, void *devname
, struct pt_regs
*fp
)
318 mir
=master_inb(IIRQ_REG
);
319 if (mir
&Q40_IRQ_FRAME_MASK
) {
320 irq_tab
[Q40_IRQ_FRAME
].count
++;
321 irq_tab
[Q40_IRQ_FRAME
].handler(Q40_IRQ_FRAME
,irq_tab
[Q40_IRQ_FRAME
].dev_id
,fp
);
322 master_outb(-1,FRAME_CLEAR_REG
);
324 if ((mir
&Q40_IRQ_SER_MASK
) || (mir
&Q40_IRQ_EXT_MASK
)) {
325 mer
=master_inb(EIRQ_REG
);
326 for (i
=0; eirqs
[i
].mask
; i
++) {
327 if (mer
&(eirqs
[i
].mask
)) {
330 * There is a little mess wrt which IRQ really caused this irq request. The
331 * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
332 * are read - which is long after the request came in. In theory IRQs should
333 * not just go away but they occassionally do
335 if (irq
>4 && irq
<=15 && mext_disabled
) {
339 if (irq_tab
[irq
].handler
== q40_defhand
) {
340 printk("handler for IRQ %d not defined\n",irq
);
341 continue; /* ignore uninited INTs :-( */
343 if ( irq_tab
[irq
].state
& IRQ_INPROGRESS
) {
344 /* some handlers do local_irq_enable() for irq latency reasons, */
345 /* however reentering an active irq handler is not permitted */
346 #ifdef IP_USE_DISABLE
347 /* in theory this is the better way to do it because it still */
348 /* lets through eg the serial irqs, unfortunately it crashes */
352 /*printk("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",irq,disabled ? "already" : "not yet"); */
353 fp
->sr
= (((fp
->sr
) & (~0x700))+0x200);
358 irq_tab
[irq
].count
++;
359 irq_tab
[irq
].state
|= IRQ_INPROGRESS
;
360 irq_tab
[irq
].handler(irq
,irq_tab
[irq
].dev_id
,fp
);
361 irq_tab
[irq
].state
&= ~IRQ_INPROGRESS
;
363 /* naively enable everything, if that fails than */
364 /* this function will be reentered immediately thus */
365 /* getting another chance to disable the IRQ */
368 #ifdef IP_USE_DISABLE
374 /*printk("reenabling irq %d\n",irq); */
377 // used to do 'goto repeat;' here, this delayed bh processing too long
381 if (mer
&& ccleirq
>0 && !aliased_irq
)
382 printk("ISA interrupt from unknown source? EIRQ_REG = %x\n",mer
),ccleirq
--;
385 mir
=master_inb(IIRQ_REG
);
386 /* should test whether keyboard irq is really enabled, doing it in defhand */
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
);
394 int show_q40_interrupts (struct seq_file
*p
, void *v
)
398 for (i
= 0; i
<= Q40_IRQ_MAX
; i
++) {
399 if (irq_tab
[i
].count
)
400 seq_printf(p
, "%sIRQ %02d: %8d %s%s\n",
401 (i
<=15) ? "ISA-" : " " ,
403 irq_tab
[i
].devname
[0] ? irq_tab
[i
].devname
: "?",
404 irq_tab
[i
].handler
== q40_defhand
?
405 " (now unassigned)" : "");
411 static irqreturn_t
q40_defhand (int irq
, void *dev_id
, struct pt_regs
*fp
)
413 if (irq
!=Q40_IRQ_KEYBOARD
)
414 printk ("Unknown q40 interrupt %d\n", irq
);
415 else master_outb(-1,KEYBOARD_UNLOCK_REG
);
418 static irqreturn_t
default_handler(int lev
, void *dev_id
, struct pt_regs
*regs
)
420 printk ("Uninitialised interrupt level %d\n", lev
);
424 irqreturn_t (*q40_default_handler
[SYS_IRQS
])(int, void *, struct pt_regs
*) = {
425 [0] = default_handler
,
426 [1] = default_handler
,
427 [2] = default_handler
,
428 [3] = default_handler
,
429 [4] = default_handler
,
430 [5] = default_handler
,
431 [6] = default_handler
,
432 [7] = default_handler
436 void q40_enable_irq (unsigned int irq
)
438 if ( irq
>=5 && irq
<=15 )
442 printk("q40_enable_irq : nested disable/enable\n");
443 if (mext_disabled
==0)
444 master_outb(1,EXT_ENABLE_REG
);
449 void q40_disable_irq (unsigned int irq
)
451 /* disable ISA iqs : only do something if the driver has been
452 * verified to be Q40 "compatible" - right now IDE, NE2K
453 * Any driver should not attempt to sleep across disable_irq !!
456 if ( irq
>=5 && irq
<=15 ) {
457 master_outb(0,EXT_ENABLE_REG
);
459 if (mext_disabled
>1) printk("disable_irq nesting count %d\n",mext_disabled
);
463 unsigned long q40_probe_irq_on (void)
465 printk("irq probing not working - reconfigure the driver to avoid this\n");
468 int q40_probe_irq_off (unsigned long irqs
)
474 * 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"