gpc.c 3.1 KB

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