irq.c 6.5 KB

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