gpc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <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. static void imx_gpc_irq_unmask(struct irq_data *d)
  58. {
  59. void __iomem *reg;
  60. u32 val;
  61. /* Sanity check for SPI irq */
  62. if (d->irq < 32)
  63. return;
  64. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  65. val = readl_relaxed(reg);
  66. val &= ~(1 << d->irq % 32);
  67. writel_relaxed(val, reg);
  68. }
  69. static void imx_gpc_irq_mask(struct irq_data *d)
  70. {
  71. void __iomem *reg;
  72. u32 val;
  73. /* Sanity check for SPI irq */
  74. if (d->irq < 32)
  75. return;
  76. reg = gpc_base + GPC_IMR1 + (d->irq / 32 - 1) * 4;
  77. val = readl_relaxed(reg);
  78. val |= 1 << (d->irq % 32);
  79. writel_relaxed(val, reg);
  80. }
  81. void __init imx_gpc_init(void)
  82. {
  83. struct device_node *np;
  84. int i;
  85. np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-gpc");
  86. gpc_base = of_iomap(np, 0);
  87. WARN_ON(!gpc_base);
  88. /* Initially mask all interrupts */
  89. for (i = 0; i < IMR_NUM; i++)
  90. writel_relaxed(~0, gpc_base + GPC_IMR1 + i * 4);
  91. /* Register GPC as the secondary interrupt controller behind GIC */
  92. gic_arch_extn.irq_mask = imx_gpc_irq_mask;
  93. gic_arch_extn.irq_unmask = imx_gpc_irq_unmask;
  94. gic_arch_extn.irq_set_wake = imx_gpc_irq_set_wake;
  95. }