irq.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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/ptrace.h>
  18. #include <linux/sysdev.h>
  19. #include <asm/hardware.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(unsigned int irq, unsigned int type)
  36. {
  37. unsigned int mask;
  38. if (irq <= 10)
  39. mask = 1 << irq;
  40. else
  41. mask = GPIO11_27_MASK(irq);
  42. if (type == IRQT_PROBE) {
  43. if ((GPIO_IRQ_rising_edge | GPIO_IRQ_falling_edge) & mask)
  44. return 0;
  45. type = __IRQT_RISEDGE | __IRQT_FALEDGE;
  46. }
  47. if (type & __IRQT_RISEDGE) {
  48. GPIO_IRQ_rising_edge |= mask;
  49. } else
  50. GPIO_IRQ_rising_edge &= ~mask;
  51. if (type & __IRQT_FALEDGE) {
  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(unsigned int irq)
  63. {
  64. GEDR = (1 << irq);
  65. }
  66. static void sa1100_low_gpio_mask(unsigned int irq)
  67. {
  68. ICMR &= ~(1 << irq);
  69. }
  70. static void sa1100_low_gpio_unmask(unsigned int irq)
  71. {
  72. ICMR |= 1 << irq;
  73. }
  74. static int sa1100_low_gpio_wake(unsigned int irq, unsigned int on)
  75. {
  76. if (on)
  77. PWER |= 1 << irq;
  78. else
  79. PWER &= ~(1 << irq);
  80. return 0;
  81. }
  82. static struct irq_chip sa1100_low_gpio_chip = {
  83. .name = "GPIO-l",
  84. .ack = sa1100_low_gpio_ack,
  85. .mask = sa1100_low_gpio_mask,
  86. .unmask = sa1100_low_gpio_unmask,
  87. .set_type = sa1100_gpio_type,
  88. .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 irqdesc *desc,
  97. struct pt_regs *regs)
  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. desc = irq_desc + irq;
  109. mask >>= 11;
  110. do {
  111. if (mask & 1)
  112. desc_handle_irq(irq, desc, regs);
  113. mask >>= 1;
  114. irq++;
  115. desc++;
  116. } while (mask);
  117. mask = GEDR & 0xfffff800;
  118. } while (mask);
  119. }
  120. /*
  121. * Like GPIO0 to 10, GPIO11-27 IRQs need to be handled specially.
  122. * In addition, the IRQs are all collected up into one bit in the
  123. * interrupt controller registers.
  124. */
  125. static void sa1100_high_gpio_ack(unsigned int irq)
  126. {
  127. unsigned int mask = GPIO11_27_MASK(irq);
  128. GEDR = mask;
  129. }
  130. static void sa1100_high_gpio_mask(unsigned int irq)
  131. {
  132. unsigned int mask = GPIO11_27_MASK(irq);
  133. GPIO_IRQ_mask &= ~mask;
  134. GRER &= ~mask;
  135. GFER &= ~mask;
  136. }
  137. static void sa1100_high_gpio_unmask(unsigned int irq)
  138. {
  139. unsigned int mask = GPIO11_27_MASK(irq);
  140. GPIO_IRQ_mask |= mask;
  141. GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
  142. GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
  143. }
  144. static int sa1100_high_gpio_wake(unsigned int irq, unsigned int on)
  145. {
  146. if (on)
  147. PWER |= GPIO11_27_MASK(irq);
  148. else
  149. PWER &= ~GPIO11_27_MASK(irq);
  150. return 0;
  151. }
  152. static struct irq_chip sa1100_high_gpio_chip = {
  153. .name = "GPIO-h",
  154. .ack = sa1100_high_gpio_ack,
  155. .mask = sa1100_high_gpio_mask,
  156. .unmask = sa1100_high_gpio_unmask,
  157. .set_type = sa1100_gpio_type,
  158. .set_wake = sa1100_high_gpio_wake,
  159. };
  160. /*
  161. * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
  162. * this is for internal IRQs i.e. from 11 to 31.
  163. */
  164. static void sa1100_mask_irq(unsigned int irq)
  165. {
  166. ICMR &= ~(1 << irq);
  167. }
  168. static void sa1100_unmask_irq(unsigned int irq)
  169. {
  170. ICMR |= (1 << irq);
  171. }
  172. /*
  173. * Apart form GPIOs, only the RTC alarm can be a wakeup event.
  174. */
  175. static int sa1100_set_wake(unsigned int irq, unsigned int on)
  176. {
  177. if (irq == IRQ_RTCAlrm) {
  178. if (on)
  179. PWER |= PWER_RTC;
  180. else
  181. PWER &= ~PWER_RTC;
  182. return 0;
  183. }
  184. return -EINVAL;
  185. }
  186. static struct irq_chip sa1100_normal_chip = {
  187. .name = "SC",
  188. .ack = sa1100_mask_irq,
  189. .mask = sa1100_mask_irq,
  190. .unmask = sa1100_unmask_irq,
  191. .set_wake = sa1100_set_wake,
  192. };
  193. static struct resource irq_resource = {
  194. .name = "irqs",
  195. .start = 0x90050000,
  196. .end = 0x9005ffff,
  197. };
  198. static struct sa1100irq_state {
  199. unsigned int saved;
  200. unsigned int icmr;
  201. unsigned int iclr;
  202. unsigned int iccr;
  203. } sa1100irq_state;
  204. static int sa1100irq_suspend(struct sys_device *dev, pm_message_t state)
  205. {
  206. struct sa1100irq_state *st = &sa1100irq_state;
  207. st->saved = 1;
  208. st->icmr = ICMR;
  209. st->iclr = ICLR;
  210. st->iccr = ICCR;
  211. /*
  212. * Disable all GPIO-based interrupts.
  213. */
  214. ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
  215. IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
  216. IC_GPIO1|IC_GPIO0);
  217. /*
  218. * Set the appropriate edges for wakeup.
  219. */
  220. GRER = PWER & GPIO_IRQ_rising_edge;
  221. GFER = PWER & GPIO_IRQ_falling_edge;
  222. /*
  223. * Clear any pending GPIO interrupts.
  224. */
  225. GEDR = GEDR;
  226. return 0;
  227. }
  228. static int sa1100irq_resume(struct sys_device *dev)
  229. {
  230. struct sa1100irq_state *st = &sa1100irq_state;
  231. if (st->saved) {
  232. ICCR = st->iccr;
  233. ICLR = st->iclr;
  234. GRER = GPIO_IRQ_rising_edge & GPIO_IRQ_mask;
  235. GFER = GPIO_IRQ_falling_edge & GPIO_IRQ_mask;
  236. ICMR = st->icmr;
  237. }
  238. return 0;
  239. }
  240. static struct sysdev_class sa1100irq_sysclass = {
  241. set_kset_name("sa11x0-irq"),
  242. .suspend = sa1100irq_suspend,
  243. .resume = sa1100irq_resume,
  244. };
  245. static struct sys_device sa1100irq_device = {
  246. .id = 0,
  247. .cls = &sa1100irq_sysclass,
  248. };
  249. static int __init sa1100irq_init_devicefs(void)
  250. {
  251. sysdev_class_register(&sa1100irq_sysclass);
  252. return sysdev_register(&sa1100irq_device);
  253. }
  254. device_initcall(sa1100irq_init_devicefs);
  255. void __init sa1100_init_irq(void)
  256. {
  257. unsigned int irq;
  258. request_resource(&iomem_resource, &irq_resource);
  259. /* disable all IRQs */
  260. ICMR = 0;
  261. /* all IRQs are IRQ, not FIQ */
  262. ICLR = 0;
  263. /* clear all GPIO edge detects */
  264. GFER = 0;
  265. GRER = 0;
  266. GEDR = -1;
  267. /*
  268. * Whatever the doc says, this has to be set for the wait-on-irq
  269. * instruction to work... on a SA1100 rev 9 at least.
  270. */
  271. ICCR = 1;
  272. for (irq = 0; irq <= 10; irq++) {
  273. set_irq_chip(irq, &sa1100_low_gpio_chip);
  274. set_irq_handler(irq, do_edge_IRQ);
  275. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  276. }
  277. for (irq = 12; irq <= 31; irq++) {
  278. set_irq_chip(irq, &sa1100_normal_chip);
  279. set_irq_handler(irq, do_level_IRQ);
  280. set_irq_flags(irq, IRQF_VALID);
  281. }
  282. for (irq = 32; irq <= 48; irq++) {
  283. set_irq_chip(irq, &sa1100_high_gpio_chip);
  284. set_irq_handler(irq, do_edge_IRQ);
  285. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  286. }
  287. /*
  288. * Install handler for GPIO 11-27 edge detect interrupts
  289. */
  290. set_irq_chip(IRQ_GPIO11_27, &sa1100_normal_chip);
  291. set_irq_chained_handler(IRQ_GPIO11_27, sa1100_high_gpio_handler);
  292. }