1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/thermal.h>
23
24#include "thermal_core.h"
25
26static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip)
27{
28 int trip_temp, trip_hyst;
29 struct thermal_instance *instance;
30
31 tz->ops->get_trip_temp(tz, trip, &trip_temp);
32
33 if (!tz->ops->get_trip_hyst) {
34 pr_warn_once("Undefined get_trip_hyst for thermal zone %s - "
35 "running with default hysteresis zero\n", tz->type);
36 trip_hyst = 0;
37 } else
38 tz->ops->get_trip_hyst(tz, trip, &trip_hyst);
39
40 dev_dbg(&tz->device, "Trip%d[temp=%d]:temp=%d:hyst=%d\n",
41 trip, trip_temp, tz->temperature,
42 trip_hyst);
43
44 mutex_lock(&tz->lock);
45
46 list_for_each_entry(instance, &tz->thermal_instances, tz_node) {
47 if (instance->trip != trip)
48 continue;
49
50
51 if (instance->target == THERMAL_NO_TARGET)
52 instance->target = 0;
53
54
55 if (instance->target != 0 && instance->target != 1) {
56 pr_warn("Thermal instance %s controlled by bang-bang has unexpected state: %ld\n",
57 instance->name, instance->target);
58 instance->target = 1;
59 }
60
61
62
63
64
65 if (instance->target == 0 && tz->temperature >= trip_temp)
66 instance->target = 1;
67 else if (instance->target == 1 &&
68 tz->temperature <= trip_temp - trip_hyst)
69 instance->target = 0;
70
71 dev_dbg(&instance->cdev->device, "target=%d\n",
72 (int)instance->target);
73
74 mutex_lock(&instance->cdev->lock);
75 instance->cdev->updated = false;
76 mutex_unlock(&instance->cdev->lock);
77 }
78
79 mutex_unlock(&tz->lock);
80}
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109static int bang_bang_control(struct thermal_zone_device *tz, int trip)
110{
111 struct thermal_instance *instance;
112
113 thermal_zone_trip_update(tz, trip);
114
115 mutex_lock(&tz->lock);
116
117 list_for_each_entry(instance, &tz->thermal_instances, tz_node)
118 thermal_cdev_update(instance->cdev);
119
120 mutex_unlock(&tz->lock);
121
122 return 0;
123}
124
125static struct thermal_governor thermal_gov_bang_bang = {
126 .name = "bang_bang",
127 .throttle = bang_bang_control,
128};
129
130int thermal_gov_bang_bang_register(void)
131{
132 return thermal_register_governor(&thermal_gov_bang_bang);
133}
134
135void thermal_gov_bang_bang_unregister(void)
136{
137 thermal_unregister_governor(&thermal_gov_bang_bang);
138}
139