irq.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation; either version 2 of the License, or (at your
  5. * option) any later version.
  6. *
  7. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  8. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  10. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  11. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  12. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  13. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  14. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  15. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  16. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * Copyright 2002 MontaVista Software Inc.
  23. * Author: MontaVista Software, Inc.
  24. * stevel@mvista.com or source@mvista.com
  25. */
  26. #include <linux/bitops.h>
  27. #include <linux/errno.h>
  28. #include <linux/init.h>
  29. #include <linux/io.h>
  30. #include <linux/kernel_stat.h>
  31. #include <linux/module.h>
  32. #include <linux/signal.h>
  33. #include <linux/sched.h>
  34. #include <linux/types.h>
  35. #include <linux/interrupt.h>
  36. #include <linux/ioport.h>
  37. #include <linux/timex.h>
  38. #include <linux/slab.h>
  39. #include <linux/random.h>
  40. #include <linux/delay.h>
  41. #include <asm/bootinfo.h>
  42. #include <asm/time.h>
  43. #include <asm/mipsregs.h>
  44. #include <asm/system.h>
  45. #include <asm/mach-rc32434/irq.h>
  46. struct intr_group {
  47. u32 mask; /* mask of valid bits in pending/mask registers */
  48. volatile u32 *base_addr;
  49. };
  50. #define RC32434_NR_IRQS (GROUP4_IRQ_BASE + 32)
  51. #if (NR_IRQS < RC32434_NR_IRQS)
  52. #error Too little irqs defined. Did you override <asm/irq.h> ?
  53. #endif
  54. static const struct intr_group intr_group[NUM_INTR_GROUPS] = {
  55. {
  56. .mask = 0x0000efff,
  57. .base_addr = (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 0 * IC_GROUP_OFFSET)},
  58. {
  59. .mask = 0x00001fff,
  60. .base_addr = (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 1 * IC_GROUP_OFFSET)},
  61. {
  62. .mask = 0x00000007,
  63. .base_addr = (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 2 * IC_GROUP_OFFSET)},
  64. {
  65. .mask = 0x0003ffff,
  66. .base_addr = (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 3 * IC_GROUP_OFFSET)},
  67. {
  68. .mask = 0xffffffff,
  69. .base_addr = (u32 *) KSEG1ADDR(IC_GROUP0_PEND + 4 * IC_GROUP_OFFSET)}
  70. };
  71. #define READ_PEND(base) (*(base))
  72. #define READ_MASK(base) (*(base + 2))
  73. #define WRITE_MASK(base, val) (*(base + 2) = (val))
  74. static inline int irq_to_group(unsigned int irq_nr)
  75. {
  76. return (irq_nr - GROUP0_IRQ_BASE) >> 5;
  77. }
  78. static inline int group_to_ip(unsigned int group)
  79. {
  80. return group + 2;
  81. }
  82. static inline void enable_local_irq(unsigned int ip)
  83. {
  84. int ipnum = 0x100 << ip;
  85. set_c0_status(ipnum);
  86. }
  87. static inline void disable_local_irq(unsigned int ip)
  88. {
  89. int ipnum = 0x100 << ip;
  90. clear_c0_status(ipnum);
  91. }
  92. static inline void ack_local_irq(unsigned int ip)
  93. {
  94. int ipnum = 0x100 << ip;
  95. clear_c0_cause(ipnum);
  96. }
  97. static void rb532_enable_irq(unsigned int irq_nr)
  98. {
  99. int ip = irq_nr - GROUP0_IRQ_BASE;
  100. unsigned int group, intr_bit;
  101. volatile unsigned int *addr;
  102. if (ip < 0)
  103. enable_local_irq(irq_nr);
  104. else {
  105. group = ip >> 5;
  106. ip &= (1 << 5) - 1;
  107. intr_bit = 1 << ip;
  108. enable_local_irq(group_to_ip(group));
  109. addr = intr_group[group].base_addr;
  110. WRITE_MASK(addr, READ_MASK(addr) & ~intr_bit);
  111. }
  112. }
  113. static void rb532_disable_irq(unsigned int irq_nr)
  114. {
  115. int ip = irq_nr - GROUP0_IRQ_BASE;
  116. unsigned int group, intr_bit, mask;
  117. volatile unsigned int *addr;
  118. if (ip < 0) {
  119. disable_local_irq(irq_nr);
  120. } else {
  121. group = ip >> 5;
  122. ip &= (1 << 5) - 1;
  123. intr_bit = 1 << ip;
  124. addr = intr_group[group].base_addr;
  125. mask = READ_MASK(addr);
  126. mask |= intr_bit;
  127. WRITE_MASK(addr, mask);
  128. /*
  129. * if there are no more interrupts enabled in this
  130. * group, disable corresponding IP
  131. */
  132. if (mask == intr_group[group].mask)
  133. disable_local_irq(group_to_ip(group));
  134. }
  135. }
  136. static void rb532_mask_and_ack_irq(unsigned int irq_nr)
  137. {
  138. rb532_disable_irq(irq_nr);
  139. ack_local_irq(group_to_ip(irq_to_group(irq_nr)));
  140. }
  141. static struct irq_chip rc32434_irq_type = {
  142. .name = "RB532",
  143. .ack = rb532_disable_irq,
  144. .mask = rb532_disable_irq,
  145. .mask_ack = rb532_mask_and_ack_irq,
  146. .unmask = rb532_enable_irq,
  147. };
  148. void __init arch_init_irq(void)
  149. {
  150. int i;
  151. pr_info("Initializing IRQ's: %d out of %d\n", RC32434_NR_IRQS, NR_IRQS);
  152. for (i = 0; i < RC32434_NR_IRQS; i++)
  153. set_irq_chip_and_handler(i, &rc32434_irq_type,
  154. handle_level_irq);
  155. }
  156. /* Main Interrupt dispatcher */
  157. asmlinkage void plat_irq_dispatch(void)
  158. {
  159. unsigned int ip, pend, group;
  160. volatile unsigned int *addr;
  161. unsigned int cp0_cause = read_c0_cause() & read_c0_status();
  162. if (cp0_cause & CAUSEF_IP7) {
  163. do_IRQ(7);
  164. } else {
  165. ip = (cp0_cause & 0x7c00);
  166. if (ip) {
  167. group = 21 + (fls(ip) - 32);
  168. addr = intr_group[group].base_addr;
  169. pend = READ_PEND(addr);
  170. pend &= ~READ_MASK(addr); /* only unmasked interrupts */
  171. pend = 39 + (fls(pend) - 32);
  172. do_IRQ((group << 5) + pend);
  173. }
  174. }
  175. }