From patchwork Sat Sep 30 17:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405173 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADC1FE7737F for ; Sat, 30 Sep 2023 17:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbjI3RJZ (ORCPT ); Sat, 30 Sep 2023 13:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234573AbjI3RJY (ORCPT ); Sat, 30 Sep 2023 13:09:24 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65225E3 for ; Sat, 30 Sep 2023 10:09:21 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40566f89f6eso124990275e9.3 for ; Sat, 30 Sep 2023 10:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093760; x=1696698560; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eazNkVg7ZDFPpoUK8MtMolTuUsmUKvo1Fk2+nn/9tis=; b=s2ijEURJA29nMB/sPvmwsqxRUpnTWdNNnV+2r7q3wbfPSk9dL0ieBOpJ4s6xBSVJdz mf3ULkfjVhEle4zlW6mAz0I3OHRO3Uk7tj8kYCHHQZuSv64NLrH5frDWri15ltjDyT/N hGN2Lmh9AmUYNm4Wc9p3b7KbvJxqkprpZJlLpjs4PU4wyIsYF7O8htwm6gJD2IjYKasb r5dQvoD7RuClhZdXEjn8cdGk8GJ4mj2f1wwyspXAY5jrPJEv3+6e2uqf09T6q4e5qO6S lCMYmA07uwq2YVvulv11XbZ+BbC5vgJi+f9HSjVnSOfo5arxi+pteQCOQqZ7qaYPmYtf 92zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093760; x=1696698560; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eazNkVg7ZDFPpoUK8MtMolTuUsmUKvo1Fk2+nn/9tis=; b=KF7KUtHbT7JHws1F5AHNf+pdhE2+82HwfOe16bregu5HCuWoGJuWoiPgUAOG7DuGyi rRfB6YDp6+8HvS0YQoAPhlogRR6lx+LTn0xb0yqh35LAF3Eec7s7Rh3X+Q+g1pxAfwe9 3HZY7QjQDow62x4LznYo8CEe1u3ToPVCtMOq4X2dzBdNTdKzsOZQncCGc+ySuQyLMo1z afFljCCCs96/xa99bp7f4eSWc/K5mbTNK9mXjbC7qrLtdu++kV894KUj+UTjw93SNa/P hFduQ3ynXoA5U9ACtVpkWCh1hGr3CWsvNbc1vwgqIl3xduR3ETJcDuSshLo2SZUmdQIW 5pfQ== X-Gm-Message-State: AOJu0YxeK12jVPFLnXTGS+J6wTFP2RG56Z7v/cfoNq0+fvOAfitNwEMA htC/MlDGdksR3eSBb5dMXp5lUQ== X-Google-Smtp-Source: AGHT+IG4DP0rG8hSbn5vGlCzsZaU5QmzvewNIjlkJTKCQsqhf7QJQegEomHzUZFdmFtXgCazDnxpwQ== X-Received: by 2002:a7b:c7d2:0:b0:405:48ba:9c with SMTP id z18-20020a7bc7d2000000b0040548ba009cmr6919155wmk.16.1696093760000; Sat, 30 Sep 2023 10:09:20 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:19 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:45 +0100 Subject: [PATCH 1/7] dt-bindings: input: syna,rmi4: document syna,pdt-fallback-desc MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-1-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly , "Jason A. Donenfeld" , Matthias Schiffer , Rob Herring , Krzysztof Kozlowski , Conor Dooley X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=1698; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=5sBJCQ4u75bNy25N0FjR/mDIgxMYqHIB2eDzShxbXlc=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMNuTgaXNiiw1DN1ten1naj8/lY/MfD2nRrnn6jKlf YtOrEjuKGVhEORgkBVTZBE/scyyae1le43tCy7AzGFlAhnCwMUpABN50cTwP15DgjeR5QTngvs7 gnnu3lojst9U7/9t/fKtxk803O/svM7wz3TV0wX69xJkbvPpeJk5OkZ8LZwkwXjBPJrJNaH7hPa qgwA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This new property allows devices to specify some register values which are missing on units with third party replacement displays. These displays use unofficial touch ICs which only implement a subset of the RMI4 specification. Signed-off-by: Caleb Connolly --- To: "Jason A. Donenfeld" To: Matthias Schiffer To: Rob Herring To: Krzysztof Kozlowski To: Conor Dooley Cc: devicetree@vger.kernel.org --- Documentation/devicetree/bindings/input/syna,rmi4.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/input/syna,rmi4.yaml b/Documentation/devicetree/bindings/input/syna,rmi4.yaml index 4d4e1a8e36be..bd6beb67ac21 100644 --- a/Documentation/devicetree/bindings/input/syna,rmi4.yaml +++ b/Documentation/devicetree/bindings/input/syna,rmi4.yaml @@ -49,6 +49,16 @@ properties: description: Delay to wait after powering on the device. + syna,pdt-fallback-desc: + $ref: /schemas/types.yaml#/definitions/uint8-array + description: + An array of pairs of function number and version. These are used + on some devices with replacement displays that use unofficial touch + controllers. These controllers do report the properties of their PDT + entries, but leave the function_number and function_version registers + blank. These values should match exactly the 5th and 4th bytes of each + PDT entry from the original display's touch controller. + vdd-supply: true vio-supply: true From patchwork Sat Sep 30 17:08:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405174 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD8F9E7737E for ; Sat, 30 Sep 2023 17:09:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234573AbjI3RJZ (ORCPT ); Sat, 30 Sep 2023 13:09:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234461AbjI3RJY (ORCPT ); Sat, 30 Sep 2023 13:09:24 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77DE1F9 for ; Sat, 30 Sep 2023 10:09:22 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-406618d0991so13161425e9.2 for ; Sat, 30 Sep 2023 10:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093761; x=1696698561; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vP0+gS+a1flrzX1mvrP/DkuvCGlYGfyvWtEP75LeBBM=; b=EqixhkYDJxCnhdTSjcbKvO0w+6YdZ3MCSk1zp9GSTa4Y/ylrw3BG7PB68mYlMh5Tpm 3L5zAvs/Z37O9cdZqDS6R14DJg9TpBHU21e5x8pDtRymD0h9gYUk6FZGK26LRB6QHggi ZKIzEp0VAIx3F/dDkHwoA56iRZzbmE4LyZgbhIOOXhilnNBwko3iQxJTic0CHag4blpr yPuXeKqkplCUxOEZTBrfR6One4cZu7vNlJV5AhVqKTau89h768DkWy6Xb8RhAywv9SHo /TWHMBKNzc37c7cR9bO/GXzr+khMIL2Ma4Od6WCp0B/qebv4KDRzGbDKg8fb2AzYtWz8 9Qyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093761; x=1696698561; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vP0+gS+a1flrzX1mvrP/DkuvCGlYGfyvWtEP75LeBBM=; b=lljaB7/6CX/bkE+OKZY8Jn6v+CO0Mo7/8WJrvQEjfpENqvnlz5K0nK9IXLnPUQMamW 3wvRzSoOtDoVWRq2l0A4KVNMsRLaH2Jz4CLIdS0I2xpiSb6Ncl2xcDFN8ehmGrXz8zjz pg3Xh86rg6an1WGgvsuGP2RDAPp9wpFDMpsnsq31enibkm27PO/XnWbRF8dFBdiXpsZg YygmfX7XJUBiB/J8djMY73miXVQJ+6ytRCRQITVPeK1xmybu5XQt9RhcMU6xEAsamibd 1lLc7kNGmEG5Prw7iEXUp+UVek052gtbp6wgW7c9FtVsFZlRJI9mU3vOTDe1034m7XDa JMVg== X-Gm-Message-State: AOJu0YxL2HwTESdTCuLfEXj/DDwGbfXsm5QiAAZv8vgdHidLLqsfd50e I76zw5463WZnkjIUVoT1Nhm8PA== X-Google-Smtp-Source: AGHT+IG0cHbhaYP3c4kVnqR7M79ML4dOiXKAjMKVcn0AVDZk8jzsHcJRfyyfB0izZYkUCJs5iD4Lfw== X-Received: by 2002:a05:600c:229a:b0:402:cc5c:c98 with SMTP id 26-20020a05600c229a00b00402cc5c0c98mr6263267wmf.13.1696093760831; Sat, 30 Sep 2023 10:09:20 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:20 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:46 +0100 Subject: [PATCH 2/7] Input: synaptics-rmi4 - handle duplicate/unknown PDT entries MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-2-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=3674; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=/ncxkYBOHJ0GuwBcZcMHJFqIgTv8HA9Y09NBC9ADCPA=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMNupl8JZl9hdYKzWsTU8Wi8mEdTzf0Hc5LadRzI3P wswePq1o5SFQZCDQVZMkUX8xDLLprWX7TW2L7gAM4eVCWQIAxenAEykSI7hr/QzZeebTd9DDs2w /7gxQKTo1+nik2Zp11KZK5ZI/nY+EcDwV0Z5wV/p/v9vK9wXmLsqxsw97xxw5pNzSOjhDocUrmJ FOwA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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: methanal Signed-off-by: methanal Signed-off-by: Caleb Connolly --- drivers/input/rmi4/rmi_driver.c | 47 +++++++++++++++++++++++++++++++++++------ drivers/input/rmi4/rmi_driver.h | 6 ++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 258d5fe3d395..cd3e4e77ab9b 100644 --- a/drivers/input/rmi4/rmi_driver.c +++ b/drivers/input/rmi4/rmi_driver.c @@ -493,12 +493,44 @@ 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) +{ + int i; + + switch (fn) { + case 0x01: + case 0x03: + case 0x11: + case 0x12: + case 0x30: + case 0x34: + case 0x3a: + case 0x54: + case 0x55: + break; + + default: + rmi_dbg(RMI_DEBUG_CORE, &rmi_dev->dev, + "PDT has unknown function number %#02x\n", fn); + return false; + } + + for (i = 0; i < state->pdt_count; i++) { + if (state->pdts[i] == fn) + return false; + } + + state->pdts[state->pdt_count++] = fn; + 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 +553,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 +566,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 +579,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 1c6c6086c0e5..e1a5412f2f8f 100644 --- a/drivers/input/rmi4/rmi_driver.h +++ b/drivers/input/rmi4/rmi_driver.h @@ -46,6 +46,12 @@ struct pdt_entry { u8 function_number; }; +struct pdt_scan_state { + u8 empty_pages; + u8 pdt_count; + u8 pdts[254]; +}; + #define RMI_REG_DESC_PRESENSE_BITS (32 * BITS_PER_BYTE) #define RMI_REG_DESC_SUBPACKET_BITS (37 * BITS_PER_BYTE) From patchwork Sat Sep 30 17:08:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405175 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F4F7E71D55 for ; Sat, 30 Sep 2023 17:09:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234603AbjI3RJ0 (ORCPT ); Sat, 30 Sep 2023 13:09:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234602AbjI3RJ0 (ORCPT ); Sat, 30 Sep 2023 13:09:26 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997A2E1 for ; Sat, 30 Sep 2023 10:09:23 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40566f89f6eso124990475e9.3 for ; Sat, 30 Sep 2023 10:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093762; x=1696698562; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3J8RLHlqMUHOOwu0JAX+LHiZvvV4F3X/qYQjfJIsE2Q=; b=PQAQhhB/0+r+s9rcenbSDvKKmahC8C7oI1q8sBQq3RNfWtliBvY41iH5LxvqGN7LjG nOYzcHvlmGPX34g+06yyNk7yDn5P/5OsTnQKleMH3uVplY7Mr349noCkDRr8UjOP8VTs 897kjj+d88PlOqNRLlFe3bpgProSr3wVMwBZ8nFnV0tuiacY7XmaISECl9nMWKKbGoh8 zKzaybEaxnWLt2YxwIiBBjXrulp9CCWQZJzfu3BTUwyPMAOmnzCSzpwcG8lCoAFI2aYy knia4WN2OFQEFPekuT6KPsoPAziPKw0LxsLzIJBBhCwzO90XEjP3sb0d9Swouy6MvCB1 bIpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093762; x=1696698562; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3J8RLHlqMUHOOwu0JAX+LHiZvvV4F3X/qYQjfJIsE2Q=; b=PTlVCriROyolEfplbcbCPKTxQU0KXr7/NI8dzbKQyG1AQ7VMm6zIns3kpHSftZYGzx 4Jsy2YoJ0CMW4t+YcCEVprJ7uoMim4XEyUIL+0x0tRBUrPDvuK7sOxzU9NrkKaDtu2Zb B3P5ZCg20NQiLMjTiSYc/xZhyQ4JEv+GH0LsMe+ptzdnhFugKSLJfTmcByUrupfgen/2 hmhR5XC3RI0A4bmk+HT2eJONhB56rga0scto1L6MhPIxlgXXYJdNDA+6jFAjAGU+cz0s 9xduQ4GjVFm6Bbb1MkFPkS7ZljlxX4F40g/wzCJ1c1v6+gSBkihCDNmFQjsByH6jQTH4 65/Q== X-Gm-Message-State: AOJu0YzCXS11xI7BICu7UGo49mXXVjq8DIIhViOPYtS97pLDbGveCew+ KLYFbaZy44YAva0RdBmyI3a4gA== X-Google-Smtp-Source: AGHT+IGzPaZ/Kh4Xt5oSaoRaQzLerFwL7UnB4jG7Gqu92ED0jaIEokBp0AvY5TrzaFtSfSSPeD1AHw== X-Received: by 2002:a7b:c397:0:b0:3fe:1b4e:c484 with SMTP id s23-20020a7bc397000000b003fe1b4ec484mr6363106wmj.5.1696093762003; Sat, 30 Sep 2023 10:09:22 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:21 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:47 +0100 Subject: [PATCH 3/7] Input: synaptics-rmi4 - f12: use hardcoded values for aftermarket touch ICs MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-3-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=6118; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=eWdxGMEpVfu6L9JxVtKHUtCsmiQeYQ0ms+XbRoDfZPY=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMNsOC0fxb8auJY493hds9kSuCVJzybSbcOuVnFxt7 oy7Nw52lLIwCHIwyIopsoifWGbZtPayvcb2BRdg5rAygQxh4OIUgIlsXM3wv6opML/Jul2/oiu3 5EqE+YUE5zUTnO1PTmmYvvr8j+SvlYwMrRUffWJDrz7bGheTsa/yBcOTvMRNDV5PN29Y+NhT3E7 hKwA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: methanal 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: methanal [changes for readability / codeflow, checkpatch fixes] Signed-off-by: Caleb Connolly --- 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 7e97944f7616..719ee3b42550 100644 --- a/drivers/input/rmi4/rmi_f12.c +++ b/drivers/input/rmi4/rmi_f12.c @@ -195,6 +195,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; @@ -315,6 +350,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; @@ -328,6 +397,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__); @@ -342,9 +412,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, @@ -352,6 +422,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 @@ -370,6 +442,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) { @@ -400,29 +484,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) @@ -520,6 +584,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 Sat Sep 30 17:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D374CE732D6 for ; Sat, 30 Sep 2023 17:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234607AbjI3RJ1 (ORCPT ); Sat, 30 Sep 2023 13:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234604AbjI3RJ1 (ORCPT ); Sat, 30 Sep 2023 13:09:27 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69956DA for ; Sat, 30 Sep 2023 10:09:24 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-405524e6769so10512175e9.1 for ; Sat, 30 Sep 2023 10:09:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093763; x=1696698563; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NtAKqaERolIHCTmRDg6aGz6W93ZG9oOqGRlldMnpGHM=; b=N7EU8+GfsM7rEuqUNMcJtfA85n0WFmk6rBhzyhu3BDes7AgUUsKGlAwYCeiVXjLd7u aOYQ5KEvxaH1sgRICDKdXt3OF1nzLkzJL5kAVLBGkiVX4/3CBGQcpL6VoxxvwrWAd7ro COMOz8LelpWYfXqnJxH3tgAGhoNy/0eeWAIJwvKr0ldXIRjpa+eCB+4/51aOFOqmBHvV bClxdeNUc+NKzqAxF7oP4gln+VoC+BdDnDJOZnN2qxFtdYb7MPczP2XMvkXzz6nIhcIB IDRaKq9i1miSRBzo72Htvfg3eWvet72tsgLOfACLgcOdRT25220mCxWHjCmVZgkjtbKJ UIDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093763; x=1696698563; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NtAKqaERolIHCTmRDg6aGz6W93ZG9oOqGRlldMnpGHM=; b=sGFnkcFkALAXlKMuEpoy9QTkErjJaf0CAN148hCvbDFdyrEx8VkeD1LkNM78FphrFr 0Fl7FbvP9RolwP/9HGZQk3V8doCxNtn/j26IXIF9slH6vKGuQW5VFwsId2wdjgpBMi6+ op06VjZtVWCQU/wQH8+2lcGL2hP6HAii4QomDpMZQoQ1Z1jwpUg5A5FQD8epVgGT4Bhg 186rWH54llTIebVJFenIga3aY8gwj7j+6S8N8UqoM7E2p4EL0ZhL39/Onnd/i/hXXJ6L t4XLMFqVlU5nTIcaQX+Ks1BUBuA45bcLlQmqCdb/Rb80nTOW+sw2z/ZxZxsuPDKcyr+s 8wRw== X-Gm-Message-State: AOJu0YzXe0/0pzRvNECxv7OYgoNz3BX3OPNqoPO84GXyB9oRnPIqtoSO xt8uZO/xZhJX1zKQhOXNkIfdyJhDN7Hl+cxQBZ8QkQ== X-Google-Smtp-Source: AGHT+IEFgpuzc+qUsPZ2B8Jaa3bfgA8jZTHu+qCQZoGfJoEG/PjS0SjyGYp1GBEjMJnMIjMjJ9vNzQ== X-Received: by 2002:a05:600c:600f:b0:405:2d29:1648 with SMTP id az15-20020a05600c600f00b004052d291648mr6313721wmb.19.1696093762948; Sat, 30 Sep 2023 10:09:22 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:22 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:48 +0100 Subject: [PATCH 4/7] Input: synaptics-rmi4 - f55: handle zero electrode count MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-4-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=1064; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=+4DaGg6VDRBPUbN6NHpCk9CFy1rQXCDvptUHWZJ41N4=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMFtdSzvv++u/5QY2/JtTNIvh4nO3nMvR8S/2yam8b 49rCNDqKGVhEORgkBVTZBE/scyyae1le43tCy7AzGFlAhnCwMUpABOZ8JPhf76GUMsWS83d225l O+1zDS2xu203LSWK2/ij70fR/+m2/xn+hyh3zI7al3j5cYjBJvH7/1Llr8v3Jd01SZlrYdDDuWz PAQA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: methanal 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: methanal [simplify code, adjust wording] Signed-off-by: Caleb Connolly --- 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 488adaca4dd0..ad2ef14ae9f4 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) { + rmi_dbg(RMI_DEBUG_FN, &fn->dev, + "F55 query returned no electrodes, giving up\n"); + return 0; + } f55->cfg_num_rx_electrodes = f55->num_rx_electrodes; f55->cfg_num_tx_electrodes = f55->num_rx_electrodes; From patchwork Sat Sep 30 17:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405176 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3CFCE7737B for ; Sat, 30 Sep 2023 17:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234604AbjI3RJ2 (ORCPT ); Sat, 30 Sep 2023 13:09:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbjI3RJ1 (ORCPT ); Sat, 30 Sep 2023 13:09:27 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FED1FA for ; Sat, 30 Sep 2023 10:09:25 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-406619b53caso13166805e9.1 for ; Sat, 30 Sep 2023 10:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093763; x=1696698563; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=k0VJ6C8kG7GHegHfpPJdNysCaTwmqIvJ6WSm4iQqP4U=; b=bN1dM71rpawhTXzZAEAYAQKQur1WgJHyflo7LnEVEh5wl9FN9miyIahdzmHT1gW009 UqgJisEvP4netDUyz192qReFz8tqGrbn1Uz1/GMZ15otOpDrddcPiLw7bKTn9afeTce6 cNsavNEQ/dq78j17O2dcVQ1yf4PS4WV5KfCJkJwrUbOx0VCmFyMGVw7OUDyjYWwvRzWq cvQ4OGpFwtk3Tju7d7KmAF86RuBVveqsASHS6ueKSJxAUCiIcs014cokAEn9hY0CdcKV X/GoojIYYl1FidMctMes6FsMTI6jJDv4a510gogfTaL9rtD29gkudIT6bVehIL0PAlcj Oxng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093763; x=1696698563; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k0VJ6C8kG7GHegHfpPJdNysCaTwmqIvJ6WSm4iQqP4U=; b=e0udbe0biHPzZfVbYnm+D1fm+bJUAKzZwDymkugdgto3C7PVM27GW22bpabQPb/kZH XfcS5GQVETVhnx+ykIQqP/pvpTcZxxtpNtCC65eYOcCumGe7DhNUDfkTIwdr6bw29gRn AbQDFh5Qwf2XMtjpNGD+/4mvkt/Jy2c4TkqLMgfPBnyPr2C3DPIA04WWmURHotAb5PmP QGYCeJhTIfQdjybOgzaLE1sLc0AnugSQ7dA3si396jrNA5YRNQgsvb+pCNzoipgKKyk6 7YCCgEYtUDW55dgIEOWqR0GjNv3rDm0AFPxJQF5EUuIxAfjdUs1Ks4OZONYCPfnoPjI3 yzTw== X-Gm-Message-State: AOJu0YzwbRhV8FyGUhMT567KPgShvngF7UCE+v5ygtAEyQ9tJ1rxqe2h sLXbLXvOuAfi1TIgk6fhCJuCCA== X-Google-Smtp-Source: AGHT+IHCLGk8syzqpqer7HrIAq6wGcQZLbCD1JNGfQ9k8s4oWvFVHyyykKCDg2ojj8BP8dZ1x6vFkg== X-Received: by 2002:a7b:c454:0:b0:405:959e:dc6f with SMTP id l20-20020a7bc454000000b00405959edc6fmr6477462wmi.37.1696093763725; Sat, 30 Sep 2023 10:09:23 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:23 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:49 +0100 Subject: [PATCH 5/7] Input: synaptics-rmi4 - don't do unaligned reads in IRQ context MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-5-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=2497; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=c8t4Dh0FV7IAxRxCe06lGztnMxn5LYVPeNtEfmL+ltU=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMDu1Jdef656ZYaLx/1NLEht7+33t1JKe8wbpq9yuN h04pL26o5SFQZCDQVZMkUX8xDLLprWX7TW2L7gAM4eVCWQIAxenAEykIoHhv/eynL+V5h6bVXVW LjLmecSg8iCe2U8wYUF2jpTARDabEob/OeUV9z+lbku3fzbJa+qDgkkTWxdlRUecXGZrJHmAKf4 0IwA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: methanal 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: methanal Signed-off-by: Caleb Connolly --- This solution does wind up doing the unaligned reads on the CPU instead, although I'm not sure how significant of a penalty this is in practise. --- 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 cd3e4e77ab9b..58bf3dfbf81c 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, + 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; @@ -1083,16 +1088,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 Sat Sep 30 17:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB9A7E7737C for ; Sat, 30 Sep 2023 17:09:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234614AbjI3RJ3 (ORCPT ); Sat, 30 Sep 2023 13:09:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbjI3RJ2 (ORCPT ); Sat, 30 Sep 2023 13:09:28 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01760FE for ; Sat, 30 Sep 2023 10:09:25 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40572aeb673so123693505e9.0 for ; Sat, 30 Sep 2023 10:09:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093764; x=1696698564; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=q1Huhh/OlwpXkMpXKcwHwnmwV8YpnbusYc64GlhC06k=; b=ycjxPIHwApQ8Rkq3WEJrcAJG1FvEzsm+LsxR/9GZxGNJzkGdC9zGVk35l6xADKhPrM jZugKXdSTCZ1fkZwGLNTj5T6GukyPRTQ/Okvfu8nsQ2AdGlydsGGGb05Sn18k9JuLUsv 5+KdPx/Jo3NxkCXEbou0eoGjOA7uxslAdUeAMScxZaoX+z0j9SyyRA/MuxUc9Kozdimr HeT1TJCyFjHtqzc4lWRjgqEhIKWjebym2z01MAHXUkAojhpJsTUbg86uuYd83dcDaOxb JOH3H8kn2eXnONzStL+ESCpm5+BtAfGTWiyNyCSFybZNtNopfYhOSTsNld437fXKyBaL MPng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093764; x=1696698564; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q1Huhh/OlwpXkMpXKcwHwnmwV8YpnbusYc64GlhC06k=; b=ZkZy04dOjxan52u8tHNjUCCgh8klAZeK1ZIGog+f97ukYTqSTU1nEZ527dAFrJfNpt uDcLKU7woKGYWGwYRsReF7SusdTC0g3BjhYNIBUeKBpHuQmuOslrYbcOgZmbvYCcWQZI b2UOql030kRB6yI2Yh8a2e1x86YlJFLBmRvhMzrtp3mLhSWfqs8DE2xu3X9lSnEMVLt7 uKyGs58681wK5Gv/b3M/hKgPXk0qqgtIxUmt+5vpRFUj0IlzcFkdd0ac3ZlDL11/ZXFU sKeY9D+vaXCprNFsPrFcjIYXTzycWwQiaPeTcFzh3pAaakHULcM2hYM7zzLVj7koZUc6 Lsow== X-Gm-Message-State: AOJu0YzJClOC314Feu7yihlELmoGg6PLNdA2B/kLzi+gTWUQSoEHX5Kf J+mwfDTKLIU0ucxVyVXnUDxPrQ== X-Google-Smtp-Source: AGHT+IGGWzA0jXfIU4Hw+pBFZeGbPRuLEaQjsqU2dB/VXEaA6vWUusZRG5PeVAvKE1nE2uHlnHw9LA== X-Received: by 2002:a05:600c:21d1:b0:401:cb45:3fb8 with SMTP id x17-20020a05600c21d100b00401cb453fb8mr6975834wmj.38.1696093764476; Sat, 30 Sep 2023 10:09:24 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:24 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:50 +0100 Subject: [PATCH 6/7] Input: synaptics-rmi4 - read product ID on aftermarket touch ICs MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-6-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=1134; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=pgIIB7OL7EFg+Qrqe6fqxDg+RErXXrlo3Ql+ExoD2SI=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMLt54vEpBQvqKnbcU/r0PjPs26XTjS9zIjvNF/cLV jHWvlvbUcrCIMjBICumyCJ+Ypll09rL9hrbF1yAmcPKBDKEgYtTACZS4MXwP1gnoZJX9YLa1YQb 87my32genbNy9q8TNbWykpIzChyyPzH8DwxPyqvQSNv0nClsmtMr9c+WOtm6c8vfeXjJFiSGNTU 9BAA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: methanal 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: methanal Signed-off-by: Caleb Connolly --- 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 d7603c50f864..4aee30d2dcde 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 Sat Sep 30 17:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caleb Connolly X-Patchwork-Id: 13405179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C85AFE7737D for ; Sat, 30 Sep 2023 17:09:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234617AbjI3RJa (ORCPT ); Sat, 30 Sep 2023 13:09:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234606AbjI3RJ3 (ORCPT ); Sat, 30 Sep 2023 13:09:29 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17D4DA for ; Sat, 30 Sep 2023 10:09:26 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40572aeb673so123693605e9.0 for ; Sat, 30 Sep 2023 10:09:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696093765; x=1696698565; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0S4YyoMRJsfSt6+U3bqbOqX9jPh1v33yWTsmXu+J/uw=; b=YUaXy7xrG5NEVOCLES2IcQxnzjsmtTtvxqDd0r0rjaDxeGud1SyOckjfvnlrBfdrPY AwkStSfqYh/4X7RNoyp3HM/eYPr0VtUT8Ii9UXrD8FZO8DwIz8aAW9N/PlU+/SzXNRQi GazVTd59QcrbqSwwYYozBUlUj08UH3GrL/vslOylLvtTQXjYC4qqz+EBtb7lisrTKP/N RqKj1GQAu7mChbERhqyx1fBgY114fXs3NDQIr79weCqEpDrrW+Sb+ijZdzWgMIpf0JmL MPfGmw0jbA++XSEsqc1zpr9vqsZI9D4CnZ9kBbroEKlijniA/ix4rFs2vq0qr8fdhIrA J7+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696093765; x=1696698565; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0S4YyoMRJsfSt6+U3bqbOqX9jPh1v33yWTsmXu+J/uw=; b=dATXZlfa6tw107f5aktrChQlgWPi7+wKq/COFSG5PGMf9lGqRLehb8HaslAolLrxM8 Q20rsskV57uxfjtfYRSPKsFKu/14bs1qgkI8+Plt/fBE4T3m4BTKlxnAFUmwj9bmao4e xOjKg8CMy4og2qRmt+7cGHHLxIyYxfx57CrOKHAOPOW8CYCyv3MChGvwbTPk88IEMY9J pSyiNW5mY7KKiNLKOfIwwbBrxktqOPqLuLdP0gaQ03RM72N8eAkwrH1DaGYqeKSiVBUo eQpLU/9gZRnO/x4ikfBIYv1/JY9z77JBRilUAwhlKuYfxrdsW0k0O8ZSY/Fm55KT8sDq NxAg== X-Gm-Message-State: AOJu0YyQ5KHPUSk3MiVpw7ZSYzCUfpf65hnlw7IqFhdIkhf1IZaF3ILk Df+x/jRaBIWFzjf/PIAq/pHtkA== X-Google-Smtp-Source: AGHT+IEuMQArzFFl4o3M9NXXO87+2a99RjnP9y0Nf+twdzXJ0GajD6y4kBW4h3foq2wahu9I0hEgQw== X-Received: by 2002:a05:600c:b4e:b0:402:95a0:b2ae with SMTP id k14-20020a05600c0b4e00b0040295a0b2aemr6499769wmr.32.1696093765288; Sat, 30 Sep 2023 10:09:25 -0700 (PDT) Received: from lion.localdomain (host-2-99-112-229.as13285.net. [2.99.112.229]) by smtp.gmail.com with ESMTPSA id y21-20020a7bcd95000000b00405c7591b09sm3756368wmj.35.2023.09.30.10.09.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 10:09:24 -0700 (PDT) From: Caleb Connolly Date: Sat, 30 Sep 2023 18:08:51 +0100 Subject: [PATCH 7/7] Input: synaptics-rmi4 - support fallback values for PDT descriptor bytes MIME-Version: 1.0 Message-Id: <20230929-caleb-rmi4-quirks-v1-7-cc3c703f022d@linaro.org> References: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> In-Reply-To: <20230929-caleb-rmi4-quirks-v1-0-cc3c703f022d@linaro.org> To: Dmitry Torokhov , Vincent Huang Cc: methanal , linux-input@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Caleb Connolly X-Mailer: b4 0.13-dev-46309 X-Developer-Signature: v=1; a=openpgp-sha256; l=5765; i=caleb.connolly@linaro.org; h=from:subject:message-id; bh=Y56SCFSNeAsG17qE46++u/KK8CjxJ0A7DKHt1n0Mzm8=; b=owGbwMvMwCFYaeA6f6eBkTjjabUkhlSJMLsWUysxr4yCxe9SzmpfERdzilSRm7Nix0rhIqGZL IX7jT90lLIwCHIwyIopsoifWGbZtPayvcb2BRdg5rAygQxh4OIUgIncWcLwT23BkQAxBb/EAxO7 zJtexfD7R+0VvXlIoC0jQW2NrHCDF8N/T+mb1YczeXY8PZr4537K7oDnKhutAr/MuNAb7TD59Ck +awA= X-Developer-Key: i=caleb.connolly@linaro.org; a=openpgp; fpr=83B24DA7FE145076BC38BB250CD904EB673A7C47 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org From: methanal 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) Introduce a new devicetree property `syna,pdt-desc` which can be used to provide platform-specific fallback values for users with a replacement display with an aftermarket touch IC. Signed-off-by: methanal [codeflow adjustments, checkpatch fixes, wording] Signed-off-by: Caleb Connolly --- drivers/input/rmi4/rmi_driver.c | 67 ++++++++++++++++++++++++++++++++++++++--- drivers/input/rmi4/rmi_driver.h | 2 ++ include/linux/rmi.h | 3 ++ 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/drivers/input/rmi4/rmi_driver.c b/drivers/input/rmi4/rmi_driver.c index 58bf3dfbf81c..5e1e3d5dd800 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 DT */ + 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]; @@ -551,7 +567,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; @@ -1028,9 +1044,11 @@ static int rmi_driver_remove(struct device *dev) } #ifdef CONFIG_OF -static int rmi_driver_of_probe(struct device *dev, +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, @@ -1038,6 +1056,45 @@ 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 platform + * may have provided backup PDT entries in the device tree. + */ + + 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; + + pdata->pdt_fallback_size = of_property_count_u8_elems(dev->of_node, + "syna,pdt-fallback-desc"); + + /* The rmi4 driver would fail later anyway, so just error out now. */ + if (pdata->pdt_fallback_size == -EINVAL) { + dev_err(dev, "First PDT entry is empty and no backup values provided\n"); + return -EINVAL; + } + + if (pdata->pdt_fallback_size < 0) { + dev_err(dev, "syna,ptd-desc property was not specified properly: %d\n", + pdata->pdt_fallback_size); + return pdata->pdt_fallback_size; + } + + pdata->pdt_fallback_desc = devm_kzalloc(dev, pdata->pdt_fallback_size, GFP_KERNEL); + + retval = of_property_read_u8_array(dev->of_node, "syna,pdt-fallback-desc", + pdata->pdt_fallback_desc, pdata->pdt_fallback_size); + if (retval < 0) + return retval; + return 0; } #else @@ -1163,7 +1220,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 e1a5412f2f8f..2531c32d6163 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 ab7eea01ab42..974597960b5e 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; + u8 *pdt_fallback_desc; + int pdt_fallback_size; + struct rmi_device_platform_data_spi spi_data; /* function handler pdata */