| 729 | | |
| 730 | | int i2c_master_send_subadress(struct i2c_client *client,const char *buf ,int count, int subadress) |
| 731 | | { |
| 732 | | char* c; |
| 733 | | |
| 734 | | int ret; |
| 735 | | struct i2c_adapter *adap=client->adapter; |
| 736 | | struct i2c_msg msg; |
| 737 | | |
| 738 | | if (client->adapter->algo->master_xfer) { |
| 739 | | c = (char*)kmalloc(sizeof(char)*(count+1),GFP_KERNEL); |
| 740 | | if (0 == c) |
| 741 | | return -ENOMEM; |
| 742 | | |
| 743 | | msg.addr = client->addr; |
| 744 | | msg.flags = client->flags & ( I2C_M_TEN|I2C_M_TENMASK ); |
| 745 | | msg.len = count+1; |
| 746 | | (const char *)msg.buf = c; |
| 747 | | |
| 748 | | c[0] = subadress; |
| 749 | | memcpy(&c[1], buf, sizeof(char)*count); |
| 750 | | |
| 751 | | DEB(printk("i2c-core.o: master_send_subadress: writing %d bytes on %s. (sa:0x%02x)\n", |
| 752 | | count,client->adapter->name,subadress)); |
| 753 | | |
| 754 | | I2C_LOCK(adap); |
| 755 | | ret = adap->algo->master_xfer(adap,&msg,1); |
| 756 | | I2C_UNLOCK(adap); |
| 757 | | |
| 758 | | /* if everything went ok (i.e. 1 msg transmitted), return #bytes |
| 759 | | * transmitted, else error code. |
| 760 | | */ |
| 761 | | |
| 762 | | kfree(c); |
| 763 | | |
| 764 | | return (ret == 1 )? count : ret; |
| 765 | | } else { |
| 766 | | printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n", |
| 767 | | client->adapter->id); |
| 768 | | return 0; |
| 769 | | } |
| 770 | | } |
| 771 | | |
| 772 | | |
| 773 | | int i2c_master_recv_subadress(struct i2c_client *client,const char *buf ,int count, int subadress) |
| 774 | | { |
| 775 | | int ret; |
| 776 | | struct i2c_adapter *adap=client->adapter; |
| 777 | | struct i2c_msg msg[2]; |
| 778 | | |
| 779 | | if (client->adapter->algo->master_xfer) { |
| 780 | | msg[0].addr = client->addr; |
| 781 | | msg[0].flags = client->flags & ( I2C_M_TEN|I2C_M_TENMASK ); |
| 782 | | msg[0].len = 1; |
| 783 | | (const char*)msg[0].buf = (const char*)&subadress; |
| 784 | | |
| 785 | | msg[1].addr = client->addr; |
| 786 | | msg[1].flags = client->flags & ( I2C_M_TEN|I2C_M_TENMASK ); |
| 787 | | msg[1].flags |= I2C_M_RD; |
| 788 | | msg[1].len = count; |
| 789 | | (const char*)msg[1].buf = (const char*)buf; |
| 790 | | |
| 791 | | DEB(printk("i2c-core.o: master_recv_subadress: reading %d bytes from subadress %d on %s.\n", |
| 792 | | count,subadress,client->adapter->name)); |
| 793 | | |
| 794 | | I2C_LOCK(adap); |
| 795 | | ret = adap->algo->master_xfer(adap,msg,2); |
| 796 | | I2C_UNLOCK(adap); |
| 797 | | |
| 798 | | /* if everything went ok (i.e. 1 msg transmitted), |
| 799 | | return 0, else return error code. |
| 800 | | */ |
| 801 | | return (ret == 1 ) ? 0 : ret; |
| 802 | | } else { |
| 803 | | printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n", |
| 804 | | client->adapter->id); |
| 805 | | return 0; |
| 806 | | } |
| 807 | | } |
| 808 | | |
| 809 | | |