irq.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright 2001 MontaVista Software Inc.
  3. * Author: MontaVista Software, Inc.
  4. * ahennessy@mvista.com
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. *
  10. * Copyright (C) 2000-2001 Toshiba Corporation
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  20. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  23. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  24. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * You should have received a copy of the GNU General Public License along
  29. * with this program; if not, write to the Free Software Foundation, Inc.,
  30. * 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #include <linux/init.h>
  33. #include <linux/sched.h>
  34. #include <linux/types.h>
  35. #include <linux/interrupt.h>
  36. #include <asm/io.h>
  37. #include <asm/mipsregs.h>
  38. #include <asm/system.h>
  39. #include <asm/processor.h>
  40. #include <asm/txx9/generic.h>
  41. #include <asm/txx9/jmr3927.h>
  42. #if JMR3927_IRQ_END > NR_IRQS
  43. #error JMR3927_IRQ_END > NR_IRQS
  44. #endif
  45. static unsigned char irc_level[TX3927_NUM_IR] = {
  46. 5, 5, 5, 5, 5, 5, /* INT[5:0] */
  47. 7, 7, /* SIO */
  48. 5, 5, 5, 0, 0, /* DMA, PIO, PCI */
  49. 6, 6, 6 /* TMR */
  50. };
  51. /*
  52. * CP0_STATUS is a thread's resource (saved/restored on context switch).
  53. * So disable_irq/enable_irq MUST handle IOC/IRC registers.
  54. */
  55. static void mask_irq_ioc(unsigned int irq)
  56. {
  57. /* 0: mask */
  58. unsigned int irq_nr = irq - JMR3927_IRQ_IOC;
  59. unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR);
  60. unsigned int bit = 1 << irq_nr;
  61. jmr3927_ioc_reg_out(imask & ~bit, JMR3927_IOC_INTM_ADDR);
  62. /* flush write buffer */
  63. (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
  64. }
  65. static void unmask_irq_ioc(unsigned int irq)
  66. {
  67. /* 0: mask */
  68. unsigned int irq_nr = irq - JMR3927_IRQ_IOC;
  69. unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR);
  70. unsigned int bit = 1 << irq_nr;
  71. jmr3927_ioc_reg_out(imask | bit, JMR3927_IOC_INTM_ADDR);
  72. /* flush write buffer */
  73. (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
  74. }
  75. static int jmr3927_ioc_irqroute(void)
  76. {
  77. unsigned char istat = jmr3927_ioc_reg_in(JMR3927_IOC_INTS2_ADDR);
  78. int i;
  79. for (i = 0; i < JMR3927_NR_IRQ_IOC; i++) {
  80. if (istat & (1 << i))
  81. return JMR3927_IRQ_IOC + i;
  82. }
  83. return -1;
  84. }
  85. static int jmr3927_irq_dispatch(int pending)
  86. {
  87. int irq;
  88. if ((pending & CAUSEF_IP7) == 0)
  89. return -1;
  90. irq = (pending >> CAUSEB_IP2) & 0x0f;
  91. irq += JMR3927_IRQ_IRC;
  92. if (irq == JMR3927_IRQ_IOCINT)
  93. irq = jmr3927_ioc_irqroute();
  94. return irq;
  95. }
  96. #ifdef CONFIG_PCI
  97. static irqreturn_t jmr3927_pcierr_interrupt(int irq, void *dev_id)
  98. {
  99. printk(KERN_WARNING "PCI error interrupt (irq 0x%x).\n", irq);
  100. printk(KERN_WARNING "pcistat:%02x, lbstat:%04lx\n",
  101. tx3927_pcicptr->pcistat, tx3927_pcicptr->lbstat);
  102. return IRQ_HANDLED;
  103. }
  104. static struct irqaction pcierr_action = {
  105. .handler = jmr3927_pcierr_interrupt,
  106. .mask = CPU_MASK_NONE,
  107. .name = "PCI error",
  108. };
  109. #endif
  110. static void __init jmr3927_irq_init(void);
  111. void __init jmr3927_irq_setup(void)
  112. {
  113. txx9_irq_dispatch = jmr3927_irq_dispatch;
  114. /* Now, interrupt control disabled, */
  115. /* all IRC interrupts are masked, */
  116. /* all IRC interrupt mode are Low Active. */
  117. /* mask all IOC interrupts */
  118. jmr3927_ioc_reg_out(0, JMR3927_IOC_INTM_ADDR);
  119. /* setup IOC interrupt mode (SOFT:High Active, Others:Low Active) */
  120. jmr3927_ioc_reg_out(JMR3927_IOC_INTF_SOFT, JMR3927_IOC_INTP_ADDR);
  121. /* clear PCI Soft interrupts */
  122. jmr3927_ioc_reg_out(0, JMR3927_IOC_INTS1_ADDR);
  123. /* clear PCI Reset interrupts */
  124. jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
  125. jmr3927_irq_init();
  126. /* setup IOC interrupt 1 (PCI, MODEM) */
  127. set_irq_chained_handler(JMR3927_IRQ_IOCINT, handle_simple_irq);
  128. #ifdef CONFIG_PCI
  129. setup_irq(JMR3927_IRQ_IRC_PCI, &pcierr_action);
  130. #endif
  131. /* enable all CPU interrupt bits. */
  132. set_c0_status(ST0_IM); /* IE bit is still 0. */
  133. }
  134. static struct irq_chip jmr3927_irq_ioc = {
  135. .name = "jmr3927_ioc",
  136. .ack = mask_irq_ioc,
  137. .mask = mask_irq_ioc,
  138. .mask_ack = mask_irq_ioc,
  139. .unmask = unmask_irq_ioc,
  140. };
  141. static void __init jmr3927_irq_init(void)
  142. {
  143. u32 i;
  144. txx9_irq_init(TX3927_IRC_REG);
  145. for (i = 0; i < TXx9_MAX_IR; i++)
  146. txx9_irq_set_pri(i, irc_level[i]);
  147. for (i = JMR3927_IRQ_IOC; i < JMR3927_IRQ_IOC + JMR3927_NR_IRQ_IOC; i++)
  148. set_irq_chip_and_handler(i, &jmr3927_irq_ioc, handle_level_irq);
  149. }