From patchwork Tue Nov 28 12:57:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10080259 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 9388A60353 for ; Tue, 28 Nov 2017 12:58:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFCA928438 for ; Tue, 28 Nov 2017 12:58:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A47FE2881A; Tue, 28 Nov 2017 12:58:05 +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 53F5A28438 for ; Tue, 28 Nov 2017 12:58:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752355AbdK1M6E (ORCPT ); Tue, 28 Nov 2017 07:58:04 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:63215 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752561AbdK1M6D (ORCPT ); Tue, 28 Nov 2017 07:58:03 -0500 Received: from localhost ([46.78.234.13]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.183]) with ESMTPSA (Nemesis) id 0LjtbV-1eqWEX42Ez-00bs3y; Tue, 28 Nov 2017 13:57:49 +0100 Date: Tue, 28 Nov 2017 13:57:59 +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 2/2] iio: hx711: fix bug in reset functionality Message-ID: <20171128125759.GA31842@arbeit> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:a+x+yqplNFGf1fDEQxrPIBID/6HQBoWYiedXWG0Iyw2CjphpAe6 poStfRT8Pi/uKFhGMb6Ht9IUXXGBUL3VV07APEYJQQP53uudFMJlIpVKESrzAWD6G351Q9Y iVO7hcTZ0T0j1WeJtvwaUAsSQ+Q0U0wz6IhK3WMH50RVvF0Nwdrtm/lVDCGxx8siSSA3nDW 9Z+7edQzLlhbsgOeX3JeQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:uxa6nq+rhSc=:Vymte0Gr1tVSZ+1gqwSGrT gs/plMuQEjU+IZfuoIyB25xxRw/GUvZ4UQQKMWKIIRodSjZBFRVUs26tcH9PICk5HJwc9MAWI WvgesJbTOG1sQhRQ19EifobdZ4gOS4dbk6vz5ZVbBo1DbL9kKyA5+wWvhYyB4ffkz9rbIb+/T OUzXYso5bBchm0EjUemGjllwtqVNESX5RrvhlwNcHnav+xknfBlfgfE8kcfA4a1GFDJU4ZTvI Oaf6FLbbZEKosucLCQi7vBjxGiThRaqfukFNEuX8/2wgnEr0ZX79JgS8REKBRvG2GjgayNdQ5 uv8PHgn+egQ/72Vi9wTGHgEpOyJ4FmzBXLfySeEqcW88GG5QrsC6oztjmtZAx9bWM1D1OVF6Z PLJASZxpIhPh4tZ9HUIS3RdvmjhEgVCmaSxvVhpMGsdwjnRNBMu5eNgCUqNv8bnhlDPOh1WH2 CcYQCqOm8Sm7EZkd5Fs7/M+P6wo+qZPi4X+qG0iIkwk/bSGRVNnCHxaujdPwbGfPGvGqF/Pte 3kMssj0LMu212NpwncEoz3GRSrqmsIsXXAEr0xMgOc6WGu174v2Io5qYTAZkHuEneoN3FHN3w OwgzutD1fnIY1YNOKR+WDIJXTR9qjpSoy/Wtn4M4qDK/hHif3oMzpo0/i2+mNqEMFCzw57yYq EBQ/99eqOdbmarRaX6fihmEcq6SiPSiiuXSsCqAlZ3lQPx7/vuZuaXMEnLzP4YfKOcTDT4vI5 7e9GplkTHuzezPqWe8SiCSbLWU/4c8VGJCAgOw== 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;