irq-sirfsoc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * interrupt controller support for CSR SiRFprimaII
  3. *
  4. * Copyright (c) 2011 Cambridge Silicon Radio Limited, a CSR plc group company.
  5. *
  6. * Licensed under GPLv2 or later.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <linux/irq.h>
  11. #include <linux/of.h>
  12. #include <linux/of_address.h>
  13. #include <linux/irqdomain.h>
  14. #include <linux/syscore_ops.h>
  15. #include <asm/mach/irq.h>
  16. #include <asm/exception.h>
  17. #include "irqchip.h"
  18. #define SIRFSOC_INT_RISC_MASK0 0x0018
  19. #define SIRFSOC_INT_RISC_MASK1 0x001C
  20. #define SIRFSOC_INT_RISC_LEVEL0 0x0020
  21. #define SIRFSOC_INT_RISC_LEVEL1 0x0024
  22. #define SIRFSOC_INIT_IRQ_ID 0x0038
  23. #define SIRFSOC_NUM_IRQS 64
  24. static struct irq_domain *sirfsoc_irqdomain;
  25. static __init void
  26. sirfsoc_alloc_gc(void __iomem *base, unsigned int irq_start, unsigned int num)
  27. {
  28. struct irq_chip_generic *gc;
  29. struct irq_chip_type *ct;
  30. int ret;
  31. unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
  32. unsigned int set = IRQ_LEVEL;
  33. ret = irq_alloc_domain_generic_chips(sirfsoc_irqdomain, num, 1, "irq_sirfsoc",
  34. handle_level_irq, clr, set, IRQ_GC_INIT_MASK_CACHE);
  35. gc = irq_get_domain_generic_chip(sirfsoc_irqdomain, irq_start);
  36. gc->reg_base = base;
  37. ct = gc->chip_types;
  38. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  39. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  40. ct->regs.mask = SIRFSOC_INT_RISC_MASK0;
  41. }
  42. static void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs)
  43. {
  44. void __iomem *base = sirfsoc_irqdomain->host_data;
  45. u32 irqstat, irqnr;
  46. irqstat = readl_relaxed(base + SIRFSOC_INIT_IRQ_ID);
  47. irqnr = irq_find_mapping(sirfsoc_irqdomain, irqstat & 0xff);
  48. handle_IRQ(irqnr, regs);
  49. }
  50. static int __init sirfsoc_irq_init(struct device_node *np,
  51. struct device_node *parent)
  52. {
  53. void __iomem *base = of_iomap(np, 0);
  54. if (!base)
  55. panic("unable to map intc cpu registers\n");
  56. sirfsoc_irqdomain = irq_domain_add_linear(np, SIRFSOC_NUM_IRQS,
  57. &irq_generic_chip_ops, base);
  58. sirfsoc_alloc_gc(base, 0, 32);
  59. sirfsoc_alloc_gc(base + 4, 32, SIRFSOC_NUM_IRQS - 32);
  60. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL0);
  61. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL1);
  62. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK0);
  63. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK1);
  64. set_handle_irq(sirfsoc_handle_irq);
  65. return 0;
  66. }
  67. IRQCHIP_DECLARE(sirfsoc_intc, "sirf,prima2-intc", sirfsoc_irq_init);
  68. struct sirfsoc_irq_status {
  69. u32 mask0;
  70. u32 mask1;
  71. u32 level0;
  72. u32 level1;
  73. };
  74. static struct sirfsoc_irq_status sirfsoc_irq_st;
  75. static int sirfsoc_irq_suspend(void)
  76. {
  77. void __iomem *base = sirfsoc_irqdomain->host_data;
  78. sirfsoc_irq_st.mask0 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK0);
  79. sirfsoc_irq_st.mask1 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK1);
  80. sirfsoc_irq_st.level0 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL0);
  81. sirfsoc_irq_st.level1 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL1);
  82. return 0;
  83. }
  84. static void sirfsoc_irq_resume(void)
  85. {
  86. void __iomem *base = sirfsoc_irqdomain->host_data;
  87. writel_relaxed(sirfsoc_irq_st.mask0, base + SIRFSOC_INT_RISC_MASK0);
  88. writel_relaxed(sirfsoc_irq_st.mask1, base + SIRFSOC_INT_RISC_MASK1);
  89. writel_relaxed(sirfsoc_irq_st.level0, base + SIRFSOC_INT_RISC_LEVEL0);
  90. writel_relaxed(sirfsoc_irq_st.level1, base + SIRFSOC_INT_RISC_LEVEL1);
  91. }
  92. static struct syscore_ops sirfsoc_irq_syscore_ops = {
  93. .suspend = sirfsoc_irq_suspend,
  94. .resume = sirfsoc_irq_resume,
  95. };
  96. static int __init sirfsoc_irq_pm_init(void)
  97. {
  98. if (!sirfsoc_irqdomain)
  99. return 0;
  100. register_syscore_ops(&sirfsoc_irq_syscore_ops);
  101. return 0;
  102. }
  103. device_initcall(sirfsoc_irq_pm_init);