From patchwork Wed Dec 6 08:52:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10095089 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 3EDEE60567 for ; Wed, 6 Dec 2017 08:52:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 326E629730 for ; Wed, 6 Dec 2017 08:52:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24EF7297B9; Wed, 6 Dec 2017 08:52:24 +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 A14CB29730 for ; Wed, 6 Dec 2017 08:52:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753383AbdLFIwX (ORCPT ); Wed, 6 Dec 2017 03:52:23 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:51916 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753356AbdLFIwW (ORCPT ); Wed, 6 Dec 2017 03:52:22 -0500 Received: from localhost ([82.113.99.28]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MYeoM-1eZCkg1FgI-00VP2T; Wed, 06 Dec 2017 09:52:05 +0100 Date: Wed, 6 Dec 2017 09:52:20 +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 v3 2/2] iio: hx711: fix bug in reset functionality Message-ID: <20171206085220.GA15428@arbeit> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:nMDK7K1a5oZERVvGNk0U5O9srhGPx/58CG5wrMqCXkn16paFMCY 4jvysE5ifxCQQ8q2UdSz0UxkktI6A4Dfj7xch5KUicIV1a3ZDYWpL/TUlW41Sv4clTbZR/L fJb4I+rGKZ9E9fmiYAFcfB64Qtv+cmP8zSus2JQ/4MMcwnf13RdbCJH9F/PET4rrfYdp/A9 GYsyYf8FzIExsL1pA3cLA== X-UI-Out-Filterresults: notjunk:1; V01:K0:JwnX9PlII70=:DQ1HTAk2zfwvrkwpns/7KQ Y773cCY30NhUnrMKHsCuTIWoKIVSChi9qBw7Phu3QrnsfgMfe34i5mp7esMtal0oK/yA4UKEh 3j9R68RO633i6IDihbRujkd14UKquaQUYkes1ZTqUFo639li8PeQLUNIUKirMdJtG0re2uN1w zvsmcGS8QPz7gFmS3AFYRFwFFibxsip8B9QEzyp4S5Inw7LVdSLfucfFUEEksM1/PutpTqYXQ 1F1xRtc47wxrWy0haxwFeO6N8dwvLQNkuSeax61Z5/2Uge1w+4AFEh6p4Ipywt7EDoWh5x63O C+uPhBhBDVccATPjPJ6n5i5e6Hz1HETsQs7TKmOFGW+aensTfTHseKtrJX1F3gghcpWP3pmCd vyEwkBCnf7NI+XBzjs+jcs5J6xJ/JMYH6Aiw2HXsxsPqmSb7LhM8jfkc1CcvQ4O4yOUh1ra0P TLh7KZiBJdaCxEk26MnyLXg2gC8AD3I0X8ryllGHXMqtlKoYv4TlpKY084FBMocepbjwY2M0E DRhlLwmKsikxy9IpE+sc4hbJY+TNyFTF/1Z4jWbGQ/GNempzZgm6kiCpjZb0eCTrI+Ktxi9hr f3gSmnSsKYzMMfCEdrXt6lr9ugGcvK4yzUufVfexrGXzcfr4+vutxsn8tKEPtAR/++OEnyBsg bHUn+FyvtnB0X0zRboYuWmNdg4CTCTrvwWJNDhJOC20BgBgTDGIFxI5BmowTfXO4UiYflCe13 5dtqbQankjNHvJmRJVp+T5Y6URPS0VwkiVFi5A== 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 37982b93a227..0a2d0b6cd38a 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;