From: Peter Rosin <peda@axentia.se>
To: linux-kernel@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>, Wolfram Sang <wsa@the-dreams.de>,
Vadim Pasternak <vadimp@mellanox.com>,
Michael Shych <michaelsh@mellanox.com>,
Guenter Roeck <linux@roeck-us.net>,
Akinobu Mita <akinobu.mita@gmail.com>,
Jean Delvare <jdelvare@suse.com>,
linux-i2c@vger.kernel.org
Subject: [PATCH 3/5] i2c: mux: pca9541: make use of __i2c_smbus_xfer
Date: Wed, 20 Jun 2018 10:51:55 +0200 [thread overview]
Message-ID: <20180620085157.30121-4-peda@axentia.se> (raw)
In-Reply-To: <20180620085157.30121-1-peda@axentia.se>
This simplifies the code, and you get retries for free if the adapter
does not support ->master_xfer.
Signed-off-by: Peter Rosin <peda@axentia.se>
---
drivers/i2c/muxes/i2c-mux-pca9541.c | 69 ++++++-------------------------------
1 file changed, 11 insertions(+), 58 deletions(-)
diff --git a/drivers/i2c/muxes/i2c-mux-pca9541.c b/drivers/i2c/muxes/i2c-mux-pca9541.c
index 6a39adaf433f..3d8c938e99e7 100644
--- a/drivers/i2c/muxes/i2c-mux-pca9541.c
+++ b/drivers/i2c/muxes/i2c-mux-pca9541.c
@@ -99,31 +99,11 @@ MODULE_DEVICE_TABLE(of, pca9541_of_match);
static int pca9541_reg_write(struct i2c_client *client, u8 command, u8 val)
{
struct i2c_adapter *adap = client->adapter;
- int ret;
-
- 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);
- }
+ union i2c_smbus_data data = { .byte = val };
- 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)
static int pca9541_reg_read(struct i2c_client *client, u8 command)
{
struct i2c_adapter *adap = client->adapter;
+ union i2c_smbus_data data;
int ret;
- u8 val;
-
- if (adap->algo->master_xfer) {
- struct i2c_msg msg[2] = {
- {
- .addr = client->addr,
- .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;
+
+ ret = __i2c_smbus_xfer(adap, client->addr, client->flags,
+ I2C_SMBUS_READ, command,
+ I2C_SMBUS_BYTE_DATA, &data);
+
+ return ret ?: data.byte;
}
/*
--
2.11.0
next prev parent reply other threads:[~2018-06-20 8:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-20 8:51 [PATCH 0/5] i2c: smbus: add unlocked __i2c_smbus_xfer variant Peter Rosin
2018-06-20 8:51 ` [PATCH 1/5] " Peter Rosin
2018-06-26 2:37 ` Wolfram Sang
2018-06-26 11:54 ` Peter Rosin
2018-06-26 13:46 ` Wolfram Sang
2018-06-27 4:18 ` Peter Rosin
2018-06-27 7:08 ` Wolfram Sang
2018-07-01 12:13 ` Wolfram Sang
2018-07-01 16:40 ` Peter Rosin
2018-06-20 8:51 ` [PATCH 2/5] i2c: mux: mlxcpld: make use of __i2c_smbus_xfer Peter Rosin
2018-06-20 9:11 ` Michael Shych
2018-06-20 8:51 ` Peter Rosin [this message]
2018-06-20 8:51 ` [PATCH 4/5] i2c: mux: pca954x: " Peter Rosin
2018-06-20 8:51 ` [PATCH 5/5] i2c: mux: " Peter Rosin
2018-07-03 21:01 ` [PATCH 0/5] i2c: smbus: add unlocked __i2c_smbus_xfer variant Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180620085157.30121-4-peda@axentia.se \
--to=peda@axentia.se \
--cc=akinobu.mita@gmail.com \
--cc=jdelvare@suse.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=michaelsh@mellanox.com \
--cc=vadimp@mellanox.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).