pm.c 3.9 KB

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