irq-sirfsoc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/irqchip.h>
  14. #include <linux/irqdomain.h>
  15. #include <linux/syscore_ops.h>
  16. #include <asm/mach/irq.h>
  17. #include <asm/exception.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_INT_BASE_OFFSET 0x0004
  24. #define SIRFSOC_NUM_IRQS 64
  25. #define SIRFSOC_NUM_BANKS (SIRFSOC_NUM_IRQS / 32)
  26. static struct irq_domain *sirfsoc_irqdomain;
  27. static void __iomem *sirfsoc_irq_get_regbase(void)
  28. {
  29. return (void __iomem __force *)sirfsoc_irqdomain->host_data;
  30. }
  31. static __init void sirfsoc_alloc_gc(void __iomem *base)
  32. {
  33. unsigned int clr = IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
  34. unsigned int set = IRQ_LEVEL;
  35. struct irq_chip_generic *gc;
  36. struct irq_chip_type *ct;
  37. int i;
  38. irq_alloc_domain_generic_chips(sirfsoc_irqdomain, 32, 1, "irq_sirfsoc",
  39. handle_level_irq, clr, set,
  40. IRQ_GC_INIT_MASK_CACHE);
  41. for (i = 0; i < SIRFSOC_NUM_BANKS; i++) {
  42. gc = irq_get_domain_generic_chip(sirfsoc_irqdomain, i * 32);
  43. gc->reg_base = base + i * SIRFSOC_INT_BASE_OFFSET;
  44. ct = gc->chip_types;
  45. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  46. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  47. ct->regs.mask = SIRFSOC_INT_RISC_MASK0;
  48. }
  49. }
  50. static void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs)
  51. {
  52. void __iomem *base = sirfsoc_irq_get_regbase();
  53. u32 irqstat;
  54. irqstat = readl_relaxed(base + SIRFSOC_INIT_IRQ_ID);
  55. handle_domain_irq(sirfsoc_irqdomain, irqstat & 0xff, regs);
  56. }
  57. static int __init sirfsoc_irq_init(struct device_node *np,
  58. struct device_node *parent)
  59. {
  60. void __iomem *base = of_iomap(np, 0);
  61. if (!base)
  62. panic("unable to map intc cpu registers\n");
  63. sirfsoc_irqdomain = irq_domain_add_linear(np, SIRFSOC_NUM_IRQS,
  64. &irq_generic_chip_ops, base);
  65. sirfsoc_alloc_gc(base);
  66. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL0);
  67. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL1);
  68. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK0);
  69. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK1);
  70. set_handle_irq(sirfsoc_handle_irq);
  71. return 0;
  72. }
  73. IRQCHIP_DECLARE(sirfsoc_intc, "sirf,prima2-intc", sirfsoc_irq_init);
  74. struct sirfsoc_irq_status {
  75. u32 mask0;
  76. u32 mask1;
  77. u32 level0;
  78. u32 level1;
  79. };
  80. static struct sirfsoc_irq_status sirfsoc_irq_st;
  81. static int sirfsoc_irq_suspend(void)
  82. {
  83. void __iomem *base = sirfsoc_irq_get_regbase();
  84. sirfsoc_irq_st.mask0 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK0);
  85. sirfsoc_irq_st.mask1 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK1);
  86. sirfsoc_irq_st.level0 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL0);
  87. sirfsoc_irq_st.level1 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL1);
  88. return 0;
  89. }
  90. static void sirfsoc_irq_resume(void)
  91. {
  92. void __iomem *base = sirfsoc_irq_get_regbase();
  93. writel_relaxed(sirfsoc_irq_st.mask0, base + SIRFSOC_INT_RISC_MASK0);
  94. writel_relaxed(sirfsoc_irq_st.mask1, base + SIRFSOC_INT_RISC_MASK1);
  95. writel_relaxed(sirfsoc_irq_st.level0, base + SIRFSOC_INT_RISC_LEVEL0);
  96. writel_relaxed(sirfsoc_irq_st.level1, base + SIRFSOC_INT_RISC_LEVEL1);
  97. }
  98. static struct syscore_ops sirfsoc_irq_syscore_ops = {
  99. .suspend = sirfsoc_irq_suspend,
  100. .resume = sirfsoc_irq_resume,
  101. };
  102. static int __init sirfsoc_irq_pm_init(void)
  103. {
  104. if (!sirfsoc_irqdomain)
  105. return 0;
  106. register_syscore_ops(&sirfsoc_irq_syscore_ops);
  107. return 0;
  108. }
  109. device_initcall(sirfsoc_irq_pm_init);