Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1110513ybd; Wed, 26 Jun 2019 11:22:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwnD7BlCI70W5yKbSUjoXlAsYUDXQHTS94y4eIZSLAukog89XUpTpArYVglT5xGDMZJrbWS X-Received: by 2002:a17:90a:be08:: with SMTP id a8mr470613pjs.69.1561573322564; Wed, 26 Jun 2019 11:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561573322; cv=none; d=google.com; s=arc-20160816; b=Vy2IwFHs+kG5CUexyAPxxOj8SKBi7Pt8EWGQsMqu+7z3peJ6S5+KOuVxwbsbP50wmr 2C43yXQNcckf07YczAcUM74ubdl96DGC5facVD7D8yK38PoVLT78na3X3xDbSmfSuyJz 5dBEI1xF6RWLcUcYocZTFGo5/2NlT5H96+L8Qd2fxa5N8Whz9p8I8ThktWZ5XhAdFfpD 5E9rnGdSG5vmz2IKbeBvme4EmcFi+zy4hwAYXNM44PFVZnrJ1dbQk1ECus8uAK7qv4NB RDuhJAibN0ZM/UqtfoT1isqO0WKymQ5QZVEuFcTjBeJ9cfP/lwvgscbhT43pF07lpuGq 9Btw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=dGf1o4n6l3ezI6eiX9s9YvYFYS5Rp6YS68UWtP5ABVs=; b=S/mCCzB2yGxRPP7bsufwcS2fNYSugCpF7p+cRX0FytXEI/7Mc2sgm60bkfyDy0d+Kl Ak6Qm5otNX4MfycvAVixr1o6K/HafgBYjFsAbNGwQdZx2XlbPj9F3G7bc7ftefRzhYcv NzCjEiUiDw42j7GYwvRE0vatnDFu1VrOpLXFz1rtvsAGxwo4SM7XHi0xhR5Rmf46djri f0JPTgX13y6yzA0BlFpQdrgIl9LDbx/QL+XANyuBpOHrom91iVo8dLm03ddT9mO6UEnS 7/LQ73HAXJauLq3/gT268uMM84HWfny/ZbofoRzs7q8vowee8nd3j5YSkKThv4zS/6EF aREQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2q7D+0HH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q7si17578721pgc.374.2019.06.26.11.21.44; Wed, 26 Jun 2019 11:22:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2q7D+0HH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726357AbfFZSVl (ORCPT + 99 others); Wed, 26 Jun 2019 14:21:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:35956 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726223AbfFZSVl (ORCPT ); Wed, 26 Jun 2019 14:21:41 -0400 Received: from archlinux (cpc149474-cmbg20-2-0-cust94.5-4.cable.virginm.net [82.4.196.95]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 562A02085A; Wed, 26 Jun 2019 18:21:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561573299; bh=0nQhYnLhLEeamrlQUtZb4J3UbsXQMGUaEnaKb6h4KfA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=2q7D+0HHhmGGjVKNFAt605mcCgei6si0y2xfuvpV1apJvaLIwMs1IWgmeVzTJpzxD 1aq6WX9joU9mxlXMCydTMDIjmyoosvUA04hdKHugFQeaseHuD6Uw2HLRs+TiDXBjMX bEkIx6emye3yzR1zNEwDcVfXMEJRLsNtylPJ8ekU= Date: Wed, 26 Jun 2019 19:21:34 +0100 From: Jonathan Cameron To: Andreas Klinger Cc: linux-iio@vger.kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, zbynek.kocur@fel.cvut.cz, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: srf04: fix wrong limitation in distance measuring Message-ID: <20190626192134.4b7aed3c@archlinux> In-Reply-To: <20190623122909.hhzskp6k5vm4wify@arbad> References: <20190623122909.hhzskp6k5vm4wify@arbad> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 23 Jun 2019 14:29:10 +0200 Andreas Klinger wrote: > The measured time value in the driver is limited to the maximum distance > which can be read by the sensor. This limitation was wrong and is fixed > by this patch. >=20 > It also takes into account that we are supporting a variety of sensors > today and that the recently added sensors have a higher maximum > distance range. >=20 > Suggested-by: Zbyn=C4=9Bk Kocur > Signed-off-by: Andreas Klinger Ideally I'm looking for Zbyn=C4=9Bk to confirm that this addresses the original question. Thanks, Jonathan > --- > drivers/iio/proximity/srf04.c | 29 +++++++++++++++-------------- > 1 file changed, 15 insertions(+), 14 deletions(-) >=20 > diff --git a/drivers/iio/proximity/srf04.c b/drivers/iio/proximity/srf04.c > index 8b50d56b0a03..01eb8cc63076 100644 > --- a/drivers/iio/proximity/srf04.c > +++ b/drivers/iio/proximity/srf04.c > @@ -110,7 +110,7 @@ static int srf04_read(struct srf04_data *data) > udelay(data->cfg->trigger_pulse_us); > gpiod_set_value(data->gpiod_trig, 0); > =20 > - /* it cannot take more than 20 ms */ > + /* it should not take more than 20 ms until echo is rising */ > ret =3D wait_for_completion_killable_timeout(&data->rising, HZ/50); > if (ret < 0) { > mutex_unlock(&data->lock); > @@ -120,7 +120,8 @@ static int srf04_read(struct srf04_data *data) > return -ETIMEDOUT; > } > =20 > - ret =3D wait_for_completion_killable_timeout(&data->falling, HZ/50); > + /* it cannot take more than 50 ms until echo is falling */ > + ret =3D wait_for_completion_killable_timeout(&data->falling, HZ/20); > if (ret < 0) { > mutex_unlock(&data->lock); > return ret; > @@ -135,19 +136,19 @@ static int srf04_read(struct srf04_data *data) > =20 > dt_ns =3D ktime_to_ns(ktime_dt); > /* > - * measuring more than 3 meters is beyond the capabilities of > - * the sensor > + * measuring more than 6,45 meters is beyond the capabilities of > + * the supported sensors > * =3D=3D> filter out invalid results for not measuring echos of > * another us sensor > * > * formula: > - * distance 3 m > - * time =3D ---------- =3D --------- =3D 9404389 ns > - * speed 319 m/s > + * distance 6,45 * 2 m > + * time =3D ---------- =3D ------------ =3D 40438871 ns > + * speed 319 m/s > * > * using a minimum speed at -20 =C2=B0C of 319 m/s > */ > - if (dt_ns > 9404389) > + if (dt_ns > 40438871) > return -EIO; > =20 > time_ns =3D dt_ns; > @@ -159,20 +160,20 @@ static int srf04_read(struct srf04_data *data) > * with Temp in =C2=B0C > * and speed in m/s > * > - * use 343 m/s as ultrasonic speed at 20 =C2=B0C here in absence of the > + * use 343,5 m/s as ultrasonic speed at 20 =C2=B0C here in absence of t= he > * temperature > * > * therefore: > - * time 343 > - * distance =3D ------ * ----- > - * 10^6 2 > + * time 343,5 time * 106 > + * distance =3D ------ * ------- =3D ------------ > + * 10^6 2 617176 > * with time in ns > * and distance in mm (one way) > * > - * because we limit to 3 meters the multiplication with 343 just > + * because we limit to 6,45 meters the multiplication with 106 just > * fits into 32 bit > */ > - distance_mm =3D time_ns * 343 / 2000000; > + distance_mm =3D time_ns * 106 / 617176; > =20 > return distance_mm; > }