aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/i2c/i2c-core.c17
-rw-r--r--include/linux/i2c.h51
2 files changed, 58 insertions, 10 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index f95b1b657618..5e58b5641a35 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1307,7 +1307,22 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1307} 1307}
1308EXPORT_SYMBOL(i2c_smbus_write_word_data); 1308EXPORT_SYMBOL(i2c_smbus_write_word_data);
1309 1309
1310/* Returns the number of read bytes */ 1310/**
1311 * i2c_smbus_read_block_data - SMBus block read request
1312 * @client: Handle to slave device
1313 * @command: Command byte issued to let the slave know what data should
1314 * be returned
1315 * @values: Byte array into which data will be read; big enough to hold
1316 * the data returned by the slave. SMBus allows at most 32 bytes.
1317 *
1318 * Returns the number of bytes read in the slave's response, else a
1319 * negative number to indicate some kind of error.
1320 *
1321 * Note that using this function requires that the client's adapter support
1322 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers
1323 * support this; its emulation through I2C messaging relies on a specific
1324 * mechanism (I2C_M_RECV_LEN) which may not be implemented.
1325 */
1311s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, 1326s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
1312 u8 *values) 1327 u8 *values)
1313{ 1328{
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index d4b63171d5d5..8fc4310f071b 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -443,19 +443,52 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
443} 443}
444#endif /* __KERNEL__ */ 444#endif /* __KERNEL__ */
445 445
446/* 446/**
447 * I2C Message - used for pure i2c transaction, also from /dev interface 447 * struct i2c_msg - an I2C transaction segment beginning with START
448 * @addr: Slave address, either seven or ten bits. When this is a ten
449 * bit address, I2C_M_TEN must be set in @flags and the adapter
450 * must support I2C_FUNC_10BIT_ADDR.
451 * @flags: I2C_M_RD is handled by all adapters. No other flags may be
452 * provided unless the adapter exported the relevant I2C_FUNC_*
453 * flags through i2c_check_functionality().
454 * @len: Number of data bytes in @buf being read from or written to the
455 * I2C slave address. For read transactions where I2C_M_RECV_LEN
456 * is set, the caller guarantees that this buffer can hold up to
457 * 32 bytes in addition to the initial length byte sent by the
458 * slave (plus, if used, the SMBus PEC); and this value will be
459 * incremented by the number of block data bytes received.
460 * @buf: The buffer into which data is read, or from which it's written.
461 *
462 * An i2c_msg is the low level representation of one segment of an I2C
463 * transaction. It is visible to drivers in the @i2c_transfer() procedure,
464 * to userspace from i2c-dev, and to I2C adapter drivers through the
465 * @i2c_adapter.@master_xfer() method.
466 *
467 * Except when I2C "protocol mangling" is used, all I2C adapters implement
468 * the standard rules for I2C transactions. Each transaction begins with a
469 * START. That is followed by the slave address, and a bit encoding read
470 * versus write. Then follow all the data bytes, possibly including a byte
471 * with SMBus PEC. The transfer terminates with a NAK, or when all those
472 * bytes have been transferred and ACKed. If this is the last message in a
473 * group, it is followed by a STOP. Otherwise it is followed by the next
474 * @i2c_msg transaction segment, beginning with a (repeated) START.
475 *
476 * Alternatively, when the adapter supports I2C_FUNC_PROTOCOL_MANGLING then
477 * passing certain @flags may have changed those standard protocol behaviors.
478 * Those flags are only for use with broken/nonconforming slaves, and with
479 * adapters which are known to support the specific mangling options they
480 * need (one or more of IGNORE_NAK, NO_RD_ACK, NOSTART, and REV_DIR_ADDR).
448 */ 481 */
449struct i2c_msg { 482struct i2c_msg {
450 __u16 addr; /* slave address */ 483 __u16 addr; /* slave address */
451 __u16 flags; 484 __u16 flags;
452#define I2C_M_TEN 0x10 /* we have a ten bit chip address */ 485#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
453#define I2C_M_RD 0x01 486#define I2C_M_RD 0x0001 /* read data, from slave to master */
454#define I2C_M_NOSTART 0x4000 487#define I2C_M_NOSTART 0x4000 /* if I2C_FUNC_PROTOCOL_MANGLING */
455#define I2C_M_REV_DIR_ADDR 0x2000 488#define I2C_M_REV_DIR_ADDR 0x2000 /* if I2C_FUNC_PROTOCOL_MANGLING */
456#define I2C_M_IGNORE_NAK 0x1000 489#define I2C_M_IGNORE_NAK 0x1000 /* if I2C_FUNC_PROTOCOL_MANGLING */
457#define I2C_M_NO_RD_ACK 0x0800 490#define I2C_M_NO_RD_ACK 0x0800 /* if I2C_FUNC_PROTOCOL_MANGLING */
458#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */ 491#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
459 __u16 len; /* msg length */ 492 __u16 len; /* msg length */
460 __u8 *buf; /* pointer to msg data */ 493 __u8 *buf; /* pointer to msg data */
461}; 494};