irq.c 7.8 KB

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