irq-sirfsoc.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 128
  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. gc = irq_alloc_generic_chip("SIRFINTC", 1, irq_start, base, handle_level_irq);
  31. ct = gc->chip_types;
  32. ct->chip.irq_mask = irq_gc_mask_clr_bit;
  33. ct->chip.irq_unmask = irq_gc_mask_set_bit;
  34. ct->regs.mask = SIRFSOC_INT_RISC_MASK0;
  35. irq_setup_generic_chip(gc, IRQ_MSK(num), IRQ_GC_INIT_MASK_CACHE, IRQ_NOREQUEST, 0);
  36. }
  37. static asmlinkage void __exception_irq_entry sirfsoc_handle_irq(struct pt_regs *regs)
  38. {
  39. void __iomem *base = sirfsoc_irqdomain->host_data;
  40. u32 irqstat, irqnr;
  41. irqstat = readl_relaxed(base + SIRFSOC_INIT_IRQ_ID);
  42. irqnr = irq_find_mapping(sirfsoc_irqdomain, irqstat & 0xff);
  43. handle_IRQ(irqnr, regs);
  44. }
  45. static int __init sirfsoc_irq_init(struct device_node *np, struct device_node *parent)
  46. {
  47. void __iomem *base = of_iomap(np, 0);
  48. if (!base)
  49. panic("unable to map intc cpu registers\n");
  50. /* using legacy because irqchip_generic does not work with linear */
  51. sirfsoc_irqdomain = irq_domain_add_legacy(np, SIRFSOC_NUM_IRQS, 0, 0,
  52. &irq_domain_simple_ops, base);
  53. sirfsoc_alloc_gc(base, 0, 32);
  54. sirfsoc_alloc_gc(base + 4, 32, SIRFSOC_NUM_IRQS - 32);
  55. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL0);
  56. writel_relaxed(0, base + SIRFSOC_INT_RISC_LEVEL1);
  57. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK0);
  58. writel_relaxed(0, base + SIRFSOC_INT_RISC_MASK1);
  59. set_handle_irq(sirfsoc_handle_irq);
  60. return 0;
  61. }
  62. IRQCHIP_DECLARE(sirfsoc_intc, "sirf,prima2-intc", sirfsoc_irq_init);
  63. struct sirfsoc_irq_status {
  64. u32 mask0;
  65. u32 mask1;
  66. u32 level0;
  67. u32 level1;
  68. };
  69. static struct sirfsoc_irq_status sirfsoc_irq_st;
  70. static int sirfsoc_irq_suspend(void)
  71. {
  72. void __iomem *base = sirfsoc_irqdomain->host_data;
  73. sirfsoc_irq_st.mask0 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK0);
  74. sirfsoc_irq_st.mask1 = readl_relaxed(base + SIRFSOC_INT_RISC_MASK1);
  75. sirfsoc_irq_st.level0 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL0);
  76. sirfsoc_irq_st.level1 = readl_relaxed(base + SIRFSOC_INT_RISC_LEVEL1);
  77. return 0;
  78. }
  79. static void sirfsoc_irq_resume(void)
  80. {
  81. void __iomem *base = sirfsoc_irqdomain->host_data;
  82. writel_relaxed(sirfsoc_irq_st.mask0, base + SIRFSOC_INT_RISC_MASK0);
  83. writel_relaxed(sirfsoc_irq_st.mask1, base + SIRFSOC_INT_RISC_MASK1);
  84. writel_relaxed(sirfsoc_irq_st.level0, base + SIRFSOC_INT_RISC_LEVEL0);
  85. writel_relaxed(sirfsoc_irq_st.level1, base + SIRFSOC_INT_RISC_LEVEL1);
  86. }
  87. static struct syscore_ops sirfsoc_irq_syscore_ops = {
  88. .suspend = sirfsoc_irq_suspend,
  89. .resume = sirfsoc_irq_resume,
  90. };
  91. static int __init sirfsoc_irq_pm_init(void)
  92. {
  93. if (!sirfsoc_irqdomain)
  94. return 0;
  95. register_syscore_ops(&sirfsoc_irq_syscore_ops);
  96. return 0;
  97. }
  98. device_initcall(sirfsoc_irq_pm_init);