From nobody Tue Oct 7 03:47:48 2025 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 D06792DE6E7; Tue, 15 Jul 2025 11:49:12 +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=1752580152; cv=none; b=eHW6Oag86nTraAdcDnyMh6l3qxy55rr6CfylkJ0qy1Jjy2bj/Pvt9ACPLh45G+WJHmCnkLEReXfqgGVeCBkCTfqaZWA58OTN/UvxVYjmzjYdtSIIjdSWAJ3xMUWUs1QB+p19rLNXmndSUaob9O/zeT+ckiHuci0W91cOGfHus5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752580152; c=relaxed/simple; bh=M6+o8JpQ/TBL6a2gpDPsjQMBcB0dz89E5FugIoYP1mo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jMF2rvG1D+keLbBDDZNY9pFkAneIu1uyBzmP7AoWa/9oFwq7fj/nFqmviGLZCXbV45v7Z3grrZAUHo3YFU5cfTFWl2+weGk0VvFilJq9KSJPC2eALSVKW/R88B5LyI3/iShV6hNN+WlX0WRcLrKxtrfTxzLhmh3MJTg8ue6B5SI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lXxMN+Xk; 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="lXxMN+Xk" Received: by smtp.kernel.org (Postfix) with ESMTPS id 75A54C4CEF6; Tue, 15 Jul 2025 11:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752580152; bh=M6+o8JpQ/TBL6a2gpDPsjQMBcB0dz89E5FugIoYP1mo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lXxMN+XksVSJoCqF1rNTcv018ElcLpnM7P62UNDySUzJb5c2xXnhfhOuCUE0OinOq cYWmjhQrwyJNOSEYk3wBVpf0QGwGEempE3N2QXTpyw3XWt8/8uemnyjqzf0ZQ4ybFk jtWyBeT+byLb9XqBbevB8AZU5MOqaxbQ7lD5MFulPjKwZMYAnfRpjYGfzviMItXM8/ QTqMBexj1Dfq9kh5k+CjleHksxiCRumqMLE7pqEhMjBGXMELlBxH56IT2g7j7mWmdX uyvZvSZkrNGLnmZKJQBmCi2foS4OLq7qS47qHJ7SWfjADFWh20flz7vtPg6W2yiJPO 4g6oWwgQc5qcg== 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 6D114C83F22; Tue, 15 Jul 2025 11:49:12 +0000 (UTC) From: David Heidelberg via B4 Relay Date: Tue, 15 Jul 2025 13:49:06 +0200 Subject: [PATCH RESEND v5 7/7] Input: synaptics-rmi4 - support fallback values for PDT descriptor bytes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250715-synaptics-rmi4-v5-7-ca255962c122@ixit.cz> References: <20250715-synaptics-rmi4-v5-0-ca255962c122@ixit.cz> In-Reply-To: <20250715-synaptics-rmi4-v5-0-ca255962c122@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=0+m46Sy94J+PlGPLtsegoEaaqVZ3KHZFG9gM8kTZvJ0=; b=owEBbQKS/ZANAwAIAWACP8TTSSByAcsmYgBodkA0IIENa+SrSLJ5/Tk7T0Jj60C09EJPvIBv1 2/gFXC1tMeJAjMEAAEIAB0WIQTXegnP7twrvVOnBHRgAj/E00kgcgUCaHZANAAKCRBgAj/E00kg ciUPD/4+/vOvVXAaIP8TOcWs1fenDp8yhZZp2yxAet8IENccLD4DCLZeaN7zdpHLLdKEkiBdsiP D8NyxD66DHYnPggt+BH781op4huRR7sGvunlf/5An4mrmYL/X2fo5MOCXyIf/agDDW2CxRPxvhN Lfbejmvu81hc1hmd3vKmRvJA8pQlteqS02TVDPq1DupmLbqB2oifafPHxkTbU9PFw/M0iCPlF0Z xRc4AUhPC5U7szZcfzFHC+Ezq4PL0GyqaJo1vA5pxwwK9EtSckYbFxb+gK/2NsLoI+KDMsaRZau CND90bRndZepyuUbVLeA40T9cctWhdVsMeHJhzZ4Qmn5lqix+UgpeJjRsLcTE6oHr7NftFaq9Vf 1AIZ1p1OPcshImycPjsXCiQ3y4hmF7wkNOzft+PiP2fkQPFOV5Jd2eIeiMkRqBO1SKtk5IJzJnt LHxJQyPtQ7JCXReMJ8EvoODReICjlXhsuzITVr2Ky/7WhPCqmenJPBbXG9vaB1Od5vAQtoNraoG h000GXYLb96AtaHKKpf1eWEoELfHbTTZVVHUm2pP4rohAHnZCimV72NvTEaOC4U1R+Teir7wmDM GkLyJkDzYFWG6jDvl8d0wSFT3gqVTwbI3SCW3cNmYPaxTslCgqvBHi8Cehg9nBrAF8rJY5487zf EVwSCRFlmW0xR6g== 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_drive= r.c index f977541d8913525d53a59e1d53c33897f1c93901..e736e90c071466cc61a441bcb30= 61564e039bfc8 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; } =20 -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 =3D rmi_get_platform_data(rm= i_dev); u8 buf[RMI_PDT_ENTRY_SIZE]; int error; =20 @@ -474,6 +475,21 @@ static int rmi_read_pdt_entry(struct rmi_device *rmi_d= ev, return error; } =20 + if (pdata->pdt_fallback_size > state->pdt_count * RMI_OF_PDT_DESC_CELLS += 1) { + /* Use the description bytes from the driver */ + buf[5] =3D pdata->pdt_fallback_desc[state->pdt_count * RMI_OF_PDT_DESC_C= ELLS]; + buf[4] =3D pdata->pdt_fallback_desc[state->pdt_count * RMI_OF_PDT_DESC_C= ELLS + 1]; + + error =3D 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 =3D pdt_address & RMI4_PAGE_MASK; entry->query_base_addr =3D buf[0]; entry->command_base_addr =3D buf[1]; @@ -546,7 +562,7 @@ static int rmi_scan_pdt_page(struct rmi_device *rmi_dev, int retval; =20 for (addr =3D pdt_start; addr >=3D pdt_end; addr -=3D RMI_PDT_ENTRY_SIZE)= { - error =3D rmi_read_pdt_entry(rmi_dev, &pdt_entry, addr); + error =3D rmi_read_pdt_entry(rmi_dev, &pdt_entry, state, addr); if (error) return error; =20 @@ -1023,9 +1039,13 @@ static int rmi_driver_remove(struct device *dev) } =20 #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[] =3D {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 =3D rmi_dev->xport->dev; + u8 buf[RMI_PDT_ENTRY_SIZE]; int retval; =20 retval =3D 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; =20 + /* + * 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 =3D 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 =3D rmi_s3706_fallback_pdt; + pdata->pdt_fallback_size =3D 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 =3D rmi_get_platform_data(rmi_dev); =20 if (rmi_dev->xport->dev->of_node) { - retval =3D rmi_driver_of_probe(rmi_dev->xport->dev, pdata); + retval =3D 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_drive= r.h index cb1cacd013a3f39db96935f705f18018bf15adff..3b87d177db59591691a56ce7ac0= 3dd2e8671421d 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 =20 +#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) =3D=3D 0x00 || (id) =3D=3D 0xff) diff --git a/include/linux/rmi.h b/include/linux/rmi.h index ab7eea01ab4274bfc9efcefcdb0cced6ec34966f..4ba2cefac85583a4ba65c70dca4= 18a2c7c65362a 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; =20 + unsigned int pdt_fallback_size; + const u8 *pdt_fallback_desc; + struct rmi_device_platform_data_spi spi_data; =20 /* function handler pdata */ --=20 2.50.0