blob: 15a4ca5d709995b55c81d08615ce7f8f68c223e7 [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
Durgadoss R23064082012-09-18 11:04:52 +053035/* Unit conversion macros */
Rasmus Villemoese866a2e2015-10-01 23:45:31 +020036#define DECI_KELVIN_TO_CELSIUS(t) ({ \
37 long _t = (t); \
38 ((_t-2732 >= 0) ? (_t-2732+5)/10 : (_t-2732-5)/10); \
39})
40#define CELSIUS_TO_DECI_KELVIN(t) ((t)*10+2732)
Aaron Lu7b83fd92014-03-25 10:40:09 +080041#define DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, off) (((t) - (off)) * 100)
42#define DECI_KELVIN_TO_MILLICELSIUS(t) DECI_KELVIN_TO_MILLICELSIUS_WITH_OFFSET(t, 2732)
Aaron Lu77e337c2014-09-03 15:13:02 +080043#define MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, off) (((t) / 100) + (off))
44#define MILLICELSIUS_TO_DECI_KELVIN(t) MILLICELSIUS_TO_DECI_KELVIN_WITH_OFFSET(t, 2732)
Durgadoss R23064082012-09-18 11:04:52 +053045
Zhang Rui1f53ef12012-12-12 15:31:37 +080046/* Default Thermal Governor */
47#if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
48#define DEFAULT_THERMAL_GOVERNOR "step_wise"
49#elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
50#define DEFAULT_THERMAL_GOVERNOR "fair_share"
51#elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
52#define DEFAULT_THERMAL_GOVERNOR "user_space"
Javi Merino6b775e82015-03-02 17:17:19 +000053#elif defined(CONFIG_THERMAL_DEFAULT_GOV_POWER_ALLOCATOR)
54#define DEFAULT_THERMAL_GOVERNOR "power_allocator"
Zhang Rui1f53ef12012-12-12 15:31:37 +080055#endif
Durgadoss Ra4a15482012-09-18 11:04:57 +053056
Zhang Rui203d3d42008-01-17 15:51:08 +080057struct thermal_zone_device;
58struct thermal_cooling_device;
Javi Merino35b11d22015-02-26 19:00:28 +000059struct thermal_instance;
Zhang Rui203d3d42008-01-17 15:51:08 +080060
Matthew Garrett6503e5d2008-11-27 17:48:13 +000061enum thermal_device_mode {
62 THERMAL_DEVICE_DISABLED = 0,
63 THERMAL_DEVICE_ENABLED,
64};
65
66enum thermal_trip_type {
67 THERMAL_TRIP_ACTIVE = 0,
68 THERMAL_TRIP_PASSIVE,
69 THERMAL_TRIP_HOT,
70 THERMAL_TRIP_CRITICAL,
71};
72
Zhang Rui601f3d42012-06-27 09:54:33 +080073enum thermal_trend {
74 THERMAL_TREND_STABLE, /* temperature is stable */
75 THERMAL_TREND_RAISING, /* temperature is raising */
76 THERMAL_TREND_DROPPING, /* temperature is dropping */
Zhang Ruid069015e2012-11-19 15:33:51 +080077 THERMAL_TREND_RAISE_FULL, /* apply highest cooling action */
78 THERMAL_TREND_DROP_FULL, /* apply lowest cooling action */
Zhang Rui601f3d42012-06-27 09:54:33 +080079};
80
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -070081/* Thermal notification reason */
82enum thermal_notify_event {
83 THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */
84 THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */
85 THERMAL_TRIP_VIOLATED, /* TRIP Point violation */
86 THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */
87 THERMAL_DEVICE_DOWN, /* Thermal device is down */
88 THERMAL_DEVICE_UP, /* Thermal device is up after a down event */
89 THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */
Brian Bian38e44da2017-08-09 11:45:40 -070090 THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -070091};
92
Zhang Rui203d3d42008-01-17 15:51:08 +080093struct thermal_zone_device_ops {
94 int (*bind) (struct thermal_zone_device *,
95 struct thermal_cooling_device *);
96 int (*unbind) (struct thermal_zone_device *,
97 struct thermal_cooling_device *);
Sascha Hauer17e83512015-07-24 08:12:54 +020098 int (*get_temp) (struct thermal_zone_device *, int *);
Sascha Hauer060c0342016-06-22 16:42:01 +080099 int (*set_trips) (struct thermal_zone_device *, int, int);
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000100 int (*get_mode) (struct thermal_zone_device *,
101 enum thermal_device_mode *);
102 int (*set_mode) (struct thermal_zone_device *,
103 enum thermal_device_mode);
104 int (*get_trip_type) (struct thermal_zone_device *, int,
105 enum thermal_trip_type *);
Sascha Hauer17e83512015-07-24 08:12:54 +0200106 int (*get_trip_temp) (struct thermal_zone_device *, int, int *);
107 int (*set_trip_temp) (struct thermal_zone_device *, int, int);
108 int (*get_trip_hyst) (struct thermal_zone_device *, int, int *);
109 int (*set_trip_hyst) (struct thermal_zone_device *, int, int);
110 int (*get_crit_temp) (struct thermal_zone_device *, int *);
111 int (*set_emul_temp) (struct thermal_zone_device *, int);
Zhang Rui601f3d42012-06-27 09:54:33 +0800112 int (*get_trend) (struct thermal_zone_device *, int,
113 enum thermal_trend *);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000114 int (*notify) (struct thermal_zone_device *, int,
115 enum thermal_trip_type);
Zhang Rui203d3d42008-01-17 15:51:08 +0800116};
117
118struct thermal_cooling_device_ops {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000119 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
120 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
121 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
Javi Merino35b11d22015-02-26 19:00:28 +0000122 int (*get_requested_power)(struct thermal_cooling_device *,
123 struct thermal_zone_device *, u32 *);
124 int (*state2power)(struct thermal_cooling_device *,
125 struct thermal_zone_device *, unsigned long, u32 *);
126 int (*power2state)(struct thermal_cooling_device *,
127 struct thermal_zone_device *, u32, unsigned long *);
Zhang Rui203d3d42008-01-17 15:51:08 +0800128};
129
Zhang Rui203d3d42008-01-17 15:51:08 +0800130struct thermal_cooling_device {
131 int id;
132 char type[THERMAL_NAME_LENGTH];
133 struct device device;
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400134 struct device_node *np;
Zhang Rui203d3d42008-01-17 15:51:08 +0800135 void *devdata;
Viresh Kumar8ea22952018-04-02 16:26:25 +0530136 void *stats;
Alan Cox5b275ce2010-11-11 15:27:29 +0000137 const struct thermal_cooling_device_ops *ops;
Zhang Ruice119f82012-06-27 14:13:04 +0800138 bool updated; /* true if the cooling device does not need update */
Zhang Ruif4a821c2012-07-24 16:56:21 +0800139 struct mutex lock; /* protect thermal_instances list */
Zhang Ruib5e4ae62012-06-27 14:11:52 +0800140 struct list_head thermal_instances;
Zhang Rui203d3d42008-01-17 15:51:08 +0800141 struct list_head node;
142};
143
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800144struct thermal_attr {
145 struct device_attribute attr;
146 char name[THERMAL_NAME_LENGTH];
147};
148
Javi Merinoc708a982014-06-25 11:00:12 +0100149/**
150 * struct thermal_zone_device - structure for a thermal zone
151 * @id: unique id number for each thermal zone
152 * @type: the thermal zone device type
153 * @device: &struct device for this thermal zone
154 * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature
155 * @trip_type_attrs: attributes for trip points for sysfs: trip type
156 * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis
157 * @devdata: private pointer for device private data
158 * @trips: number of trip points the thermal zone supports
Zhang Rui81ad4272016-03-18 10:03:24 +0800159 * @trips_disabled; bitmap for disabled trips
Javi Merinoc708a982014-06-25 11:00:12 +0100160 * @passive_delay: number of milliseconds to wait between polls when
Javi Merino6b775e82015-03-02 17:17:19 +0000161 * performing passive cooling.
Javi Merinoc708a982014-06-25 11:00:12 +0100162 * @polling_delay: number of milliseconds to wait between polls when
163 * checking whether trip points have been crossed (0 for
164 * interrupt driven systems)
165 * @temperature: current temperature. This is only for core code,
166 * drivers should use thermal_zone_get_temp() to get the
167 * current temperature
168 * @last_temperature: previous temperature read
169 * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION
170 * @passive: 1 if you've crossed a passive trip point, 0 otherwise.
Sascha Hauer060c0342016-06-22 16:42:01 +0800171 * @prev_low_trip: the low current temperature if you've crossed a passive
172 trip point.
173 * @prev_high_trip: the above current temperature if you've crossed a
174 passive trip point.
Javi Merinoc708a982014-06-25 11:00:12 +0100175 * @forced_passive: If > 0, temperature at which to switch on all ACPI
176 * processor cooling devices. Currently only used by the
177 * step-wise governor.
Chen Yu4511f712015-10-30 16:32:10 +0800178 * @need_update: if equals 1, thermal_zone_device_update needs to be invoked.
Javi Merinoc708a982014-06-25 11:00:12 +0100179 * @ops: operations this &thermal_zone_device supports
180 * @tzp: thermal zone parameters
181 * @governor: pointer to the governor for this thermal zone
Javi Merinoe33df1d2015-02-26 19:00:27 +0000182 * @governor_data: private pointer for governor data
Javi Merinoc708a982014-06-25 11:00:12 +0100183 * @thermal_instances: list of &struct thermal_instance of this thermal zone
Matthew Wilcoxb31ef822016-12-21 09:47:03 -0800184 * @ida: &struct ida to generate unique id for this zone's cooling
Javi Merinoc708a982014-06-25 11:00:12 +0100185 * devices
186 * @lock: lock to protect thermal_instances list
187 * @node: node in thermal_tz_list (in thermal_core.c)
188 * @poll_queue: delayed work for polling
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700189 * @notify_event: Last notification event
Javi Merinoc708a982014-06-25 11:00:12 +0100190 */
Zhang Rui203d3d42008-01-17 15:51:08 +0800191struct thermal_zone_device {
192 int id;
193 char type[THERMAL_NAME_LENGTH];
194 struct device device;
Eduardo Valentin4d0fe742016-11-07 21:08:52 -0800195 struct attribute_group trips_attribute_group;
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800196 struct thermal_attr *trip_temp_attrs;
197 struct thermal_attr *trip_type_attrs;
Durgadoss R27365a62012-07-25 10:10:59 +0800198 struct thermal_attr *trip_hyst_attrs;
Zhang Rui203d3d42008-01-17 15:51:08 +0800199 void *devdata;
200 int trips;
Zhang Rui81ad4272016-03-18 10:03:24 +0800201 unsigned long trips_disabled; /* bitmap for disabled trips */
Matthew Garrettb1569e92008-12-03 17:55:32 +0000202 int passive_delay;
203 int polling_delay;
Zhang Rui601f3d42012-06-27 09:54:33 +0800204 int temperature;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000205 int last_temperature;
Amit Daniel Kachhape6e238c2013-02-04 00:30:15 +0000206 int emul_temperature;
Zhang Rui908b9fb2012-06-27 14:14:05 +0800207 int passive;
Sascha Hauer060c0342016-06-22 16:42:01 +0800208 int prev_low_trip;
209 int prev_high_trip;
Matthew Garrett03a971a2008-12-03 18:00:38 +0000210 unsigned int forced_passive;
Chen Yu4511f712015-10-30 16:32:10 +0800211 atomic_t need_update;
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400212 struct thermal_zone_device_ops *ops;
Javi Merino6b775e82015-03-02 17:17:19 +0000213 struct thermal_zone_params *tzp;
Durgadoss Ra4a15482012-09-18 11:04:57 +0530214 struct thermal_governor *governor;
Javi Merinoe33df1d2015-02-26 19:00:27 +0000215 void *governor_data;
Zhang Rui2d374132012-06-27 10:09:00 +0800216 struct list_head thermal_instances;
Matthew Wilcoxb31ef822016-12-21 09:47:03 -0800217 struct ida ida;
Javi Merinoc708a982014-06-25 11:00:12 +0100218 struct mutex lock;
Zhang Rui203d3d42008-01-17 15:51:08 +0800219 struct list_head node;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000220 struct delayed_work poll_queue;
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700221 enum thermal_notify_event notify_event;
Zhang Rui203d3d42008-01-17 15:51:08 +0800222};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530223
Javi Merinoc708a982014-06-25 11:00:12 +0100224/**
225 * struct thermal_governor - structure that holds thermal governor information
226 * @name: name of the governor
Javi Merinoe33df1d2015-02-26 19:00:27 +0000227 * @bind_to_tz: callback called when binding to a thermal zone. If it
228 * returns 0, the governor is bound to the thermal zone,
229 * otherwise it fails.
230 * @unbind_from_tz: callback called when a governor is unbound from a
231 * thermal zone.
Javi Merinoc708a982014-06-25 11:00:12 +0100232 * @throttle: callback called for every trip point even if temperature is
233 * below the trip point temperature
234 * @governor_list: node in thermal_governor_list (in thermal_core.c)
235 */
Durgadoss Ra4a15482012-09-18 11:04:57 +0530236struct thermal_governor {
237 char name[THERMAL_NAME_LENGTH];
Javi Merinoe33df1d2015-02-26 19:00:27 +0000238 int (*bind_to_tz)(struct thermal_zone_device *tz);
239 void (*unbind_from_tz)(struct thermal_zone_device *tz);
Durgadoss Ra4a15482012-09-18 11:04:57 +0530240 int (*throttle)(struct thermal_zone_device *tz, int trip);
241 struct list_head governor_list;
Durgadoss Ra4a15482012-09-18 11:04:57 +0530242};
243
Durgadoss Ref873942012-09-18 11:04:55 +0530244/* Structure that holds binding parameters for a zone */
245struct thermal_bind_params {
246 struct thermal_cooling_device *cdev;
247
248 /*
249 * This is a measure of 'how effectively these devices can
Javi Merinobcdcbbc2015-02-18 16:04:25 +0000250 * cool 'this' thermal zone. It shall be determined by
251 * platform characterization. This value is relative to the
252 * rest of the weights so a cooling device whose weight is
253 * double that of another cooling device is twice as
254 * effective. See Documentation/thermal/sysfs-api.txt for more
255 * information.
Durgadoss Ref873942012-09-18 11:04:55 +0530256 */
257 int weight;
258
259 /*
260 * This is a bit mask that gives the binding relation between this
261 * thermal zone and cdev, for a particular trip point.
262 * See Documentation/thermal/sysfs-api.txt for more information.
263 */
264 int trip_mask;
Eduardo Valentina8892d832013-07-16 15:26:28 -0400265
266 /*
267 * This is an array of cooling state limits. Must have exactly
268 * 2 * thermal_zone.number_of_trip_points. It is an array consisting
269 * of tuples <lower-state upper-state> of state limits. Each trip
270 * will be associated with one state limit tuple when binding.
271 * A NULL pointer means <THERMAL_NO_LIMITS THERMAL_NO_LIMITS>
272 * on all trips.
273 */
274 unsigned long *binding_limits;
Durgadoss Ref873942012-09-18 11:04:55 +0530275 int (*match) (struct thermal_zone_device *tz,
276 struct thermal_cooling_device *cdev);
277};
278
279/* Structure to define Thermal Zone parameters */
280struct thermal_zone_params {
Durgadoss Ra4a15482012-09-18 11:04:57 +0530281 char governor_name[THERMAL_NAME_LENGTH];
Eduardo Valentinccba4ff2013-08-15 11:34:17 -0400282
283 /*
284 * a boolean to indicate if the thermal to hwmon sysfs interface
285 * is required. when no_hwmon == false, a hwmon sysfs interface
286 * will be created. when no_hwmon == true, nothing will be done
287 */
288 bool no_hwmon;
289
Durgadoss Ref873942012-09-18 11:04:55 +0530290 int num_tbps; /* Number of tbp entries */
291 struct thermal_bind_params *tbp;
Javi Merino6b775e82015-03-02 17:17:19 +0000292
293 /*
294 * Sustainable power (heat) that this thermal zone can dissipate in
295 * mW
296 */
297 u32 sustainable_power;
298
299 /*
300 * Proportional parameter of the PID controller when
301 * overshooting (i.e., when temperature is below the target)
302 */
303 s32 k_po;
304
305 /*
306 * Proportional parameter of the PID controller when
307 * undershooting
308 */
309 s32 k_pu;
310
311 /* Integral parameter of the PID controller */
312 s32 k_i;
313
314 /* Derivative parameter of the PID controller */
315 s32 k_d;
316
317 /* threshold below which the error is no longer accumulated */
318 s32 integral_cutoff;
Eduardo Valentin9d0be7f2015-05-11 19:34:23 -0700319
320 /*
321 * @slope: slope of a linear temperature adjustment curve.
322 * Used by thermal zone drivers.
323 */
324 int slope;
325 /*
326 * @offset: offset of a linear temperature adjustment curve.
327 * Used by thermal zone drivers (default 0).
328 */
329 int offset;
Durgadoss Ref873942012-09-18 11:04:55 +0530330};
331
R.Durgadoss4cb18722010-10-27 03:33:29 +0530332struct thermal_genl_event {
333 u32 orig;
334 enum events event;
335};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530336
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400337/**
338 * struct thermal_zone_of_device_ops - scallbacks for handling DT based zones
339 *
340 * Mandatory:
341 * @get_temp: a pointer to a function that reads the sensor temperature.
342 *
343 * Optional:
344 * @get_trend: a pointer to a function that reads the sensor temperature trend.
Sascha Hauer826386e2016-06-22 16:42:02 +0800345 * @set_trips: a pointer to a function that sets a temperature window. When
346 * this window is left the driver must inform the thermal core via
347 * thermal_zone_device_update.
Lukasz Majewski184a4bf2014-12-08 18:04:21 +0100348 * @set_emul_temp: a pointer to a function that sets sensor emulated
349 * temperature.
Caesar Wang5a5e78c2016-05-18 23:01:39 +0800350 * @set_trip_temp: a pointer to a function that sets the trip temperature on
351 * hardware.
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400352 */
353struct thermal_zone_of_device_ops {
Sascha Hauer17e83512015-07-24 08:12:54 +0200354 int (*get_temp)(void *, int *);
Sascha Hauere78eaf42016-06-22 16:42:03 +0800355 int (*get_trend)(void *, int, enum thermal_trend *);
Sascha Hauer826386e2016-06-22 16:42:02 +0800356 int (*set_trips)(void *, int, int);
Sascha Hauer17e83512015-07-24 08:12:54 +0200357 int (*set_emul_temp)(void *, int);
Wei Nic3509522016-03-29 18:29:17 +0800358 int (*set_trip_temp)(void *, int, int);
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400359};
360
Lukasz Majewskiad9914a2014-12-08 18:04:19 +0100361/**
362 * struct thermal_trip - representation of a point in temperature domain
363 * @np: pointer to struct device_node that this trip point was created from
364 * @temperature: temperature value in miliCelsius
365 * @hysteresis: relative hysteresis in miliCelsius
366 * @type: trip point type
367 */
368
369struct thermal_trip {
370 struct device_node *np;
Wei Ni1d0fd422016-03-03 17:33:46 +0800371 int temperature;
372 int hysteresis;
Lukasz Majewskiad9914a2014-12-08 18:04:19 +0100373 enum thermal_trip_type type;
374};
375
Durgadoss R23064082012-09-18 11:04:52 +0530376/* Function declarations */
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400377#ifdef CONFIG_THERMAL_OF
378struct thermal_zone_device *
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400379thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
380 const struct thermal_zone_of_device_ops *ops);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400381void thermal_zone_of_sensor_unregister(struct device *dev,
382 struct thermal_zone_device *tz);
Laxman Dewangane498b492016-03-09 18:40:06 +0530383struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
384 struct device *dev, int id, void *data,
385 const struct thermal_zone_of_device_ops *ops);
386void devm_thermal_zone_of_sensor_unregister(struct device *dev,
387 struct thermal_zone_device *tz);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400388#else
389static inline struct thermal_zone_device *
Eduardo Valentin2251aef2014-11-07 21:24:39 -0400390thermal_zone_of_sensor_register(struct device *dev, int id, void *data,
391 const struct thermal_zone_of_device_ops *ops)
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400392{
Punit Agrawalcd33dc92015-09-08 14:51:12 +0100393 return ERR_PTR(-ENODEV);
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400394}
395
396static inline
397void thermal_zone_of_sensor_unregister(struct device *dev,
398 struct thermal_zone_device *tz)
399{
400}
401
Laxman Dewangane498b492016-03-09 18:40:06 +0530402static inline struct thermal_zone_device *devm_thermal_zone_of_sensor_register(
403 struct device *dev, int id, void *data,
404 const struct thermal_zone_of_device_ops *ops)
405{
406 return ERR_PTR(-ENODEV);
407}
408
409static inline
410void devm_thermal_zone_of_sensor_unregister(struct device *dev,
411 struct thermal_zone_device *tz)
412{
413}
414
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400415#endif
Nishanth Menon12ca7182015-02-13 19:28:02 -0600416
417#if IS_ENABLED(CONFIG_THERMAL)
Javi Merino35b11d22015-02-26 19:00:28 +0000418static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
419{
420 return cdev->ops->get_requested_power && cdev->ops->state2power &&
421 cdev->ops->power2state;
422}
423
424int power_actor_get_max_power(struct thermal_cooling_device *,
425 struct thermal_zone_device *tz, u32 *max_power);
Javi Merinoc973c3b2015-09-14 14:23:50 +0100426int power_actor_get_min_power(struct thermal_cooling_device *,
427 struct thermal_zone_device *tz, u32 *min_power);
Javi Merino35b11d22015-02-26 19:00:28 +0000428int power_actor_set_power(struct thermal_cooling_device *,
429 struct thermal_instance *, u32);
Anton Vorontsov4b1bf582012-07-31 04:39:30 -0700430struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
Eduardo Valentin4e5e4702013-07-03 15:35:39 -0400431 void *, struct thermal_zone_device_ops *,
Javi Merino6b775e82015-03-02 17:17:19 +0000432 struct thermal_zone_params *, int, int);
Zhang Rui203d3d42008-01-17 15:51:08 +0800433void thermal_zone_device_unregister(struct thermal_zone_device *);
434
435int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
Zhang Rui9d998422012-06-26 16:35:57 +0800436 struct thermal_cooling_device *,
Kapileshwar Singh6cd9e9f2015-02-18 16:04:21 +0000437 unsigned long, unsigned long,
438 unsigned int);
Zhang Rui203d3d42008-01-17 15:51:08 +0800439int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
440 struct thermal_cooling_device *);
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700441void thermal_zone_device_update(struct thermal_zone_device *,
442 enum thermal_notify_event);
Sascha Hauer060c0342016-06-22 16:42:01 +0800443void thermal_zone_set_trips(struct thermal_zone_device *);
Durgadoss R23064082012-09-18 11:04:52 +0530444
Jean-Francois Dagenaisf991de52019-04-18 12:36:39 -0400445struct thermal_cooling_device *thermal_cooling_device_register(const char *,
446 void *, const struct thermal_cooling_device_ops *);
Eduardo Valentina116b5d2013-09-26 15:55:01 -0400447struct thermal_cooling_device *
Jean-Francois Dagenaisf991de52019-04-18 12:36:39 -0400448thermal_of_cooling_device_register(struct device_node *np, const char *, void *,
Eduardo Valentina116b5d2013-09-26 15:55:01 -0400449 const struct thermal_cooling_device_ops *);
Guenter Roeckb4ab114cc2019-04-18 12:58:15 -0700450struct thermal_cooling_device *
451devm_thermal_of_cooling_device_register(struct device *dev,
452 struct device_node *np,
453 char *type, void *devdata,
454 const struct thermal_cooling_device_ops *ops);
Zhang Rui203d3d42008-01-17 15:51:08 +0800455void thermal_cooling_device_unregister(struct thermal_cooling_device *);
Eduardo Valentin63c4d912013-04-05 12:32:28 +0000456struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name);
Sascha Hauer17e83512015-07-24 08:12:54 +0200457int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
Rajendra Nayak4a7069a2016-05-05 14:21:42 +0530458int thermal_zone_get_slope(struct thermal_zone_device *tz);
459int thermal_zone_get_offset(struct thermal_zone_device *tz);
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100460
Durgadoss R9b4298a2012-09-18 11:04:54 +0530461int get_tz_trend(struct thermal_zone_device *, int);
462struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
463 struct thermal_cooling_device *, int);
Durgadoss Rdc765482012-09-18 11:05:00 +0530464void thermal_cdev_update(struct thermal_cooling_device *);
Eduardo Valentin7b73c992013-04-23 21:48:14 +0000465void thermal_notify_framework(struct thermal_zone_device *, int);
Nishanth Menon12ca7182015-02-13 19:28:02 -0600466#else
Javi Merino35b11d22015-02-26 19:00:28 +0000467static inline bool cdev_is_power_actor(struct thermal_cooling_device *cdev)
468{ return false; }
469static inline int power_actor_get_max_power(struct thermal_cooling_device *cdev,
470 struct thermal_zone_device *tz, u32 *max_power)
471{ return 0; }
Javi Merinoc973c3b2015-09-14 14:23:50 +0100472static inline int power_actor_get_min_power(struct thermal_cooling_device *cdev,
473 struct thermal_zone_device *tz,
474 u32 *min_power)
475{ return -ENODEV; }
Javi Merino35b11d22015-02-26 19:00:28 +0000476static inline int power_actor_set_power(struct thermal_cooling_device *cdev,
477 struct thermal_instance *tz, u32 power)
478{ return 0; }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600479static inline struct thermal_zone_device *thermal_zone_device_register(
480 const char *type, int trips, int mask, void *devdata,
481 struct thermal_zone_device_ops *ops,
Arvind Yadav023b7b02017-08-31 11:30:45 +0530482 struct thermal_zone_params *tzp,
Nishanth Menon12ca7182015-02-13 19:28:02 -0600483 int passive_delay, int polling_delay)
484{ return ERR_PTR(-ENODEV); }
485static inline void thermal_zone_device_unregister(
486 struct thermal_zone_device *tz)
487{ }
488static inline int thermal_zone_bind_cooling_device(
489 struct thermal_zone_device *tz, int trip,
490 struct thermal_cooling_device *cdev,
Arnd Bergmannc86b3de2015-11-17 17:48:52 +0100491 unsigned long upper, unsigned long lower,
492 unsigned int weight)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600493{ return -ENODEV; }
494static inline int thermal_zone_unbind_cooling_device(
495 struct thermal_zone_device *tz, int trip,
496 struct thermal_cooling_device *cdev)
497{ return -ENODEV; }
Srinivas Pandruvada0e70f462016-08-26 16:21:16 -0700498static inline void thermal_zone_device_update(struct thermal_zone_device *tz,
499 enum thermal_notify_event event)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600500{ }
Sascha Hauer060c0342016-06-22 16:42:01 +0800501static inline void thermal_zone_set_trips(struct thermal_zone_device *tz)
502{ }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600503static inline struct thermal_cooling_device *
504thermal_cooling_device_register(char *type, void *devdata,
505 const struct thermal_cooling_device_ops *ops)
506{ return ERR_PTR(-ENODEV); }
507static inline struct thermal_cooling_device *
508thermal_of_cooling_device_register(struct device_node *np,
509 char *type, void *devdata, const struct thermal_cooling_device_ops *ops)
510{ return ERR_PTR(-ENODEV); }
Guenter Roeckb4ab114cc2019-04-18 12:58:15 -0700511static inline struct thermal_cooling_device *
512devm_thermal_of_cooling_device_register(struct device *dev,
513 struct device_node *np,
514 char *type, void *devdata,
515 const struct thermal_cooling_device_ops *ops)
516{
517 return ERR_PTR(-ENODEV);
518}
Nishanth Menon12ca7182015-02-13 19:28:02 -0600519static inline void thermal_cooling_device_unregister(
520 struct thermal_cooling_device *cdev)
521{ }
522static inline struct thermal_zone_device *thermal_zone_get_zone_by_name(
523 const char *name)
524{ return ERR_PTR(-ENODEV); }
525static inline int thermal_zone_get_temp(
Sascha Hauer17e83512015-07-24 08:12:54 +0200526 struct thermal_zone_device *tz, int *temp)
Nishanth Menon12ca7182015-02-13 19:28:02 -0600527{ return -ENODEV; }
Rajendra Nayak4a7069a2016-05-05 14:21:42 +0530528static inline int thermal_zone_get_slope(
529 struct thermal_zone_device *tz)
530{ return -ENODEV; }
531static inline int thermal_zone_get_offset(
532 struct thermal_zone_device *tz)
533{ return -ENODEV; }
Nishanth Menon12ca7182015-02-13 19:28:02 -0600534static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
535{ return -ENODEV; }
536static inline struct thermal_instance *
537get_thermal_instance(struct thermal_zone_device *tz,
538 struct thermal_cooling_device *cdev, int trip)
539{ return ERR_PTR(-ENODEV); }
540static inline void thermal_cdev_update(struct thermal_cooling_device *cdev)
541{ }
542static inline void thermal_notify_framework(struct thermal_zone_device *tz,
543 int trip)
544{ }
545#endif /* CONFIG_THERMAL */
Durgadoss Ra4a15482012-09-18 11:04:57 +0530546
Nishanth Menon12ca7182015-02-13 19:28:02 -0600547#if defined(CONFIG_NET) && IS_ENABLED(CONFIG_THERMAL)
Eduardo Valentin8ab3e6a2013-01-02 15:29:39 +0000548extern int thermal_generate_netlink_event(struct thermal_zone_device *tz,
549 enum events event);
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100550#else
Ezequiel Garciaf8b58702013-03-20 21:38:07 +0000551static inline int thermal_generate_netlink_event(struct thermal_zone_device *tz,
Eduardo Valentin8ab3e6a2013-01-02 15:29:39 +0000552 enum events event)
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100553{
554 return 0;
555}
556#endif
Zhang Rui203d3d42008-01-17 15:51:08 +0800557
Len Browna0dd25b2008-02-09 04:01:48 -0500558#endif /* __THERMAL_H__ */