irq.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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 <asm/mach/irq.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 <mach/hardware.h>
  25. #include "iomap.h"
  26. #include "common.h"
  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. /* Number of IRQ state bits in each MIR register */
  41. #define IRQ_BITS_PER_REG 32
  42. #define OMAP2_IRQ_BASE OMAP2_L4_IO_ADDRESS(OMAP24XX_IC_BASE)
  43. #define OMAP3_IRQ_BASE OMAP2_L4_IO_ADDRESS(OMAP34XX_IC_BASE)
  44. #define INTCPS_SIR_IRQ_OFFSET 0x0040 /* omap2/3 active interrupt offset */
  45. #define ACTIVEIRQ_MASK 0x7f /* omap2/3 active interrupt bits */
  46. #define INTCPS_NR_MIR_REGS 3
  47. #define INTCPS_NR_IRQS 96
  48. /*
  49. * OMAP2 has a number of different interrupt controllers, each interrupt
  50. * controller is identified as its own "bank". Register definitions are
  51. * fairly consistent for each bank, but not all registers are implemented
  52. * for each bank.. when in doubt, consult the TRM.
  53. */
  54. static struct omap_irq_bank {
  55. void __iomem *base_reg;
  56. unsigned int nr_irqs;
  57. } __attribute__ ((aligned(4))) irq_banks[] = {
  58. {
  59. /* MPU INTC */
  60. .nr_irqs = 96,
  61. },
  62. };
  63. static struct irq_domain *domain;
  64. /* Structure to save interrupt controller context */
  65. struct omap3_intc_regs {
  66. u32 sysconfig;
  67. u32 protection;
  68. u32 idle;
  69. u32 threshold;
  70. u32 ilr[INTCPS_NR_IRQS];
  71. u32 mir[INTCPS_NR_MIR_REGS];
  72. };
  73. /* INTC bank register get/set */
  74. static void intc_bank_write_reg(u32 val, struct omap_irq_bank *bank, u16 reg)
  75. {
  76. __raw_writel(val, bank->base_reg + reg);
  77. }
  78. static u32 intc_bank_read_reg(struct omap_irq_bank *bank, u16 reg)
  79. {
  80. return __raw_readl(bank->base_reg + reg);
  81. }
  82. /* XXX: FIQ and additional INTC support (only MPU at the moment) */
  83. static void omap_ack_irq(struct irq_data *d)
  84. {
  85. intc_bank_write_reg(0x1, &irq_banks[0], INTC_CONTROL);
  86. }
  87. static void omap_mask_ack_irq(struct irq_data *d)
  88. {
  89. irq_gc_mask_disable_reg(d);
  90. omap_ack_irq(d);
  91. }
  92. static void __init omap_irq_bank_init_one(struct omap_irq_bank *bank)
  93. {
  94. unsigned long tmp;
  95. tmp = intc_bank_read_reg(bank, INTC_REVISION) & 0xff;
  96. printk(KERN_INFO "IRQ: Found an INTC at 0x%p "
  97. "(revision %ld.%ld) with %d interrupts\n",
  98. bank->base_reg, tmp >> 4, tmp & 0xf, bank->nr_irqs);
  99. tmp = intc_bank_read_reg(bank, INTC_SYSCONFIG);
  100. tmp |= 1 << 1; /* soft reset */
  101. intc_bank_write_reg(tmp, bank, INTC_SYSCONFIG);
  102. while (!(intc_bank_read_reg(bank, INTC_SYSSTATUS) & 0x1))
  103. /* Wait for reset to complete */;
  104. /* Enable autoidle */
  105. intc_bank_write_reg(1 << 0, bank, INTC_SYSCONFIG);
  106. }
  107. int omap_irq_pending(void)
  108. {
  109. int i;
  110. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  111. struct omap_irq_bank *bank = irq_banks + i;
  112. int irq;
  113. for (irq = 0; irq < bank->nr_irqs; irq += 32)
  114. if (intc_bank_read_reg(bank, INTC_PENDING_IRQ0 +
  115. ((irq >> 5) << 5)))
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. static __init void
  121. omap_alloc_gc(void __iomem *base, unsigned int irq_start, unsigned int num)
  122. {
  123. struct irq_chip_generic *gc;
  124. struct irq_chip_type *ct;
  125. gc = irq_alloc_generic_chip("INTC", 1, irq_start, base,
  126. handle_level_irq);
  127. ct = gc->chip_types;
  128. ct->chip.irq_ack = omap_mask_ack_irq;
  129. ct->chip.irq_mask = irq_gc_mask_disable_reg;
  130. ct->chip.irq_unmask = irq_gc_unmask_enable_reg;
  131. ct->chip.flags |= IRQCHIP_SKIP_SET_WAKE;
  132. ct->regs.enable = INTC_MIR_CLEAR0;
  133. ct->regs.disable = INTC_MIR_SET0;
  134. irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE,
  135. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  136. }
  137. static void __init omap_init_irq(u32 base, int nr_irqs,
  138. struct device_node *node)
  139. {
  140. void __iomem *omap_irq_base;
  141. unsigned long nr_of_irqs = 0;
  142. unsigned int nr_banks = 0;
  143. int i, j, irq_base;
  144. omap_irq_base = ioremap(base, SZ_4K);
  145. if (WARN_ON(!omap_irq_base))
  146. return;
  147. irq_base = irq_alloc_descs(-1, 0, nr_irqs, 0);
  148. if (irq_base < 0) {
  149. pr_warn("Couldn't allocate IRQ numbers\n");
  150. irq_base = 0;
  151. }
  152. domain = irq_domain_add_legacy(node, nr_irqs, irq_base, 0,
  153. &irq_domain_simple_ops, NULL);
  154. for (i = 0; i < ARRAY_SIZE(irq_banks); i++) {
  155. struct omap_irq_bank *bank = irq_banks + i;
  156. bank->nr_irqs = nr_irqs;
  157. /* Static mapping, never released */
  158. bank->base_reg = ioremap(base, SZ_4K);
  159. if (!bank->base_reg) {
  160. pr_err("Could not ioremap irq bank%i\n", i);
  161. continue;
  162. }
  163. omap_irq_bank_init_one(bank);
  164. for (j = 0; j < bank->nr_irqs; j += 32)
  165. omap_alloc_gc(bank->base_reg + j, j + irq_base, 32);
  166. nr_of_irqs += bank->nr_irqs;
  167. nr_banks++;
  168. }
  169. pr_info("Total of %ld interrupts on %d active controller%s\n",
  170. nr_of_irqs, nr_banks, nr_banks > 1 ? "s" : "");
  171. }
  172. void __init omap2_init_irq(void)
  173. {
  174. omap_init_irq(OMAP24XX_IC_BASE, 96, NULL);
  175. }
  176. void __init omap3_init_irq(void)
  177. {
  178. omap_init_irq(OMAP34XX_IC_BASE, 96, NULL);
  179. }
  180. void __init ti81xx_init_irq(void)
  181. {
  182. omap_init_irq(OMAP34XX_IC_BASE, 128, NULL);
  183. }
  184. static inline void omap_intc_handle_irq(void __iomem *base_addr, struct pt_regs *regs)
  185. {
  186. u32 irqnr;
  187. do {
  188. irqnr = readl_relaxed(base_addr + 0x98);
  189. if (irqnr)
  190. goto out;
  191. irqnr = readl_relaxed(base_addr + 0xb8);
  192. if (irqnr)
  193. goto out;
  194. irqnr = readl_relaxed(base_addr + 0xd8);
  195. #ifdef CONFIG_SOC_TI81XX
  196. if (irqnr)
  197. goto out;
  198. irqnr = readl_relaxed(base_addr + 0xf8);
  199. #endif
  200. out:
  201. if (!irqnr)
  202. break;
  203. irqnr = readl_relaxed(base_addr + INTCPS_SIR_IRQ_OFFSET);
  204. irqnr &= ACTIVEIRQ_MASK;
  205. if (irqnr) {
  206. irqnr = irq_find_mapping(domain, irqnr);
  207. handle_IRQ(irqnr, regs);
  208. }
  209. } while (irqnr);
  210. }
  211. asmlinkage void __exception_irq_entry omap2_intc_handle_irq(struct pt_regs *regs)
  212. {
  213. void __iomem *base_addr = OMAP2_IRQ_BASE;
  214. omap_intc_handle_irq(base_addr, regs);
  215. }
  216. int __init intc_of_init(struct device_node *node,
  217. struct device_node *parent)
  218. {
  219. struct resource res;
  220. u32 nr_irq = 96;
  221. if (WARN_ON(!node))
  222. return -ENODEV;
  223. if (of_address_to_resource(node, 0, &res)) {
  224. WARN(1, "unable to get intc registers\n");
  225. return -EINVAL;
  226. }
  227. if (of_property_read_u32(node, "ti,intc-size", &nr_irq))
  228. pr_warn("unable to get intc-size, default to %d\n", nr_irq);
  229. omap_init_irq(res.start, nr_irq, of_node_get(node));
  230. return 0;
  231. }
  232. static struct of_device_id irq_match[] __initdata = {
  233. { .compatible = "ti,omap2-intc", .data = intc_of_init, },
  234. { }
  235. };
  236. void __init omap_intc_of_init(void)
  237. {
  238. of_irq_init(irq_match);
  239. }
  240. #if defined(CONFIG_ARCH_OMAP3) || defined(CONFIG_SOC_AM33XX)
  241. static struct omap3_intc_regs intc_context[ARRAY_SIZE(irq_banks)];
  242. void omap_intc_save_context(void)
  243. {
  244. int ind = 0, i = 0;
  245. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  246. struct omap_irq_bank *bank = irq_banks + ind;
  247. intc_context[ind].sysconfig =
  248. intc_bank_read_reg(bank, INTC_SYSCONFIG);
  249. intc_context[ind].protection =
  250. intc_bank_read_reg(bank, INTC_PROTECTION);
  251. intc_context[ind].idle =
  252. intc_bank_read_reg(bank, INTC_IDLE);
  253. intc_context[ind].threshold =
  254. intc_bank_read_reg(bank, INTC_THRESHOLD);
  255. for (i = 0; i < INTCPS_NR_IRQS; i++)
  256. intc_context[ind].ilr[i] =
  257. intc_bank_read_reg(bank, (0x100 + 0x4*i));
  258. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  259. intc_context[ind].mir[i] =
  260. intc_bank_read_reg(&irq_banks[0], INTC_MIR0 +
  261. (0x20 * i));
  262. }
  263. }
  264. void omap_intc_restore_context(void)
  265. {
  266. int ind = 0, i = 0;
  267. for (ind = 0; ind < ARRAY_SIZE(irq_banks); ind++) {
  268. struct omap_irq_bank *bank = irq_banks + ind;
  269. intc_bank_write_reg(intc_context[ind].sysconfig,
  270. bank, INTC_SYSCONFIG);
  271. intc_bank_write_reg(intc_context[ind].sysconfig,
  272. bank, INTC_SYSCONFIG);
  273. intc_bank_write_reg(intc_context[ind].protection,
  274. bank, INTC_PROTECTION);
  275. intc_bank_write_reg(intc_context[ind].idle,
  276. bank, INTC_IDLE);
  277. intc_bank_write_reg(intc_context[ind].threshold,
  278. bank, INTC_THRESHOLD);
  279. for (i = 0; i < INTCPS_NR_IRQS; i++)
  280. intc_bank_write_reg(intc_context[ind].ilr[i],
  281. bank, (0x100 + 0x4*i));
  282. for (i = 0; i < INTCPS_NR_MIR_REGS; i++)
  283. intc_bank_write_reg(intc_context[ind].mir[i],
  284. &irq_banks[0], INTC_MIR0 + (0x20 * i));
  285. }
  286. /* MIRs are saved and restore with other PRCM registers */
  287. }
  288. void omap3_intc_suspend(void)
  289. {
  290. /* A pending interrupt would prevent OMAP from entering suspend */
  291. omap_ack_irq(NULL);
  292. }
  293. void omap3_intc_prepare_idle(void)
  294. {
  295. /*
  296. * Disable autoidle as it can stall interrupt controller,
  297. * cf. errata ID i540 for 3430 (all revisions up to 3.1.x)
  298. */
  299. intc_bank_write_reg(0, &irq_banks[0], INTC_SYSCONFIG);
  300. }
  301. void omap3_intc_resume_idle(void)
  302. {
  303. /* Re-enable autoidle */
  304. intc_bank_write_reg(1, &irq_banks[0], INTC_SYSCONFIG);
  305. }
  306. asmlinkage void __exception_irq_entry omap3_intc_handle_irq(struct pt_regs *regs)
  307. {
  308. void __iomem *base_addr = OMAP3_IRQ_BASE;
  309. omap_intc_handle_irq(base_addr, regs);
  310. }
  311. #endif /* CONFIG_ARCH_OMAP3 */