irq.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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/bitops.h>
  15. #include <linux/init.h>
  16. #include <linux/module.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/syscore_ops.h>
  19. #include <linux/io.h>
  20. #include <linux/irq.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <asm/exception.h>
  24. #include <mach/hardware.h>
  25. #include <mach/irqs.h>
  26. #include "generic.h"
  27. #define ICIP (0x000)
  28. #define ICMR (0x004)
  29. #define ICLR (0x008)
  30. #define ICFR (0x00c)
  31. #define ICPR (0x010)
  32. #define ICCR (0x014)
  33. #define ICHP (0x018)
  34. #define IPR(i) (((i) < 32) ? (0x01c + ((i) << 2)) : \
  35. ((i) < 64) ? (0x0b0 + (((i) - 32) << 2)) : \
  36. (0x144 + (((i) - 64) << 2)))
  37. #define ICHP_VAL_IRQ (1 << 31)
  38. #define ICHP_IRQ(i) (((i) >> 16) & 0x7fff)
  39. #define IPR_VALID (1 << 31)
  40. #define MAX_INTERNAL_IRQS 128
  41. /*
  42. * This is for peripheral IRQs internal to the PXA chip.
  43. */
  44. static void __iomem *pxa_irq_base;
  45. static int pxa_internal_irq_nr;
  46. static bool cpu_has_ipr;
  47. static struct irq_domain *pxa_irq_domain;
  48. static inline void __iomem *irq_base(int i)
  49. {
  50. static unsigned long phys_base_offset[] = {
  51. 0x0,
  52. 0x9c,
  53. 0x130,
  54. };
  55. return pxa_irq_base + phys_base_offset[i];
  56. }
  57. void pxa_mask_irq(struct irq_data *d)
  58. {
  59. void __iomem *base = irq_data_get_irq_chip_data(d);
  60. irq_hw_number_t irq = irqd_to_hwirq(d);
  61. uint32_t icmr = __raw_readl(base + ICMR);
  62. icmr &= ~BIT(irq & 0x1f);
  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. irq_hw_number_t irq = irqd_to_hwirq(d);
  69. uint32_t icmr = __raw_readl(base + ICMR);
  70. icmr |= BIT(irq & 0x1f);
  71. __raw_writel(icmr, base + ICMR);
  72. }
  73. static struct irq_chip pxa_internal_irq_chip = {
  74. .name = "SC",
  75. .irq_ack = pxa_mask_irq,
  76. .irq_mask = pxa_mask_irq,
  77. .irq_unmask = pxa_unmask_irq,
  78. };
  79. asmlinkage void __exception_irq_entry icip_handle_irq(struct pt_regs *regs)
  80. {
  81. uint32_t icip, icmr, mask;
  82. do {
  83. icip = __raw_readl(pxa_irq_base + ICIP);
  84. icmr = __raw_readl(pxa_irq_base + ICMR);
  85. mask = icip & icmr;
  86. if (mask == 0)
  87. break;
  88. handle_IRQ(PXA_IRQ(fls(mask) - 1), regs);
  89. } while (1);
  90. }
  91. asmlinkage void __exception_irq_entry ichp_handle_irq(struct pt_regs *regs)
  92. {
  93. uint32_t ichp;
  94. do {
  95. __asm__ __volatile__("mrc p6, 0, %0, c5, c0, 0\n": "=r"(ichp));
  96. if ((ichp & ICHP_VAL_IRQ) == 0)
  97. break;
  98. handle_IRQ(PXA_IRQ(ICHP_IRQ(ichp)), regs);
  99. } while (1);
  100. }
  101. static int pxa_irq_map(struct irq_domain *h, unsigned int virq,
  102. irq_hw_number_t hw)
  103. {
  104. void __iomem *base = irq_base(hw / 32);
  105. /* initialize interrupt priority */
  106. if (cpu_has_ipr)
  107. __raw_writel(hw | IPR_VALID, pxa_irq_base + IPR(hw));
  108. irq_set_chip_and_handler(virq, &pxa_internal_irq_chip,
  109. handle_level_irq);
  110. irq_set_chip_data(virq, base);
  111. return 0;
  112. }
  113. static const struct irq_domain_ops pxa_irq_ops = {
  114. .map = pxa_irq_map,
  115. .xlate = irq_domain_xlate_onecell,
  116. };
  117. static __init void
  118. pxa_init_irq_common(struct device_node *node, int irq_nr,
  119. int (*fn)(struct irq_data *, unsigned int))
  120. {
  121. int n;
  122. pxa_internal_irq_nr = irq_nr;
  123. pxa_irq_domain = irq_domain_add_legacy(node, irq_nr,
  124. PXA_IRQ(0), 0,
  125. &pxa_irq_ops, NULL);
  126. if (!pxa_irq_domain)
  127. panic("Unable to add PXA IRQ domain\n");
  128. irq_set_default_host(pxa_irq_domain);
  129. for (n = 0; n < irq_nr; n += 32) {
  130. void __iomem *base = irq_base(n >> 5);
  131. __raw_writel(0, base + ICMR); /* disable all IRQs */
  132. __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */
  133. }
  134. /* only unmasked interrupts kick us out of idle */
  135. __raw_writel(1, irq_base(0) + ICCR);
  136. pxa_internal_irq_chip.irq_set_wake = fn;
  137. }
  138. void __init pxa_init_irq(int irq_nr, int (*fn)(struct irq_data *, unsigned int))
  139. {
  140. BUG_ON(irq_nr > MAX_INTERNAL_IRQS);
  141. pxa_irq_base = io_p2v(0x40d00000);
  142. cpu_has_ipr = !cpu_is_pxa25x();
  143. pxa_init_irq_common(NULL, irq_nr, fn);
  144. }
  145. #ifdef CONFIG_PM
  146. static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32];
  147. static unsigned long saved_ipr[MAX_INTERNAL_IRQS];
  148. static int pxa_irq_suspend(void)
  149. {
  150. int i;
  151. for (i = 0; i < DIV_ROUND_UP(pxa_internal_irq_nr, 32); i++) {
  152. void __iomem *base = irq_base(i);
  153. saved_icmr[i] = __raw_readl(base + ICMR);
  154. __raw_writel(0, base + ICMR);
  155. }
  156. if (cpu_has_ipr) {
  157. for (i = 0; i < pxa_internal_irq_nr; i++)
  158. saved_ipr[i] = __raw_readl(pxa_irq_base + IPR(i));
  159. }
  160. return 0;
  161. }
  162. static void pxa_irq_resume(void)
  163. {
  164. int i;
  165. for (i = 0; i < DIV_ROUND_UP(pxa_internal_irq_nr, 32); i++) {
  166. void __iomem *base = irq_base(i);
  167. __raw_writel(saved_icmr[i], base + ICMR);
  168. __raw_writel(0, base + ICLR);
  169. }
  170. if (cpu_has_ipr)
  171. for (i = 0; i < pxa_internal_irq_nr; i++)
  172. __raw_writel(saved_ipr[i], pxa_irq_base + IPR(i));
  173. __raw_writel(1, pxa_irq_base + ICCR);
  174. }
  175. #else
  176. #define pxa_irq_suspend NULL
  177. #define pxa_irq_resume NULL
  178. #endif
  179. struct syscore_ops pxa_irq_syscore_ops = {
  180. .suspend = pxa_irq_suspend,
  181. .resume = pxa_irq_resume,
  182. };
  183. #ifdef CONFIG_OF
  184. static const struct of_device_id intc_ids[] __initconst = {
  185. { .compatible = "marvell,pxa-intc", },
  186. {}
  187. };
  188. void __init pxa_dt_irq_init(int (*fn)(struct irq_data *, unsigned int))
  189. {
  190. struct device_node *node;
  191. struct resource res;
  192. int ret;
  193. node = of_find_matching_node(NULL, intc_ids);
  194. if (!node) {
  195. pr_err("Failed to find interrupt controller in arch-pxa\n");
  196. return;
  197. }
  198. ret = of_property_read_u32(node, "marvell,intc-nr-irqs",
  199. &pxa_internal_irq_nr);
  200. if (ret) {
  201. pr_err("Not found marvell,intc-nr-irqs property\n");
  202. return;
  203. }
  204. ret = of_address_to_resource(node, 0, &res);
  205. if (ret < 0) {
  206. pr_err("No registers defined for node\n");
  207. return;
  208. }
  209. pxa_irq_base = io_p2v(res.start);
  210. if (of_find_property(node, "marvell,intc-priority", NULL))
  211. cpu_has_ipr = 1;
  212. ret = irq_alloc_descs(-1, 0, pxa_internal_irq_nr, 0);
  213. if (ret < 0) {
  214. pr_err("Failed to allocate IRQ numbers\n");
  215. return;
  216. }
  217. pxa_init_irq_common(node, pxa_internal_irq_nr, fn);
  218. }
  219. #endif /* CONFIG_OF */