1 /* SPDX-License-Identifier: GPL-2.0 */
3 * thermal.h ($Revision: 0 $)
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>
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>
20 /* invalid cooling state */
21 #define THERMAL_CSTATE_INVALID -1UL
23 /* No upper/lower limit requirement */
24 #define THERMAL_NO_LIMIT ((u32)~0)
26 /* Default weight of a bound cooling device */
27 #define THERMAL_WEIGHT_DEFAULT 0
29 /* use value, which < 0K, to indicate an invalid/uninitialized temperature */
30 #define THERMAL_TEMP_INVALID -274000
32 struct thermal_zone_device;
33 struct thermal_cooling_device;
34 struct thermal_instance;
35 struct thermal_debugfs;
39 THERMAL_TREND_STABLE, /* temperature is stable */
40 THERMAL_TREND_RAISING, /* temperature is raising */
41 THERMAL_TREND_DROPPING, /* temperature is dropping */
44 /* Thermal notification reason */
45 enum 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 */
61 * struct thermal_trip - representation of a point in temperature domain
62 * @temperature: temperature value in miliCelsius
63 * @hysteresis: relative hysteresis in miliCelsius
64 * @type: trip point type
65 * @priv: pointer to driver data associated with this trip
66 * @flags: flags representing binary properties of the trip
71 enum thermal_trip_type type;
76 #define THERMAL_TRIP_FLAG_RW_TEMP BIT(0)
77 #define THERMAL_TRIP_FLAG_RW_HYST BIT(1)
79 #define THERMAL_TRIP_FLAG_RW (THERMAL_TRIP_FLAG_RW_TEMP | \
80 THERMAL_TRIP_FLAG_RW_HYST)
82 struct thermal_zone_device;
84 struct thermal_zone_device_ops {
85 int (*bind) (struct thermal_zone_device *,
86 struct thermal_cooling_device *);
87 int (*unbind) (struct thermal_zone_device *,
88 struct thermal_cooling_device *);
89 int (*get_temp) (struct thermal_zone_device *, int *);
90 int (*set_trips) (struct thermal_zone_device *, int, int);
91 int (*change_mode) (struct thermal_zone_device *,
92 enum thermal_device_mode);
93 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
94 int (*get_crit_temp) (struct thermal_zone_device *, int *);
95 int (*set_emul_temp) (struct thermal_zone_device *, int);
96 int (*get_trend) (struct thermal_zone_device *,
97 const struct thermal_trip *, enum thermal_trend *);
98 void (*hot)(struct thermal_zone_device *);
99 void (*critical)(struct thermal_zone_device *);
102 struct thermal_cooling_device_ops {
103 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
104 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
105 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
106 int (*get_requested_power)(struct thermal_cooling_device *, u32 *);
107 int (*state2power)(struct thermal_cooling_device *, unsigned long, u32 *);
108 int (*power2state)(struct thermal_cooling_device *, u32, unsigned long *);
111 struct thermal_cooling_device {
114 unsigned long max_state;
115 struct device device;
116 struct device_node *np;
119 const struct thermal_cooling_device_ops *ops;
120 bool updated; /* true if the cooling device does not need update */
121 struct mutex lock; /* protect thermal_instances list */
122 struct list_head thermal_instances;
123 struct list_head node;
124 #ifdef CONFIG_THERMAL_DEBUGFS
125 struct thermal_debugfs *debugfs;
129 /* Structure to define Thermal Zone parameters */
130 struct thermal_zone_params {
131 const char *governor_name;
134 * a boolean to indicate if the thermal to hwmon sysfs interface
135 * is required. when no_hwmon == false, a hwmon sysfs interface
136 * will be created. when no_hwmon == true, nothing will be done
141 * Sustainable power (heat) that this thermal zone can dissipate in
144 u32 sustainable_power;
147 * Proportional parameter of the PID controller when
148 * overshooting (i.e., when temperature is below the target)
153 * Proportional parameter of the PID controller when
158 /* Integral parameter of the PID controller */
161 /* Derivative parameter of the PID controller */
164 /* threshold below which the error is no longer accumulated */
168 * @slope: slope of a linear temperature adjustment curve.
169 * Used by thermal zone drivers.
173 * @offset: offset of a linear temperature adjustment curve.
174 * Used by thermal zone drivers (default 0).
179 /* Function declarations */
180 #ifdef CONFIG_THERMAL_OF
181 struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data,
182 const struct thermal_zone_device_ops *ops);
184 void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_device *tz);
189 struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data,
190 const struct thermal_zone_device_ops *ops)
192 return ERR_PTR(-ENOTSUPP);
195 static inline void devm_thermal_of_zone_unregister(struct device *dev,
196 struct thermal_zone_device *tz)
201 int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
202 struct thermal_trip *trip);
203 int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
204 struct thermal_trip *trip);
205 int for_each_thermal_trip(struct thermal_zone_device *tz,
206 int (*cb)(struct thermal_trip *, void *),
208 int thermal_zone_for_each_trip(struct thermal_zone_device *tz,
209 int (*cb)(struct thermal_trip *, void *),
211 int thermal_zone_get_num_trips(struct thermal_zone_device *tz);
212 void thermal_zone_set_trip_temp(struct thermal_zone_device *tz,
213 struct thermal_trip *trip, int temp);
215 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp);
217 #ifdef CONFIG_THERMAL
218 struct thermal_zone_device *thermal_zone_device_register_with_trips(
220 const struct thermal_trip *trips,
221 int num_trips, void *devdata,
222 const struct thermal_zone_device_ops *ops,
223 const struct thermal_zone_params *tzp,
224 int passive_delay, int polling_delay);
226 struct thermal_zone_device *thermal_tripless_zone_device_register(
229 const struct thermal_zone_device_ops *ops,
230 const struct thermal_zone_params *tzp);
232 void thermal_zone_device_unregister(struct thermal_zone_device *tz);
234 void *thermal_zone_device_priv(struct thermal_zone_device *tzd);
235 const char *thermal_zone_device_type(struct thermal_zone_device *tzd);
236 int thermal_zone_device_id(struct thermal_zone_device *tzd);
237 struct device *thermal_zone_device(struct thermal_zone_device *tzd);
239 int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
240 const struct thermal_trip *trip,
241 struct thermal_cooling_device *cdev,
242 unsigned long upper, unsigned long lower,
243 unsigned int weight);
244 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
245 struct thermal_cooling_device *,
246 unsigned long, unsigned long,
248 int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
249 const struct thermal_trip *trip,
250 struct thermal_cooling_device *cdev);
251 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
252 struct thermal_cooling_device *);
253 void thermal_zone_device_update(struct thermal_zone_device *,
254 enum thermal_notify_event);
256 struct thermal_cooling_device *thermal_cooling_device_register(const char *,
257 void *, const struct thermal_cooling_device_ops *);
258 struct thermal_cooling_device *
259 thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
260 const struct thermal_cooling_device_ops *);
261 struct thermal_cooling_device *
262 devm_thermal_of_cooling_device_register(struct device *dev,
263 struct device_node *np,
264 char *type, void *devdata,
265 const struct thermal_cooling_device_ops *ops);
266 void thermal_cooling_device_update(struct thermal_cooling_device *);
267 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
268 struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
269 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
270 int thermal_zone_get_slope(struct thermal_zone_device *tz);
271 int thermal_zone_get_offset(struct thermal_zone_device *tz);
273 int thermal_zone_device_enable(struct thermal_zone_device *tz);
274 int thermal_zone_device_disable(struct thermal_zone_device *tz);
275 void thermal_zone_device_critical(struct thermal_zone_device *tz);
277 static inline struct thermal_zone_device *thermal_zone_device_register_with_trips(
279 const struct thermal_trip *trips,
280 int num_trips, void *devdata,
281 const struct thermal_zone_device_ops *ops,
282 const struct thermal_zone_params *tzp,
283 int passive_delay, int polling_delay)
284 { return ERR_PTR(-ENODEV); }
286 static inline struct thermal_zone_device *thermal_tripless_zone_device_register(
289 struct thermal_zone_device_ops *ops,
290 const struct thermal_zone_params *tzp)
291 { return ERR_PTR(-ENODEV); }
293 static inline void thermal_zone_device_unregister(struct thermal_zone_device *tz)
296 static inline struct thermal_cooling_device *
297 thermal_cooling_device_register(const char *type, void *devdata,
298 const struct thermal_cooling_device_ops *ops)
299 { return ERR_PTR(-ENODEV); }
300 static inline struct thermal_cooling_device *
301 thermal_of_cooling_device_register(struct device_node *np,
302 const char *type, void *devdata,
303 const struct thermal_cooling_device_ops *ops)
304 { return ERR_PTR(-ENODEV); }
305 static inline struct thermal_cooling_device *
306 devm_thermal_of_cooling_device_register(struct device *dev,
307 struct device_node *np,
308 char *type, void *devdata,
309 const struct thermal_cooling_device_ops *ops)
311 return ERR_PTR(-ENODEV);
313 static inline void thermal_cooling_device_unregister(
314 struct thermal_cooling_device *cdev)
316 static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
318 { return ERR_PTR(-ENODEV); }
319 static inline int thermal_zone_get_temp(
320 struct thermal_zone_device *tz, int *temp)
322 static inline int thermal_zone_get_slope(
323 struct thermal_zone_device *tz)
325 static inline int thermal_zone_get_offset(
326 struct thermal_zone_device *tz)
329 static inline void *thermal_zone_device_priv(struct thermal_zone_device *tz)
334 static inline const char *thermal_zone_device_type(struct thermal_zone_device *tzd)
339 static inline int thermal_zone_device_id(struct thermal_zone_device *tzd)
344 static inline int thermal_zone_device_enable(struct thermal_zone_device *tz)
347 static inline int thermal_zone_device_disable(struct thermal_zone_device *tz)
349 #endif /* CONFIG_THERMAL */
351 #endif /* __THERMAL_H__ */