aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2005-05-07 16:58:46 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-22 00:51:55 -0400
commit815f55f280fb2781ba1c2a350516b73e55119c60 (patch)
tree48c06bd1650d44aa274989ce2696eb5091d3805c /drivers/i2c
parent30aedcb33970367e50b5edf373e9cd1a5cebcbe1 (diff)
[PATCH] I2C: Remove redundancy from i2c-core.c
Call i2c_transfer() from i2c_master_send() and i2c_master_recv() to avoid the redundant code that was in all three functions. It also removes unnecessary debug statements as suggested by Jean Delvare. This is important for the non-blocking interfaces because they will have to handle a non-blocking interface in this area. Having it in one place greatly simplifies the changes. Signed-off-by: Corey Minyard <minyard@acm.org> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/i2c-core.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index ecf43b13fefc..f50342832d95 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -611,27 +611,16 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
611 struct i2c_adapter *adap=client->adapter; 611 struct i2c_adapter *adap=client->adapter;
612 struct i2c_msg msg; 612 struct i2c_msg msg;
613 613
614 if (client->adapter->algo->master_xfer) { 614 msg.addr = client->addr;
615 msg.addr = client->addr; 615 msg.flags = client->flags & I2C_M_TEN;
616 msg.flags = client->flags & I2C_M_TEN; 616 msg.len = count;
617 msg.len = count; 617 msg.buf = (char *)buf;
618 msg.buf = (char *)buf;
619 618
620 dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n", 619 ret = i2c_transfer(adap, &msg, 1);
621 count);
622
623 down(&adap->bus_lock);
624 ret = adap->algo->master_xfer(adap,&msg,1);
625 up(&adap->bus_lock);
626 620
627 /* if everything went ok (i.e. 1 msg transmitted), return #bytes 621 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
628 * transmitted, else error code. 622 transmitted, else error code. */
629 */ 623 return (ret == 1) ? count : ret;
630 return (ret == 1 )? count : ret;
631 } else {
632 dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
633 return -ENOSYS;
634 }
635} 624}
636 625
637int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 626int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
@@ -639,31 +628,18 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
639 struct i2c_adapter *adap=client->adapter; 628 struct i2c_adapter *adap=client->adapter;
640 struct i2c_msg msg; 629 struct i2c_msg msg;
641 int ret; 630 int ret;
642 if (client->adapter->algo->master_xfer) { 631
643 msg.addr = client->addr; 632 msg.addr = client->addr;
644 msg.flags = client->flags & I2C_M_TEN; 633 msg.flags = client->flags & I2C_M_TEN;
645 msg.flags |= I2C_M_RD; 634 msg.flags |= I2C_M_RD;
646 msg.len = count; 635 msg.len = count;
647 msg.buf = buf; 636 msg.buf = buf;
648 637
649 dev_dbg(&client->adapter->dev, "master_recv: reading %d bytes.\n", 638 ret = i2c_transfer(adap, &msg, 1);
650 count); 639
651 640 /* If everything went ok (i.e. 1 msg transmitted), return #bytes
652 down(&adap->bus_lock); 641 transmitted, else error code. */
653 ret = adap->algo->master_xfer(adap,&msg,1); 642 return (ret == 1) ? count : ret;
654 up(&adap->bus_lock);
655
656 dev_dbg(&client->adapter->dev, "master_recv: return:%d (count:%d, addr:0x%02x)\n",
657 ret, count, client->addr);
658
659 /* if everything went ok (i.e. 1 msg transmitted), return #bytes
660 * transmitted, else error code.
661 */
662 return (ret == 1 )? count : ret;
663 } else {
664 dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
665 return -ENOSYS;
666 }
667} 643}
668 644
669 645