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