2 * thermal.h ($Revision: 0 $)
4 * Copyright (C) 2008 Intel Corp
8 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 #include <linux/idr.h>
29 #include <linux/device.h>
30 #include <linux/workqueue.h>
32 #define THERMAL_TRIPS_NONE -1
33 #define THERMAL_MAX_TRIPS 12
34 #define THERMAL_NAME_LENGTH 20
36 /* No upper/lower limit requirement */
37 #define THERMAL_NO_LIMIT -1UL
39 /* Unit conversion macros */
40 #define KELVIN_TO_CELSIUS(t) (long)(((long)t-2732 >= 0) ? \
41 ((long)t-2732+5)/10 : ((long)t-2732-5)/10)
42 #define CELSIUS_TO_KELVIN(t) ((t)*10+2732)
44 /* Adding event notification support elements */
45 #define THERMAL_GENL_FAMILY_NAME "thermal_event"
46 #define THERMAL_GENL_VERSION 0x01
47 #define THERMAL_GENL_MCAST_GROUP_NAME "thermal_mc_group"
49 /* Default Thermal Governor */
50 #if defined(CONFIG_THERMAL_DEFAULT_GOV_STEP_WISE)
51 #define DEFAULT_THERMAL_GOVERNOR "step_wise"
52 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_FAIR_SHARE)
53 #define DEFAULT_THERMAL_GOVERNOR "fair_share"
54 #elif defined(CONFIG_THERMAL_DEFAULT_GOV_USER_SPACE)
55 #define DEFAULT_THERMAL_GOVERNOR "user_space"
58 struct thermal_zone_device;
59 struct thermal_cooling_device;
61 enum thermal_device_mode {
62 THERMAL_DEVICE_DISABLED = 0,
63 THERMAL_DEVICE_ENABLED,
66 enum thermal_trip_type {
67 THERMAL_TRIP_ACTIVE = 0,
70 THERMAL_TRIP_CRITICAL,
74 THERMAL_TREND_STABLE, /* temperature is stable */
75 THERMAL_TREND_RAISING, /* temperature is raising */
76 THERMAL_TREND_DROPPING, /* temperature is dropping */
79 /* Events supported by Thermal Netlink */
87 /* attributes of thermal_genl_family */
89 THERMAL_GENL_ATTR_UNSPEC,
90 THERMAL_GENL_ATTR_EVENT,
91 __THERMAL_GENL_ATTR_MAX,
93 #define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
95 /* commands supported by the thermal_genl_family */
97 THERMAL_GENL_CMD_UNSPEC,
98 THERMAL_GENL_CMD_EVENT,
99 __THERMAL_GENL_CMD_MAX,
101 #define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
103 struct thermal_zone_device_ops {
104 int (*bind) (struct thermal_zone_device *,
105 struct thermal_cooling_device *);
106 int (*unbind) (struct thermal_zone_device *,
107 struct thermal_cooling_device *);
108 int (*get_temp) (struct thermal_zone_device *, unsigned long *);
109 int (*get_mode) (struct thermal_zone_device *,
110 enum thermal_device_mode *);
111 int (*set_mode) (struct thermal_zone_device *,
112 enum thermal_device_mode);
113 int (*get_trip_type) (struct thermal_zone_device *, int,
114 enum thermal_trip_type *);
115 int (*get_trip_temp) (struct thermal_zone_device *, int,
117 int (*set_trip_temp) (struct thermal_zone_device *, int,
119 int (*get_trip_hyst) (struct thermal_zone_device *, int,
121 int (*set_trip_hyst) (struct thermal_zone_device *, int,
123 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
124 int (*get_trend) (struct thermal_zone_device *, int,
125 enum thermal_trend *);
126 int (*notify) (struct thermal_zone_device *, int,
127 enum thermal_trip_type);
130 struct thermal_cooling_device_ops {
131 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
132 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
133 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
136 struct thermal_cooling_device {
138 char type[THERMAL_NAME_LENGTH];
139 struct device device;
141 const struct thermal_cooling_device_ops *ops;
142 bool updated; /* true if the cooling device does not need update */
143 struct mutex lock; /* protect thermal_instances list */
144 struct list_head thermal_instances;
145 struct list_head node;
148 struct thermal_attr {
149 struct device_attribute attr;
150 char name[THERMAL_NAME_LENGTH];
153 struct thermal_zone_device {
155 char type[THERMAL_NAME_LENGTH];
156 struct device device;
157 struct thermal_attr *trip_temp_attrs;
158 struct thermal_attr *trip_type_attrs;
159 struct thermal_attr *trip_hyst_attrs;
165 int last_temperature;
167 unsigned int forced_passive;
168 const struct thermal_zone_device_ops *ops;
169 const struct thermal_zone_params *tzp;
170 struct thermal_governor *governor;
171 struct list_head thermal_instances;
173 struct mutex lock; /* protect thermal_instances list */
174 struct list_head node;
175 struct delayed_work poll_queue;
178 /* Structure that holds thermal governor information */
179 struct thermal_governor {
180 char name[THERMAL_NAME_LENGTH];
181 int (*throttle)(struct thermal_zone_device *tz, int trip);
182 struct list_head governor_list;
183 struct module *owner;
186 /* Structure that holds binding parameters for a zone */
187 struct thermal_bind_params {
188 struct thermal_cooling_device *cdev;
191 * This is a measure of 'how effectively these devices can
192 * cool 'this' thermal zone. The shall be determined by platform
193 * characterization. This is on a 'percentage' scale.
194 * See Documentation/thermal/sysfs-api.txt for more information.
199 * This is a bit mask that gives the binding relation between this
200 * thermal zone and cdev, for a particular trip point.
201 * See Documentation/thermal/sysfs-api.txt for more information.
204 int (*match) (struct thermal_zone_device *tz,
205 struct thermal_cooling_device *cdev);
208 /* Structure to define Thermal Zone parameters */
209 struct thermal_zone_params {
210 char governor_name[THERMAL_NAME_LENGTH];
211 int num_tbps; /* Number of tbp entries */
212 struct thermal_bind_params *tbp;
215 struct thermal_genl_event {
220 /* Function declarations */
221 struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
222 void *, const struct thermal_zone_device_ops *,
223 const struct thermal_zone_params *, int, int);
224 void thermal_zone_device_unregister(struct thermal_zone_device *);
226 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
227 struct thermal_cooling_device *,
228 unsigned long, unsigned long);
229 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
230 struct thermal_cooling_device *);
231 void thermal_zone_device_update(struct thermal_zone_device *);
233 struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
234 const struct thermal_cooling_device_ops *);
235 void thermal_cooling_device_unregister(struct thermal_cooling_device *);
237 int get_tz_trend(struct thermal_zone_device *, int);
238 struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
239 struct thermal_cooling_device *, int);
240 void thermal_cdev_update(struct thermal_cooling_device *);
241 void notify_thermal_framework(struct thermal_zone_device *, int);
243 int thermal_register_governor(struct thermal_governor *);
244 void thermal_unregister_governor(struct thermal_governor *);
247 extern int thermal_generate_netlink_event(u32 orig, enum events event);
249 static inline int thermal_generate_netlink_event(u32 orig, enum events event)
255 #endif /* __THERMAL_H__ */