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