pm44xx.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * omap_default_idle - OMAP4 default ilde routine.'
  94. *
  95. * Implements OMAP4 memory, IO ordering requirements which can't be addressed
  96. * with default arch_idle() hook. Used by all CPUs with !CONFIG_CPUIDLE and
  97. * by secondary CPU with CONFIG_CPUIDLE.
  98. */
  99. static void omap_default_idle(void)
  100. {
  101. local_irq_disable();
  102. local_fiq_disable();
  103. omap_do_wfi();
  104. local_fiq_enable();
  105. local_irq_enable();
  106. }
  107. /**
  108. * omap4_pm_init - Init routine for OMAP4 PM
  109. *
  110. * Initializes all powerdomain and clockdomain target states
  111. * and all PRCM settings.
  112. */
  113. static int __init omap4_pm_init(void)
  114. {
  115. int ret;
  116. struct clockdomain *emif_clkdm, *mpuss_clkdm, *l3_1_clkdm;
  117. struct clockdomain *ducati_clkdm, *l3_2_clkdm, *l4_per_clkdm;
  118. if (!cpu_is_omap44xx())
  119. return -ENODEV;
  120. if (omap_rev() == OMAP4430_REV_ES1_0) {
  121. WARN(1, "Power Management not supported on OMAP4430 ES1.0\n");
  122. return -ENODEV;
  123. }
  124. pr_err("Power Management for TI OMAP4.\n");
  125. ret = pwrdm_for_each(pwrdms_setup, NULL);
  126. if (ret) {
  127. pr_err("Failed to setup powerdomains\n");
  128. goto err2;
  129. }
  130. /*
  131. * The dynamic dependency between MPUSS -> MEMIF and
  132. * MPUSS -> L4_PER/L3_* and DUCATI -> L3_* doesn't work as
  133. * expected. The hardware recommendation is to enable static
  134. * dependencies for these to avoid system lock ups or random crashes.
  135. */
  136. mpuss_clkdm = clkdm_lookup("mpuss_clkdm");
  137. emif_clkdm = clkdm_lookup("l3_emif_clkdm");
  138. l3_1_clkdm = clkdm_lookup("l3_1_clkdm");
  139. l3_2_clkdm = clkdm_lookup("l3_2_clkdm");
  140. l4_per_clkdm = clkdm_lookup("l4_per_clkdm");
  141. ducati_clkdm = clkdm_lookup("ducati_clkdm");
  142. if ((!mpuss_clkdm) || (!emif_clkdm) || (!l3_1_clkdm) ||
  143. (!l3_2_clkdm) || (!ducati_clkdm) || (!l4_per_clkdm))
  144. goto err2;
  145. ret = clkdm_add_wkdep(mpuss_clkdm, emif_clkdm);
  146. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_1_clkdm);
  147. ret |= clkdm_add_wkdep(mpuss_clkdm, l3_2_clkdm);
  148. ret |= clkdm_add_wkdep(mpuss_clkdm, l4_per_clkdm);
  149. ret |= clkdm_add_wkdep(ducati_clkdm, l3_1_clkdm);
  150. ret |= clkdm_add_wkdep(ducati_clkdm, l3_2_clkdm);
  151. if (ret) {
  152. pr_err("Failed to add MPUSS -> L3/EMIF/L4PER, DUCATI -> L3 "
  153. "wakeup dependency\n");
  154. goto err2;
  155. }
  156. ret = omap4_mpuss_init();
  157. if (ret) {
  158. pr_err("Failed to initialise OMAP4 MPUSS\n");
  159. goto err2;
  160. }
  161. (void) clkdm_for_each(clkdms_setup, NULL);
  162. #ifdef CONFIG_SUSPEND
  163. suspend_set_ops(&omap_pm_ops);
  164. #endif /* CONFIG_SUSPEND */
  165. /* Overwrite the default arch_idle() */
  166. pm_idle = omap_default_idle;
  167. err2:
  168. return ret;
  169. }
  170. late_initcall(omap4_pm_init);