Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef __ARCH_ARM_MACH_MSM_SPM_H |
| 14 | #define __ARCH_ARM_MACH_MSM_SPM_H |
| 15 | enum { |
| 16 | MSM_SPM_MODE_DISABLED, |
| 17 | MSM_SPM_MODE_CLOCK_GATING, |
| 18 | MSM_SPM_MODE_POWER_RETENTION, |
| 19 | MSM_SPM_MODE_POWER_COLLAPSE, |
| 20 | MSM_SPM_MODE_NR |
| 21 | }; |
| 22 | |
| 23 | enum { |
| 24 | MSM_SPM_L2_MODE_DISABLED = MSM_SPM_MODE_DISABLED, |
| 25 | MSM_SPM_L2_MODE_RETENTION, |
| 26 | MSM_SPM_L2_MODE_GDHS, |
| 27 | MSM_SPM_L2_MODE_POWER_COLLAPSE, |
| 28 | }; |
| 29 | |
| 30 | #if defined(CONFIG_MSM_SPM_V1) |
| 31 | |
| 32 | enum { |
| 33 | MSM_SPM_REG_SAW_AVS_CTL, |
| 34 | MSM_SPM_REG_SAW_CFG, |
| 35 | MSM_SPM_REG_SAW_SPM_CTL, |
| 36 | MSM_SPM_REG_SAW_SPM_SLP_TMR_DLY, |
| 37 | MSM_SPM_REG_SAW_SPM_WAKE_TMR_DLY, |
| 38 | MSM_SPM_REG_SAW_SLP_CLK_EN, |
| 39 | MSM_SPM_REG_SAW_SLP_HSFS_PRECLMP_EN, |
| 40 | MSM_SPM_REG_SAW_SLP_HSFS_POSTCLMP_EN, |
| 41 | MSM_SPM_REG_SAW_SLP_CLMP_EN, |
| 42 | MSM_SPM_REG_SAW_SLP_RST_EN, |
| 43 | MSM_SPM_REG_SAW_SPM_MPM_CFG, |
| 44 | MSM_SPM_REG_NR_INITIALIZE, |
| 45 | |
| 46 | MSM_SPM_REG_SAW_VCTL = MSM_SPM_REG_NR_INITIALIZE, |
| 47 | MSM_SPM_REG_SAW_STS, |
| 48 | MSM_SPM_REG_SAW_SPM_PMIC_CTL, |
| 49 | MSM_SPM_REG_NR |
| 50 | }; |
| 51 | |
| 52 | struct msm_spm_platform_data { |
| 53 | void __iomem *reg_base_addr; |
| 54 | uint32_t reg_init_values[MSM_SPM_REG_NR_INITIALIZE]; |
| 55 | |
| 56 | uint8_t awake_vlevel; |
| 57 | uint8_t retention_vlevel; |
| 58 | uint8_t collapse_vlevel; |
| 59 | uint8_t retention_mid_vlevel; |
| 60 | uint8_t collapse_mid_vlevel; |
| 61 | |
| 62 | uint32_t vctl_timeout_us; |
| 63 | }; |
| 64 | |
| 65 | #elif defined(CONFIG_MSM_SPM_V2) |
| 66 | |
| 67 | enum { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 68 | MSM_SPM_REG_SAW2_CFG, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 69 | MSM_SPM_REG_SAW2_AVS_CTL, |
| 70 | MSM_SPM_REG_SAW2_AVS_HYSTERESIS, |
| 71 | MSM_SPM_REG_SAW2_SPM_CTL, |
| 72 | MSM_SPM_REG_SAW2_PMIC_DLY, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 73 | MSM_SPM_REG_SAW2_AVS_LIMIT, |
| 74 | MSM_SPM_REG_SAW2_AVS_DLY, |
| 75 | MSM_SPM_REG_SAW2_SPM_DLY, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 76 | MSM_SPM_REG_SAW2_PMIC_DATA_0, |
| 77 | MSM_SPM_REG_SAW2_PMIC_DATA_1, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 78 | MSM_SPM_REG_SAW2_PMIC_DATA_2, |
| 79 | MSM_SPM_REG_SAW2_PMIC_DATA_3, |
| 80 | MSM_SPM_REG_SAW2_PMIC_DATA_4, |
| 81 | MSM_SPM_REG_SAW2_PMIC_DATA_5, |
| 82 | MSM_SPM_REG_SAW2_PMIC_DATA_6, |
| 83 | MSM_SPM_REG_SAW2_PMIC_DATA_7, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 84 | MSM_SPM_REG_SAW2_RST, |
| 85 | |
Mahesh Sivasubramanian | d740fab | 2012-01-20 13:49:47 -0700 | [diff] [blame] | 86 | MSM_SPM_REG_NR_INITIALIZE = MSM_SPM_REG_SAW2_RST, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 87 | |
Mahesh Sivasubramanian | d740fab | 2012-01-20 13:49:47 -0700 | [diff] [blame] | 88 | MSM_SPM_REG_SAW2_ID, |
| 89 | MSM_SPM_REG_SAW2_SECURE, |
| 90 | MSM_SPM_REG_SAW2_STS0, |
| 91 | MSM_SPM_REG_SAW2_STS1, |
| 92 | MSM_SPM_REG_SAW2_VCTL, |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 93 | MSM_SPM_REG_SAW2_SEQ_ENTRY, |
| 94 | MSM_SPM_REG_SAW2_SPM_STS, |
| 95 | MSM_SPM_REG_SAW2_AVS_STS, |
| 96 | MSM_SPM_REG_SAW2_PMIC_STS, |
| 97 | MSM_SPM_REG_SAW2_VERSION, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 98 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 99 | MSM_SPM_REG_NR, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | struct msm_spm_seq_entry { |
| 103 | uint32_t mode; |
| 104 | uint8_t *cmd; |
| 105 | bool notify_rpm; |
| 106 | }; |
| 107 | |
| 108 | struct msm_spm_platform_data { |
| 109 | void __iomem *reg_base_addr; |
| 110 | uint32_t reg_init_values[MSM_SPM_REG_NR_INITIALIZE]; |
| 111 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 112 | uint32_t ver_reg; |
| 113 | uint32_t vctl_port; |
| 114 | uint32_t phase_port; |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 115 | uint32_t pfm_port; |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 116 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 117 | uint8_t awake_vlevel; |
| 118 | uint32_t vctl_timeout_us; |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 119 | uint32_t avs_timeout_us; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 120 | |
| 121 | uint32_t num_modes; |
| 122 | struct msm_spm_seq_entry *modes; |
| 123 | }; |
| 124 | #endif |
| 125 | |
| 126 | #if defined(CONFIG_MSM_SPM_V1) || defined(CONFIG_MSM_SPM_V2) |
| 127 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 128 | /* Public functions */ |
| 129 | |
| 130 | /** |
| 131 | * msm_spm_set_low_power_mode() - Configure SPM start address for low power mode |
| 132 | * @mode: SPM LPM mode to enter |
| 133 | * @notify_rpm: Notify RPM in this mode |
| 134 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 135 | int msm_spm_set_low_power_mode(unsigned int mode, bool notify_rpm); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 136 | |
| 137 | /** |
| 138 | * msm_spm_set_vdd(): Set core voltage |
| 139 | * @cpu: core id |
| 140 | * @vlevel: Encoded PMIC data. |
| 141 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 142 | int msm_spm_set_vdd(unsigned int cpu, unsigned int vlevel); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 143 | |
| 144 | /** |
Praveen Chidambaram | 4133ba1 | 2012-09-29 22:27:03 -0600 | [diff] [blame] | 145 | * msm_spm_get_vdd(): Get core voltage |
| 146 | * @cpu: core id |
| 147 | * @return: Returns encoded PMIC data. |
| 148 | */ |
| 149 | unsigned int msm_spm_get_vdd(unsigned int cpu); |
| 150 | |
| 151 | /** |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 152 | * msm_spm_turn_on_cpu_rail(): Power on cpu rail before turning on core |
| 153 | * @cpu: core id |
| 154 | */ |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 155 | int msm_spm_turn_on_cpu_rail(unsigned int cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 156 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 157 | /* Internal low power management specific functions */ |
| 158 | |
| 159 | /** |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 160 | * msm_spm_reinit(): Reinitialize SPM registers |
| 161 | */ |
| 162 | void msm_spm_reinit(void); |
| 163 | |
| 164 | /** |
| 165 | * msm_spm_init(): Board initalization function |
| 166 | * @data: platform specific SPM register configuration data |
| 167 | * @nr_devs: Number of SPM devices being initialized |
| 168 | */ |
| 169 | int msm_spm_init(struct msm_spm_platform_data *data, int nr_devs); |
| 170 | |
| 171 | /** |
| 172 | * msm_spm_device_init(): Device tree initialization function |
| 173 | */ |
| 174 | int msm_spm_device_init(void); |
| 175 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 176 | #if defined(CONFIG_MSM_L2_SPM) |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 177 | |
| 178 | /* Public functions */ |
| 179 | |
| 180 | /** |
| 181 | * msm_spm_l2_set_low_power_mode(): Configure L2 SPM start address |
| 182 | * for low power mode |
| 183 | * @mode: SPM LPM mode to enter |
| 184 | * @notify_rpm: Notify RPM in this mode |
| 185 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 186 | int msm_spm_l2_set_low_power_mode(unsigned int mode, bool notify_rpm); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 187 | |
| 188 | /** |
| 189 | * msm_spm_apcs_set_vdd(): Set Apps processor core sub-system voltage |
| 190 | * @vlevel: Encoded PMIC data. |
| 191 | */ |
| 192 | int msm_spm_apcs_set_vdd(unsigned int vlevel); |
| 193 | |
| 194 | /** |
| 195 | * msm_spm_apcs_set_phase(): Set number of SMPS phases. |
| 196 | * phase_cnt: Number of phases to be set active |
| 197 | */ |
| 198 | int msm_spm_apcs_set_phase(unsigned int phase_cnt); |
| 199 | |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 200 | /** msm_spm_enable_fts_lpm() : Enable FTS to switch to low power |
| 201 | * when the cores are in low power modes |
| 202 | * @mode: The mode configuration for FTS |
| 203 | */ |
| 204 | int msm_spm_enable_fts_lpm(uint32_t mode); |
| 205 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 206 | /* Internal low power management specific functions */ |
| 207 | |
| 208 | /** |
| 209 | * msm_spm_l2_init(): Board initialization function |
| 210 | * @data: SPM target specific register configuration |
| 211 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 212 | int msm_spm_l2_init(struct msm_spm_platform_data *data); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * msm_spm_l2_reinit(): Reinitialize L2 SPM registers |
| 216 | */ |
Maheshkumar Sivasubramanian | 4ac2376 | 2011-11-02 10:03:06 -0600 | [diff] [blame] | 217 | void msm_spm_l2_reinit(void); |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 218 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 219 | #else |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 220 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | static inline int msm_spm_l2_set_low_power_mode(unsigned int mode, |
| 222 | bool notify_rpm) |
| 223 | { |
| 224 | return -ENOSYS; |
| 225 | } |
| 226 | static inline int msm_spm_l2_init(struct msm_spm_platform_data *data) |
| 227 | { |
| 228 | return -ENOSYS; |
| 229 | } |
Maheshkumar Sivasubramanian | 4ac2376 | 2011-11-02 10:03:06 -0600 | [diff] [blame] | 230 | static inline void msm_spm_l2_reinit(void) |
| 231 | { |
| 232 | /* empty */ |
| 233 | } |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 234 | |
| 235 | static inline int msm_spm_apcs_set_vdd(unsigned int vlevel) |
| 236 | { |
| 237 | return -ENOSYS; |
| 238 | } |
| 239 | |
| 240 | static inline int msm_spm_apcs_set_phase(unsigned int phase_cnt) |
| 241 | { |
| 242 | return -ENOSYS; |
| 243 | } |
Praveen Chidambaram | 1dbe495 | 2012-10-03 17:06:02 -0600 | [diff] [blame] | 244 | |
| 245 | static inline int msm_spm_enable_fts_lpm(uint32_t mode) |
| 246 | { |
| 247 | return -ENOSYS; |
| 248 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 249 | #endif /* defined(CONFIG_MSM_L2_SPM) */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 250 | #else /* defined(CONFIG_MSM_SPM_V1) || defined(CONFIG_MSM_SPM_V2) */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 251 | static inline int msm_spm_set_low_power_mode(unsigned int mode, bool notify_rpm) |
| 252 | { |
| 253 | return -ENOSYS; |
| 254 | } |
| 255 | |
| 256 | static inline int msm_spm_set_vdd(unsigned int cpu, unsigned int vlevel) |
| 257 | { |
| 258 | return -ENOSYS; |
| 259 | } |
| 260 | |
Praveen Chidambaram | 4133ba1 | 2012-09-29 22:27:03 -0600 | [diff] [blame] | 261 | static inline unsigned int msm_spm_get_vdd(unsigned int cpu) |
| 262 | { |
| 263 | return 0; |
| 264 | } |
| 265 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | static inline void msm_spm_reinit(void) |
| 267 | { |
| 268 | /* empty */ |
| 269 | } |
| 270 | |
Praveen Chidambaram | c0750ca | 2012-01-08 10:03:28 -0700 | [diff] [blame] | 271 | static inline int msm_spm_turn_on_cpu_rail(unsigned int cpu) |
| 272 | { |
| 273 | return -ENOSYS; |
| 274 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | |
Praveen Chidambaram | aa9d52b | 2012-04-02 11:09:47 -0600 | [diff] [blame] | 276 | static inline int msm_spm_device_init(void) |
| 277 | { |
| 278 | return -ENOSYS; |
| 279 | } |
| 280 | |
| 281 | #endif /*defined(CONFIG_MSM_SPM_V1) || defined (CONFIG_MSM_SPM_V2) */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 282 | #endif /* __ARCH_ARM_MACH_MSM_SPM_H */ |