irq-omap-intc.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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/irqdomain.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include "irqchip.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 INTCPS_NR_ILR_REGS 128
  46. #define INTCPS_NR_MIR_REGS 4
  47. #define INTC_IDLE_FUNCIDLE (1 << 0)
  48. #define INTC_IDLE_TURBO (1 << 1)
  49. #define INTC_PROTECTION_ENABLE (1 << 0)
  50. struct omap_intc_regs {
  51. u32 sysconfig;
  52. u32 protection;
  53. u32 idle;
  54. u32 threshold;
  55. u32 ilr[INTCPS_NR_ILR_REGS];
  56. u32 mir[INTCPS_NR_MIR_REGS];
  57. };
  58. static struct omap_intc_regs intc_context;
  59. static struct irq_domain *domain;
  60. static void __iomem *omap_irq_base;
  61. static int omap_nr_pending = 3;
  62. static int omap_nr_irqs = 96;
  63. static void intc_writel(u32 reg, u32 val)
  64. {
  65. writel_relaxed(val, omap_irq_base + reg);
  66. }
  67. static u32 intc_readl(u32 reg)
  68. {
  69. return readl_relaxed(omap_irq_base + reg);
  70. }
  71. void omap_intc_save_context(void)
  72. {
  73. int i;
  74. intc_context.sysconfig =
  75. intc_readl(INTC_SYSCONFIG);
  76. intc_context.protection =
  77. intc_readl(INTC_PROTECTION);
  78. intc_context.idle =
  79. intc_readl(INTC_IDLE);
  80. intc_context.threshold =
  81. intc_readl(INTC_THRESHOLD);
  82. for (i = 0; i < omap_nr_irqs; i++)
  83. intc_context.ilr[i] =
  84. intc_readl((INTC_ILR0 + 0x4 * i));
  85. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  86. intc_context.mir[i] =
  87. intc_readl(INTC_MIR0 + (0x20 * i));
  88. }
  89. void omap_intc_restore_context(void)
  90. {
  91. int i;
  92. intc_writel(INTC_SYSCONFIG, intc_context.sysconfig);
  93. intc_writel(INTC_PROTECTION, intc_context.protection);
  94. intc_writel(INTC_IDLE, intc_context.idle);
  95. intc_writel(INTC_THRESHOLD, intc_context.threshold);
  96. for (i = 0; i < omap_nr_irqs; i++)
  97. intc_writel(INTC_ILR0 + 0x4 * i,
  98. intc_context.ilr[i]);
  99. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  100. intc_writel(INTC_MIR0 + 0x20 * i,
  101. intc_context.mir[i]);
  102. /* MIRs are saved and restore with other PRCM registers */
  103. }
  104. void omap3_intc_prepare_idle(void)
  105. {
  106. /*
  107. * Disable autoidle as it can stall interrupt controller,
  108. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  109. */
  110. intc_writel(INTC_SYSCONFIG, 0);
  111. intc_writel(INTC_IDLE, INTC_IDLE_TURBO);
  112. }
  113. void omap3_intc_resume_idle(void)
  114. {
  115. /* Re-enable autoidle */
  116. intc_writel(INTC_SYSCONFIG, 1);
  117. intc_writel(INTC_IDLE, 0);
  118. }
  119. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  120. static void omap_ack_irq(struct irq_data *d)
  121. {
  122. intc_writel(INTC_CONTROL, 0x1);
  123. }
  124. static void omap_mask_ack_irq(struct irq_data *d)
  125. {
  126. irq_gc_mask_disable_reg(d);
  127. omap_ack_irq(d);
  128. }
  129. static void __init omap_irq_soft_reset(void)
  130. {
  131. unsigned long tmp;
  132. tmp = intc_readl(INTC_REVISION) & 0xff;
  133. pr_info("IRQ: Found an INTC at 0x%p (revision %ld.%ld) with %d interrupts\n",
  134. omap_irq_base, tmp >> 4, tmp & 0xf, omap_nr_irqs);
  135. tmp = intc_readl(INTC_SYSCONFIG);
  136. tmp |= 1 << 1; /* soft reset */
  137. intc_writel(INTC_SYSCONFIG, tmp);
  138. while (!(intc_readl(INTC_SYSSTATUS) & 0x1))
  139. /* Wait for reset to complete */;
  140. /* Enable autoidle */
  141. intc_writel(INTC_SYSCONFIG, 1 << 0);
  142. }
  143. int omap_irq_pending(void)
  144. {
  145. int i;
  146. for (i = 0; i < omap_nr_pending; i++)
  147. if (intc_readl(INTC_PENDING_IRQ0 + (0x20 * i)))
  148. return 1;
  149. return 0;
  150. }
  151. void omap3_intc_suspend(void)
  152. {
  153. /* A pending interrupt would prevent OMAP from entering suspend */
  154. omap_ack_irq(NULL);
  155. }
  156. static int __init omap_alloc_gc_of(struct irq_domain *d, void __iomem *base)
  157. {
  158. int ret;
  159. int i;
  160. ret = irq_alloc_domain_generic_chips(d, 32, 1, "INTC",
  161. handle_level_irq, IRQ_NOREQUEST | IRQ_NOPROBE,
  162. IRQ_LEVEL, 0);
  163. if (ret) {
  164. pr_warn("Failed to allocate irq chips\n");
  165. return ret;
  166. }
  167. for (i = 0; i < omap_nr_pending; i++) {
  168. struct irq_chip_generic *gc;
  169. struct irq_chip_type *ct;
  170. gc = irq_get_domain_generic_chip(d, 32 * i);
  171. gc->reg_base = base;
  172. ct = gc->chip_types;
  173. ct->type = IRQ_TYPE_LEVEL_MASK;
  174. ct->handler = handle_level_irq;
  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)
  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(NULL, 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. if (node)
  244. ret = omap_init_irq_of(node);
  245. else
  246. ret = omap_init_irq_legacy(base);
  247. if (ret == 0)
  248. omap_irq_enable_protection();
  249. return ret;
  250. }
  251. static asmlinkage void __exception_irq_entry
  252. omap_intc_handle_irq(struct pt_regs *regs)
  253. {
  254. u32 irqnr = 0;
  255. int handled_irq = 0;
  256. int i;
  257. do {
  258. for (i = 0; i < omap_nr_pending; i++) {
  259. irqnr = intc_readl(INTC_PENDING_IRQ0 + (0x20 * i));
  260. if (irqnr)
  261. goto out;
  262. }
  263. out:
  264. if (!irqnr)
  265. break;
  266. irqnr = intc_readl(INTC_SIR);
  267. irqnr &= ACTIVEIRQ_MASK;
  268. if (irqnr) {
  269. handle_domain_irq(domain, irqnr, regs);
  270. handled_irq = 1;
  271. }
  272. } while (irqnr);
  273. /*
  274. * If an irq is masked or deasserted while active, we will
  275. * keep ending up here with no irq handled. So remove it from
  276. * the INTC with an ack.
  277. */
  278. if (!handled_irq)
  279. omap_ack_irq(NULL);
  280. }
  281. void __init omap2_init_irq(void)
  282. {
  283. omap_nr_irqs = 96;
  284. omap_nr_pending = 3;
  285. omap_init_irq(OMAP24XX_IC_BASE, NULL);
  286. set_handle_irq(omap_intc_handle_irq);
  287. }
  288. void __init omap3_init_irq(void)
  289. {
  290. omap_nr_irqs = 96;
  291. omap_nr_pending = 3;
  292. omap_init_irq(OMAP34XX_IC_BASE, NULL);
  293. set_handle_irq(omap_intc_handle_irq);
  294. }
  295. void __init ti81xx_init_irq(void)
  296. {
  297. omap_nr_irqs = 96;
  298. omap_nr_pending = 4;
  299. omap_init_irq(OMAP34XX_IC_BASE, NULL);
  300. set_handle_irq(omap_intc_handle_irq);
  301. }
  302. static int __init intc_of_init(struct device_node *node,
  303. struct device_node *parent)
  304. {
  305. int ret;
  306. omap_nr_pending = 3;
  307. omap_nr_irqs = 96;
  308. if (WARN_ON(!node))
  309. return -ENODEV;
  310. if (of_device_is_compatible(node, "ti,am33xx-intc")) {
  311. omap_nr_irqs = 128;
  312. omap_nr_pending = 4;
  313. }
  314. ret = omap_init_irq(-1, of_node_get(node));
  315. if (ret < 0)
  316. return ret;
  317. set_handle_irq(omap_intc_handle_irq);
  318. return 0;
  319. }
  320. IRQCHIP_DECLARE(omap2_intc, "ti,omap2-intc", intc_of_init);
  321. IRQCHIP_DECLARE(omap3_intc, "ti,omap3-intc", intc_of_init);
  322. IRQCHIP_DECLARE(am33xx_intc, "ti,am33xx-intc", intc_of_init);