From patchwork Thu Nov 30 21:44:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10085697 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 0D157602B9 for ; Thu, 30 Nov 2017 21:44:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F28862A33B for ; Thu, 30 Nov 2017 21:44:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E76A12A340; Thu, 30 Nov 2017 21:44:57 +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 8BB962A33D for ; Thu, 30 Nov 2017 21:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751851AbdK3Voq (ORCPT ); Thu, 30 Nov 2017 16:44:46 -0500 Received: from mout.kundenserver.de ([217.72.192.73]:52723 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750708AbdK3Vop (ORCPT ); Thu, 30 Nov 2017 16:44:45 -0500 Received: from localhost ([46.78.254.35]) by mrelayeu.kundenserver.de (mreue102 [212.227.15.183]) with ESMTPSA (Nemesis) id 0ML81x-1eKnc446jZ-000LMo; Thu, 30 Nov 2017 22:44:30 +0100 Date: Thu, 30 Nov 2017 22:44:45 +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 v2 2/2] iio: hx711: fix bug in reset functionality Message-ID: <20171130214445.GA27345@arbeit> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:vSrLtXhyzrRHw2E9O5ux65RPV8lqZm07oJzPP9qwI8tIZ8kJC2I 1hn7ReWDWBLuFds8C+DSQSEc8Z0UIYglo9qtTfX2po/Hq3ScIHOi8p27kqgrQrVQFUQUVL7 gChvZ9rGJnVxMkTwVtDxK9LH7HBCeOimUmdMsc/tFYxddC8xBMiUu0xmiBUteICO8tSwa7a EcmGlcX0pf0i9lJ79EJUA== X-UI-Out-Filterresults: notjunk:1; V01:K0:kK6NXecPd24=:+H/eQSt/ndwOFHmVNbeLuM v1Dczq89CtReTY2tYDi47LK2lYnZsYBEieH+IXUbU9IrTQ/cVqG0NNOlFF2PAKontq7K5SLV/ +c7Fgp9OmFD+sMTDLbDCoeG3wF8c9vmJBUz3IspnQhoDHnN5vrsdGyUWzKjKIjV38Lo0RNh84 9aDwOqGTQNSpYxKwmFOqhOLywrJeyU3X8ojjJNA+mVpBMTDZFWsWoI81kDkQLfGuypSK3k+QS Y7OPd5G3g1Q3RGCV8EWAhG0JD/cQSYc4/yBPbH+eg5QO6aE2x3FQlDR40NFz2DgVPCpJ4mXQ+ y6r4uWwtVmh0YtoHwpOO4f0opIS8rWL1yemGrLgfij7899u8gfNrc1GNCGEMYx05COA9l6YTg pG8p+bBqegZ40qeH+IxgLAcR3wMcKIDjZVv1ZNmHHUs3y/jJq+Q5rkoKNITWAt9+dkiig1nc5 5mTM/AjcYh56VlVa0hCcr5yVX2vaCj85xSx7D8OLHtvz7R6GrugCyJz4zuvF1AY8HCrc4Zp2d rj+ApA72hIbm2kYF/OZQIJfydA4kFf0igokPNGB+eeeaVdEZrTOeqsX2tvnsYkddJ32MYsYin B1cEaDMhalE6y0Tq335SAYJFsi4WHfGk4EEGYNGQaee03XKAqjnd+hx6HXGo6zR6qgPtsp2CV 74BjaJXc7oReKaJ9T5jxPPOar8YcnljgPScTyXwA+CMVMlrguezRtJUeOMOqM+4TQ/LqYrzMp BPucTTx25hDu/zoTwsOyNUwY9LO8DWSFZfhyiQ== 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 als false positive wait up to 1 second until the device is in normal state by changing the channel on every trigger event it turned out that the former 100 ms are not enough for waiting until the device is in 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 d773fd69a76d..eabd2e66aca3 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;