Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1 | /* |
| 2 | * thermal.c - Generic Thermal Management Sysfs support. |
| 3 | * |
| 4 | * Copyright (C) 2008 Intel Corp |
| 5 | * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com> |
| 6 | * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com> |
| 7 | * |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 11 | */ |
| 12 | |
Joe Perches | c5a01dd | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 14 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 19 | #include <linux/kdev_t.h> |
| 20 | #include <linux/idr.h> |
| 21 | #include <linux/thermal.h> |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 22 | #include <linux/reboot.h> |
Andy Shevchenko | 42a5bf5 | 2013-05-17 11:52:02 +0000 | [diff] [blame] | 23 | #include <linux/string.h> |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 24 | #include <linux/of.h> |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 25 | #include <net/netlink.h> |
| 26 | #include <net/genetlink.h> |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 27 | #include <linux/suspend.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 28 | |
Punit Agrawal | 100a8fd | 2014-07-29 11:50:48 +0100 | [diff] [blame] | 29 | #define CREATE_TRACE_POINTS |
| 30 | #include <trace/events/thermal.h> |
| 31 | |
Durgadoss R | 71350db | 2012-09-18 11:04:53 +0530 | [diff] [blame] | 32 | #include "thermal_core.h" |
Eduardo Valentin | 0dd8879 | 2013-07-03 15:14:28 -0400 | [diff] [blame] | 33 | #include "thermal_hwmon.h" |
Durgadoss R | 71350db | 2012-09-18 11:04:53 +0530 | [diff] [blame] | 34 | |
Zhang Rui | 63c4ec9 | 2008-04-21 16:07:13 +0800 | [diff] [blame] | 35 | MODULE_AUTHOR("Zhang Rui"); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 36 | MODULE_DESCRIPTION("Generic thermal management sysfs support"); |
Eduardo Valentin | 6d8d497 | 2013-04-23 21:48:13 +0000 | [diff] [blame] | 37 | MODULE_LICENSE("GPL v2"); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 38 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 39 | static DEFINE_IDA(thermal_tz_ida); |
| 40 | static DEFINE_IDA(thermal_cdev_ida); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 41 | |
| 42 | static LIST_HEAD(thermal_tz_list); |
| 43 | static LIST_HEAD(thermal_cdev_list); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 44 | static LIST_HEAD(thermal_governor_list); |
| 45 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 46 | static DEFINE_MUTEX(thermal_list_lock); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 47 | static DEFINE_MUTEX(thermal_governor_lock); |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 48 | static DEFINE_MUTEX(poweroff_lock); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 49 | |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 50 | static atomic_t in_suspend; |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 51 | static bool power_off_triggered; |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 52 | |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 53 | static struct thermal_governor *def_governor; |
| 54 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 55 | /* |
| 56 | * Governor section: set of functions to handle thermal governors |
| 57 | * |
| 58 | * Functions to help in the life cycle of thermal governors within |
| 59 | * the thermal core and by the thermal governor code. |
| 60 | */ |
| 61 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 62 | static struct thermal_governor *__find_governor(const char *name) |
| 63 | { |
| 64 | struct thermal_governor *pos; |
| 65 | |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 66 | if (!name || !name[0]) |
| 67 | return def_governor; |
| 68 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 69 | list_for_each_entry(pos, &thermal_governor_list, governor_list) |
Rasmus Villemoes | 484ac2f | 2014-10-13 15:55:01 -0700 | [diff] [blame] | 70 | if (!strncasecmp(name, pos->name, THERMAL_NAME_LENGTH)) |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 71 | return pos; |
| 72 | |
| 73 | return NULL; |
| 74 | } |
| 75 | |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 76 | /** |
| 77 | * bind_previous_governor() - bind the previous governor of the thermal zone |
| 78 | * @tz: a valid pointer to a struct thermal_zone_device |
| 79 | * @failed_gov_name: the name of the governor that failed to register |
| 80 | * |
| 81 | * Register the previous governor of the thermal zone after a new |
| 82 | * governor has failed to be bound. |
| 83 | */ |
| 84 | static void bind_previous_governor(struct thermal_zone_device *tz, |
| 85 | const char *failed_gov_name) |
| 86 | { |
| 87 | if (tz->governor && tz->governor->bind_to_tz) { |
| 88 | if (tz->governor->bind_to_tz(tz)) { |
| 89 | dev_err(&tz->device, |
| 90 | "governor %s failed to bind and the previous one (%s) failed to bind again, thermal zone %s has no governor\n", |
| 91 | failed_gov_name, tz->governor->name, tz->type); |
| 92 | tz->governor = NULL; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * thermal_set_governor() - Switch to another governor |
| 99 | * @tz: a valid pointer to a struct thermal_zone_device |
| 100 | * @new_gov: pointer to the new governor |
| 101 | * |
| 102 | * Change the governor of thermal zone @tz. |
| 103 | * |
| 104 | * Return: 0 on success, an error if the new governor's bind_to_tz() failed. |
| 105 | */ |
| 106 | static int thermal_set_governor(struct thermal_zone_device *tz, |
| 107 | struct thermal_governor *new_gov) |
| 108 | { |
| 109 | int ret = 0; |
| 110 | |
| 111 | if (tz->governor && tz->governor->unbind_from_tz) |
| 112 | tz->governor->unbind_from_tz(tz); |
| 113 | |
| 114 | if (new_gov && new_gov->bind_to_tz) { |
| 115 | ret = new_gov->bind_to_tz(tz); |
| 116 | if (ret) { |
| 117 | bind_previous_governor(tz, new_gov->name); |
| 118 | |
| 119 | return ret; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | tz->governor = new_gov; |
| 124 | |
| 125 | return ret; |
| 126 | } |
| 127 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 128 | int thermal_register_governor(struct thermal_governor *governor) |
| 129 | { |
| 130 | int err; |
| 131 | const char *name; |
| 132 | struct thermal_zone_device *pos; |
| 133 | |
| 134 | if (!governor) |
| 135 | return -EINVAL; |
| 136 | |
| 137 | mutex_lock(&thermal_governor_lock); |
| 138 | |
| 139 | err = -EBUSY; |
Eduardo Valentin | 5027ba3 | 2016-11-07 21:09:20 -0800 | [diff] [blame] | 140 | if (!__find_governor(governor->name)) { |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 141 | bool match_default; |
| 142 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 143 | err = 0; |
| 144 | list_add(&governor->governor_list, &thermal_governor_list); |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 145 | match_default = !strncmp(governor->name, |
| 146 | DEFAULT_THERMAL_GOVERNOR, |
| 147 | THERMAL_NAME_LENGTH); |
| 148 | |
| 149 | if (!def_governor && match_default) |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 150 | def_governor = governor; |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | mutex_lock(&thermal_list_lock); |
| 154 | |
| 155 | list_for_each_entry(pos, &thermal_tz_list, node) { |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 156 | /* |
| 157 | * only thermal zones with specified tz->tzp->governor_name |
| 158 | * may run with tz->govenor unset |
| 159 | */ |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 160 | if (pos->governor) |
| 161 | continue; |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 162 | |
| 163 | name = pos->tzp->governor_name; |
| 164 | |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 165 | if (!strncasecmp(name, governor->name, THERMAL_NAME_LENGTH)) { |
| 166 | int ret; |
| 167 | |
| 168 | ret = thermal_set_governor(pos, governor); |
| 169 | if (ret) |
| 170 | dev_err(&pos->device, |
| 171 | "Failed to set governor %s for thermal zone %s: %d\n", |
| 172 | governor->name, pos->type, ret); |
| 173 | } |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | mutex_unlock(&thermal_list_lock); |
| 177 | mutex_unlock(&thermal_governor_lock); |
| 178 | |
| 179 | return err; |
| 180 | } |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 181 | |
| 182 | void thermal_unregister_governor(struct thermal_governor *governor) |
| 183 | { |
| 184 | struct thermal_zone_device *pos; |
| 185 | |
| 186 | if (!governor) |
| 187 | return; |
| 188 | |
| 189 | mutex_lock(&thermal_governor_lock); |
| 190 | |
Eduardo Valentin | 5027ba3 | 2016-11-07 21:09:20 -0800 | [diff] [blame] | 191 | if (!__find_governor(governor->name)) |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 192 | goto exit; |
| 193 | |
| 194 | mutex_lock(&thermal_list_lock); |
| 195 | |
| 196 | list_for_each_entry(pos, &thermal_tz_list, node) { |
Rasmus Villemoes | 484ac2f | 2014-10-13 15:55:01 -0700 | [diff] [blame] | 197 | if (!strncasecmp(pos->governor->name, governor->name, |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 198 | THERMAL_NAME_LENGTH)) |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 199 | thermal_set_governor(pos, NULL); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | mutex_unlock(&thermal_list_lock); |
| 203 | list_del(&governor->governor_list); |
| 204 | exit: |
| 205 | mutex_unlock(&thermal_governor_lock); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 206 | } |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 207 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 208 | int thermal_zone_device_set_policy(struct thermal_zone_device *tz, |
| 209 | char *policy) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 210 | { |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 211 | struct thermal_governor *gov; |
| 212 | int ret = -EINVAL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 213 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 214 | mutex_lock(&thermal_governor_lock); |
Durgadoss R | 9b4298a | 2012-09-18 11:04:54 +0530 | [diff] [blame] | 215 | mutex_lock(&tz->lock); |
Durgadoss R | 9b4298a | 2012-09-18 11:04:54 +0530 | [diff] [blame] | 216 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 217 | gov = __find_governor(strim(policy)); |
| 218 | if (!gov) |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 219 | goto exit; |
| 220 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 221 | ret = thermal_set_governor(tz, gov); |
| 222 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 223 | exit: |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 224 | mutex_unlock(&tz->lock); |
| 225 | mutex_unlock(&thermal_governor_lock); |
| 226 | |
| 227 | return ret; |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 228 | } |
| 229 | |
Eduardo Valentin | 1b4f484 | 2016-11-07 21:09:05 -0800 | [diff] [blame] | 230 | int thermal_build_list_of_policies(char *buf) |
| 231 | { |
| 232 | struct thermal_governor *pos; |
| 233 | ssize_t count = 0; |
| 234 | ssize_t size = PAGE_SIZE; |
| 235 | |
| 236 | mutex_lock(&thermal_governor_lock); |
| 237 | |
| 238 | list_for_each_entry(pos, &thermal_governor_list, governor_list) { |
| 239 | size = PAGE_SIZE - count; |
| 240 | count += scnprintf(buf + count, size, "%s ", pos->name); |
| 241 | } |
| 242 | count += scnprintf(buf + count, size, "\n"); |
| 243 | |
| 244 | mutex_unlock(&thermal_governor_lock); |
| 245 | |
| 246 | return count; |
| 247 | } |
| 248 | |
| 249 | static int __init thermal_register_governors(void) |
| 250 | { |
| 251 | int result; |
| 252 | |
| 253 | result = thermal_gov_step_wise_register(); |
| 254 | if (result) |
| 255 | return result; |
| 256 | |
| 257 | result = thermal_gov_fair_share_register(); |
| 258 | if (result) |
| 259 | return result; |
| 260 | |
| 261 | result = thermal_gov_bang_bang_register(); |
| 262 | if (result) |
| 263 | return result; |
| 264 | |
| 265 | result = thermal_gov_user_space_register(); |
| 266 | if (result) |
| 267 | return result; |
| 268 | |
| 269 | return thermal_gov_power_allocator_register(); |
| 270 | } |
| 271 | |
| 272 | static void thermal_unregister_governors(void) |
| 273 | { |
| 274 | thermal_gov_step_wise_unregister(); |
| 275 | thermal_gov_fair_share_unregister(); |
| 276 | thermal_gov_bang_bang_unregister(); |
| 277 | thermal_gov_user_space_unregister(); |
| 278 | thermal_gov_power_allocator_unregister(); |
| 279 | } |
| 280 | |
Eduardo Valentin | 8772e18 | 2016-11-07 21:09:15 -0800 | [diff] [blame] | 281 | /* |
| 282 | * Zone update section: main control loop applied to each zone while monitoring |
| 283 | * |
| 284 | * in polling mode. The monitoring is done using a workqueue. |
| 285 | * Same update may be done on a zone by calling thermal_zone_device_update(). |
| 286 | * |
| 287 | * An update means: |
| 288 | * - Non-critical trips will invoke the governor responsible for that zone; |
| 289 | * - Hot trips will produce a notification to userspace; |
| 290 | * - Critical trip point will cause a system shutdown. |
| 291 | */ |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 292 | static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, |
| 293 | int delay) |
| 294 | { |
| 295 | if (delay > 1000) |
| 296 | mod_delayed_work(system_freezable_wq, &tz->poll_queue, |
| 297 | round_jiffies(msecs_to_jiffies(delay))); |
| 298 | else if (delay) |
| 299 | mod_delayed_work(system_freezable_wq, &tz->poll_queue, |
| 300 | msecs_to_jiffies(delay)); |
| 301 | else |
| 302 | cancel_delayed_work(&tz->poll_queue); |
| 303 | } |
| 304 | |
| 305 | static void monitor_thermal_zone(struct thermal_zone_device *tz) |
| 306 | { |
| 307 | mutex_lock(&tz->lock); |
| 308 | |
| 309 | if (tz->passive) |
| 310 | thermal_zone_device_set_polling(tz, tz->passive_delay); |
| 311 | else if (tz->polling_delay) |
| 312 | thermal_zone_device_set_polling(tz, tz->polling_delay); |
| 313 | else |
| 314 | thermal_zone_device_set_polling(tz, 0); |
| 315 | |
| 316 | mutex_unlock(&tz->lock); |
| 317 | } |
| 318 | |
| 319 | static void handle_non_critical_trips(struct thermal_zone_device *tz, |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 320 | int trip, |
| 321 | enum thermal_trip_type trip_type) |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 322 | { |
Zhang Rui | f2234bc | 2014-01-24 10:23:19 +0800 | [diff] [blame] | 323 | tz->governor ? tz->governor->throttle(tz, trip) : |
| 324 | def_governor->throttle(tz, trip); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Keerthy | ef1d87e | 2017-04-18 09:59:59 +0530 | [diff] [blame] | 327 | /** |
| 328 | * thermal_emergency_poweroff_func - emergency poweroff work after a known delay |
| 329 | * @work: work_struct associated with the emergency poweroff function |
| 330 | * |
| 331 | * This function is called in very critical situations to force |
| 332 | * a kernel poweroff after a configurable timeout value. |
| 333 | */ |
| 334 | static void thermal_emergency_poweroff_func(struct work_struct *work) |
| 335 | { |
| 336 | /* |
| 337 | * We have reached here after the emergency thermal shutdown |
| 338 | * Waiting period has expired. This means orderly_poweroff has |
| 339 | * not been able to shut off the system for some reason. |
| 340 | * Try to shut down the system immediately using kernel_power_off |
| 341 | * if populated |
| 342 | */ |
| 343 | WARN(1, "Attempting kernel_power_off: Temperature too high\n"); |
| 344 | kernel_power_off(); |
| 345 | |
| 346 | /* |
| 347 | * Worst of the worst case trigger emergency restart |
| 348 | */ |
| 349 | WARN(1, "Attempting emergency_restart: Temperature too high\n"); |
| 350 | emergency_restart(); |
| 351 | } |
| 352 | |
| 353 | static DECLARE_DELAYED_WORK(thermal_emergency_poweroff_work, |
| 354 | thermal_emergency_poweroff_func); |
| 355 | |
| 356 | /** |
| 357 | * thermal_emergency_poweroff - Trigger an emergency system poweroff |
| 358 | * |
| 359 | * This may be called from any critical situation to trigger a system shutdown |
| 360 | * after a known period of time. By default this is not scheduled. |
| 361 | */ |
| 362 | void thermal_emergency_poweroff(void) |
| 363 | { |
| 364 | int poweroff_delay_ms = CONFIG_THERMAL_EMERGENCY_POWEROFF_DELAY_MS; |
| 365 | /* |
| 366 | * poweroff_delay_ms must be a carefully profiled positive value. |
| 367 | * Its a must for thermal_emergency_poweroff_work to be scheduled |
| 368 | */ |
| 369 | if (poweroff_delay_ms <= 0) |
| 370 | return; |
| 371 | schedule_delayed_work(&thermal_emergency_poweroff_work, |
| 372 | msecs_to_jiffies(poweroff_delay_ms)); |
| 373 | } |
| 374 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 375 | static void handle_critical_trips(struct thermal_zone_device *tz, |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 376 | int trip, enum thermal_trip_type trip_type) |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 377 | { |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 378 | int trip_temp; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 379 | |
| 380 | tz->ops->get_trip_temp(tz, trip, &trip_temp); |
| 381 | |
| 382 | /* If we have not crossed the trip_temp, we do not care. */ |
Srinivas Pandruvada | 84ffe3e | 2014-11-12 15:43:29 -0800 | [diff] [blame] | 383 | if (trip_temp <= 0 || tz->temperature < trip_temp) |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 384 | return; |
| 385 | |
Punit Agrawal | 208cd82 | 2014-07-29 11:50:50 +0100 | [diff] [blame] | 386 | trace_thermal_zone_trip(tz, trip, trip_type); |
| 387 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 388 | if (tz->ops->notify) |
| 389 | tz->ops->notify(tz, trip, trip_type); |
| 390 | |
| 391 | if (trip_type == THERMAL_TRIP_CRITICAL) { |
Eduardo Valentin | 923e0b1 | 2013-01-02 15:29:41 +0000 | [diff] [blame] | 392 | dev_emerg(&tz->device, |
| 393 | "critical temperature reached(%d C),shutting down\n", |
| 394 | tz->temperature / 1000); |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 395 | mutex_lock(&poweroff_lock); |
| 396 | if (!power_off_triggered) { |
Keerthy | ef1d87e | 2017-04-18 09:59:59 +0530 | [diff] [blame] | 397 | /* |
| 398 | * Queue a backup emergency shutdown in the event of |
| 399 | * orderly_poweroff failure |
| 400 | */ |
| 401 | thermal_emergency_poweroff(); |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 402 | orderly_poweroff(true); |
| 403 | power_off_triggered = true; |
| 404 | } |
| 405 | mutex_unlock(&poweroff_lock); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 406 | } |
| 407 | } |
| 408 | |
| 409 | static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) |
| 410 | { |
| 411 | enum thermal_trip_type type; |
| 412 | |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 413 | /* Ignore disabled trip points */ |
| 414 | if (test_bit(trip, &tz->trips_disabled)) |
| 415 | return; |
| 416 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 417 | tz->ops->get_trip_type(tz, trip, &type); |
| 418 | |
| 419 | if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT) |
| 420 | handle_critical_trips(tz, trip, type); |
| 421 | else |
| 422 | handle_non_critical_trips(tz, trip, type); |
| 423 | /* |
| 424 | * Alright, we handled this trip successfully. |
| 425 | * So, start monitoring again. |
| 426 | */ |
| 427 | monitor_thermal_zone(tz); |
| 428 | } |
| 429 | |
| 430 | static void update_temperature(struct thermal_zone_device *tz) |
| 431 | { |
Sascha Hauer | 17e8351 | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 432 | int temp, ret; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 433 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 434 | ret = thermal_zone_get_temp(tz, &temp); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 435 | if (ret) { |
Hans de Goede | 7e497a7 | 2015-03-21 15:02:55 +0100 | [diff] [blame] | 436 | if (ret != -EAGAIN) |
| 437 | dev_warn(&tz->device, |
| 438 | "failed to read out thermal zone (%d)\n", |
| 439 | ret); |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 440 | return; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 441 | } |
| 442 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 443 | mutex_lock(&tz->lock); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 444 | tz->last_temperature = tz->temperature; |
| 445 | tz->temperature = temp; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 446 | mutex_unlock(&tz->lock); |
Aaron Lu | 06475b5 | 2013-12-02 13:54:26 +0800 | [diff] [blame] | 447 | |
Punit Agrawal | 100a8fd | 2014-07-29 11:50:48 +0100 | [diff] [blame] | 448 | trace_thermal_temperature(tz); |
Zhang Rui | bb431ba | 2015-10-30 16:31:47 +0800 | [diff] [blame] | 449 | if (tz->last_temperature == THERMAL_TEMP_INVALID) |
| 450 | dev_dbg(&tz->device, "last_temperature N/A, current_temperature=%d\n", |
| 451 | tz->temperature); |
| 452 | else |
| 453 | dev_dbg(&tz->device, "last_temperature=%d, current_temperature=%d\n", |
| 454 | tz->last_temperature, tz->temperature); |
| 455 | } |
| 456 | |
| 457 | static void thermal_zone_device_reset(struct thermal_zone_device *tz) |
| 458 | { |
| 459 | struct thermal_instance *pos; |
| 460 | |
| 461 | tz->temperature = THERMAL_TEMP_INVALID; |
| 462 | tz->passive = 0; |
| 463 | list_for_each_entry(pos, &tz->thermal_instances, tz_node) |
| 464 | pos->initialized = false; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 465 | } |
| 466 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 467 | void thermal_zone_device_update(struct thermal_zone_device *tz, |
| 468 | enum thermal_notify_event event) |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 469 | { |
| 470 | int count; |
| 471 | |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 472 | if (atomic_read(&in_suspend)) |
| 473 | return; |
| 474 | |
Eduardo Valentin | 81bd4e1 | 2013-09-12 19:15:44 -0400 | [diff] [blame] | 475 | if (!tz->ops->get_temp) |
| 476 | return; |
| 477 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 478 | update_temperature(tz); |
| 479 | |
Sascha Hauer | 060c034 | 2016-06-22 16:42:01 +0800 | [diff] [blame] | 480 | thermal_zone_set_trips(tz); |
| 481 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 482 | tz->notify_event = event; |
| 483 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 484 | for (count = 0; count < tz->trips; count++) |
| 485 | handle_thermal_trip(tz, count); |
| 486 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 487 | EXPORT_SYMBOL_GPL(thermal_zone_device_update); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 488 | |
Eduardo Valentin | 106339a | 2016-11-07 21:09:14 -0800 | [diff] [blame] | 489 | /** |
| 490 | * thermal_notify_framework - Sensor drivers use this API to notify framework |
| 491 | * @tz: thermal zone device |
| 492 | * @trip: indicates which trip point has been crossed |
| 493 | * |
| 494 | * This function handles the trip events from sensor drivers. It starts |
| 495 | * throttling the cooling devices according to the policy configured. |
| 496 | * For CRITICAL and HOT trip points, this notifies the respective drivers, |
| 497 | * and does actual throttling for other trip points i.e ACTIVE and PASSIVE. |
| 498 | * The throttling policy is based on the configured platform data; if no |
| 499 | * platform data is provided, this uses the step_wise throttling policy. |
| 500 | */ |
| 501 | void thermal_notify_framework(struct thermal_zone_device *tz, int trip) |
| 502 | { |
| 503 | handle_thermal_trip(tz, trip); |
| 504 | } |
| 505 | EXPORT_SYMBOL_GPL(thermal_notify_framework); |
| 506 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 507 | static void thermal_zone_device_check(struct work_struct *work) |
| 508 | { |
| 509 | struct thermal_zone_device *tz = container_of(work, struct |
| 510 | thermal_zone_device, |
| 511 | poll_queue.work); |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 512 | thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 513 | } |
| 514 | |
Eduardo Valentin | 712afbd | 2016-11-07 21:09:16 -0800 | [diff] [blame] | 515 | /* |
| 516 | * Power actor section: interface to power actors to estimate power |
| 517 | * |
| 518 | * Set of functions used to interact to cooling devices that know |
| 519 | * how to estimate their devices power consumption. |
| 520 | */ |
Javi Merino | 9f38271 | 2015-03-26 15:53:02 +0000 | [diff] [blame] | 521 | |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 522 | /** |
| 523 | * power_actor_get_max_power() - get the maximum power that a cdev can consume |
| 524 | * @cdev: pointer to &thermal_cooling_device |
| 525 | * @tz: a valid thermal zone device pointer |
| 526 | * @max_power: pointer in which to store the maximum power |
| 527 | * |
| 528 | * Calculate the maximum power consumption in milliwats that the |
| 529 | * cooling device can currently consume and store it in @max_power. |
| 530 | * |
| 531 | * Return: 0 on success, -EINVAL if @cdev doesn't support the |
| 532 | * power_actor API or -E* on other error. |
| 533 | */ |
| 534 | int power_actor_get_max_power(struct thermal_cooling_device *cdev, |
| 535 | struct thermal_zone_device *tz, u32 *max_power) |
| 536 | { |
| 537 | if (!cdev_is_power_actor(cdev)) |
| 538 | return -EINVAL; |
| 539 | |
| 540 | return cdev->ops->state2power(cdev, tz, 0, max_power); |
| 541 | } |
| 542 | |
| 543 | /** |
Javi Merino | c973c3b | 2015-09-14 14:23:50 +0100 | [diff] [blame] | 544 | * power_actor_get_min_power() - get the mainimum power that a cdev can consume |
| 545 | * @cdev: pointer to &thermal_cooling_device |
| 546 | * @tz: a valid thermal zone device pointer |
| 547 | * @min_power: pointer in which to store the minimum power |
| 548 | * |
| 549 | * Calculate the minimum power consumption in milliwatts that the |
| 550 | * cooling device can currently consume and store it in @min_power. |
| 551 | * |
| 552 | * Return: 0 on success, -EINVAL if @cdev doesn't support the |
| 553 | * power_actor API or -E* on other error. |
| 554 | */ |
| 555 | int power_actor_get_min_power(struct thermal_cooling_device *cdev, |
| 556 | struct thermal_zone_device *tz, u32 *min_power) |
| 557 | { |
| 558 | unsigned long max_state; |
| 559 | int ret; |
| 560 | |
| 561 | if (!cdev_is_power_actor(cdev)) |
| 562 | return -EINVAL; |
| 563 | |
| 564 | ret = cdev->ops->get_max_state(cdev, &max_state); |
| 565 | if (ret) |
| 566 | return ret; |
| 567 | |
| 568 | return cdev->ops->state2power(cdev, tz, max_state, min_power); |
| 569 | } |
| 570 | |
| 571 | /** |
Eduardo Valentin | 1a7e7cc | 2016-11-07 21:08:47 -0800 | [diff] [blame] | 572 | * power_actor_set_power() - limit the maximum power a cooling device consumes |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 573 | * @cdev: pointer to &thermal_cooling_device |
| 574 | * @instance: thermal instance to update |
| 575 | * @power: the power in milliwatts |
| 576 | * |
Eduardo Valentin | 1a7e7cc | 2016-11-07 21:08:47 -0800 | [diff] [blame] | 577 | * Set the cooling device to consume at most @power milliwatts. The limit is |
| 578 | * expected to be a cap at the maximum power consumption. |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 579 | * |
| 580 | * Return: 0 on success, -EINVAL if the cooling device does not |
| 581 | * implement the power actor API or -E* for other failures. |
| 582 | */ |
| 583 | int power_actor_set_power(struct thermal_cooling_device *cdev, |
| 584 | struct thermal_instance *instance, u32 power) |
| 585 | { |
| 586 | unsigned long state; |
| 587 | int ret; |
| 588 | |
| 589 | if (!cdev_is_power_actor(cdev)) |
| 590 | return -EINVAL; |
| 591 | |
| 592 | ret = cdev->ops->power2state(cdev, instance->tz, power, &state); |
| 593 | if (ret) |
| 594 | return ret; |
| 595 | |
| 596 | instance->target = state; |
Michele Di Giorgio | d0b7306 | 2016-06-02 15:25:31 +0100 | [diff] [blame] | 597 | mutex_lock(&cdev->lock); |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 598 | cdev->updated = false; |
Michele Di Giorgio | d0b7306 | 2016-06-02 15:25:31 +0100 | [diff] [blame] | 599 | mutex_unlock(&cdev->lock); |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 600 | thermal_cdev_update(cdev); |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Eduardo Valentin | 3d0055d | 2016-11-07 21:08:54 -0800 | [diff] [blame] | 605 | void thermal_zone_device_rebind_exception(struct thermal_zone_device *tz, |
| 606 | const char *cdev_type, size_t size) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 607 | { |
Eduardo Valentin | 3d0055d | 2016-11-07 21:08:54 -0800 | [diff] [blame] | 608 | struct thermal_cooling_device *cdev = NULL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 609 | |
Eduardo Valentin | 3d0055d | 2016-11-07 21:08:54 -0800 | [diff] [blame] | 610 | mutex_lock(&thermal_list_lock); |
| 611 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 612 | /* skip non matching cdevs */ |
| 613 | if (strncmp(cdev_type, cdev->type, size)) |
| 614 | continue; |
| 615 | |
| 616 | /* re binding the exception matching the type pattern */ |
| 617 | thermal_zone_bind_cooling_device(tz, THERMAL_TRIPS_NONE, cdev, |
| 618 | THERMAL_NO_LIMIT, |
| 619 | THERMAL_NO_LIMIT, |
| 620 | THERMAL_WEIGHT_DEFAULT); |
| 621 | } |
| 622 | mutex_unlock(&thermal_list_lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 623 | } |
| 624 | |
Eduardo Valentin | 3d0055d | 2016-11-07 21:08:54 -0800 | [diff] [blame] | 625 | void thermal_zone_device_unbind_exception(struct thermal_zone_device *tz, |
| 626 | const char *cdev_type, size_t size) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 627 | { |
Eduardo Valentin | 3d0055d | 2016-11-07 21:08:54 -0800 | [diff] [blame] | 628 | struct thermal_cooling_device *cdev = NULL; |
| 629 | |
| 630 | mutex_lock(&thermal_list_lock); |
| 631 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 632 | /* skip non matching cdevs */ |
| 633 | if (strncmp(cdev_type, cdev->type, size)) |
| 634 | continue; |
| 635 | /* unbinding the exception matching the type pattern */ |
| 636 | thermal_zone_unbind_cooling_device(tz, THERMAL_TRIPS_NONE, |
| 637 | cdev); |
| 638 | } |
| 639 | mutex_unlock(&thermal_list_lock); |
| 640 | } |
| 641 | |
Eduardo Valentin | 81193e2 | 2016-11-07 21:09:17 -0800 | [diff] [blame] | 642 | /* |
| 643 | * Device management section: cooling devices, zones devices, and binding |
| 644 | * |
| 645 | * Set of functions provided by the thermal core for: |
| 646 | * - cooling devices lifecycle: registration, unregistration, |
| 647 | * binding, and unbinding. |
| 648 | * - thermal zone devices lifecycle: registration, unregistration, |
| 649 | * binding, and unbinding. |
| 650 | */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 651 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 652 | /** |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 653 | * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone |
| 654 | * @tz: pointer to struct thermal_zone_device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 655 | * @trip: indicates which trip point the cooling devices is |
| 656 | * associated with in this thermal zone. |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 657 | * @cdev: pointer to struct thermal_cooling_device |
| 658 | * @upper: the Maximum cooling state for this trip point. |
| 659 | * THERMAL_NO_LIMIT means no upper limit, |
| 660 | * and the cooling device can be in max_state. |
| 661 | * @lower: the Minimum cooling state can be used for this trip point. |
| 662 | * THERMAL_NO_LIMIT means no lower limit, |
| 663 | * and the cooling device can be in cooling state 0. |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 664 | * @weight: The weight of the cooling device to be bound to the |
| 665 | * thermal zone. Use THERMAL_WEIGHT_DEFAULT for the |
| 666 | * default value |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 667 | * |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 668 | * This interface function bind a thermal cooling device to the certain trip |
| 669 | * point of a thermal zone device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 670 | * This function is usually called in the thermal zone device .bind callback. |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 671 | * |
| 672 | * Return: 0 on success, the proper error value otherwise. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 673 | */ |
| 674 | int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, |
| 675 | int trip, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 676 | struct thermal_cooling_device *cdev, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 677 | unsigned long upper, unsigned long lower, |
| 678 | unsigned int weight) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 679 | { |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 680 | struct thermal_instance *dev; |
| 681 | struct thermal_instance *pos; |
Thomas Sujith | c751670 | 2008-02-15 00:58:50 -0500 | [diff] [blame] | 682 | struct thermal_zone_device *pos1; |
| 683 | struct thermal_cooling_device *pos2; |
Zhang Rui | 74051ba | 2012-06-26 16:27:22 +0800 | [diff] [blame] | 684 | unsigned long max_state; |
Lukasz Majewski | 9a3031d | 2014-11-18 11:16:30 +0100 | [diff] [blame] | 685 | int result, ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 686 | |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 687 | if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 688 | return -EINVAL; |
| 689 | |
Thomas Sujith | c751670 | 2008-02-15 00:58:50 -0500 | [diff] [blame] | 690 | list_for_each_entry(pos1, &thermal_tz_list, node) { |
| 691 | if (pos1 == tz) |
| 692 | break; |
| 693 | } |
| 694 | list_for_each_entry(pos2, &thermal_cdev_list, node) { |
| 695 | if (pos2 == cdev) |
| 696 | break; |
| 697 | } |
| 698 | |
| 699 | if (tz != pos1 || cdev != pos2) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 700 | return -EINVAL; |
| 701 | |
Lukasz Majewski | 9a3031d | 2014-11-18 11:16:30 +0100 | [diff] [blame] | 702 | ret = cdev->ops->get_max_state(cdev, &max_state); |
| 703 | if (ret) |
| 704 | return ret; |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 705 | |
| 706 | /* lower default 0, upper default max_state */ |
| 707 | lower = lower == THERMAL_NO_LIMIT ? 0 : lower; |
| 708 | upper = upper == THERMAL_NO_LIMIT ? max_state : upper; |
| 709 | |
| 710 | if (lower > upper || upper > max_state) |
| 711 | return -EINVAL; |
| 712 | |
Eduardo Valentin | 95e3ed1 | 2016-11-07 21:09:25 -0800 | [diff] [blame] | 713 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 714 | if (!dev) |
| 715 | return -ENOMEM; |
| 716 | dev->tz = tz; |
| 717 | dev->cdev = cdev; |
| 718 | dev->trip = trip; |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 719 | dev->upper = upper; |
| 720 | dev->lower = lower; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 721 | dev->target = THERMAL_NO_TARGET; |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 722 | dev->weight = weight; |
Zhang Rui | 74051ba | 2012-06-26 16:27:22 +0800 | [diff] [blame] | 723 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 724 | result = ida_simple_get(&tz->ida, 0, 0, GFP_KERNEL); |
| 725 | if (result < 0) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 726 | goto free_mem; |
| 727 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 728 | dev->id = result; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 729 | sprintf(dev->name, "cdev%d", dev->id); |
| 730 | result = |
| 731 | sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); |
| 732 | if (result) |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 733 | goto release_ida; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 734 | |
| 735 | sprintf(dev->attr_name, "cdev%d_trip_point", dev->id); |
Sergey Senozhatsky | 975f8c5 | 2010-04-06 14:34:51 -0700 | [diff] [blame] | 736 | sysfs_attr_init(&dev->attr.attr); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 737 | dev->attr.attr.name = dev->attr_name; |
| 738 | dev->attr.attr.mode = 0444; |
| 739 | dev->attr.show = thermal_cooling_device_trip_point_show; |
| 740 | result = device_create_file(&tz->device, &dev->attr); |
| 741 | if (result) |
| 742 | goto remove_symbol_link; |
| 743 | |
Javi Merino | db91651 | 2015-02-18 16:04:24 +0000 | [diff] [blame] | 744 | sprintf(dev->weight_attr_name, "cdev%d_weight", dev->id); |
| 745 | sysfs_attr_init(&dev->weight_attr.attr); |
| 746 | dev->weight_attr.attr.name = dev->weight_attr_name; |
| 747 | dev->weight_attr.attr.mode = S_IWUSR | S_IRUGO; |
| 748 | dev->weight_attr.show = thermal_cooling_device_weight_show; |
| 749 | dev->weight_attr.store = thermal_cooling_device_weight_store; |
| 750 | result = device_create_file(&tz->device, &dev->weight_attr); |
| 751 | if (result) |
| 752 | goto remove_trip_file; |
| 753 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 754 | mutex_lock(&tz->lock); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 755 | mutex_lock(&cdev->lock); |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 756 | list_for_each_entry(pos, &tz->thermal_instances, tz_node) |
Eduardo Valentin | b659a30 | 2016-11-07 21:09:23 -0800 | [diff] [blame] | 757 | if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { |
| 758 | result = -EEXIST; |
| 759 | break; |
| 760 | } |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 761 | if (!result) { |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 762 | list_add_tail(&dev->tz_node, &tz->thermal_instances); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 763 | list_add_tail(&dev->cdev_node, &cdev->thermal_instances); |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 764 | atomic_set(&tz->need_update, 1); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 765 | } |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 766 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 767 | mutex_unlock(&tz->lock); |
| 768 | |
| 769 | if (!result) |
| 770 | return 0; |
| 771 | |
Javi Merino | db91651 | 2015-02-18 16:04:24 +0000 | [diff] [blame] | 772 | device_remove_file(&tz->device, &dev->weight_attr); |
| 773 | remove_trip_file: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 774 | device_remove_file(&tz->device, &dev->attr); |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 775 | remove_symbol_link: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 776 | sysfs_remove_link(&tz->device.kobj, dev->name); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 777 | release_ida: |
| 778 | ida_simple_remove(&tz->ida, dev->id); |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 779 | free_mem: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 780 | kfree(dev); |
| 781 | return result; |
| 782 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 783 | EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 784 | |
| 785 | /** |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 786 | * thermal_zone_unbind_cooling_device() - unbind a cooling device from a |
| 787 | * thermal zone. |
| 788 | * @tz: pointer to a struct thermal_zone_device. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 789 | * @trip: indicates which trip point the cooling devices is |
| 790 | * associated with in this thermal zone. |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 791 | * @cdev: pointer to a struct thermal_cooling_device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 792 | * |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 793 | * This interface function unbind a thermal cooling device from the certain |
| 794 | * trip point of a thermal zone device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 795 | * This function is usually called in the thermal zone device .unbind callback. |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 796 | * |
| 797 | * Return: 0 on success, the proper error value otherwise. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 798 | */ |
| 799 | int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, |
| 800 | int trip, |
| 801 | struct thermal_cooling_device *cdev) |
| 802 | { |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 803 | struct thermal_instance *pos, *next; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 804 | |
| 805 | mutex_lock(&tz->lock); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 806 | mutex_lock(&cdev->lock); |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 807 | list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 808 | if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 809 | list_del(&pos->tz_node); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 810 | list_del(&pos->cdev_node); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 811 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 812 | mutex_unlock(&tz->lock); |
| 813 | goto unbind; |
| 814 | } |
| 815 | } |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 816 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 817 | mutex_unlock(&tz->lock); |
| 818 | |
| 819 | return -ENODEV; |
| 820 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 821 | unbind: |
Viresh Kumar | 528464e | 2015-07-23 14:32:32 +0530 | [diff] [blame] | 822 | device_remove_file(&tz->device, &pos->weight_attr); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 823 | device_remove_file(&tz->device, &pos->attr); |
| 824 | sysfs_remove_link(&tz->device.kobj, pos->name); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 825 | ida_simple_remove(&tz->ida, pos->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 826 | kfree(pos); |
| 827 | return 0; |
| 828 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 829 | EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 830 | |
| 831 | static void thermal_release(struct device *dev) |
| 832 | { |
| 833 | struct thermal_zone_device *tz; |
| 834 | struct thermal_cooling_device *cdev; |
| 835 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 836 | if (!strncmp(dev_name(dev), "thermal_zone", |
| 837 | sizeof("thermal_zone") - 1)) { |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 838 | tz = to_thermal_zone(dev); |
Jacob von Chorus | f53345e | 2016-12-30 14:07:52 -0500 | [diff] [blame] | 839 | kfree(tz->trip_type_attrs); |
| 840 | kfree(tz->trip_temp_attrs); |
| 841 | kfree(tz->trip_hyst_attrs); |
| 842 | kfree(tz->trips_attribute_group.attrs); |
| 843 | kfree(tz->device.groups); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 844 | kfree(tz); |
Eduardo Valentin | b659a30 | 2016-11-07 21:09:23 -0800 | [diff] [blame] | 845 | } else if (!strncmp(dev_name(dev), "cooling_device", |
| 846 | sizeof("cooling_device") - 1)) { |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 847 | cdev = to_cooling_device(dev); |
| 848 | kfree(cdev); |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | static struct class thermal_class = { |
| 853 | .name = "thermal", |
| 854 | .dev_release = thermal_release, |
| 855 | }; |
| 856 | |
Eduardo Valentin | 4b0d3c2 | 2016-11-07 21:09:13 -0800 | [diff] [blame] | 857 | static inline |
| 858 | void print_bind_err_msg(struct thermal_zone_device *tz, |
| 859 | struct thermal_cooling_device *cdev, int ret) |
Eduardo Valentin | f502ab8 | 2016-11-07 21:09:12 -0800 | [diff] [blame] | 860 | { |
| 861 | dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", |
| 862 | tz->type, cdev->type, ret); |
| 863 | } |
| 864 | |
| 865 | static void __bind(struct thermal_zone_device *tz, int mask, |
| 866 | struct thermal_cooling_device *cdev, |
| 867 | unsigned long *limits, |
| 868 | unsigned int weight) |
| 869 | { |
| 870 | int i, ret; |
| 871 | |
| 872 | for (i = 0; i < tz->trips; i++) { |
| 873 | if (mask & (1 << i)) { |
| 874 | unsigned long upper, lower; |
| 875 | |
| 876 | upper = THERMAL_NO_LIMIT; |
| 877 | lower = THERMAL_NO_LIMIT; |
| 878 | if (limits) { |
| 879 | lower = limits[i * 2]; |
| 880 | upper = limits[i * 2 + 1]; |
| 881 | } |
| 882 | ret = thermal_zone_bind_cooling_device(tz, i, cdev, |
| 883 | upper, lower, |
| 884 | weight); |
| 885 | if (ret) |
| 886 | print_bind_err_msg(tz, cdev, ret); |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
Eduardo Valentin | 949aad8 | 2016-11-07 21:09:09 -0800 | [diff] [blame] | 891 | static void bind_cdev(struct thermal_cooling_device *cdev) |
| 892 | { |
| 893 | int i, ret; |
| 894 | const struct thermal_zone_params *tzp; |
| 895 | struct thermal_zone_device *pos = NULL; |
| 896 | |
| 897 | mutex_lock(&thermal_list_lock); |
| 898 | |
| 899 | list_for_each_entry(pos, &thermal_tz_list, node) { |
| 900 | if (!pos->tzp && !pos->ops->bind) |
| 901 | continue; |
| 902 | |
| 903 | if (pos->ops->bind) { |
| 904 | ret = pos->ops->bind(pos, cdev); |
| 905 | if (ret) |
| 906 | print_bind_err_msg(pos, cdev, ret); |
| 907 | continue; |
| 908 | } |
| 909 | |
| 910 | tzp = pos->tzp; |
| 911 | if (!tzp || !tzp->tbp) |
| 912 | continue; |
| 913 | |
| 914 | for (i = 0; i < tzp->num_tbps; i++) { |
| 915 | if (tzp->tbp[i].cdev || !tzp->tbp[i].match) |
| 916 | continue; |
| 917 | if (tzp->tbp[i].match(pos, cdev)) |
| 918 | continue; |
| 919 | tzp->tbp[i].cdev = cdev; |
| 920 | __bind(pos, tzp->tbp[i].trip_mask, cdev, |
| 921 | tzp->tbp[i].binding_limits, |
| 922 | tzp->tbp[i].weight); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | mutex_unlock(&thermal_list_lock); |
| 927 | } |
| 928 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 929 | /** |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 930 | * __thermal_cooling_device_register() - register a new thermal cooling device |
| 931 | * @np: a pointer to a device tree node. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 932 | * @type: the thermal cooling device type. |
| 933 | * @devdata: device private data. |
| 934 | * @ops: standard thermal cooling devices callbacks. |
Eduardo Valentin | 3a6eccb | 2013-04-23 21:48:18 +0000 | [diff] [blame] | 935 | * |
| 936 | * This interface function adds a new thermal cooling device (fan/processor/...) |
| 937 | * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself |
| 938 | * to all the thermal zone devices registered at the same time. |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 939 | * It also gives the opportunity to link the cooling device to a device tree |
| 940 | * node, so that it can be bound to a thermal zone created out of device tree. |
Eduardo Valentin | 3a6eccb | 2013-04-23 21:48:18 +0000 | [diff] [blame] | 941 | * |
| 942 | * Return: a pointer to the created struct thermal_cooling_device or an |
| 943 | * ERR_PTR. Caller must check return value with IS_ERR*() helpers. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 944 | */ |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 945 | static struct thermal_cooling_device * |
| 946 | __thermal_cooling_device_register(struct device_node *np, |
| 947 | char *type, void *devdata, |
| 948 | const struct thermal_cooling_device_ops *ops) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 949 | { |
| 950 | struct thermal_cooling_device *cdev; |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 951 | struct thermal_zone_device *pos = NULL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 952 | int result; |
| 953 | |
Guenter Roeck | 204dd1d | 2012-08-07 22:36:45 -0700 | [diff] [blame] | 954 | if (type && strlen(type) >= THERMAL_NAME_LENGTH) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 955 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 956 | |
| 957 | if (!ops || !ops->get_max_state || !ops->get_cur_state || |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 958 | !ops->set_cur_state) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 959 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 960 | |
Eduardo Valentin | 95e3ed1 | 2016-11-07 21:09:25 -0800 | [diff] [blame] | 961 | cdev = kzalloc(sizeof(*cdev), GFP_KERNEL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 962 | if (!cdev) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 963 | return ERR_PTR(-ENOMEM); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 964 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 965 | result = ida_simple_get(&thermal_cdev_ida, 0, 0, GFP_KERNEL); |
| 966 | if (result < 0) { |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 967 | kfree(cdev); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 968 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 969 | } |
| 970 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 971 | cdev->id = result; |
Eduardo Valentin | c7a8b9d | 2013-04-23 21:48:12 +0000 | [diff] [blame] | 972 | strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 973 | mutex_init(&cdev->lock); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 974 | INIT_LIST_HEAD(&cdev->thermal_instances); |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 975 | cdev->np = np; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 976 | cdev->ops = ops; |
Ni Wade | 5ca0cce | 2014-02-17 11:02:55 +0800 | [diff] [blame] | 977 | cdev->updated = false; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 978 | cdev->device.class = &thermal_class; |
Eduardo Valentin | 45cf2ec | 2016-11-07 21:09:02 -0800 | [diff] [blame] | 979 | thermal_cooling_device_setup_sysfs(cdev); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 980 | cdev->devdata = devdata; |
Kay Sievers | 354655e | 2009-01-06 10:44:37 -0800 | [diff] [blame] | 981 | dev_set_name(&cdev->device, "cooling_device%d", cdev->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 982 | result = device_register(&cdev->device); |
| 983 | if (result) { |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 984 | ida_simple_remove(&thermal_cdev_ida, cdev->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 985 | kfree(cdev); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 986 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 987 | } |
| 988 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 989 | /* Add 'this' new cdev to the global cdev list */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 990 | mutex_lock(&thermal_list_lock); |
| 991 | list_add(&cdev->node, &thermal_cdev_list); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 992 | mutex_unlock(&thermal_list_lock); |
| 993 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 994 | /* Update binding information for 'this' new cdev */ |
| 995 | bind_cdev(cdev); |
| 996 | |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 997 | mutex_lock(&thermal_list_lock); |
| 998 | list_for_each_entry(pos, &thermal_tz_list, node) |
| 999 | if (atomic_cmpxchg(&pos->need_update, 1, 0)) |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 1000 | thermal_zone_device_update(pos, |
| 1001 | THERMAL_EVENT_UNSPECIFIED); |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 1002 | mutex_unlock(&thermal_list_lock); |
| 1003 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1004 | return cdev; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1005 | } |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 1006 | |
| 1007 | /** |
| 1008 | * thermal_cooling_device_register() - register a new thermal cooling device |
| 1009 | * @type: the thermal cooling device type. |
| 1010 | * @devdata: device private data. |
| 1011 | * @ops: standard thermal cooling devices callbacks. |
| 1012 | * |
| 1013 | * This interface function adds a new thermal cooling device (fan/processor/...) |
| 1014 | * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself |
| 1015 | * to all the thermal zone devices registered at the same time. |
| 1016 | * |
| 1017 | * Return: a pointer to the created struct thermal_cooling_device or an |
| 1018 | * ERR_PTR. Caller must check return value with IS_ERR*() helpers. |
| 1019 | */ |
| 1020 | struct thermal_cooling_device * |
| 1021 | thermal_cooling_device_register(char *type, void *devdata, |
| 1022 | const struct thermal_cooling_device_ops *ops) |
| 1023 | { |
| 1024 | return __thermal_cooling_device_register(NULL, type, devdata, ops); |
| 1025 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1026 | EXPORT_SYMBOL_GPL(thermal_cooling_device_register); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1027 | |
| 1028 | /** |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 1029 | * thermal_of_cooling_device_register() - register an OF thermal cooling device |
| 1030 | * @np: a pointer to a device tree node. |
| 1031 | * @type: the thermal cooling device type. |
| 1032 | * @devdata: device private data. |
| 1033 | * @ops: standard thermal cooling devices callbacks. |
| 1034 | * |
| 1035 | * This function will register a cooling device with device tree node reference. |
| 1036 | * This interface function adds a new thermal cooling device (fan/processor/...) |
| 1037 | * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself |
| 1038 | * to all the thermal zone devices registered at the same time. |
| 1039 | * |
| 1040 | * Return: a pointer to the created struct thermal_cooling_device or an |
| 1041 | * ERR_PTR. Caller must check return value with IS_ERR*() helpers. |
| 1042 | */ |
| 1043 | struct thermal_cooling_device * |
| 1044 | thermal_of_cooling_device_register(struct device_node *np, |
| 1045 | char *type, void *devdata, |
| 1046 | const struct thermal_cooling_device_ops *ops) |
| 1047 | { |
| 1048 | return __thermal_cooling_device_register(np, type, devdata, ops); |
| 1049 | } |
| 1050 | EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register); |
| 1051 | |
Eduardo Valentin | f11997f | 2016-11-07 21:09:08 -0800 | [diff] [blame] | 1052 | static void __unbind(struct thermal_zone_device *tz, int mask, |
| 1053 | struct thermal_cooling_device *cdev) |
| 1054 | { |
| 1055 | int i; |
| 1056 | |
| 1057 | for (i = 0; i < tz->trips; i++) |
| 1058 | if (mask & (1 << i)) |
| 1059 | thermal_zone_unbind_cooling_device(tz, i, cdev); |
| 1060 | } |
| 1061 | |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 1062 | /** |
Eduardo Valentin | 38e7b54 | 2016-11-07 21:09:24 -0800 | [diff] [blame] | 1063 | * thermal_cooling_device_unregister - removes a thermal cooling device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1064 | * @cdev: the thermal cooling device to remove. |
| 1065 | * |
Eduardo Valentin | 38e7b54 | 2016-11-07 21:09:24 -0800 | [diff] [blame] | 1066 | * thermal_cooling_device_unregister() must be called when a registered |
| 1067 | * thermal cooling device is no longer needed. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1068 | */ |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1069 | void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1070 | { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1071 | int i; |
| 1072 | const struct thermal_zone_params *tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1073 | struct thermal_zone_device *tz; |
| 1074 | struct thermal_cooling_device *pos = NULL; |
| 1075 | |
| 1076 | if (!cdev) |
| 1077 | return; |
| 1078 | |
| 1079 | mutex_lock(&thermal_list_lock); |
| 1080 | list_for_each_entry(pos, &thermal_cdev_list, node) |
Eduardo Valentin | b659a30 | 2016-11-07 21:09:23 -0800 | [diff] [blame] | 1081 | if (pos == cdev) |
| 1082 | break; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1083 | if (pos != cdev) { |
| 1084 | /* thermal cooling device not found */ |
| 1085 | mutex_unlock(&thermal_list_lock); |
| 1086 | return; |
| 1087 | } |
| 1088 | list_del(&cdev->node); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1089 | |
| 1090 | /* Unbind all thermal zones associated with 'this' cdev */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1091 | list_for_each_entry(tz, &thermal_tz_list, node) { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1092 | if (tz->ops->unbind) { |
| 1093 | tz->ops->unbind(tz, cdev); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1094 | continue; |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | if (!tz->tzp || !tz->tzp->tbp) |
| 1098 | continue; |
| 1099 | |
| 1100 | tzp = tz->tzp; |
| 1101 | for (i = 0; i < tzp->num_tbps; i++) { |
| 1102 | if (tzp->tbp[i].cdev == cdev) { |
| 1103 | __unbind(tz, tzp->tbp[i].trip_mask, cdev); |
| 1104 | tzp->tbp[i].cdev = NULL; |
| 1105 | } |
| 1106 | } |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1107 | } |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1108 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1109 | mutex_unlock(&thermal_list_lock); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1110 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1111 | ida_simple_remove(&thermal_cdev_ida, cdev->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1112 | device_unregister(&cdev->device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1113 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1114 | EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1115 | |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1116 | static void bind_tz(struct thermal_zone_device *tz) |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1117 | { |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1118 | int i, ret; |
| 1119 | struct thermal_cooling_device *pos = NULL; |
| 1120 | const struct thermal_zone_params *tzp = tz->tzp; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1121 | |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1122 | if (!tzp && !tz->ops->bind) |
Michele Di Giorgio | d0b7306 | 2016-06-02 15:25:31 +0100 | [diff] [blame] | 1123 | return; |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1124 | |
| 1125 | mutex_lock(&thermal_list_lock); |
| 1126 | |
| 1127 | /* If there is ops->bind, try to use ops->bind */ |
| 1128 | if (tz->ops->bind) { |
| 1129 | list_for_each_entry(pos, &thermal_cdev_list, node) { |
| 1130 | ret = tz->ops->bind(tz, pos); |
| 1131 | if (ret) |
| 1132 | print_bind_err_msg(tz, pos, ret); |
| 1133 | } |
| 1134 | goto exit; |
Michele Di Giorgio | d0b7306 | 2016-06-02 15:25:31 +0100 | [diff] [blame] | 1135 | } |
| 1136 | |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1137 | if (!tzp || !tzp->tbp) |
| 1138 | goto exit; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1139 | |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1140 | list_for_each_entry(pos, &thermal_cdev_list, node) { |
| 1141 | for (i = 0; i < tzp->num_tbps; i++) { |
| 1142 | if (tzp->tbp[i].cdev || !tzp->tbp[i].match) |
| 1143 | continue; |
| 1144 | if (tzp->tbp[i].match(tz, pos)) |
| 1145 | continue; |
| 1146 | tzp->tbp[i].cdev = pos; |
| 1147 | __bind(tz, tzp->tbp[i].trip_mask, pos, |
| 1148 | tzp->tbp[i].binding_limits, |
| 1149 | tzp->tbp[i].weight); |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1150 | } |
| 1151 | } |
Eduardo Valentin | 90f5b5b | 2016-11-07 21:09:10 -0800 | [diff] [blame] | 1152 | exit: |
| 1153 | mutex_unlock(&thermal_list_lock); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /** |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1157 | * thermal_zone_device_register() - register a new thermal zone device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1158 | * @type: the thermal zone device type |
| 1159 | * @trips: the number of trip points the thermal zone support |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1160 | * @mask: a bit string indicating the writeablility of trip points |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1161 | * @devdata: private device data |
| 1162 | * @ops: standard thermal zone device callbacks |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 1163 | * @tzp: thermal zone platform parameters |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1164 | * @passive_delay: number of milliseconds to wait between polls when |
| 1165 | * performing passive cooling |
| 1166 | * @polling_delay: number of milliseconds to wait between polls when checking |
| 1167 | * whether trip points have been crossed (0 for interrupt |
| 1168 | * driven systems) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1169 | * |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1170 | * This interface function adds a new thermal zone device (sensor) to |
| 1171 | * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the |
| 1172 | * thermal cooling devices registered at the same time. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1173 | * thermal_zone_device_unregister() must be called when the device is no |
Zhang Rui | 1b7ddb8 | 2012-06-27 09:51:12 +0800 | [diff] [blame] | 1174 | * longer needed. The passive cooling depends on the .get_trend() return value. |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1175 | * |
| 1176 | * Return: a pointer to the created struct thermal_zone_device or an |
| 1177 | * in case of error, an ERR_PTR. Caller must check return value with |
| 1178 | * IS_ERR*() helpers. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1179 | */ |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 1180 | struct thermal_zone_device * |
| 1181 | thermal_zone_device_register(const char *type, int trips, int mask, |
| 1182 | void *devdata, struct thermal_zone_device_ops *ops, |
| 1183 | struct thermal_zone_params *tzp, int passive_delay, |
| 1184 | int polling_delay) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1185 | { |
| 1186 | struct thermal_zone_device *tz; |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1187 | enum thermal_trip_type trip_type; |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 1188 | int trip_temp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1189 | int result; |
| 1190 | int count; |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 1191 | struct thermal_governor *governor; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1192 | |
Eduardo Valentin | 54fa38c | 2016-11-07 21:08:39 -0800 | [diff] [blame] | 1193 | if (!type || strlen(type) == 0) |
| 1194 | return ERR_PTR(-EINVAL); |
| 1195 | |
Guenter Roeck | 204dd1d | 2012-08-07 22:36:45 -0700 | [diff] [blame] | 1196 | if (type && strlen(type) >= THERMAL_NAME_LENGTH) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1197 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1198 | |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1199 | if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1200 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1201 | |
Eduardo Valentin | 81bd4e1 | 2013-09-12 19:15:44 -0400 | [diff] [blame] | 1202 | if (!ops) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1203 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1204 | |
Jonghwa Lee | 83720d0 | 2013-05-18 09:50:26 +0000 | [diff] [blame] | 1205 | if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp)) |
Eduardo Valentin | 6b2aa51 | 2013-01-02 15:29:42 +0000 | [diff] [blame] | 1206 | return ERR_PTR(-EINVAL); |
| 1207 | |
Eduardo Valentin | 95e3ed1 | 2016-11-07 21:09:25 -0800 | [diff] [blame] | 1208 | tz = kzalloc(sizeof(*tz), GFP_KERNEL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1209 | if (!tz) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1210 | return ERR_PTR(-ENOMEM); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1211 | |
Zhang Rui | 2d37413 | 2012-06-27 10:09:00 +0800 | [diff] [blame] | 1212 | INIT_LIST_HEAD(&tz->thermal_instances); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1213 | ida_init(&tz->ida); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1214 | mutex_init(&tz->lock); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1215 | result = ida_simple_get(&thermal_tz_ida, 0, 0, GFP_KERNEL); |
| 1216 | if (result < 0) { |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1217 | kfree(tz); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1218 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1221 | tz->id = result; |
Eduardo Valentin | 54fa38c | 2016-11-07 21:08:39 -0800 | [diff] [blame] | 1222 | strlcpy(tz->type, type, sizeof(tz->type)); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1223 | tz->ops = ops; |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 1224 | tz->tzp = tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1225 | tz->device.class = &thermal_class; |
| 1226 | tz->devdata = devdata; |
| 1227 | tz->trips = trips; |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1228 | tz->passive_delay = passive_delay; |
| 1229 | tz->polling_delay = polling_delay; |
Eduardo Valentin | 1c60086 | 2016-11-07 21:08:42 -0800 | [diff] [blame] | 1230 | |
Eduardo Valentin | 4d0fe74 | 2016-11-07 21:08:52 -0800 | [diff] [blame] | 1231 | /* sys I/F */ |
Eduardo Valentin | 1c60086 | 2016-11-07 21:08:42 -0800 | [diff] [blame] | 1232 | /* Add nodes that are always present via .groups */ |
Eduardo Valentin | 4d0fe74 | 2016-11-07 21:08:52 -0800 | [diff] [blame] | 1233 | result = thermal_zone_create_device_groups(tz, mask); |
| 1234 | if (result) |
| 1235 | goto unregister; |
| 1236 | |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 1237 | /* A new thermal zone needs to be updated anyway. */ |
| 1238 | atomic_set(&tz->need_update, 1); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1239 | |
Kay Sievers | 354655e | 2009-01-06 10:44:37 -0800 | [diff] [blame] | 1240 | dev_set_name(&tz->device, "thermal_zone%d", tz->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1241 | result = device_register(&tz->device); |
| 1242 | if (result) { |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1243 | ida_simple_remove(&thermal_tz_ida, tz->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1244 | kfree(tz); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1245 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1246 | } |
| 1247 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1248 | for (count = 0; count < trips; count++) { |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 1249 | if (tz->ops->get_trip_type(tz, count, &trip_type)) |
| 1250 | set_bit(count, &tz->trips_disabled); |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 1251 | if (tz->ops->get_trip_temp(tz, count, &trip_temp)) |
| 1252 | set_bit(count, &tz->trips_disabled); |
| 1253 | /* Check for bogus trip points */ |
| 1254 | if (trip_temp == 0) |
| 1255 | set_bit(count, &tz->trips_disabled); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 1258 | /* Update 'this' zone's governor information */ |
| 1259 | mutex_lock(&thermal_governor_lock); |
| 1260 | |
| 1261 | if (tz->tzp) |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 1262 | governor = __find_governor(tz->tzp->governor_name); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 1263 | else |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 1264 | governor = def_governor; |
| 1265 | |
| 1266 | result = thermal_set_governor(tz, governor); |
| 1267 | if (result) { |
| 1268 | mutex_unlock(&thermal_governor_lock); |
| 1269 | goto unregister; |
| 1270 | } |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 1271 | |
| 1272 | mutex_unlock(&thermal_governor_lock); |
| 1273 | |
Eduardo Valentin | ccba4ff | 2013-08-15 11:34:17 -0400 | [diff] [blame] | 1274 | if (!tz->tzp || !tz->tzp->no_hwmon) { |
| 1275 | result = thermal_add_hwmon_sysfs(tz); |
| 1276 | if (result) |
| 1277 | goto unregister; |
| 1278 | } |
Zhang Rui | e68b16a | 2008-04-21 16:07:52 +0800 | [diff] [blame] | 1279 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1280 | mutex_lock(&thermal_list_lock); |
| 1281 | list_add_tail(&tz->node, &thermal_tz_list); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1282 | mutex_unlock(&thermal_list_lock); |
| 1283 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1284 | /* Bind cooling devices for this zone */ |
| 1285 | bind_tz(tz); |
| 1286 | |
Eduardo Valentin | b659a30 | 2016-11-07 21:09:23 -0800 | [diff] [blame] | 1287 | INIT_DELAYED_WORK(&tz->poll_queue, thermal_zone_device_check); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1288 | |
Zhang Rui | bb431ba | 2015-10-30 16:31:47 +0800 | [diff] [blame] | 1289 | thermal_zone_device_reset(tz); |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 1290 | /* Update the new thermal zone and mark it as already updated. */ |
| 1291 | if (atomic_cmpxchg(&tz->need_update, 1, 0)) |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 1292 | thermal_zone_device_update(tz, THERMAL_EVENT_UNSPECIFIED); |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1293 | |
Yao Dongdong | 1401586 | 2014-10-28 07:40:25 +0000 | [diff] [blame] | 1294 | return tz; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1295 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1296 | unregister: |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1297 | ida_simple_remove(&thermal_tz_ida, tz->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1298 | device_unregister(&tz->device); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1299 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1300 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1301 | EXPORT_SYMBOL_GPL(thermal_zone_device_register); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1302 | |
| 1303 | /** |
| 1304 | * thermal_device_unregister - removes the registered thermal zone device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1305 | * @tz: the thermal zone device to remove |
| 1306 | */ |
| 1307 | void thermal_zone_device_unregister(struct thermal_zone_device *tz) |
| 1308 | { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1309 | int i; |
| 1310 | const struct thermal_zone_params *tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1311 | struct thermal_cooling_device *cdev; |
| 1312 | struct thermal_zone_device *pos = NULL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1313 | |
| 1314 | if (!tz) |
| 1315 | return; |
| 1316 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1317 | tzp = tz->tzp; |
| 1318 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1319 | mutex_lock(&thermal_list_lock); |
| 1320 | list_for_each_entry(pos, &thermal_tz_list, node) |
Eduardo Valentin | b659a30 | 2016-11-07 21:09:23 -0800 | [diff] [blame] | 1321 | if (pos == tz) |
| 1322 | break; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1323 | if (pos != tz) { |
| 1324 | /* thermal zone device not found */ |
| 1325 | mutex_unlock(&thermal_list_lock); |
| 1326 | return; |
| 1327 | } |
| 1328 | list_del(&tz->node); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1329 | |
| 1330 | /* Unbind all cdevs associated with 'this' thermal zone */ |
| 1331 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 1332 | if (tz->ops->unbind) { |
| 1333 | tz->ops->unbind(tz, cdev); |
| 1334 | continue; |
| 1335 | } |
| 1336 | |
| 1337 | if (!tzp || !tzp->tbp) |
| 1338 | break; |
| 1339 | |
| 1340 | for (i = 0; i < tzp->num_tbps; i++) { |
| 1341 | if (tzp->tbp[i].cdev == cdev) { |
| 1342 | __unbind(tz, tzp->tbp[i].trip_mask, cdev); |
| 1343 | tzp->tbp[i].cdev = NULL; |
| 1344 | } |
| 1345 | } |
| 1346 | } |
| 1347 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1348 | mutex_unlock(&thermal_list_lock); |
| 1349 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1350 | thermal_zone_device_set_polling(tz, 0); |
| 1351 | |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 1352 | thermal_set_governor(tz, NULL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1353 | |
Zhang Rui | e68b16a | 2008-04-21 16:07:52 +0800 | [diff] [blame] | 1354 | thermal_remove_hwmon_sysfs(tz); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1355 | ida_simple_remove(&thermal_tz_ida, tz->id); |
| 1356 | ida_destroy(&tz->ida); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1357 | mutex_destroy(&tz->lock); |
| 1358 | device_unregister(&tz->device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1359 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1360 | EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1361 | |
Eduardo Valentin | 63c4d91 | 2013-04-05 12:32:28 +0000 | [diff] [blame] | 1362 | /** |
| 1363 | * thermal_zone_get_zone_by_name() - search for a zone and returns its ref |
| 1364 | * @name: thermal zone name to fetch the temperature |
| 1365 | * |
| 1366 | * When only one zone is found with the passed name, returns a reference to it. |
| 1367 | * |
| 1368 | * Return: On success returns a reference to an unique thermal zone with |
| 1369 | * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid |
| 1370 | * paramenters, -ENODEV for not found and -EEXIST for multiple matches). |
| 1371 | */ |
| 1372 | struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name) |
| 1373 | { |
| 1374 | struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); |
| 1375 | unsigned int found = 0; |
| 1376 | |
| 1377 | if (!name) |
| 1378 | goto exit; |
| 1379 | |
| 1380 | mutex_lock(&thermal_list_lock); |
| 1381 | list_for_each_entry(pos, &thermal_tz_list, node) |
Rasmus Villemoes | 484ac2f | 2014-10-13 15:55:01 -0700 | [diff] [blame] | 1382 | if (!strncasecmp(name, pos->type, THERMAL_NAME_LENGTH)) { |
Eduardo Valentin | 63c4d91 | 2013-04-05 12:32:28 +0000 | [diff] [blame] | 1383 | found++; |
| 1384 | ref = pos; |
| 1385 | } |
| 1386 | mutex_unlock(&thermal_list_lock); |
| 1387 | |
| 1388 | /* nothing has been found, thus an error code for it */ |
| 1389 | if (found == 0) |
| 1390 | ref = ERR_PTR(-ENODEV); |
| 1391 | else if (found > 1) |
| 1392 | /* Success only when an unique zone is found */ |
| 1393 | ref = ERR_PTR(-EEXIST); |
| 1394 | |
| 1395 | exit: |
| 1396 | return ref; |
| 1397 | } |
| 1398 | EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); |
| 1399 | |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1400 | #ifdef CONFIG_NET |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 1401 | static const struct genl_multicast_group thermal_event_mcgrps[] = { |
| 1402 | { .name = THERMAL_GENL_MCAST_GROUP_NAME, }, |
| 1403 | }; |
| 1404 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 1405 | static struct genl_family thermal_event_genl_family __ro_after_init = { |
Johannes Berg | 489111e | 2016-10-24 14:40:03 +0200 | [diff] [blame] | 1406 | .module = THIS_MODULE, |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1407 | .name = THERMAL_GENL_FAMILY_NAME, |
| 1408 | .version = THERMAL_GENL_VERSION, |
| 1409 | .maxattr = THERMAL_GENL_ATTR_MAX, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 1410 | .mcgrps = thermal_event_mcgrps, |
| 1411 | .n_mcgrps = ARRAY_SIZE(thermal_event_mcgrps), |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1412 | }; |
| 1413 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1414 | int thermal_generate_netlink_event(struct thermal_zone_device *tz, |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 1415 | enum events event) |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1416 | { |
| 1417 | struct sk_buff *skb; |
| 1418 | struct nlattr *attr; |
| 1419 | struct thermal_genl_event *thermal_event; |
| 1420 | void *msg_header; |
| 1421 | int size; |
| 1422 | int result; |
Fabio Estevam | b11de07 | 2012-03-21 12:55:00 -0700 | [diff] [blame] | 1423 | static unsigned int thermal_event_seqnum; |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1424 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1425 | if (!tz) |
| 1426 | return -EINVAL; |
| 1427 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1428 | /* allocate memory */ |
Joe Perches | 886ee54 | 2012-03-21 12:55:01 -0700 | [diff] [blame] | 1429 | size = nla_total_size(sizeof(struct thermal_genl_event)) + |
| 1430 | nla_total_size(0); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1431 | |
| 1432 | skb = genlmsg_new(size, GFP_ATOMIC); |
| 1433 | if (!skb) |
| 1434 | return -ENOMEM; |
| 1435 | |
| 1436 | /* add the genetlink message header */ |
| 1437 | msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++, |
| 1438 | &thermal_event_genl_family, 0, |
| 1439 | THERMAL_GENL_CMD_EVENT); |
| 1440 | if (!msg_header) { |
| 1441 | nlmsg_free(skb); |
| 1442 | return -ENOMEM; |
| 1443 | } |
| 1444 | |
| 1445 | /* fill the data */ |
Joe Perches | 886ee54 | 2012-03-21 12:55:01 -0700 | [diff] [blame] | 1446 | attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT, |
| 1447 | sizeof(struct thermal_genl_event)); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1448 | |
| 1449 | if (!attr) { |
| 1450 | nlmsg_free(skb); |
| 1451 | return -EINVAL; |
| 1452 | } |
| 1453 | |
| 1454 | thermal_event = nla_data(attr); |
| 1455 | if (!thermal_event) { |
| 1456 | nlmsg_free(skb); |
| 1457 | return -EINVAL; |
| 1458 | } |
| 1459 | |
| 1460 | memset(thermal_event, 0, sizeof(struct thermal_genl_event)); |
| 1461 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1462 | thermal_event->orig = tz->id; |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1463 | thermal_event->event = event; |
| 1464 | |
| 1465 | /* send multicast genetlink message */ |
Johannes Berg | 053c095 | 2015-01-16 22:09:00 +0100 | [diff] [blame] | 1466 | genlmsg_end(skb, msg_header); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1467 | |
Johannes Berg | 68eb550 | 2013-11-19 15:19:38 +0100 | [diff] [blame] | 1468 | result = genlmsg_multicast(&thermal_event_genl_family, skb, 0, |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 1469 | 0, GFP_ATOMIC); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1470 | if (result) |
Eduardo Valentin | 923e0b1 | 2013-01-02 15:29:41 +0000 | [diff] [blame] | 1471 | dev_err(&tz->device, "Failed to send netlink event:%d", result); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1472 | |
| 1473 | return result; |
| 1474 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1475 | EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1476 | |
Johannes Berg | 56989f6 | 2016-10-24 14:40:05 +0200 | [diff] [blame] | 1477 | static int __init genetlink_init(void) |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1478 | { |
Johannes Berg | 2a94fe4 | 2013-11-19 15:19:39 +0100 | [diff] [blame] | 1479 | return genl_register_family(&thermal_event_genl_family); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1480 | } |
| 1481 | |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1482 | static void genetlink_exit(void) |
| 1483 | { |
| 1484 | genl_unregister_family(&thermal_event_genl_family); |
| 1485 | } |
| 1486 | #else /* !CONFIG_NET */ |
| 1487 | static inline int genetlink_init(void) { return 0; } |
| 1488 | static inline void genetlink_exit(void) {} |
| 1489 | #endif /* !CONFIG_NET */ |
| 1490 | |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 1491 | static int thermal_pm_notify(struct notifier_block *nb, |
Eduardo Valentin | eb7be32 | 2016-11-07 21:09:21 -0800 | [diff] [blame] | 1492 | unsigned long mode, void *_unused) |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 1493 | { |
| 1494 | struct thermal_zone_device *tz; |
| 1495 | |
| 1496 | switch (mode) { |
| 1497 | case PM_HIBERNATION_PREPARE: |
| 1498 | case PM_RESTORE_PREPARE: |
| 1499 | case PM_SUSPEND_PREPARE: |
| 1500 | atomic_set(&in_suspend, 1); |
| 1501 | break; |
| 1502 | case PM_POST_HIBERNATION: |
| 1503 | case PM_POST_RESTORE: |
| 1504 | case PM_POST_SUSPEND: |
| 1505 | atomic_set(&in_suspend, 0); |
| 1506 | list_for_each_entry(tz, &thermal_tz_list, node) { |
| 1507 | thermal_zone_device_reset(tz); |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 1508 | thermal_zone_device_update(tz, |
| 1509 | THERMAL_EVENT_UNSPECIFIED); |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 1510 | } |
| 1511 | break; |
| 1512 | default: |
| 1513 | break; |
| 1514 | } |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static struct notifier_block thermal_pm_nb = { |
| 1519 | .notifier_call = thermal_pm_notify, |
| 1520 | }; |
| 1521 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1522 | static int __init thermal_init(void) |
| 1523 | { |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1524 | int result; |
| 1525 | |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 1526 | mutex_init(&poweroff_lock); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1527 | result = thermal_register_governors(); |
| 1528 | if (result) |
| 1529 | goto error; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1530 | |
| 1531 | result = class_register(&thermal_class); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1532 | if (result) |
| 1533 | goto unregister_governors; |
| 1534 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1535 | result = genetlink_init(); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1536 | if (result) |
| 1537 | goto unregister_class; |
| 1538 | |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 1539 | result = of_parse_thermal_zones(); |
| 1540 | if (result) |
| 1541 | goto exit_netlink; |
| 1542 | |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 1543 | result = register_pm_notifier(&thermal_pm_nb); |
| 1544 | if (result) |
| 1545 | pr_warn("Thermal: Can not register suspend notifier, return %d\n", |
| 1546 | result); |
| 1547 | |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1548 | return 0; |
| 1549 | |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 1550 | exit_netlink: |
| 1551 | genetlink_exit(); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1552 | unregister_class: |
| 1553 | class_unregister(&thermal_class); |
Luis Henriques | 9d367e5 | 2014-12-03 21:20:21 +0000 | [diff] [blame] | 1554 | unregister_governors: |
| 1555 | thermal_unregister_governors(); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1556 | error: |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1557 | ida_destroy(&thermal_tz_ida); |
| 1558 | ida_destroy(&thermal_cdev_ida); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1559 | mutex_destroy(&thermal_list_lock); |
| 1560 | mutex_destroy(&thermal_governor_lock); |
Keerthy | e441fd6 | 2017-04-18 09:59:58 +0530 | [diff] [blame] | 1561 | mutex_destroy(&poweroff_lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1562 | return result; |
| 1563 | } |
| 1564 | |
| 1565 | static void __exit thermal_exit(void) |
| 1566 | { |
Zhang Rui | ff140fe | 2015-10-30 16:31:58 +0800 | [diff] [blame] | 1567 | unregister_pm_notifier(&thermal_pm_nb); |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 1568 | of_thermal_destroy_zones(); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1569 | genetlink_exit(); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1570 | class_unregister(&thermal_class); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1571 | thermal_unregister_governors(); |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 1572 | ida_destroy(&thermal_tz_ida); |
| 1573 | ida_destroy(&thermal_cdev_ida); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1574 | mutex_destroy(&thermal_list_lock); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1575 | mutex_destroy(&thermal_governor_lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1576 | } |
| 1577 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1578 | fs_initcall(thermal_init); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1579 | module_exit(thermal_exit); |