irq.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 <linux/of_address.h>
  21. #include <linux/of_irq.h>
  22. #include <asm/exception.h>
  23. #include <mach/hardware.h>
  24. #include <mach/irqs.h>
  25. #include "generic.h"
  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 void __iomem *pxa_irq_base;
  45. static int pxa_internal_irq_nr;
  46. static bool cpu_has_ipr;
  47. static inline void __iomem *irq_base(int i)
  48. {
  49. static unsigned long phys_base_offset[] = {
  50. 0x0,
  51. 0x9c,
  52. 0x130,
  53. };
  54. return pxa_irq_base + phys_base_offset[i];
  55. }
  56. void pxa_mask_irq(struct irq_data *d)
  57. {
  58. void __iomem *base = irq_data_get_irq_chip_data(d);
  59. uint32_t icmr = __raw_readl(base + ICMR);
  60. icmr &= ~(1 << IRQ_BIT(d->irq));
  61. __raw_writel(icmr, base + ICMR);
  62. }
  63. void pxa_unmask_irq(struct irq_data *d)
  64. {
  65. void __iomem *base = irq_data_get_irq_chip_data(d);
  66. uint32_t icmr = __raw_readl(base + ICMR);
  67. icmr |= 1 << IRQ_BIT(d->irq);
  68. __raw_writel(icmr, base + ICMR);
  69. }
  70. static struct irq_chip pxa_internal_irq_chip = {
  71. .name = "SC",
  72. .irq_ack = pxa_mask_irq,
  73. .irq_mask = pxa_mask_irq,
  74. .irq_unmask = pxa_unmask_irq,
  75. };
  76. asmlinkage void __exception_irq_entry icip_handle_irq(struct pt_regs *regs)
  77. {
  78. uint32_t icip, icmr, mask;
  79. do {
  80. icip = __raw_readl(pxa_irq_base + ICIP);
  81. icmr = __raw_readl(pxa_irq_base + ICMR);
  82. mask = icip & icmr;
  83. if (mask == 0)
  84. break;
  85. handle_IRQ(PXA_IRQ(fls(mask) - 1), regs);
  86. } while (1);
  87. }
  88. asmlinkage void __exception_irq_entry ichp_handle_irq(struct pt_regs *regs)
  89. {
  90. uint32_t ichp;
  91. do {
  92. __asm__ __volatile__("mrc p6, 0, %0, c5, c0, 0\n": "=r"(ichp));
  93. if ((ichp & ICHP_VAL_IRQ) == 0)
  94. break;
  95. handle_IRQ(PXA_IRQ(ICHP_IRQ(ichp)), regs);
  96. } while (1);
  97. }
  98. void __init pxa_init_irq(int irq_nr, int (*fn)(struct irq_data *, unsigned int))
  99. {
  100. int irq, i, n;
  101. BUG_ON(irq_nr > MAX_INTERNAL_IRQS);
  102. pxa_internal_irq_nr = irq_nr;
  103. cpu_has_ipr = !cpu_is_pxa25x();
  104. pxa_irq_base = io_p2v(0x40d00000);
  105. for (n = 0; n < irq_nr; n += 32) {
  106. void __iomem *base = irq_base(n >> 5);
  107. __raw_writel(0, base + ICMR); /* disable all IRQs */
  108. __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */
  109. for (i = n; (i < (n + 32)) && (i < irq_nr); i++) {
  110. /* initialize interrupt priority */
  111. if (cpu_has_ipr)
  112. __raw_writel(i | IPR_VALID, pxa_irq_base + IPR(i));
  113. irq = PXA_IRQ(i);
  114. irq_set_chip_and_handler(irq, &pxa_internal_irq_chip,
  115. handle_level_irq);
  116. irq_set_chip_data(irq, base);
  117. set_irq_flags(irq, IRQF_VALID);
  118. }
  119. }
  120. /* only unmasked interrupts kick us out of idle */
  121. __raw_writel(1, irq_base(0) + ICCR);
  122. pxa_internal_irq_chip.irq_set_wake = fn;
  123. }
  124. #ifdef CONFIG_PM
  125. static unsigned long saved_icmr[MAX_INTERNAL_IRQS/32];
  126. static unsigned long saved_ipr[MAX_INTERNAL_IRQS];
  127. static int pxa_irq_suspend(void)
  128. {
  129. int i;
  130. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  131. void __iomem *base = irq_base(i);
  132. saved_icmr[i] = __raw_readl(base + ICMR);
  133. __raw_writel(0, base + ICMR);
  134. }
  135. if (cpu_has_ipr) {
  136. for (i = 0; i < pxa_internal_irq_nr; i++)
  137. saved_ipr[i] = __raw_readl(pxa_irq_base + IPR(i));
  138. }
  139. return 0;
  140. }
  141. static void pxa_irq_resume(void)
  142. {
  143. int i;
  144. for (i = 0; i < pxa_internal_irq_nr / 32; i++) {
  145. void __iomem *base = irq_base(i);
  146. __raw_writel(saved_icmr[i], base + ICMR);
  147. __raw_writel(0, base + ICLR);
  148. }
  149. if (cpu_has_ipr)
  150. for (i = 0; i < pxa_internal_irq_nr; i++)
  151. __raw_writel(saved_ipr[i], pxa_irq_base + IPR(i));
  152. __raw_writel(1, pxa_irq_base + ICCR);
  153. }
  154. #else
  155. #define pxa_irq_suspend NULL
  156. #define pxa_irq_resume NULL
  157. #endif
  158. struct syscore_ops pxa_irq_syscore_ops = {
  159. .suspend = pxa_irq_suspend,
  160. .resume = pxa_irq_resume,
  161. };
  162. #ifdef CONFIG_OF
  163. static struct irq_domain *pxa_irq_domain;
  164. static int pxa_irq_map(struct irq_domain *h, unsigned int virq,
  165. irq_hw_number_t hw)
  166. {
  167. void __iomem *base = irq_base(hw / 32);
  168. /* initialize interrupt priority */
  169. if (cpu_has_ipr)
  170. __raw_writel(hw | IPR_VALID, pxa_irq_base + IPR(hw));
  171. irq_set_chip_and_handler(hw, &pxa_internal_irq_chip,
  172. handle_level_irq);
  173. irq_set_chip_data(hw, base);
  174. set_irq_flags(hw, IRQF_VALID);
  175. return 0;
  176. }
  177. static struct irq_domain_ops pxa_irq_ops = {
  178. .map = pxa_irq_map,
  179. .xlate = irq_domain_xlate_onecell,
  180. };
  181. static const struct of_device_id intc_ids[] __initconst = {
  182. { .compatible = "marvell,pxa-intc", },
  183. {}
  184. };
  185. void __init pxa_dt_irq_init(int (*fn)(struct irq_data *, unsigned int))
  186. {
  187. struct device_node *node;
  188. const struct of_device_id *of_id;
  189. struct pxa_intc_conf *conf;
  190. struct resource res;
  191. int n, ret;
  192. node = of_find_matching_node(NULL, intc_ids);
  193. if (!node) {
  194. pr_err("Failed to find interrupt controller in arch-pxa\n");
  195. return;
  196. }
  197. of_id = of_match_node(intc_ids, node);
  198. conf = of_id->data;
  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_irq_domain = irq_domain_add_legacy(node, pxa_internal_irq_nr, 0, 0,
  219. &pxa_irq_ops, NULL);
  220. if (!pxa_irq_domain)
  221. panic("Unable to add PXA IRQ domain\n");
  222. irq_set_default_host(pxa_irq_domain);
  223. for (n = 0; n < pxa_internal_irq_nr; n += 32) {
  224. void __iomem *base = irq_base(n >> 5);
  225. __raw_writel(0, base + ICMR); /* disable all IRQs */
  226. __raw_writel(0, base + ICLR); /* all IRQs are IRQ, not FIQ */
  227. }
  228. /* only unmasked interrupts kick us out of idle */
  229. __raw_writel(1, irq_base(0) + ICCR);
  230. pxa_internal_irq_chip.irq_set_wake = fn;
  231. }
  232. #endif /* CONFIG_OF */