omap-mpuss-lowpower.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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;
  206. unsigned int wakeup_cpu;
  207. if (omap_rev() == OMAP4430_REV_ES1_0)
  208. return -ENXIO;
  209. switch (power_state) {
  210. case PWRDM_POWER_ON:
  211. case PWRDM_POWER_INACTIVE:
  212. save_state = 0;
  213. break;
  214. case PWRDM_POWER_OFF:
  215. save_state = 1;
  216. break;
  217. case PWRDM_POWER_RET:
  218. default:
  219. /*
  220. * CPUx CSWR is invalid hardware state. Also CPUx OSWR
  221. * doesn't make much scense, since logic is lost and $L1
  222. * needs to be cleaned because of coherency. This makes
  223. * CPUx OSWR equivalent to CPUX OFF and hence not supported
  224. */
  225. WARN_ON(1);
  226. return -ENXIO;
  227. }
  228. pwrdm_pre_transition(NULL);
  229. /*
  230. * Check MPUSS next state and save interrupt controller if needed.
  231. * In MPUSS OSWR or device OFF, interrupt controller contest is lost.
  232. */
  233. mpuss_clear_prev_logic_pwrst();
  234. if ((pwrdm_read_next_pwrst(mpuss_pd) == PWRDM_POWER_RET) &&
  235. (pwrdm_read_logic_retst(mpuss_pd) == PWRDM_POWER_OFF))
  236. save_state = 2;
  237. cpu_clear_prev_logic_pwrst(cpu);
  238. set_cpu_next_pwrst(cpu, power_state);
  239. set_cpu_wakeup_addr(cpu, virt_to_phys(omap4_cpu_resume));
  240. scu_pwrst_prepare(cpu, power_state);
  241. l2x0_pwrst_prepare(cpu, save_state);
  242. /*
  243. * Call low level function with targeted low power state.
  244. */
  245. cpu_suspend(save_state, omap4_finish_suspend);
  246. /*
  247. * Restore the CPUx power state to ON otherwise CPUx
  248. * power domain can transitions to programmed low power
  249. * state while doing WFI outside the low powe code. On
  250. * secure devices, CPUx does WFI which can result in
  251. * domain transition
  252. */
  253. wakeup_cpu = smp_processor_id();
  254. set_cpu_next_pwrst(wakeup_cpu, PWRDM_POWER_ON);
  255. pwrdm_post_transition(NULL);
  256. return 0;
  257. }
  258. /**
  259. * omap4_hotplug_cpu: OMAP4 CPU hotplug entry
  260. * @cpu : CPU ID
  261. * @power_state: CPU low power state.
  262. */
  263. int __cpuinit omap4_hotplug_cpu(unsigned int cpu, unsigned int power_state)
  264. {
  265. unsigned int cpu_state = 0;
  266. struct omap4_cpu_pm_info *pm_info = &per_cpu(omap4_pm_info, cpu);
  267. if (omap_rev() == OMAP4430_REV_ES1_0)
  268. return -ENXIO;
  269. if (power_state == PWRDM_POWER_OFF)
  270. cpu_state = 1;
  271. clear_cpu_prev_pwrst(cpu);
  272. set_cpu_next_pwrst(cpu, power_state);
  273. set_cpu_wakeup_addr(cpu, virt_to_phys(pm_info->secondary_startup));
  274. scu_pwrst_prepare(cpu, power_state);
  275. /*
  276. * CPU never retuns back if targeted power state is OFF mode.
  277. * CPU ONLINE follows normal CPU ONLINE ptah via
  278. * omap_secondary_startup().
  279. */
  280. omap4_finish_suspend(cpu_state);
  281. set_cpu_next_pwrst(cpu, PWRDM_POWER_ON);
  282. return 0;
  283. }
  284. /*
  285. * Initialise OMAP4 MPUSS
  286. */
  287. int __init omap4_mpuss_init(void)
  288. {
  289. struct omap4_cpu_pm_info *pm_info;
  290. if (omap_rev() == OMAP4430_REV_ES1_0) {
  291. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  292. return -ENODEV;
  293. }
  294. sar_base = omap4_get_sar_ram_base();
  295. /* Initilaise per CPU PM information */
  296. pm_info = &per_cpu(omap4_pm_info, 0x0);
  297. pm_info->scu_sar_addr = sar_base + SCU_OFFSET0;
  298. pm_info->wkup_sar_addr = sar_base + CPU0_WAKEUP_NS_PA_ADDR_OFFSET;
  299. pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET0;
  300. pm_info->pwrdm = pwrdm_lookup("cpu0_pwrdm");
  301. if (!pm_info->pwrdm) {
  302. pr_err("Lookup failed for CPU0 pwrdm\n");
  303. return -ENODEV;
  304. }
  305. /* Clear CPU previous power domain state */
  306. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  307. cpu_clear_prev_logic_pwrst(0);
  308. /* Initialise CPU0 power domain state to ON */
  309. pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
  310. pm_info = &per_cpu(omap4_pm_info, 0x1);
  311. pm_info->scu_sar_addr = sar_base + SCU_OFFSET1;
  312. pm_info->wkup_sar_addr = sar_base + CPU1_WAKEUP_NS_PA_ADDR_OFFSET;
  313. pm_info->l2x0_sar_addr = sar_base + L2X0_SAVE_OFFSET1;
  314. if (cpu_is_omap446x())
  315. pm_info->secondary_startup = omap_secondary_startup_4460;
  316. else
  317. pm_info->secondary_startup = omap_secondary_startup;
  318. pm_info->pwrdm = pwrdm_lookup("cpu1_pwrdm");
  319. if (!pm_info->pwrdm) {
  320. pr_err("Lookup failed for CPU1 pwrdm\n");
  321. return -ENODEV;
  322. }
  323. /* Clear CPU previous power domain state */
  324. pwrdm_clear_all_prev_pwrst(pm_info->pwrdm);
  325. cpu_clear_prev_logic_pwrst(1);
  326. /* Initialise CPU1 power domain state to ON */
  327. pwrdm_set_next_pwrst(pm_info->pwrdm, PWRDM_POWER_ON);
  328. mpuss_pd = pwrdm_lookup("mpu_pwrdm");
  329. if (!mpuss_pd) {
  330. pr_err("Failed to lookup MPUSS power domain\n");
  331. return -ENODEV;
  332. }
  333. pwrdm_clear_all_prev_pwrst(mpuss_pd);
  334. mpuss_clear_prev_logic_pwrst();
  335. /* Save device type on scratchpad for low level code to use */
  336. if (omap_type() != OMAP2_DEVICE_TYPE_GP)
  337. __raw_writel(1, sar_base + OMAP_TYPE_OFFSET);
  338. else
  339. __raw_writel(0, sar_base + OMAP_TYPE_OFFSET);
  340. save_l2x0_context();
  341. return 0;
  342. }
  343. #endif