Thomas Gleixner | 873e65b | 2019-05-27 08:55:15 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 2 | /* |
| 3 | * user_space.c - A simple user space Thermal events notifier |
| 4 | * |
| 5 | * Copyright (C) 2012 Intel Corp |
| 6 | * Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com> |
| 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 10 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 11 | */ |
| 12 | |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 13 | #include <linux/thermal.h> |
Srinivas Pandruvada | 998d924 | 2016-08-26 16:21:17 -0700 | [diff] [blame] | 14 | #include <linux/slab.h> |
Willy WOLFF | 0d76d6e1 | 2017-06-24 14:06:03 +0100 | [diff] [blame] | 15 | |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 16 | #include "thermal_core.h" |
| 17 | |
| 18 | /** |
| 19 | * notify_user_space - Notifies user space about thermal events |
Amit Kucheria | 53d256e | 2019-11-20 21:15:12 +0530 | [diff] [blame] | 20 | * @tz: thermal_zone_device |
| 21 | * @trip: trip point index |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 22 | * |
| 23 | * This function notifies the user space through UEvents. |
| 24 | */ |
Sachin Kamat | e15cb14 | 2012-09-27 16:57:54 +0530 | [diff] [blame] | 25 | static int notify_user_space(struct thermal_zone_device *tz, int trip) |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 26 | { |
Srinivas Pandruvada | 998d924 | 2016-08-26 16:21:17 -0700 | [diff] [blame] | 27 | char *thermal_prop[5]; |
| 28 | int i; |
| 29 | |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 30 | mutex_lock(&tz->lock); |
Srinivas Pandruvada | 998d924 | 2016-08-26 16:21:17 -0700 | [diff] [blame] | 31 | thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type); |
| 32 | thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature); |
| 33 | thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip); |
| 34 | thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event); |
| 35 | thermal_prop[4] = NULL; |
| 36 | kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop); |
| 37 | for (i = 0; i < 4; ++i) |
| 38 | kfree(thermal_prop[i]); |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 39 | mutex_unlock(&tz->lock); |
| 40 | return 0; |
| 41 | } |
| 42 | |
Sachin Kamat | e15cb14 | 2012-09-27 16:57:54 +0530 | [diff] [blame] | 43 | static struct thermal_governor thermal_gov_user_space = { |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 44 | .name = "user_space", |
| 45 | .throttle = notify_user_space, |
Durgadoss R | 1cc807a | 2012-09-18 11:05:03 +0530 | [diff] [blame] | 46 | }; |
Daniel Lezcano | 57c5b2e | 2019-06-12 22:13:25 +0200 | [diff] [blame] | 47 | THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space); |