pm44xx.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. /*
  118. * Bootloader or kexec boot may have LOGICRETSTATE cleared
  119. * for some domains. This is the case when kexec booting from
  120. * Android kernels that support off mode for example.
  121. * Make sure it's set at least for core and per, otherwise
  122. * we currently will see lost GPIO interrupts for wlcore and
  123. * smsc911x at least if per hits retention during idle.
  124. */
  125. if (!strncmp(pwrdm->name, "core", 4) ||
  126. !strncmp(pwrdm->name, "l4per", 5) ||
  127. !strncmp(pwrdm->name, "wkup", 4))
  128. pwrdm_set_logic_retst(pwrdm, PWRDM_POWER_RET);
  129. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  130. if (!pwrst)
  131. return -ENOMEM;
  132. pwrst->pwrdm = pwrdm;
  133. pwrst->next_state = pwrdm_get_valid_lp_state(pwrdm, false,
  134. PWRDM_POWER_RET);
  135. pwrst->next_logic_state = pwrdm_get_valid_lp_state(pwrdm, true,
  136. PWRDM_POWER_OFF);
  137. list_add(&pwrst->node, &pwrst_list);
  138. return omap_set_pwrdm_state(pwrst->pwrdm, pwrst->next_state);
  139. }
  140. /**
  141. * omap_default_idle - OMAP4 default ilde routine.'
  142. *
  143. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  144. * with default cpu_do_idle() hook. Used by all CPUs with !CONFIG_CPU_IDLE and
  145. * by secondary CPU with CONFIG_CPU_IDLE.
  146. */
  147. static void omap_default_idle(void)
  148. {
  149. omap_do_wfi();
  150. }
  151. /*
  152. * The dynamic dependency between MPUSS -> MEMIF and
  153. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  154. * expected. The hardware recommendation is to enable static
  155. * dependencies for these to avoid system lock ups or random crashes.
  156. * The L4 wakeup depedency is added to workaround the OCP sync hardware
  157. * BUG with 32K synctimer which lead to incorrect timer value read
  158. * from the 32K counter. The BUG applies for GPTIMER1 and WDT2 which
  159. * are part of L4 wakeup clockdomain.
  160. */
  161. static const struct static_dep_map omap4_static_dep_map[] = {
  162. {.from = "mpuss_clkdm", .to = "l3_emif_clkdm"},
  163. {.from = "mpuss_clkdm", .to = "l3_1_clkdm"},
  164. {.from = "mpuss_clkdm", .to = "l3_2_clkdm"},
  165. {.from = "ducati_clkdm", .to = "l3_1_clkdm"},
  166. {.from = "ducati_clkdm", .to = "l3_2_clkdm"},
  167. {.from = NULL} /* TERMINATION */
  168. };
  169. static const struct static_dep_map omap5_dra7_static_dep_map[] = {
  170. {.from = "mpu_clkdm", .to = "emif_clkdm"},
  171. {.from = NULL} /* TERMINATION */
  172. };
  173. /**
  174. * omap4plus_init_static_deps() - Initialize a static dependency map
  175. * @map: Mapping of clock domains
  176. */
  177. static inline int omap4plus_init_static_deps(const struct static_dep_map *map)
  178. {
  179. int ret;
  180. struct clockdomain *from, *to;
  181. if (!map)
  182. return 0;
  183. while (map->from) {
  184. from = clkdm_lookup(map->from);
  185. to = clkdm_lookup(map->to);
  186. if (!from || !to) {
  187. pr_err("Failed lookup %s or %s for wakeup dependency\n",
  188. map->from, map->to);
  189. return -EINVAL;
  190. }
  191. ret = clkdm_add_wkdep(from, to);
  192. if (ret) {
  193. pr_err("Failed to add %s -> %s wakeup dependency(%d)\n",
  194. map->from, map->to, ret);
  195. return ret;
  196. }
  197. map++;
  198. }
  199. return 0;
  200. }
  201. /**
  202. * omap4_pm_init_early - Does early initialization necessary for OMAP4+ devices
  203. *
  204. * Initializes basic stuff for power management functionality.
  205. */
  206. int __init omap4_pm_init_early(void)
  207. {
  208. if (cpu_is_omap446x())
  209. pm44xx_errata |= PM_OMAP4_ROM_SMP_BOOT_ERRATUM_GICD;
  210. if (soc_is_omap54xx() || soc_is_dra7xx())
  211. pm44xx_errata |= PM_OMAP4_CPU_OSWR_DISABLE;
  212. return 0;
  213. }
  214. /**
  215. * omap4_pm_init - Init routine for OMAP4+ devices
  216. *
  217. * Initializes all powerdomain and clockdomain target states
  218. * and all PRCM settings.
  219. * Return: Returns the error code returned by called functions.
  220. */
  221. int __init omap4_pm_init(void)
  222. {
  223. int ret = 0;
  224. if (omap_rev() == OMAP4430_REV_ES1_0) {
  225. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  226. return -ENODEV;
  227. }
  228. pr_info("Power Management for TI OMAP4+ devices.\n");
  229. /*
  230. * OMAP4 chip PM currently works only with certain (newer)
  231. * versions of bootloaders. This is due to missing code in the
  232. * kernel to properly reset and initialize some devices.
  233. * http://www.spinics.net/lists/arm-kernel/msg218641.html
  234. */
  235. if (cpu_is_omap44xx())
  236. pr_warn("OMAP4 PM: u-boot >= v2012.07 is required for full PM support\n");
  237. ret = pwrdm_for_each(pwrdms_setup, NULL);
  238. if (ret) {
  239. pr_err("Failed to setup powerdomains.\n");
  240. goto err2;
  241. }
  242. if (cpu_is_omap44xx())
  243. ret = omap4plus_init_static_deps(omap4_static_dep_map);
  244. else if (soc_is_omap54xx() || soc_is_dra7xx())
  245. ret = omap4plus_init_static_deps(omap5_dra7_static_dep_map);
  246. if (ret) {
  247. pr_err("Failed to initialise static dependencies.\n");
  248. goto err2;
  249. }
  250. ret = omap4_mpuss_init();
  251. if (ret) {
  252. pr_err("Failed to initialise OMAP4 MPUSS\n");
  253. goto err2;
  254. }
  255. (void) clkdm_for_each(omap_pm_clkdms_setup, NULL);
  256. omap_common_suspend_init(omap4_pm_suspend);
  257. /* Overwrite the default cpu_do_idle() */
  258. arm_pm_idle = omap_default_idle;
  259. if (cpu_is_omap44xx() || soc_is_omap54xx())
  260. omap4_idle_init();
  261. err2:
  262. return ret;
  263. }