Duy Truong | e833aca | 2013-02-12 13:35:08 -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 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 13 | |
| 14 | #include <linux/export.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 16 | #include <asm/page.h> |
Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 17 | #include <linux/pm_runtime.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <mach/msm_iomap.h> |
| 19 | #include <mach/msm_bus.h> |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 20 | #include <linux/ktime.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
| 22 | #include "kgsl.h" |
| 23 | #include "kgsl_pwrscale.h" |
| 24 | #include "kgsl_device.h" |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 25 | #include "kgsl_trace.h" |
Ranjhith Kalisamy | cb1721c | 2013-05-28 16:59:59 -0600 | [diff] [blame] | 26 | #include "kgsl_sharedmem.h" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | |
Jeremy Gebben | b46f415 | 2011-10-14 14:27:00 -0600 | [diff] [blame] | 28 | #define KGSL_PWRFLAGS_POWER_ON 0 |
| 29 | #define KGSL_PWRFLAGS_CLK_ON 1 |
| 30 | #define KGSL_PWRFLAGS_AXI_ON 2 |
| 31 | #define KGSL_PWRFLAGS_IRQ_ON 3 |
| 32 | |
Lucille Sylvester | 1029789 | 2012-02-27 13:54:47 -0700 | [diff] [blame] | 33 | #define GPU_SWFI_LATENCY 3 |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 34 | #define UPDATE_BUSY_VAL 1000000 |
| 35 | #define UPDATE_BUSY 50 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 36 | |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 37 | struct clk_pair { |
| 38 | const char *name; |
| 39 | uint map; |
| 40 | }; |
| 41 | |
| 42 | struct clk_pair clks[KGSL_MAX_CLKS] = { |
| 43 | { |
| 44 | .name = "src_clk", |
| 45 | .map = KGSL_CLK_SRC, |
| 46 | }, |
| 47 | { |
| 48 | .name = "core_clk", |
| 49 | .map = KGSL_CLK_CORE, |
| 50 | }, |
| 51 | { |
| 52 | .name = "iface_clk", |
| 53 | .map = KGSL_CLK_IFACE, |
| 54 | }, |
| 55 | { |
| 56 | .name = "mem_clk", |
| 57 | .map = KGSL_CLK_MEM, |
| 58 | }, |
| 59 | { |
| 60 | .name = "mem_iface_clk", |
| 61 | .map = KGSL_CLK_MEM_IFACE, |
| 62 | }, |
| 63 | }; |
| 64 | |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 65 | /* Update the elapsed time at a particular clock level |
| 66 | * if the device is active(on_time = true).Otherwise |
| 67 | * store it as sleep time. |
| 68 | */ |
| 69 | static void update_clk_statistics(struct kgsl_device *device, |
| 70 | bool on_time) |
| 71 | { |
| 72 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 73 | struct kgsl_clk_stats *clkstats = &pwr->clk_stats; |
| 74 | ktime_t elapsed; |
| 75 | int elapsed_us; |
| 76 | if (clkstats->start.tv64 == 0) |
| 77 | clkstats->start = ktime_get(); |
| 78 | clkstats->stop = ktime_get(); |
| 79 | elapsed = ktime_sub(clkstats->stop, clkstats->start); |
| 80 | elapsed_us = ktime_to_us(elapsed); |
| 81 | clkstats->elapsed += elapsed_us; |
| 82 | if (on_time) |
| 83 | clkstats->clock_time[pwr->active_pwrlevel] += elapsed_us; |
| 84 | else |
| 85 | clkstats->clock_time[pwr->num_pwrlevels - 1] += elapsed_us; |
| 86 | clkstats->start = ktime_get(); |
| 87 | } |
| 88 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Given a requested power level do bounds checking on the constraints and |
| 91 | * return the nearest possible level |
| 92 | */ |
| 93 | |
| 94 | static inline int _adjust_pwrlevel(struct kgsl_pwrctrl *pwr, int level) |
| 95 | { |
Jordan Crouse | 00a01ba | 2012-12-05 15:58:16 -0700 | [diff] [blame] | 96 | int max_pwrlevel = max_t(int, pwr->thermal_pwrlevel, pwr->max_pwrlevel); |
| 97 | int min_pwrlevel = max_t(int, pwr->thermal_pwrlevel, pwr->min_pwrlevel); |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 98 | |
| 99 | if (level < max_pwrlevel) |
| 100 | return max_pwrlevel; |
| 101 | if (level > min_pwrlevel) |
| 102 | return min_pwrlevel; |
| 103 | |
| 104 | return level; |
| 105 | } |
| 106 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | void kgsl_pwrctrl_pwrlevel_change(struct kgsl_device *device, |
| 108 | unsigned int new_level) |
| 109 | { |
| 110 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 111 | struct kgsl_pwrlevel *pwrlevel; |
| 112 | int delta; |
Jordan Crouse | 3c337a3 | 2012-12-04 16:16:51 -0700 | [diff] [blame] | 113 | int level; |
Jordan Crouse | a29a2e0 | 2012-08-14 09:09:23 -0600 | [diff] [blame] | 114 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 115 | /* Adjust the power level to the current constraints */ |
| 116 | new_level = _adjust_pwrlevel(pwr, new_level); |
| 117 | |
| 118 | if (new_level == pwr->active_pwrlevel) |
| 119 | return; |
| 120 | |
| 121 | delta = new_level < pwr->active_pwrlevel ? -1 : 1; |
| 122 | |
| 123 | update_clk_statistics(device, true); |
| 124 | |
Jordan Crouse | 3c337a3 | 2012-12-04 16:16:51 -0700 | [diff] [blame] | 125 | level = pwr->active_pwrlevel; |
| 126 | |
| 127 | /* |
| 128 | * Set the active powerlevel first in case the clocks are off - if we |
| 129 | * don't do this then the pwrlevel change won't take effect when the |
| 130 | * clocks come back |
| 131 | */ |
| 132 | |
| 133 | pwr->active_pwrlevel = new_level; |
| 134 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 135 | if (test_bit(KGSL_PWRFLAGS_CLK_ON, &pwr->power_flags) || |
| 136 | (device->state == KGSL_STATE_NAP)) { |
| 137 | |
| 138 | /* |
| 139 | * On some platforms, instability is caused on |
| 140 | * changing clock freq when the core is busy. |
| 141 | * Idle the gpu core before changing the clock freq. |
| 142 | */ |
| 143 | |
| 144 | if (pwr->idle_needed == true) |
| 145 | device->ftbl->idle(device); |
| 146 | |
| 147 | /* |
| 148 | * Don't shift by more than one level at a time to |
| 149 | * avoid glitches. |
| 150 | */ |
| 151 | |
Jordan Crouse | 3c337a3 | 2012-12-04 16:16:51 -0700 | [diff] [blame] | 152 | while (level != new_level) { |
| 153 | level += delta; |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 154 | |
| 155 | clk_set_rate(pwr->grp_clks[0], |
Jordan Crouse | 3c337a3 | 2012-12-04 16:16:51 -0700 | [diff] [blame] | 156 | pwr->pwrlevels[level].gpu_freq); |
Kedar Joshi | c11d098 | 2012-02-07 10:59:49 +0530 | [diff] [blame] | 157 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 158 | } |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 159 | |
| 160 | pwrlevel = &pwr->pwrlevels[pwr->active_pwrlevel]; |
| 161 | |
| 162 | if (test_bit(KGSL_PWRFLAGS_AXI_ON, &pwr->power_flags)) { |
| 163 | |
| 164 | if (pwr->pcl) |
| 165 | msm_bus_scale_client_update_request(pwr->pcl, |
| 166 | pwrlevel->bus_freq); |
| 167 | else if (pwr->ebi1_clk) |
| 168 | clk_set_rate(pwr->ebi1_clk, pwrlevel->bus_freq); |
| 169 | } |
| 170 | |
| 171 | trace_kgsl_pwrlevel(device, pwr->active_pwrlevel, pwrlevel->gpu_freq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | } |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 173 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | EXPORT_SYMBOL(kgsl_pwrctrl_pwrlevel_change); |
| 175 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 176 | static int kgsl_pwrctrl_thermal_pwrlevel_store(struct device *dev, |
| 177 | struct device_attribute *attr, |
| 178 | const char *buf, size_t count) |
| 179 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 180 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 181 | struct kgsl_pwrctrl *pwr; |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 182 | int ret, level; |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 183 | |
| 184 | if (device == NULL) |
| 185 | return 0; |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 186 | |
| 187 | pwr = &device->pwrctrl; |
| 188 | |
| 189 | ret = sscanf(buf, "%d", &level); |
| 190 | if (ret != 1) |
| 191 | return count; |
| 192 | |
| 193 | if (level < 0) |
| 194 | return count; |
| 195 | |
| 196 | mutex_lock(&device->mutex); |
| 197 | |
| 198 | if (level > pwr->num_pwrlevels - 2) |
| 199 | level = pwr->num_pwrlevels - 2; |
| 200 | |
| 201 | pwr->thermal_pwrlevel = level; |
| 202 | |
| 203 | /* |
| 204 | * If there is no power policy set the clock to the requested thermal |
| 205 | * level - if thermal now happens to be higher than max, then that will |
| 206 | * be limited by the pwrlevel change function. Otherwise if there is |
| 207 | * a policy only change the active clock if it is higher then the new |
| 208 | * thermal level |
| 209 | */ |
| 210 | |
| 211 | if (device->pwrscale.policy == NULL || |
| 212 | pwr->thermal_pwrlevel > pwr->active_pwrlevel) |
| 213 | kgsl_pwrctrl_pwrlevel_change(device, pwr->thermal_pwrlevel); |
| 214 | |
| 215 | mutex_unlock(&device->mutex); |
| 216 | |
| 217 | return count; |
| 218 | } |
| 219 | |
| 220 | static int kgsl_pwrctrl_thermal_pwrlevel_show(struct device *dev, |
| 221 | struct device_attribute *attr, |
| 222 | char *buf) |
| 223 | { |
| 224 | |
| 225 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 226 | struct kgsl_pwrctrl *pwr; |
| 227 | if (device == NULL) |
| 228 | return 0; |
| 229 | pwr = &device->pwrctrl; |
| 230 | return snprintf(buf, PAGE_SIZE, "%d\n", pwr->thermal_pwrlevel); |
| 231 | } |
| 232 | |
| 233 | static int kgsl_pwrctrl_max_pwrlevel_store(struct device *dev, |
| 234 | struct device_attribute *attr, |
| 235 | const char *buf, size_t count) |
| 236 | { |
| 237 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 238 | struct kgsl_pwrctrl *pwr; |
| 239 | int ret, level, max_level; |
| 240 | |
| 241 | if (device == NULL) |
| 242 | return 0; |
| 243 | |
| 244 | pwr = &device->pwrctrl; |
| 245 | |
| 246 | ret = sscanf(buf, "%d", &level); |
| 247 | if (ret != 1) |
| 248 | return count; |
| 249 | |
| 250 | /* If the use specifies a negative number, then don't change anything */ |
| 251 | if (level < 0) |
| 252 | return count; |
| 253 | |
| 254 | mutex_lock(&device->mutex); |
| 255 | |
| 256 | /* You can't set a maximum power level lower than the minimum */ |
| 257 | if (level > pwr->min_pwrlevel) |
| 258 | level = pwr->min_pwrlevel; |
| 259 | |
| 260 | pwr->max_pwrlevel = level; |
| 261 | |
| 262 | |
| 263 | max_level = max_t(int, pwr->thermal_pwrlevel, pwr->max_pwrlevel); |
| 264 | |
| 265 | /* |
| 266 | * If there is no policy then move to max by default. Otherwise only |
| 267 | * move max if the current level happens to be higher then the new max |
| 268 | */ |
| 269 | |
| 270 | if (device->pwrscale.policy == NULL || |
| 271 | (max_level > pwr->active_pwrlevel)) |
| 272 | kgsl_pwrctrl_pwrlevel_change(device, max_level); |
| 273 | |
| 274 | mutex_unlock(&device->mutex); |
| 275 | |
| 276 | return count; |
| 277 | } |
| 278 | |
| 279 | static int kgsl_pwrctrl_max_pwrlevel_show(struct device *dev, |
| 280 | struct device_attribute *attr, |
| 281 | char *buf) |
| 282 | { |
| 283 | |
| 284 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 285 | struct kgsl_pwrctrl *pwr; |
| 286 | if (device == NULL) |
| 287 | return 0; |
| 288 | pwr = &device->pwrctrl; |
| 289 | return snprintf(buf, PAGE_SIZE, "%d\n", pwr->max_pwrlevel); |
| 290 | } |
| 291 | |
| 292 | static int kgsl_pwrctrl_min_pwrlevel_store(struct device *dev, |
| 293 | struct device_attribute *attr, |
| 294 | const char *buf, size_t count) |
| 295 | { struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 296 | struct kgsl_pwrctrl *pwr; |
| 297 | int ret, level, min_level; |
| 298 | |
| 299 | if (device == NULL) |
| 300 | return 0; |
| 301 | |
| 302 | pwr = &device->pwrctrl; |
| 303 | |
| 304 | ret = sscanf(buf, "%d", &level); |
| 305 | if (ret != 1) |
| 306 | return count; |
| 307 | |
| 308 | /* Don't do anything on obviously incorrect values */ |
| 309 | if (level < 0) |
| 310 | return count; |
| 311 | |
| 312 | mutex_lock(&device->mutex); |
| 313 | if (level > pwr->num_pwrlevels - 2) |
| 314 | level = pwr->num_pwrlevels - 2; |
| 315 | |
| 316 | /* You can't set a minimum power level lower than the maximum */ |
| 317 | if (level < pwr->max_pwrlevel) |
| 318 | level = pwr->max_pwrlevel; |
| 319 | |
| 320 | pwr->min_pwrlevel = level; |
| 321 | |
| 322 | min_level = max_t(int, pwr->thermal_pwrlevel, pwr->min_pwrlevel); |
| 323 | |
| 324 | /* Only move the power level higher if minimum is higher then the |
| 325 | * current level |
| 326 | */ |
| 327 | |
| 328 | if (min_level < pwr->active_pwrlevel) |
| 329 | kgsl_pwrctrl_pwrlevel_change(device, min_level); |
| 330 | |
| 331 | mutex_unlock(&device->mutex); |
| 332 | |
| 333 | return count; |
| 334 | } |
| 335 | |
| 336 | static int kgsl_pwrctrl_min_pwrlevel_show(struct device *dev, |
| 337 | struct device_attribute *attr, |
| 338 | char *buf) |
| 339 | { |
| 340 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 341 | struct kgsl_pwrctrl *pwr; |
| 342 | if (device == NULL) |
| 343 | return 0; |
| 344 | pwr = &device->pwrctrl; |
| 345 | return snprintf(buf, PAGE_SIZE, "%d\n", pwr->min_pwrlevel); |
| 346 | } |
| 347 | |
| 348 | static int kgsl_pwrctrl_num_pwrlevels_show(struct device *dev, |
| 349 | struct device_attribute *attr, |
| 350 | char *buf) |
| 351 | { |
| 352 | |
| 353 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 354 | struct kgsl_pwrctrl *pwr; |
| 355 | if (device == NULL) |
| 356 | return 0; |
| 357 | pwr = &device->pwrctrl; |
| 358 | return snprintf(buf, PAGE_SIZE, "%d\n", pwr->num_pwrlevels - 1); |
| 359 | } |
| 360 | |
| 361 | /* Given a GPU clock value, return the nearest powerlevel */ |
| 362 | |
| 363 | static int _get_nearest_pwrlevel(struct kgsl_pwrctrl *pwr, unsigned int clock) |
| 364 | { |
| 365 | int i; |
| 366 | |
| 367 | for (i = 0; i < pwr->num_pwrlevels - 1; i++) { |
| 368 | if (abs(pwr->pwrlevels[i].gpu_freq - clock) < 5000000) |
| 369 | return i; |
| 370 | } |
| 371 | |
| 372 | return -ERANGE; |
| 373 | } |
| 374 | |
| 375 | static int kgsl_pwrctrl_max_gpuclk_store(struct device *dev, |
| 376 | struct device_attribute *attr, |
| 377 | const char *buf, size_t count) |
| 378 | { |
| 379 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 380 | struct kgsl_pwrctrl *pwr; |
| 381 | unsigned long val; |
| 382 | int ret, level; |
| 383 | |
| 384 | if (device == NULL) |
| 385 | return 0; |
| 386 | |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 387 | pwr = &device->pwrctrl; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 388 | |
| 389 | ret = sscanf(buf, "%ld", &val); |
| 390 | if (ret != 1) |
| 391 | return count; |
| 392 | |
| 393 | mutex_lock(&device->mutex); |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 394 | level = _get_nearest_pwrlevel(pwr, val); |
| 395 | if (level < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 396 | goto done; |
| 397 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 398 | pwr->thermal_pwrlevel = level; |
| 399 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 400 | /* |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 401 | * if the thermal limit is lower than the current setting, |
| 402 | * move the speed down immediately |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 403 | */ |
| 404 | |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 405 | if (pwr->thermal_pwrlevel > pwr->active_pwrlevel) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 406 | kgsl_pwrctrl_pwrlevel_change(device, pwr->thermal_pwrlevel); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 407 | |
| 408 | done: |
| 409 | mutex_unlock(&device->mutex); |
| 410 | return count; |
| 411 | } |
| 412 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 413 | static int kgsl_pwrctrl_max_gpuclk_show(struct device *dev, |
| 414 | struct device_attribute *attr, |
| 415 | char *buf) |
| 416 | { |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 417 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 418 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 419 | struct kgsl_pwrctrl *pwr; |
| 420 | if (device == NULL) |
| 421 | return 0; |
| 422 | pwr = &device->pwrctrl; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 423 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 424 | pwr->pwrlevels[pwr->thermal_pwrlevel].gpu_freq); |
| 425 | } |
| 426 | |
| 427 | static int kgsl_pwrctrl_gpuclk_store(struct device *dev, |
| 428 | struct device_attribute *attr, |
| 429 | const char *buf, size_t count) |
| 430 | { |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 431 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 432 | struct kgsl_pwrctrl *pwr; |
| 433 | unsigned long val; |
| 434 | int ret, level; |
| 435 | |
| 436 | if (device == NULL) |
| 437 | return 0; |
| 438 | |
| 439 | pwr = &device->pwrctrl; |
| 440 | |
| 441 | ret = sscanf(buf, "%ld", &val); |
| 442 | if (ret != 1) |
| 443 | return count; |
| 444 | |
| 445 | mutex_lock(&device->mutex); |
| 446 | level = _get_nearest_pwrlevel(pwr, val); |
| 447 | if (level >= 0) |
| 448 | kgsl_pwrctrl_pwrlevel_change(device, level); |
| 449 | |
| 450 | mutex_unlock(&device->mutex); |
| 451 | return count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static int kgsl_pwrctrl_gpuclk_show(struct device *dev, |
| 455 | struct device_attribute *attr, |
| 456 | char *buf) |
| 457 | { |
| 458 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 459 | struct kgsl_pwrctrl *pwr; |
| 460 | if (device == NULL) |
| 461 | return 0; |
| 462 | pwr = &device->pwrctrl; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 463 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 464 | pwr->pwrlevels[pwr->active_pwrlevel].gpu_freq); |
| 465 | } |
| 466 | |
| 467 | static int kgsl_pwrctrl_pwrnap_store(struct device *dev, |
| 468 | struct device_attribute *attr, |
| 469 | const char *buf, size_t count) |
| 470 | { |
| 471 | char temp[20]; |
| 472 | unsigned long val; |
| 473 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 474 | struct kgsl_pwrctrl *pwr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 475 | int rc; |
| 476 | |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 477 | if (device == NULL) |
| 478 | return 0; |
| 479 | pwr = &device->pwrctrl; |
| 480 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 481 | snprintf(temp, sizeof(temp), "%.*s", |
| 482 | (int)min(count, sizeof(temp) - 1), buf); |
| 483 | rc = strict_strtoul(temp, 0, &val); |
| 484 | if (rc) |
| 485 | return rc; |
| 486 | |
| 487 | mutex_lock(&device->mutex); |
| 488 | |
| 489 | if (val == 1) |
| 490 | pwr->nap_allowed = true; |
| 491 | else if (val == 0) |
| 492 | pwr->nap_allowed = false; |
| 493 | |
| 494 | mutex_unlock(&device->mutex); |
| 495 | |
| 496 | return count; |
| 497 | } |
| 498 | |
| 499 | static int kgsl_pwrctrl_pwrnap_show(struct device *dev, |
| 500 | struct device_attribute *attr, |
| 501 | char *buf) |
| 502 | { |
| 503 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 504 | if (device == NULL) |
| 505 | return 0; |
| 506 | return snprintf(buf, PAGE_SIZE, "%d\n", device->pwrctrl.nap_allowed); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | |
| 510 | static int kgsl_pwrctrl_idle_timer_store(struct device *dev, |
| 511 | struct device_attribute *attr, |
| 512 | const char *buf, size_t count) |
| 513 | { |
| 514 | char temp[20]; |
| 515 | unsigned long val; |
| 516 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 517 | struct kgsl_pwrctrl *pwr; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 518 | const long div = 1000/HZ; |
| 519 | static unsigned int org_interval_timeout = 1; |
| 520 | int rc; |
| 521 | |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 522 | if (device == NULL) |
| 523 | return 0; |
| 524 | pwr = &device->pwrctrl; |
| 525 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 526 | snprintf(temp, sizeof(temp), "%.*s", |
| 527 | (int)min(count, sizeof(temp) - 1), buf); |
| 528 | rc = strict_strtoul(temp, 0, &val); |
| 529 | if (rc) |
| 530 | return rc; |
| 531 | |
| 532 | if (org_interval_timeout == 1) |
| 533 | org_interval_timeout = pwr->interval_timeout; |
| 534 | |
| 535 | mutex_lock(&device->mutex); |
| 536 | |
| 537 | /* Let the timeout be requested in ms, but convert to jiffies. */ |
| 538 | val /= div; |
| 539 | if (val >= org_interval_timeout) |
| 540 | pwr->interval_timeout = val; |
| 541 | |
| 542 | mutex_unlock(&device->mutex); |
| 543 | |
| 544 | return count; |
| 545 | } |
| 546 | |
| 547 | static int kgsl_pwrctrl_idle_timer_show(struct device *dev, |
| 548 | struct device_attribute *attr, |
| 549 | char *buf) |
| 550 | { |
| 551 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Jordan Crouse | 6c2992a | 2011-08-08 17:00:06 -0600 | [diff] [blame] | 552 | if (device == NULL) |
| 553 | return 0; |
| 554 | return snprintf(buf, PAGE_SIZE, "%d\n", |
| 555 | device->pwrctrl.interval_timeout); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 558 | static int kgsl_pwrctrl_gpubusy_show(struct device *dev, |
| 559 | struct device_attribute *attr, |
| 560 | char *buf) |
| 561 | { |
| 562 | int ret; |
| 563 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 564 | struct kgsl_clk_stats *clkstats = &device->pwrctrl.clk_stats; |
| 565 | ret = snprintf(buf, PAGE_SIZE, "%7d %7d\n", |
| 566 | clkstats->on_time_old, clkstats->elapsed_old); |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 567 | if (!test_bit(KGSL_PWRFLAGS_AXI_ON, &device->pwrctrl.power_flags)) { |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 568 | clkstats->on_time_old = 0; |
| 569 | clkstats->elapsed_old = 0; |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 570 | } |
| 571 | return ret; |
| 572 | } |
| 573 | |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 574 | static int kgsl_pwrctrl_gputop_show(struct device *dev, |
| 575 | struct device_attribute *attr, |
| 576 | char *buf) |
| 577 | { |
| 578 | int ret; |
| 579 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 580 | struct kgsl_clk_stats *clkstats = &device->pwrctrl.clk_stats; |
| 581 | int i = 0; |
| 582 | char *ptr = buf; |
| 583 | |
| 584 | ret = snprintf(buf, PAGE_SIZE, "%7d %7d ", clkstats->on_time_old, |
| 585 | clkstats->elapsed_old); |
| 586 | for (i = 0, ptr += ret; i < device->pwrctrl.num_pwrlevels; |
| 587 | i++, ptr += ret) |
| 588 | ret = snprintf(ptr, PAGE_SIZE, "%7d ", |
| 589 | clkstats->old_clock_time[i]); |
| 590 | |
| 591 | if (!test_bit(KGSL_PWRFLAGS_AXI_ON, &device->pwrctrl.power_flags)) { |
| 592 | clkstats->on_time_old = 0; |
| 593 | clkstats->elapsed_old = 0; |
| 594 | for (i = 0; i < KGSL_MAX_PWRLEVELS ; i++) |
| 595 | clkstats->old_clock_time[i] = 0; |
| 596 | } |
| 597 | return (unsigned int) (ptr - buf); |
| 598 | } |
| 599 | |
Anshuman Dani | 91ede1e | 2012-08-21 14:44:38 +0530 | [diff] [blame] | 600 | static int kgsl_pwrctrl_gpu_available_frequencies_show( |
| 601 | struct device *dev, |
| 602 | struct device_attribute *attr, |
| 603 | char *buf) |
| 604 | { |
| 605 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 606 | struct kgsl_pwrctrl *pwr; |
| 607 | int index, num_chars = 0; |
| 608 | |
| 609 | if (device == NULL) |
| 610 | return 0; |
| 611 | pwr = &device->pwrctrl; |
| 612 | for (index = 0; index < pwr->num_pwrlevels - 1; index++) |
| 613 | num_chars += snprintf(buf + num_chars, PAGE_SIZE, "%d ", |
| 614 | pwr->pwrlevels[index].gpu_freq); |
| 615 | buf[num_chars++] = '\n'; |
| 616 | return num_chars; |
| 617 | } |
| 618 | |
Jordan Crouse | 013cf42 | 2013-05-28 17:03:32 -0600 | [diff] [blame^] | 619 | static int kgsl_pwrctrl_reset_count_show(struct device *dev, |
| 620 | struct device_attribute *attr, |
| 621 | char *buf) |
| 622 | { |
| 623 | struct kgsl_device *device = kgsl_device_from_dev(dev); |
| 624 | return snprintf(buf, PAGE_SIZE, "%d\n", device->reset_counter); |
| 625 | } |
| 626 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 627 | DEVICE_ATTR(gpuclk, 0644, kgsl_pwrctrl_gpuclk_show, kgsl_pwrctrl_gpuclk_store); |
| 628 | DEVICE_ATTR(max_gpuclk, 0644, kgsl_pwrctrl_max_gpuclk_show, |
| 629 | kgsl_pwrctrl_max_gpuclk_store); |
Praveena Pachipulusu | 263467d | 2011-12-22 18:07:16 +0530 | [diff] [blame] | 630 | DEVICE_ATTR(pwrnap, 0664, kgsl_pwrctrl_pwrnap_show, kgsl_pwrctrl_pwrnap_store); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 631 | DEVICE_ATTR(idle_timer, 0644, kgsl_pwrctrl_idle_timer_show, |
| 632 | kgsl_pwrctrl_idle_timer_store); |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 633 | DEVICE_ATTR(gpubusy, 0444, kgsl_pwrctrl_gpubusy_show, |
| 634 | NULL); |
| 635 | DEVICE_ATTR(gputop, 0444, kgsl_pwrctrl_gputop_show, |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 636 | NULL); |
Anshuman Dani | 91ede1e | 2012-08-21 14:44:38 +0530 | [diff] [blame] | 637 | DEVICE_ATTR(gpu_available_frequencies, 0444, |
| 638 | kgsl_pwrctrl_gpu_available_frequencies_show, |
| 639 | NULL); |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 640 | DEVICE_ATTR(max_pwrlevel, 0644, |
| 641 | kgsl_pwrctrl_max_pwrlevel_show, |
| 642 | kgsl_pwrctrl_max_pwrlevel_store); |
| 643 | DEVICE_ATTR(min_pwrlevel, 0644, |
| 644 | kgsl_pwrctrl_min_pwrlevel_show, |
| 645 | kgsl_pwrctrl_min_pwrlevel_store); |
| 646 | DEVICE_ATTR(thermal_pwrlevel, 0644, |
| 647 | kgsl_pwrctrl_thermal_pwrlevel_show, |
| 648 | kgsl_pwrctrl_thermal_pwrlevel_store); |
| 649 | DEVICE_ATTR(num_pwrlevels, 0444, |
| 650 | kgsl_pwrctrl_num_pwrlevels_show, |
| 651 | NULL); |
Jordan Crouse | 013cf42 | 2013-05-28 17:03:32 -0600 | [diff] [blame^] | 652 | DEVICE_ATTR(reset_count, 0444, |
| 653 | kgsl_pwrctrl_reset_count_show, |
| 654 | NULL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 655 | |
| 656 | static const struct device_attribute *pwrctrl_attr_list[] = { |
| 657 | &dev_attr_gpuclk, |
| 658 | &dev_attr_max_gpuclk, |
| 659 | &dev_attr_pwrnap, |
| 660 | &dev_attr_idle_timer, |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 661 | &dev_attr_gpubusy, |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 662 | &dev_attr_gputop, |
Anshuman Dani | 91ede1e | 2012-08-21 14:44:38 +0530 | [diff] [blame] | 663 | &dev_attr_gpu_available_frequencies, |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 664 | &dev_attr_max_pwrlevel, |
| 665 | &dev_attr_min_pwrlevel, |
| 666 | &dev_attr_thermal_pwrlevel, |
| 667 | &dev_attr_num_pwrlevels, |
Jordan Crouse | 013cf42 | 2013-05-28 17:03:32 -0600 | [diff] [blame^] | 668 | &dev_attr_reset_count, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 669 | NULL |
| 670 | }; |
| 671 | |
| 672 | int kgsl_pwrctrl_init_sysfs(struct kgsl_device *device) |
| 673 | { |
| 674 | return kgsl_create_device_sysfs_files(device->dev, pwrctrl_attr_list); |
| 675 | } |
| 676 | |
| 677 | void kgsl_pwrctrl_uninit_sysfs(struct kgsl_device *device) |
| 678 | { |
| 679 | kgsl_remove_device_sysfs_files(device->dev, pwrctrl_attr_list); |
| 680 | } |
| 681 | |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 682 | static void update_statistics(struct kgsl_device *device) |
| 683 | { |
| 684 | struct kgsl_clk_stats *clkstats = &device->pwrctrl.clk_stats; |
| 685 | unsigned int on_time = 0; |
| 686 | int i; |
| 687 | int num_pwrlevels = device->pwrctrl.num_pwrlevels - 1; |
| 688 | /*PER CLK TIME*/ |
| 689 | for (i = 0; i < num_pwrlevels; i++) { |
| 690 | clkstats->old_clock_time[i] = clkstats->clock_time[i]; |
| 691 | on_time += clkstats->clock_time[i]; |
| 692 | clkstats->clock_time[i] = 0; |
| 693 | } |
| 694 | clkstats->old_clock_time[num_pwrlevels] = |
| 695 | clkstats->clock_time[num_pwrlevels]; |
| 696 | clkstats->clock_time[num_pwrlevels] = 0; |
| 697 | clkstats->on_time_old = on_time; |
| 698 | clkstats->elapsed_old = clkstats->elapsed; |
| 699 | clkstats->elapsed = 0; |
| 700 | } |
| 701 | |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 702 | /* Track the amount of time the gpu is on vs the total system time. * |
| 703 | * Regularly update the percentage of busy time displayed by sysfs. */ |
| 704 | static void kgsl_pwrctrl_busy_time(struct kgsl_device *device, bool on_time) |
| 705 | { |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 706 | struct kgsl_clk_stats *clkstats = &device->pwrctrl.clk_stats; |
| 707 | update_clk_statistics(device, on_time); |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 708 | /* Update the output regularly and reset the counters. */ |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 709 | if ((clkstats->elapsed > UPDATE_BUSY_VAL) || |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 710 | !test_bit(KGSL_PWRFLAGS_AXI_ON, &device->pwrctrl.power_flags)) { |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 711 | update_statistics(device); |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 712 | } |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 715 | void kgsl_pwrctrl_clk(struct kgsl_device *device, int state, |
| 716 | int requested_state) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 717 | { |
| 718 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 719 | int i = 0; |
| 720 | if (state == KGSL_PWRFLAGS_OFF) { |
| 721 | if (test_and_clear_bit(KGSL_PWRFLAGS_CLK_ON, |
| 722 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 723 | trace_kgsl_clk(device, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 724 | for (i = KGSL_MAX_CLKS - 1; i > 0; i--) |
| 725 | if (pwr->grp_clks[i]) |
| 726 | clk_disable(pwr->grp_clks[i]); |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 727 | /* High latency clock maintenance. */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 728 | if ((pwr->pwrlevels[0].gpu_freq > 0) && |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 729 | (requested_state != KGSL_STATE_NAP)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 730 | clk_set_rate(pwr->grp_clks[0], |
| 731 | pwr->pwrlevels[pwr->num_pwrlevels - 1]. |
| 732 | gpu_freq); |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 733 | for (i = KGSL_MAX_CLKS - 1; i > 0; i--) |
| 734 | if (pwr->grp_clks[i]) |
| 735 | clk_unprepare(pwr->grp_clks[i]); |
| 736 | } |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 737 | kgsl_pwrctrl_busy_time(device, true); |
Suman Tatiraju | 426da0d | 2012-09-11 13:03:28 -0700 | [diff] [blame] | 738 | } else if (requested_state == KGSL_STATE_SLEEP) { |
| 739 | /* High latency clock maintenance. */ |
| 740 | if ((pwr->pwrlevels[0].gpu_freq > 0)) |
| 741 | clk_set_rate(pwr->grp_clks[0], |
| 742 | pwr->pwrlevels[pwr->num_pwrlevels - 1]. |
| 743 | gpu_freq); |
| 744 | for (i = KGSL_MAX_CLKS - 1; i > 0; i--) |
| 745 | if (pwr->grp_clks[i]) |
| 746 | clk_unprepare(pwr->grp_clks[i]); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 747 | } |
| 748 | } else if (state == KGSL_PWRFLAGS_ON) { |
| 749 | if (!test_and_set_bit(KGSL_PWRFLAGS_CLK_ON, |
| 750 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 751 | trace_kgsl_clk(device, state); |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 752 | /* High latency clock maintenance. */ |
Ranjhith Kalisamy | c940699 | 2012-08-10 16:40:36 +0530 | [diff] [blame] | 753 | if (device->state != KGSL_STATE_NAP) { |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 754 | for (i = KGSL_MAX_CLKS - 1; i > 0; i--) |
| 755 | if (pwr->grp_clks[i]) |
| 756 | clk_prepare(pwr->grp_clks[i]); |
Ranjhith Kalisamy | c940699 | 2012-08-10 16:40:36 +0530 | [diff] [blame] | 757 | |
| 758 | if (pwr->pwrlevels[0].gpu_freq > 0) |
| 759 | clk_set_rate(pwr->grp_clks[0], |
| 760 | pwr->pwrlevels |
| 761 | [pwr->active_pwrlevel]. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 762 | gpu_freq); |
Lucille Sylvester | 5b7e57b | 2012-01-19 17:18:40 -0700 | [diff] [blame] | 763 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 764 | /* as last step, enable grp_clk |
| 765 | this is to let GPU interrupt to come */ |
| 766 | for (i = KGSL_MAX_CLKS - 1; i > 0; i--) |
| 767 | if (pwr->grp_clks[i]) |
| 768 | clk_enable(pwr->grp_clks[i]); |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 769 | kgsl_pwrctrl_busy_time(device, false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 773 | |
| 774 | void kgsl_pwrctrl_axi(struct kgsl_device *device, int state) |
| 775 | { |
| 776 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 777 | |
| 778 | if (state == KGSL_PWRFLAGS_OFF) { |
| 779 | if (test_and_clear_bit(KGSL_PWRFLAGS_AXI_ON, |
| 780 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 781 | trace_kgsl_bus(device, state); |
Lynus Vaz | 5a641cc | 2011-09-15 14:43:40 +0530 | [diff] [blame] | 782 | if (pwr->ebi1_clk) { |
| 783 | clk_set_rate(pwr->ebi1_clk, 0); |
Lucille Sylvester | 064d598 | 2012-05-08 15:42:43 -0600 | [diff] [blame] | 784 | clk_disable_unprepare(pwr->ebi1_clk); |
Lynus Vaz | 5a641cc | 2011-09-15 14:43:40 +0530 | [diff] [blame] | 785 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 786 | if (pwr->pcl) |
| 787 | msm_bus_scale_client_update_request(pwr->pcl, |
| 788 | 0); |
| 789 | } |
| 790 | } else if (state == KGSL_PWRFLAGS_ON) { |
| 791 | if (!test_and_set_bit(KGSL_PWRFLAGS_AXI_ON, |
| 792 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 793 | trace_kgsl_bus(device, state); |
Lynus Vaz | 5a641cc | 2011-09-15 14:43:40 +0530 | [diff] [blame] | 794 | if (pwr->ebi1_clk) { |
Lucille Sylvester | 064d598 | 2012-05-08 15:42:43 -0600 | [diff] [blame] | 795 | clk_prepare_enable(pwr->ebi1_clk); |
Lynus Vaz | 5a641cc | 2011-09-15 14:43:40 +0530 | [diff] [blame] | 796 | clk_set_rate(pwr->ebi1_clk, |
| 797 | pwr->pwrlevels[pwr->active_pwrlevel]. |
| 798 | bus_freq); |
| 799 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 800 | if (pwr->pcl) |
| 801 | msm_bus_scale_client_update_request(pwr->pcl, |
| 802 | pwr->pwrlevels[pwr->active_pwrlevel]. |
| 803 | bus_freq); |
| 804 | } |
| 805 | } |
| 806 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 807 | |
| 808 | void kgsl_pwrctrl_pwrrail(struct kgsl_device *device, int state) |
| 809 | { |
| 810 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 811 | |
| 812 | if (state == KGSL_PWRFLAGS_OFF) { |
| 813 | if (test_and_clear_bit(KGSL_PWRFLAGS_POWER_ON, |
| 814 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 815 | trace_kgsl_rail(device, state); |
Pu Chen | 1205378 | 2012-07-24 17:04:27 -0700 | [diff] [blame] | 816 | if (pwr->gpu_cx) |
| 817 | regulator_disable(pwr->gpu_cx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 818 | if (pwr->gpu_reg) |
| 819 | regulator_disable(pwr->gpu_reg); |
| 820 | } |
| 821 | } else if (state == KGSL_PWRFLAGS_ON) { |
| 822 | if (!test_and_set_bit(KGSL_PWRFLAGS_POWER_ON, |
| 823 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 824 | trace_kgsl_rail(device, state); |
Shubhraprakash Das | e86ba5c | 2012-04-04 18:03:27 -0600 | [diff] [blame] | 825 | if (pwr->gpu_reg) { |
| 826 | int status = regulator_enable(pwr->gpu_reg); |
| 827 | if (status) |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 828 | KGSL_DRV_ERR(device, |
| 829 | "core regulator_enable " |
| 830 | "failed: %d\n", |
| 831 | status); |
| 832 | } |
Pu Chen | 1205378 | 2012-07-24 17:04:27 -0700 | [diff] [blame] | 833 | if (pwr->gpu_cx) { |
| 834 | int status = regulator_enable(pwr->gpu_cx); |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 835 | if (status) |
| 836 | KGSL_DRV_ERR(device, |
| 837 | "cx regulator_enable " |
| 838 | "failed: %d\n", |
| 839 | status); |
Shubhraprakash Das | e86ba5c | 2012-04-04 18:03:27 -0600 | [diff] [blame] | 840 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 844 | |
| 845 | void kgsl_pwrctrl_irq(struct kgsl_device *device, int state) |
| 846 | { |
| 847 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 848 | |
| 849 | if (state == KGSL_PWRFLAGS_ON) { |
| 850 | if (!test_and_set_bit(KGSL_PWRFLAGS_IRQ_ON, |
| 851 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 852 | trace_kgsl_irq(device, state); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 853 | enable_irq(pwr->interrupt_num); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 854 | } |
| 855 | } else if (state == KGSL_PWRFLAGS_OFF) { |
| 856 | if (test_and_clear_bit(KGSL_PWRFLAGS_IRQ_ON, |
| 857 | &pwr->power_flags)) { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 858 | trace_kgsl_irq(device, state); |
Jordan Crouse | b58e61b | 2011-08-08 13:25:36 -0600 | [diff] [blame] | 859 | if (in_interrupt()) |
| 860 | disable_irq_nosync(pwr->interrupt_num); |
| 861 | else |
| 862 | disable_irq(pwr->interrupt_num); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | } |
| 866 | EXPORT_SYMBOL(kgsl_pwrctrl_irq); |
| 867 | |
| 868 | int kgsl_pwrctrl_init(struct kgsl_device *device) |
| 869 | { |
| 870 | int i, result = 0; |
| 871 | struct clk *clk; |
| 872 | struct platform_device *pdev = |
| 873 | container_of(device->parentdev, struct platform_device, dev); |
| 874 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 875 | struct kgsl_device_platform_data *pdata = pdev->dev.platform_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 876 | |
| 877 | /*acquire clocks */ |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 878 | for (i = 0; i < KGSL_MAX_CLKS; i++) { |
| 879 | if (pdata->clk_map & clks[i].map) { |
| 880 | clk = clk_get(&pdev->dev, clks[i].name); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 881 | if (IS_ERR(clk)) |
| 882 | goto clk_err; |
| 883 | pwr->grp_clks[i] = clk; |
| 884 | } |
| 885 | } |
| 886 | /* Make sure we have a source clk for freq setting */ |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 887 | if (pwr->grp_clks[0] == NULL) |
| 888 | pwr->grp_clks[0] = pwr->grp_clks[1]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 889 | |
| 890 | /* put the AXI bus into asynchronous mode with the graphics cores */ |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 891 | if (pdata->set_grp_async != NULL) |
| 892 | pdata->set_grp_async(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 893 | |
Lucille Sylvester | d260c88 | 2013-05-28 16:59:46 -0600 | [diff] [blame] | 894 | if (pdata->num_levels > KGSL_MAX_PWRLEVELS || |
| 895 | pdata->num_levels < 1) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 896 | KGSL_PWR_ERR(device, "invalid power level count: %d\n", |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 897 | pdata->num_levels); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 898 | result = -EINVAL; |
| 899 | goto done; |
| 900 | } |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 901 | pwr->num_pwrlevels = pdata->num_levels; |
Jordan Crouse | 2ddfc8a | 2012-11-27 11:33:06 -0700 | [diff] [blame] | 902 | |
| 903 | /* Initialize the user and thermal clock constraints */ |
| 904 | |
| 905 | pwr->max_pwrlevel = 0; |
| 906 | pwr->min_pwrlevel = pdata->num_levels - 2; |
| 907 | pwr->thermal_pwrlevel = 0; |
| 908 | |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 909 | pwr->active_pwrlevel = pdata->init_level; |
Lucille Sylvester | 67b4c53 | 2012-02-08 11:24:31 -0800 | [diff] [blame] | 910 | pwr->default_pwrlevel = pdata->init_level; |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 911 | for (i = 0; i < pdata->num_levels; i++) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 912 | pwr->pwrlevels[i].gpu_freq = |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 913 | (pdata->pwrlevel[i].gpu_freq > 0) ? |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 914 | clk_round_rate(pwr->grp_clks[0], |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 915 | pdata->pwrlevel[i]. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 916 | gpu_freq) : 0; |
| 917 | pwr->pwrlevels[i].bus_freq = |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 918 | pdata->pwrlevel[i].bus_freq; |
Lucille Sylvester | 596d4c2 | 2011-10-19 18:04:01 -0600 | [diff] [blame] | 919 | pwr->pwrlevels[i].io_fraction = |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 920 | pdata->pwrlevel[i].io_fraction; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 921 | } |
| 922 | /* Do not set_rate for targets in sync with AXI */ |
| 923 | if (pwr->pwrlevels[0].gpu_freq > 0) |
| 924 | clk_set_rate(pwr->grp_clks[0], pwr-> |
| 925 | pwrlevels[pwr->num_pwrlevels - 1].gpu_freq); |
| 926 | |
Matt Wagantall | d6fbf23 | 2012-05-03 20:09:28 -0700 | [diff] [blame] | 927 | pwr->gpu_reg = regulator_get(&pdev->dev, "vdd"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 928 | if (IS_ERR(pwr->gpu_reg)) |
| 929 | pwr->gpu_reg = NULL; |
| 930 | |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 931 | if (pwr->gpu_reg) { |
Pu Chen | 1205378 | 2012-07-24 17:04:27 -0700 | [diff] [blame] | 932 | pwr->gpu_cx = regulator_get(&pdev->dev, "vddcx"); |
| 933 | if (IS_ERR(pwr->gpu_cx)) |
| 934 | pwr->gpu_cx = NULL; |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 935 | } else |
Pu Chen | 1205378 | 2012-07-24 17:04:27 -0700 | [diff] [blame] | 936 | pwr->gpu_cx = NULL; |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 937 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 938 | pwr->power_flags = 0; |
| 939 | |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 940 | pwr->nap_allowed = pdata->nap_allowed; |
Kedar Joshi | c11d098 | 2012-02-07 10:59:49 +0530 | [diff] [blame] | 941 | pwr->idle_needed = pdata->idle_needed; |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 942 | pwr->interval_timeout = pdata->idle_timeout; |
Lynus Vaz | fe4bede | 2012-04-06 11:53:30 -0700 | [diff] [blame] | 943 | pwr->strtstp_sleepwake = pdata->strtstp_sleepwake; |
Matt Wagantall | 9dc0163 | 2011-08-17 18:55:04 -0700 | [diff] [blame] | 944 | pwr->ebi1_clk = clk_get(&pdev->dev, "bus_clk"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 945 | if (IS_ERR(pwr->ebi1_clk)) |
| 946 | pwr->ebi1_clk = NULL; |
| 947 | else |
| 948 | clk_set_rate(pwr->ebi1_clk, |
| 949 | pwr->pwrlevels[pwr->active_pwrlevel]. |
| 950 | bus_freq); |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 951 | if (pdata->bus_scale_table != NULL) { |
| 952 | pwr->pcl = msm_bus_scale_register_client(pdata-> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 953 | bus_scale_table); |
| 954 | if (!pwr->pcl) { |
| 955 | KGSL_PWR_ERR(device, |
| 956 | "msm_bus_scale_register_client failed: " |
| 957 | "id %d table %p", device->id, |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 958 | pdata->bus_scale_table); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 959 | result = -EINVAL; |
| 960 | goto done; |
| 961 | } |
| 962 | } |
| 963 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 964 | |
Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 965 | pm_runtime_enable(device->parentdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 966 | register_early_suspend(&device->display_off); |
| 967 | return result; |
| 968 | |
| 969 | clk_err: |
| 970 | result = PTR_ERR(clk); |
| 971 | KGSL_PWR_ERR(device, "clk_get(%s) failed: %d\n", |
Lucille Sylvester | dce84cd | 2011-10-12 14:15:37 -0600 | [diff] [blame] | 972 | clks[i].name, result); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 973 | |
| 974 | done: |
| 975 | return result; |
| 976 | } |
| 977 | |
| 978 | void kgsl_pwrctrl_close(struct kgsl_device *device) |
| 979 | { |
| 980 | struct kgsl_pwrctrl *pwr = &device->pwrctrl; |
| 981 | int i; |
| 982 | |
| 983 | KGSL_PWR_INFO(device, "close device %d\n", device->id); |
| 984 | |
Jeremy Gebben | 4f5f0de | 2012-03-01 15:51:37 -0700 | [diff] [blame] | 985 | pm_runtime_disable(device->parentdev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 986 | unregister_early_suspend(&device->display_off); |
| 987 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 988 | clk_put(pwr->ebi1_clk); |
| 989 | |
| 990 | if (pwr->pcl) |
| 991 | msm_bus_scale_unregister_client(pwr->pcl); |
| 992 | |
| 993 | pwr->pcl = 0; |
| 994 | |
| 995 | if (pwr->gpu_reg) { |
| 996 | regulator_put(pwr->gpu_reg); |
| 997 | pwr->gpu_reg = NULL; |
| 998 | } |
| 999 | |
Pu Chen | 1205378 | 2012-07-24 17:04:27 -0700 | [diff] [blame] | 1000 | if (pwr->gpu_cx) { |
| 1001 | regulator_put(pwr->gpu_cx); |
| 1002 | pwr->gpu_cx = NULL; |
Pu Chen | fe0dd3a | 2012-06-01 14:39:08 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1005 | for (i = 1; i < KGSL_MAX_CLKS; i++) |
| 1006 | if (pwr->grp_clks[i]) { |
| 1007 | clk_put(pwr->grp_clks[i]); |
| 1008 | pwr->grp_clks[i] = NULL; |
| 1009 | } |
| 1010 | |
| 1011 | pwr->grp_clks[0] = NULL; |
| 1012 | pwr->power_flags = 0; |
| 1013 | } |
| 1014 | |
| 1015 | void kgsl_idle_check(struct work_struct *work) |
| 1016 | { |
| 1017 | struct kgsl_device *device = container_of(work, struct kgsl_device, |
| 1018 | idle_check_ws); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1019 | WARN_ON(device == NULL); |
| 1020 | if (device == NULL) |
| 1021 | return; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1022 | |
| 1023 | mutex_lock(&device->mutex); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1024 | if (device->state & (KGSL_STATE_ACTIVE | KGSL_STATE_NAP)) { |
Lucille Sylvester | 721f7e7 | 2012-08-21 16:31:26 -0600 | [diff] [blame] | 1025 | kgsl_pwrscale_idle(device); |
Lucille Sylvester | c4af355 | 2011-10-27 11:44:24 -0600 | [diff] [blame] | 1026 | |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 1027 | if (kgsl_pwrctrl_sleep(device) != 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1028 | mod_timer(&device->idle_timer, |
| 1029 | jiffies + |
| 1030 | device->pwrctrl.interval_timeout); |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 1031 | /* If the GPU has been too busy to sleep, make sure * |
| 1032 | * that is acurately reflected in the % busy numbers. */ |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 1033 | device->pwrctrl.clk_stats.no_nap_cnt++; |
| 1034 | if (device->pwrctrl.clk_stats.no_nap_cnt > |
| 1035 | UPDATE_BUSY) { |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 1036 | kgsl_pwrctrl_busy_time(device, true); |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 1037 | device->pwrctrl.clk_stats.no_nap_cnt = 0; |
Suman Tatiraju | 7fe62a3 | 2011-07-14 16:40:37 -0700 | [diff] [blame] | 1038 | } |
| 1039 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1040 | } else if (device->state & (KGSL_STATE_HUNG | |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 1041 | KGSL_STATE_DUMP_AND_FT)) { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1042 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | mutex_unlock(&device->mutex); |
| 1046 | } |
| 1047 | |
| 1048 | void kgsl_timer(unsigned long data) |
| 1049 | { |
| 1050 | struct kgsl_device *device = (struct kgsl_device *) data; |
| 1051 | |
| 1052 | KGSL_PWR_INFO(device, "idle timer expired device %d\n", device->id); |
Anoop Kumar Yerukala | 03ba25f | 2012-01-23 17:32:02 +0530 | [diff] [blame] | 1053 | if (device->requested_state != KGSL_STATE_SUSPEND) { |
Lynus Vaz | fe4bede | 2012-04-06 11:53:30 -0700 | [diff] [blame] | 1054 | if (device->pwrctrl.restore_slumber || |
| 1055 | device->pwrctrl.strtstp_sleepwake) |
Lucille Sylvester | a985adf | 2012-01-16 11:11:55 -0700 | [diff] [blame] | 1056 | kgsl_pwrctrl_request_state(device, KGSL_STATE_SLUMBER); |
| 1057 | else |
| 1058 | kgsl_pwrctrl_request_state(device, KGSL_STATE_SLEEP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1059 | /* Have work run in a non-interrupt context. */ |
| 1060 | queue_work(device->work_queue, &device->idle_check_ws); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | void kgsl_pre_hwaccess(struct kgsl_device *device) |
| 1065 | { |
| 1066 | BUG_ON(!mutex_is_locked(&device->mutex)); |
Lucille Sylvester | 8b803e9 | 2012-01-12 15:19:55 -0700 | [diff] [blame] | 1067 | switch (device->state) { |
| 1068 | case KGSL_STATE_ACTIVE: |
| 1069 | return; |
| 1070 | case KGSL_STATE_NAP: |
| 1071 | case KGSL_STATE_SLEEP: |
| 1072 | case KGSL_STATE_SLUMBER: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1073 | kgsl_pwrctrl_wake(device); |
Lucille Sylvester | 8b803e9 | 2012-01-12 15:19:55 -0700 | [diff] [blame] | 1074 | break; |
| 1075 | case KGSL_STATE_SUSPEND: |
| 1076 | kgsl_check_suspended(device); |
| 1077 | break; |
| 1078 | case KGSL_STATE_INIT: |
| 1079 | case KGSL_STATE_HUNG: |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 1080 | case KGSL_STATE_DUMP_AND_FT: |
Lucille Sylvester | 8b803e9 | 2012-01-12 15:19:55 -0700 | [diff] [blame] | 1081 | if (test_bit(KGSL_PWRFLAGS_CLK_ON, |
| 1082 | &device->pwrctrl.power_flags)) |
| 1083 | break; |
| 1084 | else |
| 1085 | KGSL_PWR_ERR(device, |
| 1086 | "hw access while clocks off from state %d\n", |
| 1087 | device->state); |
| 1088 | break; |
| 1089 | default: |
| 1090 | KGSL_PWR_ERR(device, "hw access while in unknown state %d\n", |
| 1091 | device->state); |
| 1092 | break; |
| 1093 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1094 | } |
| 1095 | EXPORT_SYMBOL(kgsl_pre_hwaccess); |
| 1096 | |
| 1097 | void kgsl_check_suspended(struct kgsl_device *device) |
| 1098 | { |
| 1099 | if (device->requested_state == KGSL_STATE_SUSPEND || |
| 1100 | device->state == KGSL_STATE_SUSPEND) { |
| 1101 | mutex_unlock(&device->mutex); |
| 1102 | wait_for_completion(&device->hwaccess_gate); |
| 1103 | mutex_lock(&device->mutex); |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 1104 | } else if (device->state == KGSL_STATE_DUMP_AND_FT) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1105 | mutex_unlock(&device->mutex); |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 1106 | wait_for_completion(&device->ft_gate); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1107 | mutex_lock(&device->mutex); |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1108 | } else if (device->state == KGSL_STATE_SLUMBER) |
| 1109 | kgsl_pwrctrl_wake(device); |
| 1110 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1111 | |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1112 | static int |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1113 | _nap(struct kgsl_device *device) |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1114 | { |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1115 | switch (device->state) { |
| 1116 | case KGSL_STATE_ACTIVE: |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1117 | if (!device->ftbl->isidle(device)) { |
| 1118 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
| 1119 | return -EBUSY; |
| 1120 | } |
| 1121 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 1122 | kgsl_pwrctrl_clk(device, KGSL_PWRFLAGS_OFF, KGSL_STATE_NAP); |
| 1123 | kgsl_pwrctrl_set_state(device, KGSL_STATE_NAP); |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1124 | case KGSL_STATE_NAP: |
| 1125 | case KGSL_STATE_SLEEP: |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1126 | case KGSL_STATE_SLUMBER: |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1127 | break; |
| 1128 | default: |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1129 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1130 | break; |
| 1131 | } |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1132 | return 0; |
| 1133 | } |
| 1134 | |
| 1135 | static void |
| 1136 | _sleep_accounting(struct kgsl_device *device) |
| 1137 | { |
| 1138 | kgsl_pwrctrl_busy_time(device, false); |
Suman Tatiraju | 2bdd056 | 2012-01-26 14:49:46 -0800 | [diff] [blame] | 1139 | device->pwrctrl.clk_stats.start = ktime_set(0, 0); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1140 | device->pwrctrl.time = 0; |
| 1141 | kgsl_pwrscale_sleep(device); |
| 1142 | } |
| 1143 | |
| 1144 | static int |
| 1145 | _sleep(struct kgsl_device *device) |
| 1146 | { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1147 | switch (device->state) { |
| 1148 | case KGSL_STATE_ACTIVE: |
| 1149 | if (!device->ftbl->isidle(device)) { |
| 1150 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
| 1151 | return -EBUSY; |
| 1152 | } |
| 1153 | /* fall through */ |
| 1154 | case KGSL_STATE_NAP: |
| 1155 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_OFF); |
| 1156 | kgsl_pwrctrl_axi(device, KGSL_PWRFLAGS_OFF); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1157 | _sleep_accounting(device); |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 1158 | kgsl_pwrctrl_clk(device, KGSL_PWRFLAGS_OFF, KGSL_STATE_SLEEP); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1159 | kgsl_pwrctrl_set_state(device, KGSL_STATE_SLEEP); |
Lucille Sylvester | 1029789 | 2012-02-27 13:54:47 -0700 | [diff] [blame] | 1160 | pm_qos_update_request(&device->pm_qos_req_dma, |
| 1161 | PM_QOS_DEFAULT_VALUE); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1162 | break; |
| 1163 | case KGSL_STATE_SLEEP: |
| 1164 | case KGSL_STATE_SLUMBER: |
| 1165 | break; |
| 1166 | default: |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1167 | KGSL_PWR_WARN(device, "unhandled state %s\n", |
| 1168 | kgsl_pwrstate_to_str(device->state)); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1169 | break; |
| 1170 | } |
Shubhraprakash Das | 7a0c93c | 2012-11-20 15:15:08 -0700 | [diff] [blame] | 1171 | |
| 1172 | kgsl_mmu_disable_clk_on_ts(&device->mmu, 0, false); |
| 1173 | |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | static int |
| 1178 | _slumber(struct kgsl_device *device) |
| 1179 | { |
| 1180 | switch (device->state) { |
| 1181 | case KGSL_STATE_ACTIVE: |
| 1182 | if (!device->ftbl->isidle(device)) { |
| 1183 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1184 | return -EBUSY; |
| 1185 | } |
| 1186 | /* fall through */ |
| 1187 | case KGSL_STATE_NAP: |
| 1188 | case KGSL_STATE_SLEEP: |
| 1189 | del_timer_sync(&device->idle_timer); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1190 | device->ftbl->suspend_context(device); |
| 1191 | device->ftbl->stop(device); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1192 | _sleep_accounting(device); |
| 1193 | kgsl_pwrctrl_set_state(device, KGSL_STATE_SLUMBER); |
Suman Tatiraju | 3005cdd | 2012-03-19 14:38:11 -0700 | [diff] [blame] | 1194 | pm_qos_update_request(&device->pm_qos_req_dma, |
| 1195 | PM_QOS_DEFAULT_VALUE); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1196 | break; |
| 1197 | case KGSL_STATE_SLUMBER: |
| 1198 | break; |
| 1199 | default: |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1200 | KGSL_PWR_WARN(device, "unhandled state %s\n", |
| 1201 | kgsl_pwrstate_to_str(device->state)); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1202 | break; |
| 1203 | } |
| 1204 | return 0; |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1205 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1206 | |
| 1207 | /******************************************************************/ |
| 1208 | /* Caller must hold the device mutex. */ |
| 1209 | int kgsl_pwrctrl_sleep(struct kgsl_device *device) |
| 1210 | { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1211 | int status = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1212 | KGSL_PWR_INFO(device, "sleep device %d\n", device->id); |
| 1213 | |
| 1214 | /* Work through the legal state transitions */ |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1215 | switch (device->requested_state) { |
| 1216 | case KGSL_STATE_NAP: |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1217 | status = _nap(device); |
| 1218 | break; |
| 1219 | case KGSL_STATE_SLEEP: |
Lucille Sylvester | a985adf | 2012-01-16 11:11:55 -0700 | [diff] [blame] | 1220 | status = _sleep(device); |
Shubhraprakash Das | 602497c | 2013-05-28 16:53:24 -0600 | [diff] [blame] | 1221 | kgsl_mmu_disable_clk_on_ts(&device->mmu, 0, false); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1222 | break; |
| 1223 | case KGSL_STATE_SLUMBER: |
| 1224 | status = _slumber(device); |
| 1225 | break; |
| 1226 | default: |
| 1227 | KGSL_PWR_INFO(device, "bad state request 0x%x\n", |
| 1228 | device->requested_state); |
| 1229 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
| 1230 | status = -EINVAL; |
| 1231 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1232 | } |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1233 | return status; |
| 1234 | } |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1235 | EXPORT_SYMBOL(kgsl_pwrctrl_sleep); |
Suman Tatiraju | 2456902 | 2011-10-27 11:11:12 -0700 | [diff] [blame] | 1236 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1237 | /******************************************************************/ |
| 1238 | /* Caller must hold the device mutex. */ |
| 1239 | void kgsl_pwrctrl_wake(struct kgsl_device *device) |
| 1240 | { |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1241 | int status; |
Ranjhith Kalisamy | cb1721c | 2013-05-28 16:59:59 -0600 | [diff] [blame] | 1242 | unsigned int context_id; |
| 1243 | unsigned int state = device->state; |
| 1244 | unsigned int ts_processed = 0xdeaddead; |
| 1245 | struct kgsl_context *context; |
| 1246 | |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1247 | kgsl_pwrctrl_request_state(device, KGSL_STATE_ACTIVE); |
| 1248 | switch (device->state) { |
| 1249 | case KGSL_STATE_SLUMBER: |
| 1250 | status = device->ftbl->start(device, 0); |
| 1251 | if (status) { |
| 1252 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
| 1253 | KGSL_DRV_ERR(device, "start failed %d\n", status); |
| 1254 | break; |
| 1255 | } |
| 1256 | /* fall through */ |
| 1257 | case KGSL_STATE_SLEEP: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1258 | kgsl_pwrctrl_axi(device, KGSL_PWRFLAGS_ON); |
| 1259 | kgsl_pwrscale_wake(device); |
Ranjhith Kalisamy | cb1721c | 2013-05-28 16:59:59 -0600 | [diff] [blame] | 1260 | kgsl_sharedmem_readl(&device->memstore, |
| 1261 | (unsigned int *) &context_id, |
| 1262 | KGSL_MEMSTORE_OFFSET(KGSL_MEMSTORE_GLOBAL, |
| 1263 | current_context)); |
| 1264 | context = idr_find(&device->context_idr, context_id); |
| 1265 | if (context) |
| 1266 | ts_processed = kgsl_readtimestamp(device, context, |
| 1267 | KGSL_TIMESTAMP_RETIRED); |
| 1268 | KGSL_PWR_INFO(device, "Wake from %s state. CTXT: %d RTRD TS: %08X\n", |
| 1269 | kgsl_pwrstate_to_str(state), |
| 1270 | context ? context->id : -1, ts_processed); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1271 | /* fall through */ |
| 1272 | case KGSL_STATE_NAP: |
| 1273 | /* Turn on the core clocks */ |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 1274 | kgsl_pwrctrl_clk(device, KGSL_PWRFLAGS_ON, KGSL_STATE_ACTIVE); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1275 | /* Enable state before turning on irq */ |
| 1276 | kgsl_pwrctrl_set_state(device, KGSL_STATE_ACTIVE); |
| 1277 | kgsl_pwrctrl_irq(device, KGSL_PWRFLAGS_ON); |
| 1278 | /* Re-enable HW access */ |
| 1279 | mod_timer(&device->idle_timer, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1280 | jiffies + device->pwrctrl.interval_timeout); |
Devin Kim | 66ad4c0 | 2012-09-21 20:28:50 -0700 | [diff] [blame] | 1281 | pm_qos_update_request(&device->pm_qos_req_dma, |
| 1282 | GPU_SWFI_LATENCY); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1283 | case KGSL_STATE_ACTIVE: |
Vinay Roy | 65c41b3 | 2012-11-25 00:48:38 +0530 | [diff] [blame] | 1284 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1285 | break; |
| 1286 | default: |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1287 | KGSL_PWR_WARN(device, "unhandled state %s\n", |
| 1288 | kgsl_pwrstate_to_str(device->state)); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1289 | kgsl_pwrctrl_request_state(device, KGSL_STATE_NONE); |
| 1290 | break; |
| 1291 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1292 | } |
| 1293 | EXPORT_SYMBOL(kgsl_pwrctrl_wake); |
| 1294 | |
| 1295 | void kgsl_pwrctrl_enable(struct kgsl_device *device) |
| 1296 | { |
| 1297 | /* Order pwrrail/clk sequence based upon platform */ |
| 1298 | kgsl_pwrctrl_pwrrail(device, KGSL_PWRFLAGS_ON); |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 1299 | kgsl_pwrctrl_clk(device, KGSL_PWRFLAGS_ON, KGSL_STATE_ACTIVE); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1300 | kgsl_pwrctrl_axi(device, KGSL_PWRFLAGS_ON); |
| 1301 | } |
| 1302 | EXPORT_SYMBOL(kgsl_pwrctrl_enable); |
| 1303 | |
| 1304 | void kgsl_pwrctrl_disable(struct kgsl_device *device) |
| 1305 | { |
| 1306 | /* Order pwrrail/clk sequence based upon platform */ |
| 1307 | kgsl_pwrctrl_axi(device, KGSL_PWRFLAGS_OFF); |
Lucille Sylvester | e4a7c1a | 2012-04-11 12:17:38 -0600 | [diff] [blame] | 1308 | kgsl_pwrctrl_clk(device, KGSL_PWRFLAGS_OFF, KGSL_STATE_SLEEP); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1309 | kgsl_pwrctrl_pwrrail(device, KGSL_PWRFLAGS_OFF); |
| 1310 | } |
| 1311 | EXPORT_SYMBOL(kgsl_pwrctrl_disable); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1312 | |
| 1313 | void kgsl_pwrctrl_set_state(struct kgsl_device *device, unsigned int state) |
| 1314 | { |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1315 | trace_kgsl_pwr_set_state(device, state); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1316 | device->state = state; |
| 1317 | device->requested_state = KGSL_STATE_NONE; |
| 1318 | } |
| 1319 | EXPORT_SYMBOL(kgsl_pwrctrl_set_state); |
| 1320 | |
| 1321 | void kgsl_pwrctrl_request_state(struct kgsl_device *device, unsigned int state) |
| 1322 | { |
| 1323 | if (state != KGSL_STATE_NONE && state != device->requested_state) |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1324 | trace_kgsl_pwr_request_state(device, state); |
Jeremy Gebben | 388c297 | 2011-12-16 09:05:07 -0700 | [diff] [blame] | 1325 | device->requested_state = state; |
| 1326 | } |
| 1327 | EXPORT_SYMBOL(kgsl_pwrctrl_request_state); |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1328 | |
| 1329 | const char *kgsl_pwrstate_to_str(unsigned int state) |
| 1330 | { |
| 1331 | switch (state) { |
| 1332 | case KGSL_STATE_NONE: |
| 1333 | return "NONE"; |
| 1334 | case KGSL_STATE_INIT: |
| 1335 | return "INIT"; |
| 1336 | case KGSL_STATE_ACTIVE: |
| 1337 | return "ACTIVE"; |
| 1338 | case KGSL_STATE_NAP: |
| 1339 | return "NAP"; |
| 1340 | case KGSL_STATE_SLEEP: |
| 1341 | return "SLEEP"; |
| 1342 | case KGSL_STATE_SUSPEND: |
| 1343 | return "SUSPEND"; |
| 1344 | case KGSL_STATE_HUNG: |
| 1345 | return "HUNG"; |
Tarun Karra | d20d71a | 2013-01-25 15:38:57 -0800 | [diff] [blame] | 1346 | case KGSL_STATE_DUMP_AND_FT: |
Jeremy Gebben | b50f331 | 2011-12-16 08:58:33 -0700 | [diff] [blame] | 1347 | return "DNR"; |
| 1348 | case KGSL_STATE_SLUMBER: |
| 1349 | return "SLUMBER"; |
| 1350 | default: |
| 1351 | break; |
| 1352 | } |
| 1353 | return "UNKNOWN"; |
| 1354 | } |
| 1355 | EXPORT_SYMBOL(kgsl_pwrstate_to_str); |
| 1356 | |