irq.c 7.9 KB

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