powerdomain.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * OMAP2/3/4 powerdomain control
  3. *
  4. * Copyright (C) 2007-2008, 2010 Texas Instruments, Inc.
  5. * Copyright (C) 2007-2011 Nokia Corporation
  6. *
  7. * Paul Walmsley
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * XXX This should be moved to the mach-omap2/ directory at the earliest
  14. * opportunity.
  15. */
  16. #ifndef __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
  17. #define __ARCH_ARM_MACH_OMAP2_POWERDOMAIN_H
  18. #include <linux/types.h>
  19. #include <linux/list.h>
  20. #include <linux/spinlock.h>
  21. /* Powerdomain basic power states */
  22. #define PWRDM_POWER_OFF 0x0
  23. #define PWRDM_POWER_RET 0x1
  24. #define PWRDM_POWER_INACTIVE 0x2
  25. #define PWRDM_POWER_ON 0x3
  26. #define PWRDM_MAX_PWRSTS 4
  27. /* Powerdomain allowable state bitfields */
  28. #define PWRSTS_ON (1 << PWRDM_POWER_ON)
  29. #define PWRSTS_INACTIVE (1 << PWRDM_POWER_INACTIVE)
  30. #define PWRSTS_RET (1 << PWRDM_POWER_RET)
  31. #define PWRSTS_OFF (1 << PWRDM_POWER_OFF)
  32. #define PWRSTS_OFF_ON (PWRSTS_OFF | PWRSTS_ON)
  33. #define PWRSTS_OFF_RET (PWRSTS_OFF | PWRSTS_RET)
  34. #define PWRSTS_RET_ON (PWRSTS_RET | PWRSTS_ON)
  35. #define PWRSTS_OFF_RET_ON (PWRSTS_OFF_RET | PWRSTS_ON)
  36. #define PWRSTS_INA_ON (PWRSTS_INACTIVE | PWRSTS_ON)
  37. /*
  38. * Powerdomain flags (struct powerdomain.flags)
  39. *
  40. * PWRDM_HAS_HDWR_SAR - powerdomain has hardware save-and-restore support
  41. *
  42. * PWRDM_HAS_MPU_QUIRK - MPU pwr domain has MEM bank 0 bits in MEM
  43. * bank 1 position. This is true for OMAP3430
  44. *
  45. * PWRDM_HAS_LOWPOWERSTATECHANGE - can transition from a sleep state
  46. * to a lower sleep state without waking up the powerdomain
  47. */
  48. #define PWRDM_HAS_HDWR_SAR BIT(0)
  49. #define PWRDM_HAS_MPU_QUIRK BIT(1)
  50. #define PWRDM_HAS_LOWPOWERSTATECHANGE BIT(2)
  51. /*
  52. * Number of memory banks that are power-controllable. On OMAP4430, the
  53. * maximum is 5.
  54. */
  55. #define PWRDM_MAX_MEM_BANKS 5
  56. /*
  57. * Maximum number of clockdomains that can be associated with a powerdomain.
  58. * PER powerdomain on AM33XX is the worst case
  59. */
  60. #define PWRDM_MAX_CLKDMS 11
  61. /* XXX A completely arbitrary number. What is reasonable here? */
  62. #define PWRDM_TRANSITION_BAILOUT 100000
  63. struct clockdomain;
  64. struct powerdomain;
  65. struct voltagedomain;
  66. /**
  67. * struct powerdomain - OMAP powerdomain
  68. * @name: Powerdomain name
  69. * @voltdm: voltagedomain containing this powerdomain
  70. * @prcm_offs: the address offset from CM_BASE/PRM_BASE
  71. * @prcm_partition: (OMAP4 only) the PRCM partition ID containing @prcm_offs
  72. * @pwrsts: Possible powerdomain power states
  73. * @pwrsts_logic_ret: Possible logic power states when pwrdm in RETENTION
  74. * @flags: Powerdomain flags
  75. * @banks: Number of software-controllable memory banks in this powerdomain
  76. * @pwrsts_mem_ret: Possible memory bank pwrstates when pwrdm in RETENTION
  77. * @pwrsts_mem_on: Possible memory bank pwrstates when pwrdm in ON
  78. * @pwrdm_clkdms: Clockdomains in this powerdomain
  79. * @node: list_head linking all powerdomains
  80. * @voltdm_node: list_head linking all powerdomains in a voltagedomain
  81. * @pwrstctrl_offs: (AM33XX only) XXX_PWRSTCTRL reg offset from prcm_offs
  82. * @pwrstst_offs: (AM33XX only) XXX_PWRSTST reg offset from prcm_offs
  83. * @logicretstate_mask: (AM33XX only) mask for logic retention bitfield
  84. * in @pwrstctrl_offs
  85. * @mem_on_mask: (AM33XX only) mask for mem on bitfield in @pwrstctrl_offs
  86. * @mem_ret_mask: (AM33XX only) mask for mem ret bitfield in @pwrstctrl_offs
  87. * @mem_pwrst_mask: (AM33XX only) mask for mem state bitfield in @pwrstst_offs
  88. * @mem_retst_mask: (AM33XX only) mask for mem retention state bitfield
  89. * in @pwrstctrl_offs
  90. * @state:
  91. * @state_counter:
  92. * @timer:
  93. * @state_timer:
  94. * @_lock: spinlock used to serialize powerdomain and some clockdomain ops
  95. * @_lock_flags: stored flags when @_lock is taken
  96. *
  97. * @prcm_partition possible values are defined in mach-omap2/prcm44xx.h.
  98. */
  99. struct powerdomain {
  100. const char *name;
  101. union {
  102. const char *name;
  103. struct voltagedomain *ptr;
  104. } voltdm;
  105. const s16 prcm_offs;
  106. const u8 pwrsts;
  107. const u8 pwrsts_logic_ret;
  108. const u8 flags;
  109. const u8 banks;
  110. const u8 pwrsts_mem_ret[PWRDM_MAX_MEM_BANKS];
  111. const u8 pwrsts_mem_on[PWRDM_MAX_MEM_BANKS];
  112. const u8 prcm_partition;
  113. struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS];
  114. struct list_head node;
  115. struct list_head voltdm_node;
  116. int state;
  117. unsigned state_counter[PWRDM_MAX_PWRSTS];
  118. unsigned ret_logic_off_counter;
  119. unsigned ret_mem_off_counter[PWRDM_MAX_MEM_BANKS];
  120. spinlock_t _lock;
  121. unsigned long _lock_flags;
  122. const u8 pwrstctrl_offs;
  123. const u8 pwrstst_offs;
  124. const u32 logicretstate_mask;
  125. const u32 mem_on_mask[PWRDM_MAX_MEM_BANKS];
  126. const u32 mem_ret_mask[PWRDM_MAX_MEM_BANKS];
  127. const u32 mem_pwrst_mask[PWRDM_MAX_MEM_BANKS];
  128. const u32 mem_retst_mask[PWRDM_MAX_MEM_BANKS];
  129. #ifdef CONFIG_PM_DEBUG
  130. s64 timer;
  131. s64 state_timer[PWRDM_MAX_PWRSTS];
  132. #endif
  133. };
  134. /**
  135. * struct pwrdm_ops - Arch specific function implementations
  136. * @pwrdm_set_next_pwrst: Set the target power state for a pd
  137. * @pwrdm_read_next_pwrst: Read the target power state set for a pd
  138. * @pwrdm_read_pwrst: Read the current power state of a pd
  139. * @pwrdm_read_prev_pwrst: Read the prev power state entered by the pd
  140. * @pwrdm_set_logic_retst: Set the logic state in RET for a pd
  141. * @pwrdm_set_mem_onst: Set the Memory state in ON for a pd
  142. * @pwrdm_set_mem_retst: Set the Memory state in RET for a pd
  143. * @pwrdm_read_logic_pwrst: Read the current logic state of a pd
  144. * @pwrdm_read_prev_logic_pwrst: Read the previous logic state entered by a pd
  145. * @pwrdm_read_logic_retst: Read the logic state in RET for a pd
  146. * @pwrdm_read_mem_pwrst: Read the current memory state of a pd
  147. * @pwrdm_read_prev_mem_pwrst: Read the previous memory state entered by a pd
  148. * @pwrdm_read_mem_retst: Read the memory state in RET for a pd
  149. * @pwrdm_clear_all_prev_pwrst: Clear all previous power states logged for a pd
  150. * @pwrdm_enable_hdwr_sar: Enable Hardware Save-Restore feature for the pd
  151. * @pwrdm_disable_hdwr_sar: Disable Hardware Save-Restore feature for a pd
  152. * @pwrdm_set_lowpwrstchange: Enable pd transitions from a shallow to deep sleep
  153. * @pwrdm_wait_transition: Wait for a pd state transition to complete
  154. * @pwrdm_has_voltdm: Check if a voltdm association is needed
  155. *
  156. * Regarding @pwrdm_set_lowpwrstchange: On the OMAP2 and 3-family
  157. * chips, a powerdomain's power state is not allowed to directly
  158. * transition from one low-power state (e.g., CSWR) to another
  159. * low-power state (e.g., OFF) without first waking up the
  160. * powerdomain. This wastes energy. So OMAP4 chips support the
  161. * ability to transition a powerdomain power state directly from one
  162. * low-power state to another. The function pointed to by
  163. * @pwrdm_set_lowpwrstchange is intended to configure the OMAP4
  164. * hardware powerdomain state machine to enable this feature.
  165. */
  166. struct pwrdm_ops {
  167. int (*pwrdm_set_next_pwrst)(struct powerdomain *pwrdm, u8 pwrst);
  168. int (*pwrdm_read_next_pwrst)(struct powerdomain *pwrdm);
  169. int (*pwrdm_read_pwrst)(struct powerdomain *pwrdm);
  170. int (*pwrdm_read_prev_pwrst)(struct powerdomain *pwrdm);
  171. int (*pwrdm_set_logic_retst)(struct powerdomain *pwrdm, u8 pwrst);
  172. int (*pwrdm_set_mem_onst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
  173. int (*pwrdm_set_mem_retst)(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
  174. int (*pwrdm_read_logic_pwrst)(struct powerdomain *pwrdm);
  175. int (*pwrdm_read_prev_logic_pwrst)(struct powerdomain *pwrdm);
  176. int (*pwrdm_read_logic_retst)(struct powerdomain *pwrdm);
  177. int (*pwrdm_read_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
  178. int (*pwrdm_read_prev_mem_pwrst)(struct powerdomain *pwrdm, u8 bank);
  179. int (*pwrdm_read_mem_retst)(struct powerdomain *pwrdm, u8 bank);
  180. int (*pwrdm_clear_all_prev_pwrst)(struct powerdomain *pwrdm);
  181. int (*pwrdm_enable_hdwr_sar)(struct powerdomain *pwrdm);
  182. int (*pwrdm_disable_hdwr_sar)(struct powerdomain *pwrdm);
  183. int (*pwrdm_set_lowpwrstchange)(struct powerdomain *pwrdm);
  184. int (*pwrdm_wait_transition)(struct powerdomain *pwrdm);
  185. int (*pwrdm_has_voltdm)(void);
  186. };
  187. int pwrdm_register_platform_funcs(struct pwrdm_ops *custom_funcs);
  188. int pwrdm_register_pwrdms(struct powerdomain **pwrdm_list);
  189. int pwrdm_complete_init(void);
  190. struct powerdomain *pwrdm_lookup(const char *name);
  191. int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user),
  192. void *user);
  193. int pwrdm_for_each_nolock(int (*fn)(struct powerdomain *pwrdm, void *user),
  194. void *user);
  195. int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm);
  196. int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm);
  197. u8 pwrdm_get_valid_lp_state(struct powerdomain *pwrdm,
  198. bool is_logic_state, u8 req_state);
  199. int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst);
  200. int pwrdm_read_next_pwrst(struct powerdomain *pwrdm);
  201. int pwrdm_read_pwrst(struct powerdomain *pwrdm);
  202. int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm);
  203. int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm);
  204. int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst);
  205. int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
  206. int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst);
  207. int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm);
  208. int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm);
  209. int pwrdm_read_logic_retst(struct powerdomain *pwrdm);
  210. int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
  211. int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank);
  212. int pwrdm_read_mem_retst(struct powerdomain *pwrdm, u8 bank);
  213. int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm);
  214. int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm);
  215. bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm);
  216. int pwrdm_state_switch_nolock(struct powerdomain *pwrdm);
  217. int pwrdm_state_switch(struct powerdomain *pwrdm);
  218. int pwrdm_pre_transition(struct powerdomain *pwrdm);
  219. int pwrdm_post_transition(struct powerdomain *pwrdm);
  220. int pwrdm_get_context_loss_count(struct powerdomain *pwrdm);
  221. bool pwrdm_can_ever_lose_context(struct powerdomain *pwrdm);
  222. extern int omap_set_pwrdm_state(struct powerdomain *pwrdm, u8 state);
  223. extern void omap242x_powerdomains_init(void);
  224. extern void omap243x_powerdomains_init(void);
  225. extern void omap3xxx_powerdomains_init(void);
  226. extern void am33xx_powerdomains_init(void);
  227. extern void omap44xx_powerdomains_init(void);
  228. extern void omap54xx_powerdomains_init(void);
  229. extern void dra7xx_powerdomains_init(void);
  230. void am43xx_powerdomains_init(void);
  231. extern struct pwrdm_ops omap2_pwrdm_operations;
  232. extern struct pwrdm_ops omap3_pwrdm_operations;
  233. extern struct pwrdm_ops am33xx_pwrdm_operations;
  234. extern struct pwrdm_ops omap4_pwrdm_operations;
  235. /* Common Internal functions used across OMAP rev's */
  236. extern u32 omap2_pwrdm_get_mem_bank_onstate_mask(u8 bank);
  237. extern u32 omap2_pwrdm_get_mem_bank_retst_mask(u8 bank);
  238. extern u32 omap2_pwrdm_get_mem_bank_stst_mask(u8 bank);
  239. extern struct powerdomain wkup_omap2_pwrdm;
  240. extern struct powerdomain gfx_omap2_pwrdm;
  241. extern void pwrdm_lock(struct powerdomain *pwrdm);
  242. extern void pwrdm_unlock(struct powerdomain *pwrdm);
  243. #endif