realizationOfDataCalculation.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*
  2. * OMAP3 Power Management Routines
  3. *
  4. * Copyright (C) 2006-2008 Nokia Corporation
  5. * Tony Lindgren <tony@atomide.com>
  6. * Jouni Hogander
  7. *
  8. * Copyright (C) 2007 Texas Instruments, Inc.
  9. * Rajendra Nayak <rnayak@ti.com>
  10. *
  11. * Copyright (C) 2005 Texas Instruments, Inc.
  12. * Richard Woodruff <r-woodruff2@ti.com>
  13. *
  14. * Based on pm.c for omap1
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/pm.h>
  21. #include <linux/suspend.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/module.h>
  24. #include <linux/list.h>
  25. #include <linux/err.h>
  26. #include <linux/gpio.h>
  27. #include <linux/clk.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/omap-dma.h>
  31. #include <linux/platform_data/gpio-omap.h>
  32. #include <trace/events/power.h>
  33. #include <asm/fncpy.h>
  34. #include <asm/suspend.h>
  35. #include <asm/system_misc.h>
  36. #include "clockdomain.h"
  37. #include "powerdomain.h"
  38. #include "soc.h"
  39. #include "common.h"
  40. #include "cm3xxx.h"
  41. #include "cm-regbits-34xx.h"
  42. #include "gpmc.h"
  43. #include "prm-regbits-34xx.h"
  44. #include "prm3xxx.h"
  45. #include "pm.h"
  46. #include "sdrc.h"
  47. #include "sram.h"
  48. #include "control.h"
  49. /* pm34xx errata defined in pm.h */
  50. u16 pm34xx_errata;
  51. struct power_state {
  52. struct powerdomain *pwrdm;
  53. u32 next_state;
  54. #ifdef CONFIG_SUSPEND
  55. u32 saved_state;
  56. #endif
  57. struct list_head node;
  58. };
  59. static LIST_HEAD(pwrst_list);
  60. static int (*_omap_save_secure_sram)(u32 *addr);
  61. void (*omap3_do_wfi_sram)(void);
  62. static struct powerdomain *mpu_pwrdm, *neon_pwrdm;
  63. static struct powerdomain *core_pwrdm, *per_pwrdm;
  64. static void omap3_core_save_context(void)
  65. {
  66. omap3_ctrl_save_padconf();
  67. /*
  68. * Force write last pad into memory, as this can fail in some
  69. * cases according to errata 1.157, 1.185
  70. */
  71. omap_ctrl_writel(omap_ctrl_readl(OMAP343X_PADCONF_ETK_D14),
  72. OMAP343X_CONTROL_MEM_WKUP + 0x2a0);
  73. /* Save the Interrupt controller context */
  74. omap_intc_save_context();
  75. /* Save the GPMC context */
  76. omap3_gpmc_save_context();
  77. /* Save the system control module context, padconf already save above*/
  78. omap3_control_save_context();
  79. omap_dma_global_context_save();
  80. }
  81. static void omap3_core_restore_context(void)
  82. {
  83. /* Restore the control module context, padconf restored by h/w */
  84. omap3_control_restore_context();
  85. /* Restore the GPMC context */
  86. omap3_gpmc_restore_context();
  87. /* Restore the interrupt controller context */
  88. omap_intc_restore_context();
  89. omap_dma_global_context_restore();
  90. }
  91. /*
  92. * FIXME: This function should be called before entering off-mode after
  93. * OMAP3 secure services have been accessed. Currently it is only called
  94. * once during boot sequence, but this works as we are not using secure
  95. * services.
  96. */
  97. static void omap3_save_secure_ram_context(void)
  98. {
  99. u32 ret;
  100. int mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  101. if (omap_type() != OMAP2_DEVICE_TYPE_GP) {
  102. /*
  103. * MPU next state must be set to POWER_ON temporarily,
  104. * otherwise the WFI executed inside the ROM code
  105. * will hang the system.
  106. */
  107. pwrdm_set_next_pwrst(mpu_pwrdm, PWRDM_POWER_ON);
  108. ret = _omap_save_secure_sram((u32 *)
  109. __pa(omap3_secure_ram_storage));
  110. pwrdm_set_next_pwrst(mpu_pwrdm, mpu_next_state);
  111. /* Following is for error tracking, it should not happen */
  112. if (ret) {
  113. pr_err("save_secure_sram() returns %08x\n", ret);
  114. while (1)
  115. ;
  116. }
  117. }
  118. }
  119. /*
  120. * PRCM Interrupt Handler Helper Function
  121. *
  122. * The purpose of this function is to clear any wake-up events latched
  123. * in the PRCM PM_WKST_x registers. It is possible that a wake-up event
  124. * may occur whilst attempting to clear a PM_WKST_x register and thus
  125. * set another bit in this register. A while loop is used to ensure
  126. * that any peripheral wake-up events occurring while attempting to
  127. * clear the PM_WKST_x are detected and cleared.
  128. */
  129. static int prcm_clear_mod_irqs(s16 module, u8 regs, u32 ignore_bits)
  130. {
  131. u32 wkst, fclk, iclk, clken;
  132. u16 wkst_off = (regs == 3) ? OMAP3430ES2_PM_WKST3 : PM_WKST1;
  133. u16 fclk_off = (regs == 3) ? OMAP3430ES2_CM_FCLKEN3 : CM_FCLKEN1;
  134. u16 iclk_off = (regs == 3) ? CM_ICLKEN3 : CM_ICLKEN1;
  135. u16 grpsel_off = (regs == 3) ?
  136. OMAP3430ES2_PM_MPUGRPSEL3 : OMAP3430_PM_MPUGRPSEL;
  137. int c = 0;
  138. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  139. wkst &= omap2_prm_read_mod_reg(module, grpsel_off);
  140. wkst &= ~ignore_bits;
  141. if (wkst) {
  142. iclk = omap2_cm_read_mod_reg(module, iclk_off);
  143. fclk = omap2_cm_read_mod_reg(module, fclk_off);
  144. while (wkst) {
  145. clken = wkst;
  146. omap2_cm_set_mod_reg_bits(clken, module, iclk_off);
  147. /*
  148. * For USBHOST, we don't know whether HOST1 or
  149. * HOST2 woke us up, so enable both f-clocks
  150. */
  151. if (module == OMAP3430ES2_USBHOST_MOD)
  152. clken |= 1 << OMAP3430ES2_EN_USBHOST2_SHIFT;
  153. omap2_cm_set_mod_reg_bits(clken, module, fclk_off);
  154. omap2_prm_write_mod_reg(wkst, module, wkst_off);
  155. wkst = omap2_prm_read_mod_reg(module, wkst_off);
  156. wkst &= ~ignore_bits;
  157. c++;
  158. }
  159. omap2_cm_write_mod_reg(iclk, module, iclk_off);
  160. omap2_cm_write_mod_reg(fclk, module, fclk_off);
  161. }
  162. return c;
  163. }
  164. static irqreturn_t _prcm_int_handle_io(int irq, void *unused)
  165. {
  166. int c;
  167. c = prcm_clear_mod_irqs(WKUP_MOD, 1,
  168. ~(OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK));
  169. return c ? IRQ_HANDLED : IRQ_NONE;
  170. }
  171. static irqreturn_t _prcm_int_handle_wakeup(int irq, void *unused)
  172. {
  173. int c;
  174. /*
  175. * Clear all except ST_IO and ST_IO_CHAIN for wkup module,
  176. * these are handled in a separate handler to avoid acking
  177. * IO events before parsing in mux code
  178. */
  179. c = prcm_clear_mod_irqs(WKUP_MOD, 1,
  180. OMAP3430_ST_IO_MASK | OMAP3430_ST_IO_CHAIN_MASK);
  181. c += prcm_clear_mod_irqs(CORE_MOD, 1, 0);
  182. c += prcm_clear_mod_irqs(OMAP3430_PER_MOD, 1, 0);
  183. if (omap_rev() > OMAP3430_REV_ES1_0) {
  184. c += prcm_clear_mod_irqs(CORE_MOD, 3, 0);
  185. c += prcm_clear_mod_irqs(OMAP3430ES2_USBHOST_MOD, 1, 0);
  186. }
  187. return c ? IRQ_HANDLED : IRQ_NONE;
  188. }
  189. static void omap34xx_save_context(u32 *save)
  190. {
  191. u32 val;
  192. /* Read Auxiliary Control Register */
  193. asm("mrc p15, 0, %0, c1, c0, 1" : "=r" (val));
  194. *save++ = 1;
  195. *save++ = val;
  196. /* Read L2 AUX ctrl register */
  197. asm("mrc p15, 1, %0, c9, c0, 2" : "=r" (val));
  198. *save++ = 1;
  199. *save++ = val;
  200. }
  201. static int omap34xx_do_sram_idle(unsigned long save_state)
  202. {
  203. omap34xx_cpu_suspend(save_state);
  204. return 0;
  205. }
  206. void omap_sram_idle(void)
  207. {
  208. /* Variable to tell what needs to be saved and restored
  209. * in omap_sram_idle*/
  210. /* save_state = 0 => Nothing to save and restored */
  211. /* save_state = 1 => Only L1 and logic lost */
  212. /* save_state = 2 => Only L2 lost */
  213. /* save_state = 3 => L1, L2 and logic lost */
  214. int save_state = 0;
  215. int mpu_next_state = PWRDM_POWER_ON;
  216. int per_next_state = PWRDM_POWER_ON;
  217. int core_next_state = PWRDM_POWER_ON;
  218. int per_going_off;
  219. int core_prev_state;
  220. u32 sdrc_pwr = 0;
  221. mpu_next_state = pwrdm_read_next_pwrst(mpu_pwrdm);
  222. switch (mpu_next_state) {
  223. case PWRDM_POWER_ON:
  224. case PWRDM_POWER_RET:
  225. /* No need to save context */
  226. save_state = 0;
  227. break;
  228. case PWRDM_POWER_OFF:
  229. save_state = 3;
  230. break;
  231. default:
  232. /* Invalid state */
  233. pr_err("Invalid mpu state in sram_idle\n");
  234. return;
  235. }
  236. /* NEON control */
  237. if (pwrdm_read_pwrst(neon_pwrdm) == PWRDM_POWER_ON)
  238. pwrdm_set_next_pwrst(neon_pwrdm, mpu_next_state);
  239. /* Enable IO-PAD and IO-CHAIN wakeups */
  240. per_next_state = pwrdm_read_next_pwrst(per_pwrdm);
  241. core_next_state = pwrdm_read_next_pwrst(core_pwrdm);
  242. pwrdm_pre_transition(NULL);
  243. /* PER */
  244. if (per_next_state < PWRDM_POWER_ON) {
  245. per_going_off = (per_next_state == PWRDM_POWER_OFF) ? 1 : 0;
  246. omap2_gpio_prepare_for_idle(per_going_off);
  247. }
  248. /* CORE */
  249. if (core_next_state < PWRDM_POWER_ON) {
  250. if (core_next_state == PWRDM_POWER_OFF) {
  251. omap3_core_save_context();
  252. omap3_cm_save_context();
  253. }
  254. }
  255. omap3_intc_prepare_idle();
  256. /*
  257. * On EMU/HS devices ROM code restores a SRDC value
  258. * from scratchpad which has automatic self refresh on timeout