irq.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * arch/sh/boards/superh/microdev/irq.c
  3. *
  4. * Copyright (C) 2003 Sean McGoogan (Sean.McGoogan@superh.com)
  5. *
  6. * SuperH SH4-202 MicroDev board support.
  7. *
  8. * May be copied or modified under the terms of the GNU General Public
  9. * License. See linux/COPYING for more information.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/irq.h>
  13. #include <asm/system.h>
  14. #include <asm/io.h>
  15. #include <asm/microdev.h>
  16. #define NUM_EXTERNAL_IRQS 16 /* IRL0 .. IRL15 */
  17. static const struct {
  18. unsigned char fpgaIrq;
  19. unsigned char mapped;
  20. const char *name;
  21. } fpgaIrqTable[NUM_EXTERNAL_IRQS] = {
  22. { 0, 0, "unused" }, /* IRQ #0 IRL=15 0x200 */
  23. { MICRODEV_FPGA_IRQ_KEYBOARD, 1, "keyboard" }, /* IRQ #1 IRL=14 0x220 */
  24. { MICRODEV_FPGA_IRQ_SERIAL1, 1, "Serial #1"}, /* IRQ #2 IRL=13 0x240 */
  25. { MICRODEV_FPGA_IRQ_ETHERNET, 1, "Ethernet" }, /* IRQ #3 IRL=12 0x260 */
  26. { MICRODEV_FPGA_IRQ_SERIAL2, 0, "Serial #2"}, /* IRQ #4 IRL=11 0x280 */
  27. { 0, 0, "unused" }, /* IRQ #5 IRL=10 0x2a0 */
  28. { 0, 0, "unused" }, /* IRQ #6 IRL=9 0x2c0 */
  29. { MICRODEV_FPGA_IRQ_USB_HC, 1, "USB" }, /* IRQ #7 IRL=8 0x2e0 */
  30. { MICRODEV_IRQ_PCI_INTA, 1, "PCI INTA" }, /* IRQ #8 IRL=7 0x300 */
  31. { MICRODEV_IRQ_PCI_INTB, 1, "PCI INTB" }, /* IRQ #9 IRL=6 0x320 */
  32. { MICRODEV_IRQ_PCI_INTC, 1, "PCI INTC" }, /* IRQ #10 IRL=5 0x340 */
  33. { MICRODEV_IRQ_PCI_INTD, 1, "PCI INTD" }, /* IRQ #11 IRL=4 0x360 */
  34. { MICRODEV_FPGA_IRQ_MOUSE, 1, "mouse" }, /* IRQ #12 IRL=3 0x380 */
  35. { MICRODEV_FPGA_IRQ_IDE2, 1, "IDE #2" }, /* IRQ #13 IRL=2 0x3a0 */
  36. { MICRODEV_FPGA_IRQ_IDE1, 1, "IDE #1" }, /* IRQ #14 IRL=1 0x3c0 */
  37. { 0, 0, "unused" }, /* IRQ #15 IRL=0 0x3e0 */
  38. };
  39. #if (MICRODEV_LINUX_IRQ_KEYBOARD != 1)
  40. # error Inconsistancy in defining the IRQ# for Keyboard!
  41. #endif
  42. #if (MICRODEV_LINUX_IRQ_ETHERNET != 3)
  43. # error Inconsistancy in defining the IRQ# for Ethernet!
  44. #endif
  45. #if (MICRODEV_LINUX_IRQ_USB_HC != 7)
  46. # error Inconsistancy in defining the IRQ# for USB!
  47. #endif
  48. #if (MICRODEV_LINUX_IRQ_MOUSE != 12)
  49. # error Inconsistancy in defining the IRQ# for PS/2 Mouse!
  50. #endif
  51. #if (MICRODEV_LINUX_IRQ_IDE2 != 13)
  52. # error Inconsistancy in defining the IRQ# for secondary IDE!
  53. #endif
  54. #if (MICRODEV_LINUX_IRQ_IDE1 != 14)
  55. # error Inconsistancy in defining the IRQ# for primary IDE!
  56. #endif
  57. static void enable_microdev_irq(unsigned int irq);
  58. static void disable_microdev_irq(unsigned int irq);
  59. /* shutdown is same as "disable" */
  60. #define shutdown_microdev_irq disable_microdev_irq
  61. static void mask_and_ack_microdev(unsigned int);
  62. static void end_microdev_irq(unsigned int irq);
  63. static unsigned int startup_microdev_irq(unsigned int irq)
  64. {
  65. enable_microdev_irq(irq);
  66. return 0; /* never anything pending */
  67. }
  68. static struct hw_interrupt_type microdev_irq_type = {
  69. .typename = "MicroDev-IRQ",
  70. .startup = startup_microdev_irq,
  71. .shutdown = shutdown_microdev_irq,
  72. .enable = enable_microdev_irq,
  73. .disable = disable_microdev_irq,
  74. .ack = mask_and_ack_microdev,
  75. .end = end_microdev_irq
  76. };
  77. static void disable_microdev_irq(unsigned int irq)
  78. {
  79. unsigned int flags;
  80. unsigned int fpgaIrq;
  81. if (irq >= NUM_EXTERNAL_IRQS) return;
  82. if (!fpgaIrqTable[irq].mapped) return;
  83. fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
  84. /* disable interrupts */
  85. local_irq_save(flags);
  86. /* disable interupts on the FPGA INTC register */
  87. ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTDSB_REG);
  88. /* restore interrupts */
  89. local_irq_restore(flags);
  90. }
  91. static void enable_microdev_irq(unsigned int irq)
  92. {
  93. unsigned long priorityReg, priorities, pri;
  94. unsigned int flags;
  95. unsigned int fpgaIrq;
  96. if (irq >= NUM_EXTERNAL_IRQS) return;
  97. if (!fpgaIrqTable[irq].mapped) return;
  98. pri = 15 - irq;
  99. fpgaIrq = fpgaIrqTable[irq].fpgaIrq;
  100. priorityReg = MICRODEV_FPGA_INTPRI_REG(fpgaIrq);
  101. /* disable interrupts */
  102. local_irq_save(flags);
  103. /* set priority for the interrupt */
  104. priorities = ctrl_inl(priorityReg);
  105. priorities &= ~MICRODEV_FPGA_INTPRI_MASK(fpgaIrq);
  106. priorities |= MICRODEV_FPGA_INTPRI_LEVEL(fpgaIrq, pri);
  107. ctrl_outl(priorities, priorityReg);
  108. /* enable interupts on the FPGA INTC register */
  109. ctrl_outl(MICRODEV_FPGA_INTC_MASK(fpgaIrq), MICRODEV_FPGA_INTENB_REG);
  110. /* restore interrupts */
  111. local_irq_restore(flags);
  112. }
  113. /* This functions sets the desired irq handler to be a MicroDev type */
  114. static void __init make_microdev_irq(unsigned int irq)
  115. {
  116. disable_irq_nosync(irq);
  117. irq_desc[irq].chip = &microdev_irq_type;
  118. disable_microdev_irq(irq);
  119. }
  120. static void mask_and_ack_microdev(unsigned int irq)
  121. {
  122. disable_microdev_irq(irq);
  123. }
  124. static void end_microdev_irq(unsigned int irq)
  125. {
  126. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  127. {
  128. enable_microdev_irq(irq);
  129. }
  130. }
  131. extern void __init init_microdev_irq(void)
  132. {
  133. int i;
  134. /* disable interupts on the FPGA INTC register */
  135. ctrl_outl(~0ul, MICRODEV_FPGA_INTDSB_REG);
  136. for (i = 0; i < NUM_EXTERNAL_IRQS; i++)
  137. {
  138. make_microdev_irq(i);
  139. }
  140. }
  141. extern void microdev_print_fpga_intc_status(void)
  142. {
  143. volatile unsigned int * const intenb = (unsigned int*)MICRODEV_FPGA_INTENB_REG;
  144. volatile unsigned int * const intdsb = (unsigned int*)MICRODEV_FPGA_INTDSB_REG;
  145. volatile unsigned int * const intpria = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(0);
  146. volatile unsigned int * const intprib = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(8);
  147. volatile unsigned int * const intpric = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(16);
  148. volatile unsigned int * const intprid = (unsigned int*)MICRODEV_FPGA_INTPRI_REG(24);
  149. volatile unsigned int * const intsrc = (unsigned int*)MICRODEV_FPGA_INTSRC_REG;
  150. volatile unsigned int * const intreq = (unsigned int*)MICRODEV_FPGA_INTREQ_REG;
  151. printk("-------------------------- microdev_print_fpga_intc_status() ------------------\n");
  152. printk("FPGA_INTENB = 0x%08x\n", *intenb);
  153. printk("FPGA_INTDSB = 0x%08x\n", *intdsb);
  154. printk("FPGA_INTSRC = 0x%08x\n", *intsrc);
  155. printk("FPGA_INTREQ = 0x%08x\n", *intreq);
  156. printk("FPGA_INTPRI[3..0] = %08x:%08x:%08x:%08x\n", *intprid, *intpric, *intprib, *intpria);
  157. printk("-------------------------------------------------------------------------------\n");
  158. }