pm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 "powerdomain.h"
  19. #include "clockdomain.h"
  20. static struct omap_device_pm_latency *pm_lats;
  21. static struct device *mpu_dev;
  22. static struct device *iva_dev;
  23. static struct device *l3_dev;
  24. static struct device *dsp_dev;
  25. struct device *omap2_get_mpuss_device(void)
  26. {
  27. WARN_ON_ONCE(!mpu_dev);
  28. return mpu_dev;
  29. }
  30. struct device *omap2_get_iva_device(void)
  31. {
  32. WARN_ON_ONCE(!iva_dev);
  33. return iva_dev;
  34. }
  35. struct device *omap2_get_l3_device(void)
  36. {
  37. WARN_ON_ONCE(!l3_dev);
  38. return l3_dev;
  39. }
  40. struct device *omap4_get_dsp_device(void)
  41. {
  42. WARN_ON_ONCE(!dsp_dev);
  43. return dsp_dev;
  44. }
  45. EXPORT_SYMBOL(omap4_get_dsp_device);
  46. /* static int _init_omap_device(struct omap_hwmod *oh, void *user) */
  47. static int _init_omap_device(char *name, struct device **new_dev)
  48. {
  49. struct omap_hwmod *oh;
  50. struct omap_device *od;
  51. oh = omap_hwmod_lookup(name);
  52. if (WARN(!oh, "%s: could not find omap_hwmod for %s\n",
  53. __func__, name))
  54. return -ENODEV;
  55. od = omap_device_build(oh->name, 0, oh, NULL, 0, pm_lats, 0, false);
  56. if (WARN(IS_ERR(od), "%s: could not build omap_device for %s\n",
  57. __func__, name))
  58. return -ENODEV;
  59. *new_dev = &od->pdev.dev;
  60. return 0;
  61. }
  62. /*
  63. * Build omap_devices for processors and bus.
  64. */
  65. static void omap2_init_processor_devices(void)
  66. {
  67. _init_omap_device("mpu", &mpu_dev);
  68. _init_omap_device("iva", &iva_dev);
  69. if (cpu_is_omap44xx()) {
  70. _init_omap_device("l3_main_1", &l3_dev);
  71. _init_omap_device("dsp", &dsp_dev);
  72. } else {
  73. _init_omap_device("l3_main", &l3_dev);
  74. }
  75. }
  76. /* Types of sleep_switch used in omap_set_pwrdm_state */
  77. #define FORCEWAKEUP_SWITCH 0
  78. #define LOWPOWERSTATE_SWITCH 1
  79. /*
  80. * This sets pwrdm state (other than mpu & core. Currently only ON &
  81. * RET are supported. Function is assuming that clkdm doesn't have
  82. * hw_sup mode enabled.
  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. omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  118. break;
  119. case LOWPOWERSTATE_SWITCH:
  120. pwrdm_set_lowpwrstchange(pwrdm);
  121. break;
  122. default:
  123. return ret;
  124. }
  125. pwrdm_wait_transition(pwrdm);
  126. pwrdm_state_switch(pwrdm);
  127. err:
  128. return ret;
  129. }
  130. static int __init omap2_common_pm_init(void)
  131. {
  132. omap2_init_processor_devices();
  133. omap_pm_if_init();
  134. return 0;
  135. }
  136. postcore_initcall(omap2_common_pm_init);