irq-sa11x0.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (C) 2015 Dmitry Eremin-Solenikov
  3. * Copyright (C) 1999-2001 Nicolas Pitre
  4. *
  5. * Generic IRQ handling for the SA11x0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/irq.h>
  16. #include <linux/irqdomain.h>
  17. #include <linux/syscore_ops.h>
  18. #include <linux/irqchip/irq-sa11x0.h>
  19. #include <soc/sa1100/pwer.h>
  20. #include <asm/exception.h>
  21. #define ICIP 0x00 /* IC IRQ Pending reg. */
  22. #define ICMR 0x04 /* IC Mask Reg. */
  23. #define ICLR 0x08 /* IC Level Reg. */
  24. #define ICCR 0x0C /* IC Control Reg. */
  25. #define ICFP 0x10 /* IC FIQ Pending reg. */
  26. #define ICPR 0x20 /* IC Pending Reg. */
  27. static void __iomem *iobase;
  28. /*
  29. * We don't need to ACK IRQs on the SA1100 unless they're GPIOs
  30. * this is for internal IRQs i.e. from IRQ LCD to RTCAlrm.
  31. */
  32. static void sa1100_mask_irq(struct irq_data *d)
  33. {
  34. u32 reg;
  35. reg = readl_relaxed(iobase + ICMR);
  36. reg &= ~BIT(d->hwirq);
  37. writel_relaxed(reg, iobase + ICMR);
  38. }
  39. static void sa1100_unmask_irq(struct irq_data *d)
  40. {
  41. u32 reg;
  42. reg = readl_relaxed(iobase + ICMR);
  43. reg |= BIT(d->hwirq);
  44. writel_relaxed(reg, iobase + ICMR);
  45. }
  46. static int sa1100_set_wake(struct irq_data *d, unsigned int on)
  47. {
  48. return sa11x0_sc_set_wake(d->hwirq, on);
  49. }
  50. static struct irq_chip sa1100_normal_chip = {
  51. .name = "SC",
  52. .irq_ack = sa1100_mask_irq,
  53. .irq_mask = sa1100_mask_irq,
  54. .irq_unmask = sa1100_unmask_irq,
  55. .irq_set_wake = sa1100_set_wake,
  56. };
  57. static int sa1100_normal_irqdomain_map(struct irq_domain *d,
  58. unsigned int irq, irq_hw_number_t hwirq)
  59. {
  60. irq_set_chip_and_handler(irq, &sa1100_normal_chip,
  61. handle_level_irq);
  62. return 0;
  63. }
  64. static const struct irq_domain_ops sa1100_normal_irqdomain_ops = {
  65. .map = sa1100_normal_irqdomain_map,
  66. .xlate = irq_domain_xlate_onetwocell,
  67. };
  68. static struct irq_domain *sa1100_normal_irqdomain;
  69. static struct sa1100irq_state {
  70. unsigned int saved;
  71. unsigned int icmr;
  72. unsigned int iclr;
  73. unsigned int iccr;
  74. } sa1100irq_state;
  75. static int sa1100irq_suspend(void)
  76. {
  77. struct sa1100irq_state *st = &sa1100irq_state;
  78. st->saved = 1;
  79. st->icmr = readl_relaxed(iobase + ICMR);
  80. st->iclr = readl_relaxed(iobase + ICLR);
  81. st->iccr = readl_relaxed(iobase + ICCR);
  82. /*
  83. * Disable all GPIO-based interrupts.
  84. */
  85. writel_relaxed(st->icmr & 0xfffff000, iobase + ICMR);
  86. return 0;
  87. }
  88. static void sa1100irq_resume(void)
  89. {
  90. struct sa1100irq_state *st = &sa1100irq_state;
  91. if (st->saved) {
  92. writel_relaxed(st->iccr, iobase + ICCR);
  93. writel_relaxed(st->iclr, iobase + ICLR);
  94. writel_relaxed(st->icmr, iobase + ICMR);
  95. }
  96. }
  97. static struct syscore_ops sa1100irq_syscore_ops = {
  98. .suspend = sa1100irq_suspend,
  99. .resume = sa1100irq_resume,
  100. };
  101. static int __init sa1100irq_init_devicefs(void)
  102. {
  103. register_syscore_ops(&sa1100irq_syscore_ops);
  104. return 0;
  105. }
  106. device_initcall(sa1100irq_init_devicefs);
  107. static asmlinkage void __exception_irq_entry
  108. sa1100_handle_irq(struct pt_regs *regs)
  109. {
  110. uint32_t icip, icmr, mask;
  111. do {
  112. icip = readl_relaxed(iobase + ICIP);
  113. icmr = readl_relaxed(iobase + ICMR);
  114. mask = icip & icmr;
  115. if (mask == 0)
  116. break;
  117. handle_domain_irq(sa1100_normal_irqdomain,
  118. ffs(mask) - 1, regs);
  119. } while (1);
  120. }
  121. void __init sa11x0_init_irq_nodt(int irq_start, resource_size_t io_start)
  122. {
  123. iobase = ioremap(io_start, SZ_64K);
  124. if (WARN_ON(!iobase))
  125. return;
  126. /* disable all IRQs */
  127. writel_relaxed(0, iobase + ICMR);
  128. /* all IRQs are IRQ, not FIQ */
  129. writel_relaxed(0, iobase + ICLR);
  130. /*
  131. * Whatever the doc says, this has to be set for the wait-on-irq
  132. * instruction to work... on a SA1100 rev 9 at least.
  133. */
  134. writel_relaxed(1, iobase + ICCR);
  135. sa1100_normal_irqdomain = irq_domain_add_simple(NULL,
  136. 32, irq_start,
  137. &sa1100_normal_irqdomain_ops, NULL);
  138. set_handle_irq(sa1100_handle_irq);
  139. }