blob: c91b1e344d56d6d0ad609ebf270e7ce159f586ae [file] [log] [blame]
Lina Iyer7e3c0382018-05-07 11:52:29 -06001/* SPDX-License-Identifier: GPL-2.0 */
Zhang Rui203d3d42008-01-17 15:51:08 +08002/*
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>
Zhang Rui203d3d42008-01-17 15:51:08 +08008 */
9
10#ifndef __THERMAL_H__
11#define __THERMAL_H__
12
Eduardo Valentina116b5d2013-09-26 15:55:01 -040013#include <linux/of.h>
Zhang Rui203d3d42008-01-17 15:51:08 +080014#include <linux/idr.h>
15#include <linux/device.h>
Eduardo Valentin4d0fe742016-11-07 21:08:52 -080016#include <linux/sysfs.h>
Matthew Garrettb1569e92008-12-03 17:55:32 +000017#include <linux/workqueue.h>
Florian Fainelliaf6c9f12014-11-19 18:11:00 -080018#include <uapi/linux/thermal.h>
Zhang Rui203d3d42008-01-17 15:51:08 +080019
Durgadoss R23064082012-09-18 11:04:52 +053020#define THERMAL_TRIPS_NONE -1
21#define THERMAL_MAX_TRIPS 12
Durgadoss R23064082012-09-18 11:04:52 +053022
Zhang Rui57df8102013-02-08 14:52:06 +080023/* invalid cooling state */
24#define THERMAL_CSTATE_INVALID -1UL
25
Durgadoss R23064082012-09-18 11:04:52 +053026/* No upper/lower limit requirement */
Punit Agrawala940cb32014-12-09 12:22:01 +000027#define THERMAL_NO_LIMIT ((u32)~0)
Durgadoss R23064082012-09-18 11:04:52 +053028
Kapileshwar Singh6cd9e9f2015-02-18 16:04:21 +000029/* Default weight of a bound cooling device */
30#define THERMAL_WEIGHT_DEFAULT 0
31
Zhang Ruibb431ba2015-10-30 16:31:47 +080032/* use value, which < 0K, to indicate an invalid/uninitialized temperature */
33#define THERMAL_TEMP_INVALID -274000
34
Zhang Rui1f53ef12012-12-12 15:31:37 +080035/* Default Thermal Governor */
36#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
37#define DEFAULT_THERMAL_GOVERNOR "step_wise"
38#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
39#define DEFAULT_THERMAL_GOVERNOR "fair_share"
40#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
41#define DEFAULT_THERMAL_GOVERNOR "user_space"
Javi Merino6b775e82015-03-02 17:17:19 +000042#elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
43#define DEFAULT_THERMAL_GOVERNOR "power_allocator"
Zhang Rui1f53ef12012-12-12 15:31:37 +080044#endif
Durgadoss Ra4a15482012-09-18 11:04:57 +053045
Zhang Rui203d3d42008-01-17 15:51:08 +080046struct thermal_zone_device;
47struct thermal_cooling_device;
Javi Merino35b11d22015-02-26 19:00:28 +000048struct thermal_instance;
Zhang Rui203d3d42008-01-17 15:51:08 +080049
Matthew Garrett6503e5d2008-11-27 17:48:13 +000050enum thermal_device_mode {
51 THERMAL_DEVICE_DISABLED = 0,
52 THERMAL_DEVICE_ENABLED,
53};
54
55enum thermal_trip_type {
56 THERMAL_TRIP_ACTIVE = 0,
57 THERMAL_TRIP_PASSIVE,
58 THERMAL_TRIP_HOT,
59 THERMAL_TRIP_CRITICAL,
60};
61
Zhang Rui601f3d42012-06-27 09:54:33 +080062enum thermal_trend {
63 THERMAL_TREND_STABLE, /* temperature is stable */
64 THERMAL_TREND_RAISING, /* temperature is raising */
65 THERMAL_TREND_DROPPING, /* temperature is dropping */
Zhang Ruid069015e2012-11-19 15:33:51 +080066 THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
67 THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
Zhang Rui601f3d42012-06-27 09:54:33 +080068};
69
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -070070/* Thermal notification reason */
71enum thermal_notify_event {
72 THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */
73 THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */
74 THERMAL_TRIP_VIOLATED, /* TRIP Point violation */
75 THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */
76 THERMAL_DEVICE_DOWN, /* Thermal device is down */
77 THERMAL_DEVICE_UP, /* Thermal device is up after a down event */
78 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */
Brian Bian38e44da2017-08-09 11:45:40 -070079 THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -070080};
81
Zhang Rui203d3d42008-01-17 15:51:08 +080082struct thermal_zone_device_ops {
83 int (*bind) (struct thermal_zone_device *,
84 struct thermal_cooling_device *);
85 int (*unbind) (struct thermal_zone_device *,
86 struct thermal_cooling_device *);
Sascha Hauer17e83512015-07-24 08:12:54 +020087 int (*get_temp) (struct thermal_zone_device *, int *);
Sascha Hauer060c0342016-06-22 16:42:01 +080088 int (*set_trips) (struct thermal_zone_device *, int, int);
Matthew Garrett6503e5d2008-11-27 17:48:13 +000089 int (*get_mode) (struct thermal_zone_device *,
90 enum thermal_device_mode *);
91 int (*set_mode) (struct thermal_zone_device *,
92 enum thermal_device_mode);
93 int (*get_trip_type) (struct thermal_zone_device *, int,
94 enum thermal_trip_type *);
Sascha Hauer17e83512015-07-24 08:12:54 +020095 int (*get_trip_temp) (struct thermal_zone_device *, int, int *);
96 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
97 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *);
98 int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
99 int (*get_crit_temp) (struct thermal_zone_device *, int *);
100 int (*set_emul_temp) (struct thermal_zone_device *, int);
Zhang Rui601f3d42012-06-27 09:54:33 +0800101 int (*get_trend) (struct thermal_zone_device *, int,
102 enum thermal_trend *);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000103 int (*notify) (struct thermal_zone_device *, int,
104 enum thermal_trip_type);
Zhang Rui203d3d42008-01-17 15:51:08 +0800105};
106
107struct thermal_cooling_device_ops {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000108 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);
Javi Merino35b11d22015-02-26 19:00:28 +0000111 int (*get_requested_power)(struct thermal_cooling_device *,
112 struct thermal_zone_device *, u32 *);
113 int (*state2power)(struct thermal_cooling_device *,
114 struct thermal_zone_device *, unsigned long, u32 *);
115 int (*power2state)(struct thermal_cooling_device *,
116 struct thermal_zone_device *, u32, unsigned long *);
Zhang Rui203d3d42008-01-17 15:51:08 +0800117};
118
Zhang Rui203d3d42008-01-17 15:51:08 +0800119struct thermal_cooling_device {
120 int id;
121 char type[THERMAL_NAME_LENGTH];
122 struct device device;
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400123 struct device_node *np;
Zhang Rui203d3d42008-01-17 15:51:08 +0800124 void *devdata;
Viresh Kumar8ea22952018-04-02 16:26:25 +0530125 void *stats;
Alan Cox5b275ce2010-11-11 15:27:29 +0000126 const struct thermal_cooling_device_ops *ops;
Zhang Ruice119f82012-06-27 14:13:04 +0800127 bool updated; /* true if the cooling device does not need update */
Zhang Ruif4a821c2012-07-24 16:56:21 +0800128 struct mutex lock; /* protect thermal_instances list */
Zhang Ruib5e4ae62012-06-27 14:11:52 +0800129 struct list_head thermal_instances;
Zhang Rui203d3d42008-01-17 15:51:08 +0800130 struct list_head node;
131};
132
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800133struct thermal_attr {
134 struct device_attribute attr;
135 char name[THERMAL_NAME_LENGTH];
136};
137
Javi Merinoc708a982014-06-25 11:00:12 +0100138/**
139 * struct thermal_zone_device - structure for a thermal zone
140 * @id: unique id number for each thermal zone
141 * @type: the thermal zone device type
142 * @device: &struct device for this thermal zone
143 * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
144 * @trip_type_attrs: attributes for trip points for sysfs: trip type
145 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
146 * @devdata: private pointer for device private data
147 * @trips: number of trip points the thermal zone supports
Zhang Rui81ad4272016-03-18 10:03:24 +0800148 * @trips_disabled; bitmap for disabled trips
Javi Merinoc708a982014-06-25 11:00:12 +0100149 * @passive_delay: number of milliseconds to wait between polls when
Javi Merino6b775e82015-03-02 17:17:19 +0000150 * performing passive cooling.
Javi Merinoc708a982014-06-25 11:00:12 +0100151 * @polling_delay: number of milliseconds to wait between polls when
152 * checking whether trip points have been crossed (0 for
153 * interrupt driven systems)
154 * @temperature: current temperature. This is only for core code,
155 * drivers should use thermal_zone_get_temp() to get the
156 * current temperature
157 * @last_temperature: previous temperature read
158 * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION
159 * @passive: 1 if you've crossed a passive trip point, 0 otherwise.
Sascha Hauer060c0342016-06-22 16:42:01 +0800160 * @prev_low_trip: the low current temperature if you've crossed a passive
161 trip point.
162 * @prev_high_trip: the above current temperature if you've crossed a
163 passive trip point.
Javi Merinoc708a982014-06-25 11:00:12 +0100164 * @forced_passive: If > 0, temperature at which to switch on all ACPI
165 * processor cooling devices. Currently only used by the
166 * step-wise governor.
Chen Yu4511f712015-10-30 16:32:10 +0800167 * @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
Javi Merinoc708a982014-06-25 11:00:12 +0100168 * @ops: operations this &thermal_zone_device supports
169 * @tzp: thermal zone parameters
170 * @governor: pointer to the governor for this thermal zone
Javi Merinoe33df1d2015-02-26 19:00:27 +0000171 * @governor_data: private pointer for governor data
Javi Merinoc708a982014-06-25 11:00:12 +0100172 * @thermal_instances: list of &struct thermal_instance of this thermal zone
Matthew Wilcoxb31ef822016-12-21 09:47:03 -0800173 * @ida: &struct ida to generate unique id for this zone's cooling
Javi Merinoc708a982014-06-25 11:00:12 +0100174 * devices
175 * @lock: lock to protect thermal_instances list
176 * @node: node in thermal_tz_list (in thermal_core.c)
177 * @poll_queue: delayed work for polling
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700178 * @notify_event: Last notification event
Javi Merinoc708a982014-06-25 11:00:12 +0100179 */
Zhang Rui203d3d42008-01-17 15:51:08 +0800180struct thermal_zone_device {
181 int id;
182 char type[THERMAL_NAME_LENGTH];
183 struct device device;
Eduardo Valentin4d0fe742016-11-07 21:08:52 -0800184 struct attribute_group trips_attribute_group;
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800185 struct thermal_attr *trip_temp_attrs;
186 struct thermal_attr *trip_type_attrs;
Durgadoss R27365a62012-07-25 10:10:59 +0800187 struct thermal_attr *trip_hyst_attrs;
Zhang Rui203d3d42008-01-17 15:51:08 +0800188 void *devdata;
189 int trips;
Zhang Rui81ad4272016-03-18 10:03:24 +0800190 unsigned long trips_disabled; /* bitmap for disabled trips */
Matthew Garrettb1569e92008-12-03 17:55:32 +0000191 int passive_delay;
192 int polling_delay;
Zhang Rui601f3d42012-06-27 09:54:33 +0800193 int temperature;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000194 int last_temperature;
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000195 int emul_temperature;
Zhang Rui908b9fb2012-06-27 14:14:05 +0800196 int passive;
Sascha Hauer060c0342016-06-22 16:42:01 +0800197 int prev_low_trip;
198 int prev_high_trip;
Matthew Garrett03a971a2008-12-03 18:00:38 +0000199 unsigned int forced_passive;
Chen Yu4511f712015-10-30 16:32:10 +0800200 atomic_t need_update;
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400201 struct thermal_zone_device_ops *ops;
Javi Merino6b775e82015-03-02 17:17:19 +0000202 struct thermal_zone_params *tzp;
Durgadoss Ra4a15482012-09-18 11:04:57 +0530203 struct thermal_governor *governor;
Javi Merinoe33df1d2015-02-26 19:00:27 +0000204 void *governor_data;
Zhang Rui2d374132012-06-27 10:09:00 +0800205 struct list_head thermal_instances;
Matthew Wilcoxb31ef822016-12-21 09:47:03 -0800206 struct ida ida;
Javi Merinoc708a982014-06-25 11:00:12 +0100207 struct mutex lock;
Zhang Rui203d3d42008-01-17 15:51:08 +0800208 struct list_head node;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000209 struct delayed_work poll_queue;
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700210 enum thermal_notify_event notify_event;
Zhang Rui203d3d42008-01-17 15:51:08 +0800211};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530212
Javi Merinoc708a982014-06-25 11:00:12 +0100213/**
214 * struct thermal_governor - structure that holds thermal governor information
215 * @name: name of the governor
Javi Merinoe33df1d2015-02-26 19:00:27 +0000216 * @bind_to_tz: callback called when binding to a thermal zone. If it
217 * returns 0, the governor is bound to the thermal zone,
218 * otherwise it fails.
219 * @unbind_from_tz: callback called when a governor is unbound from a
220 * thermal zone.
Javi Merinoc708a982014-06-25 11:00:12 +0100221 * @throttle: callback called for every trip point even if temperature is
222 * below the trip point temperature
223 * @governor_list: node in thermal_governor_list (in thermal_core.c)
224 */
Durgadoss Ra4a15482012-09-18 11:04:57 +0530225struct thermal_governor {
226 char name[THERMAL_NAME_LENGTH];
Javi Merinoe33df1d2015-02-26 19:00:27 +0000227 int (*bind_to_tz)(struct thermal_zone_device *tz);
228 void (*unbind_from_tz)(struct thermal_zone_device *tz);
Durgadoss Ra4a15482012-09-18 11:04:57 +0530229 int (*throttle)(struct thermal_zone_device *tz, int trip);
230 struct list_head governor_list;
Durgadoss Ra4a15482012-09-18 11:04:57 +0530231};
232
Durgadoss Ref873942012-09-18 11:04:55 +0530233/* Structure that holds binding parameters for a zone */
234struct thermal_bind_params {
235 struct thermal_cooling_device *cdev;
236
237 /*
238 * This is a measure of 'how effectively these devices can
Javi Merinobcdcbbc2015-02-18 16:04:25 +0000239 * cool 'this' thermal zone. It shall be determined by
240 * platform characterization. This value is relative to the
241 * rest of the weights so a cooling device whose weight is
242 * double that of another cooling device is twice as
Mauro Carvalho Chehabeaf7b462019-07-26 09:51:12 -0300243 * effective. See Documentation/driver-api/thermal/sysfs-api.rst for more
Javi Merinobcdcbbc2015-02-18 16:04:25 +0000244 * information.
Durgadoss Ref873942012-09-18 11:04:55 +0530245 */
246 int weight;
247
248 /*
249 * This is a bit mask that gives the binding relation between this
250 * thermal zone and cdev, for a particular trip point.
Mauro Carvalho Chehabeaf7b462019-07-26 09:51:12 -0300251 * See Documentation/driver-api/thermal/sysfs-api.rst for more information.
Durgadoss Ref873942012-09-18 11:04:55 +0530252 */
253 int trip_mask;
Eduardo Valentina8892d832013-07-16 15:26:28 -0400254
255 /*
256 * This is an array of cooling state limits. Must have exactly
257 * 2 * thermal_zone.number_of_trip_points. It is an array consisting
258 * of tuples <lower-state upper-state> of state limits. Each trip
259 * will be associated with one state limit tuple when binding.
260 * A NULL pointer means <THERMAL_NO_LIMITS THERMAL_NO_LIMITS>
261 * on all trips.
262 */
263 unsigned long *binding_limits;
Durgadoss Ref873942012-09-18 11:04:55 +0530264 int (*match) (struct thermal_zone_device *tz,
265 struct thermal_cooling_device *cdev);
266};
267
268/* Structure to define Thermal Zone parameters */
269struct thermal_zone_params {
Durgadoss Ra4a15482012-09-18 11:04:57 +0530270 char governor_name[THERMAL_NAME_LENGTH];
Eduardo Valentinccba4ff2013-08-15 11:34:17 -0400271
272 /*
273 * a boolean to indicate if the thermal to hwmon sysfs interface
274 * is required. when no_hwmon == false, a hwmon sysfs interface
275 * will be created. when no_hwmon == true, nothing will be done
276 */
277 bool no_hwmon;
278
Durgadoss Ref873942012-09-18 11:04:55 +0530279 int num_tbps; /* Number of tbp entries */
280 struct thermal_bind_params *tbp;
Javi Merino6b775e82015-03-02 17:17:19 +0000281
282 /*
283 * Sustainable power (heat) that this thermal zone can dissipate in
284 * mW
285 */
286 u32 sustainable_power;
287
288 /*
289 * Proportional parameter of the PID controller when
290 * overshooting (i.e., when temperature is below the target)
291 */
292 s32 k_po;
293
294 /*
295 * Proportional parameter of the PID controller when
296 * undershooting
297 */
298 s32 k_pu;
299
300 /* Integral parameter of the PID controller */
301 s32 k_i;
302
303 /* Derivative parameter of the PID controller */
304 s32 k_d;
305
306 /* threshold below which the error is no longer accumulated */
307 s32 integral_cutoff;
Eduardo Valentin9d0be7f2015-05-11 19:34:23 -0700308
309 /*
310 * @slope: slope of a linear temperature adjustment curve.
311 * Used by thermal zone drivers.
312 */
313 int slope;
314 /*
315 * @offset: offset of a linear temperature adjustment curve.
316 * Used by thermal zone drivers (default 0).
317 */
318 int offset;
Durgadoss Ref873942012-09-18 11:04:55 +0530319};
320
R.Durgadoss4cb18722010-10-27 03:33:29 +0530321struct thermal_genl_event {
322 u32 orig;
323 enum events event;
324};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530325
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400326/**
327 * struct thermal_zone_of_device_ops - scallbacks for handling DT based zones
328 *
329 * Mandatory:
330 * @get_temp: a pointer to a function that reads the sensor temperature.
331 *
332 * Optional:
333 * @get_trend: a pointer to a function that reads the sensor temperature trend.
Sascha Hauer826386e2016-06-22 16:42:02 +0800334 * @set_trips: a pointer to a function that sets a temperature window. When
335 * this window is left the driver must inform the thermal core via
336 * thermal_zone_device_update.
Lukasz Majewski184a4bf2014-12-08 18:04:21 +0100337 * @set_emul_temp: a pointer to a function that sets sensor emulated
338 * temperature.
Caesar Wang5a5e78c2016-05-18 23:01:39 +0800339 * @set_trip_temp: a pointer to a function that sets the trip temperature on
340 * hardware.
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400341 */
342struct thermal_zone_of_device_ops {
Sascha Hauer17e83512015-07-24 08:12:54 +0200343 int (*get_temp)(void *, int *);
Sascha Hauere78eaf42016-06-22 16:42:03 +0800344 int (*get_trend)(void *, int, enum thermal_trend *);
Sascha Hauer826386e2016-06-22 16:42:02 +0800345 int (*set_trips)(void *, int, int);
Sascha Hauer17e83512015-07-24 08:12:54 +0200346 int (*set_emul_temp)(void *, int);
Wei Nic3509522016-03-29 18:29:17 +0800347 int (*set_trip_temp)(void *, int, int);
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400348};
349
Lukasz Majewskiad9914a2014-12-08 18:04:19 +0100350/**
351 * struct thermal_trip - representation of a point in temperature domain
352 * @np: pointer to struct device_node that this trip point was created from
353 * @temperature: temperature value in miliCelsius
354 * @hysteresis: relative hysteresis in miliCelsius
355 * @type: trip point type
356 */
357
358struct thermal_trip {
359 struct device_node *np;
Wei Ni1d0fd422016-03-03 17:33:46 +0800360 int temperature;
361 int hysteresis;
Lukasz Majewskiad9914a2014-12-08 18:04:19 +0100362 enum thermal_trip_type type;
363};
364
Durgadoss R23064082012-09-18 11:04:52 +0530365/* Function declarations */
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400366#ifdef CONFIG_THERMAL_OF
Anson Huang34471ab2020-02-22 08:08:49 +0800367int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
368 struct device_node *sensor_np,
369 u32 *id);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400370struct thermal_zone_device *
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400371thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
372 const struct thermal_zone_of_device_ops *ops);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400373void thermal_zone_of_sensor_unregister(struct device *dev,
374 struct thermal_zone_device *tz);
Laxman Dewangane498b492016-03-09 18:40:06 +0530375struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
376 struct device *dev, int id, void *data,
377 const struct thermal_zone_of_device_ops *ops);
378void devm_thermal_zone_of_sensor_unregister(struct device *dev,
379 struct thermal_zone_device *tz);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400380#else
Anson Huang34471ab2020-02-22 08:08:49 +0800381
Anson Huang15a26312020-03-03 16:04:43 +0800382static inline int thermal_zone_of_get_sensor_id(struct device_node *tz_np,
Anson Huang34471ab2020-02-22 08:08:49 +0800383 struct device_node *sensor_np,
384 u32 *id)
385{
386 return -ENOENT;
387}
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400388static inline struct thermal_zone_device *
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400389thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
390 const struct thermal_zone_of_device_ops *ops)
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400391{
Punit Agrawalcd33dc92015-09-08 14:51:12 +0100392 return ERR_PTR(-ENODEV);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400393}
394
395static inline
396void thermal_zone_of_sensor_unregister(struct device *dev,
397 struct thermal_zone_device *tz)
398{
399}
400
Laxman Dewangane498b492016-03-09 18:40:06 +0530401static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
402 struct device *dev, int id, void *data,
403 const struct thermal_zone_of_device_ops *ops)
404{
405 return ERR_PTR(-ENODEV);
406}
407
408static inline
409void devm_thermal_zone_of_sensor_unregister(struct device *dev,
410 struct thermal_zone_device *tz)
411{
412}
413
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400414#endif
Nishanth Menon12ca7182015-02-13 19:28:02 -0600415
416#if IS_ENABLED(CONFIG_THERMAL)
Javi Merino35b11d22015-02-26 19:00:28 +0000417static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
418{
419 return cdev->ops->get_requested_power && cdev->ops->state2power &&
420 cdev->ops->power2state;
421}
422
423int power_actor_get_max_power(struct thermal_cooling_device *,
424 struct thermal_zone_device *tz, u32 *max_power);
Javi Merinoc973c3b2015-09-14 14:23:50 +0100425int power_actor_get_min_power(struct thermal_cooling_device *,
426 struct thermal_zone_device *tz, u32 *min_power);
Javi Merino35b11d22015-02-26 19:00:28 +0000427int power_actor_set_power(struct thermal_cooling_device *,
428 struct thermal_instance *, u32);
Anton Vorontsov4b1bf582012-07-31 04:39:30 -0700429struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400430 void *, struct thermal_zone_device_ops *,
Javi Merino6b775e82015-03-02 17:17:19 +0000431 struct thermal_zone_params *, int, int);
Zhang Rui203d3d42008-01-17 15:51:08 +0800432void thermal_zone_device_unregister(struct thermal_zone_device *);
433
434int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
Zhang Rui9d998422012-06-26 16:35:57 +0800435 struct thermal_cooling_device *,
Kapileshwar Singh6cd9e9f2015-02-18 16:04:21 +0000436 unsigned long, unsigned long,
437 unsigned int);
Zhang Rui203d3d42008-01-17 15:51:08 +0800438int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
439 struct thermal_cooling_device *);
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700440void thermal_zone_device_update(struct thermal_zone_device *,
441 enum thermal_notify_event);
Sascha Hauer060c0342016-06-22 16:42:01 +0800442void thermal_zone_set_trips(struct thermal_zone_device *);
Durgadoss R23064082012-09-18 11:04:52 +0530443
Jean-Francois Dagenaisf991de52019-04-18 12:36:39 -0400444struct thermal_cooling_device *thermal_cooling_device_register(const char *,
445 void *, const struct thermal_cooling_device_ops *);
Eduardo Valentina116b5d2013-09-26 15:55:01 -0400446struct thermal_cooling_device *
Jean-Francois Dagenaisf991de52019-04-18 12:36:39 -0400447thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
Eduardo Valentina116b5d2013-09-26 15:55:01 -0400448 const struct thermal_cooling_device_ops *);
Guenter Roeckb4ab114cc2019-04-18 12:58:15 -0700449struct thermal_cooling_device *
450devm_thermal_of_cooling_device_register(struct device *dev,
451 struct device_node *np,
452 char *type, void *devdata,
453 const struct thermal_cooling_device_ops *ops);
Zhang Rui203d3d42008-01-17 15:51:08 +0800454void thermal_cooling_device_unregister(struct thermal_cooling_device *);
Eduardo Valentin63c4d912013-04-05 12:32:28 +0000455struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
Sascha Hauer17e83512015-07-24 08:12:54 +0200456int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
Rajendra Nayak4a7069a2016-05-05 14:21:42 +0530457int thermal_zone_get_slope(struct thermal_zone_device *tz);
458int thermal_zone_get_offset(struct thermal_zone_device *tz);
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100459
Durgadoss R9b4298a2012-09-18 11:04:54 +0530460int get_tz_trend(struct thermal_zone_device *, int);
461struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
462 struct thermal_cooling_device *, int);
Durgadoss Rdc765482012-09-18 11:05:00 +0530463void thermal_cdev_update(struct thermal_cooling_device *);
Eduardo Valentin7b73c992013-04-23 21:48:14 +0000464void thermal_notify_framework(struct thermal_zone_device *, int);
Nishanth Menon12ca7182015-02-13 19:28:02 -0600465#else
Javi Merino35b11d22015-02-26 19:00:28 +0000466static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
467{ return false; }
468static inline int power_actor_get_max_power(struct thermal_cooling_device *cdev,
469 struct thermal_zone_device *tz, u32 *max_power)
470{ return 0; }
Javi Merinoc973c3b2015-09-14 14:23:50 +0100471static inline int power_actor_get_min_power(struct thermal_cooling_device *cdev,
472 struct thermal_zone_device *tz,
473 u32 *min_power)
474{ return -ENODEV; }
Javi Merino35b11d22015-02-26 19:00:28 +0000475static inline int power_actor_set_power(struct thermal_cooling_device *cdev,
476 struct thermal_instance *tz, u32 power)
477{ return 0; }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600478static inline struct thermal_zone_device *thermal_zone_device_register(
479 const char *type, int trips, int mask, void *devdata,
480 struct thermal_zone_device_ops *ops,
Arvind Yadav023b7b02017-08-31 11:30:45 +0530481 struct thermal_zone_params *tzp,
Nishanth Menon12ca7182015-02-13 19:28:02 -0600482 int passive_delay, int polling_delay)
483{ return ERR_PTR(-ENODEV); }
484static inline void thermal_zone_device_unregister(
485 struct thermal_zone_device *tz)
486{ }
487static inline int thermal_zone_bind_cooling_device(
488 struct thermal_zone_device *tz, int trip,
489 struct thermal_cooling_device *cdev,
Arnd Bergmannc86b3de2015-11-17 17:48:52 +0100490 unsigned long upper, unsigned long lower,
491 unsigned int weight)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600492{ return -ENODEV; }
493static inline int thermal_zone_unbind_cooling_device(
494 struct thermal_zone_device *tz, int trip,
495 struct thermal_cooling_device *cdev)
496{ return -ENODEV; }
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700497static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
498 enum thermal_notify_event event)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600499{ }
Sascha Hauer060c0342016-06-22 16:42:01 +0800500static inline void thermal_zone_set_trips(struct thermal_zone_device *tz)
501{ }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600502static inline struct thermal_cooling_device *
503thermal_cooling_device_register(char *type, void *devdata,
504 const struct thermal_cooling_device_ops *ops)
505{ return ERR_PTR(-ENODEV); }
506static inline struct thermal_cooling_device *
507thermal_of_cooling_device_register(struct device_node *np,
508 char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
509{ return ERR_PTR(-ENODEV); }
Guenter Roeckb4ab114cc2019-04-18 12:58:15 -0700510static inline struct thermal_cooling_device *
511devm_thermal_of_cooling_device_register(struct device *dev,
512 struct device_node *np,
513 char *type, void *devdata,
514 const struct thermal_cooling_device_ops *ops)
515{
516 return ERR_PTR(-ENODEV);
517}
Nishanth Menon12ca7182015-02-13 19:28:02 -0600518static inline void thermal_cooling_device_unregister(
519 struct thermal_cooling_device *cdev)
520{ }
521static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
522 const char *name)
523{ return ERR_PTR(-ENODEV); }
524static inline int thermal_zone_get_temp(
Sascha Hauer17e83512015-07-24 08:12:54 +0200525 struct thermal_zone_device *tz, int *temp)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600526{ return -ENODEV; }
Rajendra Nayak4a7069a2016-05-05 14:21:42 +0530527static inline int thermal_zone_get_slope(
528 struct thermal_zone_device *tz)
529{ return -ENODEV; }
530static inline int thermal_zone_get_offset(
531 struct thermal_zone_device *tz)
532{ return -ENODEV; }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600533static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
534{ return -ENODEV; }
535static inline struct thermal_instance *
536get_thermal_instance(struct thermal_zone_device *tz,
537 struct thermal_cooling_device *cdev, int trip)
538{ return ERR_PTR(-ENODEV); }
539static inline void thermal_cdev_update(struct thermal_cooling_device *cdev)
540{ }
541static inline void thermal_notify_framework(struct thermal_zone_device *tz,
542 int trip)
543{ }
544#endif /* CONFIG_THERMAL */
Durgadoss Ra4a15482012-09-18 11:04:57 +0530545
Len Browna0dd25b2008-02-09 04:01:48 -0500546#endif /* __THERMAL_H__ */