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