irq-jcore-aic.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * J-Core SoC AIC driver
  3. *
  4. * Copyright (C) 2015-2016 Smart Energy Instruments, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/irq.h>
  11. #include <linux/io.h>
  12. #include <linux/irqchip.h>
  13. #include <linux/irqdomain.h>
  14. #include <linux/cpu.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_irq.h>
  18. #define JCORE_AIC_MAX_HWIRQ 127
  19. #define JCORE_AIC1_MIN_HWIRQ 16
  20. #define JCORE_AIC2_MIN_HWIRQ 64
  21. #define JCORE_AIC1_INTPRI_REG 8
  22. static struct irq_chip jcore_aic;
  23. /*
  24. * The J-Core AIC1 and AIC2 are cpu-local interrupt controllers and do
  25. * not distinguish or use distinct irq number ranges for per-cpu event
  26. * interrupts (timer, IPI). Since information to determine whether a
  27. * particular irq number should be treated as per-cpu is not available
  28. * at mapping time, we use a wrapper handler function which chooses
  29. * the right handler at runtime based on whether IRQF_PERCPU was used
  30. * when requesting the irq.
  31. */
  32. static void handle_jcore_irq(struct irq_desc *desc)
  33. {
  34. if (irqd_is_per_cpu(irq_desc_get_irq_data(desc)))
  35. handle_percpu_irq(desc);
  36. else
  37. handle_simple_irq(desc);
  38. }
  39. static int jcore_aic_irqdomain_map(struct irq_domain *d, unsigned int irq,
  40. irq_hw_number_t hwirq)
  41. {
  42. struct irq_chip *aic = d->host_data;
  43. irq_set_chip_and_handler(irq, aic, handle_jcore_irq);
  44. return 0;
  45. }
  46. static const struct irq_domain_ops jcore_aic_irqdomain_ops = {
  47. .map = jcore_aic_irqdomain_map,
  48. .xlate = irq_domain_xlate_onecell,
  49. };
  50. static void noop(struct irq_data *data)
  51. {
  52. }
  53. static int __init aic_irq_of_init(struct device_node *node,
  54. struct device_node *parent)
  55. {
  56. unsigned min_irq = JCORE_AIC2_MIN_HWIRQ;
  57. unsigned dom_sz = JCORE_AIC_MAX_HWIRQ+1;
  58. struct irq_domain *domain;
  59. int ret;
  60. pr_info("Initializing J-Core AIC\n");
  61. /* AIC1 needs priority initialization to receive interrupts. */
  62. if (of_device_is_compatible(node, "jcore,aic1")) {
  63. unsigned cpu;
  64. for_each_present_cpu(cpu) {
  65. void __iomem *base = of_iomap(node, cpu);
  66. if (!base) {
  67. pr_err("Unable to map AIC for cpu %u\n", cpu);
  68. return -ENOMEM;
  69. }
  70. __raw_writel(0xffffffff, base + JCORE_AIC1_INTPRI_REG);
  71. iounmap(base);
  72. }
  73. min_irq = JCORE_AIC1_MIN_HWIRQ;
  74. }
  75. /*
  76. * The irq chip framework requires either mask/unmask or enable/disable
  77. * function pointers to be provided, but the hardware does not have any
  78. * such mechanism; the only interrupt masking is at the cpu level and
  79. * it affects all interrupts. We provide dummy mask/unmask. The hardware
  80. * handles all interrupt control and clears pending status when the cpu
  81. * accepts the interrupt.
  82. */
  83. jcore_aic.irq_mask = noop;
  84. jcore_aic.irq_unmask = noop;
  85. jcore_aic.name = "AIC";
  86. ret = irq_alloc_descs(-1, min_irq, dom_sz - min_irq,
  87. of_node_to_nid(node));
  88. if (ret < 0)
  89. return ret;
  90. domain = irq_domain_add_legacy(node, dom_sz - min_irq, min_irq, min_irq,
  91. &jcore_aic_irqdomain_ops,
  92. &jcore_aic);
  93. if (!domain)
  94. return -ENOMEM;
  95. return 0;
  96. }
  97. IRQCHIP_DECLARE(jcore_aic2, "jcore,aic2", aic_irq_of_init);
  98. IRQCHIP_DECLARE(jcore_aic1, "jcore,aic1", aic_irq_of_init);