pm44xx.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * OMAP4 Power Management Routines
  3. *
  4. * Copyright (C) 2010 Texas Instruments, Inc.
  5. * Rajendra Nayak <rnayak@ti.com>
  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/pm.h>
  12. #include <linux/suspend.h>
  13. #include <linux/module.h>
  14. #include <linux/list.h>
  15. #include <linux/err.h>
  16. #include <linux/slab.h>
  17. #include "common.h"
  18. #include "clockdomain.h"
  19. #include "powerdomain.h"
  20. struct power_state {
  21. struct powerdomain *pwrdm;
  22. u32 next_state;
  23. #ifdef CONFIG_SUSPEND
  24. u32 saved_state;
  25. #endif
  26. struct list_head node;
  27. };
  28. static LIST_HEAD(pwrst_list);
  29. #ifdef CONFIG_SUSPEND
  30. static int omap4_pm_suspend(void)
  31. {
  32. do_wfi();
  33. return 0;
  34. }
  35. static int omap4_pm_enter(suspend_state_t suspend_state)
  36. {
  37. int ret = 0;
  38. switch (suspend_state) {
  39. case PM_SUSPEND_STANDBY:
  40. case PM_SUSPEND_MEM:
  41. ret = omap4_pm_suspend();
  42. break;
  43. default:
  44. ret = -EINVAL;
  45. }
  46. return ret;
  47. }
  48. static int omap4_pm_begin(suspend_state_t state)
  49. {
  50. disable_hlt();
  51. return 0;
  52. }
  53. static void omap4_pm_end(void)
  54. {
  55. enable_hlt();
  56. return;
  57. }
  58. static const struct platform_suspend_ops omap_pm_ops = {
  59. .begin = omap4_pm_begin,
  60. .end = omap4_pm_end,
  61. .enter = omap4_pm_enter,
  62. .valid = suspend_valid_only_mem,
  63. };
  64. #endif /* CONFIG_SUSPEND */
  65. /*
  66. * Enable hardware supervised mode for all clockdomains if it's
  67. * supported. Initiate sleep transition for other clockdomains, if
  68. * they are not used
  69. */
  70. static int __init clkdms_setup(struct clockdomain *clkdm, void *unused)
  71. {
  72. if (clkdm->flags & CLKDM_CAN_ENABLE_AUTO)
  73. clkdm_allow_idle(clkdm);
  74. else if (clkdm->flags & CLKDM_CAN_FORCE_SLEEP &&
  75. atomic_read(&clkdm->usecount) == 0)
  76. clkdm_sleep(clkdm);
  77. return 0;
  78. }
  79. static int __init pwrdms_setup(struct powerdomain *pwrdm, void *unused)
  80. {
  81. struct power_state *pwrst;
  82. if (!pwrdm->pwrsts)
  83. return 0;
  84. pwrst = kmalloc(sizeof(struct power_state), GFP_ATOMIC);
  85. if (!pwrst)
  86. return -ENOMEM;
  87. pwrst->pwrdm = pwrdm;
  88. pwrst->next_state = PWRDM_POWER_ON;
  89. list_add(&pwrst->node, &pwrst_list);
  90. return pwrdm_set_next_pwrst(pwrst->pwrdm, pwrst->next_state);
  91. }
  92. /**
  93. * omap4_pm_init - Init routine for OMAP4 PM
  94. *
  95. * Initializes all powerdomain and clockdomain target states
  96. * and all PRCM settings.
  97. */
  98. static int __init omap4_pm_init(void)
  99. {
  100. int ret;
  101. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm;
  102. struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm;
  103. if (!cpu_is_omap44xx())
  104. return -ENODEV;
  105. if (omap_rev() == OMAP4430_REV_ES1_0) {
  106. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  107. return -ENODEV;
  108. }
  109. pr_err("Power Management for TI OMAP4.\n");
  110. ret = pwrdm_for_each(pwrdms_setup, NULL);
  111. if (ret) {
  112. pr_err("Failed to setup powerdomains\n");
  113. goto err2;
  114. }
  115. /*
  116. * The dynamic dependency between MPUSS -> MEMIF and
  117. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  118. * expected. The hardware recommendation is to enable static
  119. * dependencies for these to avoid system lock ups or random crashes.
  120. */
  121. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  122. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  123. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  124. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  125. l4_per_clkdm = clkdm_lookup("l4_per_clkdm");
  126. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  127. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) ||
  128. (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm))
  129. goto err2;
  130. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  131. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  132. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  133. ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm);
  134. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  135. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  136. if (ret) {
  137. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 "
  138. "wakeup dependency\n");
  139. goto err2;
  140. }
  141. ret = omap4_mpuss_init();
  142. if (ret) {
  143. pr_err("Failed to initialise OMAP4 MPUSS\n");
  144. goto err2;
  145. }
  146. (void) clkdm_for_each(clkdms_setup, NULL);
  147. #ifdef CONFIG_SUSPEND
  148. suspend_set_ops(&omap_pm_ops);
  149. #endif /* CONFIG_SUSPEND */
  150. err2:
  151. return ret;
  152. }
  153. late_initcall(omap4_pm_init);