From patchwork Fri Apr 5 09:34:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Mergnat X-Patchwork-Id: 10887077 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 2310A922 for ; Fri, 5 Apr 2019 09:35:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E05C28AC6 for ; Fri, 5 Apr 2019 09:35:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F37F328B0F; Fri, 5 Apr 2019 09:35:11 +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,DKIM_SIGNED, DKIM_VALID,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 A4BFA28AC6 for ; Fri, 5 Apr 2019 09:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730512AbfDEJe4 (ORCPT ); Fri, 5 Apr 2019 05:34:56 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37426 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730467AbfDEJez (ORCPT ); Fri, 5 Apr 2019 05:34:55 -0400 Received: by mail-wm1-f66.google.com with SMTP id v14so6409801wmf.2 for ; Fri, 05 Apr 2019 02:34:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sFg9IaMybZg87mNCTA2W2IHIRutwglsZx75wyHfcxvg=; b=X1Pu3MkeJmSVn5Uzn3EqWX49UnrSpE4m6Kv1GHAdk57ZtGfE32ETQk859T39W9/cyX F8y3MCpHV/3Z1xm/tCl/yDkkhpWi24m8tP2T89VKpm/eSX5zpuzbGHm7cAQrGj4+Ho/e j7UFFtRZ+tNxP1aaFTWNfggrXCOJdM3tiee4qDmzdPpTzxJCCBzkIx4d3Fqr14cLuPVx OzUr6Pp2PmMk8FKvie7psfnUjy7G/+mnNi8/mmk+KRA78cNk4Y2dP78wcygxnA0xOBgs whchgxea0yBr4KqwZy1YmE8YkToAWvaMGPQd4kVVu9itb2Q3Ynga6F/hC19qcmqqG442 Hzkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sFg9IaMybZg87mNCTA2W2IHIRutwglsZx75wyHfcxvg=; b=j8Y8kHfFIHLPjU3TgRsazo1hkzJYITsu01+uLpCCRUWttaDUVxeY1Ai8HGZP+IFQ30 VSIjWmKY6a9aQ+3X5lu9IvplRh/RT5PJ6BoHkzK6+/ZhdjeEE/1Gyd4flb7OIO4Uv0Lf G2XPBZg68YTmmY8F5aVAX11lOei9LDGfzlMKYzhNixOeTljKSYCMdf4dNXY3MJCpb8M6 1KNtGIrvbpCDOoOCpnxCXjshuHyVPkjfhhf4NgBjbQM/dyhaDp1ct/H7d6RzFGxmGvNG ACVlnW70zsRZG7iAB895aCM8k0AOrMP1EwgZSx0e12BfE3VFkVcxHgH/knFwp/FW3x5k Jl4A== X-Gm-Message-State: APjAAAUNpCTOMqwfvGKFKa4gKf7Qsflzy+dxce1Uz31Pih6jLV1W2zWp TDd6x8jilc3kOkCYxB82oqq5uw== X-Google-Smtp-Source: APXvYqyab+2cwyBOIa0dwK24OotGY7eykkMEkpi06jQa2St+oPz6kvtVeXrKrDd4hWE2i7sb/U7Umw== X-Received: by 2002:a1c:2d45:: with SMTP id t66mr7297226wmt.106.1554456893907; Fri, 05 Apr 2019 02:34:53 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id t15sm1954128wmt.2.2019.04.05.02.34.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Apr 2019 02:34:53 -0700 (PDT) From: Alexandre Mergnat To: robh+dt@kernel.org, mark.rutland@arm.com, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, baylibre-upstreaming@groups.io, Alexandre Mergnat Subject: [PATCH 1/3] dt-bindings: Add pixart vendor Date: Fri, 5 Apr 2019 09:34:28 +0000 Message-Id: <1554456870-8104-2-git-send-email-amergnat@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> References: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> 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 PixArt Imaging Inc. is expertized in CMOS image sensors (CIS), capacitive touch controllers and related imaging application development. Signed-off-by: Alexandre Mergnat --- 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 8162b0e..dbd8893 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.txt +++ b/Documentation/devicetree/bindings/vendor-prefixes.txt @@ -313,6 +313,7 @@ phicomm PHICOMM Co., Ltd. phytec PHYTEC Messtechnik GmbH picochip Picochip Ltd pine64 Pine64 +pixart PixArt Imaging Inc. pixcir PIXCIR MICROELECTRONICS Co., Ltd plantower Plantower Co., Ltd plathome Plat'Home Co., Ltd. From patchwork Fri Apr 5 09:34:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Mergnat X-Patchwork-Id: 10887075 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 90DA21575 for ; Fri, 5 Apr 2019 09:35:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 79C1D28AC6 for ; Fri, 5 Apr 2019 09:35:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CEA628B0F; Fri, 5 Apr 2019 09:35:11 +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,DKIM_SIGNED, DKIM_VALID,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 C5E6C28AC6 for ; Fri, 5 Apr 2019 09:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730554AbfDEJfJ (ORCPT ); Fri, 5 Apr 2019 05:35:09 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54569 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730501AbfDEJe5 (ORCPT ); Fri, 5 Apr 2019 05:34:57 -0400 Received: by mail-wm1-f65.google.com with SMTP id c1so5926806wml.4 for ; Fri, 05 Apr 2019 02:34:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ot7R4QQLGeHfNAz7vr6go3wsbBhXv9hbHqFpcoxW/Ms=; b=LEhEgFjxLvkvCxZxAsqX/2NFdHWcYbLvP02jo9H5B3/9YjwY1M2wCndnyPJpiM++Jz mD9+zohLsps1hefZ3F4//5nMgE24Z6TZfUSx4uAdtEOdALqOI80NxkzNc1qaS06VXMkv TLXVAKZD5n2fRTgTNAt/jtF/i0hGityNkTp06T4Vbywhu3R3QD8nXco/Pem+ip4qd6nA wY64LdNAWMeRihrRMbNs3SKjrp7k6g/UjmlKR73PTUPHXErGfKgB7buJrGn799mTiRjn ReTIGAenvni3Mi83jUMy64hGh98HZF1YzM+XNrRkMgADCVtlq3TOe03v4DowDCmOd709 gAoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ot7R4QQLGeHfNAz7vr6go3wsbBhXv9hbHqFpcoxW/Ms=; b=kEoDDK3/+NrqJvz+B1ZINfX5W/fiplcV22oxWB3ptAdHSMDP6sb1kwkWwHvx0hd4hX 9KmXN/oXkVJMg+h8XOrmt4TTV40X8nIHegg6OMzbi9ginevQj/fUT8m20HKpi7IkFbpO KqwBCMMIReRS3f4dscGq7YjdMWOYZq/kqDSaf+Ox2M2XKkWyyNJD+WK5mPC+cqjIyWRj TJllRRNKsohtKrmst6/ta/YS+26J2/zfCAEQYQ6wRmzJQ7SqgU+u3A5M9LdVN8vyzWJD 7PyfSu72AnSwIoIJ7RNW/slu8zabDWApx9M+FKoWduFl8lIpzbU5S8CoVs3W7c//lW79 CSyA== X-Gm-Message-State: APjAAAVwzlqFpFlYMVU+IznDths1psGYn3SnVDn8AvGlD4FIEhCLtl8R OorXBMmrHW7hGH5MMr2FB1Y++g== X-Google-Smtp-Source: APXvYqxIOKP+poQeBr8GFahvuylKI6yxFSov0b9kxyWDoUR6zt0mzQwGW7iyCRMlMPJarQWE11x21Q== X-Received: by 2002:a7b:c408:: with SMTP id k8mr7378186wmi.69.1554456895339; Fri, 05 Apr 2019 02:34:55 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id t15sm1954128wmt.2.2019.04.05.02.34.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Apr 2019 02:34:54 -0700 (PDT) From: Alexandre Mergnat To: robh+dt@kernel.org, mark.rutland@arm.com, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, baylibre-upstreaming@groups.io, Alexandre Mergnat Subject: [PATCH 2/3] dt-bindings: iio: ot: Add docs pat9125 Date: Fri, 5 Apr 2019 09:34:29 +0000 Message-Id: <1554456870-8104-3-git-send-email-amergnat@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> References: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> 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 documentation for the optical tracker PAT9125 and "ot" directory for Optical Tracker chip. Signed-off-by: Alexandre Mergnat --- Documentation/devicetree/bindings/iio/ot/pat9125.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/ot/pat9125.txt diff --git a/Documentation/devicetree/bindings/iio/ot/pat9125.txt b/Documentation/devicetree/bindings/iio/ot/pat9125.txt new file mode 100644 index 0000000..2ffacaa --- /dev/null +++ b/Documentation/devicetree/bindings/iio/ot/pat9125.txt @@ -0,0 +1,18 @@ +PixArt Imaging PAT9125 Optical Tracking Miniature Chip device driver + +Required properties: + - compatible: must be "pixart,pat9125" + - reg: i2c address where to find the device + - interrupts : the sole interrupt generated by the device + + Refer to interrupt-controller/interrupts.txt for generic + interrupt client node bindings. + +Example: + +pat9125@75 { + compatible = "pixart,pat9125"; + reg = <0x75>; + interrupt-parent = <&gpio3>; + interrupts = <12 IRQ_TYPE_EDGE_FALLING>; +}; From patchwork Fri Apr 5 09:34:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandre Mergnat X-Patchwork-Id: 10887073 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 7E6721575 for ; Fri, 5 Apr 2019 09:35:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 637AF28732 for ; Fri, 5 Apr 2019 09:35:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54D6B286E5; Fri, 5 Apr 2019 09:35:02 +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,DKIM_SIGNED, DKIM_VALID,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 570AE286E5 for ; Fri, 5 Apr 2019 09:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730665AbfDEJfA (ORCPT ); Fri, 5 Apr 2019 05:35:00 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:35750 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730554AbfDEJe7 (ORCPT ); Fri, 5 Apr 2019 05:34:59 -0400 Received: by mail-wm1-f65.google.com with SMTP id y197so6444872wmd.0 for ; Fri, 05 Apr 2019 02:34:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=y/XEN4HjpNO9QIHIkRzJb1qhaaY1QJxkt53v7Xyozjo=; b=X2LEmNBAUS8qwtICqnhq44nmtbqUO/nggtW+Pl7vJWpgHKhAV3yhv4ieD93/06LmaS iHfEVD7XmbwxhHODYDgQK912IACVBaUvYcHILNBNTBEkMzM7718pzZwlu3qEb0TjlOKf 8ep87y0adqzfUCWLMyC4/E9QgCixprNFBxdLcSItMOm3OGZYi/PFeWEOF2oLs2oPlBR8 Q56DurfsCP7gQX/RqUrSlL7aKona3aoB9vNZOz6ow7dxu8J0D0yUb/7bQd0csjaTb4r6 WUa40jDG+sjCHzyt8i5dLzJAeusYjGjPCxsLT7gOYKSBi3AvmFj1GevVG8KNrcXrBaSb fp3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=y/XEN4HjpNO9QIHIkRzJb1qhaaY1QJxkt53v7Xyozjo=; b=jJlQZlEfSwTip+q9eck3YmFBtW5dCAG5mm148f8BAH7pSAwxCpUHQjswyDHW96mODa DwgmTSFt0clmmksk9D2F10ZITQ2ToBC0O31YRkvGb+xvm03p3nWz5Ld9z919QKh+F0uY V58i41YKWwOjehlBqLstwMV1JUFevffDSesFvOef5dybXAn79+CymfTrYYy++HPiCtSy paHU6R4+dDC9ynlsm81PZ7gHNWzQbIDQyEyutAi1/pIfguekMZW0F/q1BGvpbG9FKHl1 3azCB8fjTifwhZakCO0CgByKFza0rd1ADgypmm42dB95K8+W0pLJaGagDz//zXs9Zrg+ +x+Q== X-Gm-Message-State: APjAAAUIWgWyiFe7hmLFiWc/ztFIlyQUc7GRQ9kpmml6hCuPL6fzTSMT 52r0erL8t16MDFZpD/haRQBcl0Lz03UBNg== X-Google-Smtp-Source: APXvYqzVt3dTLkz/cYzY3RIpLRG3t+jirfMZ9DvADFeZsrFgS+an2DepkjSi3UPGjSPIsjVrWnQoOg== X-Received: by 2002:a1c:81cc:: with SMTP id c195mr7455712wmd.61.1554456896876; Fri, 05 Apr 2019 02:34:56 -0700 (PDT) Received: from localhost.localdomain ([51.15.160.169]) by smtp.googlemail.com with ESMTPSA id t15sm1954128wmt.2.2019.04.05.02.34.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Apr 2019 02:34:56 -0700 (PDT) From: Alexandre Mergnat To: robh+dt@kernel.org, mark.rutland@arm.com, jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, baylibre-upstreaming@groups.io, Alexandre Mergnat Subject: [PATCH 3/3] iio: Add PAT9125 optical tracker sensor Date: Fri, 5 Apr 2019 09:34:30 +0000 Message-Id: <1554456870-8104-4-git-send-email-amergnat@baylibre.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> References: <1554456870-8104-1-git-send-email-amergnat@baylibre.com> MIME-Version: 1.0 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 This adds support for PixArt Imaging’s miniature low power optical navigation chip using LASER light source enabling digital surface tracking. This IIO driver allow to read delta position on 2 axis (X and Y). The values can be taken through ponctual "read_raw" which will issue a read in the device registers to return the deltas or subscribe to the data buffer feed automaticaly by a new value using a trigger gpio. The buffer payload is: |16 bits delta X|16 bits delta Y|timestamp|. The possible I2C adresses are 0x73, 0x75 and 0x79. Unfortunately, the device configuration must be hardcoded in the initialization function and can't be changed "on-the-fly" in user space due to the lack of configuration interface. The "ot" directory is added to coutain Optical Tracker drivers. Signed-off-by: Alexandre Mergnat --- drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/ot/Kconfig | 16 ++ drivers/iio/ot/Makefile | 6 + drivers/iio/ot/pat9125.c | 407 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 431 insertions(+) create mode 100644 drivers/iio/ot/Kconfig create mode 100644 drivers/iio/ot/Makefile create mode 100644 drivers/iio/ot/pat9125.c diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index d08aeb4..bdf1bd0 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -86,6 +86,7 @@ source "drivers/iio/light/Kconfig" source "drivers/iio/magnetometer/Kconfig" source "drivers/iio/multiplexer/Kconfig" source "drivers/iio/orientation/Kconfig" +source "drivers/iio/ot/Kconfig" if IIO_TRIGGER source "drivers/iio/trigger/Kconfig" endif #IIO_TRIGGER diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index cb59932..fdda2e1 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -32,6 +32,7 @@ obj-y += light/ obj-y += magnetometer/ obj-y += multiplexer/ obj-y += orientation/ +obj-y += ot/ obj-y += potentiometer/ obj-y += potentiostat/ obj-y += pressure/ diff --git a/drivers/iio/ot/Kconfig b/drivers/iio/ot/Kconfig new file mode 100644 index 0000000..3d17fda --- /dev/null +++ b/drivers/iio/ot/Kconfig @@ -0,0 +1,16 @@ +# +# Optical tracker sensors +# +# When adding new entries keep the list in alphabetical order + +menu "Optical tracker sensors" + +config PAT9125 + tristate "Optical tracker PAT9125 I2C driver" + depends on I2C + select IIO_BUFFER + help + Say yes here to build support for PAT9125 optical tracker + sensors. + +endmenu diff --git a/drivers/iio/ot/Makefile b/drivers/iio/ot/Makefile new file mode 100644 index 0000000..cf29491 --- /dev/null +++ b/drivers/iio/ot/Makefile @@ -0,0 +1,6 @@ +# +# Makefile for industrial I/O Optical tracker sensor drivers +# + +# When adding new entries keep the list in alphabetical order +obj-$(CONFIG_PAT9125) += pat9125.o diff --git a/drivers/iio/ot/pat9125.c b/drivers/iio/ot/pat9125.c new file mode 100644 index 0000000..f416bfa --- /dev/null +++ b/drivers/iio/ot/pat9125.c @@ -0,0 +1,407 @@ +// SPDX-License-Identifier: (GPL-2.0) +/* + * Copyright (C) 2018 BayLibre, SAS + * Author: Alexandre Mergnat + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +/* I2C Address function to ID pin*/ +#define PAT9125_I2C_ADDR_HI 0x73 +#define PAT9125_I2C_ADDR_LO 0x75 +#define PAT9125_I2C_ADDR_NC 0x79 + +/* Registers */ +#define PAT9125_PRD_ID1_REG 0x00 +#define PAT9125_PRD_ID2_REG 0x01 +#define PAT9125_MOTION_STATUS_REG 0x02 +#define PAT9125_DELTA_X_LO_REG 0x03 +#define PAT9125_DELTA_Y_LO_REG 0x04 +#define PAT9125_OP_MODE_REG 0x05 +#define PAT9125_CONFIG_REG 0x06 +#define PAT9125_WRITE_PROTEC_REG 0x09 +#define PAT9125_SLEEP1_REG 0x0A +#define PAT9125_SLEEP2_REG 0x0B +#define PAT9125_RES_X_REG 0x0D +#define PAT9125_RES_Y_REG 0x0E +#define PAT9125_DELTA_XY_HI_REG 0x12 +#define PAT9125_SHUTER_REG 0x14 +#define PAT9125_FRAME_AVG_REG 0x17 +#define PAT9125_ORIENTATION_REG 0x19 + +/* Masks */ +#define PAT9125_VALID_MOTION_DATA_MASK 0x80 +#define PAT9125_RESET_MASK 0x80 + +/* Registers' values */ +#define PAT9125_SENSOR_ID_VAL 0x31 +#define PAT9125_DISABLE_WRITE_PROTECT_VAL 0x5A +#define PAT9125_ENABLE_WRITE_PROTECT_VAL 0x00 +#define PAT9125_CPI_RESOLUTION_X_VAL 0x65 +#define PAT9125_CPI_RESOLUTION_Y_VAL 0xFF + +/* Default Value of sampled value size */ +#define PAT9125_SAMPLED_VAL_BIT_SIZE 12 +#define PAT9125_SAMPLED_VAL_BYTE_SIZE 2 /* 12 bits by default */ +#define PAT9125_TIMESTAMP_BYTE_SIZE 8 /* 64 bits */ +#define PAT9125_PAYLOAD_BYTE_SIZE \ + (2 * PAT9125_SAMPLED_VAL_BYTE_SIZE + PAT9125_TIMESTAMP_BYTE_SIZE) +#define PAT9125_REALBITS_XY_VAL \ + (2 * PAT9125_SAMPLED_VAL_BIT_SIZE) +#define PAT9125_STORAGEBITS_XY_VAL \ + (2 * PAT9125_SAMPLED_VAL_BYTE_SIZE) + +struct pat9125_data { + struct i2c_client *client; + struct regmap *regmap; + s16 delta_x; + s16 delta_y; +}; + +static const struct iio_event_spec pat9125_event = { + .type = IIO_EV_TYPE_THRESH, + .dir = IIO_EV_DIR_RISING, + .mask_separate = BIT(IIO_EV_INFO_VALUE), +}; + +static const struct iio_chan_spec pat9125_channels[] = { + { + .type = IIO_DISTANCE, + .modified = 1, + .channel2 = IIO_MOD_X_AND_Y, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .address = 0, + .scan_index = 0, + .scan_type = { + .sign = 's', \ + .realbits = 24, \ + .storagebits = 32, \ + .shift = 8, \ + .endianness = IIO_BE, \ + }, + .event_spec = &pat9125_event, + .num_event_specs = 1, + }, + IIO_CHAN_SOFT_TIMESTAMP(1), +}; + +static int pat9125_read_delta(struct pat9125_data *data) +{ + struct regmap *regmap = data->regmap; + int status = 0; + int val_x = 0; + int val_y = 0; + int val_xy = 0; + int r; + + r = regmap_read(regmap, PAT9125_MOTION_STATUS_REG, &status); + if (r < 0) + return r; + + /* Check motion bit in bit7 */ + if (status & PAT9125_VALID_MOTION_DATA_MASK) { + r = regmap_read(regmap, PAT9125_DELTA_X_LO_REG, &val_x); + if (r < 0) + return r; + + r = regmap_read(regmap, PAT9125_DELTA_Y_LO_REG, &val_y); + if (r < 0) + return r; + + r = regmap_read(regmap, PAT9125_DELTA_XY_HI_REG, &val_xy); + if (r < 0) + return r; + + data->delta_x = val_x | ((val_xy << 4) & 0xF00); + data->delta_y = val_y | ((val_xy << 8) & 0xF00); + + if (data->delta_x & 0x800) + data->delta_x |= 0xF000; + + if (data->delta_y & 0x800) + data->delta_y |= 0xF000; + } + + return 0; +} + +/** + * pat9125_read_raw() - Sample and return the value(s) + * function to the associated channel info enum. + **/ +static int pat9125_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct pat9125_data *data = iio_priv(indio_dev); + int ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = pat9125_read_delta(data); + if (ret) + return ret; + + *val = data->delta_x; + *val2 = data->delta_y; + return IIO_VAL_INT; + default: + return -EINVAL; + } + + return -EINVAL; +} + +/** + * pat9125_read_event_value() - return last sampled value. + **/ +static int pat9125_read_event_value(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir, + enum iio_event_info info, + int *val, + int *val2) +{ + struct pat9125_data *data = iio_priv(indio_dev); + + switch (info) { + case IIO_EV_INFO_VALUE: + val[0] = data->delta_x; + val[1] = data->delta_y; + *val2 = 2; + return IIO_VAL_INT_MULTIPLE; + default: + return -EINVAL; + } +} + +/** + * pat9125_event_handler() - handling ring and non ring events + * @irq: The irq being handled. + * @private: struct iio_device pointer for the device. + * + */ +static irqreturn_t pat9125_event_handler(int irq, void *private) +{ + struct iio_dev *indio_dev = private; + struct pat9125_data *data = iio_priv(indio_dev); + int ret = 0; + u8 *payload; + s64 last_timestamp = iio_get_time_ns(indio_dev); + + payload = kmalloc(sizeof(s64) + 2 * + PAT9125_SAMPLED_VAL_BYTE_SIZE, GFP_KERNEL); + + ret = pat9125_read_delta(data); + if (ret) + return ret; + memcpy(&payload[0], &data->delta_x, 2); + memcpy(&payload[2], &data->delta_y, 2); + + iio_push_to_buffers_with_timestamp(indio_dev, payload, last_timestamp); + iio_push_event(indio_dev, + IIO_MOD_EVENT_CODE(IIO_DISTANCE, + 0, + IIO_MOD_X_AND_Y, + IIO_EV_TYPE_THRESH, + IIO_EV_DIR_RISING), + last_timestamp); + + return IRQ_HANDLED; +} + +static int pat9125_configure_ring(struct iio_dev *indio_dev) +{ + struct iio_buffer *buffer; + struct pat9125_data *data = iio_priv(indio_dev); + + buffer = devm_iio_kfifo_allocate(&data->client->dev); + if (!buffer) + return -ENOMEM; + + iio_device_attach_buffer(indio_dev, buffer); + indio_dev->modes |= INDIO_BUFFER_SOFTWARE; + + return 0; +} + +static const struct regmap_config pat9125_regmap_config = { + .reg_bits = 8, + .val_bits = 8, +}; + +static const struct iio_info pat9125_info = { + .read_raw = pat9125_read_raw, + .read_event_value = &pat9125_read_event_value, +}; + +static int pat9125_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct pat9125_data *data; + struct iio_dev *indio_dev; + int r, sensor_pid; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + if (!indio_dev) { + dev_err(&client->dev, "IIO device allocation failed"); + return -ENOMEM; + } + + data = iio_priv(indio_dev); + data->client = client; + + indio_dev->dev.parent = &client->dev; + indio_dev->name = id->name; + indio_dev->channels = pat9125_channels; + indio_dev->num_channels = ARRAY_SIZE(pat9125_channels); + indio_dev->info = &pat9125_info; + indio_dev->modes = INDIO_DIRECT_MODE; + + r = pat9125_configure_ring(indio_dev); + if (r < 0) { + dev_err(&client->dev, "FIFO buffer allocation failed"); + return r; + } + + data->regmap = devm_regmap_init_i2c(client, &pat9125_regmap_config); + if (IS_ERR(data->regmap)) { + dev_err(&client->dev, + "regmap init failed %ld", + PTR_ERR(data->regmap)); + return PTR_ERR(data->regmap); + } + + /* Check device ID */ + r = regmap_read(data->regmap, PAT9125_PRD_ID1_REG, &sensor_pid); + if (r < 0) + goto reg_access_fail; + if (sensor_pid != PAT9125_SENSOR_ID_VAL) + return -ENODEV; + + /* Software reset (i.e. set bit7 to 1). + * It will reset to 0 automatically + */ + r = regmap_write_bits(data->regmap, + PAT9125_CONFIG_REG, + PAT9125_RESET_MASK, + 1); + if (r < 0) + goto reg_access_fail; + + /* Delay 20ms */ + msleep(20); + + /* Disable write protect */ + r = regmap_write(data->regmap, + PAT9125_WRITE_PROTEC_REG, + PAT9125_DISABLE_WRITE_PROTECT_VAL); + if (r < 0) + goto reg_access_fail; + + /* Set X-axis resolution (depends on application) */ + r = regmap_write(data->regmap, + PAT9125_RES_X_REG, + 0x0A); + if (r < 0) + goto reg_access_fail; + + /* Set Y-axis resolution (depends on application) */ + r = regmap_write(data->regmap, + PAT9125_RES_Y_REG, + 0x0A); + if (r < 0) + goto reg_access_fail; + + /* Enable write protection */ + r = regmap_write(data->regmap, + PAT9125_WRITE_PROTEC_REG, + PAT9125_ENABLE_WRITE_PROTECT_VAL); + if (r < 0) + goto reg_access_fail; + + r = devm_iio_device_register(&client->dev, indio_dev); + if (r) { + dev_err(&client->dev, "IIO device register failed"); + return r; + } + + i2c_set_clientdata(client, indio_dev); + + dev_info(&client->dev, "%s: sensor '%s'\n", + dev_name(&indio_dev->dev), + client->name); + + /* Make read to reset motion bit status */ + r = pat9125_read_delta(data); + if (r) + goto reg_access_fail; + + /* Init GPIO IRQ */ + if (client->irq) { + r = devm_request_threaded_irq(&client->dev, + client->irq, + NULL, + pat9125_event_handler, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "pat9125", + indio_dev); + if (r) + return r; + } + return 0; + +reg_access_fail: + dev_err(&client->dev, "register access failed %d", r); + return r; +} + +static int pat9125_remove(struct i2c_client *client) +{ + dev_info(&client->dev, "PAT9125 removed\n"); + + return 0; +} + +static const struct i2c_device_id pat9125_id[] = { + { "pat9125", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, pat9125_id); + +static const unsigned short normal_i2c[] = { + PAT9125_I2C_ADDR_HI, + PAT9125_I2C_ADDR_LO, + PAT9125_I2C_ADDR_NC, + I2C_CLIENT_END +}; + +static struct i2c_driver pat9125_driver = { + .driver = { + .name = "pat9125", + }, + .probe = pat9125_probe, + .remove = pat9125_remove, + .address_list = normal_i2c, + .id_table = pat9125_id, +}; + +module_i2c_driver(pat9125_driver); + +MODULE_AUTHOR("Alexandre Mergnat "); +MODULE_DESCRIPTION("Optical Tracking sensor"); +MODULE_LICENSE("GPL"); +