pm44xx.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. /**
  36. * struct static_dep_map - Static dependency map
  37. * @from: from clockdomain
  38. * @to: to clockdomain
  39. */
  40. struct static_dep_map {
  41. const char *from;
  42. const char *to;
  43. };
  44. static u32 cpu_suspend_state = PWRDM_POWER_OFF;
  45. static LIST_HEAD(pwrst_list);
  46. #ifdef CONFIG_SUSPEND
  47. static int omap4_pm_suspend(void)
  48. {
  49. struct power_state *pwrst;
  50. int state, ret = 0;
  51. u32 cpu_id = smp_processor_id();
  52. /* Save current powerdomain state */
  53. list_for_each_entry(pwrst, &pwrst_list, node) {
  54. pwrst->saved_state = pwrdm_read_next_pwrst(pwrst->pwrdm);
  55. pwrst->saved_logic_state = pwrdm_read_logic_retst(pwrst->pwrdm);
  56. }
  57. /* Set targeted power domain states by suspend */
  58. list_for_each_entry(pwrst, &pwrst_list, node) {
  59. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  60. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->next_logic_state);
  61. }
  62. /*
  63. * For MPUSS to hit power domain retention(CSWR or OSWR),
  64. * CPU0 and CPU1 power domains need to be in OFF or DORMANT state,
  65. * since CPU power domain CSWR is not supported by hardware
  66. * Only master CPU follows suspend path. All other CPUs follow
  67. * CPU hotplug path in system wide suspend. On OMAP4, CPU power
  68. * domain CSWR is not supported by hardware.
  69. * More details can be found in OMAP4430 TRM section 4.3.4.2.
  70. */
  71. omap4_enter_lowpower(cpu_id, cpu_suspend_state);
  72. /* Restore next powerdomain state */
  73. list_for_each_entry(pwrst, &pwrst_list, node) {
  74. state = pwrdm_read_prev_pwrst(pwrst->pwrdm);
  75. if (state > pwrst->next_state) {
  76. pr_info("Powerdomain (%s) didn't enter target state %d\n",
  77. pwrst->pwrdm->name, pwrst->next_state);
  78. ret = -1;
  79. }
  80. omap_set_pwrdm_state(pwrst->pwrdm, pwrst->saved_state);
  81. pwrdm_set_logic_retst(pwrst->pwrdm, pwrst->saved_logic_state);
  82. }
  83. if (ret) {
  84. pr_crit("Could not enter target state in pm_suspend\n");
  85. /*
  86. * OMAP4 chip PM currently works only with certain (newer)
  87. * versions of bootloaders. This is due to missing code in the
  88. * kernel to properly reset and initialize some devices.
  89. * Warn the user about the bootloader version being one of the
  90. * possible causes.
  91. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  92. */
  93. pr_warn("A possible cause could be an old bootloader - try u-boot >= v2012.07\n");
  94. } else {
  95. pr_info("Successfully put all powerdomains to target state\n");
  96. }
  97. return 0;
  98. }
  99. #else
  100. #define omap4_pm_suspend NULL
  101. #endif /* CONFIG_SUSPEND */
  102. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  103. {
  104. struct power_state *pwrst;
  105. if (!pwrdm->pwrsts)
  106. return 0;
  107. /*
  108. * Skip CPU0 and CPU1 power domains. CPU1 is programmed
  109. * through hotplug path and CPU0 explicitly programmed
  110. * further down in the code path
  111. */
  112. if (!strncmp(pwrdm->name, "cpu", 3)) {
  113. if (IS_PM44XX_ERRATUM(PM_OMAP4_CPU_OSWR_DISABLE))
  114. cpu_suspend_state = PWRDM_POWER_RET;
  115. return 0;
  116. }
  117. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  118. if (!pwrst)
  119. return -ENOMEM;
  120. pwrst->pwrdm = pwrdm;
  121. pwrst->next_state = pwrdm_get_valid_lp_state(pwrdm, false,
  122. PWRDM_POWER_RET);
  123. pwrst->next_logic_state = pwrdm_get_valid_lp_state(pwrdm, true,
  124. PWRDM_POWER_OFF);
  125. list_add(&pwrst->node, &pwrst_list);
  126. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  127. }
  128. /**
  129. * omap_default_idle - OMAP4 default ilde routine.'
  130. *
  131. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  132. * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPU_IDLE and
  133. * by secondary CPU with CONFIG_CPU_IDLE.
  134. */
  135. static void omap_default_idle(void)
  136. {
  137. omap_do_wfi();
  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. * The L4 wakeup depedency is added to workaround the OCP sync hardware
  145. * BUG with 32K synctimer which lead to incorrect timer value read
  146. * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
  147. * are part of L4 wakeup clockdomain.
  148. */
  149. static const struct static_dep_map omap4_static_dep_map[] = {
  150. {.from = "mpuss_clkdm", .to = "l3_emif_clkdm"},
  151. {.from = "mpuss_clkdm", .to = "l3_1_clkdm"},
  152. {.from = "mpuss_clkdm", .to = "l3_2_clkdm"},
  153. {.from = "ducati_clkdm", .to = "l3_1_clkdm"},
  154. {.from = "ducati_clkdm", .to = "l3_2_clkdm"},
  155. {.from = NULL} /* TERMINATION */
  156. };
  157. static const struct static_dep_map omap5_dra7_static_dep_map[] = {
  158. {.from = "mpu_clkdm", .to = "emif_clkdm"},
  159. {.from = NULL} /* TERMINATION */
  160. };
  161. /**
  162. * omap4plus_init_static_deps() - Initialize a static dependency map
  163. * @map: Mapping of clock domains
  164. */
  165. static inline int omap4plus_init_static_deps(const struct static_dep_map *map)
  166. {
  167. int ret;
  168. struct clockdomain *from, *to;
  169. if (!map)
  170. return 0;
  171. while (map->from) {
  172. from = clkdm_lookup(map->from);
  173. to = clkdm_lookup(map->to);
  174. if (!from || !to) {
  175. pr_err("Failed lookup %s or %s for wakeup dependency\n",
  176. map->from, map->to);
  177. return -EINVAL;
  178. }
  179. ret = clkdm_add_wkdep(from, to);
  180. if (ret) {
  181. pr_err("Failed to add %s -> %s wakeup dependency(%d)\n",
  182. map->from, map->to, ret);
  183. return ret;
  184. }
  185. map++;
  186. }
  187. return 0;
  188. }
  189. /**
  190. * omap4_pm_init_early - Does early initialization necessary for OMAP4+ devices
  191. *
  192. * Initializes basic stuff for power management functionality.
  193. */
  194. int __init omap4_pm_init_early(void)
  195. {
  196. if (cpu_is_omap446x())
  197. pm44xx_errata |= PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD;
  198. if (soc_is_omap54xx() || soc_is_dra7xx())
  199. pm44xx_errata |= PM_OMAP4_CPU_OSWR_DISABLE;
  200. return 0;
  201. }
  202. /**
  203. * omap4_pm_init - Init routine for OMAP4+ devices
  204. *
  205. * Initializes all powerdomain and clockdomain target states
  206. * and all PRCM settings.
  207. * Return: Returns the error code returned by called functions.
  208. */
  209. int __init omap4_pm_init(void)
  210. {
  211. int ret = 0;
  212. if (omap_rev() == OMAP4430_REV_ES1_0) {
  213. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  214. return -ENODEV;
  215. }
  216. pr_info("Power Management for TI OMAP4+ devices.\n");
  217. /*
  218. * OMAP4 chip PM currently works only with certain (newer)
  219. * versions of bootloaders. This is due to missing code in the
  220. * kernel to properly reset and initialize some devices.
  221. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  222. */
  223. if (cpu_is_omap44xx())
  224. pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  225. ret = pwrdm_for_each(pwrdms_setup, NULL);
  226. if (ret) {
  227. pr_err("Failed to setup powerdomains.\n");
  228. goto err2;
  229. }
  230. if (cpu_is_omap44xx())
  231. ret = omap4plus_init_static_deps(omap4_static_dep_map);
  232. else if (soc_is_omap54xx() || soc_is_dra7xx())
  233. ret = omap4plus_init_static_deps(omap5_dra7_static_dep_map);
  234. if (ret) {
  235. pr_err("Failed to initialise static dependencies.\n");
  236. goto err2;
  237. }
  238. ret = omap4_mpuss_init();
  239. if (ret) {
  240. pr_err("Failed to initialise OMAP4 MPUSS\n");
  241. goto err2;
  242. }
  243. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  244. omap_common_suspend_init(omap4_pm_suspend);
  245. /* Overwrite the default cpu_do_idle() */
  246. arm_pm_idle = omap_default_idle;
  247. if (cpu_is_omap44xx())
  248. omap4_idle_init();
  249. err2:
  250. return ret;
  251. }