irq.c 7.1 KB

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