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/interrupt.h>
18 #include <linux/irq.h>
20 #include <asm/ptrace.h>
21 #include <asm/traps.h>
23 #include <asm/q40_master.h>
24 #include <asm/q40ints.h>
27 * Q40 IRQs are defined as follows:
28 * 3,4,5,6,7,10,11,14,15 : ISA dev IRQs
31 * 33 : frame int (50/200 Hz periodic timer)
32 * 34 : sample int (10/20 KHz periodic timer)
36 static void q40_irq_handler(unsigned int, struct pt_regs
*fp
);
37 static void q40_irq_enable(struct irq_data
*data
);
38 static void q40_irq_disable(struct irq_data
*data
);
40 unsigned short q40_ablecount
[35];
41 unsigned short q40_state
[35];
43 static unsigned int q40_irq_startup(struct irq_data
*data
)
45 unsigned int irq
= data
->irq
;
47 /* test for ISA ints not implemented by HW */
49 case 1: case 2: case 8: case 9:
50 case 11: case 12: case 13:
51 pr_warn("%s: ISA IRQ %d not implemented by HW\n", __func__
,
53 /* FIXME return -ENXIO; */
58 static void q40_irq_shutdown(struct irq_data
*data
)
62 static struct irq_chip q40_irq_chip
= {
64 .irq_startup
= q40_irq_startup
,
65 .irq_shutdown
= q40_irq_shutdown
,
66 .irq_enable
= q40_irq_enable
,
67 .irq_disable
= q40_irq_disable
,
71 * void q40_init_IRQ (void)
77 * This function is called during kernel startup to initialize
78 * the q40 IRQ handling routines.
83 void __init
q40_init_IRQ(void)
85 m68k_setup_irq_controller(&q40_irq_chip
, handle_simple_irq
, 1,
88 /* setup handler for ISA ints */
89 m68k_setup_auto_interrupt(q40_irq_handler
);
91 m68k_irq_startup_irq(IRQ_AUTO_2
);
92 m68k_irq_startup_irq(IRQ_AUTO_4
);
94 /* now enable some ints.. */
95 master_outb(1, EXT_ENABLE_REG
); /* ISA IRQ 5-15 */
97 /* make sure keyboard IRQ is disabled */
98 master_outb(0, KEY_IRQ_ENABLE_REG
);
103 * this stuff doesn't really belong here..
106 int ql_ticks
; /* 200Hz ticks since last jiffie */
107 static int sound_ticks
;
111 void q40_mksound(unsigned int hz
, unsigned int ticks
)
113 /* for now ignore hz, except that hz==0 switches off sound */
114 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
124 /* sound itself is done in q40_timer_int */
125 if (sound_ticks
== 0)
126 sound_ticks
= 1000; /* pretty long beep */
127 sound_ticks
= ticks
<< 1;
130 static irqreturn_t
q40_timer_int(int irq
, void *dev_id
)
132 irq_handler_t timer_routine
= dev_id
;
134 ql_ticks
= ql_ticks
? 0 : 1;
136 unsigned char sval
=(sound_ticks
& 1) ? 128-SVOL
: 128+SVOL
;
145 local_irq_save(flags
);
146 timer_routine(0, NULL
);
147 local_irq_restore(flags
);
152 void q40_sched_init (irq_handler_t timer_routine
)
156 timer_irq
= Q40_IRQ_FRAME
;
158 if (request_irq(timer_irq
, q40_timer_int
, 0, "timer", timer_routine
))
159 panic("Couldn't register timer int");
161 master_outb(-1, FRAME_CLEAR_REG
);
162 master_outb( 1, FRAME_RATE_REG
);
167 * tables to translate bits into IRQ numbers
168 * it is a good idea to order the entries by priority
172 struct IRQ_TABLE
{ unsigned mask
; int irq
;};
174 static struct IRQ_TABLE iirqs
[]={
175 {Q40_IRQ_FRAME_MASK
,Q40_IRQ_FRAME
},
176 {Q40_IRQ_KEYB_MASK
,Q40_IRQ_KEYBOARD
},
179 static struct IRQ_TABLE eirqs
[] = {
180 { .mask
= Q40_IRQ3_MASK
, .irq
= 3 }, /* ser 1 */
181 { .mask
= Q40_IRQ4_MASK
, .irq
= 4 }, /* ser 2 */
182 { .mask
= Q40_IRQ14_MASK
, .irq
= 14 }, /* IDE 1 */
183 { .mask
= Q40_IRQ15_MASK
, .irq
= 15 }, /* IDE 2 */
184 { .mask
= Q40_IRQ6_MASK
, .irq
= 6 }, /* floppy, handled elsewhere */
185 { .mask
= Q40_IRQ7_MASK
, .irq
= 7 }, /* par */
186 { .mask
= Q40_IRQ5_MASK
, .irq
= 5 },
187 { .mask
= Q40_IRQ10_MASK
, .irq
= 10 },
191 /* complain only this many times about spurious ints : */
192 static int ccleirq
=60; /* ISA dev IRQs*/
193 /*static int cclirq=60;*/ /* internal */
195 /* FIXME: add shared ints,mask,unmask,probing.... */
197 #define IRQ_INPROGRESS 1
198 /*static unsigned short saved_mask;*/
199 //static int do_tint=0;
202 /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
204 static int mext_disabled
=0; /* ext irq disabled by master chip? */
205 static int aliased_irq
=0; /* how many times inside handler ?*/
208 /* got interrupt, dispatch to ISA or keyboard/timer IRQs */
209 static void q40_irq_handler(unsigned int irq
, struct pt_regs
*fp
)
215 mir
= master_inb(IIRQ_REG
);
216 #ifdef CONFIG_BLK_DEV_FD
217 if ((mir
& Q40_IRQ_EXT_MASK
) &&
218 (master_inb(EIRQ_REG
) & Q40_IRQ6_MASK
)) {
226 do_IRQ(Q40_IRQ_SAMPLE
, fp
);
229 if (mir
& Q40_IRQ_FRAME_MASK
) {
230 do_IRQ(Q40_IRQ_FRAME
, fp
);
231 master_outb(-1, FRAME_CLEAR_REG
);
233 if ((mir
& Q40_IRQ_SER_MASK
) || (mir
& Q40_IRQ_EXT_MASK
)) {
234 mer
= master_inb(EIRQ_REG
);
235 for (i
= 0; eirqs
[i
].mask
; i
++) {
236 if (mer
& eirqs
[i
].mask
) {
239 * There is a little mess wrt which IRQ really caused this irq request. The
240 * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
241 * are read - which is long after the request came in. In theory IRQs should
242 * not just go away but they occasionally do
244 if (irq
> 4 && irq
<= 15 && mext_disabled
) {
248 if (q40_state
[irq
] & IRQ_INPROGRESS
) {
249 /* some handlers do local_irq_enable() for irq latency reasons, */
250 /* however reentering an active irq handler is not permitted */
251 #ifdef IP_USE_DISABLE
252 /* in theory this is the better way to do it because it still */
253 /* lets through eg the serial irqs, unfortunately it crashes */
257 /*pr_warn("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",
258 irq, disabled ? "already" : "not yet"); */
259 fp
->sr
= (((fp
->sr
) & (~0x700))+0x200);
264 q40_state
[irq
] |= IRQ_INPROGRESS
;
266 q40_state
[irq
] &= ~IRQ_INPROGRESS
;
268 /* naively enable everything, if that fails than */
269 /* this function will be reentered immediately thus */
270 /* getting another chance to disable the IRQ */
273 #ifdef IP_USE_DISABLE
280 /*pr_info("reenabling irq %d\n", irq); */
283 // used to do 'goto repeat;' here, this delayed bh processing too long
287 if (mer
&& ccleirq
> 0 && !aliased_irq
) {
288 pr_warn("ISA interrupt from unknown source? EIRQ_REG = %x\n",
294 mir
= master_inb(IIRQ_REG
);
295 /* should test whether keyboard irq is really enabled, doing it in defhand */
296 if (mir
& Q40_IRQ_KEYB_MASK
)
297 do_IRQ(Q40_IRQ_KEYBOARD
, fp
);
302 void q40_irq_enable(struct irq_data
*data
)
304 unsigned int irq
= data
->irq
;
306 if (irq
>= 5 && irq
<= 15) {
308 if (mext_disabled
> 0)
309 pr_warn("q40_irq_enable : nested disable/enable\n");
310 if (mext_disabled
== 0)
311 master_outb(1, EXT_ENABLE_REG
);
316 void q40_irq_disable(struct irq_data
*data
)
318 unsigned int irq
= data
->irq
;
320 /* disable ISA iqs : only do something if the driver has been
321 * verified to be Q40 "compatible" - right now IDE, NE2K
322 * Any driver should not attempt to sleep across disable_irq !!
325 if (irq
>= 5 && irq
<= 15) {
326 master_outb(0, EXT_ENABLE_REG
);
328 if (mext_disabled
> 1)
329 pr_info("disable_irq nesting count %d\n",