RE: [PATCH 2/5] i2c: mux: mlxcpld: make use of __i2c_smbus_xfer

From: Michael Shych
Date: Wed Jun 20 2018 - 05:11:34 EST




> -----Original Message-----
> From: Peter Rosin [mailto:peda@xxxxxxxxxx]
> Sent: Wednesday, June 20, 2018 11:52 AM
> To: linux-kernel@xxxxxxxxxxxxxxx
> Cc: Peter Rosin <peda@xxxxxxxxxx>; Wolfram Sang <wsa@xxxxxxxxxxxxx>;
> Vadim Pasternak <vadimp@xxxxxxxxxxxx>; Michael Shych
> <michaelsh@xxxxxxxxxxxx>; Guenter Roeck <linux@xxxxxxxxxxxx>;
> Akinobu Mita <akinobu.mita@xxxxxxxxx>; Jean Delvare
> <jdelvare@xxxxxxxx>; linux-i2c@xxxxxxxxxxxxxxx
> Subject: [PATCH 2/5] i2c: mux: mlxcpld: 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: Peter Rosin <peda@xxxxxxxxxx>

Acked-by: Michael Shych <michaelsh@xxxxxxxxxxxx>

> ---
> drivers/i2c/muxes/i2c-mux-mlxcpld.c | 28 ++++------------------------
> 1 file changed, 4 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/i2c/muxes/i2c-mux-mlxcpld.c b/drivers/i2c/muxes/i2c-
> mux-mlxcpld.c
> index 12ad8d65faf6..f2bf3e57ed67 100644
> --- a/drivers/i2c/muxes/i2c-mux-mlxcpld.c
> +++ b/drivers/i2c/muxes/i2c-mux-mlxcpld.c
> @@ -94,31 +94,11 @@ static int mlxcpld_mux_reg_write(struct i2c_adapter
> *adap,
> struct i2c_client *client, u8 val)
> {
> struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&client-
> >dev);
> - int ret = -ENODEV;
> -
> - if (adap->algo->master_xfer) {
> - struct i2c_msg msg;
> - u8 msgbuf[] = {pdata->sel_reg_addr, val};
> -
> - msg.addr = client->addr;
> - msg.flags = 0;
> - msg.len = 2;
> - msg.buf = msgbuf;
> - ret = __i2c_transfer(adap, &msg, 1);
> -
> - if (ret >= 0 && ret != 1)
> - ret = -EREMOTEIO;
> - } else if (adap->algo->smbus_xfer) {
> - union i2c_smbus_data data;
> -
> - data.byte = val;
> - ret = adap->algo->smbus_xfer(adap, client->addr,
> - client->flags, I2C_SMBUS_WRITE,
> - pdata->sel_reg_addr,
> - I2C_SMBUS_BYTE_DATA, &data);
> - }
> + union i2c_smbus_data data = { .byte = val };
>
> - return ret;
> + return __i2c_smbus_xfer(adap, client->addr, client->flags,
> + I2C_SMBUS_WRITE, pdata->sel_reg_addr,
> + I2C_SMBUS_BYTE_DATA, &data);
> }
>
> static int mlxcpld_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
> --
> 2.11.0