pint.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/module.h>
  15. #include <asm/system.h>
  16. #include <asm/io.h>
  17. #include <asm/machvec.h>
  18. static unsigned char pint_map[256];
  19. static unsigned long portcr_mask;
  20. static void enable_pint_irq(unsigned int irq);
  21. static void disable_pint_irq(unsigned int irq);
  22. /* shutdown is same as "disable" */
  23. #define shutdown_pint_irq disable_pint_irq
  24. static void mask_and_ack_pint(unsigned int);
  25. static void end_pint_irq(unsigned int irq);
  26. static unsigned int startup_pint_irq(unsigned int irq)
  27. {
  28. enable_pint_irq(irq);
  29. return 0; /* never anything pending */
  30. }
  31. static struct hw_interrupt_type pint_irq_type = {
  32. .typename = "PINT-IRQ",
  33. .startup = startup_pint_irq,
  34. .shutdown = shutdown_pint_irq,
  35. .enable = enable_pint_irq,
  36. .disable = disable_pint_irq,
  37. .ack = mask_and_ack_pint,
  38. .end = end_pint_irq
  39. };
  40. static void disable_pint_irq(unsigned int irq)
  41. {
  42. unsigned long val;
  43. val = ctrl_inw(INTC_INTER);
  44. val &= ~(1 << (irq - PINT_IRQ_BASE));
  45. ctrl_outw(val, INTC_INTER); /* disable PINTn */
  46. portcr_mask &= ~(3 << (irq - PINT_IRQ_BASE)*2);
  47. }
  48. static void enable_pint_irq(unsigned int irq)
  49. {
  50. unsigned long val;
  51. val = ctrl_inw(INTC_INTER);
  52. val |= 1 << (irq - PINT_IRQ_BASE);
  53. ctrl_outw(val, INTC_INTER); /* enable PINTn */
  54. portcr_mask |= 3 << (irq - PINT_IRQ_BASE)*2;
  55. }
  56. static void mask_and_ack_pint(unsigned int irq)
  57. {
  58. disable_pint_irq(irq);
  59. }
  60. static void end_pint_irq(unsigned int irq)
  61. {
  62. if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  63. enable_pint_irq(irq);
  64. }
  65. void make_pint_irq(unsigned int irq)
  66. {
  67. disable_irq_nosync(irq);
  68. irq_desc[irq].chip = &pint_irq_type;
  69. disable_pint_irq(irq);
  70. }
  71. void __init init_IRQ_pint(void)
  72. {
  73. int i;
  74. make_ipr_irq(PINT0_IRQ, PINT0_IPR_ADDR, PINT0_IPR_POS, PINT0_PRIORITY);
  75. make_ipr_irq(PINT8_IRQ, PINT8_IPR_ADDR, PINT8_IPR_POS, PINT8_PRIORITY);
  76. enable_irq(PINT0_IRQ);
  77. enable_irq(PINT8_IRQ);
  78. for(i = 0; i < 16; i++)
  79. make_pint_irq(PINT_IRQ_BASE + i);
  80. for(i = 0; i < 256; i++) {
  81. if (i & 1)
  82. pint_map[i] = 0;
  83. else if (i & 2)
  84. pint_map[i] = 1;
  85. else if (i & 4)
  86. pint_map[i] = 2;
  87. else if (i & 8)
  88. pint_map[i] = 3;
  89. else if (i & 0x10)
  90. pint_map[i] = 4;
  91. else if (i & 0x20)
  92. pint_map[i] = 5;
  93. else if (i & 0x40)
  94. pint_map[i] = 6;
  95. else if (i & 0x80)
  96. pint_map[i] = 7;
  97. }
  98. }
  99. int ipr_irq_demux(int irq)
  100. {
  101. unsigned long creg, dreg, d, sav;
  102. if (irq == PINT0_IRQ) {
  103. #if defined(CONFIG_CPU_SUBTYPE_SH7707)
  104. creg = PORT_PACR;
  105. dreg = PORT_PADR;
  106. #else
  107. creg = PORT_PCCR;
  108. dreg = PORT_PCDR;
  109. #endif
  110. sav = ctrl_inw(creg);
  111. ctrl_outw(sav | portcr_mask, creg);
  112. d = (~ctrl_inb(dreg) ^ ctrl_inw(INTC_ICR2)) &
  113. ctrl_inw(INTC_INTER) & 0xff;
  114. ctrl_outw(sav, creg);
  115. if (d == 0)
  116. return irq;
  117. return PINT_IRQ_BASE + pint_map[d];
  118. } else if (irq == PINT8_IRQ) {
  119. #if defined(CONFIG_CPU_SUBTYPE_SH7707)
  120. creg = PORT_PBCR;
  121. dreg = PORT_PBDR;
  122. #else
  123. creg = PORT_PFCR;
  124. dreg = PORT_PFDR;
  125. #endif
  126. sav = ctrl_inw(creg);
  127. ctrl_outw(sav | (portcr_mask >> 16), creg);
  128. d = (~ctrl_inb(dreg) ^ (ctrl_inw(INTC_ICR2) >> 8)) &
  129. (ctrl_inw(INTC_INTER) >> 8) & 0xff;
  130. ctrl_outw(sav, creg);
  131. if (d == 0)
  132. return irq;
  133. return PINT_IRQ_BASE + 8 + pint_map[d];
  134. }
  135. return irq;
  136. }