aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/i2c.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r--include/linux/i2c.h175
1 files changed, 93 insertions, 82 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 08be0d21864c..33a5992d4936 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -53,51 +53,62 @@ struct i2c_board_info;
53 * transmit one message at a time, a more complex version can be used to 53 * transmit one message at a time, a more complex version can be used to
54 * transmit an arbitrary number of messages without interruption. 54 * transmit an arbitrary number of messages without interruption.
55 */ 55 */
56extern int i2c_master_send(struct i2c_client *,const char* ,int); 56extern int i2c_master_send(struct i2c_client *client, const char *buf,
57extern int i2c_master_recv(struct i2c_client *,char* ,int); 57 int count);
58extern int i2c_master_recv(struct i2c_client *client, char *buf, int count);
58 59
59/* Transfer num messages. 60/* Transfer num messages.
60 */ 61 */
61extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); 62extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
62 63 int num);
63 64
64/* This is the very generalized SMBus access routine. You probably do not 65/* This is the very generalized SMBus access routine. You probably do not
65 want to use this, though; one of the functions below may be much easier, 66 want to use this, though; one of the functions below may be much easier,
66 and probably just as fast. 67 and probably just as fast.
67 Note that we use i2c_adapter here, because you do not need a specific 68 Note that we use i2c_adapter here, because you do not need a specific
68 smbus adapter to call this function. */ 69 smbus adapter to call this function. */
69extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr, 70extern s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
70 unsigned short flags, 71 unsigned short flags, char read_write, u8 command,
71 char read_write, u8 command, int size, 72 int size, union i2c_smbus_data *data);
72 union i2c_smbus_data * data);
73 73
74/* Now follow the 'nice' access routines. These also document the calling 74/* Now follow the 'nice' access routines. These also document the calling
75 conventions of i2c_smbus_xfer. */ 75 conventions of i2c_smbus_xfer. */
76 76
77extern s32 i2c_smbus_read_byte(struct i2c_client * client); 77extern s32 i2c_smbus_read_byte(struct i2c_client *client);
78extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); 78extern s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value);
79extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); 79extern s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command);
80extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, 80extern s32 i2c_smbus_write_byte_data(struct i2c_client *client,
81 u8 command, u8 value); 81 u8 command, u8 value);
82extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); 82extern s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command);
83extern s32 i2c_smbus_write_word_data(struct i2c_client * client, 83extern s32 i2c_smbus_write_word_data(struct i2c_client *client,
84 u8 command, u16 value); 84 u8 command, u16 value);
85/* Returns the number of read bytes */ 85/* Returns the number of read bytes */
86extern s32 i2c_smbus_read_block_data(struct i2c_client *client, 86extern s32 i2c_smbus_read_block_data(struct i2c_client *client,
87 u8 command, u8 *values); 87 u8 command, u8 *values);
88extern s32 i2c_smbus_write_block_data(struct i2c_client * client, 88extern s32 i2c_smbus_write_block_data(struct i2c_client *client,
89 u8 command, u8 length, 89 u8 command, u8 length, const u8 *values);
90 const u8 *values);
91/* Returns the number of read bytes */ 90/* Returns the number of read bytes */
92extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, 91extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client,
93 u8 command, u8 length, u8 *values); 92 u8 command, u8 length, u8 *values);
94extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client, 93extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
95 u8 command, u8 length, 94 u8 command, u8 length,
96 const u8 *values); 95 const u8 *values);
97 96
98/** 97/**
99 * struct i2c_driver - represent an I2C device driver 98 * struct i2c_driver - represent an I2C device driver
99 * @id: Unique driver ID (optional)
100 * @class: What kind of i2c device we instantiate (for detect) 100 * @class: What kind of i2c device we instantiate (for detect)
101 * @attach_adapter: Callback for bus addition (for legacy drivers)
102 * @detach_adapter: Callback for bus removal (for legacy drivers)
103 * @detach_client: Callback for device removal (for legacy drivers)
104 * @probe: Callback for device binding (new-style drivers)
105 * @remove: Callback for device unbinding (new-style drivers)
106 * @shutdown: Callback for device shutdown
107 * @suspend: Callback for device suspend
108 * @resume: Callback for device resume
109 * @command: Callback for bus-wide signaling (optional)
110 * @driver: Device driver model driver
111 * @id_table: List of I2C devices supported by this driver
101 * @detect: Callback for device detection 112 * @detect: Callback for device detection
102 * @address_data: The I2C addresses to probe, ignore or force (for detect) 113 * @address_data: The I2C addresses to probe, ignore or force (for detect)
103 * @clients: List of detected clients we created (for i2c-core use only) 114 * @clients: List of detected clients we created (for i2c-core use only)
@@ -157,7 +168,7 @@ struct i2c_driver {
157 /* a ioctl like command that can be used to perform specific functions 168 /* a ioctl like command that can be used to perform specific functions
158 * with the device. 169 * with the device.
159 */ 170 */
160 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg); 171 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
161 172
162 struct device_driver driver; 173 struct device_driver driver;
163 const struct i2c_device_id *id_table; 174 const struct i2c_device_id *id_table;
@@ -212,14 +223,14 @@ static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj)
212 return to_i2c_client(dev); 223 return to_i2c_client(dev);
213} 224}
214 225
215static inline void *i2c_get_clientdata (struct i2c_client *dev) 226static inline void *i2c_get_clientdata(const struct i2c_client *dev)
216{ 227{
217 return dev_get_drvdata (&dev->dev); 228 return dev_get_drvdata(&dev->dev);
218} 229}
219 230
220static inline void i2c_set_clientdata (struct i2c_client *dev, void *data) 231static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
221{ 232{
222 dev_set_drvdata (&dev->dev, data); 233 dev_set_drvdata(&dev->dev, data);
223} 234}
224 235
225/** 236/**
@@ -228,6 +239,7 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)
228 * @flags: to initialize i2c_client.flags 239 * @flags: to initialize i2c_client.flags
229 * @addr: stored in i2c_client.addr 240 * @addr: stored in i2c_client.addr
230 * @platform_data: stored in i2c_client.dev.platform_data 241 * @platform_data: stored in i2c_client.dev.platform_data
242 * @archdata: copied into i2c_client.dev.archdata
231 * @irq: stored in i2c_client.irq 243 * @irq: stored in i2c_client.irq
232 * 244 *
233 * I2C doesn't actually support hardware probing, although controllers and 245 * I2C doesn't actually support hardware probing, although controllers and
@@ -247,6 +259,7 @@ struct i2c_board_info {
247 unsigned short flags; 259 unsigned short flags;
248 unsigned short addr; 260 unsigned short addr;
249 void *platform_data; 261 void *platform_data;
262 struct dev_archdata *archdata;
250 int irq; 263 int irq;
251}; 264};
252 265
@@ -260,7 +273,7 @@ struct i2c_board_info {
260 * fields (such as associated irq, or device-specific platform_data) 273 * fields (such as associated irq, or device-specific platform_data)
261 * are provided using conventional syntax. 274 * are provided using conventional syntax.
262 */ 275 */
263#define I2C_BOARD_INFO(dev_type,dev_addr) \ 276#define I2C_BOARD_INFO(dev_type, dev_addr) \
264 .type = (dev_type), .addr = (dev_addr) 277 .type = (dev_type), .addr = (dev_addr)
265 278
266 279
@@ -294,10 +307,12 @@ extern void i2c_unregister_device(struct i2c_client *);
294 */ 307 */
295#ifdef CONFIG_I2C_BOARDINFO 308#ifdef CONFIG_I2C_BOARDINFO
296extern int 309extern int
297i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n); 310i2c_register_board_info(int busnum, struct i2c_board_info const *info,
311 unsigned n);
298#else 312#else
299static inline int 313static inline int
300i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n) 314i2c_register_board_info(int busnum, struct i2c_board_info const *info,
315 unsigned n)
301{ 316{
302 return 0; 317 return 0;
303} 318}
@@ -316,11 +331,11 @@ struct i2c_algorithm {
316 using common I2C messages */ 331 using common I2C messages */
317 /* master_xfer should return the number of messages successfully 332 /* master_xfer should return the number of messages successfully
318 processed, or a negative value on error */ 333 processed, or a negative value on error */
319 int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs, 334 int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
320 int num); 335 int num);
321 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, 336 int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
322 unsigned short flags, char read_write, 337 unsigned short flags, char read_write,
323 u8 command, int size, union i2c_smbus_data * data); 338 u8 command, int size, union i2c_smbus_data *data);
324 339
325 /* To determine what the adapter supports */ 340 /* To determine what the adapter supports */
326 u32 (*functionality) (struct i2c_adapter *); 341 u32 (*functionality) (struct i2c_adapter *);
@@ -333,7 +348,7 @@ struct i2c_algorithm {
333struct i2c_adapter { 348struct i2c_adapter {
334 struct module *owner; 349 struct module *owner;
335 unsigned int id; 350 unsigned int id;
336 unsigned int class; 351 unsigned int class; /* classes to allow probing for */
337 const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 352 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
338 void *algo_data; 353 void *algo_data;
339 354
@@ -357,14 +372,14 @@ struct i2c_adapter {
357}; 372};
358#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 373#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
359 374
360static inline void *i2c_get_adapdata (struct i2c_adapter *dev) 375static inline void *i2c_get_adapdata(const struct i2c_adapter *dev)
361{ 376{
362 return dev_get_drvdata (&dev->dev); 377 return dev_get_drvdata(&dev->dev);
363} 378}
364 379
365static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data) 380static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
366{ 381{
367 dev_set_drvdata (&dev->dev, data); 382 dev_set_drvdata(&dev->dev, data);
368} 383}
369 384
370/*flags for the client struct: */ 385/*flags for the client struct: */
@@ -437,7 +452,7 @@ extern int i2c_probe(struct i2c_adapter *adapter,
437 const struct i2c_client_address_data *address_data, 452 const struct i2c_client_address_data *address_data,
438 int (*found_proc) (struct i2c_adapter *, int, int)); 453 int (*found_proc) (struct i2c_adapter *, int, int));
439 454
440extern struct i2c_adapter* i2c_get_adapter(int id); 455extern struct i2c_adapter *i2c_get_adapter(int id);
441extern void i2c_put_adapter(struct i2c_adapter *adap); 456extern void i2c_put_adapter(struct i2c_adapter *adap);
442 457
443 458
@@ -453,7 +468,7 @@ static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func)
453 return (func & i2c_get_functionality(adap)) == func; 468 return (func & i2c_get_functionality(adap)) == func;
454} 469}
455 470
456/* Return id number for a specific adapter */ 471/* Return the adapter number for a specific adapter */
457static inline int i2c_adapter_id(struct i2c_adapter *adap) 472static inline int i2c_adapter_id(struct i2c_adapter *adap)
458{ 473{
459 return adap->nr; 474 return adap->nr;
@@ -514,7 +529,7 @@ struct i2c_msg {
514 529
515#define I2C_FUNC_I2C 0x00000001 530#define I2C_FUNC_I2C 0x00000001
516#define I2C_FUNC_10BIT_ADDR 0x00000002 531#define I2C_FUNC_10BIT_ADDR 0x00000002
517#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */ 532#define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_NOSTART etc. */
518#define I2C_FUNC_SMBUS_PEC 0x00000008 533#define I2C_FUNC_SMBUS_PEC 0x00000008
519#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */ 534#define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */
520#define I2C_FUNC_SMBUS_QUICK 0x00010000 535#define I2C_FUNC_SMBUS_QUICK 0x00010000
@@ -529,30 +544,26 @@ struct i2c_msg {
529#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 544#define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000
530#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */ 545#define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */
531#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */ 546#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */
532#define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */ 547
533#define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */ 548#define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \
534 549 I2C_FUNC_SMBUS_WRITE_BYTE)
535#define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ 550#define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \
536 I2C_FUNC_SMBUS_WRITE_BYTE) 551 I2C_FUNC_SMBUS_WRITE_BYTE_DATA)
537#define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \ 552#define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \
538 I2C_FUNC_SMBUS_WRITE_BYTE_DATA) 553 I2C_FUNC_SMBUS_WRITE_WORD_DATA)
539#define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \ 554#define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \
540 I2C_FUNC_SMBUS_WRITE_WORD_DATA) 555 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA)
541#define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \ 556#define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \
542 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) 557 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)
543#define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \ 558
544 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK) 559#define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \
545#define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \ 560 I2C_FUNC_SMBUS_BYTE | \
546 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2) 561 I2C_FUNC_SMBUS_BYTE_DATA | \
547 562 I2C_FUNC_SMBUS_WORD_DATA | \
548#define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \ 563 I2C_FUNC_SMBUS_PROC_CALL | \
549 I2C_FUNC_SMBUS_BYTE | \ 564 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
550 I2C_FUNC_SMBUS_BYTE_DATA | \ 565 I2C_FUNC_SMBUS_I2C_BLOCK | \
551 I2C_FUNC_SMBUS_WORD_DATA | \ 566 I2C_FUNC_SMBUS_PEC)
552 I2C_FUNC_SMBUS_PROC_CALL | \
553 I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \
554 I2C_FUNC_SMBUS_I2C_BLOCK | \
555 I2C_FUNC_SMBUS_PEC)
556 567
557/* 568/*
558 * Data for SMBus Messages 569 * Data for SMBus Messages
@@ -562,7 +573,7 @@ union i2c_smbus_data {
562 __u8 byte; 573 __u8 byte;
563 __u16 word; 574 __u16 word;
564 __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */ 575 __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
565 /* and one more for user-space compatibility */ 576 /* and one more for user-space compatibility */
566}; 577};
567 578
568/* i2c_smbus_xfer read or write markers */ 579/* i2c_smbus_xfer read or write markers */
@@ -590,21 +601,21 @@ union i2c_smbus_data {
590 601
591/* Default fill of many variables */ 602/* Default fill of many variables */
592#define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 603#define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
593 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 604 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
594 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 605 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
595 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 606 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
596 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 607 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
597 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 608 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
598 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 609 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
599 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 610 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
600 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 611 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
601 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 612 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
602 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 613 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
603 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 614 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
604 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 615 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
605 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 616 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
606 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ 617 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \
607 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END} 618 I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END}
608 619
609/* I2C_CLIENT_MODULE_PARM creates a module parameter, and puts it in the 620/* I2C_CLIENT_MODULE_PARM creates a module parameter, and puts it in the
610 module header */ 621 module header */
@@ -613,7 +624,7 @@ union i2c_smbus_data {
613 static unsigned short var[I2C_CLIENT_MAX_OPTS] = I2C_CLIENT_DEFAULTS; \ 624 static unsigned short var[I2C_CLIENT_MAX_OPTS] = I2C_CLIENT_DEFAULTS; \
614 static unsigned int var##_num; \ 625 static unsigned int var##_num; \
615 module_param_array(var, short, &var##_num, 0); \ 626 module_param_array(var, short, &var##_num, 0); \
616 MODULE_PARM_DESC(var,desc) 627 MODULE_PARM_DESC(var, desc)
617 628
618#define I2C_CLIENT_MODULE_PARM_FORCE(name) \ 629#define I2C_CLIENT_MODULE_PARM_FORCE(name) \
619I2C_CLIENT_MODULE_PARM(force_##name, \ 630I2C_CLIENT_MODULE_PARM(force_##name, \