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 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 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 | */ |
| 25 | |
Joe Perches | c5a01dd | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/device.h> |
| 30 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 32 | #include <linux/kdev_t.h> |
| 33 | #include <linux/idr.h> |
| 34 | #include <linux/thermal.h> |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 35 | #include <linux/reboot.h> |
Andy Shevchenko | 42a5bf5 | 2013-05-17 11:52:02 +0000 | [diff] [blame] | 36 | #include <linux/string.h> |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 37 | #include <net/netlink.h> |
| 38 | #include <net/genetlink.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 39 | |
Durgadoss R | 71350db | 2012-09-18 11:04:53 +0530 | [diff] [blame] | 40 | #include "thermal_core.h" |
Eduardo Valentin | 0dd8879 | 2013-07-03 15:14:28 -0400 | [diff] [blame^] | 41 | #include "thermal_hwmon.h" |
Durgadoss R | 71350db | 2012-09-18 11:04:53 +0530 | [diff] [blame] | 42 | |
Zhang Rui | 63c4ec9 | 2008-04-21 16:07:13 +0800 | [diff] [blame] | 43 | MODULE_AUTHOR("Zhang Rui"); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 44 | MODULE_DESCRIPTION("Generic thermal management sysfs support"); |
Eduardo Valentin | 6d8d497 | 2013-04-23 21:48:13 +0000 | [diff] [blame] | 45 | MODULE_LICENSE("GPL v2"); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 46 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 47 | static DEFINE_IDR(thermal_tz_idr); |
| 48 | static DEFINE_IDR(thermal_cdev_idr); |
| 49 | static DEFINE_MUTEX(thermal_idr_lock); |
| 50 | |
| 51 | static LIST_HEAD(thermal_tz_list); |
| 52 | static LIST_HEAD(thermal_cdev_list); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 53 | static LIST_HEAD(thermal_governor_list); |
| 54 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 55 | static DEFINE_MUTEX(thermal_list_lock); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 56 | static DEFINE_MUTEX(thermal_governor_lock); |
| 57 | |
| 58 | static struct thermal_governor *__find_governor(const char *name) |
| 59 | { |
| 60 | struct thermal_governor *pos; |
| 61 | |
| 62 | list_for_each_entry(pos, &thermal_governor_list, governor_list) |
| 63 | if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH)) |
| 64 | return pos; |
| 65 | |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | int thermal_register_governor(struct thermal_governor *governor) |
| 70 | { |
| 71 | int err; |
| 72 | const char *name; |
| 73 | struct thermal_zone_device *pos; |
| 74 | |
| 75 | if (!governor) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | mutex_lock(&thermal_governor_lock); |
| 79 | |
| 80 | err = -EBUSY; |
| 81 | if (__find_governor(governor->name) == NULL) { |
| 82 | err = 0; |
| 83 | list_add(&governor->governor_list, &thermal_governor_list); |
| 84 | } |
| 85 | |
| 86 | mutex_lock(&thermal_list_lock); |
| 87 | |
| 88 | list_for_each_entry(pos, &thermal_tz_list, node) { |
| 89 | if (pos->governor) |
| 90 | continue; |
| 91 | if (pos->tzp) |
| 92 | name = pos->tzp->governor_name; |
| 93 | else |
| 94 | name = DEFAULT_THERMAL_GOVERNOR; |
| 95 | if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH)) |
| 96 | pos->governor = governor; |
| 97 | } |
| 98 | |
| 99 | mutex_unlock(&thermal_list_lock); |
| 100 | mutex_unlock(&thermal_governor_lock); |
| 101 | |
| 102 | return err; |
| 103 | } |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 104 | |
| 105 | void thermal_unregister_governor(struct thermal_governor *governor) |
| 106 | { |
| 107 | struct thermal_zone_device *pos; |
| 108 | |
| 109 | if (!governor) |
| 110 | return; |
| 111 | |
| 112 | mutex_lock(&thermal_governor_lock); |
| 113 | |
| 114 | if (__find_governor(governor->name) == NULL) |
| 115 | goto exit; |
| 116 | |
| 117 | mutex_lock(&thermal_list_lock); |
| 118 | |
| 119 | list_for_each_entry(pos, &thermal_tz_list, node) { |
| 120 | if (!strnicmp(pos->governor->name, governor->name, |
| 121 | THERMAL_NAME_LENGTH)) |
| 122 | pos->governor = NULL; |
| 123 | } |
| 124 | |
| 125 | mutex_unlock(&thermal_list_lock); |
| 126 | list_del(&governor->governor_list); |
| 127 | exit: |
| 128 | mutex_unlock(&thermal_governor_lock); |
| 129 | return; |
| 130 | } |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 131 | |
| 132 | static int get_idr(struct idr *idr, struct mutex *lock, int *id) |
| 133 | { |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 134 | int ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 135 | |
| 136 | if (lock) |
| 137 | mutex_lock(lock); |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 138 | ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 139 | if (lock) |
| 140 | mutex_unlock(lock); |
Tejun Heo | 6deb69f | 2013-02-27 17:04:46 -0800 | [diff] [blame] | 141 | if (unlikely(ret < 0)) |
| 142 | return ret; |
| 143 | *id = ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static void release_idr(struct idr *idr, struct mutex *lock, int id) |
| 148 | { |
| 149 | if (lock) |
| 150 | mutex_lock(lock); |
| 151 | idr_remove(idr, id); |
| 152 | if (lock) |
| 153 | mutex_unlock(lock); |
| 154 | } |
| 155 | |
Durgadoss R | 9b4298a | 2012-09-18 11:04:54 +0530 | [diff] [blame] | 156 | int get_tz_trend(struct thermal_zone_device *tz, int trip) |
| 157 | { |
| 158 | enum thermal_trend trend; |
| 159 | |
Eduardo Valentin | 0c87250 | 2013-05-29 21:37:00 +0000 | [diff] [blame] | 160 | if (tz->emul_temperature || !tz->ops->get_trend || |
| 161 | tz->ops->get_trend(tz, trip, &trend)) { |
Durgadoss R | 9b4298a | 2012-09-18 11:04:54 +0530 | [diff] [blame] | 162 | if (tz->temperature > tz->last_temperature) |
| 163 | trend = THERMAL_TREND_RAISING; |
| 164 | else if (tz->temperature < tz->last_temperature) |
| 165 | trend = THERMAL_TREND_DROPPING; |
| 166 | else |
| 167 | trend = THERMAL_TREND_STABLE; |
| 168 | } |
| 169 | |
| 170 | return trend; |
| 171 | } |
| 172 | EXPORT_SYMBOL(get_tz_trend); |
| 173 | |
| 174 | struct thermal_instance *get_thermal_instance(struct thermal_zone_device *tz, |
| 175 | struct thermal_cooling_device *cdev, int trip) |
| 176 | { |
| 177 | struct thermal_instance *pos = NULL; |
| 178 | struct thermal_instance *target_instance = NULL; |
| 179 | |
| 180 | mutex_lock(&tz->lock); |
| 181 | mutex_lock(&cdev->lock); |
| 182 | |
| 183 | list_for_each_entry(pos, &tz->thermal_instances, tz_node) { |
| 184 | if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { |
| 185 | target_instance = pos; |
| 186 | break; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | mutex_unlock(&cdev->lock); |
| 191 | mutex_unlock(&tz->lock); |
| 192 | |
| 193 | return target_instance; |
| 194 | } |
| 195 | EXPORT_SYMBOL(get_thermal_instance); |
| 196 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 197 | static void print_bind_err_msg(struct thermal_zone_device *tz, |
| 198 | struct thermal_cooling_device *cdev, int ret) |
| 199 | { |
| 200 | dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n", |
| 201 | tz->type, cdev->type, ret); |
| 202 | } |
| 203 | |
| 204 | static void __bind(struct thermal_zone_device *tz, int mask, |
| 205 | struct thermal_cooling_device *cdev) |
| 206 | { |
| 207 | int i, ret; |
| 208 | |
| 209 | for (i = 0; i < tz->trips; i++) { |
| 210 | if (mask & (1 << i)) { |
| 211 | ret = thermal_zone_bind_cooling_device(tz, i, cdev, |
| 212 | THERMAL_NO_LIMIT, THERMAL_NO_LIMIT); |
| 213 | if (ret) |
| 214 | print_bind_err_msg(tz, cdev, ret); |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | static void __unbind(struct thermal_zone_device *tz, int mask, |
| 220 | struct thermal_cooling_device *cdev) |
| 221 | { |
| 222 | int i; |
| 223 | |
| 224 | for (i = 0; i < tz->trips; i++) |
| 225 | if (mask & (1 << i)) |
| 226 | thermal_zone_unbind_cooling_device(tz, i, cdev); |
| 227 | } |
| 228 | |
| 229 | static void bind_cdev(struct thermal_cooling_device *cdev) |
| 230 | { |
| 231 | int i, ret; |
| 232 | const struct thermal_zone_params *tzp; |
| 233 | struct thermal_zone_device *pos = NULL; |
| 234 | |
| 235 | mutex_lock(&thermal_list_lock); |
| 236 | |
| 237 | list_for_each_entry(pos, &thermal_tz_list, node) { |
| 238 | if (!pos->tzp && !pos->ops->bind) |
| 239 | continue; |
| 240 | |
| 241 | if (!pos->tzp && pos->ops->bind) { |
| 242 | ret = pos->ops->bind(pos, cdev); |
| 243 | if (ret) |
| 244 | print_bind_err_msg(pos, cdev, ret); |
| 245 | } |
| 246 | |
| 247 | tzp = pos->tzp; |
Hugh Dickins | 791700c | 2012-09-27 16:48:28 -0700 | [diff] [blame] | 248 | if (!tzp || !tzp->tbp) |
| 249 | continue; |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 250 | |
| 251 | for (i = 0; i < tzp->num_tbps; i++) { |
| 252 | if (tzp->tbp[i].cdev || !tzp->tbp[i].match) |
| 253 | continue; |
| 254 | if (tzp->tbp[i].match(pos, cdev)) |
| 255 | continue; |
| 256 | tzp->tbp[i].cdev = cdev; |
| 257 | __bind(pos, tzp->tbp[i].trip_mask, cdev); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | mutex_unlock(&thermal_list_lock); |
| 262 | } |
| 263 | |
| 264 | static void bind_tz(struct thermal_zone_device *tz) |
| 265 | { |
| 266 | int i, ret; |
| 267 | struct thermal_cooling_device *pos = NULL; |
| 268 | const struct thermal_zone_params *tzp = tz->tzp; |
| 269 | |
| 270 | if (!tzp && !tz->ops->bind) |
| 271 | return; |
| 272 | |
| 273 | mutex_lock(&thermal_list_lock); |
| 274 | |
| 275 | /* If there is no platform data, try to use ops->bind */ |
| 276 | if (!tzp && tz->ops->bind) { |
| 277 | list_for_each_entry(pos, &thermal_cdev_list, node) { |
| 278 | ret = tz->ops->bind(tz, pos); |
| 279 | if (ret) |
| 280 | print_bind_err_msg(tz, pos, ret); |
| 281 | } |
| 282 | goto exit; |
| 283 | } |
| 284 | |
Hugh Dickins | 791700c | 2012-09-27 16:48:28 -0700 | [diff] [blame] | 285 | if (!tzp || !tzp->tbp) |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 286 | goto exit; |
| 287 | |
| 288 | list_for_each_entry(pos, &thermal_cdev_list, node) { |
| 289 | for (i = 0; i < tzp->num_tbps; i++) { |
| 290 | if (tzp->tbp[i].cdev || !tzp->tbp[i].match) |
| 291 | continue; |
| 292 | if (tzp->tbp[i].match(tz, pos)) |
| 293 | continue; |
| 294 | tzp->tbp[i].cdev = pos; |
| 295 | __bind(tz, tzp->tbp[i].trip_mask, pos); |
| 296 | } |
| 297 | } |
| 298 | exit: |
| 299 | mutex_unlock(&thermal_list_lock); |
| 300 | } |
| 301 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 302 | static void thermal_zone_device_set_polling(struct thermal_zone_device *tz, |
| 303 | int delay) |
| 304 | { |
| 305 | if (delay > 1000) |
| 306 | mod_delayed_work(system_freezable_wq, &tz->poll_queue, |
| 307 | round_jiffies(msecs_to_jiffies(delay))); |
| 308 | else if (delay) |
| 309 | mod_delayed_work(system_freezable_wq, &tz->poll_queue, |
| 310 | msecs_to_jiffies(delay)); |
| 311 | else |
| 312 | cancel_delayed_work(&tz->poll_queue); |
| 313 | } |
| 314 | |
| 315 | static void monitor_thermal_zone(struct thermal_zone_device *tz) |
| 316 | { |
| 317 | mutex_lock(&tz->lock); |
| 318 | |
| 319 | if (tz->passive) |
| 320 | thermal_zone_device_set_polling(tz, tz->passive_delay); |
| 321 | else if (tz->polling_delay) |
| 322 | thermal_zone_device_set_polling(tz, tz->polling_delay); |
| 323 | else |
| 324 | thermal_zone_device_set_polling(tz, 0); |
| 325 | |
| 326 | mutex_unlock(&tz->lock); |
| 327 | } |
| 328 | |
| 329 | static void handle_non_critical_trips(struct thermal_zone_device *tz, |
| 330 | int trip, enum thermal_trip_type trip_type) |
| 331 | { |
Zhang Rui | d567c68 | 2012-12-12 15:23:54 +0800 | [diff] [blame] | 332 | if (tz->governor) |
| 333 | tz->governor->throttle(tz, trip); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static void handle_critical_trips(struct thermal_zone_device *tz, |
| 337 | int trip, enum thermal_trip_type trip_type) |
| 338 | { |
| 339 | long trip_temp; |
| 340 | |
| 341 | tz->ops->get_trip_temp(tz, trip, &trip_temp); |
| 342 | |
| 343 | /* If we have not crossed the trip_temp, we do not care. */ |
| 344 | if (tz->temperature < trip_temp) |
| 345 | return; |
| 346 | |
| 347 | if (tz->ops->notify) |
| 348 | tz->ops->notify(tz, trip, trip_type); |
| 349 | |
| 350 | if (trip_type == THERMAL_TRIP_CRITICAL) { |
Eduardo Valentin | 923e0b1 | 2013-01-02 15:29:41 +0000 | [diff] [blame] | 351 | dev_emerg(&tz->device, |
| 352 | "critical temperature reached(%d C),shutting down\n", |
| 353 | tz->temperature / 1000); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 354 | orderly_poweroff(true); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static void handle_thermal_trip(struct thermal_zone_device *tz, int trip) |
| 359 | { |
| 360 | enum thermal_trip_type type; |
| 361 | |
| 362 | tz->ops->get_trip_type(tz, trip, &type); |
| 363 | |
| 364 | if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT) |
| 365 | handle_critical_trips(tz, trip, type); |
| 366 | else |
| 367 | handle_non_critical_trips(tz, trip, type); |
| 368 | /* |
| 369 | * Alright, we handled this trip successfully. |
| 370 | * So, start monitoring again. |
| 371 | */ |
| 372 | monitor_thermal_zone(tz); |
| 373 | } |
| 374 | |
Eduardo Valentin | 837b26b | 2013-04-05 12:32:29 +0000 | [diff] [blame] | 375 | /** |
| 376 | * thermal_zone_get_temp() - returns its the temperature of thermal zone |
| 377 | * @tz: a valid pointer to a struct thermal_zone_device |
| 378 | * @temp: a valid pointer to where to store the resulting temperature. |
| 379 | * |
| 380 | * When a valid thermal zone reference is passed, it will fetch its |
| 381 | * temperature and fill @temp. |
| 382 | * |
| 383 | * Return: On success returns 0, an error code otherwise |
| 384 | */ |
| 385 | int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp) |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 386 | { |
Eduardo Valentin | 837b26b | 2013-04-05 12:32:29 +0000 | [diff] [blame] | 387 | int ret = -EINVAL; |
Zhang Rui | 5e20b2e | 2013-02-06 14:02:12 +0800 | [diff] [blame] | 388 | #ifdef CONFIG_THERMAL_EMULATION |
| 389 | int count; |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 390 | unsigned long crit_temp = -1UL; |
| 391 | enum thermal_trip_type type; |
Zhang Rui | 5e20b2e | 2013-02-06 14:02:12 +0800 | [diff] [blame] | 392 | #endif |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 393 | |
Eduardo Valentin | 9b19ec3 | 2013-04-25 14:13:33 +0000 | [diff] [blame] | 394 | if (!tz || IS_ERR(tz)) |
Eduardo Valentin | 837b26b | 2013-04-05 12:32:29 +0000 | [diff] [blame] | 395 | goto exit; |
| 396 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 397 | mutex_lock(&tz->lock); |
| 398 | |
| 399 | ret = tz->ops->get_temp(tz, temp); |
| 400 | #ifdef CONFIG_THERMAL_EMULATION |
| 401 | if (!tz->emul_temperature) |
| 402 | goto skip_emul; |
| 403 | |
| 404 | for (count = 0; count < tz->trips; count++) { |
| 405 | ret = tz->ops->get_trip_type(tz, count, &type); |
| 406 | if (!ret && type == THERMAL_TRIP_CRITICAL) { |
| 407 | ret = tz->ops->get_trip_temp(tz, count, &crit_temp); |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | if (ret) |
| 413 | goto skip_emul; |
| 414 | |
| 415 | if (*temp < crit_temp) |
| 416 | *temp = tz->emul_temperature; |
| 417 | skip_emul: |
| 418 | #endif |
| 419 | mutex_unlock(&tz->lock); |
Eduardo Valentin | 837b26b | 2013-04-05 12:32:29 +0000 | [diff] [blame] | 420 | exit: |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 421 | return ret; |
| 422 | } |
Eduardo Valentin | 837b26b | 2013-04-05 12:32:29 +0000 | [diff] [blame] | 423 | EXPORT_SYMBOL_GPL(thermal_zone_get_temp); |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 424 | |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 425 | static void update_temperature(struct thermal_zone_device *tz) |
| 426 | { |
| 427 | long temp; |
| 428 | int ret; |
| 429 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 430 | ret = thermal_zone_get_temp(tz, &temp); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 431 | if (ret) { |
Eduardo Valentin | 923e0b1 | 2013-01-02 15:29:41 +0000 | [diff] [blame] | 432 | dev_warn(&tz->device, "failed to read out thermal zone %d\n", |
| 433 | tz->id); |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 434 | return; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 435 | } |
| 436 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 437 | mutex_lock(&tz->lock); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 438 | tz->last_temperature = tz->temperature; |
| 439 | tz->temperature = temp; |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 440 | mutex_unlock(&tz->lock); |
| 441 | } |
| 442 | |
| 443 | void thermal_zone_device_update(struct thermal_zone_device *tz) |
| 444 | { |
| 445 | int count; |
| 446 | |
| 447 | update_temperature(tz); |
| 448 | |
| 449 | for (count = 0; count < tz->trips; count++) |
| 450 | handle_thermal_trip(tz, count); |
| 451 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 452 | EXPORT_SYMBOL_GPL(thermal_zone_device_update); |
Durgadoss R | 0c01ebb | 2012-09-18 11:05:04 +0530 | [diff] [blame] | 453 | |
| 454 | static void thermal_zone_device_check(struct work_struct *work) |
| 455 | { |
| 456 | struct thermal_zone_device *tz = container_of(work, struct |
| 457 | thermal_zone_device, |
| 458 | poll_queue.work); |
| 459 | thermal_zone_device_update(tz); |
| 460 | } |
| 461 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 462 | /* sys I/F for thermal zone */ |
| 463 | |
| 464 | #define to_thermal_zone(_dev) \ |
| 465 | container_of(_dev, struct thermal_zone_device, device) |
| 466 | |
| 467 | static ssize_t |
| 468 | type_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 469 | { |
| 470 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 471 | |
| 472 | return sprintf(buf, "%s\n", tz->type); |
| 473 | } |
| 474 | |
| 475 | static ssize_t |
| 476 | temp_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 477 | { |
| 478 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 479 | long temperature; |
| 480 | int ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 481 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 482 | ret = thermal_zone_get_temp(tz, &temperature); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 483 | |
| 484 | if (ret) |
| 485 | return ret; |
| 486 | |
| 487 | return sprintf(buf, "%ld\n", temperature); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static ssize_t |
| 491 | mode_show(struct device *dev, struct device_attribute *attr, char *buf) |
| 492 | { |
| 493 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 494 | enum thermal_device_mode mode; |
| 495 | int result; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 496 | |
| 497 | if (!tz->ops->get_mode) |
| 498 | return -EPERM; |
| 499 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 500 | result = tz->ops->get_mode(tz, &mode); |
| 501 | if (result) |
| 502 | return result; |
| 503 | |
| 504 | return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled" |
| 505 | : "disabled"); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static ssize_t |
| 509 | mode_store(struct device *dev, struct device_attribute *attr, |
| 510 | const char *buf, size_t count) |
| 511 | { |
| 512 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 513 | int result; |
| 514 | |
| 515 | if (!tz->ops->set_mode) |
| 516 | return -EPERM; |
| 517 | |
Amit Daniel Kachhap | f1f0e2a | 2012-03-21 16:40:01 +0530 | [diff] [blame] | 518 | if (!strncmp(buf, "enabled", sizeof("enabled") - 1)) |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 519 | result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED); |
Amit Daniel Kachhap | f1f0e2a | 2012-03-21 16:40:01 +0530 | [diff] [blame] | 520 | else if (!strncmp(buf, "disabled", sizeof("disabled") - 1)) |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 521 | result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED); |
| 522 | else |
| 523 | result = -EINVAL; |
| 524 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 525 | if (result) |
| 526 | return result; |
| 527 | |
| 528 | return count; |
| 529 | } |
| 530 | |
| 531 | static ssize_t |
| 532 | trip_point_type_show(struct device *dev, struct device_attribute *attr, |
| 533 | char *buf) |
| 534 | { |
| 535 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 536 | enum thermal_trip_type type; |
| 537 | int trip, result; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 538 | |
| 539 | if (!tz->ops->get_trip_type) |
| 540 | return -EPERM; |
| 541 | |
| 542 | if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip)) |
| 543 | return -EINVAL; |
| 544 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 545 | result = tz->ops->get_trip_type(tz, trip, &type); |
| 546 | if (result) |
| 547 | return result; |
| 548 | |
| 549 | switch (type) { |
| 550 | case THERMAL_TRIP_CRITICAL: |
Amit Kucheria | 625120a4 | 2009-10-16 12:46:02 +0300 | [diff] [blame] | 551 | return sprintf(buf, "critical\n"); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 552 | case THERMAL_TRIP_HOT: |
Amit Kucheria | 625120a4 | 2009-10-16 12:46:02 +0300 | [diff] [blame] | 553 | return sprintf(buf, "hot\n"); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 554 | case THERMAL_TRIP_PASSIVE: |
Amit Kucheria | 625120a4 | 2009-10-16 12:46:02 +0300 | [diff] [blame] | 555 | return sprintf(buf, "passive\n"); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 556 | case THERMAL_TRIP_ACTIVE: |
Amit Kucheria | 625120a4 | 2009-10-16 12:46:02 +0300 | [diff] [blame] | 557 | return sprintf(buf, "active\n"); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 558 | default: |
Amit Kucheria | 625120a4 | 2009-10-16 12:46:02 +0300 | [diff] [blame] | 559 | return sprintf(buf, "unknown\n"); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 560 | } |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static ssize_t |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 564 | trip_point_temp_store(struct device *dev, struct device_attribute *attr, |
| 565 | const char *buf, size_t count) |
| 566 | { |
| 567 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 568 | int trip, ret; |
| 569 | unsigned long temperature; |
| 570 | |
| 571 | if (!tz->ops->set_trip_temp) |
| 572 | return -EPERM; |
| 573 | |
| 574 | if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip)) |
| 575 | return -EINVAL; |
| 576 | |
| 577 | if (kstrtoul(buf, 10, &temperature)) |
| 578 | return -EINVAL; |
| 579 | |
| 580 | ret = tz->ops->set_trip_temp(tz, trip, temperature); |
| 581 | |
| 582 | return ret ? ret : count; |
| 583 | } |
| 584 | |
| 585 | static ssize_t |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 586 | trip_point_temp_show(struct device *dev, struct device_attribute *attr, |
| 587 | char *buf) |
| 588 | { |
| 589 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 590 | int trip, ret; |
| 591 | long temperature; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 592 | |
| 593 | if (!tz->ops->get_trip_temp) |
| 594 | return -EPERM; |
| 595 | |
| 596 | if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip)) |
| 597 | return -EINVAL; |
| 598 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 599 | ret = tz->ops->get_trip_temp(tz, trip, &temperature); |
| 600 | |
| 601 | if (ret) |
| 602 | return ret; |
| 603 | |
| 604 | return sprintf(buf, "%ld\n", temperature); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 605 | } |
| 606 | |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 607 | static ssize_t |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 608 | trip_point_hyst_store(struct device *dev, struct device_attribute *attr, |
| 609 | const char *buf, size_t count) |
| 610 | { |
| 611 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 612 | int trip, ret; |
| 613 | unsigned long temperature; |
| 614 | |
| 615 | if (!tz->ops->set_trip_hyst) |
| 616 | return -EPERM; |
| 617 | |
| 618 | if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip)) |
| 619 | return -EINVAL; |
| 620 | |
| 621 | if (kstrtoul(buf, 10, &temperature)) |
| 622 | return -EINVAL; |
| 623 | |
| 624 | /* |
| 625 | * We are not doing any check on the 'temperature' value |
| 626 | * here. The driver implementing 'set_trip_hyst' has to |
| 627 | * take care of this. |
| 628 | */ |
| 629 | ret = tz->ops->set_trip_hyst(tz, trip, temperature); |
| 630 | |
| 631 | return ret ? ret : count; |
| 632 | } |
| 633 | |
| 634 | static ssize_t |
| 635 | trip_point_hyst_show(struct device *dev, struct device_attribute *attr, |
| 636 | char *buf) |
| 637 | { |
| 638 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 639 | int trip, ret; |
| 640 | unsigned long temperature; |
| 641 | |
| 642 | if (!tz->ops->get_trip_hyst) |
| 643 | return -EPERM; |
| 644 | |
| 645 | if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip)) |
| 646 | return -EINVAL; |
| 647 | |
| 648 | ret = tz->ops->get_trip_hyst(tz, trip, &temperature); |
| 649 | |
| 650 | return ret ? ret : sprintf(buf, "%ld\n", temperature); |
| 651 | } |
| 652 | |
| 653 | static ssize_t |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 654 | passive_store(struct device *dev, struct device_attribute *attr, |
| 655 | const char *buf, size_t count) |
| 656 | { |
| 657 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 658 | struct thermal_cooling_device *cdev = NULL; |
| 659 | int state; |
| 660 | |
| 661 | if (!sscanf(buf, "%d\n", &state)) |
| 662 | return -EINVAL; |
| 663 | |
Frans Pop | 3d8e3ad | 2009-10-26 08:39:02 +0100 | [diff] [blame] | 664 | /* sanity check: values below 1000 millicelcius don't make sense |
| 665 | * and can cause the system to go into a thermal heart attack |
| 666 | */ |
| 667 | if (state && state < 1000) |
| 668 | return -EINVAL; |
| 669 | |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 670 | if (state && !tz->forced_passive) { |
| 671 | mutex_lock(&thermal_list_lock); |
| 672 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 673 | if (!strncmp("Processor", cdev->type, |
| 674 | sizeof("Processor"))) |
| 675 | thermal_zone_bind_cooling_device(tz, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 676 | THERMAL_TRIPS_NONE, cdev, |
| 677 | THERMAL_NO_LIMIT, |
| 678 | THERMAL_NO_LIMIT); |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 679 | } |
| 680 | mutex_unlock(&thermal_list_lock); |
Frans Pop | e4143b0 | 2009-10-26 08:39:03 +0100 | [diff] [blame] | 681 | if (!tz->passive_delay) |
| 682 | tz->passive_delay = 1000; |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 683 | } else if (!state && tz->forced_passive) { |
| 684 | mutex_lock(&thermal_list_lock); |
| 685 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 686 | if (!strncmp("Processor", cdev->type, |
| 687 | sizeof("Processor"))) |
| 688 | thermal_zone_unbind_cooling_device(tz, |
| 689 | THERMAL_TRIPS_NONE, |
| 690 | cdev); |
| 691 | } |
| 692 | mutex_unlock(&thermal_list_lock); |
Frans Pop | e4143b0 | 2009-10-26 08:39:03 +0100 | [diff] [blame] | 693 | tz->passive_delay = 0; |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 696 | tz->forced_passive = state; |
| 697 | |
| 698 | thermal_zone_device_update(tz); |
| 699 | |
| 700 | return count; |
| 701 | } |
| 702 | |
| 703 | static ssize_t |
| 704 | passive_show(struct device *dev, struct device_attribute *attr, |
| 705 | char *buf) |
| 706 | { |
| 707 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 708 | |
| 709 | return sprintf(buf, "%d\n", tz->forced_passive); |
| 710 | } |
| 711 | |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 712 | static ssize_t |
| 713 | policy_store(struct device *dev, struct device_attribute *attr, |
| 714 | const char *buf, size_t count) |
| 715 | { |
| 716 | int ret = -EINVAL; |
| 717 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 718 | struct thermal_governor *gov; |
Andy Shevchenko | 42a5bf5 | 2013-05-17 11:52:02 +0000 | [diff] [blame] | 719 | char name[THERMAL_NAME_LENGTH]; |
| 720 | |
| 721 | snprintf(name, sizeof(name), "%s", buf); |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 722 | |
| 723 | mutex_lock(&thermal_governor_lock); |
| 724 | |
Andy Shevchenko | 42a5bf5 | 2013-05-17 11:52:02 +0000 | [diff] [blame] | 725 | gov = __find_governor(strim(name)); |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 726 | if (!gov) |
| 727 | goto exit; |
| 728 | |
| 729 | tz->governor = gov; |
| 730 | ret = count; |
| 731 | |
| 732 | exit: |
| 733 | mutex_unlock(&thermal_governor_lock); |
| 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | static ssize_t |
| 738 | policy_show(struct device *dev, struct device_attribute *devattr, char *buf) |
| 739 | { |
| 740 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 741 | |
| 742 | return sprintf(buf, "%s\n", tz->governor->name); |
| 743 | } |
| 744 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 745 | #ifdef CONFIG_THERMAL_EMULATION |
| 746 | static ssize_t |
| 747 | emul_temp_store(struct device *dev, struct device_attribute *attr, |
| 748 | const char *buf, size_t count) |
| 749 | { |
| 750 | struct thermal_zone_device *tz = to_thermal_zone(dev); |
| 751 | int ret = 0; |
| 752 | unsigned long temperature; |
| 753 | |
| 754 | if (kstrtoul(buf, 10, &temperature)) |
| 755 | return -EINVAL; |
| 756 | |
| 757 | if (!tz->ops->set_emul_temp) { |
| 758 | mutex_lock(&tz->lock); |
| 759 | tz->emul_temperature = temperature; |
| 760 | mutex_unlock(&tz->lock); |
| 761 | } else { |
| 762 | ret = tz->ops->set_emul_temp(tz, temperature); |
| 763 | } |
| 764 | |
| 765 | return ret ? ret : count; |
| 766 | } |
| 767 | static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store); |
| 768 | #endif/*CONFIG_THERMAL_EMULATION*/ |
| 769 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 770 | static DEVICE_ATTR(type, 0444, type_show, NULL); |
| 771 | static DEVICE_ATTR(temp, 0444, temp_show, NULL); |
| 772 | static DEVICE_ATTR(mode, 0644, mode_show, mode_store); |
Joe Perches | 886ee54 | 2012-03-21 12:55:01 -0700 | [diff] [blame] | 773 | static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store); |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 774 | static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 775 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 776 | /* sys I/F for cooling device */ |
| 777 | #define to_cooling_device(_dev) \ |
| 778 | container_of(_dev, struct thermal_cooling_device, device) |
| 779 | |
| 780 | static ssize_t |
| 781 | thermal_cooling_device_type_show(struct device *dev, |
| 782 | struct device_attribute *attr, char *buf) |
| 783 | { |
| 784 | struct thermal_cooling_device *cdev = to_cooling_device(dev); |
| 785 | |
| 786 | return sprintf(buf, "%s\n", cdev->type); |
| 787 | } |
| 788 | |
| 789 | static ssize_t |
| 790 | thermal_cooling_device_max_state_show(struct device *dev, |
| 791 | struct device_attribute *attr, char *buf) |
| 792 | { |
| 793 | struct thermal_cooling_device *cdev = to_cooling_device(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 794 | unsigned long state; |
| 795 | int ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 796 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 797 | ret = cdev->ops->get_max_state(cdev, &state); |
| 798 | if (ret) |
| 799 | return ret; |
| 800 | return sprintf(buf, "%ld\n", state); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | static ssize_t |
| 804 | thermal_cooling_device_cur_state_show(struct device *dev, |
| 805 | struct device_attribute *attr, char *buf) |
| 806 | { |
| 807 | struct thermal_cooling_device *cdev = to_cooling_device(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 808 | unsigned long state; |
| 809 | int ret; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 810 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 811 | ret = cdev->ops->get_cur_state(cdev, &state); |
| 812 | if (ret) |
| 813 | return ret; |
| 814 | return sprintf(buf, "%ld\n", state); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | static ssize_t |
| 818 | thermal_cooling_device_cur_state_store(struct device *dev, |
| 819 | struct device_attribute *attr, |
| 820 | const char *buf, size_t count) |
| 821 | { |
| 822 | struct thermal_cooling_device *cdev = to_cooling_device(dev); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 823 | unsigned long state; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 824 | int result; |
| 825 | |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 826 | if (!sscanf(buf, "%ld\n", &state)) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 827 | return -EINVAL; |
| 828 | |
Roel Kluin | edb9491 | 2009-12-15 22:46:50 +0100 | [diff] [blame] | 829 | if ((long)state < 0) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 830 | return -EINVAL; |
| 831 | |
| 832 | result = cdev->ops->set_cur_state(cdev, state); |
| 833 | if (result) |
| 834 | return result; |
| 835 | return count; |
| 836 | } |
| 837 | |
| 838 | static struct device_attribute dev_attr_cdev_type = |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 839 | __ATTR(type, 0444, thermal_cooling_device_type_show, NULL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 840 | static DEVICE_ATTR(max_state, 0444, |
| 841 | thermal_cooling_device_max_state_show, NULL); |
| 842 | static DEVICE_ATTR(cur_state, 0644, |
| 843 | thermal_cooling_device_cur_state_show, |
| 844 | thermal_cooling_device_cur_state_store); |
| 845 | |
| 846 | static ssize_t |
| 847 | thermal_cooling_device_trip_point_show(struct device *dev, |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 848 | struct device_attribute *attr, char *buf) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 849 | { |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 850 | struct thermal_instance *instance; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 851 | |
| 852 | instance = |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 853 | container_of(attr, struct thermal_instance, attr); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 854 | |
| 855 | if (instance->trip == THERMAL_TRIPS_NONE) |
| 856 | return sprintf(buf, "-1\n"); |
| 857 | else |
| 858 | return sprintf(buf, "%d\n", instance->trip); |
| 859 | } |
| 860 | |
| 861 | /* Device management */ |
| 862 | |
| 863 | /** |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 864 | * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone |
| 865 | * @tz: pointer to struct thermal_zone_device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 866 | * @trip: indicates which trip point the cooling devices is |
| 867 | * associated with in this thermal zone. |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 868 | * @cdev: pointer to struct thermal_cooling_device |
| 869 | * @upper: the Maximum cooling state for this trip point. |
| 870 | * THERMAL_NO_LIMIT means no upper limit, |
| 871 | * and the cooling device can be in max_state. |
| 872 | * @lower: the Minimum cooling state can be used for this trip point. |
| 873 | * THERMAL_NO_LIMIT means no lower limit, |
| 874 | * and the cooling device can be in cooling state 0. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 875 | * |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 876 | * This interface function bind a thermal cooling device to the certain trip |
| 877 | * point of a thermal zone device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 878 | * This function is usually called in the thermal zone device .bind callback. |
Eduardo Valentin | d2e4eb8 | 2013-04-23 21:48:16 +0000 | [diff] [blame] | 879 | * |
| 880 | * Return: 0 on success, the proper error value otherwise. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 881 | */ |
| 882 | int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz, |
| 883 | int trip, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 884 | struct thermal_cooling_device *cdev, |
| 885 | unsigned long upper, unsigned long lower) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 886 | { |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 887 | struct thermal_instance *dev; |
| 888 | struct thermal_instance *pos; |
Thomas Sujith | c751670 | 2008-02-15 00:58:50 -0500 | [diff] [blame] | 889 | struct thermal_zone_device *pos1; |
| 890 | struct thermal_cooling_device *pos2; |
Zhang Rui | 74051ba | 2012-06-26 16:27:22 +0800 | [diff] [blame] | 891 | unsigned long max_state; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 892 | int result; |
| 893 | |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 894 | if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE)) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 895 | return -EINVAL; |
| 896 | |
Thomas Sujith | c751670 | 2008-02-15 00:58:50 -0500 | [diff] [blame] | 897 | list_for_each_entry(pos1, &thermal_tz_list, node) { |
| 898 | if (pos1 == tz) |
| 899 | break; |
| 900 | } |
| 901 | list_for_each_entry(pos2, &thermal_cdev_list, node) { |
| 902 | if (pos2 == cdev) |
| 903 | break; |
| 904 | } |
| 905 | |
| 906 | if (tz != pos1 || cdev != pos2) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 907 | return -EINVAL; |
| 908 | |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 909 | cdev->ops->get_max_state(cdev, &max_state); |
| 910 | |
| 911 | /* lower default 0, upper default max_state */ |
| 912 | lower = lower == THERMAL_NO_LIMIT ? 0 : lower; |
| 913 | upper = upper == THERMAL_NO_LIMIT ? max_state : upper; |
| 914 | |
| 915 | if (lower > upper || upper > max_state) |
| 916 | return -EINVAL; |
| 917 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 918 | dev = |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 919 | kzalloc(sizeof(struct thermal_instance), GFP_KERNEL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 920 | if (!dev) |
| 921 | return -ENOMEM; |
| 922 | dev->tz = tz; |
| 923 | dev->cdev = cdev; |
| 924 | dev->trip = trip; |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 925 | dev->upper = upper; |
| 926 | dev->lower = lower; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 927 | dev->target = THERMAL_NO_TARGET; |
Zhang Rui | 74051ba | 2012-06-26 16:27:22 +0800 | [diff] [blame] | 928 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 929 | result = get_idr(&tz->idr, &tz->lock, &dev->id); |
| 930 | if (result) |
| 931 | goto free_mem; |
| 932 | |
| 933 | sprintf(dev->name, "cdev%d", dev->id); |
| 934 | result = |
| 935 | sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name); |
| 936 | if (result) |
| 937 | goto release_idr; |
| 938 | |
| 939 | sprintf(dev->attr_name, "cdev%d_trip_point", dev->id); |
Sergey Senozhatsky | 975f8c5 | 2010-04-06 14:34:51 -0700 | [diff] [blame] | 940 | sysfs_attr_init(&dev->attr.attr); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 941 | dev->attr.attr.name = dev->attr_name; |
| 942 | dev->attr.attr.mode = 0444; |
| 943 | dev->attr.show = thermal_cooling_device_trip_point_show; |
| 944 | result = device_create_file(&tz->device, &dev->attr); |
| 945 | if (result) |
| 946 | goto remove_symbol_link; |
| 947 | |
| 948 | mutex_lock(&tz->lock); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 949 | mutex_lock(&cdev->lock); |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 950 | list_for_each_entry(pos, &tz->thermal_instances, tz_node) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 951 | if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { |
| 952 | result = -EEXIST; |
| 953 | break; |
| 954 | } |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 955 | if (!result) { |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 956 | list_add_tail(&dev->tz_node, &tz->thermal_instances); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 957 | list_add_tail(&dev->cdev_node, &cdev->thermal_instances); |
| 958 | } |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 959 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 960 | mutex_unlock(&tz->lock); |
| 961 | |
| 962 | if (!result) |
| 963 | return 0; |
| 964 | |
| 965 | device_remove_file(&tz->device, &dev->attr); |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 966 | remove_symbol_link: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 967 | sysfs_remove_link(&tz->device.kobj, dev->name); |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 968 | release_idr: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 969 | release_idr(&tz->idr, &tz->lock, dev->id); |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 970 | free_mem: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 971 | kfree(dev); |
| 972 | return result; |
| 973 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 974 | EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 975 | |
| 976 | /** |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 977 | * thermal_zone_unbind_cooling_device() - unbind a cooling device from a |
| 978 | * thermal zone. |
| 979 | * @tz: pointer to a struct thermal_zone_device. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 980 | * @trip: indicates which trip point the cooling devices is |
| 981 | * associated with in this thermal zone. |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 982 | * @cdev: pointer to a struct thermal_cooling_device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 983 | * |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 984 | * This interface function unbind a thermal cooling device from the certain |
| 985 | * trip point of a thermal zone device. |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 986 | * This function is usually called in the thermal zone device .unbind callback. |
Eduardo Valentin | 9892e5d | 2013-04-23 21:48:17 +0000 | [diff] [blame] | 987 | * |
| 988 | * Return: 0 on success, the proper error value otherwise. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 989 | */ |
| 990 | int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz, |
| 991 | int trip, |
| 992 | struct thermal_cooling_device *cdev) |
| 993 | { |
Zhang Rui | b81b6ba | 2012-06-27 10:08:19 +0800 | [diff] [blame] | 994 | struct thermal_instance *pos, *next; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 995 | |
| 996 | mutex_lock(&tz->lock); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 997 | mutex_lock(&cdev->lock); |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 998 | list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) { |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 999 | if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { |
Zhang Rui | cddf31b | 2012-06-27 10:09:36 +0800 | [diff] [blame] | 1000 | list_del(&pos->tz_node); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 1001 | list_del(&pos->cdev_node); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 1002 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1003 | mutex_unlock(&tz->lock); |
| 1004 | goto unbind; |
| 1005 | } |
| 1006 | } |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 1007 | mutex_unlock(&cdev->lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1008 | mutex_unlock(&tz->lock); |
| 1009 | |
| 1010 | return -ENODEV; |
| 1011 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1012 | unbind: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1013 | device_remove_file(&tz->device, &pos->attr); |
| 1014 | sysfs_remove_link(&tz->device.kobj, pos->name); |
| 1015 | release_idr(&tz->idr, &tz->lock, pos->id); |
| 1016 | kfree(pos); |
| 1017 | return 0; |
| 1018 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1019 | EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1020 | |
| 1021 | static void thermal_release(struct device *dev) |
| 1022 | { |
| 1023 | struct thermal_zone_device *tz; |
| 1024 | struct thermal_cooling_device *cdev; |
| 1025 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1026 | if (!strncmp(dev_name(dev), "thermal_zone", |
| 1027 | sizeof("thermal_zone") - 1)) { |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1028 | tz = to_thermal_zone(dev); |
| 1029 | kfree(tz); |
| 1030 | } else { |
| 1031 | cdev = to_cooling_device(dev); |
| 1032 | kfree(cdev); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | static struct class thermal_class = { |
| 1037 | .name = "thermal", |
| 1038 | .dev_release = thermal_release, |
| 1039 | }; |
| 1040 | |
| 1041 | /** |
Eduardo Valentin | 3a6eccb | 2013-04-23 21:48:18 +0000 | [diff] [blame] | 1042 | * thermal_cooling_device_register() - register a new thermal cooling device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1043 | * @type: the thermal cooling device type. |
| 1044 | * @devdata: device private data. |
| 1045 | * @ops: standard thermal cooling devices callbacks. |
Eduardo Valentin | 3a6eccb | 2013-04-23 21:48:18 +0000 | [diff] [blame] | 1046 | * |
| 1047 | * This interface function adds a new thermal cooling device (fan/processor/...) |
| 1048 | * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself |
| 1049 | * to all the thermal zone devices registered at the same time. |
| 1050 | * |
| 1051 | * Return: a pointer to the created struct thermal_cooling_device or an |
| 1052 | * ERR_PTR. Caller must check return value with IS_ERR*() helpers. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1053 | */ |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1054 | struct thermal_cooling_device * |
| 1055 | thermal_cooling_device_register(char *type, void *devdata, |
| 1056 | const struct thermal_cooling_device_ops *ops) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1057 | { |
| 1058 | struct thermal_cooling_device *cdev; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1059 | int result; |
| 1060 | |
Guenter Roeck | 204dd1d | 2012-08-07 22:36:45 -0700 | [diff] [blame] | 1061 | if (type && strlen(type) >= THERMAL_NAME_LENGTH) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1062 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1063 | |
| 1064 | if (!ops || !ops->get_max_state || !ops->get_cur_state || |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 1065 | !ops->set_cur_state) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1066 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1067 | |
| 1068 | cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL); |
| 1069 | if (!cdev) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1070 | return ERR_PTR(-ENOMEM); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1071 | |
| 1072 | result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id); |
| 1073 | if (result) { |
| 1074 | kfree(cdev); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1075 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1076 | } |
| 1077 | |
Eduardo Valentin | c7a8b9d | 2013-04-23 21:48:12 +0000 | [diff] [blame] | 1078 | strlcpy(cdev->type, type ? : "", sizeof(cdev->type)); |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 1079 | mutex_init(&cdev->lock); |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 1080 | INIT_LIST_HEAD(&cdev->thermal_instances); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1081 | cdev->ops = ops; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1082 | cdev->updated = true; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1083 | cdev->device.class = &thermal_class; |
| 1084 | cdev->devdata = devdata; |
Kay Sievers | 354655e | 2009-01-06 10:44:37 -0800 | [diff] [blame] | 1085 | dev_set_name(&cdev->device, "cooling_device%d", cdev->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1086 | result = device_register(&cdev->device); |
| 1087 | if (result) { |
| 1088 | release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); |
| 1089 | kfree(cdev); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1090 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | /* sys I/F */ |
| 1094 | if (type) { |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 1095 | result = device_create_file(&cdev->device, &dev_attr_cdev_type); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1096 | if (result) |
| 1097 | goto unregister; |
| 1098 | } |
| 1099 | |
| 1100 | result = device_create_file(&cdev->device, &dev_attr_max_state); |
| 1101 | if (result) |
| 1102 | goto unregister; |
| 1103 | |
| 1104 | result = device_create_file(&cdev->device, &dev_attr_cur_state); |
| 1105 | if (result) |
| 1106 | goto unregister; |
| 1107 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1108 | /* Add 'this' new cdev to the global cdev list */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1109 | mutex_lock(&thermal_list_lock); |
| 1110 | list_add(&cdev->node, &thermal_cdev_list); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1111 | mutex_unlock(&thermal_list_lock); |
| 1112 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1113 | /* Update binding information for 'this' new cdev */ |
| 1114 | bind_cdev(cdev); |
| 1115 | |
| 1116 | return cdev; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1117 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1118 | unregister: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1119 | release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); |
| 1120 | device_unregister(&cdev->device); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1121 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1122 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1123 | EXPORT_SYMBOL_GPL(thermal_cooling_device_register); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1124 | |
| 1125 | /** |
| 1126 | * thermal_cooling_device_unregister - removes the registered thermal cooling device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1127 | * @cdev: the thermal cooling device to remove. |
| 1128 | * |
| 1129 | * thermal_cooling_device_unregister() must be called when the device is no |
| 1130 | * longer needed. |
| 1131 | */ |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1132 | void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1133 | { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1134 | int i; |
| 1135 | const struct thermal_zone_params *tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1136 | struct thermal_zone_device *tz; |
| 1137 | struct thermal_cooling_device *pos = NULL; |
| 1138 | |
| 1139 | if (!cdev) |
| 1140 | return; |
| 1141 | |
| 1142 | mutex_lock(&thermal_list_lock); |
| 1143 | list_for_each_entry(pos, &thermal_cdev_list, node) |
| 1144 | if (pos == cdev) |
| 1145 | break; |
| 1146 | if (pos != cdev) { |
| 1147 | /* thermal cooling device not found */ |
| 1148 | mutex_unlock(&thermal_list_lock); |
| 1149 | return; |
| 1150 | } |
| 1151 | list_del(&cdev->node); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1152 | |
| 1153 | /* Unbind all thermal zones associated with 'this' cdev */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1154 | list_for_each_entry(tz, &thermal_tz_list, node) { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1155 | if (tz->ops->unbind) { |
| 1156 | tz->ops->unbind(tz, cdev); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1157 | continue; |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | if (!tz->tzp || !tz->tzp->tbp) |
| 1161 | continue; |
| 1162 | |
| 1163 | tzp = tz->tzp; |
| 1164 | for (i = 0; i < tzp->num_tbps; i++) { |
| 1165 | if (tzp->tbp[i].cdev == cdev) { |
| 1166 | __unbind(tz, tzp->tbp[i].trip_mask, cdev); |
| 1167 | tzp->tbp[i].cdev = NULL; |
| 1168 | } |
| 1169 | } |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1170 | } |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1171 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1172 | mutex_unlock(&thermal_list_lock); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1173 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1174 | if (cdev->type[0]) |
Len Brown | 543a956 | 2008-02-07 16:55:08 -0500 | [diff] [blame] | 1175 | device_remove_file(&cdev->device, &dev_attr_cdev_type); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1176 | device_remove_file(&cdev->device, &dev_attr_max_state); |
| 1177 | device_remove_file(&cdev->device, &dev_attr_cur_state); |
| 1178 | |
| 1179 | release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id); |
| 1180 | device_unregister(&cdev->device); |
| 1181 | return; |
| 1182 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1183 | EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1184 | |
Durgadoss R | dc76548 | 2012-09-18 11:05:00 +0530 | [diff] [blame] | 1185 | void thermal_cdev_update(struct thermal_cooling_device *cdev) |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1186 | { |
| 1187 | struct thermal_instance *instance; |
| 1188 | unsigned long target = 0; |
| 1189 | |
| 1190 | /* cooling device is updated*/ |
| 1191 | if (cdev->updated) |
| 1192 | return; |
| 1193 | |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 1194 | mutex_lock(&cdev->lock); |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1195 | /* Make sure cdev enters the deepest cooling state */ |
| 1196 | list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) { |
| 1197 | if (instance->target == THERMAL_NO_TARGET) |
| 1198 | continue; |
| 1199 | if (instance->target > target) |
| 1200 | target = instance->target; |
| 1201 | } |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 1202 | mutex_unlock(&cdev->lock); |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1203 | cdev->ops->set_cur_state(cdev, target); |
| 1204 | cdev->updated = true; |
| 1205 | } |
Durgadoss R | dc76548 | 2012-09-18 11:05:00 +0530 | [diff] [blame] | 1206 | EXPORT_SYMBOL(thermal_cdev_update); |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 1207 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1208 | /** |
Eduardo Valentin | 7b73c99 | 2013-04-23 21:48:14 +0000 | [diff] [blame] | 1209 | * thermal_notify_framework - Sensor drivers use this API to notify framework |
Durgadoss R | f2b4caa | 2012-09-18 11:05:05 +0530 | [diff] [blame] | 1210 | * @tz: thermal zone device |
| 1211 | * @trip: indicates which trip point has been crossed |
| 1212 | * |
| 1213 | * This function handles the trip events from sensor drivers. It starts |
| 1214 | * throttling the cooling devices according to the policy configured. |
| 1215 | * For CRITICAL and HOT trip points, this notifies the respective drivers, |
| 1216 | * and does actual throttling for other trip points i.e ACTIVE and PASSIVE. |
| 1217 | * The throttling policy is based on the configured platform data; if no |
| 1218 | * platform data is provided, this uses the step_wise throttling policy. |
| 1219 | */ |
Eduardo Valentin | 7b73c99 | 2013-04-23 21:48:14 +0000 | [diff] [blame] | 1220 | void thermal_notify_framework(struct thermal_zone_device *tz, int trip) |
Durgadoss R | f2b4caa | 2012-09-18 11:05:05 +0530 | [diff] [blame] | 1221 | { |
| 1222 | handle_thermal_trip(tz, trip); |
| 1223 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1224 | EXPORT_SYMBOL_GPL(thermal_notify_framework); |
Durgadoss R | f2b4caa | 2012-09-18 11:05:05 +0530 | [diff] [blame] | 1225 | |
| 1226 | /** |
Eduardo Valentin | 269c174 | 2013-04-23 21:48:19 +0000 | [diff] [blame] | 1227 | * create_trip_attrs() - create attributes for trip points |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1228 | * @tz: the thermal zone device |
| 1229 | * @mask: Writeable trip point bitmap. |
Eduardo Valentin | 269c174 | 2013-04-23 21:48:19 +0000 | [diff] [blame] | 1230 | * |
| 1231 | * helper function to instantiate sysfs entries for every trip |
| 1232 | * point and its properties of a struct thermal_zone_device. |
| 1233 | * |
| 1234 | * Return: 0 on success, the proper error value otherwise. |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1235 | */ |
| 1236 | static int create_trip_attrs(struct thermal_zone_device *tz, int mask) |
| 1237 | { |
| 1238 | int indx; |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1239 | int size = sizeof(struct thermal_attr) * tz->trips; |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1240 | |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1241 | tz->trip_type_attrs = kzalloc(size, GFP_KERNEL); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1242 | if (!tz->trip_type_attrs) |
| 1243 | return -ENOMEM; |
| 1244 | |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1245 | tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1246 | if (!tz->trip_temp_attrs) { |
| 1247 | kfree(tz->trip_type_attrs); |
| 1248 | return -ENOMEM; |
| 1249 | } |
| 1250 | |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1251 | if (tz->ops->get_trip_hyst) { |
| 1252 | tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL); |
| 1253 | if (!tz->trip_hyst_attrs) { |
| 1254 | kfree(tz->trip_type_attrs); |
| 1255 | kfree(tz->trip_temp_attrs); |
| 1256 | return -ENOMEM; |
| 1257 | } |
| 1258 | } |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1259 | |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1260 | |
| 1261 | for (indx = 0; indx < tz->trips; indx++) { |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1262 | /* create trip type attribute */ |
| 1263 | snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH, |
| 1264 | "trip_point_%d_type", indx); |
| 1265 | |
| 1266 | sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr); |
| 1267 | tz->trip_type_attrs[indx].attr.attr.name = |
| 1268 | tz->trip_type_attrs[indx].name; |
| 1269 | tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO; |
| 1270 | tz->trip_type_attrs[indx].attr.show = trip_point_type_show; |
| 1271 | |
| 1272 | device_create_file(&tz->device, |
| 1273 | &tz->trip_type_attrs[indx].attr); |
| 1274 | |
| 1275 | /* create trip temp attribute */ |
| 1276 | snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH, |
| 1277 | "trip_point_%d_temp", indx); |
| 1278 | |
| 1279 | sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr); |
| 1280 | tz->trip_temp_attrs[indx].attr.attr.name = |
| 1281 | tz->trip_temp_attrs[indx].name; |
| 1282 | tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO; |
| 1283 | tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show; |
| 1284 | if (mask & (1 << indx)) { |
| 1285 | tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR; |
| 1286 | tz->trip_temp_attrs[indx].attr.store = |
| 1287 | trip_point_temp_store; |
| 1288 | } |
| 1289 | |
| 1290 | device_create_file(&tz->device, |
| 1291 | &tz->trip_temp_attrs[indx].attr); |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1292 | |
| 1293 | /* create Optional trip hyst attribute */ |
| 1294 | if (!tz->ops->get_trip_hyst) |
| 1295 | continue; |
| 1296 | snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH, |
| 1297 | "trip_point_%d_hyst", indx); |
| 1298 | |
| 1299 | sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr); |
| 1300 | tz->trip_hyst_attrs[indx].attr.attr.name = |
| 1301 | tz->trip_hyst_attrs[indx].name; |
| 1302 | tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO; |
| 1303 | tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show; |
| 1304 | if (tz->ops->set_trip_hyst) { |
| 1305 | tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR; |
| 1306 | tz->trip_hyst_attrs[indx].attr.store = |
| 1307 | trip_point_hyst_store; |
| 1308 | } |
| 1309 | |
| 1310 | device_create_file(&tz->device, |
| 1311 | &tz->trip_hyst_attrs[indx].attr); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1312 | } |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | static void remove_trip_attrs(struct thermal_zone_device *tz) |
| 1317 | { |
| 1318 | int indx; |
| 1319 | |
| 1320 | for (indx = 0; indx < tz->trips; indx++) { |
| 1321 | device_remove_file(&tz->device, |
| 1322 | &tz->trip_type_attrs[indx].attr); |
| 1323 | device_remove_file(&tz->device, |
| 1324 | &tz->trip_temp_attrs[indx].attr); |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1325 | if (tz->ops->get_trip_hyst) |
| 1326 | device_remove_file(&tz->device, |
| 1327 | &tz->trip_hyst_attrs[indx].attr); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1328 | } |
| 1329 | kfree(tz->trip_type_attrs); |
| 1330 | kfree(tz->trip_temp_attrs); |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 1331 | kfree(tz->trip_hyst_attrs); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | /** |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1335 | * thermal_zone_device_register() - register a new thermal zone device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1336 | * @type: the thermal zone device type |
| 1337 | * @trips: the number of trip points the thermal zone support |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1338 | * @mask: a bit string indicating the writeablility of trip points |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1339 | * @devdata: private device data |
| 1340 | * @ops: standard thermal zone device callbacks |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 1341 | * @tzp: thermal zone platform parameters |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1342 | * @passive_delay: number of milliseconds to wait between polls when |
| 1343 | * performing passive cooling |
| 1344 | * @polling_delay: number of milliseconds to wait between polls when checking |
| 1345 | * whether trip points have been crossed (0 for interrupt |
| 1346 | * driven systems) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1347 | * |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1348 | * This interface function adds a new thermal zone device (sensor) to |
| 1349 | * /sys/class/thermal folder as thermal_zone[0-*]. It tries to bind all the |
| 1350 | * thermal cooling devices registered at the same time. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1351 | * thermal_zone_device_unregister() must be called when the device is no |
Zhang Rui | 1b7ddb8 | 2012-06-27 09:51:12 +0800 | [diff] [blame] | 1352 | * longer needed. The passive cooling depends on the .get_trend() return value. |
Eduardo Valentin | a00e55f | 2013-04-23 21:48:20 +0000 | [diff] [blame] | 1353 | * |
| 1354 | * Return: a pointer to the created struct thermal_zone_device or an |
| 1355 | * in case of error, an ERR_PTR. Caller must check return value with |
| 1356 | * IS_ERR*() helpers. |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1357 | */ |
Anton Vorontsov | 4b1bf58 | 2012-07-31 04:39:30 -0700 | [diff] [blame] | 1358 | struct thermal_zone_device *thermal_zone_device_register(const char *type, |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1359 | int trips, int mask, void *devdata, |
Alan Cox | 5b275ce | 2010-11-11 15:27:29 +0000 | [diff] [blame] | 1360 | const struct thermal_zone_device_ops *ops, |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 1361 | const struct thermal_zone_params *tzp, |
Zhang Rui | 1b7ddb8 | 2012-06-27 09:51:12 +0800 | [diff] [blame] | 1362 | int passive_delay, int polling_delay) |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1363 | { |
| 1364 | struct thermal_zone_device *tz; |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1365 | enum thermal_trip_type trip_type; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1366 | int result; |
| 1367 | int count; |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1368 | int passive = 0; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1369 | |
Guenter Roeck | 204dd1d | 2012-08-07 22:36:45 -0700 | [diff] [blame] | 1370 | if (type && strlen(type) >= THERMAL_NAME_LENGTH) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1371 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1372 | |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1373 | if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1374 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1375 | |
| 1376 | if (!ops || !ops->get_temp) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1377 | return ERR_PTR(-EINVAL); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1378 | |
Jonghwa Lee | 83720d0 | 2013-05-18 09:50:26 +0000 | [diff] [blame] | 1379 | if (trips > 0 && (!ops->get_trip_type || !ops->get_trip_temp)) |
Eduardo Valentin | 6b2aa51 | 2013-01-02 15:29:42 +0000 | [diff] [blame] | 1380 | return ERR_PTR(-EINVAL); |
| 1381 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1382 | tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL); |
| 1383 | if (!tz) |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1384 | return ERR_PTR(-ENOMEM); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1385 | |
Zhang Rui | 2d37413 | 2012-06-27 10:09:00 +0800 | [diff] [blame] | 1386 | INIT_LIST_HEAD(&tz->thermal_instances); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1387 | idr_init(&tz->idr); |
| 1388 | mutex_init(&tz->lock); |
| 1389 | result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id); |
| 1390 | if (result) { |
| 1391 | kfree(tz); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1392 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Eduardo Valentin | c7a8b9d | 2013-04-23 21:48:12 +0000 | [diff] [blame] | 1395 | strlcpy(tz->type, type ? : "", sizeof(tz->type)); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1396 | tz->ops = ops; |
Durgadoss R | 50125a9 | 2012-09-18 11:04:56 +0530 | [diff] [blame] | 1397 | tz->tzp = tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1398 | tz->device.class = &thermal_class; |
| 1399 | tz->devdata = devdata; |
| 1400 | tz->trips = trips; |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1401 | tz->passive_delay = passive_delay; |
| 1402 | tz->polling_delay = polling_delay; |
| 1403 | |
Kay Sievers | 354655e | 2009-01-06 10:44:37 -0800 | [diff] [blame] | 1404 | dev_set_name(&tz->device, "thermal_zone%d", tz->id); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1405 | result = device_register(&tz->device); |
| 1406 | if (result) { |
| 1407 | release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); |
| 1408 | kfree(tz); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1409 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* sys I/F */ |
| 1413 | if (type) { |
| 1414 | result = device_create_file(&tz->device, &dev_attr_type); |
| 1415 | if (result) |
| 1416 | goto unregister; |
| 1417 | } |
| 1418 | |
| 1419 | result = device_create_file(&tz->device, &dev_attr_temp); |
| 1420 | if (result) |
| 1421 | goto unregister; |
| 1422 | |
| 1423 | if (ops->get_mode) { |
| 1424 | result = device_create_file(&tz->device, &dev_attr_mode); |
| 1425 | if (result) |
| 1426 | goto unregister; |
| 1427 | } |
| 1428 | |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1429 | result = create_trip_attrs(tz, mask); |
| 1430 | if (result) |
| 1431 | goto unregister; |
| 1432 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1433 | for (count = 0; count < trips; count++) { |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1434 | tz->ops->get_trip_type(tz, count, &trip_type); |
| 1435 | if (trip_type == THERMAL_TRIP_PASSIVE) |
| 1436 | passive = 1; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1437 | } |
| 1438 | |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 1439 | if (!passive) { |
| 1440 | result = device_create_file(&tz->device, &dev_attr_passive); |
| 1441 | if (result) |
| 1442 | goto unregister; |
| 1443 | } |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1444 | |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 1445 | #ifdef CONFIG_THERMAL_EMULATION |
| 1446 | result = device_create_file(&tz->device, &dev_attr_emul_temp); |
| 1447 | if (result) |
| 1448 | goto unregister; |
| 1449 | #endif |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 1450 | /* Create policy attribute */ |
| 1451 | result = device_create_file(&tz->device, &dev_attr_policy); |
Matthew Garrett | 03a971a | 2008-12-03 18:00:38 +0000 | [diff] [blame] | 1452 | if (result) |
| 1453 | goto unregister; |
| 1454 | |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 1455 | /* Update 'this' zone's governor information */ |
| 1456 | mutex_lock(&thermal_governor_lock); |
| 1457 | |
| 1458 | if (tz->tzp) |
| 1459 | tz->governor = __find_governor(tz->tzp->governor_name); |
| 1460 | else |
| 1461 | tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR); |
| 1462 | |
| 1463 | mutex_unlock(&thermal_governor_lock); |
| 1464 | |
Zhang Rui | e68b16a | 2008-04-21 16:07:52 +0800 | [diff] [blame] | 1465 | result = thermal_add_hwmon_sysfs(tz); |
| 1466 | if (result) |
| 1467 | goto unregister; |
| 1468 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1469 | mutex_lock(&thermal_list_lock); |
| 1470 | list_add_tail(&tz->node, &thermal_tz_list); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1471 | mutex_unlock(&thermal_list_lock); |
| 1472 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1473 | /* Bind cooling devices for this zone */ |
| 1474 | bind_tz(tz); |
| 1475 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1476 | INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check); |
| 1477 | |
| 1478 | thermal_zone_device_update(tz); |
| 1479 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1480 | if (!result) |
| 1481 | return tz; |
| 1482 | |
Joe Perches | caca8b80 | 2012-03-21 12:55:02 -0700 | [diff] [blame] | 1483 | unregister: |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1484 | release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); |
| 1485 | device_unregister(&tz->device); |
Thomas Sujith | 3e6fda5 | 2008-02-15 00:59:50 -0500 | [diff] [blame] | 1486 | return ERR_PTR(result); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1487 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1488 | EXPORT_SYMBOL_GPL(thermal_zone_device_register); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1489 | |
| 1490 | /** |
| 1491 | * thermal_device_unregister - removes the registered thermal zone device |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1492 | * @tz: the thermal zone device to remove |
| 1493 | */ |
| 1494 | void thermal_zone_device_unregister(struct thermal_zone_device *tz) |
| 1495 | { |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1496 | int i; |
| 1497 | const struct thermal_zone_params *tzp; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1498 | struct thermal_cooling_device *cdev; |
| 1499 | struct thermal_zone_device *pos = NULL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1500 | |
| 1501 | if (!tz) |
| 1502 | return; |
| 1503 | |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1504 | tzp = tz->tzp; |
| 1505 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1506 | mutex_lock(&thermal_list_lock); |
| 1507 | list_for_each_entry(pos, &thermal_tz_list, node) |
| 1508 | if (pos == tz) |
| 1509 | break; |
| 1510 | if (pos != tz) { |
| 1511 | /* thermal zone device not found */ |
| 1512 | mutex_unlock(&thermal_list_lock); |
| 1513 | return; |
| 1514 | } |
| 1515 | list_del(&tz->node); |
Durgadoss R | 7e8ee1e | 2012-09-18 11:04:59 +0530 | [diff] [blame] | 1516 | |
| 1517 | /* Unbind all cdevs associated with 'this' thermal zone */ |
| 1518 | list_for_each_entry(cdev, &thermal_cdev_list, node) { |
| 1519 | if (tz->ops->unbind) { |
| 1520 | tz->ops->unbind(tz, cdev); |
| 1521 | continue; |
| 1522 | } |
| 1523 | |
| 1524 | if (!tzp || !tzp->tbp) |
| 1525 | break; |
| 1526 | |
| 1527 | for (i = 0; i < tzp->num_tbps; i++) { |
| 1528 | if (tzp->tbp[i].cdev == cdev) { |
| 1529 | __unbind(tz, tzp->tbp[i].trip_mask, cdev); |
| 1530 | tzp->tbp[i].cdev = NULL; |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1535 | mutex_unlock(&thermal_list_lock); |
| 1536 | |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 1537 | thermal_zone_device_set_polling(tz, 0); |
| 1538 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1539 | if (tz->type[0]) |
| 1540 | device_remove_file(&tz->device, &dev_attr_type); |
| 1541 | device_remove_file(&tz->device, &dev_attr_temp); |
| 1542 | if (tz->ops->get_mode) |
| 1543 | device_remove_file(&tz->device, &dev_attr_mode); |
Durgadoss R | 5a2c090 | 2012-09-18 11:04:58 +0530 | [diff] [blame] | 1544 | device_remove_file(&tz->device, &dev_attr_policy); |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 1545 | remove_trip_attrs(tz); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 1546 | tz->governor = NULL; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1547 | |
Zhang Rui | e68b16a | 2008-04-21 16:07:52 +0800 | [diff] [blame] | 1548 | thermal_remove_hwmon_sysfs(tz); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1549 | release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id); |
| 1550 | idr_destroy(&tz->idr); |
| 1551 | mutex_destroy(&tz->lock); |
| 1552 | device_unregister(&tz->device); |
| 1553 | return; |
| 1554 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1555 | EXPORT_SYMBOL_GPL(thermal_zone_device_unregister); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1556 | |
Eduardo Valentin | 63c4d91 | 2013-04-05 12:32:28 +0000 | [diff] [blame] | 1557 | /** |
| 1558 | * thermal_zone_get_zone_by_name() - search for a zone and returns its ref |
| 1559 | * @name: thermal zone name to fetch the temperature |
| 1560 | * |
| 1561 | * When only one zone is found with the passed name, returns a reference to it. |
| 1562 | * |
| 1563 | * Return: On success returns a reference to an unique thermal zone with |
| 1564 | * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid |
| 1565 | * paramenters, -ENODEV for not found and -EEXIST for multiple matches). |
| 1566 | */ |
| 1567 | struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name) |
| 1568 | { |
| 1569 | struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL); |
| 1570 | unsigned int found = 0; |
| 1571 | |
| 1572 | if (!name) |
| 1573 | goto exit; |
| 1574 | |
| 1575 | mutex_lock(&thermal_list_lock); |
| 1576 | list_for_each_entry(pos, &thermal_tz_list, node) |
| 1577 | if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) { |
| 1578 | found++; |
| 1579 | ref = pos; |
| 1580 | } |
| 1581 | mutex_unlock(&thermal_list_lock); |
| 1582 | |
| 1583 | /* nothing has been found, thus an error code for it */ |
| 1584 | if (found == 0) |
| 1585 | ref = ERR_PTR(-ENODEV); |
| 1586 | else if (found > 1) |
| 1587 | /* Success only when an unique zone is found */ |
| 1588 | ref = ERR_PTR(-EEXIST); |
| 1589 | |
| 1590 | exit: |
| 1591 | return ref; |
| 1592 | } |
| 1593 | EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name); |
| 1594 | |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1595 | #ifdef CONFIG_NET |
| 1596 | static struct genl_family thermal_event_genl_family = { |
| 1597 | .id = GENL_ID_GENERATE, |
| 1598 | .name = THERMAL_GENL_FAMILY_NAME, |
| 1599 | .version = THERMAL_GENL_VERSION, |
| 1600 | .maxattr = THERMAL_GENL_ATTR_MAX, |
| 1601 | }; |
| 1602 | |
| 1603 | static struct genl_multicast_group thermal_event_mcgrp = { |
| 1604 | .name = THERMAL_GENL_MCAST_GROUP_NAME, |
| 1605 | }; |
| 1606 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1607 | int thermal_generate_netlink_event(struct thermal_zone_device *tz, |
| 1608 | enum events event) |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1609 | { |
| 1610 | struct sk_buff *skb; |
| 1611 | struct nlattr *attr; |
| 1612 | struct thermal_genl_event *thermal_event; |
| 1613 | void *msg_header; |
| 1614 | int size; |
| 1615 | int result; |
Fabio Estevam | b11de07 | 2012-03-21 12:55:00 -0700 | [diff] [blame] | 1616 | static unsigned int thermal_event_seqnum; |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1617 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1618 | if (!tz) |
| 1619 | return -EINVAL; |
| 1620 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1621 | /* allocate memory */ |
Joe Perches | 886ee54 | 2012-03-21 12:55:01 -0700 | [diff] [blame] | 1622 | size = nla_total_size(sizeof(struct thermal_genl_event)) + |
| 1623 | nla_total_size(0); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1624 | |
| 1625 | skb = genlmsg_new(size, GFP_ATOMIC); |
| 1626 | if (!skb) |
| 1627 | return -ENOMEM; |
| 1628 | |
| 1629 | /* add the genetlink message header */ |
| 1630 | msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++, |
| 1631 | &thermal_event_genl_family, 0, |
| 1632 | THERMAL_GENL_CMD_EVENT); |
| 1633 | if (!msg_header) { |
| 1634 | nlmsg_free(skb); |
| 1635 | return -ENOMEM; |
| 1636 | } |
| 1637 | |
| 1638 | /* fill the data */ |
Joe Perches | 886ee54 | 2012-03-21 12:55:01 -0700 | [diff] [blame] | 1639 | attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT, |
| 1640 | sizeof(struct thermal_genl_event)); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1641 | |
| 1642 | if (!attr) { |
| 1643 | nlmsg_free(skb); |
| 1644 | return -EINVAL; |
| 1645 | } |
| 1646 | |
| 1647 | thermal_event = nla_data(attr); |
| 1648 | if (!thermal_event) { |
| 1649 | nlmsg_free(skb); |
| 1650 | return -EINVAL; |
| 1651 | } |
| 1652 | |
| 1653 | memset(thermal_event, 0, sizeof(struct thermal_genl_event)); |
| 1654 | |
Eduardo Valentin | 8ab3e6a | 2013-01-02 15:29:39 +0000 | [diff] [blame] | 1655 | thermal_event->orig = tz->id; |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1656 | thermal_event->event = event; |
| 1657 | |
| 1658 | /* send multicast genetlink message */ |
| 1659 | result = genlmsg_end(skb, msg_header); |
| 1660 | if (result < 0) { |
| 1661 | nlmsg_free(skb); |
| 1662 | return result; |
| 1663 | } |
| 1664 | |
| 1665 | result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC); |
| 1666 | if (result) |
Eduardo Valentin | 923e0b1 | 2013-01-02 15:29:41 +0000 | [diff] [blame] | 1667 | dev_err(&tz->device, "Failed to send netlink event:%d", result); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1668 | |
| 1669 | return result; |
| 1670 | } |
Eduardo Valentin | 910cb1e | 2013-04-23 21:48:15 +0000 | [diff] [blame] | 1671 | EXPORT_SYMBOL_GPL(thermal_generate_netlink_event); |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1672 | |
| 1673 | static int genetlink_init(void) |
| 1674 | { |
| 1675 | int result; |
| 1676 | |
| 1677 | result = genl_register_family(&thermal_event_genl_family); |
| 1678 | if (result) |
| 1679 | return result; |
| 1680 | |
| 1681 | result = genl_register_mc_group(&thermal_event_genl_family, |
| 1682 | &thermal_event_mcgrp); |
| 1683 | if (result) |
| 1684 | genl_unregister_family(&thermal_event_genl_family); |
| 1685 | return result; |
| 1686 | } |
| 1687 | |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 1688 | static void genetlink_exit(void) |
| 1689 | { |
| 1690 | genl_unregister_family(&thermal_event_genl_family); |
| 1691 | } |
| 1692 | #else /* !CONFIG_NET */ |
| 1693 | static inline int genetlink_init(void) { return 0; } |
| 1694 | static inline void genetlink_exit(void) {} |
| 1695 | #endif /* !CONFIG_NET */ |
| 1696 | |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1697 | static int __init thermal_register_governors(void) |
| 1698 | { |
| 1699 | int result; |
| 1700 | |
| 1701 | result = thermal_gov_step_wise_register(); |
| 1702 | if (result) |
| 1703 | return result; |
| 1704 | |
| 1705 | result = thermal_gov_fair_share_register(); |
| 1706 | if (result) |
| 1707 | return result; |
| 1708 | |
| 1709 | return thermal_gov_user_space_register(); |
| 1710 | } |
| 1711 | |
| 1712 | static void thermal_unregister_governors(void) |
| 1713 | { |
| 1714 | thermal_gov_step_wise_unregister(); |
| 1715 | thermal_gov_fair_share_unregister(); |
| 1716 | thermal_gov_user_space_unregister(); |
| 1717 | } |
| 1718 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1719 | static int __init thermal_init(void) |
| 1720 | { |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1721 | int result; |
| 1722 | |
| 1723 | result = thermal_register_governors(); |
| 1724 | if (result) |
| 1725 | goto error; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1726 | |
| 1727 | result = class_register(&thermal_class); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1728 | if (result) |
| 1729 | goto unregister_governors; |
| 1730 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1731 | result = genetlink_init(); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1732 | if (result) |
| 1733 | goto unregister_class; |
| 1734 | |
| 1735 | return 0; |
| 1736 | |
| 1737 | unregister_governors: |
| 1738 | thermal_unregister_governors(); |
| 1739 | unregister_class: |
| 1740 | class_unregister(&thermal_class); |
| 1741 | error: |
| 1742 | idr_destroy(&thermal_tz_idr); |
| 1743 | idr_destroy(&thermal_cdev_idr); |
| 1744 | mutex_destroy(&thermal_idr_lock); |
| 1745 | mutex_destroy(&thermal_list_lock); |
| 1746 | mutex_destroy(&thermal_governor_lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1747 | return result; |
| 1748 | } |
| 1749 | |
| 1750 | static void __exit thermal_exit(void) |
| 1751 | { |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1752 | genetlink_exit(); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1753 | class_unregister(&thermal_class); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1754 | thermal_unregister_governors(); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1755 | idr_destroy(&thermal_tz_idr); |
| 1756 | idr_destroy(&thermal_cdev_idr); |
| 1757 | mutex_destroy(&thermal_idr_lock); |
| 1758 | mutex_destroy(&thermal_list_lock); |
Zhang Rui | 80a26a5 | 2013-03-26 16:38:29 +0800 | [diff] [blame] | 1759 | mutex_destroy(&thermal_governor_lock); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1760 | } |
| 1761 | |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 1762 | fs_initcall(thermal_init); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 1763 | module_exit(thermal_exit); |