irq.c 6.7 KB

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