irq.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. /*
  2. * linux/arch/arm/mach-sa1100/irq.c
  3. *
  4. * Copyright (C) 1999-2001 Nicolas Pitre
  5. *
  6. * Generic IRQ handling for the SA11x0, GPIO 11-27 IRQ demultiplexing.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/ioport.h>
  17. #include <linux/syscore_ops.h>
  18. #include <mach/hardware.h>
  19. #include <mach/irqs.h>
  20. #include <asm/mach/irq.h>
  21. #include "generic.h"
  22. /*
  23. * SA1100 GPIO edge detection for IRQs:
  24. * IRQs are generated on Falling-Edge, Rising-Edge, or both.
  25. * Use this instead of directly setting GRER/GFER.
  26. */
  27. static int GPIO_IRQ_rising_edge;
  28. static int GPIO_IRQ_falling_edge;
  29. static int GPIO_IRQ_mask = (1 << 11) - 1;
  30. /*
  31. * To get the GPIO number from an IRQ number
  32. */
  33. #define GPIO_11_27_IRQ(i) ((i) - 21)
  34. #define GPIO11_27_MASK(irq) (1 << GPIO_11_27_IRQ(irq))
  35. static int sa1100_gpio_type(struct irq_data *d, unsigned int type)
  36. {
  37. unsigned int mask;
  38. if (d->irq <= 10)
  39. mask = 1 << d->irq;
  40. else
  41. mask = GPIO11_27_MASK(d->irq);
  42. if (type == IRQ_TYPE_PROBE) {
  43. if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
  44. return 0;
  45. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  46. }
  47. if (type & IRQ_TYPE_EDGE_RISING) {
  48. GPIO_IRQ_rising_edge |= mask;
  49. } else
  50. GPIO_IRQ_rising_edge &= ~mask;
  51. if (type & IRQ_TYPE_EDGE_FALLING) {
  52. GPIO_IRQ_falling_edge |= mask;
  53. } else
  54. GPIO_IRQ_falling_edge &= ~mask;
  55. GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
  56. GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
  57. return 0;
  58. }
  59. /*
  60. * GPIO IRQs must be acknowledged. This is for IRQs from 0 to 10.
  61. */
  62. static void sa1100_low_gpio_ack(struct irq_data *d)
  63. {
  64. GEDR = (1 << d->irq);
  65. }
  66. static void sa1100_low_gpio_mask(struct irq_data *d)
  67. {
  68. ICMR &= ~(1 << d->irq);
  69. }
  70. static void sa1100_low_gpio_unmask(struct irq_data *d)
  71. {
  72. ICMR |= 1 << d->irq;
  73. }
  74. static int sa1100_low_gpio_wake(struct irq_data *d, unsigned int on)
  75. {
  76. if (on)
  77. PWER |= 1 << d->irq;
  78. else
  79. PWER &= ~(1 << d->irq);
  80. return 0;
  81. }
  82. static struct irq_chip sa1100_low_gpio_chip = {
  83. .name = "GPIO-l",
  84. .irq_ack = sa1100_low_gpio_ack,
  85. .irq_mask = sa1100_low_gpio_mask,
  86. .irq_unmask = sa1100_low_gpio_unmask,
  87. .irq_set_type = sa1100_gpio_type,
  88. .irq_set_wake = sa1100_low_gpio_wake,
  89. };
  90. /*
  91. * IRQ11 (GPIO11 through 27) handler. We enter here with the
  92. * irq_controller_lock held, and IRQs disabled. Decode the IRQ
  93. * and call the handler.
  94. */
  95. static void
  96. sa1100_high_gpio_handler(unsigned int irq, struct irq_desc *desc)
  97. {
  98. unsigned int mask;
  99. mask = GEDR & 0xfffff800;
  100. do {
  101. /*
  102. * clear down all currently active IRQ sources.
  103. * We will be processing them all.
  104. */
  105. GEDR = mask;
  106. irq = IRQ_GPIO11;
  107. mask >>= 11;
  108. do {
  109. if (mask & 1)
  110. generic_handle_irq(irq);
  111. mask >>= 1;
  112. irq++;
  113. } while (mask);
  114. mask = GEDR & 0xfffff800;
  115. } while (mask);
  116. }
  117. /*
  118. * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
  119. * In addition, the IRQs are all collected up into one bit in the
  120. * interrupt controller registers.
  121. */
  122. static void sa1100_high_gpio_ack(struct irq_data *d)
  123. {
  124. unsigned int mask = GPIO11_27_MASK(d->irq);
  125. GEDR = mask;
  126. }
  127. static void sa1100_high_gpio_mask(struct irq_data *d)
  128. {
  129. unsigned int mask = GPIO11_27_MASK(d->irq);
  130. GPIO_IRQ_mask &= ~mask;
  131. GRER &= ~mask;
  132. GFER &= ~mask;
  133. }
  134. static void sa1100_high_gpio_unmask(struct irq_data *d)
  135. {
  136. unsigned int mask = GPIO11_27_MASK(d->irq);
  137. GPIO_IRQ_mask |= mask;
  138. GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
  139. GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
  140. }
  141. static int sa1100_high_gpio_wake(struct irq_data *d, unsigned int on)
  142. {
  143. if (on)
  144. PWER |= GPIO11_27_MASK(d->irq);
  145. else
  146. PWER &= ~GPIO11_27_MASK(d->irq);
  147. return 0;
  148. }
  149. static struct irq_chip sa1100_high_gpio_chip = {
  150. .name = "GPIO-h",
  151. .irq_ack = sa1100_high_gpio_ack,
  152. .irq_mask = sa1100_high_gpio_mask,
  153. .irq_unmask = sa1100_high_gpio_unmask,
  154. .irq_set_type = sa1100_gpio_type,
  155. .irq_set_wake = sa1100_high_gpio_wake,
  156. };
  157. /*
  158. * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
  159. * this is for internal IRQs i.e. from 11 to 31.
  160. */
  161. static void sa1100_mask_irq(struct irq_data *d)
  162. {
  163. ICMR &= ~(1 << d->irq);
  164. }
  165. static void sa1100_unmask_irq(struct irq_data *d)
  166. {
  167. ICMR |= (1 << d->irq);
  168. }
  169. /*
  170. * Apart form GPIOs, only the RTC alarm can be a wakeup event.
  171. */
  172. static int sa1100_set_wake(struct irq_data *d, unsigned int on)
  173. {
  174. if (d->irq == IRQ_RTCAlrm) {
  175. if (on)
  176. PWER |= PWER_RTC;
  177. else
  178. PWER &= ~PWER_RTC;
  179. return 0;
  180. }
  181. return -EINVAL;
  182. }
  183. static struct irq_chip sa1100_normal_chip = {
  184. .name = "SC",
  185. .irq_ack = sa1100_mask_irq,
  186. .irq_mask = sa1100_mask_irq,
  187. .irq_unmask = sa1100_unmask_irq,
  188. .irq_set_wake = sa1100_set_wake,
  189. };
  190. static struct resource irq_resource =
  191. DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
  192. static struct sa1100irq_state {
  193. unsigned int saved;
  194. unsigned int icmr;
  195. unsigned int iclr;
  196. unsigned int iccr;
  197. } sa1100irq_state;
  198. static int sa1100irq_suspend(void)
  199. {
  200. struct sa1100irq_state *st = &sa1100irq_state;
  201. st->saved = 1;
  202. st->icmr = ICMR;
  203. st->iclr = ICLR;
  204. st->iccr = ICCR;
  205. /*
  206. * Disable all GPIO-based interrupts.
  207. */
  208. ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
  209. IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
  210. IC_GPIO1|IC_GPIO0);
  211. /*
  212. * Set the appropriate edges for wakeup.
  213. */
  214. GRER = PWER & GPIO_IRQ_rising_edge;
  215. GFER = PWER & GPIO_IRQ_falling_edge;
  216. /*
  217. * Clear any pending GPIO interrupts.
  218. */
  219. GEDR = GEDR;
  220. return 0;
  221. }
  222. static void sa1100irq_resume(void)
  223. {
  224. struct sa1100irq_state *st = &sa1100irq_state;
  225. if (st->saved) {
  226. ICCR = st->iccr;
  227. ICLR = st->iclr;
  228. GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
  229. GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
  230. ICMR = st->icmr;
  231. }
  232. }
  233. static struct syscore_ops sa1100irq_syscore_ops = {
  234. .suspend = sa1100irq_suspend,
  235. .resume = sa1100irq_resume,
  236. };
  237. static int __init sa1100irq_init_devicefs(void)
  238. {
  239. register_syscore_ops(&sa1100irq_syscore_ops);
  240. return 0;
  241. }
  242. device_initcall(sa1100irq_init_devicefs);
  243. void __init sa1100_init_irq(void)
  244. {
  245. unsigned int irq;
  246. request_resource(&iomem_resource, &irq_resource);
  247. /* disable all IRQs */
  248. ICMR = 0;
  249. /* all IRQs are IRQ, not FIQ */
  250. ICLR = 0;
  251. /* clear all GPIO edge detects */
  252. GFER = 0;
  253. GRER = 0;
  254. GEDR = -1;
  255. /*
  256. * Whatever the doc says, this has to be set for the wait-on-irq
  257. * instruction to work... on a SA1100 rev 9 at least.
  258. */
  259. ICCR = 1;
  260. for (irq = 0; irq <= 10; irq++) {
  261. irq_set_chip_and_handler(irq, &sa1100_low_gpio_chip,
  262. handle_edge_irq);
  263. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  264. }
  265. for (irq = 12; irq <= 31; irq++) {
  266. irq_set_chip_and_handler(irq, &sa1100_normal_chip,
  267. handle_level_irq);
  268. set_irq_flags(irq, IRQF_VALID);
  269. }
  270. for (irq = 32; irq <= 48; irq++) {
  271. irq_set_chip_and_handler(irq, &sa1100_high_gpio_chip,
  272. handle_edge_irq);
  273. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  274. }
  275. /*
  276. * Install handler for GPIO 11-27 edge detect interrupts
  277. */
  278. irq_set_chip(IRQ_GPIO11_27, &sa1100_normal_chip);
  279. irq_set_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
  280. sa1100_init_gpio();
  281. }