From: Song Qiang <songqiang1304521@gmail.com>
To: jic23@kernel.org
Cc: knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net,
matt.ranostay@konsulko.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org,
Song Qiang <songqiang.1304521@gmail.com>
Subject: [PATCH] iio: proximity: lidar-v2: replace i2c block access method with the one already implemented.
Date: Thu, 13 Sep 2018 11:51:45 +0800 [thread overview]
Message-ID: <20180913035145.28056-1-songqiang.1304521@gmail.com> (raw)
This driver tries to access a block of data on a i2c bus and it tries
to manually make a device command frame and a consecutively read frame,
then uses i2c_transfer() to read data. But this has already been
implemented in i2c_smbus_read_i2c_block_data().
Sorry for not having this device by my hand, which is a little expansive
for me, but I have another i2c device and tested with both i2c_transfer()
and i2c_smbus_read_i2c_block_data() and they all ends the same.
I'm not familiar with the SMBus, don't know if the lidar_smbus_xfer()
function is the same as i2c_smbus_read_block_data()? The original code
is commented with something I'm not sure, but I think if it's a standard
SMBus, it should be able to use in here.
Hoping for someone to explain.
Signed-off-by: Song Qiang <songqiang.1304521@gmail.com>
---
.../iio/proximity/pulsedlight-lidar-lite-v2.c | 18 +-----------------
1 file changed, 1 insertion(+), 17 deletions(-)
diff --git a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
index 47af54f14756..ca880ba8e820 100644
--- a/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
+++ b/drivers/iio/proximity/pulsedlight-lidar-lite-v2.c
@@ -63,23 +63,7 @@ static const struct iio_chan_spec lidar_channels[] = {
static int lidar_i2c_xfer(struct lidar_data *data, u8 reg, u8 *val, int len)
{
- struct i2c_client *client = data->client;
- struct i2c_msg msg[2];
- int ret;
-
- msg[0].addr = client->addr;
- msg[0].flags = client->flags | I2C_M_STOP;
- msg[0].len = 1;
- msg[0].buf = (char *) ®
-
- msg[1].addr = client->addr;
- msg[1].flags = client->flags | I2C_M_RD;
- msg[1].len = len;
- msg[1].buf = (char *) val;
-
- ret = i2c_transfer(client->adapter, msg, 2);
-
- return (ret == 2) ? 0 : -EIO;
+ return i2c_smbus_read_i2c_block_data(data->client, reg, len, val);
}
static int lidar_smbus_xfer(struct lidar_data *data, u8 reg, u8 *val, int len)
--
2.17.1
next reply other threads:[~2018-09-13 8:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-13 3:51 Song Qiang [this message]
2018-09-13 21:43 ` [PATCH] iio: proximity: lidar-v2: replace i2c block access method with the one already implemented Matt Ranostay
2018-09-14 1:48 ` Song Qiang
2018-09-14 12:09 ` Himanshu Jha
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=20180913035145.28056-1-songqiang.1304521@gmail.com \
--to=songqiang1304521@gmail.com \
--cc=jic23@kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt.ranostay@konsulko.com \
--cc=pmeerw@pmeerw.net \
--cc=songqiang.1304521@gmail.com \
/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).