irq.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * Copyright (C) NEC Electronics Corporation 2004-2006
  3. *
  4. * This file is based on the arch/mips/ddb5xxx/ddb5477/irq.c
  5. *
  6. * Copyright 2001 MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/irq.h>
  25. #include <linux/types.h>
  26. #include <linux/ptrace.h>
  27. #include <linux/delay.h>
  28. #include <asm/irq_cpu.h>
  29. #include <asm/mipsregs.h>
  30. #include <asm/addrspace.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/emma/emma2rh.h>
  33. static void emma2rh_irq_enable(struct irq_data *d)
  34. {
  35. unsigned int irq = d->irq - EMMA2RH_IRQ_BASE;
  36. u32 reg_value, reg_bitmask, reg_index;
  37. reg_index = EMMA2RH_BHIF_INT_EN_0 +
  38. (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
  39. reg_value = emma2rh_in32(reg_index);
  40. reg_bitmask = 0x1 << (irq % 32);
  41. emma2rh_out32(reg_index, reg_value | reg_bitmask);
  42. }
  43. static void emma2rh_irq_disable(struct irq_data *d)
  44. {
  45. unsigned int irq = d->irq - EMMA2RH_IRQ_BASE;
  46. u32 reg_value, reg_bitmask, reg_index;
  47. reg_index = EMMA2RH_BHIF_INT_EN_0 +
  48. (EMMA2RH_BHIF_INT_EN_1 - EMMA2RH_BHIF_INT_EN_0) * (irq / 32);
  49. reg_value = emma2rh_in32(reg_index);
  50. reg_bitmask = 0x1 << (irq % 32);
  51. emma2rh_out32(reg_index, reg_value & ~reg_bitmask);
  52. }
  53. struct irq_chip emma2rh_irq_controller = {
  54. .name = "emma2rh_irq",
  55. .irq_mask = emma2rh_irq_disable,
  56. .irq_unmask = emma2rh_irq_enable,
  57. };
  58. void emma2rh_irq_init(void)
  59. {
  60. u32 i;
  61. for (i = 0; i < NUM_EMMA2RH_IRQ; i++)
  62. irq_set_chip_and_handler_name(EMMA2RH_IRQ_BASE + i,
  63. &emma2rh_irq_controller,
  64. handle_level_irq, "level");
  65. }
  66. static void emma2rh_sw_irq_enable(struct irq_data *d)
  67. {
  68. unsigned int irq = d->irq - EMMA2RH_SW_IRQ_BASE;
  69. u32 reg;
  70. reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
  71. reg |= 1 << irq;
  72. emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
  73. }
  74. static void emma2rh_sw_irq_disable(struct irq_data *d)
  75. {
  76. unsigned int irq = d->irq - EMMA2RH_SW_IRQ_BASE;
  77. u32 reg;
  78. reg = emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
  79. reg &= ~(1 << irq);
  80. emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, reg);
  81. }
  82. struct irq_chip emma2rh_sw_irq_controller = {
  83. .name = "emma2rh_sw_irq",
  84. .irq_mask = emma2rh_sw_irq_disable,
  85. .irq_unmask = emma2rh_sw_irq_enable,
  86. };
  87. void emma2rh_sw_irq_init(void)
  88. {
  89. u32 i;
  90. for (i = 0; i < NUM_EMMA2RH_IRQ_SW; i++)
  91. irq_set_chip_and_handler_name(EMMA2RH_SW_IRQ_BASE + i,
  92. &emma2rh_sw_irq_controller,
  93. handle_level_irq, "level");
  94. }
  95. static void emma2rh_gpio_irq_enable(struct irq_data *d)
  96. {
  97. unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
  98. u32 reg;
  99. reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
  100. reg |= 1 << irq;
  101. emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
  102. }
  103. static void emma2rh_gpio_irq_disable(struct irq_data *d)
  104. {
  105. unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
  106. u32 reg;
  107. reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
  108. reg &= ~(1 << irq);
  109. emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
  110. }
  111. static void emma2rh_gpio_irq_ack(struct irq_data *d)
  112. {
  113. unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
  114. emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
  115. }
  116. static void emma2rh_gpio_irq_mask_ack(struct irq_data *d)
  117. {
  118. unsigned int irq = d->irq - EMMA2RH_GPIO_IRQ_BASE;
  119. u32 reg;
  120. emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~(1 << irq));
  121. reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
  122. reg &= ~(1 << irq);
  123. emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg);
  124. }
  125. struct irq_chip emma2rh_gpio_irq_controller = {
  126. .name = "emma2rh_gpio_irq",
  127. .irq_ack = emma2rh_gpio_irq_ack,
  128. .irq_mask = emma2rh_gpio_irq_disable,
  129. .irq_mask_ack = emma2rh_gpio_irq_mask_ack,
  130. .irq_unmask = emma2rh_gpio_irq_enable,
  131. };
  132. void emma2rh_gpio_irq_init(void)
  133. {
  134. u32 i;
  135. for (i = 0; i < NUM_EMMA2RH_IRQ_GPIO; i++)
  136. irq_set_chip_and_handler_name(EMMA2RH_GPIO_IRQ_BASE + i,
  137. &emma2rh_gpio_irq_controller,
  138. handle_edge_irq, "edge");
  139. }
  140. static struct irqaction irq_cascade = {
  141. .handler = no_action,
  142. .flags = IRQF_NO_THREAD,
  143. .name = "cascade",
  144. .dev_id = NULL,
  145. .next = NULL,
  146. };
  147. /*
  148. * the first level int-handler will jump here if it is a emma2rh irq
  149. */
  150. void emma2rh_irq_dispatch(void)
  151. {
  152. u32 intStatus;
  153. u32 bitmask;
  154. u32 i;
  155. intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_0) &
  156. emma2rh_in32(EMMA2RH_BHIF_INT_EN_0);
  157. #ifdef EMMA2RH_SW_CASCADE
  158. if (intStatus & (1UL << EMMA2RH_SW_CASCADE)) {
  159. u32 swIntStatus;
  160. swIntStatus = emma2rh_in32(EMMA2RH_BHIF_SW_INT)
  161. & emma2rh_in32(EMMA2RH_BHIF_SW_INT_EN);
  162. for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
  163. if (swIntStatus & bitmask) {
  164. do_IRQ(EMMA2RH_SW_IRQ_BASE + i);
  165. return;
  166. }
  167. }
  168. }
  169. /* Skip S/W interrupt */
  170. intStatus &= ~(1UL << EMMA2RH_SW_CASCADE);
  171. #endif
  172. for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
  173. if (intStatus & bitmask) {
  174. do_IRQ(EMMA2RH_IRQ_BASE + i);
  175. return;
  176. }
  177. }
  178. intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_1) &
  179. emma2rh_in32(EMMA2RH_BHIF_INT_EN_1);
  180. #ifdef EMMA2RH_GPIO_CASCADE
  181. if (intStatus & (1UL << (EMMA2RH_GPIO_CASCADE % 32))) {
  182. u32 gpioIntStatus;
  183. gpioIntStatus = emma2rh_in32(EMMA2RH_GPIO_INT_ST)
  184. & emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
  185. for (i = 0, bitmask = 1; i < 32; i++, bitmask <<= 1) {
  186. if (gpioIntStatus & bitmask) {
  187. do_IRQ(EMMA2RH_GPIO_IRQ_BASE + i);
  188. return;
  189. }
  190. }
  191. }
  192. /* Skip GPIO interrupt */
  193. intStatus &= ~(1UL << (EMMA2RH_GPIO_CASCADE % 32));
  194. #endif
  195. for (i = 32, bitmask = 1; i < 64; i++, bitmask <<= 1) {
  196. if (intStatus & bitmask) {
  197. do_IRQ(EMMA2RH_IRQ_BASE + i);
  198. return;
  199. }
  200. }
  201. intStatus = emma2rh_in32(EMMA2RH_BHIF_INT_ST_2) &
  202. emma2rh_in32(EMMA2RH_BHIF_INT_EN_2);
  203. for (i = 64, bitmask = 1; i < 96; i++, bitmask <<= 1) {
  204. if (intStatus & bitmask) {
  205. do_IRQ(EMMA2RH_IRQ_BASE + i);
  206. return;
  207. }
  208. }
  209. }
  210. void __init arch_init_irq(void)
  211. {
  212. u32 reg;
  213. /* by default, interrupts are disabled. */
  214. emma2rh_out32(EMMA2RH_BHIF_INT_EN_0, 0);
  215. emma2rh_out32(EMMA2RH_BHIF_INT_EN_1, 0);
  216. emma2rh_out32(EMMA2RH_BHIF_INT_EN_2, 0);
  217. emma2rh_out32(EMMA2RH_BHIF_INT1_EN_0, 0);
  218. emma2rh_out32(EMMA2RH_BHIF_INT1_EN_1, 0);
  219. emma2rh_out32(EMMA2RH_BHIF_INT1_EN_2, 0);
  220. emma2rh_out32(EMMA2RH_BHIF_SW_INT_EN, 0);
  221. clear_c0_status(0xff00);
  222. set_c0_status(0x0400);
  223. #define GPIO_PCI (0xf<<15)
  224. /* setup GPIO interrupt for PCI interface */
  225. /* direction input */
  226. reg = emma2rh_in32(EMMA2RH_GPIO_DIR);
  227. emma2rh_out32(EMMA2RH_GPIO_DIR, reg & ~GPIO_PCI);
  228. /* disable interrupt */
  229. reg = emma2rh_in32(EMMA2RH_GPIO_INT_MASK);
  230. emma2rh_out32(EMMA2RH_GPIO_INT_MASK, reg & ~GPIO_PCI);
  231. /* level triggerd */
  232. reg = emma2rh_in32(EMMA2RH_GPIO_INT_MODE);
  233. emma2rh_out32(EMMA2RH_GPIO_INT_MODE, reg | GPIO_PCI);
  234. reg = emma2rh_in32(EMMA2RH_GPIO_INT_CND_A);
  235. emma2rh_out32(EMMA2RH_GPIO_INT_CND_A, reg & (~GPIO_PCI));
  236. /* interrupt clear */
  237. emma2rh_out32(EMMA2RH_GPIO_INT_ST, ~GPIO_PCI);
  238. /* init all controllers */
  239. emma2rh_irq_init();
  240. emma2rh_sw_irq_init();
  241. emma2rh_gpio_irq_init();
  242. mips_cpu_irq_init();
  243. /* setup cascade interrupts */
  244. setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_SW_CASCADE, &irq_cascade);
  245. setup_irq(EMMA2RH_IRQ_BASE + EMMA2RH_GPIO_CASCADE, &irq_cascade);
  246. setup_irq(MIPS_CPU_IRQ_BASE + 2, &irq_cascade);
  247. }
  248. asmlinkage void plat_irq_dispatch(void)
  249. {
  250. unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
  251. if (pending & STATUSF_IP7)
  252. do_IRQ(MIPS_CPU_IRQ_BASE + 7);
  253. else if (pending & STATUSF_IP2)
  254. emma2rh_irq_dispatch();
  255. else if (pending & STATUSF_IP1)
  256. do_IRQ(MIPS_CPU_IRQ_BASE + 1);
  257. else if (pending & STATUSF_IP0)
  258. do_IRQ(MIPS_CPU_IRQ_BASE + 0);
  259. else
  260. spurious_interrupt();
  261. }