irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1992 Linus Torvalds
  7. * Copyright (C) 1994 - 2001, 2003 Ralf Baechle
  8. */
  9. #include <linux/init.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/kernel.h>
  12. #include <linux/spinlock.h>
  13. #include <asm/i8259.h>
  14. #include <asm/io.h>
  15. #include <asm/jazz.h>
  16. static DEFINE_SPINLOCK(r4030_lock);
  17. static void enable_r4030_irq(unsigned int irq)
  18. {
  19. unsigned int mask = 1 << (irq - JAZZ_PARALLEL_IRQ);
  20. unsigned long flags;
  21. spin_lock_irqsave(&r4030_lock, flags);
  22. mask |= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
  23. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
  24. spin_unlock_irqrestore(&r4030_lock, flags);
  25. }
  26. static unsigned int startup_r4030_irq(unsigned int irq)
  27. {
  28. enable_r4030_irq(irq);
  29. return 0; /* never anything pending */
  30. }
  31. #define shutdown_r4030_irq disable_r4030_irq
  32. void disable_r4030_irq(unsigned int irq)
  33. {
  34. unsigned int mask = ~(1 << (irq - JAZZ_PARALLEL_IRQ));
  35. unsigned long flags;
  36. spin_lock_irqsave(&r4030_lock, flags);
  37. mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
  38. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
  39. spin_unlock_irqrestore(&r4030_lock, flags);
  40. }
  41. #define mask_and_ack_r4030_irq disable_r4030_irq
  42. static void end_r4030_irq(unsigned int irq)
  43. {
  44. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  45. enable_r4030_irq(irq);
  46. }
  47. static struct hw_interrupt_type r4030_irq_type = {
  48. .typename = "R4030",
  49. .startup = startup_r4030_irq,
  50. .shutdown = shutdown_r4030_irq,
  51. .enable = enable_r4030_irq,
  52. .disable = disable_r4030_irq,
  53. .ack = mask_and_ack_r4030_irq,
  54. .end = end_r4030_irq,
  55. };
  56. void __init init_r4030_ints(void)
  57. {
  58. int i;
  59. for (i = JAZZ_PARALLEL_IRQ; i <= JAZZ_TIMER_IRQ; i++) {
  60. irq_desc[i].status = IRQ_DISABLED;
  61. irq_desc[i].action = 0;
  62. irq_desc[i].depth = 1;
  63. irq_desc[i].handler = &r4030_irq_type;
  64. }
  65. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
  66. r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
  67. r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */
  68. }
  69. /*
  70. * On systems with i8259-style interrupt controllers we assume for
  71. * driver compatibility reasons interrupts 0 - 15 to be the i8259
  72. * interrupts even if the hardware uses a different interrupt numbering.
  73. */
  74. void __init arch_init_irq(void)
  75. {
  76. init_i8259_irqs(); /* Integrated i8259 */
  77. init_r4030_ints();
  78. change_c0_status(ST0_IM, IE_IRQ4 | IE_IRQ3 | IE_IRQ2 | IE_IRQ1);
  79. }
  80. static void loc_call(unsigned int irq, struct pt_regs *regs, unsigned int mask)
  81. {
  82. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE,
  83. r4030_read_reg16(JAZZ_IO_IRQ_ENABLE) & mask);
  84. do_IRQ(irq, regs);
  85. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE,
  86. r4030_read_reg16(JAZZ_IO_IRQ_ENABLE) | mask);
  87. }
  88. static void ll_local_dev(struct pt_regs *regs)
  89. {
  90. switch (r4030_read_reg32(JAZZ_IO_IRQ_SOURCE)) {
  91. case 0:
  92. panic("Unimplemented loc_no_irq handler");
  93. break;
  94. case 4:
  95. loc_call(JAZZ_PARALLEL_IRQ, regs, JAZZ_IE_PARALLEL);
  96. break;
  97. case 8:
  98. loc_call(JAZZ_PARALLEL_IRQ, regs, JAZZ_IE_FLOPPY);
  99. break;
  100. case 12:
  101. panic("Unimplemented loc_sound handler");
  102. break;
  103. case 16:
  104. panic("Unimplemented loc_video handler");
  105. break;
  106. case 20:
  107. loc_call(JAZZ_ETHERNET_IRQ, regs, JAZZ_IE_ETHERNET);
  108. break;
  109. case 24:
  110. loc_call(JAZZ_SCSI_IRQ, regs, JAZZ_IE_SCSI);
  111. break;
  112. case 28:
  113. loc_call(JAZZ_KEYBOARD_IRQ, regs, JAZZ_IE_KEYBOARD);
  114. break;
  115. case 32:
  116. loc_call(JAZZ_MOUSE_IRQ, regs, JAZZ_IE_MOUSE);
  117. break;
  118. case 36:
  119. loc_call(JAZZ_SERIAL1_IRQ, regs, JAZZ_IE_SERIAL1);
  120. break;
  121. case 40:
  122. loc_call(JAZZ_SERIAL2_IRQ, regs, JAZZ_IE_SERIAL2);
  123. break;
  124. }
  125. }
  126. asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
  127. {
  128. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  129. if (pending & IE_IRQ5)
  130. write_c0_compare(0);
  131. else if (pending & IE_IRQ4) {
  132. r4030_read_reg32(JAZZ_TIMER_REGISTER);
  133. do_IRQ(JAZZ_TIMER_IRQ, regs);
  134. } else if (pending & IE_IRQ3)
  135. panic("Unimplemented ISA NMI handler");
  136. else if (pending & IE_IRQ2)
  137. do_IRQ(r4030_read_reg32(JAZZ_EISA_IRQ_ACK), regs);
  138. else if (pending & IE_IRQ1) {
  139. ll_local_dev(regs);
  140. } else if (unlikely(pending & IE_IRQ0))
  141. panic("Unimplemented local_dma handler");
  142. else if (pending & IE_SW1) {
  143. clear_c0_cause(IE_SW1);
  144. panic("Unimplemented sw1 handler");
  145. } else if (pending & IE_SW0) {
  146. clear_c0_cause(IE_SW0);
  147. panic("Unimplemented sw0 handler");
  148. }
  149. }