Merge tag 'locking-urgent-2021-11-14' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-block.git] / drivers / thermal / gov_user_space.c
CommitLineData
873e65bc 1// SPDX-License-Identifier: GPL-2.0-only
1cc807a2
D
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 *
1cc807a2
D
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 */
12
998d924b 13#include <linux/slab.h>
6abea5d2 14#include <linux/thermal.h>
0d76d6e1 15
1cc807a2
D
16#include "thermal_core.h"
17
0275c9fb
DL
18static int user_space_bind(struct thermal_zone_device *tz)
19{
567af705
RW
20 pr_warn_once("Userspace governor deprecated: use thermal netlink " \
21 "notification instead\n");
0275c9fb
DL
22
23 return 0;
24}
25
1cc807a2
D
26/**
27 * notify_user_space - Notifies user space about thermal events
53d256e7
AK
28 * @tz: thermal_zone_device
29 * @trip: trip point index
1cc807a2
D
30 *
31 * This function notifies the user space through UEvents.
32 */
e15cb144 33static int notify_user_space(struct thermal_zone_device *tz, int trip)
1cc807a2 34{
998d924b
SP
35 char *thermal_prop[5];
36 int i;
37
1cc807a2 38 mutex_lock(&tz->lock);
998d924b
SP
39 thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", tz->type);
40 thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", tz->temperature);
41 thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP=%d", trip);
42 thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", tz->notify_event);
43 thermal_prop[4] = NULL;
44 kobject_uevent_env(&tz->device.kobj, KOBJ_CHANGE, thermal_prop);
45 for (i = 0; i < 4; ++i)
46 kfree(thermal_prop[i]);
1cc807a2
D
47 mutex_unlock(&tz->lock);
48 return 0;
49}
50
e15cb144 51static struct thermal_governor thermal_gov_user_space = {
1cc807a2
D
52 .name = "user_space",
53 .throttle = notify_user_space,
0275c9fb 54 .bind_to_tz = user_space_bind,
1cc807a2 55};
57c5b2ec 56THERMAL_GOVERNOR_DECLARE(thermal_gov_user_space);