pint.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * arch/sh/kernel/cpu/irq/pint.c - Interrupt handling for PINT-based IRQs.
  3. *
  4. * Copyright (C) 1999 Niibe Yutaka & Takeshi Yaegashi
  5. * Copyright (C) 2000 Kazumoto Kojima
  6. * Copyright (C) 2003 Takashi Kusuda <kusuda-takashi@hitachi-ul.co.jp>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/config.h>
  13. #include <linux/init.h>
  14. #include <linux/irq.h>
  15. #include <linux/module.h>
  16. #include <asm/system.h>
  17. #include <asm/io.h>
  18. #include <asm/machvec.h>
  19. static unsigned char pint_map[256];
  20. static unsigned long portcr_mask;
  21. static void enable_pint_irq(unsigned int irq);
  22. static void disable_pint_irq(unsigned int irq);
  23. /* shutdown is same as "disable" */
  24. #define shutdown_pint_irq disable_pint_irq
  25. static void mask_and_ack_pint(unsigned int);
  26. static void end_pint_irq(unsigned int irq);
  27. static unsigned int startup_pint_irq(unsigned int irq)
  28. {
  29. enable_pint_irq(irq);
  30. return 0; /* never anything pending */
  31. }
  32. static struct hw_interrupt_type pint_irq_type = {
  33. .typename = "PINT-IRQ",
  34. .startup = startup_pint_irq,
  35. .shutdown = shutdown_pint_irq,
  36. .enable = enable_pint_irq,
  37. .disable = disable_pint_irq,
  38. .ack = mask_and_ack_pint,
  39. .end = end_pint_irq
  40. };
  41. static void disable_pint_irq(unsigned int irq)
  42. {
  43. unsigned long val, flags;
  44. local_irq_save(flags);
  45. val = ctrl_inw(INTC_INTER);
  46. val &= ~(1 << (irq - PINT_IRQ_BASE));
  47. ctrl_outw(val, INTC_INTER); /* disable PINTn */
  48. portcr_mask &= ~(3 << (irq - PINT_IRQ_BASE)*2);
  49. local_irq_restore(flags);
  50. }
  51. static void enable_pint_irq(unsigned int irq)
  52. {
  53. unsigned long val, flags;
  54. local_irq_save(flags);
  55. val = ctrl_inw(INTC_INTER);
  56. val |= 1 << (irq - PINT_IRQ_BASE);
  57. ctrl_outw(val, INTC_INTER); /* enable PINTn */
  58. portcr_mask |= 3 << (irq - PINT_IRQ_BASE)*2;
  59. local_irq_restore(flags);
  60. }
  61. static void mask_and_ack_pint(unsigned int irq)
  62. {
  63. disable_pint_irq(irq);
  64. }
  65. static void end_pint_irq(unsigned int irq)
  66. {
  67. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  68. enable_pint_irq(irq);
  69. }
  70. void make_pint_irq(unsigned int irq)
  71. {
  72. disable_irq_nosync(irq);
  73. irq_desc[irq].handler = &pint_irq_type;
  74. disable_pint_irq(irq);
  75. }
  76. void __init init_IRQ_pint(void)
  77. {
  78. int i;
  79. make_ipr_irq(PINT0_IRQ, PINT0_IPR_ADDR, PINT0_IPR_POS, PINT0_PRIORITY);
  80. make_ipr_irq(PINT8_IRQ, PINT8_IPR_ADDR, PINT8_IPR_POS, PINT8_PRIORITY);
  81. enable_irq(PINT0_IRQ);
  82. enable_irq(PINT8_IRQ);
  83. for(i = 0; i < 16; i++)
  84. make_pint_irq(PINT_IRQ_BASE + i);
  85. for(i = 0; i < 256; i++) {
  86. if (i & 1)
  87. pint_map[i] = 0;
  88. else if (i & 2)
  89. pint_map[i] = 1;
  90. else if (i & 4)
  91. pint_map[i] = 2;
  92. else if (i & 8)
  93. pint_map[i] = 3;
  94. else if (i & 0x10)
  95. pint_map[i] = 4;
  96. else if (i & 0x20)
  97. pint_map[i] = 5;
  98. else if (i & 0x40)
  99. pint_map[i] = 6;
  100. else if (i & 0x80)
  101. pint_map[i] = 7;
  102. }
  103. }
  104. int ipr_irq_demux(int irq)
  105. {
  106. unsigned long creg, dreg, d, sav;
  107. if (irq == PINT0_IRQ) {
  108. #if defined(CONFIG_CPU_SUBTYPE_SH7707)
  109. creg = PORT_PACR;
  110. dreg = PORT_PADR;
  111. #else
  112. creg = PORT_PCCR;
  113. dreg = PORT_PCDR;
  114. #endif
  115. sav = ctrl_inw(creg);
  116. ctrl_outw(sav | portcr_mask, creg);
  117. d = (~ctrl_inb(dreg) ^ ctrl_inw(INTC_ICR2)) &
  118. ctrl_inw(INTC_INTER) & 0xff;
  119. ctrl_outw(sav, creg);
  120. if (d == 0)
  121. return irq;
  122. return PINT_IRQ_BASE + pint_map[d];
  123. } else if (irq == PINT8_IRQ) {
  124. #if defined(CONFIG_CPU_SUBTYPE_SH7707)
  125. creg = PORT_PBCR;
  126. dreg = PORT_PBDR;
  127. #else
  128. creg = PORT_PFCR;
  129. dreg = PORT_PFDR;
  130. #endif
  131. sav = ctrl_inw(creg);
  132. ctrl_outw(sav | (portcr_mask >> 16), creg);
  133. d = (~ctrl_inb(dreg) ^ (ctrl_inw(INTC_ICR2) >> 8)) &
  134. (ctrl_inw(INTC_INTER) >> 8) & 0xff;
  135. ctrl_outw(sav, creg);
  136. if (d == 0)
  137. return irq;
  138. return PINT_IRQ_BASE + 8 + pint_map[d];
  139. }
  140. return irq;
  141. }