pm.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Blackfin power management
  3. *
  4. * Copyright 2006-2009 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2
  7. * based on arm/mach-omap/pm.c
  8. * Copyright 2001, Cliff Brake <cbrake@accelent.com> and others
  9. */
  10. #include <linux/suspend.h>
  11. #include <linux/sched.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/slab.h>
  14. #include <linux/io.h>
  15. #include <linux/irq.h>
  16. #include <asm/cplb.h>
  17. #include <asm/gpio.h>
  18. #include <asm/dma.h>
  19. #include <asm/dpmc.h>
  20. void bfin_pm_suspend_standby_enter(void)
  21. {
  22. bfin_pm_standby_setup();
  23. #ifdef CONFIG_PM_BFIN_SLEEP_DEEPER
  24. sleep_deeper(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]);
  25. #else
  26. sleep_mode(bfin_sic_iwr[0], bfin_sic_iwr[1], bfin_sic_iwr[2]);
  27. #endif
  28. bfin_pm_standby_restore();
  29. #ifdef SIC_IWR0
  30. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  31. # ifdef SIC_IWR1
  32. /* BF52x system reset does not properly reset SIC_IWR1 which
  33. * will screw up the bootrom as it relies on MDMA0/1 waking it
  34. * up from IDLE instructions. See this report for more info:
  35. * http://blackfin.uclinux.org/gf/tracker/4323
  36. */
  37. if (ANOMALY_05000435)
  38. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  39. else
  40. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  41. # endif
  42. # ifdef SIC_IWR2
  43. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  44. # endif
  45. #else
  46. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  47. #endif
  48. }
  49. int bf53x_suspend_l1_mem(unsigned char *memptr)
  50. {
  51. dma_memcpy_nocache(memptr, (const void *) L1_CODE_START,
  52. L1_CODE_LENGTH);
  53. dma_memcpy_nocache(memptr + L1_CODE_LENGTH,
  54. (const void *) L1_DATA_A_START, L1_DATA_A_LENGTH);
  55. dma_memcpy_nocache(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH,
  56. (const void *) L1_DATA_B_START, L1_DATA_B_LENGTH);
  57. memcpy(memptr + L1_CODE_LENGTH + L1_DATA_A_LENGTH +
  58. L1_DATA_B_LENGTH, (const void *) L1_SCRATCH_START,
  59. L1_SCRATCH_LENGTH);
  60. return 0;
  61. }
  62. int bf53x_resume_l1_mem(unsigned char *memptr)
  63. {
  64. dma_memcpy_nocache((void *) L1_CODE_START, memptr, L1_CODE_LENGTH);
  65. dma_memcpy_nocache((void *) L1_DATA_A_START, memptr + L1_CODE_LENGTH,
  66. L1_DATA_A_LENGTH);
  67. dma_memcpy_nocache((void *) L1_DATA_B_START, memptr + L1_CODE_LENGTH +
  68. L1_DATA_A_LENGTH, L1_DATA_B_LENGTH);
  69. memcpy((void *) L1_SCRATCH_START, memptr + L1_CODE_LENGTH +
  70. L1_DATA_A_LENGTH + L1_DATA_B_LENGTH, L1_SCRATCH_LENGTH);
  71. return 0;
  72. }
  73. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
  74. static void flushinv_all_dcache(void)
  75. {
  76. u32 way, bank, subbank, set;
  77. u32 status, addr;
  78. u32 dmem_ctl = bfin_read_DMEM_CONTROL();
  79. for (bank = 0; bank < 2; ++bank) {
  80. if (!(dmem_ctl & (1 << (DMC1_P - bank))))
  81. continue;
  82. for (way = 0; way < 2; ++way)
  83. for (subbank = 0; subbank < 4; ++subbank)
  84. for (set = 0; set < 64; ++set) {
  85. bfin_write_DTEST_COMMAND(
  86. way << 26 |
  87. bank << 23 |
  88. subbank << 16 |
  89. set << 5
  90. );
  91. CSYNC();
  92. status = bfin_read_DTEST_DATA0();
  93. /* only worry about valid/dirty entries */
  94. if ((status & 0x3) != 0x3)
  95. continue;
  96. /* construct the address using the tag */
  97. addr = (status & 0xFFFFC800) | (subbank << 12) | (set << 5);
  98. /* flush it */
  99. __asm__ __volatile__("FLUSHINV[%0];" : : "a"(addr));
  100. }
  101. }
  102. }
  103. #endif
  104. int bfin_pm_suspend_mem_enter(void)
  105. {
  106. int wakeup, ret;
  107. unsigned char *memptr = kmalloc(L1_CODE_LENGTH + L1_DATA_A_LENGTH
  108. + L1_DATA_B_LENGTH + L1_SCRATCH_LENGTH,
  109. GFP_KERNEL);
  110. if (memptr == NULL) {
  111. panic("bf53x_suspend_l1_mem malloc failed");
  112. return -ENOMEM;
  113. }
  114. wakeup = bfin_read_VR_CTL() & ~FREQ;
  115. wakeup |= SCKELOW;
  116. #ifdef CONFIG_PM_BFIN_WAKE_PH6
  117. wakeup |= PHYWE;
  118. #endif
  119. #ifdef CONFIG_PM_BFIN_WAKE_GP
  120. wakeup |= GPWE;
  121. #endif
  122. ret = blackfin_dma_suspend();
  123. if (ret) {
  124. kfree(memptr);
  125. return ret;
  126. }
  127. bfin_gpio_pm_hibernate_suspend();
  128. #if defined(CONFIG_BFIN_EXTMEM_WRITEBACK) || defined(CONFIG_BFIN_L2_WRITEBACK)
  129. flushinv_all_dcache();
  130. #endif
  131. _disable_dcplb();
  132. _disable_icplb();
  133. bf53x_suspend_l1_mem(memptr);
  134. do_hibernate(wakeup | vr_wakeup); /* See you later! */
  135. bf53x_resume_l1_mem(memptr);
  136. _enable_icplb();
  137. _enable_dcplb();
  138. bfin_gpio_pm_hibernate_restore();
  139. blackfin_dma_resume();
  140. kfree(memptr);
  141. return 0;
  142. }
  143. /*
  144. * bfin_pm_valid - Tell the PM core that we only support the standby sleep
  145. * state
  146. * @state: suspend state we're checking.
  147. *
  148. */
  149. static int bfin_pm_valid(suspend_state_t state)
  150. {
  151. return (state == PM_SUSPEND_STANDBY
  152. #if !(defined(BF533_FAMILY) || defined(CONFIG_BF561))
  153. /*
  154. * On BF533/2/1:
  155. * If we enter Hibernate the SCKE Pin is driven Low,
  156. * so that the SDRAM enters Self Refresh Mode.
  157. * However when the reset sequence that follows hibernate
  158. * state is executed, SCKE is driven High, taking the
  159. * SDRAM out of Self Refresh.
  160. *
  161. * If you reconfigure and access the SDRAM "very quickly",
  162. * you are likely to avoid errors, otherwise the SDRAM
  163. * start losing its contents.
  164. * An external HW workaround is possible using logic gates.
  165. */
  166. || state == PM_SUSPEND_MEM
  167. #endif
  168. );
  169. }
  170. /*
  171. * bfin_pm_enter - Actually enter a sleep state.
  172. * @state: State we're entering.
  173. *
  174. */
  175. static int bfin_pm_enter(suspend_state_t state)
  176. {
  177. switch (state) {
  178. case PM_SUSPEND_STANDBY:
  179. bfin_pm_suspend_standby_enter();
  180. break;
  181. case PM_SUSPEND_MEM:
  182. bfin_pm_suspend_mem_enter();
  183. break;
  184. default:
  185. return -EINVAL;
  186. }
  187. return 0;
  188. }
  189. static const struct platform_suspend_ops bfin_pm_ops = {
  190. .enter = bfin_pm_enter,
  191. .valid = bfin_pm_valid,
  192. };
  193. static int __init bfin_pm_init(void)
  194. {
  195. suspend_set_ops(&bfin_pm_ops);
  196. return 0;
  197. }
  198. __initcall(bfin_pm_init);