irq.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 <linux/io.h>
  29. #include <mach/hardware.h>
  30. #include <asm/irq.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.
  36. *
  37. */
  38. #define INTCNTL_OFF 0x00
  39. #define NIMASK_OFF 0x04
  40. #define INTENNUM_OFF 0x08
  41. #define INTDISNUM_OFF 0x0C
  42. #define INTENABLEH_OFF 0x10
  43. #define INTENABLEL_OFF 0x14
  44. #define INTTYPEH_OFF 0x18
  45. #define INTTYPEL_OFF 0x1C
  46. #define NIPRIORITY_OFF(x) (0x20+4*(7-(x)))
  47. #define NIVECSR_OFF 0x40
  48. #define FIVECSR_OFF 0x44
  49. #define INTSRCH_OFF 0x48
  50. #define INTSRCL_OFF 0x4C
  51. #define INTFRCH_OFF 0x50
  52. #define INTFRCL_OFF 0x54
  53. #define NIPNDH_OFF 0x58
  54. #define NIPNDL_OFF 0x5C
  55. #define FIPNDH_OFF 0x60
  56. #define FIPNDL_OFF 0x64
  57. #define VA_AITC_BASE IO_ADDRESS(IMX_AITC_BASE)
  58. #define IMX_AITC_INTCNTL (VA_AITC_BASE + INTCNTL_OFF)
  59. #define IMX_AITC_NIMASK (VA_AITC_BASE + NIMASK_OFF)
  60. #define IMX_AITC_INTENNUM (VA_AITC_BASE + INTENNUM_OFF)
  61. #define IMX_AITC_INTDISNUM (VA_AITC_BASE + INTDISNUM_OFF)
  62. #define IMX_AITC_INTENABLEH (VA_AITC_BASE + INTENABLEH_OFF)
  63. #define IMX_AITC_INTENABLEL (VA_AITC_BASE + INTENABLEL_OFF)
  64. #define IMX_AITC_INTTYPEH (VA_AITC_BASE + INTTYPEH_OFF)
  65. #define IMX_AITC_INTTYPEL (VA_AITC_BASE + INTTYPEL_OFF)
  66. #define IMX_AITC_NIPRIORITY(x) (VA_AITC_BASE + NIPRIORITY_OFF(x))
  67. #define IMX_AITC_NIVECSR (VA_AITC_BASE + NIVECSR_OFF)
  68. #define IMX_AITC_FIVECSR (VA_AITC_BASE + FIVECSR_OFF)
  69. #define IMX_AITC_INTSRCH (VA_AITC_BASE + INTSRCH_OFF)
  70. #define IMX_AITC_INTSRCL (VA_AITC_BASE + INTSRCL_OFF)
  71. #define IMX_AITC_INTFRCH (VA_AITC_BASE + INTFRCH_OFF)
  72. #define IMX_AITC_INTFRCL (VA_AITC_BASE + INTFRCL_OFF)
  73. #define IMX_AITC_NIPNDH (VA_AITC_BASE + NIPNDH_OFF)
  74. #define IMX_AITC_NIPNDL (VA_AITC_BASE + NIPNDL_OFF)
  75. #define IMX_AITC_FIPNDH (VA_AITC_BASE + FIPNDH_OFF)
  76. #define IMX_AITC_FIPNDL (VA_AITC_BASE + FIPNDL_OFF)
  77. #if 0
  78. #define DEBUG_IRQ(fmt...) printk(fmt)
  79. #else
  80. #define DEBUG_IRQ(fmt...) do { } while (0)
  81. #endif
  82. static void
  83. imx_mask_irq(unsigned int irq)
  84. {
  85. __raw_writel(irq, IMX_AITC_INTDISNUM);
  86. }
  87. static void
  88. imx_unmask_irq(unsigned int irq)
  89. {
  90. __raw_writel(irq, IMX_AITC_INTENNUM);
  91. }
  92. #ifdef CONFIG_FIQ
  93. int imx_set_irq_fiq(unsigned int irq, unsigned int type)
  94. {
  95. unsigned int irqt;
  96. if (irq >= IMX_IRQS)
  97. return -EINVAL;
  98. if (irq < IMX_IRQS / 2) {
  99. irqt = __raw_readl(IMX_AITC_INTTYPEL) & ~(1 << irq);
  100. __raw_writel(irqt | (!!type << irq), IMX_AITC_INTTYPEL);
  101. } else {
  102. irq -= IMX_IRQS / 2;
  103. irqt = __raw_readl(IMX_AITC_INTTYPEH) & ~(1 << irq);
  104. __raw_writel(irqt | (!!type << irq), IMX_AITC_INTTYPEH);
  105. }
  106. return 0;
  107. }
  108. EXPORT_SYMBOL(imx_set_irq_fiq);
  109. #endif /* CONFIG_FIQ */
  110. static int
  111. imx_gpio_irq_type(unsigned int _irq, unsigned int type)
  112. {
  113. unsigned int irq_type = 0, irq, reg, bit;
  114. irq = _irq - IRQ_GPIOA(0);
  115. reg = irq >> 5;
  116. bit = 1 << (irq % 32);
  117. if (type == IRQ_TYPE_PROBE) {
  118. /* Don't mess with enabled GPIOs using preconfigured edges or
  119. GPIOs set to alternate function during probe */
  120. /* TODO: support probe */
  121. // if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx]) &
  122. // GPIO_bit(gpio))
  123. // return 0;
  124. // if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
  125. // return 0;
  126. // type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  127. }
  128. GIUS(reg) |= bit;
  129. DDIR(reg) &= ~(bit);
  130. DEBUG_IRQ("setting type of irq %d to ", _irq);
  131. if (type & IRQ_TYPE_EDGE_RISING) {
  132. DEBUG_IRQ("rising edges\n");
  133. irq_type = 0x0;
  134. }
  135. if (type & IRQ_TYPE_EDGE_FALLING) {
  136. DEBUG_IRQ("falling edges\n");
  137. irq_type = 0x1;
  138. }
  139. if (type & IRQ_TYPE_LEVEL_LOW) {
  140. DEBUG_IRQ("low level\n");
  141. irq_type = 0x3;
  142. }
  143. if (type & IRQ_TYPE_LEVEL_HIGH) {
  144. DEBUG_IRQ("high level\n");
  145. irq_type = 0x2;
  146. }
  147. if (irq % 32 < 16) {
  148. ICR1(reg) = (ICR1(reg) & ~(0x3 << ((irq % 16) * 2))) |
  149. (irq_type << ((irq % 16) * 2));
  150. } else {
  151. ICR2(reg) = (ICR2(reg) & ~(0x3 << ((irq % 16) * 2))) |
  152. (irq_type << ((irq % 16) * 2));
  153. }
  154. return 0;
  155. }
  156. static void
  157. imx_gpio_ack_irq(unsigned int irq)
  158. {
  159. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  160. ISR(IRQ_TO_REG(irq)) = 1 << ((irq - IRQ_GPIOA(0)) % 32);
  161. }
  162. static void
  163. imx_gpio_mask_irq(unsigned int irq)
  164. {
  165. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  166. IMR(IRQ_TO_REG(irq)) &= ~( 1 << ((irq - IRQ_GPIOA(0)) % 32));
  167. }
  168. static void
  169. imx_gpio_unmask_irq(unsigned int irq)
  170. {
  171. DEBUG_IRQ("%s: irq %d\n", __func__, irq);
  172. IMR(IRQ_TO_REG(irq)) |= 1 << ((irq - IRQ_GPIOA(0)) % 32);
  173. }
  174. static void
  175. imx_gpio_handler(unsigned int mask, unsigned int irq,
  176. struct irq_desc *desc)
  177. {
  178. while (mask) {
  179. if (mask & 1) {
  180. DEBUG_IRQ("handling irq %d\n", irq);
  181. generic_handle_irq(irq);
  182. }
  183. irq++;
  184. mask >>= 1;
  185. }
  186. }
  187. static void
  188. imx_gpioa_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  189. {
  190. unsigned int mask, irq;
  191. mask = ISR(0);
  192. irq = IRQ_GPIOA(0);
  193. imx_gpio_handler(mask, irq, desc);
  194. }
  195. static void
  196. imx_gpiob_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  197. {
  198. unsigned int mask, irq;
  199. mask = ISR(1);
  200. irq = IRQ_GPIOB(0);
  201. imx_gpio_handler(mask, irq, desc);
  202. }
  203. static void
  204. imx_gpioc_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  205. {
  206. unsigned int mask, irq;
  207. mask = ISR(2);
  208. irq = IRQ_GPIOC(0);
  209. imx_gpio_handler(mask, irq, desc);
  210. }
  211. static void
  212. imx_gpiod_demux_handler(unsigned int irq_unused, struct irq_desc *desc)
  213. {
  214. unsigned int mask, irq;
  215. mask = ISR(3);
  216. irq = IRQ_GPIOD(0);
  217. imx_gpio_handler(mask, irq, desc);
  218. }
  219. static struct irq_chip imx_internal_chip = {
  220. .name = "MPU",
  221. .ack = imx_mask_irq,
  222. .mask = imx_mask_irq,
  223. .unmask = imx_unmask_irq,
  224. };
  225. static struct irq_chip imx_gpio_chip = {
  226. .name = "GPIO",
  227. .ack = imx_gpio_ack_irq,
  228. .mask = imx_gpio_mask_irq,
  229. .unmask = imx_gpio_unmask_irq,
  230. .set_type = imx_gpio_irq_type,
  231. };
  232. void __init
  233. imx_init_irq(void)
  234. {
  235. unsigned int irq;
  236. DEBUG_IRQ("Initializing imx interrupts\n");
  237. /* Disable all interrupts initially. */
  238. /* Do not rely on the bootloader. */
  239. __raw_writel(0, IMX_AITC_INTENABLEH);
  240. __raw_writel(0, IMX_AITC_INTENABLEL);
  241. /* Mask all GPIO interrupts as well */
  242. IMR(0) = 0;
  243. IMR(1) = 0;
  244. IMR(2) = 0;
  245. IMR(3) = 0;
  246. for (irq = 0; irq < IMX_IRQS; irq++) {
  247. set_irq_chip(irq, &imx_internal_chip);
  248. set_irq_handler(irq, handle_level_irq);
  249. set_irq_flags(irq, IRQF_VALID);
  250. }
  251. for (irq = IRQ_GPIOA(0); irq < IRQ_GPIOD(32); irq++) {
  252. set_irq_chip(irq, &imx_gpio_chip);
  253. set_irq_handler(irq, handle_edge_irq);
  254. set_irq_flags(irq, IRQF_VALID);
  255. }
  256. set_irq_chained_handler(GPIO_INT_PORTA, imx_gpioa_demux_handler);
  257. set_irq_chained_handler(GPIO_INT_PORTB, imx_gpiob_demux_handler);
  258. set_irq_chained_handler(GPIO_INT_PORTC, imx_gpioc_demux_handler);
  259. set_irq_chained_handler(GPIO_INT_PORTD, imx_gpiod_demux_handler);
  260. /* Release masking of interrupts according to priority */
  261. __raw_writel(-1, IMX_AITC_NIMASK);
  262. #ifdef CONFIG_FIQ
  263. /* Initialize FIQ */
  264. init_FIQ();
  265. #endif
  266. }