blob: 58cb1c036a0edcf800653292be6f901e78fcb9bc [file] [log] [blame]
Zhang Rui203d3d42008-01-17 15:51:08 +08001/*
2 * thermal.h ($Revision: 0 $)
3 *
4 * Copyright (C) 2008 Intel Corp
5 * Copyright (C) 2008 Zhang Rui <rui.zhang@intel.com>
6 * Copyright (C) 2008 Sujith Thomas <sujith.thomas@intel.com>
7 *
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.
12 *
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.
17 *
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.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24
25#ifndef __THERMAL_H__
26#define __THERMAL_H__
27
28#include <linux/idr.h>
29#include <linux/device.h>
Matthew Garrettb1569e92008-12-03 17:55:32 +000030#include <linux/workqueue.h>
Zhang Rui203d3d42008-01-17 15:51:08 +080031
Durgadoss R23064082012-09-18 11:04:52 +053032#define THERMAL_TRIPS_NONE -1
33#define THERMAL_MAX_TRIPS 12
34#define THERMAL_NAME_LENGTH 20
35
36/* No upper/lower limit requirement */
37#define THERMAL_NO_LIMIT -1UL
38
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)
43
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"
48
Zhang Rui203d3d42008-01-17 15:51:08 +080049struct thermal_zone_device;
50struct thermal_cooling_device;
51
Matthew Garrett6503e5d2008-11-27 17:48:13 +000052enum thermal_device_mode {
53 THERMAL_DEVICE_DISABLED = 0,
54 THERMAL_DEVICE_ENABLED,
55};
56
57enum thermal_trip_type {
58 THERMAL_TRIP_ACTIVE = 0,
59 THERMAL_TRIP_PASSIVE,
60 THERMAL_TRIP_HOT,
61 THERMAL_TRIP_CRITICAL,
62};
63
Zhang Rui601f3d42012-06-27 09:54:33 +080064enum thermal_trend {
65 THERMAL_TREND_STABLE, /* temperature is stable */
66 THERMAL_TREND_RAISING, /* temperature is raising */
67 THERMAL_TREND_DROPPING, /* temperature is dropping */
68};
69
Durgadoss R23064082012-09-18 11:04:52 +053070/* Events supported by Thermal Netlink */
71enum events {
72 THERMAL_AUX0,
73 THERMAL_AUX1,
74 THERMAL_CRITICAL,
75 THERMAL_DEV_FAULT,
76};
77
78/* attributes of thermal_genl_family */
79enum {
80 THERMAL_GENL_ATTR_UNSPEC,
81 THERMAL_GENL_ATTR_EVENT,
82 __THERMAL_GENL_ATTR_MAX,
83};
84#define THERMAL_GENL_ATTR_MAX (__THERMAL_GENL_ATTR_MAX - 1)
85
86/* commands supported by the thermal_genl_family */
87enum {
88 THERMAL_GENL_CMD_UNSPEC,
89 THERMAL_GENL_CMD_EVENT,
90 __THERMAL_GENL_CMD_MAX,
91};
92#define THERMAL_GENL_CMD_MAX (__THERMAL_GENL_CMD_MAX - 1)
93
Zhang Rui203d3d42008-01-17 15:51:08 +080094struct thermal_zone_device_ops {
95 int (*bind) (struct thermal_zone_device *,
96 struct thermal_cooling_device *);
97 int (*unbind) (struct thermal_zone_device *,
98 struct thermal_cooling_device *);
Matthew Garrett6503e5d2008-11-27 17:48:13 +000099 int (*get_temp) (struct thermal_zone_device *, unsigned long *);
100 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 *);
106 int (*get_trip_temp) (struct thermal_zone_device *, int,
107 unsigned long *);
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800108 int (*set_trip_temp) (struct thermal_zone_device *, int,
109 unsigned long);
Durgadoss R27365a62012-07-25 10:10:59 +0800110 int (*get_trip_hyst) (struct thermal_zone_device *, int,
111 unsigned long *);
112 int (*set_trip_hyst) (struct thermal_zone_device *, int,
113 unsigned long);
Zhang, Rui9ec732f2008-04-10 16:13:10 +0800114 int (*get_crit_temp) (struct thermal_zone_device *, unsigned long *);
Zhang Rui601f3d42012-06-27 09:54:33 +0800115 int (*get_trend) (struct thermal_zone_device *, int,
116 enum thermal_trend *);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000117 int (*notify) (struct thermal_zone_device *, int,
118 enum thermal_trip_type);
Zhang Rui203d3d42008-01-17 15:51:08 +0800119};
120
121struct thermal_cooling_device_ops {
Matthew Garrett6503e5d2008-11-27 17:48:13 +0000122 int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
123 int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
124 int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);
Zhang Rui203d3d42008-01-17 15:51:08 +0800125};
126
Zhang Rui203d3d42008-01-17 15:51:08 +0800127struct thermal_cooling_device {
128 int id;
129 char type[THERMAL_NAME_LENGTH];
130 struct device device;
131 void *devdata;
Alan Cox5b275ce2010-11-11 15:27:29 +0000132 const struct thermal_cooling_device_ops *ops;
Zhang Ruice119f82012-06-27 14:13:04 +0800133 bool updated; /* true if the cooling device does not need update */
Zhang Ruif4a821c2012-07-24 16:56:21 +0800134 struct mutex lock; /* protect thermal_instances list */
Zhang Ruib5e4ae62012-06-27 14:11:52 +0800135 struct list_head thermal_instances;
Zhang Rui203d3d42008-01-17 15:51:08 +0800136 struct list_head node;
137};
138
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800139struct thermal_attr {
140 struct device_attribute attr;
141 char name[THERMAL_NAME_LENGTH];
142};
143
Zhang Rui203d3d42008-01-17 15:51:08 +0800144struct thermal_zone_device {
145 int id;
146 char type[THERMAL_NAME_LENGTH];
147 struct device device;
Durgadoss Rc56f5c02012-07-25 10:10:58 +0800148 struct thermal_attr *trip_temp_attrs;
149 struct thermal_attr *trip_type_attrs;
Durgadoss R27365a62012-07-25 10:10:59 +0800150 struct thermal_attr *trip_hyst_attrs;
Zhang Rui203d3d42008-01-17 15:51:08 +0800151 void *devdata;
152 int trips;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000153 int passive_delay;
154 int polling_delay;
Zhang Rui601f3d42012-06-27 09:54:33 +0800155 int temperature;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000156 int last_temperature;
Zhang Rui908b9fb2012-06-27 14:14:05 +0800157 int passive;
Matthew Garrett03a971a2008-12-03 18:00:38 +0000158 unsigned int forced_passive;
Alan Cox5b275ce2010-11-11 15:27:29 +0000159 const struct thermal_zone_device_ops *ops;
Durgadoss Ref873942012-09-18 11:04:55 +0530160 const struct thermal_zone_params *tzp;
Zhang Rui2d374132012-06-27 10:09:00 +0800161 struct list_head thermal_instances;
Zhang Rui203d3d42008-01-17 15:51:08 +0800162 struct idr idr;
Zhang Rui2d374132012-06-27 10:09:00 +0800163 struct mutex lock; /* protect thermal_instances list */
Zhang Rui203d3d42008-01-17 15:51:08 +0800164 struct list_head node;
Matthew Garrettb1569e92008-12-03 17:55:32 +0000165 struct delayed_work poll_queue;
Zhang Rui203d3d42008-01-17 15:51:08 +0800166};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530167
Durgadoss Ref873942012-09-18 11:04:55 +0530168/* Structure that holds binding parameters for a zone */
169struct thermal_bind_params {
170 struct thermal_cooling_device *cdev;
171
172 /*
173 * This is a measure of 'how effectively these devices can
174 * cool 'this' thermal zone. The shall be determined by platform
175 * characterization. This is on a 'percentage' scale.
176 * See Documentation/thermal/sysfs-api.txt for more information.
177 */
178 int weight;
179
180 /*
181 * This is a bit mask that gives the binding relation between this
182 * thermal zone and cdev, for a particular trip point.
183 * See Documentation/thermal/sysfs-api.txt for more information.
184 */
185 int trip_mask;
186 int (*match) (struct thermal_zone_device *tz,
187 struct thermal_cooling_device *cdev);
188};
189
190/* Structure to define Thermal Zone parameters */
191struct thermal_zone_params {
192 int num_tbps; /* Number of tbp entries */
193 struct thermal_bind_params *tbp;
194};
195
R.Durgadoss4cb18722010-10-27 03:33:29 +0530196struct thermal_genl_event {
197 u32 orig;
198 enum events event;
199};
R.Durgadoss4cb18722010-10-27 03:33:29 +0530200
Durgadoss R23064082012-09-18 11:04:52 +0530201/* Function declarations */
Anton Vorontsov4b1bf582012-07-31 04:39:30 -0700202struct thermal_zone_device *thermal_zone_device_register(const char *, int, int,
Durgadoss R50125a92012-09-18 11:04:56 +0530203 void *, const struct thermal_zone_device_ops *,
204 const struct thermal_zone_params *, int, int);
Zhang Rui203d3d42008-01-17 15:51:08 +0800205void thermal_zone_device_unregister(struct thermal_zone_device *);
206
207int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
Zhang Rui9d998422012-06-26 16:35:57 +0800208 struct thermal_cooling_device *,
209 unsigned long, unsigned long);
Zhang Rui203d3d42008-01-17 15:51:08 +0800210int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
211 struct thermal_cooling_device *);
Matthew Garrettb1569e92008-12-03 17:55:32 +0000212void thermal_zone_device_update(struct thermal_zone_device *);
Durgadoss R23064082012-09-18 11:04:52 +0530213
Zhang Rui203d3d42008-01-17 15:51:08 +0800214struct thermal_cooling_device *thermal_cooling_device_register(char *, void *,
Alan Cox5b275ce2010-11-11 15:27:29 +0000215 const struct thermal_cooling_device_ops *);
Zhang Rui203d3d42008-01-17 15:51:08 +0800216void thermal_cooling_device_unregister(struct thermal_cooling_device *);
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100217
Durgadoss R9b4298a2012-09-18 11:04:54 +0530218int get_tz_trend(struct thermal_zone_device *, int);
219struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
220 struct thermal_cooling_device *, int);
221
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100222#ifdef CONFIG_NET
Jean Delvare2d58d7e2011-11-04 10:31:04 +0100223extern int thermal_generate_netlink_event(u32 orig, enum events event);
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100224#else
Jean Delvare2d58d7e2011-11-04 10:31:04 +0100225static inline int thermal_generate_netlink_event(u32 orig, enum events event)
Rafael J. Wysockiaf062162011-03-01 01:12:19 +0100226{
227 return 0;
228}
229#endif
Zhang Rui203d3d42008-01-17 15:51:08 +0800230
Len Browna0dd25b2008-02-09 04:01:48 -0500231#endif /* __THERMAL_H__ */