irq.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * linux/arch/arm/mach-imx/irq.c
  3. *
  4. * Copyright (C) 1999 ARM Limited
  5. * Copyright (C) 2002 Shane Nay (shane@minirl.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. * 03/03/2004 Sascha Hauer <sascha@saschahauer.de>
  22. * Copied from the motorola bsp package and added gpio demux
  23. * interrupt handler
  24. */
  25. #include <linux/init.h>
  26. #include <linux/list.h>
  27. #include <linux/timer.h>
  28. #include <asm/hardware.h>
  29. #include <asm/irq.h>
  30. #include <asm/io.h>
  31. #include <asm/mach/irq.h>
  32. /*
  33. *
  34. * We simply use the ENABLE DISABLE registers inside of the IMX
  35. * to turn on/off specific interrupts. FIXME- We should
  36. * also add support for the accelerated interrupt controller
  37. * by putting offets to irq jump code in the appropriate
  38. * places.
  39. *
  40. */
  41. #define INTCNTL_OFF 0x00
  42. #define NIMASK_OFF 0x04
  43. #define INTENNUM_OFF 0x08
  44. #define INTDISNUM_OFF 0x0C
  45. #define INTENABLEH_OFF 0x10
  46. #define INTENABLEL_OFF 0x14
  47. #define INTTYPEH_OFF 0x18
  48. #define INTTYPEL_OFF 0x1C
  49. #define NIPRIORITY_OFF(x) (0x20+4*(7-(x)))
  50. #define NIVECSR_OFF 0x40
  51. #define FIVECSR_OFF 0x44
  52. #define INTSRCH_OFF 0x48
  53. #define INTSRCL_OFF 0x4C
  54. #define INTFRCH_OFF 0x50
  55. #define INTFRCL_OFF 0x54
  56. #define NIPNDH_OFF 0x58
  57. #define NIPNDL_OFF 0x5C
  58. #define FIPNDH_OFF 0x60
  59. #define FIPNDL_OFF 0x64
  60. #define VA_AITC_BASE IO_ADDRESS(IMX_AITC_BASE)
  61. #define IMX_AITC_INTCNTL (VA_AITC_BASE + INTCNTL_OFF)
  62. #define IMX_AITC_NIMASK (VA_AITC_BASE + NIMASK_OFF)
  63. #define IMX_AITC_INTENNUM (VA_AITC_BASE + INTENNUM_OFF)
  64. #define IMX_AITC_INTDISNUM (VA_AITC_BASE + INTDISNUM_OFF)
  65. #define IMX_AITC_INTENABLEH (VA_AITC_BASE + INTENABLEH_OFF)
  66. #define IMX_AITC_INTENABLEL (VA_AITC_BASE + INTENABLEL_OFF)
  67. #define IMX_AITC_INTTYPEH (VA_AITC_BASE + INTTYPEH_OFF)
  68. #define IMX_AITC_INTTYPEL (VA_AITC_BASE + INTTYPEL_OFF)
  69. #define IMX_AITC_NIPRIORITY(x) (VA_AITC_BASE + NIPRIORITY_OFF(x))
  70. #define IMX_AITC_NIVECSR (VA_AITC_BASE + NIVECSR_OFF)
  71. #define IMX_AITC_FIVECSR (VA_AITC_BASE + FIVECSR_OFF)
  72. #define IMX_AITC_INTSRCH (VA_AITC_BASE + INTSRCH_OFF)
  73. #define IMX_AITC_INTSRCL (VA_AITC_BASE + INTSRCL_OFF)
  74. #define IMX_AITC_INTFRCH (VA_AITC_BASE + INTFRCH_OFF)
  75. #define IMX_AITC_INTFRCL (VA_AITC_BASE + INTFRCL_OFF)
  76. #define IMX_AITC_NIPNDH (VA_AITC_BASE + NIPNDH_OFF)
  77. #define IMX_AITC_NIPNDL (VA_AITC_BASE + NIPNDL_OFF)
  78. #define IMX_AITC_FIPNDH (VA_AITC_BASE + FIPNDH_OFF)
  79. #define IMX_AITC_FIPNDL (VA_AITC_BASE + FIPNDL_OFF)
  80. #if 0
  81. #define DEBUG_IRQ(fmt...) printk(fmt)
  82. #else
  83. #define DEBUG_IRQ(fmt...) do { } while (0)
  84. #endif
  85. static void
  86. imx_mask_irq(unsigned int irq)
  87. {
  88. __raw_writel(irq, IMX_AITC_INTDISNUM);
  89. }
  90. static void
  91. imx_unmask_irq(unsigned int irq)
  92. {
  93. __raw_writel(irq, IMX_AITC_INTENNUM);
  94. }
  95. static int
  96. imx_gpio_irq_type(unsigned int _irq, unsigned int type)
  97. {
  98. unsigned int irq_type = 0, irq, reg, bit;
  99. irq = _irq - IRQ_GPIOA(0);
  100. reg = irq >> 5;
  101. bit = 1 << (irq % 32);
  102. if (type == IRQT_PROBE) {
  103. /* Don't mess with enabled GPIOs using preconfigured edges or
  104. GPIOs set to alternate function during probe */
  105. /* TODO: support probe */
  106. // if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx]) &
  107. // GPIO_bit(gpio))
  108. // return 0;
  109. // if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
  110. // return 0;
  111. // type = __IRQT_RISEDGE | __IRQT_FALEDGE;
  112. }
  113. GIUS(reg) |= bit;
  114. DDIR(reg) &= ~(bit);
  115. DEBUG_IRQ("setting type of irq %d to ", _irq);
  116. if (type & __IRQT_RISEDGE) {
  117. DEBUG_IRQ("rising edges\n");
  118. irq_type = 0x0;
  119. }
  120. if (type & __IRQT_FALEDGE) {
  121. DEBUG_IRQ("falling edges\n");
  122. irq_type = 0x1;
  123. }
  124. if (type & __IRQT_LOWLVL) {
  125. DEBUG_IRQ("low level\n");
  126. irq_type = 0x3;
  127. }
  128. if (type & __IRQT_HIGHLVL) {
  129. DEBUG_IRQ("high level\n");
  130. irq_type = 0x2;
  131. }
  132. if (irq % 32 < 16) {
  133. ICR1(reg) = (ICR1(reg) & ~(0x3 << ((irq % 16) * 2))) |
  134. (irq_type << ((irq % 16) * 2));
  135. } else {
  136. ICR2(reg) = (ICR2(reg) & ~(0x3 << ((irq % 16) * 2))) |
  137. (irq_type << ((irq % 16) * 2));
  138. }
  139. return 0;
  140. }
  141. static void
  142. imx_gpio_ack_irq(unsigned int irq)
  143. {
  144. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  145. ISR(IRQ_TO_REG(irq)) = 1 << ((irq - IRQ_GPIOA(0)) % 32);
  146. }
  147. static void
  148. imx_gpio_mask_irq(unsigned int irq)
  149. {
  150. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  151. IMR(IRQ_TO_REG(irq)) &= ~( 1 << ((irq - IRQ_GPIOA(0)) % 32));
  152. }
  153. static void
  154. imx_gpio_unmask_irq(unsigned int irq)
  155. {
  156. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  157. IMR(IRQ_TO_REG(irq)) |= 1 << ((irq - IRQ_GPIOA(0)) % 32);
  158. }
  159. static void
  160. imx_gpio_handler(unsigned int mask, unsigned int irq,
  161. struct irq_desc *desc)
  162. {
  163. desc = irq_desc + irq;
  164. while (mask) {
  165. if (mask & 1) {
  166. DEBUG_IRQ("handling irq %d\n", irq);
  167. desc_handle_irq(irq, desc);
  168. }
  169. irq++;
  170. desc++;
  171. mask >>= 1;
  172. }
  173. }
  174. static void
  175. imx_gpioa_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  176. {
  177. unsigned int mask, irq;
  178. mask = ISR(0);
  179. irq = IRQ_GPIOA(0);
  180. imx_gpio_handler(mask, irq, desc);
  181. }
  182. static void
  183. imx_gpiob_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  184. {
  185. unsigned int mask, irq;
  186. mask = ISR(1);
  187. irq = IRQ_GPIOB(0);
  188. imx_gpio_handler(mask, irq, desc);
  189. }
  190. static void
  191. imx_gpioc_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  192. {
  193. unsigned int mask, irq;
  194. mask = ISR(2);
  195. irq = IRQ_GPIOC(0);
  196. imx_gpio_handler(mask, irq, desc);
  197. }
  198. static void
  199. imx_gpiod_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  200. {
  201. unsigned int mask, irq;
  202. mask = ISR(3);
  203. irq = IRQ_GPIOD(0);
  204. imx_gpio_handler(mask, irq, desc);
  205. }
  206. static struct irq_chip imx_internal_chip = {
  207. .name = "MPU",
  208. .ack = imx_mask_irq,
  209. .mask = imx_mask_irq,
  210. .unmask = imx_unmask_irq,
  211. };
  212. static struct irq_chip imx_gpio_chip = {
  213. .name = "GPIO",
  214. .ack = imx_gpio_ack_irq,
  215. .mask = imx_gpio_mask_irq,
  216. .unmask = imx_gpio_unmask_irq,
  217. .set_type = imx_gpio_irq_type,
  218. };
  219. void __init
  220. imx_init_irq(void)
  221. {
  222. unsigned int irq;
  223. DEBUG_IRQ("Initializing imx interrupts\n");
  224. /* Disable all interrupts initially. */
  225. /* Do not rely on the bootloader. */
  226. __raw_writel(0, IMX_AITC_INTENABLEH);
  227. __raw_writel(0, IMX_AITC_INTENABLEL);
  228. /* Mask all GPIO interrupts as well */
  229. IMR(0) = 0;
  230. IMR(1) = 0;
  231. IMR(2) = 0;
  232. IMR(3) = 0;
  233. for (irq = 0; irq < IMX_IRQS; irq++) {
  234. set_irq_chip(irq, &imx_internal_chip);
  235. set_irq_handler(irq, handle_level_irq);
  236. set_irq_flags(irq, IRQF_VALID);
  237. }
  238. for (irq = IRQ_GPIOA(0); irq < IRQ_GPIOD(32); irq++) {
  239. set_irq_chip(irq, &imx_gpio_chip);
  240. set_irq_handler(irq, handle_edge_irq);
  241. set_irq_flags(irq, IRQF_VALID);
  242. }
  243. set_irq_chained_handler(GPIO_INT_PORTA, imx_gpioa_demux_handler);
  244. set_irq_chained_handler(GPIO_INT_PORTB, imx_gpiob_demux_handler);
  245. set_irq_chained_handler(GPIO_INT_PORTC, imx_gpioc_demux_handler);
  246. set_irq_chained_handler(GPIO_INT_PORTD, imx_gpiod_demux_handler);
  247. /* Release masking of interrupts according to priority */
  248. __raw_writel(-1, IMX_AITC_NIMASK);
  249. }