From nobody Sun Jun 2 08:31:06 2024 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C28521A0C; Fri, 19 Apr 2024 08:35:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.193 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515713; cv=none; b=szIh+cPi2mb+pOXvTO2VdJF9s85Dk22fMDP9XeyKVtS1sKsNLHt9OAVTGoyz1c7N2qe/Y0VDhVL2vyv1th5V3Qlxll/K1mayB3jNR02mb44vIpEsUySPLS00CI98t2m/+9POaAX8Y95RLC+YnS3yQf+6zjmddIIayploXzyPRjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515713; c=relaxed/simple; bh=xvhakI/gJi6QeG2YGEaTZ/99O68GdGOJPHyw5PUhbO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fU6e1T4j7r8tnNvXKMzAMyFbxv29ecw4IbV3WWe2fHpZ7HxyrSFlxessUlkzvN4/D+1AfFmb6xI6sujtFHc9EzUBZEaKZd+QVrQ5H50tWCi97TKC4qM0HMlUg70LfkVONyCXUoATagKEZ8nUQeGZcfjq/LcZmYv043nf0nArIq4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=KckEIBRA; arc=none smtp.client-ip=217.70.183.193 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="KckEIBRA" Received: by mail.gandi.net (Postfix) with ESMTPSA id 1ACEE240007; Fri, 19 Apr 2024 08:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713515703; 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=KpuZnh+0Pw/1mj7y4M1pa+0BGDPeeXQB2THZ9rva5uI=; b=KckEIBRAGhsHf9SJhu1CxQsmISQV2TXp7+oPJsB+xes/antW2xl0gN50ZZIKTLjivpWgfH FDN8P3+ICFsA8W8ExoupikqINaPzBp5uAGHvEhvfhDE15+mO/zLXrwPyMbbe5R1S0LdnjX cMx5//IS1TkFtJi81kHf4MlwR5cr4h7jMEDFPvTH/DK1kV+JG6G2aV8L9VHbaaPvxtldp9 BVLRkd69Lx6vF5TigbrYnZmGLlylRNhbQBxKVfTaXx4ctn1w+esmrHqBc5KEMEsVOVBKkv TFP6/8brgCC8mn1kKVVBzj0/rc9CLgANvxOAgCQK77ZRdPng/5TWFgYUb9CfGw== From: Kamel Bouhara To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Henrik Rydberg , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Marco Felsch , Jeff LaBundy Cc: catalin.popescu@leica-geosystems.com, mark.satterthwaite@touchnetix.com, Thomas Petazzoni , Gregory Clement , bsp-development.geo@leica-geosystems.com, Kamel Bouhara , Krzysztof Kozlowski Subject: [PATCH v10 1/3] dt-bindings: vendor-prefixes: Add TouchNetix AS Date: Fri, 19 Apr 2024 10:33:39 +0200 Message-ID: <20240419083342.61199-2-kamel.bouhara@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240419083342.61199-1-kamel.bouhara@bootlin.com> References: <20240419083342.61199-1-kamel.bouhara@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: kamel.bouhara@bootlin.com Content-Type: text/plain; charset="utf-8" Add vendor prefix for TouchNetix AS (https://www.touchnetix.com/products/). Signed-off-by: Kamel Bouhara Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Docum= entation/devicetree/bindings/vendor-prefixes.yaml index b97d298b3eb6..33205dea558b 100644 --- a/Documentation/devicetree/bindings/vendor-prefixes.yaml +++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml @@ -1481,6 +1481,8 @@ patternProperties: description: Toradex AG "^toshiba,.*": description: Toshiba Corporation + "^touchnetix,.*": + description: TouchNetix AS "^toumaz,.*": description: Toumaz "^tpk,.*": --=20 2.25.1 From nobody Sun Jun 2 08:31:06 2024 Received: from mslow1.mail.gandi.net (mslow1.mail.gandi.net [217.70.178.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CEE1F64CE1; Fri, 19 Apr 2024 08:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.178.240 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713516073; cv=none; b=eDK20UYlKF0tcG9FkUcadROW6rUlQr60DL1m6jU9vj3JNjhpPxYjyHb6fKEavxKEPV/5CXvPmW1V9zp2FsoIzeMoHtARx/yGGd0ZDfPaljemoDeSHZJou+duUT/MThe9TLXop8CDYR5Jc1q+wkOOl9fDChhBaLvWAlgO5ZoWoVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713516073; c=relaxed/simple; bh=hK+zHThyGFcfWzPL3idL5aMhKZJVVEbhcpP3hC1vq/8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C/SV5Kh9vmsIGZ78WC04Dn8DdTQtbwJX1jqjJLWb4iefwTtWP3lu4MdCncNjO/91CDf8onbWH18yRnHJA8XtWJL6sCUedH4FdLncebFQgpZ62Q3J6dSfnsYampuKdstSYWf22AZxM1EPGRldcBxFJhRsDvZnCK4Pd7NiJyLfXI8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=YV8yRRe3; arc=none smtp.client-ip=217.70.178.240 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="YV8yRRe3" Received: from relay5-d.mail.gandi.net (unknown [217.70.183.197]) by mslow1.mail.gandi.net (Postfix) with ESMTP id CEBACC1D73; Fri, 19 Apr 2024 08:35:12 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2BFA61C0003; Fri, 19 Apr 2024 08:35:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713515704; 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=QDcNBpZCn4u/klnUUSyHjUy9T5QmNnFvR9cDhj3/AZ0=; b=YV8yRRe31MkSG24UF7TlYzv7vP576LYt8bu0rkgH/PkH73oh+xD9QtTIS1Rqk006jTLIq5 2RPGaJQfbaSUHpg/z6GP33vUunYxi8twVVxHyd3wBuGL2/pogFvlFVNBvlVefENWAABVlS FurD7AjVAIZmYWFrAiQRE8XIWBCxWyO7RCSPgNluz8YSziINaF7IhPpRyZCXXo0fOmxAw1 QeSRtR/2QGR0gt8nq5aAQ7L0feJQ3ScyoTehy1sD5aDtV4GLDIXOmdEn1SIgstuH6sB7V2 T6p3b96kKpmDttwEfRHTPAROgd71j+PR5yTOGZICtwXVCj6cI6o0TiD1IdzLsw== From: Kamel Bouhara To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Henrik Rydberg , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Marco Felsch , Jeff LaBundy Cc: catalin.popescu@leica-geosystems.com, mark.satterthwaite@touchnetix.com, Thomas Petazzoni , Gregory Clement , bsp-development.geo@leica-geosystems.com, Kamel Bouhara , Krzysztof Kozlowski Subject: [PATCH v10 2/3] dt-bindings: input: Add TouchNetix axiom touchscreen Date: Fri, 19 Apr 2024 10:33:40 +0200 Message-ID: <20240419083342.61199-3-kamel.bouhara@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240419083342.61199-1-kamel.bouhara@bootlin.com> References: <20240419083342.61199-1-kamel.bouhara@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: kamel.bouhara@bootlin.com Content-Type: text/plain; charset="utf-8" Add the TouchNetix axiom I2C touchscreen device tree bindings documentation. Signed-off-by: Kamel Bouhara Reviewed-by: Krzysztof Kozlowski --- .../input/touchscreen/touchnetix,ax54a.yaml | 62 +++++++++++++++++++ MAINTAINERS | 6 ++ 2 files changed, 68 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/touchscreen/tou= chnetix,ax54a.yaml diff --git a/Documentation/devicetree/bindings/input/touchscreen/touchnetix= ,ax54a.yaml b/Documentation/devicetree/bindings/input/touchscreen/touchneti= x,ax54a.yaml new file mode 100644 index 000000000000..66229a4d6f15 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/touchnetix,ax54a.= yaml @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/touchnetix,ax54a.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TouchNetix Axiom series touchscreen controller + +maintainers: + - Kamel Bouhara + +allOf: + - $ref: /schemas/input/touchscreen/touchscreen.yaml# + - $ref: /schemas/input/input.yaml# + +properties: + compatible: + const: touchnetix,ax54a + + reg: + const: 0x66 + + interrupts: + maxItems: 1 + + reset-gpios: + maxItems: 1 + + vdda-supply: + description: Analog power supply regulator on VDDA pin + + vddi-supply: + description: I/O power supply regulator on VDDI pin + +required: + - compatible + - reg + - vdda-supply + - vddi-supply + +unevaluatedProperties: false + +examples: + - | + #include + #include + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + touchscreen@66 { + compatible =3D "touchnetix,ax54a"; + reg =3D <0x66>; + interrupt-parent =3D <&gpio2>; + interrupts =3D <2 IRQ_TYPE_EDGE_FALLING>; + reset-gpios =3D <&gpio1 1 GPIO_ACTIVE_HIGH>; + vdda-supply =3D <&vdda_reg>; + vddi-supply =3D <&vddi_reg>; + poll-interval =3D <20>; + }; + }; +... diff --git a/MAINTAINERS b/MAINTAINERS index 7c121493f43d..3c59cb760071 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22419,6 +22419,12 @@ L: platform-driver-x86@vger.kernel.org S: Maintained F: drivers/platform/x86/toshiba-wmi.c =20 +TOUCHNETIX AXIOM I2C TOUCHSCREEN DRIVER +M: Kamel Bouhara +L: linux-input@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/input/touchscreen/touchnetix,ax54a.ya= ml + TPM DEVICE DRIVER M: Peter Huewe M: Jarkko Sakkinen --=20 2.25.1 From nobody Sun Jun 2 08:31:06 2024 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2EA46D1C7; Fri, 19 Apr 2024 08:35:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515717; cv=none; b=ud9Sl4kBSJArHDMOUUf+MH940r6zUIIZQCHZVeEBN5IG+EdsTVa3z3FWJX2ExNcS2sYrTawlyaf7+e6Jb4FLTckveFL93KQ+FWSuAU5ZXgoZPW61H/y2uexPr8OKg197T7EurDLs2ouiRndV9XtQbMr2ItWo1YU18aKFlSq3c+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713515717; c=relaxed/simple; bh=W4RQ5w1hAa21VS9VJ3DjxoIsK9jAAUv+KUBZYYNCmmE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XRzOEIipF7vPoYXOd+RBz1ijgo4EkgSKNdBhKnV+yNeQnmtrO5asdYstlpL6WaG8Jj1sQW1zLdN3sDdMfgWAhjAt52j7DTxbn67gcEloogVTrtz3RDrCCf79B8mXcJo4hVM7i2BqEjr2MzkILwRkk7CNasJYyiFILWqXyUI9e44= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=W7mik2Oo; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="W7mik2Oo" Received: by mail.gandi.net (Postfix) with ESMTPSA id 64E9D60006; Fri, 19 Apr 2024 08:35:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1713515707; 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=Z/4hCTlNt1kZFbxTPwdI9/0ph7WbmhycJ8JyqP8WSnw=; b=W7mik2Oo0s7ZEKBg07sUIUXjY/xRlRU0h2xqs+ksCNyZ9+27O+0YmixZhVpaoopn61825F TFKGlAV+qRCXuI/bdPjooHJ8uCsuDOQM7bxywsvJ5+f9pbpGZnS7KyXlxSSooBV8rD4xmP FIadQmaaSKW2w+anrr+vZahw4Jz/5apyviQrgqrqYKKuzdEd1tJa2uABCfLDapPLzgTCDk 0CCN/MJaXDCHZG/Cw0trANZbsKcP8pZc7Z1ldsBg6LLFOiqaUK3PoQO4U2mJPuRyobp8uX ocn5h59QiJwCJx0pj0j8DyQ+3quJ0LCZQN4mgT2uOvTkFQqlspH9Cd5CVEQAsw== From: Kamel Bouhara To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Henrik Rydberg , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Marco Felsch , Jeff LaBundy Cc: catalin.popescu@leica-geosystems.com, mark.satterthwaite@touchnetix.com, Thomas Petazzoni , Gregory Clement , bsp-development.geo@leica-geosystems.com, Kamel Bouhara Subject: [PATCH v10 3/3] Input: Add TouchNetix axiom i2c touchscreen driver Date: Fri, 19 Apr 2024 10:33:41 +0200 Message-ID: <20240419083342.61199-4-kamel.bouhara@bootlin.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240419083342.61199-1-kamel.bouhara@bootlin.com> References: <20240419083342.61199-1-kamel.bouhara@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-GND-Sasl: kamel.bouhara@bootlin.com Content-Type: text/plain; charset="utf-8" Add a new driver for the TouchNetix's axiom family of touchscreen controllers. This driver only supports i2c and can be later adapted for SPI and USB support. Signed-off-by: Kamel Bouhara --- MAINTAINERS | 2 + drivers/input/touchscreen/Kconfig | 12 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/touchnetix_axiom.c | 659 +++++++++++++++++++ 4 files changed, 674 insertions(+) create mode 100644 drivers/input/touchscreen/touchnetix_axiom.c diff --git a/MAINTAINERS b/MAINTAINERS index 3c59cb760071..d9535d7e4061 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22421,9 +22421,11 @@ F: drivers/platform/x86/toshiba-wmi.c =20 TOUCHNETIX AXIOM I2C TOUCHSCREEN DRIVER M: Kamel Bouhara +M: bsp-development.geo@leica-geosystems.com L: linux-input@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/input/touchscreen/touchnetix,ax54a.ya= ml +F: drivers/input/touchscreen/touchnetix_axiom.c =20 TPM DEVICE DRIVER M: Peter Huewe diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/= Kconfig index c821fe3ee794..503ccea5c1b0 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -834,6 +834,18 @@ config TOUCHSCREEN_MIGOR To compile this driver as a module, choose M here: the module will be called migor_ts. =20 +config TOUCHSCREEN_TOUCHNETIX_AXIOM + tristate "TouchNetix AXIOM based touchscreen controllers" + depends on I2C + help + Say Y here if you have a axiom touchscreen connected to + your system. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called axiom. + config TOUCHSCREEN_TOUCHRIGHT tristate "Touchright serial touchscreen" select SERIO diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen= /Makefile index a81cb5aa21a5..6ce7b804adc7 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -91,6 +91,7 @@ obj-$(CONFIG_TOUCHSCREEN_SUR40) +=3D sur40.o obj-$(CONFIG_TOUCHSCREEN_SURFACE3_SPI) +=3D surface3_spi.o obj-$(CONFIG_TOUCHSCREEN_TI_AM335X_TSC) +=3D ti_am335x_tsc.o obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) +=3D touchit213.o +obj-$(CONFIG_TOUCHSCREEN_TOUCHNETIX_AXIOM) +=3D touchnetix_axiom.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) +=3D touchright.o obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) +=3D touchwin.o obj-$(CONFIG_TOUCHSCREEN_TS4800) +=3D ts4800-ts.o diff --git a/drivers/input/touchscreen/touchnetix_axiom.c b/drivers/input/t= ouchscreen/touchnetix_axiom.c new file mode 100644 index 000000000000..a2142de55a88 --- /dev/null +++ b/drivers/input/touchscreen/touchnetix_axiom.c @@ -0,0 +1,659 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * TouchNetix axiom Touchscreen Driver + * + * Copyright (C) 2020-2023 TouchNetix Ltd. + * + * Author(s): Bart Prescott + * Pedro Torruella + * Mark Satterthwaite + * Hannah Rossiter + * Kamel Bouhara + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#define AXIOM_PROX_LEVEL -128 +#define AXIOM_DMA_OPS_DELAY_USEC 250 +#define AXIOM_STARTUP_TIME_MS 110 +/* + * Register group u31 has 2 pages for usage table entries. + */ +#define AXIOM_U31_MAX_USAGES 0xff +#define AXIOM_U31_BYTES_PER_USAGE 6 +#define AXIOM_U31_PAGE0_LENGTH 0x0C +#define AXIOM_U31_BOOTMODE_MASK BIT(7) +#define AXIOM_U31_DEVID_MASK GENMASK(14, 0) + +#define AXIOM_MAX_REPORT_LEN 0x7f + +#define AXIOM_CMD_HEADER_READ_MASK BIT(15) +#define AXIOM_U41_MAX_TARGETS 10 + +#define AXIOM_U46_AUX_CHANNELS 4 +#define AXIOM_U46_AUX_MASK GENMASK(11, 0) + +#define AXIOM_COMMS_MAX_USAGE_PAGES 3 +#define AXIOM_COMMS_PAGE_SIZE 256 +#define AXIOM_COMMS_REPORT_LEN_MASK GENMASK(6, 0) + +#define AXIOM_REPORT_USAGE_ID 0x34 +#define AXIOM_DEVINFO_USAGE_ID 0x31 +#define AXIOM_USAGE_2HB_REPORT_ID 0x01 +#define AXIOM_USAGE_2AUX_REPORT_ID 0x46 +#define AXIOM_USAGE_2DCTS_REPORT_ID 0x41 + +#define AXIOM_PAGE_OFFSET_MASK GENMASK(6, 0) + +struct axiom_devinfo { + __le16 device_id; + u8 fw_minor; + u8 fw_major; + u8 fw_info_extra; + u8 tcp_revision; + u8 bootloader_fw_minor; + u8 bootloader_fw_major; + __le16 jedec_id; + u8 num_usages; +} __packed; + +/* + * Describes parameters of a specific usage, essentially a single element = of + * the "Usage Table" + */ +struct axiom_usage_entry { + u8 id; + u8 is_report; + u8 start_page; + u8 num_pages; +}; + +/* + * Represents state of a touch or target when detected prior to a touch (e= g. + * hover or proximity events). + */ +enum axiom_target_state { + AXIOM_TARGET_STATE_NOT_PRESENT =3D 0, + AXIOM_TARGET_STATE_PROX =3D 1, + AXIOM_TARGET_STATE_HOVER =3D 2, + AXIOM_TARGET_STATE_TOUCHING =3D 3, +}; + +struct axiom_u41_target { + enum axiom_target_state state; + u16 x; + u16 y; + s8 z; + bool insert; + bool touch; +}; + +struct axiom_target_report { + u8 index; + u8 present; + u16 x; + u16 y; + s8 z; +}; + +struct axiom_cmd_header { + __le16 target_address; + __le16 length; +} __packed; + +struct axiom_data { + struct axiom_devinfo devinfo; + struct device *dev; + struct gpio_desc *reset_gpio; + struct i2c_client *client; + struct input_dev *input_dev; + u32 max_report_len; + u8 rx_buf[AXIOM_COMMS_MAX_USAGE_PAGES * AXIOM_COMMS_PAGE_SIZE]; + struct axiom_u41_target targets[AXIOM_U41_MAX_TARGETS]; + struct axiom_usage_entry usage_table[AXIOM_U31_MAX_USAGES]; + bool usage_table_populated; + struct regulator *vdda; + struct regulator *vddi; + struct regmap *regmap; + struct touchscreen_properties prop; +}; + +static const struct regmap_config axiom_i2c_regmap_config =3D { + .reg_bits =3D 32, + .reg_format_endian =3D REGMAP_ENDIAN_LITTLE, + .val_bits =3D 8, + .val_format_endian =3D REGMAP_ENDIAN_LITTLE, +}; + +/* + * axiom devices are typically configured to report touches at a rate + * of 100Hz (10ms) for systems that require polling for reports. + * When reports are polled, it will be expected to occasionally + * observe the overflow bit being set in the reports. + * This indicates that reports are not being read fast enough. + */ +#define POLL_INTERVAL_DEFAULT_MS 10 + +/* Translate usage/page/offset triplet into physical address. */ +static u16 axiom_usage_to_target_address(struct axiom_data *ts, u8 usage, = u8 page, + char offset) +{ + /* At the moment the convention is that u31 is always at physical address= 0x0 */ + if (!ts->usage_table_populated) { + if (usage =3D=3D AXIOM_DEVINFO_USAGE_ID) + return ((page << 8) + offset); + else + return 0xffff; + } + + if (page >=3D ts->usage_table[usage].num_pages) { + dev_err(ts->dev, "Invalid usage table! usage: u%02x, page: %02x, offset:= %02x\n", + usage, page, offset); + return 0xffff; + } + + return ((ts->usage_table[usage].start_page + page) << 8) + offset; +} + +static int axiom_read(struct axiom_data *ts, u8 usage, u8 page, void *buf,= u16 len) +{ + struct axiom_cmd_header cmd_header; + u32 preamble; + int ret; + + cmd_header.target_address =3D cpu_to_le16(axiom_usage_to_target_address(t= s, usage, page, 0)); + cmd_header.length =3D cpu_to_le16(len | AXIOM_CMD_HEADER_READ_MASK); + + preamble =3D get_unaligned_le32(&cmd_header); + + ret =3D regmap_write(ts->regmap, preamble, 0); + if (ret) { + dev_err(ts->dev, "failed to write preamble, error %d\n", ret); + return ret; + } + + ret =3D regmap_raw_read(ts->regmap, 0, buf, len); + if (ret) { + dev_err(ts->dev, "failed to read target address %04x, error %d\n", + cmd_header.target_address, ret); + return ret; + } + + /* Wait device's DMA operations */ + usleep_range(AXIOM_DMA_OPS_DELAY_USEC, AXIOM_DMA_OPS_DELAY_USEC + 50); + + return 0; +} + +/* + * One of the main purposes for reading the usage table is to identify + * which usages reside at which target address. + * When performing subsequent reads or writes to AXIOM, the target address + * is used to specify which usage is being accessed. + * Consider the following discovery code which will build up the usage tab= le. + */ +static u32 axiom_populate_usage_table(struct axiom_data *ts) +{ + struct axiom_usage_entry *usage_table; + u8 *rx_data =3D ts->rx_buf; + u32 max_report_len =3D 0; + u32 usage_id; + int error; + + usage_table =3D ts->usage_table; + + /* Read the second page of usage u31 to get the usage table */ + error =3D axiom_read(ts, AXIOM_DEVINFO_USAGE_ID, 1, rx_data, + (AXIOM_U31_BYTES_PER_USAGE * ts->devinfo.num_usages)); + + if (error) + return error; + + for (usage_id =3D 0; usage_id < ts->devinfo.num_usages; usage_id++) { + u16 offset =3D (usage_id * AXIOM_U31_BYTES_PER_USAGE); + u8 id =3D rx_data[offset + 0]; + u8 start_page =3D rx_data[offset + 1]; + u8 num_pages =3D rx_data[offset + 2]; + u32 max_offset =3D ((rx_data[offset + 3] & AXIOM_PAGE_OFFSET_MASK) + 1) = * 2; + + usage_table[id].is_report =3D !num_pages; + + /* Store the entry into the usage table */ + usage_table[id].id =3D id; + usage_table[id].start_page =3D start_page; + usage_table[id].num_pages =3D num_pages; + + dev_dbg(ts->dev, "Usage u%02x Info: %*ph\n", id, AXIOM_U31_BYTES_PER_USA= GE, + &rx_data[offset]); + + /* Identify the max report length the module will receive */ + if (usage_table[id].is_report && max_offset > max_report_len) + max_report_len =3D max_offset; + } + + ts->usage_table_populated =3D true; + + return max_report_len; +} + +static int axiom_discover(struct axiom_data *ts) +{ + int error; + + /* + * Fetch the first page of usage u31 to get the + * device information and the number of usages + */ + error =3D axiom_read(ts, AXIOM_DEVINFO_USAGE_ID, 0, &ts->devinfo, AXIOM_U= 31_PAGE0_LENGTH); + if (error) + return error; + + dev_dbg(ts->dev, " Boot Mode : %s\n", + FIELD_GET(AXIOM_U31_BOOTMODE_MASK, + le16_to_cpu(ts->devinfo.device_id)) ? "BLP" : "TCP"); + dev_dbg(ts->dev, " Device ID : %04lx\n", + FIELD_GET(AXIOM_U31_DEVID_MASK, le16_to_cpu(ts->devinfo.device_id))); + dev_dbg(ts->dev, " Firmware Rev : %02x.%02x\n", ts->devinfo.fw_major, + ts->devinfo.fw_minor); + dev_dbg(ts->dev, " Bootloader Rev : %02x.%02x\n", ts->devinfo.bootloader= _fw_major, + ts->devinfo.bootloader_fw_minor); + dev_dbg(ts->dev, " FW Extra Info : %04x\n", ts->devinfo.fw_info_extra); + dev_dbg(ts->dev, " Silicon : %04x\n", le16_to_cpu(ts->devinfo.jed= ec_id)); + dev_dbg(ts->dev, " Number usages : %04x\n", ts->devinfo.num_usage= s); + + ts->max_report_len =3D axiom_populate_usage_table(ts); + if (!ts->max_report_len || !ts->devinfo.num_usages || + ts->max_report_len > AXIOM_MAX_REPORT_LEN) { + dev_err(ts->dev, "Invalid report length or usages number"); + return -EINVAL; + } + + dev_dbg(ts->dev, "Max Report Length: %u\n", ts->max_report_len); + + return 0; +} + +/* + * Support function to axiom_process_u41_report. + * Generates input-subsystem events for every target. + * After calling this function the caller shall issue + * a Sync to the input sub-system. + */ +static bool axiom_process_u41_report_target(struct axiom_data *ts, + struct axiom_target_report *target) +{ + struct input_dev *input_dev =3D ts->input_dev; + struct axiom_u41_target *target_prev_state; + enum axiom_target_state current_state; + int id; + + /* Verify the target index */ + if (target->index >=3D AXIOM_U41_MAX_TARGETS) { + dev_err(ts->dev, "Invalid target index! %u\n", target->index); + return false; + } + + target_prev_state =3D &ts->targets[target->index]; + + current_state =3D AXIOM_TARGET_STATE_NOT_PRESENT; + + if (target->present) { + if (target->z >=3D 0) + current_state =3D AXIOM_TARGET_STATE_TOUCHING; + else if (target->z > AXIOM_PROX_LEVEL && target->z < 0) + current_state =3D AXIOM_TARGET_STATE_HOVER; + else if (target->z =3D=3D AXIOM_PROX_LEVEL) + current_state =3D AXIOM_TARGET_STATE_PROX; + } + + if (target_prev_state->state =3D=3D current_state && + target_prev_state->x =3D=3D target->x && + target_prev_state->y =3D=3D target->y && + target_prev_state->z =3D=3D target->z) + return false; + + id =3D target->index; + + dev_dbg(ts->dev, "U41 Target T%u, present:%u, x:%u, y:%u, z:%d\n", + target->index, target->present, + target->x, target->y, target->z); + + switch (current_state) { + case AXIOM_TARGET_STATE_NOT_PRESENT: + case AXIOM_TARGET_STATE_PROX: + if (!target_prev_state->insert) + break; + target_prev_state->insert =3D false; + + if (!id) + input_report_key(input_dev, BTN_TOUCH, 0); + + input_mt_report_slot_inactive(input_dev); + /* + * make sure the previous coordinates are + * all off screen when the finger comes back + */ + target->x =3D 65535; + target->y =3D 65535; + target->z =3D AXIOM_PROX_LEVEL; + break; + case AXIOM_TARGET_STATE_HOVER: + case AXIOM_TARGET_STATE_TOUCHING: + target_prev_state->insert =3D true; + input_report_abs(input_dev, ABS_MT_TRACKING_ID, id); + input_report_abs(input_dev, ABS_MT_POSITION_X, target->x); + input_report_abs(input_dev, ABS_MT_POSITION_Y, target->y); + + if (current_state =3D=3D AXIOM_TARGET_STATE_TOUCHING) { + input_report_abs(input_dev, ABS_MT_DISTANCE, 0); + input_report_abs(input_dev, ABS_DISTANCE, 0); + input_report_abs(input_dev, ABS_MT_PRESSURE, target->z); + input_report_abs(input_dev, ABS_PRESSURE, target->z); + } else { + input_report_abs(input_dev, ABS_MT_DISTANCE, -target->z); + input_report_abs(input_dev, ABS_DISTANCE, -target->z); + input_report_abs(input_dev, ABS_MT_PRESSURE, 0); + input_report_abs(input_dev, ABS_PRESSURE, 0); + } + + if (!id) + input_report_key(input_dev, BTN_TOUCH, (current_state =3D=3D + AXIOM_TARGET_STATE_TOUCHING)); + break; + default: + break; + } + + target_prev_state->state =3D current_state; + target_prev_state->x =3D target->x; + target_prev_state->y =3D target->y; + target_prev_state->z =3D target->z; + + return true; +} + +/* + * U41 is the output report of the 2D CTS and contains the status of targe= ts + * (including contacts and pre-contacts) along with their X,Y,Z values. + * When a target has been removed (no longer detected), + * the corresponding X,Y,Z values will be zeroed. + */ +static bool axiom_process_u41_report(struct axiom_data *ts, u8 *rx_buf) +{ + struct axiom_target_report target; + bool update_done =3D false; + u16 target_status; + int i; + + target_status =3D get_unaligned_le16(rx_buf + 1); + + for (i =3D 0; i < AXIOM_U41_MAX_TARGETS; i++) { + u8 *target_step =3D &rx_buf[i * 4]; + + target.index =3D i; + input_mt_slot(ts->input_dev, i); + input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); + target.present =3D ((target_status & (1 << i)) !=3D 0) ? 1 : 0; + target.x =3D get_unaligned_le16(target_step + 3); + target.y =3D get_unaligned_le16(target_step + 5); + target.z =3D (s8)(rx_buf[i + 43]); + touchscreen_report_pos(ts->input_dev, &ts->prop, target.x, target.y, tru= e); + update_done |=3D axiom_process_u41_report_target(ts, &target); + } + + return update_done; +} + +/* + * U46 report contains a low level measurement data generated by the capac= itive + * displacement sensor (CDS) algorithms from the auxiliary channels. + * This information is useful when tuning multi-press to assess mechanical + * consistency in the unit's construction. + */ +static void axiom_process_u46_report(struct axiom_data *ts, u8 *rx_buf) +{ + struct input_dev *input_dev =3D ts->input_dev; + u32 event_value; + u16 aux_value; + int i; + + for (i =3D 0; i < AXIOM_U46_AUX_CHANNELS; i++) { + u8 *target_step =3D &rx_buf[i * 2]; + + input_mt_slot(input_dev, i); + input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true); + aux_value =3D get_unaligned_le16(target_step + 1) & AXIOM_U46_AUX_MASK; + event_value =3D (i << 16) | (aux_value); + input_event(input_dev, EV_MSC, MSC_RAW, event_value); + } +} + +/* + * Validates the crc and demultiplexes the axiom reports to the appropriate + * report handler + */ +static int axiom_handle_events(struct axiom_data *ts) +{ + struct input_dev *input_dev =3D ts->input_dev; + u8 *report_data =3D ts->rx_buf; + struct device *dev =3D ts->dev; + u16 crc_report; + u8 *crc_bytes; + u16 crc_calc; + int error; + u8 len; + + error =3D axiom_read(ts, AXIOM_REPORT_USAGE_ID, 0, report_data, ts->max_r= eport_len); + if (error) + return error; + + len =3D (report_data[0] & AXIOM_COMMS_REPORT_LEN_MASK) << 1; + if (len <=3D 2) { + dev_err(dev, "Zero length report discarded.\n"); + return -ENODATA; + } + + /* Validate the report CRC */ + crc_bytes =3D &report_data[len]; + + crc_report =3D get_unaligned_le16(crc_bytes - 2); + /* Length is in 16 bit words and remove the size of the CRC16 itself */ + crc_calc =3D crc16(0, report_data, (len - 2)); + + if (crc_calc !=3D crc_report) { + dev_err(dev, + "CRC mismatch! Expected: %#x, Calculated CRC: %#x.\n", + crc_report, crc_calc); + return -EINVAL; + } + + switch (report_data[1]) { + case AXIOM_USAGE_2DCTS_REPORT_ID: + if (axiom_process_u41_report(ts, &report_data[1])) { + input_mt_sync_frame(input_dev); + input_sync(input_dev); + } + break; + + case AXIOM_USAGE_2AUX_REPORT_ID: + /* This is an aux report (force) */ + axiom_process_u46_report(ts, &report_data[1]); + input_mt_sync(input_dev); + input_sync(input_dev); + break; + + case AXIOM_USAGE_2HB_REPORT_ID: + /* This is a heartbeat report */ + break; + default: + return -EINVAL; + } + + return 0; +} + +static void axiom_i2c_poll(struct input_dev *input_dev) +{ + struct axiom_data *ts =3D input_get_drvdata(input_dev); + + axiom_handle_events(ts); +} + +static irqreturn_t axiom_irq(int irq, void *dev_id) +{ + struct axiom_data *ts =3D dev_id; + + axiom_handle_events(ts); + + return IRQ_HANDLED; +} + +static void axiom_reset(struct gpio_desc *reset_gpio) +{ + gpiod_set_value_cansleep(reset_gpio, 1); + usleep_range(1000, 2000); + gpiod_set_value_cansleep(reset_gpio, 0); + msleep(AXIOM_STARTUP_TIME_MS); +} + +static int axiom_i2c_probe(struct i2c_client *client) +{ + struct device *dev =3D &client->dev; + struct input_dev *input_dev; + struct axiom_data *ts; + u32 poll_interval; + int target; + int error; + + ts =3D devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL); + if (!ts) + return -ENOMEM; + + i2c_set_clientdata(client, ts); + ts->client =3D client; + ts->dev =3D dev; + + ts->regmap =3D devm_regmap_init_i2c(client, &axiom_i2c_regmap_config); + error =3D PTR_ERR_OR_ZERO(ts->regmap); + if (error) { + dev_err(dev, "Failed to initialize regmap: %d\n", error); + return error; + } + + ts->vddi =3D devm_regulator_get(dev, "VDDI"); + if (IS_ERR(ts->vddi)) + return dev_err_probe(&client->dev, PTR_ERR(ts->vddi), + "Failed to enable VDDI regulator\n"); + + ts->vdda =3D devm_regulator_get(dev, "VDDA"); + if (IS_ERR(ts->vdda)) + return dev_err_probe(&client->dev, PTR_ERR(ts->vdda), + "Failed to enable VDDA regulator\n"); + + ts->reset_gpio =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(ts->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(ts->reset_gpio), "failed to get reset = GPIO\n"); + + if (ts->reset_gpio) + axiom_reset(ts->reset_gpio); + else + msleep(AXIOM_STARTUP_TIME_MS); + + error =3D axiom_discover(ts); + if (error) + return dev_err_probe(dev, error, "Failed touchscreen discover\n"); + + input_dev =3D devm_input_allocate_device(ts->dev); + if (!input_dev) + return -ENOMEM; + + input_dev->name =3D "TouchNetix axiom Touchscreen"; + input_dev->phys =3D "input/axiom_ts"; + + input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 65535, 0, 0); + input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 65535, 0, 0); + input_set_abs_params(input_dev, ABS_MT_TOOL_TYPE, 0, MT_TOOL_MAX, 0, 0); + input_set_abs_params(input_dev, ABS_MT_DISTANCE, 0, 127, 0, 0); + input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 127, 0, 0); + + touchscreen_parse_properties(input_dev, true, &ts->prop); + + /* Registers the axiom device as a touchscreen instead of a mouse pointer= */ + error =3D input_mt_init_slots(input_dev, AXIOM_U41_MAX_TARGETS, INPUT_MT_= DIRECT); + if (error) + return error; + + /* Enables the raw data for up to 4 force channels to be sent to the inpu= t subsystem */ + set_bit(EV_REL, input_dev->evbit); + set_bit(EV_MSC, input_dev->evbit); + /* Declare that we support "RAW" Miscellaneous events */ + set_bit(MSC_RAW, input_dev->mscbit); + + ts->input_dev =3D input_dev; + input_set_drvdata(ts->input_dev, ts); + + /* Ensure that all reports are initialised to not be present. */ + for (target =3D 0; target < AXIOM_U41_MAX_TARGETS; target++) + ts->targets[target].state =3D AXIOM_TARGET_STATE_NOT_PRESENT; + + error =3D devm_request_threaded_irq(dev, client->irq, NULL, + axiom_irq, IRQF_ONESHOT, dev_name(dev), ts); + if (error) { + dev_info(dev, "Request irq failed, falling back to polling mode"); + + error =3D input_setup_polling(input_dev, axiom_i2c_poll); + if (error) + return dev_err_probe(ts->dev, error, "Unable to set up polling mode\n"); + + if (!device_property_read_u32(ts->dev, "poll-interval", &poll_interval)) + input_set_poll_interval(input_dev, poll_interval); + else + input_set_poll_interval(input_dev, POLL_INTERVAL_DEFAULT_MS); + } + + return input_register_device(input_dev); +} + +static const struct i2c_device_id axiom_i2c_id_table[] =3D { + { "ax54a" }, + { }, +}; +MODULE_DEVICE_TABLE(i2c, axiom_i2c_id_table); + +static const struct of_device_id axiom_i2c_of_match[] =3D { + { .compatible =3D "touchnetix,ax54a", }, + { } +}; +MODULE_DEVICE_TABLE(of, axiom_i2c_of_match); + +static struct i2c_driver axiom_i2c_driver =3D { + .driver =3D { + .name =3D "axiom", + .of_match_table =3D axiom_i2c_of_match, + }, + .id_table =3D axiom_i2c_id_table, + .probe =3D axiom_i2c_probe, +}; +module_i2c_driver(axiom_i2c_driver); + +MODULE_AUTHOR("Bart Prescott "); +MODULE_AUTHOR("Pedro Torruella "); +MODULE_AUTHOR("Mark Satterthwaite "); +MODULE_AUTHOR("Hannah Rossiter "); +MODULE_AUTHOR("Kamel Bouhara "); +MODULE_DESCRIPTION("TouchNetix axiom touchscreen I2C bus driver"); +MODULE_LICENSE("GPL"); --=20 2.25.1