irq_tx4939.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * TX4939 irq routines
  3. * Based on linux/arch/mips/kernel/irq_txx9.c,
  4. * and RBTX49xx patch from CELF patch archive.
  5. *
  6. * Copyright 2001, 2003-2005 MontaVista Software Inc.
  7. * Author: MontaVista Software, Inc.
  8. * ahennessy@mvista.com
  9. * source@mvista.com
  10. * Copyright (C) 2000-2001,2005-2007 Toshiba Corporation
  11. *
  12. * This file is subject to the terms and conditions of the GNU General Public
  13. * License. See the file "COPYING" in the main directory of this archive
  14. * for more details.
  15. */
  16. /*
  17. * TX4939 defines 64 IRQs.
  18. * Similer to irq_txx9.c but different register layouts.
  19. */
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/irq.h>
  23. #include <linux/types.h>
  24. #include <asm/irq_cpu.h>
  25. #include <asm/txx9irq.h>
  26. #include <asm/txx9/tx4939.h>
  27. /* IRCER : Int. Control Enable */
  28. #define TXx9_IRCER_ICE 0x00000001
  29. /* IRCR : Int. Control */
  30. #define TXx9_IRCR_LOW 0x00000000
  31. #define TXx9_IRCR_HIGH 0x00000001
  32. #define TXx9_IRCR_DOWN 0x00000002
  33. #define TXx9_IRCR_UP 0x00000003
  34. #define TXx9_IRCR_EDGE(cr) ((cr) & 0x00000002)
  35. /* IRSCR : Int. Status Control */
  36. #define TXx9_IRSCR_EIClrE 0x00000100
  37. #define TXx9_IRSCR_EIClr_MASK 0x0000000f
  38. /* IRCSR : Int. Current Status */
  39. #define TXx9_IRCSR_IF 0x00010000
  40. #define irc_dlevel 0
  41. #define irc_elevel 1
  42. static struct {
  43. unsigned char level;
  44. unsigned char mode;
  45. } tx4939irq[TX4939_NUM_IR] __read_mostly;
  46. static void tx4939_irq_unmask(struct irq_data *d)
  47. {
  48. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  49. u32 __iomem *lvlp;
  50. int ofs;
  51. if (irq_nr < 32) {
  52. irq_nr--;
  53. lvlp = &tx4939_ircptr->lvl[(irq_nr % 16) / 2].r;
  54. } else {
  55. irq_nr -= 32;
  56. lvlp = &tx4939_ircptr->lvl[8 + (irq_nr % 16) / 2].r;
  57. }
  58. ofs = (irq_nr & 16) + (irq_nr & 1) * 8;
  59. __raw_writel((__raw_readl(lvlp) & ~(0xff << ofs))
  60. | (tx4939irq[irq_nr].level << ofs),
  61. lvlp);
  62. }
  63. static inline void tx4939_irq_mask(struct irq_data *d)
  64. {
  65. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  66. u32 __iomem *lvlp;
  67. int ofs;
  68. if (irq_nr < 32) {
  69. irq_nr--;
  70. lvlp = &tx4939_ircptr->lvl[(irq_nr % 16) / 2].r;
  71. } else {
  72. irq_nr -= 32;
  73. lvlp = &tx4939_ircptr->lvl[8 + (irq_nr % 16) / 2].r;
  74. }
  75. ofs = (irq_nr & 16) + (irq_nr & 1) * 8;
  76. __raw_writel((__raw_readl(lvlp) & ~(0xff << ofs))
  77. | (irc_dlevel << ofs),
  78. lvlp);
  79. mmiowb();
  80. }
  81. static void tx4939_irq_mask_ack(struct irq_data *d)
  82. {
  83. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  84. tx4939_irq_mask(d);
  85. if (TXx9_IRCR_EDGE(tx4939irq[irq_nr].mode)) {
  86. irq_nr--;
  87. /* clear edge detection */
  88. __raw_writel((TXx9_IRSCR_EIClrE | (irq_nr & 0xf))
  89. << (irq_nr & 0x10),
  90. &tx4939_ircptr->edc.r);
  91. }
  92. }
  93. static int tx4939_irq_set_type(struct irq_data *d, unsigned int flow_type)
  94. {
  95. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  96. u32 cr;
  97. u32 __iomem *crp;
  98. int ofs;
  99. int mode;
  100. if (flow_type & IRQF_TRIGGER_PROBE)
  101. return 0;
  102. switch (flow_type & IRQF_TRIGGER_MASK) {
  103. case IRQF_TRIGGER_RISING:
  104. mode = TXx9_IRCR_UP;
  105. break;
  106. case IRQF_TRIGGER_FALLING:
  107. mode = TXx9_IRCR_DOWN;
  108. break;
  109. case IRQF_TRIGGER_HIGH:
  110. mode = TXx9_IRCR_HIGH;
  111. break;
  112. case IRQF_TRIGGER_LOW:
  113. mode = TXx9_IRCR_LOW;
  114. break;
  115. default:
  116. return -EINVAL;
  117. }
  118. if (irq_nr < 32) {
  119. irq_nr--;
  120. crp = &tx4939_ircptr->dm[(irq_nr & 8) >> 3].r;
  121. } else {
  122. irq_nr -= 32;
  123. crp = &tx4939_ircptr->dm2[((irq_nr & 8) >> 3)].r;
  124. }
  125. ofs = (((irq_nr & 16) >> 1) | (irq_nr & (8 - 1))) * 2;
  126. cr = __raw_readl(crp);
  127. cr &= ~(0x3 << ofs);
  128. cr |= (mode & 0x3) << ofs;
  129. __raw_writel(cr, crp);
  130. tx4939irq[irq_nr].mode = mode;
  131. return 0;
  132. }
  133. static struct irq_chip tx4939_irq_chip = {
  134. .name = "TX4939",
  135. .irq_ack = tx4939_irq_mask_ack,
  136. .irq_mask = tx4939_irq_mask,
  137. .irq_mask_ack = tx4939_irq_mask_ack,
  138. .irq_unmask = tx4939_irq_unmask,
  139. .irq_set_type = tx4939_irq_set_type,
  140. };
  141. static int tx4939_irq_set_pri(int irc_irq, int new_pri)
  142. {
  143. int old_pri;
  144. if ((unsigned int)irc_irq >= TX4939_NUM_IR)
  145. return 0;
  146. old_pri = tx4939irq[irc_irq].level;
  147. tx4939irq[irc_irq].level = new_pri;
  148. return old_pri;
  149. }
  150. void __init tx4939_irq_init(void)
  151. {
  152. int i;
  153. mips_cpu_irq_init();
  154. /* disable interrupt control */
  155. __raw_writel(0, &tx4939_ircptr->den.r);
  156. __raw_writel(0, &tx4939_ircptr->maskint.r);
  157. __raw_writel(0, &tx4939_ircptr->maskext.r);
  158. /* irq_base + 0 is not used */
  159. for (i = 1; i < TX4939_NUM_IR; i++) {
  160. tx4939irq[i].level = 4; /* middle level */
  161. tx4939irq[i].mode = TXx9_IRCR_LOW;
  162. irq_set_chip_and_handler(TXX9_IRQ_BASE + i, &tx4939_irq_chip,
  163. handle_level_irq);
  164. }
  165. /* mask all IRC interrupts */
  166. __raw_writel(0, &tx4939_ircptr->msk.r);
  167. for (i = 0; i < 16; i++)
  168. __raw_writel(0, &tx4939_ircptr->lvl[i].r);
  169. /* setup IRC interrupt mode (Low Active) */
  170. for (i = 0; i < 2; i++)
  171. __raw_writel(0, &tx4939_ircptr->dm[i].r);
  172. for (i = 0; i < 2; i++)
  173. __raw_writel(0, &tx4939_ircptr->dm2[i].r);
  174. /* enable interrupt control */
  175. __raw_writel(TXx9_IRCER_ICE, &tx4939_ircptr->den.r);
  176. __raw_writel(irc_elevel, &tx4939_ircptr->msk.r);
  177. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + TX4939_IRC_INT,
  178. handle_simple_irq);
  179. /* raise priority for errors, timers, sio */
  180. tx4939_irq_set_pri(TX4939_IR_WTOERR, 7);
  181. tx4939_irq_set_pri(TX4939_IR_PCIERR, 7);
  182. tx4939_irq_set_pri(TX4939_IR_PCIPME, 7);
  183. for (i = 0; i < TX4939_NUM_IR_TMR; i++)
  184. tx4939_irq_set_pri(TX4939_IR_TMR(i), 6);
  185. for (i = 0; i < TX4939_NUM_IR_SIO; i++)
  186. tx4939_irq_set_pri(TX4939_IR_SIO(i), 5);
  187. }
  188. int tx4939_irq(void)
  189. {
  190. u32 csr = __raw_readl(&tx4939_ircptr->cs.r);
  191. if (likely(!(csr & TXx9_IRCSR_IF)))
  192. return TXX9_IRQ_BASE + (csr & (TX4939_NUM_IR - 1));
  193. return -1;
  194. }