From patchwork Wed Apr 2 18:44:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036387 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 D50C11DDA24; Wed, 2 Apr 2025 18:44:57 +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=1743619497; cv=none; b=HIFwRt8RijusZp2Benr/fYRFQSlyA6z9QAsH89sns4uMgGUoTpy1bjRuDZXDuR6CnOhAQc4W7LrSPm5vt7lNLr5+y37RO5rECJx+L1+n6L2x62Tx6JR9gutByfgkBBE0oqNfZhsibSjM+UN4QgRw2oXq4i3mLW0A+puaIAHk/dk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619497; c=relaxed/simple; bh=mt3wE+MsBBcGD6ggCzr43GLEE0Jjapqy0DoWPLDsuAw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dYLSdrTv4ontRb6T5Y15NmwKws0+O3FuJPQLnxJCXrjRaHIPEgJnw/nhF3y5AXN5j4ZL/l4OMDJtRzg9zfaVsB1YhRPK3j7xkOCX7YcOoJASv586CkKjdMpokLT5HEdO1ujWHm9BeoXW7ZSvHQFr+I44+3bF1BHY6h87BjyIAIk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aTjQKwx+; 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="aTjQKwx+" Received: by smtp.kernel.org (Postfix) with ESMTPS id 61067C4CEE8; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=mt3wE+MsBBcGD6ggCzr43GLEE0Jjapqy0DoWPLDsuAw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=aTjQKwx+buZ02HtwRABPJdnwleA8CsGGWvjaZvlTqVDp/DRyGCUqCwYshWz87fe2n qqCsd+6PFtiNKM9Z1yR5E4nOaxl4KgdcyvoNLqfpd8at/yOOHr8nYzFnGCdbM5cHaW Clk4XcfQgFxtNtA68b4H1jvlgdnSQ5lfMM3xF/lObq60qLgdFbLC4945rXgjK8emE1 58pb8LnL7LkwJs4a3QT3elu0piMo17/nSBfGNtjLbK7U/bWJfyyIvJPb/gieQ1IgvM qwXrT1HmeiuBvZtZgmyTF9cwTJJVCjxJqCqj0Hp+uEVZbCDepvLElFBpRCqLjJfwAp CRF4WjBXgfB8A== 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 46E41C36017; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:52 +0200 Subject: [PATCH v4 1/7] dt-bindings: input: syna,rmi4: Document syna,rmi4-s3706b-i2c Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250402-synaptics-rmi4-v4-1-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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=1244; i=david@ixit.cz; h=from:subject:message-id; bh=gIdWscr+Jqvsk707l9xEQnt4g2c2mNRlbPov8t2ekx4=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7YWmm94NXqofT7XHkun4456S/omngFthawuI/ E08x/7b8OSJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpgAKCRBgAj/E00kg crtTD/46/cU7EY2JWszwm4hLlXx6LZEpm+URrZCQpo2ii6zbwAdzRrWF8yaDWeD9zLsKB/f5XlJ G8tSJq1udn+CmVxZXtm/a2qMSAAddvziLcDKSl27NWgokHzdTEGVSCSrb/f6MRLbLVm1kgOraX3 bgzuBIO8RS4Bp83lx1Q7gbjoKMhALiDuQNfRJt1KOSpjuIq5H84sLmK49mqFbQEeBIWEOnyO09c mJKMZsnvyyKqU7A05axvB6jWOaLfdSzlJiY7ckFBrs4e9QcAA2FinXTLIUZWWBcEbgzaWU8sB+h NgvCrVxE1PV5GPJYf/XhM19o5kHfTe2ZFs/eaPCACCg3qYvkREYdCrodxPrz1Mr4KUgXPDPjCrY SqkgSbaEsZMAlTs+3BMbWVXVk8f2OrHu6vYF5qUMehUcvUFlAXqxC1rX2aXwONOSNE2eaOvdSy+ Ch3JrjWCazi1iWXcnCItGhvUjfrC4o+SLipmcqEUdBK5PZpyiEX19NB4nrzPviFBHltSCRmF+qK CUtd1fXjidYTDaITnezz+ekBLJ1wnVHa4G1p1fVIH+oDVRYWxeQVfIu//qO6qzDcA5qb+8oGWss bcwUTJvIj6pMf7m+ggEthsN5Htl6iW8QguRnyBgJxT4gXJOv9YxWmc1f6ztbd6fig+/ji8dGJzk +9P1xSsTgHaEelw== 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 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. Signed-off-by: David Heidelberg Acked-by: Krzysztof Kozlowski --- 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..855614718bfd1c6c41805d64e713cf5635c20f10 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-i2c # OnePlus 6/6T + - const: syna,rmi4-i2c reg: maxItems: 1 From patchwork Wed Apr 2 18:44:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036385 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 D500F1DD9AC; Wed, 2 Apr 2025 18:44:57 +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=1743619497; cv=none; b=og3n4t36t1+ZEm5ehSd5qfzBkF0UpRIeDkYOp9RwGLtxLV8VbJUzAIt1zCCpOi8Ly5xAaoUXBS992Tl3fkL7Z6ORJ9zYAW7vzKRT/KDQPdQaoOSsm3lQtypoSrmiTkWNbnVrC835Y9NRDWRYbwEc9ppldh3qGmnaqneVv8wZ354= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619497; 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=P7mtZP9SH32wznRJK3pHYycPdFwpH2nofhpXsD9atLtTkTpGFN2IrtXgGWSJAkulu51xeIsiBW9z+eWovNUIgOxRppQvG8nrFWAcmDDOcuwP1IUSeMheaAgCKqqLAiMLUoT7wJlYjb0uacrzUyMGTnZqoa0jolxAx0z+LyLNDwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gY9hDhoF; 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="gY9hDhoF" Received: by smtp.kernel.org (Postfix) with ESMTPS id 696F8C4CEE5; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=q6YqJI+AWlDUFmDegEVniY4d+tNOgVnSi2YYjBl+5n0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gY9hDhoF4cdox44fscQ4Bu4S9x2qc+iHmyg7UZaEd2f05Ifqh4D4DfZpp4JfTf5h+ B9Kf3jexJLKz+dnzZntZ/Sbl4/rLw6+64SDf8rM66nj29YZ9GO2rFMhFzrnVkDznyP tybrIoWwLzfVe5pUFqrli20ijQg5fH1IqQ9rlGomIqjMtFSN3/QzC8vytI/CbHyO+P 0pEMnGHl9KrwTcWG51vNYMOsDeNzzI8DRY00J+AY2cjsC+74kSyCqJN9eXH0gPWz7s 3ThPA68ZhgvMrmvc0npmw8VqAHUzvKF8tsBb1XOkEt4m+5VzY0XfVpBEVYrDPrjP4q DW3q7zSXnkOlQ== 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 5815AC36018; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:53 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-2-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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/ZANAwAIAWACP8TTSSByAcsmYgBn7YWmO4Hc0PE+CZJjHL+YhQvpWIIajYBURZxRc hDO3F+3J+SJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpgAKCRBgAj/E00kg csAWD/97CTdx8Q7cyYLSmGq1+4OjOSWi6WRr4jQbYa63oFEJBTNxZBmwdTfs75ftAFW0vT+SzSm 6CERhk3XmtRwuTjwNWLUvHVEgzFLfnZosNO7IqDR7UE6pToaoXiyPMS5mB1Xi7LJhAVr9gt7IL4 nddKHRU9DLq530D9otpUeIK7xDSwvLXEiCKNWbN/mkotkL3rhbdAQR1cmunDpTxawI6zoz+iz95 uzklp6/qNSDdIapkoa3cyk/PjGeoz/LiEjcjXRKFgvmTCxycYeSXUltnhK+rlSoDjWpwwVKeB+5 WqMPx1xOvrWTzLYrgAjriCg3tJ/69hgcHD07n8akgRxOqnEdvnfP+rQyyr0EhyeJ89qXXdpZ8ab gBR5RZCVzgK7xU/L9FG2+A9Ciw3Ot29uY09/d+Pwm2g/rctv5ePyX7VFEZ4oRYzFVFxqHpmuftu ftep17eGcy+MwXyb8AQONur9MOBYiaQGEBbV4HHkre95MYEGbXvz4sHBG1Q3e3szrGx4TJ50xfx VVshu9T9fG+MIt2zDfKCRClMBFxB0VuotLcQpJG2dVtsSlQm4CCKWAby29/XEf4ID4LWC6SxK98 UEl2MLqWamAxm6Hy79Cc0Q4QP0a29Q5gclmDwzOL5yWdT5yztTIzlmN5TEqTJouCIbkexCza6Sv bTF9GMP+89NfKXQ== 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 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 Wed Apr 2 18:44:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036388 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 028DB1DDC28; Wed, 2 Apr 2025 18:44:57 +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=1743619498; cv=none; b=kW0cO9yt4EPcqR7fb65QGu8RBlTVrTjQ4Al3GLKKIMquXrz3WPICDFtsMUyQXzMazLAjCEBnKJ02Iaeldc/OOZEP+O4LVUQQLCQs4Az3L05+qztre2l3hCMuFX1Uo0cEX/3CIYZf8Wtxju143wcHTCqsuVPXnlu3HFJZthQ0ymc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619498; c=relaxed/simple; bh=kX0Z61P7BjNy7WhJ24tC3m5Hm2sT157SFCHC9z9ZvXk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nog2pWORdShXRDwDevlvKRaIRpPrk77kHG0qn7THMHoFVzObxd9u+9iyYJum4gEopv8e6wxMJ3+tN0O9/fvLCiu8Vn0uDLvijNVJOLq5Mo7SscqR72nxlO2mMHll+xm9fHFhtwYdtb6esQ9RSpjvJxEuHMa0GQqirP1AZDiJnk8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XE1n5gAa; 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="XE1n5gAa" Received: by smtp.kernel.org (Postfix) with ESMTPS id 72F4CC4CEEB; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=kX0Z61P7BjNy7WhJ24tC3m5Hm2sT157SFCHC9z9ZvXk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=XE1n5gAawQvSpKPpaasw2Eg6t46J7JoUkteO2/Z/o62ui4D/Pc5nPCH2MDpYUGQhG n66QX10Ftn6DB9tuUUmf2k5l8X/fA1oQ67JdkQU29B7947KoYMYDJ7rpdIhMO6D6Ru gylTPK5aUgZSeqR5XFM5SfzhDPIxfe5QxlG+da/9N76LMwuPuAQgMUb9lM5T2lxmlV ZlB/2UR2jRTzzLiuPuke7H6xcUUwVzxd3AGxjBDmRKbK1kErgveorUuekgfZPuY0WS VqS4NgWGqgn2QrtcUk9mYpk8tZRDFDUmfnp3Uct6xvA5FYCZOFsHCjSpCQl+kJ8cuK ngZOa+LY+1IxA== 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 6690CC3601E; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:54 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-3-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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/ZANAwAIAWACP8TTSSByAcsmYgBn7YWngj1ns0CAxOHbJ9efKV2uXbhLqJhupngiJ 6h8j0iyzguJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpwAKCRBgAj/E00kg chk1D/9FIoqtN4bH/abCeTMRA0wYm5CldVtJHv2/+YnUcjvN1SVldzrTvwObXtjiWHoOZzmcLUm wa/ArFChF/gGf8mhzEN687vGYk772rmxy7y5U3V1P14Xut8DtLqGg7Sn1JM8nfiQc+nF+tK66jK +EekzfdUpc+JB0W5il4FZwtfojRMHzadxxTHoMCamXs1XrdIWqlnuDcXU76BW9/sUvlA2VFBJMD 6Yx3G9shs5nwL9TcqcsXc2BPTN/hrXLYMfKstJJ4Yz3La6QUrNlDCKu6bVTiZ4eiHVKLO6NUDwc Hm7k3mteaOWYMtayz5/euHwX5vpPKQdpU5xhY6Pq0cMkbHWquUfkTYuiPnvyYJBIX8v0XLXf0x0 MIWfF7pLhYq+E2/dMH6+1RmY5jsDO/C7nxKDhmjYTPnJosrJTUNWfgOS7hydIE4ft5nyOp2Nkgw slFta1D/VKAyBoPze08p7qt26k2IUTeXePbHSYrqv3ujtWyqLMZ4orZ9eFogJFLtCExLYT0DJsq U4l+14IlmJbE7zgnwjQSGSfoxIasWOyaztULLe5cYrR3GatwPH2+m/ezGNSWXdDqxyZgZbk0NQ5 GzmVa+LQMRVDumvDDsxywEpQM5T8KQbrCHonh8NC2JvqDxMdDrimLgnSTLsXrX8JwWHNyWCz0rW c48l29pt+2vdFrQ== 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 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 Wed Apr 2 18:44:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036384 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 C54B05C96; Wed, 2 Apr 2025 18:44:57 +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=1743619497; cv=none; b=DtDkn/FnNEopL59rXNqwdFIrSz9YI9IITDJmQCNxJ4oe+o99vM3x2Veo7T3iSlvyj5QYnK9qA+w6cJfxPjzF63kOW0rahg9FG+CfDBuQ90oD1c6rDY+jJaeUu60+0GFh4JTPGXmKRaEsH83N6sPNLOgo1yHvSrNEwR5r8lwmVBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619497; c=relaxed/simple; bh=K6/VEo1yc3K+YbVulpek7YWtEuSKS3IBBhc0oUdWlo8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E61Sa323tyDnHaP0ujvxyRzmGCuqmXG+xq3cobPx/3DOgdqxnOi96hIynAHE41cptNs+/A12u9vsb/CB3LjhB5snnt+cb3DD+JSP1haLWqTiYvWB96Kt0ik8lWiLxtoeOHgH1vv4ioXg2Hoospykebtw/1O+6H72rWVIIR5pVIQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sv82GQd0; 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="sv82GQd0" Received: by smtp.kernel.org (Postfix) with ESMTPS id 86639C4CEEC; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=K6/VEo1yc3K+YbVulpek7YWtEuSKS3IBBhc0oUdWlo8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sv82GQd0NWtWYQv9eso32IBO8fwiisUdxX4teHgHM323MUtc7qhv5jKpqM35GK6mM GiJ+q/o4KBk3Dwi4r/EgyPniymzstEOxqYkuFJD4nY+5sv6pcAV564hjKjWRyo/Y5v a3de22M3lpKns0gfYKeUXe9TImvGMrSk27BVHTHIzOBI5BSUCVuq869lRE4fcD+N9a vbCIsO0yp5NBAVQAiPpfjWgmhguKvIA71X4+MGj1k6Y3ItjrWdzwriOaQjE4Cfs7no 4kIqwFhGPrhxlzXvdwM8g0hF0QSYdHoloQrqXSno0mmdSFTcpSm3GgqXZDecQw/j7f aPd6l2O4Dfg6Q== 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 77797C3601B; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:55 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-4-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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/ZANAwAIAWACP8TTSSByAcsmYgBn7YWn4JQyFb7VhDg5lLgW60stVOWrBynm+ok1A na4mWl3IM+JAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpwAKCRBgAj/E00kg clq1D/9DsKFFzs5oylrtmlIOR9XlaQqSEQDBrlgF8OFfTswnh95jneM0QWsJdXt4GCOZ7ydhaWc XnRFAFk45zSU9iZHgxYjwWFxFV6mKP/eKacB2f+nEmX01Qj/KcKgeYkPAQybnwUNnoWlnHR9PSn R+ZYkVH5YRbkRLSKsnTpWz/UX7/tkRiH5Z4aRD4iaqwpRPUSMZW56wcOFy53Em+cYsiDCQLj9Bd nkKlZPzkGBzT3euAHy1+Ut/sIIKl5vfQSNbCZb2rz4UywBtE3yORM2YWjPViFQMFio6gG8NovD7 aDdZ+BEXMT3rNf/xopKg1hdDvoZAlCuIEAZq9O80LdlFagZnMAeGE+8fCco/AOalFmgeliqEphQ XLWL5cIsiXIhkF3Zj9C2srrV/Ez+xF+cHzhoFsPqnySHPI21TCHXCJkNhodmj6hhqWon8wJR2rL 7Pgg0mCsHzb6R1cPPHyH2xawSH+nrj5dsFjXlDYMwtsVW3axa8fPVzd1bPDkC2P8q7UTy63ioaG Zv7IYR3pY0dDgQzbjgfMNe+64QNQKhNt8nMiTaMrJL1S4osbgS0f70EEa8cpg2hpER42XvIw7bS pqXa3EhOZlm9bS3wETzyMLeCTGpi0/zPWq36FGDa5V/WqP12TxBzfm57f4Rb9Zl8QKQZ6vKBlv6 wsdP8Ld+wY56Esg== 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 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 Wed Apr 2 18:44:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036390 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 6AC3E1E8325; Wed, 2 Apr 2025 18:44:58 +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=1743619498; cv=none; b=gagKSSmmIXfkt768kycaXn1wCriGUFaoqECjdrwbGTUPMVs2jtFbS1r/mA0/XRiaPu34bIPr3b4Hoy7fXEVE7mnOHHPaHwLXPwK1eWWZVEznRpRgFmSzTCpf1Zu2O+lRJDFuAMzBd0M3T94iS2UZnVYzD9yR6nn/aP9bUolTaf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619498; c=relaxed/simple; bh=uhoOYFv9own1t9GTd9uKLCLoHj0zKUN854bDbom6MDw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=diCKce4kS0nW9kOPXNU5pUTlTYdLqKsMFdVTJowqQmOkd70U7V4nQSceofzSOSubg9mJEhEeCRGNWqQXgvggRJ0gLeAX8v2Rjo3BYgu0bb/z+ckLp81dnYhaMnDHHEW60rWRJWY/QjvjNJeSWo6sNUQlVl8xFb5XemR9G74ZWiU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LhbQ48vq; 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="LhbQ48vq" Received: by smtp.kernel.org (Postfix) with ESMTPS id 93A3EC4CEF2; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=uhoOYFv9own1t9GTd9uKLCLoHj0zKUN854bDbom6MDw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=LhbQ48vqPyqmnm4ABxJmzcEECXHYJmjXeI0WF72JhT5iRDLtHsuIbFh8jwQLNtvMJ 6zCPyHnDxvdjyLBNCaeCIzKycI2CdEJFRPSs4msxBN4MO3VkFFeFMrSj5DRfavxInF tQiVJm5rl38Heg8lUoq8RiOTFil7OCKPyMgj26CwvKytDSJNT8watJj8mIocOzH0+Q M3DWdn/4vA4SyO5iTeIYvh+qU/oVHuFruM7lj+z9g+RsMOTHntXJxEh45HiK1F/FRc BmNnPeRn8r7aImg8OoT9OvbRcOsHnXFh5L9wDPp+5yFMcgQsY57G1GBAG0ECfqx/S2 FaJu+7cjp3+DQ== 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 8906BC36017; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:56 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-5-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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/ZANAwAIAWACP8TTSSByAcsmYgBn7YWn/MP81rV9Ai3YBRmaVNbv+GCZaR4aqY8Z2 7jKtV2jv1mJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpwAKCRBgAj/E00kg ch3REACV+Sw+Ehcsl6co/1yutsFO8jpuFKCjDFYaX4X6PuILT97X2sBpBeAKvgyNFcWy681SsSe zPDFNVwnh5jAnAHdvCTqPV8GJToSnkdSgQzsBsUfVbGAq1ZY9nnPcSWOAGwjmR3RHRZ7mpYWkEN 7lGt9njfD/bj6iNIv/HtxgMgMz1fXBH/9FlbcXo8WZrHIUtPx1RcM+6vW0hiUgf0C+S51jh9BRr BQt1BpWuFcDEjOXNW1h4rFMmpYtn7iJdzCTSfcdVfO7ww3F9W8+bnpTroW9kZo1kc7EmxYautjk hH88dXFZumwqNxV0xSwvbhDafbf9HmbjmNsqNjdUoHAWReSiSoOvbTFBYKWxPrOp+IeRDJUWvBP GqBVzDZr+XW5n7P0EUG9WdIoOuveOCEtYE5jHSkdRjRedi0EeZpuy43sfF5/0FvhU1JJHWk83la /Uiz5Q2q4zqRLWlCGei4XBZEoss81akGlx5G3ueWV8ei/bfngI7v/OUpwz/GEoNGxDblf1Dacpp MEYWFWWphPMPdBU9Ese9kb1QSa1sY8vYUkii8r62AqOL5K9Vcw1RG8gYPSXvqZDnVGjA7YcF+lR POKMqFWZQjoUQuL5p3eJZYQRZnHACAINO79XWG74qPBQLVlM4mRBKh5Fo2At9MHhq8L4WVPLLjL z/sYSD5zCZcG92g== 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 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 Wed Apr 2 18:44:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036389 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 1460C1DED49; Wed, 2 Apr 2025 18:44:58 +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=1743619498; cv=none; b=CMmJRxRFW1AnyikTtz/Ngi+09Y9IHF1V2Y1t+p4krjL4EiWiNoKl+43y2us+B0ok5BICwK9nPFR0ZeLgMFkiV+5Rynp/G8sjiOzk/NDkKKXzhulxDwi4qPvFOitUaVQqSxnbG0YH+6J6Ni2mWrpBECLuvh9D7yN11SesXsqJZYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619498; c=relaxed/simple; bh=HeOIUhogeLDXtT5wIduDA0u/HH6Hvijhg5yr5b3aZqg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=WwNQ8glB0ZJCw/ySOW6u5Ibm+XkvHvRUXbh11se2hI8wjACBqVnkgNyuu7KxrmYhqVzRg6wVt0gNjWFl0EYnvCRy7TQxpjiQaEA5oUdRcZyD0C2P2LDEt8kUnkhKQu3q4k/Ki50pcreNbRNhSVywg9NrXyPp+52Mjq8VJYOAtbA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=myPVDqak; 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="myPVDqak" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9F3CBC4CEF4; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=HeOIUhogeLDXtT5wIduDA0u/HH6Hvijhg5yr5b3aZqg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=myPVDqakZ0IcQEnFVJurgfa4Ml4AoEpZ2+Tg+6GO/yoByjUwnUdbgOuaziFXIC7kP ERc45NuZTCxRsFnG0UCGvE8jnlT9uW8mkkvBXMzJSNr9WZTSOf9ONYumPnlJZzkuXz Y2Tly/5IV5iTpMrUuZh3l+anm5ykdZD4gURe7hp9/lvU9eX6AmZ/5mDikKkpBZ+yF2 dUzTjzFC3gsnjrXiVPPM9tYxWYSy0qqU6Fp/1FhuVt/LPS8HAelYmzIHTuXNpKBcR5 ZL8EAYhJX9P6E44ihlM0tGMSo8wACsXNyKHzfBtSeUH5AXDtq4yLSstGS66Z+ybA/8 H17ivPodrsTZA== 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 971C3C28B20; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:57 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-6-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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/ZANAwAIAWACP8TTSSByAcsmYgBn7YWnijG6OkcpTVIBmk0cKl9KKtjytMDZK+55T r2VjtipXtuJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpwAKCRBgAj/E00kg ck9nD/4tAdYAHLj2PTxpZT0SmmwgTSLss693LlWw6pZ/DiJx6dMyfIbrMOGqOsV7upY/YQGCrIQ PCBRh9JESfzUeB9uiNAUO0adcoDtLTktyRocx2usFlfQBN7PbTaavx00E1T9CFhnjGMdn7lRr2B +akyv8lP+arIBOF3MddHwVLWUHRJ5h46iOruN+pctMWWq6Orhg327GOyeheIlaUDhukszd5cZZ9 r18qYhBVzHStD2mrLzx75tiFB08pPxscYp9HqgGgXCHGT3kw7swVV8sBFypanbKu/s1HGih+F0C WAnWUlZAoVPgTc0bsRWUET6It/xxQjLfKp4eyBsW68EOZ5khnKnd8XyIzx+W9wOdXbMcC1vCOeh 2W+ptlfcyoMXfe5P2vuftNG+AamXz4dgksgxDkQ7Rt7ny32wjg0L+LJUeSOSovveH2jJLqsW25w 4JpmBeVoijv8tjhF2GSppJY+7Awzgi4inLtG6e4/zgi4ugICEwek0T9pN/BMxlfmI+uHRyH/uu3 PnQT5u68+MUwQccZ61wluLNjprqfON+lQAkJ0sXnDeR7i02KGGF9afEs8JwYIe87NTg0AtavEbz yDbRubuG1fJnoz3LZQQPDgNq33MluebvGmmwV6pKcByBhdLK3xgEGgspoRce5bq3UIBbDu4+Uot /Atyu/eJSZ+wduQ== 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 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 Wed Apr 2 18:44:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Heidelberg X-Patchwork-Id: 14036391 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 6ACCE1E8326; Wed, 2 Apr 2025 18:44:58 +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=1743619498; cv=none; b=DBL7BjVNapoDqMJ6B5OQjkkaEqrnMnCzLt93wTnZCbkcmvdSNgfOO7D1UizM+HZKmIh2S/4ubT8FV0XcmIQFPO6ql/yJuXIwTowjqv0E/pSidcNlR22ME5ur90q2ev1lfYysi2nBaKHKZxmcdl3Fx7PmW+nhZ2RQJuvYV4+anZY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743619498; c=relaxed/simple; bh=KMXbP+d7+bUNUhZApv2XwquEnkouU0Fyg4oOuo4wt/0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=TyokfhfrsQW3CkFAnE6jIHKRUZZJ6VwyzKrR4WCeaGLENIoId4l7OC/ChGl3Rm8hETxmD6o/s6BJL4crRZibGosn0J1KOFNYkehoE1PNojJiOAzKF7awOb6ddTA5TLhNwChtVSXbGRwkCTUc822VlovKk6PLeiEkoA18/uBd9XY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CUtf6z6e; 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="CUtf6z6e" Received: by smtp.kernel.org (Postfix) with ESMTPS id C40ECC4CEF8; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743619497; bh=KMXbP+d7+bUNUhZApv2XwquEnkouU0Fyg4oOuo4wt/0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=CUtf6z6e9T9+j4eNY5YfF/ur0Zuxj9Yx3Ns2stefkoZLEu+OMDwPZEf4j8i5UYCA+ G64bIXMuZxFZKOaYcuSIrtvNsddWTgAElsCBv+aRp2CI6td3p1wJl94r9bR+xMCtCz 7v/p57WlsALea4e0Tge4r76G3176bH1+t+qGINHdO05tnQuPw6J/9WguYl2M6kxoLt 0I73goXEhGADSHYYxuS8jmTncrK2h89Acy1XdH/72ZLsVOkCZKlbNCBnm12b0woV8E glpfo+ITs3nLTDva8fh+DUOOXZZpTxzwLDnmizVfj8VFD13784QUVfG13uMB2/FT8X PL3ZqX1R/6YPg== 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 B4379C36018; Wed, 2 Apr 2025 18:44:57 +0000 (UTC) Date: Wed, 02 Apr 2025 20:44:58 +0200 Subject: [PATCH v4 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: <20250402-synaptics-rmi4-v4-7-1bb95959e564@ixit.cz> References: <20250402-synaptics-rmi4-v4-0-1bb95959e564@ixit.cz> In-Reply-To: <20250402-synaptics-rmi4-v4-0-1bb95959e564@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=5816; i=david@ixit.cz; h=from:subject:message-id; bh=EcnHIzziNROnQaxWGT3erqWPMO6vAK4Oqsl/ftYBi0c=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBn7YWnOzMV3HgrAfN+GoFvV/Fx+6QcxQAGBpmUu FGt6iydKcSJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCZ+2FpwAKCRBgAj/E00kg clLUD/0XOrQnjtP2kt9S9fbjFSvHd0BGnFvwKLUzck0ZwPg/apmpOVk9p1SeattLZC8MTV4pWGa /pqukhazj7IggULJGii/PbPN8R3NfCfnT6n6BjmbRUPs4WVSqnFd1yK0ssOq7KHXBdM0YXq/mop tW5JtREu2lL2KchbTjNtSdqupMaVRw+vXphZD79usy/EhOp11kbxP1c0iUGXk5yLQruKND2GOd4 KJ8EmJrVD6GCcwWGokaReNP4LMQa8Z2g+Zse7VqtCWccExm/7Pt1UOmlzDbk5LoCtNMAlLAPZtW KQSwxeJaqgrbJ1VyGcbQnmT/xG88uAr+oCfIg2eteZXDFTT6tBHcPP/v1d466UhE1evfY7FW2cg xvJGMgsv69+jPctj3/gV4+jULauIk6n88FGNuJMYTzXXTx5Vmw3L7QTsp8ko8v8UMA5KEnwsMrY 85THojSWqlRM4NzY1+/TMt3WabQG/fPrUro0rEOTlDXanEddPfYOnbMzkCSUeYLhjJ9GYqx28sU zQ+jOTtd1dGwhe33G0Z4DMmxkUgA5n81tr5jeMwcH31NvRWvlKViZK//DVG/ObgDlWORiLVSE8Q of+G6dIlW5vCs+5Cvujw3LuJCtO+dhMmmyFQQOGMFEd4lMmQ2IuKF23Liw8veqTpsMgQteA6wyH nFPSGsufrMDyR1A== 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 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..4f81360bcdb8c1e28600436e40888aa68aa309c4 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-i2c")) { + 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 */