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