pm44xx.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. struct power_state {
  25. struct powerdomain *pwrdm;
  26. u32 next_state;
  27. #ifdef CONFIG_SUSPEND
  28. u32 saved_state;
  29. u32 saved_logic_state;
  30. #endif
  31. struct list_head node;
  32. };
  33. static LIST_HEAD(pwrst_list);
  34. #ifdef CONFIG_SUSPEND
  35. static int omap4_pm_suspend(void)
  36. {
  37. struct power_state *pwrst;
  38. int state, ret = 0;
  39. u32 cpu_id = smp_processor_id();
  40. /* Save current powerdomain state */
  41. list_for_each_entry(pwrst, &pwrst_list, node) {
  42. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  43. pwrst->saved_logic_state = pwrdm_read_logic_retst(pwrst->pwrdm);
  44. }
  45. /* Set targeted power domain states by suspend */
  46. list_for_each_entry(pwrst, &pwrst_list, node) {
  47. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  48. pwrdm_set_logic_retst(pwrst->pwrdm, PWRDM_POWER_OFF);
  49. }
  50. /*
  51. * For MPUSS to hit power domain retention(CSWR or OSWR),
  52. * CPU0 and CPU1 power domains need to be in OFF or DORMANT state,
  53. * since CPU power domain CSWR is not supported by hardware
  54. * Only master CPU follows suspend path. All other CPUs follow
  55. * CPU hotplug path in system wide suspend. On OMAP4, CPU power
  56. * domain CSWR is not supported by hardware.
  57. * More details can be found in OMAP4430 TRM section 4.3.4.2.
  58. */
  59. omap4_enter_lowpower(cpu_id, PWRDM_POWER_OFF);
  60. /* Restore next powerdomain state */
  61. list_for_each_entry(pwrst, &pwrst_list, node) {
  62. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  63. if (state > pwrst->next_state) {
  64. pr_info("Powerdomain (%s) didn't enter target state %d\n",
  65. pwrst->pwrdm->name, pwrst->next_state);
  66. ret = -1;
  67. }
  68. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  69. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->saved_logic_state);
  70. }
  71. if (ret) {
  72. pr_crit("Could not enter target state in pm_suspend\n");
  73. /*
  74. * OMAP4 chip PM currently works only with certain (newer)
  75. * versions of bootloaders. This is due to missing code in the
  76. * kernel to properly reset and initialize some devices.
  77. * Warn the user about the bootloader version being one of the
  78. * possible causes.
  79. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  80. */
  81. pr_warn("A possible cause could be an old bootloader - try u-boot >= v2012.07\n");
  82. } else {
  83. pr_info("Successfully put all powerdomains to target state\n");
  84. }
  85. return 0;
  86. }
  87. #endif /* CONFIG_SUSPEND */
  88. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  89. {
  90. struct power_state *pwrst;
  91. if (!pwrdm->pwrsts)
  92. return 0;
  93. /*
  94. * Skip CPU0 and CPU1 power domains. CPU1 is programmed
  95. * through hotplug path and CPU0 explicitly programmed
  96. * further down in the code path
  97. */
  98. if (!strncmp(pwrdm->name, "cpu", 3))
  99. return 0;
  100. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  101. if (!pwrst)
  102. return -ENOMEM;
  103. pwrst->pwrdm = pwrdm;
  104. pwrst->next_state = PWRDM_POWER_RET;
  105. list_add(&pwrst->node, &pwrst_list);
  106. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  107. }
  108. /**
  109. * omap_default_idle - OMAP4 default ilde routine.'
  110. *
  111. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  112. * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPU_IDLE and
  113. * by secondary CPU with CONFIG_CPU_IDLE.
  114. */
  115. static void omap_default_idle(void)
  116. {
  117. omap_do_wfi();
  118. }
  119. /**
  120. * omap4_init_static_deps - Add OMAP4 static dependencies
  121. *
  122. * Add needed static clockdomain dependencies on OMAP4 devices.
  123. * Return: 0 on success or 'err' on failures
  124. */
  125. static inline int omap4_init_static_deps(void)
  126. {
  127. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm;
  128. struct clockdomain *ducati_clkdm, *l3_2_clkdm;
  129. int ret = 0;
  130. if (omap_rev() == OMAP4430_REV_ES1_0) {
  131. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  132. return -ENODEV;
  133. }
  134. pr_err("Power Management for TI OMAP4.\n");
  135. /*
  136. * OMAP4 chip PM currently works only with certain (newer)
  137. * versions of bootloaders. This is due to missing code in the
  138. * kernel to properly reset and initialize some devices.
  139. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  140. */
  141. pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  142. ret = pwrdm_for_each(pwrdms_setup, NULL);
  143. if (ret) {
  144. pr_err("Failed to setup powerdomains\n");
  145. return ret;
  146. }
  147. /*
  148. * The dynamic dependency between MPUSS -> MEMIF and
  149. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  150. * expected. The hardware recommendation is to enable static
  151. * dependencies for these to avoid system lock ups or random crashes.
  152. * The L4 wakeup depedency is added to workaround the OCP sync hardware
  153. * BUG with 32K synctimer which lead to incorrect timer value read
  154. * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
  155. * are part of L4 wakeup clockdomain.
  156. */
  157. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  158. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  159. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  160. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  161. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  162. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) ||
  163. (!l3_2_clkdm) || (!ducati_clkdm))
  164. return -EINVAL;
  165. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  166. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  167. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  168. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  169. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  170. if (ret) {
  171. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 wakeup dependency\n");
  172. return -EINVAL;
  173. }
  174. return ret;
  175. }
  176. /**
  177. * omap4_pm_init - Init routine for OMAP4+ devices
  178. *
  179. * Initializes all powerdomain and clockdomain target states
  180. * and all PRCM settings.
  181. * Return: Returns the error code returned by called functions.
  182. */
  183. int __init omap4_pm_init(void)
  184. {
  185. int ret = 0;
  186. if (omap_rev() == OMAP4430_REV_ES1_0) {
  187. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  188. return -ENODEV;
  189. }
  190. pr_info("Power Management for TI OMAP4+ devices.\n");
  191. ret = pwrdm_for_each(pwrdms_setup, NULL);
  192. if (ret) {
  193. pr_err("Failed to setup powerdomains.\n");
  194. goto err2;
  195. }
  196. if (cpu_is_omap44xx()) {
  197. ret = omap4_init_static_deps();
  198. if (ret)
  199. goto err2;
  200. }
  201. ret = omap4_mpuss_init();
  202. if (ret) {
  203. pr_err("Failed to initialise OMAP4 MPUSS\n");
  204. goto err2;
  205. }
  206. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  207. #ifdef CONFIG_SUSPEND
  208. omap_pm_suspend = omap4_pm_suspend;
  209. #endif
  210. /* Overwrite the default cpu_do_idle() */
  211. arm_pm_idle = omap_default_idle;
  212. if (cpu_is_omap44xx())
  213. omap4_idle_init();
  214. err2:
  215. return ret;
  216. }