irq.c 6.5 KB

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