aboutsummaryrefslogtreecommitdiff
path: root/drivers/thermal/backward_compatible.c
blob: 11d4e1063dbb9b91e43b7a07cb97e166b13aa63c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/thermal.h>

#include "thermal_core.h"

/**
 * backward_compatible_throttle
 * @tz - thermal_zone_device
 *
 * This function update the cooler state by monitoring the current temperature and trip points
 */
static int backward_compatible_throttle(struct thermal_zone_device *tz, int trip)
{
	long trip_temp;
	struct thermal_instance *instance;

	if (trip == THERMAL_TRIPS_NONE) {
		trip_temp = tz->forced_passive;
	} else {
		tz->ops->get_trip_temp(tz, trip, &trip_temp);
	}

	/* mutex_lock(&tz->lock); */

	list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
		if (instance->trip != trip)
			continue;

		if (tz->temperature >= trip_temp)
			instance->target = 1;
		else
			instance->target = 0;
		instance->cdev->updated = false;
		thermal_cdev_update(instance->cdev);
	}

	/* mutex_unlock(&tz->lock); */

	return 0;
}

static struct thermal_governor thermal_gov_backward_compatible = {
	.name = "backward_compatible",
	.throttle = backward_compatible_throttle,
	/* .owner                = THIS_MODULE, */
};

static int __init thermal_gov_backward_compatible_init(void)
{
	return thermal_register_governor(&thermal_gov_backward_compatible);
}

static void __exit thermal_gov_backward_compatible_exit(void)
{
	thermal_unregister_governor(&thermal_gov_backward_compatible);
}

/* This should load after thermal framework */
fs_initcall(thermal_gov_backward_compatible_init);
module_exit(thermal_gov_backward_compatible_exit);

MODULE_AUTHOR("Weiyi Lu");
MODULE_DESCRIPTION("A backward compatible Thermal governor");
MODULE_LICENSE("GPL");