Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/thermal/cpu_cooling.c |
| 3 | * |
| 4 | * Copyright (C) 2012 Samsung Electronics Co., Ltd(http://www.samsung.com) |
| 5 | * Copyright (C) 2012 Amit Daniel <amit.kachhap@linaro.org> |
| 6 | * |
Viresh Kumar | 73904cb | 2014-12-04 09:42:08 +0530 | [diff] [blame] | 7 | * Copyright (C) 2014 Viresh Kumar <viresh.kumar@linaro.org> |
| 8 | * |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; version 2 of the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 | * |
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | */ |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/thermal.h> |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 27 | #include <linux/cpufreq.h> |
| 28 | #include <linux/err.h> |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 29 | #include <linux/pm_opp.h> |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 30 | #include <linux/slab.h> |
| 31 | #include <linux/cpu.h> |
| 32 | #include <linux/cpu_cooling.h> |
| 33 | |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 34 | #include <trace/events/thermal.h> |
| 35 | |
Viresh Kumar | 07d888d | 2014-12-04 09:41:49 +0530 | [diff] [blame] | 36 | /* |
| 37 | * Cooling state <-> CPUFreq frequency |
| 38 | * |
| 39 | * Cooling states are translated to frequencies throughout this driver and this |
| 40 | * is the relation between them. |
| 41 | * |
| 42 | * Highest cooling state corresponds to lowest possible frequency. |
| 43 | * |
| 44 | * i.e. |
| 45 | * level 0 --> 1st Max Freq |
| 46 | * level 1 --> 2nd Max Freq |
| 47 | * ... |
| 48 | */ |
| 49 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 50 | /** |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 51 | * struct power_table - frequency to power conversion |
| 52 | * @frequency: frequency in KHz |
| 53 | * @power: power in mW |
| 54 | * |
| 55 | * This structure is built when the cooling device registers and helps |
| 56 | * in translating frequency to power and viceversa. |
| 57 | */ |
| 58 | struct power_table { |
| 59 | u32 frequency; |
| 60 | u32 power; |
| 61 | }; |
| 62 | |
| 63 | /** |
Eduardo Valentin | 3b3c074 | 2013-04-17 17:11:56 +0000 | [diff] [blame] | 64 | * struct cpufreq_cooling_device - data for cooling device with cpufreq |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 65 | * @id: unique integer value corresponding to each cpufreq_cooling_device |
| 66 | * registered. |
Eduardo Valentin | 3b3c074 | 2013-04-17 17:11:56 +0000 | [diff] [blame] | 67 | * @cool_dev: thermal_cooling_device pointer to keep track of the |
| 68 | * registered cooling device. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 69 | * @cpufreq_state: integer value representing the current state of cpufreq |
| 70 | * cooling devices. |
| 71 | * @cpufreq_val: integer value representing the absolute value of the clipped |
| 72 | * frequency. |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 73 | * @max_level: maximum cooling level. One less than total number of valid |
| 74 | * cpufreq frequencies. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 75 | * @allowed_cpus: all the cpus involved for this cpufreq_cooling_device. |
Javi Merino | fc4de35 | 2014-12-15 16:55:52 +0000 | [diff] [blame] | 76 | * @node: list_head to link all cpufreq_cooling_device together. |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 77 | * @last_load: load measured by the latest call to cpufreq_get_actual_power() |
| 78 | * @time_in_idle: previous reading of the absolute time that this cpu was idle |
| 79 | * @time_in_idle_timestamp: wall time of the last invocation of |
| 80 | * get_cpu_idle_time_us() |
| 81 | * @dyn_power_table: array of struct power_table for frequency to power |
| 82 | * conversion, sorted in ascending order. |
| 83 | * @dyn_power_table_entries: number of entries in the @dyn_power_table array |
| 84 | * @cpu_dev: the first cpu_device from @allowed_cpus that has OPPs registered |
| 85 | * @plat_get_static_power: callback to calculate the static power |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 86 | * |
Viresh Kumar | beca605 | 2014-12-04 09:41:48 +0530 | [diff] [blame] | 87 | * This structure is required for keeping information of each registered |
| 88 | * cpufreq_cooling_device. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 89 | */ |
| 90 | struct cpufreq_cooling_device { |
| 91 | int id; |
| 92 | struct thermal_cooling_device *cool_dev; |
| 93 | unsigned int cpufreq_state; |
| 94 | unsigned int cpufreq_val; |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 95 | unsigned int max_level; |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 96 | unsigned int *freq_table; /* In descending order */ |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 97 | struct cpumask allowed_cpus; |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 98 | struct list_head node; |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 99 | u32 last_load; |
| 100 | u64 *time_in_idle; |
| 101 | u64 *time_in_idle_timestamp; |
| 102 | struct power_table *dyn_power_table; |
| 103 | int dyn_power_table_entries; |
| 104 | struct device *cpu_dev; |
| 105 | get_static_t plat_get_static_power; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 106 | }; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 107 | static DEFINE_IDR(cpufreq_idr); |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 108 | static DEFINE_MUTEX(cooling_cpufreq_lock); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 109 | |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 110 | static LIST_HEAD(cpufreq_dev_list); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * get_idr - function to get a unique id. |
| 114 | * @idr: struct idr * handle used to create a id. |
| 115 | * @id: int * value generated by this function. |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 116 | * |
| 117 | * This function will populate @id with an unique |
| 118 | * id, using the idr API. |
| 119 | * |
| 120 | * Return: 0 on success, an error code on failure. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 121 | */ |
| 122 | static int get_idr(struct idr *idr, int *id) |
| 123 | { |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 124 | int ret; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 125 | |
| 126 | mutex_lock(&cooling_cpufreq_lock); |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 127 | ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 128 | mutex_unlock(&cooling_cpufreq_lock); |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 129 | if (unlikely(ret < 0)) |
| 130 | return ret; |
| 131 | *id = ret; |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 132 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * release_idr - function to free the unique id. |
| 138 | * @idr: struct idr * handle used for creating the id. |
| 139 | * @id: int value representing the unique id. |
| 140 | */ |
| 141 | static void release_idr(struct idr *idr, int id) |
| 142 | { |
| 143 | mutex_lock(&cooling_cpufreq_lock); |
| 144 | idr_remove(idr, id); |
| 145 | mutex_unlock(&cooling_cpufreq_lock); |
| 146 | } |
| 147 | |
| 148 | /* Below code defines functions to be used for cpufreq as cooling device */ |
| 149 | |
| 150 | /** |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 151 | * get_level: Find the level for a particular frequency |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 152 | * @cpufreq_dev: cpufreq_dev for which the property is required |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 153 | * @freq: Frequency |
Eduardo Valentin | 82b9ee4 | 2013-04-17 17:12:00 +0000 | [diff] [blame] | 154 | * |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 155 | * Return: level on success, THERMAL_CSTATE_INVALID on error. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 156 | */ |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 157 | static unsigned long get_level(struct cpufreq_cooling_device *cpufreq_dev, |
| 158 | unsigned int freq) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 159 | { |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 160 | unsigned long level; |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 161 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 162 | for (level = 0; level <= cpufreq_dev->max_level; level++) { |
| 163 | if (freq == cpufreq_dev->freq_table[level]) |
| 164 | return level; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 165 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 166 | if (freq > cpufreq_dev->freq_table[level]) |
| 167 | break; |
Zhang Rui | fc35b35 | 2013-02-08 13:09:32 +0800 | [diff] [blame] | 168 | } |
Zhang Rui | a116776 | 2014-01-02 11:57:48 +0800 | [diff] [blame] | 169 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 170 | return THERMAL_CSTATE_INVALID; |
Zhang Rui | fc35b35 | 2013-02-08 13:09:32 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Eduardo Valentin | 44952d3 | 2013-04-17 17:12:05 +0000 | [diff] [blame] | 173 | /** |
Viresh Kumar | 728c03c | 2014-12-04 09:41:47 +0530 | [diff] [blame] | 174 | * cpufreq_cooling_get_level - for a given cpu, return the cooling level. |
Eduardo Valentin | 44952d3 | 2013-04-17 17:12:05 +0000 | [diff] [blame] | 175 | * @cpu: cpu for which the level is required |
| 176 | * @freq: the frequency of interest |
| 177 | * |
| 178 | * This function will match the cooling level corresponding to the |
| 179 | * requested @freq and return it. |
| 180 | * |
| 181 | * Return: The matched cooling level on success or THERMAL_CSTATE_INVALID |
| 182 | * otherwise. |
| 183 | */ |
Zhang Rui | 57df810 | 2013-02-08 14:52:06 +0800 | [diff] [blame] | 184 | unsigned long cpufreq_cooling_get_level(unsigned int cpu, unsigned int freq) |
| 185 | { |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 186 | struct cpufreq_cooling_device *cpufreq_dev; |
Zhang Rui | 57df810 | 2013-02-08 14:52:06 +0800 | [diff] [blame] | 187 | |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 188 | mutex_lock(&cooling_cpufreq_lock); |
| 189 | list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { |
| 190 | if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 191 | mutex_unlock(&cooling_cpufreq_lock); |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 192 | return get_level(cpufreq_dev, freq); |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | mutex_unlock(&cooling_cpufreq_lock); |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 196 | |
Viresh Kumar | b9f8b41 | 2014-12-04 09:42:05 +0530 | [diff] [blame] | 197 | pr_err("%s: cpu:%d not part of any cooling device\n", __func__, cpu); |
| 198 | return THERMAL_CSTATE_INVALID; |
Zhang Rui | 57df810 | 2013-02-08 14:52:06 +0800 | [diff] [blame] | 199 | } |
Eduardo Valentin | 243dbd9 | 2013-04-17 17:11:57 +0000 | [diff] [blame] | 200 | EXPORT_SYMBOL_GPL(cpufreq_cooling_get_level); |
Zhang Rui | 57df810 | 2013-02-08 14:52:06 +0800 | [diff] [blame] | 201 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 202 | static void update_cpu_device(int cpu) |
| 203 | { |
| 204 | struct cpufreq_cooling_device *cpufreq_dev; |
| 205 | |
| 206 | mutex_lock(&cooling_cpufreq_lock); |
| 207 | list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { |
| 208 | if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { |
| 209 | cpufreq_dev->cpu_dev = get_cpu_device(cpu); |
| 210 | if (!cpufreq_dev->cpu_dev) { |
| 211 | dev_warn(&cpufreq_dev->cool_dev->device, |
| 212 | "No cpu device for new policy cpu %d\n", |
| 213 | cpu); |
| 214 | } |
| 215 | break; |
| 216 | } |
| 217 | } |
| 218 | mutex_unlock(&cooling_cpufreq_lock); |
| 219 | } |
| 220 | |
| 221 | static void remove_cpu_device(int cpu) |
| 222 | { |
| 223 | struct cpufreq_cooling_device *cpufreq_dev; |
| 224 | |
| 225 | mutex_lock(&cooling_cpufreq_lock); |
| 226 | list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { |
| 227 | if (cpumask_test_cpu(cpu, &cpufreq_dev->allowed_cpus)) { |
| 228 | cpufreq_dev->cpu_dev = NULL; |
| 229 | break; |
| 230 | } |
| 231 | } |
| 232 | mutex_unlock(&cooling_cpufreq_lock); |
| 233 | } |
| 234 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 235 | /** |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 236 | * cpufreq_thermal_notifier - notifier callback for cpufreq policy change. |
| 237 | * @nb: struct notifier_block * with callback info. |
| 238 | * @event: value showing cpufreq event for which this function invoked. |
| 239 | * @data: callback-specific data |
Eduardo Valentin | bab3055 | 2013-04-17 17:12:09 +0000 | [diff] [blame] | 240 | * |
Javi Merino | 9746b6e | 2014-06-25 18:11:17 +0100 | [diff] [blame] | 241 | * Callback to hijack the notification on cpufreq policy transition. |
Eduardo Valentin | bab3055 | 2013-04-17 17:12:09 +0000 | [diff] [blame] | 242 | * Every time there is a change in policy, we will intercept and |
| 243 | * update the cpufreq policy with thermal constraints. |
| 244 | * |
| 245 | * Return: 0 (success) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 246 | */ |
| 247 | static int cpufreq_thermal_notifier(struct notifier_block *nb, |
Eduardo Valentin | 5fda7f6 | 2013-04-17 17:12:11 +0000 | [diff] [blame] | 248 | unsigned long event, void *data) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 249 | { |
| 250 | struct cpufreq_policy *policy = data; |
| 251 | unsigned long max_freq = 0; |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 252 | struct cpufreq_cooling_device *cpufreq_dev; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 253 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 254 | switch (event) { |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 255 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 256 | case CPUFREQ_ADJUST: |
| 257 | mutex_lock(&cooling_cpufreq_lock); |
| 258 | list_for_each_entry(cpufreq_dev, &cpufreq_dev_list, node) { |
| 259 | if (!cpumask_test_cpu(policy->cpu, |
| 260 | &cpufreq_dev->allowed_cpus)) |
| 261 | continue; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 262 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 263 | max_freq = cpufreq_dev->cpufreq_val; |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 264 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 265 | if (policy->max != max_freq) |
| 266 | cpufreq_verify_within_limits(policy, 0, |
| 267 | max_freq); |
| 268 | } |
| 269 | mutex_unlock(&cooling_cpufreq_lock); |
| 270 | break; |
| 271 | |
| 272 | case CPUFREQ_CREATE_POLICY: |
| 273 | update_cpu_device(policy->cpu); |
| 274 | break; |
| 275 | case CPUFREQ_REMOVE_POLICY: |
| 276 | remove_cpu_device(policy->cpu); |
| 277 | break; |
| 278 | default: |
| 279 | return NOTIFY_DONE; |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 280 | } |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 281 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 282 | return NOTIFY_OK; |
| 283 | } |
| 284 | |
| 285 | /** |
| 286 | * build_dyn_power_table() - create a dynamic power to frequency table |
| 287 | * @cpufreq_device: the cpufreq cooling device in which to store the table |
| 288 | * @capacitance: dynamic power coefficient for these cpus |
| 289 | * |
| 290 | * Build a dynamic power to frequency table for this cpu and store it |
| 291 | * in @cpufreq_device. This table will be used in cpu_power_to_freq() and |
| 292 | * cpu_freq_to_power() to convert between power and frequency |
| 293 | * efficiently. Power is stored in mW, frequency in KHz. The |
| 294 | * resulting table is in ascending order. |
| 295 | * |
| 296 | * Return: 0 on success, -E* on error. |
| 297 | */ |
| 298 | static int build_dyn_power_table(struct cpufreq_cooling_device *cpufreq_device, |
| 299 | u32 capacitance) |
| 300 | { |
| 301 | struct power_table *power_table; |
| 302 | struct dev_pm_opp *opp; |
| 303 | struct device *dev = NULL; |
| 304 | int num_opps = 0, cpu, i, ret = 0; |
| 305 | unsigned long freq; |
| 306 | |
| 307 | rcu_read_lock(); |
| 308 | |
| 309 | for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { |
| 310 | dev = get_cpu_device(cpu); |
| 311 | if (!dev) { |
| 312 | dev_warn(&cpufreq_device->cool_dev->device, |
| 313 | "No cpu device for cpu %d\n", cpu); |
| 314 | continue; |
| 315 | } |
| 316 | |
| 317 | num_opps = dev_pm_opp_get_opp_count(dev); |
| 318 | if (num_opps > 0) { |
| 319 | break; |
| 320 | } else if (num_opps < 0) { |
| 321 | ret = num_opps; |
| 322 | goto unlock; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if (num_opps == 0) { |
| 327 | ret = -EINVAL; |
| 328 | goto unlock; |
| 329 | } |
| 330 | |
| 331 | power_table = kcalloc(num_opps, sizeof(*power_table), GFP_KERNEL); |
Javi Merino | 0cdf97e | 2015-03-20 18:20:13 +0000 | [diff] [blame^] | 332 | if (!power_table) { |
| 333 | ret = -ENOMEM; |
| 334 | goto unlock; |
| 335 | } |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 336 | |
| 337 | for (freq = 0, i = 0; |
| 338 | opp = dev_pm_opp_find_freq_ceil(dev, &freq), !IS_ERR(opp); |
| 339 | freq++, i++) { |
| 340 | u32 freq_mhz, voltage_mv; |
| 341 | u64 power; |
| 342 | |
| 343 | freq_mhz = freq / 1000000; |
| 344 | voltage_mv = dev_pm_opp_get_voltage(opp) / 1000; |
| 345 | |
| 346 | /* |
| 347 | * Do the multiplication with MHz and millivolt so as |
| 348 | * to not overflow. |
| 349 | */ |
| 350 | power = (u64)capacitance * freq_mhz * voltage_mv * voltage_mv; |
| 351 | do_div(power, 1000000000); |
| 352 | |
| 353 | /* frequency is stored in power_table in KHz */ |
| 354 | power_table[i].frequency = freq / 1000; |
| 355 | |
| 356 | /* power is stored in mW */ |
| 357 | power_table[i].power = power; |
| 358 | } |
| 359 | |
| 360 | if (i == 0) { |
| 361 | ret = PTR_ERR(opp); |
| 362 | goto unlock; |
| 363 | } |
| 364 | |
| 365 | cpufreq_device->cpu_dev = dev; |
| 366 | cpufreq_device->dyn_power_table = power_table; |
| 367 | cpufreq_device->dyn_power_table_entries = i; |
| 368 | |
| 369 | unlock: |
| 370 | rcu_read_unlock(); |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | static u32 cpu_freq_to_power(struct cpufreq_cooling_device *cpufreq_device, |
| 375 | u32 freq) |
| 376 | { |
| 377 | int i; |
| 378 | struct power_table *pt = cpufreq_device->dyn_power_table; |
| 379 | |
| 380 | for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) |
| 381 | if (freq < pt[i].frequency) |
| 382 | break; |
| 383 | |
| 384 | return pt[i - 1].power; |
| 385 | } |
| 386 | |
| 387 | static u32 cpu_power_to_freq(struct cpufreq_cooling_device *cpufreq_device, |
| 388 | u32 power) |
| 389 | { |
| 390 | int i; |
| 391 | struct power_table *pt = cpufreq_device->dyn_power_table; |
| 392 | |
| 393 | for (i = 1; i < cpufreq_device->dyn_power_table_entries; i++) |
| 394 | if (power < pt[i].power) |
| 395 | break; |
| 396 | |
| 397 | return pt[i - 1].frequency; |
| 398 | } |
| 399 | |
| 400 | /** |
| 401 | * get_load() - get load for a cpu since last updated |
| 402 | * @cpufreq_device: &struct cpufreq_cooling_device for this cpu |
| 403 | * @cpu: cpu number |
| 404 | * |
| 405 | * Return: The average load of cpu @cpu in percentage since this |
| 406 | * function was last called. |
| 407 | */ |
| 408 | static u32 get_load(struct cpufreq_cooling_device *cpufreq_device, int cpu) |
| 409 | { |
| 410 | u32 load; |
| 411 | u64 now, now_idle, delta_time, delta_idle; |
| 412 | |
| 413 | now_idle = get_cpu_idle_time(cpu, &now, 0); |
| 414 | delta_idle = now_idle - cpufreq_device->time_in_idle[cpu]; |
| 415 | delta_time = now - cpufreq_device->time_in_idle_timestamp[cpu]; |
| 416 | |
| 417 | if (delta_time <= delta_idle) |
| 418 | load = 0; |
| 419 | else |
| 420 | load = div64_u64(100 * (delta_time - delta_idle), delta_time); |
| 421 | |
| 422 | cpufreq_device->time_in_idle[cpu] = now_idle; |
| 423 | cpufreq_device->time_in_idle_timestamp[cpu] = now; |
| 424 | |
| 425 | return load; |
| 426 | } |
| 427 | |
| 428 | /** |
| 429 | * get_static_power() - calculate the static power consumed by the cpus |
| 430 | * @cpufreq_device: struct &cpufreq_cooling_device for this cpu cdev |
| 431 | * @tz: thermal zone device in which we're operating |
| 432 | * @freq: frequency in KHz |
| 433 | * @power: pointer in which to store the calculated static power |
| 434 | * |
| 435 | * Calculate the static power consumed by the cpus described by |
| 436 | * @cpu_actor running at frequency @freq. This function relies on a |
| 437 | * platform specific function that should have been provided when the |
| 438 | * actor was registered. If it wasn't, the static power is assumed to |
| 439 | * be negligible. The calculated static power is stored in @power. |
| 440 | * |
| 441 | * Return: 0 on success, -E* on failure. |
| 442 | */ |
| 443 | static int get_static_power(struct cpufreq_cooling_device *cpufreq_device, |
| 444 | struct thermal_zone_device *tz, unsigned long freq, |
| 445 | u32 *power) |
| 446 | { |
| 447 | struct dev_pm_opp *opp; |
| 448 | unsigned long voltage; |
| 449 | struct cpumask *cpumask = &cpufreq_device->allowed_cpus; |
| 450 | unsigned long freq_hz = freq * 1000; |
| 451 | |
| 452 | if (!cpufreq_device->plat_get_static_power || |
| 453 | !cpufreq_device->cpu_dev) { |
| 454 | *power = 0; |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | rcu_read_lock(); |
| 459 | |
| 460 | opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz, |
| 461 | true); |
| 462 | voltage = dev_pm_opp_get_voltage(opp); |
| 463 | |
| 464 | rcu_read_unlock(); |
| 465 | |
| 466 | if (voltage == 0) { |
| 467 | dev_warn_ratelimited(cpufreq_device->cpu_dev, |
| 468 | "Failed to get voltage for frequency %lu: %ld\n", |
| 469 | freq_hz, IS_ERR(opp) ? PTR_ERR(opp) : 0); |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | |
| 473 | return cpufreq_device->plat_get_static_power(cpumask, tz->passive_delay, |
| 474 | voltage, power); |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * get_dynamic_power() - calculate the dynamic power |
| 479 | * @cpufreq_device: &cpufreq_cooling_device for this cdev |
| 480 | * @freq: current frequency |
| 481 | * |
| 482 | * Return: the dynamic power consumed by the cpus described by |
| 483 | * @cpufreq_device. |
| 484 | */ |
| 485 | static u32 get_dynamic_power(struct cpufreq_cooling_device *cpufreq_device, |
| 486 | unsigned long freq) |
| 487 | { |
| 488 | u32 raw_cpu_power; |
| 489 | |
| 490 | raw_cpu_power = cpu_freq_to_power(cpufreq_device, freq); |
| 491 | return (raw_cpu_power * cpufreq_device->last_load) / 100; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 492 | } |
| 493 | |
Eduardo Valentin | 1b9e352 | 2013-04-17 17:12:02 +0000 | [diff] [blame] | 494 | /* cpufreq cooling device callback functions are defined below */ |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 495 | |
| 496 | /** |
| 497 | * cpufreq_get_max_state - callback function to get the max cooling state. |
| 498 | * @cdev: thermal cooling device pointer. |
| 499 | * @state: fill this variable with the max cooling state. |
Eduardo Valentin | 62c0042 | 2013-04-17 17:12:12 +0000 | [diff] [blame] | 500 | * |
| 501 | * Callback for the thermal cooling device to return the cpufreq |
| 502 | * max cooling state. |
| 503 | * |
| 504 | * Return: 0 on success, an error code otherwise. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 505 | */ |
| 506 | static int cpufreq_get_max_state(struct thermal_cooling_device *cdev, |
| 507 | unsigned long *state) |
| 508 | { |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 509 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 510 | |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 511 | *state = cpufreq_device->max_level; |
| 512 | return 0; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /** |
| 516 | * cpufreq_get_cur_state - callback function to get the current cooling state. |
| 517 | * @cdev: thermal cooling device pointer. |
| 518 | * @state: fill this variable with the current cooling state. |
Eduardo Valentin | 3672552 | 2013-04-17 17:12:13 +0000 | [diff] [blame] | 519 | * |
| 520 | * Callback for the thermal cooling device to return the cpufreq |
| 521 | * current cooling state. |
| 522 | * |
| 523 | * Return: 0 on success, an error code otherwise. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 524 | */ |
| 525 | static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev, |
| 526 | unsigned long *state) |
| 527 | { |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 528 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 529 | |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 530 | *state = cpufreq_device->cpufreq_state; |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 531 | |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 532 | return 0; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | /** |
| 536 | * cpufreq_set_cur_state - callback function to set the current cooling state. |
| 537 | * @cdev: thermal cooling device pointer. |
| 538 | * @state: set this variable to the current cooling state. |
Eduardo Valentin | 56e05fdb | 2013-04-17 17:12:14 +0000 | [diff] [blame] | 539 | * |
| 540 | * Callback for the thermal cooling device to change the cpufreq |
| 541 | * current cooling state. |
| 542 | * |
| 543 | * Return: 0 on success, an error code otherwise. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 544 | */ |
| 545 | static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, |
| 546 | unsigned long state) |
| 547 | { |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 548 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
Viresh Kumar | 5194fe4 | 2014-12-04 09:42:00 +0530 | [diff] [blame] | 549 | unsigned int cpu = cpumask_any(&cpufreq_device->allowed_cpus); |
| 550 | unsigned int clip_freq; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 551 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 552 | /* Request state should be less than max_level */ |
| 553 | if (WARN_ON(state > cpufreq_device->max_level)) |
| 554 | return -EINVAL; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 555 | |
Viresh Kumar | 5194fe4 | 2014-12-04 09:42:00 +0530 | [diff] [blame] | 556 | /* Check if the old cooling action is same as new cooling action */ |
| 557 | if (cpufreq_device->cpufreq_state == state) |
| 558 | return 0; |
| 559 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 560 | clip_freq = cpufreq_device->freq_table[state]; |
Viresh Kumar | 5194fe4 | 2014-12-04 09:42:00 +0530 | [diff] [blame] | 561 | cpufreq_device->cpufreq_state = state; |
| 562 | cpufreq_device->cpufreq_val = clip_freq; |
| 563 | |
| 564 | cpufreq_update_policy(cpu); |
| 565 | |
| 566 | return 0; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 567 | } |
| 568 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 569 | /** |
| 570 | * cpufreq_get_requested_power() - get the current power |
| 571 | * @cdev: &thermal_cooling_device pointer |
| 572 | * @tz: a valid thermal zone device pointer |
| 573 | * @power: pointer in which to store the resulting power |
| 574 | * |
| 575 | * Calculate the current power consumption of the cpus in milliwatts |
| 576 | * and store it in @power. This function should actually calculate |
| 577 | * the requested power, but it's hard to get the frequency that |
| 578 | * cpufreq would have assigned if there were no thermal limits. |
| 579 | * Instead, we calculate the current power on the assumption that the |
| 580 | * immediate future will look like the immediate past. |
| 581 | * |
| 582 | * We use the current frequency and the average load since this |
| 583 | * function was last called. In reality, there could have been |
| 584 | * multiple opps since this function was last called and that affects |
| 585 | * the load calculation. While it's not perfectly accurate, this |
| 586 | * simplification is good enough and works. REVISIT this, as more |
| 587 | * complex code may be needed if experiments show that it's not |
| 588 | * accurate enough. |
| 589 | * |
| 590 | * Return: 0 on success, -E* if getting the static power failed. |
| 591 | */ |
| 592 | static int cpufreq_get_requested_power(struct thermal_cooling_device *cdev, |
| 593 | struct thermal_zone_device *tz, |
| 594 | u32 *power) |
| 595 | { |
| 596 | unsigned long freq; |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 597 | int i = 0, cpu, ret; |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 598 | u32 static_power, dynamic_power, total_load = 0; |
| 599 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 600 | u32 *load_cpu = NULL; |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 601 | |
| 602 | freq = cpufreq_quick_get(cpumask_any(&cpufreq_device->allowed_cpus)); |
| 603 | |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 604 | if (trace_thermal_power_cpu_get_power_enabled()) { |
| 605 | u32 ncpus = cpumask_weight(&cpufreq_device->allowed_cpus); |
| 606 | |
| 607 | load_cpu = devm_kcalloc(&cdev->device, ncpus, sizeof(*load_cpu), |
| 608 | GFP_KERNEL); |
| 609 | } |
| 610 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 611 | for_each_cpu(cpu, &cpufreq_device->allowed_cpus) { |
| 612 | u32 load; |
| 613 | |
| 614 | if (cpu_online(cpu)) |
| 615 | load = get_load(cpufreq_device, cpu); |
| 616 | else |
| 617 | load = 0; |
| 618 | |
| 619 | total_load += load; |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 620 | if (trace_thermal_power_cpu_limit_enabled() && load_cpu) |
| 621 | load_cpu[i] = load; |
| 622 | |
| 623 | i++; |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | cpufreq_device->last_load = total_load; |
| 627 | |
| 628 | dynamic_power = get_dynamic_power(cpufreq_device, freq); |
| 629 | ret = get_static_power(cpufreq_device, tz, freq, &static_power); |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 630 | if (ret) { |
| 631 | if (load_cpu) |
| 632 | devm_kfree(&cdev->device, load_cpu); |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 633 | return ret; |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | if (load_cpu) { |
| 637 | trace_thermal_power_cpu_get_power( |
| 638 | &cpufreq_device->allowed_cpus, |
| 639 | freq, load_cpu, i, dynamic_power, static_power); |
| 640 | |
| 641 | devm_kfree(&cdev->device, load_cpu); |
| 642 | } |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 643 | |
| 644 | *power = static_power + dynamic_power; |
| 645 | return 0; |
| 646 | } |
| 647 | |
| 648 | /** |
| 649 | * cpufreq_state2power() - convert a cpu cdev state to power consumed |
| 650 | * @cdev: &thermal_cooling_device pointer |
| 651 | * @tz: a valid thermal zone device pointer |
| 652 | * @state: cooling device state to be converted |
| 653 | * @power: pointer in which to store the resulting power |
| 654 | * |
| 655 | * Convert cooling device state @state into power consumption in |
| 656 | * milliwatts assuming 100% load. Store the calculated power in |
| 657 | * @power. |
| 658 | * |
| 659 | * Return: 0 on success, -EINVAL if the cooling device state could not |
| 660 | * be converted into a frequency or other -E* if there was an error |
| 661 | * when calculating the static power. |
| 662 | */ |
| 663 | static int cpufreq_state2power(struct thermal_cooling_device *cdev, |
| 664 | struct thermal_zone_device *tz, |
| 665 | unsigned long state, u32 *power) |
| 666 | { |
| 667 | unsigned int freq, num_cpus; |
| 668 | cpumask_t cpumask; |
| 669 | u32 static_power, dynamic_power; |
| 670 | int ret; |
| 671 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
| 672 | |
| 673 | cpumask_and(&cpumask, &cpufreq_device->allowed_cpus, cpu_online_mask); |
| 674 | num_cpus = cpumask_weight(&cpumask); |
| 675 | |
| 676 | /* None of our cpus are online, so no power */ |
| 677 | if (num_cpus == 0) { |
| 678 | *power = 0; |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | freq = cpufreq_device->freq_table[state]; |
| 683 | if (!freq) |
| 684 | return -EINVAL; |
| 685 | |
| 686 | dynamic_power = cpu_freq_to_power(cpufreq_device, freq) * num_cpus; |
| 687 | ret = get_static_power(cpufreq_device, tz, freq, &static_power); |
| 688 | if (ret) |
| 689 | return ret; |
| 690 | |
| 691 | *power = static_power + dynamic_power; |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * cpufreq_power2state() - convert power to a cooling device state |
| 697 | * @cdev: &thermal_cooling_device pointer |
| 698 | * @tz: a valid thermal zone device pointer |
| 699 | * @power: power in milliwatts to be converted |
| 700 | * @state: pointer in which to store the resulting state |
| 701 | * |
| 702 | * Calculate a cooling device state for the cpus described by @cdev |
| 703 | * that would allow them to consume at most @power mW and store it in |
| 704 | * @state. Note that this calculation depends on external factors |
| 705 | * such as the cpu load or the current static power. Calling this |
| 706 | * function with the same power as input can yield different cooling |
| 707 | * device states depending on those external factors. |
| 708 | * |
| 709 | * Return: 0 on success, -ENODEV if no cpus are online or -EINVAL if |
| 710 | * the calculated frequency could not be converted to a valid state. |
| 711 | * The latter should not happen unless the frequencies available to |
| 712 | * cpufreq have changed since the initialization of the cpu cooling |
| 713 | * device. |
| 714 | */ |
| 715 | static int cpufreq_power2state(struct thermal_cooling_device *cdev, |
| 716 | struct thermal_zone_device *tz, u32 power, |
| 717 | unsigned long *state) |
| 718 | { |
| 719 | unsigned int cpu, cur_freq, target_freq; |
| 720 | int ret; |
| 721 | s32 dyn_power; |
| 722 | u32 last_load, normalised_power, static_power; |
| 723 | struct cpufreq_cooling_device *cpufreq_device = cdev->devdata; |
| 724 | |
| 725 | cpu = cpumask_any_and(&cpufreq_device->allowed_cpus, cpu_online_mask); |
| 726 | |
| 727 | /* None of our cpus are online */ |
| 728 | if (cpu >= nr_cpu_ids) |
| 729 | return -ENODEV; |
| 730 | |
| 731 | cur_freq = cpufreq_quick_get(cpu); |
| 732 | ret = get_static_power(cpufreq_device, tz, cur_freq, &static_power); |
| 733 | if (ret) |
| 734 | return ret; |
| 735 | |
| 736 | dyn_power = power - static_power; |
| 737 | dyn_power = dyn_power > 0 ? dyn_power : 0; |
| 738 | last_load = cpufreq_device->last_load ?: 1; |
| 739 | normalised_power = (dyn_power * 100) / last_load; |
| 740 | target_freq = cpu_power_to_freq(cpufreq_device, normalised_power); |
| 741 | |
| 742 | *state = cpufreq_cooling_get_level(cpu, target_freq); |
| 743 | if (*state == THERMAL_CSTATE_INVALID) { |
| 744 | dev_warn_ratelimited(&cdev->device, |
| 745 | "Failed to convert %dKHz for cpu %d into a cdev state\n", |
| 746 | target_freq, cpu); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
Javi Merino | 6828a47 | 2015-03-02 17:17:20 +0000 | [diff] [blame] | 750 | trace_thermal_power_cpu_limit(&cpufreq_device->allowed_cpus, |
| 751 | target_freq, *state, power); |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 752 | return 0; |
| 753 | } |
| 754 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 755 | /* Bind cpufreq callbacks to thermal cooling device ops */ |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 756 | static struct thermal_cooling_device_ops cpufreq_cooling_ops = { |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 757 | .get_max_state = cpufreq_get_max_state, |
| 758 | .get_cur_state = cpufreq_get_cur_state, |
| 759 | .set_cur_state = cpufreq_set_cur_state, |
| 760 | }; |
| 761 | |
| 762 | /* Notifier for cpufreq policy change */ |
| 763 | static struct notifier_block thermal_cpufreq_notifier_block = { |
| 764 | .notifier_call = cpufreq_thermal_notifier, |
| 765 | }; |
| 766 | |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 767 | static unsigned int find_next_max(struct cpufreq_frequency_table *table, |
| 768 | unsigned int prev_max) |
| 769 | { |
| 770 | struct cpufreq_frequency_table *pos; |
| 771 | unsigned int max = 0; |
| 772 | |
| 773 | cpufreq_for_each_valid_entry(pos, table) { |
| 774 | if (pos->frequency > max && pos->frequency < prev_max) |
| 775 | max = pos->frequency; |
| 776 | } |
| 777 | |
| 778 | return max; |
| 779 | } |
| 780 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 781 | /** |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 782 | * __cpufreq_cooling_register - helper function to create cpufreq cooling device |
| 783 | * @np: a valid struct device_node to the cooling device device tree node |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 784 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. |
Viresh Kumar | 405fb82 | 2014-12-04 09:41:55 +0530 | [diff] [blame] | 785 | * Normally this should be same as cpufreq policy->related_cpus. |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 786 | * @capacitance: dynamic power coefficient for these cpus |
| 787 | * @plat_static_func: function to calculate the static power consumed by these |
| 788 | * cpus (optional) |
Eduardo Valentin | 12cb08b | 2013-04-17 17:12:15 +0000 | [diff] [blame] | 789 | * |
| 790 | * This interface function registers the cpufreq cooling device with the name |
| 791 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 792 | * cooling devices. It also gives the opportunity to link the cooling device |
| 793 | * with a device tree node, in order to bind it via the thermal DT code. |
Eduardo Valentin | 12cb08b | 2013-04-17 17:12:15 +0000 | [diff] [blame] | 794 | * |
| 795 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 796 | * on failure, it returns a corresponding ERR_PTR(). |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 797 | */ |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 798 | static struct thermal_cooling_device * |
| 799 | __cpufreq_cooling_register(struct device_node *np, |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 800 | const struct cpumask *clip_cpus, u32 capacitance, |
| 801 | get_static_t plat_static_func) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 802 | { |
| 803 | struct thermal_cooling_device *cool_dev; |
Viresh Kumar | 5d3bdb8 | 2014-12-04 09:41:52 +0530 | [diff] [blame] | 804 | struct cpufreq_cooling_device *cpufreq_dev; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 805 | char dev_name[THERMAL_NAME_LENGTH]; |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 806 | struct cpufreq_frequency_table *pos, *table; |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 807 | unsigned int freq, i, num_cpus; |
Viresh Kumar | 405fb82 | 2014-12-04 09:41:55 +0530 | [diff] [blame] | 808 | int ret; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 809 | |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 810 | table = cpufreq_frequency_get_table(cpumask_first(clip_cpus)); |
| 811 | if (!table) { |
Eduardo Valentin | 0f1be51 | 2014-12-04 09:41:43 +0530 | [diff] [blame] | 812 | pr_debug("%s: CPUFreq table not found\n", __func__); |
| 813 | return ERR_PTR(-EPROBE_DEFER); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 814 | } |
Eduardo Valentin | 0f1be51 | 2014-12-04 09:41:43 +0530 | [diff] [blame] | 815 | |
Viresh Kumar | 98d522f | 2014-12-04 09:41:50 +0530 | [diff] [blame] | 816 | cpufreq_dev = kzalloc(sizeof(*cpufreq_dev), GFP_KERNEL); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 817 | if (!cpufreq_dev) |
| 818 | return ERR_PTR(-ENOMEM); |
| 819 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 820 | num_cpus = cpumask_weight(clip_cpus); |
| 821 | cpufreq_dev->time_in_idle = kcalloc(num_cpus, |
| 822 | sizeof(*cpufreq_dev->time_in_idle), |
| 823 | GFP_KERNEL); |
| 824 | if (!cpufreq_dev->time_in_idle) { |
| 825 | cool_dev = ERR_PTR(-ENOMEM); |
| 826 | goto free_cdev; |
| 827 | } |
| 828 | |
| 829 | cpufreq_dev->time_in_idle_timestamp = |
| 830 | kcalloc(num_cpus, sizeof(*cpufreq_dev->time_in_idle_timestamp), |
| 831 | GFP_KERNEL); |
| 832 | if (!cpufreq_dev->time_in_idle_timestamp) { |
| 833 | cool_dev = ERR_PTR(-ENOMEM); |
| 834 | goto free_time_in_idle; |
| 835 | } |
| 836 | |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 837 | /* Find max levels */ |
| 838 | cpufreq_for_each_valid_entry(pos, table) |
| 839 | cpufreq_dev->max_level++; |
| 840 | |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 841 | cpufreq_dev->freq_table = kmalloc(sizeof(*cpufreq_dev->freq_table) * |
| 842 | cpufreq_dev->max_level, GFP_KERNEL); |
| 843 | if (!cpufreq_dev->freq_table) { |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 844 | cool_dev = ERR_PTR(-ENOMEM); |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 845 | goto free_time_in_idle_timestamp; |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 846 | } |
| 847 | |
Viresh Kumar | dcc6c7f | 2014-12-04 09:42:02 +0530 | [diff] [blame] | 848 | /* max_level is an index, not a counter */ |
| 849 | cpufreq_dev->max_level--; |
| 850 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 851 | cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); |
| 852 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 853 | if (capacitance) { |
| 854 | cpufreq_cooling_ops.get_requested_power = |
| 855 | cpufreq_get_requested_power; |
| 856 | cpufreq_cooling_ops.state2power = cpufreq_state2power; |
| 857 | cpufreq_cooling_ops.power2state = cpufreq_power2state; |
| 858 | cpufreq_dev->plat_get_static_power = plat_static_func; |
| 859 | |
| 860 | ret = build_dyn_power_table(cpufreq_dev, capacitance); |
| 861 | if (ret) { |
| 862 | cool_dev = ERR_PTR(ret); |
| 863 | goto free_table; |
| 864 | } |
| 865 | } |
| 866 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 867 | ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); |
| 868 | if (ret) { |
Viresh Kumar | 730abe0 | 2014-12-04 09:41:58 +0530 | [diff] [blame] | 869 | cool_dev = ERR_PTR(ret); |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 870 | goto free_table; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 871 | } |
| 872 | |
Eduardo Valentin | 99871a7 | 2013-04-17 17:12:17 +0000 | [diff] [blame] | 873 | snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d", |
| 874 | cpufreq_dev->id); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 875 | |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 876 | cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, |
| 877 | &cpufreq_cooling_ops); |
Viresh Kumar | 730abe0 | 2014-12-04 09:41:58 +0530 | [diff] [blame] | 878 | if (IS_ERR(cool_dev)) |
| 879 | goto remove_idr; |
| 880 | |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 881 | /* Fill freq-table in descending order of frequencies */ |
| 882 | for (i = 0, freq = -1; i <= cpufreq_dev->max_level; i++) { |
| 883 | freq = find_next_max(table, freq); |
| 884 | cpufreq_dev->freq_table[i] = freq; |
| 885 | |
| 886 | /* Warn for duplicate entries */ |
| 887 | if (!freq) |
| 888 | pr_warn("%s: table has duplicate entries\n", __func__); |
| 889 | else |
| 890 | pr_debug("%s: freq:%u KHz\n", __func__, freq); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 891 | } |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 892 | |
Viresh Kumar | 4843c4a | 2014-12-04 09:42:07 +0530 | [diff] [blame] | 893 | cpufreq_dev->cpufreq_val = cpufreq_dev->freq_table[0]; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 894 | cpufreq_dev->cool_dev = cool_dev; |
Viresh Kumar | 92e615e | 2014-12-04 09:41:51 +0530 | [diff] [blame] | 895 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 896 | mutex_lock(&cooling_cpufreq_lock); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 897 | |
| 898 | /* Register the notifier for first cpufreq cooling device */ |
Viresh Kumar | 2479bb6 | 2014-12-04 09:42:04 +0530 | [diff] [blame] | 899 | if (list_empty(&cpufreq_dev_list)) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 900 | cpufreq_register_notifier(&thermal_cpufreq_notifier_block, |
Eduardo Valentin | 5fda7f6 | 2013-04-17 17:12:11 +0000 | [diff] [blame] | 901 | CPUFREQ_POLICY_NOTIFIER); |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 902 | list_add(&cpufreq_dev->node, &cpufreq_dev_list); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 903 | |
| 904 | mutex_unlock(&cooling_cpufreq_lock); |
Eduardo Valentin | 79491e5 | 2013-04-17 17:11:59 +0000 | [diff] [blame] | 905 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 906 | return cool_dev; |
Viresh Kumar | 730abe0 | 2014-12-04 09:41:58 +0530 | [diff] [blame] | 907 | |
| 908 | remove_idr: |
| 909 | release_idr(&cpufreq_idr, cpufreq_dev->id); |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 910 | free_table: |
| 911 | kfree(cpufreq_dev->freq_table); |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 912 | free_time_in_idle_timestamp: |
| 913 | kfree(cpufreq_dev->time_in_idle_timestamp); |
| 914 | free_time_in_idle: |
| 915 | kfree(cpufreq_dev->time_in_idle); |
Viresh Kumar | 730abe0 | 2014-12-04 09:41:58 +0530 | [diff] [blame] | 916 | free_cdev: |
| 917 | kfree(cpufreq_dev); |
| 918 | |
| 919 | return cool_dev; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 920 | } |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 921 | |
| 922 | /** |
| 923 | * cpufreq_cooling_register - function to create cpufreq cooling device. |
| 924 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. |
| 925 | * |
| 926 | * This interface function registers the cpufreq cooling device with the name |
| 927 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq |
| 928 | * cooling devices. |
| 929 | * |
| 930 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 931 | * on failure, it returns a corresponding ERR_PTR(). |
| 932 | */ |
| 933 | struct thermal_cooling_device * |
| 934 | cpufreq_cooling_register(const struct cpumask *clip_cpus) |
| 935 | { |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 936 | return __cpufreq_cooling_register(NULL, clip_cpus, 0, NULL); |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 937 | } |
Eduardo Valentin | 243dbd9 | 2013-04-17 17:11:57 +0000 | [diff] [blame] | 938 | EXPORT_SYMBOL_GPL(cpufreq_cooling_register); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 939 | |
| 940 | /** |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 941 | * of_cpufreq_cooling_register - function to create cpufreq cooling device. |
| 942 | * @np: a valid struct device_node to the cooling device device tree node |
| 943 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen. |
| 944 | * |
| 945 | * This interface function registers the cpufreq cooling device with the name |
| 946 | * "thermal-cpufreq-%x". This api can support multiple instances of cpufreq |
| 947 | * cooling devices. Using this API, the cpufreq cooling device will be |
| 948 | * linked to the device tree node provided. |
| 949 | * |
| 950 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 951 | * on failure, it returns a corresponding ERR_PTR(). |
| 952 | */ |
| 953 | struct thermal_cooling_device * |
| 954 | of_cpufreq_cooling_register(struct device_node *np, |
| 955 | const struct cpumask *clip_cpus) |
| 956 | { |
| 957 | if (!np) |
| 958 | return ERR_PTR(-EINVAL); |
| 959 | |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 960 | return __cpufreq_cooling_register(np, clip_cpus, 0, NULL); |
Eduardo Valentin | 39d99cf | 2013-09-12 19:26:45 -0400 | [diff] [blame] | 961 | } |
| 962 | EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register); |
| 963 | |
| 964 | /** |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 965 | * cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions |
| 966 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen |
| 967 | * @capacitance: dynamic power coefficient for these cpus |
| 968 | * @plat_static_func: function to calculate the static power consumed by these |
| 969 | * cpus (optional) |
| 970 | * |
| 971 | * This interface function registers the cpufreq cooling device with |
| 972 | * the name "thermal-cpufreq-%x". This api can support multiple |
| 973 | * instances of cpufreq cooling devices. Using this function, the |
| 974 | * cooling device will implement the power extensions by using a |
| 975 | * simple cpu power model. The cpus must have registered their OPPs |
| 976 | * using the OPP library. |
| 977 | * |
| 978 | * An optional @plat_static_func may be provided to calculate the |
| 979 | * static power consumed by these cpus. If the platform's static |
| 980 | * power consumption is unknown or negligible, make it NULL. |
| 981 | * |
| 982 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 983 | * on failure, it returns a corresponding ERR_PTR(). |
| 984 | */ |
| 985 | struct thermal_cooling_device * |
| 986 | cpufreq_power_cooling_register(const struct cpumask *clip_cpus, u32 capacitance, |
| 987 | get_static_t plat_static_func) |
| 988 | { |
| 989 | return __cpufreq_cooling_register(NULL, clip_cpus, capacitance, |
| 990 | plat_static_func); |
| 991 | } |
| 992 | EXPORT_SYMBOL(cpufreq_power_cooling_register); |
| 993 | |
| 994 | /** |
| 995 | * of_cpufreq_power_cooling_register() - create cpufreq cooling device with power extensions |
| 996 | * @np: a valid struct device_node to the cooling device device tree node |
| 997 | * @clip_cpus: cpumask of cpus where the frequency constraints will happen |
| 998 | * @capacitance: dynamic power coefficient for these cpus |
| 999 | * @plat_static_func: function to calculate the static power consumed by these |
| 1000 | * cpus (optional) |
| 1001 | * |
| 1002 | * This interface function registers the cpufreq cooling device with |
| 1003 | * the name "thermal-cpufreq-%x". This api can support multiple |
| 1004 | * instances of cpufreq cooling devices. Using this API, the cpufreq |
| 1005 | * cooling device will be linked to the device tree node provided. |
| 1006 | * Using this function, the cooling device will implement the power |
| 1007 | * extensions by using a simple cpu power model. The cpus must have |
| 1008 | * registered their OPPs using the OPP library. |
| 1009 | * |
| 1010 | * An optional @plat_static_func may be provided to calculate the |
| 1011 | * static power consumed by these cpus. If the platform's static |
| 1012 | * power consumption is unknown or negligible, make it NULL. |
| 1013 | * |
| 1014 | * Return: a valid struct thermal_cooling_device pointer on success, |
| 1015 | * on failure, it returns a corresponding ERR_PTR(). |
| 1016 | */ |
| 1017 | struct thermal_cooling_device * |
| 1018 | of_cpufreq_power_cooling_register(struct device_node *np, |
| 1019 | const struct cpumask *clip_cpus, |
| 1020 | u32 capacitance, |
| 1021 | get_static_t plat_static_func) |
| 1022 | { |
| 1023 | if (!np) |
| 1024 | return ERR_PTR(-EINVAL); |
| 1025 | |
| 1026 | return __cpufreq_cooling_register(np, clip_cpus, capacitance, |
| 1027 | plat_static_func); |
| 1028 | } |
| 1029 | EXPORT_SYMBOL(of_cpufreq_power_cooling_register); |
| 1030 | |
| 1031 | /** |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1032 | * cpufreq_cooling_unregister - function to remove cpufreq cooling device. |
| 1033 | * @cdev: thermal cooling device pointer. |
Eduardo Valentin | 135266b | 2013-04-17 17:12:16 +0000 | [diff] [blame] | 1034 | * |
| 1035 | * This interface function unregisters the "thermal-cpufreq-%x" cooling device. |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1036 | */ |
| 1037 | void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev) |
| 1038 | { |
Eduardo Valentin | 50e66c7 | 2013-08-15 10:54:46 -0400 | [diff] [blame] | 1039 | struct cpufreq_cooling_device *cpufreq_dev; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1040 | |
Eduardo Valentin | 50e66c7 | 2013-08-15 10:54:46 -0400 | [diff] [blame] | 1041 | if (!cdev) |
| 1042 | return; |
| 1043 | |
| 1044 | cpufreq_dev = cdev->devdata; |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1045 | mutex_lock(&cooling_cpufreq_lock); |
Yadwinder Singh Brar | 2dcd851 | 2014-11-07 19:12:29 +0530 | [diff] [blame] | 1046 | list_del(&cpufreq_dev->node); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1047 | |
| 1048 | /* Unregister the notifier for the last cpufreq cooling device */ |
Viresh Kumar | 2479bb6 | 2014-12-04 09:42:04 +0530 | [diff] [blame] | 1049 | if (list_empty(&cpufreq_dev_list)) |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1050 | cpufreq_unregister_notifier(&thermal_cpufreq_notifier_block, |
Eduardo Valentin | 5fda7f6 | 2013-04-17 17:12:11 +0000 | [diff] [blame] | 1051 | CPUFREQ_POLICY_NOTIFIER); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1052 | mutex_unlock(&cooling_cpufreq_lock); |
hongbo.zhang | 160b7d8 | 2012-10-30 17:48:59 +0100 | [diff] [blame] | 1053 | |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1054 | thermal_cooling_device_unregister(cpufreq_dev->cool_dev); |
| 1055 | release_idr(&cpufreq_idr, cpufreq_dev->id); |
Javi Merino | c36cf07 | 2015-02-26 19:00:29 +0000 | [diff] [blame] | 1056 | kfree(cpufreq_dev->time_in_idle_timestamp); |
| 1057 | kfree(cpufreq_dev->time_in_idle); |
Viresh Kumar | f685901 | 2014-12-04 09:42:06 +0530 | [diff] [blame] | 1058 | kfree(cpufreq_dev->freq_table); |
Amit Daniel Kachhap | 0236141 | 2012-08-16 17:11:40 +0530 | [diff] [blame] | 1059 | kfree(cpufreq_dev); |
| 1060 | } |
Eduardo Valentin | 243dbd9 | 2013-04-17 17:11:57 +0000 | [diff] [blame] | 1061 | EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister); |