Skip to content

Commit 839d881

Browse files
committed
Merge branch 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'i2c-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: i2c: Functions for byte-swapped smbus_write/read_word_data i2c-algo-pca: Return standard fault codes i2c-algo-bit: Return standard fault codes i2c-algo-bit: Be verbose on bus testing failure i2c-algo-bit: Let user test buses without failing i2c/scx200_acb: Fix section mismatch warning in scx200_pci_drv i2c: I2C_ELEKTOR should depend on HAS_IOPORT
2 parents 0cfdc72 + 06a6784 commit 839d881

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

Documentation/i2c/smbus-protocol

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ byte. But this time, the data is a complete word (16 bits).
8888

8989
S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
9090

91+
Note the convenience function i2c_smbus_read_word_swapped is
92+
available for reads where the two data bytes are the other way
93+
around (not SMBus compliant, but very popular.)
94+
9195

9296
SMBus Write Byte: i2c_smbus_write_byte_data()
9397
==============================================
@@ -108,6 +112,10 @@ specified through the Comm byte.
108112

109113
S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
110114

115+
Note the convenience function i2c_smbus_write_word_swapped is
116+
available for writes where the two data bytes are the other way
117+
around (not SMBus compliant, but very popular.)
118+
111119

112120
SMBus Process Call: i2c_smbus_process_call()
113121
=============================================

drivers/i2c/algos/i2c-algo-bit.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
/* ----- global variables --------------------------------------------- */
4848

4949
static int bit_test; /* see if the line-setting functions work */
50-
module_param(bit_test, bool, 0);
51-
MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck");
50+
module_param(bit_test, int, S_IRUGO);
51+
MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck");
5252

5353
#ifdef DEBUG
5454
static int i2c_debug = 1;
@@ -250,7 +250,9 @@ static int test_bus(struct i2c_adapter *i2c_adap)
250250
sda = getsda(adap);
251251
scl = (adap->getscl == NULL) ? 1 : getscl(adap);
252252
if (!scl || !sda) {
253-
printk(KERN_WARNING "%s: bus seems to be busy\n", name);
253+
printk(KERN_WARNING
254+
"%s: bus seems to be busy (scl=%d, sda=%d)\n",
255+
name, scl, sda);
254256
goto bailout;
255257
}
256258

@@ -441,7 +443,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
441443
acknak(i2c_adap, 0);
442444
dev_err(&i2c_adap->dev, "readbytes: invalid "
443445
"block length (%d)\n", inval);
444-
return -EREMOTEIO;
446+
return -EPROTO;
445447
}
446448
/* The original count value accounts for the extra
447449
bytes, that is, either 1 for a regular transaction,
@@ -470,7 +472,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
470472
* reads, writes as well as 10bit-addresses.
471473
* returns:
472474
* 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set
473-
* -x an error occurred (like: -EREMOTEIO if the device did not answer, or
475+
* -x an error occurred (like: -ENXIO if the device did not answer, or
474476
* -ETIMEDOUT, for example if the lines are stuck...)
475477
*/
476478
static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
@@ -493,14 +495,14 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
493495
if ((ret != 1) && !nak_ok) {
494496
dev_err(&i2c_adap->dev,
495497
"died at extended address code\n");
496-
return -EREMOTEIO;
498+
return -ENXIO;
497499
}
498500
/* the remaining 8 bit address */
499501
ret = i2c_outb(i2c_adap, msg->addr & 0x7f);
500502
if ((ret != 1) && !nak_ok) {
501503
/* the chip did not ack / xmission error occurred */
502504
dev_err(&i2c_adap->dev, "died at 2nd address code\n");
503-
return -EREMOTEIO;
505+
return -ENXIO;
504506
}
505507
if (flags & I2C_M_RD) {
506508
bit_dbg(3, &i2c_adap->dev, "emitting repeated "
@@ -512,7 +514,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
512514
if ((ret != 1) && !nak_ok) {
513515
dev_err(&i2c_adap->dev,
514516
"died at repeated address code\n");
515-
return -EREMOTEIO;
517+
return -EIO;
516518
}
517519
}
518520
} else { /* normal 7bit address */
@@ -570,7 +572,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
570572
ret, ret == 1 ? "" : "s");
571573
if (ret < pmsg->len) {
572574
if (ret >= 0)
573-
ret = -EREMOTEIO;
575+
ret = -EIO;
574576
goto bailout;
575577
}
576578
} else {
@@ -581,7 +583,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
581583
ret, ret == 1 ? "" : "s");
582584
if (ret < pmsg->len) {
583585
if (ret >= 0)
584-
ret = -EREMOTEIO;
586+
ret = -EIO;
585587
goto bailout;
586588
}
587589
}
@@ -624,7 +626,7 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap,
624626

