xref: /linux/drivers/thermal/gov_user_space.c (revision 5027ec19f1049a07df5b0a37b1f462514cf2724b)
1 // SPDX-License-Identifier: GPL-2.0-only
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  *
10  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11  */
12 
13 #include <linux/slab.h>
14 #include <linux/thermal.h>
15 
16 #include "thermal_core.h"
17 
18 static int user_space_bind(struct thermal_zone_device *tz)
19 {
20 	pr_info_once("Consider using thermal netlink events interface\n");
21 
22 	return 0;
23 }
24 
25 /**
26  * notify_user_space - Notifies user space about thermal events
27  * @tz: thermal_zone_device
28  * @trip: trip point
29  *
30  * This function notifies the user space through UEvents.
31  */
32 static int notify_user_space(struct thermal_zone_device *tz,
33 			     const struct thermal_trip *trip)
34 {
35 	char *thermal_prop[5];
36 	int i;
37 
38 	lockdep_assert_held(&tz->lock);
39 
40 	thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
41 	thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
42 	thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d",
43 				    thermal_zone_trip_id(tz, trip));
44 	thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
45 	thermal_prop[4] = NULL;
46 	kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
47 	for (i = 0; i < 4; ++i)
48 		kfree(thermal_prop[i]);
49 
50 	return 0;
51 }
52 
53 static struct thermal_governor thermal_gov_user_space = {
54 	.name		= "user_space",
55 	.throttle	= notify_user_space,
56 	.bind_to_tz	= user_space_bind,
57 };
58 THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);
59