From patchwork Wed Dec 13 17:10:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10110423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40900602B3 for ; Wed, 13 Dec 2017 17:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2ABCF294EB for ; Wed, 13 Dec 2017 17:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F42329309; Wed, 13 Dec 2017 17:11:02 +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=-6.9 required=2.0 tests=BAYES_00,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 9BC9729510 for ; Wed, 13 Dec 2017 17:11:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753776AbdLMRLB (ORCPT ); Wed, 13 Dec 2017 12:11:01 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:56163 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753771AbdLMRK7 (ORCPT ); Wed, 13 Dec 2017 12:10:59 -0500 Received: from localhost ([2.247.254.144]) by mrelayeu.kundenserver.de (mreue004 [212.227.15.167]) with ESMTPSA (Nemesis) id 0LckOB-1er6j028u7-00k608; Wed, 13 Dec 2017 18:10:42 +0100 Date: Wed, 13 Dec 2017 18:10:34 +0100 From: Andreas Klinger To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, singhalsimran0@gmail.com, linux-iio@vger.kernel.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH v4 2/2] iio: hx711: fix bug in reset functionality Message-ID: <20171213171034.GA25360@arbeit> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:M+eQvnCRcFCnYv0sfxB8H0lSjzdefIIr7ZG6fx9L2Mw0LlEeuiX h9jaq6GehYWX4r9JGkSfLNhr9iw19sAKI2yXL7kXxUJDR01XF3uKdUOI/9uiV8ATP63Js7n FilP16D7jEEpVxNVi2oXNWKGL4ABx/rn8nc/FVCqLO1VKM9jeEpMoMlIQll6/aaVbnisjZf 5+RGCRrEHIPzS17tReWLw== X-UI-Out-Filterresults: notjunk:1; V01:K0:y0S3nPLn/kA=:UXFjDms2e1sYe//QvP6FL7 l7c8pR+VbrgSbydQpvAJiDTUS25/k8uxZiKnCecvJ+yJFatlnW45bPHb6OaEF9y0fN1UytbIu p5RCeEI2zfyt/sc4JRQHlBES5fT1iboW/gAoaQicF81tBL1S9BZR9Lhajz3GGhp08++5TngRZ go12n/68BISQk9rb5zovWb9G1n5/EChbLWe1UEwKUxf6b2kXXQ614ktydEsZbkP+riWbgpkvs qSombGiDoKjydlodxvJlbuTekt+LvQnrLm7L6JWlkf2XtuLQKjBChL2WDegiw6xon153Jm7+V C89xD/VsBndC0mgWgb5C74E1XssDsAYMThrU+fd3BR/qGPLvMRJbcZ1Dj87VotT7kmGsIkhIR O4mt92UuRiJ3jLJuEwSvyeqphNYyxd9D0H0FhRxxTRsbK0nuD5Wg+5uMNLBKNeliYJI/kmHg8 LjPOVQX6NblnBjRuijn7Zq1G/Z0nqA6nmYqc46AIkV7ISavMRr1cbSU4Ecq1280wHV93Ojzei Mdfzz8nfpwUbGl/8NMqC55au8QHe/Jtlw8N1J6KAQwvHUW93hlghzc7z4q87ePvkIzL6aKOqo AQuGM46i7kPYbGznMbxzaF2agYF5OtBc97Nv+wuUn6+680xxMrToVvs1XlyOKT0GwCNnL3n2N VbbpxQz7ozfZ1v4VB93NEDNXMvXjUjoQQpJGE3/i4ho42o3+gKZOEsKDfisj+59BOr2QzZiiu 3jTyyWBAEa6qk3LOIFjHHvwu6Ulm3ZKXO/A5XQ== 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 Return value in hx711_reset() should indicate status of dout otherwise the calling function is reporting an error as false positive If there are two reads too close to each other, then the second one will never succeed. This happens especially when using buffered mode with both channels enabled. When changing the channel on every trigger event the former 100 ms are not enough for waiting until the device indicates normal mode. Wait up to 1 second until the device turns into normal mode. Signed-off-by: Andreas Klinger --- drivers/iio/adc/hx711.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/hx711.c b/drivers/iio/adc/hx711.c index a38162ee7dcb..9430b54121e0 100644 --- a/drivers/iio/adc/hx711.c +++ b/drivers/iio/adc/hx711.c @@ -153,15 +153,16 @@ static int hx711_wait_for_ready(struct hx711_data *hx711_data) int i, val; /* - * a maximum reset cycle time of 56 ms was measured. - * we round it up to 100 ms + * in some rare cases the reset takes quite a long time + * especially when the channel is changed. + * Allow up to one second for it */ for (i = 0; i < 100; i++) { val = gpiod_get_value(hx711_data->gpiod_dout); if (!val) break; - /* sleep at least 1 ms */ - msleep(1); + /* sleep at least 10 ms */ + msleep(10); } if (val) return -EIO; @@ -203,9 +204,7 @@ static int hx711_reset(struct hx711_data *hx711_data) * after a dummy read we need to wait vor readiness * for not mixing gain pulses with the clock */ - ret = hx711_wait_for_ready(hx711_data); - if (ret) - return ret; + val = hx711_wait_for_ready(hx711_data); } return val;