irq-zevio.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * linux/drivers/irqchip/irq-zevio.c
  3. *
  4. * Copyright (C) 2013 Daniel Tang <tangrs@tangrs.id.au>
  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 version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. */
  11. #include <linux/io.h>
  12. #include <linux/irq.h>
  13. #include <linux/irqchip.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_irq.h>
  17. #include <asm/mach/irq.h>
  18. #include <asm/exception.h>
  19. #define IO_STATUS 0x000
  20. #define IO_RAW_STATUS 0x004
  21. #define IO_ENABLE 0x008
  22. #define IO_DISABLE 0x00C
  23. #define IO_CURRENT 0x020
  24. #define IO_RESET 0x028
  25. #define IO_MAX_PRIOTY 0x02C
  26. #define IO_IRQ_BASE 0x000
  27. #define IO_FIQ_BASE 0x100
  28. #define IO_INVERT_SEL 0x200
  29. #define IO_STICKY_SEL 0x204
  30. #define IO_PRIORITY_SEL 0x300
  31. #define MAX_INTRS 32
  32. #define FIQ_START MAX_INTRS
  33. static struct irq_domain *zevio_irq_domain;
  34. static void __iomem *zevio_irq_io;
  35. static void zevio_irq_ack(struct irq_data *irqd)
  36. {
  37. struct irq_chip_generic *gc = irq_data_get_irq_chip_data(irqd);
  38. struct irq_chip_regs *regs = &irq_data_get_chip_type(irqd)->regs;
  39. readl(gc->reg_base + regs->ack);
  40. }
  41. static void __exception_irq_entry zevio_handle_irq(struct pt_regs *regs)
  42. {
  43. int irqnr;
  44. while (readl(zevio_irq_io + IO_STATUS)) {
  45. irqnr = readl(zevio_irq_io + IO_CURRENT);
  46. handle_domain_irq(zevio_irq_domain, irqnr, regs);
  47. };
  48. }
  49. static void __init zevio_init_irq_base(void __iomem *base)
  50. {
  51. /* Disable all interrupts */
  52. writel(~0, base + IO_DISABLE);
  53. /* Accept interrupts of all priorities */
  54. writel(0xF, base + IO_MAX_PRIOTY);
  55. /* Reset existing interrupts */
  56. readl(base + IO_RESET);
  57. }
  58. static int __init zevio_of_init(struct device_node *node,
  59. struct device_node *parent)
  60. {
  61. unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
  62. struct irq_chip_generic *gc;
  63. int ret;
  64. if (WARN_ON(zevio_irq_io || zevio_irq_domain))
  65. return -EBUSY;
  66. zevio_irq_io = of_iomap(node, 0);
  67. BUG_ON(!zevio_irq_io);
  68. /* Do not invert interrupt status bits */
  69. writel(~0, zevio_irq_io + IO_INVERT_SEL);
  70. /* Disable sticky interrupts */
  71. writel(0, zevio_irq_io + IO_STICKY_SEL);
  72. /* We don't use IRQ priorities. Set each IRQ to highest priority. */
  73. memset_io(zevio_irq_io + IO_PRIORITY_SEL, 0, MAX_INTRS * sizeof(u32));
  74. /* Init IRQ and FIQ */
  75. zevio_init_irq_base(zevio_irq_io + IO_IRQ_BASE);
  76. zevio_init_irq_base(zevio_irq_io + IO_FIQ_BASE);
  77. zevio_irq_domain = irq_domain_add_linear(node, MAX_INTRS,
  78. &irq_generic_chip_ops, NULL);
  79. BUG_ON(!zevio_irq_domain);
  80. ret = irq_alloc_domain_generic_chips(zevio_irq_domain, MAX_INTRS, 1,
  81. "zevio_intc", handle_level_irq,
  82. clr, 0, IRQ_GC_INIT_MASK_CACHE);
  83. BUG_ON(ret);
  84. gc = irq_get_domain_generic_chip(zevio_irq_domain, 0);
  85. gc->reg_base = zevio_irq_io;
  86. gc->chip_types[0].chip.irq_ack = zevio_irq_ack;
  87. gc->chip_types[0].chip.irq_mask = irq_gc_mask_disable_reg;
  88. gc->chip_types[0].chip.irq_unmask = irq_gc_unmask_enable_reg;
  89. gc->chip_types[0].regs.mask = IO_IRQ_BASE + IO_ENABLE;
  90. gc->chip_types[0].regs.enable = IO_IRQ_BASE + IO_ENABLE;
  91. gc->chip_types[0].regs.disable = IO_IRQ_BASE + IO_DISABLE;
  92. gc->chip_types[0].regs.ack = IO_IRQ_BASE + IO_RESET;
  93. set_handle_irq(zevio_handle_irq);
  94. pr_info("TI-NSPIRE classic IRQ controller\n");
  95. return 0;
  96. }
  97. IRQCHIP_DECLARE(zevio_irq, "lsi,zevio-intc", zevio_of_init);