irq.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. static struct resource irq_resource =
  72. DEFINE_RES_MEM_NAMED(0x90050000, SZ_64K, "irqs");
  73. static struct sa1100irq_state {
  74. unsigned int saved;
  75. unsigned int icmr;
  76. unsigned int iclr;
  77. unsigned int iccr;
  78. } sa1100irq_state;
  79. static int sa1100irq_suspend(void)
  80. {
  81. struct sa1100irq_state *st = &sa1100irq_state;
  82. st->saved = 1;
  83. st->icmr = ICMR;
  84. st->iclr = ICLR;
  85. st->iccr = ICCR;
  86. /*
  87. * Disable all GPIO-based interrupts.
  88. */
  89. ICMR &= ~(IC_GPIO11_27|IC_GPIO10|IC_GPIO9|IC_GPIO8|IC_GPIO7|
  90. IC_GPIO6|IC_GPIO5|IC_GPIO4|IC_GPIO3|IC_GPIO2|
  91. IC_GPIO1|IC_GPIO0);
  92. return 0;
  93. }
  94. static void sa1100irq_resume(void)
  95. {
  96. struct sa1100irq_state *st = &sa1100irq_state;
  97. if (st->saved) {
  98. ICCR = st->iccr;
  99. ICLR = st->iclr;
  100. ICMR = st->icmr;
  101. }
  102. }
  103. static struct syscore_ops sa1100irq_syscore_ops = {
  104. .suspend = sa1100irq_suspend,
  105. .resume = sa1100irq_resume,
  106. };
  107. static int __init sa1100irq_init_devicefs(void)
  108. {
  109. register_syscore_ops(&sa1100irq_syscore_ops);
  110. return 0;
  111. }
  112. device_initcall(sa1100irq_init_devicefs);
  113. static asmlinkage void __exception_irq_entry
  114. sa1100_handle_irq(struct pt_regs *regs)
  115. {
  116. uint32_t icip, icmr, mask;
  117. do {
  118. icip = (ICIP);
  119. icmr = (ICMR);
  120. mask = icip & icmr;
  121. if (mask == 0)
  122. break;
  123. handle_domain_irq(sa1100_normal_irqdomain,
  124. ffs(mask) - 1, regs);
  125. } while (1);
  126. }
  127. void __init sa1100_init_irq(void)
  128. {
  129. request_resource(&iomem_resource, &irq_resource);
  130. /* disable all IRQs */
  131. ICMR = 0;
  132. /* all IRQs are IRQ, not FIQ */
  133. ICLR = 0;
  134. /*
  135. * Whatever the doc says, this has to be set for the wait-on-irq
  136. * instruction to work... on a SA1100 rev 9 at least.
  137. */
  138. ICCR = 1;
  139. sa1100_normal_irqdomain = irq_domain_add_simple(NULL,
  140. 32, IRQ_GPIO0_SC,
  141. &sa1100_normal_irqdomain_ops, NULL);
  142. set_handle_irq(sa1100_handle_irq);
  143. sa1100_init_gpio();
  144. }