]> Pileus Git - ~andy/linux/blob - include/linux/i2c-sensor.h
[PATCH] hwmon: hwmon vs i2c, second round (02/11)
[~andy/linux] / 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 the detect information.
26    normal_i2c: filled in by the module writer. Terminated by I2C_CLIENT_END.
27      A list of I2C addresses which should normally be examined.
28    probe: insmod parameter. Initialize this list with I2C_CLIENT_END values.
29      A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
30      I2C bus), the second is the address. These addresses are also probed,
31      as if they were in the 'normal' list.
32    ignore: insmod parameter. Initialize this list with I2C_CLIENT_END values.
33      A list of pairs. The first value is a bus number (ANY_I2C_BUS for any
34      I2C bus), the second is the I2C address. These addresses are never
35      probed. This parameter overrules 'normal' and  probe', but not the
36     'force' lists.
37    forces: insmod parameters. A list, ending with a NULL element.
38      Force variables overrule all other variables; they force a detection on
39      that place. If a specific chip is given, the module blindly assumes this
40      chip type is present; if a general force (kind == 0) is given, the module
41      will still try to figure out what type of chip is present. This is useful
42      if for some reasons the detect for SMBus address space filled fails.
43 */
44 struct i2c_address_data {
45         unsigned short *normal_i2c;
46         unsigned short *probe;
47         unsigned short *ignore;
48         unsigned short **forces;
49 };
50
51 #define SENSORS_MODULE_PARM_FORCE(name) \
52   I2C_CLIENT_MODULE_PARM(force_ ## name, \
53                       "List of adapter,address pairs which are unquestionably" \
54                       " assumed to contain a `" # name "' chip")
55
56
57 /* This defines several insmod variables, and the addr_data structure */
58 #define SENSORS_INSMOD \
59   I2C_CLIENT_MODULE_PARM(probe, \
60                       "List of adapter,address pairs to scan additionally"); \
61   I2C_CLIENT_MODULE_PARM(ignore, \
62                       "List of adapter,address pairs not to scan"); \
63         static struct i2c_address_data addr_data = {                    \
64                         .normal_i2c =           normal_i2c,             \
65                         .probe =                probe,                  \
66                         .ignore =               ignore,                 \
67                         .forces =               forces,                 \
68                 }
69
70 /* The following functions create an enum with the chip names as elements. 
71    The first element of the enum is any_chip. These are the only macros
72    a module will want to use. */
73
74 #define SENSORS_INSMOD_0 \
75   enum chips { any_chip }; \
76   I2C_CLIENT_MODULE_PARM(force, \
77                       "List of adapter,address pairs to boldly assume " \
78                       "to be present"); \
79   static unsigned short *forces[] = { force, \
80                                       NULL }; \
81   SENSORS_INSMOD
82
83 #define SENSORS_INSMOD_1(chip1) \
84   enum chips { any_chip, chip1 }; \
85   I2C_CLIENT_MODULE_PARM(force, \
86                       "List of adapter,address pairs to boldly assume " \
87                       "to be present"); \
88   SENSORS_MODULE_PARM_FORCE(chip1); \
89   static unsigned short *forces[] = { force, \
90                                       force_##chip1, \
91                                       NULL }; \
92   SENSORS_INSMOD
93
94 #define SENSORS_INSMOD_2(chip1,chip2) \
95   enum chips { any_chip, chip1, chip2 }; \
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   SENSORS_MODULE_PARM_FORCE(chip2); \
101   static unsigned short *forces[] = { force, \
102                                       force_##chip1, \
103                                       force_##chip2, \
104                                       NULL }; \
105   SENSORS_INSMOD
106
107 #define SENSORS_INSMOD_3(chip1,chip2,chip3) \
108   enum chips { any_chip, chip1, chip2, chip3 }; \
109   I2C_CLIENT_MODULE_PARM(force, \
110                       "List of adapter,address pairs to boldly assume " \
111                       "to be present"); \
112   SENSORS_MODULE_PARM_FORCE(chip1); \
113   SENSORS_MODULE_PARM_FORCE(chip2); \
114   SENSORS_MODULE_PARM_FORCE(chip3); \
115   static unsigned short *forces[] = { force, \
116                                       force_##chip1, \
117                                       force_##chip2, \
118                                       force_##chip3, \
119                                       NULL }; \
120   SENSORS_INSMOD
121
122 #define SENSORS_INSMOD_4(chip1,chip2,chip3,chip4) \
123   enum chips { any_chip, chip1, chip2, chip3, chip4 }; \
124   I2C_CLIENT_MODULE_PARM(force, \
125                       "List of adapter,address pairs to boldly assume " \
126                       "to be present"); \
127   SENSORS_MODULE_PARM_FORCE(chip1); \
128   SENSORS_MODULE_PARM_FORCE(chip2); \
129   SENSORS_MODULE_PARM_FORCE(chip3); \
130   SENSORS_MODULE_PARM_FORCE(chip4); \
131   static unsigned short *forces[] = { force, \
132                                       force_##chip1, \
133                                       force_##chip2, \
134                                       force_##chip3, \
135                                       force_##chip4, \
136                                       NULL}; \
137   SENSORS_INSMOD
138
139 #define SENSORS_INSMOD_5(chip1,chip2,chip3,chip4,chip5) \
140   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \
141   I2C_CLIENT_MODULE_PARM(force, \
142                       "List of adapter,address pairs to boldly assume " \
143                       "to be present"); \
144   SENSORS_MODULE_PARM_FORCE(chip1); \
145   SENSORS_MODULE_PARM_FORCE(chip2); \
146   SENSORS_MODULE_PARM_FORCE(chip3); \
147   SENSORS_MODULE_PARM_FORCE(chip4); \
148   SENSORS_MODULE_PARM_FORCE(chip5); \
149   static unsigned short *forces[] = { force, \
150                                       force_##chip1, \
151                                       force_##chip2, \
152                                       force_##chip3, \
153                                       force_##chip4, \
154                                       force_##chip5, \
155                                       NULL }; \
156   SENSORS_INSMOD
157
158 #define SENSORS_INSMOD_6(chip1,chip2,chip3,chip4,chip5,chip6) \
159   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \
160   I2C_CLIENT_MODULE_PARM(force, \
161                       "List of adapter,address pairs to boldly assume " \
162                       "to be present"); \
163   SENSORS_MODULE_PARM_FORCE(chip1); \
164   SENSORS_MODULE_PARM_FORCE(chip2); \
165   SENSORS_MODULE_PARM_FORCE(chip3); \
166   SENSORS_MODULE_PARM_FORCE(chip4); \
167   SENSORS_MODULE_PARM_FORCE(chip5); \
168   SENSORS_MODULE_PARM_FORCE(chip6); \
169   static unsigned short *forces[] = { force, \
170                                       force_##chip1, \
171                                       force_##chip2, \
172                                       force_##chip3, \
173                                       force_##chip4, \
174                                       force_##chip5, \
175                                       force_##chip6, \
176                                       NULL }; \
177   SENSORS_INSMOD
178
179 #define SENSORS_INSMOD_7(chip1,chip2,chip3,chip4,chip5,chip6,chip7) \
180   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7 }; \
181   I2C_CLIENT_MODULE_PARM(force, \
182                       "List of adapter,address pairs to boldly assume " \
183                       "to be present"); \
184   SENSORS_MODULE_PARM_FORCE(chip1); \
185   SENSORS_MODULE_PARM_FORCE(chip2); \
186   SENSORS_MODULE_PARM_FORCE(chip3); \
187   SENSORS_MODULE_PARM_FORCE(chip4); \
188   SENSORS_MODULE_PARM_FORCE(chip5); \
189   SENSORS_MODULE_PARM_FORCE(chip6); \
190   SENSORS_MODULE_PARM_FORCE(chip7); \
191   static unsigned short *forces[] = { force, \
192                                       force_##chip1, \
193                                       force_##chip2, \
194                                       force_##chip3, \
195                                       force_##chip4, \
196                                       force_##chip5, \
197                                       force_##chip6, \
198                                       force_##chip7, \
199                                       NULL }; \
200   SENSORS_INSMOD
201
202 #define SENSORS_INSMOD_8(chip1,chip2,chip3,chip4,chip5,chip6,chip7,chip8) \
203   enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8 }; \
204   I2C_CLIENT_MODULE_PARM(force, \
205                       "List of adapter,address pairs to boldly assume " \
206                       "to be present"); \
207   SENSORS_MODULE_PARM_FORCE(chip1); \
208   SENSORS_MODULE_PARM_FORCE(chip2); \
209   SENSORS_MODULE_PARM_FORCE(chip3); \
210   SENSORS_MODULE_PARM_FORCE(chip4); \
211   SENSORS_MODULE_PARM_FORCE(chip5); \
212   SENSORS_MODULE_PARM_FORCE(chip6); \
213   SENSORS_MODULE_PARM_FORCE(chip7); \
214   SENSORS_MODULE_PARM_FORCE(chip8); \
215   static unsigned short *forces[] = { force, \
216                                       force_##chip1, \
217                                       force_##chip2, \
218                                       force_##chip3, \
219                                       force_##chip4, \
220                                       force_##chip5, \
221                                       force_##chip6, \
222                                       force_##chip7, \
223                                       force_##chip8, \
224                                       NULL }; \
225   SENSORS_INSMOD
226
227 /* Detect function. It iterates over all possible addresses itself. For
228    SMBus addresses, it will only call found_proc if some client is connected
229    to the SMBus (unless a 'force' matched). */
230 extern int i2c_detect(struct i2c_adapter *adapter,
231                       struct i2c_address_data *address_data,
232                       int (*found_proc) (struct i2c_adapter *, int, int));
233
234 #endif                          /* def _LINUX_I2C_SENSOR_H */