Lina Iyer | 7e3c038 | 2018-05-07 11:52:29 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 2 | /* |
| 3 | * thermal.h ($Revision: 0 $) |
| 4 | * |
| 5 | * Copyright (C) 2008 Intel Corp |
| 6 | * Copyright (C) 2008 Zhang Rui <[email protected]> |
| 7 | * Copyright (C) 2008 Sujith Thomas <[email protected]> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __THERMAL_H__ |
| 11 | #define __THERMAL_H__ |
| 12 | |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 13 | #include <linux/of.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 14 | #include <linux/idr.h> |
| 15 | #include <linux/device.h> |
Eduardo Valentin | 4d0fe74 | 2016-11-07 21:08:52 -0800 | [diff] [blame] | 16 | #include <linux/sysfs.h> |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 17 | #include <linux/workqueue.h> |
Florian Fainelli | af6c9f1 | 2014-11-19 18:11:00 -0800 | [diff] [blame] | 18 | #include <uapi/linux/thermal.h> |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 19 | |
Zhang Rui | 57df8106 | 2013-02-08 14:52:06 +0800 | [diff] [blame] | 20 | /* invalid cooling state */ |
| 21 | #define THERMAL_CSTATE_INVALID -1UL |
| 22 | |
Durgadoss R | 2306408 | 2012-09-18 11:04:52 +0530 | [diff] [blame] | 23 | /* No upper/lower limit requirement */ |
Punit Agrawal | a940cb3 | 2014-12-09 12:22:01 +0000 | [diff] [blame] | 24 | #define THERMAL_NO_LIMIT ((u32)~0) |
Durgadoss R | 2306408 | 2012-09-18 11:04:52 +0530 | [diff] [blame] | 25 | |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 26 | /* Default weight of a bound cooling device */ |
| 27 | #define THERMAL_WEIGHT_DEFAULT 0 |
| 28 | |
Zhang Rui | bb431ba | 2015-10-30 16:31:47 +0800 | [diff] [blame] | 29 | /* use value, which < 0K, to indicate an invalid/uninitialized temperature */ |
| 30 | #define THERMAL_TEMP_INVALID -274000 |
| 31 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 32 | struct thermal_zone_device; |
| 33 | struct thermal_cooling_device; |
Javi Merino | 35b11d2 | 2015-02-26 19:00:28 +0000 | [diff] [blame] | 34 | struct thermal_instance; |
Daniel Lezcano | c68df44 | 2020-04-02 16:27:40 +0200 | [diff] [blame] | 35 | struct thermal_attr; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 36 | |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 37 | enum thermal_trend { |
| 38 | THERMAL_TREND_STABLE, /* temperature is stable */ |
| 39 | THERMAL_TREND_RAISING, /* temperature is raising */ |
| 40 | THERMAL_TREND_DROPPING, /* temperature is dropping */ |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 41 | }; |
| 42 | |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 43 | /* Thermal notification reason */ |
| 44 | enum thermal_notify_event { |
| 45 | THERMAL_EVENT_UNSPECIFIED, /* Unspecified event */ |
| 46 | THERMAL_EVENT_TEMP_SAMPLE, /* New Temperature sample */ |
| 47 | THERMAL_TRIP_VIOLATED, /* TRIP Point violation */ |
| 48 | THERMAL_TRIP_CHANGED, /* TRIP Point temperature changed */ |
| 49 | THERMAL_DEVICE_DOWN, /* Thermal device is down */ |
| 50 | THERMAL_DEVICE_UP, /* Thermal device is up after a down event */ |
| 51 | THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */ |
Brian Bian | 38e44da | 2017-08-09 11:45:40 -0700 | [diff] [blame] | 52 | THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */ |
Srinivas Pandruvada | 8805231 | 2020-09-15 15:36:49 -0700 | [diff] [blame] | 53 | THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */ |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 56 | struct thermal_zone_device_ops { |
| 57 | int (*bind) (struct thermal_zone_device *, |
| 58 | struct thermal_cooling_device *); |
| 59 | int (*unbind) (struct thermal_zone_device *, |
| 60 | struct thermal_cooling_device *); |
Sascha Hauer | 17e8351a | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 61 | int (*get_temp) (struct thermal_zone_device *, int *); |
Sascha Hauer | 060c034 | 2016-06-22 16:42:01 +0800 | [diff] [blame] | 62 | int (*set_trips) (struct thermal_zone_device *, int, int); |
Andrzej Pietrasiewicz | f5e50bf4 | 2020-06-29 14:29:25 +0200 | [diff] [blame] | 63 | int (*change_mode) (struct thermal_zone_device *, |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 64 | enum thermal_device_mode); |
| 65 | int (*get_trip_type) (struct thermal_zone_device *, int, |
| 66 | enum thermal_trip_type *); |
Sascha Hauer | 17e8351a | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 67 | int (*get_trip_temp) (struct thermal_zone_device *, int, int *); |
| 68 | int (*set_trip_temp) (struct thermal_zone_device *, int, int); |
| 69 | int (*get_trip_hyst) (struct thermal_zone_device *, int, int *); |
| 70 | int (*set_trip_hyst) (struct thermal_zone_device *, int, int); |
| 71 | int (*get_crit_temp) (struct thermal_zone_device *, int *); |
| 72 | int (*set_emul_temp) (struct thermal_zone_device *, int); |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 73 | int (*get_trend) (struct thermal_zone_device *, int, |
| 74 | enum thermal_trend *); |
Daniel Lezcano | d7203ee | 2020-12-10 13:15:11 +0100 | [diff] [blame] | 75 | void (*hot)(struct thermal_zone_device *); |
| 76 | void (*critical)(struct thermal_zone_device *); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 77 | }; |
| 78 | |
Daniel Lezcano | 646274d | 2022-07-22 22:00:01 +0200 | [diff] [blame] | 79 | /** |
| 80 | * struct thermal_trip - representation of a point in temperature domain |
| 81 | * @temperature: temperature value in miliCelsius |
| 82 | * @hysteresis: relative hysteresis in miliCelsius |
| 83 | * @type: trip point type |
| 84 | */ |
| 85 | struct thermal_trip { |
| 86 | int temperature; |
| 87 | int hysteresis; |
| 88 | enum thermal_trip_type type; |
| 89 | }; |
| 90 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 91 | struct thermal_cooling_device_ops { |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 92 | int (*get_max_state) (struct thermal_cooling_device *, unsigned long *); |
| 93 | int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *); |
| 94 | int (*set_cur_state) (struct thermal_cooling_device *, unsigned long); |
zhuguangqing | ecd1d2a | 2020-09-14 15:11:01 +0800 | [diff] [blame] | 95 | int (*get_requested_power)(struct thermal_cooling_device *, u32 *); |
| 96 | int (*state2power)(struct thermal_cooling_device *, unsigned long, u32 *); |
| 97 | int (*power2state)(struct thermal_cooling_device *, u32, unsigned long *); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 98 | }; |
| 99 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 100 | struct thermal_cooling_device { |
| 101 | int id; |
Daniel Lezcano | 5848376 | 2021-03-14 12:13:29 +0100 | [diff] [blame] | 102 | char *type; |
Viresh Kumar | 80bb3b9 | 2022-10-17 15:33:01 +0530 | [diff] [blame] | 103 | unsigned long max_state; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 104 | struct device device; |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 105 | struct device_node *np; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 106 | void *devdata; |
Viresh Kumar | 8ea2295 | 2018-04-02 16:26:25 +0530 | [diff] [blame] | 107 | void *stats; |
Alan Cox | 5b275ce | 2010-11-11 15:27:29 +0000 | [diff] [blame] | 108 | const struct thermal_cooling_device_ops *ops; |
Zhang Rui | ce119f8 | 2012-06-27 14:13:04 +0800 | [diff] [blame] | 109 | bool updated; /* true if the cooling device does not need update */ |
Zhang Rui | f4a821c | 2012-07-24 16:56:21 +0800 | [diff] [blame] | 110 | struct mutex lock; /* protect thermal_instances list */ |
Zhang Rui | b5e4ae6 | 2012-06-27 14:11:52 +0800 | [diff] [blame] | 111 | struct list_head thermal_instances; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 112 | struct list_head node; |
| 113 | }; |
| 114 | |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 115 | /** |
| 116 | * struct thermal_zone_device - structure for a thermal zone |
| 117 | * @id: unique id number for each thermal zone |
| 118 | * @type: the thermal zone device type |
| 119 | * @device: &struct device for this thermal zone |
| 120 | * @trip_temp_attrs: attributes for trip points for sysfs: trip temperature |
| 121 | * @trip_type_attrs: attributes for trip points for sysfs: trip type |
| 122 | * @trip_hyst_attrs: attributes for trip points for sysfs: trip hysteresis |
Andrzej Pietrasiewicz | cbba1d7 | 2020-06-29 14:29:17 +0200 | [diff] [blame] | 123 | * @mode: current mode of this thermal zone |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 124 | * @devdata: private pointer for device private data |
Daniel Lezcano | fae11de | 2022-07-22 22:00:05 +0200 | [diff] [blame] | 125 | * @trips: an array of struct thermal_trip |
Daniel Lezcano | e5bfcd3 | 2022-07-22 22:00:04 +0200 | [diff] [blame] | 126 | * @num_trips: number of trip points the thermal zone supports |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 127 | * @trips_disabled; bitmap for disabled trips |
Daniel Lezcano | 17d399c | 2020-12-16 23:03:35 +0100 | [diff] [blame] | 128 | * @passive_delay_jiffies: number of jiffies to wait between polls when |
| 129 | * performing passive cooling. |
Daniel Lezcano | 17d399c | 2020-12-16 23:03:35 +0100 | [diff] [blame] | 130 | * @polling_delay_jiffies: number of jiffies to wait between polls when |
| 131 | * checking whether trip points have been crossed (0 for |
| 132 | * interrupt driven systems) |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 133 | * @temperature: current temperature. This is only for core code, |
| 134 | * drivers should use thermal_zone_get_temp() to get the |
| 135 | * current temperature |
| 136 | * @last_temperature: previous temperature read |
| 137 | * @emul_temperature: emulated temperature when using CONFIG_THERMAL_EMULATION |
| 138 | * @passive: 1 if you've crossed a passive trip point, 0 otherwise. |
Sascha Hauer | 060c034 | 2016-06-22 16:42:01 +0800 | [diff] [blame] | 139 | * @prev_low_trip: the low current temperature if you've crossed a passive |
| 140 | trip point. |
| 141 | * @prev_high_trip: the above current temperature if you've crossed a |
| 142 | passive trip point. |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 143 | * @need_update: if equals 1, thermal_zone_device_update needs to be invoked. |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 144 | * @ops: operations this &thermal_zone_device supports |
| 145 | * @tzp: thermal zone parameters |
| 146 | * @governor: pointer to the governor for this thermal zone |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 147 | * @governor_data: private pointer for governor data |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 148 | * @thermal_instances: list of &struct thermal_instance of this thermal zone |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 149 | * @ida: &struct ida to generate unique id for this zone's cooling |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 150 | * devices |
| 151 | * @lock: lock to protect thermal_instances list |
| 152 | * @node: node in thermal_tz_list (in thermal_core.c) |
| 153 | * @poll_queue: delayed work for polling |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 154 | * @notify_event: Last notification event |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 155 | */ |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 156 | struct thermal_zone_device { |
| 157 | int id; |
| 158 | char type[THERMAL_NAME_LENGTH]; |
| 159 | struct device device; |
Eduardo Valentin | 4d0fe74 | 2016-11-07 21:08:52 -0800 | [diff] [blame] | 160 | struct attribute_group trips_attribute_group; |
Durgadoss R | c56f5c0 | 2012-07-25 10:10:58 +0800 | [diff] [blame] | 161 | struct thermal_attr *trip_temp_attrs; |
| 162 | struct thermal_attr *trip_type_attrs; |
Durgadoss R | 27365a6 | 2012-07-25 10:10:59 +0800 | [diff] [blame] | 163 | struct thermal_attr *trip_hyst_attrs; |
Andrzej Pietrasiewicz | cbba1d7 | 2020-06-29 14:29:17 +0200 | [diff] [blame] | 164 | enum thermal_device_mode mode; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 165 | void *devdata; |
Daniel Lezcano | fae11de | 2022-07-22 22:00:05 +0200 | [diff] [blame] | 166 | struct thermal_trip *trips; |
Daniel Lezcano | e5bfcd3 | 2022-07-22 22:00:04 +0200 | [diff] [blame] | 167 | int num_trips; |
Zhang Rui | 81ad427 | 2016-03-18 10:03:24 +0800 | [diff] [blame] | 168 | unsigned long trips_disabled; /* bitmap for disabled trips */ |
Daniel Lezcano | 17d399c | 2020-12-16 23:03:35 +0100 | [diff] [blame] | 169 | unsigned long passive_delay_jiffies; |
| 170 | unsigned long polling_delay_jiffies; |
Zhang Rui | 601f3d4 | 2012-06-27 09:54:33 +0800 | [diff] [blame] | 171 | int temperature; |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 172 | int last_temperature; |
Amit Daniel Kachhap | e6e238c | 2013-02-04 00:30:15 +0000 | [diff] [blame] | 173 | int emul_temperature; |
Zhang Rui | 908b9fb | 2012-06-27 14:14:05 +0800 | [diff] [blame] | 174 | int passive; |
Sascha Hauer | 060c034 | 2016-06-22 16:42:01 +0800 | [diff] [blame] | 175 | int prev_low_trip; |
| 176 | int prev_high_trip; |
Chen Yu | 4511f71 | 2015-10-30 16:32:10 +0800 | [diff] [blame] | 177 | atomic_t need_update; |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 178 | struct thermal_zone_device_ops *ops; |
Javi Merino | 6b775e8 | 2015-03-02 17:17:19 +0000 | [diff] [blame] | 179 | struct thermal_zone_params *tzp; |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 180 | struct thermal_governor *governor; |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 181 | void *governor_data; |
Zhang Rui | 2d37413 | 2012-06-27 10:09:00 +0800 | [diff] [blame] | 182 | struct list_head thermal_instances; |
Matthew Wilcox | b31ef82 | 2016-12-21 09:47:03 -0800 | [diff] [blame] | 183 | struct ida ida; |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 184 | struct mutex lock; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 185 | struct list_head node; |
Matthew Garrett | b1569e9 | 2008-12-03 17:55:32 +0000 | [diff] [blame] | 186 | struct delayed_work poll_queue; |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 187 | enum thermal_notify_event notify_event; |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 188 | }; |
R.Durgadoss | 4cb1872 | 2010-10-27 03:33:29 +0530 | [diff] [blame] | 189 | |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 190 | /** |
| 191 | * struct thermal_governor - structure that holds thermal governor information |
| 192 | * @name: name of the governor |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 193 | * @bind_to_tz: callback called when binding to a thermal zone. If it |
| 194 | * returns 0, the governor is bound to the thermal zone, |
| 195 | * otherwise it fails. |
| 196 | * @unbind_from_tz: callback called when a governor is unbound from a |
| 197 | * thermal zone. |
Javi Merino | c708a98 | 2014-06-25 11:00:12 +0100 | [diff] [blame] | 198 | * @throttle: callback called for every trip point even if temperature is |
| 199 | * below the trip point temperature |
| 200 | * @governor_list: node in thermal_governor_list (in thermal_core.c) |
| 201 | */ |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 202 | struct thermal_governor { |
| 203 | char name[THERMAL_NAME_LENGTH]; |
Javi Merino | e33df1d | 2015-02-26 19:00:27 +0000 | [diff] [blame] | 204 | int (*bind_to_tz)(struct thermal_zone_device *tz); |
| 205 | void (*unbind_from_tz)(struct thermal_zone_device *tz); |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 206 | int (*throttle)(struct thermal_zone_device *tz, int trip); |
| 207 | struct list_head governor_list; |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 208 | }; |
| 209 | |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 210 | /* Structure that holds binding parameters for a zone */ |
| 211 | struct thermal_bind_params { |
| 212 | struct thermal_cooling_device *cdev; |
| 213 | |
| 214 | /* |
| 215 | * This is a measure of 'how effectively these devices can |
Javi Merino | bcdcbbc | 2015-02-18 16:04:25 +0000 | [diff] [blame] | 216 | * cool 'this' thermal zone. It shall be determined by |
| 217 | * platform characterization. This value is relative to the |
| 218 | * rest of the weights so a cooling device whose weight is |
| 219 | * double that of another cooling device is twice as |
Mauro Carvalho Chehab | eaf7b46 | 2019-07-26 09:51:12 -0300 | [diff] [blame] | 220 | * effective. See Documentation/driver-api/thermal/sysfs-api.rst for more |
Javi Merino | bcdcbbc | 2015-02-18 16:04:25 +0000 | [diff] [blame] | 221 | * information. |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 222 | */ |
| 223 | int weight; |
| 224 | |
| 225 | /* |
| 226 | * This is a bit mask that gives the binding relation between this |
| 227 | * thermal zone and cdev, for a particular trip point. |
Mauro Carvalho Chehab | eaf7b46 | 2019-07-26 09:51:12 -0300 | [diff] [blame] | 228 | * See Documentation/driver-api/thermal/sysfs-api.rst for more information. |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 229 | */ |
| 230 | int trip_mask; |
Eduardo Valentin | a8892d83 | 2013-07-16 15:26:28 -0400 | [diff] [blame] | 231 | |
| 232 | /* |
| 233 | * This is an array of cooling state limits. Must have exactly |
| 234 | * 2 * thermal_zone.number_of_trip_points. It is an array consisting |
| 235 | * of tuples <lower-state upper-state> of state limits. Each trip |
| 236 | * will be associated with one state limit tuple when binding. |
| 237 | * A NULL pointer means <THERMAL_NO_LIMITS THERMAL_NO_LIMITS> |
| 238 | * on all trips. |
| 239 | */ |
| 240 | unsigned long *binding_limits; |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 241 | int (*match) (struct thermal_zone_device *tz, |
| 242 | struct thermal_cooling_device *cdev); |
| 243 | }; |
| 244 | |
| 245 | /* Structure to define Thermal Zone parameters */ |
| 246 | struct thermal_zone_params { |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 247 | char governor_name[THERMAL_NAME_LENGTH]; |
Eduardo Valentin | ccba4ff | 2013-08-15 11:34:17 -0400 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * a boolean to indicate if the thermal to hwmon sysfs interface |
| 251 | * is required. when no_hwmon == false, a hwmon sysfs interface |
| 252 | * will be created. when no_hwmon == true, nothing will be done |
| 253 | */ |
| 254 | bool no_hwmon; |
| 255 | |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 256 | int num_tbps; /* Number of tbp entries */ |
| 257 | struct thermal_bind_params *tbp; |
Javi Merino | 6b775e8 | 2015-03-02 17:17:19 +0000 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * Sustainable power (heat) that this thermal zone can dissipate in |
| 261 | * mW |
| 262 | */ |
| 263 | u32 sustainable_power; |
| 264 | |
| 265 | /* |
| 266 | * Proportional parameter of the PID controller when |
| 267 | * overshooting (i.e., when temperature is below the target) |
| 268 | */ |
| 269 | s32 k_po; |
| 270 | |
| 271 | /* |
| 272 | * Proportional parameter of the PID controller when |
| 273 | * undershooting |
| 274 | */ |
| 275 | s32 k_pu; |
| 276 | |
| 277 | /* Integral parameter of the PID controller */ |
| 278 | s32 k_i; |
| 279 | |
| 280 | /* Derivative parameter of the PID controller */ |
| 281 | s32 k_d; |
| 282 | |
| 283 | /* threshold below which the error is no longer accumulated */ |
| 284 | s32 integral_cutoff; |
Eduardo Valentin | 9d0be7f | 2015-05-11 19:34:23 -0700 | [diff] [blame] | 285 | |
| 286 | /* |
| 287 | * @slope: slope of a linear temperature adjustment curve. |
| 288 | * Used by thermal zone drivers. |
| 289 | */ |
| 290 | int slope; |
| 291 | /* |
| 292 | * @offset: offset of a linear temperature adjustment curve. |
| 293 | * Used by thermal zone drivers (default 0). |
| 294 | */ |
| 295 | int offset; |
Durgadoss R | ef87394 | 2012-09-18 11:04:55 +0530 | [diff] [blame] | 296 | }; |
| 297 | |
Durgadoss R | 2306408 | 2012-09-18 11:04:52 +0530 | [diff] [blame] | 298 | /* Function declarations */ |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 299 | #ifdef CONFIG_THERMAL_OF |
Daniel Lezcano | 3fd6d6e | 2022-08-05 00:43:17 +0200 | [diff] [blame] | 300 | struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, |
| 301 | const struct thermal_zone_device_ops *ops); |
| 302 | |
| 303 | struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data, |
| 304 | const struct thermal_zone_device_ops *ops); |
| 305 | |
| 306 | void thermal_of_zone_unregister(struct thermal_zone_device *tz); |
| 307 | |
| 308 | void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_device *tz); |
| 309 | |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 310 | void thermal_of_zone_unregister(struct thermal_zone_device *tz); |
| 311 | |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 312 | #else |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 313 | static inline |
| 314 | struct thermal_zone_device *thermal_of_zone_register(struct device_node *sensor, int id, void *data, |
| 315 | const struct thermal_zone_device_ops *ops) |
Anson Huang | 34471ab | 2020-02-22 08:08:49 +0800 | [diff] [blame] | 316 | { |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 317 | return ERR_PTR(-ENOTSUPP); |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | static inline |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 321 | struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, int id, void *data, |
| 322 | const struct thermal_zone_device_ops *ops) |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 323 | { |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 324 | return ERR_PTR(-ENOTSUPP); |
Laxman Dewangan | e498b49 | 2016-03-09 18:40:06 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Daniel Lezcano | 3fd6d6e | 2022-08-05 00:43:17 +0200 | [diff] [blame] | 327 | static inline void thermal_of_zone_unregister(struct thermal_zone_device *tz) |
| 328 | { |
| 329 | } |
| 330 | |
Daniel Lezcano | f59ac19 | 2022-08-05 00:43:49 +0200 | [diff] [blame] | 331 | static inline void devm_thermal_of_zone_unregister(struct device *dev, |
| 332 | struct thermal_zone_device *tz) |
Daniel Lezcano | 3fd6d6e | 2022-08-05 00:43:17 +0200 | [diff] [blame] | 333 | { |
| 334 | } |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 335 | #endif |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 336 | |
Daniel Lezcano | 6051826 | 2020-04-02 16:27:45 +0200 | [diff] [blame] | 337 | #ifdef CONFIG_THERMAL |
Anton Vorontsov | 4b1bf58 | 2012-07-31 04:39:30 -0700 | [diff] [blame] | 338 | struct thermal_zone_device *thermal_zone_device_register(const char *, int, int, |
Eduardo Valentin | 4e5e470 | 2013-07-03 15:35:39 -0400 | [diff] [blame] | 339 | void *, struct thermal_zone_device_ops *, |
Javi Merino | 6b775e8 | 2015-03-02 17:17:19 +0000 | [diff] [blame] | 340 | struct thermal_zone_params *, int, int); |
Daniel Lezcano | fae11de | 2022-07-22 22:00:05 +0200 | [diff] [blame] | 341 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 342 | void thermal_zone_device_unregister(struct thermal_zone_device *); |
| 343 | |
Daniel Lezcano | fae11de | 2022-07-22 22:00:05 +0200 | [diff] [blame] | 344 | struct thermal_zone_device * |
| 345 | thermal_zone_device_register_with_trips(const char *, struct thermal_trip *, int, int, |
| 346 | void *, struct thermal_zone_device_ops *, |
| 347 | struct thermal_zone_params *, int, int); |
| 348 | |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 349 | int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int, |
Zhang Rui | 9d99842 | 2012-06-26 16:35:57 +0800 | [diff] [blame] | 350 | struct thermal_cooling_device *, |
Kapileshwar Singh | 6cd9e9f | 2015-02-18 16:04:21 +0000 | [diff] [blame] | 351 | unsigned long, unsigned long, |
| 352 | unsigned int); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 353 | int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int, |
| 354 | struct thermal_cooling_device *); |
Srinivas Pandruvada | 0e70f46 | 2016-08-26 16:21:16 -0700 | [diff] [blame] | 355 | void thermal_zone_device_update(struct thermal_zone_device *, |
| 356 | enum thermal_notify_event); |
Durgadoss R | 2306408 | 2012-09-18 11:04:52 +0530 | [diff] [blame] | 357 | |
Jean-Francois Dagenais | f991de5 | 2019-04-18 12:36:39 -0400 | [diff] [blame] | 358 | struct thermal_cooling_device *thermal_cooling_device_register(const char *, |
| 359 | void *, const struct thermal_cooling_device_ops *); |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 360 | struct thermal_cooling_device * |
Jean-Francois Dagenais | f991de5 | 2019-04-18 12:36:39 -0400 | [diff] [blame] | 361 | thermal_of_cooling_device_register(struct device_node *np, const char *, void *, |
Eduardo Valentin | a116b5d | 2013-09-26 15:55:01 -0400 | [diff] [blame] | 362 | const struct thermal_cooling_device_ops *); |
Guenter Roeck | b4ab114cc | 2019-04-18 12:58:15 -0700 | [diff] [blame] | 363 | struct thermal_cooling_device * |
| 364 | devm_thermal_of_cooling_device_register(struct device *dev, |
| 365 | struct device_node *np, |
| 366 | char *type, void *devdata, |
| 367 | const struct thermal_cooling_device_ops *ops); |
Zhang Rui | 203d3d4 | 2008-01-17 15:51:08 +0800 | [diff] [blame] | 368 | void thermal_cooling_device_unregister(struct thermal_cooling_device *); |
Eduardo Valentin | 63c4d91 | 2013-04-05 12:32:28 +0000 | [diff] [blame] | 369 | struct thermal_zone_device *thermal_zone_get_zone_by_name(const char *name); |
Sascha Hauer | 17e8351a | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 370 | int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp); |
Rajendra Nayak | 4a7069a | 2016-05-05 14:21:42 +0530 | [diff] [blame] | 371 | int thermal_zone_get_slope(struct thermal_zone_device *tz); |
| 372 | int thermal_zone_get_offset(struct thermal_zone_device *tz); |
Rafael J. Wysocki | af06216 | 2011-03-01 01:12:19 +0100 | [diff] [blame] | 373 | |
Andrzej Pietrasiewicz | ac5d9ec | 2020-06-29 14:29:20 +0200 | [diff] [blame] | 374 | int thermal_zone_device_enable(struct thermal_zone_device *tz); |
| 375 | int thermal_zone_device_disable(struct thermal_zone_device *tz); |
Daniel Lezcano | d7203ee | 2020-12-10 13:15:11 +0100 | [diff] [blame] | 376 | void thermal_zone_device_critical(struct thermal_zone_device *tz); |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 377 | #else |
| 378 | static inline struct thermal_zone_device *thermal_zone_device_register( |
| 379 | const char *type, int trips, int mask, void *devdata, |
| 380 | struct thermal_zone_device_ops *ops, |
Arvind Yadav | 023b7b0 | 2017-08-31 11:30:45 +0530 | [diff] [blame] | 381 | struct thermal_zone_params *tzp, |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 382 | int passive_delay, int polling_delay) |
| 383 | { return ERR_PTR(-ENODEV); } |
| 384 | static inline void thermal_zone_device_unregister( |
| 385 | struct thermal_zone_device *tz) |
| 386 | { } |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 387 | static inline struct thermal_cooling_device * |
Arnd Bergmann | fb83610 | 2021-07-22 11:06:44 +0200 | [diff] [blame] | 388 | thermal_cooling_device_register(const char *type, void *devdata, |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 389 | const struct thermal_cooling_device_ops *ops) |
| 390 | { return ERR_PTR(-ENODEV); } |
| 391 | static inline struct thermal_cooling_device * |
| 392 | thermal_of_cooling_device_register(struct device_node *np, |
Arnd Bergmann | fb83610 | 2021-07-22 11:06:44 +0200 | [diff] [blame] | 393 | const char *type, void *devdata, |
| 394 | const struct thermal_cooling_device_ops *ops) |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 395 | { return ERR_PTR(-ENODEV); } |
Guenter Roeck | b4ab114cc | 2019-04-18 12:58:15 -0700 | [diff] [blame] | 396 | static inline struct thermal_cooling_device * |
| 397 | devm_thermal_of_cooling_device_register(struct device *dev, |
| 398 | struct device_node *np, |
| 399 | char *type, void *devdata, |
| 400 | const struct thermal_cooling_device_ops *ops) |
| 401 | { |
| 402 | return ERR_PTR(-ENODEV); |
| 403 | } |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 404 | static inline void thermal_cooling_device_unregister( |
| 405 | struct thermal_cooling_device *cdev) |
| 406 | { } |
| 407 | static inline struct thermal_zone_device *thermal_zone_get_zone_by_name( |
| 408 | const char *name) |
| 409 | { return ERR_PTR(-ENODEV); } |
| 410 | static inline int thermal_zone_get_temp( |
Sascha Hauer | 17e8351a | 2015-07-24 08:12:54 +0200 | [diff] [blame] | 411 | struct thermal_zone_device *tz, int *temp) |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 412 | { return -ENODEV; } |
Rajendra Nayak | 4a7069a | 2016-05-05 14:21:42 +0530 | [diff] [blame] | 413 | static inline int thermal_zone_get_slope( |
| 414 | struct thermal_zone_device *tz) |
| 415 | { return -ENODEV; } |
| 416 | static inline int thermal_zone_get_offset( |
| 417 | struct thermal_zone_device *tz) |
| 418 | { return -ENODEV; } |
Daniel Lezcano | f0129c2 | 2020-04-02 16:27:43 +0200 | [diff] [blame] | 419 | |
Andrzej Pietrasiewicz | ac5d9ec | 2020-06-29 14:29:20 +0200 | [diff] [blame] | 420 | static inline int thermal_zone_device_enable(struct thermal_zone_device *tz) |
| 421 | { return -ENODEV; } |
| 422 | |
| 423 | static inline int thermal_zone_device_disable(struct thermal_zone_device *tz) |
| 424 | { return -ENODEV; } |
Nishanth Menon | 12ca718 | 2015-02-13 19:28:02 -0600 | [diff] [blame] | 425 | #endif /* CONFIG_THERMAL */ |
Durgadoss R | a4a1548 | 2012-09-18 11:04:57 +0530 | [diff] [blame] | 426 | |
Len Brown | a0dd25b | 2008-02-09 04:01:48 -0500 | [diff] [blame] | 427 | #endif /* __THERMAL_H__ */ |