aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2008-07-14 16:38:24 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-07-14 16:38:24 -0400
commita1cdedac634eef81f747078bf1c27ad36ab13553 (patch)
treebad5345576651c91392d87d8673eeefd46ff88aa
parentae7193f7fa3e1735ab70807eb6e35a2a6575623f (diff)
i2c: Kerneldoc for most I/O calls
Provide kerneldoc for most of the I2C and SMBus I/O calls. Add a comment summarizing some fault reporting issues which affect the ability to provide clean fault reports through I2C master transfer calls. (Making it hard to precisely specify their return values...) Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r--drivers/i2c/i2c-core.c133
1 files changed, 124 insertions, 9 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3695a4a1ab77..527d51319f3c 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -945,10 +945,39 @@ module_exit(i2c_exit);
945 * ---------------------------------------------------- 945 * ----------------------------------------------------
946 */ 946 */
947 947
948/**
949 * i2c_transfer - execute a single or combined I2C message
950 * @adap: Handle to I2C bus
951 * @msgs: One or more messages to execute before STOP is issued to
952 * terminate the operation; each message begins with a START.
953 * @num: Number of messages to be executed.
954 *
955 * Returns negative errno, else the number of messages executed.
956 *
957 * Note that there is no requirement that each message be sent to
958 * the same slave address, although that is the most common model.
959 */
948int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) 960int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
949{ 961{
950 int ret; 962 int ret;
951 963
964 /* REVISIT the fault reporting model here is weak:
965 *
966 * - When we get an error after receiving N bytes from a slave,
967 * there is no way to report "N".
968 *
969 * - When we get a NAK after transmitting N bytes to a slave,
970 * there is no way to report "N" ... or to let the master
971 * continue executing the rest of this combined message, if
972 * that's the appropriate response.
973 *
974 * - When for example "num" is two and we successfully complete
975 * the first message but get an error part way through the
976 * second, it's unclear whether that should be reported as
977 * one (discarding status on the second message) or errno
978 * (discarding status on the first one).
979 */
980
952 if (adap->algo->master_xfer) { 981 if (adap->algo->master_xfer) {
953#ifdef DEBUG 982#ifdef DEBUG
954 for (ret = 0; ret < num; ret++) { 983 for (ret = 0; ret < num; ret++) {
@@ -979,6 +1008,14 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
979} 1008}
980EXPORT_SYMBOL(i2c_transfer); 1009EXPORT_SYMBOL(i2c_transfer);
981 1010
1011/**
1012 * i2c_master_send - issue a single I2C message in master transmit mode
1013 * @client: Handle to slave device
1014 * @buf: Data that will be written to the slave
1015 * @count: How many bytes to write
1016 *
1017 * Returns negative errno, or else the number of bytes written.
1018 */
982int i2c_master_send(struct i2c_client *client,const char *buf ,int count) 1019int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
983{ 1020{
984 int ret; 1021 int ret;
@@ -998,6 +1035,14 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
998} 1035}
999EXPORT_SYMBOL(i2c_master_send); 1036EXPORT_SYMBOL(i2c_master_send);
1000 1037
1038/**
1039 * i2c_master_recv - issue a single I2C message in master receive mode
1040 * @client: Handle to slave device
1041 * @buf: Where to store data read from slave
1042 * @count: How many bytes to read
1043 *
1044 * Returns negative errno, or else the number of bytes read.
1045 */
1001int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 1046int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
1002{ 1047{
1003 struct i2c_adapter *adap=client->adapter; 1048 struct i2c_adapter *adap=client->adapter;
@@ -1303,6 +1348,13 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
1303 return 0; 1348 return 0;
1304} 1349}
1305 1350
1351/**
1352 * i2c_smbus_read_byte - SMBus "receive byte" protocol
1353 * @client: Handle to slave device
1354 *
1355 * This executes the SMBus "receive byte" protocol, returning negative errno
1356 * else the byte received from the device.
1357 */
1306s32 i2c_smbus_read_byte(struct i2c_client *client) 1358s32 i2c_smbus_read_byte(struct i2c_client *client)
1307{ 1359{
1308 union i2c_smbus_data data; 1360 union i2c_smbus_data data;
@@ -1315,6 +1367,14 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
1315} 1367}
1316EXPORT_SYMBOL(i2c_smbus_read_byte); 1368EXPORT_SYMBOL(i2c_smbus_read_byte);
1317 1369
1370/**
1371 * i2c_smbus_write_byte - SMBus "send byte" protocol
1372 * @client: Handle to slave device
1373 * @value: Byte to be sent
1374 *
1375 * This executes the SMBus "send byte" protocol, returning negative errno
1376 * else zero on success.
1377 */
1318s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1378s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
1319{ 1379{
1320 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1380 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
@@ -1322,6 +1382,14 @@ s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
1322} 1382}
1323EXPORT_SYMBOL(i2c_smbus_write_byte); 1383EXPORT_SYMBOL(i2c_smbus_write_byte);
1324 1384
1385/**
1386 * i2c_smbus_read_byte_data - SMBus "read byte" protocol
1387 * @client: Handle to slave device
1388 * @command: Byte interpreted by slave
1389 *
1390 * This executes the SMBus "read byte" protocol, returning negative errno
1391 * else a data byte received from the device.
1392 */
1325s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1393s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
1326{ 1394{
1327 union i2c_smbus_data data; 1395 union i2c_smbus_data data;
@@ -1334,6 +1402,15 @@ s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
1334} 1402}
1335EXPORT_SYMBOL(i2c_smbus_read_byte_data); 1403EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1336 1404
1405/**
1406 * i2c_smbus_write_byte_data - SMBus "write byte" protocol
1407 * @client: Handle to slave device
1408 * @command: Byte interpreted by slave
1409 * @value: Byte being written
1410 *
1411 * This executes the SMBus "write byte" protocol, returning negative errno
1412 * else zero on success.
1413 */
1337s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1414s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
1338{ 1415{
1339 union i2c_smbus_data data; 1416 union i2c_smbus_data data;
@@ -1344,6 +1421,14 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
1344} 1421}
1345EXPORT_SYMBOL(i2c_smbus_write_byte_data); 1422EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1346 1423
1424/**
1425 * i2c_smbus_read_word_data - SMBus "read word" protocol
1426 * @client: Handle to slave device
1427 * @command: Byte interpreted by slave
1428 *
1429 * This executes the SMBus "read word" protocol, returning negative errno
1430 * else a 16-bit unsigned "word" received from the device.
1431 */
1347s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1432s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
1348{ 1433{
1349 union i2c_smbus_data data; 1434 union i2c_smbus_data data;
@@ -1356,6 +1441,15 @@ s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
1356} 1441}
1357EXPORT_SYMBOL(i2c_smbus_read_word_data); 1442EXPORT_SYMBOL(i2c_smbus_read_word_data);
1358 1443
1444/**
1445 * i2c_smbus_write_word_data - SMBus "write word" protocol
1446 * @client: Handle to slave device
1447 * @command: Byte interpreted by slave
1448 * @value: 16-bit "word" being written
1449 *
1450 * This executes the SMBus "write word" protocol, returning negative errno
1451 * else zero on success.
1452 */
1359s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1453s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1360{ 1454{
1361 union i2c_smbus_data data; 1455 union i2c_smbus_data data;
@@ -1367,15 +1461,14 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1367EXPORT_SYMBOL(i2c_smbus_write_word_data); 1461EXPORT_SYMBOL(i2c_smbus_write_word_data);
1368 1462
1369/** 1463/**
1370 * i2c_smbus_read_block_data - SMBus block read request 1464 * i2c_smbus_read_block_data - SMBus "block read" protocol
1371 * @client: Handle to slave device 1465 * @client: Handle to slave device
1372 * @command: Command byte issued to let the slave know what data should 1466 * @command: Byte interpreted by slave
1373 * be returned
1374 * @values: Byte array into which data will be read; big enough to hold 1467 * @values: Byte array into which data will be read; big enough to hold
1375 * the data returned by the slave. SMBus allows at most 32 bytes. 1468 * the data returned by the slave. SMBus allows at most 32 bytes.
1376 * 1469 *
1377 * Returns the number of bytes read in the slave's response, else a 1470 * This executes the SMBus "block read" protocol, returning negative errno
1378 * negative number to indicate some kind of error. 1471 * else the number of data bytes in the slave's response.
1379 * 1472 *
1380 * Note that using this function requires that the client's adapter support 1473 * Note that using this function requires that the client's adapter support
1381 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers 1474 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers
@@ -1399,6 +1492,16 @@ s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
1399} 1492}
1400EXPORT_SYMBOL(i2c_smbus_read_block_data); 1493EXPORT_SYMBOL(i2c_smbus_read_block_data);
1401 1494
1495/**
1496 * i2c_smbus_write_block_data - SMBus "block write" protocol
1497 * @client: Handle to slave device
1498 * @command: Byte interpreted by slave
1499 * @length: Size of data block; SMBus allows at most 32 bytes
1500 * @values: Byte array which will be written.
1501 *
1502 * This executes the SMBus "block write" protocol, returning negative errno
1503 * else zero on success.
1504 */
1402s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1505s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1403 u8 length, const u8 *values) 1506 u8 length, const u8 *values)
1404{ 1507{
@@ -1615,9 +1718,21 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1615 return 0; 1718 return 0;
1616} 1719}
1617 1720
1618 1721/**
1722 * i2c_smbus_xfer - execute SMBus protocol operations
1723 * @adapter: Handle to I2C bus
1724 * @addr: Address of SMBus slave on that bus
1725 * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC)
1726 * @read_write: I2C_SMBUS_READ or I2C_SMBUS_WRITE
1727 * @command: Byte interpreted by slave, for protocols which use such bytes
1728 * @protocol: SMBus protocol operation to execute, such as I2C_SMBUS_PROC_CALL
1729 * @data: Data to be read or written
1730 *
1731 * This executes an SMBus protocol operation, and returns a negative
1732 * errno code else zero on success.
1733 */
1619s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, 1734s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1620 char read_write, u8 command, int size, 1735 char read_write, u8 command, int protocol,
1621 union i2c_smbus_data * data) 1736 union i2c_smbus_data * data)
1622{ 1737{
1623 s32 res; 1738 s32 res;
@@ -1627,11 +1742,11 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1627 if (adapter->algo->smbus_xfer) { 1742 if (adapter->algo->smbus_xfer) {
1628 mutex_lock(&adapter->bus_lock); 1743 mutex_lock(&adapter->bus_lock);
1629 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, 1744 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
1630 command,size,data); 1745 command, protocol, data);
1631 mutex_unlock(&adapter->bus_lock); 1746 mutex_unlock(&adapter->bus_lock);
1632 } else 1747 } else
1633 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1748 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1634 command,size,data); 1749 command, protocol, data);
1635 1750
1636 return res; 1751 return res;
1637} 1752}