gpc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/io.h>
  13. #include <linux/irq.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_irq.h>
  17. #include <asm/hardware/gic.h>
  18. #define GPC_IMR1 0x008
  19. #define GPC_PGC_CPU_PDN 0x2a0
  20. #define IMR_NUM 4
  21. static void __iomem *gpc_base;
  22. static u32 gpc_wake_irqs[IMR_NUM];
  23. static u32 gpc_saved_imrs[IMR_NUM];
  24. void imx_gpc_pre_suspend(void)
  25. {
  26. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  27. int i;
  28. /* Tell GPC to power off ARM core when suspend */
  29. writel_relaxed(0x1, gpc_base + GPC_PGC_CPU_PDN);
  30. for (i = 0; i < IMR_NUM; i++) {
  31. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  32. writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4);
  33. }
  34. }
  35. void imx_gpc_post_resume(void)
  36. {
  37. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  38. int i;
  39. /* Keep ARM core powered on for other low-power modes */
  40. writel_relaxed(0x0, gpc_base + GPC_PGC_CPU_PDN);
  41. for (i = 0; i < IMR_NUM; i++)
  42. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  43. }
  44. static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
  45. {
  46. unsigned int idx = d->irq / 32 - 1;
  47. u32 mask;
  48. /* Sanity check for SPI irq */
  49. if (d->irq < 32)
  50. return -EINVAL;
  51. mask = 1 << d->irq % 32;
  52. gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
  53. gpc_wake_irqs[idx] & ~mask;
  54. return 0;
  55. }
  56. static void imx_gpc_irq_unmask(struct irq_data *d)
  57. {
  58. void __iomem *reg;
  59. u32 val;
  60. /* Sanity check for SPI irq */
  61. if (d->irq < 32)
  62. return;
  63. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  64. val = readl_relaxed(reg);
  65. val &= ~(1 << d->irq % 32);
  66. writel_relaxed(val, reg);
  67. }
  68. static void imx_gpc_irq_mask(struct irq_data *d)
  69. {
  70. void __iomem *reg;
  71. u32 val;
  72. /* Sanity check for SPI irq */
  73. if (d->irq < 32)
  74. return;
  75. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  76. val = readl_relaxed(reg);
  77. val |= 1 << (d->irq % 32);
  78. writel_relaxed(val, reg);
  79. }
  80. void __init imx_gpc_init(void)
  81. {
  82. struct device_node *np;
  83. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
  84. gpc_base = of_iomap(np, 0);
  85. WARN_ON(!gpc_base);
  86. /* Register GPC as the secondary interrupt controller behind GIC */
  87. gic_arch_extn.irq_mask = imx_gpc_irq_mask;
  88. gic_arch_extn.irq_unmask = imx_gpc_irq_unmask;
  89. gic_arch_extn.irq_set_wake = imx_gpc_irq_set_wake;
  90. }