aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/i2c/i2c-core-base.c64
-rw-r--r--include/linux/i2c.h34
2 files changed, 48 insertions, 50 deletions
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index b6ca97f0322b..bb34a5d41133 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -1911,63 +1911,35 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1911EXPORT_SYMBOL(i2c_transfer); 1911EXPORT_SYMBOL(i2c_transfer);
1912 1912
1913/** 1913/**
1914 * i2c_master_send - issue a single I2C message in master transmit mode 1914 * i2c_transfer_buffer_flags - issue a single I2C message transferring data
1915 * to/from a buffer
1915 * @client: Handle to slave device 1916 * @client: Handle to slave device
1916 * @buf: Data that will be written to the slave 1917 * @buf: Where the data is stored
1917 * @count: How many bytes to write, must be less than 64k since msg.len is u16 1918 * @count: How many bytes to transfer, must be less than 64k since msg.len is u16
1919 * @flags: The flags to be used for the message, e.g. I2C_M_RD for reads
1918 * 1920 *
1919 * Returns negative errno, or else the number of bytes written. 1921 * Returns negative errno, or else the number of bytes transferred.
1920 */ 1922 */
1921int i2c_master_send(const struct i2c_client *client, const char *buf, int count) 1923int i2c_transfer_buffer_flags(const struct i2c_client *client, char *buf,
1924 int count, u16 flags)
1922{ 1925{
1923 int ret; 1926 int ret;
1924 struct i2c_adapter *adap = client->adapter; 1927 struct i2c_msg msg = {
1925 struct i2c_msg msg; 1928 .addr = client->addr,
1926 1929 .flags = flags | (client->flags & I2C_M_TEN),
1927 msg.addr = client->addr; 1930 .len = count,
1928 msg.flags = client->flags & I2C_M_TEN; 1931 .buf = buf,
1929 msg.len = count; 1932 };
1930 msg.buf = (char *)buf;
1931
1932 ret = i2c_transfer(adap, &msg, 1);
1933
1934 /*
1935 * If everything went ok (i.e. 1 msg transmitted), return #bytes
1936 * transmitted, else error code.
1937 */
1938 return (ret == 1) ? count : ret;
1939}
1940EXPORT_SYMBOL(i2c_master_send);
1941
1942/**
1943 * i2c_master_recv - issue a single I2C message in master receive mode
1944 * @client: Handle to slave device
1945 * @buf: Where to store data read from slave
1946 * @count: How many bytes to read, must be less than 64k since msg.len is u16
1947 *
1948 * Returns negative errno, or else the number of bytes read.
1949 */
1950int i2c_master_recv(const struct i2c_client *client, char *buf, int count)
1951{
1952 struct i2c_adapter *adap = client->adapter;
1953 struct i2c_msg msg;
1954 int ret;
1955
1956 msg.addr = client->addr;
1957 msg.flags = client->flags & I2C_M_TEN;
1958 msg.flags |= I2C_M_RD;
1959 msg.len = count;
1960 msg.buf = buf;
1961 1933
1962 ret = i2c_transfer(adap, &msg, 1); 1934 ret = i2c_transfer(client->adapter, &msg, 1);
1963 1935
1964 /* 1936 /*
1965 * If everything went ok (i.e. 1 msg received), return #bytes received, 1937 * If everything went ok (i.e. 1 msg transferred), return #bytes
1966 * else error code. 1938 * transferred, else error code.
1967 */ 1939 */
1968 return (ret == 1) ? count : ret; 1940 return (ret == 1) ? count : ret;
1969} 1941}
1970EXPORT_SYMBOL(i2c_master_recv); 1942EXPORT_SYMBOL(i2c_transfer_buffer_flags);
1971 1943
1972/* ---------------------------------------------------- 1944/* ----------------------------------------------------
1973 * the i2c address scanning function 1945 * the i2c address scanning function
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 9d9d379b5a15..5ac0f9055715 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -63,10 +63,36 @@ struct property_entry;
63 * transmit an arbitrary number of messages without interruption. 63 * transmit an arbitrary number of messages without interruption.
64 * @count must be be less than 64k since msg.len is u16. 64 * @count must be be less than 64k since msg.len is u16.
65 */ 65 */
66extern int i2c_master_send(const struct i2c_client *client, const char *buf, 66extern int i2c_transfer_buffer_flags(const struct i2c_client *client,
67 int count); 67 char *buf, int count, u16 flags);
68extern int i2c_master_recv(const struct i2c_client *client, char *buf, 68
69 int count); 69/**
70 * i2c_master_recv - issue a single I2C message in master receive mode
71 * @client: Handle to slave device
72 * @buf: Where to store data read from slave
73 * @count: How many bytes to read, must be less than 64k since msg.len is u16
74 *
75 * Returns negative errno, or else the number of bytes read.
76 */
77static inline int i2c_master_recv(const struct i2c_client *client,
78 char *buf, int count)
79{
80 return i2c_transfer_buffer_flags(client, buf, count, I2C_M_RD);
81};
82
83/**
84 * i2c_master_send - issue a single I2C message in master transmit mode
85 * @client: Handle to slave device
86 * @buf: Data that will be written to the slave
87 * @count: How many bytes to write, must be less than 64k since msg.len is u16
88 *
89 * Returns negative errno, or else the number of bytes written.
90 */
91static inline int i2c_master_send(const struct i2c_client *client,
92 const char *buf, int count)
93{
94 return i2c_transfer_buffer_flags(client, (char *)buf, count, 0);
95};
70 96
71/* Transfer num messages. 97/* Transfer num messages.
72 */ 98 */