~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/i2c.h

Version: ~ [ linux-5.0-rc7 ] ~ [ linux-4.20.12 ] ~ [ linux-4.19.25 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.103 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.160 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.176 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.136 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.63 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp