synchronousMemoryDatabase.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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
  28. * OFF OFF OFF(Device 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/pgalloc.h>
  48. #include <asm/suspend.h>
  49. #include <asm/hardware/cache-l2x0.h>
  50. #include "soc.h"
  51. #include "common.h"
  52. #include "omap44xx.h"
  53. #include "omap4-sar-layout.h"
  54. #include "pm.h"
  55. #include "prcm_mpu44xx.h"
  56. #include "prminst44xx.h"
  57. #include "prcm44xx.h"
  58. #include "prm44xx.h"
  59. #include "prm-regbits-44xx.h"
  60. #ifdef CONFIG_SMP
  61. struct omap4_cpu_pm_info {
  62. struct powerdomain *pwrdm;
  63. void __iomem *scu_sar_addr;
  64. void __iomem *wkup_sar_addr;
  65. void __iomem *l2x0_sar_addr;
  66. void (*secondary_startup)(void);
  67. };
  68. static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
  69. static struct powerdomain *mpuss_pd;
  70. static void __iomem *sar_base;
  71. /*
  72. * Program the wakeup routine address for the CPU0 and CPU1
  73. * used for OFF or DORMANT wakeup.
  74. */
  75. static inline void set_cpu_wakeup_addr(unsigned int cpu_id, u32 addr)
  76. {
  77. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  78. __raw_writel(addr, pm_info->wkup_sar_addr);
  79. }
  80. /*
  81. * Set the CPUx powerdomain's previous power state
  82. */
  83. static inline void set_cpu_next_pwrst(unsigned int cpu_id,
  84. unsigned int power_state)
  85. {
  86. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  87. pwrdm_set_next_pwrst(pm_info->pwrdm, power_state);
  88. }
  89. /*
  90. * Read CPU's previous power state
  91. */
  92. static inline unsigned int read_cpu_prev_pwrst(unsigned int cpu_id)
  93. {
  94. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  95. return pwrdm_read_prev_pwrst(pm_info->pwrdm);
  96. }
  97. /*
  98. * Clear the CPUx powerdomain's previous power state
  99. */
  100. static inline void clear_cpu_prev_pwrst(unsigned int cpu_id)
  101. {
  102. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  103. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  104. }
  105. /*
  106. * Store the SCU power status value to scratchpad memory
  107. */
  108. static void scu_pwrst_prepare(unsigned int cpu_id, unsigned int cpu_state)
  109. {
  110. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  111. u32 scu_pwr_st;
  112. switch (cpu_state) {
  113. case PWRDM_POWER_RET:
  114. scu_pwr_st = SCU_PM_DORMANT;
  115. break;
  116. case PWRDM_POWER_OFF:
  117. scu_pwr_st = SCU_PM_POWEROFF;
  118. break;
  119. case PWRDM_POWER_ON:
  120. case PWRDM_POWER_INACTIVE:
  121. default:
  122. scu_pwr_st = SCU_PM_NORMAL;
  123. break;
  124. }
  125. __raw_writel(scu_pwr_st, pm_info->scu_sar_addr);
  126. }
  127. /* Helper functions for MPUSS OSWR */
  128. static inline void mpuss_clear_prev_logic_pwrst(void)
  129. {
  130. u32 reg;
  131. reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  132. OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
  133. omap4_prminst_write_inst_reg(reg, OMAP4430_PRM_PARTITION,
  134. OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
  135. }
  136. static inline void cpu_clear_prev_logic_pwrst(unsigned int cpu_id)
  137. {
  138. u32 reg;
  139. if (cpu_id) {
  140. reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU1_INST,
  141. OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
  142. omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU1_INST,
  143. OMAP4_RM_CPU1_CPU1_CONTEXT_OFFSET);
  144. } else {
  145. reg = omap4_prcm_mpu_read_inst_reg(OMAP4430_PRCM_MPU_CPU0_INST,
  146. OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
  147. omap4_prcm_mpu_write_inst_reg(reg, OMAP4430_PRCM_MPU_CPU0_INST,
  148. OMAP4_RM_CPU0_CPU0_CONTEXT_OFFSET);
  149. }
  150. }
  151. /**
  152. * omap4_mpuss_read_prev_context_state:
  153. * Function returns the MPUSS previous context state
  154. */
  155. u32 omap4_mpuss_read_prev_context_state(void)
  156. {
  157. u32 reg;
  158. reg = omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION,
  159. OMAP4430_PRM_MPU_INST, OMAP4_RM_MPU_MPU_CONTEXT_OFFSET);
  160. reg &= OMAP4430_LOSTCONTEXT_DFF_MASK;
  161. return reg;
  162. }
  163. /*
  164. * Store the CPU cluster state for L2X0 low power operations.
  165. */
  166. static void l2x0_pwrst_prepare(unsigned int cpu_id, unsigned int save_state)
  167. {
  168. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu_id);
  169. __raw_writel(save_state, pm_info->l2x0_sar_addr);
  170. }
  171. /*
  172. * Save the L2X0 AUXCTRL and POR value to SAR memory. Its used to
  173. * in every restore MPUSS OFF path.
  174. */
  175. #ifdef CONFIG_CACHE_L2X0
  176. static void save_l2x0_context(void)
  177. {
  178. u32 val;
  179. void __iomem *l2x0_base = omap4_get_l2cache_base();
  180. val = __raw_readl(l2x0_base + L2X0_AUX_CTRL);
  181. __raw_writel(val, sar_base + L2X0_AUXCTRL_OFFSET);
  182. val = __raw_readl(l2x0_base + L2X0_PREFETCH_CTRL);
  183. __raw_writel(val, sar_base + L2X0_PREFETCH_CTRL_OFFSET);
  184. }
  185. #else
  186. static void save_l2x0_context(void)
  187. {}
  188. #endif
  189. /**
  190. * omap4_enter_lowpower: OMAP4 MPUSS Low Power Entry Function
  191. * The purpose of this function is to manage low power programming
  192. * of OMAP4 MPUSS subsystem
  193. * @cpu : CPU ID
  194. * @power_state: Low power state.
  195. *
  196. * MPUSS states for the context save:
  197. * save_state =
  198. * 0 - Nothing lost and no need to save: MPUSS INACTIVE
  199. * 1 - CPUx L1 and logic lost: MPUSS CSWR
  200. * 2 - CPUx L1 and logic lost + GIC lost: MPUSS OSWR
  201. * 3 - CPUx L1 and logic lost + GIC + L2 lost: DEVICE OFF
  202. */
  203. int omap4_enter_lowpower(unsigned int cpu, unsigned int power_state)
  204. {
  205. unsigned int save_state = 0;