thermal: Fix spelling mistake "disabed" -> "disabled"
[linux-block.git] / include / linux / thermal.h
CommitLineData
7e3c0381 1/* SPDX-License-Identifier: GPL-2.0 */
203d3d4a
ZR
2/*
3 * thermal.h ($Revision: 0 $)
4 *
5 * Copyright (C) 2008 Intel Corp
6 * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
7 * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
203d3d4a
ZR
8 */
9
10#ifndef __THERMAL_H__
11#define __THERMAL_H__
12
a116b5d4 13#include <linux/of.h>
203d3d4a
ZR
14#include <linux/idr.h>
15#include <linux/device.h>
4d0fe749 16#include <linux/sysfs.h>
b1569e99 17#include <linux/workqueue.h>
af6c9f16 18#include <uapi/linux/thermal.h>
203d3d4a 19
23064088 20#define THERMAL_MAX_TRIPS 12
23064088 21
57df8106
ZR
22/* invalid cooling state */
23#define THERMAL_CSTATE_INVALID -1UL
24
23064088 25/* No upper/lower limit requirement */
a940cb34 26#define THERMAL_NO_LIMIT ((u32)~0)
23064088 27
6cd9e9f6
KS
28/* Default weight of a bound cooling device */
29#define THERMAL_WEIGHT_DEFAULT 0
30
bb431ba2
ZR
31/* use value, which < 0K, to indicate an invalid/uninitialized temperature */
32#define THERMAL_TEMP_INVALID -274000
33
203d3d4a
ZR
34struct thermal_zone_device;
35struct thermal_cooling_device;
35b11d2e 36struct thermal_instance;
c68df440 37struct thermal_attr;
203d3d4a 38
601f3d42
ZR
39enum thermal_trend {
40 THERMAL_TREND_STABLE, /* temperature is stable */
41 THERMAL_TREND_RAISING, /* temperature is raising */
42 THERMAL_TREND_DROPPING, /* temperature is dropping */
d069015e
ZR
43 THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
44 THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
601f3d42
ZR
45};
46
0e70f466
SP
47/* Thermal notification reason */
48enum thermal_notify_event {
49 THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */
50 THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */
51 THERMAL_TRIP_VIOLATED, /* TRIP Point violation */
52 THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */
53 THERMAL_DEVICE_DOWN, /* Thermal device is down */
54 THERMAL_DEVICE_UP, /* Thermal device is up after a down event */
55 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */
38e44da5 56 THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
88052319 57 THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
0e70f466
SP
58};
59
203d3d4a
ZR
60struct thermal_zone_device_ops {
61 int (*bind) (struct thermal_zone_device *,
62 struct thermal_cooling_device *);
63 int (*unbind) (struct thermal_zone_device *,
64 struct thermal_cooling_device *);
17e8351a 65 int (*get_temp) (struct thermal_zone_device *, int *);
060c034a 66 int (*set_trips) (struct thermal_zone_device *, int, int);
f5e50bf4 67 int (*change_mode) (struct thermal_zone_device *,
6503e5df
MG
68 enum thermal_device_mode);
69 int (*get_trip_type) (struct thermal_zone_device *, int,
70 enum thermal_trip_type *);
17e8351a
SH
71 int (*get_trip_temp) (struct thermal_zone_device *, int, int *);
72 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
73 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *);
74 int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
75 int (*get_crit_temp) (struct thermal_zone_device *, int *);
76 int (*set_emul_temp) (struct thermal_zone_device *, int);
601f3d42
ZR
77 int (*get_trend) (struct thermal_zone_device *, int,
78 enum thermal_trend *);
d7203eed
DL
79 void (*hot)(struct thermal_zone_device *);
80 void (*critical)(struct thermal_zone_device *);
203d3d4a
ZR
81};
82
83struct thermal_cooling_device_ops {
6503e5df
MG
84 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
85 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
86 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
ecd1d2a3 87 int (*get_requested_power)(struct thermal_cooling_device *, u32 *);
88 int (*state2power)(struct thermal_cooling_device *, unsigned long, u32 *);
89 int (*power2state)(struct thermal_cooling_device *, u32, unsigned long *);
203d3d4a
ZR
90};
91
203d3d4a
ZR
92struct thermal_cooling_device {
93 int id;
94 char type[THERMAL_NAME_LENGTH];
95 struct device device;
4e5e4705 96 struct device_node *np;
203d3d4a 97 void *devdata;
8ea22951 98 void *stats;
5b275ce2 99 const struct thermal_cooling_device_ops *ops;
ce119f83 100 bool updated; /* true if the cooling device does not need update */
f4a821ce 101 struct mutex lock; /* protect thermal_instances list */
b5e4ae62 102 struct list_head thermal_instances;
203d3d4a
ZR
103 struct list_head node;
104};
105
c708a98f
JM
106/**
107 * struct thermal_zone_device - structure for a thermal zone
108 * @id: unique id number for each thermal zone
109 * @type: the thermal zone device type
110 * @device: &struct device for this thermal zone
111 * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
112 * @trip_type_attrs: attributes for trip points for sysfs: trip type
113 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
cbba1d71 114 * @mode: current mode of this thermal zone
c708a98f
JM
115 * @devdata: private pointer for device private data
116 * @trips: number of trip points the thermal zone supports
81ad4276 117 * @trips_disabled; bitmap for disabled trips
17d399cd
DL
118 * @passive_delay_jiffies: number of jiffies to wait between polls when
119 * performing passive cooling.
17d399cd
DL
120 * @polling_delay_jiffies: number of jiffies to wait between polls when
121 * checking whether trip points have been crossed (0 for
122 * interrupt driven systems)
c708a98f
JM
123 * @temperature: current temperature. This is only for core code,
124 * drivers should use thermal_zone_get_temp() to get the
125 * current temperature
126 * @last_temperature: previous temperature read
127 * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION
128 * @passive: 1 if you've crossed a passive trip point, 0 otherwise.
060c034a
SH
129 * @prev_low_trip: the low current temperature if you've crossed a passive
130 trip point.
131 * @prev_high_trip: the above current temperature if you've crossed a
132 passive trip point.
4511f716 133 * @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
c708a98f
JM
134 * @ops: operations this &thermal_zone_device supports
135 * @tzp: thermal zone parameters
136 * @governor: pointer to the governor for this thermal zone
e33df1d2 137 * @governor_data: private pointer for governor data
c708a98f 138 * @thermal_instances: list of &struct thermal_instance of this thermal zone
b31ef828 139 * @ida: &struct ida to generate unique id for this zone's cooling
c708a98f
JM
140 * devices
141 * @lock: lock to protect thermal_instances list
142 * @node: node in thermal_tz_list (in thermal_core.c)
143 * @poll_queue: delayed work for polling
0e70f466 144 * @notify_event: Last notification event
c708a98f 145 */
203d3d4a
ZR
146struct thermal_zone_device {
147 int id;
148 char type[THERMAL_NAME_LENGTH];
149 struct device device;
4d0fe749 150 struct attribute_group trips_attribute_group;
c56f5c03
D
151 struct thermal_attr *trip_temp_attrs;
152 struct thermal_attr *trip_type_attrs;
27365a6c 153 struct thermal_attr *trip_hyst_attrs;
cbba1d71 154 enum thermal_device_mode mode;
203d3d4a
ZR
155 void *devdata;
156 int trips;
81ad4276 157 unsigned long trips_disabled; /* bitmap for disabled trips */
17d399cd
DL
158 unsigned long passive_delay_jiffies;
159 unsigned long polling_delay_jiffies;
601f3d42 160 int temperature;
b1569e99 161 int last_temperature;
e6e238c3 162 int emul_temperature;
908b9fb7 163 int passive;
060c034a
SH
164 int prev_low_trip;
165 int prev_high_trip;
4511f716 166 atomic_t need_update;
4e5e4705 167 struct thermal_zone_device_ops *ops;
6b775e87 168 struct thermal_zone_params *tzp;
a4a15485 169 struct thermal_governor *governor;
e33df1d2 170 void *governor_data;
2d374139 171 struct list_head thermal_instances;
b31ef828 172 struct ida ida;
c708a98f 173 struct mutex lock;
203d3d4a 174 struct list_head node;
b1569e99 175 struct delayed_work poll_queue;
0e70f466 176 enum thermal_notify_event notify_event;
203d3d4a 177};
4cb18728 178
c708a98f
JM
179/**
180 * struct thermal_governor - structure that holds thermal governor information
181 * @name: name of the governor
e33df1d2
JM
182 * @bind_to_tz: callback called when binding to a thermal zone. If it
183 * returns 0, the governor is bound to the thermal zone,
184 * otherwise it fails.
185 * @unbind_from_tz: callback called when a governor is unbound from a
186 * thermal zone.
c708a98f
JM
187 * @throttle: callback called for every trip point even if temperature is
188 * below the trip point temperature
189 * @governor_list: node in thermal_governor_list (in thermal_core.c)
190 */
a4a15485
D
191struct thermal_governor {
192 char name[THERMAL_NAME_LENGTH];
e33df1d2
JM
193 int (*bind_to_tz)(struct thermal_zone_device *tz);
194 void (*unbind_from_tz)(struct thermal_zone_device *tz);
a4a15485
D
195 int (*throttle)(struct thermal_zone_device *tz, int trip);
196 struct list_head governor_list;
a4a15485
D
197};
198
ef873947
D
199/* Structure that holds binding parameters for a zone */
200struct thermal_bind_params {
201 struct thermal_cooling_device *cdev;
202
203 /*
204 * This is a measure of 'how effectively these devices can
bcdcbbc7
JM
205 * cool 'this' thermal zone. It shall be determined by
206 * platform characterization. This value is relative to the
207 * rest of the weights so a cooling device whose weight is
208 * double that of another cooling device is twice as
eaf7b460 209 * effective. See Documentation/driver-api/thermal/sysfs-api.rst for more
bcdcbbc7 210 * information.
ef873947
D
211 */
212 int weight;
213
214 /*
215 * This is a bit mask that gives the binding relation between this
216 * thermal zone and cdev, for a particular trip point.
eaf7b460 217 * See Documentation/driver-api/thermal/sysfs-api.rst for more information.
ef873947
D
218 */
219 int trip_mask;
a8892d83
EV
220
221 /*
222 * This is an array of cooling state limits. Must have exactly
223 * 2 * thermal_zone.number_of_trip_points. It is an array consisting
224 * of tuples <lower-state upper-state> of state limits. Each trip
225 * will be associated with one state limit tuple when binding.
226 * A NULL pointer means <THERMAL_NO_LIMITS THERMAL_NO_LIMITS>
227 * on all trips.
228 */
229 unsigned long *binding_limits;
ef873947
D
230 int (*match) (struct thermal_zone_device *tz,
231 struct thermal_cooling_device *cdev);
232};
233
234/* Structure to define Thermal Zone parameters */
235struct thermal_zone_params {
a4a15485 236 char governor_name[THERMAL_NAME_LENGTH];
ccba4ffd
EV
237
238 /*
239 * a boolean to indicate if the thermal to hwmon sysfs interface
240 * is required. when no_hwmon == false, a hwmon sysfs interface
241 * will be created. when no_hwmon == true, nothing will be done
242 */
243 bool no_hwmon;
244
ef873947
D
245 int num_tbps; /* Number of tbp entries */
246 struct thermal_bind_params *tbp;
6b775e87
JM
247
248 /*
249 * Sustainable power (heat) that this thermal zone can dissipate in
250 * mW
251 */
252 u32 sustainable_power;
253
254 /*
255 * Proportional parameter of the PID controller when
256 * overshooting (i.e., when temperature is below the target)
257 */
258 s32 k_po;
259
260 /*
261 * Proportional parameter of the PID controller when
262 * undershooting
263 */
264 s32 k_pu;
265
266 /* Integral parameter of the PID controller */
267 s32 k_i;
268
269 /* Derivative parameter of the PID controller */
270 s32 k_d;
271
272 /* threshold below which the error is no longer accumulated */
273 s32 integral_cutoff;
9d0be7f4
EV
274
275 /*
276 * @slope: slope of a linear temperature adjustment curve.
277 * Used by thermal zone drivers.
278 */
279 int slope;
280 /*
281 * @offset: offset of a linear temperature adjustment curve.
282 * Used by thermal zone drivers (default 0).
283 */
284 int offset;
ef873947
D
285};
286
2251aef6
EV
287/**
288 * struct thermal_zone_of_device_ops - scallbacks for handling DT based zones
289 *
290 * Mandatory:
291 * @get_temp: a pointer to a function that reads the sensor temperature.
292 *
293 * Optional:
294 * @get_trend: a pointer to a function that reads the sensor temperature trend.
826386e7
SH
295 * @set_trips: a pointer to a function that sets a temperature window. When
296 * this window is left the driver must inform the thermal core via
297 * thermal_zone_device_update.
184a4bf6
LM
298 * @set_emul_temp: a pointer to a function that sets sensor emulated
299 * temperature.
5a5e78cd
CW
300 * @set_trip_temp: a pointer to a function that sets the trip temperature on
301 * hardware.
2251aef6
EV
302 */
303struct thermal_zone_of_device_ops {
17e8351a 304 int (*get_temp)(void *, int *);
e78eaf45 305 int (*get_trend)(void *, int, enum thermal_trend *);
826386e7 306 int (*set_trips)(void *, int, int);
17e8351a 307 int (*set_emul_temp)(void *, int);
c3509521 308 int (*set_trip_temp)(void *, int, int);
2251aef6
EV
309};
310
23064088 311/* Function declarations */
4e5e4705 312#ifdef CONFIG_THERMAL_OF
34471abf
AH
313int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
314 struct device_node *sensor_np,
315 u32 *id);
4e5e4705 316struct thermal_zone_device *
2251aef6
EV
317thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
318 const struct thermal_zone_of_device_ops *ops);
4e5e4705
EV
319void thermal_zone_of_sensor_unregister(struct device *dev,
320 struct thermal_zone_device *tz);
e498b498
LD
321struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
322 struct device *dev, int id, void *data,
323 const struct thermal_zone_of_device_ops *ops);
324void devm_thermal_zone_of_sensor_unregister(struct device *dev,
325 struct thermal_zone_device *tz);
4e5e4705 326#else
34471abf 327
15a26319 328static inline int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
34471abf
AH
329 struct device_node *sensor_np,
330 u32 *id)
331{
332 return -ENOENT;
333}
4e5e4705 334static inline struct thermal_zone_device *
2251aef6
EV
335thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
336 const struct thermal_zone_of_device_ops *ops)
4e5e4705 337{
cd33dc9a 338 return ERR_PTR(-ENODEV);
4e5e4705
EV
339}
340
341static inline
342void thermal_zone_of_sensor_unregister(struct device *dev,
343 struct thermal_zone_device *tz)
344{
345}
346
e498b498
LD
347static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
348 struct device *dev, int id, void *data,
349 const struct thermal_zone_of_device_ops *ops)
350{
351 return ERR_PTR(-ENODEV);
352}
353
354static inline
355void devm_thermal_zone_of_sensor_unregister(struct device *dev,
356 struct thermal_zone_device *tz)
357{
358}
359
4e5e4705 360#endif
12ca7188 361
60518260 362#ifdef CONFIG_THERMAL
4b1bf587 363struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
4e5e4705 364 void *, struct thermal_zone_device_ops *,
6b775e87 365 struct thermal_zone_params *, int, int);
203d3d4a
ZR
366void thermal_zone_device_unregister(struct thermal_zone_device *);
367
368int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
9d99842f 369 struct thermal_cooling_device *,
6cd9e9f6
KS
370 unsigned long, unsigned long,
371 unsigned int);
203d3d4a
ZR
372int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
373 struct thermal_cooling_device *);
0e70f466
SP
374void thermal_zone_device_update(struct thermal_zone_device *,
375 enum thermal_notify_event);
23064088 376
f991de53
JFD
377struct thermal_cooling_device *thermal_cooling_device_register(const char *,
378 void *, const struct thermal_cooling_device_ops *);
a116b5d4 379struct thermal_cooling_device *
f991de53 380thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
a116b5d4 381 const struct thermal_cooling_device_ops *);
b4ab114c
GR
382struct thermal_cooling_device *
383devm_thermal_of_cooling_device_register(struct device *dev,
384 struct device_node *np,
385 char *type, void *devdata,
386 const struct thermal_cooling_device_ops *ops);
203d3d4a 387void thermal_cooling_device_unregister(struct thermal_cooling_device *);
63c4d919 388struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
17e8351a 389int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
4a7069a3
RN
390int thermal_zone_get_slope(struct thermal_zone_device *tz);
391int thermal_zone_get_offset(struct thermal_zone_device *tz);
af06216a 392
7b73c993 393void thermal_notify_framework(struct thermal_zone_device *, int);
ac5d9ecc
AP
394int thermal_zone_device_enable(struct thermal_zone_device *tz);
395int thermal_zone_device_disable(struct thermal_zone_device *tz);
d7203eed 396void thermal_zone_device_critical(struct thermal_zone_device *tz);
12ca7188
NM
397#else
398static inline struct thermal_zone_device *thermal_zone_device_register(
399 const char *type, int trips, int mask, void *devdata,
400 struct thermal_zone_device_ops *ops,
023b7b07 401 struct thermal_zone_params *tzp,
12ca7188
NM
402 int passive_delay, int polling_delay)
403{ return ERR_PTR(-ENODEV); }
404static inline void thermal_zone_device_unregister(
405 struct thermal_zone_device *tz)
406{ }
12ca7188
NM
407static inline struct thermal_cooling_device *
408thermal_cooling_device_register(char *type, void *devdata,
409 const struct thermal_cooling_device_ops *ops)
410{ return ERR_PTR(-ENODEV); }
411static inline struct thermal_cooling_device *
412thermal_of_cooling_device_register(struct device_node *np,
413 char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
414{ return ERR_PTR(-ENODEV); }
b4ab114c
GR
415static inline struct thermal_cooling_device *
416devm_thermal_of_cooling_device_register(struct device *dev,
417 struct device_node *np,
418 char *type, void *devdata,
419 const struct thermal_cooling_device_ops *ops)
420{
421 return ERR_PTR(-ENODEV);
422}
12ca7188
NM
423static inline void thermal_cooling_device_unregister(
424 struct thermal_cooling_device *cdev)
425{ }
426static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
427 const char *name)
428{ return ERR_PTR(-ENODEV); }
429static inline int thermal_zone_get_temp(
17e8351a 430 struct thermal_zone_device *tz, int *temp)
12ca7188 431{ return -ENODEV; }
4a7069a3
RN
432static inline int thermal_zone_get_slope(
433 struct thermal_zone_device *tz)
434{ return -ENODEV; }
435static inline int thermal_zone_get_offset(
436 struct thermal_zone_device *tz)
437{ return -ENODEV; }
f0129c23 438
12ca7188
NM
439static inline void thermal_notify_framework(struct thermal_zone_device *tz,
440 int trip)
441{ }
ac5d9ecc
AP
442
443static inline int thermal_zone_device_enable(struct thermal_zone_device *tz)
444{ return -ENODEV; }
445
446static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
447{ return -ENODEV; }
12ca7188
NM
448#endif /* CONFIG_THERMAL */
449
a0dd25b2 450#endif /* __THERMAL_H__ */