Merge tag 'arm-fixes-6.11-3' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-block.git] / include / linux / thermal.h
... / ...
CommitLineData
1/* SPDX-License-Identifier: GPL-2.0 */
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>
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/* invalid cooling state */
21#define THERMAL_CSTATE_INVALID -1UL
22
23/* No upper/lower limit requirement */
24#define THERMAL_NO_LIMIT ((u32)~0)
25
26/* Default weight of a bound cooling device */
27#define THERMAL_WEIGHT_DEFAULT 0
28
29/* use value, which < 0K, to indicate an invalid/uninitialized temperature */
30#define THERMAL_TEMP_INVALID -274000
31
32struct thermal_zone_device;
33struct thermal_cooling_device;
34struct thermal_instance;
35struct thermal_debugfs;
36struct thermal_attr;
37
38enum thermal_trend {
39 THERMAL_TREND_STABLE, /* temperature is stable */
40 THERMAL_TREND_RAISING, /* temperature is raising */
41 THERMAL_TREND_DROPPING, /* temperature is dropping */
42};
43
44/* Thermal notification reason */
45enum thermal_notify_event {
46 THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */
47 THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */
48 THERMAL_TRIP_VIOLATED, /* TRIP Point violation */
49 THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */
50 THERMAL_DEVICE_DOWN, /* Thermal device is down */
51 THERMAL_DEVICE_UP, /* Thermal device is up after a down event */
52 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */
53 THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
54 THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */
55 THERMAL_TZ_BIND_CDEV, /* Cooling dev is bind to the thermal zone */
56 THERMAL_TZ_UNBIND_CDEV, /* Cooling dev is unbind from the thermal zone */
57 THERMAL_INSTANCE_WEIGHT_CHANGED, /* Thermal instance weight changed */
58 THERMAL_TZ_RESUME, /* Thermal zone is resuming after system sleep */
59};
60
61/**
62 * struct thermal_trip - representation of a point in temperature domain
63 * @temperature: temperature value in miliCelsius
64 * @hysteresis: relative hysteresis in miliCelsius
65 * @type: trip point type
66 * @priv: pointer to driver data associated with this trip
67 * @flags: flags representing binary properties of the trip
68 */
69struct thermal_trip {
70 int temperature;
71 int hysteresis;
72 enum thermal_trip_type type;
73 u8 flags;
74 void *priv;
75};
76
77#define THERMAL_TRIP_FLAG_RW_TEMP BIT(0)
78#define THERMAL_TRIP_FLAG_RW_HYST BIT(1)
79
80#define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \
81 THERMAL_TRIP_FLAG_RW_HYST)
82
83#define THERMAL_TRIP_PRIV_TO_INT(_val_) (uintptr_t)(_val_)
84#define THERMAL_INT_TO_TRIP_PRIV(_val_) (void *)(uintptr_t)(_val_)
85
86struct thermal_zone_device;
87
88struct thermal_zone_device_ops {
89 int (*bind) (struct thermal_zone_device *,
90 struct thermal_cooling_device *);
91 int (*unbind) (struct thermal_zone_device *,
92 struct thermal_cooling_device *);
93 int (*get_temp) (struct thermal_zone_device *, int *);
94 int (*set_trips) (struct thermal_zone_device *, int, int);
95 int (*change_mode) (struct thermal_zone_device *,
96 enum thermal_device_mode);
97 int (*set_trip_temp) (struct thermal_zone_device *,
98 const struct thermal_trip *, int);
99 int (*get_crit_temp) (struct thermal_zone_device *, int *);
100 int (*set_emul_temp) (struct thermal_zone_device *, int);
101 int (*get_trend) (struct thermal_zone_device *,
102 const struct thermal_trip *, enum thermal_trend *);
103 void (*hot)(struct thermal_zone_device *);
104 void (*critical)(struct thermal_zone_device *);
105};
106
107struct thermal_cooling_device_ops {
108 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
109 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
110 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
111 int (*get_requested_power)(struct thermal_cooling_device *, u32 *);
112 int (*state2power)(struct thermal_cooling_device *, unsigned long, u32 *);
113 int (*power2state)(struct thermal_cooling_device *, u32, unsigned long *);
114};
115
116struct thermal_cooling_device {
117 int id;
118 const char *type;
119 unsigned long max_state;
120 struct device device;
121 struct device_node *np;
122 void *devdata;
123 void *stats;
124 const struct thermal_cooling_device_ops *ops;
125 bool updated; /* true if the cooling device does not need update */
126 struct mutex lock; /* protect thermal_instances list */
127 struct list_head thermal_instances;
128 struct list_head node;
129#ifdef CONFIG_THERMAL_DEBUGFS
130 struct thermal_debugfs *debugfs;
131#endif
132};
133
134/* Structure to define Thermal Zone parameters */
135struct thermal_zone_params {
136 const char *governor_name;
137
138 /*
139 * a boolean to indicate if the thermal to hwmon sysfs interface
140 * is required. when no_hwmon == false, a hwmon sysfs interface
141 * will be created. when no_hwmon == true, nothing will be done
142 */
143 bool no_hwmon;
144
145 /*
146 * Sustainable power (heat) that this thermal zone can dissipate in
147 * mW
148 */
149 u32 sustainable_power;
150
151 /*
152 * Proportional parameter of the PID controller when
153 * overshooting (i.e., when temperature is below the target)
154 */
155 s32 k_po;
156
157 /*
158 * Proportional parameter of the PID controller when
159 * undershooting
160 */
161 s32 k_pu;
162
163 /* Integral parameter of the PID controller */
164 s32 k_i;
165
166 /* Derivative parameter of the PID controller */
167 s32 k_d;
168
169 /* threshold below which the error is no longer accumulated */
170 s32 integral_cutoff;
171
172 /*
173 * @slope: slope of a linear temperature adjustment curve.
174 * Used by thermal zone drivers.
175 */
176 int slope;
177 /*
178 * @offset: offset of a linear temperature adjustment curve.
179 * Used by thermal zone drivers (default 0).
180 */
181 int offset;
182};
183
184/* Function declarations */
185#ifdef CONFIG_THERMAL_OF
186struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data,
187 const struct thermal_zone_device_ops *ops);
188
189void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_device *tz);
190
191#else
192
193static inline
194struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data,
195 const struct thermal_zone_device_ops *ops)
196{
197 return ERR_PTR(-ENOTSUPP);
198}
199
200static inline void devm_thermal_of_zone_unregister(struct device *dev,
201 struct thermal_zone_device *tz)
202{
203}
204#endif
205
206int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
207 struct thermal_trip *trip);
208int for_each_thermal_trip(struct thermal_zone_device *tz,
209 int (*cb)(struct thermal_trip *, void *),
210 void *data);
211int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
212 int (*cb)(struct thermal_trip *, void *),
213 void *data);
214int thermal_zone_get_num_trips(struct thermal_zone_device *tz);
215void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
216 struct thermal_trip *trip, int temp);
217
218int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp);
219
220#ifdef CONFIG_THERMAL
221struct thermal_zone_device *thermal_zone_device_register_with_trips(
222 const char *type,
223 const struct thermal_trip *trips,
224 int num_trips, void *devdata,
225 const struct thermal_zone_device_ops *ops,
226 const struct thermal_zone_params *tzp,
227 unsigned int passive_delay,
228 unsigned int polling_delay);
229
230struct thermal_zone_device *thermal_tripless_zone_device_register(
231 const char *type,
232 void *devdata,
233 const struct thermal_zone_device_ops *ops,
234 const struct thermal_zone_params *tzp);
235
236void thermal_zone_device_unregister(struct thermal_zone_device *tz);
237
238void *thermal_zone_device_priv(struct thermal_zone_device *tzd);
239const char *thermal_zone_device_type(struct thermal_zone_device *tzd);
240int thermal_zone_device_id(struct thermal_zone_device *tzd);
241struct device *thermal_zone_device(struct thermal_zone_device *tzd);
242
243int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
244 const struct thermal_trip *trip,
245 struct thermal_cooling_device *cdev,
246 unsigned long upper, unsigned long lower,
247 unsigned int weight);
248int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
249 struct thermal_cooling_device *,
250 unsigned long, unsigned long,
251 unsigned int);
252int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
253 const struct thermal_trip *trip,
254 struct thermal_cooling_device *cdev);
255int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
256 struct thermal_cooling_device *);
257void thermal_zone_device_update(struct thermal_zone_device *,
258 enum thermal_notify_event);
259
260struct thermal_cooling_device *thermal_cooling_device_register(const char *,
261 void *, const struct thermal_cooling_device_ops *);
262struct thermal_cooling_device *
263thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
264 const struct thermal_cooling_device_ops *);
265struct thermal_cooling_device *
266devm_thermal_of_cooling_device_register(struct device *dev,
267 struct device_node *np,
268 const char *type, void *devdata,
269 const struct thermal_cooling_device_ops *ops);
270void thermal_cooling_device_update(struct thermal_cooling_device *);
271void thermal_cooling_device_unregister(struct thermal_cooling_device *);
272struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
273int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
274int thermal_zone_get_slope(struct thermal_zone_device *tz);
275int thermal_zone_get_offset(struct thermal_zone_device *tz);
276bool thermal_trip_is_bound_to_cdev(struct thermal_zone_device *tz,
277 const struct thermal_trip *trip,
278 struct thermal_cooling_device *cdev);
279
280int thermal_zone_device_enable(struct thermal_zone_device *tz);
281int thermal_zone_device_disable(struct thermal_zone_device *tz);
282void thermal_zone_device_critical(struct thermal_zone_device *tz);
283#else
284static inline struct thermal_zone_device *thermal_zone_device_register_with_trips(
285 const char *type,
286 const struct thermal_trip *trips,
287 int num_trips, void *devdata,
288 const struct thermal_zone_device_ops *ops,
289 const struct thermal_zone_params *tzp,
290 int passive_delay, int polling_delay)
291{ return ERR_PTR(-ENODEV); }
292
293static inline struct thermal_zone_device *thermal_tripless_zone_device_register(
294 const char *type,
295 void *devdata,
296 struct thermal_zone_device_ops *ops,
297 const struct thermal_zone_params *tzp)
298{ return ERR_PTR(-ENODEV); }
299
300static inline void thermal_zone_device_unregister(struct thermal_zone_device *tz)
301{ }
302
303static inline struct thermal_cooling_device *
304thermal_cooling_device_register(const char *type, void *devdata,
305 const struct thermal_cooling_device_ops *ops)
306{ return ERR_PTR(-ENODEV); }
307static inline struct thermal_cooling_device *
308thermal_of_cooling_device_register(struct device_node *np,
309 const char *type, void *devdata,
310 const struct thermal_cooling_device_ops *ops)
311{ return ERR_PTR(-ENODEV); }
312static inline struct thermal_cooling_device *
313devm_thermal_of_cooling_device_register(struct device *dev,
314 struct device_node *np,
315 const char *type, void *devdata,
316 const struct thermal_cooling_device_ops *ops)
317{
318 return ERR_PTR(-ENODEV);
319}
320static inline void thermal_cooling_device_unregister(
321 struct thermal_cooling_device *cdev)
322{ }
323static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
324 const char *name)
325{ return ERR_PTR(-ENODEV); }
326static inline int thermal_zone_get_temp(
327 struct thermal_zone_device *tz, int *temp)
328{ return -ENODEV; }
329static inline int thermal_zone_get_slope(
330 struct thermal_zone_device *tz)
331{ return -ENODEV; }
332static inline int thermal_zone_get_offset(
333 struct thermal_zone_device *tz)
334{ return -ENODEV; }
335
336static inline void *thermal_zone_device_priv(struct thermal_zone_device *tz)
337{
338 return NULL;
339}
340
341static inline const char *thermal_zone_device_type(struct thermal_zone_device *tzd)
342{
343 return NULL;
344}
345
346static inline int thermal_zone_device_id(struct thermal_zone_device *tzd)
347{
348 return -ENODEV;
349}
350
351static inline int thermal_zone_device_enable(struct thermal_zone_device *tz)
352{ return -ENODEV; }
353
354static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
355{ return -ENODEV; }
356#endif /* CONFIG_THERMAL */
357
358#endif /* __THERMAL_H__ */