From patchwork Thu Apr 10 14:28:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 879930 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 2358C2857D7; Thu, 10 Apr 2025 14:28:23 +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=1744295304; cv=none; b=WAXdwyHMkRm3yijeAv3a9e6IWvWGcdUeCwkiM/Y8rg/HArr1bP4CQqynUB+9kLvFObKwvxnsgzrHXXj1uXlXYy+zest9mJERMagaMJj7gXsvLMUqJcZYGJc2PzqLKSNPhMoi7OVbUmlsXLQy4xS0EyPQAaSu5ub7Cxzod+IVT4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=07lRH/Xs/03N+5c/0GvvGnaaiwRX1lGStx7S5SnlxLM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mbWglP/4E/LSHgyfyZXX+F2AbcN74riAbCpp2gDKMJHFZM9AMy+I2gwduVcE1FrnqnsdYHuCTpk8bV017HnnZ1KUNBm2rJeba7o0lnhuOcddQd+6zwzlXwbLxeOyffsiAVe4HCtfFbUiqBii6vn8g9zRCUL1U1Iy2e+tFfwB3TY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g3I9cHWb; 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="g3I9cHWb" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9C613C4CEE8; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295303; bh=07lRH/Xs/03N+5c/0GvvGnaaiwRX1lGStx7S5SnlxLM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=g3I9cHWbNlwgKVZ0ewPfNMUlKM0AFXM3LLouylmkXOQmtqYvYHOMXi3PZuAIwyCqK HYrH7AS5uYtHkQSEmGJ7CDTOsqtc1/hGP7JeGoBsRmpDeHGiF//+wqxwFuWRsT8Av5 ZV3c5U9CXYT2KlrXNoyvAspNZXbNa6rQovUIEjs/FBkgjPnrJ/5BbKIg75PZBvAcX5 OGTFCifdGci1LalUdKt1ikclnboaEN1sSu+2iKuPdAFryfYef0bagzam7o5CKMNgz3 TWrp/LJc1AJDhjUQd3uMCnonrYr6wy8pP9j+3B/EfKwOo7xHqcpWD3zFVpjrMk9MaI apDHE65yZs5dQ== 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 88DC5C369AA; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:19 +0200 Subject: [PATCH v5 1/7] dt-bindings: input: syna,rmi4: Document syna,rmi4-s3706b Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-1-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Krzysztof Kozlowski , David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1304; i=david@ixit.cz; h=from:subject:message-id; bh=vZ1A1BKo6qcJdGwTku+fpPYc8gaI2CIp5TJIm0fjjbo=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFPKRohmi+kM4ZwOrlgDzZ8E75/XLNBy1c0 21mvrqCIdSJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg cvghD/9ZcQbkw1tVd2KIYU39rQZH8BDZ5SUAf3Nb1lZwArrntOQANjeQHN1D7VOCPDz+mRK+IiP OBnObNOPr/NhYLvbxD4bbQUQvvRPF/shH9mPTIGrbaPZcloQLnH3onV1pqbGPSaRPIjB6BX2EzU hPVq7UjsMNR+x4HnSMmHc/j959chBjaUG7IRts2SkDb2XiFCWqART8nVs5+SMrzoeDt1sgn5HEQ 3hdQQXMciIsxbonEH8HpT61pOdRDaYnaCuZ/fU3Y+3ceSQDJM7BbU3MYyyw8ZN6ibrRN75HllDZ phqOk2ti3O4UIbf3k1HOywxzMkTHa2qfFODdubI4ZMqytfLbP/eG25fXL2ZayMbQLy+hFHBppaI dDP2rvMWVHpmANOghMba9HENLriwDSwR1VQzUNOAQPCDwDqPC7f5R6K5Ojb0BQ3DGecZWM5+qIP IRSME8rr+pbH/qlL0FcxSzzjasMfA/JszSzArJ2YTBVeBzWgH8vDBYGd6KX3dMMzGdl/MQAbVdx G7WFjLI+6F3nq7e7YguI8+IOTTLFlrRR5k+bqYT+5e9Pt5YPvxIz/+nAcinAhr5NxZ+cGYEk2QH vvm5bKku7Dpn7wyuQVtxFu8o+fJ2zj7W8ebMhkOQse5AFMcWYmzVJ4rfDsRkeTffqeOwlENZIph uB60GktHxtOnjbQ== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: David Heidelberg Mostly irrelevant for authentic Synaptics touchscreens, but very important for applying workarounds to cheap TS knockoffs. These knockoffs work well with the downstream driver, and since the user has no way to distinguish them, later in this patch set, we introduce workarounds to ensure they function as well as possible. Acked-by: Krzysztof Kozlowski Signed-off-by: David Heidelberg --- Documentation/devicetree/bindings/input/syna,rmi4.yaml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/input/syna,rmi4.yaml b/Documentation/devicetree/bindings/input/syna,rmi4.yaml index b522c8d3ce0db719ff379f2fefbdca79e73d027c..d5d0225e3826fa5a0559cbd99115c505ab113aa0 100644 --- a/Documentation/devicetree/bindings/input/syna,rmi4.yaml +++ b/Documentation/devicetree/bindings/input/syna,rmi4.yaml @@ -18,9 +18,14 @@ description: | properties: compatible: - enum: - - syna,rmi4-i2c - - syna,rmi4-spi + oneOf: + - enum: + - syna,rmi4-i2c + - syna,rmi4-spi + - items: + - enum: + - syna,rmi4-s3706b # OnePlus 6/6T + - const: syna,rmi4-i2c reg: maxItems: 1 From patchwork Thu Apr 10 14:28:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 881071 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 235112853F5; Thu, 10 Apr 2025 14:28:23 +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=1744295304; cv=none; b=tEnHzGRRVaPqzIfiSfquVK7nss4+avdC4VyByb5gQqrMNyuLSRaoilYhKmbO1NdqZlCG112J6OJ0lypJf5YREWDiS+uJJFhcr/MOwm4kexLyC9KjrFYbIF1IToHwfjlqRa+R61yk1yc4DzsuDOkkhw2HCM9UCNQNIrqt9T84Uwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=q6YqJI+AWlDUFmDegEVniY4d+tNOgVnSi2YYjBl+5n0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YyJNAGbyCo/dHXwXcRue8Ayc9n/LHt/t17Jz4IVGBmyUFPKvk2piyf1zSWOUDBNW3Q50WWf4BHgTsotOJ3hyHFs4DaIJ8J3C78tVQEbj0lVPf98AcJh1p0mBp92Y0Oy5RzTztb2x6NlumgPbTAjwjvHz7jI/h/vUjyk1lVeoW9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ibU5IqEK; 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="ibU5IqEK" Received: by smtp.kernel.org (Postfix) with ESMTPS id ABEA0C4CEEA; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295303; bh=q6YqJI+AWlDUFmDegEVniY4d+tNOgVnSi2YYjBl+5n0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ibU5IqEKAIvSgIaFpqQuU5Y7ZhrbMAcplYjmjWGf+6x2v/sYheuZtrnEOWdf2LZdw 8oC8Mw8srudBIfyU7Rxl1iFccjSfbe/zKdcwaFHrQiucygT2VDR6hddP0KmUfWJmnP imkpHuKUrwe/5g7KYjjiQgXvVgVanOse869c72JhOg79H2/Jmv+htI3+ZvOOiuZYij U3YQt8XtjKnr4+n+Lg8zmWF2C3c2n8eEXdC8VoTSgdJD8PNABFeGq+S4Hfle0Q+FUJ NXsN+YBNdbuVm/03oi4Jpf70e7JvwKzV8J3LDh8ih+3oyTZLLdJTjuSmVpmeo0Whsr eZS4Dlw/SU9Ew== 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 9A112C369A5; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:20 +0200 Subject: [PATCH v5 2/7] Input: synaptics-rmi4 - handle duplicate/unknown PDT entries Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-2-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3909; i=david@ixit.cz; h=from:subject:message-id; bh=UsHStuHcTC7EY8d7D+PJ8GiyG0tV5bXzwAzuKYQFCvE=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFm4V/QP30jEL9ZXlRModhu4BlXuozpNi3P 0KIMBHrHK6JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg cs/vEACRzylm4inhcAvtVjq2ISNeuZVD9clfOVdzwbjHvTygb4K/5ekmKlGPWumnybaHuMqrv/B 8q91E8HBouP9eQKy4yh1UIlV/5ovY5Qc+zRU4hnC51wRpU1GeFLyvaynjYLNwj+bgUzIoOIaYCM BhEweq7Qs03shV4gFJK3ci6Ine5e0G3qwoPAA2YKCMLu5rrPDg4QWL4yRaWAl+778eSAZprjpfl 2vJixN31FHibG0DevWRkAdincQejdRxKjQOwO8eUrzOBokTuQ/YAfceQOI0CkcPajpoEtQHq2my UPNv6xSec5sKRe3JjIQ1IigTgGYf+mwJEm+rDQGgMaWhqj/KH7KFR//eERGE7/awaqSPgIwHn0p d2zESGKmXFVuXa2vimccvhy2Gq0r/1sFTf7KA4+LG/kd0LGh2P223J4x3J7slgYpWF93+cS7IZ7 X3zZCcHhFRqc0Z8+8rdey3nVBPHk1DIAKpfG6kKT/H/NADYaYkDJP/3/nDf3AtmhRY2WA3inuT+ qbRFmIUFN5wuBYxYZryPms9UQoG7h78QFhvdw7Hzq9Pyjpn9FSFXb0hqnCvErbw9QsKGFkHPTW6 Sf5v8VxFwfbZ2/FggKP+JRcCu3M+u6kZV/y+rvhuCXHnOj2xDRQflJLoepKDf5TaG/Qr3CzoVZ/ qESDMJJgYANOUJQ== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Caleb Connolly Some third party rmi4-compatible ICs don't expose their PDT entries very well. Add a few checks to skip duplicate entries as well as entries for unsupported functions. This is required to support some phones with third party displays. Validated on a stock OnePlus 6T (original parts): manufacturer: Synaptics, product: S3706B, fw id: 2852315 Co-developed-by: Kaustabh Chakraborty Signed-off-by: Kaustabh Chakraborty Signed-off-by: Caleb Connolly Co-developed-by: David Heidelberg Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_driver.c | 42 +++++++++++++++++++++++++++++++++++------ drivers/input/rmi4/rmi_driver.h | 8 ++++++++ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 2168b6cd7167334d44553c9c566f870a4e034179..0f6dbe586c652d641178f43ec27df3613126ca66 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -493,12 +493,39 @@ static void rmi_driver_copy_pdt_to_fd(const struct pdt_entry *pdt, fd->function_version = pdt->function_version; } +static bool rmi_pdt_entry_is_valid(struct rmi_device *rmi_dev, + struct pdt_scan_state *state, u8 fn) +{ + switch (fn) { + case 0x01: + case 0x03: + case 0x11: + case 0x12: + case 0x30: + case 0x34: + case 0x3a: + case 0x54: + case 0x55: + if (state->pdts[fn] == true) + return false; + break; + default: + rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, + "PDT has unknown function number %#02x\n", fn); + return false; + } + + state->pdts[fn] = true; + state->pdt_count++; + return true; +} + #define RMI_SCAN_CONTINUE 0 #define RMI_SCAN_DONE 1 static int rmi_scan_pdt_page(struct rmi_device *rmi_dev, int page, - int *empty_pages, + struct pdt_scan_state *state, void *ctx, int (*callback)(struct rmi_device *rmi_dev, void *ctx, @@ -521,6 +548,9 @@ static int rmi_scan_pdt_page(struct rmi_device *rmi_dev, if (RMI4_END_OF_PDT(pdt_entry.function_number)) break; + if (!rmi_pdt_entry_is_valid(rmi_dev, state, pdt_entry.function_number)) + continue; + retval = callback(rmi_dev, ctx, &pdt_entry); if (retval != RMI_SCAN_CONTINUE) return retval; @@ -531,11 +561,11 @@ static int rmi_scan_pdt_page(struct rmi_device *rmi_dev, * or more is found, stop scanning. */ if (addr == pdt_start) - ++*empty_pages; + ++state->empty_pages; else - *empty_pages = 0; + state->empty_pages = 0; - return (data->bootloader_mode || *empty_pages >= 2) ? + return (data->bootloader_mode || state->empty_pages >= 2) ? RMI_SCAN_DONE : RMI_SCAN_CONTINUE; } @@ -544,11 +574,11 @@ int rmi_scan_pdt(struct rmi_device *rmi_dev, void *ctx, void *ctx, const struct pdt_entry *entry)) { int page; - int empty_pages = 0; + struct pdt_scan_state state = {0, 0, {0}}; int retval = RMI_SCAN_DONE; for (page = 0; page <= RMI4_MAX_PAGE; page++) { - retval = rmi_scan_pdt_page(rmi_dev, page, &empty_pages, + retval = rmi_scan_pdt_page(rmi_dev, page, &state, ctx, callback); if (retval != RMI_SCAN_CONTINUE) break; diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index 3bfe9013043ef3dff46249095a5b3116c8f7d9a6..cb1cacd013a3f39db96935f705f18018bf15adff 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -46,6 +46,14 @@ struct pdt_entry { u8 function_number; }; +#define RMI_PDT_MAX 0x55 + +struct pdt_scan_state { + u8 empty_pages; + u8 pdt_count; + bool pdts[RMI_PDT_MAX]; +}; + #define RMI_REG_DESC_PRESENSE_BITS (32 * BITS_PER_BYTE) #define RMI_REG_DESC_SUBPACKET_BITS (37 * BITS_PER_BYTE) From patchwork Thu Apr 10 14:28:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 881070 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 3EBC428A41B; Thu, 10 Apr 2025 14:28:24 +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=1744295304; cv=none; b=CZvb1+FhdLNKWpDVi5sXjN2upkZPfActkgtaXKtETpHJQ/nsNdisXFeYmUmqtvJ01u9QzxDGR6K8gb4XPD3YYa9KK21s4BlxasbBWz8l0lyNr00B8LQiX1xsHWenTbpzb6scVwOvEJOUYa4VqVFRrz5i3WEJliPoj3FFkEnPJ+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=kX0Z61P7BjNy7WhJ24tC3m5Hm2sT157SFCHC9z9ZvXk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FseAW+ZDGTAINJfMhynbjSZUTmGuKxjEIfDLPOi1C0BvQGCccmuhlJO6s/BwgE7qMY1mEIiu2wUAtIBnH1XWzmG6Atc55KahxS9j0TaTKi0J3Jevq+OGf2PKN1/aaqHHVYnllDsNdCsXn0ekTu/KxAaWlh9qt5gFwT/NOw7xmBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=exlAi+LU; 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="exlAi+LU" Received: by smtp.kernel.org (Postfix) with ESMTPS id BD297C4AF0D; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295303; bh=kX0Z61P7BjNy7WhJ24tC3m5Hm2sT157SFCHC9z9ZvXk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=exlAi+LUuFaR3c5iyouHmjtf4KMchKoSW054c/t2NMJnvppmOITnE7GVyVK+1ik4x 2+PKkSRHNLSgiaQa9Jhow6tmGrv70cdQ/1ZRufXbPOcRBTtS1zP9Wq7nPuSIsg8wpI aw2QbYsV142O+gn+TZAhQIFU3QmgllOpVfEf68/uzT3hQcm4Zfqkh1gKL8axblanKc 2NoOH8N1PeJe19CXRvjXU0sEXiP4hF19GM8Ajk9pb51ySxq3wjbZt3ygQaC2NBxEtf dmgcR+Hj5mLaqeOJ1rkC7yxH773k6Qx+TAbjlBqB3UolMENC0gdQoz7YaiP7by4W2v stpo1kZWyCxOQ== 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 AF5CEC369A9; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:21 +0200 Subject: [PATCH v5 3/7] Input: synaptics-rmi4 - f12: use hardcoded values for aftermarket touch ICs Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-3-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6241; i=david@ixit.cz; h=from:subject:message-id; bh=p/XNvq/UvwSU23ySeWSs7BuMIwAQjW0v6Rn2pc6/CJk=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFJtD1ncwT8gtytv/7i8LfEX1C3bfnVfVXp GzjgFtr8USJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg ch+OD/wJuzry9HrPWahhy8Kq75EhObeUhbq8aWGjtCP8HQj+ydBNzUmq8U6s7JdLm0HGBpEBNWl Nc++ED5vX+kDycQNEAWPXSKLJDVIB+rSeOBVtj8+hMhAohXJ12Zei6PegjKQvuSa0CyYWsoYvVh GaYv+fMU+7rMCQRWDJDvBqEE0wIkmLPTIeitxiQFl/mw/HFaVMW8Zs7sTERMCfOwq/FbWlRNc0C ALo2S/601fHKSza/bPp8JyMuOCOD2IkZwp3f+uz2/eN+CdUTYHk4A6mdkQ4BPoWRDClyQk+tbCz WMlHr7oBdjQ9yG/S5f0QVKwctAvwkCdIKZa9hfqS2eBvDOyxTZVCjOMVfEIIMkS8a+ZuDZaC75I KiKPm+/RSNqRvJprZyYubqCw0vJCUCjIiLW1P+weiHQBdgh+ELkM9aX4+qutJZouhMF/4W63UZM U0z965BRiHKgF79uSm3iSFCR/ilPtxhVbtJ2IYjalMAdWaa+Z8wHsdrTQbEWa3ZTLt3Zd6dlnin F32E+Vq8KlH4UvhWfSnCvieVZL1qKbbebUbPNPfSvLdvf3Qjnbhx3/Va99FeeMhKx/xlxih3yzZ x5mXiwf2zgz8qp0rnFUOm5H/Erefs1HJ07o1iLOIT68qiPJc//FeBbcgKeF32ykbBzSTSYFnIba WLSLXcDBA5fZSRg== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Kaustabh Chakraborty Some replacement displays include third-party touch ICs which are devoid of register descriptors. Create a fake data register descriptor for such ICs and provide hardcoded default values. It isn't possible to reliably determine if the touch IC is original or not, so these fallback values are offered as an alternative to the error path when register descriptors aren't available. Signed-off-by: Kaustabh Chakraborty [changes for readability / codeflow, checkpatch fixes] Signed-off-by: Caleb Connolly Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_f12.c | 117 +++++++++++++++++++++++++++++++++---------- 1 file changed, 91 insertions(+), 26 deletions(-) diff --git a/drivers/input/rmi4/rmi_f12.c b/drivers/input/rmi4/rmi_f12.c index 8246fe77114bbd8b795ba35d5a37ede8727fc7cb..1a103cc5f2235a6eafd7a3f5b89cbfc9e53203d2 100644 --- a/drivers/input/rmi4/rmi_f12.c +++ b/drivers/input/rmi4/rmi_f12.c @@ -218,6 +218,41 @@ static void rmi_f12_process_objects(struct f12_data *f12, u8 *data1, int size) rmi_2d_sensor_abs_report(sensor, &sensor->objs[i], i); } +static void rmi_f12_set_hardcoded_desc(struct rmi_function *fn, struct f12_data *f12) +{ + struct rmi_2d_sensor *sensor = &f12->sensor; + struct rmi_register_desc_item *reg_desc; + + /* We have no f12->data_reg_desc, so the pkt_size is 0, override it with + * a somewhat sensible default (this corresponds to 10 fingers). + */ + sensor->pkt_size = 88; + + /* + * There are no register descriptors to get these values from. + * We set them to high values to either be overwritten by the clip + * properties from devicetree, or to just not get in the way. + */ + sensor->max_x = 65535; + sensor->max_y = 65535; + + /* + * Create the Data1 register descriptor so that touch events + * can work properly. + */ + reg_desc = devm_kcalloc(&fn->dev, 1, + sizeof(struct rmi_register_desc_item), GFP_KERNEL); + reg_desc->reg = 1; + reg_desc->reg_size = 80; + reg_desc->num_subpackets = 10; + + f12->data1 = reg_desc; + f12->data1_offset = 0; + sensor->nbr_fingers = reg_desc->num_subpackets; + sensor->report_abs = 1; + sensor->attn_size += reg_desc->reg_size; +} + static irqreturn_t rmi_f12_attention(int irq, void *ctx) { int retval; @@ -338,6 +373,40 @@ static int rmi_f12_config(struct rmi_function *fn) return 0; } +static int rmi_f12_sensor_init(struct rmi_function *fn, struct f12_data *f12) +{ + struct rmi_2d_sensor *sensor = &f12->sensor; + + sensor->fn = fn; + f12->data_addr = fn->fd.data_base_addr; + + /* On quirky devices that don't have a data_reg_desc we hardcode the packet + * in rmi_f12_set_hardcoded_desc(). Make sure not to set it to 0 here. + */ + if (!sensor->pkt_size) + sensor->pkt_size = rmi_register_desc_calc_size(&f12->data_reg_desc); + + sensor->axis_align = + f12->sensor_pdata.axis_align; + + sensor->x_mm = f12->sensor_pdata.x_mm; + sensor->y_mm = f12->sensor_pdata.y_mm; + sensor->dribble = f12->sensor_pdata.dribble; + + if (sensor->sensor_type == rmi_sensor_default) + sensor->sensor_type = + f12->sensor_pdata.sensor_type; + + rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: data packet size: %d\n", __func__, + sensor->pkt_size); + + sensor->data_pkt = devm_kzalloc(&fn->dev, sensor->pkt_size, GFP_KERNEL); + if (!sensor->data_pkt) + return -ENOMEM; + + return 0; +} + static int rmi_f12_probe(struct rmi_function *fn) { struct f12_data *f12; @@ -351,6 +420,7 @@ static int rmi_f12_probe(struct rmi_function *fn) struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev); u16 data_offset = 0; int mask_size; + bool hardcoded_desc_quirk = false; rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s\n", __func__); @@ -365,9 +435,9 @@ static int rmi_f12_probe(struct rmi_function *fn) ++query_addr; if (!(buf & BIT(0))) { - dev_err(&fn->dev, - "Behavior of F12 without register descriptors is undefined.\n"); - return -ENODEV; + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "No register descriptors defined for F12, using fallback\n"); + hardcoded_desc_quirk = true; } f12 = devm_kzalloc(&fn->dev, sizeof(struct f12_data) + mask_size * 2, @@ -375,6 +445,8 @@ static int rmi_f12_probe(struct rmi_function *fn) if (!f12) return -ENOMEM; + dev_set_drvdata(&fn->dev, f12); + f12->abs_mask = (unsigned long *)((char *)f12 + sizeof(struct f12_data)); f12->rel_mask = (unsigned long *)((char *)f12 @@ -393,6 +465,18 @@ static int rmi_f12_probe(struct rmi_function *fn) f12->sensor_pdata = pdata->sensor_pdata; } + sensor = &f12->sensor; + + if (hardcoded_desc_quirk) { + rmi_f12_set_hardcoded_desc(fn, f12); + + ret = rmi_f12_sensor_init(fn, f12); + if (ret) + return ret; + + goto skip_register_desc; + } + ret = rmi_read_register_desc(rmi_dev, query_addr, &f12->query_reg_desc); if (ret) { @@ -423,29 +507,9 @@ static int rmi_f12_probe(struct rmi_function *fn) } query_addr += 3; - sensor = &f12->sensor; - sensor->fn = fn; - f12->data_addr = fn->fd.data_base_addr; - sensor->pkt_size = rmi_register_desc_calc_size(&f12->data_reg_desc); - - sensor->axis_align = - f12->sensor_pdata.axis_align; - - sensor->x_mm = f12->sensor_pdata.x_mm; - sensor->y_mm = f12->sensor_pdata.y_mm; - sensor->dribble = f12->sensor_pdata.dribble; - - if (sensor->sensor_type == rmi_sensor_default) - sensor->sensor_type = - f12->sensor_pdata.sensor_type; - - rmi_dbg(RMI_DEBUG_FN, &fn->dev, "%s: data packet size: %d\n", __func__, - sensor->pkt_size); - sensor->data_pkt = devm_kzalloc(&fn->dev, sensor->pkt_size, GFP_KERNEL); - if (!sensor->data_pkt) - return -ENOMEM; - - dev_set_drvdata(&fn->dev, f12); + ret = rmi_f12_sensor_init(fn, f12); + if (ret) + return ret; ret = rmi_f12_read_sensor_tuning(f12); if (ret) @@ -543,6 +607,7 @@ static int rmi_f12_probe(struct rmi_function *fn) data_offset += item->reg_size; } +skip_register_desc: /* allocate the in-kernel tracking buffers */ sensor->tracking_pos = devm_kcalloc(&fn->dev, sensor->nbr_fingers, sizeof(struct input_mt_pos), From patchwork Thu Apr 10 14:28:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 881069 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 3EB58204697; Thu, 10 Apr 2025 14:28:24 +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=1744295304; cv=none; b=fEvKJUNTWD5D/H17D5yiRQRXOcIdmNZVQeT4sbWN3OPligF9rruxgEUOxCrSi+2OFckBsQclWSbFEcwjkMIADZPAl/0rcbXsNWJ4UkZyyXokN2vIEMJRJmCDXXEjr4tD5L7PWmsQteg5g/EFBuCzDqFOzntiSEhtO/1Dj6tV0JY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=K6/VEo1yc3K+YbVulpek7YWtEuSKS3IBBhc0oUdWlo8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=azvsDUe2YoTGt8ND/yxgpT/owwrAbg4OUYjoQF5ARWLu6gW3Vbrz18BOaw14P1/n3MKUFklAQDPXL6isnI9Re+pXUIoXO4WbVaR1dOFdPgHUbhk+BpaIO9WjbWps4vETXPeWdyUAkv2hMPWKo+8OydhAzSEEae54uZMKhLNe9cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qYRKlUfW; 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="qYRKlUfW" Received: by smtp.kernel.org (Postfix) with ESMTPS id CB59EC4CEE9; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295303; bh=K6/VEo1yc3K+YbVulpek7YWtEuSKS3IBBhc0oUdWlo8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qYRKlUfW6z3P+0mCv3cQOBXLwdHzsZbu6mcE6kKnQ0hta1+dFcfgzEuGbYudBaNxW 0fg+0Zcagy34IW5QKiPtpZ/J61NED+U9XoUbkVliZDZWpRtYu6zVigNPXPBtxVIwbX nRqC1LsHzCisQYnIOlcnd2hQuL6Q4gsvv2BsCq2rVWu55Jfracp3JBCEz0Cxot/zIa qGBoGMJgkhRO9NLA4M33doMZxyiiOklGisYye8VyqcEIWLBh+/j/IRX/SPb6GnwUgA zOaKL3+v44cAl4AefBlL+DldO3mUBY6ssosvEctTBOiSV1Yzgw9WSxILDu+fzAZixg BDOSZEk8FA+Rg== 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 C0474C369AA; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:22 +0200 Subject: [PATCH v5 4/7] Input: synaptics-rmi4 - f55: handle zero electrode count Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-4-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1193; i=david@ixit.cz; h=from:subject:message-id; bh=H6bOmSExs0ZAgCP3cU3lwTLmd7Kss/M3Mr3SFnE+ZgM=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFwKp6ff+vZ6GDhp91Ltzu1lYjveQ2qOzR/ eeY8Bl74OCJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg cvXPD/4hbZ/koHOjQ27g0Ou3R7xnOaHpxzzWNvKT3Wa7du3vbvEhcVl9GjDqe50anwUV/LTvdxY oNd62daVeCNwhZj8xZnDY//w/EVqtdjfzkY9Qi3W/deu2I1TaRPzY6tqFxCAeMG4l47EZg2kQGZ VhkSQUYzI3d3h0GqbiwqyhOBzOmWRT3D4XMjg7TdaiSf57TPSz0WrkCNrl4C7xwH/rdh7BJrQkv XUd3RXj+GG53G8ydBdBDUcLCnzp8MUzd2zHvsOHVTcW5/E9OaVy5K9NAiG0Z8USpjf6EjA6KJky 8NoYsb8axPLAo8SmbbJESM3Qq+3RA0vqUo7sT/+q6RYhmtmBN6Ay3P668aJ4zMz+hdOemN1kx6Y 6C0PIgERil/MMWscwugJMIsA7Ot5Whz7WQShmp9wS8+aA2PoL2GoLJGXx+vr0aeGdzBF5Trk4x7 rzm+eezJAUUza/X4ubQQEVqhVZETwojbQ4To191GS6APXcADth8hsivDHe28e2kn1ZW1fsliWxe biK4h/AH4Tx0tcZPv8uSVYNCJXxw99XXiu/bTPZF/BUb3CyiRG7VgME5Uz89wJbzLUHpsnbi1n/ eK7ltffCwhAlU9S7bFA34sgSQno2hqUDSFxLENdDNdBn//dfKqGZC/rfux3sfvbfYM7F5W2kOB9 96rsvC00T8U9eJg== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Kaustabh Chakraborty Some third party ICs claim to support f55 but report an electrode count of 0. Catch this and bail out early so that we don't confuse the i2c bus with 0 sized reads. Signed-off-by: Kaustabh Chakraborty [simplify code, adjust wording] Signed-off-by: Caleb Connolly Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_f55.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/input/rmi4/rmi_f55.c b/drivers/input/rmi4/rmi_f55.c index 488adaca4dd00482cd1106d813b32871092c83a0..776c915b82e72b8a6eb5ec701cce9059c87089c4 100644 --- a/drivers/input/rmi4/rmi_f55.c +++ b/drivers/input/rmi4/rmi_f55.c @@ -52,6 +52,11 @@ static int rmi_f55_detect(struct rmi_function *fn) f55->num_rx_electrodes = f55->qry[F55_NUM_RX_OFFSET]; f55->num_tx_electrodes = f55->qry[F55_NUM_TX_OFFSET]; + if (!f55->num_rx_electrodes || !f55->num_tx_electrodes) { + dev_err(&fn->dev, "%s: F55 query returned no electrodes, giving up\n", + __func__); + return -EINVAL; + } f55->cfg_num_rx_electrodes = f55->num_rx_electrodes; f55->cfg_num_tx_electrodes = f55->num_rx_electrodes; From patchwork Thu Apr 10 14:28:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 879927 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 8054728CF5A; Thu, 10 Apr 2025 14:28:24 +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=1744295304; cv=none; b=nO5B3QJvc1qwvp5St+RFQG2Z2Xji7hKDkUa6zAIsVdeUzBJBXNx1o8n8mFSd4kYOaV9tn/8TAoQE+9J9Zu92fyedN73YWCdNdq30wdGz7zwLAbQHFamRdTtoQ2HVQOyuilKASKW82APTOG+hEC4NcTe3IfAMI3AdKYIv+ZP/adg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=uhoOYFv9own1t9GTd9uKLCLoHj0zKUN854bDbom6MDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ifq2ok3HQaqaKz+W23Hu6JKxODXlvRqqCelirMHX2TJ1ztGFTS75GrnH32wc4nekzXICysM+5+LZGHhQG0Lj/ps0eDF4Zi1zx8AnA0TSm2f26hz7rvJqKQVqIoi0iu2gvIGMCvc7l8gQoNBv0RlQ16Q/ykKjo1rhEvBX4wRv9ZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rfa+SSwh; 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="rfa+SSwh" Received: by smtp.kernel.org (Postfix) with ESMTPS id D9E43C4CEF0; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295304; bh=uhoOYFv9own1t9GTd9uKLCLoHj0zKUN854bDbom6MDw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=rfa+SSwhuFPe/HXCWr/Pd7XyEJZsDkCbiA9cgMXyUN4RkX1JGW7Yjn2gmG5DdmBGP 20P86jpYSxOQ27iicyO7FJCB6TwSuJzRxXewpFSmuao4zWAZkeP1EanP0e+3yu6z/c NuaobtXa3KpgeoyQ5U9TEI8OF04dlUFAGR/ElUMS9ha0zZoAvgC5B0p4pOKcHIdSyp c9vZGayfsi5UMYDfh8HURk8YlQYSWEEz3Xz5lZn3E/kgpmaxmA873u/jNawZ6nNz4P GW1sUWZWf+EgyUuGk4A5roEVFgGHQuPY5e+SDjmN2paCWWcPX1cE4doVqIoLPDzVOv iPChqcS6pRy9Q== 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 CEF0BC369AB; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:23 +0200 Subject: [PATCH v5 5/7] Input: synaptics-rmi4 - don't do unaligned reads in IRQ context Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-5-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2474; i=david@ixit.cz; h=from:subject:message-id; bh=yMLuXgF9v/gFFJ+eFIvXnbQst25n9j3YV0dhX4KqpyU=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFmjYsKd4012UJV1sQ5g8dVUQula1pMnNHL y9RLMiDF3CJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg clExEACdXQa8cCM10O9K6rzfHkTi2+1H7mbGlKjuN39h25Fg9H85ItmRvRSwHK92BkFa6RDUmT9 DMYuZFcMHCUE5wqxaaUM1LV6PTTGmoaj20AYXi7gd5azOX9DRttSYtSAuAkOl2etCukXpLHDV7R ZkukkbTdcBTzrkgCXh+eUvy4lKhd+F3urto4tRart2RkalbYnh53QslRHvIgaVlfvVDKB1MQZKm 2zARuDWJJcQ3lryEszvuDMgrn1poJa+LLU1H9yUbAPHTlbHq00vIU/m1KuJW07X1/+1miTFLcgJ W2geL7JWcQsSAoeDKFBvL9OePyDpDB7wlCXUqneHc+goIoslhfeno+4CXHAOeIyX7I39Lzr2/5Y Sx1V7yIkVW4KGkQKlWlr+dA9joYLE1FufhGigPFc/bXfcYUExae9Vm/Lwh2Rz2uU29fCQuha+ut bVw2zugBdbfnBvxUyXmt7b8jF/mMGXPLpUrlaYmLZ9IOxZRqUZ3WrwzAAbYMPs3PDVKQdXNBNHh +wtrLQk61l/poSUV7mxiiO5O6Rg+/iWHQ69h2ocjx9ozdJRMtfEgiKt0S+iuHLVbQcsWrFEZF9S r5sT0PPZzHEasUuf/HkBCZYzQwG27TuJGjzMzzxP2t5aYHL2ph+ZEoMUipuu/BOYdWc228VuiXW DQ5SbUT3L0Ap1Bg== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Kaustabh Chakraborty Some replacement displays include third-party touch ICs which incur a significant penalty (1-2 seconds) when doing certain unaligned reads. This is enough to break functionality when it happens in the hot path, so adjust the interrupt handler to not read from an unaligned address. Signed-off-by: Kaustabh Chakraborty Signed-off-by: Caleb Connolly Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_driver.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 0f6dbe586c652d641178f43ec27df3613126ca66..f977541d8913525d53a59e1d53c33897f1c93901 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -136,9 +136,14 @@ static int rmi_process_interrupt_requests(struct rmi_device *rmi_dev) return 0; if (!data->attn_data.data) { + /* + * Read the device status register as well and ignore it. + * Some aftermarket ICs have issues with interrupt requests + * otherwise. + */ error = rmi_read_block(rmi_dev, - data->f01_container->fd.data_base_addr + 1, - data->irq_status, data->num_of_irq_regs); + data->f01_container->fd.data_base_addr, + (u8 *)data->irq_status - 1, data->num_of_irq_regs + 1); if (error < 0) { dev_err(dev, "Failed to read irqs, code=%d\n", error); return error; @@ -1078,16 +1083,17 @@ int rmi_probe_interrupts(struct rmi_driver_data *data) data->num_of_irq_regs = (data->irq_count + 7) / 8; size = BITS_TO_LONGS(data->irq_count) * sizeof(unsigned long); - data->irq_memory = devm_kcalloc(dev, size, 4, GFP_KERNEL); + data->irq_memory = devm_kzalloc(dev, size * 4 + 1, GFP_KERNEL); if (!data->irq_memory) { dev_err(dev, "Failed to allocate memory for irq masks.\n"); return -ENOMEM; } - data->irq_status = data->irq_memory + size * 0; - data->fn_irq_bits = data->irq_memory + size * 1; - data->current_irq_mask = data->irq_memory + size * 2; - data->new_irq_mask = data->irq_memory + size * 3; + /* The first byte is reserved for the device status register */ + data->irq_status = data->irq_memory + size * 0 + 1; + data->fn_irq_bits = data->irq_memory + size * 1 + 1; + data->current_irq_mask = data->irq_memory + size * 2 + 1; + data->new_irq_mask = data->irq_memory + size * 3 + 1; return retval; } From patchwork Thu Apr 10 14:28:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 881068 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 807FB28CF5C; Thu, 10 Apr 2025 14:28:24 +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=1744295304; cv=none; b=JVT1tZTcxBvrtfFf+DA5LQ5Bll5grL3pYpmxO7xiKLguQ4qrMOgZ60hxP00B+oHD0C6HsGAsmaZX/p0wF4+Dska8EuqpnThj4VXhWI9BBrxe+ILK8DK8uU3zMK7xAUffwRhoGzX9NPiVLbl1R5QRio030Z0jJk8VRDTPSVaH3tY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=HeOIUhogeLDXtT5wIduDA0u/HH6Hvijhg5yr5b3aZqg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RHYNaZQjbIBNk5VIGeyesrsbIMS+TyJFrdVtRvGixOZTHtGNoDvAlC/I6ZTEz1u+pDnkZpZO22BFoqNiRwBfsSBNh0setkp7LbtCV8piMa3RN3V1ZGJEZ743toWklUkdORyywSng/zzNZUZ3Su2gWxgoCB5uOESHRJFDkhd9rpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ImpoqnmQ; 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="ImpoqnmQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id EF303C4CEF3; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295304; bh=HeOIUhogeLDXtT5wIduDA0u/HH6Hvijhg5yr5b3aZqg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ImpoqnmQ1G6dbIF/QBSKKLFOHEskswXMsoaW3aUcp81VdN/8+0OwIkmjCGWlTJ785 K2ZUuvKKDQWJwA6Etbn3pYgnUBdHPjPqgrw7zZM2y2YNq+WPpDXQ1ID8Irx/V+fm3q XOXLlEClzRww8YYWis/Q112AcmP6aETYkBpgqLlsAQrT0cVHxDc91gINGmmx8DL1le K8DOW5Ur6frPHLwbMn+FafeVdjZm9Uo00W/ECCpKfHAnDWsKw3P0n146emx1iWJH/6 Bp8tBkHcTZ3FfmtcSuQ1cpCKx2V1VMkCWpQibdGjX7q2l61hBjix59QM/l7cIXFvKk q5SrUJjY02KxA== 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 E2177C369A5; Thu, 10 Apr 2025 14:28:23 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:24 +0200 Subject: [PATCH v5 6/7] Input: synaptics-rmi4 - read product ID on aftermarket touch ICs Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-6-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1257; i=david@ixit.cz; h=from:subject:message-id; bh=fMXBJWuwOFgydtCp3BkAhLq4KC36XWjDlNvLR8bR7vw=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFUqNTBVM/GY6vug1erJlsA3VIrAOgx4LSe gpvRBBp0l6JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg cmYFD/sHqXVSPzp5jgWDXUwWxLaJdqhRo0zKA3Sz6LdcdCxfR/4HcpVHNhlRhqXUjjTaHFGkbAp AeVlpjCcq3kCrmJ2KOgME18orqIHtWHnSo1EcBy3bF3egVyhSiAEwyGP3xCtjsX88bXO/zcMD7J IsZDqcvL5UwgkOD2Gih0cU5UPXPgBNpmp3njS2j8WNEzjnozt06FfyT7bLFWD7hcCOB6f+L5tBS 0wq+ANzjcvdumIC0Qw0ZNhqkYftRoNYy5M3JJ7GbRS3GvltUwFBFsksTp9W+hxx2hcBg+2+jbnt L1KyQd9WHNtvj6df+863IzkoUAO3aGajAWlkkDQu3IELOwPNesJLykQFt9aMoPTDEyOxqCveyk9 OfbzOTE/dIjEeDxHKwS6OIUsODYpfcUtVMVjxlcjPWE0qXajDOQqxX66eIdQGlvjueqfEgk/yyu /lluzNpQt8QvfxtrvXXG00KX9nzbmyJr/k5DWMK/4dybkayWIXVLX+oRykudBLgHFQkj3PGmU16 rs7JXjRevKZ/i0YWvUdjCy/+RDf2wgdwZ9rc7U53MtVHtENPuQHXzSTd46ffMN1GY9JB25mLH8K u4lXpVNWlXjU6HNi3VF7JbxVDxVyIfO/aV1DJLxCsG6j0BlCJ7G6pXnbRcGjQs84qSIypw2CSgF FJMtcbYGOgfOSBg== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Kaustabh Chakraborty Some replacement displays include third-party touch ICs which do not report the product ID correctly unless we read directly from the product ID register. Add a check and a fallback read to handle this. Signed-off-by: Kaustabh Chakraborty Signed-off-by: Caleb Connolly Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_f01.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/input/rmi4/rmi_f01.c b/drivers/input/rmi4/rmi_f01.c index 47be64284b25ede8103ada86d6b58fd3a26976bb..2278e9b6a920774b07ec9dd3e452cedc69469be8 100644 --- a/drivers/input/rmi4/rmi_f01.c +++ b/drivers/input/rmi4/rmi_f01.c @@ -250,6 +250,20 @@ static int rmi_f01_read_properties(struct rmi_device *rmi_dev, } } + /* + * Some aftermarket ICs put garbage into the product id field unless + * we read directly from the product id register. + */ + if (props->product_id[0] < 0x20) { + ret = rmi_read_block(rmi_dev, query_base_addr + 11, + props->product_id, RMI_PRODUCT_ID_LENGTH); + if (ret) { + dev_err(&rmi_dev->dev, + "Failed to read product id: %d\n", ret); + return ret; + } + } + return 0; } From patchwork Thu Apr 10 14:28:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg via B4 Relay X-Patchwork-Id: 879928 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 8065728CF5B; Thu, 10 Apr 2025 14:28:24 +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=1744295304; cv=none; b=bEPgTOQWoZyv61oUOEKenAh/jXyLEIXIMyHLfbpExjMcCs4jjtBce/zDmcjTuteU4bLOyantQX89kIUN9mFl4Q8IRDF7wwAVB0NXsC9UvVCFK0BYBXR8ZeZjpuHMGLFHx5idW3Rt+gkZBO7IdE5VR4wGs1LOwDtsCFqnzFYpV6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744295304; c=relaxed/simple; bh=1m5MrCMQZzlU0LN1R3HC+JwbXbXfHGmK5U8Hi2uUEyQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CkhioTTr0oxyHRsvj0aBT/aWgGwV8r58QLBsK/aQ1K7e+gDnupq7h0xo6L7ZJqh3tb7hPa0GbLAWBqxi+rzdQtsshKriSruxgdsBqIfI84BoqkFiodbY09Kfsh6Ey8LysVripdwXMSK31DVp3ToAWpVoQ3myVR0q1jj5juNSV9s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gji7fY8D; 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="gji7fY8D" Received: by smtp.kernel.org (Postfix) with ESMTPS id 0BF91C4CEED; Thu, 10 Apr 2025 14:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744295304; bh=1m5MrCMQZzlU0LN1R3HC+JwbXbXfHGmK5U8Hi2uUEyQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gji7fY8DFeP004b5Iejv6FALlhgzP7dYKkZCpsLielfBcGg7x0arY9RcS5Bv7BKbP PKOUiX55IJhS81lGgm7HUAhDzwlgfb35f84dSDeTBdYd7JcM03OpxeA/4qCHr5ijOb yZZfLcr1sxcJJGV1C2+zdz1tTW8MeJn3W5Amoy+Sn+IqlSLQLue5whQ44Gt4/IECQ9 asgb2RxNc1/GpY+Ep13C9MbtEDy+8RTE6eW/fGJx6ehINkCbctpiCzqPURSE/9lMUh Wzx8G8YzRa2J+QFvH57QQjhTixX+A/74Ergciphqk8espJvWtHow5MB35r3uKPeZ8U p+IWVrLjxvfJw== 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 01800C369A9; Thu, 10 Apr 2025 14:28:24 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Thu, 10 Apr 2025 16:28:25 +0200 Subject: [PATCH v5 7/7] Input: synaptics-rmi4 - support fallback values for PDT descriptor bytes Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250410-synaptics-rmi4-v5-7-b41bb90f78b9@ixit.cz> References: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> In-Reply-To: <20250410-synaptics-rmi4-v5-0-b41bb90f78b9@ixit.cz> To: Kaustabh Chakraborty , Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "Jason A. Donenfeld" , Matthias Schiffer , Vincent Huang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Caleb Connolly , phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, David Heidelberg X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5812; i=david@ixit.cz; h=from:subject:message-id; bh=DYMCSRx4MYk/eiJZRVIbkMrJs+fsXN/6sXerZ8espFs=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn99WFILMWTotJJzfqkt07UciWHWfwLLcdraefK +eWaJEz1eGJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ/fVhQAKCRBgAj/E00kg cg6eD/4pEfQGtsusYNhAuIKQiEbi7zyY13QPhez7C1VHAsIblmK4vWf/K4vNcSdkTORNrEUqZxy MKz/eKGbDMEBRCWo4WwnmP4G3eq2pNy5VRjSNhVObQm/n9P0Zyt9M08gh76CZHPLhvsktHbzzKg uHQ4u2aYhH6jUlUS/8yi2i4Wek4piscVmFpqCnCQw28rTf8gb5xGxC1gLTKN4AcDpbyw6NmSjWD /AyAkVvNKWuSbZP/GiCWQmERhbtr1uK7aVH4RpEdRZrYdaKMDNw0aIB0tIiXTfy2i0mFfFWfDdK W060UQJVrLFE4cAlEIRG50lihHVk3dOEeTvnSpXpXgpeli6w48ZcvRxW9TmYpd8JW2MqnHj7Hz3 2RByGzUo3KoRDoK8AlFdl+CUmrJEO2E3oDXlsB1drjF6jMCDefVxnnxbcIrya/jQu8f8QpGzrxr hZVNh+5VOBiq0p/uY930OVlyyX1u8oxwhbE1NVkL/sBr0WiXmuTpRV/Af+GeckA8hzovcPrQt+n jRyHe11grMay0VD0wmhwmS+FgmmYXjx0K73lbCuQ8KelxNjYTUmPugXSxPybZMtc4TnDb8oVLVD sJagrXW+21t/ze7qW4JCRezbm7MHUbHi9KjEBKuTraYEcL1VBbQie9ko7I40xu3hRBVWXlswr/1 spMdD6yCS4HJvfA== X-Developer-Key: i=david@ixit.cz; a=openpgp; fpr=D77A09CFEEDC2BBD53A7047460023FC4D3492072 X-Endpoint-Received: by B4 Relay for david@ixit.cz/default with auth_id=355 X-Original-From: David Heidelberg Reply-To: david@ixit.cz From: Kaustabh Chakraborty Some replacement displays include third-party touch ICs which do not expose the function number and the interrupt status in its PDT entries. OnePlus 6 (original touch IC) rmi4_i2c 12-0020: read 6 bytes at 0x00e3: 0 (2b 22 0d 06 01 01) OnePlus 6 (aftermarket touch IC) rmi4_i2c 12-0020: read 6 bytes at 0x00e3: 0 (2c 23 0d 06 00 00) Signed-off-by: Kaustabh Chakraborty [codeflow adjustments, checkpatch fixes, wording] Signed-off-by: Caleb Connolly Co-developed-by: David Heidelberg Signed-off-by: David Heidelberg --- drivers/input/rmi4/rmi_driver.c | 62 +++++++++++++++++++++++++++++++++++------ drivers/input/rmi4/rmi_driver.h | 2 ++ include/linux/rmi.h | 3 ++ 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index f977541d8913525d53a59e1d53c33897f1c93901..e736e90c071466cc61a441bcb3061564e039bfc8 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -461,9 +461,10 @@ static int rmi_driver_reset_handler(struct rmi_device *rmi_dev) return 0; } -static int rmi_read_pdt_entry(struct rmi_device *rmi_dev, - struct pdt_entry *entry, u16 pdt_address) +static int rmi_read_pdt_entry(struct rmi_device *rmi_dev, struct pdt_entry *entry, + struct pdt_scan_state *state, u16 pdt_address) { + const struct rmi_device_platform_data *pdata = rmi_get_platform_data(rmi_dev); u8 buf[RMI_PDT_ENTRY_SIZE]; int error; @@ -474,6 +475,21 @@ static int rmi_read_pdt_entry(struct rmi_device *rmi_dev, return error; } + if (pdata->pdt_fallback_size > state->pdt_count * RMI_OF_PDT_DESC_CELLS + 1) { + /* Use the description bytes from the driver */ + buf[5] = pdata->pdt_fallback_desc[state->pdt_count * RMI_OF_PDT_DESC_CELLS]; + buf[4] = pdata->pdt_fallback_desc[state->pdt_count * RMI_OF_PDT_DESC_CELLS + 1]; + + error = rmi_read_block(rmi_dev, pdt_address, buf, + RMI_PDT_ENTRY_SIZE - 2); + if (error) { + dev_err(&rmi_dev->dev, + "Read PDT entry at %#06x failed, code: %d.\n", + pdt_address, error); + return error; + } + } + entry->page_start = pdt_address & RMI4_PAGE_MASK; entry->query_base_addr = buf[0]; entry->command_base_addr = buf[1]; @@ -546,7 +562,7 @@ static int rmi_scan_pdt_page(struct rmi_device *rmi_dev, int retval; for (addr = pdt_start; addr >= pdt_end; addr -= RMI_PDT_ENTRY_SIZE) { - error = rmi_read_pdt_entry(rmi_dev, &pdt_entry, addr); + error = rmi_read_pdt_entry(rmi_dev, &pdt_entry, state, addr); if (error) return error; @@ -1023,9 +1039,13 @@ static int rmi_driver_remove(struct device *dev) } #ifdef CONFIG_OF -static int rmi_driver_of_probe(struct device *dev, - struct rmi_device_platform_data *pdata) +static const u8 rmi_s3706_fallback_pdt[] = {34, 41, 01, 01, 12, 01}; + +static int rmi_driver_of_probe(struct rmi_device *rmi_dev, + struct rmi_device_platform_data *pdata) { + struct device *dev = rmi_dev->xport->dev; + u8 buf[RMI_PDT_ENTRY_SIZE]; int retval; retval = rmi_of_property_read_u32(dev, &pdata->reset_delay_ms, @@ -1033,11 +1053,37 @@ static int rmi_driver_of_probe(struct device *dev, if (retval) return retval; + /* + * In some aftermerket touch ICs, the first PDT entry is empty and + * the function number register is 0. If so, the driver + * may have provide backup PDT entries. + */ + + retval = rmi_read_block(rmi_dev, PDT_START_SCAN_LOCATION, + buf, RMI_PDT_ENTRY_SIZE); + if (retval) { + dev_err(dev, "Read PDT entry at %#06x failed, code: %d.\n", + PDT_START_SCAN_LOCATION, retval); + return retval; + } + + if (!RMI4_END_OF_PDT(buf[5])) + return 0; + + /* List of known PDT entries per compatible. */ + if (of_device_is_compatible(dev->of_node, "syna,rmi4-s3706b")) { + pdata->pdt_fallback_desc = rmi_s3706_fallback_pdt; + pdata->pdt_fallback_size = ARRAY_SIZE(rmi_s3706_fallback_pdt); + } else { + dev_err(dev, "First PDT entry is empty and no backup values provided.\n"); + return -EINVAL; + } + return 0; } #else -static inline int rmi_driver_of_probe(struct device *dev, - struct rmi_device_platform_data *pdata) +static inline int rmi_driver_of_probe(struct rmi_device *rmi_dev, + struct rmi_device_platform_data *pdata) { return -ENODEV; } @@ -1158,7 +1204,7 @@ static int rmi_driver_probe(struct device *dev) pdata = rmi_get_platform_data(rmi_dev); if (rmi_dev->xport->dev->of_node) { - retval = rmi_driver_of_probe(rmi_dev->xport->dev, pdata); + retval = rmi_driver_of_probe(rmi_dev, pdata); if (retval) return retval; } diff --git a/drivers/input/rmi4/rmi_driver.h b/drivers/input/rmi4/rmi_driver.h index cb1cacd013a3f39db96935f705f18018bf15adff..3b87d177db59591691a56ce7ac03dd2e8671421d 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -31,6 +31,8 @@ #define RMI_PDT_FUNCTION_VERSION_MASK 0x60 #define RMI_PDT_INT_SOURCE_COUNT_MASK 0x07 +#define RMI_OF_PDT_DESC_CELLS 2 + #define PDT_START_SCAN_LOCATION 0x00e9 #define PDT_END_SCAN_LOCATION 0x0005 #define RMI4_END_OF_PDT(id) ((id) == 0x00 || (id) == 0xff) diff --git a/include/linux/rmi.h b/include/linux/rmi.h index ab7eea01ab4274bfc9efcefcdb0cced6ec34966f..4ba2cefac85583a4ba65c70dca418a2c7c65362a 100644 --- a/include/linux/rmi.h +++ b/include/linux/rmi.h @@ -214,6 +214,9 @@ struct rmi_device_platform_data { int reset_delay_ms; int irq; + unsigned int pdt_fallback_size; + const u8 *pdt_fallback_desc; + struct rmi_device_platform_data_spi spi_data; /* function handler pdata */