pm.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. /*
  60. * This sets pwrdm state (other than mpu & core. Currently only ON &
  61. * RET are supported.
  62. */
  63. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 pwrst)
  64. {
  65. u8 curr_pwrst, next_pwrst;
  66. int sleep_switch = -1, ret = 0, hwsup = 0;
  67. if (!pwrdm || IS_ERR(pwrdm))
  68. return -EINVAL;
  69. while (!(pwrdm->pwrsts & (1 << pwrst))) {
  70. if (pwrst == PWRDM_POWER_OFF)
  71. return ret;
  72. pwrst--;
  73. }
  74. next_pwrst = pwrdm_read_next_pwrst(pwrdm);
  75. if (next_pwrst == pwrst)
  76. return ret;
  77. curr_pwrst = pwrdm_read_pwrst(pwrdm);
  78. if (curr_pwrst < PWRDM_POWER_ON) {
  79. if ((curr_pwrst > pwrst) &&
  80. (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
  81. sleep_switch = LOWPOWERSTATE_SWITCH;
  82. } else {
  83. hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
  84. clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  85. sleep_switch = FORCEWAKEUP_SWITCH;
  86. }
  87. }
  88. ret = pwrdm_set_next_pwrst(pwrdm, pwrst);
  89. if (ret)
  90. pr_err("%s: unable to set power state of powerdomain: %s\n",
  91. __func__, pwrdm->name);
  92. switch (sleep_switch) {
  93. case FORCEWAKEUP_SWITCH:
  94. if (hwsup)
  95. clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  96. else
  97. clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  98. break;
  99. case LOWPOWERSTATE_SWITCH:
  100. pwrdm_set_lowpwrstchange(pwrdm);
  101. pwrdm_wait_transition(pwrdm);
  102. pwrdm_state_switch(pwrdm);
  103. break;
  104. }
  105. return ret;
  106. }
  107. /*
  108. * This API is to be called during init to set the various voltage
  109. * domains to the voltage as per the opp table. Typically we boot up
  110. * at the nominal voltage. So this function finds out the rate of
  111. * the clock associated with the voltage domain, finds out the correct
  112. * opp entry and sets the voltage domain to the voltage specified
  113. * in the opp entry
  114. */
  115. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  116. const char *oh_name)
  117. {
  118. struct voltagedomain *voltdm;
  119. struct clk *clk;
  120. struct opp *opp;
  121. unsigned long freq, bootup_volt;
  122. struct device *dev;
  123. if (!vdd_name || !clk_name || !oh_name) {
  124. pr_err("%s: invalid parameters\n", __func__);
  125. goto exit;
  126. }
  127. dev = omap_device_get_by_hwmod_name(oh_name);
  128. if (IS_ERR(dev)) {
  129. pr_err("%s: Unable to get dev pointer for hwmod %s\n",
  130. __func__, oh_name);
  131. goto exit;
  132. }
  133. voltdm = voltdm_lookup(vdd_name);
  134. if (IS_ERR(voltdm)) {
  135. pr_err("%s: unable to get vdd pointer for vdd_%s\n",
  136. __func__, vdd_name);
  137. goto exit;
  138. }
  139. clk = clk_get(NULL, clk_name);
  140. if (IS_ERR(clk)) {
  141. pr_err("%s: unable to get clk %s\n", __func__, clk_name);
  142. goto exit;
  143. }
  144. freq = clk->rate;
  145. clk_put(clk);
  146. opp = opp_find_freq_ceil(dev, &freq);
  147. if (IS_ERR(opp)) {
  148. pr_err("%s: unable to find boot up OPP for vdd_%s\n",
  149. __func__, vdd_name);
  150. goto exit;
  151. }
  152. bootup_volt = opp_get_voltage(opp);
  153. if (!bootup_volt) {
  154. pr_err("%s: unable to find voltage corresponding "
  155. "to the bootup OPP for vdd_%s\n", __func__, vdd_name);
  156. goto exit;
  157. }
  158. voltdm_scale(voltdm, bootup_volt);
  159. return 0;
  160. exit:
  161. pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
  162. return -EINVAL;
  163. }
  164. static void __init omap3_init_voltages(void)
  165. {
  166. if (!cpu_is_omap34xx())
  167. return;
  168. omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
  169. omap2_set_init_voltage("core", "l3_ick", "l3_main");
  170. }
  171. static void __init omap4_init_voltages(void)
  172. {
  173. if (!cpu_is_omap44xx())
  174. return;
  175. omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
  176. omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
  177. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
  178. }
  179. static int __init omap2_common_pm_init(void)
  180. {
  181. if (!of_have_populated_dt())
  182. omap2_init_processor_devices();
  183. omap_pm_if_init();
  184. return 0;
  185. }
  186. postcore_initcall(omap2_common_pm_init);
  187. static int __init omap2_common_pm_late_init(void)
  188. {
  189. /* Init the voltage layer */
  190. omap_pmic_late_init();
  191. omap_voltage_late_init();
  192. /* Initialize the voltages */
  193. omap3_init_voltages();
  194. omap4_init_voltages();
  195. /* Smartreflex device init */
  196. omap_devinit_smartreflex();
  197. return 0;
  198. }
  199. late_initcall(omap2_common_pm_late_init);