625627
if (bit_test) {
626628
ret = test_bus(adap);
627-
if (ret < 0)
629+
if (bit_test >= 2 && ret < 0)
628630
return -ENODEV;
629631
}
630632

drivers/i2c/algos/i2c-algo-pca.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
196196
} else {
197197
dev_dbg(&i2c_adap->dev, "bus is not idle. status is "
198198
"%#04x\n", state);
199-
return -EAGAIN;
199+
return -EBUSY;
200200
}
201201
}
202202

@@ -224,7 +224,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
224224
}
225225

226226
curmsg = 0;
227-
ret = -EREMOTEIO;
227+
ret = -EIO;
228228
while (curmsg < num) {
229229
state = pca_status(adap);
230230

@@ -259,6 +259,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
259259
case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */
260260
DEB2("NOT ACK received after SLA+W\n");
261261
pca_stop(adap);
262+
ret = -ENXIO;
262263
goto out;
263264

264265
case 0x40: /* SLA+R has been transmitted; ACK has been received */
@@ -283,6 +284,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
283284
case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */
284285
DEB2("NOT ACK received after SLA+R\n");
285286
pca_stop(adap);
287+
ret = -ENXIO;
286288
goto out;
287289

288290
case 0x30: /* Data byte in I2CDAT has been transmitted; NOT ACK has been received */

drivers/i2c/busses/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ config I2C_ACORN
789789

790790
config I2C_ELEKTOR
791791
tristate "Elektor ISA card"
792-
depends on ISA && BROKEN_ON_SMP
792+
depends on ISA && HAS_IOPORT && BROKEN_ON_SMP
793793
select I2C_ALGOPCF
794794
help
795795
This supports the PCF8584 ISA bus I2C adapter. Say Y if you own

drivers/i2c/busses/scx200_acb.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ static int __devexit scx200_remove(struct platform_device *pdev)
550550
return 0;
551551
}
552552

553-
static struct platform_driver scx200_pci_drv = {
553+
static struct platform_driver scx200_pci_driver = {
554554
.driver = {
555555
.name = "cs5535-smb",
556556
.owner = THIS_MODULE,
@@ -593,14 +593,14 @@ static int __init scx200_acb_init(void)
593593
return 0;
594594

595595
/* No ISA devices; register the platform driver for PCI-based devices */
596-
return platform_driver_register(&scx200_pci_drv);
596+
return platform_driver_register(&scx200_pci_driver);
597597
}
598598

599599
static void __exit scx200_acb_cleanup(void)
600600
{
601601
struct scx200_acb_iface *iface;
602602

603-
platform_driver_unregister(&scx200_pci_drv);
603+
platform_driver_unregister(&scx200_pci_driver);
604604

605605
mutex_lock(&scx200_acb_list_mutex);
606606
while ((iface = scx200_acb_list) != NULL) {

include/linux/i2c.h

+17
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/sched.h> /* for completion */
3535
#include <linux/mutex.h>
3636
#include <linux/of.h> /* for struct device_node */
37+
#include <linux/swab.h> /* for swab16 */
3738

3839
extern struct bus_type i2c_bus_type;
3940
extern struct device_type i2c_adapter_type;
@@ -88,6 +89,22 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client,
8889
u8 command);
8990
extern s32 i2c_smbus_write_word_data(const struct i2c_client *client,
9091
u8 command, u16 value);
92+
93+
static inline s32
94+
i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
95+
{
96+
s32 value = i2c_smbus_read_word_data(client, command);
97+
98+
return (value < 0) ? value : swab16(value);
99+
}
100+
101+
static inline s32
102+
i2c_smbus_write_word_swapped(const struct i2c_client *client,
103+
u8 command, u16 value)
104+
{
105+
return i2c_smbus_write_word_data(client, command, swab16(value));
106+
}
107+
91108
/* Returns the number of read bytes */
92109
extern s32 i2c_smbus_read_block_data(const struct i2c_client *client,
93110
u8 command, u8 *values);

0 commit comments

Comments
 (0)