q40ints.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  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. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <asm/machdep.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/traps.h>
  21. #include <asm/q40_master.h>
  22. #include <asm/q40ints.h>
  23. /*
  24. * Q40 IRQs are defined as follows:
  25. * 3,4,5,6,7,10,11,14,15 : ISA dev IRQs
  26. * 16-31: reserved
  27. * 32 : keyboard int
  28. * 33 : frame int (50/200 Hz periodic timer)
  29. * 34 : sample int (10/20 KHz periodic timer)
  30. *
  31. */
  32. static void q40_irq_handler(unsigned int, struct pt_regs *fp);
  33. static void q40_irq_enable(struct irq_data *data);
  34. static void q40_irq_disable(struct irq_data *data);
  35. unsigned short q40_ablecount[35];
  36. unsigned short q40_state[35];
  37. static unsigned int q40_irq_startup(struct irq_data *data)
  38. {
  39. unsigned int irq = data->irq;
  40. /* test for ISA ints not implemented by HW */
  41. switch (irq) {
  42. case 1: case 2: case 8: case 9:
  43. case 11: case 12: case 13:
  44. pr_warn("%s: ISA IRQ %d not implemented by HW\n", __func__,
  45. irq);
  46. /* FIXME return -ENXIO; */
  47. }
  48. return 0;
  49. }
  50. static void q40_irq_shutdown(struct irq_data *data)
  51. {
  52. }
  53. static struct irq_chip q40_irq_chip = {
  54. .name = "q40",
  55. .irq_startup = q40_irq_startup,
  56. .irq_shutdown = q40_irq_shutdown,
  57. .irq_enable = q40_irq_enable,
  58. .irq_disable = q40_irq_disable,
  59. };
  60. /*
  61. * void q40_init_IRQ (void)
  62. *
  63. * Parameters: None
  64. *
  65. * Returns: Nothing
  66. *
  67. * This function is called during kernel startup to initialize
  68. * the q40 IRQ handling routines.
  69. */
  70. static int disabled;
  71. void __init q40_init_IRQ(void)
  72. {
  73. m68k_setup_irq_controller(&q40_irq_chip, handle_simple_irq, 1,
  74. Q40_IRQ_MAX);
  75. /* setup handler for ISA ints */
  76. m68k_setup_auto_interrupt(q40_irq_handler);
  77. m68k_irq_startup_irq(IRQ_AUTO_2);
  78. m68k_irq_startup_irq(IRQ_AUTO_4);
  79. /* now enable some ints.. */
  80. master_outb(1, EXT_ENABLE_REG); /* ISA IRQ 5-15 */
  81. /* make sure keyboard IRQ is disabled */
  82. master_outb(0, KEY_IRQ_ENABLE_REG);
  83. }
  84. /*
  85. * this stuff doesn't really belong here..
  86. */
  87. int ql_ticks; /* 200Hz ticks since last jiffie */
  88. static int sound_ticks;
  89. #define SVOL 45
  90. void q40_mksound(unsigned int hz, unsigned int ticks)
  91. {
  92. /* for now ignore hz, except that hz==0 switches off sound */
  93. /* simply alternate the ampl (128-SVOL)-(128+SVOL)-..-.. at 200Hz */
  94. if (hz == 0) {
  95. if (sound_ticks)
  96. sound_ticks = 1;
  97. *DAC_LEFT = 128;
  98. *DAC_RIGHT = 128;
  99. return;
  100. }
  101. /* sound itself is done in q40_timer_int */
  102. if (sound_ticks == 0)
  103. sound_ticks = 1000; /* pretty long beep */
  104. sound_ticks = ticks << 1;
  105. }
  106. static irqreturn_t q40_timer_int(int irq, void *dev_id)
  107. {
  108. ql_ticks = ql_ticks ? 0 : 1;
  109. if (sound_ticks) {
  110. unsigned char sval=(sound_ticks & 1) ? 128-SVOL : 128+SVOL;
  111. sound_ticks--;
  112. *DAC_LEFT=sval;
  113. *DAC_RIGHT=sval;
  114. }
  115. if (!ql_ticks) {
  116. unsigned long flags;
  117. local_irq_save(flags);
  118. legacy_timer_tick(1);
  119. timer_heartbeat();
  120. local_irq_restore(flags);
  121. }
  122. return IRQ_HANDLED;
  123. }
  124. void q40_sched_init (void)
  125. {
  126. int timer_irq;
  127. timer_irq = Q40_IRQ_FRAME;
  128. if (request_irq(timer_irq, q40_timer_int, 0, "timer", NULL))
  129. panic("Couldn't register timer int");
  130. master_outb(-1, FRAME_CLEAR_REG);
  131. master_outb( 1, FRAME_RATE_REG);
  132. }
  133. /*
  134. * tables to translate bits into IRQ numbers
  135. * it is a good idea to order the entries by priority
  136. *
  137. */
  138. struct IRQ_TABLE{ unsigned mask; int irq ;};
  139. #if 0
  140. static struct IRQ_TABLE iirqs[]={
  141. {Q40_IRQ_FRAME_MASK,Q40_IRQ_FRAME},
  142. {Q40_IRQ_KEYB_MASK,Q40_IRQ_KEYBOARD},
  143. {0,0}};
  144. #endif
  145. static struct IRQ_TABLE eirqs[] = {
  146. { .mask = Q40_IRQ3_MASK, .irq = 3 }, /* ser 1 */
  147. { .mask = Q40_IRQ4_MASK, .irq = 4 }, /* ser 2 */
  148. { .mask = Q40_IRQ14_MASK, .irq = 14 }, /* IDE 1 */
  149. { .mask = Q40_IRQ15_MASK, .irq = 15 }, /* IDE 2 */
  150. { .mask = Q40_IRQ6_MASK, .irq = 6 }, /* floppy, handled elsewhere */
  151. { .mask = Q40_IRQ7_MASK, .irq = 7 }, /* par */
  152. { .mask = Q40_IRQ5_MASK, .irq = 5 },
  153. { .mask = Q40_IRQ10_MASK, .irq = 10 },
  154. {0,0}
  155. };
  156. /* complain only this many times about spurious ints : */
  157. static int ccleirq=60; /* ISA dev IRQs*/
  158. /*static int cclirq=60;*/ /* internal */
  159. /* FIXME: add shared ints,mask,unmask,probing.... */
  160. #define IRQ_INPROGRESS 1
  161. /*static unsigned short saved_mask;*/
  162. //static int do_tint=0;
  163. #define DEBUG_Q40INT
  164. /*#define IP_USE_DISABLE *//* would be nice, but crashes ???? */
  165. static int mext_disabled=0; /* ext irq disabled by master chip? */
  166. static int aliased_irq=0; /* how many times inside handler ?*/
  167. /* got interrupt, dispatch to ISA or keyboard/timer IRQs */
  168. static void q40_irq_handler(unsigned int irq, struct pt_regs *fp)
  169. {
  170. unsigned mir, mer;
  171. int i;
  172. //repeat:
  173. mir = master_inb(IIRQ_REG);
  174. #ifdef CONFIG_BLK_DEV_FD
  175. if ((mir & Q40_IRQ_EXT_MASK) &&
  176. (master_inb(EIRQ_REG) & Q40_IRQ6_MASK)) {
  177. floppy_hardint();
  178. return;
  179. }
  180. #endif
  181. switch (irq) {
  182. case 4:
  183. case 6:
  184. do_IRQ(Q40_IRQ_SAMPLE, fp);
  185. return;
  186. }
  187. if (mir & Q40_IRQ_FRAME_MASK) {
  188. do_IRQ(Q40_IRQ_FRAME, fp);
  189. master_outb(-1, FRAME_CLEAR_REG);
  190. }
  191. if ((mir & Q40_IRQ_SER_MASK) || (mir & Q40_IRQ_EXT_MASK)) {
  192. mer = master_inb(EIRQ_REG);
  193. for (i = 0; eirqs[i].mask; i++) {
  194. if (mer & eirqs[i].mask) {
  195. irq = eirqs[i].irq;
  196. /*
  197. * There is a little mess wrt which IRQ really caused this irq request. The
  198. * main problem is that IIRQ_REG and EIRQ_REG reflect the state when they
  199. * are read - which is long after the request came in. In theory IRQs should
  200. * not just go away but they occasionally do
  201. */
  202. if (irq > 4 && irq <= 15 && mext_disabled) {
  203. /*aliased_irq++;*/
  204. goto iirq;
  205. }
  206. if (q40_state[irq] & IRQ_INPROGRESS) {
  207. /* some handlers do local_irq_enable() for irq latency reasons, */
  208. /* however reentering an active irq handler is not permitted */
  209. #ifdef IP_USE_DISABLE
  210. /* in theory this is the better way to do it because it still */
  211. /* lets through eg the serial irqs, unfortunately it crashes */
  212. disable_irq(irq);
  213. disabled = 1;
  214. #else
  215. /*pr_warn("IRQ_INPROGRESS detected for irq %d, disabling - %s disabled\n",
  216. irq, disabled ? "already" : "not yet"); */
  217. fp->sr = (((fp->sr) & (~0x700))+0x200);
  218. disabled = 1;
  219. #endif
  220. goto iirq;
  221. }
  222. q40_state[irq] |= IRQ_INPROGRESS;
  223. do_IRQ(irq, fp);
  224. q40_state[irq] &= ~IRQ_INPROGRESS;
  225. /* naively enable everything, if that fails than */
  226. /* this function will be reentered immediately thus */
  227. /* getting another chance to disable the IRQ */
  228. if (disabled) {
  229. #ifdef IP_USE_DISABLE
  230. if (irq > 4) {
  231. disabled = 0;
  232. enable_irq(irq);
  233. }
  234. #else
  235. disabled = 0;
  236. /*pr_info("reenabling irq %d\n", irq); */
  237. #endif
  238. }
  239. // used to do 'goto repeat;' here, this delayed bh processing too long
  240. return;
  241. }
  242. }
  243. if (mer && ccleirq > 0 && !aliased_irq) {
  244. pr_warn("ISA interrupt from unknown source? EIRQ_REG = %x\n",
  245. mer);
  246. ccleirq--;
  247. }
  248. }
  249. iirq:
  250. mir = master_inb(IIRQ_REG);
  251. /* should test whether keyboard irq is really enabled, doing it in defhand */
  252. if (mir & Q40_IRQ_KEYB_MASK)
  253. do_IRQ(Q40_IRQ_KEYBOARD, fp);
  254. return;
  255. }
  256. void q40_irq_enable(struct irq_data *data)
  257. {
  258. unsigned int irq = data->irq;
  259. if (irq >= 5 && irq <= 15) {
  260. mext_disabled--;
  261. if (mext_disabled > 0)
  262. pr_warn("q40_irq_enable : nested disable/enable\n");
  263. if (mext_disabled == 0)
  264. master_outb(1, EXT_ENABLE_REG);
  265. }
  266. }
  267. void q40_irq_disable(struct irq_data *data)
  268. {
  269. unsigned int irq = data->irq;
  270. /* disable ISA iqs : only do something if the driver has been
  271. * verified to be Q40 "compatible" - right now IDE, NE2K
  272. * Any driver should not attempt to sleep across disable_irq !!
  273. */
  274. if (irq >= 5 && irq <= 15) {
  275. master_outb(0, EXT_ENABLE_REG);
  276. mext_disabled++;
  277. if (mext_disabled > 1)
  278. pr_info("disable_irq nesting count %d\n",
  279. mext_disabled);
  280. }
  281. }