pm.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. sleep_switch = FORCEWAKEUP_SWITCH;
  112. }
  113. }
  114. ret = pwrdm_set_next_pwrst(pwrdm, state);
  115. if (ret) {
  116. printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
  117. pwrdm->name);
  118. goto err;
  119. }
  120. switch (sleep_switch) {
  121. case FORCEWAKEUP_SWITCH:
  122. if (hwsup)
  123. clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  124. else
  125. clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  126. break;
  127. case LOWPOWERSTATE_SWITCH:
  128. pwrdm_set_lowpwrstchange(pwrdm);
  129. break;
  130. default:
  131. return ret;
  132. }
  133. pwrdm_state_switch(pwrdm);
  134. err:
  135. return ret;
  136. }
  137. /*
  138. * This API is to be called during init to put the various voltage
  139. * domains to the voltage as per the opp table. Typically we boot up
  140. * at the nominal voltage. So this function finds out the rate of
  141. * the clock associated with the voltage domain, finds out the correct
  142. * opp entry and puts the voltage domain to the voltage specifies
  143. * in the opp entry
  144. */
  145. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  146. struct device *dev)
  147. {
  148. struct voltagedomain *voltdm;
  149. struct clk *clk;
  150. struct opp *opp;
  151. unsigned long freq, bootup_volt;
  152. if (!vdd_name || !clk_name || !dev) {
  153. printk(KERN_ERR "%s: Invalid parameters!\n", __func__);
  154. goto exit;
  155. }
  156. voltdm = omap_voltage_domain_lookup(vdd_name);
  157. if (IS_ERR(voltdm)) {
  158. printk(KERN_ERR "%s: Unable to get vdd pointer for vdd_%s\n",
  159. __func__, vdd_name);
  160. goto exit;
  161. }
  162. clk = clk_get(NULL, clk_name);
  163. if (IS_ERR(clk)) {
  164. printk(KERN_ERR "%s: unable to get clk %s\n",
  165. __func__, clk_name);
  166. goto exit;
  167. }
  168. freq = clk->rate;
  169. clk_put(clk);
  170. opp = opp_find_freq_ceil(dev, &freq);
  171. if (IS_ERR(opp)) {
  172. printk(KERN_ERR "%s: unable to find boot up OPP for vdd_%s\n",
  173. __func__, vdd_name);
  174. goto exit;
  175. }
  176. bootup_volt = opp_get_voltage(opp);
  177. if (!bootup_volt) {
  178. printk(KERN_ERR "%s: unable to find voltage corresponding"
  179. "to the bootup OPP for vdd_%s\n", __func__, vdd_name);
  180. goto exit;
  181. }
  182. omap_voltage_scale_vdd(voltdm, bootup_volt);
  183. return 0;
  184. exit:
  185. printk(KERN_ERR "%s: Unable to put vdd_%s to its init voltage\n\n",
  186. __func__, vdd_name);
  187. return -EINVAL;
  188. }
  189. static void __init omap3_init_voltages(void)
  190. {
  191. if (!cpu_is_omap34xx())
  192. return;
  193. omap2_set_init_voltage("mpu", "dpll1_ck", mpu_dev);
  194. omap2_set_init_voltage("core", "l3_ick", l3_dev);
  195. }
  196. static void __init omap4_init_voltages(void)
  197. {
  198. if (!cpu_is_omap44xx())
  199. return;
  200. omap2_set_init_voltage("mpu", "dpll_mpu_ck", mpu_dev);
  201. omap2_set_init_voltage("core", "l3_div_ck", l3_dev);
  202. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", iva_dev);
  203. }
  204. static int __init omap2_common_pm_init(void)
  205. {
  206. omap2_init_processor_devices();
  207. omap_pm_if_init();
  208. return 0;
  209. }
  210. postcore_initcall(omap2_common_pm_init);
  211. static int __init omap2_common_pm_late_init(void)
  212. {
  213. /* Init the OMAP TWL parameters */
  214. omap3_twl_init();
  215. omap4_twl_init();
  216. /* Init the voltage layer */
  217. omap_voltage_late_init();
  218. /* Initialize the voltages */
  219. omap3_init_voltages();
  220. omap4_init_voltages();
  221. /* Smartreflex device init */
  222. omap_devinit_smartreflex();
  223. return 0;
  224. }
  225. late_initcall(omap2_common_pm_late_init);