gpc.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright 2011-2013 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 <linux/irqchip/arm-gic.h>
  18. #include "common.h"
  19. #define GPC_IMR1 0x008
  20. #define GPC_PGC_CPU_PDN 0x2a0
  21. #define IMR_NUM 4
  22. static void __iomem *gpc_base;
  23. static u32 gpc_wake_irqs[IMR_NUM];
  24. static u32 gpc_saved_imrs[IMR_NUM];
  25. void imx_gpc_pre_suspend(bool arm_power_off)
  26. {
  27. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  28. int i;
  29. /* Tell GPC to power off ARM core when suspend */
  30. if (arm_power_off)
  31. writel_relaxed(0x1, gpc_base + GPC_PGC_CPU_PDN);
  32. for (i = 0; i < IMR_NUM; i++) {
  33. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  34. writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4);
  35. }
  36. }
  37. void imx_gpc_post_resume(void)
  38. {
  39. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  40. int i;
  41. /* Keep ARM core powered on for other low-power modes */
  42. writel_relaxed(0x0, gpc_base + GPC_PGC_CPU_PDN);
  43. for (i = 0; i < IMR_NUM; i++)
  44. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  45. }
  46. static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
  47. {
  48. unsigned int idx = d->irq / 32 - 1;
  49. u32 mask;
  50. /* Sanity check for SPI irq */
  51. if (d->irq < 32)
  52. return -EINVAL;
  53. mask = 1 << d->irq % 32;
  54. gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
  55. gpc_wake_irqs[idx] & ~mask;
  56. return 0;
  57. }
  58. void imx_gpc_mask_all(void)
  59. {
  60. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  61. int i;
  62. for (i = 0; i < IMR_NUM; i++) {
  63. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  64. writel_relaxed(~0, reg_imr1 + i * 4);
  65. }
  66. }
  67. void imx_gpc_restore_all(void)
  68. {
  69. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  70. int i;
  71. for (i = 0; i < IMR_NUM; i++)
  72. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  73. }
  74. void imx_gpc_irq_unmask(struct irq_data *d)
  75. {
  76. void __iomem *reg;
  77. u32 val;
  78. /* Sanity check for SPI irq */
  79. if (d->irq < 32)
  80. return;
  81. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  82. val = readl_relaxed(reg);
  83. val &= ~(1 << d->irq % 32);
  84. writel_relaxed(val, reg);
  85. }
  86. void imx_gpc_irq_mask(struct irq_data *d)
  87. {
  88. void __iomem *reg;
  89. u32 val;
  90. /* Sanity check for SPI irq */
  91. if (d->irq < 32)
  92. return;
  93. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  94. val = readl_relaxed(reg);
  95. val |= 1 << (d->irq % 32);
  96. writel_relaxed(val, reg);
  97. }
  98. void __init imx_gpc_init(void)
  99. {
  100. struct device_node *np;
  101. int i;
  102. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
  103. gpc_base = of_iomap(np, 0);
  104. WARN_ON(!gpc_base);
  105. /* Initially mask all interrupts */
  106. for (i = 0; i < IMR_NUM; i++)
  107. writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
  108. /* Register GPC as the secondary interrupt controller behind GIC */
  109. gic_arch_extn.irq_mask = imx_gpc_irq_mask;
  110. gic_arch_extn.irq_unmask = imx_gpc_irq_unmask;
  111. gic_arch_extn.irq_set_wake = imx_gpc_irq_set_wake;
  112. }