irq-mxs.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Copyright (C) 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright (C) 2014 Oleksij Rempel <linux@rempel-privat.de>
  4. * Add Alphascale ASM9260 support.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/irq.h>
  23. #include <linux/irqchip.h>
  24. #include <linux/irqdomain.h>
  25. #include <linux/io.h>
  26. #include <linux/of.h>
  27. #include <linux/of_address.h>
  28. #include <linux/of_irq.h>
  29. #include <linux/stmp_device.h>
  30. #include <asm/exception.h>
  31. #include "alphascale_asm9260-icoll.h"
  32. /*
  33. * this device provide 4 offsets for each register:
  34. * 0x0 - plain read write mode
  35. * 0x4 - set mode, OR logic.
  36. * 0x8 - clr mode, XOR logic.
  37. * 0xc - togle mode.
  38. */
  39. #define SET_REG 4
  40. #define CLR_REG 8
  41. #define HW_ICOLL_VECTOR 0x0000
  42. #define HW_ICOLL_LEVELACK 0x0010
  43. #define HW_ICOLL_CTRL 0x0020
  44. #define HW_ICOLL_STAT_OFFSET 0x0070
  45. #define HW_ICOLL_INTERRUPT0 0x0120
  46. #define HW_ICOLL_INTERRUPTn(n) ((n) * 0x10)
  47. #define BM_ICOLL_INTR_ENABLE BIT(2)
  48. #define BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 0x1
  49. #define ICOLL_NUM_IRQS 128
  50. enum icoll_type {
  51. ICOLL,
  52. ASM9260_ICOLL,
  53. };
  54. struct icoll_priv {
  55. void __iomem *vector;
  56. void __iomem *levelack;
  57. void __iomem *ctrl;
  58. void __iomem *stat;
  59. void __iomem *intr;
  60. void __iomem *clear;
  61. enum icoll_type type;
  62. };
  63. static struct icoll_priv icoll_priv;
  64. static struct irq_domain *icoll_domain;
  65. /* calculate bit offset depending on number of intterupt per register */
  66. static u32 icoll_intr_bitshift(struct irq_data *d, u32 bit)
  67. {
  68. /*
  69. * mask lower part of hwirq to convert it
  70. * in 0, 1, 2 or 3 and then multiply it by 8 (or shift by 3)
  71. */
  72. return bit << ((d->hwirq & 3) << 3);
  73. }
  74. /* calculate mem offset depending on number of intterupt per register */
  75. static void __iomem *icoll_intr_reg(struct irq_data *d)
  76. {
  77. /* offset = hwirq / intr_per_reg * 0x10 */
  78. return icoll_priv.intr + ((d->hwirq >> 2) * 0x10);
  79. }
  80. static void icoll_ack_irq(struct irq_data *d)
  81. {
  82. /*
  83. * The Interrupt Collector is able to prioritize irqs.
  84. * Currently only level 0 is used. So acking can use
  85. * BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0 unconditionally.
  86. */
  87. __raw_writel(BV_ICOLL_LEVELACK_IRQLEVELACK__LEVEL0,
  88. icoll_priv.levelack);
  89. }
  90. static void icoll_mask_irq(struct irq_data *d)
  91. {
  92. __raw_writel(BM_ICOLL_INTR_ENABLE,
  93. icoll_priv.intr + CLR_REG + HW_ICOLL_INTERRUPTn(d->hwirq));
  94. }
  95. static void icoll_unmask_irq(struct irq_data *d)
  96. {
  97. __raw_writel(BM_ICOLL_INTR_ENABLE,
  98. icoll_priv.intr + SET_REG + HW_ICOLL_INTERRUPTn(d->hwirq));
  99. }
  100. static void asm9260_mask_irq(struct irq_data *d)
  101. {
  102. __raw_writel(icoll_intr_bitshift(d, BM_ICOLL_INTR_ENABLE),
  103. icoll_intr_reg(d) + CLR_REG);
  104. }
  105. static void asm9260_unmask_irq(struct irq_data *d)
  106. {
  107. __raw_writel(ASM9260_BM_CLEAR_BIT(d->hwirq),
  108. icoll_priv.clear +
  109. ASM9260_HW_ICOLL_CLEARn(d->hwirq));
  110. __raw_writel(icoll_intr_bitshift(d, BM_ICOLL_INTR_ENABLE),
  111. icoll_intr_reg(d) + SET_REG);
  112. }
  113. static struct irq_chip mxs_icoll_chip = {
  114. .irq_ack = icoll_ack_irq,
  115. .irq_mask = icoll_mask_irq,
  116. .irq_unmask = icoll_unmask_irq,
  117. .flags = IRQCHIP_MASK_ON_SUSPEND |
  118. IRQCHIP_SKIP_SET_WAKE,
  119. };
  120. static struct irq_chip asm9260_icoll_chip = {
  121. .irq_ack = icoll_ack_irq,
  122. .irq_mask = asm9260_mask_irq,
  123. .irq_unmask = asm9260_unmask_irq,
  124. .flags = IRQCHIP_MASK_ON_SUSPEND |
  125. IRQCHIP_SKIP_SET_WAKE,
  126. };
  127. asmlinkage void __exception_irq_entry icoll_handle_irq(struct pt_regs *regs)
  128. {
  129. u32 irqnr;
  130. irqnr = __raw_readl(icoll_priv.stat);
  131. __raw_writel(irqnr, icoll_priv.vector);
  132. handle_domain_irq(icoll_domain, irqnr, regs);
  133. }
  134. static int icoll_irq_domain_map(struct irq_domain *d, unsigned int virq,
  135. irq_hw_number_t hw)
  136. {
  137. struct irq_chip *chip;
  138. if (icoll_priv.type == ICOLL)
  139. chip = &mxs_icoll_chip;
  140. else
  141. chip = &asm9260_icoll_chip;
  142. irq_set_chip_and_handler(virq, chip, handle_level_irq);
  143. return 0;
  144. }
  145. static const struct irq_domain_ops icoll_irq_domain_ops = {
  146. .map = icoll_irq_domain_map,
  147. .xlate = irq_domain_xlate_onecell,
  148. };
  149. static void __init icoll_add_domain(struct device_node *np,
  150. int num)
  151. {
  152. icoll_domain = irq_domain_add_linear(np, num,
  153. &icoll_irq_domain_ops, NULL);
  154. if (!icoll_domain)
  155. panic("%s: unable to create irq domain", np->full_name);
  156. }
  157. static void __iomem * __init icoll_init_iobase(struct device_node *np)
  158. {
  159. void __iomem *icoll_base;
  160. icoll_base = of_io_request_and_map(np, 0, np->name);
  161. if (IS_ERR(icoll_base))
  162. panic("%s: unable to map resource", np->full_name);
  163. return icoll_base;
  164. }
  165. static int __init icoll_of_init(struct device_node *np,
  166. struct device_node *interrupt_parent)
  167. {
  168. void __iomem *icoll_base;
  169. icoll_priv.type = ICOLL;
  170. icoll_base = icoll_init_iobase(np);
  171. icoll_priv.vector = icoll_base + HW_ICOLL_VECTOR;
  172. icoll_priv.levelack = icoll_base + HW_ICOLL_LEVELACK;
  173. icoll_priv.ctrl = icoll_base + HW_ICOLL_CTRL;
  174. icoll_priv.stat = icoll_base + HW_ICOLL_STAT_OFFSET;
  175. icoll_priv.intr = icoll_base + HW_ICOLL_INTERRUPT0;
  176. icoll_priv.clear = NULL;
  177. /*
  178. * Interrupt Collector reset, which initializes the priority
  179. * for each irq to level 0.
  180. */
  181. stmp_reset_block(icoll_priv.ctrl);
  182. icoll_add_domain(np, ICOLL_NUM_IRQS);
  183. return 0;
  184. }
  185. IRQCHIP_DECLARE(mxs, "fsl,icoll", icoll_of_init);
  186. static int __init asm9260_of_init(struct device_node *np,
  187. struct device_node *interrupt_parent)
  188. {
  189. void __iomem *icoll_base;
  190. int i;
  191. icoll_priv.type = ASM9260_ICOLL;
  192. icoll_base = icoll_init_iobase(np);
  193. icoll_priv.vector = icoll_base + ASM9260_HW_ICOLL_VECTOR;
  194. icoll_priv.levelack = icoll_base + ASM9260_HW_ICOLL_LEVELACK;
  195. icoll_priv.ctrl = icoll_base + ASM9260_HW_ICOLL_CTRL;
  196. icoll_priv.stat = icoll_base + ASM9260_HW_ICOLL_STAT_OFFSET;
  197. icoll_priv.intr = icoll_base + ASM9260_HW_ICOLL_INTERRUPT0;
  198. icoll_priv.clear = icoll_base + ASM9260_HW_ICOLL_CLEAR0;
  199. writel_relaxed(ASM9260_BM_CTRL_IRQ_ENABLE,
  200. icoll_priv.ctrl);
  201. /*
  202. * ASM9260 don't provide reset bit. So, we need to set level 0
  203. * manually.
  204. */
  205. for (i = 0; i < 16 * 0x10; i += 0x10)
  206. writel(0, icoll_priv.intr + i);
  207. icoll_add_domain(np, ASM9260_NUM_IRQS);
  208. set_handle_irq(icoll_handle_irq);
  209. return 0;
  210. }
  211. IRQCHIP_DECLARE(asm9260, "alphascale,asm9260-icoll", asm9260_of_init);