pm.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 <plat/omap-pm.h>
  17. #include <plat/omap_device.h>
  18. #include <plat/common.h>
  19. #include "voltage.h"
  20. #include "powerdomain.h"
  21. #include "clockdomain.h"
  22. #include "pm.h"
  23. static struct omap_device_pm_latency *pm_lats;
  24. static struct device *mpu_dev;
  25. static struct device *iva_dev;
  26. static struct device *l3_dev;
  27. static struct device *dsp_dev;
  28. struct device *omap2_get_mpuss_device(void)
  29. {
  30. WARN_ON_ONCE(!mpu_dev);
  31. return mpu_dev;
  32. }
  33. struct device *omap2_get_iva_device(void)
  34. {
  35. WARN_ON_ONCE(!iva_dev);
  36. return iva_dev;
  37. }
  38. struct device *omap2_get_l3_device(void)
  39. {
  40. WARN_ON_ONCE(!l3_dev);
  41. return l3_dev;
  42. }
  43. struct device *omap4_get_dsp_device(void)
  44. {
  45. WARN_ON_ONCE(!dsp_dev);
  46. return dsp_dev;
  47. }
  48. EXPORT_SYMBOL(omap4_get_dsp_device);
  49. /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
  50. static int _init_omap_device(char *name, struct device **new_dev)
  51. {
  52. struct omap_hwmod *oh;
  53. struct omap_device *od;
  54. oh = omap_hwmod_lookup(name);
  55. if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
  56. __func__, name))
  57. return -ENODEV;
  58. od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
  59. if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
  60. __func__, name))
  61. return -ENODEV;
  62. *new_dev = &od->pdev.dev;
  63. return 0;
  64. }
  65. /*
  66. * Build omap_devices for processors and bus.
  67. */
  68. static void omap2_init_processor_devices(void)
  69. {
  70. _init_omap_device("mpu", &mpu_dev);
  71. if (omap3_has_iva())
  72. _init_omap_device("iva", &iva_dev);
  73. if (cpu_is_omap44xx()) {
  74. _init_omap_device("l3_main_1", &l3_dev);
  75. _init_omap_device("dsp", &dsp_dev);
  76. _init_omap_device("iva", &iva_dev);
  77. } else {
  78. _init_omap_device("l3_main", &l3_dev);
  79. }
  80. }
  81. /* Types of sleep_switch used in omap_set_pwrdm_state */
  82. #define FORCEWAKEUP_SWITCH 0
  83. #define LOWPOWERSTATE_SWITCH 1
  84. /*
  85. * This sets pwrdm state (other than mpu & core. Currently only ON &
  86. * RET are supported.
  87. */
  88. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
  89. {
  90. u32 cur_state;
  91. int sleep_switch = -1;
  92. int ret = 0;
  93. int hwsup = 0;
  94. if (pwrdm == NULL || IS_ERR(pwrdm))
  95. return -EINVAL;
  96. while (!(pwrdm->pwrsts & (1 << state))) {
  97. if (state == PWRDM_POWER_OFF)
  98. return ret;
  99. state--;
  100. }
  101. cur_state = pwrdm_read_next_pwrst(pwrdm);
  102. if (cur_state == state)
  103. return ret;
  104. if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
  105. if ((pwrdm_read_pwrst(pwrdm) > state) &&
  106. (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
  107. sleep_switch = LOWPOWERSTATE_SWITCH;
  108. } else {
  109. hwsup = clkdm_in_hwsup(pwrdm->pwrdm_clkdms[0]);
  110. clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  111. pwrdm_wait_transition(pwrdm);
  112. sleep_switch = FORCEWAKEUP_SWITCH;
  113. }
  114. }
  115. ret = pwrdm_set_next_pwrst(pwrdm, state);
  116. if (ret) {
  117. printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
  118. pwrdm->name);
  119. goto err;
  120. }
  121. switch (sleep_switch) {
  122. case FORCEWAKEUP_SWITCH:
  123. if (hwsup)
  124. clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  125. else
  126. clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  127. break;
  128. case LOWPOWERSTATE_SWITCH:
  129. pwrdm_set_lowpwrstchange(pwrdm);
  130. break;
  131. default:
  132. return ret;
  133. }
  134. pwrdm_wait_transition(pwrdm);
  135. pwrdm_state_switch(pwrdm);
  136. err:
  137. return ret;
  138. }
  139. /*
  140. * This API is to be called during init to put the various voltage
  141. * domains to the voltage as per the opp table. Typically we boot up
  142. * at the nominal voltage. So this function finds out the rate of
  143. * the clock associated with the voltage domain, finds out the correct
  144. * opp entry and puts the voltage domain to the voltage specifies
  145. * in the opp entry
  146. */
  147. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  148. struct device *dev)
  149. {
  150. struct voltagedomain *voltdm;
  151. struct clk *clk;
  152. struct opp *opp;
  153. unsigned long freq, bootup_volt;
  154. if (!vdd_name || !clk_name || !dev) {
  155. printk(KERN_ERR "%s: Invalid parameters!\n", __func__);
  156. goto exit;
  157. }
  158. voltdm = omap_voltage_domain_lookup(vdd_name);
  159. if (IS_ERR(voltdm)) {
  160. printk(KERN_ERR "%s: Unable to get vdd pointer for vdd_%s\n",
  161. __func__, vdd_name);
  162. goto exit;
  163. }
  164. clk = clk_get(NULL, clk_name);
  165. if (IS_ERR(clk)) {
  166. printk(KERN_ERR "%s: unable to get clk %s\n",
  167. __func__, clk_name);
  168. goto exit;
  169. }
  170. freq = clk->rate;
  171. clk_put(clk);
  172. opp = opp_find_freq_ceil(dev, &freq);
  173. if (IS_ERR(opp)) {
  174. printk(KERN_ERR "%s: unable to find boot up OPP for vdd_%s\n",
  175. __func__, vdd_name);
  176. goto exit;
  177. }
  178. bootup_volt = opp_get_voltage(opp);
  179. if (!bootup_volt) {
  180. printk(KERN_ERR "%s: unable to find voltage corresponding"
  181. "to the bootup OPP for vdd_%s\n", __func__, vdd_name);
  182. goto exit;
  183. }
  184. omap_voltage_scale_vdd(voltdm, bootup_volt);
  185. return 0;
  186. exit:
  187. printk(KERN_ERR "%s: Unable to put vdd_%s to its init voltage\n\n",
  188. __func__, vdd_name);
  189. return -EINVAL;
  190. }
  191. static void __init omap3_init_voltages(void)
  192. {
  193. if (!cpu_is_omap34xx())
  194. return;
  195. omap2_set_init_voltage("mpu", "dpll1_ck", mpu_dev);
  196. omap2_set_init_voltage("core", "l3_ick", l3_dev);
  197. }
  198. static void __init omap4_init_voltages(void)
  199. {
  200. if (!cpu_is_omap44xx())
  201. return;
  202. omap2_set_init_voltage("mpu", "dpll_mpu_ck", mpu_dev);
  203. omap2_set_init_voltage("core", "l3_div_ck", l3_dev);
  204. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", iva_dev);
  205. }
  206. static int __init omap2_common_pm_init(void)
  207. {
  208. omap2_init_processor_devices();
  209. omap_pm_if_init();
  210. return 0;
  211. }
  212. postcore_initcall(omap2_common_pm_init);
  213. static int __init omap2_common_pm_late_init(void)
  214. {
  215. /* Init the OMAP TWL parameters */
  216. omap3_twl_init();
  217. omap4_twl_init();
  218. /* Init the voltage layer */
  219. omap_voltage_late_init();
  220. /* Initialize the voltages */
  221. omap3_init_voltages();
  222. omap4_init_voltages();
  223. /* Smartreflex device init */
  224. omap_devinit_smartreflex();
  225. return 0;
  226. }
  227. late_initcall(omap2_common_pm_late_init);