1
0

0007-irqchip-irq-ath79-intc-add-irq-cascade-driver-for-QC.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. From f3eacff2310a60348a755c50a8da6fc251fc8587 Mon Sep 17 00:00:00 2001
  2. From: John Crispin <john@phrozen.org>
  3. Date: Tue, 6 Mar 2018 09:55:13 +0100
  4. Subject: [PATCH 07/33] irqchip/irq-ath79-intc: add irq cascade driver for
  5. QCA9556 SoCs
  6. Signed-off-by: John Crispin <john@phrozen.org>
  7. ---
  8. drivers/irqchip/Makefile | 1 +
  9. drivers/irqchip/irq-ath79-intc.c | 142 +++++++++++++++++++++++++++++++++++++++
  10. 2 files changed, 143 insertions(+)
  11. create mode 100644 drivers/irqchip/irq-ath79-intc.c
  12. --- a/drivers/irqchip/Makefile
  13. +++ b/drivers/irqchip/Makefile
  14. @@ -3,6 +3,7 @@ obj-$(CONFIG_IRQCHIP) += irqchip.o
  15. obj-$(CONFIG_ALPINE_MSI) += irq-alpine-msi.o
  16. obj-$(CONFIG_ATH79) += irq-ath79-cpu.o
  17. +obj-$(CONFIG_ATH79) += irq-ath79-intc.o
  18. obj-$(CONFIG_ATH79) += irq-ath79-misc.o
  19. obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2835.o
  20. obj-$(CONFIG_ARCH_BCM2835) += irq-bcm2836.o
  21. --- /dev/null
  22. +++ b/drivers/irqchip/irq-ath79-intc.c
  23. @@ -0,0 +1,142 @@
  24. +/*
  25. + * Atheros AR71xx/AR724x/AR913x specific interrupt handling
  26. + *
  27. + * Copyright (C) 2018 John Crispin <john@phrozen.org>
  28. + *
  29. + * This program is free software; you can redistribute it and/or modify it
  30. + * under the terms of the GNU General Public License version 2 as published
  31. + * by the Free Software Foundation.
  32. + */
  33. +
  34. +#include <linux/interrupt.h>
  35. +#include <linux/irqchip.h>
  36. +#include <linux/of.h>
  37. +#include <linux/of_irq.h>
  38. +#include <linux/irqdomain.h>
  39. +
  40. +#include <asm/irq_cpu.h>
  41. +#include <asm/mach-ath79/ath79.h>
  42. +#include <asm/mach-ath79/ar71xx_regs.h>
  43. +
  44. +#define ATH79_MAX_INTC_CASCADE 3
  45. +
  46. +struct ath79_intc {
  47. + struct irq_chip chip;
  48. + u32 irq;
  49. + u32 pending_mask;
  50. + u32 int_status;
  51. + u32 irq_mask[ATH79_MAX_INTC_CASCADE];
  52. + u32 irq_wb_chan[ATH79_MAX_INTC_CASCADE];
  53. +};
  54. +
  55. +static void ath79_intc_irq_handler(struct irq_desc *desc)
  56. +{
  57. + struct irq_domain *domain = irq_desc_get_handler_data(desc);
  58. + struct ath79_intc *intc = domain->host_data;
  59. + u32 pending;
  60. +
  61. + pending = ath79_reset_rr(intc->int_status);
  62. + pending &= intc->pending_mask;
  63. +
  64. + if (pending) {
  65. + int i;
  66. +
  67. + for (i = 0; i < domain->hwirq_max; i++)
  68. + if (pending & intc->irq_mask[i]) {
  69. + if (intc->irq_wb_chan[i] != 0xffffffff)
  70. + ath79_ddr_wb_flush(intc->irq_wb_chan[i]);
  71. + generic_handle_irq(irq_find_mapping(domain, i));
  72. + }
  73. + } else {
  74. + spurious_interrupt();
  75. + }
  76. +}
  77. +
  78. +static void ath79_intc_irq_enable(struct irq_data *d)
  79. +{
  80. + struct ath79_intc *intc = d->domain->host_data;
  81. + enable_irq(intc->irq);
  82. +}
  83. +
  84. +static void ath79_intc_irq_disable(struct irq_data *d)
  85. +{
  86. + struct ath79_intc *intc = d->domain->host_data;
  87. + disable_irq(intc->irq);
  88. +}
  89. +
  90. +static int ath79_intc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  91. +{
  92. + struct ath79_intc *intc = d->host_data;
  93. +
  94. + irq_set_chip_and_handler(irq, &intc->chip, handle_level_irq);
  95. +
  96. + return 0;
  97. +}
  98. +
  99. +static const struct irq_domain_ops ath79_irq_domain_ops = {
  100. + .xlate = irq_domain_xlate_onecell,
  101. + .map = ath79_intc_map,
  102. +};
  103. +
  104. +static int __init ath79_intc_of_init(
  105. + struct device_node *node, struct device_node *parent)
  106. +{
  107. + struct irq_domain *domain;
  108. + struct ath79_intc *intc;
  109. + int cnt, cntwb, i, err;
  110. +
  111. + cnt = of_property_count_u32_elems(node, "qca,pending-bits");
  112. + if (cnt > ATH79_MAX_INTC_CASCADE)
  113. + panic("Too many INTC pending bits\n");
  114. +
  115. + intc = kzalloc(sizeof(*intc), GFP_KERNEL);
  116. + if (!intc)
  117. + panic("Failed to allocate INTC memory\n");
  118. + intc->chip = dummy_irq_chip;
  119. + intc->chip.name = "INTC";
  120. + intc->chip.irq_disable = ath79_intc_irq_disable;
  121. + intc->chip.irq_enable = ath79_intc_irq_enable;
  122. +
  123. + if (of_property_read_u32(node, "qca,int-status-addr", &intc->int_status) < 0) {
  124. + panic("Missing address of interrupt status register\n");
  125. + }
  126. +
  127. + of_property_read_u32_array(node, "qca,pending-bits", intc->irq_mask, cnt);
  128. + for (i = 0; i < cnt; i++) {
  129. + intc->pending_mask |= intc->irq_mask[i];
  130. + intc->irq_wb_chan[i] = 0xffffffff;
  131. + }
  132. +
  133. + cntwb = of_count_phandle_with_args(
  134. + node, "qca,ddr-wb-channels", "#qca,ddr-wb-channel-cells");
  135. +
  136. + for (i = 0; i < cntwb; i++) {
  137. + struct of_phandle_args args;
  138. + u32 irq = i;
  139. +
  140. + of_property_read_u32_index(
  141. + node, "qca,ddr-wb-channel-interrupts", i, &irq);
  142. + if (irq >= ATH79_MAX_INTC_CASCADE)
  143. + continue;
  144. +
  145. + err = of_parse_phandle_with_args(
  146. + node, "qca,ddr-wb-channels",
  147. + "#qca,ddr-wb-channel-cells",
  148. + i, &args);
  149. + if (err)
  150. + return err;
  151. +
  152. + intc->irq_wb_chan[irq] = args.args[0];
  153. + }
  154. +
  155. + intc->irq = irq_of_parse_and_map(node, 0);
  156. + if (!intc->irq)
  157. + panic("Failed to get INTC IRQ");
  158. +
  159. + domain = irq_domain_add_linear(node, cnt, &ath79_irq_domain_ops, intc);
  160. + irq_set_chained_handler_and_data(intc->irq, ath79_intc_irq_handler, domain);
  161. +
  162. + return 0;
  163. +}
  164. +IRQCHIP_DECLARE(ath79_intc, "qca,ar9340-intc",
  165. + ath79_intc_of_init);