From patchwork Mon Oct 17 10:04:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 3366 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1363549wrs; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7qK/SXcuYjsO+krnYPcnoJrtpjyDihYjxchhXHwRE8icm6wCchBUq5c633ZokoPXS/dcmY X-Received: by 2002:a17:907:2cf1:b0:78d:c7a1:172d with SMTP id hz17-20020a1709072cf100b0078dc7a1172dmr7926241ejc.51.1666001372230; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001372; cv=none; d=google.com; s=arc-20160816; b=ZOEBYjae/byXRIAd5FOBAHGDG7wCgsKb4n5UGgDp6ftq177RZG9ps4mkF/avswVVz4 7DF/rmMz2hlhhjQNsdgsk3zG2+wDZvVIwntyvjZ0+vRK+EI2m1UrRou61g5dsgAcuCGu wpzp5u3insbrCNdO4NvQ+3gBMAboi5nAzih0FI7W4Xd7AfLBdfssPg4HFb9Zd+JASCxH 1sREpYrnnkd0c42JAFSVeRGsOo8VIPiPbB1M/voSH92HRsAwT0O+iKGUeRvUNctNt66R ppf0KQduSC8u3r3Bo7IGJajgUHGOgzIt3zLHmo1Ww0EPAFAHOgNkd+ou0b/mmztqYbB7 r8Eg== 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=l9BHDLmttWeYOs5g2PuG083SJb6QiJ8j+IRVJjZHwNo=; b=VyMyUZEeaE8T3ZH6XvtoEq2mWLU6L0PSxkXNOjoYgSbMEBsS1FtEHckDnSVaYJJUk1 Jf/UbOYbK+IdLNUYIAac8V+Zc6vgxdYZlTiss4BihdUkBSL72fCFpQgXYzoetcMt18fR t6c/pc1MgcrE50gYupVLsNwYOtMatKeYv4I4zGgisK1VCf1pAs5/d+gmL+jGhhAIGLIn 9xUNkBZvh3WINzVIzYLvgmmfYlRheIUOwr9tq+rlyFZy5qqQq7VHCV3qaXNrH9C/UTuA KTn2YhqASSbeEOqssykW4wCrfaU0N/xhEfo3uHtBMWIEJjfXHukHrhmiPmmioLdndfLW hxYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b="SIIOPSR/"; 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 ds1-20020a170907724100b0078dee0fce23si9697719ejc.123.2022.10.17.03.09.02; Mon, 17 Oct 2022 03:09:32 -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="SIIOPSR/"; 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 S231241AbiJQKFM (ORCPT + 99 others); Mon, 17 Oct 2022 06:05:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiJQKE6 (ORCPT ); Mon, 17 Oct 2022 06:04:58 -0400 Received: from mout-y-209.mailbox.org (mout-y-209.mailbox.org [91.198.250.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B95AB18E34; Mon, 17 Oct 2022 03:04:45 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4MrXfK0C5xz9tbR; Mon, 17 Oct 2022 12:04:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666001081; 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=l9BHDLmttWeYOs5g2PuG083SJb6QiJ8j+IRVJjZHwNo=; b=SIIOPSR/xAYC6BS3oDeG++iEq7vnakFf2A0PRKUG7f9OqLJO8gpndRzt9enjLVv0VQubXK 96EJF+16eS9Y1FJHKK4+F+aZK6anBtjw3WvPg/ukZ/A86O7RqeVmDlqRLlEc9hbecIBGPe Dvfb7R2OLCPpvUKojGXB0mRnuOYcdmb/h45uTRLSiYMTHBxd9gACrjsPYCpdJbrxEecxyi T0cKdr6hpmDuYHtZU5fnIk+xCz2/5ytCKBFyU3i8bYwJDN8IFTxJLCampm70Y59rDnxUce iLw7Wx4CIALSNiP6h743lSbQYbJUQxNJTk7e1gOroXhN1DwVSMjKvWsbWYmhuA== 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 v4 1/3] dt-bindings: touchscreen: add Himax hx83112b bindings Date: Mon, 17 Oct 2022 12:04:06 +0200 Message-Id: <20221017100409.189293-2-job@noorman.info> In-Reply-To: <20221017100409.189293-1-job@noorman.info> References: <20221017100409.189293-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MrXfK0C5xz9tbR 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?1746929054990481977?= X-GMAIL-MSGID: =?utf-8?q?1746929054990481977?= 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 9ddcc242081c..2418bffe9187 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9094,6 +9094,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 17 10:04:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 3364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1363450wrs; Mon, 17 Oct 2022 03:09:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Zu0zvoIhx+QR5Fa4U27QbdECmoc2J8HHx7L8YKtUimgzgJ/6PEWoz5Vh8INrwfeP6CxOO X-Received: by 2002:a17:906:cc0f:b0:78e:1208:8796 with SMTP id ml15-20020a170906cc0f00b0078e12088796mr7943575ejb.601.1666001359299; Mon, 17 Oct 2022 03:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001359; cv=none; d=google.com; s=arc-20160816; b=KaoXg24EPnhP7Y2yZgzZAH11/RVKk3vPMw5WPjhD3ULkwQNgddMcsVi6sPY5t63g0l X+GdziiQqCX6L2nlFAeYwa8VTTgIZLKl8ubLJhcvQ5qOX4ydbSgHK7eEF5UKVlJXjgJc hBzBDTayWtM8Iqs1eArH/l/RWLqjufkvzCvlWxsWMSdusPilfvbkgcgi1otOyycbJJ23 jONoyPFVIdPGUBVoNNXlmDqn+D9aPs3jT07MqNtNyPNkQ/b58C9KIVNhRll/O3HNama2 WYV0S9VWDWUTFRZ06fQVITHI20M0s6dFKmqzZwtuOoRA8NRAoM+kAdcnr7DznnGcHy/I NblA== 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=h6QfzRve5D0lCUNwNJjHMATpymf0hyMeZ/hqpUngBJ4=; b=pP7PYBImddwDMUnECYfXi8sFu8EQov6w83oY82Ra4jq6nvvmz7QgCQzfL6Oo903xtO EH43pUW1JU6N1uXJwDp2Yn+S7wtHD8tTvGiMASHbrLUdx2dUq//5zV9D1ZtwzbFjMUIO omt3VUNFxWl0A8fpddjZRpkxZuM+Of9IQ+go8H5MMAk2Bal3mAWRgaU6nhrUaDOAYKZi VMSL2BREVMRXUaJ+SSKnH2lyPBe8X8GUbAooVPY1SBRPrtdgk3qHka+zBpbbh30rmpyr m8Me7D2OpKYRCfOZ1DteFF0/0Z4xeMlGPgG5hQgf+1letOM7bnLdn/dcuiw5V7UM3s7M aDQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=R0dWi1yU; 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 hb7-20020a170907160700b0078decbc3f73si9073911ejc.460.2022.10.17.03.08.54; Mon, 17 Oct 2022 03:09:19 -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=R0dWi1yU; 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 S230434AbiJQKFD (ORCPT + 99 others); Mon, 17 Oct 2022 06:05:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231514AbiJQKEz (ORCPT ); Mon, 17 Oct 2022 06:04:55 -0400 Received: from mout-y-111.mailbox.org (mout-y-111.mailbox.org [91.198.250.236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B96C219009; Mon, 17 Oct 2022 03:04:46 -0700 (PDT) Received: from smtp202.mailbox.org (unknown [91.198.250.118]) (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 4MrXfL5PZYz9t00; Mon, 17 Oct 2022 12:04:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666001082; 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=h6QfzRve5D0lCUNwNJjHMATpymf0hyMeZ/hqpUngBJ4=; b=R0dWi1yUTVo87yMxmXc2f7eVdsrKGna1PhMq6/UuRafit4GlBm4IgbdjRXRr80B2bxsDJM TQwZkU2SQf+M1LKv1i0G6EAMwuPnQrbG57TU8dd6R/xB/crX+lcffVQzN2w8fAQ/TxCvEE o+V7EP6ptPsYXMYA6Fp5Pm0fIVVawcF0WaCbhBBnsbQT3RnaQI933IbW0srGO1PvDi0RoF 9CJ32WHuXu+BVS4dwo+1RSfikuFtIpIoq+3P0MZPky5FAY9+lnVz7ujnOWAcKqJj/gCEJq 3ipDcCAni9smGHR8sS8Ns1UlB3d30b+SMsMrvXQLckm6Eqz24lIBsZMRKBqorw== From: Job Noorman To: Dmitry Torokhov , Job Noorman , Henrik Rydberg Cc: Luca Weiss , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH v4 2/3] Input: add driver for Himax hx83112b touchscreen devices Date: Mon, 17 Oct 2022 12:04:07 +0200 Message-Id: <20221017100409.189293-3-job@noorman.info> In-Reply-To: <20221017100409.189293-1-job@noorman.info> References: <20221017100409.189293-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MrXfL5PZYz9t00 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?1746929041175562264?= X-GMAIL-MSGID: =?utf-8?q?1746929041175562264?= 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 --- MAINTAINERS | 1 + drivers/input/touchscreen/Kconfig | 11 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/himax_hx83112b.c | 367 +++++++++++++++++++++ 4 files changed, 380 insertions(+) create mode 100644 drivers/input/touchscreen/himax_hx83112b.c diff --git a/MAINTAINERS b/MAINTAINERS index 2418bffe9187..51a03f9586f1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9099,6 +9099,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..113b7dd7da2f 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -1379,4 +1379,15 @@ 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 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..6f76fe48cfdd --- /dev/null +++ b/drivers/input/touchscreen/himax_hx83112b.c @@ -0,0 +1,367 @@ +// 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; + } + + if (!himax_verify_checksum(ts, &event)) { + /* + * We cannot process the current event when it has an invalid + * checksum but we don't consider this a fatal error. + */ + return 0; + } + + himax_process_event(ts, &event); + return 0; +} + +static irqreturn_t himax_irq_handler(int irq, void *dev_id) +{ + struct himax_ts_data *ts = dev_id; + int 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(&client->dev, + "Failed to initialize regmap: %d\n", error); + return error; + } + + ts->gpiod_rst = devm_gpiod_get(&ts->client->dev, "reset", + GPIOD_OUT_HIGH); + error = PTR_ERR_OR_ZERO(ts->gpiod_rst); + if (error) { + if (error != -EPROBE_DEFER) + dev_err(&ts->client->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(&client->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 17 10:04:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Job Noorman X-Patchwork-Id: 3365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1363548wrs; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6wV7g0s6Oc27L6yhwOrGTWb5xPMyMfopVNA1a9zyTvPwYF0MQppRWMiA/2jC02JnLjj01h X-Received: by 2002:a17:907:2cd8:b0:78e:7fe:a38f with SMTP id hg24-20020a1709072cd800b0078e07fea38fmr8258566ejc.632.1666001372101; Mon, 17 Oct 2022 03:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666001372; cv=none; d=google.com; s=arc-20160816; b=rcSxbMQRNKTYe1MxgUalL9IPPfo8t8ogcUmRRPUe0IDoXy9hx1zdCflohhdVcqhIJY qhK8J9jVk7miu1q2wMOBZ0x2HN0M9TGWMSCdDuTwpn91zWcYFtyMg6xVx3cCBNQdpSNU qqfNGfdqwkoqJlcGJ7NMBfO9RDz8VIqV9br5+2odHyPmIX5W2HR6mvkhGYe8nA3NqLuB WePKTWpbiXYBB9f2ch6LL1ur9hQk2t5OPHeG7XZf+0uTRcIUuoI129IbO6zSTIp1x4Yo XSMs+3ybUos7wR8TjhahOTI024IMl6v2F8MpYWjs5NNrKK6tZnhgbai/b+ydkddgy++h rDLw== 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=S9dcsqJ0RaWCdCguljfpy7EPjfO3aVZqXfHBh2syRzs=; b=wS12nfQS5ARleJFJuz5Esa5ggBgAY9JBraapZ2JgOZQS5gRCC6e04ufsRj4Eq++FF3 5gUWKQVMp0n6mYosjESZAGIt4RGo5+kXTy6JrSfZzuNjCmR5CUV2whrg/EiKtxDl2dQn c0VYCmMd6iQH510QhDmdNAWMg2c1KhghTu/8nVreqRBx5Ie8aEiW9Jy6rgkOZMqDpIxK ZYoSjJFuyZE6zSXomdrRoqLSGnT42uwx4od/UhfxGpopUS+HGt89asRpLuOwzMzHAsY+ cbsFoEG6xmSuLp5hsNFb4d16PD/0OjCVMqeli01dtzIAlq/9xYEECfaUXDRQMDOiFMMJ 3O9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@noorman.info header.s=MBO0001 header.b=yZTCTWvd; 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 n11-20020a05640205cb00b0045d03c18e5bsi10853745edx.560.2022.10.17.03.09.02; Mon, 17 Oct 2022 03:09:32 -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=yZTCTWvd; 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 S231551AbiJQKFQ (ORCPT + 99 others); Mon, 17 Oct 2022 06:05:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230505AbiJQKE6 (ORCPT ); Mon, 17 Oct 2022 06:04:58 -0400 Received: from mout-y-209.mailbox.org (mout-y-209.mailbox.org [91.198.250.237]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68E7E11C31; Mon, 17 Oct 2022 03:04:48 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4MrXfN1mHtz9tdD; Mon, 17 Oct 2022 12:04:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=noorman.info; s=MBO0001; t=1666001084; 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=S9dcsqJ0RaWCdCguljfpy7EPjfO3aVZqXfHBh2syRzs=; b=yZTCTWvdLGN4BsYOh3C0a7UJh5dTHrIWyvQVAlb3hXKjWlfUUzhmwW1GYMUA77AzHjdhND eeAwUcwsQnJQZQHIVRXGan6WZRD0c7CiRkQUXAy/ehI2xDK7/8ySjrUZdGi6p9a7VRKsa9 t3xDI6myDB4usaILamMbnaPr1N+hoNrCzLnNSK0pHjUfwNdA0lD/FbzTomZm890OJj5lhn wywc1HINnuu4MvO4fTcSmWE6DFNCfMxtto8OvspRJYKpmJhXOdoXWg8lQ6JIxIOwF+l2um TeIfzKlZn7sBbCRtOz77N0C7eXFW/TePk+PUXi/ZJJK+d1mkCxjvsAPdmNLYkA== From: Job Noorman To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Rob Herring , Krzysztof Kozlowski Cc: Luca Weiss , Job Noorman , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 3/3] arm64: dts: qcom: sdm632: fairphone-fp3: add touchscreen Date: Mon, 17 Oct 2022 12:04:08 +0200 Message-Id: <20221017100409.189293-4-job@noorman.info> In-Reply-To: <20221017100409.189293-1-job@noorman.info> References: <20221017100409.189293-1-job@noorman.info> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4MrXfN1mHtz9tdD 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?1746929054538650844?= X-GMAIL-MSGID: =?utf-8?q?1746929054538650844?= 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 = ;