From patchwork Sun Mar 17 20:35:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10856571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54EAE1515 for ; Sun, 17 Mar 2019 20:35:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F768292AA for ; Sun, 17 Mar 2019 20:35:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 33446292AC; Sun, 17 Mar 2019 20:35:41 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 128ED292AB for ; Sun, 17 Mar 2019 20:35:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727534AbfCQUfj convert rfc822-to-8bit (ORCPT ); Sun, 17 Mar 2019 16:35:39 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:40277 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfCQUfi (ORCPT ); Sun, 17 Mar 2019 16:35:38 -0400 Received: from localhost ([46.189.28.83]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1N6bHC-1gxGm02N2s-01808Z; Sun, 17 Mar 2019 21:35:02 +0100 Date: Sun, 17 Mar 2019 21:35:00 +0100 From: Andreas Klinger To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, afaerber@suse.de, arnd@arndb.de, davem@davemloft.net, gregkh@linuxfoundation.org, johan@kernel.org, khilman@baylibre.com, knaack.h@gmx.de, lars@metafoo.de, linux-kernel@vger.kernel.org, martin.blumenstingl@googlemail.com, mchehab+samsung@kernel.org, m.othacehe@gmail.com, nicolas.ferre@microchip.com, pmeerw@pmeerw.net, robh@kernel.org, songqiang1304521@gmail.com, treding@nvidia.com, techsupport@maxbotix.com Subject: [PATCH v3 1/4] dt-bindings: Add vendor prefix for MaxBotix Message-ID: <20190317203458.bgculdjvtt44zkch@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:PadraYS2CHdeeQ8MfeWDYWE5JnY1aKhKbbmPgDJiLM4EzslKJCb mcqth62D4voTEtXSdIbMoQFN46QKybpN1GIROlpKWzeVrZh4u4iu2EwYyAttTa7sAWx1En0 +qtKvlwNB3QbV7pm98S+i7omI0SCwlkfW8AA/lzoUkV7pLqG0hS0XYKw1EGhn/2Llr+pnXQ 3VTuKMfV1o2YD5ceuSdXg== X-UI-Out-Filterresults: notjunk:1;V03:K0:NqtOF6OOMv0=:F70TIV1pUGUUsy8o53xP3B Gvhlm+PClgnAcQ+N9NI3ydrFrD2XGfBaZCYrEjFBp4e6jr3JagMkLkteUukcoMsSG9dq9YSQX EZpdBcBdP1Q9EgRKq0QRIkHhVgAQLYLEZbmAzUMNym7bOOSIIFV3dGURE26ylAb2QiOnpFNzk 5Gw70ubo/uMO/eNPKiQHb1uyFJ8wZ0uekeveUbry5HGmhjtcuprGwp1pdc/QmVZvllKU9bzJH P64i+h/0QljVICEFG3PTpFExGM96CT9/iY3fZp42juyy9vbwIyIJryIqXkWxhtWgf3z/dH2qa h3PCc8kceg/xNr9zpIReqPO8yePJDdK4ofW9JBn9Zl+FDz9fvBGXLatugevRUtrehmVb4ANBb /8GAlvFNa2+csVkZbd6ZZ/RRSjzXjoU+qGGH3zu4WubnxhSNIPZ5ypGP2wKCPhQRL1oGBdSqj uST7fQAbnk7zzcCWKTWMkeOmXsbuEvHYbpHwSzWnMQn6F/k2aXZe9lhV5CTwy9liJqRkENVHI 6EoSrwCSnH1pECeo7ub0kc4wLrRJA8fXl1JjcSqN90LWV9LPpcZe/vGlpCnXr8bnxB0RwC+1v iLGlr94picr7azOriwf/Pt7iImwrdfm1IQ0ir1nIE4pynQOGcqaXfRHIPUO3OoN53vqztg6rB WgIOxKZI9Y0UReQqRPmzgZB8OJZksEcffAQVmAJkEPMnA0QynC904YAzwQSVgH/cVXxC7VKnQ sB04ShpMFDZsLW51ViF514fYoawyLSIMLqKUEg== 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 Add MaxBotix, which is a vendor of ultrasonic rangers in different varieties and interfaces. Signed-off-by: Andreas Klinger Reviewed-by: Andreas Färber Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/vendor-prefixes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt index 389508584f48..added54a1108 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -225,6 +225,7 @@ lsi LSI Corp. (LSI Logic) lwn Liebherr-Werk Nenzing GmbH macnica Macnica Americas marvell Marvell Technology Group Ltd. +maxbotix MaxBotix Inc. maxim Maxim Integrated Products mbvl Mobiveil Inc. mcube mCube From patchwork Sun Mar 17 20:35:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10856573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A79C01515 for ; Sun, 17 Mar 2019 20:36:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9106D292AA for ; Sun, 17 Mar 2019 20:36:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85070292AC; Sun, 17 Mar 2019 20:36:04 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 7231E292AA for ; Sun, 17 Mar 2019 20:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726333AbfCQUgC (ORCPT ); Sun, 17 Mar 2019 16:36:02 -0400 Received: from mout.kundenserver.de ([212.227.17.13]:44953 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725914AbfCQUgC (ORCPT ); Sun, 17 Mar 2019 16:36:02 -0400 Received: from localhost ([46.189.28.64]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MOiU5-1hO77l24xL-00Q8tO; Sun, 17 Mar 2019 21:35:30 +0100 Date: Sun, 17 Mar 2019 21:35:27 +0100 From: Andreas Klinger To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, afaerber@suse.de, arnd@arndb.de, davem@davemloft.net, gregkh@linuxfoundation.org, johan@kernel.org, khilman@baylibre.com, knaack.h@gmx.de, lars@metafoo.de, linux-kernel@vger.kernel.org, martin.blumenstingl@googlemail.com, mchehab+samsung@kernel.org, m.othacehe@gmail.com, nicolas.ferre@microchip.com, pmeerw@pmeerw.net, robh@kernel.org, songqiang1304521@gmail.com, treding@nvidia.com, techsupport@maxbotix.com Subject: [PATCH v3 2/4] dt-bindings: maxbotix,mb1232: Add MaxBotix i2c ultrasonic rangers Message-ID: <20190317203526.4pcwo4gdrrng44v7@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:02yJIr+R1YtvWTALINFEyVUJqlblYDJC/bKT2YFeFpU5KbPzZsx TB4lq5yuWUPHSKBt8p8uxGwNZT2mx5HtEkV7WWKwcly91f0NBCNWeUTUhJy72A5hy5h8KCj MLJJhUx/c1M7kNj6Ju8ffRGQplirhWNmKa20Z9tCXP0cUjmHKG/LiFj7rQbQUmCP2GXNvTn AXwwpMODvYRGc9s4Ypcaw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Pne+EnYjylw=:BlM7TIdxBYjbZeIQ6MQW6D ZaQQkjKu8yDs5cpLvC5WoEYsUHCgj0BcwSbPQ4hkWnbNFUXRtJijta+73gl3Zw0JQ92uwNPgG xfiJ4j6Cnw3iLhAIGU82tqn5KHRc9CzvsPm1yjU7o6JWZ24U6CY/CQaro5wPeXwQATn2AF4Rq F9MuRC/a6/5kPmXrqC4KYEwLlUNhpCHESFbzd9dtE5J8+VxRitbPB0+jBWBxTKZ1cKv/Nj1Gb qLQOgeSIrRSkJSFZS5h/nspIIwFXG6RvgM0TQLicOm1u8Pm/gRXejlU1iLs9N7o2rOBEHY2/2 B93YY48hZUzVcsa+9f5qFKj1ptHDEE16sPfkDAkNb4iMUmf9IR9OODlxxDTQQoBmlIHes+tcM VqT3paKhM6X1imNEfu8+mOld085LF3zMh8QbU8DCnhYlEorzckddKbr2RPhsWk30tMK2rsEBp sUUSNhfoDb++Zud9vOafAWhDWhvbLm0dmswCbGhm9+kx7UrwP5XZ3b7wsWnczvduVngxH5e7+ +fgsmJLUibebTaNKWJ6xULM46ZRYf/FHa2EWZ9fGbtCLjJfeUTwS6kgf2tTD1C2KRRq0h7LKK A1pR3dgNjf7hYZEc8IlIWlblIUVOYMwvLDWi4HdMq/lzWVWyrdX2QxgpLg6YP6mU1EPr+kd8w fbi/MvkS5U8sao7J1OVfX8di8REUw0/cgmflK8maotMWKhH1sEExMi6pf9K/XitVcTj4HCc5C ltmyIx3DNng7uMll9J1ev+/ZfdUw+l0Q3RhX0w== 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 Add doc for dt binding maxbotix,mb1232. This binding is for MaxBotix I2CXL-MaxSonar ultrasonic rangers which share a common i2c interface. Signed-off-by: Andreas Klinger Reviewed-by: Rob Herring --- .../bindings/iio/proximity/maxbotix,mb1232.txt | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.txt diff --git a/Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.txt b/Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.txt new file mode 100644 index 000000000000..0e9df87eca1d --- /dev/null +++ b/Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.txt @@ -0,0 +1,31 @@ +* MaxBotix I2CXL-MaxSonar ultrasonic distance sensor of type mb1202, + mb1212, mb1222, mb1232, mb1242, mb7040 or mb7137 using the i2c interface + for ranging + +Required properties: + - compatible: "maxbotix,mb1202", + "maxbotix,mb1212", + "maxbotix,mb1222", + "maxbotix,mb1232", + "maxbotix,mb1242", + "maxbotix,mb7040" or + "maxbotix,mb7137" + + - reg: i2c address of the device, see also i2c/i2c.txt + +Optional properties: + - interrupt-parent: Interrupt controller to use + + - interrupts: Interrupt used to announce the preceding reading + request has finished and that data is available. + If no interrupt is specified the device driver + falls back to wait a fixed amount of time until + data can be retrieved. + +Example: +proximity@70 { + compatible = "maxbotix,mb1232"; + reg = <0x70>; + interrupt-parent = <&gpio2>; + interrupts = <2 IRQ_TYPE_EDGE_FALLING>; +}; From patchwork Sun Mar 17 20:38:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10856575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6800C1515 for ; Sun, 17 Mar 2019 20:38:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F0B428D1B for ; Sun, 17 Mar 2019 20:38:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 431DA292B1; Sun, 17 Mar 2019 20:38:43 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 7D65A28D1B for ; Sun, 17 Mar 2019 20:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbfCQUim (ORCPT ); Sun, 17 Mar 2019 16:38:42 -0400 Received: from mout.kundenserver.de ([212.227.126.130]:45675 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727173AbfCQUim (ORCPT ); Sun, 17 Mar 2019 16:38:42 -0400 Received: from localhost ([46.189.28.83]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MaIrN-1hZcHg2DUD-00WFDn; Sun, 17 Mar 2019 21:38:05 +0100 Date: Sun, 17 Mar 2019 21:38:03 +0100 From: Andreas Klinger To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, afaerber@suse.de, arnd@arndb.de, davem@davemloft.net, gregkh@linuxfoundation.org, johan@kernel.org, khilman@baylibre.com, knaack.h@gmx.de, lars@metafoo.de, linux-kernel@vger.kernel.org, martin.blumenstingl@googlemail.com, mchehab+samsung@kernel.org, m.othacehe@gmail.com, nicolas.ferre@microchip.com, pmeerw@pmeerw.net, robh@kernel.org, songqiang1304521@gmail.com, treding@nvidia.com, techsupport@maxbotix.com Subject: [PATCH v3 3/4] mb1232.c: add distance iio sensor with i2c Message-ID: <20190317203801.uz2rhpyevsulh5c5@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:whqIwsffZXTjGrSzWhED3rlyJpa+2FV29GCkgRas5p1RVq7pZ12 uSSrLUzqHMhIIQIN/0frVuL0y/91QOnky6kMbnp++fCE/SiyCH9eIxt/67kHhXp+cbFEgcY 5FQT8LHnhoYbqCgRdtqbkPpD9KcIZQ4GI7P9ZtR9PfewQ739IGFPhszDT2sR/1Kt0Z/Rm+C 72u+JvGwa3eoEBXqeDMhQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:Rw2v5e4Fd9Q=:NhXnLHXW4GBI2aZp1CLqRK buOcI120YLXpi9RR4OTCr+Ll6457sWAcMAtDg1IhwsTN/bqtxzb/FbwwWjf3VzW78RMxdbm/E /MyzPBuADRnr3z/lKJfK2dcG+vDuMDZ3wSCXfD0A6jK6E0PP41Qd8K8UL0w2AVVL0UXOCjhd0 tA7Zr09OAH4jqMLqX0IeQvsebaqjfuqJRE5/Fc4CHOfdzJBQz9ZQ/NVSd0jDKOaaJ26uZACc7 Phbvxl22UEQYjWyrV6lxarDv5KsZal+vj7HwDwtjGlhlqcl7mCN+JsBfTm+0Yo51HvDMiEfeW TZHSF2B/JrP+Z9qV71eh/yVN5P5H8sNHP+OfuqaJLO32gUhnY6hPkVsJRcRsUjmbhTQKT/Y0S PCsoUTF47ZxTaOgEXUWV0sEC0w60L6p7PMkhgH5n5zY6QQ+JHQQ+jpL09py64jAJaOWPFGNjC QiDC5TN/seKpMNg2+8qm020sx5NggAyGp0P740tWoVOwpNL7nVL+QHmkRdHcoe7Q/7zzxpa8A AXSIjzh9E7UmOnc0PMil+psCCEAtVSkxfKp40jPR2eUedkxTqXx1VfWn5GA1n2+qZDGHn8Vae GkXegf0BWe3n0m7rmL8HvuW/CU28Wbp4RSRLaO+Su1Gp6mi2ik/LwdFohL8+jdIjs96gPPtSS 2/52JluAnrbDxocQf5kLxcjg8xrFMuAbER0w/20GYYH5Id+PspOdVVMYa2BIHERMCMiiifOc7 ls0sDxgaPoBlU9mRM3TISQAfYRxt03eVt+mTEw== 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 Add I2CXL-MaxSonar ultrasonic distance sensors of types mb1202, mb1212, mb1222, mb1232, mb1242, mb7040, mb7137 using an i2c interface Implemented functionality: - reading the distance via in_distance_raw - buffered mode with trigger - make use of interrupt to announce completion of ranging Add mb1232 driver to Kconfig and Makefile Signed-off-by: Andreas Klinger --- drivers/iio/proximity/Kconfig | 12 ++ drivers/iio/proximity/Makefile | 1 + drivers/iio/proximity/mb1232.c | 274 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 287 insertions(+) create mode 100644 drivers/iio/proximity/mb1232.c diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig index b99367a89f81..12a3d3d40a91 100644 --- a/drivers/iio/proximity/Kconfig +++ b/drivers/iio/proximity/Kconfig @@ -45,6 +45,18 @@ config LIDAR_LITE_V2 To compile this driver as a module, choose M here: the module will be called pulsedlight-lite-v2 +config MB1232 + tristate "MaxSonar I2CXL family ultrasonic sensors" + depends on I2C + help + Say Y to build a driver for the ultrasonic sensors I2CXL of + MaxBotix which have an i2c interface. It can be used to measure + the distance of objects. Supported types are mb1202, mb1212, + mb1222, mb1232, mb1242, mb7040, mb7137 + + To compile this driver as a module, choose M here: the + module will be called mb1232. + config RFD77402 tristate "RFD77402 ToF sensor" depends on I2C diff --git a/drivers/iio/proximity/Makefile b/drivers/iio/proximity/Makefile index 6d031f903c4c..0bb5f9de13d6 100644 --- a/drivers/iio/proximity/Makefile +++ b/drivers/iio/proximity/Makefile @@ -7,6 +7,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_RFD77402) += rfd77402.o obj-$(CONFIG_SRF04) += srf04.o obj-$(CONFIG_SRF08) += srf08.o diff --git a/drivers/iio/proximity/mb1232.c b/drivers/iio/proximity/mb1232.c new file mode 100644 index 000000000000..d061cb16da93 --- /dev/null +++ b/drivers/iio/proximity/mb1232.c @@ -0,0 +1,274 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * mb1232.c - Support for MaxBotix I2CXL-MaxSonar-EZ series ultrasonic + * ranger with i2c interface + * actually tested with mb1232 type + * + * Copyright (c) 2019 Andreas Klinger + * + * For details about the device see: + * https://www.maxbotix.com/documents/I2CXL-MaxSonar-EZ_Datasheet.pdf + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* registers of MaxSonar device */ +#define MB1232_RANGE_COMMAND 0x51 /* Command for reading range */ +#define MB1232_ADDR_UNLOCK_1 0xAA /* Command 1 for changing address */ +#define MB1232_ADDR_UNLOCK_2 0xA5 /* Command 2 for changing address */ + +struct mb1232_data { + struct i2c_client *client; + + struct mutex lock; + + /* + * optionally a gpio can be used to announce when ranging has + * finished + * since we are just using the falling trigger of it we request + * only the interrupt for announcing when data is ready to be read + */ + struct completion ranging; + int irqnr; +}; + +static irqreturn_t mb1232_handle_irq(int irq, void *dev_id) +{ + struct iio_dev *indio_dev = dev_id; + struct mb1232_data *data = iio_priv(indio_dev); + + complete(&data->ranging); + + return IRQ_HANDLED; +} + +static s16 mb1232_read_distance(struct mb1232_data *data) +{ + struct i2c_client *client = data->client; + int ret; + s16 distance; + __be16 buf; + + mutex_lock(&data->lock); + + reinit_completion(&data->ranging); + + ret = i2c_smbus_write_byte(client, MB1232_RANGE_COMMAND); + if (ret < 0) { + dev_err(&client->dev, "write command - err: %d\n", ret); + goto error_unlock; + } + + if (data->irqnr >= 0) { + /* it cannot take more than 100 ms */ + ret = wait_for_completion_killable_timeout(&data->ranging, + HZ/10); + if (ret < 0) + goto error_unlock; + else if (ret == 0) { + ret = -ETIMEDOUT; + goto error_unlock; + } + } else { + /* use simple sleep if announce irq is not connected */ + msleep(15); + } + + ret = i2c_master_recv(client, (char *)&buf, sizeof(buf)); + if (ret < 0) { + dev_err(&client->dev, "i2c_master_recv: ret=%d\n", ret); + goto error_unlock; + } + + distance = __be16_to_cpu(buf); + /* check for not returning misleading error codes */ + if (distance < 0) { + dev_err(&client->dev, "distance=%d\n", distance); + ret = -EINVAL; + goto error_unlock; + } + + mutex_unlock(&data->lock); + + return distance; + +error_unlock: + mutex_unlock(&data->lock); + + return ret; +} + +static irqreturn_t mb1232_trigger_handler(int irq, void *p) +{ + struct iio_poll_func *pf = p; + struct iio_dev *indio_dev = pf->indio_dev; + struct mb1232_data *data = iio_priv(indio_dev); + /* + * triggered buffer + * 16-bit channel + 48-bit padding + 64-bit timestamp + */ + s16 buffer[8]; + + buffer[0] = mb1232_read_distance(data); + if (buffer[0] < 0) + goto err; + + iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); + +err: + iio_trigger_notify_done(indio_dev->trig); + return IRQ_HANDLED; +} + +static int mb1232_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *channel, int *val, + int *val2, long mask) +{ + struct mb1232_data *data = iio_priv(indio_dev); + int ret; + + if (channel->type != IIO_DISTANCE) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = mb1232_read_distance(data); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + /* 1 LSB is 1 cm */ + *val = 0; + *val2 = 10000; + return IIO_VAL_INT_PLUS_MICRO; + default: + return -EINVAL; + } +} + +static const struct iio_chan_spec mb1232_channels[] = { + { + .type = IIO_DISTANCE, + .info_mask_separate = + BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE), + .scan_index = 0, + .scan_type = { + .sign = 's', + .realbits = 16, + .storagebits = 16, + .endianness = IIO_CPU, + }, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +}; + +static const struct iio_info mb1232_info = { + .read_raw = mb1232_read_raw, +}; + +static int mb1232_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct mb1232_data *data; + int ret; + struct device *dev = &client->dev; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_READ_BYTE | + I2C_FUNC_SMBUS_WRITE_BYTE)) + return -ENODEV; + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + indio_dev->info = &mb1232_info; + indio_dev->name = id->name; + indio_dev->dev.parent = dev; + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->channels = mb1232_channels; + indio_dev->num_channels = ARRAY_SIZE(mb1232_channels); + + mutex_init(&data->lock); + + init_completion(&data->ranging); + + data->irqnr = irq_of_parse_and_map(dev->of_node, 0); + if (data->irqnr <= 0) { + /* usage of interrupt is optional */ + data->irqnr = -1; + } else { + ret = devm_request_irq(dev, data->irqnr, mb1232_handle_irq, + IRQF_TRIGGER_FALLING, id->name, indio_dev); + if (ret < 0) { + dev_err(dev, "request_irq: %d\n", ret); + return ret; + } + } + + ret = devm_iio_triggered_buffer_setup(dev, indio_dev, + iio_pollfunc_store_time, mb1232_trigger_handler, NULL); + if (ret < 0) { + dev_err(dev, "setup of iio triggered buffer failed\n"); + return ret; + } + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct of_device_id of_mb1232_match[] = { + { .compatible = "maxbotix,mb1202", }, + { .compatible = "maxbotix,mb1212", }, + { .compatible = "maxbotix,mb1222", }, + { .compatible = "maxbotix,mb1232", }, + { .compatible = "maxbotix,mb1242", }, + { .compatible = "maxbotix,mb7040", }, + { .compatible = "maxbotix,mb7137", }, + {}, +}; + +MODULE_DEVICE_TABLE(of, of_mb1232_match); + +static const struct i2c_device_id mb1232_id[] = { + { "maxbotix-mb1202", }, + { "maxbotix-mb1212", }, + { "maxbotix-mb1222", }, + { "maxbotix-mb1232", }, + { "maxbotix-mb1242", }, + { "maxbotix-mb7040", }, + { "maxbotix-mb7137", }, + { } +}; +MODULE_DEVICE_TABLE(i2c, mb1232_id); + +static struct i2c_driver mb1232_driver = { + .driver = { + .name = "maxbotix-mb1232", + .of_match_table = of_mb1232_match, + }, + .probe = mb1232_probe, + .id_table = mb1232_id, +}; +module_i2c_driver(mb1232_driver); + +MODULE_AUTHOR("Andreas Klinger "); +MODULE_DESCRIPTION("Maxbotix I2CXL-MaxSonar i2c ultrasonic ranger driver"); +MODULE_LICENSE("GPL"); From patchwork Sun Mar 17 20:38:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Klinger X-Patchwork-Id: 10856577 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D51813B5 for ; Sun, 17 Mar 2019 20:39:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376EB2909B for ; Sun, 17 Mar 2019 20:39:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A9FE290D9; Sun, 17 Mar 2019 20:39:10 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 184B32909B for ; Sun, 17 Mar 2019 20:39:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726735AbfCQUjI (ORCPT ); Sun, 17 Mar 2019 16:39:08 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:33085 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726452AbfCQUjI (ORCPT ); Sun, 17 Mar 2019 16:39:08 -0400 Received: from localhost ([46.189.28.64]) by mrelayeu.kundenserver.de (mreue107 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M2fM1-1h23ui0Ypj-004CDZ; Sun, 17 Mar 2019 21:38:31 +0100 Date: Sun, 17 Mar 2019 21:38:29 +0100 From: Andreas Klinger To: devicetree@vger.kernel.org, linux-iio@vger.kernel.org Cc: jic23@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, afaerber@suse.de, arnd@arndb.de, davem@davemloft.net, gregkh@linuxfoundation.org, johan@kernel.org, khilman@baylibre.com, knaack.h@gmx.de, lars@metafoo.de, linux-kernel@vger.kernel.org, martin.blumenstingl@googlemail.com, mchehab+samsung@kernel.org, m.othacehe@gmail.com, nicolas.ferre@microchip.com, pmeerw@pmeerw.net, robh@kernel.org, songqiang1304521@gmail.com, treding@nvidia.com, techsupport@maxbotix.com Subject: [PATCH v3 4/4] MAINTAINERS: add maintainer for maxbotix ultrasonic driver Message-ID: <20190317203827.ocgsj24itlqzqjvc@arbad> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170113 (1.7.2) X-Provags-ID: V03:K1:qPNL7kc4ifmmZvoWQ1c7Q0xrViiHLGYKe4xdT643yPVyEPmTonq OGfvCOxVUMJaKI/vpimJr7l5tPKVy5xP/C+7udw5VGRI+Mv7eXr24iYAKe2ccY7KTo5xfTa sx94EMhpLvJIskwsROn9HUJ2uOxEXVVdIXN97TZwUvC+gOxxIA9QlgMVdqBOGKlT/RoWvtx ixGeAn3k8O9De+M4ZlHPQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:31Xcbi7fnYw=:gTJHj9gWotClFEx0uc7VNk j4Hi8yaDqPOG7cOYDUbDukyPU/jhCXxhsrhNYvr5gCpdTMWodloSOs8FwR0+HCO/86ugQZokw TSnsnpzkh2dzX7/NSS/llmx1qC0wj5IxlEDg1ZOAQlLIh2jepc+lHVM1KLZ2QEyk5jmbANwQ5 OioSa/67jUesM2jo8PLu8jwqxzSeFP3cTMXkpgUVekRsvlIGH9kllKAzYXscOYC3OrLPypVUJ umbZcpYq+nTfqeSh+FbP6U51NhSdlVpE2wxyP2X2DhE3evzSNQdBi5HjEQA6lBimNwNCStvHl ixpCZYNvRAbYZTCL5fLtayVgOzPJcYT+pJ6T1+tYt+y+k4/YYs0zh1eh2kvJF2NTQDQu3x292 +6te1+f6lh8KnLUI6lGRZ8B5U0QGdZiF8Oz7IE8Te8dsvqoRCSObf5HWPNS4dE4hnSFueFtJI qdnBPhlrbOn/O0UUVhxb+xpnY9Qxkv1mNTna/hKVjJRB78gqWy1ojD8KIgX3u3oOn3ZuplYEx k0La4ZnMxnreZzNspJ9BGaSXPdFxi+IClSoUhvDMo8vWW8oxRfPBHryxbLm3gSu55hLvpHShk B5wKQShco7P3bTf+mQN1SfntIsSVcL45c5x2hGP7I3/unafgBffxaxyU7sJOQqK7dtsbKIRBh Ea7DHZecg0XDsM/F2YArF/4b5HjDZRa3E4yBy4wgduiuPPlgLJ7WPGFLO3DIaPwmt26Ikg88A 7YQY8XYITL+bry4+1gWRAD7E1sfJwjZXHKWCTQ6bx632/5eFJG+yp6O2NewDTVUqTLy2aupaz yKOsM7Op6AHluECfOCMaU/HI42wPEnkDaUQTKCmfMDP2VYx1XkTwvxMqE3PfsflA4piO0h1Bn 7qi4fk2nYv4iv92WbPhhHSvQ0D2UiTyCwRdwrAQQThVp06cddc6xaDY6uJYwuPC7QVwOwFqxo 7jOro3khI4w== 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 add a maintainer for the newly created ultrasonic driver family of maxbotix Signed-off-by: Andreas Klinger --- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index dce5c099f43c..fa054f8cc7fb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9234,6 +9234,13 @@ S: Maintained F: Documentation/devicetree/bindings/sound/max9860.txt F: sound/soc/codecs/max9860.* +MAXBOTIX ULTRASONIC RANGER IIO DRIVER +M: Andreas Klinger +L: linux-iio@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/iio/proximity/maxbotix,mb1232.txt +F: drivers/iio/proximity/mb1232.c + MAXIM MAX77802 PMIC REGULATOR DEVICE DRIVER M: Javier Martinez Canillas L: linux-kernel@vger.kernel.org