From 9519282a02e74f0bf780eb371a3160824c23965a Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Sun, 30 Oct 2011 13:47:24 +0100 Subject: i2c: I2C_ELEKTOR should depend on HAS_IOPORT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On m68k, I get: drivers/i2c/busses/i2c-elektor.c: In function ‘pcf_isa_init’: drivers/i2c/busses/i2c-elektor.c:153: error: implicit declaration of function ‘ioport_map’ drivers/i2c/busses/i2c-elektor.c:153: warning: assignment makes pointer from integer without a cast drivers/i2c/busses/i2c-elektor.c: In function ‘elektor_probe’: drivers/i2c/busses/i2c-elektor.c:287: error: implicit declaration of function ‘ioport_unmap’ Since commit 82ed223c264def2b15ee4bec2e8c3048092ceb5f ("iomap: make IOPORT/PCI mapping functions conditional"), ioport_map() is only available on platforms that set HAS_IOPORT. Signed-off-by: Geert Uytterhoeven Signed-off-by: Jean Delvare --- drivers/i2c/busses/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 646068e5100b..d1fc5cf9aa4d 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -789,7 +789,7 @@ config I2C_ACORN config I2C_ELEKTOR tristate "Elektor ISA card" - depends on ISA && BROKEN_ON_SMP + depends on ISA && HAS_IOPORT && BROKEN_ON_SMP select I2C_ALGOPCF help This supports the PCF8584 ISA bus I2C adapter. Say Y if you own -- cgit v1.2.3 From 6fcf84a2c0d5f51a457555d76e037cf3cc85bc7a Mon Sep 17 00:00:00 2001 From: Harvey Yang Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c/scx200_acb: Fix section mismatch warning in scx200_pci_drv WARNING: drivers/i2c/busses/built-in.o(.data+0x47c8): Section mismatch in reference from the variable scx200_pci_drv to the function .devinit.text:scx200_probe() The variable scx200_pci_drv references the function __devinit scx200_probe() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *driver, *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console Signed-off-by: Harvey Yang Signed-off-by: Jean Delvare --- drivers/i2c/busses/scx200_acb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c index 986e5f62debe..91e349c884c5 100644 --- a/drivers/i2c/busses/scx200_acb.c +++ b/drivers/i2c/busses/scx200_acb.c @@ -550,7 +550,7 @@ static int __devexit scx200_remove(struct platform_device *pdev) return 0; } -static struct platform_driver scx200_pci_drv = { +static struct platform_driver scx200_pci_driver = { .driver = { .name = "cs5535-smb", .owner = THIS_MODULE, @@ -593,14 +593,14 @@ static int __init scx200_acb_init(void) return 0; /* No ISA devices; register the platform driver for PCI-based devices */ - return platform_driver_register(&scx200_pci_drv); + return platform_driver_register(&scx200_pci_driver); } static void __exit scx200_acb_cleanup(void) { struct scx200_acb_iface *iface; - platform_driver_unregister(&scx200_pci_drv); + platform_driver_unregister(&scx200_pci_driver); mutex_lock(&scx200_acb_list_mutex); while ((iface = scx200_acb_list) != NULL) { -- cgit v1.2.3 From 1bddab7f7d5b61f17b0bbd669f60818d553620be Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c-algo-bit: Let user test buses without failing Always failing to register I2C buses when the line testing fails is a little harsh. While such a failure is definitely a bug in the driver that exposes the affected I2C bus, things may still work fine if the missing initialization steps are done later, before the I2C bus is used. So it seems a better debugging tool to just report the test failure by default. I introduce bit_test=2 if anyone really misses the original behavior of bit_test=1. Signed-off-by: Jean Delvare Reviewed-by: Alex Deucher --- drivers/i2c/algos/i2c-algo-bit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index d6d58684712b..66bebfc81c22 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c @@ -47,8 +47,8 @@ /* ----- global variables --------------------------------------------- */ static int bit_test; /* see if the line-setting functions work */ -module_param(bit_test, bool, 0); -MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); +module_param(bit_test, int, S_IRUGO); +MODULE_PARM_DESC(bit_test, "lines testing - 0 off; 1 report; 2 fail if stuck"); #ifdef DEBUG static int i2c_debug = 1; @@ -624,7 +624,7 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap, if (bit_test) { ret = test_bus(adap); - if (ret < 0) + if (bit_test >= 2 && ret < 0) return -ENODEV; } -- cgit v1.2.3 From f6beb67d8e77454200acc3755344944bd946cded Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c-algo-bit: Be verbose on bus testing failure If bus testing fails due to the bus being seen as busy, it might be helpful for developers to know which line is unexpectedly low. Signed-off-by: Jean Delvare Reviewed-by: Alex Deucher --- drivers/i2c/algos/i2c-algo-bit.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index 66bebfc81c22..c20530a98ca3 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c @@ -250,7 +250,9 @@ static int test_bus(struct i2c_adapter *i2c_adap) sda = getsda(adap); scl = (adap->getscl == NULL) ? 1 : getscl(adap); if (!scl || !sda) { - printk(KERN_WARNING "%s: bus seems to be busy\n", name); + printk(KERN_WARNING + "%s: bus seems to be busy (scl=%d, sda=%d)\n", + name, scl, sda); goto bailout; } -- cgit v1.2.3 From abc01b2718ee1d26e83c4c62c4b79806b3240ac7 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c-algo-bit: Return standard fault codes Adjust i2c-algo-bit to return fault codes compliant with Documentation/i2c/fault-codes, rather than the undocumented and vague -EREMOTEIO. Signed-off-by: Jean Delvare --- drivers/i2c/algos/i2c-algo-bit.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c index c20530a98ca3..85584a547c25 100644 --- a/drivers/i2c/algos/i2c-algo-bit.c +++ b/drivers/i2c/algos/i2c-algo-bit.c @@ -443,7 +443,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) acknak(i2c_adap, 0); dev_err(&i2c_adap->dev, "readbytes: invalid " "block length (%d)\n", inval); - return -EREMOTEIO; + return -EPROTO; } /* The original count value accounts for the extra bytes, that is, either 1 for a regular transaction, @@ -472,7 +472,7 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) * reads, writes as well as 10bit-addresses. * returns: * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set - * -x an error occurred (like: -EREMOTEIO if the device did not answer, or + * -x an error occurred (like: -ENXIO if the device did not answer, or * -ETIMEDOUT, for example if the lines are stuck...) */ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) @@ -495,14 +495,14 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) if ((ret != 1) && !nak_ok) { dev_err(&i2c_adap->dev, "died at extended address code\n"); - return -EREMOTEIO; + return -ENXIO; } /* the remaining 8 bit address */ ret = i2c_outb(i2c_adap, msg->addr & 0x7f); if ((ret != 1) && !nak_ok) { /* the chip did not ack / xmission error occurred */ dev_err(&i2c_adap->dev, "died at 2nd address code\n"); - return -EREMOTEIO; + return -ENXIO; } if (flags & I2C_M_RD) { bit_dbg(3, &i2c_adap->dev, "emitting repeated " @@ -514,7 +514,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) if ((ret != 1) && !nak_ok) { dev_err(&i2c_adap->dev, "died at repeated address code\n"); - return -EREMOTEIO; + return -EIO; } } } else { /* normal 7bit address */ @@ -572,7 +572,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, ret, ret == 1 ? "" : "s"); if (ret < pmsg->len) { if (ret >= 0) - ret = -EREMOTEIO; + ret = -EIO; goto bailout; } } else { @@ -583,7 +583,7 @@ static int bit_xfer(struct i2c_adapter *i2c_adap, ret, ret == 1 ? "" : "s"); if (ret < pmsg->len) { if (ret >= 0) - ret = -EREMOTEIO; + ret = -EIO; goto bailout; } } -- cgit v1.2.3 From 4403988afc0a92b8faf59b46f51d25fafaf0e63d Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c-algo-pca: Return standard fault codes Adjust i2c-algo-pca to return fault codes compliant with Documentation/i2c/fault-codes, rather than the undocumented and vague -EREMOTEIO. Signed-off-by: Jean Delvare Cc: Wolfram Sang --- drivers/i2c/algos/i2c-algo-pca.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c index 4ca9cf9cde73..beb9ffe2564b 100644 --- a/drivers/i2c/algos/i2c-algo-pca.c +++ b/drivers/i2c/algos/i2c-algo-pca.c @@ -196,7 +196,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, } else { dev_dbg(&i2c_adap->dev, "bus is not idle. status is " "%#04x\n", state); - return -EAGAIN; + return -EBUSY; } } @@ -224,7 +224,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, } curmsg = 0; - ret = -EREMOTEIO; + ret = -EIO; while (curmsg < num) { state = pca_status(adap); @@ -259,6 +259,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */ DEB2("NOT ACK received after SLA+W\n"); pca_stop(adap); + ret = -ENXIO; goto out; case 0x40: /* SLA+R has been transmitted; ACK has been received */ @@ -283,6 +284,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap, case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */ DEB2("NOT ACK received after SLA+R\n"); pca_stop(adap); + ret = -ENXIO; goto out; case 0x30: /* Data byte in I2CDAT has been transmitted; NOT ACK has been received */ -- cgit v1.2.3 From 06a67848c6681a73e621e47c056490d51a07289f Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Sun, 30 Oct 2011 13:47:25 +0100 Subject: i2c: Functions for byte-swapped smbus_write/read_word_data Reimplemented at least 17 times discounting error mangling cases where it could be used. Signed-off-by: Jonathan Cameron Signed-off-by: Jean Delvare --- Documentation/i2c/smbus-protocol | 8 ++++++++ include/linux/i2c.h | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Documentation/i2c/smbus-protocol b/Documentation/i2c/smbus-protocol index 7c19d1a2bea0..49f5b680809d 100644 --- a/Documentation/i2c/smbus-protocol +++ b/Documentation/i2c/smbus-protocol @@ -88,6 +88,10 @@ byte. But this time, the data is a complete word (16 bits). S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P +Note the convenience function i2c_smbus_read_word_swapped is +available for reads where the two data bytes are the other way +around (not SMBus compliant, but very popular.) + SMBus Write Byte: i2c_smbus_write_byte_data() ============================================== @@ -108,6 +112,10 @@ specified through the Comm byte. S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P +Note the convenience function i2c_smbus_write_word_swapped is +available for writes where the two data bytes are the other way +around (not SMBus compliant, but very popular.) + SMBus Process Call: i2c_smbus_process_call() ============================================= diff --git a/include/linux/i2c.h b/include/linux/i2c.h index a6c652ef516d..38a21c3edd2c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -34,6 +34,7 @@ #include /* for completion */ #include #include /* for struct device_node */ +#include /* for swab16 */ extern struct bus_type i2c_bus_type; extern struct device_type i2c_adapter_type; @@ -88,6 +89,22 @@ extern s32 i2c_smbus_read_word_data(const struct i2c_client *client, u8 command); extern s32 i2c_smbus_write_word_data(const struct i2c_client *client, u8 command, u16 value); + +static inline s32 +i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command) +{ + s32 value = i2c_smbus_read_word_data(client, command); + + return (value < 0) ? value : swab16(value); +} + +static inline s32 +i2c_smbus_write_word_swapped(const struct i2c_client *client, + u8 command, u16 value) +{ + return i2c_smbus_write_word_data(client, command, swab16(value)); +} + /* Returns the number of read bytes */ extern s32 i2c_smbus_read_block_data(const struct i2c_client *client, u8 command, u8 *values); -- cgit v1.2.3