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