Priyanka Mathur | f198a16 | 2012-12-05 19:05:00 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, The Linux Foundation. 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 | |
| 14 | #ifndef __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H |
| 15 | #define __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H |
| 16 | |
| 17 | #include <mach/rpm.h> |
Priyanka Mathur | f198a16 | 2012-12-05 19:05:00 -0800 | [diff] [blame] | 18 | #include <linux/notifier.h> |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 19 | #include "pm.h" |
Priyanka Mathur | f198a16 | 2012-12-05 19:05:00 -0800 | [diff] [blame] | 20 | #include "test-lpm.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
Praveen Chidambaram | 7849901 | 2011-11-01 17:15:17 -0600 | [diff] [blame] | 22 | enum { |
| 23 | MSM_RPMRS_ID_PXO_CLK = 0, |
| 24 | MSM_RPMRS_ID_L2_CACHE_CTL = 1, |
| 25 | MSM_RPMRS_ID_VDD_DIG_0 = 2, |
| 26 | MSM_RPMRS_ID_VDD_DIG_1 = 3, |
| 27 | MSM_RPMRS_ID_VDD_MEM_0 = 4, |
| 28 | MSM_RPMRS_ID_VDD_MEM_1 = 5, |
| 29 | MSM_RPMRS_ID_RPM_CTL = 6, |
| 30 | MSM_RPMRS_ID_LAST, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | enum { |
| 34 | MSM_RPMRS_PXO_OFF = 0, |
| 35 | MSM_RPMRS_PXO_ON = 1, |
| 36 | }; |
| 37 | |
| 38 | enum { |
| 39 | MSM_RPMRS_L2_CACHE_HSFS_OPEN = 0, |
| 40 | MSM_RPMRS_L2_CACHE_GDHS = 1, |
| 41 | MSM_RPMRS_L2_CACHE_RETENTION = 2, |
| 42 | MSM_RPMRS_L2_CACHE_ACTIVE = 3, |
| 43 | }; |
| 44 | |
Praveen Chidambaram | 9dfa871 | 2011-09-14 16:25:01 -0600 | [diff] [blame] | 45 | enum { |
| 46 | MSM_RPMRS_MASK_RPM_CTL_CPU_HALT = 1, |
| 47 | MSM_RPMRS_MASK_RPM_CTL_MULTI_TIER = 2, |
| 48 | }; |
| 49 | |
Praveen Chidambaram | 7849901 | 2011-11-01 17:15:17 -0600 | [diff] [blame] | 50 | enum { |
| 51 | MSM_RPMRS_VDD_MEM_RET_LOW = 0, |
| 52 | MSM_RPMRS_VDD_MEM_RET_HIGH = 1, |
| 53 | MSM_RPMRS_VDD_MEM_ACTIVE = 2, |
| 54 | MSM_RPMRS_VDD_MEM_MAX = 3, |
| 55 | MSM_RPMRS_VDD_MEM_LAST, |
| 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | MSM_RPMRS_VDD_DIG_RET_LOW = 0, |
| 60 | MSM_RPMRS_VDD_DIG_RET_HIGH = 1, |
| 61 | MSM_RPMRS_VDD_DIG_ACTIVE = 2, |
| 62 | MSM_RPMRS_VDD_DIG_MAX = 3, |
| 63 | MSM_RPMRS_VDD_DIG_LAST, |
| 64 | }; |
| 65 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 66 | #define MSM_RPMRS_LIMITS(_pxo, _l2, _vdd_upper_b, _vdd) { \ |
| 67 | MSM_RPMRS_PXO_##_pxo, \ |
| 68 | MSM_RPMRS_L2_CACHE_##_l2, \ |
| 69 | MSM_RPMRS_VDD_MEM_##_vdd_upper_b, \ |
| 70 | MSM_RPMRS_VDD_MEM_##_vdd, \ |
| 71 | MSM_RPMRS_VDD_DIG_##_vdd_upper_b, \ |
| 72 | MSM_RPMRS_VDD_DIG_##_vdd, \ |
| 73 | {0}, {0}, \ |
| 74 | } |
| 75 | |
Praveen Chidambaram | 7849901 | 2011-11-01 17:15:17 -0600 | [diff] [blame] | 76 | struct msm_rpmrs_limits { |
| 77 | uint32_t pxo; |
| 78 | uint32_t l2_cache; |
| 79 | uint32_t vdd_mem_upper_bound; |
| 80 | uint32_t vdd_mem; |
| 81 | uint32_t vdd_dig_upper_bound; |
| 82 | uint32_t vdd_dig; |
| 83 | |
| 84 | uint32_t latency_us[NR_CPUS]; |
| 85 | uint32_t power[NR_CPUS]; |
| 86 | }; |
| 87 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | struct msm_rpmrs_level { |
| 89 | enum msm_pm_sleep_mode sleep_mode; |
| 90 | struct msm_rpmrs_limits rs_limits; |
| 91 | bool available; |
| 92 | uint32_t latency_us; |
| 93 | uint32_t steady_state_power; |
| 94 | uint32_t energy_overhead; |
| 95 | uint32_t time_overhead_us; |
| 96 | }; |
| 97 | |
Praveen Chidambaram | 7849901 | 2011-11-01 17:15:17 -0600 | [diff] [blame] | 98 | struct msm_rpmrs_platform_data { |
| 99 | struct msm_rpmrs_level *levels; |
| 100 | unsigned int num_levels; |
| 101 | unsigned int vdd_mem_levels[MSM_RPMRS_VDD_MEM_LAST]; |
| 102 | unsigned int vdd_dig_levels[MSM_RPMRS_VDD_DIG_LAST]; |
| 103 | unsigned int vdd_mask; |
| 104 | unsigned int rpmrs_target_id[MSM_RPMRS_ID_LAST]; |
| 105 | }; |
| 106 | |
Priyanka Mathur | f198a16 | 2012-12-05 19:05:00 -0800 | [diff] [blame] | 107 | enum { |
| 108 | MSM_LPM_STATE_ENTER = 0, |
| 109 | MSM_LPM_STATE_EXIT = 1, |
| 110 | }; |
| 111 | |
| 112 | /** |
| 113 | * struct msm_lpm_sleep_data - abstraction to get sleep data |
| 114 | * @limits: pointer to the msm_rpmrs_limits structure |
| 115 | * @kernel_sleep: kernel sleep time as decided by the power calculation |
| 116 | * algorithm |
| 117 | * |
| 118 | * This structure is an abstraction to get the limits and kernel sleep time |
| 119 | * during enter sleep. |
| 120 | */ |
| 121 | |
| 122 | struct msm_lpm_sleep_data { |
| 123 | struct msm_rpmrs_limits *limits; |
| 124 | uint32_t kernel_sleep; |
| 125 | }; |
| 126 | |
| 127 | #define MSM_PM(field) MSM_RPMRS_##field |
| 128 | |
| 129 | /** |
| 130 | * msm_pm_get_pxo() - get the limits for pxo |
| 131 | * @limits: pointer to the msm_rpmrs_limits structure |
| 132 | * |
| 133 | * This function gets the limits to the resource pxo on |
| 134 | * 8960 |
| 135 | */ |
| 136 | |
| 137 | uint32_t msm_pm_get_pxo(struct msm_rpmrs_limits *limits); |
| 138 | |
| 139 | /** |
| 140 | * msm_pm_get_l2_cache() - get the limits for l2 cache |
| 141 | * @limits: pointer to the msm_rpmrs_limits structure |
| 142 | * |
| 143 | * This function gets the limits to the resource l2 cache |
| 144 | * on 8960 |
| 145 | */ |
| 146 | |
| 147 | uint32_t msm_pm_get_l2_cache(struct msm_rpmrs_limits *limits); |
| 148 | |
| 149 | /** |
| 150 | * msm_pm_get_vdd_mem() - get the limits for pxo |
| 151 | * @limits: pointer to the msm_rpmrs_limits structure |
| 152 | * |
| 153 | * This function gets the limits to the resource vdd mem |
| 154 | * on 8960 |
| 155 | */ |
| 156 | |
| 157 | uint32_t msm_pm_get_vdd_mem(struct msm_rpmrs_limits *limits); |
| 158 | |
| 159 | /** |
| 160 | * msm_pm_get_vdd_dig() - get the limits for vdd dig |
| 161 | * @limits: pointer to the msm_rpmrs_limits structure |
| 162 | * |
| 163 | * This function gets the limits to the resource vdd dig |
| 164 | * on 8960 |
| 165 | */ |
| 166 | |
| 167 | uint32_t msm_pm_get_vdd_dig(struct msm_rpmrs_limits *limits); |
| 168 | |
| 169 | /** |
| 170 | * msm_lpm_register_notifier() - register for notifications |
| 171 | * @cpu: cpu to debug |
| 172 | * @level_iter: low power level index to debug |
| 173 | * @nb: notifier block to callback on notifications |
| 174 | * @is_latency_measure: is it latency measure |
| 175 | * |
| 176 | * This function sets the permitted level to the index of the |
| 177 | * level under test and registers notifier for callback. |
| 178 | */ |
| 179 | |
| 180 | int msm_lpm_register_notifier(int cpu, int level_iter, |
| 181 | struct notifier_block *nb, bool is_latency_measure); |
| 182 | |
| 183 | /** |
| 184 | * msm_lpm_unregister_notifier() - unregister from notifications |
| 185 | * @cpu: cpu to debug |
| 186 | * @nb: notifier block to callback on notifications |
| 187 | * |
| 188 | * This function sets the permitted level to a value one more than |
| 189 | * available levels count which indicates that all levels are |
| 190 | * permitted and it also unregisters notifier for callback. |
| 191 | */ |
| 192 | |
| 193 | int msm_lpm_unregister_notifier(int cpu, struct notifier_block *nb); |
| 194 | |
Vikram Mulukutla | be97fbe | 2012-05-16 21:36:33 -0700 | [diff] [blame] | 195 | #if defined(CONFIG_MSM_RPM) |
| 196 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 197 | int msm_rpmrs_set(int ctx, struct msm_rpm_iv_pair *req, int count); |
| 198 | int msm_rpmrs_set_noirq(int ctx, struct msm_rpm_iv_pair *req, int count); |
Praveen Chidambaram | 9dfa871 | 2011-09-14 16:25:01 -0600 | [diff] [blame] | 199 | int msm_rpmrs_set_bits_noirq(int ctx, struct msm_rpm_iv_pair *req, int count, |
| 200 | int *mask); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | |
| 202 | static inline int msm_rpmrs_set_nosleep( |
| 203 | int ctx, struct msm_rpm_iv_pair *req, int count) |
| 204 | { |
| 205 | unsigned long flags; |
| 206 | int rc; |
| 207 | |
| 208 | local_irq_save(flags); |
| 209 | rc = msm_rpmrs_set_noirq(ctx, req, count); |
| 210 | local_irq_restore(flags); |
| 211 | |
| 212 | return rc; |
| 213 | } |
| 214 | |
| 215 | int msm_rpmrs_clear(int ctx, struct msm_rpm_iv_pair *req, int count); |
| 216 | int msm_rpmrs_clear_noirq(int ctx, struct msm_rpm_iv_pair *req, int count); |
| 217 | |
| 218 | static inline int msm_rpmrs_clear_nosleep( |
| 219 | int ctx, struct msm_rpm_iv_pair *req, int count) |
| 220 | { |
| 221 | unsigned long flags; |
| 222 | int rc; |
| 223 | |
| 224 | local_irq_save(flags); |
| 225 | rc = msm_rpmrs_clear_noirq(ctx, req, count); |
| 226 | local_irq_restore(flags); |
| 227 | |
| 228 | return rc; |
| 229 | } |
| 230 | |
| 231 | void msm_rpmrs_show_resources(void); |
Praveen Chidambaram | 7849901 | 2011-11-01 17:15:17 -0600 | [diff] [blame] | 232 | int msm_rpmrs_levels_init(struct msm_rpmrs_platform_data *data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 233 | |
Vikram Mulukutla | be97fbe | 2012-05-16 21:36:33 -0700 | [diff] [blame] | 234 | #else |
| 235 | |
| 236 | static inline int msm_rpmrs_set(int ctx, struct msm_rpm_iv_pair *req, |
| 237 | int count) |
| 238 | { |
| 239 | return -ENODEV; |
| 240 | } |
| 241 | |
| 242 | static inline int msm_rpmrs_set_noirq(int ctx, struct msm_rpm_iv_pair *req, |
| 243 | int count) |
| 244 | { |
| 245 | return -ENODEV; |
| 246 | } |
| 247 | |
| 248 | static inline int msm_rpmrs_set_bits_noirq(int ctx, struct msm_rpm_iv_pair *req, |
| 249 | int count, int *mask) |
| 250 | { |
| 251 | return -ENODEV; |
| 252 | } |
| 253 | |
| 254 | static inline int msm_rpmrs_set_nosleep( |
| 255 | int ctx, struct msm_rpm_iv_pair *req, int count) |
| 256 | { |
| 257 | return -ENODEV; |
| 258 | } |
| 259 | |
| 260 | static inline int msm_rpmrs_clear(int ctx, struct msm_rpm_iv_pair *req, |
| 261 | int count) |
| 262 | { |
| 263 | return -ENODEV; |
| 264 | } |
| 265 | |
| 266 | static inline int msm_rpmrs_clear_noirq(int ctx, struct msm_rpm_iv_pair *req, |
| 267 | int count) |
| 268 | { |
| 269 | return -ENODEV; |
| 270 | } |
| 271 | |
| 272 | static inline int msm_rpmrs_clear_nosleep( |
| 273 | int ctx, struct msm_rpm_iv_pair *req, int count) |
| 274 | { |
| 275 | return -ENODEV; |
| 276 | } |
| 277 | |
| 278 | static inline struct msm_rpmrs_limits *msm_rpmrs_lowest_limits( |
| 279 | bool from_idle, enum msm_pm_sleep_mode sleep_mode, uint32_t latency_us, |
| 280 | uint32_t sleep_us) |
| 281 | { |
| 282 | return NULL; |
| 283 | } |
| 284 | |
| 285 | static inline int msm_rpmrs_enter_sleep(uint32_t sclk_count, |
| 286 | struct msm_rpmrs_limits *limits, bool from_idle, bool notify_rpm) |
| 287 | { |
| 288 | return -ENODEV; |
| 289 | } |
| 290 | |
| 291 | static inline void msm_rpmrs_exit_sleep(struct msm_rpmrs_limits *limits, |
| 292 | bool from_idle, bool notify_rpm, bool collapsed) |
| 293 | { |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | static inline int msm_rpmrs_levels_init(struct msm_rpmrs_platform_data *data) |
| 298 | { |
| 299 | return -ENODEV; |
| 300 | } |
| 301 | |
| 302 | #endif /* CONFIG_MSM_RPM */ |
| 303 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 304 | #endif /* __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H */ |