Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp10208imm; Thu, 13 Sep 2018 14:44:40 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ7tLRjpLMc9/H+z+AM7lNlHJk144+wCydZWbaH4rIv8ds9irb/r3Jd01z/naBl9mItj9yV X-Received: by 2002:a62:3001:: with SMTP id w1-v6mr9155932pfw.19.1536875080774; Thu, 13 Sep 2018 14:44:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536875080; cv=none; d=google.com; s=arc-20160816; b=Xl1jSnwXa029cDYExo9T0seHk2Kly0hBJWGMlErX4kaSpl1Z/zoWG1jtjFhJfLMxBM lM1yeemZ3HIbUuUrfws+dhnQA7yNrQCqJjHF+emsEg7E81dPOHwxPakZX/aCkJt042XO aFyqyYqes2vzsRSfcn8zIeSAZ2F99gIAvPYadUxoEDeTtyoUxi0ewz7uRnzNcjypHpUQ mHiUPTy1TCIa4NQvDC4iSMFAL1rBrqdGKhyJVtxgYGuE7Kw2Yty/8E3TJeqIopk/Sxa9 3EelCkCBCh1rWZxX0BdHid2nFqVAC7u3P8p/KePo+RuJiXIVMi57LiHN85iiI9CLlFay yE4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=QC4xCRBf+sqKJaI3IajyAgsIYn5dr5uvIXjrxS/MNtg=; b=IxnFH6miOtmqfWUYKtZms1bgP4xEkVjqLVlFLnr70SgFiyN+/CZ6UrkyPuNNwJ7KxF ydgT2POBAosRv/Cfa3/SkMOHep1uAzJzO1WkWbSq2GLbxiljlxFPUE1LNOJ2RVR6z0Cr 4LjFYsuqT64EHNis0ye+rhjgNkSCntduktqj5OGvzaFlNVLae1IILIYXn9eDoidjFfGf Zb/COzInjJzdx9AxUrOMEZG6QGIReJBe4XKgbhPWgluA7QKPPvbczByA3Up6ukrEBK3S 5I82N3TOmcS02Nl3fAsSRx/M5lichtZNw6Zzqo0iKfWLFEl+btOmVM3hhIUlK7hogCcy zf4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=EJrt2maw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v84-v6si5031355pfd.71.2018.09.13.14.44.25; Thu, 13 Sep 2018 14:44:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@konsulko.com header.s=google header.b=EJrt2maw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728239AbeINCzI (ORCPT + 99 others); Thu, 13 Sep 2018 22:55:08 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:38320 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727773AbeINCzI (ORCPT ); Thu, 13 Sep 2018 22:55:08 -0400 Received: by mail-io1-f68.google.com with SMTP id y3-v6so4424932ioc.5 for ; Thu, 13 Sep 2018 14:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QC4xCRBf+sqKJaI3IajyAgsIYn5dr5uvIXjrxS/MNtg=; b=EJrt2mawuW9zJlvzt5xdRxqky8DEB+JBFpMcWdyCDS4xjb81alTbs+JIbuWQC8IuKS ox/U1HqtI9+s7g243F7R10Fze89kt1Adc3UkHLzqWl5xht9A4D+FdrnbkoU/LIZnBm5Z 2/N4dxr2Ny7i6F/yq3xPwyzvMSWSL9/nyqI8o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QC4xCRBf+sqKJaI3IajyAgsIYn5dr5uvIXjrxS/MNtg=; b=MkhTJy1BhiU1pYmh4HzVPvxeef/M9J4MzDzvZFeNrxeWC86CuiCpOyCbRrcu+pLvI7 /QJQPaxiiXFMjM19IpigC6r3rdXeauIJuAv65uat3ae2mF0vTM8HD/T2kdHIzV6P+WY4 ulobkXgF+Ei+MZ7cF0qt6r8i/rQv5tSZJzntodvyrxbzfE+L020MO60hJXknz6UvVbNM SLFa5UlHzKKhd3zrWaSCMsL/+WoEObe/jMddzoZHY+Utmbgv+YP6wWvfp3omwJAv8BCn GIyyYiAPQe3iXd2GRO+/W5NFRTy4DwihmzzEy+1VLW48wRcFS2LE4UjLaq9hdUWOAm8W eN0Q== X-Gm-Message-State: APzg51AbBW8ilyq23U5dGQUm7qq99pWFumC5unGiSSEsn577ngDhkYhw 64P6msBimW06TLNC5aakBOVCE1Jtswo1Ig0Lwq0K/g== X-Received: by 2002:a6b:ac45:: with SMTP id v66-v6mr8385048ioe.66.1536875028000; Thu, 13 Sep 2018 14:43:48 -0700 (PDT) MIME-Version: 1.0 References: <20180913035145.28056-1-songqiang.1304521@gmail.com> In-Reply-To: <20180913035145.28056-1-songqiang.1304521@gmail.com> From: Matt Ranostay Date: Thu, 13 Sep 2018 14:43:35 -0700 Message-ID: Subject: Re: [PATCH] iio: proximity: lidar-v2: replace i2c block access method with the one already implemented. To: songqiang1304521@gmail.com Cc: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, songqiang.1304521@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 12, 2018 at 8:51 PM Song Qiang wrote: > > 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. > Yes actually there is a reason for this insanity! It isn't actually SMBUS (note the lidar_smbus_xfer function below it) and has a odd way to read registers via I2C. Basically the I2C_M_STOP flags is the reason you can use the standard i2c_smbus_read_i2c_block_data(). Page 6 in this datasheet * http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf > Signed-off-by: Song Qiang > --- > .../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 >