irq-xtensa-mx.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Xtensa MX interrupt distributor
  3. *
  4. * Copyright (C) 2002 - 2013 Tensilica, 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/interrupt.h>
  11. #include <linux/irqdomain.h>
  12. #include <linux/irq.h>
  13. #include <linux/irqchip.h>
  14. #include <linux/of.h>
  15. #include <asm/mxregs.h>
  16. #define HW_IRQ_IPI_COUNT 2
  17. #define HW_IRQ_MX_BASE 2
  18. #define HW_IRQ_EXTERN_BASE 3
  19. static DEFINE_PER_CPU(unsigned int, cached_irq_mask);
  20. static int xtensa_mx_irq_map(struct irq_domain *d, unsigned int irq,
  21. irq_hw_number_t hw)
  22. {
  23. if (hw < HW_IRQ_IPI_COUNT) {
  24. struct irq_chip *irq_chip = d->host_data;
  25. irq_set_chip_and_handler_name(irq, irq_chip,
  26. handle_percpu_irq, "ipi");
  27. irq_set_status_flags(irq, IRQ_LEVEL);
  28. return 0;
  29. }
  30. return xtensa_irq_map(d, irq, hw);
  31. }
  32. /*
  33. * Device Tree IRQ specifier translation function which works with one or
  34. * two cell bindings. First cell value maps directly to the hwirq number.
  35. * Second cell if present specifies whether hwirq number is external (1) or
  36. * internal (0).
  37. */
  38. static int xtensa_mx_irq_domain_xlate(struct irq_domain *d,
  39. struct device_node *ctrlr,
  40. const u32 *intspec, unsigned int intsize,
  41. unsigned long *out_hwirq, unsigned int *out_type)
  42. {
  43. return xtensa_irq_domain_xlate(intspec, intsize,
  44. intspec[0], intspec[0] + HW_IRQ_EXTERN_BASE,
  45. out_hwirq, out_type);
  46. }
  47. static const struct irq_domain_ops xtensa_mx_irq_domain_ops = {
  48. .xlate = xtensa_mx_irq_domain_xlate,
  49. .map = xtensa_mx_irq_map,
  50. };
  51. void secondary_init_irq(void)
  52. {
  53. __this_cpu_write(cached_irq_mask,
  54. XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  55. XCHAL_INTTYPE_MASK_EXTERN_LEVEL);
  56. set_sr(XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  57. XCHAL_INTTYPE_MASK_EXTERN_LEVEL, intenable);
  58. }
  59. static void xtensa_mx_irq_mask(struct irq_data *d)
  60. {
  61. unsigned int mask = 1u << d->hwirq;
  62. if (mask & (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  63. XCHAL_INTTYPE_MASK_EXTERN_LEVEL)) {
  64. set_er(1u << (xtensa_get_ext_irq_no(d->hwirq) -
  65. HW_IRQ_MX_BASE), MIENG);
  66. } else {
  67. mask = __this_cpu_read(cached_irq_mask) & ~mask;
  68. __this_cpu_write(cached_irq_mask, mask);
  69. set_sr(mask, intenable);
  70. }
  71. }
  72. static void xtensa_mx_irq_unmask(struct irq_data *d)
  73. {
  74. unsigned int mask = 1u << d->hwirq;
  75. if (mask & (XCHAL_INTTYPE_MASK_EXTERN_EDGE |
  76. XCHAL_INTTYPE_MASK_EXTERN_LEVEL)) {
  77. set_er(1u << (xtensa_get_ext_irq_no(d->hwirq) -
  78. HW_IRQ_MX_BASE), MIENGSET);
  79. } else {
  80. mask |= __this_cpu_read(cached_irq_mask);
  81. __this_cpu_write(cached_irq_mask, mask);
  82. set_sr(mask, intenable);
  83. }
  84. }
  85. static void xtensa_mx_irq_enable(struct irq_data *d)
  86. {
  87. variant_irq_enable(d->hwirq);
  88. xtensa_mx_irq_unmask(d);
  89. }
  90. static void xtensa_mx_irq_disable(struct irq_data *d)
  91. {
  92. xtensa_mx_irq_mask(d);
  93. variant_irq_disable(d->hwirq);
  94. }
  95. static void xtensa_mx_irq_ack(struct irq_data *d)
  96. {
  97. set_sr(1 << d->hwirq, intclear);
  98. }
  99. static int xtensa_mx_irq_retrigger(struct irq_data *d)
  100. {
  101. set_sr(1 << d->hwirq, intset);
  102. return 1;
  103. }
  104. static int xtensa_mx_irq_set_affinity(struct irq_data *d,
  105. const struct cpumask *dest, bool force)
  106. {
  107. unsigned mask = 1u << cpumask_any_and(dest, cpu_online_mask);
  108. set_er(mask, MIROUT(d->hwirq - HW_IRQ_MX_BASE));
  109. return 0;
  110. }
  111. static struct irq_chip xtensa_mx_irq_chip = {
  112. .name = "xtensa-mx",
  113. .irq_enable = xtensa_mx_irq_enable,
  114. .irq_disable = xtensa_mx_irq_disable,
  115. .irq_mask = xtensa_mx_irq_mask,
  116. .irq_unmask = xtensa_mx_irq_unmask,
  117. .irq_ack = xtensa_mx_irq_ack,
  118. .irq_retrigger = xtensa_mx_irq_retrigger,
  119. .irq_set_affinity = xtensa_mx_irq_set_affinity,
  120. };
  121. int __init xtensa_mx_init_legacy(struct device_node *interrupt_parent)
  122. {
  123. struct irq_domain *root_domain =
  124. irq_domain_add_legacy(NULL, NR_IRQS - 1, 1, 0,
  125. &xtensa_mx_irq_domain_ops,
  126. &xtensa_mx_irq_chip);
  127. irq_set_default_host(root_domain);
  128. secondary_init_irq();
  129. return 0;
  130. }
  131. static int __init xtensa_mx_init(struct device_node *np,
  132. struct device_node *interrupt_parent)
  133. {
  134. struct irq_domain *root_domain =
  135. irq_domain_add_linear(np, NR_IRQS, &xtensa_mx_irq_domain_ops,
  136. &xtensa_mx_irq_chip);
  137. irq_set_default_host(root_domain);
  138. secondary_init_irq();
  139. return 0;
  140. }
  141. IRQCHIP_DECLARE(xtensa_mx_irq_chip, "cdns,xtensa-mx", xtensa_mx_init);