From patchwork Mon Oct 24 13:59:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 10386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp697200wru; Mon, 24 Oct 2022 16:13:04 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5xqSgBE/hS4vhxzQQNxrg3nu/fN7G4cvVVLpJ9Yhjgcrj2bdNkdwOXjGKso4hoPcuocsJx X-Received: by 2002:aa7:c041:0:b0:45c:1584:23db with SMTP id k1-20020aa7c041000000b0045c158423dbmr32892921edo.184.1666653184609; Mon, 24 Oct 2022 16:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666653184; cv=none; d=google.com; s=arc-20160816; b=kLKtMLOsvQRDn1H7bHsVo4j9C5BPGZP+QdONwQijcJnKv4VEVq1OS4u96+JmbCZMA8 4rDmWvw9ZZygUVSPgrrIAd48M9DE7JewAGTffnGY8sLWzGDZHrCrE9KKnbQiYIlHSLGj NMCxBtY+3SyGIwNOJHIvkCPbEPoKsAMagZQIEuinC0BkvAtgYYK2vd9k4CsTHnj2V9w1 5MmLnep+h32BITDXwNZjqWMkd11h5Y9QxEo7eQJobxquyBkPd/AcXn/kIcOiIJ707Jj9 PpVSqy3xjw/7kQ2zkRuWRIbvG+dcLivCL025IUmo6EPyBEiygmq40sy62j5XduEQNhpG ZLsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xgG1+/mqCR7NFJDaGitypAnL4fZThzOryVEVRuhQPXg=; b=LbTrdZ34rjyxohKzPjTDfTevSpf4HMF2nz0Y6HaFDPZ54EonSQm0SpEB5XR37z+3UN 8+zXQ0a36BPUd13Rpzy8V1kXvV5V2IX5i8mukx/1VTZGzc6ELE0jcUai9wEHLzH5sz73 tJFPexwTpumA7aS1Vfwh0IlopAyZo4QLAJL/ck6tMURQswnKt3aqCBJm2/E8Nf+JvP+E HbnKrSBDkhauV/BFzNAup86Lso4AtmPLtgI7AsiS77ZykvnOuN0ccvHePWoB6c7I/XUG ajvDCqbAZZYK5QBJmUnDVJZmsi4tZNiPy4V4zNq2R+3yVvcTIlFbRdGEQLJCIo51ZE7d fzDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=T7cdqwZp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr21-20020a170907721500b0072fc714c92fsi1064571ejc.902.2022.10.24.16.12.40; Mon, 24 Oct 2022 16:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=T7cdqwZp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230462AbiJXW51 (ORCPT + 99 others); Mon, 24 Oct 2022 18:57:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232178AbiJXW5E (ORCPT ); Mon, 24 Oct 2022 18:57:04 -0400 Received: from mout-y-111.mailbox.org (mout-y-111.mailbox.org [IPv6:2001:67c:2050:103:465::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DC7D261AD9; Mon, 24 Oct 2022 14:18:33 -0700 (PDT) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4MwxXv50gFz9tPh; Mon, 24 Oct 2022 16:00:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666620015; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xgG1+/mqCR7NFJDaGitypAnL4fZThzOryVEVRuhQPXg=; b=T7cdqwZpGNkSkEyO+O/KpPasMxKTDJiuAOIVWIJv2No/nvtQhnc+qp/MxVBP0X1iruNMA2 5f1b4yPBnHCI2MLv+Qm3y85xtU7LUvnL75T71ZGASKq+imAKa7VEbN/DrM2iFtK8V38yeV 2GUPIfOjKHGvWWrCuMKx8Hpw/3+DTnkYbPNOvrECLSExYSk7jODURST7MnwDB3sWkOLc0Y LiKhGpZSMMPEDfzj/HvI3GfmPRKa+W5LcuWV9syR9cq4esdltqcNu7AMIAwlZ8ClfeoBBS UpLJHytloQPUcppvsUzGjiXmdKISepCp0NYiAcpLyBrfLP/sKuViYojjJC3GTA== From: Job Noorman To: Job Noorman , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski Cc: Luca Weiss , Rob Herring , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 1/3] dt-bindings: touchscreen: add Himax hx83112b bindings Date: Mon, 24 Oct 2022 15:59:57 +0200 Message-Id: <20221024140001.139111-2-job@noorman.info> In-Reply-To: <20221024140001.139111-1-job@noorman.info> References: <20221024140001.139111-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MwxXv50gFz9tPh X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747612529651729837?= X-GMAIL-MSGID: =?utf-8?q?1747612529651729837?= This patch adds device tree bindings for Himax 83112b touchscreen devices. Signed-off-by: Job Noorman Reviewed-by: Rob Herring --- .../input/touchscreen/himax,hx83112b.yaml | 63 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml diff --git a/Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml b/Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml new file mode 100644 index 000000000000..be2ba185c086 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/himax,hx83112b.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Himax hx83112b touchscreen controller bindings + +maintainers: + - Job Noorman + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + enum: + - himax,hx83112b + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + touchscreen-inverted-x: true + touchscreen-inverted-y: true + touchscreen-size-x: true + touchscreen-size-y: true + touchscreen-swapped-x-y: true + +additionalProperties: false + +required: + - compatible + - reg + - interrupts + - reset-gpios + - touchscreen-size-x + - touchscreen-size-y + +examples: + - | + #include + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + touchscreen@48 { + compatible = "himax,hx83112b"; + reg = <0x48>; + interrupt-parent = <&tlmm>; + interrupts = <65 IRQ_TYPE_LEVEL_LOW>; + touchscreen-size-x = <1080>; + touchscreen-size-y = <2160>; + reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>; + }; + }; + +... diff --git a/MAINTAINERS b/MAINTAINERS index cf0f18502372..469ab6382906 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9162,6 +9162,12 @@ W: http://www.highpoint-tech.com F: Documentation/scsi/hptiop.rst F: drivers/scsi/hptiop.c +HIMAX HX83112B TOUCHSCREEN SUPPORT +M: Job Noorman +L: linux-input@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml + HIPPI M: Jes Sorensen L: linux-hippi@sunsite.dk From patchwork Mon Oct 24 13:59:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 9860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp559690wru; Mon, 24 Oct 2022 10:06:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6OaXwnGa1jJt0/cjSmb8kXkoS3cx+HIWHuLwcNRTzWBrFB2+LPnKEOzkps+hBMFBcsotkf X-Received: by 2002:a17:90a:b28d:b0:20d:6790:19fa with SMTP id c13-20020a17090ab28d00b0020d679019famr74531681pjr.68.1666631214570; Mon, 24 Oct 2022 10:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666631214; cv=none; d=google.com; s=arc-20160816; b=SHhsCaUbEVr/OEiRNHOIVjB25Fug8PkA0VvemP0qB3c1IYx5nA64TPaYlDMRntCj72 3wbNH5C5Pc+8+R9glEmzLQbibxSiWhVzSM9FYc2BJYDDuB/ukjsNNd4WO0B9aGmv8Uv+ syZ7xCi3+T/4UvwKZAxkfAuMKgxVFj71O1lH9kAf6O4e8F3HW+eaz+eJ+lzkWWPQkDlv yXF73S7dwarjVLORskNw4SmtoNRZt6IU0jQAuCVavNz7drAoAe7XQRHLK9zU2GxbPDlY tLY1Sc62zQcD4r4d5f4uRmtLxe/MbUeu5NVIrAaZT8LrwFk+kRm/TIk+BEz6iPSZHYkE xGeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+Hu6KOzMv3HxBQv4jJSlS0/i8Q4iFlmmsPQVlXEuvAo=; b=utA/2xMUmaRXnYIQDQw60O5bc6+q03nmD9gBgFbCjUVxA2VTfOBRGHDuSab5N38AAQ tPiuqvFvu0Gn6YXf5AXFay/AB55blZyCpNVkBwmvdn5BbjD25kTifSUhM1WHCy4laXPc EayP0V28ZsCq4hb6nRUcfWh2Q+2qBukjqhsBAbVaDZhT87DqAUYs9+c9x/Jcj21VC0LP elgY2+w+WJBYgfUedV67528QUckIdhsSw9ZGiMlvys7oi9lFHbNngWN12z/AyF/8hvWg bXw4q00JZksk8Jd/FVWH3jh83EhLvKVbUHkE/fn1GbDM1Vu9mIAwK0mu27Ool8azkoCP wCHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=gb3Gp484; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iy4-20020a170903130400b00186ac934b2dsi14817plb.284.2022.10.24.10.06.40; Mon, 24 Oct 2022 10:06:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=gb3Gp484; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234054AbiJXRFh (ORCPT + 99 others); Mon, 24 Oct 2022 13:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233538AbiJXRDI (ORCPT ); Mon, 24 Oct 2022 13:03:08 -0400 Received: from mout-y-111.mailbox.org (mout-y-111.mailbox.org [IPv6:2001:67c:2050:103:465::111]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B60829CAE; Mon, 24 Oct 2022 08:39:37 -0700 (PDT) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-111.mailbox.org (Postfix) with ESMTPS id 4MwxXx59l0z9tPm; Mon, 24 Oct 2022 16:00:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666620017; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Hu6KOzMv3HxBQv4jJSlS0/i8Q4iFlmmsPQVlXEuvAo=; b=gb3Gp484/6Z1HFlmZwFwTIKx7eCtmbKPDe3HYDdmTR1r0Ec8RpJbqAvI77qWeYp74jz/gb kr9uffm6EXyfUFM/vuF5eBzQ6bZCxFmwbbwqLcJWY0L/dvY3/bwWQJfj5FpzWuScKSLVLs bzshoal7btUw1BuDME0y5cI2wKu7EzfkCJNIKTpyj0v1ZHSEqUrGJZi8NeB0fDeRblOJyh gn21DBGDUGC+fL8+MaR86qy1hnXlnipNUBRH51sMKLtvEfTudb9RfKPiaW8ghsiY+3k2Yg GCuxTW6e0F3iFa9+MQGEWg4N2S8Gf7QlOPtNUD4pS3Uj1O8gczRojjUf0N95Gg== From: Job Noorman To: Dmitry Torokhov , Job Noorman , Henrik Rydberg Cc: Luca Weiss , Jeff LaBundy , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH v6 2/3] Input: add driver for Himax hx83112b touchscreen devices Date: Mon, 24 Oct 2022 15:59:58 +0200 Message-Id: <20221024140001.139111-3-job@noorman.info> In-Reply-To: <20221024140001.139111-1-job@noorman.info> References: <20221024140001.139111-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MwxXx59l0z9tPm X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747589492381805235?= X-GMAIL-MSGID: =?utf-8?q?1747589492381805235?= This patch adds support for Himax hx83112b touchscreen devices. As there are no publicly available data sheets for these devices, the implementation is based on the driver of the downstream Android kernel used in the Fairphone 3. This patch is a complete rewrite, though, and the code bears no resemblence to the original implementation. The driver has been tested on the aforementioned phone. Signed-off-by: Job Noorman Reviewed-by: Jeff LaBundy --- MAINTAINERS | 1 + drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/himax_hx83112b.c | 361 +++++++++++++++++++++ 4 files changed, 375 insertions(+) create mode 100644 drivers/input/touchscreen/himax_hx83112b.c diff --git a/MAINTAINERS b/MAINTAINERS index 469ab6382906..8d9fe0ac632c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9167,6 +9167,7 @@ M: Job Noorman L: linux-input@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/input/touchscreen/himax,hx83112b.yaml +F: drivers/input/touchscreen/himax_hx83112b.c HIPPI M: Jes Sorensen diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index dc90a3ea51ee..8cdb16a811e6 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1379,4 +1379,16 @@ config TOUCHSCREEN_ZINITIX To compile this driver as a module, choose M here: the module will be called zinitix. +config TOUCHSCREEN_HIMAX_HX83112B + tristate "Himax hx83112b touchscreen driver" + depends on I2C + select REGMAP_I2C + help + Say Y here to enable support for Himax hx83112b touchscreens. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called himax_hx83112b. + endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 557f84fd2075..0f8bf79e01fe 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -116,3 +116,4 @@ obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023) += rohm_bu21023.o obj-$(CONFIG_TOUCHSCREEN_RASPBERRYPI_FW) += raspberrypi-ts.o obj-$(CONFIG_TOUCHSCREEN_IQS5XX) += iqs5xx.o obj-$(CONFIG_TOUCHSCREEN_ZINITIX) += zinitix.o +obj-$(CONFIG_TOUCHSCREEN_HIMAX_HX83112B) += himax_hx83112b.o diff --git a/drivers/input/touchscreen/himax_hx83112b.c b/drivers/input/touchscreen/himax_hx83112b.c new file mode 100644 index 000000000000..ed550cd33eb7 --- /dev/null +++ b/drivers/input/touchscreen/himax_hx83112b.c @@ -0,0 +1,361 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for Himax hx83112b touchscreens + * + * Copyright (C) 2022 Job Noorman + * + * This code is based on "Himax Android Driver Sample Code for QCT platform": + * + * Copyright (C) 2017 Himax Corporation. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HIMAX_ID_83112B 0x83112b + +#define HIMAX_MAX_POINTS 10 + +#define HIMAX_REG_CFG_SET_ADDR 0x00 +#define HIMAX_REG_CFG_INIT_READ 0x0c +#define HIMAX_REG_CFG_READ_VALUE 0x08 +#define HIMAX_REG_READ_EVENT 0x30 + +#define HIMAX_CFG_PRODUCT_ID 0x900000d0 + +#define HIMAX_INVALID_COORD 0xffff + +struct himax_event_point { + __be16 x; + __be16 y; +} __packed; + +struct himax_event { + struct himax_event_point points[HIMAX_MAX_POINTS]; + u8 majors[HIMAX_MAX_POINTS]; + u8 pad0[2]; + u8 num_points; + u8 pad1[2]; + u8 checksum_fix; +} __packed; + +static_assert(sizeof(struct himax_event) == 56); + +struct himax_ts_data { + struct gpio_desc *gpiod_rst; + struct input_dev *input_dev; + struct i2c_client *client; + struct regmap *regmap; + struct touchscreen_properties props; +}; + +static const struct regmap_config himax_regmap_config = { + .reg_bits = 8, + .val_bits = 32, + .val_format_endian = REGMAP_ENDIAN_LITTLE, +}; + +static int himax_read_config(struct himax_ts_data *ts, u32 address, u32 *dst) +{ + int error; + + error = regmap_write(ts->regmap, HIMAX_REG_CFG_SET_ADDR, address); + if (error) + return error; + + error = regmap_write(ts->regmap, HIMAX_REG_CFG_INIT_READ, 0x0); + if (error) + return error; + + error = regmap_read(ts->regmap, HIMAX_REG_CFG_READ_VALUE, dst); + if (error) + return error; + + return 0; +} + +static void himax_reset(struct himax_ts_data *ts) +{ + gpiod_set_value_cansleep(ts->gpiod_rst, 1); + + /* Delay copied from downstream driver */ + msleep(20); + gpiod_set_value_cansleep(ts->gpiod_rst, 0); + + /* + * The downstream driver doesn't contain this delay but is seems safer + * to include it. The range is just a guess that seems to work well. + */ + usleep_range(1000, 1100); +} + +static int himax_read_product_id(struct himax_ts_data *ts, u32 *product_id) +{ + int error; + + error = himax_read_config(ts, HIMAX_CFG_PRODUCT_ID, product_id); + if (error) + return error; + + *product_id >>= 8; + return 0; +} + +static int himax_check_product_id(struct himax_ts_data *ts) +{ + int error; + u32 product_id; + + error = himax_read_product_id(ts, &product_id); + if (error) + return error; + + dev_dbg(&ts->client->dev, "Product id: %x\n", product_id); + + switch (product_id) { + case HIMAX_ID_83112B: + return 0; + + default: + dev_err(&ts->client->dev, + "Unknown product id: %x\n", product_id); + return -EINVAL; + } +} + +static int himax_input_register(struct himax_ts_data *ts) +{ + int error; + + ts->input_dev = devm_input_allocate_device(&ts->client->dev); + if (!ts->input_dev) { + dev_err(&ts->client->dev, "Failed to allocate input device\n"); + return -ENOMEM; + } + + ts->input_dev->name = "Himax Touchscreen"; + + input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_X); + input_set_capability(ts->input_dev, EV_ABS, ABS_MT_POSITION_Y); + input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0); + input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 200, 0, 0); + + touchscreen_parse_properties(ts->input_dev, true, &ts->props); + + error = input_mt_init_slots(ts->input_dev, HIMAX_MAX_POINTS, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (error) { + dev_err(&ts->client->dev, + "Failed to initialize MT slots: %d\n", error); + return error; + } + + error = input_register_device(ts->input_dev); + if (error) { + dev_err(&ts->client->dev, + "Failed to register input device: %d\n", error); + return error; + } + + return 0; +} + +static u8 himax_event_get_num_points(const struct himax_event *event) +{ + if (event->num_points == 0xff) + return 0; + else + return event->num_points & 0x0f; +} + +static bool himax_process_event_point(struct himax_ts_data *ts, + const struct himax_event *event, + int point_index) +{ + const struct himax_event_point *point = &event->points[point_index]; + u16 x = be16_to_cpu(point->x); + u16 y = be16_to_cpu(point->y); + u8 w = event->majors[point_index]; + + if (x == HIMAX_INVALID_COORD || y == HIMAX_INVALID_COORD) + return false; + + input_mt_slot(ts->input_dev, point_index); + input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); + touchscreen_report_pos(ts->input_dev, &ts->props, x, y, true); + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); + input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); + return true; +} + +static void himax_process_event(struct himax_ts_data *ts, + const struct himax_event *event) +{ + int i; + int num_points_left = himax_event_get_num_points(event); + + for (i = 0; i < HIMAX_MAX_POINTS && num_points_left > 0; i++) { + if (himax_process_event_point(ts, event, i)) + num_points_left--; + } + + input_mt_sync_frame(ts->input_dev); + input_sync(ts->input_dev); +} + +static bool himax_verify_checksum(struct himax_ts_data *ts, + const struct himax_event *event) +{ + u8 *data = (u8 *)event; + int i; + u16 checksum = 0; + + for (i = 0; i < sizeof(*event); i++) + checksum += data[i]; + + if ((checksum & 0x00ff) != 0) { + dev_err(&ts->client->dev, "Wrong event checksum: %04x\n", + checksum); + return false; + } + + return true; +} + +static int himax_handle_input(struct himax_ts_data *ts) +{ + int error; + struct himax_event event; + + error = regmap_raw_read(ts->regmap, HIMAX_REG_READ_EVENT, &event, + sizeof(event)); + if (error) { + dev_err(&ts->client->dev, "Failed to read input event: %d\n", + error); + return error; + } + + /* + * Only process the current event when it has a valid checksum but + * don't consider it a fatal error when it doesn't. + */ + if (himax_verify_checksum(ts, &event)) + himax_process_event(ts, &event); + + return 0; +} + +static irqreturn_t himax_irq_handler(int irq, void *dev_id) +{ + int error; + struct himax_ts_data *ts = dev_id; + + error = himax_handle_input(ts); + if (error) + return IRQ_NONE; + + return IRQ_HANDLED; +} + +static int himax_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int error; + struct device *dev = &client->dev; + struct himax_ts_data *ts; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(dev, "I2C check functionality failed\n"); + return -ENXIO; + } + + ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + if (!ts) + return -ENOMEM; + + i2c_set_clientdata(client, ts); + ts->client = client; + + ts->regmap = devm_regmap_init_i2c(client, &himax_regmap_config); + error = PTR_ERR_OR_ZERO(ts->regmap); + if (error) { + dev_err(dev, "Failed to initialize regmap: %d\n", error); + return error; + } + + ts->gpiod_rst = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); + error = PTR_ERR_OR_ZERO(ts->gpiod_rst); + if (error) { + dev_err(dev, "Failed to get reset GPIO: %d\n", error); + return error; + } + + himax_reset(ts); + + error = himax_check_product_id(ts); + if (error) + return error; + + error = himax_input_register(ts); + if (error) + return error; + + return devm_request_threaded_irq(dev, client->irq, NULL, + himax_irq_handler, IRQF_ONESHOT, + client->name, ts); +} + +static int himax_suspend(struct device *dev) +{ + struct himax_ts_data *ts = dev_get_drvdata(dev); + + disable_irq(ts->client->irq); + return 0; +} + +static int himax_resume(struct device *dev) +{ + struct himax_ts_data *ts = dev_get_drvdata(dev); + + enable_irq(ts->client->irq); + return 0; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(himax_pm_ops, himax_suspend, himax_resume); + +static const struct i2c_device_id himax_ts_id[] = { + { "hx83112b", 0 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(i2c, himax_ts_id); + +#ifdef CONFIG_OF +static const struct of_device_id himax_of_match[] = { + { .compatible = "himax,hx83112b" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, himax_of_match); +#endif + +static struct i2c_driver himax_ts_driver = { + .probe = himax_probe, + .id_table = himax_ts_id, + .driver = { + .name = "Himax-hx83112b-TS", + .of_match_table = of_match_ptr(himax_of_match), + .pm = pm_sleep_ptr(&himax_pm_ops), + }, +}; +module_i2c_driver(himax_ts_driver); + +MODULE_AUTHOR("Job Noorman "); +MODULE_DESCRIPTION("Himax hx83112b touchscreen driver"); +MODULE_LICENSE("GPL"); From patchwork Mon Oct 24 13:59:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 9882 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp570080wru; Mon, 24 Oct 2022 10:30:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7eXRs57u3U0cn7pbnvVQHk7Tj3vuytkA/65cyXE7swa7Lf5gcFO4unXGJehqmBokJZk8aT X-Received: by 2002:a05:6402:27c6:b0:461:e426:dc8b with SMTP id c6-20020a05640227c600b00461e426dc8bmr3284034ede.403.1666632609055; Mon, 24 Oct 2022 10:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666632609; cv=none; d=google.com; s=arc-20160816; b=kbNyekQUUakKIjZecC7wFRvcvxHt6N5s2Nyf/gNeDusCIc6UkUrQgUkdqJu/rWbaio 9/Qd5esR1hhlL0yzbiWvUkPKYxyerKSKmB9moChA8eqmauwX/QEb4+Kmxn7teURFANip 0V0LVPYHnCL7UW+L7wkoiPFnk+SFgqmtmmq8ipcEH9uEBU+u04Dr070vcOwBJ9sk440D pQ2cCniw8cPYluWVOh7dz/HhMzfifyWuV3BFtLFglUmjhVV0BA7BuAl3bpaxs7ux657u Q/iWBeRnTSiU/3b+M6HNa/mcEh3d73lFRKNZpQ6ssOab0S0iFUEv1PcrEYP9ll1gO/XX 6vRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jwBbiiF+pKf0bcTgRsblZnn0hi/Wak5zHyTIoUTbsXg=; b=EWb5Zo+l0VaokaGXkxn99FZ2RcGafdGr8uJnrvd0uBxcNbkrf9BY0EVfQgkhOfrgZW FhEizKRMkHD41y2y4IBmUQ8QH2NhhYilbgYoX+PauVWdVkn9AHp+1Rq+An77r1sJ0iM9 96bzaylWRCD0S1hpvP2QHRvfBz1ICKzFKoVgbOHReD+wETiBs2lLFHqlGn8v541k2ACM z+K/NEM/XkQh6/0e+L9GRE5+EuVc6kLHmmTyWV0eUzxGQSI6G8eiKaBRLWHwC6auudEO bF1NzL7Ge3G3jjvV60d+/VNQobKeBSom/DkZuHiqBlqGrgc9z7bMd9Bm4eGbw4c/ir4Y iBeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=X9tiX3Wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nb15-20020a1709071c8f00b007a6c5a23a48si348320ejc.551.2022.10.24.10.29.44; Mon, 24 Oct 2022 10:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=X9tiX3Wt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=noorman.info Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230494AbiJXRWl (ORCPT + 99 others); Mon, 24 Oct 2022 13:22:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234416AbiJXRWB (ORCPT ); Mon, 24 Oct 2022 13:22:01 -0400 Received: from mout-y-209.mailbox.org (mout-y-209.mailbox.org [IPv6:2001:67c:2050:103:465::209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7070419C058; Mon, 24 Oct 2022 08:56:40 -0700 (PDT) Received: from smtp1.mailbox.org (unknown [91.198.250.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-y-209.mailbox.org (Postfix) with ESMTPS id 4MwxXz37PLz9tXK; Mon, 24 Oct 2022 16:00:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666620019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jwBbiiF+pKf0bcTgRsblZnn0hi/Wak5zHyTIoUTbsXg=; b=X9tiX3WtVJIGoT6Io4l77o5nM7sGiyP2NDU2lLNKA1lc58X1abNUvndGiAM2k7TgLlfIkE kwvGHv4g+T1hllgldThejlma9JjOR5KhDPL9LYRjWSzr7E7kjLO0UljYTlqRn2QyBX9lQg wg/fGUc1BRTbXLEvbxeCb6j1HN+eDro1n2De/CIXnpWL3jmlxn24lQrmsvYlTaOLMb2ic5 LYNXk0Aa59+OSl/OoEOujYf0iNhGuyp++GrYYi9KtSGhpvIAI05QiiRsztxkUr1MXk8UUW Nd31b+DsTTonahKvjjx5mcUYzOGtTPlm8eUY5BkayKNBj5tAgJUT6h0rvS+jAQ== From: Job Noorman To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski Cc: Luca Weiss , Job Noorman , Krzysztof Kozlowski , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 3/3] arm64: dts: qcom: sdm632: fairphone-fp3: add touchscreen Date: Mon, 24 Oct 2022 15:59:59 +0200 Message-Id: <20221024140001.139111-4-job@noorman.info> In-Reply-To: <20221024140001.139111-1-job@noorman.info> References: <20221024140001.139111-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MwxXz37PLz9tXK X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747590954885878124?= X-GMAIL-MSGID: =?utf-8?q?1747590954885878124?= Add Himax hx83112b touchscreen to the FP3 DT. Signed-off-by: Job Noorman Reviewed-by: Krzysztof Kozlowski --- arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts b/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts index 891e314bc782..2920504461d3 100644 --- a/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts +++ b/arch/arm64/boot/dts/qcom/sdm632-fairphone-fp3.dts @@ -49,6 +49,20 @@ &hsusb_phy { vdda-phy-dpdm-supply = <&pm8953_l13>; }; +&i2c_3 { + status = "okay"; + + touchscreen@48 { + compatible = "himax,hx83112b"; + reg = <0x48>; + interrupt-parent = <&tlmm>; + interrupts = <65 IRQ_TYPE_LEVEL_LOW>; + touchscreen-size-x = <1080>; + touchscreen-size-y = <2160>; + reset-gpios = <&tlmm 64 GPIO_ACTIVE_LOW>; + }; +}; + &pm8953_resin { status = "okay"; linux,code = ;