irq.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2011-2012 Texas Instruments Incorporated
  3. *
  4. * This borrows heavily from powerpc version, which is:
  5. *
  6. * Derived from arch/i386/kernel/irq.c
  7. * Copyright (C) 1992 Linus Torvalds
  8. * Adapted from arch/i386 by Gary Thomas
  9. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  10. * Updated and modified by Cort Dougan <cort@fsmlabs.com>
  11. * Copyright (C) 1996-2001 Cort Dougan
  12. * Adapted for Power Macintosh by Paul Mackerras
  13. * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/slab.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/radix-tree.h>
  23. #include <linux/module.h>
  24. #include <linux/of.h>
  25. #include <linux/of_irq.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/kernel_stat.h>
  28. #include <asm/megamod-pic.h>
  29. #include <asm/special_insns.h>
  30. unsigned long irq_err_count;
  31. static DEFINE_RAW_SPINLOCK(core_irq_lock);
  32. static void mask_core_irq(struct irq_data *data)
  33. {
  34. unsigned int prio = data->hwirq;
  35. raw_spin_lock(&core_irq_lock);
  36. and_creg(IER, ~(1 << prio));
  37. raw_spin_unlock(&core_irq_lock);
  38. }
  39. static void unmask_core_irq(struct irq_data *data)
  40. {
  41. unsigned int prio = data->hwirq;
  42. raw_spin_lock(&core_irq_lock);
  43. or_creg(IER, 1 << prio);
  44. raw_spin_unlock(&core_irq_lock);
  45. }
  46. static struct irq_chip core_chip = {
  47. .name = "core",
  48. .irq_mask = mask_core_irq,
  49. .irq_unmask = unmask_core_irq,
  50. };
  51. static int prio_to_virq[NR_PRIORITY_IRQS];
  52. asmlinkage void c6x_do_IRQ(unsigned int prio, struct pt_regs *regs)
  53. {
  54. struct pt_regs *old_regs = set_irq_regs(regs);
  55. irq_enter();
  56. generic_handle_irq(prio_to_virq[prio]);
  57. irq_exit();
  58. set_irq_regs(old_regs);
  59. }
  60. static struct irq_domain *core_domain;
  61. static int core_domain_map(struct irq_domain *h, unsigned int virq,
  62. irq_hw_number_t hw)
  63. {
  64. if (hw < 4 || hw >= NR_PRIORITY_IRQS)
  65. return -EINVAL;
  66. prio_to_virq[hw] = virq;
  67. irq_set_status_flags(virq, IRQ_LEVEL);
  68. irq_set_chip_and_handler(virq, &core_chip, handle_level_irq);
  69. return 0;
  70. }
  71. static const struct irq_domain_ops core_domain_ops = {
  72. .map = core_domain_map,
  73. .xlate = irq_domain_xlate_onecell,
  74. };
  75. void __init init_IRQ(void)
  76. {
  77. struct device_node *np;
  78. /* Mask all priority IRQs */
  79. and_creg(IER, ~0xfff0);
  80. np = of_find_compatible_node(NULL, NULL, "ti,c64x+core-pic");
  81. if (np != NULL) {
  82. /* create the core host */
  83. core_domain = irq_domain_add_linear(np, NR_PRIORITY_IRQS,
  84. &core_domain_ops, NULL);
  85. if (core_domain)
  86. irq_set_default_host(core_domain);
  87. of_node_put(np);
  88. }
  89. printk(KERN_INFO "Core interrupt controller initialized\n");
  90. /* now we're ready for other SoC controllers */
  91. megamod_pic_init();
  92. /* Clear all general IRQ flags */
  93. set_creg(ICR, 0xfff0);
  94. }
  95. void ack_bad_irq(int irq)
  96. {
  97. printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
  98. irq_err_count++;
  99. }
  100. int arch_show_interrupts(struct seq_file *p, int prec)
  101. {
  102. seq_printf(p, "%*s: %10lu\n", prec, "Err", irq_err_count);
  103. return 0;
  104. }