From nobody Wed Nov 27 00:26:08 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 696F01C07CD; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; cv=none; b=ILsCAwUTKi6fWTzQqYqLXe7+sYCYhjZiubpVVy5bvy12OO/m/xrryDmXNfTKCzyd4wMCCy7HxWUliYyow/1J82l5MXMcRgWlqGQDzB9AlwsSfAOegMGThHFPdCYuev2QlXK+M+CzBGnB++AlRPGPz7SnAevOF6SrJNy4N1szeaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; c=relaxed/simple; bh=k4sHN8F0vEpbhstI4pP9YlVgxqXHlxI77MHkEXqdZ2Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TfYa1IbYxxoWZeQlAT1taJt/g3nq2Vlhjy5W1UcSY00JjcRcAzWu7Dk2dMKy00ftc0B333oX+8fR7eQR7rDg0XgnttuVECNxdczBtTOdDCzYxAtwodOPebIDZtb3rj17VSGip+b5LT87ir4dSlQ+/ufil9QoZ/3ZtQxW2x52lsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AmGBVFFU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AmGBVFFU" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0A3EFC4CECF; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728996812; bh=k4sHN8F0vEpbhstI4pP9YlVgxqXHlxI77MHkEXqdZ2Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AmGBVFFUhDFf9q0SM1LLzat+P7WqsQzZLhYDcBg3hgko2cGkggQOuJmcjfVVjrsuz R/iBFzOvaMcC3BbQR/ffQt41gUJtXBbEY4xtuVveKUdxipqi4d73CeZnXNvdaNFZ+j 3DbWop7M3NRkYW598qwtD0EcHLLhibAMMng4s6a1Uwp7ma8oSEjGsbxGv+nWSt4Q+z /ZTTnAjC+sgzvaGreg6UPIviY69KDNCePp/wpOxQxx8stT8phNbwYoAXOwyfVBAUOR K54ZBt5YiCZQtBgCSAbPsfTNGb/O8AtOnMlI+TocwUr1F9SwK0JTzAkcHfJ3nnjUCt JwrrFiIJaFvnA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB0E0D21690; Tue, 15 Oct 2024 12:53:31 +0000 (UTC) From: George Chan via B4 Relay Date: Tue, 15 Oct 2024 20:53:29 +0800 Subject: [PATCH RFC/RFT 1/3] dt-bindings: touchscreen: Add binding for Novatek NT36xxx series driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241015-nt36xxx-v1-1-3919d0bffee6@gmail.com> References: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> In-Reply-To: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Del Regno , Henrik Rydberg Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, George Chan X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728996810; l=2336; i=gchan9527@gmail.com; s=20241015; h=from:subject:message-id; bh=6oXy8utpLvYCjX6FpS5vMO4JWOmudlGhgWpN7w1GKpA=; b=CWp38R0kg4uaRnXXylbmhUTfN0jCdb9ZlwmWTWEB23Q+QeTeiwx1ni+IxplTJCJ1KKwRp0uKk X7ejSsE16zZA5e6/vpxusNPxamsZPsFqVl7osdTto0WB7CYSF86tKyR X-Developer-Key: i=gchan9527@gmail.com; a=ed25519; pk=dscYWhT+BiQOBMpPE19NFQAjBBmcpipc6zdf2MTze/U= X-Endpoint-Received: by B4 Relay for gchan9527@gmail.com/20241015 with auth_id=248 X-Original-From: George Chan Reply-To: gchan9527@gmail.com From: George Chan Add binding for the Novatek NT36xxx series touchscreen driver. Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: George Chan --- .../bindings/input/touchscreen/nt36xxx.yaml | 70 ++++++++++++++++++= ++++ 1 file changed, 70 insertions(+) diff --git a/Documentation/devicetree/bindings/input/touchscreen/nt36xxx.ya= ml b/Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml new file mode 100644 index 0000000000..3919f0d026 --- /dev/null +++ b/Documentation/devicetree/bindings/input/touchscreen/nt36xxx.yaml @@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/touchscreen/nt36xxx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Novatek NT36xxx series touchscreen controller Bindings + +maintainers: + - AngeloGioacchino Del Regno + - George Chan + +allOf: + - $ref: touchscreen.yaml# + +properties: + compatible: + enum: + - novatek,nt36525-spi + - novatek,nt36672a-spi + - novatek,nt36675-spi + - novatek,nt36676f-spi + - novatek,nt36772-spi + + reg: + maxItems: 1 + + irq-gpio: + maxItems: 1 + + vdd-supply: + description: Power supply regulator for VDD pin + + vio-supply: + description: Power supply regulator on VDD-IO pin + + firmware-name: + description: Firmware for device initialization, if unspecify, all + other IC treat as no firmware needed. For nt36675, defau= lt + to "novatek_ts_tianma_fw.bin". + + spi-max-frequency: + description: Set max frequency to spi bus communication. This is optio= nal. + +unevaluatedProperties: false + +required: + - compatible + - reg + - irq-gpio + +examples: + - | + #include + #include + + spi { + #address-cells =3D <1>; + #size-cells =3D <0>; + + touchscreen@0 { + compatible =3D "novatek,nt36675-spi"; + reg =3D <0>; + spi-max-frequency =3D <4000000>; + irq-gpio =3D <&tlmm 9 0x2001>; + firmware-name =3D "novatek_ts_tianma_fw.bin"; + }; + }; + +... --=20 2.43.0 From nobody Wed Nov 27 00:26:08 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8791A1C07E0; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; cv=none; b=mGIzPoo0RJvMVCdsmLdxI6enocG47UcRklb7UIko640/7/NL/PYx8iXpQmFpwwDUDSr/tyN2hzKZHmqzRHOaTRux/0vk6Pnb5SZWpt+RJ8i7ECq1AZgw+3pxfb4gCLMltiy/qRxhueXLhwI00RmpZTKHg6htdigc+7ZyiOLJ/pU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; c=relaxed/simple; bh=IDx+EVqsGXyGLT8dGiUWR61++nVkC8eWcKacQwSWIrc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ogj9tqkrAC11s0cMB6GVHUnL5bNDHWclFPaF7W/fMcEjzawfQ86I9vtZIWxpW0+td7n+ge5KNYgznkhAvXs65+k5J5zTE4bRfoVQgD1ge50Gx3EIgpuue5KRY2NLwRLkdDFajqojdn4Vf5xTlgxA+LipALmPViz738YV1Zc3FSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mlIevQ4r; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mlIevQ4r" Received: by smtp.kernel.org (Postfix) with ESMTPS id 20A43C4CED0; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728996812; bh=IDx+EVqsGXyGLT8dGiUWR61++nVkC8eWcKacQwSWIrc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mlIevQ4rheKOO79Ul17wdIIuecYJbUbF7hdQzQmwGl3Nu2i40TQ1ugN3MghtUxp1z RytGllDQgUw/KjuQbWvPELN9k1NwMrpLM7OG+osWky3SaqUEq23m+0bcbz9DPJ/3UE q6XPTnSY4R7m6YHhV/FIB+QUyCWgoGul4n/pER+dKC5YUuL4LtNXU2b75waLTTQtdL wXw+Rhst8KuHMAjWP+jyHkmzrtaIbzwKJy3jf3KZPv8fpnIfLf8oFzusPCBIAywKUK 7O/cTYrd0xmB+LLlSXOicXPbz9N8HvKeKMfuwbA0RhSj5fr2cuRTM2aoSGtvFxqtMw QMkHW10YGZWVg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FC40D21699; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) From: George Chan via B4 Relay Date: Tue, 15 Oct 2024 20:53:30 +0800 Subject: [PATCH RFC/RFT 2/3] Input: Add Novatek NT36xxx touchscreen driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241015-nt36xxx-v1-2-3919d0bffee6@gmail.com> References: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> In-Reply-To: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Del Regno , Henrik Rydberg Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, George Chan X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728996810; l=56382; i=gchan9527@gmail.com; s=20241015; h=from:subject:message-id; bh=+FF0n/qJDw0gKzT+err6CRYavmZ50RC/wgLfEpEOMNM=; b=Qw//vVYw5958Wo8w1lOSSDIHlJlFKlkF3BPsSWGittYO+OYWlyAA6IntRZiwue/QdkR1ykJ/K AbB1aTngdM6DyQ5irqYMr38ct5R04i3TY9f7ycP8cuec+CC+ufNL8bA X-Developer-Key: i=gchan9527@gmail.com; a=ed25519; pk=dscYWhT+BiQOBMpPE19NFQAjBBmcpipc6zdf2MTze/U= X-Endpoint-Received: by B4 Relay for gchan9527@gmail.com/20241015 with auth_id=248 X-Original-From: George Chan Reply-To: gchan9527@gmail.com From: George Chan This is a driver for the Novatek in-cell touch controller and supports various chips from the NT36xxx family, currently including below as listed: - NT36525 - NT36672A - NT36675 - NT36676F - NT36772 - NT36870 Functionality like wake gestures and firmware flashing is not included. Firmware loading at probe is supported. This driver is lightly based on the downstream implementation [1]. [1] https://github.com/Rasenkai/caf-tsoft-Novatek-nt36xxx And rewrite as standard i2c driver [2][3] [2] https://lore.kernel.org/all/20201026173045.165236-4-kholk11@gmail.com/T/ [3] https://lore.kernel.org/lkml/20230808-topic-nt36xxx-v10-1-dd135dfa0b5e@= linaro.org/T/ Then a new rewrite further happened for spi driver [4] [4] https://github.com/99degree/linux/tree/nt36xxx This driver referenced to goodix berlin driver spi ops that had been in mainline kernel. Also, implementation included panel-follower ops, pm_runtime ops as well as firmware download ops that is added as spi driver. Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: George Chan --- drivers/input/touchscreen/Kconfig | 13 + drivers/input/touchscreen/Makefile | 2 + drivers/input/touchscreen/nt36xxx.h | 142 +++ drivers/input/touchscreen/nt36xxx_core.c | 1422 ++++++++++++++++++++++++++= ++++ drivers/input/touchscreen/nt36xxx_spi.c | 256 ++++++ 5 files changed, 1835 insertions(+) diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/= Kconfig index 1ac26fc2e3..654877da4c 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -663,6 +663,19 @@ config TOUCHSCREEN_IMAGIS To compile this driver as a module, choose M here: the module will be called imagis. =20 +config TOUCHSCREEN_NT36XXX_SPI + tristate "Novatek NT36XXX In-Cell SPI touchscreen controller" + depends on SPI_MASTER + select REGMAP + help + Say Y here if you have a Novatek NT36xxx series In-Cell + touchscreen connected to your system over SPI. + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called nt36xxx_ts_spi. + config TOUCHSCREEN_IMX6UL_TSC tristate "Freescale i.MX6UL touchscreen controller" depends on ((OF && GPIOLIB) || COMPILE_TEST) && HAS_IOMEM diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen= /Makefile index 82bc837ca0..6358a636a5 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -7,6 +7,7 @@ =20 wm97xx-ts-y :=3D wm97xx-core.o goodix_ts-y :=3D goodix.o goodix_fwupload.o +nt36xxx_spi_ts-y :=3D nt36xxx_spi.o nt36xxx_core.o =20 obj-$(CONFIG_TOUCHSCREEN_88PM860X) +=3D 88pm860x-ts.o obj-$(CONFIG_TOUCHSCREEN_AD7877) +=3D ad7877.o @@ -67,6 +68,7 @@ obj-$(CONFIG_TOUCHSCREEN_MSG2638) +=3D msg2638.o obj-$(CONFIG_TOUCHSCREEN_MTOUCH) +=3D mtouch.o obj-$(CONFIG_TOUCHSCREEN_MK712) +=3D mk712.o obj-$(CONFIG_TOUCHSCREEN_NOVATEK_NVT_TS) +=3D novatek-nvt-ts.o +obj-$(CONFIG_TOUCHSCREEN_NT36XXX_SPI) +=3D nt36xxx_spi_ts.o obj-$(CONFIG_TOUCHSCREEN_HP600) +=3D hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_HP7XX) +=3D jornada720_ts.o obj-$(CONFIG_TOUCHSCREEN_IPAQ_MICRO) +=3D ipaq-micro-ts.o diff --git a/drivers/input/touchscreen/nt36xxx.h b/drivers/input/touchscree= n/nt36xxx.h new file mode 100644 index 0000000000..7bf1f72290 --- /dev/null +++ b/drivers/input/touchscreen/nt36xxx.h @@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2010 - 2017 Novatek, Inc. + * Copyright (C) 2020 AngeloGioacchino Del Regno + * Copyright (C) 2023-2024 George Chan + */ + +#ifndef NT36XXX_H +#define NT36XXX_H + +#define NT36XXX_INPUT_DEVICE_NAME "Novatek NT36XXX Touch Sensor" +#define MAX_SPI_FREQ_HZ 5000000 + +/* FW Param address */ +#define NT36XXX_FW_ADDR 0x01 + +#define NT36XXX_TRANSFER_LEN (63*1024) + +/* due to extra framework layer, the transfer trunk is as small as + * 128 otherwize dma error happened, all routed to spi_sync() +*/ + +/* Number of bytes for chip identification */ +#define NT36XXX_ID_LEN_MAX 6 + +/* Touch info */ +#define TOUCH_DEFAULT_MAX_WIDTH 1080 +#define TOUCH_DEFAULT_MAX_HEIGHT 2246 +#define TOUCH_MAX_FINGER_NUM 10 +#define TOUCH_MAX_PRESSURE 1000 + +/* Point data length */ +#define POINT_DATA_LEN 65 + +/* Misc */ +#define NT36XXX_NUM_SUPPLIES 4 +#define NT36XXX_MAX_RETRIES 5 +#define NT36XXX_MAX_FW_RST_RETRY 50 + +enum nt36xxx_chips { + NT36525_IC =3D 0x1, + NT36672A_IC, + NT36676F_IC, + NT36772_IC, + NT36675_IC, + NT36870_IC, + NTMAX_IC, +}; + +enum nt36xxx_cmds { + NT36XXX_CMD_ENTER_SLEEP =3D 0x11, + NT36XXX_CMD_BOOTLOADER_RESET =3D 0x69, +}; + +enum nt36xxx_events { + NT36XXX_EVT_REPORT =3D 0x00, + NT36XXX_EVT_CRC =3D 0x35, + NT36XXX_EVT_HOST_CMD =3D 0x50, + NT36XXX_EVT_HS_OR_SUBCMD =3D 0x51, /* Handshake or subcomma= nd byte */ + NT36XXX_EVT_RESET_COMPLETE =3D 0x60, + NT36XXX_EVT_FWINFO =3D 0x78, + NT36XXX_EVT_READ_PID =3D 0x80, + NT36XXX_EVT_PROJECTID =3D 0x9a, /* Excess 0x80 write bit= , messed trouble, ignored */ +}; + +enum nt36xxx_fw_state { + NT36XXX_STATE_INIT =3D 0xa0, /* IC Reset */ + NT36XXX_STATE_REK =3D 0xa1, /* ReK baseline */ + NT36XXX_STATE_REK_FINISH =3D 0xa2, /* Baseline is ready */ + NT36XXX_STATE_NORMAL_RUN =3D 0xa3, /* Firmware is running */ + NT36XXX_STATE_MAX =3D 0xaf +}; + +struct nt36xxx_ts; + +struct nvt_fw_parse_data { + uint8_t partition; + uint8_t ilm_dlm_num; +}; + +struct nvt_ts_bin_map { + char name[12]; + uint32_t bin_addr; + uint32_t sram_addr; + uint32_t size; + uint32_t crc; + uint32_t loaded; +}; + +struct nvt_ts_hw_info { + uint8_t carrier_system; + uint8_t hw_crc; +}; + +struct nt36xxx_abs_object { + u16 x; + u16 y; + u16 z; + u8 tm; +}; + +struct nt36xxx_fw_info { + u8 fw_ver; + u8 x_num; + u8 y_num; + u8 max_buttons; + u16 abs_x_max; + u16 abs_y_max; + u16 nvt_pid; +}; + +struct nt36xxx_chip_data { + const u32 *mmap; + const struct regmap_config *config; + + const char* fw_name; + unsigned int max_x; + unsigned int max_y; + unsigned int abs_x_max; + unsigned int abs_y_max; + unsigned int max_button; + const struct input_id *id; +}; + +struct nt36xxx_trim_table { + u8 id[NT36XXX_ID_LEN_MAX]; + u8 mask[NT36XXX_ID_LEN_MAX]; + enum nt36xxx_chips mapid; + uint8_t carrier_system; + uint8_t hw_crc; +}; + +int nt36xxx_probe(struct device *dev, int irq, const struct input_id *id, + struct regmap *regmap); + +extern const struct dev_pm_ops nt36xxx_pm_ops; +extern const u32 nt36675_memory_maps[]; +extern const u32 nt36672a_memory_maps[]; +extern const u32 nt36772_memory_maps[]; +extern const u32 nt36676f_memory_maps[]; +extern const u32 nt36525_memory_maps[]; +#endif diff --git a/drivers/input/touchscreen/nt36xxx_core.c b/drivers/input/touch= screen/nt36xxx_core.c new file mode 100644 index 0000000000..a27abe566b --- /dev/null +++ b/drivers/input/touchscreen/nt36xxx_core.c @@ -0,0 +1,1422 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Driver for Novatek NT36xxx series touchscreens + * + * Copyright (C) 2010 - 2018 Novatek, Inc. + * Copyright (C) 2020 XiaoMi, Inc. + * Copyright (C) 2020 AngeloGioacchino Del Regno + * Copyright (C) 2023-2024 George Chan + * + * Based on nt36xxx.c i2c driver from AngeloGioacchino Del Regno + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nt36xxx.h" + +/* Main mmap to spi addr */ +enum { + MMAP_BASELINE_ADDR, + MMAP_BASELINE_BTN_ADDR, + MMAP_BLD_CRC_EN_ADDR, + MMAP_BLD_DES_ADDR, + MMAP_BLD_ILM_DLM_CRC_ADDR, + MMAP_BLD_LENGTH_ADDR, + MMAP_BOOT_RDY_ADDR, + MMAP_DIFF_BTN_PIPE0_ADDR, + MMAP_DIFF_BTN_PIPE1_ADDR, + MMAP_DIFF_PIPE0_ADDR, + MMAP_DIFF_PIPE1_ADDR, + MMAP_DLM_DES_ADDR, + MMAP_DLM_LENGTH_ADDR, + MMAP_DMA_CRC_EN_ADDR, + MMAP_DMA_CRC_FLAG_ADDR, + MMAP_ENG_RST_ADDR, + MMAP_EVENT_BUF_ADDR, + MMAP_G_DLM_CHECKSUM_ADDR, + MMAP_G_ILM_CHECKSUM_ADDR, + MMAP_ILM_DES_ADDR, + MMAP_ILM_LENGTH_ADDR, + MMAP_POR_CD_ADDR, + MMAP_RAW_BTN_PIPE0_ADDR, + MMAP_RAW_BTN_PIPE1_ADDR, + MMAP_RAW_PIPE0_ADDR, + MMAP_RAW_PIPE1_ADDR, + MMAP_READ_FLASH_CHECKSUM_ADDR, + MMAP_RW_FLASH_DATA_ADDR, + MMAP_R_DLM_CHECKSUM_ADDR, + MMAP_R_ILM_CHECKSUM_ADDR, + MMAP_SPI_RD_FAST_ADDR, + MMAP_SWRST_N8_ADDR, + + /* below are magic numbers in source code */ + MMAP_MAGIC_NUMBER_0X1F64E_ADDR, + + /* this addr is not specific to */ + MMAP_TOP_ADDR, + MMAP_MAX_ADDR =3D MMAP_TOP_ADDR, +} nt36xxx_ts_mem_map; + +static struct drm_panel_follower_funcs nt36xxx_panel_follower_funcs; + +struct nt36xxx_ts { + struct regmap *regmap; + + struct input_dev *input; + struct regulator_bulk_data *supplies; + struct gpio_desc *reset_gpio; + struct gpio_desc *irq_gpio; + int irq; + struct device *dev; + + struct mutex lock; + +#define NT36XXX_STATUS_SUSPEND BIT(0) +#define NT36XXX_STATUS_DOWNLOAD_COMPLETE BIT(1) +#define NT36XXX_STATUS_DOWNLOAD_RECOVER BIT(2) +#define NT36XXX_STATUS_PREPARE_FIRMWARE BIT(3) +#define NT36XXX_STATUS_NEED_FIRMWARE BIT(4) + + unsigned int status; + + struct touchscreen_properties prop; + struct nt36xxx_fw_info fw_info; + struct nt36xxx_abs_object abs_obj; + + struct drm_panel_follower panel_follower; + + struct delayed_work work; + + /* this is a duplicate with nt36xxx_chip_data and since the address might + * change in boot/init/download stages so make it a copy of initial map a= nd + * update accordingly + */ + u32 *mmap; + u32 mmap_data[MMAP_MAX_ADDR]; + + struct nvt_fw_parse_data fw_data; + struct nvt_ts_bin_map *bin_map; + + uint8_t hw_crc; + + const char * fw_name; + struct firmware fw_entry; /* containing request fw data */ + const struct nt36xxx_chip_data *data; +}; + +static const struct nt36xxx_trim_table trim_id_table[] =3D { + /* TODO: port and test all related module */ + { + .id =3D { 0x0A, 0xFF, 0xFF, 0x72, 0x66, 0x03 }, + .mask =3D { 1, 0, 0, 1, 1, 1 }, + .mapid =3D NT36672A_IC, + }, + { + .id =3D { 0x55, 0x00, 0xFF, 0x00, 0x00, 0x00 }, + .mask =3D { 1, 1, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0x55, 0x72, 0xFF, 0x00, 0x00, 0x00 }, + .mask =3D { 1, 1, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xAA, 0x00, 0xFF, 0x00, 0x00, 0x00 }, + .mask =3D { 1, 1, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xAA, 0x72, 0xFF, 0x00, 0x00, 0x00 }, + .mask =3D { 1, 1, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x72, 0x67, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x70, 0x66, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x70, 0x67, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x72, 0x66, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x25, 0x65, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x70, 0x68, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36772_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x76, 0x66, 0x03 }, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36676F_IC, + }, + { + .id =3D { 0xFF, 0xFF, 0xFF, 0x75, 0x66, 0x03}, + .mask =3D { 0, 0, 0, 1, 1, 1 }, + .mapid =3D NT36675_IC, + .hw_crc =3D 2, + }, + { }, +}; + +const u32 nt36675_memory_maps[] =3D { + [MMAP_EVENT_BUF_ADDR] =3D 0x22D00, + [MMAP_RAW_PIPE0_ADDR] =3D 0x24000, + [MMAP_RAW_PIPE1_ADDR] =3D 0x24000, + [MMAP_BASELINE_ADDR] =3D 0x21B90, + [MMAP_DIFF_PIPE0_ADDR] =3D 0x20C60, + [MMAP_DIFF_PIPE1_ADDR] =3D 0x24C60, + [MMAP_READ_FLASH_CHECKSUM_ADDR] =3D 0x24000, + [MMAP_RW_FLASH_DATA_ADDR] =3D 0x24002, + [MMAP_BOOT_RDY_ADDR] =3D 0x3F10D, + [MMAP_BLD_LENGTH_ADDR] =3D 0x3F138, + [MMAP_ILM_LENGTH_ADDR] =3D 0x3F118, + [MMAP_DLM_LENGTH_ADDR] =3D 0x3F130, + [MMAP_BLD_DES_ADDR] =3D 0x3F114, + [MMAP_ILM_DES_ADDR] =3D 0x3F128, + [MMAP_DLM_DES_ADDR] =3D 0x3F12C, + [MMAP_G_ILM_CHECKSUM_ADDR] =3D 0x3F100, + [MMAP_G_DLM_CHECKSUM_ADDR] =3D 0x3F104, + [MMAP_R_ILM_CHECKSUM_ADDR] =3D 0x3F120, + [MMAP_R_DLM_CHECKSUM_ADDR] =3D 0x3F124, + [MMAP_BLD_CRC_EN_ADDR] =3D 0x3F30E, + [MMAP_DMA_CRC_EN_ADDR] =3D 0x3F136, + [MMAP_BLD_ILM_DLM_CRC_ADDR] =3D 0x3F133, + [MMAP_DMA_CRC_FLAG_ADDR] =3D 0x3F134, + + /* below are specified by dts, so it might change by project-based */ + [MMAP_SPI_RD_FAST_ADDR] =3D 0x03F310, + [MMAP_SWRST_N8_ADDR] =3D 0x03F0FE, + + [MMAP_ENG_RST_ADDR] =3D 0x7FFF80, + [MMAP_MAGIC_NUMBER_0X1F64E_ADDR] =3D 0x1F64E, + + [MMAP_TOP_ADDR] =3D 0xffffff, +}; + +const u32 nt36672a_memory_maps[] =3D { + [MMAP_EVENT_BUF_ADDR] =3D 0x21C00, + [MMAP_RAW_PIPE0_ADDR] =3D 0x20000, + [MMAP_RAW_PIPE1_ADDR] =3D 0x23000, + [MMAP_BASELINE_ADDR] =3D 0x20BFC, + [MMAP_BASELINE_BTN_ADDR] =3D 0x23BFC, + [MMAP_DIFF_PIPE0_ADDR] =3D 0x206DC, + [MMAP_DIFF_PIPE1_ADDR] =3D 0x236DC, + [MMAP_RAW_BTN_PIPE0_ADDR] =3D 0x20510, + [MMAP_RAW_BTN_PIPE1_ADDR] =3D 0x23510, + [MMAP_DIFF_BTN_PIPE0_ADDR] =3D 0x20BF0, + [MMAP_DIFF_BTN_PIPE1_ADDR] =3D 0x23BF0, + [MMAP_READ_FLASH_CHECKSUM_ADDR] =3D 0x24000, + [MMAP_RW_FLASH_DATA_ADDR] =3D 0x24002, + /* Phase 2 Host Download */ + [MMAP_BOOT_RDY_ADDR] =3D 0x3F10D, + /* BLD CRC */ + [MMAP_BLD_LENGTH_ADDR] =3D 0x3F10E, //0x3F10E ~ 0x3F10F (2 bytes) + [MMAP_ILM_LENGTH_ADDR] =3D 0x3F118, //0x3F118 ~ 0x3F119 (2 bytes) + [MMAP_DLM_LENGTH_ADDR] =3D 0x3F130, //0x3F130 ~ 0x3F131 (2 bytes) + [MMAP_BLD_DES_ADDR] =3D 0x3F114, //0x3F114 ~ 0x3F116 (3 bytes) + [MMAP_ILM_DES_ADDR] =3D 0x3F128, //0x3F128 ~ 0x3F12A (3 bytes) + [MMAP_DLM_DES_ADDR] =3D 0x3F12C, //0x3F12C ~ 0x3F12E (3 bytes) + [MMAP_G_ILM_CHECKSUM_ADDR] =3D 0x3F100, //0x3F100 ~ 0x3F103 (4 byt= es) + [MMAP_G_DLM_CHECKSUM_ADDR] =3D 0x3F104, //0x3F104 ~ 0x3F107 (4 byt= es) + [MMAP_R_ILM_CHECKSUM_ADDR] =3D 0x3F120, //0x3F120 ~ 0x3F123 (4 bytes) + [MMAP_R_DLM_CHECKSUM_ADDR] =3D 0x3F124, //0x3F124 ~ 0x3F127 (4 bytes) + [MMAP_BLD_CRC_EN_ADDR] =3D 0x3F30E, + [MMAP_DMA_CRC_EN_ADDR] =3D 0x3F132, + [MMAP_BLD_ILM_DLM_CRC_ADDR] =3D 0x3F133, + [MMAP_DMA_CRC_FLAG_ADDR] =3D 0x3F134, + + /* below are specified by dts, so it might change by project-based */ + [MMAP_SPI_RD_FAST_ADDR] =3D 0x03F310, + [MMAP_SWRST_N8_ADDR] =3D 0x03F0FE, + + [MMAP_ENG_RST_ADDR] =3D 0x7FFF80, + [MMAP_MAGIC_NUMBER_0X1F64E_ADDR] =3D 0x1F64E, + + [MMAP_TOP_ADDR] =3D 0xffffff, +}; + +const u32 nt36676f_memory_maps[] =3D { + [MMAP_EVENT_BUF_ADDR] =3D 0x11A00, + [MMAP_RAW_PIPE0_ADDR] =3D 0x10000, + [MMAP_RAW_PIPE1_ADDR] =3D 0x12000, + [MMAP_BASELINE_ADDR] =3D 0x10B08, + [MMAP_BASELINE_BTN_ADDR] =3D 0x12B08, + [MMAP_DIFF_PIPE0_ADDR] =3D 0x1064C, + [MMAP_DIFF_PIPE1_ADDR] =3D 0x1264C, + [MMAP_RAW_BTN_PIPE0_ADDR] =3D 0x10634, + [MMAP_RAW_BTN_PIPE1_ADDR] =3D 0x12634, + [MMAP_DIFF_BTN_PIPE0_ADDR] =3D 0x10AFC, + [MMAP_DIFF_BTN_PIPE1_ADDR] =3D 0x12AFC, + [MMAP_READ_FLASH_CHECKSUM_ADDR] =3D 0x14000, + [MMAP_RW_FLASH_DATA_ADDR] =3D 0x14002, + + /* below are specified by dts, so it might change by project-based */ + [MMAP_SPI_RD_FAST_ADDR] =3D 0x03F310, + [MMAP_SWRST_N8_ADDR] =3D 0x03F0FE, + + [MMAP_ENG_RST_ADDR] =3D 0x7FFF80, + [MMAP_MAGIC_NUMBER_0X1F64E_ADDR] =3D 0x1F64E, + + [MMAP_TOP_ADDR] =3D 0xffffff, +}; + +const u32 nt36772_memory_maps[] =3D { + [MMAP_EVENT_BUF_ADDR] =3D 0x11E00, + [MMAP_RAW_PIPE0_ADDR] =3D 0x10000, + [MMAP_RAW_PIPE1_ADDR] =3D 0x12000, + [MMAP_BASELINE_ADDR] =3D 0x10E70, + [MMAP_BASELINE_BTN_ADDR] =3D 0x12E70, + [MMAP_DIFF_PIPE0_ADDR] =3D 0x10830, + [MMAP_DIFF_PIPE1_ADDR] =3D 0x12830, + [MMAP_RAW_BTN_PIPE0_ADDR] =3D 0x10E60, + [MMAP_RAW_BTN_PIPE1_ADDR] =3D 0x12E60, + [MMAP_DIFF_BTN_PIPE0_ADDR] =3D 0x10E68, + [MMAP_DIFF_BTN_PIPE1_ADDR] =3D 0x12E68, + [MMAP_READ_FLASH_CHECKSUM_ADDR] =3D 0x14000, + [MMAP_RW_FLASH_DATA_ADDR] =3D 0x14002, + /* Phase 2 Host Download */ + [MMAP_BOOT_RDY_ADDR] =3D 0x1F141, + [MMAP_POR_CD_ADDR] =3D 0x1F61C, + /* BLD CRC */ + [MMAP_R_ILM_CHECKSUM_ADDR] =3D 0x1BF00, + + /* below are specified by dts, so it might change by project-based */ + [MMAP_SPI_RD_FAST_ADDR] =3D 0x03F310, + [MMAP_SWRST_N8_ADDR] =3D 0x03F0FE, + + [MMAP_ENG_RST_ADDR] =3D 0x7FFF80, + [MMAP_MAGIC_NUMBER_0X1F64E_ADDR] =3D 0x1F64E, + + [MMAP_TOP_ADDR] =3D 0xffffff, +}; + +const u32 nt36525_memory_maps[] =3D { + [MMAP_EVENT_BUF_ADDR] =3D 0x11A00, + [MMAP_RAW_PIPE0_ADDR] =3D 0x10000, + [MMAP_RAW_PIPE1_ADDR] =3D 0x12000, + [MMAP_BASELINE_ADDR] =3D 0x10B08, + [MMAP_BASELINE_BTN_ADDR] =3D 0x12B08, + [MMAP_DIFF_PIPE0_ADDR] =3D 0x1064C, + [MMAP_DIFF_PIPE1_ADDR] =3D 0x1264C, + [MMAP_RAW_BTN_PIPE0_ADDR] =3D 0x10634, + [MMAP_RAW_BTN_PIPE1_ADDR] =3D 0x12634, + [MMAP_DIFF_BTN_PIPE0_ADDR] =3D 0x10AFC, + [MMAP_DIFF_BTN_PIPE1_ADDR] =3D 0x12AFC, + [MMAP_READ_FLASH_CHECKSUM_ADDR] =3D 0x14000, + [MMAP_RW_FLASH_DATA_ADDR] =3D 0x14002, + + /* Phase 2 Host Download */ + [MMAP_BOOT_RDY_ADDR] =3D 0x1F141, + [MMAP_POR_CD_ADDR] =3D 0x1F61C, + /* BLD CRC */ + [MMAP_R_ILM_CHECKSUM_ADDR] =3D 0x1BF00, + + /* below are specified by dts, so it might change by project-based */ + [MMAP_SPI_RD_FAST_ADDR] =3D 0x03F310, + [MMAP_SWRST_N8_ADDR] =3D 0x03F0FE, + + [MMAP_ENG_RST_ADDR] =3D 0x7FFF80, + [MMAP_MAGIC_NUMBER_0X1F64E_ADDR] =3D 0x1F64E, + + [MMAP_TOP_ADDR] =3D 0xffffff, +}; + +void __maybe_unused _debug_irq(struct nt36xxx_ts *ts, int line) { + struct irq_desc *desc; + desc =3D irq_data_to_desc( irq_get_irq_data(ts->irq)); + dev_info(ts->dev, "%d irq_desc depth=3D%d", line, desc->depth ); +} + +#define debug_irq(a) _debug_irq(a, __LINE__) + +static int nt36xxx_eng_reset_idle(struct nt36xxx_ts *ts) +{ + int ret; + + if(!ts) { + dev_err(ts->dev, "%s %s empty", __func__, "nt36xxx_ts"); + return -EINVAL; + } + + if(!ts->mmap) { + dev_err(ts->dev, "%s %s empty", __func__, "ts->mmap"); + return -EINVAL; + } + + if(ts->mmap[MMAP_ENG_RST_ADDR] =3D=3D 0) { + dev_err(ts->dev, "%s %s empty", __func__, "MMAP_ENG_RST_ADDR"); + return -EINVAL; + } + + /* HACK to output something without read */ + ret =3D regmap_write(ts->regmap, ts->mmap[MMAP_ENG_RST_ADDR], + 0x5a); + if (ret) { + dev_err(ts->dev, "%s regmap write error\n", __func__); + return ret; + } + + /* Wait until the MCU resets the fw state */ + usleep_range(15000, 16000); + + /* seemed not long enough */ + msleep(30); + return ret; +} + +/* + * nt36xxx_bootloader_reset - Reset MCU to bootloader + * @ts: Main driver structure + * + * Return: Always zero for success, negative number for error + */ +static int nt36xxx_bootloader_reset(struct nt36xxx_ts *ts) +{ + int ret =3D 0; + + //in spi version, need to set page to SWRST_N8_ADDR + if (ts->mmap[MMAP_SWRST_N8_ADDR]) { + ret =3D regmap_write(ts->regmap, ts->mmap[MMAP_SWRST_N8_ADDR], + NT36XXX_CMD_BOOTLOADER_RESET); + if (ret) + return ret; + } else { + pr_info("plz make sure MMAP_SWRST_N8_ADDR is set!\n"); + return -EINVAL; + } + + /* MCU has to reboot from bootloader: this is the typical boot time */ + msleep(35); + + if (ts->mmap[MMAP_SPI_RD_FAST_ADDR]) { + ret =3D regmap_write(ts->regmap, ts->mmap[MMAP_SPI_RD_FAST= _ADDR], 0); + if (ret) + return ret; + } + + return ret; +} + +/** + * nt36xxx_check_reset_state - Check the boot state during reset + * @ts: Main driver structure + * @fw_state: Enumeration containing firmware states + * + * Return: Always zero for success, negative number for error + */ +static int nt36xxx_check_reset_state(struct nt36xxx_ts *ts, + enum nt36xxx_fw_state fw_state) +{ + u8 buf[8] =3D { 0 }; + int ret =3D 0, retry =3D NT36XXX_MAX_FW_RST_RETRY; + + do { + ret =3D regmap_raw_read(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR] + | NT36XXX_EVT_RESET_COMPLETE, buf, 6); + if (likely(ret =3D=3D 0) && + (buf[1] >=3D fw_state) && + (buf[1] <=3D NT36XXX_STATE_MAX)) { + ret =3D 0; + break; + } + usleep_range(10000, 11000); + } while (--retry); + + if (!retry) { + dev_err(ts->dev, "Firmware reset failed.\n"); + ret =3D -EBUSY; + } + + return ret; +} + +/** + * nt36xxx_report - Report touch events + * @ts: Main driver structure + * + * Return: Always zero for success, negative number for error + */ +static void nt36xxx_report(struct nt36xxx_ts *ts) +{ + struct nt36xxx_abs_object *obj =3D &ts->abs_obj; + struct input_dev *input =3D ts->input; + u8 input_id =3D 0; + u8 point[POINT_DATA_LEN + 1] =3D { 0 }; + unsigned int ppos =3D 0; + int i, ret, finger_cnt =3D 0; + uint8_t press_id[TOUCH_MAX_FINGER_NUM] =3D {0}; + + ret =3D regmap_raw_read(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR], + point, sizeof(point)); + if (ret < 0) { + dev_err(ts->dev, + "Cannot read touch point data: %d\n", ret); + goto xfer_error; + } + + /* wdt recovery and esd check */ + for (i =3D 0; i < 7; i++) { + if ((point[i] !=3D 0xFD) && (point[i] !=3D 0xFE) && (point[i] !=3D 0x77)= ) { + break; + } + + mutex_lock(&ts->lock); + ts->status |=3D NT36XXX_STATUS_DOWNLOAD_RECOVER; + mutex_unlock(&ts->lock); + goto xfer_error; + } + + for (i =3D 0; i < TOUCH_MAX_FINGER_NUM; i++) { + ppos =3D 6 * i + 1; + input_id =3D point[ppos + 0] >> 3; + + if ((input_id =3D=3D 0) || (input_id > TOUCH_MAX_FINGER_NUM)) { + continue; + } + + if (((point[ppos] & 0x07) =3D=3D 0x01) || + ((point[ppos] & 0x07) =3D=3D 0x02)) { + obj->x =3D (point[ppos + 1] << 4) + + (point[ppos + 3] >> 4); + obj->y =3D (point[ppos + 2] << 4) + + (point[ppos + 3] & 0xf); + + if ((obj->x > ts->prop.max_x) || + (obj->y > ts->prop.max_y)) + continue; + + obj->tm =3D point[ppos + 4]; + if (obj->tm =3D=3D 0) + obj->tm =3D 1; + + obj->z =3D point[ppos + 5]; + if (i < 2) { + obj->z +=3D point[i + 63] << 8; + if (obj->z > TOUCH_MAX_PRESSURE) + obj->z =3D TOUCH_MAX_PRESSURE; + } + + if (obj->z =3D=3D 0) + obj->z =3D 1; + + press_id[input_id - 1] =3D 1; + + input_mt_slot(input, input_id - 1); + input_mt_report_slot_state(input, + MT_TOOL_FINGER, true); + touchscreen_report_pos(input, &ts->prop, + obj->x, + obj->y, true); + + input_report_abs(input, ABS_MT_TOUCH_MAJOR, obj->tm); + input_report_abs(input, ABS_MT_PRESSURE, obj->z); + + finger_cnt++; + } + } + + input_mt_sync_frame(input); + + input_sync(input); + +xfer_error: + return; +} + +static irqreturn_t nt36xxx_irq_handler(int irq, void *dev_id) +{ + struct nt36xxx_ts *ts =3D dev_id; + + if (!ts->mmap) + goto exit; + + disable_irq_nosync(ts->irq); + + nt36xxx_report(ts); + + enable_irq(ts->irq); + +exit: + if (ts->status & NT36XXX_STATUS_DOWNLOAD_RECOVER) { + mutex_lock(&ts->lock); + ts->status &=3D ~NT36XXX_STATUS_DOWNLOAD_RECOVER; + mutex_unlock(&ts->lock); + /* TODO: other builtin eeprom model might have another reset + * approach other than download, might add here afterward */ + if (ts->fw_name) + schedule_delayed_work(&ts->work, 40000); + } + + return IRQ_HANDLED; +} + + +/** + * nt36xxx_chip_version_init - Detect Novatek NT36xxx family IC + * @ts: Main driver structure + * + * This function reads the ChipID from the IC and sets the right + * memory map for the detected chip. + * + * Return: Always zero for success, negative number for error + */ +static int nt36xxx_chip_version_init(struct nt36xxx_ts *ts) +{ + u8 buf[32] =3D { 0 }; + int retry =3D NT36XXX_MAX_RETRIES; + int sz =3D sizeof(trim_id_table) / sizeof(struct nt36xxx_trim_table); + int i, list, mapid, ret; + + ret =3D nt36xxx_bootloader_reset(ts); + if (ret) { + dev_err(ts->dev, "Can't reset the nvt IC\n"); + return ret; + } + + do { + ret =3D regmap_raw_read(ts->regmap, ts->mmap[MMAP_MAGIC_NUMBER_0X1F64E_A= DDR], buf, 7); + + if (ret) + continue; + + dev_dbg(ts->dev, "%s buf[0]=3D0x%02X, buf[1]=3D0x%02X, buf[2]=3D0x%02X, = buf[3]=3D0x%02X, buf[4]=3D0x%02X, buf[5]=3D0x%02X, buf[6]=3D0x%02X sz=3D%d\= n", + __func__, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], sz); + + /* Compare read chip id with trim list */ + for (list =3D 0; list < sz; list++) { + + /* Compare each not masked byte */ + for (i =3D 0; i < NT36XXX_ID_LEN_MAX; i++) { + if (trim_id_table[list].mask[i] && + buf[i + 1] !=3D trim_id_table[list].id[i]) + break; + } + + /* found and match with mask */ + if (i =3D=3D NT36XXX_ID_LEN_MAX) { + mapid =3D trim_id_table[list].mapid; + ret =3D 0; + ts->hw_crc =3D trim_id_table[list].hw_crc; + + if (mapid =3D=3D 0) { + dev_info(ts->dev, "NVT touch IC hw not found i=3D%d list=3D%d\n", i, = list); + ret =3D -ENOENT; + goto exit; + } + + WARN_ON(ts->hw_crc < 1); + + dev_dbg(ts->dev, "hw crc support=3D%d\n", ts->hw_crc); + + dev_info(ts->dev, "This is NVT touch IC, %06x, mapid %d", *(int*)&buf[= 4], mapid); + return 0; + } + + ret =3D -ENOENT; + } + + usleep_range(10000, 11000); + } while (--retry); + +exit: + return ret; +} + +/* + * this function is nearly direct copy from vendor source +*/ +static int32_t nvt_bin_header_parser(struct device *dev, int hw_crc, const= u8 *fwdata, size_t fwsize, struct nvt_ts_bin_map **bin_map_ptr, uint8_t *p= artition_ptr, uint8_t ilm_dlm_num) +{ + uint8_t list =3D 0; + uint32_t pos =3D 0x00; + uint32_t end =3D 0x00; + uint8_t info_sec_num =3D 0; + uint8_t ovly_sec_num =3D 0; + uint8_t ovly_info =3D 0; + uint8_t partition; + struct nvt_ts_bin_map *bin_map; + + /* Find the header size */ + end =3D fwdata[0] + (fwdata[1] << 8) + (fwdata[2] << 16) + (fwdata[3] << = 24); + pos =3D 0x30; /* info section start at 0x30 offset */ + while (pos < end) { + info_sec_num ++; + pos +=3D 0x10; /* each header info is 16 bytes */ + } + + /* + * Find the DLM OVLY section + * [0:3] Overlay Section Number + * [4] Overlay Info + */ + ovly_info =3D (fwdata[0x28] & 0x10) >> 4; + ovly_sec_num =3D (ovly_info) ? (fwdata[0x28] & 0x0F) : 0; + + /* + * calculate all partition number + * ilm_dlm_num (ILM & DLM) + ovly_sec_num + info_sec_num + */ + *partition_ptr =3D partition =3D ilm_dlm_num + ovly_sec_num + info_sec_nu= m; + dev_dbg(dev, "ovly_info =3D %d, ilm_dlm_num =3D %d, ovly_sec_num =3D %d, = info_sec_num =3D %d, partition =3D %d\n", + ovly_info, ilm_dlm_num, ovly_sec_num, info_sec_num, partition); + + /* allocated memory for header info */ + *bin_map_ptr =3D bin_map =3D (struct nvt_ts_bin_map *)kzalloc((partition = + 1) * sizeof(struct nvt_ts_bin_map), GFP_KERNEL); + if(bin_map =3D=3D NULL) { + dev_err(dev, "kzalloc for bin_map failed!\n"); + return -ENOMEM; + } + + for (list =3D 0; list < partition; list++) { + /* + * [1] parsing ILM & DLM header info + * bin_addr : sram_addr : size (12-bytes) + * crc located at 0x18 & 0x1C + */ + if (list < ilm_dlm_num) { + memcpy(&bin_map[list].bin_addr, &(fwdata[0 + list*12]), 4); + memcpy(&bin_map[list].sram_addr, &(fwdata[4 + list*12]), 4); + memcpy(&bin_map[list].size, &(fwdata[8 + list*12]), 4); + memcpy(&bin_map[list].crc, &(fwdata[0x18 + list*4]), 4); + + if (!hw_crc) { + dev_err(dev, "%s %d sw-crc not support", __func__, __LINE__); + return -EINVAL; + } + + if (list =3D=3D 0) + sprintf(bin_map[list].name, "ILM"); + else if (list =3D=3D 1) + sprintf(bin_map[list].name, "DLM"); + } + + /* + * [2] parsing others header info + * sram_addr : size : bin_addr : crc (16-bytes) + */ + if ((list >=3D ilm_dlm_num) && (list < (ilm_dlm_num + info_sec_num))) { + + /* others partition located at 0x30 offset */ + pos =3D 0x30 + (0x10 * (list - ilm_dlm_num)); + + memcpy(&bin_map[list].sram_addr, &(fwdata[pos]), 4); + memcpy(&bin_map[list].size, &(fwdata[pos+4]), 4); + memcpy(&bin_map[list].bin_addr, &(fwdata[pos+8]), 4); + memcpy(&bin_map[list].crc, &(fwdata[pos+12]), 4); + + if (!hw_crc) { + dev_info(dev, "ok, hw_crc not presents!"); + return -EINVAL; + } + + /* detect header end to protect parser function */ + if ((bin_map[list].bin_addr =3D=3D 0) && (bin_map[list].size !=3D 0)) { + sprintf(bin_map[list].name, "Header"); + } else { + sprintf(bin_map[list].name, "Info-%d", (list - ilm_dlm_num)); + } + } + + /* + * [3] parsing overlay section header info + * sram_addr : size : bin_addr : crc (16-bytes) + */ + if (list >=3D (ilm_dlm_num + info_sec_num)) { + /* overlay info located at DLM (list =3D 1) start addr */ + pos =3D bin_map[1].bin_addr + (0x10 * (list- ilm_dlm_num - info_sec_num= )); + + memcpy(&bin_map[list].sram_addr, &(fwdata[pos]), 4); + memcpy(&bin_map[list].size, &(fwdata[pos+4]), 4); + memcpy(&bin_map[list].bin_addr, &(fwdata[pos+8]), 4); + memcpy(&bin_map[list].crc, &(fwdata[pos+12]), 4); + + if (!hw_crc) { + dev_err(dev, "%s %d sw_crc not support", _= _func__, __LINE__); + return -EINVAL; + } + + sprintf(bin_map[list].name, "Overlay-%d", (list- ilm_dlm_num - info_sec= _num)); + } + + /* BIN size error detect */ + if ((bin_map[list].bin_addr + bin_map[list].size) > fwsize) { + dev_err(dev, "access range (0x%08X to 0x%08X) is larger than bin size!\= n", + bin_map[list].bin_addr, bin_map[list].bin_addr + bin_map[list].size); + return -EINVAL; + } + + dev_dbg(dev, "[%d][%s] SRAM (0x%08X), SIZE (0x%08X), BIN (0x%08X), CRC (= 0x%08X)\n", + list, bin_map[list].name, + bin_map[list].sram_addr, bin_map[list].size,= bin_map[list].bin_addr, bin_map[list].crc); + } + + return 0; +} + +static int32_t nt36xxx_download_firmware_hw_crc(struct nt36xxx_ts *ts) { + uint32_t list =3D 0; + uint32_t bin_addr, sram_addr, size; + struct nvt_ts_bin_map *bin_map =3D ts->bin_map; + + nt36xxx_bootloader_reset(ts); + + for (list =3D 0; list < ts->fw_data.partition; list++) { + int j; + + /* initialize variable */ + sram_addr =3D bin_map[list].sram_addr; + size =3D bin_map[list].size; + bin_addr =3D bin_map[list].bin_addr; + + /* ignore reserved partition (Reserved Partition size is zero) */ + if (!size) { + dev_dbg(ts->dev, "found empty part %d. skipping ", list); + continue; + } else { + size =3D size + 1; + dev_dbg(ts->dev, "found useful part %d. size 0x%x ", list, size); + } + + bin_map[list].loaded =3D 1; + + if (size / NT36XXX_TRANSFER_LEN) + dev_dbg(ts->dev, "%s %d paged write [%s] 0x%x, window 0x%x, residue 0x%= x", + __func__, __LINE__, bin_map[list].name, size, + NT36XXX_TRANSFER_LEN, size % NT36XXX_TRANSFER_LEN); + + for (j =3D 0; j < size; j +=3D NT36XXX_TRANSFER_LEN) { + int window_size =3D ((size - j) / NT36XXX_TRANSFER_LEN) ? NT36XXX_TRANS= FER_LEN : + ((size - j) % NT36XXX_TRANSFER_LEN); + + regmap_bulk_write(ts->regmap, sram_addr + j, &ts->fw_entry.data[bin_add= r + j], + window_size); + } + + } + + return 0; +} + +static void nt36xxx_release_memory(void *data); +static int _nt36xxx_boot_prepare_firmware(struct nt36xxx_ts *ts) { + int i, ret; + size_t fw_need_write_size =3D 0; + const struct firmware *fw_entry; + void *data; + + WARN_ON(ts->hw_crc !=3D 2); + + /* add one more guard */ + if (ts->status & NT36XXX_STATUS_PREPARE_FIRMWARE) + return 0; + + /* supposed we need to load once and use many time */ + if (ts->fw_entry.data) + return 0; + + ret =3D request_firmware(&fw_entry, ts->fw_name, ts->dev); + if (ret) { + dev_err(ts->dev, "request fw fail name=3D%s\n", ts->fw_name); + return -ENOMEM; + } + + /* + * must allocate in DMA buffer otherwise fail spi tx DMA + * so we need to manage our own fw struct + * pm_resume need to re-upload fw for NT36675 IC + * + */ + ts->fw_entry.data =3D data =3D kmemdup(fw_entry->data, fw_entry->size, GF= P_KERNEL | GFP_DMA); + + release_firmware(fw_entry); + if (!ts->fw_entry.data) { + dev_err(ts->dev, "memdup fw_data fail\n"); + return -ENOMEM; + } + ts->fw_entry.size =3D fw_entry->size; + + WARN_ON(ts->fw_entry.data[0] !=3D fw_entry->data[0]); + + for (i =3D (ts->fw_entry.size / 4096); i > 0; i--) { + if (strncmp(&ts->fw_entry.data[i * 4096 - 3], "NVT", 3) =3D=3D 0) { + fw_need_write_size =3D i * 4096; + break; + } + + if (strncmp(&ts->fw_entry.data[i * 4096 - 3], "MOD", 3) =3D=3D 0) { + fw_need_write_size =3D i * 4096; + break; + } + } + + if (fw_need_write_size =3D=3D 0) { + dev_err(ts->dev, "fw parsing error\n"); + kfree (data); + if (ts->bin_map) { + kfree(ts->bin_map); + ts->bin_map =3D NULL; + } + return -EIO; + } + + if (*(ts->fw_entry.data + (fw_need_write_size - 4096)) + *(ts->fw_entry.d= ata + + ((fw_need_write_size - 4096) + 1)) !=3D 0xFF) { + dev_err(ts->dev, "bin file FW_VER + FW_VER_BAR should be 0xFF!"); + dev_err(ts->dev, "FW_VER=3D0x%02X, FW_VER_BAR=3D0x%02X\n", + *(ts->fw_entry.data+(fw_need_write_size - 4096)), + *(ts->fw_entry.data+(fw_need_write_size - 4096 + 1))); + + kfree (data); + if (ts->bin_map) { + kfree(ts->bin_map); + ts->bin_map =3D NULL; + } + return -EIO; + } + + ts->fw_data.ilm_dlm_num =3D 2; + + ret =3D nvt_bin_header_parser(ts->dev, ts->hw_crc, ts->fw_entry.data, ts-= >fw_entry.size, + &ts->bin_map, &ts->fw_data.partition, ts->fw_data.ilm_dlm_num); + if (ret) { + kfree (data); + if(ret !=3D -ENOMEM){ + if (ts->bin_map) { + kfree(ts->bin_map); + ts->bin_map =3D NULL; + } + } + + /* really dont let the tasklet re-enter since no needed for broken fw da= ta */ + ts->status |=3D NT36XXX_STATUS_DOWNLOAD_COMPLETE; + dev_err(ts->dev, "Parsing fw error, stop re-loading fw now on, ret=3D0x%= x!", ret); + return ret; + } + + ts->status |=3D NT36XXX_STATUS_PREPARE_FIRMWARE; + + ret =3D devm_add_action_or_reset(ts->dev, nt36xxx_release_memory, ts); + if (ret) + return ret; + + return 0; +} + +static int _nt36xxx_boot_download_firmware(struct nt36xxx_ts *ts) { + int i, ret, retry =3D 0; + u8 val[8 * 4] =3D {0}; + + if (!(ts->status & NT36XXX_STATUS_PREPARE_FIRMWARE)) + return -EIO; + + if (ts->hw_crc) { + ret =3D nt36xxx_download_firmware_hw_crc(ts); + if (ret) { + dev_err(ts->dev, "nt36xxx_download_firmware_hw_crc fail!"); + return ret; + } + + } else { + dev_err(ts->dev, "non-hw_crc model is not support yet!"); + return -EIO; + } + + /* set ilm & dlm reg bank */ + for (i =3D 0; i < ts->fw_data.partition; i++) { + if (0 =3D=3D strncmp(ts->bin_map[i].name, "ILM", 3)) { + regmap_raw_write(ts->regmap, ts->mmap[MMAP_ILM_DES_ADDR], &ts->bin_map[= i].sram_addr, 3); + regmap_raw_write(ts->regmap, ts->mmap[MMAP_ILM_LENGTH_ADDR], &ts->bin_m= ap[i].size, 3); + + /* crc > 1 then len =3D 4, crc =3D 1 then len =3D 3 */ + regmap_raw_write(ts->regmap, ts->mmap[MMAP_G_ILM_CHECKSUM_ADDR], &ts->b= in_map[i].crc, + sizeof(ts->bin_map[i].crc)); + } + if (0 =3D=3D strncmp(ts->bin_map[i].name, "DLM", 3)) { + regmap_raw_write(ts->regmap, ts->mmap[MMAP_DLM_DES_ADDR], &ts->bin_map[= i].sram_addr, 3); + regmap_raw_write(ts->regmap, ts->mmap[MMAP_DLM_LENGTH_ADDR], &ts->bin_m= ap[i].size, 3); + + /* crc > 1 then len =3D 4, crc =3D 1 then len =3D 3 */ + regmap_raw_write(ts->regmap, ts->mmap[MMAP_G_DLM_CHECKSUM_ADDR], &ts->b= in_map[i].crc, + sizeof(ts->bin_map[i].crc)); + } + } + + /* nvt_bld_crc_enable() */ + /* crc enable */ + regmap_raw_read(ts->regmap, ts->mmap[MMAP_BLD_CRC_EN_ADDR], val, 1); + + val[0] |=3D 1 << 7; + regmap_raw_write(ts->regmap, ts->mmap[MMAP_BLD_CRC_EN_ADDR], val, 1); + + /* enable fw crc */ + val[0] =3D 0; + regmap_raw_write(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR] | NT36XXX_EVT_= RESET_COMPLETE, val, 1); + + val[0] =3D 0xae; + regmap_raw_write(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR] | NT36XXX_EVT_= HOST_CMD, val, 1); + + /* nvt_boot_ready() */ + /* Set Boot Ready Bit */ + val[0] =3D 0x1; + regmap_raw_write(ts->regmap, ts->mmap[MMAP_BOOT_RDY_ADDR], val, 1); + + /* old logic 5ms, retention to 10ms */ + usleep_range(10000, 11000); + + /* nvt_check_fw_reset_state() */ + ret =3D nt36xxx_check_reset_state(ts, NT36XXX_STATE_INIT); + if (ret) + return ret; + +check_fw: + /* nvt_get_fw_info() */ + ret =3D regmap_raw_read(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR] | NT36X= XX_EVT_FWINFO, val, 16); + if (ret) + return ret; + + dev_dbg(ts->dev, "Get default fw_ver=3D%d, max_x=3D%d, max_y=3D%d, by def= ault max_x=3D%d max_y=3D%d\n", + val[2], ts->prop.max_x, ts->prop.max_y, ts->data->max_x, ts->data->max= _y); + + if (val[0] !=3D 0xff && retry < 5) { + dev_err(ts->dev, "FW info is broken! fw_ver=3D0x%02X, ~fw_ver=3D0x%02X\n= ", val[1], val[2]); + retry++; + goto check_fw; + } + + dev_info(ts->dev, "Touch IC fw loaded ok"); + + ts->status |=3D NT36XXX_STATUS_DOWNLOAD_COMPLETE; + + return 0; +} + +static void nt36xxx_download_firmware(struct work_struct *work) { + struct nt36xxx_ts *ts =3D container_of(work, struct nt36xxx_ts, work.work= ); + int ret; + + cancel_delayed_work(&ts->work); + + mutex_lock(&ts->lock); + _nt36xxx_boot_prepare_firmware(ts); + mutex_unlock(&ts->lock); + + if (!(ts->status & NT36XXX_STATUS_PREPARE_FIRMWARE)) + goto exit; + + /* so the pm resume might have code to enable regulators. */ + ret =3D pm_runtime_resume_and_get(ts->dev); + if (ret) { + dev_err(ts->dev, "%s resume fail 0x%x", __func__, ret); + goto exit; + } + + disable_irq_nosync(ts->irq); + + mutex_lock(&ts->lock); + + ret =3D nt36xxx_eng_reset_idle(ts); + if (ret) { + dev_err(ts->dev, "Failed to check chip version\n"); + goto unlock; + } + + /* Set memory maps for the specific chip version */ + ret =3D nt36xxx_chip_version_init(ts); + if (ret) { + dev_err(ts->dev, "Failed to check chip version\n"); + goto unlock; + } + + dev_dbg(ts->dev, "ts->status=3D0x%x", ts->status); + + _nt36xxx_boot_download_firmware(ts); +unlock: + mutex_unlock(&ts->lock); + enable_irq(ts->irq); + + pm_runtime_put(ts->dev); +exit: + if (!(ts->status & NT36XXX_STATUS_DOWNLOAD_COMPLETE)) { + schedule_delayed_work(&ts->work, 4000); + } +} + +static void nt36xxx_release_memory(void *data) +{ + struct nt36xxx_ts *ts =3D data; + kfree(ts->bin_map); + kfree(ts->fw_entry.data); +} + +static void nt36xxx_disable_regulators(void *data) +{ + struct nt36xxx_ts *ts =3D data; + + regulator_bulk_disable(NT36XXX_NUM_SUPPLIES, ts->supplies); +} + +static int nt36xxx_input_dev_config(struct nt36xxx_ts *ts, const struct in= put_id *id) +{ + struct device *dev =3D ts->dev; + int ret; + + ts->input =3D devm_input_allocate_device(dev); + if (!ts->input) + return -ENOMEM; + + input_set_drvdata(ts->input, ts); + + ts->input->phys =3D devm_kasprintf(dev, GFP_KERNEL, + "%s/input0", dev_name(dev)); + if (!ts->input->phys) + return -ENOMEM; + + ts->input->name =3D "nt36xxx_spi_0"; + ts->input->dev.parent =3D dev; + ts->input->id =3D *id; + + input_set_abs_params(ts->input, ABS_MT_PRESSURE, 0, + TOUCH_MAX_PRESSURE, 0, 0); + input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); + + input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, + ts->data->abs_x_max - 1, 0, 0); + input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, + ts->data->abs_y_max - 1, 0, 0); + + touchscreen_parse_properties(ts->input, true, &ts->prop); + + WARN_ON(ts->prop.max_x < 1); + + ret =3D input_mt_init_slots(ts->input, TOUCH_MAX_FINGER_NUM, + INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); + if (ret) { + dev_err(dev, "Cannot init MT slots (%d)\n", ret); + return ret; + } + + ret =3D input_register_device(ts->input); + if (ret) { + dev_err(dev, "Failed to register input device: %d\n", + ret); + return ret; + } + + return 0; +} + +static int nt36xxx_of_compatible(struct device *dev) +{ + struct device_node *np =3D dev->of_node; + + if (!of_device_is_compatible(np, "novatek,NVT-default-spi")) { + const char *path =3D "/chosen"; + struct device_node *dt_node; + const char *bootargs; + + dt_node =3D of_find_node_by_path(path); + if (!dt_node) { + dev_err(dev, "Failed to find device-tree node: %s\n", path); + return -ENODEV; + } + + if (!of_property_read_string(dt_node, "bootargs", &bootargs)) + if (!strstr(bootargs, "tianma") && !strstr(bootargs, "nt36")) + return -ENODEV; + + dev_info(dev, "Try to probe novatek/tianma panel as specified in chosen/= bootargs."); + } + return 0; +} + +int nt36xxx_probe(struct device *dev, int irq, const struct input_id *id, + struct regmap *regmap) +{ + const struct nt36xxx_chip_data *chip_data; + const char *signed_fwname =3D NULL; + int ret; + + struct nt36xxx_ts *ts =3D devm_kzalloc(dev, sizeof(struct nt36xxx_ts), GF= P_KERNEL); + if (!ts) + return -ENOMEM; + + dev_set_drvdata(dev, ts); + + chip_data =3D of_device_get_match_data(dev); + if(!chip_data) + return -EINVAL; + + ts->dev =3D dev; + ts->regmap =3D regmap; + ts->irq =3D irq; + + ts->data =3D chip_data; + memcpy(ts->mmap_data, chip_data->mmap, sizeof(ts->mmap_data)); + ts->mmap =3D ts->mmap_data; + + ts->supplies =3D devm_kcalloc(dev, NT36XXX_NUM_SUPPLIES, + sizeof(*ts->supplies), GFP_KERNEL); + if (!ts->supplies) + return -ENOMEM; + + ts->reset_gpio =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + if (IS_ERR(ts->reset_gpio)) + return PTR_ERR(ts->reset_gpio); + + gpiod_set_consumer_name(ts->reset_gpio, "nt36xxx_reset"); + + ts->irq_gpio =3D devm_gpiod_get_optional(dev, "irq", GPIOD_IN); + if (IS_ERR(ts->irq_gpio)) + return PTR_ERR(ts->irq_gpio); + + if (irq <=3D 0) { + ts->irq =3D gpiod_to_irq(ts->irq_gpio); + if (ts->irq <=3D0) { + dev_err(dev, "either need irq or irq-gpio specified in devicetree node!= \n"); + return -EINVAL; + } + + dev_info(ts->dev, "irq %d", ts->irq); + } + + gpiod_set_consumer_name(ts->irq_gpio, "nt36xxx_irq"); + + if (drm_is_panel_follower(dev)) + goto skip_regulators; + + /* These supplies are optional, also shared with LCD panel */ + ts->supplies[0].supply =3D "vdd"; + ts->supplies[1].supply =3D "vio"; + ts->supplies[2].supply =3D "vio2"; + ts->supplies[3].supply =3D "vio3"; + ret =3D devm_regulator_bulk_get(dev, + NT36XXX_NUM_SUPPLIES, + ts->supplies); + if (ret) + return dev_err_probe(dev, ret, + "Cannot get supplies: %d\n", ret); + + ret =3D regulator_bulk_enable(NT36XXX_NUM_SUPPLIES, ts->supplies); + if (ret) + return ret; + + usleep_range(10000, 11000); + + ret =3D devm_add_action_or_reset(dev, nt36xxx_disable_regulators, ts); + if (ret) + return ret; + +skip_regulators: + mutex_init(&ts->lock); + + ret =3D nt36xxx_eng_reset_idle(ts); + if (ret) { + dev_err(dev, "Failed to check chip version\n"); + return ret; + } + + /* Set memory maps for the specific chip version */ + ret =3D nt36xxx_chip_version_init(ts); + if (ret) { + dev_err(dev, "Failed to check chip version\n"); + return ret; + } + + ret =3D nt36xxx_of_compatible(dev); + if (ret) { + return ret; + } + + /* copy the const mmap into drvdata */ + memcpy(ts->mmap_data, ts->data->mmap, sizeof(ts->mmap_data)); + ts->mmap =3D ts->mmap_data; + + ret =3D nt36xxx_input_dev_config(ts, ts->data->id); + if (ret) { + dev_err(dev, "failed set input device: %d\n", ret); + return ret; + } + + ret =3D devm_request_threaded_irq(dev, ts->irq, NULL, nt36xxx_irq_handler, + IRQ_TYPE_EDGE_RISING | IRQF_ONESHOT, dev_name(dev), ts); + if (ret) { + dev_err(dev, "request irq failed: %d\n", ret); + return ret; + } + + /* init with default name */ + ts->fw_name =3D ts->data->fw_name; + /* support overriding fw name */ + of_property_read_string_index(ts->dev->of_node, "firmware-name", 0, &sign= ed_fwname); + if (signed_fwname) + ts->fw_name =3D signed_fwname; + + if (drm_is_panel_follower(dev)) { + ts->panel_follower.funcs =3D &nt36xxx_panel_follower_funcs; + devm_drm_panel_add_follower(dev, &ts->panel_follower); + } + + pm_runtime_enable(dev); + + /* have to make sure this is first time schedule work, if devm_drm_panel_= add_follower + * called into internal resume with schedule_delay_work, then block it ov= er there */ + if (ts->fw_name) { + ts->status |=3D NT36XXX_STATUS_NEED_FIRMWARE; + + /* make the driver sleep while waiting tasklet fw download */ + pm_runtime_suspend(dev); + + devm_delayed_work_autocancel(dev, &ts->work, nt36xxx_download_firmware); + schedule_delayed_work(&ts->work, 0); + } + + dev_info(dev, "probe ok!"); + return 0; +} + +EXPORT_SYMBOL_GPL(nt36xxx_probe); + +static int __maybe_unused nt36xxx_internal_pm_suspend(struct device *dev) +{ + struct nt36xxx_ts *ts =3D dev_get_drvdata(dev); + int ret =3D 0; + + mutex_lock(&ts->lock); + ts->status |=3D NT36XXX_STATUS_SUSPEND; + mutex_unlock(&ts->lock); + + cancel_delayed_work_sync(&ts->work); + + /* adding the mutex is to protect concurrent with download_task */ + mutex_lock(&ts->lock); + if (ts->mmap[MMAP_EVENT_BUF_ADDR]) { + ret =3D regmap_write(ts->regmap, ts->mmap[MMAP_EVENT_BUF_ADDR], NT36XXX_= CMD_ENTER_SLEEP); + } + + if (ret) + dev_err(ts->dev, "Cannot enter suspend!\n"); + mutex_unlock(&ts->lock); + + return 0; +} + +static int __maybe_unused nt36xxx_pm_suspend(struct device *dev) +{ + struct nt36xxx_ts *ts =3D dev_get_drvdata(dev); + int ret=3D0; + + if (drm_is_panel_follower(dev)) + return 0; + + disable_irq_nosync(ts->irq); + + regulator_bulk_disable(NT36XXX_NUM_SUPPLIES, ts->supplies); + + ret =3D nt36xxx_internal_pm_suspend(dev); + return ret; +} + +static int __maybe_unused nt36xxx_internal_pm_resume(struct device *dev) +{ + struct nt36xxx_ts *ts =3D dev_get_drvdata(dev); + + mutex_lock(&ts->lock); + if(ts->status & (NT36XXX_STATUS_SUSPEND | NT36XXX_STATUS_DOWNLOAD_COMPLET= E)) + ts->status &=3D ~(NT36XXX_STATUS_SUSPEND | NT36XXX_STATUS_= DOWNLOAD_COMPLETE); + mutex_unlock(&ts->lock); + + if (ts->status & NT36XXX_STATUS_NEED_FIRMWARE) + schedule_delayed_work(&ts->work, 0); + + return 0; +} + +static int __maybe_unused nt36xxx_pm_resume(struct device *dev) +{ + struct nt36xxx_ts *ts =3D dev_get_drvdata(dev); + int ret=3D0; + + if (drm_is_panel_follower(dev)) + return 0; + + enable_irq(ts->irq); + + ret =3D regulator_bulk_enable(NT36XXX_NUM_SUPPLIES, ts->supplies); + + ret =3D nt36xxx_internal_pm_resume(dev); + return ret; +} + +EXPORT_GPL_SIMPLE_DEV_PM_OPS(nt36xxx_pm_ops, + nt36xxx_pm_suspend, + nt36xxx_pm_resume); + +static int panel_prepared(struct drm_panel_follower *follower) +{ + struct nt36xxx_ts *ts =3D container_of(follower, struct nt36xxx_ts, panel= _follower); + + if (ts->status & NT36XXX_STATUS_SUSPEND) + enable_irq(ts->irq); + + /* supposed to clear the flag here, but leave to internal_pm_resume + * for greater purpose, then clear flag as: + * ts->status &=3D ~NT36XXX_STATUS_SUSPEND; + */ + return nt36xxx_internal_pm_resume(ts->dev); +} + +static int panel_unpreparing(struct drm_panel_follower *follower) +{ + struct nt36xxx_ts *ts =3D container_of(follower, struct nt36xxx_ts, panel= _follower); + + mutex_lock(&ts->lock); + ts->status |=3D NT36XXX_STATUS_SUSPEND; + mutex_unlock(&ts->lock); + + disable_irq_nosync(ts->irq); + + return nt36xxx_internal_pm_suspend(ts->dev); +} + +static struct drm_panel_follower_funcs nt36xxx_panel_follower_funcs =3D { + .panel_prepared =3D panel_prepared, + .panel_unpreparing =3D panel_unpreparing, +}; + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("NT36XXX Touchscreen driver"); +MODULE_AUTHOR("AngeloGioacchino Del Regno "); +MODULE_AUTHOR("George Chan "); diff --git a/drivers/input/touchscreen/nt36xxx_spi.c b/drivers/input/touchs= creen/nt36xxx_spi.c new file mode 100644 index 0000000000..21d2a4c79c --- /dev/null +++ b/drivers/input/touchscreen/nt36xxx_spi.c @@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * NT36XXX SPI Touchscreen Driver + * + * Copyright (C) 2020 - 2021 Goodix, Inc. + * Copyright (C) 2023 Linaro Ltd. + * Copyright (C) 2023-2024 George Chan + * + * Based on goodix_ts_berlin driver. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nt36xxx.h" + +#define SPI_READ_PREFIX_LEN 1 +#define SPI_WRITE_PREFIX_LEN 1 + +#define DEBUG 0 + +/* + * there are two kinds of spi read/write: + * (a)spi_read()/spi_write()/spi_write_then_read(), + * (b)and the spi_sync itself. + * + * we have to choose one and stick together, cross-use otherwise caused pr= oblem. + * the addressing mode is | 0xff 0xXX 0xYY | 0xZ1 ... data1...| 0xZ2 ...da= ta2... | ... + * 0xXX is bit[23..16] + * 0xYY is bit[15..7] + * above describe a 'page select' ops + * 0xZ1 is bit[7..0], addr for read ops + * 0xZ2 is bit[7..0] | 0x80, addr for write ops + * there is no restriction on the read write order. +*/ +static int nt36xxx_spi_write(void *dev, const void *data, + size_t len) +{ + struct spi_device *spi =3D to_spi_device((struct device *)dev); + int32_t ret; + + void *data1 =3D kmemdup(data, len, GFP_KERNEL|GFP_DMA); + if (!data1) + return -ENOMEM; + + u8 addr[4] =3D { 0xff, *(u32 *)data >> 15, *(u32 *)data >> 7, (*(u32 *)d= ata & 0x7f) | 0x80}; + memcpy(data1, addr, 4); + + dev_dbg(dev, "%s len=3D0x%lx", __func__, len); + + spi_write(spi, data1, 3); + ret =3D spi_write(spi, data1 + 3, len - 3); + if (ret) + dev_err(dev, "transfer err %d\n ", ret); + else if (DEBUG) { + + print_hex_dump(KERN_INFO, __func__, DUMP_PREFIX_OFFSET, + 16, 1, data, 3, true); + + print_hex_dump(KERN_INFO, __func__, DUMP_PREFIX_OFFSET, + 16, 1, data + 3, (len - 3) > 0x20 ? 0x20 : len - 3 , true); + } + + kfree(data1); + return ret; +} + +static int nt36xxx_spi_read(void *dev, const void *reg_buf, + size_t reg_size, void *val_buf, + size_t val_size) +{ + struct spi_device *spi =3D to_spi_device(dev); + int ret; + u8 addr[4] =3D { 0xff, *(u32 *)reg_buf >> 15, *(u32 *)reg_buf >> 7, *(u3= 2 *)reg_buf & 0x7f }; + + ret =3D spi_write(spi, addr, 3); + if (ret) { + dev_err(dev, "transfer0 err %s %d ret=3D%d", __func__, __LINE__, ret); + return ret; + } + + ret =3D spi_write_then_read(spi, &addr[3] , 1, val_buf, val_size); + if (ret) { + dev_err(dev, "transfer1 err %s %d ret=3D%d", __func__, __LINE__, ret); + return ret; + } + + if (DEBUG) { + print_hex_dump(KERN_INFO, __func__, DUMP_PREFIX_OFFSET, + 16, 1, addr, 3, true); + + print_hex_dump(KERN_INFO, __func__, DUMP_PREFIX_OFFSET, + 16, 1, addr, (val_size) > 0x20 ? 0x20 : val_size % 0x20 , true); + + print_hex_dump(KERN_INFO, __func__, DUMP_PREFIX_OFFSET, + 16, 1, val_buf, (val_size > 0x20) ? 0x20 : val_size % 0x20 , true); + } + + return ret; +} + +const struct regmap_config nt36xxx_regmap_config_32bit =3D { + .name =3D "nt36xxx_hw", + .reg_bits =3D 32, + .val_bits =3D 8, + .read =3D nt36xxx_spi_read, + .write =3D nt36xxx_spi_write, + + .max_raw_read =3D NT36XXX_TRANSFER_LEN + 8, + .max_raw_write =3D NT36XXX_TRANSFER_LEN + 8, + + .zero_flag_mask =3D true, /* this is needed to make sure addr is not writ= e_masked */ + .cache_type =3D REGCACHE_NONE, +}; + +static const struct input_id nt36xxx_spi_input_id =3D { + .bustype =3D BUS_SPI, +}; + +static int nt36xxx_spi_probe(struct spi_device *spi) +{ + struct regmap_config *regmap_config; + struct regmap *regmap; + size_t max_size; + int ret =3D 0; + + dev_dbg(&spi->dev, "%s %d", __func__, __LINE__); + + regmap_config =3D devm_kmemdup(&spi->dev, &nt36xxx_regmap_config_32bit, + sizeof(*regmap_config), GFP_KERNEL); + if (!regmap_config) { + dev_err(&spi->dev, "memdup regmap_config fail\n"); + return -ENOMEM; + } + + spi->mode =3D SPI_MODE_0; + spi->bits_per_word =3D 8; + ret =3D spi_setup(spi); + if (ret) { + dev_err(&spi->dev, "SPI setup error %d\n", ret); + return ret; + } + + /* don't exceed max specified SPI CLK frequency */ + if (spi->max_speed_hz > MAX_SPI_FREQ_HZ) { + dev_err(&spi->dev, "SPI CLK %d Hz?\n", spi->max_speed_hz); + return -EINVAL; + } + + max_size =3D spi_max_transfer_size(spi); + regmap_config->max_raw_read =3D max_size - SPI_READ_PREFIX_LEN; + regmap_config->max_raw_write =3D max_size - SPI_WRITE_PREFIX_LEN; + + regmap =3D devm_regmap_init(&spi->dev, NULL, spi, regmap_config); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + return nt36xxx_probe(&spi->dev, spi->irq, + &nt36xxx_spi_input_id, regmap); +} + +const struct nt36xxx_chip_data default_config =3D { + .config =3D &nt36xxx_regmap_config_32bit, + .mmap =3D nt36676f_memory_maps, + .max_x =3D 1080, + .max_y =3D 2400, + .abs_x_max =3D 1080, + .abs_y_max =3D 2400, + .id =3D &nt36xxx_spi_input_id, +}; + +const struct nt36xxx_chip_data miatoll_tianma_nt36675 =3D { + .config =3D &nt36xxx_regmap_config_32bit, + .mmap =3D nt36675_memory_maps, + .fw_name =3D "novatek_ts_tianma_fw.bin", + .max_x =3D 1080, + .max_y =3D 2400, + .abs_x_max =3D 1080, + .abs_y_max =3D 2400, + .id =3D &nt36xxx_spi_input_id, +}; + +const struct nt36xxx_chip_data generic_nt36676f =3D { + .config =3D &nt36xxx_regmap_config_32bit, + .mmap =3D nt36676f_memory_maps, + .max_x =3D 1080, + .max_y =3D 2400, + .abs_x_max =3D 1080, + .abs_y_max =3D 2400, + .id =3D &nt36xxx_spi_input_id, +}; + +const struct nt36xxx_chip_data generic_nt36772 =3D { + .config =3D &nt36xxx_regmap_config_32bit, + .mmap =3D nt36772_memory_maps, + .max_x =3D 1080, + .max_y =3D 2400, + .abs_x_max =3D 1080, + .abs_y_max =3D 2400, + .id =3D &nt36xxx_spi_input_id, +}; + +const struct nt36xxx_chip_data generic_nt36525 =3D { + .config =3D &nt36xxx_regmap_config_32bit, + .mmap =3D nt36525_memory_maps, + .max_x =3D 1080, + .max_y =3D 2400, + .abs_x_max =3D 1080, + .abs_y_max =3D 2400, + .id =3D &nt36xxx_spi_input_id, +}; + +static const struct spi_device_id nt36xxx_spi_ids[] =3D { + { "nt36675-spi", 0 }, + { }, +}; +MODULE_DEVICE_TABLE(spi, nt36xxx_spi_ids); + +static const struct of_device_id nt36xxx_spi_of_match[] =3D { + { .compatible =3D "novatek,nt36675-spi", .data =3D &miatoll_tianma_nt3667= 5, }, + { .compatible =3D "novatek,nt36672a-spi", .data =3D &miatoll_tianma_nt366= 75, }, + { .compatible =3D "novatek,nt36676f-spi", .data =3D &generic_nt36676f, }, + { .compatible =3D "novatek,nt36772-spi", .data =3D &generic_nt36772, }, + { .compatible =3D "novatek,nt36525-spi", .data =3D &generic_nt36525, }, + /* + * this is served for two special purpose. + * (1) detect/display model only, and bail out in the end + * (2) checking device varients, mixed use of novatek and focaltech spi ic + * TODO: might add auto select mmap for unknown nvt device. + */ + { .compatible =3D "novatek,NVT-default-spi", .data =3D &default_config, }, + { } +}; +MODULE_DEVICE_TABLE(of, nt36xxx_spi_of_match); + +static struct spi_driver nt36xxx_spi_driver =3D { + .driver =3D { + .name =3D "nt36675-spi", + .of_match_table =3D nt36xxx_spi_of_match, + .pm =3D pm_sleep_ptr(&nt36xxx_pm_ops), + }, + .probe =3D nt36xxx_spi_probe, + .id_table =3D nt36xxx_spi_ids, +}; +module_spi_driver(nt36xxx_spi_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("NT36XXX SPI Touchscreen driver"); +MODULE_AUTHOR("Neil Armstrong "); +MODULE_AUTHOR("George Chan "); --=20 2.43.0 From nobody Wed Nov 27 00:26:08 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8794F1C07E5; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; cv=none; b=RWDq5uwHdlO5fAKJV1kNDfOHqsJYPq3FIeCdWlRnaJ85ZG3rqa4Q3OZy3gXoJK1JpSaWORRo2Xi7YqEC35gc7QRy4ail8ZWecqqnaS0SBtoA7o67Xblxus7Ug4Wg44EoNhh9XzP7iE0+X7NCX5m3MrXTP4JSr4W3fyLWq9JbZy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728996812; c=relaxed/simple; bh=Udnv1koDwbInVk0nEtEsG9PIAwZTO9fQsSD5ERFyx0Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VemFn+q2ufe1aXCqrIpPVHrkO74vDYsO0Plw8U6BSx3jx61TeRJl27q5aNXNlqEw9PhP+vtRaoHAgpsdLA4Sn/e2KSot/0/KLmGDgCR8KGe1dMPLQTJdsClti2JAzaCpb88f7xYPg3ZJhnxAEJwgnORok0QqO8LgEUeL5YFh4C4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AfC8smwn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AfC8smwn" Received: by smtp.kernel.org (Postfix) with ESMTPS id 29C2CC4CED2; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728996812; bh=Udnv1koDwbInVk0nEtEsG9PIAwZTO9fQsSD5ERFyx0Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=AfC8smwnmghjBAVSSws9C+MKUkIKkYWPsE7UTBzl7Q3hpSImONJ70FotEYB2Z5y4m sz72barFcKYLrtP+1dG6e7uq1XDqvBHJxupt2nCpPenvJ9gIBn10bl9WQlzMeqlhO1 BDbFnJEkLPKdKrLZMFTF1zDfh0SzXmecpvBwLFkHA9x3Zr8k6Iju98UZ5Hekxw/Lxr woZa874ilKx7Yc+4tRol1Q3u4QAaOVK29947kGYaTqebw1v+V9+Vj4ORBx5ZGs5uBj ZGOcpM1TmXlS5N3zt/Xvq6tYUYf/xS5yjRBBdBYRI5JCUYaL6j433btFB3qtLqodpu C3z0gtsB9rXZQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EDDBD216A2; Tue, 15 Oct 2024 12:53:32 +0000 (UTC) From: George Chan via B4 Relay Date: Tue, 15 Oct 2024 20:53:31 +0800 Subject: [PATCH RFC/RFT 3/3] dts: sm7125-xiaomi-joyeuse: Sample device tree for reference Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241015-nt36xxx-v1-3-3919d0bffee6@gmail.com> References: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> In-Reply-To: <20241015-nt36xxx-v1-0-3919d0bffee6@gmail.com> To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Del Regno , Henrik Rydberg Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, George Chan X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1728996810; l=6157; i=gchan9527@gmail.com; s=20241015; h=from:subject:message-id; bh=tWQZcmPANb4gyYg3Iy7tm37YDTp8/euoXHalxbM18xI=; b=LpMt6KwLQJJNw2ApXjiVTFev3urGDEjLrV4ifAm4rghDhKju/6l5pSvCF1By3ymwJAdwDXGAl 4I6CBpnVE/IACDBLermLo56NxcrYbTBr/dDOEjn2heqvCAV/cAjwTXP X-Developer-Key: i=gchan9527@gmail.com; a=ed25519; pk=dscYWhT+BiQOBMpPE19NFQAjBBmcpipc6zdf2MTze/U= X-Endpoint-Received: by B4 Relay for gchan9527@gmail.com/20241015 with auth_id=248 X-Original-From: George Chan Reply-To: gchan9527@gmail.com From: George Chan Provide a include-made-easy devicetree file for demo. This sample file aimed including novatek touch support. Reviewers please ignore this patch. The full device tree is at below: https://github.com/99degree/linux/tree/working-20241015/arch/arm64/boot/dts= /qcom Signed-off-by: George Chan --- arch/arm64/boot/dts/qcom/Makefile | 1 + .../boot/dts/qcom/sm7125-xiaomi-joyeuse-touch.dts | 183 +++++++++++++++++= ++++ 2 files changed, 184 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/Makefile b/arch/arm64/boot/dts/qcom/M= akefile index aea1d69db5..ba9786555b 100644 --- a/arch/arm64/boot/dts/qcom/Makefile +++ b/arch/arm64/boot/dts/qcom/Makefile @@ -235,6 +235,7 @@ dtb-$(CONFIG_ARCH_QCOM) +=3D sm6350-sony-xperia-lena-pd= x213.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm6375-sony-xperia-murray-pdx225.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm7125-xiaomi-curtana.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm7125-xiaomi-joyeuse.dtb +dtb-$(CONFIG_ARCH_QCOM) +=3D sm7125-xiaomi-joyeuse-touch.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm7225-fairphone-fp4.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm8150-hdk.dtb dtb-$(CONFIG_ARCH_QCOM) +=3D sm8150-microsoft-surface-duo.dtb diff --git a/arch/arm64/boot/dts/qcom/sm7125-xiaomi-joyeuse-touch.dts b/arc= h/arm64/boot/dts/qcom/sm7125-xiaomi-joyeuse-touch.dts new file mode 100644 index 0000000000..4a43db701d --- /dev/null +++ b/arch/arm64/boot/dts/qcom/sm7125-xiaomi-joyeuse-touch.dts @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: (GPL-2.0+ OR MIT) + +#ifndef SM7125_XIAOMI_JOYEUSE_TOUCH_DTS +#define SM7125_XIAOMI_JOYEUSE_TOUCH_DTS + +#include +#include + +#include "sm7125-xiaomi-joyeuse-display.dts" + +&soc { + gpi_dma0: dma-controller@800000 { + compatible =3D "qcom,sm7125-gpi-dma", "qcom,sm6350-gpi-dma"; + reg =3D <0 0x00800000 0 0x60000>; + interrupts =3D , + , + , + , + , + , + , + , + , + ; + dma-channels =3D <10>; + dma-channel-mask =3D <0x1f>; + iommus =3D <&apps_smmu 0x56 0x0>; + #dma-cells =3D <3>; + =09 + status =3D "disabled"; + }; + + gpi_dma1: dma-controller@a00000 { + compatible =3D "qcom,sm7125-gpi-dma", "qcom,sm6350-gpi-dma"; + reg =3D <0 0x00a00000 0 0x60000>; + interrupts =3D , + , + , + , + , + , + , + , + , + ; + dma-channels =3D <10>; + dma-channel-mask =3D <0x3f>; + iommus =3D <&apps_smmu 0x4d6 0x0>; + #dma-cells =3D <3>; + =09 + status =3D "disabled"; + }; +}; + +//spi@880000 +&spi0 { + dmas =3D <&gpi_dma0 0 0 QCOM_GPI_SPI>, + <&gpi_dma0 1 0 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@884000 +&spi1 { + dmas =3D <&gpi_dma0 0 1 QCOM_GPI_SPI>, + <&gpi_dma0 1 1 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; +//spi@88c000 +&spi3 { + dmas =3D <&gpi_dma0 0 3 QCOM_GPI_SPI>, + <&gpi_dma0 1 3 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@88c000 +&spi3 { + dmas =3D <&gpi_dma0 0 3 QCOM_GPI_SPI>, + <&gpi_dma0 1 3 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@894000 +&spi5 { + dmas =3D <&gpi_dma0 0 5 QCOM_GPI_SPI>, + <&gpi_dma0 1 5 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@a80000 +&spi6 { + dmas =3D <&gpi_dma1 0 0 QCOM_GPI_SPI>, + <&gpi_dma1 1 0 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@a88000 +&spi8 { + dmas =3D <&gpi_dma1 0 2 QCOM_GPI_SPI>, + <&gpi_dma1 1 2 QCOM_GPI_SPI>; + dma-names =3D "tx", "rx"; +}; + +//spi@a90000 +&spi10 { + dma-names =3D "tx", "rx"; + dmas =3D <&gpi_dma1 0 4 QCOM_GPI_SPI>, + <&gpi_dma1 1 4 QCOM_GPI_SPI>; +}; + +//spi@a94000 +&spi11 { + dma-names =3D "tx", "rx"; + dmas =3D <&gpi_dma1 0 5 QCOM_GPI_SPI>, + <&gpi_dma1 1 5 QCOM_GPI_SPI>; +}; + +&spi11 { + status =3D "okay"; + + touchscreen: touchscreen@0 { + compatible =3D "novatek,nt36675-spi", + "novatek,nt36xxx-spi", + "novatek,NVT-ts-spi"; + =09 + reg =3D <0>; + + /* caught from joyeuse dtb*/ + spi-max-frequency =3D <4000000>; + + /* ts->irq report 194 */ + /* interrupts =3D <&tlmm 194 IRQ_TYPE_EDGE_FALLING>; */ + /* interrupt=3D <&tlmm 13 2>; */ //dtb specified, but GPIO= 13 is CAM_MCLK0 + + novatek,reset-gpio =3D <&tlmm 8 0x00>; + novatek,irq-gpio =3D <&tlmm 9 0x2001>; + + /* 672C */ + novatek,swrst-n8-addr =3D <0x03F0FE>; + novatek,spi-rd-fast-addr =3D <0x03F310>; + + reset-gpio =3D <&tlmm 8 0x00>; + /* dtb show <&tlmm 13 2>*/ + irq-gpio =3D <&tlmm 9 0x2001>; + +/* + touch_ibb-supply =3D <0x241>; //lcdb_ncp + touch_lab-supply =3D <0x240>; //qcom,qpnp-lcdb-regulator l= do + touch_vddio-supply =3D <0x33c>; //pm6150_l18 +*/ + + vio-supply =3D <&vreg_l18a_3p0>; + vdd-supply =3D <&vreg_l18a_3p0>; + + panel =3D <&panel0>; + status =3D "okay"; + }; +}; + + +&qup_spi11_spi { + drive-strength =3D <2>; + //bias-disable; +}; + +&qup_spi11_cs { + drive-strength =3D <2>; + //bias-disable; +}; + +&qup_spi11_cs_gpio { + drive-strength =3D <2>; + bias-disable; +}; + +&gpi_dma0 { + status =3D "okay"; +}; + +&gpi_dma1 { + status =3D "okay"; +}; + +#endif --=20 2.43.0