irq-moxart.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * MOXA ART SoCs IRQ chip driver.
  3. *
  4. * Copyright (C) 2013 Jonas Jensen
  5. *
  6. * Jonas Jensen <jonas.jensen@gmail.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/io.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqchip.h>
  15. #include <linux/of.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/irqdomain.h>
  19. #include <asm/exception.h>
  20. #define IRQ_SOURCE_REG 0
  21. #define IRQ_MASK_REG 0x04
  22. #define IRQ_CLEAR_REG 0x08
  23. #define IRQ_MODE_REG 0x0c
  24. #define IRQ_LEVEL_REG 0x10
  25. #define IRQ_STATUS_REG 0x14
  26. #define FIQ_SOURCE_REG 0x20
  27. #define FIQ_MASK_REG 0x24
  28. #define FIQ_CLEAR_REG 0x28
  29. #define FIQ_MODE_REG 0x2c
  30. #define FIQ_LEVEL_REG 0x30
  31. #define FIQ_STATUS_REG 0x34
  32. struct moxart_irq_data {
  33. void __iomem *base;
  34. struct irq_domain *domain;
  35. unsigned int interrupt_mask;
  36. };
  37. static struct moxart_irq_data intc;
  38. static void __exception_irq_entry handle_irq(struct pt_regs *regs)
  39. {
  40. u32 irqstat;
  41. int hwirq;
  42. irqstat = readl(intc.base + IRQ_STATUS_REG);
  43. while (irqstat) {
  44. hwirq = ffs(irqstat) - 1;
  45. handle_IRQ(irq_linear_revmap(intc.domain, hwirq), regs);
  46. irqstat &= ~(1 << hwirq);
  47. }
  48. }
  49. static int __init moxart_of_intc_init(struct device_node *node,
  50. struct device_node *parent)
  51. {
  52. unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
  53. int ret;
  54. struct irq_chip_generic *gc;
  55. intc.base = of_iomap(node, 0);
  56. if (!intc.base) {
  57. pr_err("%s: unable to map IC registers\n",
  58. node->full_name);
  59. return -EINVAL;
  60. }
  61. intc.domain = irq_domain_add_linear(node, 32, &irq_generic_chip_ops,
  62. intc.base);
  63. if (!intc.domain) {
  64. pr_err("%s: unable to create IRQ domain\n", node->full_name);
  65. return -EINVAL;
  66. }
  67. ret = irq_alloc_domain_generic_chips(intc.domain, 32, 1,
  68. "MOXARTINTC", handle_edge_irq,
  69. clr, 0, IRQ_GC_INIT_MASK_CACHE);
  70. if (ret) {
  71. pr_err("%s: could not allocate generic chip\n",
  72. node->full_name);
  73. irq_domain_remove(intc.domain);
  74. return -EINVAL;
  75. }
  76. ret = of_property_read_u32(node, "interrupt-mask",
  77. &intc.interrupt_mask);
  78. if (ret)
  79. pr_err("%s: could not read interrupt-mask DT property\n",
  80. node->full_name);
  81. gc = irq_get_domain_generic_chip(intc.domain, 0);
  82. gc->reg_base = intc.base;
  83. gc->chip_types[0].regs.mask = IRQ_MASK_REG;
  84. gc->chip_types[0].regs.ack = IRQ_CLEAR_REG;
  85. gc->chip_types[0].chip.irq_ack = irq_gc_ack_set_bit;
  86. gc->chip_types[0].chip.irq_mask = irq_gc_mask_clr_bit;
  87. gc->chip_types[0].chip.irq_unmask = irq_gc_mask_set_bit;
  88. writel(0, intc.base + IRQ_MASK_REG);
  89. writel(0xffffffff, intc.base + IRQ_CLEAR_REG);
  90. writel(intc.interrupt_mask, intc.base + IRQ_MODE_REG);
  91. writel(intc.interrupt_mask, intc.base + IRQ_LEVEL_REG);
  92. set_handle_irq(handle_irq);
  93. return 0;
  94. }
  95. IRQCHIP_DECLARE(moxa_moxart_ic, "moxa,moxart-ic", moxart_of_intc_init);