pm.c 3.0 KB

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