Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 1 | /* |
| 2 | * OMAP2/3 powerdomain control |
| 3 | * |
| 4 | * Copyright (C) 2007-8 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2007-8 Nokia Corporation |
| 6 | * |
| 7 | * Written by 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 | |
| 14 | #ifndef ASM_ARM_ARCH_OMAP_POWERDOMAIN |
| 15 | #define ASM_ARM_ARCH_OMAP_POWERDOMAIN |
| 16 | |
| 17 | #include <linux/types.h> |
| 18 | #include <linux/list.h> |
| 19 | |
| 20 | #include <asm/atomic.h> |
| 21 | |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 22 | #include <plat/cpu.h> |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 23 | |
| 24 | |
| 25 | /* Powerdomain basic power states */ |
| 26 | #define PWRDM_POWER_OFF 0x0 |
| 27 | #define PWRDM_POWER_RET 0x1 |
| 28 | #define PWRDM_POWER_INACTIVE 0x2 |
| 29 | #define PWRDM_POWER_ON 0x3 |
| 30 | |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame^] | 31 | #define PWRDM_MAX_PWRSTS 4 |
| 32 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 33 | /* Powerdomain allowable state bitfields */ |
| 34 | #define PWRSTS_OFF_ON ((1 << PWRDM_POWER_OFF) | \ |
| 35 | (1 << PWRDM_POWER_ON)) |
| 36 | |
| 37 | #define PWRSTS_OFF_RET ((1 << PWRDM_POWER_OFF) | \ |
| 38 | (1 << PWRDM_POWER_RET)) |
| 39 | |
| 40 | #define PWRSTS_OFF_RET_ON (PWRSTS_OFF_RET | (1 << PWRDM_POWER_ON)) |
| 41 | |
| 42 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 43 | /* Powerdomain flags */ |
| 44 | #define PWRDM_HAS_HDWR_SAR (1 << 0) /* hardware save-and-restore support */ |
| 45 | |
| 46 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 47 | /* |
| 48 | * Number of memory banks that are power-controllable. On OMAP3430, the |
| 49 | * maximum is 4. |
| 50 | */ |
| 51 | #define PWRDM_MAX_MEM_BANKS 4 |
| 52 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 53 | /* |
| 54 | * Maximum number of clockdomains that can be associated with a powerdomain. |
Paul Walmsley | d37f1a1 | 2008-09-10 10:47:36 -0600 | [diff] [blame] | 55 | * CORE powerdomain on OMAP3 is the worst case |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 56 | */ |
Paul Walmsley | d37f1a1 | 2008-09-10 10:47:36 -0600 | [diff] [blame] | 57 | #define PWRDM_MAX_CLKDMS 4 |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 58 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 59 | /* XXX A completely arbitrary number. What is reasonable here? */ |
| 60 | #define PWRDM_TRANSITION_BAILOUT 100000 |
| 61 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 62 | struct clockdomain; |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 63 | struct powerdomain; |
| 64 | |
| 65 | /* Encodes dependencies between powerdomains - statically defined */ |
| 66 | struct pwrdm_dep { |
| 67 | |
| 68 | /* Powerdomain name */ |
| 69 | const char *pwrdm_name; |
| 70 | |
| 71 | /* Powerdomain pointer - resolved by the powerdomain code */ |
| 72 | struct powerdomain *pwrdm; |
| 73 | |
| 74 | /* Flags to mark OMAP chip restrictions, etc. */ |
| 75 | const struct omap_chip_id omap_chip; |
| 76 | |
| 77 | }; |
| 78 | |
| 79 | struct powerdomain { |
| 80 | |
| 81 | /* Powerdomain name */ |
| 82 | const char *name; |
| 83 | |
| 84 | /* the address offset from CM_BASE/PRM_BASE */ |
| 85 | const s16 prcm_offs; |
| 86 | |
| 87 | /* Used to represent the OMAP chip types containing this pwrdm */ |
| 88 | const struct omap_chip_id omap_chip; |
| 89 | |
| 90 | /* Bit shift of this powerdomain's PM_WKDEP/CM_SLEEPDEP bit */ |
| 91 | const u8 dep_bit; |
| 92 | |
| 93 | /* Powerdomains that can be told to wake this powerdomain up */ |
| 94 | struct pwrdm_dep *wkdep_srcs; |
| 95 | |
| 96 | /* Powerdomains that can be told to keep this pwrdm from inactivity */ |
| 97 | struct pwrdm_dep *sleepdep_srcs; |
| 98 | |
| 99 | /* Possible powerdomain power states */ |
| 100 | const u8 pwrsts; |
| 101 | |
| 102 | /* Possible logic power states when pwrdm in RETENTION */ |
| 103 | const u8 pwrsts_logic_ret; |
| 104 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 105 | /* Powerdomain flags */ |
| 106 | const u8 flags; |
| 107 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 108 | /* Number of software-controllable memory banks in this powerdomain */ |
| 109 | const u8 banks; |
| 110 | |
| 111 | /* Possible memory bank pwrstates when pwrdm in RETENTION */ |
| 112 | const u8 pwrsts_mem_ret[PWRDM_MAX_MEM_BANKS]; |
| 113 | |
| 114 | /* Possible memory bank pwrstates when pwrdm is ON */ |
| 115 | const u8 pwrsts_mem_on[PWRDM_MAX_MEM_BANKS]; |
| 116 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 117 | /* Clockdomains in this powerdomain */ |
| 118 | struct clockdomain *pwrdm_clkdms[PWRDM_MAX_CLKDMS]; |
| 119 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 120 | struct list_head node; |
| 121 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 122 | int state; |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame^] | 123 | unsigned state_counter[PWRDM_MAX_PWRSTS]; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 124 | |
| 125 | #ifdef CONFIG_PM_DEBUG |
| 126 | s64 timer; |
Paul Walmsley | 2354eb5 | 2009-12-08 16:33:12 -0700 | [diff] [blame^] | 127 | s64 state_timer[PWRDM_MAX_PWRSTS]; |
Peter 'p2' De Schrijver | 331b93f | 2008-10-15 18:13:48 +0300 | [diff] [blame] | 128 | #endif |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | |
| 132 | void pwrdm_init(struct powerdomain **pwrdm_list); |
| 133 | |
| 134 | int pwrdm_register(struct powerdomain *pwrdm); |
| 135 | int pwrdm_unregister(struct powerdomain *pwrdm); |
| 136 | struct powerdomain *pwrdm_lookup(const char *name); |
| 137 | |
Peter 'p2' De Schrijver | a23456e | 2008-10-15 18:13:47 +0300 | [diff] [blame] | 138 | int pwrdm_for_each(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 139 | void *user); |
Artem Bityutskiy | ee894b1 | 2009-10-01 10:01:55 +0300 | [diff] [blame] | 140 | int pwrdm_for_each_nolock(int (*fn)(struct powerdomain *pwrdm, void *user), |
| 141 | void *user); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 142 | |
Paul Walmsley | 8420bb1 | 2008-08-19 11:08:44 +0300 | [diff] [blame] | 143 | int pwrdm_add_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm); |
| 144 | int pwrdm_del_clkdm(struct powerdomain *pwrdm, struct clockdomain *clkdm); |
| 145 | int pwrdm_for_each_clkdm(struct powerdomain *pwrdm, |
| 146 | int (*fn)(struct powerdomain *pwrdm, |
| 147 | struct clockdomain *clkdm)); |
| 148 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 149 | int pwrdm_add_wkdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 150 | int pwrdm_del_wkdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 151 | int pwrdm_read_wkdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 152 | int pwrdm_add_sleepdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 153 | int pwrdm_del_sleepdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 154 | int pwrdm_read_sleepdep(struct powerdomain *pwrdm1, struct powerdomain *pwrdm2); |
| 155 | |
| 156 | int pwrdm_get_mem_bank_count(struct powerdomain *pwrdm); |
| 157 | |
| 158 | int pwrdm_set_next_pwrst(struct powerdomain *pwrdm, u8 pwrst); |
| 159 | int pwrdm_read_next_pwrst(struct powerdomain *pwrdm); |
Paul Walmsley | fecb494 | 2009-01-27 19:12:50 -0700 | [diff] [blame] | 160 | int pwrdm_read_pwrst(struct powerdomain *pwrdm); |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 161 | int pwrdm_read_prev_pwrst(struct powerdomain *pwrdm); |
| 162 | int pwrdm_clear_all_prev_pwrst(struct powerdomain *pwrdm); |
| 163 | |
| 164 | int pwrdm_set_logic_retst(struct powerdomain *pwrdm, u8 pwrst); |
| 165 | int pwrdm_set_mem_onst(struct powerdomain *pwrdm, u8 bank, u8 pwrst); |
| 166 | int pwrdm_set_mem_retst(struct powerdomain *pwrdm, u8 bank, u8 pwrst); |
| 167 | |
| 168 | int pwrdm_read_logic_pwrst(struct powerdomain *pwrdm); |
| 169 | int pwrdm_read_prev_logic_pwrst(struct powerdomain *pwrdm); |
| 170 | int pwrdm_read_mem_pwrst(struct powerdomain *pwrdm, u8 bank); |
| 171 | int pwrdm_read_prev_mem_pwrst(struct powerdomain *pwrdm, u8 bank); |
| 172 | |
Paul Walmsley | 0b7cbfb | 2008-06-25 18:09:37 -0600 | [diff] [blame] | 173 | int pwrdm_enable_hdwr_sar(struct powerdomain *pwrdm); |
| 174 | int pwrdm_disable_hdwr_sar(struct powerdomain *pwrdm); |
| 175 | bool pwrdm_has_hdwr_sar(struct powerdomain *pwrdm); |
| 176 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 177 | int pwrdm_wait_transition(struct powerdomain *pwrdm); |
| 178 | |
Peter 'p2' De Schrijver | ba20bb1 | 2008-10-15 17:48:43 +0300 | [diff] [blame] | 179 | int pwrdm_state_switch(struct powerdomain *pwrdm); |
| 180 | int pwrdm_clkdm_state_switch(struct clockdomain *clkdm); |
| 181 | int pwrdm_pre_transition(void); |
| 182 | int pwrdm_post_transition(void); |
| 183 | |
Paul Walmsley | ad67ef6 | 2008-08-19 11:08:40 +0300 | [diff] [blame] | 184 | #endif |