pm.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010-2013
  3. * Author: Rickard Andersson <rickard.andersson@stericsson.com> for
  4. * ST-Ericsson.
  5. * Author: Daniel Lezcano <daniel.lezcano@linaro.org> for Linaro.
  6. * License terms: GNU General Public License (GPL) version 2
  7. *
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/irqchip/arm-gic.h>
  11. #include <linux/delay.h>
  12. #include <linux/io.h>
  13. #include <linux/platform_data/arm-ux500-pm.h>
  14. #include "db8500-regs.h"
  15. /* ARM WFI Standby signal register */
  16. #define PRCM_ARM_WFI_STANDBY (prcmu_base + 0x130)
  17. #define PRCM_ARM_WFI_STANDBY_WFI0 0x08
  18. #define PRCM_ARM_WFI_STANDBY_WFI1 0x10
  19. #define PRCM_IOCR (prcmu_base + 0x310)
  20. #define PRCM_IOCR_IOFORCE 0x1
  21. /* Dual A9 core interrupt management unit registers */
  22. #define PRCM_A9_MASK_REQ (prcmu_base + 0x328)
  23. #define PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ 0x1
  24. #define PRCM_A9_MASK_ACK (prcmu_base + 0x32c)
  25. #define PRCM_ARMITMSK31TO0 (prcmu_base + 0x11c)
  26. #define PRCM_ARMITMSK63TO32 (prcmu_base + 0x120)
  27. #define PRCM_ARMITMSK95TO64 (prcmu_base + 0x124)
  28. #define PRCM_ARMITMSK127TO96 (prcmu_base + 0x128)
  29. #define PRCM_POWER_STATE_VAL (prcmu_base + 0x25C)
  30. #define PRCM_ARMITVAL31TO0 (prcmu_base + 0x260)
  31. #define PRCM_ARMITVAL63TO32 (prcmu_base + 0x264)
  32. #define PRCM_ARMITVAL95TO64 (prcmu_base + 0x268)
  33. #define PRCM_ARMITVAL127TO96 (prcmu_base + 0x26C)
  34. static void __iomem *prcmu_base;
  35. /* This function decouple the gic from the prcmu */
  36. int prcmu_gic_decouple(void)
  37. {
  38. u32 val = readl(PRCM_A9_MASK_REQ);
  39. /* Set bit 0 register value to 1 */
  40. writel(val | PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ,
  41. PRCM_A9_MASK_REQ);
  42. /* Make sure the register is updated */
  43. readl(PRCM_A9_MASK_REQ);
  44. /* Wait a few cycles for the gic mask completion */
  45. udelay(1);
  46. return 0;
  47. }
  48. /* This function recouple the gic with the prcmu */
  49. int prcmu_gic_recouple(void)
  50. {
  51. u32 val = readl(PRCM_A9_MASK_REQ);
  52. /* Set bit 0 register value to 0 */
  53. writel(val & ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, PRCM_A9_MASK_REQ);
  54. return 0;
  55. }
  56. #define PRCMU_GIC_NUMBER_REGS 5
  57. /*
  58. * This function checks if there are pending irq on the gic. It only
  59. * makes sense if the gic has been decoupled before with the
  60. * db8500_prcmu_gic_decouple function. Disabling an interrupt only
  61. * disables the forwarding of the interrupt to any CPU interface. It
  62. * does not prevent the interrupt from changing state, for example
  63. * becoming pending, or active and pending if it is already
  64. * active. Hence, we have to check the interrupt is pending *and* is
  65. * active.
  66. */
  67. bool prcmu_gic_pending_irq(void)
  68. {
  69. u32 pr; /* Pending register */
  70. u32 er; /* Enable register */
  71. void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
  72. int i;
  73. /* 5 registers. STI & PPI not skipped */
  74. for (i = 0; i < PRCMU_GIC_NUMBER_REGS; i++) {
  75. pr = readl_relaxed(dist_base + GIC_DIST_PENDING_SET + i * 4);
  76. er = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
  77. if (pr & er)
  78. return true; /* There is a pending interrupt */
  79. }
  80. return false;
  81. }
  82. /*
  83. * This function checks if there are pending interrupt on the
  84. * prcmu which has been delegated to monitor the irqs with the
  85. * db8500_prcmu_copy_gic_settings function.
  86. */
  87. bool prcmu_pending_irq(void)
  88. {
  89. u32 it, im;
  90. int i;
  91. for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
  92. it = readl(PRCM_ARMITVAL31TO0 + i * 4);
  93. im = readl(PRCM_ARMITMSK31TO0 + i * 4);
  94. if (it & im)
  95. return true; /* There is a pending interrupt */
  96. }
  97. return false;
  98. }
  99. /*
  100. * This function checks if the specified cpu is in in WFI. It's usage
  101. * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple
  102. * function. Of course passing smp_processor_id() to this function will
  103. * always return false...
  104. */
  105. bool prcmu_is_cpu_in_wfi(int cpu)
  106. {
  107. return readl(PRCM_ARM_WFI_STANDBY) & cpu ? PRCM_ARM_WFI_STANDBY_WFI1 :
  108. PRCM_ARM_WFI_STANDBY_WFI0;
  109. }
  110. /*
  111. * This function copies the gic SPI settings to the prcmu in order to
  112. * monitor them and abort/finish the retention/off sequence or state.
  113. */
  114. int prcmu_copy_gic_settings(void)
  115. {
  116. u32 er; /* Enable register */
  117. void __iomem *dist_base = __io_address(U8500_GIC_DIST_BASE);
  118. int i;
  119. /* We skip the STI and PPI */
  120. for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
  121. er = readl_relaxed(dist_base +
  122. GIC_DIST_ENABLE_SET + (i + 1) * 4);
  123. writel(er, PRCM_ARMITMSK31TO0 + i * 4);
  124. }
  125. return 0;
  126. }
  127. void __init ux500_pm_init(u32 phy_base, u32 size)
  128. {
  129. prcmu_base = ioremap(phy_base, size);
  130. if (!prcmu_base) {
  131. pr_err("could not remap PRCMU for PM functions\n");
  132. return;
  133. }
  134. /*
  135. * On watchdog reboot the GIC is in some cases decoupled.
  136. * This will make sure that the GIC is correctly configured.
  137. */
  138. prcmu_gic_recouple();
  139. }