irq-omap-intc.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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->chip.irq_ack = omap_mask_ack_irq;
  176. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  177. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  178. ct->chip.flags |= IRQCHIP_SKIP_SET_WAKE;
  179. ct->regs.enable = INTC_MIR_CLEAR0 + 32 * i;
  180. ct->regs.disable = INTC_MIR_SET0 + 32 * i;
  181. }
  182. return 0;
  183. }
  184. static void __init omap_alloc_gc_legacy(void __iomem *base,
  185. unsigned int irq_start, unsigned int num)
  186. {
  187. struct irq_chip_generic *gc;
  188. struct irq_chip_type *ct;
  189. gc = irq_alloc_generic_chip("INTC", 1, irq_start, base,
  190. handle_level_irq);
  191. ct = gc->chip_types;
  192. ct->chip.irq_ack = omap_mask_ack_irq;
  193. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  194. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  195. ct->chip.flags |= IRQCHIP_SKIP_SET_WAKE;
  196. ct->regs.enable = INTC_MIR_CLEAR0;
  197. ct->regs.disable = INTC_MIR_SET0;
  198. irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
  199. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  200. }
  201. static int __init omap_init_irq_of(struct device_node *node)
  202. {
  203. int ret;
  204. omap_irq_base = of_iomap(node, 0);
  205. if (WARN_ON(!omap_irq_base))
  206. return -ENOMEM;
  207. domain = irq_domain_add_linear(node, omap_nr_irqs,
  208. &irq_generic_chip_ops, NULL);
  209. omap_irq_soft_reset();
  210. ret = omap_alloc_gc_of(domain, omap_irq_base);
  211. if (ret < 0)
  212. irq_domain_remove(domain);
  213. return ret;
  214. }
  215. static int __init omap_init_irq_legacy(u32 base, struct device_node *node)
  216. {
  217. int j, irq_base;
  218. omap_irq_base = ioremap(base, SZ_4K);
  219. if (WARN_ON(!omap_irq_base))
  220. return -ENOMEM;
  221. irq_base = irq_alloc_descs(-1, 0, omap_nr_irqs, 0);
  222. if (irq_base < 0) {
  223. pr_warn("Couldn't allocate IRQ numbers\n");
  224. irq_base = 0;
  225. }
  226. domain = irq_domain_add_legacy(node, omap_nr_irqs, irq_base, 0,
  227. &irq_domain_simple_ops, NULL);
  228. omap_irq_soft_reset();
  229. for (j = 0; j < omap_nr_irqs; j += 32)
  230. omap_alloc_gc_legacy(omap_irq_base + j, j + irq_base, 32);
  231. return 0;
  232. }
  233. static void __init omap_irq_enable_protection(void)
  234. {
  235. u32 reg;
  236. reg = intc_readl(INTC_PROTECTION);
  237. reg |= INTC_PROTECTION_ENABLE;
  238. intc_writel(INTC_PROTECTION, reg);
  239. }
  240. static int __init omap_init_irq(u32 base, struct device_node *node)
  241. {
  242. int ret;
  243. /*
  244. * FIXME legacy OMAP DMA driver sitting under arch/arm/plat-omap/dma.c
  245. * depends is still not ready for linear IRQ domains; because of that
  246. * we need to temporarily "blacklist" OMAP2 and OMAP3 devices from using
  247. * linear IRQ Domain until that driver is finally fixed.
  248. */
  249. if (of_device_is_compatible(node, "ti,omap2-intc") ||
  250. of_device_is_compatible(node, "ti,omap3-intc")) {
  251. struct resource res;
  252. if (of_address_to_resource(node, 0, &res))
  253. return -ENOMEM;
  254. base = res.start;
  255. ret = omap_init_irq_legacy(base, node);
  256. } else if (node) {
  257. ret = omap_init_irq_of(node);
  258. } else {
  259. ret = omap_init_irq_legacy(base, NULL);
  260. }
  261. if (ret == 0)
  262. omap_irq_enable_protection();
  263. return ret;
  264. }
  265. static asmlinkage void __exception_irq_entry
  266. omap_intc_handle_irq(struct pt_regs *regs)
  267. {
  268. extern unsigned long irq_err_count;
  269. u32 irqnr;
  270. irqnr = intc_readl(INTC_SIR);
  271. /*
  272. * A spurious IRQ can result if interrupt that triggered the
  273. * sorting is no longer active during the sorting (10 INTC
  274. * functional clock cycles after interrupt assertion). Or a
  275. * change in interrupt mask affected the result during sorting
  276. * time. There is no special handling required except ignoring
  277. * the SIR register value just read and retrying.
  278. * See section 6.2.5 of AM335x TRM Literature Number: SPRUH73K
  279. *
  280. * Many a times, a spurious interrupt situation has been fixed
  281. * by adding a flush for the posted write acking the IRQ in
  282. * the device driver. Typically, this is going be the device
  283. * driver whose interrupt was handled just before the spurious
  284. * IRQ occurred. Pay attention to those device drivers if you
  285. * run into hitting the spurious IRQ condition below.
  286. */
  287. if (unlikely((irqnr & SPURIOUSIRQ_MASK) == SPURIOUSIRQ_MASK)) {
  288. pr_err_once("%s: spurious irq!\n", __func__);
  289. irq_err_count++;
  290. omap_ack_irq(NULL);
  291. return;
  292. }
  293. irqnr &= ACTIVEIRQ_MASK;
  294. handle_domain_irq(domain, irqnr, regs);
  295. }
  296. void __init omap3_init_irq(void)
  297. {
  298. omap_nr_irqs = 96;
  299. omap_nr_pending = 3;
  300. omap_init_irq(OMAP34XX_IC_BASE, NULL);
  301. set_handle_irq(omap_intc_handle_irq);
  302. }
  303. static int __init intc_of_init(struct device_node *node,
  304. struct device_node *parent)
  305. {
  306. int ret;
  307. omap_nr_pending = 3;
  308. omap_nr_irqs = 96;
  309. if (WARN_ON(!node))
  310. return -ENODEV;
  311. if (of_device_is_compatible(node, "ti,dm814-intc") ||
  312. of_device_is_compatible(node, "ti,dm816-intc") ||
  313. of_device_is_compatible(node, "ti,am33xx-intc")) {
  314. omap_nr_irqs = 128;
  315. omap_nr_pending = 4;
  316. }
  317. ret = omap_init_irq(-1, of_node_get(node));
  318. if (ret < 0)
  319. return ret;
  320. set_handle_irq(omap_intc_handle_irq);
  321. return 0;
  322. }
  323. IRQCHIP_DECLARE(omap2_intc, "ti,omap2-intc", intc_of_init);
  324. IRQCHIP_DECLARE(omap3_intc, "ti,omap3-intc", intc_of_init);
  325. IRQCHIP_DECLARE(dm814x_intc, "ti,dm814-intc", intc_of_init);
  326. IRQCHIP_DECLARE(dm816x_intc, "ti,dm816-intc", intc_of_init);
  327. IRQCHIP_DECLARE(am33xx_intc, "ti,am33xx-intc", intc_of_init);