irq.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * linux/arch/arm/mach-pxa/irq.c
  3. *
  4. * Generic PXA IRQ handling, GPIO IRQ demultiplexing, etc.
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Jun 15, 2001
  8. * Copyright: MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/ptrace.h>
  18. #include <asm/hardware.h>
  19. #include <asm/irq.h>
  20. #include <asm/mach/irq.h>
  21. #include <asm/arch/pxa-regs.h>
  22. #include "generic.h"
  23. /*
  24. * This is for peripheral IRQs internal to the PXA chip.
  25. */
  26. static void pxa_mask_low_irq(unsigned int irq)
  27. {
  28. ICMR &= ~(1 << (irq + PXA_IRQ_SKIP));
  29. }
  30. static void pxa_unmask_low_irq(unsigned int irq)
  31. {
  32. ICMR |= (1 << (irq + PXA_IRQ_SKIP));
  33. }
  34. static struct irqchip pxa_internal_chip_low = {
  35. .ack = pxa_mask_low_irq,
  36. .mask = pxa_mask_low_irq,
  37. .unmask = pxa_unmask_low_irq,
  38. };
  39. #if PXA_INTERNAL_IRQS > 32
  40. /*
  41. * This is for the second set of internal IRQs as found on the PXA27x.
  42. */
  43. static void pxa_mask_high_irq(unsigned int irq)
  44. {
  45. ICMR2 &= ~(1 << (irq - 32 + PXA_IRQ_SKIP));
  46. }
  47. static void pxa_unmask_high_irq(unsigned int irq)
  48. {
  49. ICMR2 |= (1 << (irq - 32 + PXA_IRQ_SKIP));
  50. }
  51. static struct irqchip pxa_internal_chip_high = {
  52. .ack = pxa_mask_high_irq,
  53. .mask = pxa_mask_high_irq,
  54. .unmask = pxa_unmask_high_irq,
  55. };
  56. #endif
  57. /*
  58. * PXA GPIO edge detection for IRQs:
  59. * IRQs are generated on Falling-Edge, Rising-Edge, or both.
  60. * Use this instead of directly setting GRER/GFER.
  61. */
  62. static long GPIO_IRQ_rising_edge[4];
  63. static long GPIO_IRQ_falling_edge[4];
  64. static long GPIO_IRQ_mask[4];
  65. static int pxa_gpio_irq_type(unsigned int irq, unsigned int type)
  66. {
  67. int gpio, idx;
  68. gpio = IRQ_TO_GPIO(irq);
  69. idx = gpio >> 5;
  70. if (type == IRQT_PROBE) {
  71. /* Don't mess with enabled GPIOs using preconfigured edges or
  72. GPIOs set to alternate function during probe */
  73. if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx]) &
  74. GPIO_bit(gpio))
  75. return 0;
  76. if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
  77. return 0;
  78. type = __IRQT_RISEDGE | __IRQT_FALEDGE;
  79. }
  80. /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */
  81. pxa_gpio_mode(gpio | GPIO_IN);
  82. if (type & __IRQT_RISEDGE) {
  83. /* printk("rising "); */
  84. __set_bit (gpio, GPIO_IRQ_rising_edge);
  85. } else
  86. __clear_bit (gpio, GPIO_IRQ_rising_edge);
  87. if (type & __IRQT_FALEDGE) {
  88. /* printk("falling "); */
  89. __set_bit (gpio, GPIO_IRQ_falling_edge);
  90. } else
  91. __clear_bit (gpio, GPIO_IRQ_falling_edge);
  92. /* printk("edges\n"); */
  93. GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
  94. GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
  95. return 0;
  96. }
  97. /*
  98. * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1.
  99. */
  100. static void pxa_ack_low_gpio(unsigned int irq)
  101. {
  102. GEDR0 = (1 << (irq - IRQ_GPIO0));
  103. }
  104. static struct irqchip pxa_low_gpio_chip = {
  105. .ack = pxa_ack_low_gpio,
  106. .mask = pxa_mask_low_irq,
  107. .unmask = pxa_unmask_low_irq,
  108. .set_type = pxa_gpio_irq_type,
  109. };
  110. /*
  111. * Demux handler for GPIO>=2 edge detect interrupts
  112. */
  113. static void pxa_gpio_demux_handler(unsigned int irq, struct irqdesc *desc,
  114. struct pt_regs *regs)
  115. {
  116. unsigned int mask;
  117. int loop;
  118. do {
  119. loop = 0;
  120. mask = GEDR0 & ~3;
  121. if (mask) {
  122. GEDR0 = mask;
  123. irq = IRQ_GPIO(2);
  124. desc = irq_desc + irq;
  125. mask >>= 2;
  126. do {
  127. if (mask & 1)
  128. desc_handle_irq(irq, desc, regs);
  129. irq++;
  130. desc++;
  131. mask >>= 1;
  132. } while (mask);
  133. loop = 1;
  134. }
  135. mask = GEDR1;
  136. if (mask) {
  137. GEDR1 = mask;
  138. irq = IRQ_GPIO(32);
  139. desc = irq_desc + irq;
  140. do {
  141. if (mask & 1)
  142. desc_handle_irq(irq, desc, regs);
  143. irq++;
  144. desc++;
  145. mask >>= 1;
  146. } while (mask);
  147. loop = 1;
  148. }
  149. mask = GEDR2;
  150. if (mask) {
  151. GEDR2 = mask;
  152. irq = IRQ_GPIO(64);
  153. desc = irq_desc + irq;
  154. do {
  155. if (mask & 1)
  156. desc_handle_irq(irq, desc, regs);
  157. irq++;
  158. desc++;
  159. mask >>= 1;
  160. } while (mask);
  161. loop = 1;
  162. }
  163. #if PXA_LAST_GPIO >= 96
  164. mask = GEDR3;
  165. if (mask) {
  166. GEDR3 = mask;
  167. irq = IRQ_GPIO(96);
  168. desc = irq_desc + irq;
  169. do {
  170. if (mask & 1)
  171. desc_handle_irq(irq, desc, regs);
  172. irq++;
  173. desc++;
  174. mask >>= 1;
  175. } while (mask);
  176. loop = 1;
  177. }
  178. #endif
  179. } while (loop);
  180. }
  181. static void pxa_ack_muxed_gpio(unsigned int irq)
  182. {
  183. int gpio = irq - IRQ_GPIO(2) + 2;
  184. GEDR(gpio) = GPIO_bit(gpio);
  185. }
  186. static void pxa_mask_muxed_gpio(unsigned int irq)
  187. {
  188. int gpio = irq - IRQ_GPIO(2) + 2;
  189. __clear_bit(gpio, GPIO_IRQ_mask);
  190. GRER(gpio) &= ~GPIO_bit(gpio);
  191. GFER(gpio) &= ~GPIO_bit(gpio);
  192. }
  193. static void pxa_unmask_muxed_gpio(unsigned int irq)
  194. {
  195. int gpio = irq - IRQ_GPIO(2) + 2;
  196. int idx = gpio >> 5;
  197. __set_bit(gpio, GPIO_IRQ_mask);
  198. GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
  199. GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
  200. }
  201. static struct irqchip pxa_muxed_gpio_chip = {
  202. .ack = pxa_ack_muxed_gpio,
  203. .mask = pxa_mask_muxed_gpio,
  204. .unmask = pxa_unmask_muxed_gpio,
  205. .set_type = pxa_gpio_irq_type,
  206. };
  207. void __init pxa_init_irq(void)
  208. {
  209. int irq;
  210. /* disable all IRQs */
  211. ICMR = 0;
  212. /* all IRQs are IRQ, not FIQ */
  213. ICLR = 0;
  214. /* clear all GPIO edge detects */
  215. GFER0 = 0;
  216. GFER1 = 0;
  217. GFER2 = 0;
  218. GRER0 = 0;
  219. GRER1 = 0;
  220. GRER2 = 0;
  221. GEDR0 = GEDR0;
  222. GEDR1 = GEDR1;
  223. GEDR2 = GEDR2;
  224. #ifdef CONFIG_PXA27x
  225. /* And similarly for the extra regs on the PXA27x */
  226. ICMR2 = 0;
  227. ICLR2 = 0;
  228. GFER3 = 0;
  229. GRER3 = 0;
  230. GEDR3 = GEDR3;
  231. #endif
  232. /* only unmasked interrupts kick us out of idle */
  233. ICCR = 1;
  234. /* GPIO 0 and 1 must have their mask bit always set */
  235. GPIO_IRQ_mask[0] = 3;
  236. for (irq = PXA_IRQ(PXA_IRQ_SKIP); irq <= PXA_IRQ(31); irq++) {
  237. set_irq_chip(irq, &pxa_internal_chip_low);
  238. set_irq_handler(irq, do_level_IRQ);
  239. set_irq_flags(irq, IRQF_VALID);
  240. }
  241. #if PXA_INTERNAL_IRQS > 32
  242. for (irq = PXA_IRQ(32); irq < PXA_IRQ(PXA_INTERNAL_IRQS); irq++) {
  243. set_irq_chip(irq, &pxa_internal_chip_high);
  244. set_irq_handler(irq, do_level_IRQ);
  245. set_irq_flags(irq, IRQF_VALID);
  246. }
  247. #endif
  248. for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
  249. set_irq_chip(irq, &pxa_low_gpio_chip);
  250. set_irq_handler(irq, do_edge_IRQ);
  251. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  252. }
  253. for (irq = IRQ_GPIO(2); irq <= IRQ_GPIO(PXA_LAST_GPIO); irq++) {
  254. set_irq_chip(irq, &pxa_muxed_gpio_chip);
  255. set_irq_handler(irq, do_edge_IRQ);
  256. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  257. }
  258. /* Install handler for GPIO>=2 edge detect interrupts */
  259. set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
  260. set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);
  261. }