Loading...
1===================================
2Generic Thermal Sysfs driver How To
3===================================
4
5Written by Sujith Thomas <sujith.thomas@intel.com>, Zhang Rui <rui.zhang@intel.com>
6
7Updated: 2 January 2008
8
9Copyright (c) 2008 Intel Corporation
10
11
120. Introduction
13===============
14
15The generic thermal sysfs provides a set of interfaces for thermal zone
16devices (sensors) and thermal cooling devices (fan, processor...) to register
17with the thermal management solution and to be a part of it.
18
19This how-to focuses on enabling new thermal zone and cooling devices to
20participate in thermal management.
21This solution is platform independent and any type of thermal zone devices
22and cooling devices should be able to make use of the infrastructure.
23
24The main task of the thermal sysfs driver is to expose thermal zone attributes
25as well as cooling device attributes to the user space.
26An intelligent thermal management application can make decisions based on
27inputs from thermal zone attributes (the current temperature and trip point
28temperature) and throttle appropriate devices.
29
30- `[0-*]` denotes any positive number starting from 0
31- `[1-*]` denotes any positive number starting from 1
32
331. thermal sysfs driver interface functions
34===========================================
35
361.1 thermal zone device interface
37---------------------------------
38
39 ::
40
41 struct thermal_zone_device
42 *thermal_zone_device_register(char *type,
43 int trips, int mask, void *devdata,
44 struct thermal_zone_device_ops *ops,
45 const struct thermal_zone_params *tzp,
46 int passive_delay, int polling_delay))
47
48 This interface function adds a new thermal zone device (sensor) to
49 /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to bind all the
50 thermal cooling devices registered at the same time.
51
52 type:
53 the thermal zone type.
54 trips:
55 the total number of trip points this thermal zone supports.
56 mask:
57 Bit string: If 'n'th bit is set, then trip point 'n' is writable.
58 devdata:
59 device private data
60 ops:
61 thermal zone device call-backs.
62
63 .bind:
64 bind the thermal zone device with a thermal cooling device.
65 .unbind:
66 unbind the thermal zone device with a thermal cooling device.
67 .get_temp:
68 get the current temperature of the thermal zone.
69 .set_trips:
70 set the trip points window. Whenever the current temperature
71 is updated, the trip points immediately below and above the
72 current temperature are found.
73 .get_mode:
74 get the current mode (enabled/disabled) of the thermal zone.
75
76 - "enabled" means the kernel thermal management is
77 enabled.
78 - "disabled" will prevent kernel thermal driver action
79 upon trip points so that user applications can take
80 charge of thermal management.
81 .set_mode:
82 set the mode (enabled/disabled) of the thermal zone.
83 .get_trip_type:
84 get the type of certain trip point.
85 .get_trip_temp:
86 get the temperature above which the certain trip point
87 will be fired.
88 .set_emul_temp:
89 set the emulation temperature which helps in debugging
90 different threshold temperature points.
91 tzp:
92 thermal zone platform parameters.
93 passive_delay:
94 number of milliseconds to wait between polls when
95 performing passive cooling.
96 polling_delay:
97 number of milliseconds to wait between polls when checking
98 whether trip points have been crossed (0 for interrupt driven systems).
99
100 ::
101
102 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
103
104 This interface function removes the thermal zone device.
105 It deletes the corresponding entry from /sys/class/thermal folder and
106 unbinds all the thermal cooling devices it uses.
107
108 ::
109
110 struct thermal_zone_device
111 *thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
112 void *data,
113 const struct thermal_zone_of_device_ops *ops)
114
115 This interface adds a new sensor to a DT thermal zone.
116 This function will search the list of thermal zones described in
117 device tree and look for the zone that refer to the sensor device
118 pointed by dev->of_node as temperature providers. For the zone
119 pointing to the sensor node, the sensor will be added to the DT
120 thermal zone device.
121
122 The parameters for this interface are:
123
124 dev:
125 Device node of sensor containing valid node pointer in
126 dev->of_node.
127 sensor_id:
128 a sensor identifier, in case the sensor IP has more
129 than one sensors
130 data:
131 a private pointer (owned by the caller) that will be
132 passed back, when a temperature reading is needed.
133 ops:
134 `struct thermal_zone_of_device_ops *`.
135
136 ============== =======================================
137 get_temp a pointer to a function that reads the
138 sensor temperature. This is mandatory
139 callback provided by sensor driver.
140 set_trips a pointer to a function that sets a
141 temperature window. When this window is
142 left the driver must inform the thermal
143 core via thermal_zone_device_update.
144 get_trend a pointer to a function that reads the
145 sensor temperature trend.
146 set_emul_temp a pointer to a function that sets
147 sensor emulated temperature.
148 ============== =======================================
149
150 The thermal zone temperature is provided by the get_temp() function
151 pointer of thermal_zone_of_device_ops. When called, it will
152 have the private pointer @data back.
153
154 It returns error pointer if fails otherwise valid thermal zone device
155 handle. Caller should check the return handle with IS_ERR() for finding
156 whether success or not.
157
158 ::
159
160 void thermal_zone_of_sensor_unregister(struct device *dev,
161 struct thermal_zone_device *tzd)
162
163 This interface unregisters a sensor from a DT thermal zone which was
164 successfully added by interface thermal_zone_of_sensor_register().
165 This function removes the sensor callbacks and private data from the
166 thermal zone device registered with thermal_zone_of_sensor_register()
167 interface. It will also silent the zone by remove the .get_temp() and
168 get_trend() thermal zone device callbacks.
169
170 ::
171
172 struct thermal_zone_device
173 *devm_thermal_zone_of_sensor_register(struct device *dev,
174 int sensor_id,
175 void *data,
176 const struct thermal_zone_of_device_ops *ops)
177
178 This interface is resource managed version of
179 thermal_zone_of_sensor_register().
180
181 All details of thermal_zone_of_sensor_register() described in
182 section 1.1.3 is applicable here.
183
184 The benefit of using this interface to register sensor is that it
185 is not require to explicitly call thermal_zone_of_sensor_unregister()
186 in error path or during driver unbinding as this is done by driver
187 resource manager.
188
189 ::
190
191 void devm_thermal_zone_of_sensor_unregister(struct device *dev,
192 struct thermal_zone_device *tzd)
193
194 This interface is resource managed version of
195 thermal_zone_of_sensor_unregister().
196 All details of thermal_zone_of_sensor_unregister() described in
197 section 1.1.4 is applicable here.
198 Normally this function will not need to be called and the resource
199 management code will ensure that the resource is freed.
200
201 ::
202
203 int thermal_zone_get_slope(struct thermal_zone_device *tz)
204
205 This interface is used to read the slope attribute value
206 for the thermal zone device, which might be useful for platform
207 drivers for temperature calculations.
208
209 ::
210
211 int thermal_zone_get_offset(struct thermal_zone_device *tz)
212
213 This interface is used to read the offset attribute value
214 for the thermal zone device, which might be useful for platform
215 drivers for temperature calculations.
216
2171.2 thermal cooling device interface
218------------------------------------
219
220
221 ::
222
223 struct thermal_cooling_device
224 *thermal_cooling_device_register(char *name,
225 void *devdata, struct thermal_cooling_device_ops *)
226
227 This interface function adds a new thermal cooling device (fan/processor/...)
228 to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries to bind itself
229 to all the thermal zone devices registered at the same time.
230
231 name:
232 the cooling device name.
233 devdata:
234 device private data.
235 ops:
236 thermal cooling devices call-backs.
237
238 .get_max_state:
239 get the Maximum throttle state of the cooling device.
240 .get_cur_state:
241 get the Currently requested throttle state of the
242 cooling device.
243 .set_cur_state:
244 set the Current throttle state of the cooling device.
245
246 ::
247
248 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
249
250 This interface function removes the thermal cooling device.
251 It deletes the corresponding entry from /sys/class/thermal folder and
252 unbinds itself from all the thermal zone devices using it.
253
2541.3 interface for binding a thermal zone device with a thermal cooling device
255-----------------------------------------------------------------------------
256
257 ::
258
259 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
260 int trip, struct thermal_cooling_device *cdev,
261 unsigned long upper, unsigned long lower, unsigned int weight);
262
263 This interface function binds a thermal cooling device to a particular trip
264 point of a thermal zone device.
265
266 This function is usually called in the thermal zone device .bind callback.
267
268 tz:
269 the thermal zone device
270 cdev:
271 thermal cooling device
272 trip:
273 indicates which trip point in this thermal zone the cooling device
274 is associated with.
275 upper:
276 the Maximum cooling state for this trip point.
277 THERMAL_NO_LIMIT means no upper limit,
278 and the cooling device can be in max_state.
279 lower:
280 the Minimum cooling state can be used for this trip point.
281 THERMAL_NO_LIMIT means no lower limit,
282 and the cooling device can be in cooling state 0.
283 weight:
284 the influence of this cooling device in this thermal
285 zone. See 1.4.1 below for more information.
286
287 ::
288
289 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
290 int trip, struct thermal_cooling_device *cdev);
291
292 This interface function unbinds a thermal cooling device from a particular
293 trip point of a thermal zone device. This function is usually called in
294 the thermal zone device .unbind callback.
295
296 tz:
297 the thermal zone device
298 cdev:
299 thermal cooling device
300 trip:
301 indicates which trip point in this thermal zone the cooling device
302 is associated with.
303
3041.4 Thermal Zone Parameters
305---------------------------
306
307 ::
308
309 struct thermal_zone_params
310
311 This structure defines the platform level parameters for a thermal zone.
312 This data, for each thermal zone should come from the platform layer.
313 This is an optional feature where some platforms can choose not to
314 provide this data.
315
316 .governor_name:
317 Name of the thermal governor used for this zone
318 .no_hwmon:
319 a boolean to indicate if the thermal to hwmon sysfs interface
320 is required. when no_hwmon == false, a hwmon sysfs interface
321 will be created. when no_hwmon == true, nothing will be done.
322 In case the thermal_zone_params is NULL, the hwmon interface
323 will be created (for backward compatibility).
324
3252. sysfs attributes structure
326=============================
327
328== ================
329RO read only value
330WO write only value
331RW read/write value
332== ================
333
334Thermal sysfs attributes will be represented under /sys/class/thermal.
335Hwmon sysfs I/F extension is also available under /sys/class/hwmon
336if hwmon is compiled in or built as a module.
337
338Thermal zone device sys I/F, created once it's registered::
339
340 /sys/class/thermal/thermal_zone[0-*]:
341 |---type: Type of the thermal zone
342 |---temp: Current temperature
343 |---mode: Working mode of the thermal zone
344 |---policy: Thermal governor used for this zone
345 |---available_policies: Available thermal governors for this zone
346 |---trip_point_[0-*]_temp: Trip point temperature
347 |---trip_point_[0-*]_type: Trip point type
348 |---trip_point_[0-*]_hyst: Hysteresis value for this trip point
349 |---emul_temp: Emulated temperature set node
350 |---sustainable_power: Sustainable dissipatable power
351 |---k_po: Proportional term during temperature overshoot
352 |---k_pu: Proportional term during temperature undershoot
353 |---k_i: PID's integral term in the power allocator gov
354 |---k_d: PID's derivative term in the power allocator
355 |---integral_cutoff: Offset above which errors are accumulated
356 |---slope: Slope constant applied as linear extrapolation
357 |---offset: Offset constant applied as linear extrapolation
358
359Thermal cooling device sys I/F, created once it's registered::
360
361 /sys/class/thermal/cooling_device[0-*]:
362 |---type: Type of the cooling device(processor/fan/...)
363 |---max_state: Maximum cooling state of the cooling device
364 |---cur_state: Current cooling state of the cooling device
365 |---stats: Directory containing cooling device's statistics
366 |---stats/reset: Writing any value resets the statistics
367 |---stats/time_in_state_ms: Time (msec) spent in various cooling states
368 |---stats/total_trans: Total number of times cooling state is changed
369 |---stats/trans_table: Cooling state transition table
370
371
372Then next two dynamic attributes are created/removed in pairs. They represent
373the relationship between a thermal zone and its associated cooling device.
374They are created/removed for each successful execution of
375thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device.
376
377::
378
379 /sys/class/thermal/thermal_zone[0-*]:
380 |---cdev[0-*]: [0-*]th cooling device in current thermal zone
381 |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
382 |---cdev[0-*]_weight: Influence of the cooling device in
383 this thermal zone
384
385Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
386the generic thermal driver also creates a hwmon sysfs I/F for each _type_
387of thermal zone device. E.g. the generic thermal driver registers one hwmon
388class device and build the associated hwmon sysfs I/F for all the registered
389ACPI thermal zones.
390
391Please read Documentation/ABI/testing/sysfs-class-thermal for thermal
392zone and cooling device attribute details.
393
394::
395
396 /sys/class/hwmon/hwmon[0-*]:
397 |---name: The type of the thermal zone devices
398 |---temp[1-*]_input: The current temperature of thermal zone [1-*]
399 |---temp[1-*]_critical: The critical trip point of thermal zone [1-*]
400
401Please read Documentation/hwmon/sysfs-interface.rst for additional information.
402
4033. A simple implementation
404==========================
405
406ACPI thermal zone may support multiple trip points like critical, hot,
407passive, active. If an ACPI thermal zone supports critical, passive,
408active[0] and active[1] at the same time, it may register itself as a
409thermal_zone_device (thermal_zone1) with 4 trip points in all.
410It has one processor and one fan, which are both registered as
411thermal_cooling_device. Both are considered to have the same
412effectiveness in cooling the thermal zone.
413
414If the processor is listed in _PSL method, and the fan is listed in _AL0
415method, the sys I/F structure will be built like this::
416
417 /sys/class/thermal:
418 |thermal_zone1:
419 |---type: acpitz
420 |---temp: 37000
421 |---mode: enabled
422 |---policy: step_wise
423 |---available_policies: step_wise fair_share
424 |---trip_point_0_temp: 100000
425 |---trip_point_0_type: critical
426 |---trip_point_1_temp: 80000
427 |---trip_point_1_type: passive
428 |---trip_point_2_temp: 70000
429 |---trip_point_2_type: active0
430 |---trip_point_3_temp: 60000
431 |---trip_point_3_type: active1
432 |---cdev0: --->/sys/class/thermal/cooling_device0
433 |---cdev0_trip_point: 1 /* cdev0 can be used for passive */
434 |---cdev0_weight: 1024
435 |---cdev1: --->/sys/class/thermal/cooling_device3
436 |---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
437 |---cdev1_weight: 1024
438
439 |cooling_device0:
440 |---type: Processor
441 |---max_state: 8
442 |---cur_state: 0
443
444 |cooling_device3:
445 |---type: Fan
446 |---max_state: 2
447 |---cur_state: 0
448
449 /sys/class/hwmon:
450 |hwmon0:
451 |---name: acpitz
452 |---temp1_input: 37000
453 |---temp1_crit: 100000
454
4554. Export Symbol APIs
456=====================
457
4584.1. get_tz_trend
459-----------------
460
461This function returns the trend of a thermal zone, i.e the rate of change
462of temperature of the thermal zone. Ideally, the thermal sensor drivers
463are supposed to implement the callback. If they don't, the thermal
464framework calculated the trend by comparing the previous and the current
465temperature values.
466
4674.2. get_thermal_instance
468-------------------------
469
470This function returns the thermal_instance corresponding to a given
471{thermal_zone, cooling_device, trip_point} combination. Returns NULL
472if such an instance does not exist.
473
4744.3. thermal_cdev_update
475------------------------
476
477This function serves as an arbitrator to set the state of a cooling
478device. It sets the cooling device to the deepest cooling state if
479possible.
480
4815. thermal_emergency_poweroff
482=============================
483
484On an event of critical trip temperature crossing the thermal framework
485shuts down the system by calling hw_protection_shutdown(). The
486hw_protection_shutdown() first attempts to perform an orderly shutdown
487but accepts a delay after which it proceeds doing a forced power-off
488or as last resort an emergency_restart.
489
490The delay should be carefully profiled so as to give adequate time for
491orderly poweroff.
492
493If the delay is set to 0 emergency poweroff will not be supported. So a
494carefully profiled non-zero positive value is a must for emergency
495poweroff to be triggered.
1===================================
2Generic Thermal Sysfs driver How To
3===================================
4
5Written by Sujith Thomas <sujith.thomas@intel.com>, Zhang Rui <rui.zhang@intel.com>
6
7Copyright (c) 2008 Intel Corporation
8
9
100. Introduction
11===============
12
13The generic thermal sysfs provides a set of interfaces for thermal zone
14devices (sensors) and thermal cooling devices (fan, processor...) to register
15with the thermal management solution and to be a part of it.
16
17This how-to focuses on enabling new thermal zone and cooling devices to
18participate in thermal management.
19This solution is platform independent and any type of thermal zone devices
20and cooling devices should be able to make use of the infrastructure.
21
22The main task of the thermal sysfs driver is to expose thermal zone attributes
23as well as cooling device attributes to the user space.
24An intelligent thermal management application can make decisions based on
25inputs from thermal zone attributes (the current temperature and trip point
26temperature) and throttle appropriate devices.
27
28- `[0-*]` denotes any positive number starting from 0
29- `[1-*]` denotes any positive number starting from 1
30
311. thermal sysfs driver interface functions
32===========================================
33
341.1 thermal zone device interface
35---------------------------------
36
37 ::
38
39 struct thermal_zone_device *
40 thermal_zone_device_register_with_trips(const char *type,
41 const struct thermal_trip *trips,
42 int num_trips, void *devdata,
43 const struct thermal_zone_device_ops *ops,
44 const struct thermal_zone_params *tzp,
45 unsigned int passive_delay,
46 unsigned int polling_delay)
47
48 This interface function adds a new thermal zone device (sensor) to the
49 /sys/class/thermal folder as `thermal_zone[0-*]`. It tries to bind all the
50 thermal cooling devices registered to it at the same time.
51
52 type:
53 the thermal zone type.
54 trips:
55 the table of trip points for this thermal zone.
56 devdata:
57 device private data
58 ops:
59 thermal zone device call-backs.
60
61 .should_bind:
62 check whether or not a given cooling device should be bound to
63 a given trip point in this thermal zone.
64 .get_temp:
65 get the current temperature of the thermal zone.
66 .set_trips:
67 set the trip points window. Whenever the current temperature
68 is updated, the trip points immediately below and above the
69 current temperature are found.
70 .change_mode:
71 change the mode (enabled/disabled) of the thermal zone.
72 .set_trip_temp:
73 set the temperature of a given trip point.
74 .get_crit_temp:
75 get the critical temperature for this thermal zone.
76 .set_emul_temp:
77 set the emulation temperature which helps in debugging
78 different threshold temperature points.
79 .get_trend:
80 get the trend of most recent zone temperature changes.
81 .hot:
82 hot trip point crossing handler.
83 .critical:
84 critical trip point crossing handler.
85 tzp:
86 thermal zone platform parameters.
87 passive_delay:
88 number of milliseconds to wait between polls when performing passive
89 cooling.
90 polling_delay:
91 number of milliseconds to wait between polls when checking
92 whether trip points have been crossed (0 for interrupt driven systems).
93
94 ::
95
96 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
97
98 This interface function removes the thermal zone device.
99 It deletes the corresponding entry from /sys/class/thermal folder and
100 unbinds all the thermal cooling devices it uses.
101
102 ::
103
104 struct thermal_zone_device
105 *thermal_zone_of_sensor_register(struct device *dev, int sensor_id,
106 void *data,
107 const struct thermal_zone_of_device_ops *ops)
108
109 This interface adds a new sensor to a DT thermal zone.
110 This function will search the list of thermal zones described in
111 device tree and look for the zone that refer to the sensor device
112 pointed by dev->of_node as temperature providers. For the zone
113 pointing to the sensor node, the sensor will be added to the DT
114 thermal zone device.
115
116 The parameters for this interface are:
117
118 dev:
119 Device node of sensor containing valid node pointer in
120 dev->of_node.
121 sensor_id:
122 a sensor identifier, in case the sensor IP has more
123 than one sensors
124 data:
125 a private pointer (owned by the caller) that will be
126 passed back, when a temperature reading is needed.
127 ops:
128 `struct thermal_zone_of_device_ops *`.
129
130 ============== =======================================
131 get_temp a pointer to a function that reads the
132 sensor temperature. This is mandatory
133 callback provided by sensor driver.
134 set_trips a pointer to a function that sets a
135 temperature window. When this window is
136 left the driver must inform the thermal
137 core via thermal_zone_device_update.
138 get_trend a pointer to a function that reads the
139 sensor temperature trend.
140 set_emul_temp a pointer to a function that sets
141 sensor emulated temperature.
142 ============== =======================================
143
144 The thermal zone temperature is provided by the get_temp() function
145 pointer of thermal_zone_of_device_ops. When called, it will
146 have the private pointer @data back.
147
148 It returns error pointer if fails otherwise valid thermal zone device
149 handle. Caller should check the return handle with IS_ERR() for finding
150 whether success or not.
151
152 ::
153
154 void thermal_zone_of_sensor_unregister(struct device *dev,
155 struct thermal_zone_device *tzd)
156
157 This interface unregisters a sensor from a DT thermal zone which was
158 successfully added by interface thermal_zone_of_sensor_register().
159 This function removes the sensor callbacks and private data from the
160 thermal zone device registered with thermal_zone_of_sensor_register()
161 interface. It will also silent the zone by remove the .get_temp() and
162 get_trend() thermal zone device callbacks.
163
164 ::
165
166 struct thermal_zone_device
167 *devm_thermal_zone_of_sensor_register(struct device *dev,
168 int sensor_id,
169 void *data,
170 const struct thermal_zone_of_device_ops *ops)
171
172 This interface is resource managed version of
173 thermal_zone_of_sensor_register().
174
175 All details of thermal_zone_of_sensor_register() described in
176 section 1.1.3 is applicable here.
177
178 The benefit of using this interface to register sensor is that it
179 is not require to explicitly call thermal_zone_of_sensor_unregister()
180 in error path or during driver unbinding as this is done by driver
181 resource manager.
182
183 ::
184
185 void devm_thermal_zone_of_sensor_unregister(struct device *dev,
186 struct thermal_zone_device *tzd)
187
188 This interface is resource managed version of
189 thermal_zone_of_sensor_unregister().
190 All details of thermal_zone_of_sensor_unregister() described in
191 section 1.1.4 is applicable here.
192 Normally this function will not need to be called and the resource
193 management code will ensure that the resource is freed.
194
195 ::
196
197 int thermal_zone_get_slope(struct thermal_zone_device *tz)
198
199 This interface is used to read the slope attribute value
200 for the thermal zone device, which might be useful for platform
201 drivers for temperature calculations.
202
203 ::
204
205 int thermal_zone_get_offset(struct thermal_zone_device *tz)
206
207 This interface is used to read the offset attribute value
208 for the thermal zone device, which might be useful for platform
209 drivers for temperature calculations.
210
2111.2 thermal cooling device interface
212------------------------------------
213
214
215 ::
216
217 struct thermal_cooling_device
218 *thermal_cooling_device_register(char *name,
219 void *devdata, struct thermal_cooling_device_ops *)
220
221 This interface function adds a new thermal cooling device (fan/processor/...)
222 to /sys/class/thermal/ folder as `cooling_device[0-*]`. It tries to bind itself
223 to all the thermal zone devices registered at the same time.
224
225 name:
226 the cooling device name.
227 devdata:
228 device private data.
229 ops:
230 thermal cooling devices call-backs.
231
232 .get_max_state:
233 get the Maximum throttle state of the cooling device.
234 .get_cur_state:
235 get the Currently requested throttle state of the
236 cooling device.
237 .set_cur_state:
238 set the Current throttle state of the cooling device.
239
240 ::
241
242 void thermal_cooling_device_unregister(struct thermal_cooling_device *cdev)
243
244 This interface function removes the thermal cooling device.
245 It deletes the corresponding entry from /sys/class/thermal folder and
246 unbinds itself from all the thermal zone devices using it.
247
2481.4 Thermal Zone Parameters
249---------------------------
250
251 ::
252
253 struct thermal_zone_params
254
255 This structure defines the platform level parameters for a thermal zone.
256 This data, for each thermal zone should come from the platform layer.
257 This is an optional feature where some platforms can choose not to
258 provide this data.
259
260 .governor_name:
261 Name of the thermal governor used for this zone
262 .no_hwmon:
263 a boolean to indicate if the thermal to hwmon sysfs interface
264 is required. when no_hwmon == false, a hwmon sysfs interface
265 will be created. when no_hwmon == true, nothing will be done.
266 In case the thermal_zone_params is NULL, the hwmon interface
267 will be created (for backward compatibility).
268
2692. sysfs attributes structure
270=============================
271
272== ================
273RO read only value
274WO write only value
275RW read/write value
276== ================
277
278Thermal sysfs attributes will be represented under /sys/class/thermal.
279Hwmon sysfs I/F extension is also available under /sys/class/hwmon
280if hwmon is compiled in or built as a module.
281
282Thermal zone device sys I/F, created once it's registered::
283
284 /sys/class/thermal/thermal_zone[0-*]:
285 |---type: Type of the thermal zone
286 |---temp: Current temperature
287 |---mode: Working mode of the thermal zone
288 |---policy: Thermal governor used for this zone
289 |---available_policies: Available thermal governors for this zone
290 |---trip_point_[0-*]_temp: Trip point temperature
291 |---trip_point_[0-*]_type: Trip point type
292 |---trip_point_[0-*]_hyst: Hysteresis value for this trip point
293 |---emul_temp: Emulated temperature set node
294 |---sustainable_power: Sustainable dissipatable power
295 |---k_po: Proportional term during temperature overshoot
296 |---k_pu: Proportional term during temperature undershoot
297 |---k_i: PID's integral term in the power allocator gov
298 |---k_d: PID's derivative term in the power allocator
299 |---integral_cutoff: Offset above which errors are accumulated
300 |---slope: Slope constant applied as linear extrapolation
301 |---offset: Offset constant applied as linear extrapolation
302
303Thermal cooling device sys I/F, created once it's registered::
304
305 /sys/class/thermal/cooling_device[0-*]:
306 |---type: Type of the cooling device(processor/fan/...)
307 |---max_state: Maximum cooling state of the cooling device
308 |---cur_state: Current cooling state of the cooling device
309 |---stats: Directory containing cooling device's statistics
310 |---stats/reset: Writing any value resets the statistics
311 |---stats/time_in_state_ms: Time (msec) spent in various cooling states
312 |---stats/total_trans: Total number of times cooling state is changed
313 |---stats/trans_table: Cooling state transition table
314
315
316Then next two dynamic attributes are created/removed in pairs. They represent
317the relationship between a thermal zone and its associated cooling device.
318
319::
320
321 /sys/class/thermal/thermal_zone[0-*]:
322 |---cdev[0-*]: [0-*]th cooling device in current thermal zone
323 |---cdev[0-*]_trip_point: Trip point that cdev[0-*] is associated with
324 |---cdev[0-*]_weight: Influence of the cooling device in
325 this thermal zone
326
327Besides the thermal zone device sysfs I/F and cooling device sysfs I/F,
328the generic thermal driver also creates a hwmon sysfs I/F for each _type_
329of thermal zone device. E.g. the generic thermal driver registers one hwmon
330class device and build the associated hwmon sysfs I/F for all the registered
331ACPI thermal zones.
332
333Please read Documentation/ABI/testing/sysfs-class-thermal for thermal
334zone and cooling device attribute details.
335
336::
337
338 /sys/class/hwmon/hwmon[0-*]:
339 |---name: The type of the thermal zone devices
340 |---temp[1-*]_input: The current temperature of thermal zone [1-*]
341 |---temp[1-*]_critical: The critical trip point of thermal zone [1-*]
342
343Please read Documentation/hwmon/sysfs-interface.rst for additional information.
344
3453. A simple implementation
346==========================
347
348ACPI thermal zone may support multiple trip points like critical, hot,
349passive, active. If an ACPI thermal zone supports critical, passive,
350active[0] and active[1] at the same time, it may register itself as a
351thermal_zone_device (thermal_zone1) with 4 trip points in all.
352It has one processor and one fan, which are both registered as
353thermal_cooling_device. Both are considered to have the same
354effectiveness in cooling the thermal zone.
355
356If the processor is listed in _PSL method, and the fan is listed in _AL0
357method, the sys I/F structure will be built like this::
358
359 /sys/class/thermal:
360 |thermal_zone1:
361 |---type: acpitz
362 |---temp: 37000
363 |---mode: enabled
364 |---policy: step_wise
365 |---available_policies: step_wise fair_share
366 |---trip_point_0_temp: 100000
367 |---trip_point_0_type: critical
368 |---trip_point_1_temp: 80000
369 |---trip_point_1_type: passive
370 |---trip_point_2_temp: 70000
371 |---trip_point_2_type: active0
372 |---trip_point_3_temp: 60000
373 |---trip_point_3_type: active1
374 |---cdev0: --->/sys/class/thermal/cooling_device0
375 |---cdev0_trip_point: 1 /* cdev0 can be used for passive */
376 |---cdev0_weight: 1024
377 |---cdev1: --->/sys/class/thermal/cooling_device3
378 |---cdev1_trip_point: 2 /* cdev1 can be used for active[0]*/
379 |---cdev1_weight: 1024
380
381 |cooling_device0:
382 |---type: Processor
383 |---max_state: 8
384 |---cur_state: 0
385
386 |cooling_device3:
387 |---type: Fan
388 |---max_state: 2
389 |---cur_state: 0
390
391 /sys/class/hwmon:
392 |hwmon0:
393 |---name: acpitz
394 |---temp1_input: 37000
395 |---temp1_crit: 100000
396
3974. Export Symbol APIs
398=====================
399
4004.1. get_tz_trend
401-----------------
402
403This function returns the trend of a thermal zone, i.e the rate of change
404of temperature of the thermal zone. Ideally, the thermal sensor drivers
405are supposed to implement the callback. If they don't, the thermal
406framework calculated the trend by comparing the previous and the current
407temperature values.
408
4094.2. thermal_cdev_update
410------------------------
411
412This function serves as an arbitrator to set the state of a cooling
413device. It sets the cooling device to the deepest cooling state if
414possible.
415
4165. thermal_emergency_poweroff
417=============================
418
419On an event of critical trip temperature crossing the thermal framework
420shuts down the system by calling hw_protection_shutdown(). The
421hw_protection_shutdown() first attempts to perform an orderly shutdown
422but accepts a delay after which it proceeds doing a forced power-off
423or as last resort an emergency_restart.
424
425The delay should be carefully profiled so as to give adequate time for
426orderly poweroff.
427
428If the delay is set to 0 emergency poweroff will not be supported. So a
429carefully profiled non-zero positive value is a must for emergency
430poweroff to be triggered.