blob: 6886a5d0007b1eab15a77b1947c1937d2e5b93e7 [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>
Geert Uytterhoevena03010e2011-08-18 14:47:16 +020018#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Arnd Bergmannd6444092020-09-24 16:37:37 +020020#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/ptrace.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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:
Geert Uytterhoeven446926f2016-12-06 17:11:01 +010052 pr_warn("%s: ISA IRQ %d not implemented by HW\n", __func__,
53 irq);
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020054 /* FIXME return -ENXIO; */
Roman Zippel77dda332006-06-25 05:47:05 -070055 }
56 return 0;
57}
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020059static void q40_irq_shutdown(struct irq_data *data)
Roman Zippel77dda332006-06-25 05:47:05 -070060{
61}
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020063static struct irq_chip q40_irq_chip = {
Roman Zippel77dda332006-06-25 05:47:05 -070064 .name = "q40",
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +020065 .irq_startup = q40_irq_startup,
66 .irq_shutdown = q40_irq_shutdown,
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020067 .irq_enable = q40_irq_enable,
68 .irq_disable = q40_irq_disable,
Roman Zippel77dda332006-06-25 05:47:05 -070069};
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/*
72 * void q40_init_IRQ (void)
73 *
74 * Parameters: None
75 *
76 * Returns: Nothing
77 *
78 * This function is called during kernel startup to initialize
79 * the q40 IRQ handling routines.
80 */
81
Roman Zippel77dda332006-06-25 05:47:05 -070082static int disabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Al Viro66a3f822007-07-20 04:33:28 +010084void __init q40_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
Geert Uytterhoevenedb34722011-06-01 11:15:21 +020086 m68k_setup_irq_controller(&q40_irq_chip, handle_simple_irq, 1,
87 Q40_IRQ_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 /* setup handler for ISA ints */
Roman Zippel77dda332006-06-25 05:47:05 -070090 m68k_setup_auto_interrupt(q40_irq_handler);
91
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +020092 m68k_irq_startup_irq(IRQ_AUTO_2);
93 m68k_irq_startup_irq(IRQ_AUTO_4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 /* now enable some ints.. */
Roman Zippel77dda332006-06-25 05:47:05 -070096 master_outb(1, EXT_ENABLE_REG); /* ISA IRQ 5-15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 /* make sure keyboard IRQ is disabled */
Roman Zippel77dda332006-06-25 05:47:05 -070099 master_outb(0, KEY_IRQ_ENABLE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/*
104 * this stuff doesn't really belong here..
Roman Zippel77dda332006-06-25 05:47:05 -0700105 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107int ql_ticks; /* 200Hz ticks since last jiffie */
108static int sound_ticks;
109
110#define SVOL 45
111
112void q40_mksound(unsigned int hz, unsigned int ticks)
113{
Roman Zippel77dda332006-06-25 05:47:05 -0700114 /* for now ignore hz, except that hz==0 switches off sound */
115 /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
116 if (hz == 0) {
117 if (sound_ticks)
118 sound_ticks = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Roman Zippel77dda332006-06-25 05:47:05 -0700120 *DAC_LEFT = 128;
121 *DAC_RIGHT = 128;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Roman Zippel77dda332006-06-25 05:47:05 -0700123 return;
124 }
125 /* sound itself is done in q40_timer_int */
126 if (sound_ticks == 0)
127 sound_ticks = 1000; /* pretty long beep */
128 sound_ticks = ticks << 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
Finn Thain1efdd4b2018-12-01 11:53:10 +1100131static irqreturn_t q40_timer_int(int irq, void *dev_id)
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
Finn Thain1efdd4b2018-12-01 11:53:10 +1100141 if (!ql_ticks) {
142 unsigned long flags;
143
144 local_irq_save(flags);
Arnd Bergmann42f1d572020-09-24 17:21:00 +0200145 legacy_timer_tick(1);
Arnd Bergmannd6444092020-09-24 16:37:37 +0200146 timer_heartbeat();
Finn Thain1efdd4b2018-12-01 11:53:10 +1100147 local_irq_restore(flags);
148 }
Roman Zippel77dda332006-06-25 05:47:05 -0700149 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Arnd Bergmannf9a01532020-09-24 17:29:17 +0200152void q40_sched_init (void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Roman Zippel77dda332006-06-25 05:47:05 -0700154 int timer_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Roman Zippel77dda332006-06-25 05:47:05 -0700156 timer_irq = Q40_IRQ_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Arnd Bergmann42f1d572020-09-24 17:21:00 +0200158 if (request_irq(timer_irq, q40_timer_int, 0, "timer", NULL))
Roman Zippel77dda332006-06-25 05:47:05 -0700159 panic("Couldn't register timer int");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Roman Zippel77dda332006-06-25 05:47:05 -0700161 master_outb(-1, FRAME_CLEAR_REG);
162 master_outb( 1, FRAME_RATE_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165
166/*
167 * tables to translate bits into IRQ numbers
168 * it is a good idea to order the entries by priority
169 *
170*/
171
172struct IRQ_TABLE{ unsigned mask; int irq ;};
173#if 0
174static struct IRQ_TABLE iirqs[]={
175 {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
176 {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
177 {0,0}};
178#endif
179static 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 },
188 {0,0}
189};
190
191/* complain only this many times about spurious ints : */
Simon Arlott0c79cf62007-10-20 01:20:32 +0200192static int ccleirq=60; /* ISA dev IRQs*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193/*static int cclirq=60;*/ /* internal */
194
195/* FIXME: add shared ints,mask,unmask,probing.... */
196
197#define IRQ_INPROGRESS 1
198/*static unsigned short saved_mask;*/
199//static int do_tint=0;
200
201#define DEBUG_Q40INT
202/*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
203
204static int mext_disabled=0; /* ext irq disabled by master chip? */
205static int aliased_irq=0; /* how many times inside handler ?*/
206
207
Roman Zippel77dda332006-06-25 05:47:05 -0700208/* got interrupt, dispatch to ISA or keyboard/timer IRQs */
209static void q40_irq_handler(unsigned int irq, struct pt_regs *fp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Roman Zippel77dda332006-06-25 05:47:05 -0700211 unsigned mir, mer;
212 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214//repeat:
Roman Zippel77dda332006-06-25 05:47:05 -0700215 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)) {
219 floppy_hardint();
220 return;
221 }
222#endif
223 switch (irq) {
224 case 4:
225 case 6:
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200226 do_IRQ(Q40_IRQ_SAMPLE, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700227 return;
228 }
229 if (mir & Q40_IRQ_FRAME_MASK) {
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200230 do_IRQ(Q40_IRQ_FRAME, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700231 master_outb(-1, FRAME_CLEAR_REG);
232 }
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) {
237 irq = eirqs[i].irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
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
Simon Arlott0c79cf62007-10-20 01:20:32 +0200242 * not just go away but they occasionally do
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 */
Roman Zippel77dda332006-06-25 05:47:05 -0700244 if (irq > 4 && irq <= 15 && mext_disabled) {
245 /*aliased_irq++;*/
246 goto iirq;
247 }
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251#ifdef IP_USE_DISABLE
Roman Zippel77dda332006-06-25 05:47:05 -0700252 /* in theory this is the better way to do it because it still */
253 /* lets through eg the serial irqs, unfortunately it crashes */
254 disable_irq(irq);
255 disabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256#else
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100257 /*pr_warn("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",
Roman Zippel77dda332006-06-25 05:47:05 -0700258 irq, disabled ? "already" : "not yet"); */
259 fp->sr = (((fp->sr) & (~0x700))+0x200);
260 disabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#endif
Roman Zippel77dda332006-06-25 05:47:05 -0700262 goto iirq;
263 }
264 q40_state[irq] |= IRQ_INPROGRESS;
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200265 do_IRQ(irq, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700266 q40_state[irq] &= ~IRQ_INPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Roman Zippel77dda332006-06-25 05:47:05 -0700268 /* naively enable everything, if that fails than */
269 /* this function will be reentered immediately thus */
270 /* getting another chance to disable the IRQ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Roman Zippel77dda332006-06-25 05:47:05 -0700272 if (disabled) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#ifdef IP_USE_DISABLE
Roman Zippel77dda332006-06-25 05:47:05 -0700274 if (irq > 4) {
275 disabled = 0;
276 enable_irq(irq);
277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278#else
Roman Zippel77dda332006-06-25 05:47:05 -0700279 disabled = 0;
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100280 /*pr_info("reenabling irq %d\n", irq); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281#endif
Roman Zippel77dda332006-06-25 05:47:05 -0700282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283// used to do 'goto repeat;' here, this delayed bh processing too long
Roman Zippel77dda332006-06-25 05:47:05 -0700284 return;
285 }
286 }
287 if (mer && ccleirq > 0 && !aliased_irq) {
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100288 pr_warn("ISA interrupt from unknown source? EIRQ_REG = %x\n",
289 mer);
Roman Zippel77dda332006-06-25 05:47:05 -0700290 ccleirq--;
291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
Roman Zippel77dda332006-06-25 05:47:05 -0700293 iirq:
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)
Geert Uytterhoeven1425df82011-07-01 20:39:19 +0200297 do_IRQ(Q40_IRQ_KEYBOARD, fp);
Roman Zippel77dda332006-06-25 05:47:05 -0700298
299 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200302void q40_irq_enable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200304 unsigned int irq = data->irq;
305
Roman Zippel77dda332006-06-25 05:47:05 -0700306 if (irq >= 5 && irq <= 15) {
307 mext_disabled--;
308 if (mext_disabled > 0)
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100309 pr_warn("q40_irq_enable : nested disable/enable\n");
Roman Zippel77dda332006-06-25 05:47:05 -0700310 if (mext_disabled == 0)
311 master_outb(1, EXT_ENABLE_REG);
312 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200316void q40_irq_disable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200318 unsigned int irq = data->irq;
319
Roman Zippel77dda332006-06-25 05:47:05 -0700320 /* 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 !!
323 */
324
325 if (irq >= 5 && irq <= 15) {
326 master_outb(0, EXT_ENABLE_REG);
327 mext_disabled++;
328 if (mext_disabled > 1)
Geert Uytterhoeven446926f2016-12-06 17:11:01 +0100329 pr_info("disable_irq nesting count %d\n",
330 mext_disabled);
Roman Zippel77dda332006-06-25 05:47:05 -0700331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}