1 // SPDX-License-Identifier: GPL-2.0-only
3 * user_space.c - A simple user space Thermal events notifier
5 * Copyright (C) 2012 Intel Corp
6 * Copyright (C) 2012 Durgadoss R <durgadoss.r@intel.com>
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 #include <linux/slab.h>
14 #include <linux/thermal.h>
16 #include "thermal_core.h"
18 static int user_space_bind(struct thermal_zone_device *tz)
20 pr_info_once("Consider using thermal netlink events interface\n");
26 * notify_user_space - Notifies user space about thermal events
27 * @tz: thermal_zone_device
28 * @trip: trip point index
30 * This function notifies the user space through UEvents.
32 static int notify_user_space(struct thermal_zone_device *tz, int trip)
34 char *thermal_prop[5];
37 mutex_lock(&tz->lock);
38 thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
39 thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
40 thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
41 thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
42 thermal_prop[4] = NULL;
43 kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
44 for (i = 0; i < 4; ++i)
45 kfree(thermal_prop[i]);
46 mutex_unlock(&tz->lock);
50 static struct thermal_governor thermal_gov_user_space = {
52 .throttle = notify_user_space,
53 .bind_to_tz = user_space_bind,
55 THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);