1
2
3
4
5
6
7
8
9
10#ifndef __THERMAL_H__
11#define __THERMAL_H__
12
13#include <linux/of.h>
14#include <linux/idr.h>
15#include <linux/device.h>
16#include <linux/sysfs.h>
17#include <linux/workqueue.h>
18#include <uapi/linux/thermal.h>
19
20#define THERMAL_MAX_TRIPS 12
21
22
23#define THERMAL_CSTATE_INVALID -1UL
24
25
26#define THERMAL_NO_LIMIT ((u32)~0)
27
28
29#define THERMAL_WEIGHT_DEFAULT 0
30
31
32#define THERMAL_TEMP_INVALID -274000
33
34struct thermal_zone_device;
35struct thermal_cooling_device;
36struct thermal_instance;
37struct thermal_attr;
38
39enum thermal_trend {
40 THERMAL_TREND_STABLE,
41 THERMAL_TREND_RAISING,
42 THERMAL_TREND_DROPPING,
43 THERMAL_TREND_RAISE_FULL,
44 THERMAL_TREND_DROP_FULL,
45};
46
47
48enum thermal_notify_event {
49 THERMAL_EVENT_UNSPECIFIED,
50 THERMAL_EVENT_TEMP_SAMPLE,
51 THERMAL_TRIP_VIOLATED,
52 THERMAL_TRIP_CHANGED,
53 THERMAL_DEVICE_DOWN,
54 THERMAL_DEVICE_UP,
55 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED,
56 THERMAL_TABLE_CHANGED,
57 THERMAL_EVENT_KEEP_ALIVE,
58};
59
60struct thermal_zone_device_ops {
61 int (*bind) (struct thermal_zone_device *,
62 struct thermal_cooling_device *);
63 int (*unbind) (struct thermal_zone_device *,
64 struct thermal_cooling_device *);
65 int (*get_temp) (struct thermal_zone_device *, int *);
66 int (*set_trips) (struct thermal_zone_device *, int, int);
67 int (*change_mode) (struct thermal_zone_device *,
68 enum thermal_device_mode);
69 int (*get_trip_type) (struct thermal_zone_device *, int,
70 enum thermal_trip_type *);
71 int (*get_trip_temp) (struct thermal_zone_device *, int, int *);
72 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
73 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *);
74 int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
75 int (*get_crit_temp) (struct thermal_zone_device *, int *);
76 int (*set_emul_temp) (struct thermal_zone_device *, int);
77 int (*get_trend) (struct thermal_zone_device *, int,
78 enum thermal_trend *);
79 void (*hot)(struct thermal_zone_device *);
80 void (*critical)(struct thermal_zone_device *);
81};
82
83struct thermal_cooling_device_ops {
84 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
85 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
86 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
87 int (*get_requested_power)(struct thermal_cooling_device *, u32 *);
88 int (*state2power)(struct thermal_cooling_device *, unsigned long, u32 *);
89 int (*power2state)(struct thermal_cooling_device *, u32, unsigned long *);
90};
91
92struct thermal_cooling_device {
93 int id;
94 char *type;
95 struct device device;
96 struct device_node *np;
97 void *devdata;
98 void *stats;
99 const struct thermal_cooling_device_ops *ops;
100 bool updated;
101 struct mutex lock;
102 struct list_head thermal_instances;
103 struct list_head node;
104};
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146struct thermal_zone_device {
147 int id;
148 char type[THERMAL_NAME_LENGTH];
149 struct device device;
150 struct attribute_group trips_attribute_group;
151 struct thermal_attr *trip_temp_attrs;
152 struct thermal_attr *trip_type_attrs;
153 struct thermal_attr *trip_hyst_attrs;
154 enum thermal_device_mode mode;
155 void *devdata;
156 int trips;
157 unsigned long trips_disabled;
158 unsigned long passive_delay_jiffies;
159 unsigned long polling_delay_jiffies;
160 int temperature;
161 int last_temperature;
162 int emul_temperature;
163 int passive;
164 int prev_low_trip;
165 int prev_high_trip;
166 atomic_t need_update;
167 struct thermal_zone_device_ops *ops;
168 struct thermal_zone_params *tzp;
169 struct thermal_governor *governor;
170 void *governor_data;
171 struct list_head thermal_instances;
172 struct ida ida;
173 struct mutex lock;
174 struct list_head node;
175 struct delayed_work poll_queue;
176 enum thermal_notify_event notify_event;
177};
178
179
180
181
182
183
184
185
186
187
188
189
190
191struct thermal_governor {
192 char name[THERMAL_NAME_LENGTH];
193 int (*bind_to_tz)(struct thermal_zone_device *tz);
194 void (*unbind_from_tz)(struct thermal_zone_device *tz);
195 int (*throttle)(struct thermal_zone_device *tz, int trip);
196 struct list_head governor_list;
197};
198
199
200struct thermal_bind_params {
201 struct thermal_cooling_device *cdev;
202
203
204
205
206
207
208
209
210
211
212 int weight;
213
214
215
216
217
218
219 int trip_mask;
220
221
222
223
224
225
226
227
228
229 unsigned long *binding_limits;
230 int (*match) (struct thermal_zone_device *tz,
231 struct thermal_cooling_device *cdev);
232};
233
234
235struct thermal_zone_params {
236 char governor_name[THERMAL_NAME_LENGTH];
237
238
239
240
241
242
243 bool no_hwmon;
244
245 int num_tbps;
246 struct thermal_bind_params *tbp;
247
248
249
250
251
252 u32 sustainable_power;
253
254
255
256
257
258 s32 k_po;
259
260
261
262
263
264 s32 k_pu;
265
266
267 s32 k_i;
268
269
270 s32 k_d;
271
272
273 s32 integral_cutoff;
274
275
276
277
278
279 int slope;
280
281
282
283
284 int offset;
285};
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303struct thermal_zone_of_device_ops {
304 int (*get_temp)(void *, int *);
305 int (*get_trend)(void *, int, enum thermal_trend *);
306 int (*set_trips)(void *, int, int);
307 int (*set_emul_temp)(void *, int);
308 int (*set_trip_temp)(void *, int, int);
309};
310
311
312#ifdef CONFIG_THERMAL_OF
313int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
314 struct device_node *sensor_np,
315 u32 *id);
316struct thermal_zone_device *
317thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
318 const struct thermal_zone_of_device_ops *ops);
319void thermal_zone_of_sensor_unregister(struct device *dev,
320 struct thermal_zone_device *tz);
321struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
322 struct device *dev, int id, void *data,
323 const struct thermal_zone_of_device_ops *ops);
324void devm_thermal_zone_of_sensor_unregister(struct device *dev,
325 struct thermal_zone_device *tz);
326#else
327
328static inline int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
329 struct device_node *sensor_np,
330 u32 *id)
331{
332 return -ENOENT;
333}
334static inline struct thermal_zone_device *
335thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
336 const struct thermal_zone_of_device_ops *ops)
337{
338 return ERR_PTR(-ENODEV);
339}
340
341static inline
342void thermal_zone_of_sensor_unregister(struct device *dev,
343 struct thermal_zone_device *tz)
344{
345}
346
347static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
348 struct device *dev, int id, void *data,
349 const struct thermal_zone_of_device_ops *ops)
350{
351 return ERR_PTR(-ENODEV);
352}
353
354static inline
355void devm_thermal_zone_of_sensor_unregister(struct device *dev,
356 struct thermal_zone_device *tz)
357{
358}
359
360#endif
361
362#ifdef CONFIG_THERMAL
363struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
364 void *, struct thermal_zone_device_ops *,
365 struct thermal_zone_params *, int, int);
366void thermal_zone_device_unregister(struct thermal_zone_device *);
367
368int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
369 struct thermal_cooling_device *,
370 unsigned long, unsigned long,
371 unsigned int);
372int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
373 struct thermal_cooling_device *);
374void thermal_zone_device_update(struct thermal_zone_device *,
375 enum thermal_notify_event);
376
377struct thermal_cooling_device *thermal_cooling_device_register(const char *,
378 void *, const struct thermal_cooling_device_ops *);
379struct thermal_cooling_device *
380thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
381 const struct thermal_cooling_device_ops *);
382struct thermal_cooling_device *
383devm_thermal_of_cooling_device_register(struct device *dev,
384 struct device_node *np,
385 char *type, void *devdata,
386 const struct thermal_cooling_device_ops *ops);
387void thermal_cooling_device_unregister(struct thermal_cooling_device *);
388struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
389int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
390int thermal_zone_get_slope(struct thermal_zone_device *tz);
391int thermal_zone_get_offset(struct thermal_zone_device *tz);
392
393int thermal_zone_device_enable(struct thermal_zone_device *tz);
394int thermal_zone_device_disable(struct thermal_zone_device *tz);
395void thermal_zone_device_critical(struct thermal_zone_device *tz);
396#else
397static inline struct thermal_zone_device *thermal_zone_device_register(
398 const char *type, int trips, int mask, void *devdata,
399 struct thermal_zone_device_ops *ops,
400 struct thermal_zone_params *tzp,
401 int passive_delay, int polling_delay)
402{ return ERR_PTR(-ENODEV); }
403static inline void thermal_zone_device_unregister(
404 struct thermal_zone_device *tz)
405{ }
406static inline struct thermal_cooling_device *
407thermal_cooling_device_register(const char *type, void *devdata,
408 const struct thermal_cooling_device_ops *ops)
409{ return ERR_PTR(-ENODEV); }
410static inline struct thermal_cooling_device *
411thermal_of_cooling_device_register(struct device_node *np,
412 const char *type, void *devdata,
413 const struct thermal_cooling_device_ops *ops)
414{ return ERR_PTR(-ENODEV); }
415static inline struct thermal_cooling_device *
416devm_thermal_of_cooling_device_register(struct device *dev,
417 struct device_node *np,
418 char *type, void *devdata,
419 const struct thermal_cooling_device_ops *ops)
420{
421 return ERR_PTR(-ENODEV);
422}
423static inline void thermal_cooling_device_unregister(
424 struct thermal_cooling_device *cdev)
425{ }
426static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
427 const char *name)
428{ return ERR_PTR(-ENODEV); }
429static inline int thermal_zone_get_temp(
430 struct thermal_zone_device *tz, int *temp)
431{ return -ENODEV; }
432static inline int thermal_zone_get_slope(
433 struct thermal_zone_device *tz)
434{ return -ENODEV; }
435static inline int thermal_zone_get_offset(
436 struct thermal_zone_device *tz)
437{ return -ENODEV; }
438
439static inline int thermal_zone_device_enable(struct thermal_zone_device *tz)
440{ return -ENODEV; }
441
442static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
443{ return -ENODEV; }
444#endif
445
446#endif
447