irq-omap-intc.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /*
  2. * linux/arch/arm/mach-omap2/irq.c
  3. *
  4. * Interrupt handler for OMAP2 boards.
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. * Author: Paul Mundt <paul.mundt@nokia.com>
  8. *
  9. * This file is subject to the terms and conditions of the GNU General Public
  10. * License. See the file "COPYING" in the main directory of this archive
  11. * for more details.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/io.h>
  18. #include <asm/exception.h>
  19. #include <linux/irqchip.h>
  20. #include <linux/irqdomain.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <linux/of_irq.h>
  24. #include <linux/irqchip/irq-omap-intc.h>
  25. /* Define these here for now until we drop all board-files */
  26. #define OMAP24XX_IC_BASE 0x480fe000
  27. #define OMAP34XX_IC_BASE 0x48200000
  28. /* selected INTC register offsets */
  29. #define INTC_REVISION 0x0000
  30. #define INTC_SYSCONFIG 0x0010
  31. #define INTC_SYSSTATUS 0x0014
  32. #define INTC_SIR 0x0040
  33. #define INTC_CONTROL 0x0048
  34. #define INTC_PROTECTION 0x004C
  35. #define INTC_IDLE 0x0050
  36. #define INTC_THRESHOLD 0x0068
  37. #define INTC_MIR0 0x0084
  38. #define INTC_MIR_CLEAR0 0x0088
  39. #define INTC_MIR_SET0 0x008c
  40. #define INTC_PENDING_IRQ0 0x0098
  41. #define INTC_PENDING_IRQ1 0x00b8
  42. #define INTC_PENDING_IRQ2 0x00d8
  43. #define INTC_PENDING_IRQ3 0x00f8
  44. #define INTC_ILR0 0x0100
  45. #define ACTIVEIRQ_MASK 0x7f /* omap2/3 active interrupt bits */
  46. #define SPURIOUSIRQ_MASK (0x1ffffff << 7)
  47. #define INTCPS_NR_ILR_REGS 128
  48. #define INTCPS_NR_MIR_REGS 4
  49. #define INTC_IDLE_FUNCIDLE (1 << 0)
  50. #define INTC_IDLE_TURBO (1 << 1)
  51. #define INTC_PROTECTION_ENABLE (1 << 0)
  52. struct omap_intc_regs {
  53. u32 sysconfig;
  54. u32 protection;
  55. u32 idle;
  56. u32 threshold;
  57. u32 ilr[INTCPS_NR_ILR_REGS];
  58. u32 mir[INTCPS_NR_MIR_REGS];
  59. };
  60. static struct omap_intc_regs intc_context;
  61. static struct irq_domain *domain;
  62. static void __iomem *omap_irq_base;
  63. static int omap_nr_pending = 3;
  64. static int omap_nr_irqs = 96;
  65. static void intc_writel(u32 reg, u32 val)
  66. {
  67. writel_relaxed(val, omap_irq_base + reg);
  68. }
  69. static u32 intc_readl(u32 reg)
  70. {
  71. return readl_relaxed(omap_irq_base + reg);
  72. }
  73. void omap_intc_save_context(void)
  74. {
  75. int i;
  76. intc_context.sysconfig =
  77. intc_readl(INTC_SYSCONFIG);
  78. intc_context.protection =
  79. intc_readl(INTC_PROTECTION);
  80. intc_context.idle =
  81. intc_readl(INTC_IDLE);
  82. intc_context.threshold =
  83. intc_readl(INTC_THRESHOLD);
  84. for (i = 0; i < omap_nr_irqs; i++)
  85. intc_context.ilr[i] =
  86. intc_readl((INTC_ILR0 + 0x4 * i));
  87. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  88. intc_context.mir[i] =
  89. intc_readl(INTC_MIR0 + (0x20 * i));
  90. }
  91. void omap_intc_restore_context(void)
  92. {
  93. int i;
  94. intc_writel(INTC_SYSCONFIG, intc_context.sysconfig);
  95. intc_writel(INTC_PROTECTION, intc_context.protection);
  96. intc_writel(INTC_IDLE, intc_context.idle);
  97. intc_writel(INTC_THRESHOLD, intc_context.threshold);
  98. for (i = 0; i < omap_nr_irqs; i++)
  99. intc_writel(INTC_ILR0 + 0x4 * i,
  100. intc_context.ilr[i]);
  101. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  102. intc_writel(INTC_MIR0 + 0x20 * i,
  103. intc_context.mir[i]);
  104. /* MIRs are saved and restore with other PRCM registers */
  105. }
  106. void omap3_intc_prepare_idle(void)
  107. {
  108. /*
  109. * Disable autoidle as it can stall interrupt controller,
  110. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  111. */
  112. intc_writel(INTC_SYSCONFIG, 0);
  113. intc_writel(INTC_IDLE, INTC_IDLE_TURBO);
  114. }
  115. void omap3_intc_resume_idle(void)
  116. {
  117. /* Re-enable autoidle */
  118. intc_writel(INTC_SYSCONFIG, 1);
  119. intc_writel(INTC_IDLE, 0);
  120. }
  121. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  122. static void omap_ack_irq(struct irq_data *d)
  123. {
  124. intc_writel(INTC_CONTROL, 0x1);
  125. }
  126. static void omap_mask_ack_irq(struct irq_data *d)
  127. {
  128. irq_gc_mask_disable_reg(d);
  129. omap_ack_irq(d);
  130. }
  131. static void __init omap_irq_soft_reset(void)
  132. {
  133. unsigned long tmp;
  134. tmp = intc_readl(INTC_REVISION) & 0xff;
  135. pr_info("IRQ: Found an INTC at 0x%p (revision %ld.%ld) with %d interrupts\n",
  136. omap_irq_base, tmp >> 4, tmp & 0xf, omap_nr_irqs);
  137. tmp = intc_readl(INTC_SYSCONFIG);
  138. tmp |= 1 << 1; /* soft reset */
  139. intc_writel(INTC_SYSCONFIG, tmp);
  140. while (!(intc_readl(INTC_SYSSTATUS) & 0x1))
  141. /* Wait for reset to complete */;
  142. /* Enable autoidle */
  143. intc_writel(INTC_SYSCONFIG, 1 << 0);
  144. }
  145. int omap_irq_pending(void)
  146. {
  147. int i;
  148. for (i = 0; i < omap_nr_pending; i++)
  149. if (intc_readl(INTC_PENDING_IRQ0 + (0x20 * i)))
  150. return 1;
  151. return 0;
  152. }
  153. void omap3_intc_suspend(void)
  154. {
  155. /* A pending interrupt would prevent OMAP from entering suspend */
  156. omap_ack_irq(NULL);
  157. }
  158. static int __init omap_alloc_gc_of(struct irq_domain *d, void __iomem *base)
  159. {
  160. int ret;
  161. int i;
  162. ret = irq_alloc_domain_generic_chips(d, 32, 1, "INTC",
  163. handle_level_irq, IRQ_NOREQUEST | IRQ_NOPROBE,
  164. IRQ_LEVEL, 0);
  165. if (ret) {
  166. pr_warn("Failed to allocate irq chips\n");
  167. return ret;
  168. }
  169. for (i = 0; i < omap_nr_pending; i++) {
  170. struct irq_chip_generic *gc;
  171. struct irq_chip_type *ct;
  172. gc = irq_get_domain_generic_chip(d, 32 * i);
  173. gc->reg_base = base;
  174. ct = gc->chip_types;
  175. ct->type = IRQ_TYPE_LEVEL_MASK;
  176. ct->chip.irq_ack = omap_mask_ack_irq;
  177. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  178. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  179. ct->chip.flags |= IRQCHIP_SKIP_SET_WAKE;
  180. ct->regs.enable = INTC_MIR_CLEAR0 + 32 * i;
  181. ct->regs.disable = INTC_MIR_SET0 + 32 * i;
  182. }
  183. return 0;
  184. }
  185. static void __init omap_alloc_gc_legacy(void __iomem *base,
  186. unsigned int irq_start, unsigned int num)
  187. {
  188. struct irq_chip_generic *gc;
  189. struct irq_chip_type *ct;
  190. gc = irq_alloc_generic_chip("INTC", 1, irq_start, base,
  191. handle_level_irq);
  192. ct = gc->chip_types;
  193. ct->chip.irq_ack = omap_mask_ack_irq;
  194. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  195. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  196. ct->chip.flags |= IRQCHIP_SKIP_SET_WAKE;
  197. ct->regs.enable = INTC_MIR_CLEAR0;
  198. ct->regs.disable = INTC_MIR_SET0;
  199. irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
  200. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  201. }
  202. static int __init omap_init_irq_of(struct device_node *node)
  203. {
  204. int ret;
  205. omap_irq_base = of_iomap(node, 0);
  206. if (WARN_ON(!omap_irq_base))
  207. return -ENOMEM;
  208. domain = irq_domain_add_linear(node, omap_nr_irqs,
  209. &irq_generic_chip_ops, NULL);
  210. omap_irq_soft_reset();
  211. ret = omap_alloc_gc_of(domain, omap_irq_base);
  212. if (ret < 0)
  213. irq_domain_remove(domain);
  214. return ret;
  215. }
  216. static int __init omap_init_irq_legacy(u32 base, struct device_node *node)
  217. {
  218. int j, irq_base;
  219. omap_irq_base = ioremap(base, SZ_4K);
  220. if (WARN_ON(!omap_irq_base))
  221. return -ENOMEM;
  222. irq_base = irq_alloc_descs(-1, 0, omap_nr_irqs, 0);
  223. if (irq_base < 0) {
  224. pr_warn("Couldn't allocate IRQ numbers\n");
  225. irq_base = 0;
  226. }
  227. domain = irq_domain_add_legacy(node, omap_nr_irqs, irq_base, 0,
  228. &irq_domain_simple_ops, NULL);
  229. omap_irq_soft_reset();
  230. for (j = 0; j < omap_nr_irqs; j += 32)
  231. omap_alloc_gc_legacy(omap_irq_base + j, j + irq_base, 32);
  232. return 0;
  233. }
  234. static void __init omap_irq_enable_protection(void)
  235. {
  236. u32 reg;
  237. reg = intc_readl(INTC_PROTECTION);
  238. reg |= INTC_PROTECTION_ENABLE;
  239. intc_writel(INTC_PROTECTION, reg);
  240. }
  241. static int __init omap_init_irq(u32 base, struct device_node *node)
  242. {
  243. int ret;
  244. /*
  245. * FIXME legacy OMAP DMA driver sitting under arch/arm/plat-omap/dma.c
  246. * depends is still not ready for linear IRQ domains; because of that
  247. * we need to temporarily "blacklist" OMAP2 and OMAP3 devices from using
  248. * linear IRQ Domain until that driver is finally fixed.
  249. */
  250. if (of_device_is_compatible(node, "ti,omap2-intc") ||
  251. of_device_is_compatible(node, "ti,omap3-intc")) {
  252. struct resource res;
  253. if (of_address_to_resource(node, 0, &res))
  254. return -ENOMEM;
  255. base = res.start;
  256. ret = omap_init_irq_legacy(base, node);
  257. } else if (node) {
  258. ret = omap_init_irq_of(node);
  259. } else {
  260. ret = omap_init_irq_legacy(base, NULL);
  261. }
  262. if (ret == 0)
  263. omap_irq_enable_protection();
  264. return ret;
  265. }
  266. static asmlinkage void __exception_irq_entry
  267. omap_intc_handle_irq(struct pt_regs *regs)
  268. {
  269. extern unsigned long irq_err_count;
  270. u32 irqnr;
  271. irqnr = intc_readl(INTC_SIR);
  272. /*
  273. * A spurious IRQ can result if interrupt that triggered the
  274. * sorting is no longer active during the sorting (10 INTC
  275. * functional clock cycles after interrupt assertion). Or a
  276. * change in interrupt mask affected the result during sorting
  277. * time. There is no special handling required except ignoring
  278. * the SIR register value just read and retrying.
  279. * See section 6.2.5 of AM335x TRM Literature Number: SPRUH73K
  280. *
  281. * Many a times, a spurious interrupt situation has been fixed
  282. * by adding a flush for the posted write acking the IRQ in
  283. * the device driver. Typically, this is going be the device
  284. * driver whose interrupt was handled just before the spurious
  285. * IRQ occurred. Pay attention to those device drivers if you
  286. * run into hitting the spurious IRQ condition below.
  287. */
  288. if (unlikely((irqnr & SPURIOUSIRQ_MASK) == SPURIOUSIRQ_MASK)) {
  289. pr_err_once("%s: spurious irq!\n", __func__);
  290. irq_err_count++;
  291. omap_ack_irq(NULL);
  292. return;
  293. }
  294. irqnr &= ACTIVEIRQ_MASK;
  295. handle_domain_irq(domain, irqnr, regs);
  296. }
  297. void __init omap3_init_irq(void)
  298. {
  299. omap_nr_irqs = 96;
  300. omap_nr_pending = 3;
  301. omap_init_irq(OMAP34XX_IC_BASE, NULL);
  302. set_handle_irq(omap_intc_handle_irq);
  303. }
  304. static int __init intc_of_init(struct device_node *node,
  305. struct device_node *parent)
  306. {
  307. int ret;
  308. omap_nr_pending = 3;
  309. omap_nr_irqs = 96;
  310. if (WARN_ON(!node))
  311. return -ENODEV;
  312. if (of_device_is_compatible(node, "ti,dm814-intc") ||
  313. of_device_is_compatible(node, "ti,dm816-intc") ||
  314. of_device_is_compatible(node, "ti,am33xx-intc")) {
  315. omap_nr_irqs = 128;
  316. omap_nr_pending = 4;
  317. }
  318. ret = omap_init_irq(-1, of_node_get(node));
  319. if (ret < 0)
  320. return ret;
  321. set_handle_irq(omap_intc_handle_irq);
  322. return 0;
  323. }
  324. IRQCHIP_DECLARE(omap2_intc, "ti,omap2-intc", intc_of_init);
  325. IRQCHIP_DECLARE(omap3_intc, "ti,omap3-intc", intc_of_init);
  326. IRQCHIP_DECLARE(dm814x_intc, "ti,dm814-intc", intc_of_init);
  327. IRQCHIP_DECLARE(dm816x_intc, "ti,dm816-intc", intc_of_init);
  328. IRQCHIP_DECLARE(am33xx_intc, "ti,am33xx-intc", intc_of_init);