blob: cb245f972e1a61595cf007420da1ba779ee1c15b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/m68k/q40/q40ints.c
3 *
4 * Copyright (C) 1999,2001 Richard Zidlicky
5 *
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.
9 *
10 * .. used to be loosely based on bvme6000ints.c
11 *
12 */
13
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/ptrace.h>
20#include <asm/system.h>
21#include <asm/irq.h>
22#include <asm/traps.h>
23
24#include <asm/q40_master.h>
25#include <asm/q40ints.h>
26
27/*
28 * Q40 IRQs are defined as follows:
29 * 3,4,5,6,7,10,11,14,15 : ISA dev IRQs
30 * 16-31: reserved
31 * 32 : keyboard int
32 * 33 : frame int (50/200 Hz periodic timer)
33 * 34 : sample int (10/20 KHz periodic timer)
34 *
35*/
36
Roman Zippel77dda332006-06-25 05:47:05 -070037static void q40_irq_handler(unsigned int, struct pt_regs *fp);
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020038static void q40_irq_enable(struct irq_data *data);
39static void q40_irq_disable(struct irq_data *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Roman Zippel77dda332006-06-25 05:47:05 -070041unsigned short q40_ablecount[35];
42unsigned short q40_state[35];
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020044static unsigned int q40_irq_startup(struct irq_data *data)
Roman Zippel77dda332006-06-25 05:47:05 -070045{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020046 unsigned int irq = data->irq;
47
Roman Zippel77dda332006-06-25 05:47:05 -070048 /* test for ISA ints not implemented by HW */
49 switch (irq) {
50 case 1: case 2: case 8: case 9:
51 case 11: case 12: case 13:
Harvey Harrisonf85e7cd2008-04-28 02:13:49 -070052 printk("%s: ISA IRQ %d not implemented by HW\n", __func__, irq);
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020053 /* FIXME return -ENXIO; */
Roman Zippel77dda332006-06-25 05:47:05 -070054 }
55 return 0;
56}
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020058static void q40_irq_shutdown(struct irq_data *data)
Roman Zippel77dda332006-06-25 05:47:05 -070059{
60}
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020062static struct irq_chip q40_irq_chip = {
Roman Zippel77dda332006-06-25 05:47:05 -070063 .name = "q40",
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020064 .irq_startup = q40_irq_startup,
65 .irq_shutdown = q40_irq_shutdown,
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020066 .irq_enable = q40_irq_enable,
67 .irq_disable = q40_irq_disable,
Roman Zippel77dda332006-06-25 05:47:05 -070068};
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70/*
71 * void q40_init_IRQ (void)
72 *
73 * Parameters: None
74 *
75 * Returns: Nothing
76 *
77 * This function is called during kernel startup to initialize
78 * the q40 IRQ handling routines.
79 */
80
Roman Zippel77dda332006-06-25 05:47:05 -070081static int disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Al Viro66a3f822007-07-20 04:33:28 +010083void __init q40_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020085 m68k_setup_irq_chip(&q40_irq_chip, 1, Q40_IRQ_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 /* setup handler for ISA ints */
Roman Zippel77dda332006-06-25 05:47:05 -070088 m68k_setup_auto_interrupt(q40_irq_handler);
89
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020090 m68k_irq_startup_irq(IRQ_AUTO_2);
91 m68k_irq_startup_irq(IRQ_AUTO_4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 /* now enable some ints.. */
Roman Zippel77dda332006-06-25 05:47:05 -070094 master_outb(1, EXT_ENABLE_REG); /* ISA IRQ 5-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /* make sure keyboard IRQ is disabled */
Roman Zippel77dda332006-06-25 05:47:05 -070097 master_outb(0, KEY_IRQ_ENABLE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101/*
102 * this stuff doesn't really belong here..
Roman Zippel77dda332006-06-25 05:47:05 -0700103 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105int ql_ticks; /* 200Hz ticks since last jiffie */
106static int sound_ticks;
107
108#define SVOL 45
109
110void q40_mksound(unsigned int hz, unsigned int ticks)
111{
Roman Zippel77dda332006-06-25 05:47:05 -0700112 /* for now ignore hz, except that hz==0 switches off sound */
113 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
114 if (hz == 0) {
115 if (sound_ticks)
116 sound_ticks = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Roman Zippel77dda332006-06-25 05:47:05 -0700118 *DAC_LEFT = 128;
119 *DAC_RIGHT = 128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Roman Zippel77dda332006-06-25 05:47:05 -0700121 return;
122 }
123 /* sound itself is done in q40_timer_int */
124 if (sound_ticks == 0)
125 sound_ticks = 1000; /* pretty long beep */
126 sound_ticks = ticks << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127}
128
David Howells40220c12006-10-09 12:19:47 +0100129static irq_handler_t q40_timer_routine;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Al Viro2850bc22006-10-07 14:16:45 +0100131static irqreturn_t q40_timer_int (int irq, void * dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Roman Zippel77dda332006-06-25 05:47:05 -0700133 ql_ticks = ql_ticks ? 0 : 1;
134 if (sound_ticks) {
135 unsigned char sval=(sound_ticks & 1) ? 128-SVOL : 128+SVOL;
136 sound_ticks--;
137 *DAC_LEFT=sval;
138 *DAC_RIGHT=sval;
139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Roman Zippel77dda332006-06-25 05:47:05 -0700141 if (!ql_ticks)
Al Viro2850bc22006-10-07 14:16:45 +0100142 q40_timer_routine(irq, dev);
Roman Zippel77dda332006-06-25 05:47:05 -0700143 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
David Howells40220c12006-10-09 12:19:47 +0100146void q40_sched_init (irq_handler_t timer_routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Roman Zippel77dda332006-06-25 05:47:05 -0700148 int timer_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Roman Zippel77dda332006-06-25 05:47:05 -0700150 q40_timer_routine = timer_routine;
151 timer_irq = Q40_IRQ_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Roman Zippel77dda332006-06-25 05:47:05 -0700153 if (request_irq(timer_irq, q40_timer_int, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 "timer", q40_timer_int))
Roman Zippel77dda332006-06-25 05:47:05 -0700155 panic("Couldn't register timer int");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Roman Zippel77dda332006-06-25 05:47:05 -0700157 master_outb(-1, FRAME_CLEAR_REG);
158 master_outb( 1, FRAME_RATE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161
162/*
163 * tables to translate bits into IRQ numbers
164 * it is a good idea to order the entries by priority
165 *
166*/
167
168struct IRQ_TABLE{ unsigned mask; int irq ;};
169#if 0
170static struct IRQ_TABLE iirqs[]={
171 {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
172 {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
173 {0,0}};
174#endif
175static struct IRQ_TABLE eirqs[] = {
176 { .mask = Q40_IRQ3_MASK, .irq = 3 }, /* ser 1 */
177 { .mask = Q40_IRQ4_MASK, .irq = 4 }, /* ser 2 */
178 { .mask = Q40_IRQ14_MASK, .irq = 14 }, /* IDE 1 */
179 { .mask = Q40_IRQ15_MASK, .irq = 15 }, /* IDE 2 */
180 { .mask = Q40_IRQ6_MASK, .irq = 6 }, /* floppy, handled elsewhere */
181 { .mask = Q40_IRQ7_MASK, .irq = 7 }, /* par */
182 { .mask = Q40_IRQ5_MASK, .irq = 5 },
183 { .mask = Q40_IRQ10_MASK, .irq = 10 },
184 {0,0}
185};
186
187/* complain only this many times about spurious ints : */
Simon Arlott0c79cf62007-10-20 01:20:32 +0200188static int ccleirq=60; /* ISA dev IRQs*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189/*static int cclirq=60;*/ /* internal */
190
191/* FIXME: add shared ints,mask,unmask,probing.... */
192
193#define IRQ_INPROGRESS 1
194/*static unsigned short saved_mask;*/
195//static int do_tint=0;
196
197#define DEBUG_Q40INT
198/*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
199
200static int mext_disabled=0; /* ext irq disabled by master chip? */
201static int aliased_irq=0; /* how many times inside handler ?*/
202
203
Roman Zippel77dda332006-06-25 05:47:05 -0700204/* got interrupt, dispatch to ISA or keyboard/timer IRQs */
205static void q40_irq_handler(unsigned int irq, struct pt_regs *fp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Roman Zippel77dda332006-06-25 05:47:05 -0700207 unsigned mir, mer;
208 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210//repeat:
Roman Zippel77dda332006-06-25 05:47:05 -0700211 mir = master_inb(IIRQ_REG);
212#ifdef CONFIG_BLK_DEV_FD
213 if ((mir & Q40_IRQ_EXT_MASK) &&
214 (master_inb(EIRQ_REG) & Q40_IRQ6_MASK)) {
215 floppy_hardint();
216 return;
217 }
218#endif
219 switch (irq) {
220 case 4:
221 case 6:
Al Viro2850bc22006-10-07 14:16:45 +0100222 __m68k_handle_int(Q40_IRQ_SAMPLE, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700223 return;
224 }
225 if (mir & Q40_IRQ_FRAME_MASK) {
Al Viro2850bc22006-10-07 14:16:45 +0100226 __m68k_handle_int(Q40_IRQ_FRAME, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700227 master_outb(-1, FRAME_CLEAR_REG);
228 }
229 if ((mir & Q40_IRQ_SER_MASK) || (mir & Q40_IRQ_EXT_MASK)) {
230 mer = master_inb(EIRQ_REG);
231 for (i = 0; eirqs[i].mask; i++) {
232 if (mer & eirqs[i].mask) {
233 irq = eirqs[i].irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/*
235 * There is a little mess wrt which IRQ really caused this irq request. The
236 * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
237 * are read - which is long after the request came in. In theory IRQs should
Simon Arlott0c79cf62007-10-20 01:20:32 +0200238 * not just go away but they occasionally do
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
Roman Zippel77dda332006-06-25 05:47:05 -0700240 if (irq > 4 && irq <= 15 && mext_disabled) {
241 /*aliased_irq++;*/
242 goto iirq;
243 }
244 if (q40_state[irq] & IRQ_INPROGRESS) {
245 /* some handlers do local_irq_enable() for irq latency reasons, */
246 /* however reentering an active irq handler is not permitted */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247#ifdef IP_USE_DISABLE
Roman Zippel77dda332006-06-25 05:47:05 -0700248 /* in theory this is the better way to do it because it still */
249 /* lets through eg the serial irqs, unfortunately it crashes */
250 disable_irq(irq);
251 disabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252#else
Roman Zippel77dda332006-06-25 05:47:05 -0700253 /*printk("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",
254 irq, disabled ? "already" : "not yet"); */
255 fp->sr = (((fp->sr) & (~0x700))+0x200);
256 disabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257#endif
Roman Zippel77dda332006-06-25 05:47:05 -0700258 goto iirq;
259 }
260 q40_state[irq] |= IRQ_INPROGRESS;
Al Viro2850bc22006-10-07 14:16:45 +0100261 __m68k_handle_int(irq, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700262 q40_state[irq] &= ~IRQ_INPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Roman Zippel77dda332006-06-25 05:47:05 -0700264 /* naively enable everything, if that fails than */
265 /* this function will be reentered immediately thus */
266 /* getting another chance to disable the IRQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Roman Zippel77dda332006-06-25 05:47:05 -0700268 if (disabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#ifdef IP_USE_DISABLE
Roman Zippel77dda332006-06-25 05:47:05 -0700270 if (irq > 4) {
271 disabled = 0;
272 enable_irq(irq);
273 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#else
Roman Zippel77dda332006-06-25 05:47:05 -0700275 disabled = 0;
276 /*printk("reenabling irq %d\n", irq); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277#endif
Roman Zippel77dda332006-06-25 05:47:05 -0700278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279// used to do 'goto repeat;' here, this delayed bh processing too long
Roman Zippel77dda332006-06-25 05:47:05 -0700280 return;
281 }
282 }
283 if (mer && ccleirq > 0 && !aliased_irq) {
284 printk("ISA interrupt from unknown source? EIRQ_REG = %x\n",mer);
285 ccleirq--;
286 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
Roman Zippel77dda332006-06-25 05:47:05 -0700288 iirq:
289 mir = master_inb(IIRQ_REG);
290 /* should test whether keyboard irq is really enabled, doing it in defhand */
291 if (mir & Q40_IRQ_KEYB_MASK)
Al Viro2850bc22006-10-07 14:16:45 +0100292 __m68k_handle_int(Q40_IRQ_KEYBOARD, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700293
294 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200297void q40_irq_enable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200299 unsigned int irq = data->irq;
300
Roman Zippel77dda332006-06-25 05:47:05 -0700301 if (irq >= 5 && irq <= 15) {
302 mext_disabled--;
303 if (mext_disabled > 0)
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200304 printk("q40_irq_enable : nested disable/enable\n");
Roman Zippel77dda332006-06-25 05:47:05 -0700305 if (mext_disabled == 0)
306 master_outb(1, EXT_ENABLE_REG);
307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200311void q40_irq_disable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200313 unsigned int irq = data->irq;
314
Roman Zippel77dda332006-06-25 05:47:05 -0700315 /* disable ISA iqs : only do something if the driver has been
316 * verified to be Q40 "compatible" - right now IDE, NE2K
317 * Any driver should not attempt to sleep across disable_irq !!
318 */
319
320 if (irq >= 5 && irq <= 15) {
321 master_outb(0, EXT_ENABLE_REG);
322 mext_disabled++;
323 if (mext_disabled > 1)
324 printk("disable_irq nesting count %d\n",mext_disabled);
325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
Roman Zippel77dda332006-06-25 05:47:05 -0700328unsigned long q40_probe_irq_on(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
Roman Zippel77dda332006-06-25 05:47:05 -0700330 printk("irq probing not working - reconfigure the driver to avoid this\n");
331 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
Roman Zippel77dda332006-06-25 05:47:05 -0700333int q40_probe_irq_off(unsigned long irqs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
Roman Zippel77dda332006-06-25 05:47:05 -0700335 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}