Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6555913ybx; Mon, 11 Nov 2019 10:53:40 -0800 (PST) X-Google-Smtp-Source: APXvYqwgIRdGrsVkeKLp4OQ4d6YO7wvazvMCDXx8fhir6ijqrqv4Xh+q+RqzPWVZhsYxp6ywt2PI X-Received: by 2002:aa7:d642:: with SMTP id v2mr27709537edr.175.1573498420753; Mon, 11 Nov 2019 10:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498420; cv=none; d=google.com; s=arc-20160816; b=lBRX/wXJ5+vB2COLBEK6fRejkDV6wUb9HOJaclsAZm4fUFPX355ofznFlTKFxHHdN+ GE5EPkZ/7kBCn29Ah9U5NhTn1+29/LU8kwyungRGTCcLJOpn+ONNMinWsX6yq1PwXy4H QPKCfdbgEyRCIZlQr2h1QkheNO3wrsXvsnFYbAMpKECmzXaBZ9k/5pajJof+H3qdmuO9 Ofn2YWAQpi3ujwaAX62Qvlmbw5lYV/qf6oP7mGipOtYIQ1qaE5U35BF9XAIt8wmv+93c T7eFmlPSowniB36w5fInzsbjNEdtZrrQCTIBlGamLA7bCltVZrFpK33rXEwRWRVhBuYp n3Lg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bn/VXEUU1ydWdwj1C7t9gHquHVKW7KarPzGsCgGfeOM=; b=XklEwF0LCNmKlBuVRnph6fdOhTdy8YiMQtpS6sJF58+zYqGO+c9sHNcXGIgf+WFuie +4U0clpVJMmEQXI7GtlPitOWd21sA7YPoUcQnyM31GF6f2fzbJLFbEA0eS2b/O4e8J9P u/eKSQS1SC+ZuQgxIbxCk4WAzGAgI14q4hQYFVpbyN3H3w6tV9sU2QggoawRiYbQofMJ h2gJj5+OpyUiGaUItbltjf/9QTpsNYxCipp9u+xXYq/m+An2c9QfzBhAjSWhTHLh7+jO 0VjWJ6Q4mwkIJc4PJq7i504IW43bGa4kUlj1tiudZuB3QVQJYTIlxL5HjxQluBRK9d/D FC8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Re/1U4yk"; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q4si9828303ejb.136.2019.11.11.10.53.16; Mon, 11 Nov 2019 10:53:40 -0800 (PST) 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="Re/1U4yk"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728461AbfKKSuc (ORCPT + 99 others); Mon, 11 Nov 2019 13:50:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:44242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730367AbfKKSua (ORCPT ); Mon, 11 Nov 2019 13:50:30 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 53800204FD; Mon, 11 Nov 2019 18:50:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498229; bh=IfH9tq6cL2VYhnjLG1DC36yApFqfu+QxjovjyIrrBio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Re/1U4ykr/DUJhz4M3Cw7SmpnT36BwH+AcOxT55dPCLwFbc0Rf7fYnknkffPVGaNU OXjlMFguiArFbpqiufcEtWnLP28S3nZdOn5N8J5ut/bvdRnPBqbEZ5N7u2FMSvMGRO 0E9daRYuBe9QvOa00ExgXgz8r3/kKQtO96poMizM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Zbyn=C4=9Bk=20Kocur?= , Andreas Klinger , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.3 059/193] iio: srf04: fix wrong limitation in distance measuring Date: Mon, 11 Nov 2019 19:27:21 +0100 Message-Id: <20191111181505.341643858@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andreas Klinger commit 431f7667bd6889a274913162dfd19cce9d84848e upstream. 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. 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. Changes in v2: - Added a Tested-by Suggested-by: Zbyněk Kocur Tested-by: Zbyněk Kocur Signed-off-by: Andreas Klinger Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/proximity/srf04.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) --- a/drivers/iio/proximity/srf04.c +++ b/drivers/iio/proximity/srf04.c @@ -110,7 +110,7 @@ static int srf04_read(struct srf04_data udelay(data->cfg->trigger_pulse_us); gpiod_set_value(data->gpiod_trig, 0); - /* it cannot take more than 20 ms */ + /* it should not take more than 20 ms until echo is rising */ ret = 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 return -ETIMEDOUT; } - ret = wait_for_completion_killable_timeout(&data->falling, HZ/50); + /* it cannot take more than 50 ms until echo is falling */ + ret = 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 dt_ns = 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 * ==> filter out invalid results for not measuring echos of * another us sensor * * formula: - * distance 3 m - * time = ---------- = --------- = 9404389 ns - * speed 319 m/s + * distance 6,45 * 2 m + * time = ---------- = ------------ = 40438871 ns + * speed 319 m/s * * using a minimum speed at -20 °C of 319 m/s */ - if (dt_ns > 9404389) + if (dt_ns > 40438871) return -EIO; time_ns = dt_ns; @@ -159,20 +160,20 @@ static int srf04_read(struct srf04_data * with Temp in °C * and speed in m/s * - * use 343 m/s as ultrasonic speed at 20 °C here in absence of the + * use 343,5 m/s as ultrasonic speed at 20 °C here in absence of the * temperature * * therefore: - * time 343 - * distance = ------ * ----- - * 10^6 2 + * time 343,5 time * 106 + * distance = ------ * ------- = ------------ + * 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 = time_ns * 343 / 2000000; + distance_mm = time_ns * 106 / 617176; return distance_mm; }