irq.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 irqdesc *desc,
  117. struct pt_regs *regs)
  118. {
  119. unsigned int mask;
  120. int loop;
  121. do {
  122. loop = 0;
  123. mask = GEDR0 & ~3;
  124. if (mask) {
  125. GEDR0 = mask;
  126. irq = IRQ_GPIO(2);
  127. desc = irq_desc + irq;
  128. mask >>= 2;
  129. do {
  130. if (mask & 1)
  131. desc_handle_irq(irq, desc, regs);
  132. irq++;
  133. desc++;
  134. mask >>= 1;
  135. } while (mask);
  136. loop = 1;
  137. }
  138. mask = GEDR1;
  139. if (mask) {
  140. GEDR1 = mask;
  141. irq = IRQ_GPIO(32);
  142. desc = irq_desc + irq;
  143. do {
  144. if (mask & 1)
  145. desc_handle_irq(irq, desc, regs);
  146. irq++;
  147. desc++;
  148. mask >>= 1;
  149. } while (mask);
  150. loop = 1;
  151. }
  152. mask = GEDR2;
  153. if (mask) {
  154. GEDR2 = mask;
  155. irq = IRQ_GPIO(64);
  156. desc = irq_desc + irq;
  157. do {
  158. if (mask & 1)
  159. desc_handle_irq(irq, desc, regs);
  160. irq++;
  161. desc++;
  162. mask >>= 1;
  163. } while (mask);
  164. loop = 1;
  165. }
  166. #if PXA_LAST_GPIO >= 96
  167. mask = GEDR3;
  168. if (mask) {
  169. GEDR3 = mask;
  170. irq = IRQ_GPIO(96);
  171. desc = irq_desc + irq;
  172. do {
  173. if (mask & 1)
  174. desc_handle_irq(irq, desc, regs);
  175. irq++;
  176. desc++;
  177. mask >>= 1;
  178. } while (mask);
  179. loop = 1;
  180. }
  181. #endif
  182. } while (loop);
  183. }
  184. static void pxa_ack_muxed_gpio(unsigned int irq)
  185. {
  186. int gpio = irq - IRQ_GPIO(2) + 2;
  187. GEDR(gpio) = GPIO_bit(gpio);
  188. }
  189. static void pxa_mask_muxed_gpio(unsigned int irq)
  190. {
  191. int gpio = irq - IRQ_GPIO(2) + 2;
  192. __clear_bit(gpio, GPIO_IRQ_mask);
  193. GRER(gpio) &= ~GPIO_bit(gpio);
  194. GFER(gpio) &= ~GPIO_bit(gpio);
  195. }
  196. static void pxa_unmask_muxed_gpio(unsigned int irq)
  197. {
  198. int gpio = irq - IRQ_GPIO(2) + 2;
  199. int idx = gpio >> 5;
  200. __set_bit(gpio, GPIO_IRQ_mask);
  201. GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
  202. GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
  203. }
  204. static struct irq_chip pxa_muxed_gpio_chip = {
  205. .name = "GPIO",
  206. .ack = pxa_ack_muxed_gpio,
  207. .mask = pxa_mask_muxed_gpio,
  208. .unmask = pxa_unmask_muxed_gpio,
  209. .set_type = pxa_gpio_irq_type,
  210. };
  211. void __init pxa_init_irq(void)
  212. {
  213. int irq;
  214. /* disable all IRQs */
  215. ICMR = 0;
  216. /* all IRQs are IRQ, not FIQ */
  217. ICLR = 0;
  218. /* clear all GPIO edge detects */
  219. GFER0 = 0;
  220. GFER1 = 0;
  221. GFER2 = 0;
  222. GRER0 = 0;
  223. GRER1 = 0;
  224. GRER2 = 0;
  225. GEDR0 = GEDR0;
  226. GEDR1 = GEDR1;
  227. GEDR2 = GEDR2;
  228. #ifdef CONFIG_PXA27x
  229. /* And similarly for the extra regs on the PXA27x */
  230. ICMR2 = 0;
  231. ICLR2 = 0;
  232. GFER3 = 0;
  233. GRER3 = 0;
  234. GEDR3 = GEDR3;
  235. #endif
  236. /* only unmasked interrupts kick us out of idle */
  237. ICCR = 1;
  238. /* GPIO 0 and 1 must have their mask bit always set */
  239. GPIO_IRQ_mask[0] = 3;
  240. for (irq = PXA_IRQ(PXA_IRQ_SKIP); irq <= PXA_IRQ(31); irq++) {
  241. set_irq_chip(irq, &pxa_internal_chip_low);
  242. set_irq_handler(irq, do_level_IRQ);
  243. set_irq_flags(irq, IRQF_VALID);
  244. }
  245. #if PXA_INTERNAL_IRQS > 32
  246. for (irq = PXA_IRQ(32); irq < PXA_IRQ(PXA_INTERNAL_IRQS); irq++) {
  247. set_irq_chip(irq, &pxa_internal_chip_high);
  248. set_irq_handler(irq, do_level_IRQ);
  249. set_irq_flags(irq, IRQF_VALID);
  250. }
  251. #endif
  252. for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
  253. set_irq_chip(irq, &pxa_low_gpio_chip);
  254. set_irq_handler(irq, do_edge_IRQ);
  255. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  256. }
  257. for (irq = IRQ_GPIO(2); irq <= IRQ_GPIO(PXA_LAST_GPIO); irq++) {
  258. set_irq_chip(irq, &pxa_muxed_gpio_chip);
  259. set_irq_handler(irq, do_edge_IRQ);
  260. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  261. }
  262. /* Install handler for GPIO>=2 edge detect interrupts */
  263. set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
  264. set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);
  265. }