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 */