irq.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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 int pxa_set_wake(unsigned int irq, unsigned int on)
  34. {
  35. u32 mask;
  36. switch (irq) {
  37. case IRQ_RTCAlrm:
  38. mask = PWER_RTC;
  39. break;
  40. #ifdef CONFIG_PXA27x
  41. /* REVISIT can handle USBH1, USBH2, USB, MSL, USIM, ... */
  42. #endif
  43. default:
  44. return -EINVAL;
  45. }
  46. if (on)
  47. PWER |= mask;
  48. else
  49. PWER &= ~mask;
  50. return 0;
  51. }
  52. static struct irq_chip pxa_internal_chip_low = {
  53. .name = "SC",
  54. .ack = pxa_mask_low_irq,
  55. .mask = pxa_mask_low_irq,
  56. .unmask = pxa_unmask_low_irq,
  57. .set_wake = pxa_set_wake,
  58. };
  59. #if PXA_INTERNAL_IRQS > 32
  60. /*
  61. * This is for the second set of internal IRQs as found on the PXA27x.
  62. */
  63. static void pxa_mask_high_irq(unsigned int irq)
  64. {
  65. ICMR2 &= ~(1 << (irq - 32 + PXA_IRQ_SKIP));
  66. }
  67. static void pxa_unmask_high_irq(unsigned int irq)
  68. {
  69. ICMR2 |= (1 << (irq - 32 + PXA_IRQ_SKIP));
  70. }
  71. static struct irq_chip pxa_internal_chip_high = {
  72. .name = "SC-hi",
  73. .ack = pxa_mask_high_irq,
  74. .mask = pxa_mask_high_irq,
  75. .unmask = pxa_unmask_high_irq,
  76. };
  77. #endif
  78. /* Note that if an input/irq line ever gets changed to an output during
  79. * suspend, the relevant PWER, PRER, and PFER bits should be cleared.
  80. */
  81. #ifdef CONFIG_PXA27x
  82. /* PXA27x: Various gpios can issue wakeup events. This logic only
  83. * handles the simple cases, not the WEMUX2 and WEMUX3 options
  84. */
  85. #define PXA27x_GPIO_NOWAKE_MASK \
  86. ((1 << 8) | (1 << 7) | (1 << 6) | (1 << 5) | (1 << 2))
  87. #define WAKEMASK(gpio) \
  88. (((gpio) <= 15) \
  89. ? ((1 << (gpio)) & ~PXA27x_GPIO_NOWAKE_MASK) \
  90. : ((gpio == 35) ? (1 << 24) : 0))
  91. #else
  92. /* pxa 210, 250, 255, 26x: gpios 0..15 can issue wakeups */
  93. #define WAKEMASK(gpio) (((gpio) <= 15) ? (1 << (gpio)) : 0)
  94. #endif
  95. /*
  96. * PXA GPIO edge detection for IRQs:
  97. * IRQs are generated on Falling-Edge, Rising-Edge, or both.
  98. * Use this instead of directly setting GRER/GFER.
  99. */
  100. static long GPIO_IRQ_rising_edge[4];
  101. static long GPIO_IRQ_falling_edge[4];
  102. static long GPIO_IRQ_mask[4];
  103. static int pxa_gpio_irq_type(unsigned int irq, unsigned int type)
  104. {
  105. int gpio, idx;
  106. u32 mask;
  107. gpio = IRQ_TO_GPIO(irq);
  108. idx = gpio >> 5;
  109. mask = WAKEMASK(gpio);
  110. if (type == IRQT_PROBE) {
  111. /* Don't mess with enabled GPIOs using preconfigured edges or
  112. GPIOs set to alternate function or to output during probe */
  113. if ((GPIO_IRQ_rising_edge[idx] | GPIO_IRQ_falling_edge[idx] | GPDR(gpio)) &
  114. GPIO_bit(gpio))
  115. return 0;
  116. if (GAFR(gpio) & (0x3 << (((gpio) & 0xf)*2)))
  117. return 0;
  118. type = __IRQT_RISEDGE | __IRQT_FALEDGE;
  119. }
  120. /* printk(KERN_DEBUG "IRQ%d (GPIO%d): ", irq, gpio); */
  121. pxa_gpio_mode(gpio | GPIO_IN);
  122. if (type & __IRQT_RISEDGE) {
  123. /* printk("rising "); */
  124. __set_bit (gpio, GPIO_IRQ_rising_edge);
  125. PRER |= mask;
  126. } else {
  127. __clear_bit (gpio, GPIO_IRQ_rising_edge);
  128. PRER &= ~mask;
  129. }
  130. if (type & __IRQT_FALEDGE) {
  131. /* printk("falling "); */
  132. __set_bit (gpio, GPIO_IRQ_falling_edge);
  133. PFER |= mask;
  134. } else {
  135. __clear_bit (gpio, GPIO_IRQ_falling_edge);
  136. PFER &= ~mask;
  137. }
  138. /* printk("edges\n"); */
  139. GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
  140. GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
  141. return 0;
  142. }
  143. /*
  144. * GPIO IRQs must be acknowledged. This is for GPIO 0 and 1.
  145. */
  146. static void pxa_ack_low_gpio(unsigned int irq)
  147. {
  148. GEDR0 = (1 << (irq - IRQ_GPIO0));
  149. }
  150. static int pxa_set_gpio_wake(unsigned int irq, unsigned int on)
  151. {
  152. int gpio = IRQ_TO_GPIO(irq);
  153. u32 mask = WAKEMASK(gpio);
  154. if (!mask)
  155. return -EINVAL;
  156. if (on)
  157. PWER |= mask;
  158. else
  159. PWER &= ~mask;
  160. return 0;
  161. }
  162. static struct irq_chip pxa_low_gpio_chip = {
  163. .name = "GPIO-l",
  164. .ack = pxa_ack_low_gpio,
  165. .mask = pxa_mask_low_irq,
  166. .unmask = pxa_unmask_low_irq,
  167. .set_type = pxa_gpio_irq_type,
  168. .set_wake = pxa_set_gpio_wake,
  169. };
  170. /*
  171. * Demux handler for GPIO>=2 edge detect interrupts
  172. */
  173. static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc)
  174. {
  175. unsigned int mask;
  176. int loop;
  177. do {
  178. loop = 0;
  179. mask = GEDR0 & ~3;
  180. if (mask) {
  181. GEDR0 = mask;
  182. irq = IRQ_GPIO(2);
  183. desc = irq_desc + irq;
  184. mask >>= 2;
  185. do {
  186. if (mask & 1)
  187. desc_handle_irq(irq, desc);
  188. irq++;
  189. desc++;
  190. mask >>= 1;
  191. } while (mask);
  192. loop = 1;
  193. }
  194. mask = GEDR1;
  195. if (mask) {
  196. GEDR1 = mask;
  197. irq = IRQ_GPIO(32);
  198. desc = irq_desc + irq;
  199. do {
  200. if (mask & 1)
  201. desc_handle_irq(irq, desc);
  202. irq++;
  203. desc++;
  204. mask >>= 1;
  205. } while (mask);
  206. loop = 1;
  207. }
  208. mask = GEDR2;
  209. if (mask) {
  210. GEDR2 = mask;
  211. irq = IRQ_GPIO(64);
  212. desc = irq_desc + irq;
  213. do {
  214. if (mask & 1)
  215. desc_handle_irq(irq, desc);
  216. irq++;
  217. desc++;
  218. mask >>= 1;
  219. } while (mask);
  220. loop = 1;
  221. }
  222. #if PXA_LAST_GPIO >= 96
  223. mask = GEDR3;
  224. if (mask) {
  225. GEDR3 = mask;
  226. irq = IRQ_GPIO(96);
  227. desc = irq_desc + irq;
  228. do {
  229. if (mask & 1)
  230. desc_handle_irq(irq, desc);
  231. irq++;
  232. desc++;
  233. mask >>= 1;
  234. } while (mask);
  235. loop = 1;
  236. }
  237. #endif
  238. } while (loop);
  239. }
  240. static void pxa_ack_muxed_gpio(unsigned int irq)
  241. {
  242. int gpio = irq - IRQ_GPIO(2) + 2;
  243. GEDR(gpio) = GPIO_bit(gpio);
  244. }
  245. static void pxa_mask_muxed_gpio(unsigned int irq)
  246. {
  247. int gpio = irq - IRQ_GPIO(2) + 2;
  248. __clear_bit(gpio, GPIO_IRQ_mask);
  249. GRER(gpio) &= ~GPIO_bit(gpio);
  250. GFER(gpio) &= ~GPIO_bit(gpio);
  251. }
  252. static void pxa_unmask_muxed_gpio(unsigned int irq)
  253. {
  254. int gpio = irq - IRQ_GPIO(2) + 2;
  255. int idx = gpio >> 5;
  256. __set_bit(gpio, GPIO_IRQ_mask);
  257. GRER(gpio) = GPIO_IRQ_rising_edge[idx] & GPIO_IRQ_mask[idx];
  258. GFER(gpio) = GPIO_IRQ_falling_edge[idx] & GPIO_IRQ_mask[idx];
  259. }
  260. static struct irq_chip pxa_muxed_gpio_chip = {
  261. .name = "GPIO",
  262. .ack = pxa_ack_muxed_gpio,
  263. .mask = pxa_mask_muxed_gpio,
  264. .unmask = pxa_unmask_muxed_gpio,
  265. .set_type = pxa_gpio_irq_type,
  266. .set_wake = pxa_set_gpio_wake,
  267. };
  268. void __init pxa_init_irq(void)
  269. {
  270. int irq;
  271. /* disable all IRQs */
  272. ICMR = 0;
  273. /* all IRQs are IRQ, not FIQ */
  274. ICLR = 0;
  275. /* clear all GPIO edge detects */
  276. GFER0 = 0;
  277. GFER1 = 0;
  278. GFER2 = 0;
  279. GRER0 = 0;
  280. GRER1 = 0;
  281. GRER2 = 0;
  282. GEDR0 = GEDR0;
  283. GEDR1 = GEDR1;
  284. GEDR2 = GEDR2;
  285. #ifdef CONFIG_PXA27x
  286. /* And similarly for the extra regs on the PXA27x */
  287. ICMR2 = 0;
  288. ICLR2 = 0;
  289. GFER3 = 0;
  290. GRER3 = 0;
  291. GEDR3 = GEDR3;
  292. #endif
  293. /* only unmasked interrupts kick us out of idle */
  294. ICCR = 1;
  295. /* GPIO 0 and 1 must have their mask bit always set */
  296. GPIO_IRQ_mask[0] = 3;
  297. for (irq = PXA_IRQ(PXA_IRQ_SKIP); irq <= PXA_IRQ(31); irq++) {
  298. set_irq_chip(irq, &pxa_internal_chip_low);
  299. set_irq_handler(irq, handle_level_irq);
  300. set_irq_flags(irq, IRQF_VALID);
  301. }
  302. #if PXA_INTERNAL_IRQS > 32
  303. for (irq = PXA_IRQ(32); irq < PXA_IRQ(PXA_INTERNAL_IRQS); irq++) {
  304. set_irq_chip(irq, &pxa_internal_chip_high);
  305. set_irq_handler(irq, handle_level_irq);
  306. set_irq_flags(irq, IRQF_VALID);
  307. }
  308. #endif
  309. for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
  310. set_irq_chip(irq, &pxa_low_gpio_chip);
  311. set_irq_handler(irq, handle_edge_irq);
  312. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  313. }
  314. for (irq = IRQ_GPIO(2); irq <= IRQ_GPIO(PXA_LAST_GPIO); irq++) {
  315. set_irq_chip(irq, &pxa_muxed_gpio_chip);
  316. set_irq_handler(irq, handle_edge_irq);
  317. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  318. }
  319. /* Install handler for GPIO>=2 edge detect interrupts */
  320. set_irq_chip(IRQ_GPIO_2_x, &pxa_internal_chip_low);
  321. set_irq_chained_handler(IRQ_GPIO_2_x, pxa_gpio_demux_handler);
  322. }