irq-omap-intc.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. /* Define these here for now until we drop all board-files */
  25. #define OMAP24XX_IC_BASE 0x480fe000
  26. #define OMAP34XX_IC_BASE 0x48200000
  27. /* selected INTC register offsets */
  28. #define INTC_REVISION 0x0000
  29. #define INTC_SYSCONFIG 0x0010
  30. #define INTC_SYSSTATUS 0x0014
  31. #define INTC_SIR 0x0040
  32. #define INTC_CONTROL 0x0048
  33. #define INTC_PROTECTION 0x004C
  34. #define INTC_IDLE 0x0050
  35. #define INTC_THRESHOLD 0x0068
  36. #define INTC_MIR0 0x0084
  37. #define INTC_MIR_CLEAR0 0x0088
  38. #define INTC_MIR_SET0 0x008c
  39. #define INTC_PENDING_IRQ0 0x0098
  40. #define INTC_PENDING_IRQ1 0x00b8
  41. #define INTC_PENDING_IRQ2 0x00d8
  42. #define INTC_PENDING_IRQ3 0x00f8
  43. #define INTC_ILR0 0x0100
  44. #define ACTIVEIRQ_MASK 0x7f /* omap2/3 active interrupt bits */
  45. #define SPURIOUSIRQ_MASK (0x1ffffff << 7)
  46. #define INTCPS_NR_ILR_REGS 128
  47. #define INTCPS_NR_MIR_REGS 4
  48. #define INTC_IDLE_FUNCIDLE (1 << 0)
  49. #define INTC_IDLE_TURBO (1 << 1)
  50. #define INTC_PROTECTION_ENABLE (1 << 0)
  51. struct omap_intc_regs {
  52. u32 sysconfig;
  53. u32 protection;
  54. u32 idle;
  55. u32 threshold;
  56. u32 ilr[INTCPS_NR_ILR_REGS];
  57. u32 mir[INTCPS_NR_MIR_REGS];
  58. };
  59. static struct omap_intc_regs intc_context;
  60. static struct irq_domain *domain;
  61. static void __iomem *omap_irq_base;
  62. static int omap_nr_pending = 3;
  63. static int omap_nr_irqs = 96;
  64. static void intc_writel(u32 reg, u32 val)
  65. {
  66. writel_relaxed(val, omap_irq_base + reg);
  67. }
  68. static u32 intc_readl(u32 reg)
  69. {
  70. return readl_relaxed(omap_irq_base + reg);
  71. }
  72. void omap_intc_save_context(void)
  73. {
  74. int i;
  75. intc_context.sysconfig =
  76. intc_readl(INTC_SYSCONFIG);
  77. intc_context.protection =
  78. intc_readl(INTC_PROTECTION);
  79. intc_context.idle =
  80. intc_readl(INTC_IDLE);
  81. intc_context.threshold =
  82. intc_readl(INTC_THRESHOLD);
  83. for (i = 0; i < omap_nr_irqs; i++)
  84. intc_context.ilr[i] =
  85. intc_readl((INTC_ILR0 + 0x4 * i));
  86. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  87. intc_context.mir[i] =
  88. intc_readl(INTC_MIR0 + (0x20 * i));
  89. }
  90. void omap_intc_restore_context(void)
  91. {
  92. int i;
  93. intc_writel(INTC_SYSCONFIG, intc_context.sysconfig);
  94. intc_writel(INTC_PROTECTION, intc_context.protection);
  95. intc_writel(INTC_IDLE, intc_context.idle);
  96. intc_writel(INTC_THRESHOLD, intc_context.threshold);
  97. for (i = 0; i < omap_nr_irqs; i++)
  98. intc_writel(INTC_ILR0 + 0x4 * i,
  99. intc_context.ilr[i]);
  100. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  101. intc_writel(INTC_MIR0 + 0x20 * i,
  102. intc_context.mir[i]);
  103. /* MIRs are saved and restore with other PRCM registers */
  104. }
  105. void omap3_intc_prepare_idle(void)
  106. {
  107. /*
  108. * Disable autoidle as it can stall interrupt controller,
  109. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  110. */
  111. intc_writel(INTC_SYSCONFIG, 0);
  112. intc_writel(INTC_IDLE, INTC_IDLE_TURBO);
  113. }
  114. void omap3_intc_resume_idle(void)
  115. {
  116. /* Re-enable autoidle */
  117. intc_writel(INTC_SYSCONFIG, 1);
  118. intc_writel(INTC_IDLE, 0);
  119. }
  120. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  121. static void omap_ack_irq(struct irq_data *d)
  122. {
  123. intc_writel(INTC_CONTROL, 0x1);
  124. }
  125. static void omap_mask_ack_irq(struct irq_data *d)
  126. {
  127. irq_gc_mask_disable_reg(d);
  128. omap_ack_irq(d);
  129. }
  130. static void __init omap_irq_soft_reset(void)
  131. {
  132. unsigned long tmp;
  133. tmp = intc_readl(INTC_REVISION) & 0xff;
  134. pr_info("IRQ: Found an INTC at 0x%p (revision %ld.%ld) with %d interrupts\n",
  135. omap_irq_base, tmp >> 4, tmp & 0xf, omap_nr_irqs);
  136. tmp = intc_readl(INTC_SYSCONFIG);
  137. tmp |= 1 << 1; /* soft reset */
  138. intc_writel(INTC_SYSCONFIG, tmp);
  139. while (!(intc_readl(INTC_SYSSTATUS) & 0x1))
  140. /* Wait for reset to complete */;
  141. /* Enable autoidle */
  142. intc_writel(INTC_SYSCONFIG, 1 << 0);
  143. }
  144. int omap_irq_pending(void)
  145. {
  146. int i;
  147. for (i = 0; i < omap_nr_pending; i++)
  148. if (intc_readl(INTC_PENDING_IRQ0 + (0x20 * i)))
  149. return 1;
  150. return 0;
  151. }
  152. void omap3_intc_suspend(void)
  153. {
  154. /* A pending interrupt would prevent OMAP from entering suspend */
  155. omap_ack_irq(NULL);
  156. }
  157. static int __init omap_alloc_gc_of(struct irq_domain *d, void __iomem *base)
  158. {
  159. int ret;
  160. int i;
  161. ret = irq_alloc_domain_generic_chips(d, 32, 1, "INTC",
  162. handle_level_irq, IRQ_NOREQUEST | IRQ_NOPROBE,
  163. IRQ_LEVEL, 0);
  164. if (ret) {
  165. pr_warn("Failed to allocate irq chips\n");
  166. return ret;
  167. }
  168. for (i = 0; i < omap_nr_pending; i++) {
  169. struct irq_chip_generic *gc;
  170. struct irq_chip_type *ct;
  171. gc = irq_get_domain_generic_chip(d, 32 * i);
  172. gc->reg_base = base;
  173. ct = gc->chip_types;
  174. ct->type = IRQ_TYPE_LEVEL_MASK;
  175. ct->handler = handle_level_irq;
  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);