pm.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. * Author: Ulf Hansson <ulf.hansson@linaro.org> for Linaro.
  7. *
  8. * License terms: GNU General Public License (GPL) version 2
  9. *
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/irqchip/arm-gic.h>
  13. #include <linux/delay.h>
  14. #include <linux/io.h>
  15. #include <linux/suspend.h>
  16. #include <linux/platform_data/arm-ux500-pm.h>
  17. #include <linux/of.h>
  18. #include <linux/of_address.h>
  19. #include "db8500-regs.h"
  20. #include "pm_domains.h"
  21. /* ARM WFI Standby signal register */
  22. #define PRCM_ARM_WFI_STANDBY (prcmu_base + 0x130)
  23. #define PRCM_ARM_WFI_STANDBY_WFI0 0x08
  24. #define PRCM_ARM_WFI_STANDBY_WFI1 0x10
  25. #define PRCM_IOCR (prcmu_base + 0x310)
  26. #define PRCM_IOCR_IOFORCE 0x1
  27. /* Dual A9 core interrupt management unit registers */
  28. #define PRCM_A9_MASK_REQ (prcmu_base + 0x328)
  29. #define PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ 0x1
  30. #define PRCM_A9_MASK_ACK (prcmu_base + 0x32c)
  31. #define PRCM_ARMITMSK31TO0 (prcmu_base + 0x11c)
  32. #define PRCM_ARMITMSK63TO32 (prcmu_base + 0x120)
  33. #define PRCM_ARMITMSK95TO64 (prcmu_base + 0x124)
  34. #define PRCM_ARMITMSK127TO96 (prcmu_base + 0x128)
  35. #define PRCM_POWER_STATE_VAL (prcmu_base + 0x25C)
  36. #define PRCM_ARMITVAL31TO0 (prcmu_base + 0x260)
  37. #define PRCM_ARMITVAL63TO32 (prcmu_base + 0x264)
  38. #define PRCM_ARMITVAL95TO64 (prcmu_base + 0x268)
  39. #define PRCM_ARMITVAL127TO96 (prcmu_base + 0x26C)
  40. static void __iomem *prcmu_base;
  41. static void __iomem *dist_base;
  42. /* This function decouple the gic from the prcmu */
  43. int prcmu_gic_decouple(void)
  44. {
  45. u32 val = readl(PRCM_A9_MASK_REQ);
  46. /* Set bit 0 register value to 1 */
  47. writel(val | PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ,
  48. PRCM_A9_MASK_REQ);
  49. /* Make sure the register is updated */
  50. readl(PRCM_A9_MASK_REQ);
  51. /* Wait a few cycles for the gic mask completion */
  52. udelay(1);
  53. return 0;
  54. }
  55. /* This function recouple the gic with the prcmu */
  56. int prcmu_gic_recouple(void)
  57. {
  58. u32 val = readl(PRCM_A9_MASK_REQ);
  59. /* Set bit 0 register value to 0 */
  60. writel(val & ~PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ, PRCM_A9_MASK_REQ);
  61. return 0;
  62. }
  63. #define PRCMU_GIC_NUMBER_REGS 5
  64. /*
  65. * This function checks if there are pending irq on the gic. It only
  66. * makes sense if the gic has been decoupled before with the
  67. * db8500_prcmu_gic_decouple function. Disabling an interrupt only
  68. * disables the forwarding of the interrupt to any CPU interface. It
  69. * does not prevent the interrupt from changing state, for example
  70. * becoming pending, or active and pending if it is already
  71. * active. Hence, we have to check the interrupt is pending *and* is
  72. * active.
  73. */
  74. bool prcmu_gic_pending_irq(void)
  75. {
  76. u32 pr; /* Pending register */
  77. u32 er; /* Enable register */
  78. int i;
  79. /* 5 registers. STI & PPI not skipped */
  80. for (i = 0; i < PRCMU_GIC_NUMBER_REGS; i++) {
  81. pr = readl_relaxed(dist_base + GIC_DIST_PENDING_SET + i * 4);
  82. er = readl_relaxed(dist_base + GIC_DIST_ENABLE_SET + i * 4);
  83. if (pr & er)
  84. return true; /* There is a pending interrupt */
  85. }
  86. return false;
  87. }
  88. /*
  89. * This function checks if there are pending interrupt on the
  90. * prcmu which has been delegated to monitor the irqs with the
  91. * db8500_prcmu_copy_gic_settings function.
  92. */
  93. bool prcmu_pending_irq(void)
  94. {
  95. u32 it, im;
  96. int i;
  97. for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
  98. it = readl(PRCM_ARMITVAL31TO0 + i * 4);
  99. im = readl(PRCM_ARMITMSK31TO0 + i * 4);
  100. if (it & im)
  101. return true; /* There is a pending interrupt */
  102. }
  103. return false;
  104. }
  105. /*
  106. * This function checks if the specified cpu is in in WFI. It's usage
  107. * makes sense only if the gic is decoupled with the db8500_prcmu_gic_decouple
  108. * function. Of course passing smp_processor_id() to this function will
  109. * always return false...
  110. */
  111. bool prcmu_is_cpu_in_wfi(int cpu)
  112. {
  113. return readl(PRCM_ARM_WFI_STANDBY) &
  114. (cpu ? PRCM_ARM_WFI_STANDBY_WFI1 : PRCM_ARM_WFI_STANDBY_WFI0);
  115. }
  116. /*
  117. * This function copies the gic SPI settings to the prcmu in order to
  118. * monitor them and abort/finish the retention/off sequence or state.
  119. */
  120. int prcmu_copy_gic_settings(void)
  121. {
  122. u32 er; /* Enable register */
  123. int i;
  124. /* We skip the STI and PPI */
  125. for (i = 0; i < PRCMU_GIC_NUMBER_REGS - 1; i++) {
  126. er = readl_relaxed(dist_base +
  127. GIC_DIST_ENABLE_SET + (i + 1) * 4);
  128. writel(er, PRCM_ARMITMSK31TO0 + i * 4);
  129. }
  130. return 0;
  131. }
  132. #ifdef CONFIG_SUSPEND
  133. static int ux500_suspend_enter(suspend_state_t state)
  134. {
  135. cpu_do_idle();
  136. return 0;
  137. }
  138. static int ux500_suspend_valid(suspend_state_t state)
  139. {
  140. return state == PM_SUSPEND_MEM || state == PM_SUSPEND_STANDBY;
  141. }
  142. static const struct platform_suspend_ops ux500_suspend_ops = {
  143. .enter = ux500_suspend_enter,
  144. .valid = ux500_suspend_valid,
  145. };
  146. #define UX500_SUSPEND_OPS (&ux500_suspend_ops)
  147. #else
  148. #define UX500_SUSPEND_OPS NULL
  149. #endif
  150. void __init ux500_pm_init(u32 phy_base, u32 size)
  151. {
  152. struct device_node *np;
  153. prcmu_base = ioremap(phy_base, size);
  154. if (!prcmu_base) {
  155. pr_err("could not remap PRCMU for PM functions\n");
  156. return;
  157. }
  158. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
  159. dist_base = of_iomap(np, 0);
  160. of_node_put(np);
  161. if (!dist_base) {
  162. pr_err("could not remap GIC dist base for PM functions\n");
  163. return;
  164. }
  165. /*
  166. * On watchdog reboot the GIC is in some cases decoupled.
  167. * This will make sure that the GIC is correctly configured.
  168. */
  169. prcmu_gic_recouple();
  170. /* Set up ux500 suspend callbacks. */
  171. suspend_set_ops(UX500_SUSPEND_OPS);
  172. /* Initialize ux500 power domains */
  173. ux500_pm_domains_init();
  174. }