blob: 5f6af8ade3249f22e0f95014f369a696ee56bf60 [file] [log] [blame]
Zhang Rui203d3d42008-01-17 15:51:08 +08001/*
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 Perchesc5a01dd2012-03-21 12:55:02 -070026#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
Zhang Rui203d3d42008-01-17 15:51:08 +080028#include <linux/module.h>
29#include <linux/device.h>
30#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Zhang Rui203d3d42008-01-17 15:51:08 +080032#include <linux/kdev_t.h>
33#include <linux/idr.h>
34#include <linux/thermal.h>
Matthew Garrettb1569e92008-12-03 17:55:32 +000035#include <linux/reboot.h>
R.Durgadoss4cb18722010-10-27 03:33:29 +053036#include <net/netlink.h>
37#include <net/genetlink.h>
Zhang Rui203d3d42008-01-17 15:51:08 +080038
Durgadoss R71350db2012-09-18 11:04:53 +053039#include "thermal_core.h"
40
Zhang Rui63c4ec92008-04-21 16:07:13 +080041MODULE_AUTHOR("Zhang Rui");
Zhang Rui203d3d42008-01-17 15:51:08 +080042MODULE_DESCRIPTION("Generic thermal management sysfs support");
Eduardo Valentin6d8d4972013-04-23 21:48:13 +000043MODULE_LICENSE("GPL v2");
Zhang Rui203d3d42008-01-17 15:51:08 +080044
Zhang Rui203d3d42008-01-17 15:51:08 +080045static DEFINE_IDR(thermal_tz_idr);
46static DEFINE_IDR(thermal_cdev_idr);
47static DEFINE_MUTEX(thermal_idr_lock);
48
49static LIST_HEAD(thermal_tz_list);
50static LIST_HEAD(thermal_cdev_list);
Durgadoss Ra4a15482012-09-18 11:04:57 +053051static LIST_HEAD(thermal_governor_list);
52
Zhang Rui203d3d42008-01-17 15:51:08 +080053static DEFINE_MUTEX(thermal_list_lock);
Durgadoss Ra4a15482012-09-18 11:04:57 +053054static DEFINE_MUTEX(thermal_governor_lock);
55
56static struct thermal_governor *__find_governor(const char *name)
57{
58 struct thermal_governor *pos;
59
60 list_for_each_entry(pos, &thermal_governor_list, governor_list)
61 if (!strnicmp(name, pos->name, THERMAL_NAME_LENGTH))
62 return pos;
63
64 return NULL;
65}
66
67int thermal_register_governor(struct thermal_governor *governor)
68{
69 int err;
70 const char *name;
71 struct thermal_zone_device *pos;
72
73 if (!governor)
74 return -EINVAL;
75
76 mutex_lock(&thermal_governor_lock);
77
78 err = -EBUSY;
79 if (__find_governor(governor->name) == NULL) {
80 err = 0;
81 list_add(&governor->governor_list, &thermal_governor_list);
82 }
83
84 mutex_lock(&thermal_list_lock);
85
86 list_for_each_entry(pos, &thermal_tz_list, node) {
87 if (pos->governor)
88 continue;
89 if (pos->tzp)
90 name = pos->tzp->governor_name;
91 else
92 name = DEFAULT_THERMAL_GOVERNOR;
93 if (!strnicmp(name, governor->name, THERMAL_NAME_LENGTH))
94 pos->governor = governor;
95 }
96
97 mutex_unlock(&thermal_list_lock);
98 mutex_unlock(&thermal_governor_lock);
99
100 return err;
101}
Durgadoss Ra4a15482012-09-18 11:04:57 +0530102
103void thermal_unregister_governor(struct thermal_governor *governor)
104{
105 struct thermal_zone_device *pos;
106
107 if (!governor)
108 return;
109
110 mutex_lock(&thermal_governor_lock);
111
112 if (__find_governor(governor->name) == NULL)
113 goto exit;
114
115 mutex_lock(&thermal_list_lock);
116
117 list_for_each_entry(pos, &thermal_tz_list, node) {
118 if (!strnicmp(pos->governor->name, governor->name,
119 THERMAL_NAME_LENGTH))
120 pos->governor = NULL;
121 }
122
123 mutex_unlock(&thermal_list_lock);
124 list_del(&governor->governor_list);
125exit:
126 mutex_unlock(&thermal_governor_lock);
127 return;
128}
Zhang Rui203d3d42008-01-17 15:51:08 +0800129
130static int get_idr(struct idr *idr, struct mutex *lock, int *id)
131{
Tejun Heo6deb69f2013-02-27 17:04:46 -0800132 int ret;
Zhang Rui203d3d42008-01-17 15:51:08 +0800133
134 if (lock)
135 mutex_lock(lock);
Tejun Heo6deb69f2013-02-27 17:04:46 -0800136 ret = idr_alloc(idr, NULL, 0, 0, GFP_KERNEL);
Zhang Rui203d3d42008-01-17 15:51:08 +0800137 if (lock)
138 mutex_unlock(lock);
Tejun Heo6deb69f2013-02-27 17:04:46 -0800139 if (unlikely(ret < 0))
140 return ret;
141 *id = ret;
Zhang Rui203d3d42008-01-17 15:51:08 +0800142 return 0;
143}
144
145static void release_idr(struct idr *idr, struct mutex *lock, int id)
146{
147 if (lock)
148 mutex_lock(lock);
149 idr_remove(idr, id);
150 if (lock)
151 mutex_unlock(lock);
152}
153
Durgadoss R9b4298a2012-09-18 11:04:54 +0530154int get_tz_trend(struct thermal_zone_device *tz, int trip)
155{
156 enum thermal_trend trend;
157
158 if (!tz->ops->get_trend || tz->ops->get_trend(tz, trip, &trend)) {
159 if (tz->temperature > tz->last_temperature)
160 trend = THERMAL_TREND_RAISING;
161 else if (tz->temperature < tz->last_temperature)
162 trend = THERMAL_TREND_DROPPING;
163 else
164 trend = THERMAL_TREND_STABLE;
165 }
166
167 return trend;
168}
169EXPORT_SYMBOL(get_tz_trend);
170
171struct thermal_instance *get_thermal_instance(struct thermal_zone_device *tz,
172 struct thermal_cooling_device *cdev, int trip)
173{
174 struct thermal_instance *pos = NULL;
175 struct thermal_instance *target_instance = NULL;
176
177 mutex_lock(&tz->lock);
178 mutex_lock(&cdev->lock);
179
180 list_for_each_entry(pos, &tz->thermal_instances, tz_node) {
181 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
182 target_instance = pos;
183 break;
184 }
185 }
186
187 mutex_unlock(&cdev->lock);
188 mutex_unlock(&tz->lock);
189
190 return target_instance;
191}
192EXPORT_SYMBOL(get_thermal_instance);
193
Durgadoss R7e8ee1e2012-09-18 11:04:59 +0530194static void print_bind_err_msg(struct thermal_zone_device *tz,
195 struct thermal_cooling_device *cdev, int ret)
196{
197 dev_err(&tz->device, "binding zone %s with cdev %s failed:%d\n",
198 tz->type, cdev->type, ret);
199}
200
201static void __bind(struct thermal_zone_device *tz, int mask,
202 struct thermal_cooling_device *cdev)
203{
204 int i, ret;
205
206 for (i = 0; i < tz->trips; i++) {
207 if (mask & (1 << i)) {
208 ret = thermal_zone_bind_cooling_device(tz, i, cdev,
209 THERMAL_NO_LIMIT, THERMAL_NO_LIMIT);
210 if (ret)
211 print_bind_err_msg(tz, cdev, ret);
212 }
213 }
214}
215
216static void __unbind(struct thermal_zone_device *tz, int mask,
217 struct thermal_cooling_device *cdev)
218{
219 int i;
220
221 for (i = 0; i < tz->trips; i++)
222 if (mask & (1 << i))
223 thermal_zone_unbind_cooling_device(tz, i, cdev);
224}
225
226static void bind_cdev(struct thermal_cooling_device *cdev)
227{
228 int i, ret;
229 const struct thermal_zone_params *tzp;
230 struct thermal_zone_device *pos = NULL;
231
232 mutex_lock(&thermal_list_lock);
233
234 list_for_each_entry(pos, &thermal_tz_list, node) {
235 if (!pos->tzp && !pos->ops->bind)
236 continue;
237
238 if (!pos->tzp && pos->ops->bind) {
239 ret = pos->ops->bind(pos, cdev);
240 if (ret)
241 print_bind_err_msg(pos, cdev, ret);
242 }
243
244 tzp = pos->tzp;
Hugh Dickins791700c2012-09-27 16:48:28 -0700245 if (!tzp || !tzp->tbp)
246 continue;
Durgadoss R7e8ee1e2012-09-18 11:04:59 +0530247
248 for (i = 0; i < tzp->num_tbps; i++) {
249 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
250 continue;
251 if (tzp->tbp[i].match(pos, cdev))
252 continue;
253 tzp->tbp[i].cdev = cdev;
254 __bind(pos, tzp->tbp[i].trip_mask, cdev);
255 }
256 }
257
258 mutex_unlock(&thermal_list_lock);
259}
260
261static void bind_tz(struct thermal_zone_device *tz)
262{
263 int i, ret;
264 struct thermal_cooling_device *pos = NULL;
265 const struct thermal_zone_params *tzp = tz->tzp;
266
267 if (!tzp && !tz->ops->bind)
268 return;
269
270 mutex_lock(&thermal_list_lock);
271
272 /* If there is no platform data, try to use ops->bind */
273 if (!tzp && tz->ops->bind) {
274 list_for_each_entry(pos, &thermal_cdev_list, node) {
275 ret = tz->ops->bind(tz, pos);
276 if (ret)
277 print_bind_err_msg(tz, pos, ret);
278 }
279 goto exit;
280 }
281
Hugh Dickins791700c2012-09-27 16:48:28 -0700282 if (!tzp || !tzp->tbp)
Durgadoss R7e8ee1e2012-09-18 11:04:59 +0530283 goto exit;
284
285 list_for_each_entry(pos, &thermal_cdev_list, node) {
286 for (i = 0; i < tzp->num_tbps; i++) {
287 if (tzp->tbp[i].cdev || !tzp->tbp[i].match)
288 continue;
289 if (tzp->tbp[i].match(tz, pos))
290 continue;
291 tzp->tbp[i].cdev = pos;
292 __bind(tz, tzp->tbp[i].trip_mask, pos);
293 }
294 }
295exit:
296 mutex_unlock(&thermal_list_lock);
297}
298
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530299static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
300 int delay)
301{
302 if (delay > 1000)
303 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
304 round_jiffies(msecs_to_jiffies(delay)));
305 else if (delay)
306 mod_delayed_work(system_freezable_wq, &tz->poll_queue,
307 msecs_to_jiffies(delay));
308 else
309 cancel_delayed_work(&tz->poll_queue);
310}
311
312static void monitor_thermal_zone(struct thermal_zone_device *tz)
313{
314 mutex_lock(&tz->lock);
315
316 if (tz->passive)
317 thermal_zone_device_set_polling(tz, tz->passive_delay);
318 else if (tz->polling_delay)
319 thermal_zone_device_set_polling(tz, tz->polling_delay);
320 else
321 thermal_zone_device_set_polling(tz, 0);
322
323 mutex_unlock(&tz->lock);
324}
325
326static void handle_non_critical_trips(struct thermal_zone_device *tz,
327 int trip, enum thermal_trip_type trip_type)
328{
Zhang Ruid567c682012-12-12 15:23:54 +0800329 if (tz->governor)
330 tz->governor->throttle(tz, trip);
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530331}
332
333static void handle_critical_trips(struct thermal_zone_device *tz,
334 int trip, enum thermal_trip_type trip_type)
335{
336 long trip_temp;
337
338 tz->ops->get_trip_temp(tz, trip, &trip_temp);
339
340 /* If we have not crossed the trip_temp, we do not care. */
341 if (tz->temperature < trip_temp)
342 return;
343
344 if (tz->ops->notify)
345 tz->ops->notify(tz, trip, trip_type);
346
347 if (trip_type == THERMAL_TRIP_CRITICAL) {
Eduardo Valentin923e0b12013-01-02 15:29:41 +0000348 dev_emerg(&tz->device,
349 "critical temperature reached(%d C),shutting down\n",
350 tz->temperature / 1000);
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530351 orderly_poweroff(true);
352 }
353}
354
355static void handle_thermal_trip(struct thermal_zone_device *tz, int trip)
356{
357 enum thermal_trip_type type;
358
359 tz->ops->get_trip_type(tz, trip, &type);
360
361 if (type == THERMAL_TRIP_CRITICAL || type == THERMAL_TRIP_HOT)
362 handle_critical_trips(tz, trip, type);
363 else
364 handle_non_critical_trips(tz, trip, type);
365 /*
366 * Alright, we handled this trip successfully.
367 * So, start monitoring again.
368 */
369 monitor_thermal_zone(tz);
370}
371
Eduardo Valentin837b26b2013-04-05 12:32:29 +0000372/**
373 * thermal_zone_get_temp() - returns its the temperature of thermal zone
374 * @tz: a valid pointer to a struct thermal_zone_device
375 * @temp: a valid pointer to where to store the resulting temperature.
376 *
377 * When a valid thermal zone reference is passed, it will fetch its
378 * temperature and fill @temp.
379 *
380 * Return: On success returns 0, an error code otherwise
381 */
382int thermal_zone_get_temp(struct thermal_zone_device *tz, unsigned long *temp)
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000383{
Eduardo Valentin837b26b2013-04-05 12:32:29 +0000384 int ret = -EINVAL;
Zhang Rui5e20b2e2013-02-06 14:02:12 +0800385#ifdef CONFIG_THERMAL_EMULATION
386 int count;
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000387 unsigned long crit_temp = -1UL;
388 enum thermal_trip_type type;
Zhang Rui5e20b2e2013-02-06 14:02:12 +0800389#endif
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000390
Eduardo Valentin837b26b2013-04-05 12:32:29 +0000391 if (IS_ERR_OR_NULL(tz))
392 goto exit;
393
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000394 mutex_lock(&tz->lock);
395
396 ret = tz->ops->get_temp(tz, temp);
397#ifdef CONFIG_THERMAL_EMULATION
398 if (!tz->emul_temperature)
399 goto skip_emul;
400
401 for (count = 0; count < tz->trips; count++) {
402 ret = tz->ops->get_trip_type(tz, count, &type);
403 if (!ret && type == THERMAL_TRIP_CRITICAL) {
404 ret = tz->ops->get_trip_temp(tz, count, &crit_temp);
405 break;
406 }
407 }
408
409 if (ret)
410 goto skip_emul;
411
412 if (*temp < crit_temp)
413 *temp = tz->emul_temperature;
414skip_emul:
415#endif
416 mutex_unlock(&tz->lock);
Eduardo Valentin837b26b2013-04-05 12:32:29 +0000417exit:
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000418 return ret;
419}
Eduardo Valentin837b26b2013-04-05 12:32:29 +0000420EXPORT_SYMBOL_GPL(thermal_zone_get_temp);
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000421
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530422static void update_temperature(struct thermal_zone_device *tz)
423{
424 long temp;
425 int ret;
426
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000427 ret = thermal_zone_get_temp(tz, &temp);
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530428 if (ret) {
Eduardo Valentin923e0b12013-01-02 15:29:41 +0000429 dev_warn(&tz->device, "failed to read out thermal zone %d\n",
430 tz->id);
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000431 return;
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530432 }
433
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000434 mutex_lock(&tz->lock);
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530435 tz->last_temperature = tz->temperature;
436 tz->temperature = temp;
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530437 mutex_unlock(&tz->lock);
438}
439
440void thermal_zone_device_update(struct thermal_zone_device *tz)
441{
442 int count;
443
444 update_temperature(tz);
445
446 for (count = 0; count < tz->trips; count++)
447 handle_thermal_trip(tz, count);
448}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +0000449EXPORT_SYMBOL_GPL(thermal_zone_device_update);
Durgadoss R0c01ebb2012-09-18 11:05:04 +0530450
451static void thermal_zone_device_check(struct work_struct *work)
452{
453 struct thermal_zone_device *tz = container_of(work, struct
454 thermal_zone_device,
455 poll_queue.work);
456 thermal_zone_device_update(tz);
457}
458
Zhang Rui203d3d42008-01-17 15:51:08 +0800459/* sys I/F for thermal zone */
460
461#define to_thermal_zone(_dev) \
462 container_of(_dev, struct thermal_zone_device, device)
463
464static ssize_t
465type_show(struct device *dev, struct device_attribute *attr, char *buf)
466{
467 struct thermal_zone_device *tz = to_thermal_zone(dev);
468
469 return sprintf(buf, "%s\n", tz->type);
470}
471
472static ssize_t
473temp_show(struct device *dev, struct device_attribute *attr, char *buf)
474{
475 struct thermal_zone_device *tz = to_thermal_zone(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000476 long temperature;
477 int ret;
Zhang Rui203d3d42008-01-17 15:51:08 +0800478
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000479 ret = thermal_zone_get_temp(tz, &temperature);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000480
481 if (ret)
482 return ret;
483
484 return sprintf(buf, "%ld\n", temperature);
Zhang Rui203d3d42008-01-17 15:51:08 +0800485}
486
487static ssize_t
488mode_show(struct device *dev, struct device_attribute *attr, char *buf)
489{
490 struct thermal_zone_device *tz = to_thermal_zone(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000491 enum thermal_device_mode mode;
492 int result;
Zhang Rui203d3d42008-01-17 15:51:08 +0800493
494 if (!tz->ops->get_mode)
495 return -EPERM;
496
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000497 result = tz->ops->get_mode(tz, &mode);
498 if (result)
499 return result;
500
501 return sprintf(buf, "%s\n", mode == THERMAL_DEVICE_ENABLED ? "enabled"
502 : "disabled");
Zhang Rui203d3d42008-01-17 15:51:08 +0800503}
504
505static ssize_t
506mode_store(struct device *dev, struct device_attribute *attr,
507 const char *buf, size_t count)
508{
509 struct thermal_zone_device *tz = to_thermal_zone(dev);
510 int result;
511
512 if (!tz->ops->set_mode)
513 return -EPERM;
514
Amit Daniel Kachhapf1f0e2a2012-03-21 16:40:01 +0530515 if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000516 result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
Amit Daniel Kachhapf1f0e2a2012-03-21 16:40:01 +0530517 else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000518 result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
519 else
520 result = -EINVAL;
521
Zhang Rui203d3d42008-01-17 15:51:08 +0800522 if (result)
523 return result;
524
525 return count;
526}
527
528static ssize_t
529trip_point_type_show(struct device *dev, struct device_attribute *attr,
530 char *buf)
531{
532 struct thermal_zone_device *tz = to_thermal_zone(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000533 enum thermal_trip_type type;
534 int trip, result;
Zhang Rui203d3d42008-01-17 15:51:08 +0800535
536 if (!tz->ops->get_trip_type)
537 return -EPERM;
538
539 if (!sscanf(attr->attr.name, "trip_point_%d_type", &trip))
540 return -EINVAL;
541
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000542 result = tz->ops->get_trip_type(tz, trip, &type);
543 if (result)
544 return result;
545
546 switch (type) {
547 case THERMAL_TRIP_CRITICAL:
Amit Kucheria625120a42009-10-16 12:46:02 +0300548 return sprintf(buf, "critical\n");
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000549 case THERMAL_TRIP_HOT:
Amit Kucheria625120a42009-10-16 12:46:02 +0300550 return sprintf(buf, "hot\n");
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000551 case THERMAL_TRIP_PASSIVE:
Amit Kucheria625120a42009-10-16 12:46:02 +0300552 return sprintf(buf, "passive\n");
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000553 case THERMAL_TRIP_ACTIVE:
Amit Kucheria625120a42009-10-16 12:46:02 +0300554 return sprintf(buf, "active\n");
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000555 default:
Amit Kucheria625120a42009-10-16 12:46:02 +0300556 return sprintf(buf, "unknown\n");
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000557 }
Zhang Rui203d3d42008-01-17 15:51:08 +0800558}
559
560static ssize_t
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800561trip_point_temp_store(struct device *dev, struct device_attribute *attr,
562 const char *buf, size_t count)
563{
564 struct thermal_zone_device *tz = to_thermal_zone(dev);
565 int trip, ret;
566 unsigned long temperature;
567
568 if (!tz->ops->set_trip_temp)
569 return -EPERM;
570
571 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
572 return -EINVAL;
573
574 if (kstrtoul(buf, 10, &temperature))
575 return -EINVAL;
576
577 ret = tz->ops->set_trip_temp(tz, trip, temperature);
578
579 return ret ? ret : count;
580}
581
582static ssize_t
Zhang Rui203d3d42008-01-17 15:51:08 +0800583trip_point_temp_show(struct device *dev, struct device_attribute *attr,
584 char *buf)
585{
586 struct thermal_zone_device *tz = to_thermal_zone(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000587 int trip, ret;
588 long temperature;
Zhang Rui203d3d42008-01-17 15:51:08 +0800589
590 if (!tz->ops->get_trip_temp)
591 return -EPERM;
592
593 if (!sscanf(attr->attr.name, "trip_point_%d_temp", &trip))
594 return -EINVAL;
595
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000596 ret = tz->ops->get_trip_temp(tz, trip, &temperature);
597
598 if (ret)
599 return ret;
600
601 return sprintf(buf, "%ld\n", temperature);
Zhang Rui203d3d42008-01-17 15:51:08 +0800602}
603
Matthew Garrett03a971a2008-12-03 18:00:38 +0000604static ssize_t
Durgadoss R27365a62012-07-25 10:10:59 +0800605trip_point_hyst_store(struct device *dev, struct device_attribute *attr,
606 const char *buf, size_t count)
607{
608 struct thermal_zone_device *tz = to_thermal_zone(dev);
609 int trip, ret;
610 unsigned long temperature;
611
612 if (!tz->ops->set_trip_hyst)
613 return -EPERM;
614
615 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
616 return -EINVAL;
617
618 if (kstrtoul(buf, 10, &temperature))
619 return -EINVAL;
620
621 /*
622 * We are not doing any check on the 'temperature' value
623 * here. The driver implementing 'set_trip_hyst' has to
624 * take care of this.
625 */
626 ret = tz->ops->set_trip_hyst(tz, trip, temperature);
627
628 return ret ? ret : count;
629}
630
631static ssize_t
632trip_point_hyst_show(struct device *dev, struct device_attribute *attr,
633 char *buf)
634{
635 struct thermal_zone_device *tz = to_thermal_zone(dev);
636 int trip, ret;
637 unsigned long temperature;
638
639 if (!tz->ops->get_trip_hyst)
640 return -EPERM;
641
642 if (!sscanf(attr->attr.name, "trip_point_%d_hyst", &trip))
643 return -EINVAL;
644
645 ret = tz->ops->get_trip_hyst(tz, trip, &temperature);
646
647 return ret ? ret : sprintf(buf, "%ld\n", temperature);
648}
649
650static ssize_t
Matthew Garrett03a971a2008-12-03 18:00:38 +0000651passive_store(struct device *dev, struct device_attribute *attr,
652 const char *buf, size_t count)
653{
654 struct thermal_zone_device *tz = to_thermal_zone(dev);
655 struct thermal_cooling_device *cdev = NULL;
656 int state;
657
658 if (!sscanf(buf, "%d\n", &state))
659 return -EINVAL;
660
Frans Pop3d8e3ad2009-10-26 08:39:02 +0100661 /* sanity check: values below 1000 millicelcius don't make sense
662 * and can cause the system to go into a thermal heart attack
663 */
664 if (state && state < 1000)
665 return -EINVAL;
666
Matthew Garrett03a971a2008-12-03 18:00:38 +0000667 if (state && !tz->forced_passive) {
668 mutex_lock(&thermal_list_lock);
669 list_for_each_entry(cdev, &thermal_cdev_list, node) {
670 if (!strncmp("Processor", cdev->type,
671 sizeof("Processor")))
672 thermal_zone_bind_cooling_device(tz,
Zhang Rui9d998422012-06-26 16:35:57 +0800673 THERMAL_TRIPS_NONE, cdev,
674 THERMAL_NO_LIMIT,
675 THERMAL_NO_LIMIT);
Matthew Garrett03a971a2008-12-03 18:00:38 +0000676 }
677 mutex_unlock(&thermal_list_lock);
Frans Pope4143b02009-10-26 08:39:03 +0100678 if (!tz->passive_delay)
679 tz->passive_delay = 1000;
Matthew Garrett03a971a2008-12-03 18:00:38 +0000680 } else if (!state && tz->forced_passive) {
681 mutex_lock(&thermal_list_lock);
682 list_for_each_entry(cdev, &thermal_cdev_list, node) {
683 if (!strncmp("Processor", cdev->type,
684 sizeof("Processor")))
685 thermal_zone_unbind_cooling_device(tz,
686 THERMAL_TRIPS_NONE,
687 cdev);
688 }
689 mutex_unlock(&thermal_list_lock);
Frans Pope4143b02009-10-26 08:39:03 +0100690 tz->passive_delay = 0;
Matthew Garrett03a971a2008-12-03 18:00:38 +0000691 }
692
Matthew Garrett03a971a2008-12-03 18:00:38 +0000693 tz->forced_passive = state;
694
695 thermal_zone_device_update(tz);
696
697 return count;
698}
699
700static ssize_t
701passive_show(struct device *dev, struct device_attribute *attr,
702 char *buf)
703{
704 struct thermal_zone_device *tz = to_thermal_zone(dev);
705
706 return sprintf(buf, "%d\n", tz->forced_passive);
707}
708
Durgadoss R5a2c0902012-09-18 11:04:58 +0530709static ssize_t
710policy_store(struct device *dev, struct device_attribute *attr,
711 const char *buf, size_t count)
712{
713 int ret = -EINVAL;
714 struct thermal_zone_device *tz = to_thermal_zone(dev);
715 struct thermal_governor *gov;
716
717 mutex_lock(&thermal_governor_lock);
718
719 gov = __find_governor(buf);
720 if (!gov)
721 goto exit;
722
723 tz->governor = gov;
724 ret = count;
725
726exit:
727 mutex_unlock(&thermal_governor_lock);
728 return ret;
729}
730
731static ssize_t
732policy_show(struct device *dev, struct device_attribute *devattr, char *buf)
733{
734 struct thermal_zone_device *tz = to_thermal_zone(dev);
735
736 return sprintf(buf, "%s\n", tz->governor->name);
737}
738
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000739#ifdef CONFIG_THERMAL_EMULATION
740static ssize_t
741emul_temp_store(struct device *dev, struct device_attribute *attr,
742 const char *buf, size_t count)
743{
744 struct thermal_zone_device *tz = to_thermal_zone(dev);
745 int ret = 0;
746 unsigned long temperature;
747
748 if (kstrtoul(buf, 10, &temperature))
749 return -EINVAL;
750
751 if (!tz->ops->set_emul_temp) {
752 mutex_lock(&tz->lock);
753 tz->emul_temperature = temperature;
754 mutex_unlock(&tz->lock);
755 } else {
756 ret = tz->ops->set_emul_temp(tz, temperature);
757 }
758
759 return ret ? ret : count;
760}
761static DEVICE_ATTR(emul_temp, S_IWUSR, NULL, emul_temp_store);
762#endif/*CONFIG_THERMAL_EMULATION*/
763
Zhang Rui203d3d42008-01-17 15:51:08 +0800764static DEVICE_ATTR(type, 0444, type_show, NULL);
765static DEVICE_ATTR(temp, 0444, temp_show, NULL);
766static DEVICE_ATTR(mode, 0644, mode_show, mode_store);
Joe Perches886ee542012-03-21 12:55:01 -0700767static DEVICE_ATTR(passive, S_IRUGO | S_IWUSR, passive_show, passive_store);
Durgadoss R5a2c0902012-09-18 11:04:58 +0530768static DEVICE_ATTR(policy, S_IRUGO | S_IWUSR, policy_show, policy_store);
Zhang Rui203d3d42008-01-17 15:51:08 +0800769
Zhang Rui203d3d42008-01-17 15:51:08 +0800770/* sys I/F for cooling device */
771#define to_cooling_device(_dev) \
772 container_of(_dev, struct thermal_cooling_device, device)
773
774static ssize_t
775thermal_cooling_device_type_show(struct device *dev,
776 struct device_attribute *attr, char *buf)
777{
778 struct thermal_cooling_device *cdev = to_cooling_device(dev);
779
780 return sprintf(buf, "%s\n", cdev->type);
781}
782
783static ssize_t
784thermal_cooling_device_max_state_show(struct device *dev,
785 struct device_attribute *attr, char *buf)
786{
787 struct thermal_cooling_device *cdev = to_cooling_device(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000788 unsigned long state;
789 int ret;
Zhang Rui203d3d42008-01-17 15:51:08 +0800790
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000791 ret = cdev->ops->get_max_state(cdev, &state);
792 if (ret)
793 return ret;
794 return sprintf(buf, "%ld\n", state);
Zhang Rui203d3d42008-01-17 15:51:08 +0800795}
796
797static ssize_t
798thermal_cooling_device_cur_state_show(struct device *dev,
799 struct device_attribute *attr, char *buf)
800{
801 struct thermal_cooling_device *cdev = to_cooling_device(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000802 unsigned long state;
803 int ret;
Zhang Rui203d3d42008-01-17 15:51:08 +0800804
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000805 ret = cdev->ops->get_cur_state(cdev, &state);
806 if (ret)
807 return ret;
808 return sprintf(buf, "%ld\n", state);
Zhang Rui203d3d42008-01-17 15:51:08 +0800809}
810
811static ssize_t
812thermal_cooling_device_cur_state_store(struct device *dev,
813 struct device_attribute *attr,
814 const char *buf, size_t count)
815{
816 struct thermal_cooling_device *cdev = to_cooling_device(dev);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000817 unsigned long state;
Zhang Rui203d3d42008-01-17 15:51:08 +0800818 int result;
819
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000820 if (!sscanf(buf, "%ld\n", &state))
Zhang Rui203d3d42008-01-17 15:51:08 +0800821 return -EINVAL;
822
Roel Kluinedb94912009-12-15 22:46:50 +0100823 if ((long)state < 0)
Zhang Rui203d3d42008-01-17 15:51:08 +0800824 return -EINVAL;
825
826 result = cdev->ops->set_cur_state(cdev, state);
827 if (result)
828 return result;
829 return count;
830}
831
832static struct device_attribute dev_attr_cdev_type =
Len Brown543a9562008-02-07 16:55:08 -0500833__ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
Zhang Rui203d3d42008-01-17 15:51:08 +0800834static DEVICE_ATTR(max_state, 0444,
835 thermal_cooling_device_max_state_show, NULL);
836static DEVICE_ATTR(cur_state, 0644,
837 thermal_cooling_device_cur_state_show,
838 thermal_cooling_device_cur_state_store);
839
840static ssize_t
841thermal_cooling_device_trip_point_show(struct device *dev,
Len Brown543a9562008-02-07 16:55:08 -0500842 struct device_attribute *attr, char *buf)
Zhang Rui203d3d42008-01-17 15:51:08 +0800843{
Zhang Ruib81b6ba2012-06-27 10:08:19 +0800844 struct thermal_instance *instance;
Zhang Rui203d3d42008-01-17 15:51:08 +0800845
846 instance =
Zhang Ruib81b6ba2012-06-27 10:08:19 +0800847 container_of(attr, struct thermal_instance, attr);
Zhang Rui203d3d42008-01-17 15:51:08 +0800848
849 if (instance->trip == THERMAL_TRIPS_NONE)
850 return sprintf(buf, "-1\n");
851 else
852 return sprintf(buf, "%d\n", instance->trip);
853}
854
855/* Device management */
856
Rene Herman16d75232008-06-24 19:38:56 +0200857#if defined(CONFIG_THERMAL_HWMON)
858
Zhang Ruie68b16a2008-04-21 16:07:52 +0800859/* hwmon sys I/F */
860#include <linux/hwmon.h>
Jean Delvare31f53962011-07-28 13:48:42 -0700861
862/* thermal zone devices with the same type share one hwmon device */
863struct thermal_hwmon_device {
864 char type[THERMAL_NAME_LENGTH];
865 struct device *device;
866 int count;
867 struct list_head tz_list;
868 struct list_head node;
869};
870
871struct thermal_hwmon_attr {
872 struct device_attribute attr;
873 char name[16];
874};
875
876/* one temperature input for each thermal zone */
877struct thermal_hwmon_temp {
878 struct list_head hwmon_node;
879 struct thermal_zone_device *tz;
880 struct thermal_hwmon_attr temp_input; /* hwmon sys attr */
881 struct thermal_hwmon_attr temp_crit; /* hwmon sys attr */
882};
883
Zhang Ruie68b16a2008-04-21 16:07:52 +0800884static LIST_HEAD(thermal_hwmon_list);
885
886static ssize_t
887name_show(struct device *dev, struct device_attribute *attr, char *buf)
888{
Greg Kroah-Hartman0e968a32009-04-30 14:43:31 -0700889 struct thermal_hwmon_device *hwmon = dev_get_drvdata(dev);
Zhang Ruie68b16a2008-04-21 16:07:52 +0800890 return sprintf(buf, "%s\n", hwmon->type);
891}
892static DEVICE_ATTR(name, 0444, name_show, NULL);
893
894static ssize_t
895temp_input_show(struct device *dev, struct device_attribute *attr, char *buf)
896{
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000897 long temperature;
898 int ret;
Zhang Ruie68b16a2008-04-21 16:07:52 +0800899 struct thermal_hwmon_attr *hwmon_attr
900 = container_of(attr, struct thermal_hwmon_attr, attr);
Jean Delvare31f53962011-07-28 13:48:42 -0700901 struct thermal_hwmon_temp *temp
902 = container_of(hwmon_attr, struct thermal_hwmon_temp,
Zhang Ruie68b16a2008-04-21 16:07:52 +0800903 temp_input);
Jean Delvare31f53962011-07-28 13:48:42 -0700904 struct thermal_zone_device *tz = temp->tz;
Zhang Ruie68b16a2008-04-21 16:07:52 +0800905
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000906 ret = thermal_zone_get_temp(tz, &temperature);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000907
908 if (ret)
909 return ret;
910
911 return sprintf(buf, "%ld\n", temperature);
Zhang Ruie68b16a2008-04-21 16:07:52 +0800912}
913
914static ssize_t
915temp_crit_show(struct device *dev, struct device_attribute *attr,
916 char *buf)
917{
918 struct thermal_hwmon_attr *hwmon_attr
919 = container_of(attr, struct thermal_hwmon_attr, attr);
Jean Delvare31f53962011-07-28 13:48:42 -0700920 struct thermal_hwmon_temp *temp
921 = container_of(hwmon_attr, struct thermal_hwmon_temp,
Zhang Ruie68b16a2008-04-21 16:07:52 +0800922 temp_crit);
Jean Delvare31f53962011-07-28 13:48:42 -0700923 struct thermal_zone_device *tz = temp->tz;
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000924 long temperature;
925 int ret;
Zhang Ruie68b16a2008-04-21 16:07:52 +0800926
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000927 ret = tz->ops->get_trip_temp(tz, 0, &temperature);
928 if (ret)
929 return ret;
930
931 return sprintf(buf, "%ld\n", temperature);
Zhang Ruie68b16a2008-04-21 16:07:52 +0800932}
933
934
Jean Delvare0d97d7a2011-07-28 13:48:41 -0700935static struct thermal_hwmon_device *
936thermal_hwmon_lookup_by_type(const struct thermal_zone_device *tz)
937{
938 struct thermal_hwmon_device *hwmon;
939
940 mutex_lock(&thermal_list_lock);
941 list_for_each_entry(hwmon, &thermal_hwmon_list, node)
942 if (!strcmp(hwmon->type, tz->type)) {
943 mutex_unlock(&thermal_list_lock);
944 return hwmon;
945 }
946 mutex_unlock(&thermal_list_lock);
947
948 return NULL;
949}
950
Jean Delvare31f53962011-07-28 13:48:42 -0700951/* Find the temperature input matching a given thermal zone */
952static struct thermal_hwmon_temp *
953thermal_hwmon_lookup_temp(const struct thermal_hwmon_device *hwmon,
954 const struct thermal_zone_device *tz)
955{
956 struct thermal_hwmon_temp *temp;
957
958 mutex_lock(&thermal_list_lock);
959 list_for_each_entry(temp, &hwmon->tz_list, hwmon_node)
960 if (temp->tz == tz) {
961 mutex_unlock(&thermal_list_lock);
962 return temp;
963 }
964 mutex_unlock(&thermal_list_lock);
965
966 return NULL;
967}
968
Zhang Ruie68b16a2008-04-21 16:07:52 +0800969static int
970thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
971{
972 struct thermal_hwmon_device *hwmon;
Jean Delvare31f53962011-07-28 13:48:42 -0700973 struct thermal_hwmon_temp *temp;
Zhang Ruie68b16a2008-04-21 16:07:52 +0800974 int new_hwmon_device = 1;
975 int result;
976
Jean Delvare0d97d7a2011-07-28 13:48:41 -0700977 hwmon = thermal_hwmon_lookup_by_type(tz);
978 if (hwmon) {
979 new_hwmon_device = 0;
980 goto register_sys_interface;
981 }
Zhang Ruie68b16a2008-04-21 16:07:52 +0800982
983 hwmon = kzalloc(sizeof(struct thermal_hwmon_device), GFP_KERNEL);
984 if (!hwmon)
985 return -ENOMEM;
986
987 INIT_LIST_HEAD(&hwmon->tz_list);
988 strlcpy(hwmon->type, tz->type, THERMAL_NAME_LENGTH);
989 hwmon->device = hwmon_device_register(NULL);
990 if (IS_ERR(hwmon->device)) {
991 result = PTR_ERR(hwmon->device);
992 goto free_mem;
993 }
Greg Kroah-Hartman0e968a32009-04-30 14:43:31 -0700994 dev_set_drvdata(hwmon->device, hwmon);
Zhang Ruie68b16a2008-04-21 16:07:52 +0800995 result = device_create_file(hwmon->device, &dev_attr_name);
996 if (result)
Durgadoss Rb299eb52011-03-03 04:30:13 +0530997 goto free_mem;
Zhang Ruie68b16a2008-04-21 16:07:52 +0800998
999 register_sys_interface:
Jean Delvare31f53962011-07-28 13:48:42 -07001000 temp = kzalloc(sizeof(struct thermal_hwmon_temp), GFP_KERNEL);
1001 if (!temp) {
1002 result = -ENOMEM;
1003 goto unregister_name;
1004 }
1005
1006 temp->tz = tz;
Zhang Ruie68b16a2008-04-21 16:07:52 +08001007 hwmon->count++;
1008
Guenter Roeck79a49162012-07-21 10:53:48 +10001009 snprintf(temp->temp_input.name, sizeof(temp->temp_input.name),
Zhang Ruie68b16a2008-04-21 16:07:52 +08001010 "temp%d_input", hwmon->count);
Jean Delvare31f53962011-07-28 13:48:42 -07001011 temp->temp_input.attr.attr.name = temp->temp_input.name;
1012 temp->temp_input.attr.attr.mode = 0444;
1013 temp->temp_input.attr.show = temp_input_show;
1014 sysfs_attr_init(&temp->temp_input.attr.attr);
1015 result = device_create_file(hwmon->device, &temp->temp_input.attr);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001016 if (result)
Jean Delvare31f53962011-07-28 13:48:42 -07001017 goto free_temp_mem;
Zhang Ruie68b16a2008-04-21 16:07:52 +08001018
1019 if (tz->ops->get_crit_temp) {
1020 unsigned long temperature;
1021 if (!tz->ops->get_crit_temp(tz, &temperature)) {
Guenter Roeck79a49162012-07-21 10:53:48 +10001022 snprintf(temp->temp_crit.name,
1023 sizeof(temp->temp_crit.name),
Zhang Ruie68b16a2008-04-21 16:07:52 +08001024 "temp%d_crit", hwmon->count);
Jean Delvare31f53962011-07-28 13:48:42 -07001025 temp->temp_crit.attr.attr.name = temp->temp_crit.name;
1026 temp->temp_crit.attr.attr.mode = 0444;
1027 temp->temp_crit.attr.show = temp_crit_show;
1028 sysfs_attr_init(&temp->temp_crit.attr.attr);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001029 result = device_create_file(hwmon->device,
Jean Delvare31f53962011-07-28 13:48:42 -07001030 &temp->temp_crit.attr);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001031 if (result)
Durgadoss Rb299eb52011-03-03 04:30:13 +05301032 goto unregister_input;
Zhang Ruie68b16a2008-04-21 16:07:52 +08001033 }
1034 }
1035
1036 mutex_lock(&thermal_list_lock);
1037 if (new_hwmon_device)
1038 list_add_tail(&hwmon->node, &thermal_hwmon_list);
Jean Delvare31f53962011-07-28 13:48:42 -07001039 list_add_tail(&temp->hwmon_node, &hwmon->tz_list);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001040 mutex_unlock(&thermal_list_lock);
1041
1042 return 0;
1043
Durgadoss Rb299eb52011-03-03 04:30:13 +05301044 unregister_input:
Jean Delvare31f53962011-07-28 13:48:42 -07001045 device_remove_file(hwmon->device, &temp->temp_input.attr);
1046 free_temp_mem:
1047 kfree(temp);
Durgadoss Rb299eb52011-03-03 04:30:13 +05301048 unregister_name:
Zhang Ruie68b16a2008-04-21 16:07:52 +08001049 if (new_hwmon_device) {
1050 device_remove_file(hwmon->device, &dev_attr_name);
1051 hwmon_device_unregister(hwmon->device);
1052 }
1053 free_mem:
1054 if (new_hwmon_device)
1055 kfree(hwmon);
1056
1057 return result;
1058}
1059
1060static void
1061thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
1062{
Jean Delvare31f53962011-07-28 13:48:42 -07001063 struct thermal_hwmon_device *hwmon;
1064 struct thermal_hwmon_temp *temp;
Zhang Ruie68b16a2008-04-21 16:07:52 +08001065
Jean Delvare31f53962011-07-28 13:48:42 -07001066 hwmon = thermal_hwmon_lookup_by_type(tz);
1067 if (unlikely(!hwmon)) {
1068 /* Should never happen... */
1069 dev_dbg(&tz->device, "hwmon device lookup failed!\n");
1070 return;
1071 }
1072
1073 temp = thermal_hwmon_lookup_temp(hwmon, tz);
1074 if (unlikely(!temp)) {
1075 /* Should never happen... */
1076 dev_dbg(&tz->device, "temperature input lookup failed!\n");
1077 return;
1078 }
1079
1080 device_remove_file(hwmon->device, &temp->temp_input.attr);
Durgadoss Rb299eb52011-03-03 04:30:13 +05301081 if (tz->ops->get_crit_temp)
Jean Delvare31f53962011-07-28 13:48:42 -07001082 device_remove_file(hwmon->device, &temp->temp_crit.attr);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001083
1084 mutex_lock(&thermal_list_lock);
Jean Delvare31f53962011-07-28 13:48:42 -07001085 list_del(&temp->hwmon_node);
1086 kfree(temp);
Zhang Ruie68b16a2008-04-21 16:07:52 +08001087 if (!list_empty(&hwmon->tz_list)) {
1088 mutex_unlock(&thermal_list_lock);
1089 return;
1090 }
1091 list_del(&hwmon->node);
1092 mutex_unlock(&thermal_list_lock);
1093
1094 device_remove_file(hwmon->device, &dev_attr_name);
1095 hwmon_device_unregister(hwmon->device);
1096 kfree(hwmon);
1097}
1098#else
1099static int
1100thermal_add_hwmon_sysfs(struct thermal_zone_device *tz)
1101{
1102 return 0;
1103}
1104
1105static void
1106thermal_remove_hwmon_sysfs(struct thermal_zone_device *tz)
1107{
1108}
1109#endif
1110
Zhang Rui203d3d42008-01-17 15:51:08 +08001111/**
Eduardo Valentind2e4eb82013-04-23 21:48:16 +00001112 * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
1113 * @tz: pointer to struct thermal_zone_device
Zhang Rui203d3d42008-01-17 15:51:08 +08001114 * @trip: indicates which trip point the cooling devices is
1115 * associated with in this thermal zone.
Eduardo Valentind2e4eb82013-04-23 21:48:16 +00001116 * @cdev: pointer to struct thermal_cooling_device
1117 * @upper: the Maximum cooling state for this trip point.
1118 * THERMAL_NO_LIMIT means no upper limit,
1119 * and the cooling device can be in max_state.
1120 * @lower: the Minimum cooling state can be used for this trip point.
1121 * THERMAL_NO_LIMIT means no lower limit,
1122 * and the cooling device can be in cooling state 0.
Len Brown543a9562008-02-07 16:55:08 -05001123 *
Eduardo Valentind2e4eb82013-04-23 21:48:16 +00001124 * This interface function bind a thermal cooling device to the certain trip
1125 * point of a thermal zone device.
Len Brown543a9562008-02-07 16:55:08 -05001126 * This function is usually called in the thermal zone device .bind callback.
Eduardo Valentind2e4eb82013-04-23 21:48:16 +00001127 *
1128 * Return: 0 on success, the proper error value otherwise.
Zhang Rui203d3d42008-01-17 15:51:08 +08001129 */
1130int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
1131 int trip,
Zhang Rui9d998422012-06-26 16:35:57 +08001132 struct thermal_cooling_device *cdev,
1133 unsigned long upper, unsigned long lower)
Zhang Rui203d3d42008-01-17 15:51:08 +08001134{
Zhang Ruib81b6ba2012-06-27 10:08:19 +08001135 struct thermal_instance *dev;
1136 struct thermal_instance *pos;
Thomas Sujithc7516702008-02-15 00:58:50 -05001137 struct thermal_zone_device *pos1;
1138 struct thermal_cooling_device *pos2;
Zhang Rui74051ba2012-06-26 16:27:22 +08001139 unsigned long max_state;
Zhang Rui203d3d42008-01-17 15:51:08 +08001140 int result;
1141
Len Brown543a9562008-02-07 16:55:08 -05001142 if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
Zhang Rui203d3d42008-01-17 15:51:08 +08001143 return -EINVAL;
1144
Thomas Sujithc7516702008-02-15 00:58:50 -05001145 list_for_each_entry(pos1, &thermal_tz_list, node) {
1146 if (pos1 == tz)
1147 break;
1148 }
1149 list_for_each_entry(pos2, &thermal_cdev_list, node) {
1150 if (pos2 == cdev)
1151 break;
1152 }
1153
1154 if (tz != pos1 || cdev != pos2)
Zhang Rui203d3d42008-01-17 15:51:08 +08001155 return -EINVAL;
1156
Zhang Rui9d998422012-06-26 16:35:57 +08001157 cdev->ops->get_max_state(cdev, &max_state);
1158
1159 /* lower default 0, upper default max_state */
1160 lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
1161 upper = upper == THERMAL_NO_LIMIT ? max_state : upper;
1162
1163 if (lower > upper || upper > max_state)
1164 return -EINVAL;
1165
Zhang Rui203d3d42008-01-17 15:51:08 +08001166 dev =
Zhang Ruib81b6ba2012-06-27 10:08:19 +08001167 kzalloc(sizeof(struct thermal_instance), GFP_KERNEL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001168 if (!dev)
1169 return -ENOMEM;
1170 dev->tz = tz;
1171 dev->cdev = cdev;
1172 dev->trip = trip;
Zhang Rui9d998422012-06-26 16:35:57 +08001173 dev->upper = upper;
1174 dev->lower = lower;
Zhang Ruice119f82012-06-27 14:13:04 +08001175 dev->target = THERMAL_NO_TARGET;
Zhang Rui74051ba2012-06-26 16:27:22 +08001176
Zhang Rui203d3d42008-01-17 15:51:08 +08001177 result = get_idr(&tz->idr, &tz->lock, &dev->id);
1178 if (result)
1179 goto free_mem;
1180
1181 sprintf(dev->name, "cdev%d", dev->id);
1182 result =
1183 sysfs_create_link(&tz->device.kobj, &cdev->device.kobj, dev->name);
1184 if (result)
1185 goto release_idr;
1186
1187 sprintf(dev->attr_name, "cdev%d_trip_point", dev->id);
Sergey Senozhatsky975f8c52010-04-06 14:34:51 -07001188 sysfs_attr_init(&dev->attr.attr);
Zhang Rui203d3d42008-01-17 15:51:08 +08001189 dev->attr.attr.name = dev->attr_name;
1190 dev->attr.attr.mode = 0444;
1191 dev->attr.show = thermal_cooling_device_trip_point_show;
1192 result = device_create_file(&tz->device, &dev->attr);
1193 if (result)
1194 goto remove_symbol_link;
1195
1196 mutex_lock(&tz->lock);
Zhang Ruif4a821c2012-07-24 16:56:21 +08001197 mutex_lock(&cdev->lock);
Zhang Ruicddf31b2012-06-27 10:09:36 +08001198 list_for_each_entry(pos, &tz->thermal_instances, tz_node)
Zhang Rui203d3d42008-01-17 15:51:08 +08001199 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
1200 result = -EEXIST;
1201 break;
1202 }
Zhang Ruib5e4ae62012-06-27 14:11:52 +08001203 if (!result) {
Zhang Ruicddf31b2012-06-27 10:09:36 +08001204 list_add_tail(&dev->tz_node, &tz->thermal_instances);
Zhang Ruib5e4ae62012-06-27 14:11:52 +08001205 list_add_tail(&dev->cdev_node, &cdev->thermal_instances);
1206 }
Zhang Ruif4a821c2012-07-24 16:56:21 +08001207 mutex_unlock(&cdev->lock);
Zhang Rui203d3d42008-01-17 15:51:08 +08001208 mutex_unlock(&tz->lock);
1209
1210 if (!result)
1211 return 0;
1212
1213 device_remove_file(&tz->device, &dev->attr);
Joe Perchescaca8b82012-03-21 12:55:02 -07001214remove_symbol_link:
Zhang Rui203d3d42008-01-17 15:51:08 +08001215 sysfs_remove_link(&tz->device.kobj, dev->name);
Joe Perchescaca8b82012-03-21 12:55:02 -07001216release_idr:
Zhang Rui203d3d42008-01-17 15:51:08 +08001217 release_idr(&tz->idr, &tz->lock, dev->id);
Joe Perchescaca8b82012-03-21 12:55:02 -07001218free_mem:
Zhang Rui203d3d42008-01-17 15:51:08 +08001219 kfree(dev);
1220 return result;
1221}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001222EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
Zhang Rui203d3d42008-01-17 15:51:08 +08001223
1224/**
1225 * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
Zhang Rui203d3d42008-01-17 15:51:08 +08001226 * @tz: thermal zone device
1227 * @trip: indicates which trip point the cooling devices is
1228 * associated with in this thermal zone.
1229 * @cdev: thermal cooling device
Len Brown543a9562008-02-07 16:55:08 -05001230 *
1231 * This function is usually called in the thermal zone device .unbind callback.
Zhang Rui203d3d42008-01-17 15:51:08 +08001232 */
1233int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
1234 int trip,
1235 struct thermal_cooling_device *cdev)
1236{
Zhang Ruib81b6ba2012-06-27 10:08:19 +08001237 struct thermal_instance *pos, *next;
Zhang Rui203d3d42008-01-17 15:51:08 +08001238
1239 mutex_lock(&tz->lock);
Zhang Ruif4a821c2012-07-24 16:56:21 +08001240 mutex_lock(&cdev->lock);
Zhang Ruicddf31b2012-06-27 10:09:36 +08001241 list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
Len Brown543a9562008-02-07 16:55:08 -05001242 if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
Zhang Ruicddf31b2012-06-27 10:09:36 +08001243 list_del(&pos->tz_node);
Zhang Ruib5e4ae62012-06-27 14:11:52 +08001244 list_del(&pos->cdev_node);
Zhang Ruif4a821c2012-07-24 16:56:21 +08001245 mutex_unlock(&cdev->lock);
Zhang Rui203d3d42008-01-17 15:51:08 +08001246 mutex_unlock(&tz->lock);
1247 goto unbind;
1248 }
1249 }
Zhang Ruif4a821c2012-07-24 16:56:21 +08001250 mutex_unlock(&cdev->lock);
Zhang Rui203d3d42008-01-17 15:51:08 +08001251 mutex_unlock(&tz->lock);
1252
1253 return -ENODEV;
1254
Joe Perchescaca8b82012-03-21 12:55:02 -07001255unbind:
Zhang Rui203d3d42008-01-17 15:51:08 +08001256 device_remove_file(&tz->device, &pos->attr);
1257 sysfs_remove_link(&tz->device.kobj, pos->name);
1258 release_idr(&tz->idr, &tz->lock, pos->id);
1259 kfree(pos);
1260 return 0;
1261}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001262EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
Zhang Rui203d3d42008-01-17 15:51:08 +08001263
1264static void thermal_release(struct device *dev)
1265{
1266 struct thermal_zone_device *tz;
1267 struct thermal_cooling_device *cdev;
1268
Joe Perchescaca8b82012-03-21 12:55:02 -07001269 if (!strncmp(dev_name(dev), "thermal_zone",
1270 sizeof("thermal_zone") - 1)) {
Zhang Rui203d3d42008-01-17 15:51:08 +08001271 tz = to_thermal_zone(dev);
1272 kfree(tz);
1273 } else {
1274 cdev = to_cooling_device(dev);
1275 kfree(cdev);
1276 }
1277}
1278
1279static struct class thermal_class = {
1280 .name = "thermal",
1281 .dev_release = thermal_release,
1282};
1283
1284/**
1285 * thermal_cooling_device_register - register a new thermal cooling device
1286 * @type: the thermal cooling device type.
1287 * @devdata: device private data.
1288 * @ops: standard thermal cooling devices callbacks.
1289 */
Joe Perchescaca8b82012-03-21 12:55:02 -07001290struct thermal_cooling_device *
1291thermal_cooling_device_register(char *type, void *devdata,
1292 const struct thermal_cooling_device_ops *ops)
Zhang Rui203d3d42008-01-17 15:51:08 +08001293{
1294 struct thermal_cooling_device *cdev;
Zhang Rui203d3d42008-01-17 15:51:08 +08001295 int result;
1296
Guenter Roeck204dd1d2012-08-07 22:36:45 -07001297 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001298 return ERR_PTR(-EINVAL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001299
1300 if (!ops || !ops->get_max_state || !ops->get_cur_state ||
Len Brown543a9562008-02-07 16:55:08 -05001301 !ops->set_cur_state)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001302 return ERR_PTR(-EINVAL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001303
1304 cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
1305 if (!cdev)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001306 return ERR_PTR(-ENOMEM);
Zhang Rui203d3d42008-01-17 15:51:08 +08001307
1308 result = get_idr(&thermal_cdev_idr, &thermal_idr_lock, &cdev->id);
1309 if (result) {
1310 kfree(cdev);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001311 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001312 }
1313
Eduardo Valentinc7a8b9d2013-04-23 21:48:12 +00001314 strlcpy(cdev->type, type ? : "", sizeof(cdev->type));
Zhang Ruif4a821c2012-07-24 16:56:21 +08001315 mutex_init(&cdev->lock);
Zhang Ruib5e4ae62012-06-27 14:11:52 +08001316 INIT_LIST_HEAD(&cdev->thermal_instances);
Zhang Rui203d3d42008-01-17 15:51:08 +08001317 cdev->ops = ops;
Zhang Ruice119f82012-06-27 14:13:04 +08001318 cdev->updated = true;
Zhang Rui203d3d42008-01-17 15:51:08 +08001319 cdev->device.class = &thermal_class;
1320 cdev->devdata = devdata;
Kay Sievers354655e2009-01-06 10:44:37 -08001321 dev_set_name(&cdev->device, "cooling_device%d", cdev->id);
Zhang Rui203d3d42008-01-17 15:51:08 +08001322 result = device_register(&cdev->device);
1323 if (result) {
1324 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1325 kfree(cdev);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001326 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001327 }
1328
1329 /* sys I/F */
1330 if (type) {
Len Brown543a9562008-02-07 16:55:08 -05001331 result = device_create_file(&cdev->device, &dev_attr_cdev_type);
Zhang Rui203d3d42008-01-17 15:51:08 +08001332 if (result)
1333 goto unregister;
1334 }
1335
1336 result = device_create_file(&cdev->device, &dev_attr_max_state);
1337 if (result)
1338 goto unregister;
1339
1340 result = device_create_file(&cdev->device, &dev_attr_cur_state);
1341 if (result)
1342 goto unregister;
1343
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301344 /* Add 'this' new cdev to the global cdev list */
Zhang Rui203d3d42008-01-17 15:51:08 +08001345 mutex_lock(&thermal_list_lock);
1346 list_add(&cdev->node, &thermal_cdev_list);
Zhang Rui203d3d42008-01-17 15:51:08 +08001347 mutex_unlock(&thermal_list_lock);
1348
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301349 /* Update binding information for 'this' new cdev */
1350 bind_cdev(cdev);
1351
1352 return cdev;
Zhang Rui203d3d42008-01-17 15:51:08 +08001353
Joe Perchescaca8b82012-03-21 12:55:02 -07001354unregister:
Zhang Rui203d3d42008-01-17 15:51:08 +08001355 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1356 device_unregister(&cdev->device);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001357 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001358}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001359EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
Zhang Rui203d3d42008-01-17 15:51:08 +08001360
1361/**
1362 * thermal_cooling_device_unregister - removes the registered thermal cooling device
Zhang Rui203d3d42008-01-17 15:51:08 +08001363 * @cdev: the thermal cooling device to remove.
1364 *
1365 * thermal_cooling_device_unregister() must be called when the device is no
1366 * longer needed.
1367 */
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301368void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
Zhang Rui203d3d42008-01-17 15:51:08 +08001369{
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301370 int i;
1371 const struct thermal_zone_params *tzp;
Zhang Rui203d3d42008-01-17 15:51:08 +08001372 struct thermal_zone_device *tz;
1373 struct thermal_cooling_device *pos = NULL;
1374
1375 if (!cdev)
1376 return;
1377
1378 mutex_lock(&thermal_list_lock);
1379 list_for_each_entry(pos, &thermal_cdev_list, node)
1380 if (pos == cdev)
1381 break;
1382 if (pos != cdev) {
1383 /* thermal cooling device not found */
1384 mutex_unlock(&thermal_list_lock);
1385 return;
1386 }
1387 list_del(&cdev->node);
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301388
1389 /* Unbind all thermal zones associated with 'this' cdev */
Zhang Rui203d3d42008-01-17 15:51:08 +08001390 list_for_each_entry(tz, &thermal_tz_list, node) {
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301391 if (tz->ops->unbind) {
1392 tz->ops->unbind(tz, cdev);
Zhang Rui203d3d42008-01-17 15:51:08 +08001393 continue;
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301394 }
1395
1396 if (!tz->tzp || !tz->tzp->tbp)
1397 continue;
1398
1399 tzp = tz->tzp;
1400 for (i = 0; i < tzp->num_tbps; i++) {
1401 if (tzp->tbp[i].cdev == cdev) {
1402 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1403 tzp->tbp[i].cdev = NULL;
1404 }
1405 }
Zhang Rui203d3d42008-01-17 15:51:08 +08001406 }
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301407
Zhang Rui203d3d42008-01-17 15:51:08 +08001408 mutex_unlock(&thermal_list_lock);
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301409
Zhang Rui203d3d42008-01-17 15:51:08 +08001410 if (cdev->type[0])
Len Brown543a9562008-02-07 16:55:08 -05001411 device_remove_file(&cdev->device, &dev_attr_cdev_type);
Zhang Rui203d3d42008-01-17 15:51:08 +08001412 device_remove_file(&cdev->device, &dev_attr_max_state);
1413 device_remove_file(&cdev->device, &dev_attr_cur_state);
1414
1415 release_idr(&thermal_cdev_idr, &thermal_idr_lock, cdev->id);
1416 device_unregister(&cdev->device);
1417 return;
1418}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001419EXPORT_SYMBOL_GPL(thermal_cooling_device_unregister);
Zhang Rui203d3d42008-01-17 15:51:08 +08001420
Durgadoss Rdc765482012-09-18 11:05:00 +05301421void thermal_cdev_update(struct thermal_cooling_device *cdev)
Zhang Ruice119f82012-06-27 14:13:04 +08001422{
1423 struct thermal_instance *instance;
1424 unsigned long target = 0;
1425
1426 /* cooling device is updated*/
1427 if (cdev->updated)
1428 return;
1429
Zhang Ruif4a821c2012-07-24 16:56:21 +08001430 mutex_lock(&cdev->lock);
Zhang Ruice119f82012-06-27 14:13:04 +08001431 /* Make sure cdev enters the deepest cooling state */
1432 list_for_each_entry(instance, &cdev->thermal_instances, cdev_node) {
1433 if (instance->target == THERMAL_NO_TARGET)
1434 continue;
1435 if (instance->target > target)
1436 target = instance->target;
1437 }
Zhang Ruif4a821c2012-07-24 16:56:21 +08001438 mutex_unlock(&cdev->lock);
Zhang Ruice119f82012-06-27 14:13:04 +08001439 cdev->ops->set_cur_state(cdev, target);
1440 cdev->updated = true;
1441}
Durgadoss Rdc765482012-09-18 11:05:00 +05301442EXPORT_SYMBOL(thermal_cdev_update);
Zhang Ruice119f82012-06-27 14:13:04 +08001443
Matthew Garrettb1569e92008-12-03 17:55:32 +00001444/**
Eduardo Valentin7b73c992013-04-23 21:48:14 +00001445 * thermal_notify_framework - Sensor drivers use this API to notify framework
Durgadoss Rf2b4caa2012-09-18 11:05:05 +05301446 * @tz: thermal zone device
1447 * @trip: indicates which trip point has been crossed
1448 *
1449 * This function handles the trip events from sensor drivers. It starts
1450 * throttling the cooling devices according to the policy configured.
1451 * For CRITICAL and HOT trip points, this notifies the respective drivers,
1452 * and does actual throttling for other trip points i.e ACTIVE and PASSIVE.
1453 * The throttling policy is based on the configured platform data; if no
1454 * platform data is provided, this uses the step_wise throttling policy.
1455 */
Eduardo Valentin7b73c992013-04-23 21:48:14 +00001456void thermal_notify_framework(struct thermal_zone_device *tz, int trip)
Durgadoss Rf2b4caa2012-09-18 11:05:05 +05301457{
1458 handle_thermal_trip(tz, trip);
1459}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001460EXPORT_SYMBOL_GPL(thermal_notify_framework);
Durgadoss Rf2b4caa2012-09-18 11:05:05 +05301461
1462/**
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001463 * create_trip_attrs - create attributes for trip points
1464 * @tz: the thermal zone device
1465 * @mask: Writeable trip point bitmap.
1466 */
1467static int create_trip_attrs(struct thermal_zone_device *tz, int mask)
1468{
1469 int indx;
Durgadoss R27365a62012-07-25 10:10:59 +08001470 int size = sizeof(struct thermal_attr) * tz->trips;
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001471
Durgadoss R27365a62012-07-25 10:10:59 +08001472 tz->trip_type_attrs = kzalloc(size, GFP_KERNEL);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001473 if (!tz->trip_type_attrs)
1474 return -ENOMEM;
1475
Durgadoss R27365a62012-07-25 10:10:59 +08001476 tz->trip_temp_attrs = kzalloc(size, GFP_KERNEL);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001477 if (!tz->trip_temp_attrs) {
1478 kfree(tz->trip_type_attrs);
1479 return -ENOMEM;
1480 }
1481
Durgadoss R27365a62012-07-25 10:10:59 +08001482 if (tz->ops->get_trip_hyst) {
1483 tz->trip_hyst_attrs = kzalloc(size, GFP_KERNEL);
1484 if (!tz->trip_hyst_attrs) {
1485 kfree(tz->trip_type_attrs);
1486 kfree(tz->trip_temp_attrs);
1487 return -ENOMEM;
1488 }
1489 }
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001490
Durgadoss R27365a62012-07-25 10:10:59 +08001491
1492 for (indx = 0; indx < tz->trips; indx++) {
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001493 /* create trip type attribute */
1494 snprintf(tz->trip_type_attrs[indx].name, THERMAL_NAME_LENGTH,
1495 "trip_point_%d_type", indx);
1496
1497 sysfs_attr_init(&tz->trip_type_attrs[indx].attr.attr);
1498 tz->trip_type_attrs[indx].attr.attr.name =
1499 tz->trip_type_attrs[indx].name;
1500 tz->trip_type_attrs[indx].attr.attr.mode = S_IRUGO;
1501 tz->trip_type_attrs[indx].attr.show = trip_point_type_show;
1502
1503 device_create_file(&tz->device,
1504 &tz->trip_type_attrs[indx].attr);
1505
1506 /* create trip temp attribute */
1507 snprintf(tz->trip_temp_attrs[indx].name, THERMAL_NAME_LENGTH,
1508 "trip_point_%d_temp", indx);
1509
1510 sysfs_attr_init(&tz->trip_temp_attrs[indx].attr.attr);
1511 tz->trip_temp_attrs[indx].attr.attr.name =
1512 tz->trip_temp_attrs[indx].name;
1513 tz->trip_temp_attrs[indx].attr.attr.mode = S_IRUGO;
1514 tz->trip_temp_attrs[indx].attr.show = trip_point_temp_show;
1515 if (mask & (1 << indx)) {
1516 tz->trip_temp_attrs[indx].attr.attr.mode |= S_IWUSR;
1517 tz->trip_temp_attrs[indx].attr.store =
1518 trip_point_temp_store;
1519 }
1520
1521 device_create_file(&tz->device,
1522 &tz->trip_temp_attrs[indx].attr);
Durgadoss R27365a62012-07-25 10:10:59 +08001523
1524 /* create Optional trip hyst attribute */
1525 if (!tz->ops->get_trip_hyst)
1526 continue;
1527 snprintf(tz->trip_hyst_attrs[indx].name, THERMAL_NAME_LENGTH,
1528 "trip_point_%d_hyst", indx);
1529
1530 sysfs_attr_init(&tz->trip_hyst_attrs[indx].attr.attr);
1531 tz->trip_hyst_attrs[indx].attr.attr.name =
1532 tz->trip_hyst_attrs[indx].name;
1533 tz->trip_hyst_attrs[indx].attr.attr.mode = S_IRUGO;
1534 tz->trip_hyst_attrs[indx].attr.show = trip_point_hyst_show;
1535 if (tz->ops->set_trip_hyst) {
1536 tz->trip_hyst_attrs[indx].attr.attr.mode |= S_IWUSR;
1537 tz->trip_hyst_attrs[indx].attr.store =
1538 trip_point_hyst_store;
1539 }
1540
1541 device_create_file(&tz->device,
1542 &tz->trip_hyst_attrs[indx].attr);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001543 }
1544 return 0;
1545}
1546
1547static void remove_trip_attrs(struct thermal_zone_device *tz)
1548{
1549 int indx;
1550
1551 for (indx = 0; indx < tz->trips; indx++) {
1552 device_remove_file(&tz->device,
1553 &tz->trip_type_attrs[indx].attr);
1554 device_remove_file(&tz->device,
1555 &tz->trip_temp_attrs[indx].attr);
Durgadoss R27365a62012-07-25 10:10:59 +08001556 if (tz->ops->get_trip_hyst)
1557 device_remove_file(&tz->device,
1558 &tz->trip_hyst_attrs[indx].attr);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001559 }
1560 kfree(tz->trip_type_attrs);
1561 kfree(tz->trip_temp_attrs);
Durgadoss R27365a62012-07-25 10:10:59 +08001562 kfree(tz->trip_hyst_attrs);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001563}
1564
1565/**
Zhang Rui203d3d42008-01-17 15:51:08 +08001566 * thermal_zone_device_register - register a new thermal zone device
1567 * @type: the thermal zone device type
1568 * @trips: the number of trip points the thermal zone support
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001569 * @mask: a bit string indicating the writeablility of trip points
Zhang Rui203d3d42008-01-17 15:51:08 +08001570 * @devdata: private device data
1571 * @ops: standard thermal zone device callbacks
Durgadoss R50125a92012-09-18 11:04:56 +05301572 * @tzp: thermal zone platform parameters
Matthew Garrettb1569e92008-12-03 17:55:32 +00001573 * @passive_delay: number of milliseconds to wait between polls when
1574 * performing passive cooling
1575 * @polling_delay: number of milliseconds to wait between polls when checking
1576 * whether trip points have been crossed (0 for interrupt
1577 * driven systems)
Zhang Rui203d3d42008-01-17 15:51:08 +08001578 *
1579 * thermal_zone_device_unregister() must be called when the device is no
Zhang Rui1b7ddb82012-06-27 09:51:12 +08001580 * longer needed. The passive cooling depends on the .get_trend() return value.
Zhang Rui203d3d42008-01-17 15:51:08 +08001581 */
Anton Vorontsov4b1bf582012-07-31 04:39:30 -07001582struct thermal_zone_device *thermal_zone_device_register(const char *type,
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001583 int trips, int mask, void *devdata,
Alan Cox5b275ce2010-11-11 15:27:29 +00001584 const struct thermal_zone_device_ops *ops,
Durgadoss R50125a92012-09-18 11:04:56 +05301585 const struct thermal_zone_params *tzp,
Zhang Rui1b7ddb82012-06-27 09:51:12 +08001586 int passive_delay, int polling_delay)
Zhang Rui203d3d42008-01-17 15:51:08 +08001587{
1588 struct thermal_zone_device *tz;
Matthew Garrett03a971a2008-12-03 18:00:38 +00001589 enum thermal_trip_type trip_type;
Zhang Rui203d3d42008-01-17 15:51:08 +08001590 int result;
1591 int count;
Matthew Garrett03a971a2008-12-03 18:00:38 +00001592 int passive = 0;
Zhang Rui203d3d42008-01-17 15:51:08 +08001593
Guenter Roeck204dd1d2012-08-07 22:36:45 -07001594 if (type && strlen(type) >= THERMAL_NAME_LENGTH)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001595 return ERR_PTR(-EINVAL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001596
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001597 if (trips > THERMAL_MAX_TRIPS || trips < 0 || mask >> trips)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001598 return ERR_PTR(-EINVAL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001599
1600 if (!ops || !ops->get_temp)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001601 return ERR_PTR(-EINVAL);
Zhang Rui203d3d42008-01-17 15:51:08 +08001602
Eduardo Valentin6b2aa512013-01-02 15:29:42 +00001603 if (trips > 0 && !ops->get_trip_type)
1604 return ERR_PTR(-EINVAL);
1605
Zhang Rui203d3d42008-01-17 15:51:08 +08001606 tz = kzalloc(sizeof(struct thermal_zone_device), GFP_KERNEL);
1607 if (!tz)
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001608 return ERR_PTR(-ENOMEM);
Zhang Rui203d3d42008-01-17 15:51:08 +08001609
Zhang Rui2d374132012-06-27 10:09:00 +08001610 INIT_LIST_HEAD(&tz->thermal_instances);
Zhang Rui203d3d42008-01-17 15:51:08 +08001611 idr_init(&tz->idr);
1612 mutex_init(&tz->lock);
1613 result = get_idr(&thermal_tz_idr, &thermal_idr_lock, &tz->id);
1614 if (result) {
1615 kfree(tz);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001616 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001617 }
1618
Eduardo Valentinc7a8b9d2013-04-23 21:48:12 +00001619 strlcpy(tz->type, type ? : "", sizeof(tz->type));
Zhang Rui203d3d42008-01-17 15:51:08 +08001620 tz->ops = ops;
Durgadoss R50125a92012-09-18 11:04:56 +05301621 tz->tzp = tzp;
Zhang Rui203d3d42008-01-17 15:51:08 +08001622 tz->device.class = &thermal_class;
1623 tz->devdata = devdata;
1624 tz->trips = trips;
Matthew Garrettb1569e92008-12-03 17:55:32 +00001625 tz->passive_delay = passive_delay;
1626 tz->polling_delay = polling_delay;
1627
Kay Sievers354655e2009-01-06 10:44:37 -08001628 dev_set_name(&tz->device, "thermal_zone%d", tz->id);
Zhang Rui203d3d42008-01-17 15:51:08 +08001629 result = device_register(&tz->device);
1630 if (result) {
1631 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1632 kfree(tz);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001633 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001634 }
1635
1636 /* sys I/F */
1637 if (type) {
1638 result = device_create_file(&tz->device, &dev_attr_type);
1639 if (result)
1640 goto unregister;
1641 }
1642
1643 result = device_create_file(&tz->device, &dev_attr_temp);
1644 if (result)
1645 goto unregister;
1646
1647 if (ops->get_mode) {
1648 result = device_create_file(&tz->device, &dev_attr_mode);
1649 if (result)
1650 goto unregister;
1651 }
1652
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001653 result = create_trip_attrs(tz, mask);
1654 if (result)
1655 goto unregister;
1656
Zhang Rui203d3d42008-01-17 15:51:08 +08001657 for (count = 0; count < trips; count++) {
Matthew Garrett03a971a2008-12-03 18:00:38 +00001658 tz->ops->get_trip_type(tz, count, &trip_type);
1659 if (trip_type == THERMAL_TRIP_PASSIVE)
1660 passive = 1;
Zhang Rui203d3d42008-01-17 15:51:08 +08001661 }
1662
Durgadoss R5a2c0902012-09-18 11:04:58 +05301663 if (!passive) {
1664 result = device_create_file(&tz->device, &dev_attr_passive);
1665 if (result)
1666 goto unregister;
1667 }
Matthew Garrett03a971a2008-12-03 18:00:38 +00001668
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +00001669#ifdef CONFIG_THERMAL_EMULATION
1670 result = device_create_file(&tz->device, &dev_attr_emul_temp);
1671 if (result)
1672 goto unregister;
1673#endif
Durgadoss R5a2c0902012-09-18 11:04:58 +05301674 /* Create policy attribute */
1675 result = device_create_file(&tz->device, &dev_attr_policy);
Matthew Garrett03a971a2008-12-03 18:00:38 +00001676 if (result)
1677 goto unregister;
1678
Durgadoss Ra4a15482012-09-18 11:04:57 +05301679 /* Update 'this' zone's governor information */
1680 mutex_lock(&thermal_governor_lock);
1681
1682 if (tz->tzp)
1683 tz->governor = __find_governor(tz->tzp->governor_name);
1684 else
1685 tz->governor = __find_governor(DEFAULT_THERMAL_GOVERNOR);
1686
1687 mutex_unlock(&thermal_governor_lock);
1688
Zhang Ruie68b16a2008-04-21 16:07:52 +08001689 result = thermal_add_hwmon_sysfs(tz);
1690 if (result)
1691 goto unregister;
1692
Zhang Rui203d3d42008-01-17 15:51:08 +08001693 mutex_lock(&thermal_list_lock);
1694 list_add_tail(&tz->node, &thermal_tz_list);
Zhang Rui203d3d42008-01-17 15:51:08 +08001695 mutex_unlock(&thermal_list_lock);
1696
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301697 /* Bind cooling devices for this zone */
1698 bind_tz(tz);
1699
Matthew Garrettb1569e92008-12-03 17:55:32 +00001700 INIT_DELAYED_WORK(&(tz->poll_queue), thermal_zone_device_check);
1701
1702 thermal_zone_device_update(tz);
1703
Zhang Rui203d3d42008-01-17 15:51:08 +08001704 if (!result)
1705 return tz;
1706
Joe Perchescaca8b82012-03-21 12:55:02 -07001707unregister:
Zhang Rui203d3d42008-01-17 15:51:08 +08001708 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1709 device_unregister(&tz->device);
Thomas Sujith3e6fda52008-02-15 00:59:50 -05001710 return ERR_PTR(result);
Zhang Rui203d3d42008-01-17 15:51:08 +08001711}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001712EXPORT_SYMBOL_GPL(thermal_zone_device_register);
Zhang Rui203d3d42008-01-17 15:51:08 +08001713
1714/**
1715 * thermal_device_unregister - removes the registered thermal zone device
Zhang Rui203d3d42008-01-17 15:51:08 +08001716 * @tz: the thermal zone device to remove
1717 */
1718void thermal_zone_device_unregister(struct thermal_zone_device *tz)
1719{
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301720 int i;
1721 const struct thermal_zone_params *tzp;
Zhang Rui203d3d42008-01-17 15:51:08 +08001722 struct thermal_cooling_device *cdev;
1723 struct thermal_zone_device *pos = NULL;
Zhang Rui203d3d42008-01-17 15:51:08 +08001724
1725 if (!tz)
1726 return;
1727
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301728 tzp = tz->tzp;
1729
Zhang Rui203d3d42008-01-17 15:51:08 +08001730 mutex_lock(&thermal_list_lock);
1731 list_for_each_entry(pos, &thermal_tz_list, node)
1732 if (pos == tz)
1733 break;
1734 if (pos != tz) {
1735 /* thermal zone device not found */
1736 mutex_unlock(&thermal_list_lock);
1737 return;
1738 }
1739 list_del(&tz->node);
Durgadoss R7e8ee1e2012-09-18 11:04:59 +05301740
1741 /* Unbind all cdevs associated with 'this' thermal zone */
1742 list_for_each_entry(cdev, &thermal_cdev_list, node) {
1743 if (tz->ops->unbind) {
1744 tz->ops->unbind(tz, cdev);
1745 continue;
1746 }
1747
1748 if (!tzp || !tzp->tbp)
1749 break;
1750
1751 for (i = 0; i < tzp->num_tbps; i++) {
1752 if (tzp->tbp[i].cdev == cdev) {
1753 __unbind(tz, tzp->tbp[i].trip_mask, cdev);
1754 tzp->tbp[i].cdev = NULL;
1755 }
1756 }
1757 }
1758
Zhang Rui203d3d42008-01-17 15:51:08 +08001759 mutex_unlock(&thermal_list_lock);
1760
Matthew Garrettb1569e92008-12-03 17:55:32 +00001761 thermal_zone_device_set_polling(tz, 0);
1762
Zhang Rui203d3d42008-01-17 15:51:08 +08001763 if (tz->type[0])
1764 device_remove_file(&tz->device, &dev_attr_type);
1765 device_remove_file(&tz->device, &dev_attr_temp);
1766 if (tz->ops->get_mode)
1767 device_remove_file(&tz->device, &dev_attr_mode);
Durgadoss R5a2c0902012-09-18 11:04:58 +05301768 device_remove_file(&tz->device, &dev_attr_policy);
Durgadoss Rc56f5c02012-07-25 10:10:58 +08001769 remove_trip_attrs(tz);
Durgadoss Ra4a15482012-09-18 11:04:57 +05301770 tz->governor = NULL;
Zhang Rui203d3d42008-01-17 15:51:08 +08001771
Zhang Ruie68b16a2008-04-21 16:07:52 +08001772 thermal_remove_hwmon_sysfs(tz);
Zhang Rui203d3d42008-01-17 15:51:08 +08001773 release_idr(&thermal_tz_idr, &thermal_idr_lock, tz->id);
1774 idr_destroy(&tz->idr);
1775 mutex_destroy(&tz->lock);
1776 device_unregister(&tz->device);
1777 return;
1778}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001779EXPORT_SYMBOL_GPL(thermal_zone_device_unregister);
Zhang Rui203d3d42008-01-17 15:51:08 +08001780
Eduardo Valentin63c4d912013-04-05 12:32:28 +00001781/**
1782 * thermal_zone_get_zone_by_name() - search for a zone and returns its ref
1783 * @name: thermal zone name to fetch the temperature
1784 *
1785 * When only one zone is found with the passed name, returns a reference to it.
1786 *
1787 * Return: On success returns a reference to an unique thermal zone with
1788 * matching name equals to @name, an ERR_PTR otherwise (-EINVAL for invalid
1789 * paramenters, -ENODEV for not found and -EEXIST for multiple matches).
1790 */
1791struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name)
1792{
1793 struct thermal_zone_device *pos = NULL, *ref = ERR_PTR(-EINVAL);
1794 unsigned int found = 0;
1795
1796 if (!name)
1797 goto exit;
1798
1799 mutex_lock(&thermal_list_lock);
1800 list_for_each_entry(pos, &thermal_tz_list, node)
1801 if (!strnicmp(name, pos->type, THERMAL_NAME_LENGTH)) {
1802 found++;
1803 ref = pos;
1804 }
1805 mutex_unlock(&thermal_list_lock);
1806
1807 /* nothing has been found, thus an error code for it */
1808 if (found == 0)
1809 ref = ERR_PTR(-ENODEV);
1810 else if (found > 1)
1811 /* Success only when an unique zone is found */
1812 ref = ERR_PTR(-EEXIST);
1813
1814exit:
1815 return ref;
1816}
1817EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_name);
1818
Rafael J. Wysockiaf062162011-03-01 01:12:19 +01001819#ifdef CONFIG_NET
1820static struct genl_family thermal_event_genl_family = {
1821 .id = GENL_ID_GENERATE,
1822 .name = THERMAL_GENL_FAMILY_NAME,
1823 .version = THERMAL_GENL_VERSION,
1824 .maxattr = THERMAL_GENL_ATTR_MAX,
1825};
1826
1827static struct genl_multicast_group thermal_event_mcgrp = {
1828 .name = THERMAL_GENL_MCAST_GROUP_NAME,
1829};
1830
Eduardo Valentin8ab3e6a2013-01-02 15:29:39 +00001831int thermal_generate_netlink_event(struct thermal_zone_device *tz,
1832 enum events event)
R.Durgadoss4cb18722010-10-27 03:33:29 +05301833{
1834 struct sk_buff *skb;
1835 struct nlattr *attr;
1836 struct thermal_genl_event *thermal_event;
1837 void *msg_header;
1838 int size;
1839 int result;
Fabio Estevamb11de072012-03-21 12:55:00 -07001840 static unsigned int thermal_event_seqnum;
R.Durgadoss4cb18722010-10-27 03:33:29 +05301841
Eduardo Valentin8ab3e6a2013-01-02 15:29:39 +00001842 if (!tz)
1843 return -EINVAL;
1844
R.Durgadoss4cb18722010-10-27 03:33:29 +05301845 /* allocate memory */
Joe Perches886ee542012-03-21 12:55:01 -07001846 size = nla_total_size(sizeof(struct thermal_genl_event)) +
1847 nla_total_size(0);
R.Durgadoss4cb18722010-10-27 03:33:29 +05301848
1849 skb = genlmsg_new(size, GFP_ATOMIC);
1850 if (!skb)
1851 return -ENOMEM;
1852
1853 /* add the genetlink message header */
1854 msg_header = genlmsg_put(skb, 0, thermal_event_seqnum++,
1855 &thermal_event_genl_family, 0,
1856 THERMAL_GENL_CMD_EVENT);
1857 if (!msg_header) {
1858 nlmsg_free(skb);
1859 return -ENOMEM;
1860 }
1861
1862 /* fill the data */
Joe Perches886ee542012-03-21 12:55:01 -07001863 attr = nla_reserve(skb, THERMAL_GENL_ATTR_EVENT,
1864 sizeof(struct thermal_genl_event));
R.Durgadoss4cb18722010-10-27 03:33:29 +05301865
1866 if (!attr) {
1867 nlmsg_free(skb);
1868 return -EINVAL;
1869 }
1870
1871 thermal_event = nla_data(attr);
1872 if (!thermal_event) {
1873 nlmsg_free(skb);
1874 return -EINVAL;
1875 }
1876
1877 memset(thermal_event, 0, sizeof(struct thermal_genl_event));
1878
Eduardo Valentin8ab3e6a2013-01-02 15:29:39 +00001879 thermal_event->orig = tz->id;
R.Durgadoss4cb18722010-10-27 03:33:29 +05301880 thermal_event->event = event;
1881
1882 /* send multicast genetlink message */
1883 result = genlmsg_end(skb, msg_header);
1884 if (result < 0) {
1885 nlmsg_free(skb);
1886 return result;
1887 }
1888
1889 result = genlmsg_multicast(skb, 0, thermal_event_mcgrp.id, GFP_ATOMIC);
1890 if (result)
Eduardo Valentin923e0b12013-01-02 15:29:41 +00001891 dev_err(&tz->device, "Failed to send netlink event:%d", result);
R.Durgadoss4cb18722010-10-27 03:33:29 +05301892
1893 return result;
1894}
Eduardo Valentin910cb1e2013-04-23 21:48:15 +00001895EXPORT_SYMBOL_GPL(thermal_generate_netlink_event);
R.Durgadoss4cb18722010-10-27 03:33:29 +05301896
1897static int genetlink_init(void)
1898{
1899 int result;
1900
1901 result = genl_register_family(&thermal_event_genl_family);
1902 if (result)
1903 return result;
1904
1905 result = genl_register_mc_group(&thermal_event_genl_family,
1906 &thermal_event_mcgrp);
1907 if (result)
1908 genl_unregister_family(&thermal_event_genl_family);
1909 return result;
1910}
1911
Rafael J. Wysockiaf062162011-03-01 01:12:19 +01001912static void genetlink_exit(void)
1913{
1914 genl_unregister_family(&thermal_event_genl_family);
1915}
1916#else /* !CONFIG_NET */
1917static inline int genetlink_init(void) { return 0; }
1918static inline void genetlink_exit(void) {}
1919#endif /* !CONFIG_NET */
1920
Zhang Rui80a26a52013-03-26 16:38:29 +08001921static int __init thermal_register_governors(void)
1922{
1923 int result;
1924
1925 result = thermal_gov_step_wise_register();
1926 if (result)
1927 return result;
1928
1929 result = thermal_gov_fair_share_register();
1930 if (result)
1931 return result;
1932
1933 return thermal_gov_user_space_register();
1934}
1935
1936static void thermal_unregister_governors(void)
1937{
1938 thermal_gov_step_wise_unregister();
1939 thermal_gov_fair_share_unregister();
1940 thermal_gov_user_space_unregister();
1941}
1942
Zhang Rui203d3d42008-01-17 15:51:08 +08001943static int __init thermal_init(void)
1944{
Zhang Rui80a26a52013-03-26 16:38:29 +08001945 int result;
1946
1947 result = thermal_register_governors();
1948 if (result)
1949 goto error;
Zhang Rui203d3d42008-01-17 15:51:08 +08001950
1951 result = class_register(&thermal_class);
Zhang Rui80a26a52013-03-26 16:38:29 +08001952 if (result)
1953 goto unregister_governors;
1954
R.Durgadoss4cb18722010-10-27 03:33:29 +05301955 result = genetlink_init();
Zhang Rui80a26a52013-03-26 16:38:29 +08001956 if (result)
1957 goto unregister_class;
1958
1959 return 0;
1960
1961unregister_governors:
1962 thermal_unregister_governors();
1963unregister_class:
1964 class_unregister(&thermal_class);
1965error:
1966 idr_destroy(&thermal_tz_idr);
1967 idr_destroy(&thermal_cdev_idr);
1968 mutex_destroy(&thermal_idr_lock);
1969 mutex_destroy(&thermal_list_lock);
1970 mutex_destroy(&thermal_governor_lock);
Zhang Rui203d3d42008-01-17 15:51:08 +08001971 return result;
1972}
1973
1974static void __exit thermal_exit(void)
1975{
Zhang Rui80a26a52013-03-26 16:38:29 +08001976 genetlink_exit();
Zhang Rui203d3d42008-01-17 15:51:08 +08001977 class_unregister(&thermal_class);
Zhang Rui80a26a52013-03-26 16:38:29 +08001978 thermal_unregister_governors();
Zhang Rui203d3d42008-01-17 15:51:08 +08001979 idr_destroy(&thermal_tz_idr);
1980 idr_destroy(&thermal_cdev_idr);
1981 mutex_destroy(&thermal_idr_lock);
1982 mutex_destroy(&thermal_list_lock);
Zhang Rui80a26a52013-03-26 16:38:29 +08001983 mutex_destroy(&thermal_governor_lock);
Zhang Rui203d3d42008-01-17 15:51:08 +08001984}
1985
R.Durgadoss4cb18722010-10-27 03:33:29 +05301986fs_initcall(thermal_init);
Zhang Rui203d3d42008-01-17 15:51:08 +08001987module_exit(thermal_exit);