Abhijeet Dharmapurikar | 7b933c5 | 2012-08-23 15:51:58 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -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 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/module.h> |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 17 | #include <linux/kthread.h> |
| 18 | #include <linux/kobject.h> |
| 19 | #include <linux/ktime.h> |
| 20 | #include <linux/hrtimer.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/spinlock.h> |
| 23 | #include <linux/stringify.h> |
| 24 | #include <linux/debugfs.h> |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 25 | #include <linux/msm_tsens.h> |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 26 | #include <asm/atomic.h> |
| 27 | #include <asm/page.h> |
| 28 | #include <mach/msm_dcvs.h> |
| 29 | |
| 30 | #define CORE_HANDLE_OFFSET (0xA0) |
| 31 | #define __err(f, ...) pr_err("MSM_DCVS: %s: " f, __func__, __VA_ARGS__) |
| 32 | #define __info(f, ...) pr_info("MSM_DCVS: %s: " f, __func__, __VA_ARGS__) |
| 33 | #define MAX_PENDING (5) |
| 34 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 35 | struct core_attribs { |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 36 | struct kobj_attribute freq_change_us; |
| 37 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 38 | struct kobj_attribute disable_pc_threshold; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 39 | struct kobj_attribute em_win_size_min_us; |
| 40 | struct kobj_attribute em_win_size_max_us; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 41 | struct kobj_attribute em_max_util_pct; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 42 | struct kobj_attribute group_id; |
| 43 | struct kobj_attribute max_freq_chg_time_us; |
| 44 | struct kobj_attribute slack_mode_dynamic; |
| 45 | struct kobj_attribute slack_time_min_us; |
| 46 | struct kobj_attribute slack_time_max_us; |
| 47 | struct kobj_attribute slack_weight_thresh_pct; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 48 | struct kobj_attribute ss_iobusy_conv; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 49 | struct kobj_attribute ss_win_size_min_us; |
| 50 | struct kobj_attribute ss_win_size_max_us; |
| 51 | struct kobj_attribute ss_util_pct; |
| 52 | |
| 53 | struct kobj_attribute active_coeff_a; |
| 54 | struct kobj_attribute active_coeff_b; |
| 55 | struct kobj_attribute active_coeff_c; |
| 56 | struct kobj_attribute leakage_coeff_a; |
| 57 | struct kobj_attribute leakage_coeff_b; |
| 58 | struct kobj_attribute leakage_coeff_c; |
| 59 | struct kobj_attribute leakage_coeff_d; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 60 | |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 61 | struct kobj_attribute thermal_poll_ms; |
| 62 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 63 | struct attribute_group attrib_group; |
| 64 | }; |
| 65 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 66 | enum pending_freq_state { |
| 67 | /* |
| 68 | * used by the thread to check if pending_freq was updated while it was |
| 69 | * setting previous frequency - this is written to and used by the |
| 70 | * freq updating thread |
| 71 | */ |
| 72 | NO_OUTSTANDING_FREQ_CHANGE = 0, |
| 73 | |
| 74 | /* |
| 75 | * This request is set to indicate that the governor is stopped and no |
| 76 | * more frequency change requests are accepted untill it starts again. |
| 77 | * This is checked/used by the threads that want to change the freq |
| 78 | */ |
| 79 | STOP_FREQ_CHANGE = -1, |
| 80 | |
| 81 | /* |
| 82 | * Any other +ve value means that a freq change was requested and the |
| 83 | * thread has not gotten around to update it |
| 84 | * |
| 85 | * Any other -ve value means that this is the last freq change i.e. a |
| 86 | * freq change was requested but the thread has not run yet and |
| 87 | * meanwhile the governor was stopped. |
| 88 | */ |
| 89 | }; |
| 90 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 91 | struct dcvs_core { |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 92 | spinlock_t idle_state_change_lock; |
| 93 | /* 0 when not idle (busy) 1 when idle and -1 when governor starts and |
| 94 | * we dont know whether the next call is going to be idle enter or exit |
| 95 | */ |
| 96 | int idle_entered; |
| 97 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 98 | enum msm_dcvs_core_type type; |
| 99 | /* this is the number in each type for example cpu 0,1,2 and gpu 0,1 */ |
| 100 | int type_core_num; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 101 | char core_name[CORE_NAME_MAX]; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 102 | uint32_t actual_freq; |
| 103 | uint32_t freq_change_us; |
| 104 | |
| 105 | uint32_t max_time_us; /* core param */ |
| 106 | |
| 107 | struct msm_dcvs_algo_param algo_param; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 108 | struct msm_dcvs_energy_curve_coeffs coeffs; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 109 | |
| 110 | /* private */ |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 111 | ktime_t time_start; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 112 | struct task_struct *task; |
| 113 | struct core_attribs attrib; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 114 | uint32_t dcvs_core_id; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 115 | struct msm_dcvs_core_info *info; |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 116 | int sensor; |
Abhijeet Dharmapurikar | bbb52fe | 2012-08-31 20:31:16 -0700 | [diff] [blame] | 117 | wait_queue_head_t wait_q; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 118 | |
| 119 | int (*set_frequency)(int type_core_num, unsigned int freq); |
| 120 | unsigned int (*get_frequency)(int type_core_num); |
| 121 | int (*idle_enable)(int type_core_num, |
Abhijeet Dharmapurikar | 6e9b34f | 2012-09-10 16:03:39 -0700 | [diff] [blame] | 122 | enum msm_core_control_event event); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 123 | |
| 124 | spinlock_t pending_freq_lock; |
| 125 | int pending_freq; |
| 126 | |
| 127 | struct hrtimer slack_timer; |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 128 | struct delayed_work temperature_work; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 131 | static int msm_dcvs_enabled = 1; |
| 132 | module_param_named(enable, msm_dcvs_enabled, int, S_IRUGO | S_IWUSR | S_IWGRP); |
| 133 | |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 134 | static struct dentry *debugfs_base; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 135 | |
| 136 | static struct dcvs_core core_list[CORES_MAX]; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 137 | |
| 138 | static struct kobject *cores_kobj; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 139 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 140 | static void force_stop_slack_timer(struct dcvs_core *core) |
| 141 | { |
| 142 | unsigned long flags; |
| 143 | |
| 144 | spin_lock_irqsave(&core->idle_state_change_lock, flags); |
| 145 | hrtimer_cancel(&core->slack_timer); |
| 146 | spin_unlock_irqrestore(&core->idle_state_change_lock, flags); |
| 147 | } |
| 148 | |
| 149 | static void stop_slack_timer(struct dcvs_core *core) |
| 150 | { |
| 151 | unsigned long flags; |
| 152 | |
| 153 | spin_lock_irqsave(&core->idle_state_change_lock, flags); |
| 154 | /* err only for cpu type's GPU's can do idle exit consecutively */ |
| 155 | if (core->idle_entered == 1 && !(core->dcvs_core_id >= GPU_OFFSET)) |
| 156 | __err("%s trying to reenter idle", core->core_name); |
| 157 | core->idle_entered = 1; |
| 158 | hrtimer_cancel(&core->slack_timer); |
| 159 | core->idle_entered = 1; |
| 160 | spin_unlock_irqrestore(&core->idle_state_change_lock, flags); |
| 161 | } |
| 162 | |
| 163 | static void start_slack_timer(struct dcvs_core *core, int slack_us) |
| 164 | { |
| 165 | unsigned long flags1, flags2; |
| 166 | int ret; |
| 167 | |
| 168 | spin_lock_irqsave(&core->idle_state_change_lock, flags2); |
| 169 | |
| 170 | spin_lock_irqsave(&core->pending_freq_lock, flags1); |
| 171 | |
| 172 | /* err only for cpu type's GPU's can do idle enter consecutively */ |
| 173 | if (core->idle_entered == 0 && !(core->dcvs_core_id >= GPU_OFFSET)) |
| 174 | __err("%s trying to reexit idle", core->core_name); |
| 175 | core->idle_entered = 0; |
| 176 | /* |
| 177 | * only start the timer if governor is not stopped |
| 178 | */ |
| 179 | if (slack_us != 0 |
| 180 | && !(core->pending_freq < NO_OUTSTANDING_FREQ_CHANGE)) { |
| 181 | ret = hrtimer_start(&core->slack_timer, |
| 182 | ktime_set(0, slack_us * 1000), |
| 183 | HRTIMER_MODE_REL_PINNED); |
| 184 | if (ret) { |
| 185 | pr_err("%s Failed to start timer ret = %d\n", |
| 186 | core->core_name, ret); |
| 187 | } |
| 188 | } |
| 189 | spin_unlock_irqrestore(&core->pending_freq_lock, flags1); |
| 190 | |
| 191 | spin_unlock_irqrestore(&core->idle_state_change_lock, flags2); |
| 192 | } |
| 193 | |
| 194 | static void restart_slack_timer(struct dcvs_core *core, int slack_us) |
| 195 | { |
| 196 | unsigned long flags1, flags2; |
| 197 | int ret; |
| 198 | |
| 199 | spin_lock_irqsave(&core->idle_state_change_lock, flags2); |
| 200 | |
| 201 | hrtimer_cancel(&core->slack_timer); |
| 202 | |
| 203 | spin_lock_irqsave(&core->pending_freq_lock, flags1); |
| 204 | |
| 205 | /* |
| 206 | * only start the timer if idle is not entered |
| 207 | * and governor is not stopped |
| 208 | */ |
| 209 | if (slack_us != 0 && (core->idle_entered != 1) |
| 210 | && !(core->pending_freq < NO_OUTSTANDING_FREQ_CHANGE)) { |
| 211 | ret = hrtimer_start(&core->slack_timer, |
| 212 | ktime_set(0, slack_us * 1000), |
| 213 | HRTIMER_MODE_REL_PINNED); |
| 214 | if (ret) { |
| 215 | pr_err("%s Failed to start timer ret = %d\n", |
| 216 | core->core_name, ret); |
| 217 | } |
| 218 | } |
| 219 | spin_unlock_irqrestore(&core->pending_freq_lock, flags1); |
| 220 | spin_unlock_irqrestore(&core->idle_state_change_lock, flags2); |
| 221 | } |
| 222 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 223 | static int __msm_dcvs_change_freq(struct dcvs_core *core) |
| 224 | { |
| 225 | int ret = 0; |
| 226 | unsigned long flags = 0; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 227 | int requested_freq = 0; |
| 228 | ktime_t time_start; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 229 | uint32_t slack_us = 0; |
| 230 | uint32_t ret1 = 0; |
| 231 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 232 | spin_lock_irqsave(&core->pending_freq_lock, flags); |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 233 | repeat: |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 234 | BUG_ON(!core->pending_freq); |
| 235 | if (core->pending_freq == STOP_FREQ_CHANGE) |
| 236 | BUG(); |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 237 | |
| 238 | requested_freq = core->pending_freq; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 239 | time_start = core->time_start; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 240 | core->time_start = ns_to_ktime(0); |
| 241 | |
| 242 | if (requested_freq < 0) { |
| 243 | requested_freq = -1 * requested_freq; |
| 244 | core->pending_freq = STOP_FREQ_CHANGE; |
| 245 | } else { |
| 246 | core->pending_freq = NO_OUTSTANDING_FREQ_CHANGE; |
| 247 | } |
| 248 | |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 249 | if (requested_freq == core->actual_freq) |
| 250 | goto out; |
| 251 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 252 | spin_unlock_irqrestore(&core->pending_freq_lock, flags); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 253 | |
| 254 | /** |
| 255 | * Call the frequency sink driver to change the frequency |
| 256 | * We will need to get back the actual frequency in KHz and |
| 257 | * the record the time taken to change it. |
| 258 | */ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 259 | ret = core->set_frequency(core->type_core_num, requested_freq); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 260 | if (ret <= 0) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 261 | __err("Core %s failed to set freq %u\n", |
| 262 | core->core_name, requested_freq); |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 263 | /* continue to call TZ to get updated slack timer */ |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 264 | else |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 265 | core->actual_freq = ret; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 266 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 267 | core->freq_change_us = (uint32_t)ktime_to_us( |
| 268 | ktime_sub(ktime_get(), time_start)); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 269 | |
| 270 | /** |
| 271 | * Disable low power modes if the actual frequency is > |
| 272 | * disable_pc_threshold. |
| 273 | */ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 274 | if (core->actual_freq > core->algo_param.disable_pc_threshold) { |
| 275 | core->idle_enable(core->type_core_num, |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 276 | MSM_DCVS_DISABLE_HIGH_LATENCY_MODES); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 277 | } else if (core->actual_freq <= core->algo_param.disable_pc_threshold) { |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 278 | core->idle_enable(core->type_core_num, |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 279 | MSM_DCVS_ENABLE_HIGH_LATENCY_MODES); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Update algorithm with new freq and time taken to change |
| 284 | * to this frequency and that will get us the new slack |
| 285 | * timer |
| 286 | */ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 287 | ret = msm_dcvs_scm_event(core->dcvs_core_id, |
| 288 | MSM_DCVS_SCM_CLOCK_FREQ_UPDATE, |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 289 | core->actual_freq, core->freq_change_us, |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 290 | &slack_us, &ret1); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 291 | if (ret) { |
| 292 | __err("Error sending core (%s) dcvs_core_id = %d freq change (%u) reqfreq = %d slack_us=%d ret = %d\n", |
| 293 | core->core_name, core->dcvs_core_id, |
| 294 | core->actual_freq, requested_freq, |
| 295 | slack_us, ret); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 298 | /* TODO confirm that we get a valid freq from SM even when the above |
| 299 | * FREQ_UPDATE fails |
| 300 | */ |
| 301 | restart_slack_timer(core, slack_us); |
| 302 | spin_lock_irqsave(&core->pending_freq_lock, flags); |
| 303 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 304 | /** |
| 305 | * By the time we are done with freq changes, we could be asked to |
| 306 | * change again. Check before exiting. |
| 307 | */ |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 308 | if (core->pending_freq != NO_OUTSTANDING_FREQ_CHANGE |
| 309 | && core->pending_freq != STOP_FREQ_CHANGE) { |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 310 | goto repeat; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 311 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 312 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 313 | out: /* should always be jumped to with the spin_lock held */ |
| 314 | spin_unlock_irqrestore(&core->pending_freq_lock, flags); |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 315 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 316 | return ret; |
| 317 | } |
| 318 | |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 319 | static void msm_dcvs_report_temp_work(struct work_struct *work) |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 320 | { |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 321 | struct dcvs_core *core = container_of(work, |
| 322 | struct dcvs_core, |
| 323 | temperature_work.work); |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 324 | struct msm_dcvs_core_info *info = core->info; |
| 325 | struct tsens_device tsens_dev; |
| 326 | int ret; |
| 327 | unsigned long temp = 0; |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 328 | int interval_ms; |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 329 | |
| 330 | tsens_dev.sensor_num = core->sensor; |
| 331 | ret = tsens_get_temp(&tsens_dev, &temp); |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 332 | if (!temp) { |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 333 | tsens_dev.sensor_num = 0; |
| 334 | ret = tsens_get_temp(&tsens_dev, &temp); |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 335 | if (!temp) |
| 336 | goto out; |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 339 | if (temp == info->power_param.current_temp) |
| 340 | goto out; |
| 341 | info->power_param.current_temp = temp; |
| 342 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 343 | ret = msm_dcvs_scm_set_power_params(core->dcvs_core_id, |
| 344 | &info->power_param, |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 345 | &info->freq_tbl[0], &core->coeffs); |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 346 | out: |
| 347 | if (info->thermal_poll_ms == 0) |
| 348 | interval_ms = 60000; |
| 349 | else if (info->thermal_poll_ms < 1000) |
| 350 | interval_ms = 1000; |
| 351 | else |
| 352 | interval_ms = info->thermal_poll_ms; |
| 353 | |
| 354 | schedule_delayed_work(&core->temperature_work, |
| 355 | msecs_to_jiffies(interval_ms)); |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 358 | static int msm_dcvs_do_freq(void *data) |
| 359 | { |
| 360 | struct dcvs_core *core = (struct dcvs_core *)data; |
| 361 | static struct sched_param param = {.sched_priority = MAX_RT_PRIO - 1}; |
| 362 | |
| 363 | sched_setscheduler(current, SCHED_FIFO, ¶m); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 364 | |
| 365 | while (!kthread_should_stop()) { |
Abhijeet Dharmapurikar | bbb52fe | 2012-08-31 20:31:16 -0700 | [diff] [blame] | 366 | wait_event(core->wait_q, !(core->pending_freq == 0 || |
| 367 | core->pending_freq == -1) || |
| 368 | kthread_should_stop()); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 369 | |
| 370 | if (kthread_should_stop()) |
| 371 | break; |
| 372 | |
Abhijeet Dharmapurikar | bbb52fe | 2012-08-31 20:31:16 -0700 | [diff] [blame] | 373 | __msm_dcvs_change_freq(core); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 379 | /* freq_pending_lock should be held */ |
| 380 | static void request_freq_change(struct dcvs_core *core, int new_freq) |
| 381 | { |
| 382 | if (new_freq == NO_OUTSTANDING_FREQ_CHANGE) { |
| 383 | if (core->pending_freq != STOP_FREQ_CHANGE) { |
| 384 | __err("%s gov started with earlier pending freq %d\n", |
| 385 | core->core_name, core->pending_freq); |
| 386 | } |
| 387 | core->pending_freq = NO_OUTSTANDING_FREQ_CHANGE; |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | if (new_freq == STOP_FREQ_CHANGE) { |
| 392 | if (core->pending_freq == NO_OUTSTANDING_FREQ_CHANGE) |
| 393 | core->pending_freq = STOP_FREQ_CHANGE; |
| 394 | else if (core->pending_freq > 0) |
| 395 | core->pending_freq = -1 * core->pending_freq; |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | if (core->pending_freq < 0) { |
| 400 | /* a value less than 0 means that the governor has stopped |
| 401 | * and no more freq changes should be requested |
| 402 | */ |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | if (core->actual_freq != new_freq && core->pending_freq != new_freq) { |
| 407 | core->pending_freq = new_freq; |
| 408 | core->time_start = ktime_get(); |
| 409 | wake_up(&core->wait_q); |
| 410 | } |
| 411 | } |
| 412 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 413 | static int msm_dcvs_update_freq(struct dcvs_core *core, |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 414 | enum msm_dcvs_scm_event event, uint32_t param0, |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 415 | uint32_t *ret1) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 416 | { |
| 417 | int ret = 0; |
| 418 | unsigned long flags = 0; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 419 | uint32_t new_freq = -EINVAL; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 420 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 421 | spin_lock_irqsave(&core->pending_freq_lock, flags); |
| 422 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 423 | ret = msm_dcvs_scm_event(core->dcvs_core_id, event, param0, |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 424 | core->actual_freq, &new_freq, ret1); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 425 | if (ret) { |
Jeff Ohlstein | 4aa4a2b | 2012-06-28 19:03:49 -0700 | [diff] [blame] | 426 | if (ret == -13) |
| 427 | ret = 0; |
| 428 | else |
| 429 | __err("Error (%d) sending SCM event %d for core %s\n", |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 430 | ret, event, core->core_name); |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 431 | goto out; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 434 | if (new_freq == 0) { |
| 435 | /* |
| 436 | * sometimes TZ gives us a 0 freq back, |
| 437 | * do not queue up a request |
| 438 | */ |
| 439 | goto out; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 440 | } |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 441 | |
| 442 | request_freq_change(core, new_freq); |
| 443 | |
Abhijeet Dharmapurikar | 584187d | 2012-08-31 19:36:08 -0700 | [diff] [blame] | 444 | out: |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 445 | spin_unlock_irqrestore(&core->pending_freq_lock, flags); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | static enum hrtimer_restart msm_dcvs_core_slack_timer(struct hrtimer *timer) |
| 451 | { |
| 452 | int ret = 0; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 453 | struct dcvs_core *core = container_of(timer, |
| 454 | struct dcvs_core, slack_timer); |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 455 | uint32_t ret1; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 456 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 457 | /** |
| 458 | * Timer expired, notify TZ |
| 459 | * Dont care about the third arg. |
| 460 | */ |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 461 | ret = msm_dcvs_update_freq(core, MSM_DCVS_SCM_QOS_TIMER_EXPIRED, 0, |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 462 | &ret1); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 463 | if (ret) |
| 464 | __err("Timer expired for core %s but failed to notify.\n", |
| 465 | core->core_name); |
| 466 | |
| 467 | return HRTIMER_NORESTART; |
| 468 | } |
| 469 | |
| 470 | /* Helper functions and macros for sysfs nodes for a core */ |
| 471 | #define CORE_FROM_ATTRIBS(attr, name) \ |
| 472 | container_of(container_of(attr, struct core_attribs, name), \ |
| 473 | struct dcvs_core, attrib); |
| 474 | |
| 475 | #define DCVS_PARAM_SHOW(_name, v) \ |
| 476 | static ssize_t msm_dcvs_attr_##_name##_show(struct kobject *kobj, \ |
| 477 | struct kobj_attribute *attr, char *buf) \ |
| 478 | { \ |
| 479 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
| 480 | return snprintf(buf, PAGE_SIZE, "%d\n", v); \ |
| 481 | } |
| 482 | |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 483 | #define DCVS_PARAM_STORE(_name) \ |
| 484 | static ssize_t msm_dcvs_attr_##_name##_show(struct kobject *kobj,\ |
| 485 | struct kobj_attribute *attr, char *buf) \ |
| 486 | { \ |
| 487 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
| 488 | return snprintf(buf, PAGE_SIZE, "%d\n", core->info->_name); \ |
| 489 | } \ |
| 490 | static ssize_t msm_dcvs_attr_##_name##_store(struct kobject *kobj, \ |
| 491 | struct kobj_attribute *attr, const char *buf, size_t count) \ |
| 492 | { \ |
| 493 | int ret = 0; \ |
| 494 | uint32_t val = 0; \ |
| 495 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
| 496 | ret = kstrtouint(buf, 10, &val); \ |
| 497 | if (ret) { \ |
| 498 | __err("Invalid input %s for %s\n", buf, __stringify(_name));\ |
| 499 | } else { \ |
| 500 | core->info->_name = val; \ |
| 501 | } \ |
| 502 | return count; \ |
| 503 | } |
| 504 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 505 | #define DCVS_ALGO_PARAM(_name) \ |
| 506 | static ssize_t msm_dcvs_attr_##_name##_show(struct kobject *kobj,\ |
| 507 | struct kobj_attribute *attr, char *buf) \ |
| 508 | { \ |
| 509 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
| 510 | return snprintf(buf, PAGE_SIZE, "%d\n", core->algo_param._name); \ |
| 511 | } \ |
| 512 | static ssize_t msm_dcvs_attr_##_name##_store(struct kobject *kobj, \ |
| 513 | struct kobj_attribute *attr, const char *buf, size_t count) \ |
| 514 | { \ |
| 515 | int ret = 0; \ |
| 516 | uint32_t val = 0; \ |
| 517 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 518 | ret = kstrtouint(buf, 10, &val); \ |
| 519 | if (ret) { \ |
| 520 | __err("Invalid input %s for %s\n", buf, __stringify(_name));\ |
| 521 | } else { \ |
| 522 | uint32_t old_val = core->algo_param._name; \ |
| 523 | core->algo_param._name = val; \ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 524 | ret = msm_dcvs_scm_set_algo_params(core->dcvs_core_id, \ |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 525 | &core->algo_param); \ |
| 526 | if (ret) { \ |
| 527 | core->algo_param._name = old_val; \ |
| 528 | __err("Error(%d) in setting %d for algo param %s\n",\ |
| 529 | ret, val, __stringify(_name)); \ |
| 530 | } \ |
| 531 | } \ |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 532 | return count; \ |
| 533 | } |
| 534 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 535 | #define DCVS_ENERGY_PARAM(_name) \ |
| 536 | static ssize_t msm_dcvs_attr_##_name##_show(struct kobject *kobj,\ |
| 537 | struct kobj_attribute *attr, char *buf) \ |
| 538 | { \ |
| 539 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
| 540 | return snprintf(buf, PAGE_SIZE, "%d\n", core->coeffs._name); \ |
| 541 | } \ |
| 542 | static ssize_t msm_dcvs_attr_##_name##_store(struct kobject *kobj, \ |
| 543 | struct kobj_attribute *attr, const char *buf, size_t count) \ |
| 544 | { \ |
| 545 | int ret = 0; \ |
| 546 | int32_t val = 0; \ |
| 547 | struct dcvs_core *core = CORE_FROM_ATTRIBS(attr, _name); \ |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 548 | ret = kstrtoint(buf, 10, &val); \ |
| 549 | if (ret) { \ |
| 550 | __err("Invalid input %s for %s\n", buf, __stringify(_name));\ |
| 551 | } else { \ |
| 552 | int32_t old_val = core->coeffs._name; \ |
| 553 | core->coeffs._name = val; \ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 554 | ret = msm_dcvs_scm_set_power_params(core->dcvs_core_id, \ |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 555 | &core->info->power_param, &core->info->freq_tbl[0], \ |
| 556 | &core->coeffs); \ |
| 557 | if (ret) { \ |
| 558 | core->coeffs._name = old_val; \ |
| 559 | __err("Error(%d) in setting %d for coeffs param %s\n",\ |
| 560 | ret, val, __stringify(_name)); \ |
| 561 | } \ |
| 562 | } \ |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 563 | return count; \ |
| 564 | } |
| 565 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 566 | #define DCVS_RO_ATTRIB(i, _name) \ |
| 567 | core->attrib._name.attr.name = __stringify(_name); \ |
| 568 | core->attrib._name.attr.mode = S_IRUGO; \ |
| 569 | core->attrib._name.show = msm_dcvs_attr_##_name##_show; \ |
| 570 | core->attrib._name.store = NULL; \ |
| 571 | core->attrib.attrib_group.attrs[i] = &core->attrib._name.attr; |
| 572 | |
| 573 | #define DCVS_RW_ATTRIB(i, _name) \ |
| 574 | core->attrib._name.attr.name = __stringify(_name); \ |
| 575 | core->attrib._name.attr.mode = S_IRUGO | S_IWUSR; \ |
| 576 | core->attrib._name.show = msm_dcvs_attr_##_name##_show; \ |
| 577 | core->attrib._name.store = msm_dcvs_attr_##_name##_store; \ |
| 578 | core->attrib.attrib_group.attrs[i] = &core->attrib._name.attr; |
| 579 | |
| 580 | /** |
| 581 | * Function declarations for different attributes. |
| 582 | * Gets used when setting the attribute show and store parameters. |
| 583 | */ |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 584 | DCVS_PARAM_SHOW(freq_change_us, (core->freq_change_us)) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 585 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 586 | DCVS_ALGO_PARAM(disable_pc_threshold) |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 587 | DCVS_ALGO_PARAM(em_win_size_min_us) |
| 588 | DCVS_ALGO_PARAM(em_win_size_max_us) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 589 | DCVS_ALGO_PARAM(em_max_util_pct) |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 590 | DCVS_ALGO_PARAM(group_id) |
| 591 | DCVS_ALGO_PARAM(max_freq_chg_time_us) |
| 592 | DCVS_ALGO_PARAM(slack_mode_dynamic) |
| 593 | DCVS_ALGO_PARAM(slack_time_min_us) |
| 594 | DCVS_ALGO_PARAM(slack_time_max_us) |
| 595 | DCVS_ALGO_PARAM(slack_weight_thresh_pct) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 596 | DCVS_ALGO_PARAM(ss_iobusy_conv) |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 597 | DCVS_ALGO_PARAM(ss_win_size_min_us) |
| 598 | DCVS_ALGO_PARAM(ss_win_size_max_us) |
| 599 | DCVS_ALGO_PARAM(ss_util_pct) |
| 600 | |
| 601 | DCVS_ENERGY_PARAM(active_coeff_a) |
| 602 | DCVS_ENERGY_PARAM(active_coeff_b) |
| 603 | DCVS_ENERGY_PARAM(active_coeff_c) |
| 604 | DCVS_ENERGY_PARAM(leakage_coeff_a) |
| 605 | DCVS_ENERGY_PARAM(leakage_coeff_b) |
| 606 | DCVS_ENERGY_PARAM(leakage_coeff_c) |
| 607 | DCVS_ENERGY_PARAM(leakage_coeff_d) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 608 | |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 609 | DCVS_PARAM_STORE(thermal_poll_ms) |
| 610 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 611 | static int msm_dcvs_setup_core_sysfs(struct dcvs_core *core) |
| 612 | { |
| 613 | int ret = 0; |
| 614 | struct kobject *core_kobj = NULL; |
Abhijeet Dharmapurikar | 3587638 | 2012-09-13 16:09:51 -0700 | [diff] [blame^] | 615 | const int attr_count = 24; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 616 | |
| 617 | BUG_ON(!cores_kobj); |
| 618 | |
| 619 | core->attrib.attrib_group.attrs = |
| 620 | kzalloc(attr_count * sizeof(struct attribute *), GFP_KERNEL); |
| 621 | |
| 622 | if (!core->attrib.attrib_group.attrs) { |
| 623 | ret = -ENOMEM; |
| 624 | goto done; |
| 625 | } |
| 626 | |
Abhijeet Dharmapurikar | 3587638 | 2012-09-13 16:09:51 -0700 | [diff] [blame^] | 627 | DCVS_RO_ATTRIB(0, freq_change_us); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 628 | |
Abhijeet Dharmapurikar | 3587638 | 2012-09-13 16:09:51 -0700 | [diff] [blame^] | 629 | DCVS_RW_ATTRIB(1, disable_pc_threshold); |
| 630 | DCVS_RW_ATTRIB(2, em_win_size_min_us); |
| 631 | DCVS_RW_ATTRIB(3, em_win_size_max_us); |
| 632 | DCVS_RW_ATTRIB(4, em_max_util_pct); |
| 633 | DCVS_RW_ATTRIB(5, group_id); |
| 634 | DCVS_RW_ATTRIB(6, max_freq_chg_time_us); |
| 635 | DCVS_RW_ATTRIB(7, slack_mode_dynamic); |
| 636 | DCVS_RW_ATTRIB(8, slack_weight_thresh_pct); |
| 637 | DCVS_RW_ATTRIB(9, slack_time_min_us); |
| 638 | DCVS_RW_ATTRIB(10, slack_time_max_us); |
| 639 | DCVS_RW_ATTRIB(11, ss_iobusy_conv); |
| 640 | DCVS_RW_ATTRIB(12, ss_win_size_min_us); |
| 641 | DCVS_RW_ATTRIB(13, ss_win_size_max_us); |
| 642 | DCVS_RW_ATTRIB(14, ss_util_pct); |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 643 | |
Abhijeet Dharmapurikar | 3587638 | 2012-09-13 16:09:51 -0700 | [diff] [blame^] | 644 | DCVS_RW_ATTRIB(15, active_coeff_a); |
| 645 | DCVS_RW_ATTRIB(16, active_coeff_b); |
| 646 | DCVS_RW_ATTRIB(17, active_coeff_c); |
| 647 | DCVS_RW_ATTRIB(18, leakage_coeff_a); |
| 648 | DCVS_RW_ATTRIB(19, leakage_coeff_b); |
| 649 | DCVS_RW_ATTRIB(20, leakage_coeff_c); |
| 650 | DCVS_RW_ATTRIB(21, leakage_coeff_d); |
| 651 | DCVS_RW_ATTRIB(22, thermal_poll_ms); |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 652 | |
Abhijeet Dharmapurikar | 3587638 | 2012-09-13 16:09:51 -0700 | [diff] [blame^] | 653 | core->attrib.attrib_group.attrs[23] = NULL; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 654 | |
| 655 | core_kobj = kobject_create_and_add(core->core_name, cores_kobj); |
| 656 | if (!core_kobj) { |
| 657 | ret = -ENOMEM; |
| 658 | goto done; |
| 659 | } |
| 660 | |
| 661 | ret = sysfs_create_group(core_kobj, &core->attrib.attrib_group); |
| 662 | if (ret) |
| 663 | __err("Cannot create core %s attr group\n", core->core_name); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 664 | |
| 665 | done: |
| 666 | if (ret) { |
| 667 | kfree(core->attrib.attrib_group.attrs); |
| 668 | kobject_del(core_kobj); |
| 669 | } |
| 670 | |
| 671 | return ret; |
| 672 | } |
| 673 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 674 | /* Return the core and initialize non platform data specific numbers in it */ |
| 675 | static struct dcvs_core *msm_dcvs_add_core(enum msm_dcvs_core_type type, |
| 676 | int num) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 677 | { |
| 678 | struct dcvs_core *core = NULL; |
| 679 | int i; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 680 | char name[CORE_NAME_MAX]; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 681 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 682 | switch (type) { |
| 683 | case MSM_DCVS_CORE_TYPE_CPU: |
| 684 | i = CPU_OFFSET + num; |
| 685 | BUG_ON(i >= GPU_OFFSET); |
| 686 | snprintf(name, CORE_NAME_MAX, "cpu%d", num); |
| 687 | break; |
| 688 | case MSM_DCVS_CORE_TYPE_GPU: |
| 689 | i = GPU_OFFSET + num; |
| 690 | BUG_ON(i >= CORES_MAX); |
| 691 | snprintf(name, CORE_NAME_MAX, "gpu%d", num); |
| 692 | break; |
| 693 | default: |
| 694 | return NULL; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 697 | core = &core_list[i]; |
| 698 | core->dcvs_core_id = i; |
Abhijeet Dharmapurikar | 2ebc0fe | 2012-09-12 14:05:13 -0700 | [diff] [blame] | 699 | strlcpy(core->core_name, name, CORE_NAME_MAX); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 700 | spin_lock_init(&core->pending_freq_lock); |
| 701 | spin_lock_init(&core->idle_state_change_lock); |
| 702 | hrtimer_init(&core->slack_timer, |
| 703 | CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); |
| 704 | core->slack_timer.function = msm_dcvs_core_slack_timer; |
Abhijeet Dharmapurikar | 2ebc0fe | 2012-09-12 14:05:13 -0700 | [diff] [blame] | 705 | return core; |
| 706 | } |
| 707 | |
| 708 | /* Return the core if found or add to list if @add_to_list is true */ |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 709 | static struct dcvs_core *msm_dcvs_get_core(int offset) |
Abhijeet Dharmapurikar | 2ebc0fe | 2012-09-12 14:05:13 -0700 | [diff] [blame] | 710 | { |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 711 | /* if the handle is still not set bug */ |
| 712 | BUG_ON(core_list[offset].dcvs_core_id == -1); |
| 713 | return &core_list[offset]; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 714 | } |
| 715 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 716 | |
| 717 | int msm_dcvs_register_core( |
| 718 | enum msm_dcvs_core_type type, |
| 719 | int type_core_num, |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 720 | struct msm_dcvs_core_info *info, |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 721 | int (*set_frequency)(int type_core_num, unsigned int freq), |
| 722 | unsigned int (*get_frequency)(int type_core_num), |
| 723 | int (*idle_enable)(int type_core_num, |
Abhijeet Dharmapurikar | 6e9b34f | 2012-09-10 16:03:39 -0700 | [diff] [blame] | 724 | enum msm_core_control_event event), |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 725 | int sensor) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 726 | { |
| 727 | int ret = -EINVAL; |
| 728 | struct dcvs_core *core = NULL; |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 729 | uint32_t ret1; |
| 730 | uint32_t ret2; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 731 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 732 | core = msm_dcvs_add_core(type, type_core_num); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 733 | if (!core) |
| 734 | return ret; |
| 735 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 736 | core->type = type; |
| 737 | core->type_core_num = type_core_num; |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 738 | core->set_frequency = set_frequency; |
| 739 | core->get_frequency = get_frequency; |
Abhijeet Dharmapurikar | 6e9b34f | 2012-09-10 16:03:39 -0700 | [diff] [blame] | 740 | core->idle_enable = idle_enable; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 741 | core->pending_freq = STOP_FREQ_CHANGE; |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 742 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 743 | core->info = info; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 744 | memcpy(&core->algo_param, &info->algo_param, |
| 745 | sizeof(struct msm_dcvs_algo_param)); |
| 746 | |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 747 | memcpy(&core->coeffs, &info->energy_coeffs, |
| 748 | sizeof(struct msm_dcvs_energy_curve_coeffs)); |
| 749 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 750 | /* |
| 751 | * The tz expects cpu0 to represent bit 0 in the mask, however the |
| 752 | * dcvs_core_id needs to start from 1, dcvs_core_id = 0 is used to |
| 753 | * indicate that this request is not associated with any core. |
| 754 | * mpdecision |
| 755 | */ |
| 756 | info->core_param.core_bitmask_id |
| 757 | = 1 << (core->dcvs_core_id - CPU_OFFSET); |
Abhijeet Dharmapurikar | b6c0577 | 2012-08-26 18:27:53 -0700 | [diff] [blame] | 758 | core->sensor = sensor; |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 759 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 760 | ret = msm_dcvs_scm_register_core(core->dcvs_core_id, &info->core_param); |
| 761 | if (ret) { |
| 762 | __err("%s: scm register core fail handle = %d ret = %d\n", |
| 763 | __func__, core->dcvs_core_id, ret); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 764 | goto bail; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 765 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 766 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 767 | ret = msm_dcvs_scm_set_algo_params(core->dcvs_core_id, |
| 768 | &info->algo_param); |
| 769 | if (ret) { |
| 770 | __err("%s: scm algo params failed ret = %d\n", __func__, ret); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 771 | goto bail; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 772 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 773 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 774 | ret = msm_dcvs_scm_set_power_params(core->dcvs_core_id, |
| 775 | &info->power_param, |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 776 | &info->freq_tbl[0], &core->coeffs); |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 777 | if (ret) { |
| 778 | __err("%s: scm power params failed ret = %d\n", __func__, ret); |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 779 | goto bail; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 780 | } |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 781 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 782 | ret = msm_dcvs_scm_event(core->dcvs_core_id, MSM_DCVS_SCM_CORE_ONLINE, |
Abhijeet Dharmapurikar | 7e37e6e | 2012-08-23 18:58:44 -0700 | [diff] [blame] | 783 | core->actual_freq, 0, &ret1, &ret2); |
| 784 | if (ret) |
| 785 | goto bail; |
| 786 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 787 | ret = msm_dcvs_setup_core_sysfs(core); |
| 788 | if (ret) { |
| 789 | __err("Unable to setup core %s sysfs\n", core->core_name); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 790 | goto bail; |
| 791 | } |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 792 | core->idle_entered = -1; |
Abhijeet Dharmapurikar | bbb52fe | 2012-08-31 20:31:16 -0700 | [diff] [blame] | 793 | init_waitqueue_head(&core->wait_q); |
| 794 | core->task = kthread_run(msm_dcvs_do_freq, (void *)core, |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 795 | "msm_dcvs/%d", core->dcvs_core_id); |
| 796 | ret = core->dcvs_core_id; |
Abhijeet Dharmapurikar | 19cf474 | 2012-09-13 11:11:54 -0700 | [diff] [blame] | 797 | |
| 798 | INIT_DELAYED_WORK(&core->temperature_work, msm_dcvs_report_temp_work); |
| 799 | schedule_delayed_work(&core->temperature_work, |
| 800 | msecs_to_jiffies(info->thermal_poll_ms)); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 801 | return ret; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 802 | bail: |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 803 | core->dcvs_core_id = -1; |
| 804 | return -EINVAL; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 805 | } |
| 806 | EXPORT_SYMBOL(msm_dcvs_register_core); |
| 807 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 808 | void msm_dcvs_update_limits(int dcvs_core_id) |
Abhijeet Dharmapurikar | c43f0db | 2012-08-31 20:42:53 -0700 | [diff] [blame] | 809 | { |
| 810 | struct dcvs_core *core; |
| 811 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 812 | if (dcvs_core_id < CPU_OFFSET || dcvs_core_id > CORES_MAX) { |
| 813 | __err("%s invalid dcvs_core_id = %d returning -EINVAL\n", |
| 814 | __func__, dcvs_core_id); |
Abhijeet Dharmapurikar | c43f0db | 2012-08-31 20:42:53 -0700 | [diff] [blame] | 815 | return; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 816 | } |
Abhijeet Dharmapurikar | c43f0db | 2012-08-31 20:42:53 -0700 | [diff] [blame] | 817 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 818 | core = msm_dcvs_get_core(dcvs_core_id); |
| 819 | core->actual_freq = core->get_frequency(core->type_core_num); |
Abhijeet Dharmapurikar | c43f0db | 2012-08-31 20:42:53 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 822 | int msm_dcvs_freq_sink_start(int dcvs_core_id) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 823 | { |
| 824 | int ret = -EINVAL; |
| 825 | struct dcvs_core *core = NULL; |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 826 | uint32_t ret1; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 827 | unsigned long flags; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 828 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 829 | if (dcvs_core_id < CPU_OFFSET || dcvs_core_id > CORES_MAX) { |
| 830 | __err("%s invalid dcvs_core_id = %d returning -EINVAL\n", |
| 831 | __func__, dcvs_core_id); |
| 832 | return -EINVAL; |
| 833 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 834 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 835 | core = msm_dcvs_get_core(dcvs_core_id); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 836 | if (!core) |
| 837 | return ret; |
| 838 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 839 | core->actual_freq = core->get_frequency(core->type_core_num); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 840 | |
| 841 | spin_lock_irqsave(&core->pending_freq_lock, flags); |
| 842 | /* mark that we are ready to accept new frequencies */ |
| 843 | request_freq_change(core, NO_OUTSTANDING_FREQ_CHANGE); |
| 844 | spin_unlock_irqrestore(&core->pending_freq_lock, flags); |
| 845 | |
| 846 | spin_lock_irqsave(&core->idle_state_change_lock, flags); |
| 847 | core->idle_entered = -1; |
| 848 | spin_unlock_irqrestore(&core->idle_state_change_lock, flags); |
| 849 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 850 | /* Notify TZ to start receiving idle info for the core */ |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 851 | ret = msm_dcvs_update_freq(core, MSM_DCVS_SCM_DCVS_ENABLE, 1, &ret1); |
| 852 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 853 | core->idle_enable(core->type_core_num, MSM_DCVS_ENABLE_IDLE_PULSE); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 854 | return 0; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 855 | } |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 856 | EXPORT_SYMBOL(msm_dcvs_freq_sink_start); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 857 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 858 | int msm_dcvs_freq_sink_stop(int dcvs_core_id) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 859 | { |
| 860 | int ret = -EINVAL; |
| 861 | struct dcvs_core *core = NULL; |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 862 | uint32_t ret1; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 863 | uint32_t freq; |
| 864 | unsigned long flags; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 865 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 866 | if (dcvs_core_id < 0 || dcvs_core_id > CORES_MAX) { |
| 867 | pr_err("%s invalid dcvs_core_id = %d returning -EINVAL\n", |
| 868 | __func__, dcvs_core_id); |
| 869 | return -EINVAL; |
| 870 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 871 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 872 | core = msm_dcvs_get_core(dcvs_core_id); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 873 | if (!core) { |
| 874 | __err("couldn't find core for coreid = %d\n", dcvs_core_id); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 875 | return ret; |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 876 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 877 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 878 | core->idle_enable(core->type_core_num, MSM_DCVS_DISABLE_IDLE_PULSE); |
| 879 | /* Notify TZ to stop receiving idle info for the core */ |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 880 | ret = msm_dcvs_scm_event(core->dcvs_core_id, MSM_DCVS_SCM_DCVS_ENABLE, |
| 881 | 0, core->actual_freq, &freq, &ret1); |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 882 | core->idle_enable(core->type_core_num, |
| 883 | MSM_DCVS_ENABLE_HIGH_LATENCY_MODES); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 884 | spin_lock_irqsave(&core->pending_freq_lock, flags); |
| 885 | /* flush out all the pending freq changes */ |
| 886 | request_freq_change(core, STOP_FREQ_CHANGE); |
| 887 | spin_unlock_irqrestore(&core->pending_freq_lock, flags); |
| 888 | force_stop_slack_timer(core); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 889 | |
| 890 | return 0; |
| 891 | } |
Abhijeet Dharmapurikar | 50bcc83 | 2012-08-31 22:10:41 -0700 | [diff] [blame] | 892 | EXPORT_SYMBOL(msm_dcvs_freq_sink_stop); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 893 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 894 | int msm_dcvs_idle(int dcvs_core_id, enum msm_core_idle_state state, |
| 895 | uint32_t iowaited) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 896 | { |
| 897 | int ret = 0; |
| 898 | struct dcvs_core *core = NULL; |
Eugene Seah | 76af983 | 2012-03-28 18:43:53 -0600 | [diff] [blame] | 899 | uint32_t timer_interval_us = 0; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 900 | uint32_t r0, r1; |
| 901 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 902 | if (dcvs_core_id < CPU_OFFSET || dcvs_core_id > CORES_MAX) { |
| 903 | pr_err("invalid dcvs_core_id = %d ret -EINVAL\n", dcvs_core_id); |
| 904 | return -EINVAL; |
| 905 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 906 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 907 | core = msm_dcvs_get_core(dcvs_core_id); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 908 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 909 | switch (state) { |
| 910 | case MSM_DCVS_IDLE_ENTER: |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 911 | stop_slack_timer(core); |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 912 | ret = msm_dcvs_scm_event(core->dcvs_core_id, |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 913 | MSM_DCVS_SCM_IDLE_ENTER, 0, 0, &r0, &r1); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 914 | if (ret < 0 && ret != -13) |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 915 | __err("Error (%d) sending idle enter for %s\n", |
| 916 | ret, core->core_name); |
| 917 | break; |
| 918 | |
| 919 | case MSM_DCVS_IDLE_EXIT: |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 920 | ret = msm_dcvs_update_freq(core, MSM_DCVS_SCM_IDLE_EXIT, |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 921 | iowaited, &timer_interval_us); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 922 | if (ret) |
| 923 | __err("Error (%d) sending idle exit for %s\n", |
| 924 | ret, core->core_name); |
Abhijeet Dharmapurikar | 080f49d | 2012-09-12 18:14:01 -0700 | [diff] [blame] | 925 | start_slack_timer(core, timer_interval_us); |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 926 | break; |
| 927 | } |
| 928 | |
| 929 | return ret; |
| 930 | } |
| 931 | EXPORT_SYMBOL(msm_dcvs_idle); |
| 932 | |
| 933 | static int __init msm_dcvs_late_init(void) |
| 934 | { |
| 935 | struct kobject *module_kobj = NULL; |
| 936 | int ret = 0; |
| 937 | |
| 938 | module_kobj = kset_find_obj(module_kset, KBUILD_MODNAME); |
| 939 | if (!module_kobj) { |
| 940 | pr_err("%s: cannot find kobject for module %s\n", |
| 941 | __func__, KBUILD_MODNAME); |
| 942 | ret = -ENOENT; |
| 943 | goto err; |
| 944 | } |
| 945 | |
| 946 | cores_kobj = kobject_create_and_add("cores", module_kobj); |
| 947 | if (!cores_kobj) { |
| 948 | __err("Cannot create %s kobject\n", "cores"); |
| 949 | ret = -ENOMEM; |
| 950 | goto err; |
| 951 | } |
| 952 | |
| 953 | debugfs_base = debugfs_create_dir("msm_dcvs", NULL); |
| 954 | if (!debugfs_base) { |
| 955 | __err("Cannot create debugfs base %s\n", "msm_dcvs"); |
| 956 | ret = -ENOENT; |
| 957 | goto err; |
| 958 | } |
| 959 | |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 960 | err: |
| 961 | if (ret) { |
| 962 | kobject_del(cores_kobj); |
| 963 | cores_kobj = NULL; |
| 964 | debugfs_remove(debugfs_base); |
| 965 | } |
| 966 | |
| 967 | return ret; |
| 968 | } |
| 969 | late_initcall(msm_dcvs_late_init); |
| 970 | |
| 971 | static int __init msm_dcvs_early_init(void) |
| 972 | { |
| 973 | int ret = 0; |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 974 | int i; |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 975 | |
| 976 | if (!msm_dcvs_enabled) { |
| 977 | __info("Not enabled (%d)\n", msm_dcvs_enabled); |
| 978 | return 0; |
| 979 | } |
| 980 | |
Abhijeet Dharmapurikar | 3edb5de | 2012-09-13 11:02:03 -0700 | [diff] [blame] | 981 | |
| 982 | /* Only need about 32kBytes for normal operation */ |
| 983 | ret = msm_dcvs_scm_init(SZ_32K); |
| 984 | if (ret) { |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 985 | __err("Unable to initialize DCVS err=%d\n", ret); |
Abhijeet Dharmapurikar | 3edb5de | 2012-09-13 11:02:03 -0700 | [diff] [blame] | 986 | goto done; |
| 987 | } |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 988 | |
Abhijeet Dharmapurikar | da4e6de | 2012-09-12 16:40:20 -0700 | [diff] [blame] | 989 | for (i = 0; i < CORES_MAX; i++) |
| 990 | core_list[i].dcvs_core_id = -1; |
Abhijeet Dharmapurikar | 3edb5de | 2012-09-13 11:02:03 -0700 | [diff] [blame] | 991 | done: |
Praveen Chidambaram | f53ef1b | 2011-12-06 08:27:49 -0700 | [diff] [blame] | 992 | return ret; |
| 993 | } |
| 994 | postcore_initcall(msm_dcvs_early_init); |