pm.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * pm.c - Common OMAP2+ power management-related code
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc.
  5. * Copyright (C) 2010 Nokia Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/err.h>
  15. #include <linux/opp.h>
  16. #include <linux/export.h>
  17. #include <plat/omap-pm.h>
  18. #include <plat/omap_device.h>
  19. #include "common.h"
  20. #include "voltage.h"
  21. #include "powerdomain.h"
  22. #include "clockdomain.h"
  23. #include "pm.h"
  24. #include "twl-common.h"
  25. static struct omap_device_pm_latency *pm_lats;
  26. static int __init _init_omap_device(char *name)
  27. {
  28. struct omap_hwmod *oh;
  29. struct platform_device *pdev;
  30. oh = omap_hwmod_lookup(name);
  31. if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
  32. __func__, name))
  33. return -ENODEV;
  34. pdev = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
  35. if (WARN(IS_ERR(pdev), "%s: could not build omap_device for %s\n",
  36. __func__, name))
  37. return -ENODEV;
  38. return 0;
  39. }
  40. /*
  41. * Build omap_devices for processors and bus.
  42. */
  43. static void omap2_init_processor_devices(void)
  44. {
  45. _init_omap_device("mpu");
  46. if (omap3_has_iva())
  47. _init_omap_device("iva");
  48. if (cpu_is_omap44xx()) {
  49. _init_omap_device("l3_main_1");
  50. _init_omap_device("dsp");
  51. _init_omap_device("iva");
  52. } else {
  53. _init_omap_device("l3_main");
  54. }
  55. }
  56. /* Types of sleep_switch used in omap_set_pwrdm_state */
  57. #define FORCEWAKEUP_SWITCH 0
  58. #define LOWPOWERSTATE_SWITCH 1
  59. int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
  60. {
  61. if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
  62. clkdm_allow_idle(clkdm);
  63. else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
  64. atomic_read(&clkdm->usecount) == 0)
  65. clkdm_sleep(clkdm);
  66. return 0;
  67. }
  68. /*
  69. * This sets pwrdm state (other than mpu & core. Currently only ON &
  70. * RET are supported.
  71. */
  72. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 pwrst)
  73. {
  74. u8 curr_pwrst, next_pwrst;
  75. int sleep_switch = -1, ret = 0, hwsup = 0;
  76. if (!pwrdm || IS_ERR(pwrdm))
  77. return -EINVAL;
  78. while (!(pwrdm->pwrsts & (1 << pwrst))) {
  79. if (pwrst == PWRDM_POWER_OFF)
  80. return ret;
  81. pwrst--;
  82. }
  83. next_pwrst = pwrdm_read_next_pwrst(pwrdm);
  84. if (next_pwrst == pwrst)
  85. return ret;
  86. curr_pwrst = pwrdm_read_pwrst(pwrdm);
  87. if (curr_pwrst < PWRDM_POWER_ON) {
  88. if ((curr_pwrst > pwrst) &&
  89. (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
  90. sleep_switch = LOWPOWERSTATE_SWITCH;
  91. } else {
  92. hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
  93. clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  94. sleep_switch = FORCEWAKEUP_SWITCH;
  95. }
  96. }
  97. ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
  98. if (ret)
  99. pr_err("%s: unable to set power state of powerdomain: %s\n",
  100. __func__, pwrdm->name);
  101. switch (sleep_switch) {
  102. case FORCEWAKEUP_SWITCH:
  103. if (hwsup)
  104. clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  105. else
  106. clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  107. break;
  108. case LOWPOWERSTATE_SWITCH:
  109. pwrdm_set_lowpwrstchange(pwrdm);
  110. pwrdm_wait_transition(pwrdm);
  111. pwrdm_state_switch(pwrdm);
  112. break;
  113. }
  114. return ret;
  115. }
  116. /*
  117. * This API is to be called during init to set the various voltage
  118. * domains to the voltage as per the opp table. Typically we boot up
  119. * at the nominal voltage. So this function finds out the rate of
  120. * the clock associated with the voltage domain, finds out the correct
  121. * opp entry and sets the voltage domain to the voltage specified
  122. * in the opp entry
  123. */
  124. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  125. const char *oh_name)
  126. {
  127. struct voltagedomain *voltdm;
  128. struct clk *clk;
  129. struct opp *opp;
  130. unsigned long freq, bootup_volt;
  131. struct device *dev;
  132. if (!vdd_name || !clk_name || !oh_name) {
  133. pr_err("%s: invalid parameters\n", __func__);
  134. goto exit;
  135. }
  136. dev = omap_device_get_by_hwmod_name(oh_name);
  137. if (IS_ERR(dev)) {
  138. pr_err("%s: Unable to get dev pointer for hwmod %s\n",
  139. __func__, oh_name);
  140. goto exit;
  141. }
  142. voltdm = voltdm_lookup(vdd_name);
  143. if (IS_ERR(voltdm)) {
  144. pr_err("%s: unable to get vdd pointer for vdd_%s\n",
  145. __func__, vdd_name);
  146. goto exit;
  147. }
  148. clk = clk_get(NULL, clk_name);
  149. if (IS_ERR(clk)) {
  150. pr_err("%s: unable to get clk %s\n", __func__, clk_name);
  151. goto exit;
  152. }
  153. freq = clk->rate;
  154. clk_put(clk);
  155. opp = opp_find_freq_ceil(dev, &freq);
  156. if (IS_ERR(opp)) {
  157. pr_err("%s: unable to find boot up OPP for vdd_%s\n",
  158. __func__, vdd_name);
  159. goto exit;
  160. }
  161. bootup_volt = opp_get_voltage(opp);
  162. if (!bootup_volt) {
  163. pr_err("%s: unable to find voltage corresponding "
  164. "to the bootup OPP for vdd_%s\n", __func__, vdd_name);
  165. goto exit;
  166. }
  167. voltdm_scale(voltdm, bootup_volt);
  168. return 0;
  169. exit:
  170. pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
  171. return -EINVAL;
  172. }
  173. static void __init omap3_init_voltages(void)
  174. {
  175. if (!cpu_is_omap34xx())
  176. return;
  177. omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
  178. omap2_set_init_voltage("core", "l3_ick", "l3_main");
  179. }
  180. static void __init omap4_init_voltages(void)
  181. {
  182. if (!cpu_is_omap44xx())
  183. return;
  184. omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
  185. omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
  186. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
  187. }
  188. static int __init omap2_common_pm_init(void)
  189. {
  190. if (!of_have_populated_dt())
  191. omap2_init_processor_devices();
  192. omap_pm_if_init();
  193. return 0;
  194. }
  195. postcore_initcall(omap2_common_pm_init);
  196. static int __init omap2_common_pm_late_init(void)
  197. {
  198. /* Init the voltage layer */
  199. omap_pmic_late_init();
  200. omap_voltage_late_init();
  201. /* Initialize the voltages */
  202. omap3_init_voltages();
  203. omap4_init_voltages();
  204. /* Smartreflex device init */
  205. omap_devinit_smartreflex();
  206. return 0;
  207. }
  208. late_initcall(omap2_common_pm_late_init);