omap-mpuss-lowpower.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * OMAP MPUSS low power code
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. *
  7. * OMAP4430 MPUSS mainly consists of dual Cortex-A9 with per-CPU
  8. * Local timer and Watchdog, GIC, SCU, PL310 L2 cache controller,
  9. * CPU0 and CPU1 LPRM modules.
  10. * CPU0, CPU1 and MPUSS each have there own power domain and
  11. * hence multiple low power combinations of MPUSS are possible.
  12. *
  13. * The CPU0 and CPU1 can't support Closed switch Retention (CSWR)
  14. * because the mode is not supported by hw constraints of dormant
  15. * mode. While waking up from the dormant mode, a reset signal
  16. * to the Cortex-A9 processor must be asserted by the external
  17. * power controller.
  18. *
  19. * With architectural inputs and hardware recommendations, only
  20. * below modes are supported from power gain vs latency point of view.
  21. *
  22. * CPU0 CPU1 MPUSS
  23. * ----------------------------------------------
  24. * ON ON ON
  25. * ON(Inactive) OFF ON(Inactive)
  26. * OFF OFF CSWR
  27. * OFF OFF OSWR (*TBD)
  28. * OFF OFF OFF* (*TBD)
  29. * ----------------------------------------------
  30. *
  31. * Note: CPU0 is the master core and it is the last CPU to go down
  32. * and first to wake-up when MPUSS low power states are excercised
  33. *
  34. *
  35. * This program is free software; you can redistribute it and/or modify
  36. * it under the terms of the GNU General Public License version 2 as
  37. * published by the Free Software Foundation.
  38. */
  39. #include <linux/kernel.h>
  40. #include <linux/io.h>
  41. #include <linux/errno.h>
  42. #include <linux/linkage.h>
  43. #include <linux/smp.h>
  44. #include <asm/cacheflush.h>
  45. #include <asm/tlbflush.h>
  46. #include <asm/smp_scu.h>
  47. #include <asm/system.h>
  48. #include <asm/pgalloc.h>
  49. #include <asm/suspend.h>
  50. #include <plat/omap44xx.h>
  51. #include "common.h"
  52. #include "omap4-sar-layout.h"
  53. #include "pm.h"
  54. #include "powerdomain.h"
  55. #ifdef CONFIG_SMP
  56. struct omap4_cpu_pm_info {
  57. struct powerdomain *pwrdm;
  58. void __iomem *scu_sar_addr;
  59. void __iomem *wkup_sar_addr;
  60. };
  61. static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
  62. /*
  63. * Program the wakeup routine address for the CPU0 and CPU1
  64. * used for OFF or DORMANT wakeup.
  65. */
  66. static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
  67. {
  68. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  69. __raw_writel(addr, pm_info->wkup_sar_addr);
  70. }
  71. /*
  72. * Set the CPUx powerdomain's previous power state
  73. */
  74. static inline void set_cpu_next_pwrst(unsigned int cpu_id,
  75. unsigned int power_state)
  76. {
  77. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  78. pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
  79. }
  80. /*
  81. * Read CPU's previous power state
  82. */
  83. static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
  84. {
  85. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  86. return pwrdm_read_prev_pwrst(pm_info->pwrdm);
  87. }
  88. /*
  89. * Clear the CPUx powerdomain's previous power state
  90. */
  91. static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
  92. {
  93. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  94. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  95. }
  96. /*
  97. * Store the SCU power status value to scratchpad memory
  98. */
  99. static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
  100. {
  101. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  102. u32 scu_pwr_st;
  103. switch (cpu_state) {
  104. case PWRDM_POWER_RET:
  105. scu_pwr_st = SCU_PM_DORMANT;
  106. break;
  107. case PWRDM_POWER_OFF:
  108. scu_pwr_st = SCU_PM_POWEROFF;
  109. break;
  110. case PWRDM_POWER_ON:
  111. case PWRDM_POWER_INACTIVE:
  112. default:
  113. scu_pwr_st = SCU_PM_NORMAL;
  114. break;
  115. }
  116. __raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
  117. }
  118. /**
  119. * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
  120. * The purpose of this function is to manage low power programming
  121. * of OMAP4 MPUSS subsystem
  122. * @cpu : CPU ID
  123. * @power_state: Low power state.
  124. */
  125. int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
  126. {
  127. unsigned int save_state = 0;
  128. unsigned int wakeup_cpu;
  129. if (omap_rev() == OMAP4430_REV_ES1_0)
  130. return -ENXIO;
  131. switch (power_state) {
  132. case PWRDM_POWER_ON:
  133. case PWRDM_POWER_INACTIVE:
  134. save_state = 0;
  135. break;
  136. case PWRDM_POWER_OFF:
  137. save_state = 1;
  138. break;
  139. case PWRDM_POWER_RET:
  140. default:
  141. /*
  142. * CPUx CSWR is invalid hardware state. Also CPUx OSWR
  143. * doesn't make much scense, since logic is lost and $L1
  144. * needs to be cleaned because of coherency. This makes
  145. * CPUx OSWR equivalent to CPUX OFF and hence not supported
  146. */
  147. WARN_ON(1);
  148. return -ENXIO;
  149. }
  150. clear_cpu_prev_pwrst(cpu);
  151. set_cpu_next_pwrst(cpu, power_state);
  152. set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume));
  153. scu_pwrst_prepare(cpu, power_state);
  154. /*
  155. * Call low level function with targeted low power state.
  156. */
  157. cpu_suspend(save_state, omap4_finish_suspend);
  158. /*
  159. * Restore the CPUx power state to ON otherwise CPUx
  160. * power domain can transitions to programmed low power
  161. * state while doing WFI outside the low powe code. On
  162. * secure devices, CPUx does WFI which can result in
  163. * domain transition
  164. */
  165. wakeup_cpu = smp_processor_id();
  166. set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON);
  167. return 0;
  168. }
  169. /*
  170. * Initialise OMAP4 MPUSS
  171. */
  172. int __init omap4_mpuss_init(void)
  173. {
  174. struct omap4_cpu_pm_info *pm_info;
  175. void __iomem *sar_base = omap4_get_sar_ram_base();
  176. if (omap_rev() == OMAP4430_REV_ES1_0) {
  177. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  178. return -ENODEV;
  179. }
  180. /* Initilaise per CPU PM information */
  181. pm_info = &per_cpu(omap4_pm_info, 0x0);
  182. pm_info->scu_sar_addr = sar_base + SCU_OFFSET0;
  183. pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET;
  184. pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm");
  185. if (!pm_info->pwrdm) {
  186. pr_err("Lookup failed for CPU0 pwrdm\n");
  187. return -ENODEV;
  188. }
  189. /* Clear CPU previous power domain state */
  190. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  191. /* Initialise CPU0 power domain state to ON */
  192. pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
  193. pm_info = &per_cpu(omap4_pm_info, 0x1);
  194. pm_info->scu_sar_addr = sar_base + SCU_OFFSET1;
  195. pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET;
  196. pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm");
  197. if (!pm_info->pwrdm) {
  198. pr_err("Lookup failed for CPU1 pwrdm\n");
  199. return -ENODEV;
  200. }
  201. /* Clear CPU previous power domain state */
  202. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  203. /* Initialise CPU1 power domain state to ON */
  204. pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
  205. /* Save device type on scratchpad for low level code to use */
  206. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  207. __raw_writel(1, sar_base + OMAP_TYPE_OFFSET);
  208. else
  209. __raw_writel(0, sar_base + OMAP_TYPE_OFFSET);
  210. return 0;
  211. }
  212. #endif