gpc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 GPC_PGC_CPU_PUPSCR 0x2a4
  22. #define GPC_PGC_CPU_PDNSCR 0x2a8
  23. #define GPC_PGC_SW2ISO_SHIFT 0x8
  24. #define GPC_PGC_SW_SHIFT 0x0
  25. #define IMR_NUM 4
  26. static void __iomem *gpc_base;
  27. static u32 gpc_wake_irqs[IMR_NUM];
  28. static u32 gpc_saved_imrs[IMR_NUM];
  29. void imx_gpc_set_arm_power_up_timing(u32 sw2iso, u32 sw)
  30. {
  31. writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) |
  32. (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PUPSCR);
  33. }
  34. void imx_gpc_set_arm_power_down_timing(u32 sw2iso, u32 sw)
  35. {
  36. writel_relaxed((sw2iso << GPC_PGC_SW2ISO_SHIFT) |
  37. (sw << GPC_PGC_SW_SHIFT), gpc_base + GPC_PGC_CPU_PDNSCR);
  38. }
  39. void imx_gpc_set_arm_power_in_lpm(bool power_off)
  40. {
  41. writel_relaxed(power_off, gpc_base + GPC_PGC_CPU_PDN);
  42. }
  43. void imx_gpc_pre_suspend(bool arm_power_off)
  44. {
  45. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  46. int i;
  47. /* Tell GPC to power off ARM core when suspend */
  48. if (arm_power_off)
  49. imx_gpc_set_arm_power_in_lpm(arm_power_off);
  50. for (i = 0; i < IMR_NUM; i++) {
  51. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  52. writel_relaxed(~gpc_wake_irqs[i], reg_imr1 + i * 4);
  53. }
  54. }
  55. void imx_gpc_post_resume(void)
  56. {
  57. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  58. int i;
  59. /* Keep ARM core powered on for other low-power modes */
  60. imx_gpc_set_arm_power_in_lpm(false);
  61. for (i = 0; i < IMR_NUM; i++)
  62. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  63. }
  64. static int imx_gpc_irq_set_wake(struct irq_data *d, unsigned int on)
  65. {
  66. unsigned int idx = d->hwirq / 32 - 1;
  67. u32 mask;
  68. /* Sanity check for SPI irq */
  69. if (d->hwirq < 32)
  70. return -EINVAL;
  71. mask = 1 << d->hwirq % 32;
  72. gpc_wake_irqs[idx] = on ? gpc_wake_irqs[idx] | mask :
  73. gpc_wake_irqs[idx] & ~mask;
  74. return 0;
  75. }
  76. void imx_gpc_mask_all(void)
  77. {
  78. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  79. int i;
  80. for (i = 0; i < IMR_NUM; i++) {
  81. gpc_saved_imrs[i] = readl_relaxed(reg_imr1 + i * 4);
  82. writel_relaxed(~0, reg_imr1 + i * 4);
  83. }
  84. }
  85. void imx_gpc_restore_all(void)
  86. {
  87. void __iomem *reg_imr1 = gpc_base + GPC_IMR1;
  88. int i;
  89. for (i = 0; i < IMR_NUM; i++)
  90. writel_relaxed(gpc_saved_imrs[i], reg_imr1 + i * 4);
  91. }
  92. void imx_gpc_hwirq_unmask(unsigned int hwirq)
  93. {
  94. void __iomem *reg;
  95. u32 val;
  96. reg = gpc_base + GPC_IMR1 + (hwirq / 32 - 1) * 4;
  97. val = readl_relaxed(reg);
  98. val &= ~(1 << hwirq % 32);
  99. writel_relaxed(val, reg);
  100. }
  101. void imx_gpc_hwirq_mask(unsigned int hwirq)
  102. {
  103. void __iomem *reg;
  104. u32 val;
  105. reg = gpc_base + GPC_IMR1 + (hwirq / 32 - 1) * 4;
  106. val = readl_relaxed(reg);
  107. val |= 1 << (hwirq % 32);
  108. writel_relaxed(val, reg);
  109. }
  110. static void imx_gpc_irq_unmask(struct irq_data *d)
  111. {
  112. /* Sanity check for SPI irq */
  113. if (d->hwirq < 32)
  114. return;
  115. imx_gpc_hwirq_unmask(d->hwirq);
  116. }
  117. static void imx_gpc_irq_mask(struct irq_data *d)
  118. {
  119. /* Sanity check for SPI irq */
  120. if (d->hwirq < 32)
  121. return;
  122. imx_gpc_hwirq_mask(d->hwirq);
  123. }
  124. void __init imx_gpc_init(void)
  125. {
  126. struct device_node *np;
  127. int i;
  128. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
  129. gpc_base = of_iomap(np, 0);
  130. WARN_ON(!gpc_base);
  131. /* Initially mask all interrupts */
  132. for (i = 0; i < IMR_NUM; i++)
  133. writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
  134. /* Register GPC as the secondary interrupt controller behind GIC */
  135. gic_arch_extn.irq_mask = imx_gpc_irq_mask;
  136. gic_arch_extn.irq_unmask = imx_gpc_irq_unmask;
  137. gic_arch_extn.irq_set_wake = imx_gpc_irq_set_wake;
  138. }