pm.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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 <plat/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. _init_omap_device("iva", &iva_dev);
  72. if (cpu_is_omap44xx()) {
  73. _init_omap_device("l3_main_1", &l3_dev);
  74. _init_omap_device("dsp", &dsp_dev);
  75. } else {
  76. _init_omap_device("l3_main", &l3_dev);
  77. }
  78. }
  79. /* Types of sleep_switch used in omap_set_pwrdm_state */
  80. #define FORCEWAKEUP_SWITCH 0
  81. #define LOWPOWERSTATE_SWITCH 1
  82. /*
  83. * This sets pwrdm state (other than mpu & core. Currently only ON &
  84. * RET are supported.
  85. */
  86. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
  87. {
  88. u32 cur_state;
  89. int sleep_switch = 0;
  90. int ret = 0;
  91. if (pwrdm == NULL || IS_ERR(pwrdm))
  92. return -EINVAL;
  93. while (!(pwrdm->pwrsts & (1 << state))) {
  94. if (state == PWRDM_POWER_OFF)
  95. return ret;
  96. state--;
  97. }
  98. cur_state = pwrdm_read_next_pwrst(pwrdm);
  99. if (cur_state == state)
  100. return ret;
  101. if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
  102. if ((pwrdm_read_pwrst(pwrdm) > state) &&
  103. (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
  104. sleep_switch = LOWPOWERSTATE_SWITCH;
  105. } else {
  106. omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  107. pwrdm_wait_transition(pwrdm);
  108. sleep_switch = FORCEWAKEUP_SWITCH;
  109. }
  110. }
  111. ret = pwrdm_set_next_pwrst(pwrdm, state);
  112. if (ret) {
  113. printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
  114. pwrdm->name);
  115. goto err;
  116. }
  117. switch (sleep_switch) {
  118. case FORCEWAKEUP_SWITCH:
  119. if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO)
  120. omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  121. else
  122. omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  123. break;
  124. case LOWPOWERSTATE_SWITCH:
  125. pwrdm_set_lowpwrstchange(pwrdm);
  126. break;
  127. default:
  128. return ret;
  129. }
  130. pwrdm_wait_transition(pwrdm);
  131. pwrdm_state_switch(pwrdm);
  132. err:
  133. return ret;
  134. }
  135. /*
  136. * This API is to be called during init to put the various voltage
  137. * domains to the voltage as per the opp table. Typically we boot up
  138. * at the nominal voltage. So this function finds out the rate of
  139. * the clock associated with the voltage domain, finds out the correct
  140. * opp entry and puts the voltage domain to the voltage specifies
  141. * in the opp entry
  142. */
  143. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  144. struct device *dev)
  145. {
  146. struct voltagedomain *voltdm;
  147. struct clk *clk;
  148. struct opp *opp;
  149. unsigned long freq, bootup_volt;
  150. if (!vdd_name || !clk_name || !dev) {
  151. printk(KERN_ERR "%s: Invalid parameters!\n", __func__);
  152. goto exit;
  153. }
  154. voltdm = omap_voltage_domain_lookup(vdd_name);
  155. if (IS_ERR(voltdm)) {
  156. printk(KERN_ERR "%s: Unable to get vdd pointer for vdd_%s\n",
  157. __func__, vdd_name);
  158. goto exit;
  159. }
  160. clk = clk_get(NULL, clk_name);
  161. if (IS_ERR(clk)) {
  162. printk(KERN_ERR "%s: unable to get clk %s\n",
  163. __func__, clk_name);
  164. goto exit;
  165. }
  166. freq = clk->rate;
  167. clk_put(clk);
  168. opp = opp_find_freq_ceil(dev, &freq);
  169. if (IS_ERR(opp)) {
  170. printk(KERN_ERR "%s: unable to find boot up OPP for vdd_%s\n",
  171. __func__, vdd_name);
  172. goto exit;
  173. }
  174. bootup_volt = opp_get_voltage(opp);
  175. if (!bootup_volt) {
  176. printk(KERN_ERR "%s: unable to find voltage corresponding"
  177. "to the bootup OPP for vdd_%s\n", __func__, vdd_name);
  178. goto exit;
  179. }
  180. omap_voltage_scale_vdd(voltdm, bootup_volt);
  181. return 0;
  182. exit:
  183. printk(KERN_ERR "%s: Unable to put vdd_%s to its init voltage\n\n",
  184. __func__, vdd_name);
  185. return -EINVAL;
  186. }
  187. static void __init omap3_init_voltages(void)
  188. {
  189. if (!cpu_is_omap34xx())
  190. return;
  191. omap2_set_init_voltage("mpu", "dpll1_ck", mpu_dev);
  192. omap2_set_init_voltage("core", "l3_ick", l3_dev);
  193. }
  194. static int __init omap2_common_pm_init(void)
  195. {
  196. omap2_init_processor_devices();
  197. omap_pm_if_init();
  198. return 0;
  199. }
  200. postcore_initcall(omap2_common_pm_init);
  201. static int __init omap2_common_pm_late_init(void)
  202. {
  203. /* Init the OMAP TWL parameters */
  204. omap3_twl_init();
  205. omap4_twl_init();
  206. /* Init the voltage layer */
  207. omap_voltage_late_init();
  208. /* Initialize the voltages */
  209. omap3_init_voltages();
  210. /* Smartreflex device init */
  211. omap_devinit_smartreflex();
  212. return 0;
  213. }
  214. late_initcall(omap2_common_pm_late_init);