irq.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * linux/arch/arm/mach-pxa/irq.c
  3. *
  4. * Generic PXA IRQ handling
  5. *
  6. * Author: Nicolas Pitre
  7. * Created: Jun 15, 2001
  8. * Copyright: MontaVista Software Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/syscore_ops.h>
  18. #include <linux/io.h>
  19. #include <linux/irq.h>
  20. #include <asm/exception.h>
  21. #include <mach/hardware.h>
  22. #include <mach/irqs.h>
  23. #include <mach/gpio-pxa.h>
  24. #include "generic.h"
  25. #define IRQ_BASE io_p2v(0x40d00000)
  26. #define ICIP (0x000)
  27. #define ICMR (0x004)
  28. #define ICLR (0x008)
  29. #define ICFR (0x00c)
  30. #define ICPR (0x010)
  31. #define ICCR (0x014)
  32. #define ICHP (0x018)
  33. #define IPR(i) (((i) < 32) ? (0x01c + ((i) << 2)) : \
  34. ((i) < 64) ? (0x0b0 + (((i) - 32) << 2)) : \
  35. (0x144 + (((i) - 64) << 2)))
  36. #define ICHP_VAL_IRQ (1 << 31)
  37. #define ICHP_IRQ(i) (((i) >> 16) & 0x7fff)
  38. #define IPR_VALID (1 << 31)
  39. #define IRQ_BIT(n) (((n) - PXA_IRQ(0)) & 0x1f)
  40. #define MAX_INTERNAL_IRQS 128
  41. /*
  42. * This is for peripheral IRQs internal to the PXA chip.
  43. */
  44. static int pxa_internal_irq_nr;
  45. static inline int cpu_has_ipr(void)
  46. {
  47. return !cpu_is_pxa25x();
  48. }
  49. static inline void __iomem *irq_base(int i)
  50. {
  51. static unsigned long phys_base[] = {
  52. 0x40d00000,
  53. 0x40d0009c,
  54. 0x40d00130,
  55. };
  56. return io_p2v(phys_base[i]);
  57. }
  58. void pxa_mask_irq(struct irq_data *d)
  59. {
  60. void __iomem *base = irq_data_get_irq_chip_data(d);
  61. uint32_t icmr = __raw_readl(base + ICMR);
  62. icmr &= ~(1 << IRQ_BIT(d->irq));
  63. __raw_writel(icmr, base + ICMR);
  64. }
  65. void pxa_unmask_irq(struct irq_data *d)
  66. {
  67. void __iomem *base = irq_data_get_irq_chip_data(d);
  68. uint32_t icmr = __raw_readl(base + ICMR);
  69. icmr |= 1 << IRQ_BIT(d->irq);
  70. __raw_writel(icmr, base + ICMR);
  71. }
  72. static struct irq_chip pxa_internal_irq_chip = {
  73. .name = "SC",
  74. .irq_ack = pxa_mask_irq,
  75. .irq_mask = pxa_mask_irq,
  76. .irq_unmask = pxa_unmask_irq,
  77. };
  78. /*
  79. * GPIO IRQs for GPIO 0 and 1
  80. */
  81. static int pxa_set_low_gpio_type(struct irq_data *d, unsigned int type)
  82. {
  83. int gpio = d->irq - IRQ_GPIO0;
  84. if (__gpio_is_occupied(gpio)) {
  85. pr_err("%s failed: GPIO is configured\n", __func__);
  86. return -EINVAL;
  87. }
  88. if (type & IRQ_TYPE_EDGE_RISING)
  89. GRER0 |= GPIO_bit(gpio);
  90. else
  91. GRER0 &= ~GPIO_bit(gpio);
  92. if (type & IRQ_TYPE_EDGE_FALLING)
  93. GFER0 |= GPIO_bit(gpio);
  94. else
  95. GFER0 &= ~GPIO_bit(gpio);
  96. return 0;
  97. }
  98. static void pxa_ack_low_gpio(struct irq_data *d)
  99. {
  100. GEDR0 = (1 << (d->irq - IRQ_GPIO0));
  101. }
  102. static struct irq_chip pxa_low_gpio_chip = {
  103. .name = "GPIO-l",
  104. .irq_ack = pxa_ack_low_gpio,
  105. .irq_mask = pxa_mask_irq,
  106. .irq_unmask = pxa_unmask_irq,
  107. .irq_set_type = pxa_set_low_gpio_type,
  108. };
  109. asmlinkage void __exception_irq_entry icip_handle_irq(struct pt_regs *regs)
  110. {
  111. uint32_t icip, icmr, mask;
  112. do {
  113. icip = __raw_readl(IRQ_BASE + ICIP);
  114. icmr = __raw_readl(IRQ_BASE + ICMR);
  115. mask = icip & icmr;
  116. if (mask == 0)
  117. break;
  118. handle_IRQ(PXA_IRQ(fls(mask) - 1), regs);
  119. } while (1);
  120. }
  121. asmlinkage void __exception_irq_entry ichp_handle_irq(struct pt_regs *regs)
  122. {
  123. uint32_t ichp;
  124. do {
  125. __asm__ __volatile__("mrc p6, 0, %0, c5, c0, 0\n": "=r"(ichp));
  126. if ((ichp & ICHP_VAL_IRQ) == 0)
  127. break;
  128. handle_IRQ(PXA_IRQ(ICHP_IRQ(ichp)), regs);
  129. } while (1);
  130. }
  131. static void __init pxa_init_low_gpio_irq(set_wake_t fn)
  132. {
  133. int irq;
  134. /* clear edge detection on GPIO 0 and 1 */
  135. GFER0 &= ~0x3;
  136. GRER0 &= ~0x3;
  137. GEDR0 = 0x3;
  138. for (irq = IRQ_GPIO0; irq <= IRQ_GPIO1; irq++) {
  139. irq_set_chip_and_handler(irq, &pxa_low_gpio_chip,
  140. handle_edge_irq);
  141. irq_set_chip_data(irq, irq_base(0));
  142. set_irq_flags(irq, IRQF_VALID);
  143. }
  144. pxa_low_gpio_chip.irq_set_wake = fn;
  145. }
  146. void __init pxa_init_irq(int irq_nr, set_wake_t fn)
  147. {
  148. int irq, i, n;
  149. BUG_ON(irq_nr > MAX_INTERNAL_IRQS);
  150. pxa_internal_irq_nr = irq_nr;
  151. for (n = 0; n < irq_nr; n += 32) {
  152. void __iomem *base = irq_base(n >> 5);
  153. __raw_writel(0, base + ICMR); /* disable all IRQs */
  154. __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */
  155. for (i = n; (i < (n + 32)) && (i < irq_nr); i++) {
  156. /* initialize interrupt priority */
  157. if (cpu_has_ipr())
  158. __raw_writel(i | IPR_VALID, IRQ_BASE + IPR(i));
  159. irq = PXA_IRQ(i);
  160. irq_set_chip_and_handler(irq, &pxa_internal_irq_chip,
  161. handle_level_irq);
  162. irq_set_chip_data(irq, base);
  163. set_irq_flags(irq, IRQF_VALID);
  164. }
  165. }
  166. /* only unmasked interrupts kick us out of idle */
  167. __raw_writel(1, irq_base(0) + ICCR);
  168. pxa_internal_irq_chip.irq_set_wake = fn;
  169. pxa_init_low_gpio_irq(fn);
  170. }
  171. #ifdef CONFIG_PM
  172. static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32];
  173. static unsigned long saved_ipr[MAX_INTERNAL_IRQS];
  174. static int pxa_irq_suspend(void)
  175. {
  176. int i;
  177. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  178. void __iomem *base = irq_base(i);
  179. saved_icmr[i] = __raw_readl(base + ICMR);
  180. __raw_writel(0, base + ICMR);
  181. }
  182. if (cpu_has_ipr()) {
  183. for (i = 0; i < pxa_internal_irq_nr; i++)
  184. saved_ipr[i] = __raw_readl(IRQ_BASE + IPR(i));
  185. }
  186. return 0;
  187. }
  188. static void pxa_irq_resume(void)
  189. {
  190. int i;
  191. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  192. void __iomem *base = irq_base(i);
  193. __raw_writel(saved_icmr[i], base + ICMR);
  194. __raw_writel(0, base + ICLR);
  195. }
  196. if (cpu_has_ipr())
  197. for (i = 0; i < pxa_internal_irq_nr; i++)
  198. __raw_writel(saved_ipr[i], IRQ_BASE + IPR(i));
  199. __raw_writel(1, IRQ_BASE + ICCR);
  200. }
  201. #else
  202. #define pxa_irq_suspend NULL
  203. #define pxa_irq_resume NULL
  204. #endif
  205. struct syscore_ops pxa_irq_syscore_ops = {
  206. .suspend = pxa_irq_suspend,
  207. .resume = pxa_irq_resume,
  208. };