pm.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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/powerdomain.h>
  19. #include <plat/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. /*
  77. * This sets pwrdm state (other than mpu & core. Currently only ON &
  78. * RET are supported. Function is assuming that clkdm doesn't have
  79. * hw_sup mode enabled.
  80. */
  81. int omap_set_pwrdm_state(struct powerdomain *pwrdm, u32 state)
  82. {
  83. u32 cur_state;
  84. int sleep_switch = 0;
  85. int ret = 0;
  86. if (pwrdm == NULL || IS_ERR(pwrdm))
  87. return -EINVAL;
  88. while (!(pwrdm->pwrsts & (1 << state))) {
  89. if (state == PWRDM_POWER_OFF)
  90. return ret;
  91. state--;
  92. }
  93. cur_state = pwrdm_read_next_pwrst(pwrdm);
  94. if (cur_state == state)
  95. return ret;
  96. if (pwrdm_read_pwrst(pwrdm) < PWRDM_POWER_ON) {
  97. omap2_clkdm_wakeup(pwrdm->pwrdm_clkdms[0]);
  98. sleep_switch = 1;
  99. pwrdm_wait_transition(pwrdm);
  100. }
  101. ret = pwrdm_set_next_pwrst(pwrdm, state);
  102. if (ret) {
  103. printk(KERN_ERR "Unable to set state of powerdomain: %s\n",
  104. pwrdm->name);
  105. goto err;
  106. }
  107. if (sleep_switch) {
  108. omap2_clkdm_allow_idle(pwrdm->pwrdm_clkdms[0]);
  109. pwrdm_wait_transition(pwrdm);
  110. pwrdm_state_switch(pwrdm);
  111. }
  112. err:
  113. return ret;
  114. }
  115. static int __init omap2_common_pm_init(void)
  116. {
  117. omap2_init_processor_devices();
  118. omap_pm_if_init();
  119. return 0;
  120. }
  121. device_initcall(omap2_common_pm_init);