pm.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 <plat/omap-pm.h>
  16. #include <plat/omap_device.h>
  17. #include <plat/common.h>
  18. #include <plat/voltage.h>
  19. #include "powerdomain.h"
  20. #include "clockdomain.h"
  21. static struct omap_device_pm_latency *pm_lats;
  22. static struct device *mpu_dev;
  23. static struct device *iva_dev;
  24. static struct device *l3_dev;
  25. static struct device *dsp_dev;
  26. struct device *omap2_get_mpuss_device(void)
  27. {
  28. WARN_ON_ONCE(!mpu_dev);
  29. return mpu_dev;
  30. }
  31. struct device *omap2_get_iva_device(void)
  32. {
  33. WARN_ON_ONCE(!iva_dev);
  34. return iva_dev;
  35. }
  36. struct device *omap2_get_l3_device(void)
  37. {
  38. WARN_ON_ONCE(!l3_dev);
  39. return l3_dev;
  40. }
  41. struct device *omap4_get_dsp_device(void)
  42. {
  43. WARN_ON_ONCE(!dsp_dev);
  44. return dsp_dev;
  45. }
  46. EXPORT_SYMBOL(omap4_get_dsp_device);
  47. /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
  48. static int _init_omap_device(char *name, struct device **new_dev)
  49. {
  50. struct omap_hwmod *oh;
  51. struct omap_device *od;
  52. oh = omap_hwmod_lookup(name);
  53. if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
  54. __func__, name))
  55. return -ENODEV;
  56. od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
  57. if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
  58. __func__, name))
  59. return -ENODEV;
  60. *new_dev = &od->pdev.dev;
  61. return 0;
  62. }
  63. /*
  64. * Build omap_devices for processors and bus.
  65. */
  66. static void omap2_init_processor_devices(void)
  67. {
  68. _init_omap_device("mpu", &mpu_dev);
  69. _init_omap_device("iva", &iva_dev);
  70. if (cpu_is_omap44xx()) {
  71. _init_omap_device("l3_main_1", &l3_dev);
  72. _init_omap_device("dsp", &dsp_dev);
  73. } else {
  74. _init_omap_device("l3_main", &l3_dev);
  75. }
  76. }
  77. /* Types of sleep_switch used in omap_set_pwrdm_state */
  78. #define FORCEWAKEUP_SWITCH 0
  79. #define LOWPOWERSTATE_SWITCH 1
  80. /*
  81. * This sets pwrdm state (other than mpu & core. Currently only ON &
  82. * RET are supported.
  83. */
  84. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
  85. {
  86. u32 cur_state;
  87. int sleep_switch = 0;
  88. int ret = 0;
  89. if (pwrdm == NULL || IS_ERR(pwrdm))
  90. return -EINVAL;
  91. while (!(pwrdm->pwrsts & (1 << state))) {
  92. if (state == PWRDM_POWER_OFF)
  93. return ret;
  94. state--;
  95. }
  96. cur_state = pwrdm_read_next_pwrst(pwrdm);
  97. if (cur_state == state)
  98. return ret;
  99. if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
  100. if ((pwrdm_read_pwrst(pwrdm) > state) &&
  101. (pwrdm->flags & PWRDM_HAS_LOWPOWERSTATECHANGE)) {
  102. sleep_switch = LOWPOWERSTATE_SWITCH;
  103. } else {
  104. omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  105. pwrdm_wait_transition(pwrdm);
  106. sleep_switch = FORCEWAKEUP_SWITCH;
  107. }
  108. }
  109. ret = pwrdm_set_next_pwrst(pwrdm, state);
  110. if (ret) {
  111. printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
  112. pwrdm->name);
  113. goto err;
  114. }
  115. switch (sleep_switch) {
  116. case FORCEWAKEUP_SWITCH:
  117. if (pwrdm->pwrdm_clkdms[0]->flags & CLKDM_CAN_ENABLE_AUTO)
  118. omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  119. else
  120. omap2_clkdm_sleep(pwrdm->pwrdm_clkdms[0]);
  121. break;
  122. case LOWPOWERSTATE_SWITCH:
  123. pwrdm_set_lowpwrstchange(pwrdm);
  124. break;
  125. default:
  126. return ret;
  127. }
  128. pwrdm_wait_transition(pwrdm);
  129. pwrdm_state_switch(pwrdm);
  130. err:
  131. return ret;
  132. }
  133. static int __init omap2_common_pm_init(void)
  134. {
  135. omap2_init_processor_devices();
  136. omap_pm_if_init();
  137. return 0;
  138. }
  139. postcore_initcall(omap2_common_pm_init);
  140. static int __init omap2_common_pm_late_init(void)
  141. {
  142. omap_voltage_late_init();
  143. return 0;
  144. }
  145. late_initcall(omap2_common_pm_late_init);