]> err.no Git - linux-2.6/blob - include/linux/i2c-sensor.h
[PATCH] I2C: Separate non-i2c hwmon drivers from i2c-core (9/9)
[linux-2.6] / include / linux / i2c-sensor.h
1 /*
2     i2c-sensor.h - Part of the i2c package
3     was originally sensors.h - Part of lm_sensors, Linux kernel modules
4                                for hardware monitoring
5     Copyright (c) 1998, 1999  Frodo Looijaard <frodol@dds.nl>
6
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef _LINUX_I2C_SENSOR_H
23 #define _LINUX_I2C_SENSOR_H
24
25 /* A structure containing detect information.
26    Force variables overrule all other variables; they force a detection on
27    that place. If a specific chip is given, the module blindly assumes this
28    chip type is present; if a general force (kind == 0) is given, the module
29    will still try to figure out what type of chip is present. This is useful
30    if for some reasons the detect for SMBus address space filled fails.
31    probe: insmod parameter. Initialize this list with I2C_CLIENT_END values.
32      A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
33      I2C bus), the second is the address.
34    kind: The kind of chip. 0 equals any chip.
35 */
36 struct i2c_force_data {
37         unsigned short *force;
38         unsigned short kind;
39 };
40
41 /* A structure containing the detect information.
42    normal_i2c: filled in by the module writer. Terminated by I2C_CLIENT_END.
43      A list of I2C addresses which should normally be examined.
44    probe: insmod parameter. Initialize this list with I2C_CLIENT_END values.
45      A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
46      I2C bus), the second is the address. These addresses are also probed,
47      as if they were in the 'normal' list.
48    ignore: insmod parameter. Initialize this list with I2C_CLIENT_END values.
49      A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
50      I2C bus), the second is the I2C address. These addresses are never
51      probed. This parameter overrules 'normal' and  probe', but not the
52     'force' lists.
53    force_data: insmod parameters. A list, ending with an element of which
54      the force field is NULL.
55 */
56 struct i2c_address_data {
57         unsigned short *normal_i2c;
58         unsigned short *probe;
59         unsigned short *ignore;
60         struct i2c_force_data *forces;
61 };
62
63 #define SENSORS_MODULE_PARM_FORCE(name) \
64   I2C_CLIENT_MODULE_PARM(force_ ## name, \
65                       "List of adapter,address pairs which are unquestionably" \
66                       " assumed to contain a `" # name "' chip")
67
68
69 /* This defines several insmod variables, and the addr_data structure */
70 #define SENSORS_INSMOD \
71   I2C_CLIENT_MODULE_PARM(probe, \
72                       "List of adapter,address pairs to scan additionally"); \
73   I2C_CLIENT_MODULE_PARM(ignore, \
74                       "List of adapter,address pairs not to scan"); \
75         static struct i2c_address_data addr_data = {                    \
76                         .normal_i2c =           normal_i2c,             \
77                         .probe =                probe,                  \
78                         .ignore =               ignore,                 \
79                         .forces =               forces,                 \
80                 }
81
82 /* The following functions create an enum with the chip names as elements. 
83    The first element of the enum is any_chip. These are the only macros
84    a module will want to use. */
85
86 #define SENSORS_INSMOD_0 \
87   enum chips { any_chip }; \
88   I2C_CLIENT_MODULE_PARM(force, \
89                       "List of adapter,address pairs to boldly assume " \
90                       "to be present"); \
91   static struct i2c_force_data forces[] = {{force,any_chip},{NULL}}; \
92   SENSORS_INSMOD
93
94 #define SENSORS_INSMOD_1(chip1) \
95   enum chips { any_chip, chip1 }; \
96   I2C_CLIENT_MODULE_PARM(force, \
97                       "List of adapter,address pairs to boldly assume " \
98                       "to be present"); \
99   SENSORS_MODULE_PARM_FORCE(chip1); \
100   static struct i2c_force_data forces[] = {{force,any_chip},\
101                                                  {force_ ## chip1,chip1}, \
102                                                  {NULL}}; \
103   SENSORS_INSMOD
104
105 #define SENSORS_INSMOD_2(chip1,chip2) \
106   enum chips { any_chip, chip1, chip2 }; \
107   I2C_CLIENT_MODULE_PARM(force, \
108                       "List of adapter,address pairs to boldly assume " \
109                       "to be present"); \
110   SENSORS_MODULE_PARM_FORCE(chip1); \
111   SENSORS_MODULE_PARM_FORCE(chip2); \
112   static struct i2c_force_data forces[] = {{force,any_chip}, \
113                                                  {force_ ## chip1,chip1}, \
114                                                  {force_ ## chip2,chip2}, \
115                                                  {NULL}}; \
116   SENSORS_INSMOD
117
118 #define SENSORS_INSMOD_3(chip1,chip2,chip3) \
119   enum chips { any_chip, chip1, chip2, chip3 }; \
120   I2C_CLIENT_MODULE_PARM(force, \
121                       "List of adapter,address pairs to boldly assume " \
122                       "to be present"); \
123   SENSORS_MODULE_PARM_FORCE(chip1); \
124   SENSORS_MODULE_PARM_FORCE(chip2); \
125   SENSORS_MODULE_PARM_FORCE(chip3); \
126   static struct i2c_force_data forces[] = {{force,any_chip}, \
127                                                  {force_ ## chip1,chip1}, \
128                                                  {force_ ## chip2,chip2}, \
129                                                  {force_ ## chip3,chip3}, \
130                                                  {NULL}}; \
131   SENSORS_INSMOD
132
133 #define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
134   enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
135   I2C_CLIENT_MODULE_PARM(force, \
136                       "List of adapter,address pairs to boldly assume " \
137                       "to be present"); \
138   SENSORS_MODULE_PARM_FORCE(chip1); \
139   SENSORS_MODULE_PARM_FORCE(chip2); \
140   SENSORS_MODULE_PARM_FORCE(chip3); \
141   SENSORS_MODULE_PARM_FORCE(chip4); \
142   static struct i2c_force_data forces[] = {{force,any_chip}, \
143                                                  {force_ ## chip1,chip1}, \
144                                                  {force_ ## chip2,chip2}, \
145                                                  {force_ ## chip3,chip3}, \
146                                                  {force_ ## chip4,chip4}, \
147                                                  {NULL}}; \
148   SENSORS_INSMOD
149
150 #define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
151   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
152   I2C_CLIENT_MODULE_PARM(force, \
153                       "List of adapter,address pairs to boldly assume " \
154                       "to be present"); \
155   SENSORS_MODULE_PARM_FORCE(chip1); \
156   SENSORS_MODULE_PARM_FORCE(chip2); \
157   SENSORS_MODULE_PARM_FORCE(chip3); \
158   SENSORS_MODULE_PARM_FORCE(chip4); \
159   SENSORS_MODULE_PARM_FORCE(chip5); \
160   static struct i2c_force_data forces[] = {{force,any_chip}, \
161                                                  {force_ ## chip1,chip1}, \
162                                                  {force_ ## chip2,chip2}, \
163                                                  {force_ ## chip3,chip3}, \
164                                                  {force_ ## chip4,chip4}, \
165                                                  {force_ ## chip5,chip5}, \
166                                                  {NULL}}; \
167   SENSORS_INSMOD
168
169 #define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
170   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
171   I2C_CLIENT_MODULE_PARM(force, \
172                       "List of adapter,address pairs to boldly assume " \
173                       "to be present"); \
174   SENSORS_MODULE_PARM_FORCE(chip1); \
175   SENSORS_MODULE_PARM_FORCE(chip2); \
176   SENSORS_MODULE_PARM_FORCE(chip3); \
177   SENSORS_MODULE_PARM_FORCE(chip4); \
178   SENSORS_MODULE_PARM_FORCE(chip5); \
179   SENSORS_MODULE_PARM_FORCE(chip6); \
180   static struct i2c_force_data forces[] = {{force,any_chip}, \
181                                                  {force_ ## chip1,chip1}, \
182                                                  {force_ ## chip2,chip2}, \
183                                                  {force_ ## chip3,chip3}, \
184                                                  {force_ ## chip4,chip4}, \
185                                                  {force_ ## chip5,chip5}, \
186                                                  {force_ ## chip6,chip6}, \
187                                                  {NULL}}; \
188   SENSORS_INSMOD
189
190 #define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
191   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
192   I2C_CLIENT_MODULE_PARM(force, \
193                       "List of adapter,address pairs to boldly assume " \
194                       "to be present"); \
195   SENSORS_MODULE_PARM_FORCE(chip1); \
196   SENSORS_MODULE_PARM_FORCE(chip2); \
197   SENSORS_MODULE_PARM_FORCE(chip3); \
198   SENSORS_MODULE_PARM_FORCE(chip4); \
199   SENSORS_MODULE_PARM_FORCE(chip5); \
200   SENSORS_MODULE_PARM_FORCE(chip6); \
201   SENSORS_MODULE_PARM_FORCE(chip7); \
202   static struct i2c_force_data forces[] = {{force,any_chip}, \
203                                                  {force_ ## chip1,chip1}, \
204                                                  {force_ ## chip2,chip2}, \
205                                                  {force_ ## chip3,chip3}, \
206                                                  {force_ ## chip4,chip4}, \
207                                                  {force_ ## chip5,chip5}, \
208                                                  {force_ ## chip6,chip6}, \
209                                                  {force_ ## chip7,chip7}, \
210                                                  {NULL}}; \
211   SENSORS_INSMOD
212
213 #define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
214   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
215   I2C_CLIENT_MODULE_PARM(force, \
216                       "List of adapter,address pairs to boldly assume " \
217                       "to be present"); \
218   SENSORS_MODULE_PARM_FORCE(chip1); \
219   SENSORS_MODULE_PARM_FORCE(chip2); \
220   SENSORS_MODULE_PARM_FORCE(chip3); \
221   SENSORS_MODULE_PARM_FORCE(chip4); \
222   SENSORS_MODULE_PARM_FORCE(chip5); \
223   SENSORS_MODULE_PARM_FORCE(chip6); \
224   SENSORS_MODULE_PARM_FORCE(chip7); \
225   SENSORS_MODULE_PARM_FORCE(chip8); \
226   static struct i2c_force_data forces[] = {{force,any_chip}, \
227                                                  {force_ ## chip1,chip1}, \
228                                                  {force_ ## chip2,chip2}, \
229                                                  {force_ ## chip3,chip3}, \
230                                                  {force_ ## chip4,chip4}, \
231                                                  {force_ ## chip5,chip5}, \
232                                                  {force_ ## chip6,chip6}, \
233                                                  {force_ ## chip7,chip7}, \
234                                                  {force_ ## chip8,chip8}, \
235                                                  {NULL}}; \
236   SENSORS_INSMOD
237
238 /* Detect function. It iterates over all possible addresses itself. For
239    SMBus addresses, it will only call found_proc if some client is connected
240    to the SMBus (unless a 'force' matched). */
241 extern int i2c_detect(struct i2c_adapter *adapter,
242                       struct i2c_address_data *address_data,
243                       int (*found_proc) (struct i2c_adapter *, int, int));
244
245
246 /* This macro is used to scale user-input to sensible values in almost all
247    chip drivers. */
248 static inline int SENSORS_LIMIT(long value, long low, long high)
249 {
250         if (value < low)
251                 return low;
252         else if (value > high)
253                 return high;
254         else
255                 return value;
256 }
257 #endif                          /* def _LINUX_I2C_SENSOR_H */