diff options
-rw-r--r-- | Documentation/i2c/writing-clients | 8 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 97 |
2 files changed, 57 insertions, 48 deletions
diff --git a/Documentation/i2c/writing-clients b/Documentation/i2c/writing-clients index d4cd4126d1ad..ba5d1971f35f 100644 --- a/Documentation/i2c/writing-clients +++ b/Documentation/i2c/writing-clients | |||
@@ -598,10 +598,10 @@ be added back later if needed: | |||
598 | u8 command, u8 length, | 598 | u8 command, u8 length, |
599 | u8 *values) | 599 | u8 *values) |
600 | 600 | ||
601 | All these transactions return -1 on failure. The 'write' transactions | 601 | All these transactions return a negative errno value on failure. The 'write' |
602 | return 0 on success; the 'read' transactions return the read value, except | 602 | transactions return 0 on success; the 'read' transactions return the read |
603 | for read_block, which returns the number of values read. The block buffers | 603 | value, except for block transactions, which return the number of values |
604 | need not be longer than 32 bytes. | 604 | read. The block buffers need not be longer than 32 bytes. |
605 | 605 | ||
606 | You can read the file `smbus-protocol' for more information about the | 606 | You can read the file `smbus-protocol' for more information about the |
607 | actual SMBus protocol. | 607 | actual SMBus protocol. |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index bb5c215a24e0..937f1dcbf3d7 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -974,7 +974,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) | |||
974 | return ret; | 974 | return ret; |
975 | } else { | 975 | } else { |
976 | dev_dbg(&adap->dev, "I2C level transfers not supported\n"); | 976 | dev_dbg(&adap->dev, "I2C level transfers not supported\n"); |
977 | return -ENOSYS; | 977 | return -EOPNOTSUPP; |
978 | } | 978 | } |
979 | } | 979 | } |
980 | EXPORT_SYMBOL(i2c_transfer); | 980 | EXPORT_SYMBOL(i2c_transfer); |
@@ -1106,7 +1106,7 @@ int i2c_probe(struct i2c_adapter *adapter, | |||
1106 | 1106 | ||
1107 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " | 1107 | dev_warn(&adapter->dev, "SMBus Quick command not supported, " |
1108 | "can't probe for chips\n"); | 1108 | "can't probe for chips\n"); |
1109 | return -1; | 1109 | return -EOPNOTSUPP; |
1110 | } | 1110 | } |
1111 | 1111 | ||
1112 | /* Probe entries are done second, and are not affected by ignore | 1112 | /* Probe entries are done second, and are not affected by ignore |
@@ -1298,7 +1298,7 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg) | |||
1298 | if (rpec != cpec) { | 1298 | if (rpec != cpec) { |
1299 | pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n", | 1299 | pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n", |
1300 | rpec, cpec); | 1300 | rpec, cpec); |
1301 | return -1; | 1301 | return -EBADMSG; |
1302 | } | 1302 | } |
1303 | return 0; | 1303 | return 0; |
1304 | } | 1304 | } |
@@ -1313,11 +1313,12 @@ EXPORT_SYMBOL(i2c_smbus_write_quick); | |||
1313 | s32 i2c_smbus_read_byte(struct i2c_client *client) | 1313 | s32 i2c_smbus_read_byte(struct i2c_client *client) |
1314 | { | 1314 | { |
1315 | union i2c_smbus_data data; | 1315 | union i2c_smbus_data data; |
1316 | if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1316 | int status; |
1317 | I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) | 1317 | |
1318 | return -1; | 1318 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1319 | else | 1319 | I2C_SMBUS_READ, 0, |
1320 | return data.byte; | 1320 | I2C_SMBUS_BYTE, &data); |
1321 | return (status < 0) ? status : data.byte; | ||
1321 | } | 1322 | } |
1322 | EXPORT_SYMBOL(i2c_smbus_read_byte); | 1323 | EXPORT_SYMBOL(i2c_smbus_read_byte); |
1323 | 1324 | ||
@@ -1331,11 +1332,12 @@ EXPORT_SYMBOL(i2c_smbus_write_byte); | |||
1331 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) | 1332 | s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) |
1332 | { | 1333 | { |
1333 | union i2c_smbus_data data; | 1334 | union i2c_smbus_data data; |
1334 | if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1335 | int status; |
1335 | I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) | 1336 | |
1336 | return -1; | 1337 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1337 | else | 1338 | I2C_SMBUS_READ, command, |
1338 | return data.byte; | 1339 | I2C_SMBUS_BYTE_DATA, &data); |
1340 | return (status < 0) ? status : data.byte; | ||
1339 | } | 1341 | } |
1340 | EXPORT_SYMBOL(i2c_smbus_read_byte_data); | 1342 | EXPORT_SYMBOL(i2c_smbus_read_byte_data); |
1341 | 1343 | ||
@@ -1352,11 +1354,12 @@ EXPORT_SYMBOL(i2c_smbus_write_byte_data); | |||
1352 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) | 1354 | s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) |
1353 | { | 1355 | { |
1354 | union i2c_smbus_data data; | 1356 | union i2c_smbus_data data; |
1355 | if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1357 | int status; |
1356 | I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) | 1358 | |
1357 | return -1; | 1359 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1358 | else | 1360 | I2C_SMBUS_READ, command, |
1359 | return data.word; | 1361 | I2C_SMBUS_WORD_DATA, &data); |
1362 | return (status < 0) ? status : data.word; | ||
1360 | } | 1363 | } |
1361 | EXPORT_SYMBOL(i2c_smbus_read_word_data); | 1364 | EXPORT_SYMBOL(i2c_smbus_read_word_data); |
1362 | 1365 | ||
@@ -1390,11 +1393,13 @@ s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command, | |||
1390 | u8 *values) | 1393 | u8 *values) |
1391 | { | 1394 | { |
1392 | union i2c_smbus_data data; | 1395 | union i2c_smbus_data data; |
1396 | int status; | ||
1393 | 1397 | ||
1394 | if (i2c_smbus_xfer(client->adapter, client->addr, client->flags, | 1398 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1395 | I2C_SMBUS_READ, command, | 1399 | I2C_SMBUS_READ, command, |
1396 | I2C_SMBUS_BLOCK_DATA, &data)) | 1400 | I2C_SMBUS_BLOCK_DATA, &data); |
1397 | return -1; | 1401 | if (status) |
1402 | return status; | ||
1398 | 1403 | ||
1399 | memcpy(values, &data.block[1], data.block[0]); | 1404 | memcpy(values, &data.block[1], data.block[0]); |
1400 | return data.block[0]; | 1405 | return data.block[0]; |
@@ -1421,14 +1426,16 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command, | |||
1421 | u8 length, u8 *values) | 1426 | u8 length, u8 *values) |
1422 | { | 1427 | { |
1423 | union i2c_smbus_data data; | 1428 | union i2c_smbus_data data; |
1429 | int status; | ||
1424 | 1430 | ||
1425 | if (length > I2C_SMBUS_BLOCK_MAX) | 1431 | if (length > I2C_SMBUS_BLOCK_MAX) |
1426 | length = I2C_SMBUS_BLOCK_MAX; | 1432 | length = I2C_SMBUS_BLOCK_MAX; |
1427 | data.block[0] = length; | 1433 | data.block[0] = length; |
1428 | if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, | 1434 | status = i2c_smbus_xfer(client->adapter, client->addr, client->flags, |
1429 | I2C_SMBUS_READ,command, | 1435 | I2C_SMBUS_READ, command, |
1430 | I2C_SMBUS_I2C_BLOCK_DATA,&data)) | 1436 | I2C_SMBUS_I2C_BLOCK_DATA, &data); |
1431 | return -1; | 1437 | if (status < 0) |
1438 | return status; | ||
1432 | 1439 | ||
1433 | memcpy(values, &data.block[1], data.block[0]); | 1440 | memcpy(values, &data.block[1], data.block[0]); |
1434 | return data.block[0]; | 1441 | return data.block[0]; |
@@ -1469,6 +1476,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1469 | }; | 1476 | }; |
1470 | int i; | 1477 | int i; |
1471 | u8 partial_pec = 0; | 1478 | u8 partial_pec = 0; |
1479 | int status; | ||
1472 | 1480 | ||
1473 | msgbuf0[0] = command; | 1481 | msgbuf0[0] = command; |
1474 | switch(size) { | 1482 | switch(size) { |
@@ -1518,10 +1526,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1518 | } else { | 1526 | } else { |
1519 | msg[0].len = data->block[0] + 2; | 1527 | msg[0].len = data->block[0] + 2; |
1520 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { | 1528 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { |
1521 | dev_err(&adapter->dev, "smbus_access called with " | 1529 | dev_err(&adapter->dev, |
1522 | "invalid block write size (%d)\n", | 1530 | "Invalid block write size %d\n", |
1523 | data->block[0]); | 1531 | data->block[0]); |
1524 | return -1; | 1532 | return -EINVAL; |
1525 | } | 1533 | } |
1526 | for (i = 1; i < msg[0].len; i++) | 1534 | for (i = 1; i < msg[0].len; i++) |
1527 | msgbuf0[i] = data->block[i-1]; | 1535 | msgbuf0[i] = data->block[i-1]; |
@@ -1531,10 +1539,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1531 | num = 2; /* Another special case */ | 1539 | num = 2; /* Another special case */ |
1532 | read_write = I2C_SMBUS_READ; | 1540 | read_write = I2C_SMBUS_READ; |
1533 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { | 1541 | if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { |
1534 | dev_err(&adapter->dev, "%s called with invalid " | 1542 | dev_err(&adapter->dev, |
1535 | "block proc call size (%d)\n", __func__, | 1543 | "Invalid block write size %d\n", |
1536 | data->block[0]); | 1544 | data->block[0]); |
1537 | return -1; | 1545 | return -EINVAL; |
1538 | } | 1546 | } |
1539 | msg[0].len = data->block[0] + 2; | 1547 | msg[0].len = data->block[0] + 2; |
1540 | for (i = 1; i < msg[0].len; i++) | 1548 | for (i = 1; i < msg[0].len; i++) |
@@ -1549,19 +1557,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1549 | } else { | 1557 | } else { |
1550 | msg[0].len = data->block[0] + 1; | 1558 | msg[0].len = data->block[0] + 1; |
1551 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) { | 1559 | if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) { |
1552 | dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with " | 1560 | dev_err(&adapter->dev, |
1553 | "invalid block write size (%d)\n", | 1561 | "Invalid block write size %d\n", |
1554 | data->block[0]); | 1562 | data->block[0]); |
1555 | return -1; | 1563 | return -EINVAL; |
1556 | } | 1564 | } |
1557 | for (i = 1; i <= data->block[0]; i++) | 1565 | for (i = 1; i <= data->block[0]; i++) |
1558 | msgbuf0[i] = data->block[i]; | 1566 | msgbuf0[i] = data->block[i]; |
1559 | } | 1567 | } |
1560 | break; | 1568 | break; |
1561 | default: | 1569 | default: |
1562 | dev_err(&adapter->dev, "smbus_access called with invalid size (%d)\n", | 1570 | dev_err(&adapter->dev, "Unsupported transaction %d\n", size); |
1563 | size); | 1571 | return -EOPNOTSUPP; |
1564 | return -1; | ||
1565 | } | 1572 | } |
1566 | 1573 | ||
1567 | i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK | 1574 | i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK |
@@ -1579,13 +1586,15 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, | |||
1579 | msg[num-1].len++; | 1586 | msg[num-1].len++; |
1580 | } | 1587 | } |
1581 | 1588 | ||
1582 | if (i2c_transfer(adapter, msg, num) < 0) | 1589 | status = i2c_transfer(adapter, msg, num); |
1583 | return -1; | 1590 | if (status < 0) |
1591 | return status; | ||
1584 | 1592 | ||
1585 | /* Check PEC if last message is a read */ | 1593 | /* Check PEC if last message is a read */ |
1586 | if (i && (msg[num-1].flags & I2C_M_RD)) { | 1594 | if (i && (msg[num-1].flags & I2C_M_RD)) { |
1587 | if (i2c_smbus_check_pec(partial_pec, &msg[num-1]) < 0) | 1595 | status = i2c_smbus_check_pec(partial_pec, &msg[num-1]); |
1588 | return -1; | 1596 | if (status < 0) |
1597 | return status; | ||
1589 | } | 1598 | } |
1590 | 1599 | ||
1591 | if (read_write == I2C_SMBUS_READ) | 1600 | if (read_write == I2C_SMBUS_READ) |