From patchwork Thu Sep 13 03:51:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Qiang X-Patchwork-Id: 10598681 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B87A921 for ; Thu, 13 Sep 2018 03:51:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B57C2A6B0 for ; Thu, 13 Sep 2018 03:51:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F4DB2A6B4; Thu, 13 Sep 2018 03:51:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD9BA2A6B0 for ; Thu, 13 Sep 2018 03:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726399AbeIMI73 (ORCPT ); Thu, 13 Sep 2018 04:59:29 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:44187 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726364AbeIMI72 (ORCPT ); Thu, 13 Sep 2018 04:59:28 -0400 Received: by mail-pg1-f196.google.com with SMTP id r1-v6so2076806pgp.11; Wed, 12 Sep 2018 20:51:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=m9xhX8/BiQDyqokLrSJV49GjJPvdwE/vv1tVO/83JB4=; b=tz6MHqpzXUn48EOsTIkd5kaYzdpSTA4zAkMmMu9ouTw/t3es2yTTNYDiY2xtXAHtf2 RAZurBQktwAbQ/Dq2BY3KteDjqp6rM2OuiFM1br00QGoAeipjE6yzL8JsoX61lgD6QFH tfC0MOkIf9xgQUQ2SzUcueoHkW4T8Ea4h62phv3yx5xIaCEfMIpOB3lZyk6/v2NkisJV FbfYO+hBbCKW+zXioNTmaRpZZV4fAe81Rxtw3Mhb7vU3U8gLfEr2CaYMSMCj5RygwaQW jBLCtK/lwEiHZVKhHpCma1pdrA4JNz1GKDztuLO+Bf3cXh3ykvAAYkXrMgPX5d1AiMFi yZHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=m9xhX8/BiQDyqokLrSJV49GjJPvdwE/vv1tVO/83JB4=; b=mKT0saecwu1CGZNgOJ9o+05ar4NMdL6MKqXHulZldkLq4V2xY8afL7FRJFrijFp/tZ rm78SoMkxlxpUGEKWsEyc1TBxs8/B1jW/5yA8IA5DOEhlOldejMMU5rqDgE0Q37EQoEr MAjytCoVAn1zLqdhXKv0AZ+yIR/VtFjBCxBN4XIUkPq+4zGbp0oWqxtK+UmCOfxbhKQG 6tz0/xhNgxU4T3bC4YR2bIeqiEgejkPEzu/jzH4uHs1Uzpb4tNGq4CABrqfQeu6a9HAc inO87w03F6MeTZfLyXXbN4xZNPsYJ44HVZtxdlUjbQKJt9JpmPVvzJBJinlcIx53enXr B3qg== X-Gm-Message-State: APzg51CCh4gnLcqXJ6l9j1oBPCt2B50+7IDiDGhlTmve7+7zRa2JlMwq 1k8zpVokL4RxQ5rtje2mJlg= X-Google-Smtp-Source: ANB0VdbCu/1XM0DbZxiO+JQKab1ZykY1UOUOBjOA6SvuTBnr5B8CCsnTdWK5NPo6B+GNzgaOvIDA8A== X-Received: by 2002:a63:4386:: with SMTP id q128-v6mr5055254pga.353.1536810711881; Wed, 12 Sep 2018 20:51:51 -0700 (PDT) Received: from localhost (104.176.229.35.bc.googleusercontent.com. [35.229.176.104]) by smtp.gmail.com with ESMTPSA id 83-v6sm4949499pft.40.2018.09.12.20.51.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Sep 2018 20:51:51 -0700 (PDT) From: Song Qiang X-Google-Original-From: Song Qiang 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 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 Message-Id: <20180913035145.28056-1-songqiang.1304521@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- .../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)