Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+46 -17
+8
Documentation/i2c/smbus-protocol
··· 88 88 89 89 S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P 90 90 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 + 91 95 92 96 SMBus Write Byte: i2c_smbus_write_byte_data() 93 97 ============================================== ··· 111 107 specified through the Comm byte. 112 108 113 109 S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P 110 + 111 + Note the convenience function i2c_smbus_write_word_swapped is 112 + available for writes where the two data bytes are the other way 113 + around (not SMBus compliant, but very popular.) 114 114 115 115 116 116 SMBus Process Call: i2c_smbus_process_call()
+13 -11
drivers/i2c/algos/i2c-algo-bit.c
··· 47 47 /* ----- global variables --------------------------------------------- */ 48 48 49 49 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"); 52 52 53 53 #ifdef DEBUG 54 54 static int i2c_debug = 1; ··· 250 250 sda = getsda(adap); 251 251 scl = (adap->getscl == NULL) ? 1 : getscl(adap); 252 252 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); 254 256 goto bailout; 255 257 } 256 258 ··· 443 441 acknak(i2c_adap, 0); 444 442 dev_err(&i2c_adap->dev, "readbytes: invalid " 445 443 "block length (%d)\n", inval); 446 - return -EREMOTEIO; 444 + return -EPROTO; 447 445 } 448 446 /* The original count value accounts for the extra 449 447 bytes, that is, either 1 for a regular transaction, ··· 472 470 * reads, writes as well as 10bit-addresses. 473 471 * returns: 474 472 * 0 everything went okay, the chip ack'ed, or IGNORE_NAK flag was set 475 - * -x an error occurred (like: -EREMOTEIO if the device did not answer, or 473 + * -x an error occurred (like: -ENXIO if the device did not answer, or 476 474 * -ETIMEDOUT, for example if the lines are stuck...) 477 475 */ 478 476 static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) ··· 495 493 if ((ret != 1) && !nak_ok) { 496 494 dev_err(&i2c_adap->dev, 497 495 "died at extended address code\n"); 498 - return -EREMOTEIO; 496 + return -ENXIO; 499 497 } 500 498 /* the remaining 8 bit address */ 501 499 ret = i2c_outb(i2c_adap, msg->addr & 0x7f); 502 500 if ((ret != 1) && !nak_ok) { 503 501 /* the chip did not ack / xmission error occurred */ 504 502 dev_err(&i2c_adap->dev, "died at 2nd address code\n"); 505 - return -EREMOTEIO; 503 + return -ENXIO; 506 504 } 507 505 if (flags & I2C_M_RD) { 508 506 bit_dbg(3, &i2c_adap->dev, "emitting repeated " ··· 514 512 if ((ret != 1) && !nak_ok) { 515 513 dev_err(&i2c_adap->dev, 516 514 "died at repeated address code\n"); 517 - return -EREMOTEIO; 515 + return -EIO; 518 516 } 519 517 } 520 518 } else { /* normal 7bit address */ ··· 572 570 ret, ret == 1 ? "" : "s"); 573 571 if (ret < pmsg->len) { 574 572 if (ret >= 0) 575 - ret = -EREMOTEIO; 573 + ret = -EIO; 576 574 goto bailout; 577 575 } 578 576 } else { ··· 583 581 ret, ret == 1 ? "" : "s"); 584 582 if (ret < pmsg->len) { 585 583 if (ret >= 0) 586 - ret = -EREMOTEIO; 584 + ret = -EIO; 587 585 goto bailout; 588 586 } 589 587 } ··· 626 624 627 625 if (bit_test) { 628 626 ret = test_bus(adap); 629 - if (ret < 0) 627 + if (bit_test >= 2 && ret < 0) 630 628 return -ENODEV; 631 629 } 632 630
+4 -2
drivers/i2c/algos/i2c-algo-pca.c
··· 196 196 } else { 197 197 dev_dbg(&i2c_adap->dev, "bus is not idle. status is " 198 198 "%#04x\n", state); 199 - return -EAGAIN; 199 + return -EBUSY; 200 200 } 201 201 } 202 202 ··· 224 224 } 225 225 226 226 curmsg = 0; 227 - ret = -EREMOTEIO; 227 + ret = -EIO; 228 228 while (curmsg < num) { 229 229 state = pca_status(adap); 230 230 ··· 259 259 case 0x20: /* SLA+W has been transmitted; NOT ACK has been received */ 260 260 DEB2("NOT ACK received after SLA+W\n"); 261 261 pca_stop(adap); 262 + ret = -ENXIO; 262 263 goto out; 263 264 264 265 case 0x40: /* SLA+R has been transmitted; ACK has been received */ ··· 284 283 case 0x48: /* SLA+R has been transmitted; NOT ACK has been received */ 285 284 DEB2("NOT ACK received after SLA+R\n"); 286 285 pca_stop(adap); 286 + ret = -ENXIO; 287 287 goto out; 288 288 289 289 case 0x30: /* Data byte in I2CDAT has been transmitted; NOT ACK has been received */
+1 -1
drivers/i2c/busses/Kconfig
··· 789 789 790 790 config I2C_ELEKTOR 791 791 tristate "Elektor ISA card" 792 - depends on ISA && BROKEN_ON_SMP 792 + depends on ISA && HAS_IOPORT && BROKEN_ON_SMP 793 793 select I2C_ALGOPCF 794 794 help 795 795 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
+3 -3
drivers/i2c/busses/scx200_acb.c
··· 550 550 return 0; 551 551 } 552 552 553 - static struct platform_driver scx200_pci_drv = { 553 + static struct platform_driver scx200_pci_driver = { 554 554 .driver = { 555 555 .name = "cs5535-smb", 556 556 .owner = THIS_MODULE, ··· 593 593 return 0; 594 594 595 595 /* 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); 597 597 } 598 598 599 599 static void __exit scx200_acb_cleanup(void) 600 600 { 601 601 struct scx200_acb_iface *iface; 602 602 603 - platform_driver_unregister(&scx200_pci_drv); 603 + platform_driver_unregister(&scx200_pci_driver); 604 604 605 605 mutex_lock(&scx200_acb_list_mutex); 606 606 while ((iface = scx200_acb_list) != NULL) {
+17
include/linux/i2c.h
··· 34 34 #include <linux/sched.h> /* for completion */ 35 35 #include <linux/mutex.h> 36 36 #include <linux/of.h> /* for struct device_node */ 37 + #include <linux/swab.h> /* for swab16 */ 37 38 38 39 extern struct bus_type i2c_bus_type; 39 40 extern struct device_type i2c_adapter_type; ··· 89 88 u8 command); 90 89 extern s32 i2c_smbus_write_word_data(const struct i2c_client *client, 91 90 u8 command, u16 value); 91 + 92 + static inline s32 93 + i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command) 94 + { 95 + s32 value = i2c_smbus_read_word_data(client, command); 96 + 97 + return (value < 0) ? value : swab16(value); 98 + } 99 + 100 + static inline s32 101 + i2c_smbus_write_word_swapped(const struct i2c_client *client, 102 + u8 command, u16 value) 103 + { 104 + return i2c_smbus_write_word_data(client, command, swab16(value)); 105 + } 106 + 92 107 /* Returns the number of read bytes */ 93 108 extern s32 i2c_smbus_read_block_data(const struct i2c_client *client, 94 109 u8 command, u8 *values);