xref: /OK3568_Linux_fs/kernel/drivers/thermal/gov_user_space.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  user_space.c - A simple user space Thermal events notifier
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 2012 Intel Corp
6*4882a593Smuzhiyun  *  Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/slab.h>
14*4882a593Smuzhiyun #include <linux/thermal.h>
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #include "thermal_core.h"
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /**
19*4882a593Smuzhiyun  * notify_user_space - Notifies user space about thermal events
20*4882a593Smuzhiyun  * @tz: thermal_zone_device
21*4882a593Smuzhiyun  * @trip: trip point index
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  * This function notifies the user space through UEvents.
24*4882a593Smuzhiyun  */
notify_user_space(struct thermal_zone_device * tz,int trip)25*4882a593Smuzhiyun static int notify_user_space(struct thermal_zone_device *tz, int trip)
26*4882a593Smuzhiyun {
27*4882a593Smuzhiyun 	char *thermal_prop[5];
28*4882a593Smuzhiyun 	int i;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun 	mutex_lock(&tz->lock);
31*4882a593Smuzhiyun 	thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
32*4882a593Smuzhiyun 	thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
33*4882a593Smuzhiyun 	thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
34*4882a593Smuzhiyun 	thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
35*4882a593Smuzhiyun 	thermal_prop[4] = NULL;
36*4882a593Smuzhiyun 	kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
37*4882a593Smuzhiyun 	for (i = 0; i < 4; ++i)
38*4882a593Smuzhiyun 		kfree(thermal_prop[i]);
39*4882a593Smuzhiyun 	mutex_unlock(&tz->lock);
40*4882a593Smuzhiyun 	return 0;
41*4882a593Smuzhiyun }
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun static struct thermal_governor thermal_gov_user_space = {
44*4882a593Smuzhiyun 	.name		= "user_space",
45*4882a593Smuzhiyun 	.throttle	= notify_user_space,
46*4882a593Smuzhiyun };
47*4882a593Smuzhiyun THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);
48