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