This source file includes following definitions.
- thermal_zone_of_sensor_register
- thermal_zone_of_sensor_unregister
- devm_thermal_zone_of_sensor_register
- devm_thermal_zone_of_sensor_unregister
- cdev_is_power_actor
- cdev_is_power_actor
- power_actor_get_max_power
- power_actor_get_min_power
- power_actor_set_power
- thermal_zone_device_register
- thermal_zone_device_unregister
- thermal_zone_bind_cooling_device
- thermal_zone_unbind_cooling_device
- thermal_zone_device_update
- thermal_zone_set_trips
- thermal_cooling_device_register
- thermal_of_cooling_device_register
- devm_thermal_of_cooling_device_register
- thermal_cooling_device_unregister
- thermal_zone_get_zone_by_name
- thermal_zone_get_temp
- thermal_zone_get_slope
- thermal_zone_get_offset
- get_tz_trend
- get_thermal_instance
- thermal_cdev_update
- thermal_notify_framework
- thermal_generate_netlink_event
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
35
36 #define DECI_KELVIN_TO_CELSIUS(t) ({ \
37 long _t = (t); \
38 ((_t-2732 >= 0) ? (_t-2732+5)/10 : (_t-2732-5)/10); \
39 })
40 #define CELSIUS_TO_DECI_KELVIN(t) ((t)*10+2732)
41 #define DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, off) (((t) - (off)) * 100)
42 #define DECI_KELVIN_TO_MILLICELSIUS(t) DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, 2732)
43 #define MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, off) (((t) / 100) + (off))
44 #define MILLICELSIUS_TO_DECI_KELVIN(t) MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, 2732)
45
46
47 #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
48 #define DEFAULT_THERMAL_GOVERNOR "step_wise"
49 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
50 #define DEFAULT_THERMAL_GOVERNOR "fair_share"
51 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
52 #define DEFAULT_THERMAL_GOVERNOR "user_space"
53 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
54 #define DEFAULT_THERMAL_GOVERNOR "power_allocator"
55 #endif
56
57 struct thermal_zone_device;
58 struct thermal_cooling_device;
59 struct thermal_instance;
60
61 enum thermal_device_mode {
62 THERMAL_DEVICE_DISABLED = 0,
63 THERMAL_DEVICE_ENABLED,
64 };
65
66 enum thermal_trip_type {
67 THERMAL_TRIP_ACTIVE = 0,
68 THERMAL_TRIP_PASSIVE,
69 THERMAL_TRIP_HOT,
70 THERMAL_TRIP_CRITICAL,
71 };
72
73 enum thermal_trend {
74 THERMAL_TREND_STABLE,
75 THERMAL_TREND_RAISING,
76 THERMAL_TREND_DROPPING,
77 THERMAL_TREND_RAISE_FULL,
78 THERMAL_TREND_DROP_FULL,
79 };
80
81
82 enum thermal_notify_event {
83 THERMAL_EVENT_UNSPECIFIED,
84 THERMAL_EVENT_TEMP_SAMPLE,
85 THERMAL_TRIP_VIOLATED,
86 THERMAL_TRIP_CHANGED,
87 THERMAL_DEVICE_DOWN,
88 THERMAL_DEVICE_UP,
89 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED,
90 THERMAL_TABLE_CHANGED,
91 };
92
93 struct thermal_zone_device_ops {
94 int (*bind) (struct thermal_zone_device *,
95 struct thermal_cooling_device *);
96 int (*unbind) (struct thermal_zone_device *,
97 struct thermal_cooling_device *);
98 int (*get_temp) (struct thermal_zone_device *, int *);
99 int (*set_trips) (struct thermal_zone_device *, int, int);
100 int (*get_mode) (struct thermal_zone_device *,
101 enum thermal_device_mode *);
102 int (*set_mode) (struct thermal_zone_device *,
103 enum thermal_device_mode);
104 int (*get_trip_type) (struct thermal_zone_device *, int,
105 enum thermal_trip_type *);
106 int (*get_trip_temp) (struct thermal_zone_device *, int, int *);
107 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
108 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *);
109 int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
110 int (*get_crit_temp) (struct thermal_zone_device *, int *);
111 int (*set_emul_temp) (struct thermal_zone_device *, int);
112 int (*get_trend) (struct thermal_zone_device *, int,
113 enum thermal_trend *);
114 int (*notify) (struct thermal_zone_device *, int,
115 enum thermal_trip_type);
116 };
117
118 struct thermal_cooling_device_ops {
119 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
120 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
121 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
122 int (*get_requested_power)(struct thermal_cooling_device *,
123 struct thermal_zone_device *, u32 *);
124 int (*state2power)(struct thermal_cooling_device *,
125 struct thermal_zone_device *, unsigned long, u32 *);
126 int (*power2state)(struct thermal_cooling_device *,
127 struct thermal_zone_device *, u32, unsigned long *);
128 };
129
130 struct thermal_cooling_device {
131 int id;
132 char type[THERMAL_NAME_LENGTH];
133 struct device device;
134 struct device_node *np;
135 void *devdata;
136 void *stats;
137 const struct thermal_cooling_device_ops *ops;
138 bool updated;
139 struct mutex lock;
140 struct list_head thermal_instances;
141 struct list_head node;
142 };
143
144 struct thermal_attr {
145 struct device_attribute attr;
146 char name[THERMAL_NAME_LENGTH];
147 };
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 struct thermal_zone_device {
192 int id;
193 char type[THERMAL_NAME_LENGTH];
194 struct device device;
195 struct attribute_group trips_attribute_group;
196 struct thermal_attr *trip_temp_attrs;
197 struct thermal_attr *trip_type_attrs;
198 struct thermal_attr *trip_hyst_attrs;
199 void *devdata;
200 int trips;
201 unsigned long trips_disabled;
202 int passive_delay;
203 int polling_delay;
204 int temperature;
205 int last_temperature;
206 int emul_temperature;
207 int passive;
208 int prev_low_trip;
209 int prev_high_trip;
210 unsigned int forced_passive;
211 atomic_t need_update;
212 struct thermal_zone_device_ops *ops;
213 struct thermal_zone_params *tzp;
214 struct thermal_governor *governor;
215 void *governor_data;
216 struct list_head thermal_instances;
217 struct ida ida;
218 struct mutex lock;
219 struct list_head node;
220 struct delayed_work poll_queue;
221 enum thermal_notify_event notify_event;
222 };
223
224
225
226
227
228
229
230
231
232
233
234
235
236 struct thermal_governor {
237 char name[THERMAL_NAME_LENGTH];
238 int (*bind_to_tz)(struct thermal_zone_device *tz);
239 void (*unbind_from_tz)(struct thermal_zone_device *tz);
240 int (*throttle)(struct thermal_zone_device *tz, int trip);
241 struct list_head governor_list;
242 };
243
244
245 struct thermal_bind_params {
246 struct thermal_cooling_device *cdev;
247
248
249
250
251
252
253
254
255
256
257 int weight;
258
259
260
261
262
263
264 int trip_mask;
265
266
267
268
269
270
271
272
273
274 unsigned long *binding_limits;
275 int (*match) (struct thermal_zone_device *tz,
276 struct thermal_cooling_device *cdev);
277 };
278
279
280 struct thermal_zone_params {
281 char governor_name[THERMAL_NAME_LENGTH];
282
283
284
285
286
287
288 bool no_hwmon;
289
290 int num_tbps;
291 struct thermal_bind_params *tbp;
292
293
294
295
296
297 u32 sustainable_power;
298
299
300
301
302
303 s32 k_po;
304
305
306
307
308
309 s32 k_pu;
310
311
312 s32 k_i;
313
314
315 s32 k_d;
316
317
318 s32 integral_cutoff;
319
320
321
322
323
324 int slope;
325
326
327
328
329 int offset;
330 };
331
332 struct thermal_genl_event {
333 u32 orig;
334 enum events event;
335 };
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353 struct thermal_zone_of_device_ops {
354 int (*get_temp)(void *, int *);
355 int (*get_trend)(void *, int, enum thermal_trend *);
356 int (*set_trips)(void *, int, int);
357 int (*set_emul_temp)(void *, int);
358 int (*set_trip_temp)(void *, int, int);
359 };
360
361
362
363
364
365
366
367
368
369 struct thermal_trip {
370 struct device_node *np;
371 int temperature;
372 int hysteresis;
373 enum thermal_trip_type type;
374 };
375
376
377 #ifdef CONFIG_THERMAL_OF
378 struct thermal_zone_device *
379 thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
380 const struct thermal_zone_of_device_ops *ops);
381 void thermal_zone_of_sensor_unregister(struct device *dev,
382 struct thermal_zone_device *tz);
383 struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
384 struct device *dev, int id, void *data,
385 const struct thermal_zone_of_device_ops *ops);
386 void devm_thermal_zone_of_sensor_unregister(struct device *dev,
387 struct thermal_zone_device *tz);
388 #else
389 static inline struct thermal_zone_device *
390 thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
391 const struct thermal_zone_of_device_ops *ops)
392 {
393 return ERR_PTR(-ENODEV);
394 }
395
396 static inline
397 void thermal_zone_of_sensor_unregister(struct device *dev,
398 struct thermal_zone_device *tz)
399 {
400 }
401
402 static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
403 struct device *dev, int id, void *data,
404 const struct thermal_zone_of_device_ops *ops)
405 {
406 return ERR_PTR(-ENODEV);
407 }
408
409 static inline
410 void devm_thermal_zone_of_sensor_unregister(struct device *dev,
411 struct thermal_zone_device *tz)
412 {
413 }
414
415 #endif
416
417 #if IS_ENABLED(CONFIG_THERMAL)
418 static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
419 {
420 return cdev->ops->get_requested_power && cdev->ops->state2power &&
421 cdev->ops->power2state;
422 }
423
424 int power_actor_get_max_power(struct thermal_cooling_device *,
425 struct thermal_zone_device *tz, u32 *max_power);
426 int power_actor_get_min_power(struct thermal_cooling_device *,
427 struct thermal_zone_device *tz, u32 *min_power);
428 int power_actor_set_power(struct thermal_cooling_device *,
429 struct thermal_instance *, u32);
430 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
431 void *, struct thermal_zone_device_ops *,
432 struct thermal_zone_params *, int, int);
433 void thermal_zone_device_unregister(struct thermal_zone_device *);
434
435 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
436 struct thermal_cooling_device *,
437 unsigned long, unsigned long,
438 unsigned int);
439 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
440 struct thermal_cooling_device *);
441 void thermal_zone_device_update(struct thermal_zone_device *,
442 enum thermal_notify_event);
443 void thermal_zone_set_trips(struct thermal_zone_device *);
444
445 struct thermal_cooling_device *thermal_cooling_device_register(const char *,
446 void *, const struct thermal_cooling_device_ops *);
447 struct thermal_cooling_device *
448 thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
449 const struct thermal_cooling_device_ops *);
450 struct thermal_cooling_device *
451 devm_thermal_of_cooling_device_register(struct device *dev,
452 struct device_node *np,
453 char *type, void *devdata,
454 const struct thermal_cooling_device_ops *ops);
455 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
456 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
457 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
458 int thermal_zone_get_slope(struct thermal_zone_device *tz);
459 int thermal_zone_get_offset(struct thermal_zone_device *tz);
460
461 int get_tz_trend(struct thermal_zone_device *, int);
462 struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
463 struct thermal_cooling_device *, int);
464 void thermal_cdev_update(struct thermal_cooling_device *);
465 void thermal_notify_framework(struct thermal_zone_device *, int);
466 #else
467 static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
468 { return false; }
469 static inline int power_actor_get_max_power(struct thermal_cooling_device *cdev,
470 struct thermal_zone_device *tz, u32 *max_power)
471 { return 0; }
472 static inline int power_actor_get_min_power(struct thermal_cooling_device *cdev,
473 struct thermal_zone_device *tz,
474 u32 *min_power)
475 { return -ENODEV; }
476 static inline int power_actor_set_power(struct thermal_cooling_device *cdev,
477 struct thermal_instance *tz, u32 power)
478 { return 0; }
479 static inline struct thermal_zone_device *thermal_zone_device_register(
480 const char *type, int trips, int mask, void *devdata,
481 struct thermal_zone_device_ops *ops,
482 struct thermal_zone_params *tzp,
483 int passive_delay, int polling_delay)
484 { return ERR_PTR(-ENODEV); }
485 static inline void thermal_zone_device_unregister(
486 struct thermal_zone_device *tz)
487 { }
488 static inline int thermal_zone_bind_cooling_device(
489 struct thermal_zone_device *tz, int trip,
490 struct thermal_cooling_device *cdev,
491 unsigned long upper, unsigned long lower,
492 unsigned int weight)
493 { return -ENODEV; }
494 static inline int thermal_zone_unbind_cooling_device(
495 struct thermal_zone_device *tz, int trip,
496 struct thermal_cooling_device *cdev)
497 { return -ENODEV; }
498 static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
499 enum thermal_notify_event event)
500 { }
501 static inline void thermal_zone_set_trips(struct thermal_zone_device *tz)
502 { }
503 static inline struct thermal_cooling_device *
504 thermal_cooling_device_register(char *type, void *devdata,
505 const struct thermal_cooling_device_ops *ops)
506 { return ERR_PTR(-ENODEV); }
507 static inline struct thermal_cooling_device *
508 thermal_of_cooling_device_register(struct device_node *np,
509 char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
510 { return ERR_PTR(-ENODEV); }
511 static inline struct thermal_cooling_device *
512 devm_thermal_of_cooling_device_register(struct device *dev,
513 struct device_node *np,
514 char *type, void *devdata,
515 const struct thermal_cooling_device_ops *ops)
516 {
517 return ERR_PTR(-ENODEV);
518 }
519 static inline void thermal_cooling_device_unregister(
520 struct thermal_cooling_device *cdev)
521 { }
522 static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
523 const char *name)
524 { return ERR_PTR(-ENODEV); }
525 static inline int thermal_zone_get_temp(
526 struct thermal_zone_device *tz, int *temp)
527 { return -ENODEV; }
528 static inline int thermal_zone_get_slope(
529 struct thermal_zone_device *tz)
530 { return -ENODEV; }
531 static inline int thermal_zone_get_offset(
532 struct thermal_zone_device *tz)
533 { return -ENODEV; }
534 static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
535 { return -ENODEV; }
536 static inline struct thermal_instance *
537 get_thermal_instance(struct thermal_zone_device *tz,
538 struct thermal_cooling_device *cdev, int trip)
539 { return ERR_PTR(-ENODEV); }
540 static inline void thermal_cdev_update(struct thermal_cooling_device *cdev)
541 { }
542 static inline void thermal_notify_framework(struct thermal_zone_device *tz,
543 int trip)
544 { }
545 #endif
546
547 #if defined(CONFIG_NET) && IS_ENABLED(CONFIG_THERMAL)
548 extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
549 enum events event);
550 #else
551 static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz,
552 enum events event)
553 {
554 return 0;
555 }
556 #endif
557
558 #endif