From patchwork Mon Nov 18 07:35:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 11249021 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8ECA1593 for ; Mon, 18 Nov 2019 07:36:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B268420726 for ; Mon, 18 Nov 2019 07:36:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726813AbfKRHgd (ORCPT ); Mon, 18 Nov 2019 02:36:33 -0500 Received: from mout.kundenserver.de ([212.227.126.134]:54791 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbfKRHgc (ORCPT ); Mon, 18 Nov 2019 02:36:32 -0500 Received: from localhost ([185.35.208.129]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MSI6i-1iPxjA08gS-00Sf2D; Mon, 18 Nov 2019 08:35:56 +0100 Date: Mon, 18 Nov 2019 08:35:55 +0100 From: Andreas Klinger To: robh+dt@kernel.org, jic23@kernel.org, mark.rutland@arm.com Cc: mripard@kernel.org, shawnguo@kernel.org, heiko@sntech.de, icenowy@aosc.io, laurent.pinchart@ideasonboard.com, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, christophe.jaillet@wanadoo.fr, tglx@linutronix.de, mchehab+samsung@kernel.org, davem@davemloft.net, paulmck@linux.ibm.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] dt-bindings: add vendor prefix parallax Message-ID: <20191118073553.2df736if7xk65e3y@arbad> MIME-Version: 1.0 Content-Disposition: inline User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5HeEd W1+E1wzBdHB6/ERl3xv0ypQlj6czVrqyXrx0AuBMEu88Pwjy5cfkUZQV3bcbJ+yV8wzJRqj+4 BI163WnfQTRBwenJhDCOltTiCaNAF+5Zv+0FTxFQTGmoDGsPx1wc2PcetNp6Hp+M54ZPb7Xko zYiPaSZA2K9NlBBNsa0Y3It0iAn/sfEIoBSuihrPM= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add new vendor prefix parallax for newly created ping iio sensors. Signed-off-by: Andreas Klinger Acked-by: Rob Herring --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml index 967e78c5ec0a..d3f9690e1e4b 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -713,6 +713,8 @@ patternProperties: description: Panasonic Corporation "^parade,.*": description: Parade Technologies Inc. + "^parallax,.*": + description: Parallax Inc. "^pda,.*": description: Precision Design Associates, Inc. "^pericom,.*": From patchwork Mon Nov 18 07:36:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 11249023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4FB2C1390 for ; Mon, 18 Nov 2019 07:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 39224206F4 for ; Mon, 18 Nov 2019 07:36:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726666AbfKRHgt (ORCPT ); Mon, 18 Nov 2019 02:36:49 -0500 Received: from mout.kundenserver.de ([212.227.126.130]:55427 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726400AbfKRHgt (ORCPT ); Mon, 18 Nov 2019 02:36:49 -0500 Received: from localhost ([185.35.208.129]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MnpP8-1i3dg71iXK-00pOvd; Mon, 18 Nov 2019 08:36:13 +0100 Date: Mon, 18 Nov 2019 08:36:12 +0100 From: Andreas Klinger To: robh+dt@kernel.org, jic23@kernel.org, mark.rutland@arm.com Cc: mripard@kernel.org, shawnguo@kernel.org, heiko@sntech.de, icenowy@aosc.io, laurent.pinchart@ideasonboard.com, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, christophe.jaillet@wanadoo.fr, tglx@linutronix.de, mchehab+samsung@kernel.org, davem@davemloft.net, paulmck@linux.ibm.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] dt-bindings: add parallax ping sensors Message-ID: <20191118073611.pvge47kgupu6omrf@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:yVseu36YheWCygoGq+ft3p0e0iu8fgGoKVfl3cImcfWXq7IcQ9v 64IAheX8Irfb2fO312Ve/wzH2zy/MAH7M+GlZpMlrXI3zSCniIfWpiaD6/Skwy6o/TifgE9 NzCq2LrIS+SsWfF+DB98Du8F691gjwNijTTZtEKyRkDS968omddwyzSGzj/oA2FMtBacECv bgNshXrgyCIa5aLeWs3+g== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:DYhdsw6dcKk=:NqfLp2QdMcVk0WkrnIOvz5 b6dteCGGPpVjdM/dysyfVLmCY+HICoFmMOMYrZoXxDGp/J/4yb0IPJL0ZEaw3y3pwk5ISwM7Y TmkMMQzkkrCGeMlbVxfozmx3eWunPL+FrQD8DzXIagziVyl8hNOHngXhXZ7rbHKOK8JE6Sucy 6OcoHhP5AGR+VNi7081U3VFobDQ2/i8LKUjQ6dGtafMpkxG3KooDzfPk/h0/UJLEJIHylfy3h Lw3PYEpXOW67n71SdjaCAIQsvDvEO35x1CFdUbTb/+m++iLeM+jm1CMPYFq9Xr1PzXrYqubcT AwDF+H7rliM68BRXPl9fA3fi87mXaO3kLI6t2Fpj55UgFV7pHl+yUpU9VjsDfmbW/AYT0F8B/ 5M+Txa4cNfii5/0mWgeIGWg9EHLS8KhAhCj0XxzxJRGiHDu13z//D7iWD2CvOmEauHS6ds4Q2 MO6yXeYkNCJVhgXEdK3iDK69tkJj4KrhmkZijmf6rajFkBld4oo9l93TeeutCW0ymArIeHIhX ELQ2BJM9y/guuhu0tEUzIbRz3hQzyaGluX0eazs+eU1VRq+Fjhh96Jhfaq9E0TV7vksI0mCzl A6a7CF7v3n4EI+JYIRMT+ReHZT8SaH4xMnbUM3tPbLkEosIwQsYqeoMSE5Hh/yVvsJOXWOuhV Sz6/9BAJDH7PTeC5AifoYx8a/V+U7cdMlFcgcIhrYdF4FtJbh7J6BPfyxr5kuFK0InzLs61oU AnGGuwmgmfvpia25DjhMhQyrUlCF9i7CkMXd95gvL6cxP7UD5J4X+g5OF4Se+JfZK5poopbZW UATJ90b8bz+1fBx0tEDkjAvsWfuLupffDHKJfVILz3NjC+7QhmwbDzKWdymUHAK4pSLdCfgAu HkjnhzY2BC22vtP699P7YSg4hrPHPxYgHy9Lu5wE4= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add dt-bindings for parallax PING))) and LaserPING iio sensors, which are used for measuring distances. Signed-off-by: Andreas Klinger Reviewed-by: Rob Herring --- .../bindings/iio/proximity/parallax-ping.yaml | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/proximity/parallax-ping.yaml diff --git a/Documentation/devicetree/bindings/iio/proximity/parallax-ping.yaml b/Documentation/devicetree/bindings/iio/proximity/parallax-ping.yaml new file mode 100644 index 000000000000..a079c9921af6 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/proximity/parallax-ping.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/proximity/parallax-ping.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Parallax PING))) and LaserPING range finder + +maintainers: + - Andreas Klinger + +description: | + Bit-banging driver using one GPIO: + - ping-gpios is raised by the driver to start measurement + - direction of ping-gpio is then switched into input with an interrupt + for receiving distance value as PWM signal + + Specifications about the devices can be found at: + http://parallax.com/sites/default/files/downloads/28041-LaserPING-2m-Rangefinder-Guide.pdf + http://parallax.com/sites/default/files/downloads/28015-PING-Documentation-v1.6.pdf + +properties: + compatible: + enum: + - parallax,ping + - parallax,laserping + + ping-gpios: + description: + Definition of the GPIO for the triggering and echo (output and input) + This GPIO is set for about 5 us by the driver to tell the device it + should initiate the measurement cycle. Afterwards the GPIO is switched + to input direction with an interrupt. The device sets it and the + length of the input signal corresponds to the measured distance. + It needs to be an GPIO which is able to deliver an interrupt because + the time between two interrupts is measured in the driver. + See Documentation/devicetree/bindings/gpio/gpio.txt for information + on how to specify a consumer gpio. + maxItems: 1 + +required: + - compatible + - ping-gpios + +examples: + - | + #include + proximity { + compatible = "parallax,laserping"; + ping-gpios = <&gpio0 26 GPIO_ACTIVE_HIGH>; + }; From patchwork Mon Nov 18 07:36:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 11249025 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AC0111390 for ; Mon, 18 Nov 2019 07:37:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8390E20726 for ; Mon, 18 Nov 2019 07:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726985AbfKRHhD convert rfc822-to-8bit (ORCPT ); Mon, 18 Nov 2019 02:37:03 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:55117 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbfKRHhC (ORCPT ); Mon, 18 Nov 2019 02:37:02 -0500 Received: from localhost ([185.35.208.129]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MKd92-1iIEUd1o2G-00KvUp; Mon, 18 Nov 2019 08:36:31 +0100 Date: Mon, 18 Nov 2019 08:36:30 +0100 From: Andreas Klinger To: robh+dt@kernel.org, jic23@kernel.org, mark.rutland@arm.com Cc: mripard@kernel.org, shawnguo@kernel.org, heiko@sntech.de, icenowy@aosc.io, laurent.pinchart@ideasonboard.com, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, christophe.jaillet@wanadoo.fr, tglx@linutronix.de, mchehab+samsung@kernel.org, davem@davemloft.net, paulmck@linux.ibm.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] iio: ping: add parallax ping sensors Message-ID: <20191118073629.54cjpk26zzf632bf@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:FCvJITshYaKuHJDXjosa0kriBOCumtZ8Uq+D/+df69O5f6gbRoL H4VJ4e2o0EeD26gFdR/KF5zbY+I9E2PpkDBRrBg/NPq/35QP9I4lspjviBcD/cFSpBUFZIG U1TN4oC8hsfyvzrrC+ZiJ+6C3tZPiVZsJpGa+zZFf+TNpGp3Kz7p3rI8PsBBFPreK7S9hFc cj64hGgTIF97BeQ0g0MHQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:boa6QTYlYeQ=:VaMuJy+fFnRRZrxFp5UlV2 dC1AjWoBGFQ+NI+NtHDLFhOTw4IGWW1Ual1RMeSD0zisx3MfVA9tLPjeVKgbaTSLp7zSLB0KM PZ8cHrHr9WdUMEApXLja366WGkFYvjvvyInHwWwgG9H+gMCfwVeMX9ec97obbLidY4UE1m6hq /q/TVWtYUyOhqJZWT5Jaqun6Q2oq2P8/XbfhO7PWPHjXnfv+pPaWqbgpq/FmuV1KbRt4XGdQa FMh02DGhyNGUtFmswJf66Mv03bZ5Z6e9geIIGusG6DBcOy5Gf3356leGm3WPa/Xcv/ROmLPz4 grdmuwlD/nyJkfw2UY6Rs0pwUu2/n1Ajm1/6yHqnhg8ajfroXy3OUnPYJpdxMMPXrMt/V2t/a BiNz48r1yMcn34qHJMOe+AsztB1jn0fItNc2oDedwXgDhjAqsOK2NCvibmJpOw14Mw3kt34m+ UUMItnIRamPbV8j1E4yjbpmK8c9tVEl0IQI/BR19QQLcOrNNuMEP/Fife8eKByRQ5HAOtVYVl uoLepkLplEBJuPtDkPul/qWmitnUMZN1JPhXAkCAs8vsadRHtxtkBzwDl7+W/AEEnRyGm04g/ OhGSEQdntO7ABJ3dL+OtmSQ1zC7mCVxKwP8FhdcsvpOs26S6Mn+c5R6n9UdT3CFWpF8M+NBQm 2XJfl+wcjcAo9FSEOIK45xZ9oYAbWIktvU+Eftmsw+f6cjGCMwFi2HRlQRp1xhsYuMLFOkt++ g+vwRJWR0ZMtsCwzMLFQ3HCAtP3yojoZHtbxJJ8MRbB+UmGArKYTG7jEArQVWPaD9HrLpMEEN td2TiXBzJKMxkyvpEMCMXEnb0Ocs4PQ3CbwnJqtcNtI6RVM6qEEfrzYuX3TUy/FuzkDET0cet RsuApecopabClj9sfjTyhawIUXQoz9K1WVNjPGfz0= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add support for parallax ping and laser ping sensors with just one pin for trigger and echo signal. This driver is based on srf04. In contrast to it it's necessary to change direction of the pin and to request the irq just for the period when the echo is rising and falling. Because this adds a lot of cases there is this individual driver for handling this type of sensors. Add a new configuration variable CONFIG_PING to Kconfig and Makefile. Signed-off-by: Andreas Klinger --- drivers/iio/proximity/Kconfig | 15 ++ drivers/iio/proximity/Makefile | 1 + drivers/iio/proximity/ping.c | 333 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 349 insertions(+) create mode 100644 drivers/iio/proximity/ping.c diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig index d53601447da4..37606d400805 100644 --- a/drivers/iio/proximity/Kconfig +++ b/drivers/iio/proximity/Kconfig @@ -58,6 +58,21 @@ config MB1232 To compile this driver as a module, choose M here: the module will be called mb1232. +config PING + tristate "Parallax GPIO bitbanged ranger sensors" + depends on GPIOLIB + help + Say Y here to build a driver for GPIO bitbanged ranger sensors + with just one GPIO for the trigger and echo. This driver can be + used to measure the distance of objects. + + Actually supported are: + - Parallax PING))) (ultrasonic) + - Parallax LaserPING (time-of-flight) + + To compile this driver as a module, choose M here: the + module will be called ping. + config RFD77402 tristate "RFD77402 ToF sensor" depends on I2C diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile index 0bb5f9de13d6..c591b019304e 100644 --- a/drivers/iio/proximity/Makefile +++ b/drivers/iio/proximity/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_AS3935) += as3935.o obj-$(CONFIG_ISL29501) += isl29501.o obj-$(CONFIG_LIDAR_LITE_V2) += pulsedlight-lidar-lite-v2.o obj-$(CONFIG_MB1232) += mb1232.o +obj-$(CONFIG_PING) += ping.o obj-$(CONFIG_RFD77402) += rfd77402.o obj-$(CONFIG_SRF04) += srf04.o obj-$(CONFIG_SRF08) += srf08.o diff --git a/drivers/iio/proximity/ping.c b/drivers/iio/proximity/ping.c new file mode 100644 index 000000000000..81067338b1ce --- /dev/null +++ b/drivers/iio/proximity/ping.c @@ -0,0 +1,333 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * PING: ultrasonic sensor for distance measuring by using only one GPIOs + * + * Copyright (c) 2019 Andreas Klinger + * + * For details about the devices see: + * http://parallax.com/sites/default/files/downloads/28041-LaserPING-2m-Rangefinder-Guide.pdf + * http://parallax.com/sites/default/files/downloads/28015-PING-Documentation-v1.6.pdf + * + * the measurement cycle as timing diagram looks like: + * + * GPIO ___ ________________________ + * ping: __/ \____________/ \________________ + * ^ ^ ^ ^ + * |<->| interrupt interrupt + * udelay(5) (ts_rising) (ts_falling) + * |<---------------------->| + * . pulse time measured . + * . --> one round trip of ultra sonic waves + * ultra . . + * sonic _ _ _. . + * burst: _________/ \_/ \_/ \_________________________________________ + * . + * ultra . + * sonic _ _ _. + * echo: __________________________________/ \_/ \_/ \________________ + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct ping_cfg { + unsigned long trigger_pulse_us; /* length of trigger pulse */ + int laserping_error; /* support error code in */ + /* pulse width of laser */ + /* ping sensors */ + s64 timeout_ns; /* timeout in ns */ +}; + +struct ping_data { + struct device *dev; + struct gpio_desc *gpiod_ping; + struct mutex lock; + int irqnr; + ktime_t ts_rising; + ktime_t ts_falling; + struct completion rising; + struct completion falling; + const struct ping_cfg *cfg; +}; + +static const struct ping_cfg pa_ping_cfg = { + .trigger_pulse_us = 5, + .laserping_error = 0, + .timeout_ns = 18500000, /* 3 meters */ +}; + +static const struct ping_cfg pa_laser_ping_cfg = { + .trigger_pulse_us = 5, + .laserping_error = 1, + .timeout_ns = 15500000, /* 2 meters plus error codes */ +}; + +static irqreturn_t ping_handle_irq(int irq, void *dev_id) +{ + struct iio_dev *indio_dev = dev_id; + struct ping_data *data = iio_priv(indio_dev); + ktime_t now = ktime_get(); + + if (gpiod_get_value(data->gpiod_ping)) { + data->ts_rising = now; + complete(&data->rising); + } else { + data->ts_falling = now; + complete(&data->falling); + } + + return IRQ_HANDLED; +} + +static int ping_read(struct ping_data *data) +{ + int ret; + ktime_t ktime_dt; + s64 dt_ns; + u32 time_ns, distance_mm; + struct platform_device *pdev = to_platform_device(data->dev); + struct iio_dev *indio_dev = iio_priv_to_dev(data); + + /* + * just one read-echo-cycle can take place at a time + * ==> lock against concurrent reading calls + */ + mutex_lock(&data->lock); + + reinit_completion(&data->rising); + reinit_completion(&data->falling); + + gpiod_set_value(data->gpiod_ping, 1); + udelay(data->cfg->trigger_pulse_us); + gpiod_set_value(data->gpiod_ping, 0); + + ret = gpiod_direction_input(data->gpiod_ping); + if (ret < 0) { + mutex_unlock(&data->lock); + return ret; + } + + data->irqnr = gpiod_to_irq(data->gpiod_ping); + if (data->irqnr < 0) { + dev_err(data->dev, "gpiod_to_irq: %d\n", data->irqnr); + return data->irqnr; + } + + ret = request_irq(data->irqnr, ping_handle_irq, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, + pdev->name, indio_dev); + if (ret < 0) { + dev_err(data->dev, "request_irq: %d\n", ret); + return ret; + } + + /* 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) + goto err_reset_direction; + else if (ret == 0) { + ret = -ETIMEDOUT; + goto err_reset_direction; + } + + /* it cannot take more than 50 ms until echo is falling */ + ret = wait_for_completion_killable_timeout(&data->falling, HZ/20); + if (ret < 0) + goto err_reset_direction; + else if (ret == 0) { + ret = -ETIMEDOUT; + goto err_reset_direction; + } + + ktime_dt = ktime_sub(data->ts_falling, data->ts_rising); + + free_irq(data->irqnr, indio_dev); + + ret = gpiod_direction_output(data->gpiod_ping, GPIOD_OUT_LOW); + if (ret < 0) { + mutex_unlock(&data->lock); + return ret; + } + + mutex_unlock(&data->lock); + + dt_ns = ktime_to_ns(ktime_dt); + if (dt_ns > data->cfg->timeout_ns) { + dev_dbg(data->dev, "distance out of range: dt=%lldns\n", + dt_ns); + return -EIO; + } + + time_ns = dt_ns; + + /* + * read error code of laser ping sensor and give users chance to + * figure out error by using dynamic debuggging + */ + if (data->cfg->laserping_error) { + if ((time_ns > 12500000) && (time_ns <= 13500000)) { + dev_dbg(data->dev, "target too close or to far\n"); + return -EIO; + } + if ((time_ns > 13500000) && (time_ns <= 14500000)) { + dev_dbg(data->dev, "internal sensor error\n"); + return -EIO; + } + if ((time_ns > 14500000) && (time_ns <= 15500000)) { + dev_dbg(data->dev, "internal sensor timeout\n"); + return -EIO; + } + } + + /* + * the speed as function of the temperature is approximately: + * + * speed = 331,5 + 0,6 * Temp + * with Temp in °C + * and speed in m/s + * + * use 343,5 m/s as ultrasonic speed at 20 °C here in absence of the + * temperature + * + * therefore: + * time 343,5 time * 232 + * distance = ------ * ------- = ------------ + * 10^6 2 1350800 + * with time in ns + * and distance in mm (one way) + * + * because we limit to 3 meters the multiplication with 232 just + * fits into 32 bit + */ + distance_mm = time_ns * 232 / 1350800; + + return distance_mm; + +err_reset_direction: + free_irq(data->irqnr, indio_dev); + mutex_unlock(&data->lock); + + if (gpiod_direction_output(data->gpiod_ping, GPIOD_OUT_LOW)) + dev_dbg(data->dev, "error in gpiod_direction_output\n"); + return ret; +} + +static int ping_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long info) +{ + struct ping_data *data = iio_priv(indio_dev); + int ret; + + if (channel->type != IIO_DISTANCE) + return -EINVAL; + + switch (info) { + case IIO_CHAN_INFO_RAW: + ret = ping_read(data); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + /* + * maximum resolution in datasheet is 1 mm + * 1 LSB is 1 mm + */ + *val = 0; + *val2 = 1000; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static const struct iio_info ping_iio_info = { + .read_raw = ping_read_raw, +}; + +static const struct iio_chan_spec ping_chan_spec[] = { + { + .type = IIO_DISTANCE, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + }, +}; + +static const struct of_device_id of_ping_match[] = { + { .compatible = "parallax,ping", .data = &pa_ping_cfg}, + { .compatible = "parallax,laserping", .data = &pa_ping_cfg}, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_ping_match); + +static int ping_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct ping_data *data; + struct iio_dev *indio_dev; + + indio_dev = devm_iio_device_alloc(dev, sizeof(struct ping_data)); + if (!indio_dev) { + dev_err(dev, "failed to allocate IIO device\n"); + return -ENOMEM; + } + + data = iio_priv(indio_dev); + data->dev = dev; + data->cfg = of_device_get_match_data(dev); + + mutex_init(&data->lock); + init_completion(&data->rising); + init_completion(&data->falling); + + data->gpiod_ping = devm_gpiod_get(dev, "ping", GPIOD_OUT_LOW); + if (IS_ERR(data->gpiod_ping)) { + dev_err(dev, "failed to get ping-gpios: err=%ld\n", + PTR_ERR(data->gpiod_ping)); + return PTR_ERR(data->gpiod_ping); + } + + if (gpiod_cansleep(data->gpiod_ping)) { + dev_err(data->dev, "cansleep-GPIOs not supported\n"); + return -ENODEV; + } + + platform_set_drvdata(pdev, indio_dev); + + indio_dev->name = "ping"; + indio_dev->dev.parent = &pdev->dev; + indio_dev->info = &ping_iio_info; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = ping_chan_spec; + indio_dev->num_channels = ARRAY_SIZE(ping_chan_spec); + + return devm_iio_device_register(dev, indio_dev); +} + +static struct platform_driver ping_driver = { + .probe = ping_probe, + .driver = { + .name = "ping-gpio", + .of_match_table = of_ping_match, + }, +}; + +module_platform_driver(ping_driver); + +MODULE_AUTHOR("Andreas Klinger "); +MODULE_DESCRIPTION("PING sensors for distance measuring using one GPIOs"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("platform:ping"); From patchwork Mon Nov 18 07:36:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 11249027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A29931593 for ; Mon, 18 Nov 2019 07:37:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8AB4F20726 for ; Mon, 18 Nov 2019 07:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726595AbfKRHh0 (ORCPT ); Mon, 18 Nov 2019 02:37:26 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:38567 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726460AbfKRHhZ (ORCPT ); Mon, 18 Nov 2019 02:37:25 -0500 Received: from localhost ([185.35.208.129]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N9dg5-1hli4Z3cEH-015WVh; Mon, 18 Nov 2019 08:36:54 +0100 Date: Mon, 18 Nov 2019 08:36:50 +0100 From: Andreas Klinger To: robh+dt@kernel.org, jic23@kernel.org, mark.rutland@arm.com Cc: mripard@kernel.org, shawnguo@kernel.org, heiko@sntech.de, icenowy@aosc.io, laurent.pinchart@ideasonboard.com, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, christophe.jaillet@wanadoo.fr, tglx@linutronix.de, mchehab+samsung@kernel.org, davem@davemloft.net, paulmck@linux.ibm.com, devicetree@vger.kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] MAINTAINERS: add maintainer for ping iio sensors Message-ID: <20191118073648.tk4otab6alsiuzt7@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:ZISP8DP7LxxcjVaKcb0HRurcDIs/0YQTEspXlzOeNUD09UpU21I A8MfWMOlgmmvZwYxE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BdGiYizWTk5YBvT/cr+KtSXKuT/6qvdBkZNk+0QLJOmbE 0N0MLkHejM1mychbQr5z9VBDKKf/oY5Ld4CKzAJ1Y= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org Add a maintainer for the new parallax PING))) and LaserPING IIO sensors Signed-off-by: Andreas Klinger --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index c6c34d04ce95..ad469adffb99 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12264,6 +12264,13 @@ L: platform-driver-x86@vger.kernel.org S: Maintained F: drivers/platform/x86/panasonic-laptop.c +PARALLAX PING IIO SENSOR DRIVER +M: Andreas Klinger +L: linux-iio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/iio/proximity/parallax-ping.yaml +F: drivers/iio/proximity/ping.c + PARALLEL LCD/KEYPAD PANEL DRIVER M: Willy Tarreau M: Ksenija Stanojevic