ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / 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 or ISA address space filled
31    fails.
32    probe: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
33      A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
34      the ISA bus, -1 for any I2C bus), the second is the address. 
35    kind: The kind of chip. 0 equals any chip.
36 */
37 struct i2c_force_data {
38         unsigned short *force;
39         unsigned short kind;
40 };
41
42 /* A structure containing the detect information.
43    normal_i2c: filled in by the module writer. Terminated by I2C_CLIENT_ISA_END.
44      A list of I2C addresses which should normally be examined.
45    normal_i2c_range: filled in by the module writer. Terminated by 
46      I2C_CLIENT_ISA_END
47      A list of pairs of I2C addresses, each pair being an inclusive range of
48      addresses which should normally be examined.
49    normal_isa: filled in by the module writer. Terminated by SENSORS_ISA_END.
50      A list of ISA addresses which should normally be examined.
51    normal_isa_range: filled in by the module writer. Terminated by 
52      SENSORS_ISA_END
53      A list of triples. The first two elements are ISA addresses, being an
54      range of addresses which should normally be examined. The third is the
55      modulo parameter: only addresses which are 0 module this value relative
56      to the first address of the range are actually considered.
57    probe: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
58      A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
59      the ISA bus, -1 for any I2C bus), the second is the address. These
60      addresses are also probed, as if they were in the 'normal' list.
61    probe_range: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END 
62      values.
63      A list of triples. The first value is a bus number (ANY_I2C_ISA_BUS for
64      the ISA bus, -1 for any I2C bus), the second and third are addresses. 
65      These form an inclusive range of addresses that are also probed, as
66      if they were in the 'normal' list.
67    ignore: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END values.
68      A list of pairs. The first value is a bus number (ANY_I2C_ISA_BUS for
69      the ISA bus, -1 for any I2C bus), the second is the I2C address. These
70      addresses are never probed. This parameter overrules 'normal' and 
71      'probe', but not the 'force' lists.
72    ignore_range: insmod parameter. Initialize this list with I2C_CLIENT_ISA_END 
73       values.
74      A list of triples. The first value is a bus number (ANY_I2C_ISA_BUS for
75      the ISA bus, -1 for any I2C bus), the second and third are addresses. 
76      These form an inclusive range of I2C addresses that are never probed.
77      This parameter overrules 'normal' and 'probe', but not the 'force' lists.
78    force_data: insmod parameters. A list, ending with an element of which
79      the force field is NULL.
80 */
81 struct i2c_address_data {
82         unsigned short *normal_i2c;
83         unsigned short *normal_i2c_range;
84         unsigned int *normal_isa;
85         unsigned int *normal_isa_range;
86         unsigned short *probe;
87         unsigned short *probe_range;
88         unsigned short *ignore;
89         unsigned short *ignore_range;
90         struct i2c_force_data *forces;
91 };
92
93 #define SENSORS_MODULE_PARM_FORCE(name) \
94   I2C_CLIENT_MODULE_PARM(force_ ## name, \
95                       "List of adapter,address pairs which are unquestionably" \
96                       " assumed to contain a `" # name "' chip")
97
98
99 /* This defines several insmod variables, and the addr_data structure */
100 #define SENSORS_INSMOD \
101   I2C_CLIENT_MODULE_PARM(probe, \
102                       "List of adapter,address pairs to scan additionally"); \
103   I2C_CLIENT_MODULE_PARM(probe_range, \
104                       "List of adapter,start-addr,end-addr triples to scan " \
105                       "additionally"); \
106   I2C_CLIENT_MODULE_PARM(ignore, \
107                       "List of adapter,address pairs not to scan"); \
108   I2C_CLIENT_MODULE_PARM(ignore_range, \
109                       "List of adapter,start-addr,end-addr triples not to " \
110                       "scan"); \
111         static struct i2c_address_data addr_data = {                    \
112                         .normal_i2c =           normal_i2c,             \
113                         .normal_i2c_range =     normal_i2c_range,       \
114                         .normal_isa =           normal_isa,             \
115                         .normal_isa_range =     normal_isa_range,       \
116                         .probe =                probe,                  \
117                         .probe_range =          probe_range,            \
118                         .ignore =               ignore,                 \
119                         .ignore_range =         ignore_range,           \
120                         .forces =               forces,                 \
121                 }
122
123 /* The following functions create an enum with the chip names as elements. 
124    The first element of the enum is any_chip. These are the only macros
125    a module will want to use. */
126
127 #define SENSORS_INSMOD_0 \
128   enum chips { any_chip }; \
129   I2C_CLIENT_MODULE_PARM(force, \
130                       "List of adapter,address pairs to boldly assume " \
131                       "to be present"); \
132   static struct i2c_force_data forces[] = {{force,any_chip},{NULL}}; \
133   SENSORS_INSMOD
134
135 #define SENSORS_INSMOD_1(chip1) \
136   enum chips { any_chip, chip1 }; \
137   I2C_CLIENT_MODULE_PARM(force, \
138                       "List of adapter,address pairs to boldly assume " \
139                       "to be present"); \
140   SENSORS_MODULE_PARM_FORCE(chip1); \
141   static struct i2c_force_data forces[] = {{force,any_chip},\
142                                                  {force_ ## chip1,chip1}, \
143                                                  {NULL}}; \
144   SENSORS_INSMOD
145
146 #define SENSORS_INSMOD_2(chip1,chip2) \
147   enum chips { any_chip, chip1, chip2 }; \
148   I2C_CLIENT_MODULE_PARM(force, \
149                       "List of adapter,address pairs to boldly assume " \
150                       "to be present"); \
151   SENSORS_MODULE_PARM_FORCE(chip1); \
152   SENSORS_MODULE_PARM_FORCE(chip2); \
153   static struct i2c_force_data forces[] = {{force,any_chip}, \
154                                                  {force_ ## chip1,chip1}, \
155                                                  {force_ ## chip2,chip2}, \
156                                                  {NULL}}; \
157   SENSORS_INSMOD
158
159 #define SENSORS_INSMOD_3(chip1,chip2,chip3) \
160   enum chips { any_chip, chip1, chip2, chip3 }; \
161   I2C_CLIENT_MODULE_PARM(force, \
162                       "List of adapter,address pairs to boldly assume " \
163                       "to be present"); \
164   SENSORS_MODULE_PARM_FORCE(chip1); \
165   SENSORS_MODULE_PARM_FORCE(chip2); \
166   SENSORS_MODULE_PARM_FORCE(chip3); \
167   static struct i2c_force_data forces[] = {{force,any_chip}, \
168                                                  {force_ ## chip1,chip1}, \
169                                                  {force_ ## chip2,chip2}, \
170                                                  {force_ ## chip3,chip3}, \
171                                                  {NULL}}; \
172   SENSORS_INSMOD
173
174 #define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
175   enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
176   I2C_CLIENT_MODULE_PARM(force, \
177                       "List of adapter,address pairs to boldly assume " \
178                       "to be present"); \
179   SENSORS_MODULE_PARM_FORCE(chip1); \
180   SENSORS_MODULE_PARM_FORCE(chip2); \
181   SENSORS_MODULE_PARM_FORCE(chip3); \
182   SENSORS_MODULE_PARM_FORCE(chip4); \
183   static struct i2c_force_data forces[] = {{force,any_chip}, \
184                                                  {force_ ## chip1,chip1}, \
185                                                  {force_ ## chip2,chip2}, \
186                                                  {force_ ## chip3,chip3}, \
187                                                  {force_ ## chip4,chip4}, \
188                                                  {NULL}}; \
189   SENSORS_INSMOD
190
191 #define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
192   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
193   I2C_CLIENT_MODULE_PARM(force, \
194                       "List of adapter,address pairs to boldly assume " \
195                       "to be present"); \
196   SENSORS_MODULE_PARM_FORCE(chip1); \
197   SENSORS_MODULE_PARM_FORCE(chip2); \
198   SENSORS_MODULE_PARM_FORCE(chip3); \
199   SENSORS_MODULE_PARM_FORCE(chip4); \
200   SENSORS_MODULE_PARM_FORCE(chip5); \
201   static struct i2c_force_data forces[] = {{force,any_chip}, \
202                                                  {force_ ## chip1,chip1}, \
203                                                  {force_ ## chip2,chip2}, \
204                                                  {force_ ## chip3,chip3}, \
205                                                  {force_ ## chip4,chip4}, \
206                                                  {force_ ## chip5,chip5}, \
207                                                  {NULL}}; \
208   SENSORS_INSMOD
209
210 #define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
211   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
212   I2C_CLIENT_MODULE_PARM(force, \
213                       "List of adapter,address pairs to boldly assume " \
214                       "to be present"); \
215   SENSORS_MODULE_PARM_FORCE(chip1); \
216   SENSORS_MODULE_PARM_FORCE(chip2); \
217   SENSORS_MODULE_PARM_FORCE(chip3); \
218   SENSORS_MODULE_PARM_FORCE(chip4); \
219   SENSORS_MODULE_PARM_FORCE(chip5); \
220   SENSORS_MODULE_PARM_FORCE(chip6); \
221   static struct i2c_force_data forces[] = {{force,any_chip}, \
222                                                  {force_ ## chip1,chip1}, \
223                                                  {force_ ## chip2,chip2}, \
224                                                  {force_ ## chip3,chip3}, \
225                                                  {force_ ## chip4,chip4}, \
226                                                  {force_ ## chip5,chip5}, \
227                                                  {force_ ## chip6,chip6}, \
228                                                  {NULL}}; \
229   SENSORS_INSMOD
230
231 #define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
232   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
233   I2C_CLIENT_MODULE_PARM(force, \
234                       "List of adapter,address pairs to boldly assume " \
235                       "to be present"); \
236   SENSORS_MODULE_PARM_FORCE(chip1); \
237   SENSORS_MODULE_PARM_FORCE(chip2); \
238   SENSORS_MODULE_PARM_FORCE(chip3); \
239   SENSORS_MODULE_PARM_FORCE(chip4); \
240   SENSORS_MODULE_PARM_FORCE(chip5); \
241   SENSORS_MODULE_PARM_FORCE(chip6); \
242   SENSORS_MODULE_PARM_FORCE(chip7); \
243   static struct i2c_force_data forces[] = {{force,any_chip}, \
244                                                  {force_ ## chip1,chip1}, \
245                                                  {force_ ## chip2,chip2}, \
246                                                  {force_ ## chip3,chip3}, \
247                                                  {force_ ## chip4,chip4}, \
248                                                  {force_ ## chip5,chip5}, \
249                                                  {force_ ## chip6,chip6}, \
250                                                  {force_ ## chip7,chip7}, \
251                                                  {NULL}}; \
252   SENSORS_INSMOD
253
254 #define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
255   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
256   I2C_CLIENT_MODULE_PARM(force, \
257                       "List of adapter,address pairs to boldly assume " \
258                       "to be present"); \
259   SENSORS_MODULE_PARM_FORCE(chip1); \
260   SENSORS_MODULE_PARM_FORCE(chip2); \
261   SENSORS_MODULE_PARM_FORCE(chip3); \
262   SENSORS_MODULE_PARM_FORCE(chip4); \
263   SENSORS_MODULE_PARM_FORCE(chip5); \
264   SENSORS_MODULE_PARM_FORCE(chip6); \
265   SENSORS_MODULE_PARM_FORCE(chip7); \
266   SENSORS_MODULE_PARM_FORCE(chip8); \
267   static struct i2c_force_data forces[] = {{force,any_chip}, \
268                                                  {force_ ## chip1,chip1}, \
269                                                  {force_ ## chip2,chip2}, \
270                                                  {force_ ## chip3,chip3}, \
271                                                  {force_ ## chip4,chip4}, \
272                                                  {force_ ## chip5,chip5}, \
273                                                  {force_ ## chip6,chip6}, \
274                                                  {force_ ## chip7,chip7}, \
275                                                  {force_ ## chip8,chip8}, \
276                                                  {NULL}}; \
277   SENSORS_INSMOD
278
279 /* Detect function. It iterates over all possible addresses itself. For
280    SMBus addresses, it will only call found_proc if some client is connected
281    to the SMBus (unless a 'force' matched); for ISA detections, this is not
282    done. */
283 extern int i2c_detect(struct i2c_adapter *adapter,
284                       struct i2c_address_data *address_data,
285                       int (*found_proc) (struct i2c_adapter *, int, int));
286
287
288 /* This macro is used to scale user-input to sensible values in almost all
289    chip drivers. */
290 static inline int SENSORS_LIMIT(long value, long low, long high)
291 {
292         if (value < low)
293                 return low;
294         else if (value > high)
295                 return high;
296         else
297                 return value;
298 }
299 #endif                          /* def _LINUX_I2C_SENSOR_H */