pm44xx.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * OMAP4 Power Management Routines
  3. *
  4. * Copyright (C) 2010-2011 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. local_fiq_disable();
  118. omap_do_wfi();
  119. local_fiq_enable();
  120. }
  121. /**
  122. * omap4_pm_init - Init routine for OMAP4 PM
  123. *
  124. * Initializes all powerdomain and clockdomain target states
  125. * and all PRCM settings.
  126. */
  127. int __init omap4_pm_init(void)
  128. {
  129. int ret;
  130. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm, *l4wkup;
  131. struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm;
  132. if (omap_rev() == OMAP4430_REV_ES1_0) {
  133. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  134. return -ENODEV;
  135. }
  136. pr_err("Power Management for TI OMAP4.\n");
  137. /*
  138. * OMAP4 chip PM currently works only with certain (newer)
  139. * versions of bootloaders. This is due to missing code in the
  140. * kernel to properly reset and initialize some devices.
  141. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  142. */
  143. pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  144. ret = pwrdm_for_each(pwrdms_setup, NULL);
  145. if (ret) {
  146. pr_err("Failed to setup powerdomains\n");
  147. goto err2;
  148. }
  149. /*
  150. * The dynamic dependency between MPUSS -> MEMIF and
  151. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  152. * expected. The hardware recommendation is to enable static
  153. * dependencies for these to avoid system lock ups or random crashes.
  154. * The L4 wakeup depedency is added to workaround the OCP sync hardware
  155. * BUG with 32K synctimer which lead to incorrect timer value read
  156. * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
  157. * are part of L4 wakeup clockdomain.
  158. */
  159. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  160. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  161. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  162. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  163. l4_per_clkdm = clkdm_lookup("l4_per_clkdm");
  164. l4wkup = clkdm_lookup("l4_wkup_clkdm");
  165. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  166. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) || (!l4wkup) ||
  167. (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm))
  168. goto err2;
  169. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  170. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  171. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  172. ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm);
  173. ret |= clkdm_add_wkdep(mpuss_clkdm, l4wkup);
  174. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  175. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  176. if (ret) {
  177. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 wakeup dependency\n");
  178. goto err2;
  179. }
  180. ret = omap4_mpuss_init();
  181. if (ret) {
  182. pr_err("Failed to initialise OMAP4 MPUSS\n");
  183. goto err2;
  184. }
  185. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  186. #ifdef CONFIG_SUSPEND
  187. omap_pm_suspend = omap4_pm_suspend;
  188. #endif
  189. /* Overwrite the default cpu_do_idle() */
  190. arm_pm_idle = omap_default_idle;
  191. omap4_idle_init();
  192. err2:
  193. return ret;
  194. }