irq.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. void disable_r4030_irq(unsigned int irq)
  27. {
  28. unsigned int mask = ~(1 << (irq - JAZZ_PARALLEL_IRQ));
  29. unsigned long flags;
  30. spin_lock_irqsave(&r4030_lock, flags);
  31. mask &= r4030_read_reg16(JAZZ_IO_IRQ_ENABLE);
  32. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, mask);
  33. spin_unlock_irqrestore(&r4030_lock, flags);
  34. }
  35. static void end_r4030_irq(unsigned int irq)
  36. {
  37. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  38. enable_r4030_irq(irq);
  39. }
  40. static struct irq_chip r4030_irq_type = {
  41. .typename = "R4030",
  42. .ack = disable_r4030_irq,
  43. .mask = disable_r4030_irq,
  44. .mask_ack = disable_r4030_irq,
  45. .unmask = enable_r4030_irq,
  46. .end = end_r4030_irq,
  47. };
  48. void __init init_r4030_ints(void)
  49. {
  50. int i;
  51. for (i = JAZZ_PARALLEL_IRQ; i <= JAZZ_TIMER_IRQ; i++)
  52. set_irq_chip_and_handler(i, &r4030_irq_type, handle_level_irq);
  53. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE, 0);
  54. r4030_read_reg16(JAZZ_IO_IRQ_SOURCE); /* clear pending IRQs */
  55. r4030_read_reg32(JAZZ_R4030_INVAL_ADDR); /* clear error bits */
  56. }
  57. /*
  58. * On systems with i8259-style interrupt controllers we assume for
  59. * driver compatibility reasons interrupts 0 - 15 to be the i8259
  60. * interrupts even if the hardware uses a different interrupt numbering.
  61. */
  62. void __init arch_init_irq(void)
  63. {
  64. init_i8259_irqs(); /* Integrated i8259 */
  65. init_r4030_ints();
  66. change_c0_status(ST0_IM, IE_IRQ4 | IE_IRQ3 | IE_IRQ2 | IE_IRQ1);
  67. }
  68. static void loc_call(unsigned int irq, unsigned int mask)
  69. {
  70. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE,
  71. r4030_read_reg16(JAZZ_IO_IRQ_ENABLE) & mask);
  72. do_IRQ(irq);
  73. r4030_write_reg16(JAZZ_IO_IRQ_ENABLE,
  74. r4030_read_reg16(JAZZ_IO_IRQ_ENABLE) | mask);
  75. }
  76. static void ll_local_dev(void)
  77. {
  78. switch (r4030_read_reg32(JAZZ_IO_IRQ_SOURCE)) {
  79. case 0:
  80. panic("Unimplemented loc_no_irq handler");
  81. break;
  82. case 4:
  83. loc_call(JAZZ_PARALLEL_IRQ, JAZZ_IE_PARALLEL);
  84. break;
  85. case 8:
  86. loc_call(JAZZ_PARALLEL_IRQ, JAZZ_IE_FLOPPY);
  87. break;
  88. case 12:
  89. panic("Unimplemented loc_sound handler");
  90. break;
  91. case 16:
  92. panic("Unimplemented loc_video handler");
  93. break;
  94. case 20:
  95. loc_call(JAZZ_ETHERNET_IRQ, JAZZ_IE_ETHERNET);
  96. break;
  97. case 24:
  98. loc_call(JAZZ_SCSI_IRQ, JAZZ_IE_SCSI);
  99. break;
  100. case 28:
  101. loc_call(JAZZ_KEYBOARD_IRQ, JAZZ_IE_KEYBOARD);
  102. break;
  103. case 32:
  104. loc_call(JAZZ_MOUSE_IRQ, JAZZ_IE_MOUSE);
  105. break;
  106. case 36:
  107. loc_call(JAZZ_SERIAL1_IRQ, JAZZ_IE_SERIAL1);
  108. break;
  109. case 40:
  110. loc_call(JAZZ_SERIAL2_IRQ, JAZZ_IE_SERIAL2);
  111. break;
  112. }
  113. }
  114. asmlinkage void plat_irq_dispatch(void)
  115. {
  116. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  117. if (pending & IE_IRQ5)
  118. write_c0_compare(0);
  119. else if (pending & IE_IRQ4) {
  120. r4030_read_reg32(JAZZ_TIMER_REGISTER);
  121. do_IRQ(JAZZ_TIMER_IRQ);
  122. } else if (pending & IE_IRQ3)
  123. panic("Unimplemented ISA NMI handler");
  124. else if (pending & IE_IRQ2)
  125. do_IRQ(r4030_read_reg32(JAZZ_EISA_IRQ_ACK));
  126. else if (pending & IE_IRQ1) {
  127. ll_local_dev();
  128. } else if (unlikely(pending & IE_IRQ0))
  129. panic("Unimplemented local_dma handler");
  130. else if (pending & IE_SW1) {
  131. clear_c0_cause(IE_SW1);
  132. panic("Unimplemented sw1 handler");
  133. } else if (pending & IE_SW0) {
  134. clear_c0_cause(IE_SW0);
  135. panic("Unimplemented sw0 handler");
  136. }
  137. }