[PATCH] i2c: Drop out-of-date, colliding ioctl definitions
[pandora-kernel.git] / include / linux / i2c.h
1 /* ------------------------------------------------------------------------- */
2 /*                                                                           */
3 /* i2c.h - definitions for the i2c-bus interface                             */
4 /*                                                                           */
5 /* ------------------------------------------------------------------------- */
6 /*   Copyright (C) 1995-2000 Simon G. Vogl
7
8     This program is free software; you can redistribute it and/or modify
9     it under the terms of the GNU General Public License as published by
10     the Free Software Foundation; either version 2 of the License, or
11     (at your option) any later version.
12
13     This program is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17
18     You should have received a copy of the GNU General Public License
19     along with this program; if not, write to the Free Software
20     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                */
21 /* ------------------------------------------------------------------------- */
22
23 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and
24    Frodo Looijaard <frodol@dds.nl> */
25
26 #ifndef _LINUX_I2C_H
27 #define _LINUX_I2C_H
28
29 #include <linux/module.h>
30 #include <linux/types.h>
31 #include <linux/i2c-id.h>
32 #include <linux/device.h>       /* for struct device */
33 #include <asm/semaphore.h>
34
35 /* --- For i2c-isa ---------------------------------------------------- */
36
37 extern void i2c_adapter_dev_release(struct device *dev);
38 extern struct device_driver i2c_adapter_driver;
39 extern struct class i2c_adapter_class;
40 extern struct bus_type i2c_bus_type;
41
42 /* --- General options ------------------------------------------------ */
43
44 struct i2c_msg;
45 struct i2c_algorithm;
46 struct i2c_adapter;
47 struct i2c_client;
48 struct i2c_driver;
49 union i2c_smbus_data;
50
51 /*
52  * The master routines are the ones normally used to transmit data to devices
53  * on a bus (or read from them). Apart from two basic transfer functions to 
54  * transmit one message at a time, a more complex version can be used to 
55  * transmit an arbitrary number of messages without interruption.
56  */
57 extern int i2c_master_send(struct i2c_client *,const char* ,int);
58 extern int i2c_master_recv(struct i2c_client *,char* ,int);
59
60 /* Transfer num messages.
61  */
62 extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num);
63
64 /*
65  * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor. 
66  * This is not tested/implemented yet and will change in the future.
67  */
68 extern int i2c_slave_send(struct i2c_client *,char*,int);
69 extern int i2c_slave_recv(struct i2c_client *,char*,int);
70
71
72
73 /* This is the very generalized SMBus access routine. You probably do not
74    want to use this, though; one of the functions below may be much easier,
75    and probably just as fast. 
76    Note that we use i2c_adapter here, because you do not need a specific
77    smbus adapter to call this function. */
78 extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr, 
79                            unsigned short flags,
80                            char read_write, u8 command, int size,
81                            union i2c_smbus_data * data);
82
83 /* Now follow the 'nice' access routines. These also document the calling
84    conventions of smbus_access. */
85
86 extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value);
87 extern s32 i2c_smbus_read_byte(struct i2c_client * client);
88 extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value);
89 extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command);
90 extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,
91                                      u8 command, u8 value);
92 extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);
93 extern s32 i2c_smbus_write_word_data(struct i2c_client * client,
94                                      u8 command, u16 value);
95 extern s32 i2c_smbus_write_block_data(struct i2c_client * client,
96                                       u8 command, u8 length,
97                                       u8 *values);
98 /* Returns the number of read bytes */
99 extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,
100                                          u8 command, u8 *values);
101
102 /*
103  * A driver is capable of handling one or more physical devices present on
104  * I2C adapters. This information is used to inform the driver of adapter
105  * events.
106  */
107
108 struct i2c_driver {
109         struct module *owner;
110         char name[32];
111         int id;
112         unsigned int class;
113         unsigned int flags;             /* div., see below              */
114
115         /* Notifies the driver that a new bus has appeared. This routine
116          * can be used by the driver to test if the bus meets its conditions
117          * & seek for the presence of the chip(s) it supports. If found, it 
118          * registers the client(s) that are on the bus to the i2c admin. via
119          * i2c_attach_client.
120          */
121         int (*attach_adapter)(struct i2c_adapter *);
122         int (*detach_adapter)(struct i2c_adapter *);
123
124         /* tells the driver that a client is about to be deleted & gives it 
125          * the chance to remove its private data. Also, if the client struct
126          * has been dynamically allocated by the driver in the function above,
127          * it must be freed here.
128          */
129         int (*detach_client)(struct i2c_client *);
130         
131         /* a ioctl like command that can be used to perform specific functions
132          * with the device.
133          */
134         int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
135
136         struct device_driver driver;
137         struct list_head list;
138 };
139 #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
140
141 #define I2C_NAME_SIZE   50
142
143 /*
144  * i2c_client identifies a single device (i.e. chip) that is connected to an 
145  * i2c bus. The behaviour is defined by the routines of the driver. This
146  * function is mainly used for lookup & other admin. functions.
147  */
148 struct i2c_client {
149         unsigned int flags;             /* div., see below              */
150         unsigned short addr;            /* chip address - NOTE: 7bit    */
151                                         /* addresses are stored in the  */
152                                         /* _LOWER_ 7 bits               */
153         struct i2c_adapter *adapter;    /* the adapter we sit on        */
154         struct i2c_driver *driver;      /* and our access routines      */
155         int usage_count;                /* How many accesses currently  */
156                                         /* to the client                */
157         struct device dev;              /* the device structure         */
158         struct list_head list;
159         char name[I2C_NAME_SIZE];
160         struct completion released;
161 };
162 #define to_i2c_client(d) container_of(d, struct i2c_client, dev)
163
164 static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
165 {
166         return to_i2c_client(container_of(kobj, struct device, kobj));
167 }
168
169 static inline void *i2c_get_clientdata (struct i2c_client *dev)
170 {
171         return dev_get_drvdata (&dev->dev);
172 }
173
174 static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
175 {
176         dev_set_drvdata (&dev->dev, data);
177 }
178
179 /*
180  * The following structs are for those who like to implement new bus drivers:
181  * i2c_algorithm is the interface to a class of hardware solutions which can
182  * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
183  * to name two of the most common.
184  */
185 struct i2c_algorithm {
186         /* If an adapter algorithm can't do I2C-level access, set master_xfer
187            to NULL. If an adapter algorithm can do SMBus access, set 
188            smbus_xfer. If set to NULL, the SMBus protocol is simulated
189            using common I2C messages */
190         int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs, 
191                            int num);
192         int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, 
193                            unsigned short flags, char read_write,
194                            u8 command, int size, union i2c_smbus_data * data);
195
196         /* --- these optional/future use for some adapter types.*/
197         int (*slave_send)(struct i2c_adapter *,char*,int);
198         int (*slave_recv)(struct i2c_adapter *,char*,int);
199
200         /* --- ioctl like call to set div. parameters. */
201         int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
202
203         /* To determine what the adapter supports */
204         u32 (*functionality) (struct i2c_adapter *);
205 };
206
207 /*
208  * i2c_adapter is the structure used to identify a physical i2c bus along
209  * with the access algorithms necessary to access it.
210  */
211 struct i2c_adapter {
212         struct module *owner;
213         unsigned int id;
214         unsigned int class;
215         struct i2c_algorithm *algo;/* the algorithm to access the bus   */
216         void *algo_data;
217
218         /* --- administration stuff. */
219         int (*client_register)(struct i2c_client *);
220         int (*client_unregister)(struct i2c_client *);
221
222         /* data fields that are valid for all devices   */
223         struct semaphore bus_lock;
224         struct semaphore clist_lock;
225
226         int timeout;
227         int retries;
228         struct device dev;              /* the adapter device */
229         struct class_device class_dev;  /* the class device */
230
231         int nr;
232         struct list_head clients;
233         struct list_head list;
234         char name[I2C_NAME_SIZE];
235         struct completion dev_released;
236         struct completion class_dev_released;
237 };
238 #define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
239 #define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev)
240
241 static inline void *i2c_get_adapdata (struct i2c_adapter *dev)
242 {
243         return dev_get_drvdata (&dev->dev);
244 }
245
246 static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data)
247 {
248         dev_set_drvdata (&dev->dev, data);
249 }
250
251 /*flags for the driver struct: */
252 #define I2C_DF_NOTIFY   0x01            /* notify on bus (de/a)ttaches  */
253 #if 0
254 /* this flag is gone -- there is a (optional) driver->detach_adapter
255  * callback now which can be used instead */
256 # define I2C_DF_DUMMY   0x02
257 #endif
258
259 /*flags for the client struct: */
260 #define I2C_CLIENT_ALLOW_USE            0x01    /* Client allows access */
261 #define I2C_CLIENT_ALLOW_MULTIPLE_USE   0x02    /* Allow multiple access-locks */
262                                                 /* on an i2c_client */
263 #define I2C_CLIENT_PEC  0x04                    /* Use Packet Error Checking */
264 #define I2C_CLIENT_TEN  0x10                    /* we have a ten bit chip address       */
265                                                 /* Must equal I2C_M_TEN below */
266
267 /* i2c adapter classes (bitmask) */
268 #define I2C_CLASS_HWMON         (1<<0)  /* lm_sensors, ... */
269 #define I2C_CLASS_TV_ANALOG     (1<<1)  /* bttv + friends */
270 #define I2C_CLASS_TV_DIGITAL    (1<<2)  /* dvb cards */
271 #define I2C_CLASS_DDC           (1<<3)  /* i2c-matroxfb ? */
272 #define I2C_CLASS_CAM_ANALOG    (1<<4)  /* camera with analog CCD */
273 #define I2C_CLASS_CAM_DIGITAL   (1<<5)  /* most webcams */
274 #define I2C_CLASS_SOUND         (1<<6)  /* sound devices */
275 #define I2C_CLASS_ALL           (UINT_MAX) /* all of the above */
276
277 /* i2c_client_address_data is the struct for holding default client
278  * addresses for a driver and for the parameters supplied on the
279  * command line
280  */
281 struct i2c_client_address_data {
282         unsigned short *normal_i2c;
283         unsigned short *probe;
284         unsigned short *ignore;
285         unsigned short **forces;
286 };
287
288 /* Internal numbers to terminate lists */
289 #define I2C_CLIENT_END          0xfffeU
290
291 /* The numbers to use to set I2C bus address */
292 #define ANY_I2C_BUS             0xffff
293 #define ANY_I2C_ISA_BUS         9191
294
295
296 /* ----- functions exported by i2c.o */
297
298 /* administration...
299  */
300 extern int i2c_add_adapter(struct i2c_adapter *);
301 extern int i2c_del_adapter(struct i2c_adapter *);
302
303 extern int i2c_add_driver(struct i2c_driver *);
304 extern int i2c_del_driver(struct i2c_driver *);
305
306 extern int i2c_attach_client(struct i2c_client *);
307 extern int i2c_detach_client(struct i2c_client *);
308
309 /* New function: This is to get an i2c_client-struct for controlling the 
310    client either by using i2c_control-function or having the 
311    client-module export functions that can be used with the i2c_client
312    -struct. */
313 extern struct i2c_client *i2c_get_client(int driver_id, int adapter_id, 
314                                         struct i2c_client *prev);
315
316 /* Should be used with new function
317    extern struct i2c_client *i2c_get_client(int,int,struct i2c_client *);
318    to make sure that client-struct is valid and that it is okay to access
319    the i2c-client. 
320    returns -EACCES if client doesn't allow use (default)
321    returns -EBUSY if client doesn't allow multiple use (default) and 
322    usage_count >0 */
323 extern int i2c_use_client(struct i2c_client *);
324 extern int i2c_release_client(struct i2c_client *);
325
326 /* call the i2c_client->command() of all attached clients with
327  * the given arguments */
328 extern void i2c_clients_command(struct i2c_adapter *adap,
329                                 unsigned int cmd, void *arg);
330
331 /* returns -EBUSY if address has been taken, 0 if not. Note that the only
332    other place at which this is called is within i2c_attach_client; so
333    you can cheat by simply not registering. Not recommended, of course! */
334 extern int i2c_check_addr (struct i2c_adapter *adapter, int addr);
335
336 /* Detect function. It iterates over all possible addresses itself.
337  * It will only call found_proc if some client is connected at the
338  * specific address (unless a 'force' matched);
339  */
340 extern int i2c_probe(struct i2c_adapter *adapter, 
341                 struct i2c_client_address_data *address_data,
342                 int (*found_proc) (struct i2c_adapter *, int, int));
343
344 /* An ioctl like call to set div. parameters of the adapter.
345  */
346 extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
347
348 extern struct i2c_adapter* i2c_get_adapter(int id);
349 extern void i2c_put_adapter(struct i2c_adapter *adap);
350
351
352 /* Return the functionality mask */
353 static inline u32 i2c_get_functionality(struct i2c_adapter *adap)
354 {
355         return adap->algo->functionality(adap);
356 }
357
358 /* Return 1 if adapter supports everything we need, 0 if not. */
359 static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func)
360 {
361         return (func & i2c_get_functionality(adap)) == func;
362 }
363
364 /* Return id number for a specific adapter */
365 static inline int i2c_adapter_id(struct i2c_adapter *adap)
366 {
367         return adap->nr;
368 }
369
370 /*
371  * I2C Message - used for pure i2c transaction, also from /dev interface
372  */
373 struct i2c_msg {
374         __u16 addr;     /* slave address                        */
375         __u16 flags;            
376 #define I2C_M_TEN       0x10    /* we have a ten bit chip address       */
377 #define I2C_M_RD        0x01
378 #define I2C_M_NOSTART   0x4000
379 #define I2C_M_REV_DIR_ADDR      0x2000
380 #define I2C_M_IGNORE_NAK        0x1000
381 #define I2C_M_NO_RD_ACK         0x0800
382         __u16 len;              /* msg length                           */
383         __u8 *buf;              /* pointer to msg data                  */
384 };
385
386 /* To determine what functionality is present */
387
388 #define I2C_FUNC_I2C                    0x00000001
389 #define I2C_FUNC_10BIT_ADDR             0x00000002
390 #define I2C_FUNC_PROTOCOL_MANGLING      0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */
391 #define I2C_FUNC_SMBUS_HWPEC_CALC       0x00000008 /* SMBus 2.0 */
392 #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC  0x00000800 /* SMBus 2.0 */ 
393 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ 
394 #define I2C_FUNC_SMBUS_PROC_CALL_PEC    0x00002000 /* SMBus 2.0 */
395 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */
396 #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL  0x00008000 /* SMBus 2.0 */
397 #define I2C_FUNC_SMBUS_QUICK            0x00010000 
398 #define I2C_FUNC_SMBUS_READ_BYTE        0x00020000 
399 #define I2C_FUNC_SMBUS_WRITE_BYTE       0x00040000 
400 #define I2C_FUNC_SMBUS_READ_BYTE_DATA   0x00080000 
401 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA  0x00100000 
402 #define I2C_FUNC_SMBUS_READ_WORD_DATA   0x00200000 
403 #define I2C_FUNC_SMBUS_WRITE_WORD_DATA  0x00400000 
404 #define I2C_FUNC_SMBUS_PROC_CALL        0x00800000 
405 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA  0x01000000 
406 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 
407 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK   0x04000000 /* I2C-like block xfer  */
408 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK  0x08000000 /* w/ 1-byte reg. addr. */
409 #define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2  0x10000000 /* I2C-like block xfer  */
410 #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */
411 #define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC  0x40000000 /* SMBus 2.0 */
412 #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */
413
414 #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
415                              I2C_FUNC_SMBUS_WRITE_BYTE)
416 #define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \
417                                   I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
418 #define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \
419                                   I2C_FUNC_SMBUS_WRITE_WORD_DATA)
420 #define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
421                                    I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
422 #define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
423                                   I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
424 #define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \
425                                     I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2)
426 #define I2C_FUNC_SMBUS_BLOCK_DATA_PEC (I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \
427                                        I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC)
428 #define I2C_FUNC_SMBUS_WORD_DATA_PEC  (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \
429                                        I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC)
430
431 #define I2C_FUNC_SMBUS_READ_BYTE_PEC            I2C_FUNC_SMBUS_READ_BYTE_DATA
432 #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC           I2C_FUNC_SMBUS_WRITE_BYTE_DATA
433 #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC       I2C_FUNC_SMBUS_READ_WORD_DATA
434 #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC      I2C_FUNC_SMBUS_WRITE_WORD_DATA
435 #define I2C_FUNC_SMBUS_BYTE_PEC                 I2C_FUNC_SMBUS_BYTE_DATA
436 #define I2C_FUNC_SMBUS_BYTE_DATA_PEC            I2C_FUNC_SMBUS_WORD_DATA
437
438 #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
439                              I2C_FUNC_SMBUS_BYTE | \
440                              I2C_FUNC_SMBUS_BYTE_DATA | \
441                              I2C_FUNC_SMBUS_WORD_DATA | \
442                              I2C_FUNC_SMBUS_PROC_CALL | \
443                              I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
444                              I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \
445                              I2C_FUNC_SMBUS_I2C_BLOCK)
446
447 /* 
448  * Data for SMBus Messages 
449  */
450 #define I2C_SMBUS_BLOCK_MAX     32      /* As specified in SMBus standard */    
451 #define I2C_SMBUS_I2C_BLOCK_MAX 32      /* Not specified but we use same structure */
452 union i2c_smbus_data {
453         __u8 byte;
454         __u16 word;
455         __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
456                                                     /* and one more for PEC */
457 };
458
459 /* smbus_access read or write markers */
460 #define I2C_SMBUS_READ  1
461 #define I2C_SMBUS_WRITE 0
462
463 /* SMBus transaction types (size parameter in the above functions) 
464    Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */
465 #define I2C_SMBUS_QUICK             0
466 #define I2C_SMBUS_BYTE              1
467 #define I2C_SMBUS_BYTE_DATA         2 
468 #define I2C_SMBUS_WORD_DATA         3
469 #define I2C_SMBUS_PROC_CALL         4
470 #define I2C_SMBUS_BLOCK_DATA        5
471 #define I2C_SMBUS_I2C_BLOCK_DATA    6
472 #define I2C_SMBUS_BLOCK_PROC_CALL   7           /* SMBus 2.0 */
473 #define I2C_SMBUS_BLOCK_DATA_PEC    8           /* SMBus 2.0 */
474 #define I2C_SMBUS_PROC_CALL_PEC     9           /* SMBus 2.0 */
475 #define I2C_SMBUS_BLOCK_PROC_CALL_PEC  10       /* SMBus 2.0 */
476 #define I2C_SMBUS_WORD_DATA_PEC    11           /* SMBus 2.0 */
477
478
479 /* ----- commands for the ioctl like i2c_command call:
480  * note that additional calls are defined in the algorithm and hw 
481  *      dependent layers - these can be listed here, or see the 
482  *      corresponding header files.
483  */
484                                 /* -> bit-adapter specific ioctls       */
485 #define I2C_RETRIES     0x0701  /* number of times a device address      */
486                                 /* should be polled when not            */
487                                 /* acknowledging                        */
488 #define I2C_TIMEOUT     0x0702  /* set timeout - call with int          */
489
490
491 /* this is for i2c-dev.c        */
492 #define I2C_SLAVE       0x0703  /* Change slave address                 */
493                                 /* Attn.: Slave address is 7 or 10 bits */
494 #define I2C_SLAVE_FORCE 0x0706  /* Change slave address                 */
495                                 /* Attn.: Slave address is 7 or 10 bits */
496                                 /* This changes the address, even if it */
497                                 /* is already taken!                    */
498 #define I2C_TENBIT      0x0704  /* 0 for 7 bit addrs, != 0 for 10 bit   */
499
500 #define I2C_FUNCS       0x0705  /* Get the adapter functionality */
501 #define I2C_RDWR        0x0707  /* Combined R/W transfer (one stop only)*/
502 #define I2C_PEC         0x0708  /* != 0 for SMBus PEC                   */
503
504 #define I2C_SMBUS       0x0720  /* SMBus-level access */
505
506 /* ----- I2C-DEV: char device interface stuff ------------------------- */
507
508 #define I2C_MAJOR       89              /* Device major number          */
509
510 /* These defines are used for probing i2c client addresses */
511 /* The length of the option lists */
512 #define I2C_CLIENT_MAX_OPTS 48
513
514 /* Default fill of many variables */
515 #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
516                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
517                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
518                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
519                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
520                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
521                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
522                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
523                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
524                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
525                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
526                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
527                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
528                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
529                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
530                           I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END}
531
532 /* I2C_CLIENT_MODULE_PARM creates a module parameter, and puts it in the
533    module header */
534
535 #define I2C_CLIENT_MODULE_PARM(var,desc) \
536   static unsigned short var[I2C_CLIENT_MAX_OPTS] = I2C_CLIENT_DEFAULTS; \
537   static unsigned int var##_num; \
538   module_param_array(var, short, &var##_num, 0); \
539   MODULE_PARM_DESC(var,desc)
540
541 #define I2C_CLIENT_MODULE_PARM_FORCE(name)                              \
542 I2C_CLIENT_MODULE_PARM(force_##name,                                    \
543                        "List of adapter,address pairs which are "       \
544                        "unquestionably assumed to contain a `"          \
545                        # name "' chip")
546
547
548 #define I2C_CLIENT_INSMOD_COMMON                                        \
549 I2C_CLIENT_MODULE_PARM(probe, "List of adapter,address pairs to scan "  \
550                        "additionally");                                 \
551 I2C_CLIENT_MODULE_PARM(ignore, "List of adapter,address pairs not to "  \
552                        "scan");                                         \
553 static struct i2c_client_address_data addr_data = {                     \
554         .normal_i2c     = normal_i2c,                                   \
555         .probe          = probe,                                        \
556         .ignore         = ignore,                                       \
557         .forces         = forces,                                       \
558 }
559
560 /* These are the ones you want to use in your own drivers. Pick the one
561    which matches the number of devices the driver differenciates between. */
562 #define I2C_CLIENT_INSMOD \
563   I2C_CLIENT_MODULE_PARM(force, \
564                       "List of adapter,address pairs to boldly assume " \
565                       "to be present"); \
566         static unsigned short *forces[] = {                             \
567                         force,                                          \
568                         NULL                                            \
569                 };                                                      \
570 I2C_CLIENT_INSMOD_COMMON
571
572 #define I2C_CLIENT_INSMOD_1(chip1)                                      \
573 enum chips { any_chip, chip1 };                                         \
574 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
575                        "boldly assume to be present");                  \
576 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
577 static unsigned short *forces[] = { force, force_##chip1, NULL };       \
578 I2C_CLIENT_INSMOD_COMMON
579
580 #define I2C_CLIENT_INSMOD_2(chip1, chip2)                               \
581 enum chips { any_chip, chip1, chip2 };                                  \
582 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
583                        "boldly assume to be present");                  \
584 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
585 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
586 static unsigned short *forces[] = { force, force_##chip1,               \
587                                     force_##chip2, NULL };              \
588 I2C_CLIENT_INSMOD_COMMON
589
590 #define I2C_CLIENT_INSMOD_3(chip1, chip2, chip3)                        \
591 enum chips { any_chip, chip1, chip2, chip3 };                           \
592 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
593                        "boldly assume to be present");                  \
594 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
595 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
596 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
597 static unsigned short *forces[] = { force, force_##chip1,               \
598                                     force_##chip2, force_##chip3,       \
599                                     NULL };                             \
600 I2C_CLIENT_INSMOD_COMMON
601
602 #define I2C_CLIENT_INSMOD_4(chip1, chip2, chip3, chip4)                 \
603 enum chips { any_chip, chip1, chip2, chip3, chip4 };                    \
604 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
605                        "boldly assume to be present");                  \
606 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
607 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
608 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
609 I2C_CLIENT_MODULE_PARM_FORCE(chip4);                                    \
610 static unsigned short *forces[] = { force, force_##chip1,               \
611                                     force_##chip2, force_##chip3,       \
612                                     force_##chip4, NULL};               \
613 I2C_CLIENT_INSMOD_COMMON
614
615 #define I2C_CLIENT_INSMOD_5(chip1, chip2, chip3, chip4, chip5)          \
616 enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 };             \
617 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
618                        "boldly assume to be present");                  \
619 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
620 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
621 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
622 I2C_CLIENT_MODULE_PARM_FORCE(chip4);                                    \
623 I2C_CLIENT_MODULE_PARM_FORCE(chip5);                                    \
624 static unsigned short *forces[] = { force, force_##chip1,               \
625                                     force_##chip2, force_##chip3,       \
626                                     force_##chip4, force_##chip5,       \
627                                     NULL };                             \
628 I2C_CLIENT_INSMOD_COMMON
629
630 #define I2C_CLIENT_INSMOD_6(chip1, chip2, chip3, chip4, chip5, chip6)   \
631 enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 };      \
632 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
633                        "boldly assume to be present");                  \
634 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
635 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
636 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
637 I2C_CLIENT_MODULE_PARM_FORCE(chip4);                                    \
638 I2C_CLIENT_MODULE_PARM_FORCE(chip5);                                    \
639 I2C_CLIENT_MODULE_PARM_FORCE(chip6);                                    \
640 static unsigned short *forces[] = { force, force_##chip1,               \
641                                     force_##chip2, force_##chip3,       \
642                                     force_##chip4, force_##chip5,       \
643                                     force_##chip6, NULL };              \
644 I2C_CLIENT_INSMOD_COMMON
645
646 #define I2C_CLIENT_INSMOD_7(chip1, chip2, chip3, chip4, chip5, chip6, chip7) \
647 enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6,        \
648              chip7 };                                                   \
649 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
650                        "boldly assume to be present");                  \
651 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
652 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
653 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
654 I2C_CLIENT_MODULE_PARM_FORCE(chip4);                                    \
655 I2C_CLIENT_MODULE_PARM_FORCE(chip5);                                    \
656 I2C_CLIENT_MODULE_PARM_FORCE(chip6);                                    \
657 I2C_CLIENT_MODULE_PARM_FORCE(chip7);                                    \
658 static unsigned short *forces[] = { force, force_##chip1,               \
659                                     force_##chip2, force_##chip3,       \
660                                     force_##chip4, force_##chip5,       \
661                                     force_##chip6, force_##chip7,       \
662                                     NULL };                             \
663 I2C_CLIENT_INSMOD_COMMON
664
665 #define I2C_CLIENT_INSMOD_8(chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8) \
666 enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6,        \
667              chip7, chip8 };                                            \
668 I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to "       \
669                        "boldly assume to be present");                  \
670 I2C_CLIENT_MODULE_PARM_FORCE(chip1);                                    \
671 I2C_CLIENT_MODULE_PARM_FORCE(chip2);                                    \
672 I2C_CLIENT_MODULE_PARM_FORCE(chip3);                                    \
673 I2C_CLIENT_MODULE_PARM_FORCE(chip4);                                    \
674 I2C_CLIENT_MODULE_PARM_FORCE(chip5);                                    \
675 I2C_CLIENT_MODULE_PARM_FORCE(chip6);                                    \
676 I2C_CLIENT_MODULE_PARM_FORCE(chip7);                                    \
677 I2C_CLIENT_MODULE_PARM_FORCE(chip8);                                    \
678 static unsigned short *forces[] = { force, force_##chip1,               \
679                                     force_##chip2, force_##chip3,       \
680                                     force_##chip4, force_##chip5,       \
681                                     force_##chip6, force_##chip7,       \
682                                     force_##chip8, NULL };              \
683 I2C_CLIENT_INSMOD_COMMON
684
685 #endif /* _LINUX_I2C_H */