irq.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Moschip MCS814x generic interrupt controller routines
  3. *
  4. * Copyright (C) 2012, Florian Fainelli <florian@openwrt.org>
  5. *
  6. * Licensed under the GPLv2
  7. */
  8. #include <linux/init.h>
  9. #include <linux/irq.h>
  10. #include <linux/io.h>
  11. #include <linux/of.h>
  12. #include <linux/of_address.h>
  13. #include <linux/irqdomain.h>
  14. #include <asm/exception.h>
  15. #include <asm/mach/irq.h>
  16. #include <mach/mcs814x.h>
  17. static void __iomem *mcs814x_intc_base;
  18. static struct irq_domain *domain;
  19. static void __init mcs814x_alloc_gc(void __iomem *base, unsigned int irq_start,
  20. unsigned int num)
  21. {
  22. struct irq_chip_generic *gc;
  23. struct irq_chip_type *ct;
  24. if (irq_alloc_domain_generic_chips(domain, num, 1, "mcs814x-intc", handle_level_irq,
  25. IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, 0))
  26. panic("unable to allocate domain generic irq chip");
  27. gc = irq_get_domain_generic_chip(domain, irq_start);
  28. if (!gc)
  29. panic("unable to get generic irq chip");
  30. gc->reg_base = base;
  31. ct = gc->chip_types;
  32. ct->chip.irq_ack = irq_gc_unmask_enable_reg;
  33. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  34. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  35. ct->regs.mask = MCS814X_IRQ_MASK;
  36. ct->regs.enable = MCS814X_IRQ_ICR;
  37. /* Clear all interrupts */
  38. writel_relaxed(0xffffffff, base + MCS814X_IRQ_ICR);
  39. }
  40. asmlinkage void __exception_irq_entry mcs814x_handle_irq(struct pt_regs *regs)
  41. {
  42. u32 status, irq;
  43. do {
  44. /* read the status register */
  45. status = __raw_readl(mcs814x_intc_base + MCS814X_IRQ_STS0);
  46. if (!status)
  47. break;
  48. irq = ffs(status) - 1;
  49. status |= (1 << irq);
  50. /* clear the interrupt */
  51. __raw_writel(status, mcs814x_intc_base + MCS814X_IRQ_STS0);
  52. /* call the generic handler */
  53. handle_domain_irq(domain, irq, regs);
  54. } while (1);
  55. }
  56. static const struct of_device_id mcs814x_intc_ids[] = {
  57. { .compatible = "moschip,mcs814x-intc" },
  58. { /* sentinel */ },
  59. };
  60. void __init mcs814x_of_irq_init(void)
  61. {
  62. struct device_node *np;
  63. np = of_find_matching_node(NULL, mcs814x_intc_ids);
  64. if (!np)
  65. panic("unable to find compatible intc node in dtb\n");
  66. mcs814x_intc_base = of_iomap(np, 0);
  67. if (!mcs814x_intc_base)
  68. panic("unable to map intc cpu registers\n");
  69. domain = irq_domain_add_linear(np, 32, &irq_generic_chip_ops, NULL);
  70. if (!domain)
  71. panic("unable to add irq domain\n");
  72. irq_set_default_host(domain);
  73. of_node_put(np);
  74. mcs814x_alloc_gc(mcs814x_intc_base, 0, 32);
  75. }