pm.c 5.4 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/pm_opp.h>
  16. #include <linux/export.h>
  17. #include <linux/suspend.h>
  18. #include <linux/cpu.h>
  19. #include <asm/system_misc.h>
  20. #include "omap-pm.h"
  21. #include "omap_device.h"
  22. #include "common.h"
  23. #include "soc.h"
  24. #include "prcm-common.h"
  25. #include "voltage.h"
  26. #include "powerdomain.h"
  27. #include "clockdomain.h"
  28. #include "pm.h"
  29. #ifdef CONFIG_SUSPEND
  30. /*
  31. * omap_pm_suspend: points to a function that does the SoC-specific
  32. * suspend work
  33. */
  34. static int (*omap_pm_suspend)(void);
  35. #endif
  36. #ifdef CONFIG_PM
  37. /**
  38. * struct omap2_oscillator - Describe the board main oscillator latencies
  39. * @startup_time: oscillator startup latency
  40. * @shutdown_time: oscillator shutdown latency
  41. */
  42. struct omap2_oscillator {
  43. u32 startup_time;
  44. u32 shutdown_time;
  45. };
  46. static struct omap2_oscillator oscillator = {
  47. .startup_time = ULONG_MAX,
  48. .shutdown_time = ULONG_MAX,
  49. };
  50. void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
  51. {
  52. oscillator.startup_time = tstart;
  53. oscillator.shutdown_time = tshut;
  54. }
  55. void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
  56. {
  57. if (!tstart || !tshut)
  58. return;
  59. *tstart = oscillator.startup_time;
  60. *tshut = oscillator.shutdown_time;
  61. }
  62. #endif
  63. int omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
  64. {
  65. clkdm_allow_idle(clkdm);
  66. return 0;
  67. }
  68. /*
  69. * This API is to be called during init to set the various voltage
  70. * domains to the voltage as per the opp table. Typically we boot up
  71. * at the nominal voltage. So this function finds out the rate of
  72. * the clock associated with the voltage domain, finds out the correct
  73. * opp entry and sets the voltage domain to the voltage specified
  74. * in the opp entry
  75. */
  76. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  77. const char *oh_name)
  78. {
  79. struct voltagedomain *voltdm;
  80. struct clk *clk;
  81. struct dev_pm_opp *opp;
  82. unsigned long freq, bootup_volt;
  83. struct device *dev;
  84. if (!vdd_name || !clk_name || !oh_name) {
  85. pr_err("%s: invalid parameters\n", __func__);
  86. goto exit;
  87. }
  88. if (!strncmp(oh_name, "mpu", 3))
  89. /*
  90. * All current OMAPs share voltage rail and clock
  91. * source, so CPU0 is used to represent the MPU-SS.
  92. */
  93. dev = get_cpu_device(0);
  94. else
  95. dev = omap_device_get_by_hwmod_name(oh_name);
  96. if (IS_ERR(dev)) {
  97. pr_err("%s: Unable to get dev pointer for hwmod %s\n",
  98. __func__, oh_name);
  99. goto exit;
  100. }
  101. voltdm = voltdm_lookup(vdd_name);
  102. if (!voltdm) {
  103. pr_err("%s: unable to get vdd pointer for vdd_%s\n",
  104. __func__, vdd_name);
  105. goto exit;
  106. }
  107. clk = clk_get(NULL, clk_name);
  108. if (IS_ERR(clk)) {
  109. pr_err("%s: unable to get clk %s\n", __func__, clk_name);
  110. goto exit;
  111. }
  112. freq = clk_get_rate(clk);
  113. clk_put(clk);
  114. opp = dev_pm_opp_find_freq_ceil(dev, &freq);
  115. if (IS_ERR(opp)) {
  116. pr_err("%s: unable to find boot up OPP for vdd_%s\n",
  117. __func__, vdd_name);
  118. goto exit;
  119. }
  120. bootup_volt = dev_pm_opp_get_voltage(opp);
  121. dev_pm_opp_put(opp);
  122. if (!bootup_volt) {
  123. pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
  124. __func__, vdd_name);
  125. goto exit;
  126. }
  127. voltdm_scale(voltdm, bootup_volt);
  128. return 0;
  129. exit:
  130. pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
  131. return -EINVAL;
  132. }
  133. #ifdef CONFIG_SUSPEND
  134. static int omap_pm_enter(suspend_state_t suspend_state)
  135. {
  136. int ret = 0;
  137. if (!omap_pm_suspend)
  138. return -ENOENT; /* XXX doublecheck */
  139. switch (suspend_state) {
  140. case PM_SUSPEND_MEM:
  141. ret = omap_pm_suspend();
  142. break;
  143. default:
  144. ret = -EINVAL;
  145. }
  146. return ret;
  147. }
  148. static int omap_pm_begin(suspend_state_t state)
  149. {
  150. cpu_idle_poll_ctrl(true);
  151. if (soc_is_omap34xx())
  152. omap_prcm_irq_prepare();
  153. return 0;
  154. }
  155. static void omap_pm_end(void)
  156. {
  157. cpu_idle_poll_ctrl(false);
  158. }
  159. static void omap_pm_wake(void)
  160. {
  161. if (soc_is_omap34xx())
  162. omap_prcm_irq_complete();
  163. }
  164. static const struct platform_suspend_ops omap_pm_ops = {
  165. .begin = omap_pm_begin,
  166. .end = omap_pm_end,
  167. .enter = omap_pm_enter,
  168. .wake = omap_pm_wake,
  169. .valid = suspend_valid_only_mem,
  170. };
  171. /**
  172. * omap_common_suspend_init - Set common suspend routines for OMAP SoCs
  173. * @pm_suspend: function pointer to SoC specific suspend function
  174. */
  175. void omap_common_suspend_init(void *pm_suspend)
  176. {
  177. omap_pm_suspend = pm_suspend;
  178. suspend_set_ops(&omap_pm_ops);
  179. }
  180. #endif /* CONFIG_SUSPEND */
  181. static void __init omap3_init_voltages(void)
  182. {
  183. if (!soc_is_omap34xx())
  184. return;
  185. omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
  186. omap2_set_init_voltage("core", "l3_ick", "l3_main");
  187. }
  188. static void __init omap4_init_voltages(void)
  189. {
  190. if (!soc_is_omap44xx())
  191. return;
  192. omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
  193. omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
  194. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
  195. }
  196. static int __init omap2_common_pm_init(void)
  197. {
  198. omap_pm_if_init();
  199. return 0;
  200. }
  201. omap_postcore_initcall(omap2_common_pm_init);
  202. int __init omap2_common_pm_late_init(void)
  203. {
  204. /* Init the voltage layer */
  205. omap3_twl_init();
  206. omap4_twl_init();
  207. omap_voltage_late_init();
  208. /* Initialize the voltages */
  209. omap3_init_voltages();
  210. omap4_init_voltages();
  211. /* Smartreflex device init */
  212. omap_devinit_smartreflex();
  213. return 0;
  214. }