pm.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. #include "twl-common.h"
  30. #ifdef CONFIG_SUSPEND
  31. /*
  32. * omap_pm_suspend: points to a function that does the SoC-specific
  33. * suspend work
  34. */
  35. static int (*omap_pm_suspend)(void);
  36. #endif
  37. #ifdef CONFIG_PM
  38. /**
  39. * struct omap2_oscillator - Describe the board main oscillator latencies
  40. * @startup_time: oscillator startup latency
  41. * @shutdown_time: oscillator shutdown latency
  42. */
  43. struct omap2_oscillator {
  44. u32 startup_time;
  45. u32 shutdown_time;
  46. };
  47. static struct omap2_oscillator oscillator = {
  48. .startup_time = ULONG_MAX,
  49. .shutdown_time = ULONG_MAX,
  50. };
  51. void omap_pm_setup_oscillator(u32 tstart, u32 tshut)
  52. {
  53. oscillator.startup_time = tstart;
  54. oscillator.shutdown_time = tshut;
  55. }
  56. void omap_pm_get_oscillator(u32 *tstart, u32 *tshut)
  57. {
  58. if (!tstart || !tshut)
  59. return;
  60. *tstart = oscillator.startup_time;
  61. *tshut = oscillator.shutdown_time;
  62. }
  63. #endif
  64. static int __init _init_omap_device(char *name)
  65. {
  66. struct omap_hwmod *oh;
  67. struct platform_device *pdev;
  68. oh = omap_hwmod_lookup(name);
  69. if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
  70. __func__, name))
  71. return -ENODEV;
  72. pdev = omap_device_build(oh->name, 0, oh, NULL, 0);
  73. if (WARN(IS_ERR(pdev), "%s: could not build omap_device for %s\n",
  74. __func__, name))
  75. return -ENODEV;
  76. return 0;
  77. }
  78. /*
  79. * Build omap_devices for processors and bus.
  80. */
  81. static void __init omap2_init_processor_devices(void)
  82. {
  83. _init_omap_device("mpu");
  84. if (omap3_has_iva())
  85. _init_omap_device("iva");
  86. if (cpu_is_omap44xx()) {
  87. _init_omap_device("l3_main_1");
  88. _init_omap_device("dsp");
  89. _init_omap_device("iva");
  90. } else {
  91. _init_omap_device("l3_main");
  92. }
  93. }
  94. int __init omap_pm_clkdms_setup(struct clockdomain *clkdm, void *unused)
  95. {
  96. clkdm_allow_idle(clkdm);
  97. return 0;
  98. }
  99. /*
  100. * This API is to be called during init to set the various voltage
  101. * domains to the voltage as per the opp table. Typically we boot up
  102. * at the nominal voltage. So this function finds out the rate of
  103. * the clock associated with the voltage domain, finds out the correct
  104. * opp entry and sets the voltage domain to the voltage specified
  105. * in the opp entry
  106. */
  107. static int __init omap2_set_init_voltage(char *vdd_name, char *clk_name,
  108. const char *oh_name)
  109. {
  110. struct voltagedomain *voltdm;
  111. struct clk *clk;
  112. struct dev_pm_opp *opp;
  113. unsigned long freq, bootup_volt;
  114. struct device *dev;
  115. if (!vdd_name || !clk_name || !oh_name) {
  116. pr_err("%s: invalid parameters\n", __func__);
  117. goto exit;
  118. }
  119. if (!strncmp(oh_name, "mpu", 3))
  120. /*
  121. * All current OMAPs share voltage rail and clock
  122. * source, so CPU0 is used to represent the MPU-SS.
  123. */
  124. dev = get_cpu_device(0);
  125. else
  126. dev = omap_device_get_by_hwmod_name(oh_name);
  127. if (IS_ERR(dev)) {
  128. pr_err("%s: Unable to get dev pointer for hwmod %s\n",
  129. __func__, oh_name);
  130. goto exit;
  131. }
  132. voltdm = voltdm_lookup(vdd_name);
  133. if (!voltdm) {
  134. pr_err("%s: unable to get vdd pointer for vdd_%s\n",
  135. __func__, vdd_name);
  136. goto exit;
  137. }
  138. clk = clk_get(NULL, clk_name);
  139. if (IS_ERR(clk)) {
  140. pr_err("%s: unable to get clk %s\n", __func__, clk_name);
  141. goto exit;
  142. }
  143. freq = clk_get_rate(clk);
  144. clk_put(clk);
  145. rcu_read_lock();
  146. opp = dev_pm_opp_find_freq_ceil(dev, &freq);
  147. if (IS_ERR(opp)) {
  148. rcu_read_unlock();
  149. pr_err("%s: unable to find boot up OPP for vdd_%s\n",
  150. __func__, vdd_name);
  151. goto exit;
  152. }
  153. bootup_volt = dev_pm_opp_get_voltage(opp);
  154. rcu_read_unlock();
  155. if (!bootup_volt) {
  156. pr_err("%s: unable to find voltage corresponding to the bootup OPP for vdd_%s\n",
  157. __func__, vdd_name);
  158. goto exit;
  159. }
  160. voltdm_scale(voltdm, bootup_volt);
  161. return 0;
  162. exit:
  163. pr_err("%s: unable to set vdd_%s\n", __func__, vdd_name);
  164. return -EINVAL;
  165. }
  166. #ifdef CONFIG_SUSPEND
  167. static int omap_pm_enter(suspend_state_t suspend_state)
  168. {
  169. int ret = 0;
  170. if (!omap_pm_suspend)
  171. return -ENOENT; /* XXX doublecheck */
  172. switch (suspend_state) {
  173. case PM_SUSPEND_STANDBY:
  174. case PM_SUSPEND_MEM:
  175. ret = omap_pm_suspend();
  176. break;
  177. default:
  178. ret = -EINVAL;
  179. }
  180. return ret;
  181. }
  182. static int omap_pm_begin(suspend_state_t state)
  183. {
  184. cpu_idle_poll_ctrl(true);
  185. if (cpu_is_omap34xx())
  186. omap_prcm_irq_prepare();
  187. return 0;
  188. }
  189. static void omap_pm_end(void)
  190. {
  191. cpu_idle_poll_ctrl(false);
  192. }
  193. static void omap_pm_wake(void)
  194. {
  195. if (cpu_is_omap34xx())
  196. omap_prcm_irq_complete();
  197. }
  198. static const struct platform_suspend_ops omap_pm_ops = {
  199. .begin = omap_pm_begin,
  200. .end = omap_pm_end,
  201. .enter = omap_pm_enter,
  202. .wake = omap_pm_wake,
  203. .valid = suspend_valid_only_mem,
  204. };
  205. /**
  206. * omap_common_suspend_init - Set common suspend routines for OMAP SoCs
  207. * @pm_suspend: function pointer to SoC specific suspend function
  208. */
  209. void omap_common_suspend_init(void *pm_suspend)
  210. {
  211. omap_pm_suspend = pm_suspend;
  212. suspend_set_ops(&omap_pm_ops);
  213. }
  214. #endif /* CONFIG_SUSPEND */
  215. static void __init omap3_init_voltages(void)
  216. {
  217. if (!cpu_is_omap34xx())
  218. return;
  219. omap2_set_init_voltage("mpu_iva", "dpll1_ck", "mpu");
  220. omap2_set_init_voltage("core", "l3_ick", "l3_main");
  221. }
  222. static void __init omap4_init_voltages(void)
  223. {
  224. if (!cpu_is_omap44xx())
  225. return;
  226. omap2_set_init_voltage("mpu", "dpll_mpu_ck", "mpu");
  227. omap2_set_init_voltage("core", "l3_div_ck", "l3_main_1");
  228. omap2_set_init_voltage("iva", "dpll_iva_m5x2_ck", "iva");
  229. }
  230. static inline void omap_init_cpufreq(void)
  231. {
  232. struct platform_device_info devinfo = { .name = "omap-cpufreq" };
  233. if (!of_have_populated_dt())
  234. platform_device_register_full(&devinfo);
  235. }
  236. static int __init omap2_common_pm_init(void)
  237. {
  238. if (!of_have_populated_dt())
  239. omap2_init_processor_devices();
  240. omap_pm_if_init();
  241. return 0;
  242. }
  243. omap_postcore_initcall(omap2_common_pm_init);
  244. int __init omap2_common_pm_late_init(void)
  245. {
  246. if (of_have_populated_dt()) {
  247. omap3_twl_init();
  248. omap4_twl_init();
  249. }
  250. /* Init the voltage layer */
  251. omap_pmic_late_init();
  252. omap_voltage_late_init();
  253. /* Initialize the voltages */
  254. omap3_init_voltages();
  255. omap4_init_voltages();
  256. /* Smartreflex device init */
  257. omap_devinit_smartreflex();
  258. /* cpufreq dummy device instantiation */
  259. omap_init_cpufreq();
  260. return 0;
  261. }