irq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Realtek RTL83XX architecture specific IRQ handling
  4. *
  5. * based on the original BSP
  6. * Copyright (C) 2006-2012 Tony Wu ([email protected])
  7. * Copyright (C) 2020 B. Koblitz
  8. * Copyright (C) 2020 Bert Vermeulen <[email protected]>
  9. * Copyright (C) 2020 John Crispin <[email protected]>
  10. */
  11. #include <linux/irqchip.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/of_address.h>
  14. #include <asm/irq_cpu.h>
  15. #include <linux/of_irq.h>
  16. #include <asm/cevt-r4k.h>
  17. #include <mach-rtl83xx.h>
  18. #include "irq.h"
  19. #define REALTEK_CPU_IRQ_SHARED0 (MIPS_CPU_IRQ_BASE + 2)
  20. #define REALTEK_CPU_IRQ_UART (MIPS_CPU_IRQ_BASE + 3)
  21. #define REALTEK_CPU_IRQ_SWITCH (MIPS_CPU_IRQ_BASE + 4)
  22. #define REALTEK_CPU_IRQ_SHARED1 (MIPS_CPU_IRQ_BASE + 5)
  23. #define REALTEK_CPU_IRQ_EXTERNAL (MIPS_CPU_IRQ_BASE + 6)
  24. #define REALTEK_CPU_IRQ_COUNTER (MIPS_CPU_IRQ_BASE + 7)
  25. #define REG(x) (rtl83xx_ictl_base + x)
  26. extern struct rtl83xx_soc_info soc_info;
  27. static DEFINE_RAW_SPINLOCK(irq_lock);
  28. static void __iomem *rtl83xx_ictl_base;
  29. static void rtl83xx_ictl_enable_irq(struct irq_data *i)
  30. {
  31. unsigned long flags;
  32. u32 value;
  33. raw_spin_lock_irqsave(&irq_lock, flags);
  34. value = rtl83xx_r32(REG(RTL83XX_ICTL_GIMR));
  35. value |= BIT(i->hwirq);
  36. rtl83xx_w32(value, REG(RTL83XX_ICTL_GIMR));
  37. raw_spin_unlock_irqrestore(&irq_lock, flags);
  38. }
  39. static void rtl83xx_ictl_disable_irq(struct irq_data *i)
  40. {
  41. unsigned long flags;
  42. u32 value;
  43. raw_spin_lock_irqsave(&irq_lock, flags);
  44. value = rtl83xx_r32(REG(RTL83XX_ICTL_GIMR));
  45. value &= ~BIT(i->hwirq);
  46. rtl83xx_w32(value, REG(RTL83XX_ICTL_GIMR));
  47. raw_spin_unlock_irqrestore(&irq_lock, flags);
  48. }
  49. static struct irq_chip rtl83xx_ictl_irq = {
  50. .name = "RTL83xx",
  51. .irq_enable = rtl83xx_ictl_enable_irq,
  52. .irq_disable = rtl83xx_ictl_disable_irq,
  53. .irq_ack = rtl83xx_ictl_disable_irq,
  54. .irq_mask = rtl83xx_ictl_disable_irq,
  55. .irq_unmask = rtl83xx_ictl_enable_irq,
  56. .irq_eoi = rtl83xx_ictl_enable_irq,
  57. };
  58. static int intc_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
  59. {
  60. irq_set_chip_and_handler(hw, &rtl83xx_ictl_irq, handle_level_irq);
  61. return 0;
  62. }
  63. static const struct irq_domain_ops irq_domain_ops = {
  64. .map = intc_map,
  65. .xlate = irq_domain_xlate_onecell,
  66. };
  67. static void rtl838x_irq_dispatch(struct irq_desc *desc)
  68. {
  69. unsigned int pending = rtl83xx_r32(REG(RTL83XX_ICTL_GIMR)) & rtl83xx_r32(REG(RTL83XX_ICTL_GISR));
  70. if (pending) {
  71. struct irq_domain *domain = irq_desc_get_handler_data(desc);
  72. generic_handle_irq(irq_find_mapping(domain, __ffs(pending)));
  73. } else {
  74. spurious_interrupt();
  75. }
  76. }
  77. asmlinkage void plat_irq_dispatch(void)
  78. {
  79. unsigned int pending;
  80. pending = read_c0_cause() & read_c0_status() & ST0_IM;
  81. if (pending & CAUSEF_IP7)
  82. do_IRQ(REALTEK_CPU_IRQ_COUNTER);
  83. else if (pending & CAUSEF_IP6)
  84. do_IRQ(REALTEK_CPU_IRQ_EXTERNAL);
  85. else if (pending & CAUSEF_IP5)
  86. do_IRQ(REALTEK_CPU_IRQ_SHARED1);
  87. else if (pending & CAUSEF_IP4)
  88. do_IRQ(REALTEK_CPU_IRQ_SWITCH);
  89. else if (pending & CAUSEF_IP3)
  90. do_IRQ(REALTEK_CPU_IRQ_UART);
  91. else if (pending & CAUSEF_IP2)
  92. do_IRQ(REALTEK_CPU_IRQ_SHARED0);
  93. else
  94. spurious_interrupt();
  95. }
  96. static void __init icu_of_init(struct device_node *node, struct device_node *parent)
  97. {
  98. struct irq_domain *domain;
  99. domain = irq_domain_add_simple(node, 32, 0,
  100. &irq_domain_ops, NULL);
  101. irq_set_chained_handler_and_data(2, rtl838x_irq_dispatch, domain);
  102. irq_set_chained_handler_and_data(5, rtl838x_irq_dispatch, domain);
  103. rtl83xx_ictl_base = of_iomap(node, 0);
  104. if (!rtl83xx_ictl_base)
  105. return;
  106. /* Disable all cascaded interrupts */
  107. rtl83xx_w32(0, REG(RTL83XX_ICTL_GIMR));
  108. /* Set up interrupt routing */
  109. rtl83xx_w32(RTL83XX_IRR0_SETTING, REG(RTL83XX_IRR0));
  110. rtl83xx_w32(RTL83XX_IRR1_SETTING, REG(RTL83XX_IRR1));
  111. rtl83xx_w32(RTL83XX_IRR2_SETTING, REG(RTL83XX_IRR2));
  112. rtl83xx_w32(RTL83XX_IRR3_SETTING, REG(RTL83XX_IRR3));
  113. /* Clear timer interrupt */
  114. write_c0_compare(0);
  115. /* Enable all CPU interrupts */
  116. write_c0_status(read_c0_status() | ST0_IM);
  117. /* Enable timer0 and uart0 interrupts */
  118. rtl83xx_w32(BIT(RTL83XX_IRQ_TC0) | BIT(RTL83XX_IRQ_UART0), REG(RTL83XX_ICTL_GIMR));
  119. }
  120. static struct of_device_id __initdata of_irq_ids[] = {
  121. { .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_irq_of_init },
  122. { .compatible = "realtek,rt8380-intc", .data = icu_of_init },
  123. {},
  124. };
  125. void __init arch_init_irq(void)
  126. {
  127. of_irq_init(of_irq_ids);
  128. }