ints_h8s.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * linux/arch/h8300/platform/h8s/ints_h8s.c
  3. * Interrupt handling CPU variants
  4. *
  5. * Yoshinori Sato <ysato@users.sourceforge.jp>
  6. *
  7. */
  8. #include <linux/config.h>
  9. #include <linux/init.h>
  10. #include <linux/errno.h>
  11. #include <linux/kernel.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/traps.h>
  14. #include <asm/irq.h>
  15. #include <asm/io.h>
  16. #include <asm/gpio.h>
  17. #include <asm/regs267x.h>
  18. /* saved vector list */
  19. const int __initdata h8300_saved_vectors[]={
  20. #if defined(CONFIG_GDB_DEBUG)
  21. TRACE_VEC,
  22. TRAP3_VEC,
  23. #endif
  24. -1
  25. };
  26. /* trap entry table */
  27. const unsigned long __initdata h8300_trap_table[NR_TRAPS]={
  28. 0,0,0,0,0,
  29. (unsigned long)trace_break, /* TRACE */
  30. 0,0,
  31. (unsigned long)system_call, /* TRAPA #0 */
  32. 0,0,0,0,0,0,0
  33. };
  34. /* IRQ pin assignment */
  35. struct irq_pins {
  36. unsigned char port_no;
  37. unsigned char bit_no;
  38. } __attribute__((aligned(1),packed));
  39. /* ISTR = 0 */
  40. const static struct irq_pins irq_assign_table0[16]={
  41. {H8300_GPIO_P5,H8300_GPIO_B0},{H8300_GPIO_P5,H8300_GPIO_B1},
  42. {H8300_GPIO_P5,H8300_GPIO_B2},{H8300_GPIO_P5,H8300_GPIO_B3},
  43. {H8300_GPIO_P5,H8300_GPIO_B4},{H8300_GPIO_P5,H8300_GPIO_B5},
  44. {H8300_GPIO_P5,H8300_GPIO_B6},{H8300_GPIO_P5,H8300_GPIO_B7},
  45. {H8300_GPIO_P6,H8300_GPIO_B0},{H8300_GPIO_P6,H8300_GPIO_B1},
  46. {H8300_GPIO_P6,H8300_GPIO_B2},{H8300_GPIO_P6,H8300_GPIO_B3},
  47. {H8300_GPIO_P6,H8300_GPIO_B4},{H8300_GPIO_P6,H8300_GPIO_B5},
  48. {H8300_GPIO_PF,H8300_GPIO_B1},{H8300_GPIO_PF,H8300_GPIO_B2},
  49. };
  50. /* ISTR = 1 */
  51. const static struct irq_pins irq_assign_table1[16]={
  52. {H8300_GPIO_P8,H8300_GPIO_B0},{H8300_GPIO_P8,H8300_GPIO_B1},
  53. {H8300_GPIO_P8,H8300_GPIO_B2},{H8300_GPIO_P8,H8300_GPIO_B3},
  54. {H8300_GPIO_P8,H8300_GPIO_B4},{H8300_GPIO_P8,H8300_GPIO_B5},
  55. {H8300_GPIO_PH,H8300_GPIO_B2},{H8300_GPIO_PH,H8300_GPIO_B3},
  56. {H8300_GPIO_P2,H8300_GPIO_B0},{H8300_GPIO_P2,H8300_GPIO_B1},
  57. {H8300_GPIO_P2,H8300_GPIO_B2},{H8300_GPIO_P2,H8300_GPIO_B3},
  58. {H8300_GPIO_P2,H8300_GPIO_B4},{H8300_GPIO_P2,H8300_GPIO_B5},
  59. {H8300_GPIO_P2,H8300_GPIO_B6},{H8300_GPIO_P2,H8300_GPIO_B7},
  60. };
  61. /* IRQ to GPIO pinno transrate */
  62. #define IRQ_GPIO_MAP(irqbit,irq,port,bit) \
  63. do { \
  64. if (*(volatile unsigned short *)ITSR & irqbit) { \
  65. port = irq_assign_table1[irq - EXT_IRQ0].port_no; \
  66. bit = irq_assign_table1[irq - EXT_IRQ0].bit_no; \
  67. } else { \
  68. port = irq_assign_table0[irq - EXT_IRQ0].port_no; \
  69. bit = irq_assign_table0[irq - EXT_IRQ0].bit_no; \
  70. } \
  71. } while(0)
  72. int h8300_enable_irq_pin(unsigned int irq)
  73. {
  74. if (irq >= EXT_IRQ0 && irq <= EXT_IRQ15) {
  75. unsigned short ptn = 1 << (irq - EXT_IRQ0);
  76. unsigned int port_no,bit_no;
  77. IRQ_GPIO_MAP(ptn, irq, port_no, bit_no);
  78. if (H8300_GPIO_RESERVE(port_no, bit_no) == 0)
  79. return -EBUSY; /* pin already use */
  80. H8300_GPIO_DDR(port_no, bit_no, H8300_GPIO_INPUT);
  81. *(volatile unsigned short *)ISR &= ~ptn; /* ISR clear */
  82. }
  83. return 0;
  84. }
  85. void h8300_disable_irq_pin(unsigned int irq)
  86. {
  87. if (irq >= EXT_IRQ0 && irq <= EXT_IRQ15) {
  88. /* disable interrupt & release IRQ pin */
  89. unsigned short ptn = 1 << (irq - EXT_IRQ0);
  90. unsigned short port_no,bit_no;
  91. *(volatile unsigned short *)ISR &= ~ptn;
  92. *(volatile unsigned short *)IER &= ~ptn;
  93. IRQ_GPIO_MAP(ptn, irq, port_no, bit_no);
  94. H8300_GPIO_FREE(port_no, bit_no);
  95. }
  96. }