Commit a5306b80 authored by Peter Rosin's avatar Peter Rosin Committed by Wolfram Sang

i2c: mux: pca9541: make use of __i2c_smbus_xfer

This simplifies the code, and you get retries for free if the adapter
does not support ->master_xfer.
Signed-off-by: default avatarPeter Rosin <peda@axentia.se>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent d7a0aef2
...@@ -99,31 +99,11 @@ MODULE_DEVICE_TABLE(of, pca9541_of_match); ...@@ -99,31 +99,11 @@ MODULE_DEVICE_TABLE(of, pca9541_of_match);
static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val) static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
{ {
struct i2c_adapter *adap = client->adapter; struct i2c_adapter *adap = client->adapter;
int ret; union i2c_smbus_data data = { .byte = val };
if (adap->algo->master_xfer) {
struct i2c_msg msg;
char buf[2];
msg.addr = client->addr;
msg.flags = 0;
msg.len = 2;
buf[0] = command;
buf[1] = val;
msg.buf = buf;
ret = __i2c_transfer(adap, &msg, 1);
} else {
union i2c_smbus_data data;
data.byte = val;
ret = adap->algo->smbus_xfer(adap, client->addr,
client->flags,
I2C_SMBUS_WRITE,
command,
I2C_SMBUS_BYTE_DATA, &data);
}
return ret; return __i2c_smbus_xfer(adap, client->addr, client->flags,
I2C_SMBUS_WRITE, command,
I2C_SMBUS_BYTE_DATA, &data);
} }
/* /*
...@@ -133,41 +113,14 @@ static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val) ...@@ -133,41 +113,14 @@ static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
static int pca9541_reg_read(struct i2c_client *client, u8 command) static int pca9541_reg_read(struct i2c_client *client, u8 command)
{ {
struct i2c_adapter *adap = client->adapter; struct i2c_adapter *adap = client->adapter;
union i2c_smbus_data data;
int ret; int ret;
u8 val;
ret = __i2c_smbus_xfer(adap, client->addr, client->flags,
if (adap->algo->master_xfer) { I2C_SMBUS_READ, command,
struct i2c_msg msg[2] = { I2C_SMBUS_BYTE_DATA, &data);
{
.addr = client->addr, return ret ?: data.byte;
.flags = 0,
.len = 1,
.buf = &command
},
{
.addr = client->addr,
.flags = I2C_M_RD,
.len = 1,
.buf = &val
}
};
ret = __i2c_transfer(adap, msg, 2);
if (ret == 2)
ret = val;
else if (ret >= 0)
ret = -EIO;
} else {
union i2c_smbus_data data;
ret = adap->algo->smbus_xfer(adap, client->addr,
client->flags,
I2C_SMBUS_READ,
command,
I2C_SMBUS_BYTE_DATA, &data);
if (!ret)
ret = data.byte;
}
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment