pm44xx.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 "common.h"
  19. #include "clockdomain.h"
  20. #include "powerdomain.h"
  21. #include "pm.h"
  22. struct power_state {
  23. struct powerdomain *pwrdm;
  24. u32 next_state;
  25. #ifdef CONFIG_SUSPEND
  26. u32 saved_state;
  27. u32 saved_logic_state;
  28. #endif
  29. struct list_head node;
  30. };
  31. static LIST_HEAD(pwrst_list);
  32. #ifdef CONFIG_SUSPEND
  33. static int omap4_pm_suspend(void)
  34. {
  35. struct power_state *pwrst;
  36. int state, ret = 0;
  37. u32 cpu_id = smp_processor_id();
  38. /* Save current powerdomain state */
  39. list_for_each_entry(pwrst, &pwrst_list, node) {
  40. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  41. pwrst->saved_logic_state = pwrdm_read_logic_retst(pwrst->pwrdm);
  42. }
  43. /* Set targeted power domain states by suspend */
  44. list_for_each_entry(pwrst, &pwrst_list, node) {
  45. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  46. pwrdm_set_logic_retst(pwrst->pwrdm, PWRDM_POWER_OFF);
  47. }
  48. /*
  49. * For MPUSS to hit power domain retention(CSWR or OSWR),
  50. * CPU0 and CPU1 power domains need to be in OFF or DORMANT state,
  51. * since CPU power domain CSWR is not supported by hardware
  52. * Only master CPU follows suspend path. All other CPUs follow
  53. * CPU hotplug path in system wide suspend. On OMAP4, CPU power
  54. * domain CSWR is not supported by hardware.
  55. * More details can be found in OMAP4430 TRM section 4.3.4.2.
  56. */
  57. omap4_enter_lowpower(cpu_id, PWRDM_POWER_OFF);
  58. /* Restore next powerdomain state */
  59. list_for_each_entry(pwrst, &pwrst_list, node) {
  60. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  61. if (state > pwrst->next_state) {
  62. pr_info("Powerdomain (%s) didn't enter "
  63. "target state %d\n",
  64. pwrst->pwrdm->name, pwrst->next_state);
  65. ret = -1;
  66. }
  67. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  68. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->saved_logic_state);
  69. }
  70. if (ret)
  71. pr_crit("Could not enter target state in pm_suspend\n");
  72. else
  73. pr_info("Successfully put all powerdomains to target state\n");
  74. return 0;
  75. }
  76. #endif /* CONFIG_SUSPEND */
  77. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  78. {
  79. struct power_state *pwrst;
  80. if (!pwrdm->pwrsts)
  81. return 0;
  82. /*
  83. * Skip CPU0 and CPU1 power domains. CPU1 is programmed
  84. * through hotplug path and CPU0 explicitly programmed
  85. * further down in the code path
  86. */
  87. if (!strncmp(pwrdm->name, "cpu", 3))
  88. return 0;
  89. /*
  90. * FIXME: Remove this check when core retention is supported
  91. * Only MPUSS power domain is added in the list.
  92. */
  93. if (strcmp(pwrdm->name, "mpu_pwrdm"))
  94. return 0;
  95. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  96. if (!pwrst)
  97. return -ENOMEM;
  98. pwrst->pwrdm = pwrdm;
  99. pwrst->next_state = PWRDM_POWER_RET;
  100. list_add(&pwrst->node, &pwrst_list);
  101. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  102. }
  103. /**
  104. * omap_default_idle - OMAP4 default ilde routine.'
  105. *
  106. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  107. * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPUIDLE and
  108. * by secondary CPU with CONFIG_CPUIDLE.
  109. */
  110. static void omap_default_idle(void)
  111. {
  112. local_fiq_disable();
  113. omap_do_wfi();
  114. local_fiq_enable();
  115. }
  116. /**
  117. * omap4_pm_init - Init routine for OMAP4 PM
  118. *
  119. * Initializes all powerdomain and clockdomain target states
  120. * and all PRCM settings.
  121. */
  122. static int __init omap4_pm_init(void)
  123. {
  124. int ret;
  125. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm;
  126. struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm;
  127. if (!cpu_is_omap44xx())
  128. return -ENODEV;
  129. if (omap_rev() == OMAP4430_REV_ES1_0) {
  130. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  131. return -ENODEV;
  132. }
  133. pr_err("Power Management for TI OMAP4.\n");
  134. ret = pwrdm_for_each(pwrdms_setup, NULL);
  135. if (ret) {
  136. pr_err("Failed to setup powerdomains\n");
  137. goto err2;
  138. }
  139. /*
  140. * The dynamic dependency between MPUSS -> MEMIF and
  141. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  142. * expected. The hardware recommendation is to enable static
  143. * dependencies for these to avoid system lock ups or random crashes.
  144. */
  145. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  146. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  147. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  148. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  149. l4_per_clkdm = clkdm_lookup("l4_per_clkdm");
  150. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  151. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) ||
  152. (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm))
  153. goto err2;
  154. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  155. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  156. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  157. ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm);
  158. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  159. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  160. if (ret) {
  161. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 "
  162. "wakeup dependency\n");
  163. goto err2;
  164. }
  165. ret = omap4_mpuss_init();
  166. if (ret) {
  167. pr_err("Failed to initialise OMAP4 MPUSS\n");
  168. goto err2;
  169. }
  170. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  171. #ifdef CONFIG_SUSPEND
  172. omap_pm_suspend = omap4_pm_suspend;
  173. #endif
  174. /* Overwrite the default cpu_do_idle() */
  175. arm_pm_idle = omap_default_idle;
  176. omap4_idle_init();
  177. err2:
  178. return ret;
  179. }
  180. late_initcall(omap4_pm_init);