pm44xx.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * OMAP4+ Power Management Routines
  3. *
  4. * Copyright (C) 2010-2013 Texas Instruments, Inc.
  5. * Rajendra Nayak <rnayak@ti.com>
  6. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/pm.h>
  13. #include <linux/suspend.h>
  14. #include <linux/module.h>
  15. #include <linux/list.h>
  16. #include <linux/err.h>
  17. #include <linux/slab.h>
  18. #include <asm/system_misc.h>
  19. #include "soc.h"
  20. #include "common.h"
  21. #include "clockdomain.h"
  22. #include "powerdomain.h"
  23. #include "pm.h"
  24. u16 pm44xx_errata;
  25. struct power_state {
  26. struct powerdomain *pwrdm;
  27. u32 next_state;
  28. u32 next_logic_state;
  29. #ifdef CONFIG_SUSPEND
  30. u32 saved_state;
  31. u32 saved_logic_state;
  32. #endif
  33. struct list_head node;
  34. };
  35. static u32 cpu_suspend_state = PWRDM_POWER_OFF;
  36. static LIST_HEAD(pwrst_list);
  37. #ifdef CONFIG_SUSPEND
  38. static int omap4_pm_suspend(void)
  39. {
  40. struct power_state *pwrst;
  41. int state, ret = 0;
  42. u32 cpu_id = smp_processor_id();
  43. /* Save current powerdomain state */
  44. list_for_each_entry(pwrst, &pwrst_list, node) {
  45. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  46. pwrst->saved_logic_state = pwrdm_read_logic_retst(pwrst->pwrdm);
  47. }
  48. /* Set targeted power domain states by suspend */
  49. list_for_each_entry(pwrst, &pwrst_list, node) {
  50. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  51. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->next_logic_state);
  52. }
  53. /*
  54. * For MPUSS to hit power domain retention(CSWR or OSWR),
  55. * CPU0 and CPU1 power domains need to be in OFF or DORMANT state,
  56. * since CPU power domain CSWR is not supported by hardware
  57. * Only master CPU follows suspend path. All other CPUs follow
  58. * CPU hotplug path in system wide suspend. On OMAP4, CPU power
  59. * domain CSWR is not supported by hardware.
  60. * More details can be found in OMAP4430 TRM section 4.3.4.2.
  61. */
  62. omap4_enter_lowpower(cpu_id, cpu_suspend_state);
  63. /* Restore next powerdomain state */
  64. list_for_each_entry(pwrst, &pwrst_list, node) {
  65. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  66. if (state > pwrst->next_state) {
  67. pr_info("Powerdomain (%s) didn't enter target state %d\n",
  68. pwrst->pwrdm->name, pwrst->next_state);
  69. ret = -1;
  70. }
  71. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  72. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->saved_logic_state);
  73. }
  74. if (ret) {
  75. pr_crit("Could not enter target state in pm_suspend\n");
  76. /*
  77. * OMAP4 chip PM currently works only with certain (newer)
  78. * versions of bootloaders. This is due to missing code in the
  79. * kernel to properly reset and initialize some devices.
  80. * Warn the user about the bootloader version being one of the
  81. * possible causes.
  82. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  83. */
  84. pr_warn("A possible cause could be an old bootloader - try u-boot >= v2012.07\n");
  85. } else {
  86. pr_info("Successfully put all powerdomains to target state\n");
  87. }
  88. return 0;
  89. }
  90. #else
  91. #define omap4_pm_suspend NULL
  92. #endif /* CONFIG_SUSPEND */
  93. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  94. {
  95. struct power_state *pwrst;
  96. if (!pwrdm->pwrsts)
  97. return 0;
  98. /*
  99. * Skip CPU0 and CPU1 power domains. CPU1 is programmed
  100. * through hotplug path and CPU0 explicitly programmed
  101. * further down in the code path
  102. */
  103. if (!strncmp(pwrdm->name, "cpu", 3)) {
  104. if (IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE))
  105. cpu_suspend_state = PWRDM_POWER_RET;
  106. return 0;
  107. }
  108. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  109. if (!pwrst)
  110. return -ENOMEM;
  111. pwrst->pwrdm = pwrdm;
  112. pwrst->next_state = pwrdm_get_valid_lp_state(pwrdm, false,
  113. PWRDM_POWER_RET);
  114. pwrst->next_logic_state = pwrdm_get_valid_lp_state(pwrdm, true,
  115. PWRDM_POWER_OFF);
  116. list_add(&pwrst->node, &pwrst_list);
  117. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  118. }
  119. /**
  120. * omap_default_idle - OMAP4 default ilde routine.'
  121. *
  122. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  123. * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPU_IDLE and
  124. * by secondary CPU with CONFIG_CPU_IDLE.
  125. */
  126. static void omap_default_idle(void)
  127. {
  128. omap_do_wfi();
  129. }
  130. /**
  131. * omap4_init_static_deps - Add OMAP4 static dependencies
  132. *
  133. * Add needed static clockdomain dependencies on OMAP4 devices.
  134. * Return: 0 on success or 'err' on failures
  135. */
  136. static inline int omap4_init_static_deps(void)
  137. {
  138. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm;
  139. struct clockdomain *ducati_clkdm, *l3_2_clkdm;
  140. int ret = 0;
  141. /*
  142. * The dynamic dependency between MPUSS -> MEMIF and
  143. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  144. * expected. The hardware recommendation is to enable static
  145. * dependencies for these to avoid system lock ups or random crashes.
  146. * The L4 wakeup depedency is added to workaround the OCP sync hardware
  147. * BUG with 32K synctimer which lead to incorrect timer value read
  148. * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
  149. * are part of L4 wakeup clockdomain.
  150. */
  151. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  152. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  153. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  154. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  155. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  156. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) ||
  157. (!l3_2_clkdm) || (!ducati_clkdm))
  158. return -EINVAL;
  159. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  160. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  161. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  162. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  163. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  164. if (ret) {
  165. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 wakeup dependency\n");
  166. return -EINVAL;
  167. }
  168. return ret;
  169. }
  170. /**
  171. * omap5_dra7_init_static_deps - Init static clkdm dependencies on OMAP5 and
  172. * DRA7
  173. *
  174. * The dynamic dependency between MPUSS -> EMIF is broken and has
  175. * not worked as expected. The hardware recommendation is to
  176. * enable static dependencies for these to avoid system
  177. * lock ups or random crashes.
  178. */
  179. static inline int omap5_dra7_init_static_deps(void)
  180. {
  181. struct clockdomain *mpuss_clkdm, *emif_clkdm;
  182. int ret;
  183. mpuss_clkdm = clkdm_lookup("mpu_clkdm");
  184. emif_clkdm = clkdm_lookup("emif_clkdm");
  185. if (!mpuss_clkdm || !emif_clkdm)
  186. return -EINVAL;
  187. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  188. if (ret)
  189. pr_err("Failed to add MPUSS -> EMIF wakeup dependency\n");
  190. return ret;
  191. }
  192. /**
  193. * omap4_pm_init_early - Does early initialization necessary for OMAP4+ devices
  194. *
  195. * Initializes basic stuff for power management functionality.
  196. */
  197. int __init omap4_pm_init_early(void)
  198. {
  199. if (cpu_is_omap446x())
  200. pm44xx_errata |= PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD;
  201. if (soc_is_omap54xx() || soc_is_dra7xx())
  202. pm44xx_errata |= PM_OMAP4_CPU_OSWR_DISABLE;
  203. return 0;
  204. }
  205. /**
  206. * omap4_pm_init - Init routine for OMAP4+ devices
  207. *
  208. * Initializes all powerdomain and clockdomain target states
  209. * and all PRCM settings.
  210. * Return: Returns the error code returned by called functions.
  211. */
  212. int __init omap4_pm_init(void)
  213. {
  214. int ret = 0;
  215. if (omap_rev() == OMAP4430_REV_ES1_0) {
  216. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  217. return -ENODEV;
  218. }
  219. pr_info("Power Management for TI OMAP4+ devices.\n");
  220. /*
  221. * OMAP4 chip PM currently works only with certain (newer)
  222. * versions of bootloaders. This is due to missing code in the
  223. * kernel to properly reset and initialize some devices.
  224. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  225. */
  226. if (cpu_is_omap44xx())
  227. pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  228. ret = pwrdm_for_each(pwrdms_setup, NULL);
  229. if (ret) {
  230. pr_err("Failed to setup powerdomains.\n");
  231. goto err2;
  232. }
  233. if (cpu_is_omap44xx())
  234. ret = omap4_init_static_deps();
  235. else if (soc_is_omap54xx() || soc_is_dra7xx())
  236. ret = omap5_dra7_init_static_deps();
  237. if (ret) {
  238. pr_err("Failed to initialise static dependencies.\n");
  239. goto err2;
  240. }
  241. ret = omap4_mpuss_init();
  242. if (ret) {
  243. pr_err("Failed to initialise OMAP4 MPUSS\n");
  244. goto err2;
  245. }
  246. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  247. omap_common_suspend_init(omap4_pm_suspend);
  248. /* Overwrite the default cpu_do_idle() */
  249. arm_pm_idle = omap_default_idle;
  250. if (cpu_is_omap44xx())
  251. omap4_idle_init();
  252. err2:
  253. return ret;
  254. }