From patchwork Mon Nov 6 08:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 741634 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D4E3C0018A for ; Mon, 6 Nov 2023 08:34:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231289AbjKFIeH (ORCPT ); Mon, 6 Nov 2023 03:34:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231202AbjKFIeG (ORCPT ); Mon, 6 Nov 2023 03:34:06 -0500 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B931D47 for ; Mon, 6 Nov 2023 00:34:02 -0800 (PST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-40907b82ab9so29907225e9.1 for ; Mon, 06 Nov 2023 00:34:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699259641; x=1699864441; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=31dDSPmTEwAk2xBEYscYsgGP3NvqtS1pbeFP7C1NdB4=; b=EifMfDWGLfmvhxW303ApSFWk6FNqHN5+bzCaFjwrdtZ0JaKvlQiKxvUX0h2S0iw/a+ E9SEvnW3aY9GZtfLVjR9ZaSzCk5G1Nrc7Hd88rQjzaXycClejrd6myVtJPpsg/o1KlUz A5bYcQO/02pPWJywg6zn+1cGtVJasoizxmbYzYP7/Xu+0Kmti6uCQvROMziEY0OyrC3C QuTSjmIH9HR5EE/yD9A0b3D4vbCMg6PhcovtRWfd6iw3Z3Y9ql/ACD4qc9ughzhtiw+E qEkMXs/L1NKdEp3FKrUsaBFk4YAqOUnY49SO5uBbHimpVBkOWSj41uNmM37NxK7FCLIl A9Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699259641; x=1699864441; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=31dDSPmTEwAk2xBEYscYsgGP3NvqtS1pbeFP7C1NdB4=; b=NzOkMkcz2lkFbw0oKqfn+oRAU7Wxzf3vA7S9FG2II47f9ea+wRqucuExOh5mffJVz1 J2dttbnRO55dKnP8Fw+BSso80RaHoK29YRgKlKDrV0hdH25/XMx74rS+WPKvHG3kRm5Q PIHckHffPWxGuppXu9AOt35Jz6+XPI7oUmOd+TQj5NGpDphg1uX7KmPgjhhBy4cBEEX7 JShgjgHJEzVF7gT2JBIFgYo5cXOYjYBl6vDYYbk2cpsyBb0x5Tgnj8Y1Zoz6IerJ2o8f bcPBWT8e4ncsH+iZ5QYW7sHc9eF+uw/yVR7iAQOKZDaXQKj8p4TlP1OJ9mmRKcpNyr2w O/hQ== X-Gm-Message-State: AOJu0YybGheh2VGqXia8UoOg+oF/qBy0rp3BS29mcz9sp6rQgboUT3Kc 39G/B0++kcCUF0oM+0e/kYqtlw== X-Google-Smtp-Source: AGHT+IF1lIvUnDu4ryB7v1WnbFD2iFOhMO+MpX4NuYm+pN4GRFwFu2Rykf5XDHYpKYGHg/33gMkSwg== X-Received: by 2002:a05:600c:3b14:b0:405:3f06:d2ef with SMTP id m20-20020a05600c3b1400b004053f06d2efmr10335512wms.4.1699259640971; Mon, 06 Nov 2023 00:34:00 -0800 (PST) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id q24-20020a7bce98000000b0040648217f4fsm11132991wmj.39.2023.11.06.00.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 00:34:00 -0800 (PST) From: Neil Armstrong Date: Mon, 06 Nov 2023 09:33:56 +0100 Subject: [PATCH v11 1/4] dt-bindings: input: document Goodix Berlin Touchscreen IC MIME-Version: 1.0 Message-Id: <20231106-topic-goodix-berlin-upstream-initial-v11-1-5c47e9707c03@linaro.org> References: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> In-Reply-To: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bastien Nocera , Hans de Goede , Henrik Rydberg , Jeff LaBundy , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong , Rob Herring X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3093; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=sfk9uxvNPIwk9f8d5iBn9m2N4nTZgMQFpRmAil1gnVU=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBlSKT0fNTCUzanqriHuEA5SmSalaSvfvYk/BWuQMbO rZo+49uJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZUik9AAKCRB33NvayMhJ0VWTD/ 4uuraJ0vtjWd9ZAkmH1J1mSbuUK1CmLr3JV9RSzdxBib1OI++2Ut3X8SLdKcz3Qxa2JxTsaSdIBNyl Fl6Go+7OC3tMqh/kO0DclKx7GlCqq6jg8JiKJXwyFvX0WndMDe1tRFVkDEibmpOT5DsOHR39s16QHB uQYt7DeMolyw8iOa2Z+XNA7YP34TmYMFx9bJDe8IHjByy5FjtkGmaL4Leyw6yhlcnahSritfjqUkef Gsm7XVOl9xEtEv9NccN74gwOuaPI9lg9tVdu4TFAnUblIx8sjSv+WkGjd/+JImVphmQIxgnBa409+m pCl7+9DlNZJGb7fgUFHIipv+WLtBuQwJ7ZxENTi7szCNMEUAHuuqsa0XBgFN0aasdG7nNmqYcoH9IG alochTBY3ImFqnbU2krvA7Htt0VzX7Ez3Vsv7Whc8A168uQJuwoqBxz8OsQKSRLJGmCqBj/dmeSUPH suygHLZJ2JODuop7+YJWMA2jNL6LlfGwN09WqqeJpNGN6tHW76bXG0A4+KrkJgM46bP9CqaytUiDWM QRM9jKwy+QswXT+nvzAdtfIsW/P55NeLs45j3+tNEIn33LsYlCiH7LWKPBZ4edL//vLiIq2UX6rsNu 0s7ve8iJOKDn3gVpFlG3E+95zpYXHL8XJambhHeIg5mMOjrs8DM+HKs4DrBA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Document the Goodix GT9916 wich is part of the "Berlin" serie of Touchscreen controllers IC from Goodix. Reviewed-by: Rob Herring Signed-off-by: Neil Armstrong --- .../bindings/input/touchscreen/goodix,gt9916.yaml | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/Documentation/devicetree/bindings/input/touchscreen/goodix,gt9916.yaml b/Documentation/devicetree/bindings/input/touchscreen/goodix,gt9916.yaml new file mode 100644 index 000000000000..d90f045ac06c --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/goodix,gt9916.yaml @@ -0,0 +1,95 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/goodix,gt9916.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Goodix Berlin series touchscreen controller + +description: The Goodix Berlin series of touchscreen controllers + be connected to either I2C or SPI buses. + +maintainers: + - Neil Armstrong + +allOf: + - $ref: touchscreen.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + enum: + - goodix,gt9916 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + avdd-supply: + description: Analog power supply regulator on AVDD pin + + vddio-supply: + description: power supply regulator on VDDIO pin + + spi-max-frequency: true + 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 + - avdd-supply + - touchscreen-size-x + - touchscreen-size-y + +examples: + - | + #include + #include + i2c { + #address-cells = <1>; + #size-cells = <0>; + touchscreen@5d { + compatible = "goodix,gt9916"; + reg = <0x5d>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_LEVEL_LOW>; + reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>; + avdd-supply = <&ts_avdd>; + touchscreen-size-x = <1024>; + touchscreen-size-y = <768>; + }; + }; + - | + #include + #include + spi { + #address-cells = <1>; + #size-cells = <0>; + num-cs = <1>; + cs-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>; + touchscreen@0 { + compatible = "goodix,gt9916"; + reg = <0>; + interrupt-parent = <&gpio>; + interrupts = <25 IRQ_TYPE_LEVEL_LOW>; + reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>; + avdd-supply = <&ts_avdd>; + spi-max-frequency = <1000000>; + touchscreen-size-x = <1024>; + touchscreen-size-y = <768>; + }; + }; + +... From patchwork Mon Nov 6 08:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 741633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8090C001DB for ; Mon, 6 Nov 2023 08:34:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231381AbjKFIeJ (ORCPT ); Mon, 6 Nov 2023 03:34:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231307AbjKFIeJ (ORCPT ); Mon, 6 Nov 2023 03:34:09 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE540D57 for ; Mon, 6 Nov 2023 00:34:03 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-408382da7f0so31495505e9.0 for ; Mon, 06 Nov 2023 00:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699259642; x=1699864442; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZSYhUIAXXomRdTRQe0GV+ZtRHBAGTkbKoPRmZyWR3JA=; b=B7VHcvtD1yNeKLCkWCOjGdyhku0hxmnJw+9KlJ3apHXCSKxLnOWDMsMvalXwFHCZ0d O/8TJ+CjoKRUFntF75ldbFLcHHDVgWEHlCDPg2Q9QW94J3Z8Jg9dVriJpuJtQsbIZc4m Bz9/aeeCaPwcf90GqMrJy2sOgGge0HXqJhj91jV/+lGftcMTG/Js+mSDbEkvrHUa5mEy 88zFVyd1MxVTR65NztqNu4UmjRxvSotK1UD/cAXCbrqaEHNBppi5BKb0SSIg0GjaTfsb qb0N/HlDVkl2XES3lIEp0vlRkJfZLAz+cP1tlilJ1mXQ8NWucwPcEvEXFGd69Ffw9n53 ESxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699259642; x=1699864442; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZSYhUIAXXomRdTRQe0GV+ZtRHBAGTkbKoPRmZyWR3JA=; b=im08L9d+pCvnyKpocNEo4KvGVDwgChbMic4A7NlhPFEXkGRCHu9MUVXUhIGC3VLomx Z/uOeiKYVM8albi8zUMqzrDS9jl76S+eHyn/fMFNKdKK6FFT08isNH3cQRgcYu7B05KJ SsZAp5BhYZkofXkizyK2bf3uO1D1mgdpbcdxY1ErnyIp8R9SHH4nvy3cGGc4bhYvivQX onu4dOUiuZ0I3UaLZwxfFt8ejHhOlp3uYo9MzROIPT3qw/eWe7qagMfpeOkIkw4HdTrH qxHItO3eqDWfULZaHcBWETGVI/K7o67TkUP+12p/SgL9vMp4GD3btvuFO3LV2nHb1lz8 bX0A== X-Gm-Message-State: AOJu0Yxz+Uf0t9ZNYUZ9BGwJoyAbh4WEg4dsTMRB/tzMbhd7B+sB2WHR jO5SAC0yYEQ3OoVeCL+fyfgGdw== X-Google-Smtp-Source: AGHT+IHpLBEsjQFqFGTUDnACLeuxSKsjktakrNilWVGXBeTbyFYodZ/Trx2srGhrznJyu/baCyRBuw== X-Received: by 2002:a05:600c:5119:b0:406:849f:f3cd with SMTP id o25-20020a05600c511900b00406849ff3cdmr23980116wms.29.1699259642023; Mon, 06 Nov 2023 00:34:02 -0800 (PST) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id q24-20020a7bce98000000b0040648217f4fsm11132991wmj.39.2023.11.06.00.34.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 00:34:01 -0800 (PST) From: Neil Armstrong Date: Mon, 06 Nov 2023 09:33:57 +0100 Subject: [PATCH v11 2/4] Input: add core support for Goodix Berlin Touchscreen IC MIME-Version: 1.0 Message-Id: <20231106-topic-goodix-berlin-upstream-initial-v11-2-5c47e9707c03@linaro.org> References: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> In-Reply-To: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bastien Nocera , Hans de Goede , Henrik Rydberg , Jeff LaBundy , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=23127; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=4dcrGEOCp59/X1pRbMmVSwiAkVUfK8MPaylzNqpOHCM=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBlSKT10OyErAnZ7St4MYtSipHAsFvBiq4YlMzC7duC EwKGGvKJAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZUik9QAKCRB33NvayMhJ0bRnD/ 9JGdLbhOID0TzIMrn2vUvZMx+ofwr2WMp/UFW9ILwitq8/NNqr2425Wq7IX8YCGFJtLhavN5fTW39y YKJEh574b9Ewo+FKXJktiO+jeU7HpF4SDeuHoD+hNXpHRGaHUj2N2tk/QbVDNKOxFqx5w87weffvBI 07K+a88k8jD4rfPKEQKY9Lbx/e/6VhA0MmUOhxtgAyt2rvvw6iugrwZn42mbOrOF7gXqa915vws0WR zvFetDj+NRlMrCn0QiPpOMVqvASu0OmiFW/G0bKmg3ctwyEh5RlWzV04KxItiXsu6SafExRdXRJh0s sD/TMXI8b3GN/j+YTfUVi9iSlm2m/b5sJZHTnf5EqOKQERrmwTEPhFZyxnKfSbe700xa85xylOUx5+ ElG1Cch9ufpuWr/BdIrnSi6/WX8AB8UuWZEIqEO51RLoohvyREHOgAvEGHSWNMTSYPFfxypNEFg2dm NQdVhsBLVqU6AnW/pJEl7teuohhjQapvUGIfexPOo3HDCMyK1P0HEihkrR3VxPcDrjJdW1ZYpCtmgS WeL4Z+sgg8N4CrMbXa0z2wbCR4ybd+FriY6cTt2WO53+MpEOLZE0zNzQ5fCgz9oaQtKK2p+ON83EIk ygRm/QufPe3N5DuB3UOQ8rIwvBYaOXz8/yUXixE7XrfUYH/iD5xGrRuYvQpA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add initial support for the new Goodix "Berlin" touchscreen ICs. These touchscreen ICs support SPI, I2C and I3C interface, up to 10 finger touch, stylus and gestures events. This initial driver is derived from the Goodix goodix_ts_berlin available at [1] and [2] and only supports the GT9916 IC present on the Qualcomm SM8550 MTP & QRD touch panel. The current implementation only supports BerlinD, aka GT9916. Support for advanced features like: - Firmware & config update - Stylus events - Gestures events - Previous revisions support (BerlinA or BerlinB) is not included in current version. The current support will work with currently flashed firmware and config, and bail out if firmware or config aren't flashed yet. [1] https://github.com/goodix/goodix_ts_berlin [2] https://git.codelinaro.org/clo/la/platform/vendor/opensource/touch-drivers Reviewed-by: Jeff LaBundy Signed-off-by: Neil Armstrong --- drivers/input/touchscreen/Kconfig | 3 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/goodix_berlin.h | 159 +++++++ drivers/input/touchscreen/goodix_berlin_core.c | 595 +++++++++++++++++++++++++ 4 files changed, 758 insertions(+) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index e3e2324547b9..950da599ae1a 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -416,6 +416,9 @@ config TOUCHSCREEN_GOODIX To compile this driver as a module, choose M here: the module will be called goodix. +config TOUCHSCREEN_GOODIX_BERLIN_CORE + tristate + config TOUCHSCREEN_HIDEEP tristate "HiDeep Touch IC" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 62bd24f3ac8e..2e2f3e70cd2c 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -47,6 +47,7 @@ obj-$(CONFIG_TOUCHSCREEN_EGALAX_SERIAL) += egalax_ts_serial.o obj-$(CONFIG_TOUCHSCREEN_EXC3000) += exc3000.o obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix_ts.o +obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE) += goodix_berlin_core.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o diff --git a/drivers/input/touchscreen/goodix_berlin.h b/drivers/input/touchscreen/goodix_berlin.h new file mode 100644 index 000000000000..235f44947a28 --- /dev/null +++ b/drivers/input/touchscreen/goodix_berlin.h @@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Goodix Touchscreen Driver + * Copyright (C) 2020 - 2021 Goodix, Inc. + * Copyright (C) 2023 Linaro Ltd. + * + * Based on goodix_berlin_berlin driver. + */ + +#ifndef __GOODIX_BERLIN_H_ +#define __GOODIX_BERLIN_H_ + +#include +#include +#include +#include +#include + +#define GOODIX_BERLIN_MAX_TOUCH 10 + +#define GOODIX_BERLIN_NORMAL_RESET_DELAY_MS 100 + +#define GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN 8 +#define GOODIX_BERLIN_STATUS_OFFSET 0 +#define GOODIX_BERLIN_REQUEST_TYPE_OFFSET 2 + +#define GOODIX_BERLIN_BYTES_PER_POINT 8 +#define GOODIX_BERLIN_COOR_DATA_CHECKSUM_SIZE 2 +#define GOODIX_BERLIN_COOR_DATA_CHECKSUM_MASK GENMASK(15, 0) + +/* Read n finger events */ +#define GOODIX_BERLIN_IRQ_READ_LEN(n) (GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN + \ + (GOODIX_BERLIN_BYTES_PER_POINT * (n)) + \ + GOODIX_BERLIN_COOR_DATA_CHECKSUM_SIZE) + +#define GOODIX_BERLIN_TOUCH_EVENT BIT(7) +#define GOODIX_BERLIN_REQUEST_EVENT BIT(6) +#define GOODIX_BERLIN_TOUCH_COUNT_MASK GENMASK(3, 0) + +#define GOODIX_BERLIN_REQUEST_CODE_RESET 3 + +#define GOODIX_BERLIN_POINT_TYPE_MASK GENMASK(3, 0) +#define GOODIX_BERLIN_POINT_TYPE_STYLUS_HOVER 1 +#define GOODIX_BERLIN_POINT_TYPE_STYLUS 3 + +#define GOODIX_BERLIN_TOUCH_ID_MASK GENMASK(7, 4) + +#define GOODIX_BERLIN_DEV_CONFIRM_VAL 0xAA +#define GOODIX_BERLIN_BOOTOPTION_ADDR 0x10000 +#define GOODIX_BERLIN_FW_VERSION_INFO_ADDR 0x10014 + +#define GOODIX_BERLIN_IC_INFO_MAX_LEN SZ_1K +#define GOODIX_BERLIN_IC_INFO_ADDR 0x10070 + +struct goodix_berlin_fw_version { + u8 rom_pid[6]; + u8 rom_vid[3]; + u8 rom_vid_reserved; + u8 patch_pid[8]; + u8 patch_vid[4]; + u8 patch_vid_reserved; + u8 sensor_id; + u8 reserved[2]; + __le16 checksum; +} __packed; + +struct goodix_berlin_ic_info_version { + u8 info_customer_id; + u8 info_version_id; + u8 ic_die_id; + u8 ic_version_id; + __le32 config_id; + u8 config_version; + u8 frame_data_customer_id; + u8 frame_data_version_id; + u8 touch_data_customer_id; + u8 touch_data_version_id; + u8 reserved[3]; +} __packed; + +struct goodix_berlin_ic_info_feature { + __le16 freqhop_feature; + __le16 calibration_feature; + __le16 gesture_feature; + __le16 side_touch_feature; + __le16 stylus_feature; +} __packed; + +struct goodix_berlin_ic_info_misc { + __le32 cmd_addr; + __le16 cmd_max_len; + __le32 cmd_reply_addr; + __le16 cmd_reply_len; + __le32 fw_state_addr; + __le16 fw_state_len; + __le32 fw_buffer_addr; + __le16 fw_buffer_max_len; + __le32 frame_data_addr; + __le16 frame_data_head_len; + __le16 fw_attr_len; + __le16 fw_log_len; + u8 pack_max_num; + u8 pack_compress_version; + __le16 stylus_struct_len; + __le16 mutual_struct_len; + __le16 self_struct_len; + __le16 noise_struct_len; + __le32 touch_data_addr; + __le16 touch_data_head_len; + __le16 point_struct_len; + __le16 reserved1; + __le16 reserved2; + __le32 mutual_rawdata_addr; + __le32 mutual_diffdata_addr; + __le32 mutual_refdata_addr; + __le32 self_rawdata_addr; + __le32 self_diffdata_addr; + __le32 self_refdata_addr; + __le32 iq_rawdata_addr; + __le32 iq_refdata_addr; + __le32 im_rawdata_addr; + __le16 im_readata_len; + __le32 noise_rawdata_addr; + __le16 noise_rawdata_len; + __le32 stylus_rawdata_addr; + __le16 stylus_rawdata_len; + __le32 noise_data_addr; + __le32 esd_addr; +} __packed; + +struct goodix_berlin_touch_data { + u8 id; + u8 unused; + __le16 x; + __le16 y; + __le16 w; +} __packed; + +struct goodix_berlin_core { + struct device *dev; + struct regmap *regmap; + struct regulator *avdd; + struct regulator *iovdd; + struct gpio_desc *reset_gpio; + struct touchscreen_properties props; + struct goodix_berlin_fw_version fw_version; + struct input_dev *input_dev; + int irq; + + /* Runtime parameters extracted from IC_INFO buffer */ + u32 touch_data_addr; +}; + +int goodix_berlin_probe(struct device *dev, int irq, const struct input_id *id, + struct regmap *regmap); + +extern const struct dev_pm_ops goodix_berlin_pm_ops; + +#endif diff --git a/drivers/input/touchscreen/goodix_berlin_core.c b/drivers/input/touchscreen/goodix_berlin_core.c new file mode 100644 index 000000000000..c66e2f0c6529 --- /dev/null +++ b/drivers/input/touchscreen/goodix_berlin_core.c @@ -0,0 +1,595 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Goodix Touchscreen Driver + * Copyright (C) 2020 - 2021 Goodix, Inc. + * Copyright (C) 2023 Linaro Ltd. + * + * Based on goodix_ts_berlin driver. + */ +#include +#include +#include +#include +#include + +#include "goodix_berlin.h" + +/* + * Goodix "Berlin" Touchscreen IC driver + * + * This driver is distinct from goodix.c since hardware interface + * is different enough to require a new driver. + * None of the register address or data structure are close enough + * to the previous generations. + * + * Currently only handles Multitouch events with already + * programmed firmware and "config" for "Revision D" Berlin IC. + * + * Support is missing for: + * - ESD Management + * - Firmware update/flashing + * - "Config" update/flashing + * - Stylus Events + * - Gesture Events + * - Support for older revisions (A & B) + */ + +static bool goodix_berlin_checksum_valid(const u8 *data, int size) +{ + u32 cal_checksum = 0; + u16 r_checksum; + u32 i; + + if (size < GOODIX_BERLIN_COOR_DATA_CHECKSUM_SIZE) + return false; + + for (i = 0; i < size - GOODIX_BERLIN_COOR_DATA_CHECKSUM_SIZE; i++) + cal_checksum += data[i]; + + r_checksum = get_unaligned_le16(&data[i]); + + return FIELD_GET(GOODIX_BERLIN_COOR_DATA_CHECKSUM_MASK, cal_checksum) == r_checksum; +} + +static bool goodix_berlin_is_dummy_data(struct goodix_berlin_core *cd, + const u8 *data, int size) +{ + int i; + + /* + * If the device is missing or doesn't respond the buffer + * could be filled with bus default line state, 0x00 or 0xff, + * so declare success the first time we encounter neither. + */ + for (i = 0; i < size; i++) + if (data[i] > 0 && data[i] < 0xff) + return false; + + return true; +} + +static int goodix_berlin_dev_confirm(struct goodix_berlin_core *cd) +{ + u8 tx_buf[8], rx_buf[8]; + int retry = 3; + int error; + + memset(tx_buf, GOODIX_BERLIN_DEV_CONFIRM_VAL, sizeof(tx_buf)); + while (retry--) { + error = regmap_raw_write(cd->regmap, GOODIX_BERLIN_BOOTOPTION_ADDR, tx_buf, + sizeof(tx_buf)); + if (error) + return error; + + error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_BOOTOPTION_ADDR, rx_buf, + sizeof(rx_buf)); + if (error) + return error; + + if (!memcmp(tx_buf, rx_buf, sizeof(tx_buf))) + return 0; + + usleep_range(5000, 5100); + } + + dev_err(cd->dev, "device confirm failed, rx_buf: %*ph\n", 8, rx_buf); + + return -EINVAL; +} + +static int goodix_berlin_power_on(struct goodix_berlin_core *cd, bool on) +{ + int error = 0; + + if (on) { + error = regulator_enable(cd->iovdd); + if (error) { + dev_err(cd->dev, "Failed to enable iovdd: %d\n", error); + return error; + } + + /* Vendor waits 3ms for IOVDD to settle */ + usleep_range(3000, 3100); + + error = regulator_enable(cd->avdd); + if (error) { + dev_err(cd->dev, "Failed to enable avdd: %d\n", error); + goto err_iovdd_disable; + } + + /* Vendor waits 15ms for IOVDD to settle */ + usleep_range(15000, 15100); + + gpiod_set_value(cd->reset_gpio, 0); + + /* Vendor waits 4ms for Firmware to initialize */ + usleep_range(4000, 4100); + + error = goodix_berlin_dev_confirm(cd); + if (error) + goto err_dev_reset; + + /* Vendor waits 100ms for Firmware to fully boot */ + msleep(GOODIX_BERLIN_NORMAL_RESET_DELAY_MS); + + return 0; + } + +err_dev_reset: + gpiod_set_value(cd->reset_gpio, 1); + + regulator_disable(cd->avdd); + +err_iovdd_disable: + regulator_disable(cd->iovdd); + + return error; +} + +static int goodix_berlin_read_version(struct goodix_berlin_core *cd) +{ + u8 buf[sizeof(struct goodix_berlin_fw_version)]; + int error; + + error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_FW_VERSION_INFO_ADDR, buf, sizeof(buf)); + if (error) { + dev_err(cd->dev, "error reading fw version, %d\n", error); + return error; + } + + if (!goodix_berlin_checksum_valid(buf, sizeof(buf))) { + dev_err(cd->dev, "invalid fw version: checksum error\n"); + return -EINVAL; + } + + memcpy(&cd->fw_version, buf, sizeof(cd->fw_version)); + + return 0; +} + +/* Only extract necessary data for runtime */ +static int goodix_berlin_convert_ic_info(struct goodix_berlin_core *cd, + const u8 *data, u16 length) +{ + struct goodix_berlin_ic_info_misc misc; + unsigned int offset = 0; + u8 param_num; + + offset += sizeof(__le16); /* length */ + offset += sizeof(struct goodix_berlin_ic_info_version); + offset += sizeof(struct goodix_berlin_ic_info_feature); + + /* IC_INFO Parameters, variable width structure */ + offset += 4 * sizeof(u8); /* drv_num, sen_num, button_num, force_num */ + + if (offset >= length) + goto invalid_offset; + + param_num = data[offset++]; /* active_scan_rate_num */ + + offset += param_num * sizeof(__le16); + + if (offset >= length) + goto invalid_offset; + + param_num = data[offset++]; /* mutual_freq_num*/ + + offset += param_num * sizeof(__le16); + + if (offset >= length) + goto invalid_offset; + + param_num = data[offset++]; /* self_tx_freq_num */ + + offset += param_num * sizeof(__le16); + + if (offset >= length) + goto invalid_offset; + + param_num = data[offset++]; /* self_rx_freq_num */ + + offset += param_num * sizeof(__le16); + + if (offset >= length) + goto invalid_offset; + + param_num = data[offset++]; /* stylus_freq_num */ + + offset += param_num * sizeof(__le16); + + if (offset + sizeof(misc) > length) + goto invalid_offset; + + /* goodix_berlin_ic_info_misc */ + memcpy(&misc, &data[offset], sizeof(misc)); + + cd->touch_data_addr = le32_to_cpu(misc.touch_data_addr); + + return 0; + +invalid_offset: + dev_err(cd->dev, "ic_info length is invalid (offset %d length %d)\n", + offset, length); + return -EINVAL; +} + +static int goodix_berlin_get_ic_info(struct goodix_berlin_core *cd) +{ + __le16 length_raw; + u8 *afe_data; + u16 length; + int error; + + afe_data = kzalloc(GOODIX_BERLIN_IC_INFO_MAX_LEN, GFP_KERNEL); + if (!afe_data) + return -ENOMEM; + + error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_IC_INFO_ADDR, + &length_raw, sizeof(length_raw)); + if (error) { + dev_err(cd->dev, "failed get ic info length, %d\n", error); + goto free_afe_data; + } + + length = le16_to_cpu(length_raw); + if (length >= GOODIX_BERLIN_IC_INFO_MAX_LEN) { + dev_err(cd->dev, "invalid ic info length %d\n", length); + error = -EINVAL; + goto free_afe_data; + } + + error = regmap_raw_read(cd->regmap, GOODIX_BERLIN_IC_INFO_ADDR, + afe_data, length); + if (error) { + dev_err(cd->dev, "failed get ic info data, %d\n", error); + goto free_afe_data; + } + + /* check whether the data is valid (ex. bus default values) */ + if (goodix_berlin_is_dummy_data(cd, afe_data, length)) { + dev_err(cd->dev, "fw info data invalid\n"); + error = -EINVAL; + goto free_afe_data; + } + + if (!goodix_berlin_checksum_valid(afe_data, length)) { + dev_err(cd->dev, "fw info checksum error\n"); + error = -EINVAL; + goto free_afe_data; + } + + error = goodix_berlin_convert_ic_info(cd, afe_data, length); + if (error) + goto free_afe_data; + + /* check some key info */ + if (!cd->touch_data_addr) { + dev_err(cd->dev, "touch_data_addr is null\n"); + error = -EINVAL; + goto free_afe_data; + } + + return 0; + +free_afe_data: + kfree(afe_data); + + return error; +} + +static void goodix_berlin_parse_finger(struct goodix_berlin_core *cd, + const void *buf, int touch_num) +{ + const struct goodix_berlin_touch_data *touch_data = buf; + int i; + + /* Report finger touches */ + for (i = 0; i < touch_num; i++) { + unsigned int id; + + id = FIELD_GET(GOODIX_BERLIN_TOUCH_ID_MASK, touch_data[i].id); + + if (id >= GOODIX_BERLIN_MAX_TOUCH) { + dev_warn_ratelimited(cd->dev, "invalid finger id %d\n", id); + continue; + } + + input_mt_slot(cd->input_dev, id); + input_mt_report_slot_state(cd->input_dev, MT_TOOL_FINGER, true); + + touchscreen_report_pos(cd->input_dev, &cd->props, + __le16_to_cpu(touch_data[i].x), + __le16_to_cpu(touch_data[i].y), + true); + input_report_abs(cd->input_dev, ABS_MT_TOUCH_MAJOR, + __le16_to_cpu(touch_data[i].w)); + } + + input_mt_sync_frame(cd->input_dev); + input_sync(cd->input_dev); +} + +static void goodix_berlin_touch_handler(struct goodix_berlin_core *cd, + const void *pre_buf, u32 pre_buf_len) +{ + u8 buffer[GOODIX_BERLIN_IRQ_READ_LEN(GOODIX_BERLIN_MAX_TOUCH)]; + u8 point_type, touch_num; + int error; + + /* copy pre-data to buffer */ + memcpy(buffer, pre_buf, pre_buf_len); + + touch_num = FIELD_GET(GOODIX_BERLIN_TOUCH_COUNT_MASK, + buffer[GOODIX_BERLIN_REQUEST_TYPE_OFFSET]); + + if (touch_num > GOODIX_BERLIN_MAX_TOUCH) { + dev_warn(cd->dev, "invalid touch num %d\n", touch_num); + return; + } + + if (touch_num) { + /* read more data if more than 2 touch events */ + if (unlikely(touch_num > 2)) { + error = regmap_raw_read(cd->regmap, + cd->touch_data_addr + pre_buf_len, + &buffer[pre_buf_len], + (touch_num - 2) * GOODIX_BERLIN_BYTES_PER_POINT); + if (error) { + dev_err_ratelimited(cd->dev, "failed to get touch data, %d\n", + error); + return; + } + } + + point_type = FIELD_GET(GOODIX_BERLIN_POINT_TYPE_MASK, + buffer[GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN]); + + if (point_type == GOODIX_BERLIN_POINT_TYPE_STYLUS || + point_type == GOODIX_BERLIN_POINT_TYPE_STYLUS_HOVER) { + dev_warn_once(cd->dev, "Stylus event type not handled\n"); + return; + } + + if (!goodix_berlin_checksum_valid(&buffer[GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN], + touch_num * GOODIX_BERLIN_BYTES_PER_POINT + 2)) { + dev_err(cd->dev, "touch data checksum error, data: %*ph\n", + touch_num * GOODIX_BERLIN_BYTES_PER_POINT + 2, + &buffer[GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN]); + return; + } + } + + goodix_berlin_parse_finger(cd, &buffer[GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN], + touch_num); +} + +static int goodix_berlin_request_handle_reset(struct goodix_berlin_core *cd) +{ + gpiod_set_value(cd->reset_gpio, 1); + usleep_range(2000, 2100); + gpiod_set_value(cd->reset_gpio, 0); + + msleep(GOODIX_BERLIN_NORMAL_RESET_DELAY_MS); + + return 0; +} + +static irqreturn_t goodix_berlin_threadirq_func(int irq, void *data) +{ + struct goodix_berlin_core *cd = data; + u8 buf[GOODIX_BERLIN_IRQ_READ_LEN(2)]; + u8 event_status; + int error; + + /* First, read buffer with space for 2 touch events */ + error = regmap_raw_read(cd->regmap, cd->touch_data_addr, buf, + GOODIX_BERLIN_IRQ_READ_LEN(2)); + if (error) { + dev_err_ratelimited(cd->dev, "failed get event head data, %d\n", error); + return IRQ_HANDLED; + } + + if (buf[GOODIX_BERLIN_STATUS_OFFSET] == 0) + return IRQ_HANDLED; + + if (!goodix_berlin_checksum_valid(buf, GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN)) { + dev_warn_ratelimited(cd->dev, "touch head checksum err : %*ph\n", + GOODIX_BERLIN_IRQ_EVENT_HEAD_LEN, buf); + return IRQ_HANDLED; + } + + event_status = buf[GOODIX_BERLIN_STATUS_OFFSET]; + + if (event_status & GOODIX_BERLIN_TOUCH_EVENT) + goodix_berlin_touch_handler(cd, buf, GOODIX_BERLIN_IRQ_READ_LEN(2)); + + if (event_status & GOODIX_BERLIN_REQUEST_EVENT) { + switch (buf[GOODIX_BERLIN_REQUEST_TYPE_OFFSET]) { + case GOODIX_BERLIN_REQUEST_CODE_RESET: + if (cd->reset_gpio) + goodix_berlin_request_handle_reset(cd); + break; + + default: + dev_warn(cd->dev, "unsupported request code 0x%x\n", + buf[GOODIX_BERLIN_REQUEST_TYPE_OFFSET]); + } + } + + /* Clear up status field */ + regmap_write(cd->regmap, cd->touch_data_addr, 0); + + return IRQ_HANDLED; +} + +static int goodix_berlin_input_dev_config(struct goodix_berlin_core *cd, + const struct input_id *id) +{ + struct input_dev *input_dev; + int error; + + input_dev = devm_input_allocate_device(cd->dev); + if (!input_dev) + return -ENOMEM; + + cd->input_dev = input_dev; + input_set_drvdata(input_dev, cd); + + input_dev->name = "Goodix Berlin Capacitive TouchScreen"; + input_dev->phys = "input/ts"; + + input_dev->id = *id; + + input_set_abs_params(cd->input_dev, ABS_MT_POSITION_X, 0, SZ_64K - 1, 0, 0); + input_set_abs_params(cd->input_dev, ABS_MT_POSITION_Y, 0, SZ_64K - 1, 0, 0); + input_set_abs_params(cd->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); + + touchscreen_parse_properties(cd->input_dev, true, &cd->props); + + error = input_mt_init_slots(cd->input_dev, GOODIX_BERLIN_MAX_TOUCH, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (error) + return error; + + error = input_register_device(cd->input_dev); + if (error) + return error; + + return 0; +} + +static int goodix_berlin_pm_suspend(struct device *dev) +{ + struct goodix_berlin_core *cd = dev_get_drvdata(dev); + + disable_irq(cd->irq); + + return goodix_berlin_power_on(cd, false); +} + +static int goodix_berlin_pm_resume(struct device *dev) +{ + struct goodix_berlin_core *cd = dev_get_drvdata(dev); + int error; + + error = goodix_berlin_power_on(cd, true); + if (error) + return error; + + enable_irq(cd->irq); + + return 0; +} + +EXPORT_GPL_SIMPLE_DEV_PM_OPS(goodix_berlin_pm_ops, + goodix_berlin_pm_suspend, + goodix_berlin_pm_resume); + +static void goodix_berlin_power_off(void *data) +{ + struct goodix_berlin_core *cd = data; + + goodix_berlin_power_on(cd, false); +} + +int goodix_berlin_probe(struct device *dev, int irq, const struct input_id *id, + struct regmap *regmap) +{ + struct goodix_berlin_core *cd; + int error; + + if (irq <= 0) { + dev_err(dev, "Missing interrupt number\n"); + return -EINVAL; + } + + cd = devm_kzalloc(dev, sizeof(*cd), GFP_KERNEL); + if (!cd) + return -ENOMEM; + + cd->dev = dev; + cd->regmap = regmap; + cd->irq = irq; + + cd->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(cd->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(cd->reset_gpio), + "Failed to request reset gpio\n"); + + cd->avdd = devm_regulator_get(dev, "avdd"); + if (IS_ERR(cd->avdd)) + return dev_err_probe(dev, PTR_ERR(cd->avdd), + "Failed to request avdd regulator\n"); + + cd->iovdd = devm_regulator_get(dev, "iovdd"); + if (IS_ERR(cd->iovdd)) + return dev_err_probe(dev, PTR_ERR(cd->iovdd), + "Failed to request iovdd regulator\n"); + + error = goodix_berlin_power_on(cd, true); + if (error) { + dev_err(dev, "failed power on"); + return error; + } + + error = devm_add_action_or_reset(dev, goodix_berlin_power_off, cd); + if (error) + return error; + + error = goodix_berlin_read_version(cd); + if (error) { + dev_err(dev, "failed to get version info"); + return error; + } + + error = goodix_berlin_get_ic_info(cd); + if (error) { + dev_err(dev, "invalid ic info, abort"); + return error; + } + + error = goodix_berlin_input_dev_config(cd, id); + if (error) { + dev_err(dev, "failed set input device"); + return error; + } + + error = devm_request_threaded_irq(dev, irq, NULL, + goodix_berlin_threadirq_func, + IRQF_ONESHOT, "goodix-berlin", cd); + if (error) { + dev_err(dev, "request threaded irq failed: %d\n", error); + return error; + } + + dev_set_drvdata(dev, cd); + + dev_dbg(dev, "Goodix Berlin %s Touchscreen Controller", cd->fw_version.patch_pid); + + return 0; +} +EXPORT_SYMBOL_GPL(goodix_berlin_probe); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Goodix Berlin Core Touchscreen driver"); +MODULE_AUTHOR("Neil Armstrong "); From patchwork Mon Nov 6 08:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 742126 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A0A0C4708E for ; Mon, 6 Nov 2023 08:34:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbjKFIeI (ORCPT ); Mon, 6 Nov 2023 03:34:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbjKFIeH (ORCPT ); Mon, 6 Nov 2023 03:34:07 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97DE9184 for ; Mon, 6 Nov 2023 00:34:04 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-407da05f05aso29531055e9.3 for ; Mon, 06 Nov 2023 00:34:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699259643; x=1699864443; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=tid5p5CbwnFew1OoFmZZ3rTS9lA993ke+t72lpp1p7Y=; b=b6wJLoX96yBlWtkcfIhd5mDosB/eDmsmYWDbLFCcimvYRgm9XkCmRzvc380etF2cwk c6m+x6wPy2WXFL/VpbJ291VlJhOKaVVQFaMjVugJiKpIksIAFpVZbQVcJxLpoiWeQAjZ bpB6vYyAtBqznvMUP1MpcczW5h5/g4DckgjoUBoQaNNrhwubeHPS2weVYgu0qKI5fyTN tLPtpSq96oLiiEhGhDwbTytBaqEuXPHKiOwfwh3A+yWc/+6rz/McCBk2E7uWeD2y/9xh i1padH0IuiqHcy+VtGBp9k/llopAb92b2BVD6qAXKaoX6zhDTIuCQG+N4vTBFtHykRGw wznA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699259643; x=1699864443; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tid5p5CbwnFew1OoFmZZ3rTS9lA993ke+t72lpp1p7Y=; b=Msyh/+/lzsse1Nr6u8pAlc7/bZWusG32mFdEW4OLWL9je6wmJbXn9rHQM7Od0EkZOK oKFfkVtKFP1deWICEvNJpd1wP0cWTfVujBvN8R4I/ra6G4h1jWyaOqN9EUNCVt7JBQ32 UnasSQtk+kVdwGk5OqDqlqwLNzJYhgSt7hKfXdZjTrJDBAp8ZOEtr0XpqisI0FqyqvOJ oJZCSNkNz+GyhvsEzYBlfibaPfOJ2s6fHJCKPR6ViQfpuj5EJH7xw510RW4sIhEtFW42 waGECVJvWwaMVWsTp+b9eZQ4xxzMaMc6zBbmjDMB5S9FrdY4lqzKMhDd0eRuqPN0RRYm skaw== X-Gm-Message-State: AOJu0Yy5D2z1lzW9O7wSpQTz8RTnyxaXdgEBzaImCjZ4DfR5QVXV368X wfyvoDpE3vAczb07qtl9ikr6pQ== X-Google-Smtp-Source: AGHT+IF9hx0+ythJ4hs40XdkE7PYrN8XIyqUy3i6UMmlLHGB/m2RejTiCvY/fcPdy2h5w43RX+uT3g== X-Received: by 2002:a05:600c:3b28:b0:402:ee9e:ed98 with SMTP id m40-20020a05600c3b2800b00402ee9eed98mr22702351wms.34.1699259642911; Mon, 06 Nov 2023 00:34:02 -0800 (PST) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id q24-20020a7bce98000000b0040648217f4fsm11132991wmj.39.2023.11.06.00.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 00:34:02 -0800 (PST) From: Neil Armstrong Date: Mon, 06 Nov 2023 09:33:58 +0100 Subject: [PATCH v11 3/4] Input: goodix-berlin - add I2C support for Goodix Berlin Touchscreen IC MIME-Version: 1.0 Message-Id: <20231106-topic-goodix-berlin-upstream-initial-v11-3-5c47e9707c03@linaro.org> References: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> In-Reply-To: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bastien Nocera , Hans de Goede , Henrik Rydberg , Jeff LaBundy , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4539; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=/29OxaflwzQer1E/gOu8Bz3LG+5phtsz3jcz094am9k=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBlSKT1e5yXT32uz4G+42ChIZKQIvajR75VmTOLTjPF +FD2iY2JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZUik9QAKCRB33NvayMhJ0UqxD/ 9c4B626vCGVTnd6wJEWoe/GnJQO1oyhgL9lPUFZhMwpVJfW8VprhHEiPuuhH8dFA71wlwumcqpEwsP 4Os4+y71F3arVELFSe2/tm29Pa0Tvqs6+NP//66lrDmlmxLiLioabZc6WksDvtw3GOa+ddb0rGiqAd kydB3i+bjyLIoY4c2RrddE8SzZ6C9SgOIxRzNBTe4AUqaCiM9mvv/H09jTbJRiBlqgrX7dfPLkaXj3 gJzY3cJzf8cy8d1gzzH57/5UMY1Wldg2mCeYqY4ntqPSE7CVyTH+P1m8WXZWo1EE1gr6gNV+OZuJyg WFbZfNbcvLgwlctU3xE6fWYF78PdpbjPct/hrv35KQHhcyht3x1FwrVHO5JitvtTq6b0dljsoMZSGt rbz/O7zO8m6eiRkWiubuoKa1GcSCfaeBkvqBX2CNWCqIFq/CvYgV9bT9M8Nazw3g1unjGOsd0MtY7I zV70bRfSP6kIL3/tt2WLbMrQ3WGdv+elEg7zmXhTTsVMrYkdULqFFLeI0tIhNz6ECuB+anNeYzMGD6 pcFNxoAeZltlwi+8mGJCfs3U1/1muPa4VeNiVZ6o8MknYEr51hRZZxU95CIbJzcpsE+rmb6zwXKzoc xti6+GtBEPtbae0mxHpHItVgpSK0oDyxFnGvkcxMSVfqvMc/P8ZRAa2d2hqA== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add initial support for the new Goodix "Berlin" touchscreen ICs over the I2C interface. This initial driver is derived from the Goodix goodix_ts_berlin available at [1] and [2] and only supports the GT9916 IC present on the Qualcomm SM8550 MTP & QRD touch panel. The current implementation only supports BerlinD, aka GT9916. [1] https://github.com/goodix/goodix_ts_berlin [2] https://git.codelinaro.org/clo/la/platform/vendor/opensource/touch-drivers Reviewed-by: Jeff LaBundy Signed-off-by: Neil Armstrong --- drivers/input/touchscreen/Kconfig | 14 +++++ drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/goodix_berlin_i2c.c | 74 +++++++++++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 950da599ae1a..cc7b88118158 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -419,6 +419,20 @@ config TOUCHSCREEN_GOODIX config TOUCHSCREEN_GOODIX_BERLIN_CORE tristate +config TOUCHSCREEN_GOODIX_BERLIN_I2C + tristate "Goodix Berlin I2C touchscreen" + depends on I2C + select REGMAP_I2C + select TOUCHSCREEN_GOODIX_BERLIN_CORE + help + Say Y here if you have a Goodix Berlin IC connected to + your system via I2C. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called goodix_berlin_i2c. + config TOUCHSCREEN_HIDEEP tristate "HiDeep Touch IC" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 2e2f3e70cd2c..7ef677cf7a10 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_TOUCHSCREEN_EXC3000) += exc3000.o obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE) += goodix_berlin_core.o +obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_I2C) += goodix_berlin_i2c.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o diff --git a/drivers/input/touchscreen/goodix_berlin_i2c.c b/drivers/input/touchscreen/goodix_berlin_i2c.c new file mode 100644 index 000000000000..4d5bcc101569 --- /dev/null +++ b/drivers/input/touchscreen/goodix_berlin_i2c.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Goodix Berlin Touchscreen Driver + * + * Copyright (C) 2020 - 2021 Goodix, Inc. + * Copyright (C) 2023 Linaro Ltd. + * + * Based on goodix_ts_berlin driver. + */ +#include +#include +#include +#include + +#include "goodix_berlin.h" + +#define I2C_MAX_TRANSFER_SIZE 256 + +static const struct regmap_config goodix_berlin_i2c_regmap_conf = { + .reg_bits = 32, + .val_bits = 8, + .max_raw_read = I2C_MAX_TRANSFER_SIZE, + .max_raw_write = I2C_MAX_TRANSFER_SIZE, +}; + +/* vendor & product left unassigned here, should probably be updated from fw info */ +static const struct input_id goodix_berlin_i2c_input_id = { + .bustype = BUS_I2C, +}; + +static int goodix_berlin_i2c_probe(struct i2c_client *client) +{ + struct regmap *regmap; + int error; + + regmap = devm_regmap_init_i2c(client, &goodix_berlin_i2c_regmap_conf); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + error = goodix_berlin_probe(&client->dev, client->irq, + &goodix_berlin_i2c_input_id, regmap); + if (error) + return error; + + return 0; +} + +static const struct i2c_device_id goodix_berlin_i2c_id[] = { + { "gt9916", 0 }, + { } +}; + +MODULE_DEVICE_TABLE(i2c, goodix_berlin_i2c_id); + +static const struct of_device_id goodix_berlin_i2c_of_match[] = { + { .compatible = "goodix,gt9916", }, + { } +}; +MODULE_DEVICE_TABLE(of, goodix_berlin_i2c_of_match); + +static struct i2c_driver goodix_berlin_i2c_driver = { + .driver = { + .name = "goodix-berlin-i2c", + .of_match_table = goodix_berlin_i2c_of_match, + .pm = pm_sleep_ptr(&goodix_berlin_pm_ops), + }, + .probe = goodix_berlin_i2c_probe, + .id_table = goodix_berlin_i2c_id, +}; +module_i2c_driver(goodix_berlin_i2c_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Goodix Berlin I2C Touchscreen driver"); +MODULE_AUTHOR("Neil Armstrong "); From patchwork Mon Nov 6 08:33:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Neil Armstrong X-Patchwork-Id: 742125 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47D74C4332F for ; Mon, 6 Nov 2023 08:34:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbjKFIeY (ORCPT ); Mon, 6 Nov 2023 03:34:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230431AbjKFIeK (ORCPT ); Mon, 6 Nov 2023 03:34:10 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6F11DB for ; Mon, 6 Nov 2023 00:34:05 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9de7a43bd1aso223885366b.3 for ; Mon, 06 Nov 2023 00:34:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699259644; x=1699864444; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OxnVNSfczT25XAfpC4X+ICgFqABO9v8W+zLZSFvXeiM=; b=l0dOYpJgyr7MpCXzr2PK6914ol0WKBP1Cy/zYU+e9rVir5zByr9LbyZI/386Ymvbpq +z/XKMbaNvb2veItYy5PITAPWdvhgwMuCmjXJuSSCihqessoY7V2aWRFrfP+mtCCBRlP MtvxQIbbKmXATVh5k06Tb1XYq+qYIK2gdKam0NogoE0EkRtvBYCjdtIlRBnd02hiZP5B QAyg7wT/u5zPInlPhXVaXvmo+NWgd7VMDy2gq72Dl6qGcWYLf8ZR0gH0WpHUc8c8c/Qn qbf+0fsJ0yjjrEmlziX6TyAe8akc4OKFEebLEn76xMHV8T/9r68EpoO4ec7vwuqoR/Cy 1DJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699259644; x=1699864444; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OxnVNSfczT25XAfpC4X+ICgFqABO9v8W+zLZSFvXeiM=; b=gmyn0v5fV4X9D2sXWXQxoWqRn5R7UerUh2K8qP3kX+J7LZc/UQnTbWJTYNred5Pld1 DwhgT9R/1OAXAx1sG0WCU8u+oS74hgBfWt9lxvRQROpjKHX61XmeO3DYLhMluVYP0rkg GK8U6I2KrDDX2nvRE8Gs6csAOYYkoisB9dDAzWhF5w/CpkDGluEvWREDqKvpYAv7NZ63 +oHnAYNRdOGjNR3eDz81s1Xq7xVbtv8UBtrkjq/Zv9crn9D6jlGyHKUOHuhAb4VDGEpe Jcln6y78jORcJgA5XsXdGlHsIyUL4VJANkhTgU0jC0NM1iKOdEu3AYLk3M8AZuGrsLIL j+tQ== X-Gm-Message-State: AOJu0YyPvQd8Ul8SqUSFD3YEm6XPvRQaJaxnTA5qTpQ9qa7XZN8azLt7 iwJw4L2+jEmPXGUGh0IZCCeigw== X-Google-Smtp-Source: AGHT+IEH0+oVX58+uggKJ7R9Rqu8bdFhdAVwjxs0JsLvDyYFiK4op9g98SYsIi9Nm/DHVLmPUigpXw== X-Received: by 2002:a17:907:26c5:b0:9e0:2319:16dc with SMTP id bp5-20020a17090726c500b009e0231916dcmr2466244ejc.73.1699259644042; Mon, 06 Nov 2023 00:34:04 -0800 (PST) Received: from arrakeen.starnux.net ([2a01:e0a:982:cbb0:52eb:f6ff:feb3:451a]) by smtp.gmail.com with ESMTPSA id q24-20020a7bce98000000b0040648217f4fsm11132991wmj.39.2023.11.06.00.34.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 00:34:03 -0800 (PST) From: Neil Armstrong Date: Mon, 06 Nov 2023 09:33:59 +0100 Subject: [PATCH v11 4/4] Input: goodix-berlin - add SPI support for Goodix Berlin Touchscreen IC MIME-Version: 1.0 Message-Id: <20231106-topic-goodix-berlin-upstream-initial-v11-4-5c47e9707c03@linaro.org> References: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> In-Reply-To: <20231106-topic-goodix-berlin-upstream-initial-v11-0-5c47e9707c03@linaro.org> To: Dmitry Torokhov , linux-input@vger.kernel.org Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bastien Nocera , Hans de Goede , Henrik Rydberg , Jeff LaBundy , linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Neil Armstrong X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=8067; i=neil.armstrong@linaro.org; h=from:subject:message-id; bh=IRI86qOlgcP+lY+pewvMbMLCeQCDU17m1zaFOv0kod4=; b=owEBbQKS/ZANAwAKAXfc29rIyEnRAcsmYgBlSKT2L/YIoIVQCfo/epBR8EfFUB+oHqLAeES4nTBl rRb/Y/6JAjMEAAEKAB0WIQQ9U8YmyFYF/h30LIt33NvayMhJ0QUCZUik9gAKCRB33NvayMhJ0WU9EA CD+XjwmhLu0Bi0k3zqpiosQTJr5WVPxuvvJiPf8pBfYKm0hi5Ae6gclEWUBkeY1hkMMzJQ53+p6/O0 zNZ+bSX0e4RzSm0OcnCny33ueKV0+RomM8fikoJOW+JzRvYEmtwhrsRESWxLJbFIEr0ffh2MIJBsrP kWgHif1sDgdV+LjNWCHqaOvgpXi4MbEktlemUiGnx6BFmGMhuZi03NezTDImfLRgSYBv6g/H8PoEZW UajOM7EsK2OvW0hoadwLd8YVnJlPMu/Y3S9SPK0VvvZLV5pbo7mdXXgSDDAOyZKkFKIEk6FC7bvWOm GnvrRB1iPjj1589U4laOmL7x7HYkcPxWk3llxSDguA/oZrTOUTS5OYa1ZqMq8Mb9drdKmqTLfoDo3i gfL8FshdQl0MHwAgMi2AGXS+9TWTKYcz+RoEBzQlrvFRSoj5J2n4G/TDiMSE2v3/+GmIIqzRgY39LI LdcrKfNuRrSU+EUIiOJj9IkoffJq5zszATkR5zjIvcjNBpy+CYh9M+VbQErRusIubG+6IBb+VDHR4y Z/5zJFA+gfoXKGiWlYy/zR6KHkYanSzahg0SYu8l4ds09JWhA98nqTzRdT4+Uk+zhbEsPoBb68d8vB QMqhW9GiUWdgrs8SI/cnxgV2R309tltlNnTYwJahqjgJJOvU5XzpYOk4ey4Q== X-Developer-Key: i=neil.armstrong@linaro.org; a=openpgp; fpr=89EC3D058446217450F22848169AB7B1A4CFF8AE Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add initial support for the new Goodix "Berlin" touchscreen ICs over the SPI interface. The driver doesn't use the regmap_spi code since the SPI messages needs to be prefixed, thus this custom regmap code. This initial driver is derived from the Goodix goodix_ts_berlin available at [1] and [2] and only supports the GT9916 IC present on the Qualcomm SM8550 MTP & QRD touch panel. The current implementation only supports BerlinD, aka GT9916. [1] https://github.com/goodix/goodix_ts_berlin [2] https://git.codelinaro.org/clo/la/platform/vendor/opensource/touch-drivers Reviewed-by: Jeff LaBundy Signed-off-by: Neil Armstrong --- drivers/input/touchscreen/Kconfig | 14 ++ drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/goodix_berlin_spi.c | 177 ++++++++++++++++++++++++++ 3 files changed, 192 insertions(+) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index cc7b88118158..c821fe3ee794 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -433,6 +433,20 @@ config TOUCHSCREEN_GOODIX_BERLIN_I2C To compile this driver as a module, choose M here: the module will be called goodix_berlin_i2c. +config TOUCHSCREEN_GOODIX_BERLIN_SPI + tristate "Goodix Berlin SPI touchscreen" + depends on SPI_MASTER + select REGMAP + select TOUCHSCREEN_GOODIX_BERLIN_CORE + help + Say Y here if you have a Goodix Berlin IC connected to + your system via SPI. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called goodix_berlin_spi. + config TOUCHSCREEN_HIDEEP tristate "HiDeep Touch IC" depends on I2C diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 7ef677cf7a10..a81cb5aa21a5 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -49,6 +49,7 @@ obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX) += goodix_ts.o obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_CORE) += goodix_berlin_core.o obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_I2C) += goodix_berlin_i2c.o +obj-$(CONFIG_TOUCHSCREEN_GOODIX_BERLIN_SPI) += goodix_berlin_spi.o obj-$(CONFIG_TOUCHSCREEN_HIDEEP) += hideep.o obj-$(CONFIG_TOUCHSCREEN_HYNITRON_CSTXXX) += hynitron_cstxxx.o obj-$(CONFIG_TOUCHSCREEN_ILI210X) += ili210x.o diff --git a/drivers/input/touchscreen/goodix_berlin_spi.c b/drivers/input/touchscreen/goodix_berlin_spi.c new file mode 100644 index 000000000000..502b143e9e05 --- /dev/null +++ b/drivers/input/touchscreen/goodix_berlin_spi.c @@ -0,0 +1,177 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Goodix Berlin Touchscreen Driver + * + * Copyright (C) 2020 - 2021 Goodix, Inc. + * Copyright (C) 2023 Linaro Ltd. + * + * Based on goodix_ts_berlin driver. + */ +#include +#include +#include +#include +#include + +#include "goodix_berlin.h" + +#define GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN 1 +#define GOODIX_BERLIN_REGISTER_WIDTH 4 +#define GOODIX_BERLIN_SPI_READ_DUMMY_LEN 3 +#define GOODIX_BERLIN_SPI_READ_PREFIX_LEN (GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN + \ + GOODIX_BERLIN_REGISTER_WIDTH + \ + GOODIX_BERLIN_SPI_READ_DUMMY_LEN) +#define GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN (GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN + \ + GOODIX_BERLIN_REGISTER_WIDTH) + +#define GOODIX_BERLIN_SPI_WRITE_FLAG 0xF0 +#define GOODIX_BERLIN_SPI_READ_FLAG 0xF1 + +static int goodix_berlin_spi_read(void *context, const void *reg_buf, + size_t reg_size, void *val_buf, + size_t val_size) +{ + struct spi_device *spi = context; + struct spi_transfer xfers; + struct spi_message spi_msg; + const u32 *reg = reg_buf; /* reg is stored as native u32 at start of buffer */ + u8 *buf; + int error; + + if (reg_size != GOODIX_BERLIN_REGISTER_WIDTH) + return -EINVAL; + + buf = kzalloc(GOODIX_BERLIN_SPI_READ_PREFIX_LEN + val_size, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + spi_message_init(&spi_msg); + memset(&xfers, 0, sizeof(xfers)); + + /* buffer format: 0xF1 + addr(4bytes) + dummy(3bytes) + data */ + buf[0] = GOODIX_BERLIN_SPI_READ_FLAG; + put_unaligned_be32(*reg, buf + GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN); + memset(buf + GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN + GOODIX_BERLIN_REGISTER_WIDTH, + 0xff, GOODIX_BERLIN_SPI_READ_DUMMY_LEN); + + xfers.tx_buf = buf; + xfers.rx_buf = buf; + xfers.len = GOODIX_BERLIN_SPI_READ_PREFIX_LEN + val_size; + xfers.cs_change = 0; + spi_message_add_tail(&xfers, &spi_msg); + + error = spi_sync(spi, &spi_msg); + if (error < 0) + dev_err(&spi->dev, "spi transfer error, %d", error); + else + memcpy(val_buf, buf + GOODIX_BERLIN_SPI_READ_PREFIX_LEN, val_size); + + kfree(buf); + return error; +} + +static int goodix_berlin_spi_write(void *context, const void *data, + size_t count) +{ + unsigned int len = count - GOODIX_BERLIN_REGISTER_WIDTH; + struct spi_device *spi = context; + struct spi_transfer xfers; + struct spi_message spi_msg; + const u32 *reg = data; /* reg is stored as native u32 at start of buffer */ + u8 *buf; + int error; + + buf = kzalloc(GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN + len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + spi_message_init(&spi_msg); + memset(&xfers, 0, sizeof(xfers)); + + buf[0] = GOODIX_BERLIN_SPI_WRITE_FLAG; + put_unaligned_be32(*reg, buf + GOODIX_BERLIN_SPI_TRANS_PREFIX_LEN); + memcpy(buf + GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN, + data + GOODIX_BERLIN_REGISTER_WIDTH, len); + + xfers.tx_buf = buf; + xfers.len = GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN + len; + xfers.cs_change = 0; + spi_message_add_tail(&xfers, &spi_msg); + + error = spi_sync(spi, &spi_msg); + if (error < 0) + dev_err(&spi->dev, "spi transfer error, %d", error); + + kfree(buf); + return error; +} + +static const struct regmap_config goodix_berlin_spi_regmap_conf = { + .reg_bits = 32, + .val_bits = 8, + .read = goodix_berlin_spi_read, + .write = goodix_berlin_spi_write, +}; + +/* vendor & product left unassigned here, should probably be updated from fw info */ +static const struct input_id goodix_berlin_spi_input_id = { + .bustype = BUS_SPI, +}; + +static int goodix_berlin_spi_probe(struct spi_device *spi) +{ + struct regmap_config regmap_config; + struct regmap *regmap; + size_t max_size; + int error = 0; + + spi->mode = SPI_MODE_0; + spi->bits_per_word = 8; + error = spi_setup(spi); + if (error) + return error; + + max_size = spi_max_transfer_size(spi); + + regmap_config = goodix_berlin_spi_regmap_conf; + regmap_config.max_raw_read = max_size - GOODIX_BERLIN_SPI_READ_PREFIX_LEN; + regmap_config.max_raw_write = max_size - GOODIX_BERLIN_SPI_WRITE_PREFIX_LEN; + + regmap = devm_regmap_init(&spi->dev, NULL, spi, ®map_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + error = goodix_berlin_probe(&spi->dev, spi->irq, + &goodix_berlin_spi_input_id, regmap); + if (error) + return error; + + return 0; +} + +static const struct spi_device_id goodix_berlin_spi_ids[] = { + { "gt9916" }, + { }, +}; +MODULE_DEVICE_TABLE(spi, goodix_berlin_spi_ids); + +static const struct of_device_id goodix_berlin_spi_of_match[] = { + { .compatible = "goodix,gt9916", }, + { } +}; +MODULE_DEVICE_TABLE(of, goodix_berlin_spi_of_match); + +static struct spi_driver goodix_berlin_spi_driver = { + .driver = { + .name = "goodix-berlin-spi", + .of_match_table = goodix_berlin_spi_of_match, + .pm = pm_sleep_ptr(&goodix_berlin_pm_ops), + }, + .probe = goodix_berlin_spi_probe, + .id_table = goodix_berlin_spi_ids, +}; +module_spi_driver(goodix_berlin_spi_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("Goodix Berlin SPI Touchscreen driver"); +MODULE_AUTHOR("Neil Armstrong ");