irq-nvic.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * drivers/irq/irq-nvic.c
  3. *
  4. * Copyright (C) 2008 ARM Limited, All Rights Reserved.
  5. * Copyright (C) 2013 Pengutronix
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Support for the Nested Vectored Interrupt Controller found on the
  12. * ARMv7-M CPUs (Cortex-M3/M4)
  13. */
  14. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15. #include <linux/init.h>
  16. #include <linux/kernel.h>
  17. #include <linux/slab.h>
  18. #include <linux/err.h>
  19. #include <linux/io.h>
  20. #include <linux/of.h>
  21. #include <linux/of_address.h>
  22. #include <linux/irq.h>
  23. #include <linux/irqdomain.h>
  24. #include <asm/v7m.h>
  25. #include <asm/exception.h>
  26. #include "irqchip.h"
  27. #define NVIC_ISER 0x000
  28. #define NVIC_ICER 0x080
  29. #define NVIC_IPR 0x300
  30. #define NVIC_MAX_BANKS 16
  31. /*
  32. * Each bank handles 32 irqs. Only the 16th (= last) bank handles only
  33. * 16 irqs.
  34. */
  35. #define NVIC_MAX_IRQ ((NVIC_MAX_BANKS - 1) * 32 + 16)
  36. static struct irq_domain *nvic_irq_domain;
  37. asmlinkage void __exception_irq_entry
  38. nvic_handle_irq(irq_hw_number_t hwirq, struct pt_regs *regs)
  39. {
  40. unsigned int irq = irq_linear_revmap(nvic_irq_domain, hwirq);
  41. handle_IRQ(irq, regs);
  42. }
  43. static void nvic_eoi(struct irq_data *d)
  44. {
  45. /*
  46. * This is a no-op as end of interrupt is signaled by the exception
  47. * return sequence.
  48. */
  49. }
  50. static int __init nvic_of_init(struct device_node *node,
  51. struct device_node *parent)
  52. {
  53. unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
  54. unsigned int irqs, i, ret, numbanks;
  55. void __iomem *nvic_base;
  56. numbanks = (readl_relaxed(V7M_SCS_ICTR) &
  57. V7M_SCS_ICTR_INTLINESNUM_MASK) + 1;
  58. nvic_base = of_iomap(node, 0);
  59. if (!nvic_base) {
  60. pr_warn("unable to map nvic registers\n");
  61. return -ENOMEM;
  62. }
  63. irqs = numbanks * 32;
  64. if (irqs > NVIC_MAX_IRQ)
  65. irqs = NVIC_MAX_IRQ;
  66. nvic_irq_domain =
  67. irq_domain_add_linear(node, irqs, &irq_generic_chip_ops, NULL);
  68. if (!nvic_irq_domain) {
  69. pr_warn("Failed to allocate irq domain\n");
  70. return -ENOMEM;
  71. }
  72. ret = irq_alloc_domain_generic_chips(nvic_irq_domain, 32, 1,
  73. "nvic_irq", handle_fasteoi_irq,
  74. clr, 0, IRQ_GC_INIT_MASK_CACHE);
  75. if (ret) {
  76. pr_warn("Failed to allocate irq chips\n");
  77. irq_domain_remove(nvic_irq_domain);
  78. return ret;
  79. }
  80. for (i = 0; i < numbanks; ++i) {
  81. struct irq_chip_generic *gc;
  82. gc = irq_get_domain_generic_chip(nvic_irq_domain, 32 * i);
  83. gc->reg_base = nvic_base + 4 * i;
  84. gc->chip_types[0].regs.enable = NVIC_ISER;
  85. gc->chip_types[0].regs.disable = NVIC_ICER;
  86. gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg;
  87. gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg;
  88. gc->chip_types[0].chip.irq_eoi = nvic_eoi;
  89. /* disable interrupts */
  90. writel_relaxed(~0, gc->reg_base + NVIC_ICER);
  91. }
  92. /* Set priority on all interrupts */
  93. for (i = 0; i < irqs; i += 4)
  94. writel_relaxed(0, nvic_base + NVIC_IPR + i);
  95. return 0;
  96. }
  97. IRQCHIP_DECLARE(armv7m_nvic, "arm,armv7m-nvic", nvic_of_init);