irq_txx9.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Based on linux/arch/mips/jmr3927/rbhma3100/irq.c,
  3. * linux/arch/mips/tx4927/common/tx4927_irq.c,
  4. * linux/arch/mips/tx4938/common/irq.c
  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 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. #include <linux/init.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/types.h>
  19. #include <linux/irq.h>
  20. #include <asm/txx9irq.h>
  21. struct txx9_irc_reg {
  22. u32 cer;
  23. u32 cr[2];
  24. u32 unused0;
  25. u32 ilr[8];
  26. u32 unused1[4];
  27. u32 imr;
  28. u32 unused2[7];
  29. u32 scr;
  30. u32 unused3[7];
  31. u32 ssr;
  32. u32 unused4[7];
  33. u32 csr;
  34. };
  35. /* IRCER : Int. Control Enable */
  36. #define TXx9_IRCER_ICE 0x00000001
  37. /* IRCR : Int. Control */
  38. #define TXx9_IRCR_LOW 0x00000000
  39. #define TXx9_IRCR_HIGH 0x00000001
  40. #define TXx9_IRCR_DOWN 0x00000002
  41. #define TXx9_IRCR_UP 0x00000003
  42. #define TXx9_IRCR_EDGE(cr) ((cr) & 0x00000002)
  43. /* IRSCR : Int. Status Control */
  44. #define TXx9_IRSCR_EIClrE 0x00000100
  45. #define TXx9_IRSCR_EIClr_MASK 0x0000000f
  46. /* IRCSR : Int. Current Status */
  47. #define TXx9_IRCSR_IF 0x00010000
  48. #define TXx9_IRCSR_ILV_MASK 0x00000700
  49. #define TXx9_IRCSR_IVL_MASK 0x0000001f
  50. #define irc_dlevel 0
  51. #define irc_elevel 1
  52. static struct txx9_irc_reg __iomem *txx9_ircptr __read_mostly;
  53. static struct {
  54. unsigned char level;
  55. unsigned char mode;
  56. } txx9irq[TXx9_MAX_IR] __read_mostly;
  57. static void txx9_irq_unmask(struct irq_data *d)
  58. {
  59. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  60. u32 __iomem *ilrp = &txx9_ircptr->ilr[(irq_nr % 16 ) / 2];
  61. int ofs = irq_nr / 16 * 16 + (irq_nr & 1) * 8;
  62. __raw_writel((__raw_readl(ilrp) & ~(0xff << ofs))
  63. | (txx9irq[irq_nr].level << ofs),
  64. ilrp);
  65. #ifdef CONFIG_CPU_TX39XX
  66. /* update IRCSR */
  67. __raw_writel(0, &txx9_ircptr->imr);
  68. __raw_writel(irc_elevel, &txx9_ircptr->imr);
  69. #endif
  70. }
  71. static inline void txx9_irq_mask(struct irq_data *d)
  72. {
  73. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  74. u32 __iomem *ilrp = &txx9_ircptr->ilr[(irq_nr % 16) / 2];
  75. int ofs = irq_nr / 16 * 16 + (irq_nr & 1) * 8;
  76. __raw_writel((__raw_readl(ilrp) & ~(0xff << ofs))
  77. | (irc_dlevel << ofs),
  78. ilrp);
  79. #ifdef CONFIG_CPU_TX39XX
  80. /* update IRCSR */
  81. __raw_writel(0, &txx9_ircptr->imr);
  82. __raw_writel(irc_elevel, &txx9_ircptr->imr);
  83. /* flush write buffer */
  84. __raw_readl(&txx9_ircptr->ssr);
  85. #else
  86. mmiowb();
  87. #endif
  88. }
  89. static void txx9_irq_mask_ack(struct irq_data *d)
  90. {
  91. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  92. txx9_irq_mask(d);
  93. /* clear edge detection */
  94. if (unlikely(TXx9_IRCR_EDGE(txx9irq[irq_nr].mode)))
  95. __raw_writel(TXx9_IRSCR_EIClrE | irq_nr, &txx9_ircptr->scr);
  96. }
  97. static int txx9_irq_set_type(struct irq_data *d, unsigned int flow_type)
  98. {
  99. unsigned int irq_nr = d->irq - TXX9_IRQ_BASE;
  100. u32 cr;
  101. u32 __iomem *crp;
  102. int ofs;
  103. int mode;
  104. if (flow_type & IRQF_TRIGGER_PROBE)
  105. return 0;
  106. switch (flow_type & IRQF_TRIGGER_MASK) {
  107. case IRQF_TRIGGER_RISING: mode = TXx9_IRCR_UP; break;
  108. case IRQF_TRIGGER_FALLING: mode = TXx9_IRCR_DOWN; break;
  109. case IRQF_TRIGGER_HIGH: mode = TXx9_IRCR_HIGH; break;
  110. case IRQF_TRIGGER_LOW: mode = TXx9_IRCR_LOW; break;
  111. default:
  112. return -EINVAL;
  113. }
  114. crp = &txx9_ircptr->cr[(unsigned int)irq_nr / 8];
  115. cr = __raw_readl(crp);
  116. ofs = (irq_nr & (8 - 1)) * 2;
  117. cr &= ~(0x3 << ofs);
  118. cr |= (mode & 0x3) << ofs;
  119. __raw_writel(cr, crp);
  120. txx9irq[irq_nr].mode = mode;
  121. return 0;
  122. }
  123. static struct irq_chip txx9_irq_chip = {
  124. .name = "TXX9",
  125. .irq_ack = txx9_irq_mask_ack,
  126. .irq_mask = txx9_irq_mask,
  127. .irq_mask_ack = txx9_irq_mask_ack,
  128. .irq_unmask = txx9_irq_unmask,
  129. .irq_set_type = txx9_irq_set_type,
  130. };
  131. void __init txx9_irq_init(unsigned long baseaddr)
  132. {
  133. int i;
  134. txx9_ircptr = ioremap(baseaddr, sizeof(struct txx9_irc_reg));
  135. for (i = 0; i < TXx9_MAX_IR; i++) {
  136. txx9irq[i].level = 4; /* middle level */
  137. txx9irq[i].mode = TXx9_IRCR_LOW;
  138. irq_set_chip_and_handler(TXX9_IRQ_BASE + i, &txx9_irq_chip,
  139. handle_level_irq);
  140. }
  141. /* mask all IRC interrupts */
  142. __raw_writel(0, &txx9_ircptr->imr);
  143. for (i = 0; i < 8; i++)
  144. __raw_writel(0, &txx9_ircptr->ilr[i]);
  145. /* setup IRC interrupt mode (Low Active) */
  146. for (i = 0; i < 2; i++)
  147. __raw_writel(0, &txx9_ircptr->cr[i]);
  148. /* enable interrupt control */
  149. __raw_writel(TXx9_IRCER_ICE, &txx9_ircptr->cer);
  150. __raw_writel(irc_elevel, &txx9_ircptr->imr);
  151. }
  152. int __init txx9_irq_set_pri(int irc_irq, int new_pri)
  153. {
  154. int old_pri;
  155. if ((unsigned int)irc_irq >= TXx9_MAX_IR)
  156. return 0;
  157. old_pri = txx9irq[irc_irq].level;
  158. txx9irq[irc_irq].level = new_pri;
  159. return old_pri;
  160. }
  161. int txx9_irq(void)
  162. {
  163. u32 csr = __raw_readl(&txx9_ircptr->csr);
  164. if (likely(!(csr & TXx9_IRCSR_IF)))
  165. return TXX9_IRQ_BASE + (csr & (TXx9_MAX_IR - 1));
  166. return -1;
  167. }