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. set_irq_flags(virq, IRQF_VALID);
  112. return 0;
  113. }
  114. static struct irq_domain_ops pxa_irq_ops = {
  115. .map = pxa_irq_map,
  116. .xlate = irq_domain_xlate_onecell,
  117. };
  118. static __init void
  119. pxa_init_irq_common(struct device_node *node, int irq_nr,
  120. int (*fn)(struct irq_data *, unsigned int))
  121. {
  122. int n;
  123. pxa_internal_irq_nr = irq_nr;
  124. pxa_irq_domain = irq_domain_add_legacy(node, irq_nr,
  125. PXA_IRQ(0), 0,
  126. &pxa_irq_ops, NULL);
  127. if (!pxa_irq_domain)
  128. panic("Unable to add PXA IRQ domain\n");
  129. irq_set_default_host(pxa_irq_domain);
  130. for (n = 0; n < irq_nr; n += 32) {
  131. void __iomem *base = irq_base(n >> 5);
  132. __raw_writel(0, base + ICMR); /* disable all IRQs */
  133. __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */
  134. }
  135. /* only unmasked interrupts kick us out of idle */
  136. __raw_writel(1, irq_base(0) + ICCR);
  137. pxa_internal_irq_chip.irq_set_wake = fn;
  138. }
  139. void __init pxa_init_irq(int irq_nr, int (*fn)(struct irq_data *, unsigned int))
  140. {
  141. BUG_ON(irq_nr > MAX_INTERNAL_IRQS);
  142. pxa_irq_base = io_p2v(0x40d00000);
  143. cpu_has_ipr = !cpu_is_pxa25x();
  144. pxa_init_irq_common(NULL, irq_nr, fn);
  145. }
  146. #ifdef CONFIG_PM
  147. static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32];
  148. static unsigned long saved_ipr[MAX_INTERNAL_IRQS];
  149. static int pxa_irq_suspend(void)
  150. {
  151. int i;
  152. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  153. void __iomem *base = irq_base(i);
  154. saved_icmr[i] = __raw_readl(base + ICMR);
  155. __raw_writel(0, base + ICMR);
  156. }
  157. if (cpu_has_ipr) {
  158. for (i = 0; i < pxa_internal_irq_nr; i++)
  159. saved_ipr[i] = __raw_readl(pxa_irq_base + IPR(i));
  160. }
  161. return 0;
  162. }
  163. static void pxa_irq_resume(void)
  164. {
  165. int i;
  166. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  167. void __iomem *base = irq_base(i);
  168. __raw_writel(saved_icmr[i], base + ICMR);
  169. __raw_writel(0, base + ICLR);
  170. }
  171. if (cpu_has_ipr)
  172. for (i = 0; i < pxa_internal_irq_nr; i++)
  173. __raw_writel(saved_ipr[i], pxa_irq_base + IPR(i));
  174. __raw_writel(1, pxa_irq_base + ICCR);
  175. }
  176. #else
  177. #define pxa_irq_suspend NULL
  178. #define pxa_irq_resume NULL
  179. #endif
  180. struct syscore_ops pxa_irq_syscore_ops = {
  181. .suspend = pxa_irq_suspend,
  182. .resume = pxa_irq_resume,
  183. };
  184. #ifdef CONFIG_OF
  185. static const struct of_device_id intc_ids[] __initconst = {
  186. { .compatible = "marvell,pxa-intc", },
  187. {}
  188. };
  189. void __init pxa_dt_irq_init(int (*fn)(struct irq_data *, unsigned int))
  190. {
  191. struct device_node *node;
  192. struct resource res;
  193. int ret;
  194. node = of_find_matching_node(NULL, intc_ids);
  195. if (!node) {
  196. pr_err("Failed to find interrupt controller in arch-pxa\n");
  197. return;
  198. }
  199. ret = of_property_read_u32(node, "marvell,intc-nr-irqs",
  200. &pxa_internal_irq_nr);
  201. if (ret) {
  202. pr_err("Not found marvell,intc-nr-irqs property\n");
  203. return;
  204. }
  205. ret = of_address_to_resource(node, 0, &res);
  206. if (ret < 0) {
  207. pr_err("No registers defined for node\n");
  208. return;
  209. }
  210. pxa_irq_base = io_p2v(res.start);
  211. if (of_find_property(node, "marvell,intc-priority", NULL))
  212. cpu_has_ipr = 1;
  213. ret = irq_alloc_descs(-1, 0, pxa_internal_irq_nr, 0);
  214. if (ret < 0) {
  215. pr_err("Failed to allocate IRQ numbers\n");
  216. return;
  217. }
  218. pxa_init_irq_common(node, pxa_internal_irq_nr, fn);
  219. }
  220. #endif /* CONFIG_OF */