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: 728256 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D898618055 for ; Sat, 30 Sep 2023 17:09:25 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1FFEE3 for ; Sat, 30 Sep 2023 10:09:23 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40652e570d9so28531315e9.1 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=DixOjv9rLGvQ9J0/GtZnwDAbRXifUynITOLIPe6WumT4wMZteewzJtZD9gKTSRgyTG S5L5+DFiaSyWqCplumg2ZIO6J0TBOqfwG6bxuArgqzRcdK7Dn+3m3VVKwSO3FeczwDRC 6Ojvcw84dXg1vURyNSsIP/VeANEbDNyJvMz+fb4oR1/awabCD2z2BxRUjMv+L67rE2XR WFo6T3uYTFeY7/Yb4DcWg31/9NdIAPZC4dRjdYE2KEuEnJAzvCNn7K4HbTPUIdKUNsrB ncbMmx1inZvZFVAGx7uXaasPlRtKSHbBTg2bN6TRttKwTwZxTc/vtabjBPQanEWs6kfP n5Sg== X-Gm-Message-State: AOJu0YwEpTNQjQe9jXWBZFss/g14SibjKCkgKPv8l6L+AMsw2/4ccY9k fJ0QTtrWaqjLVo0DZLF6OOIDBA== 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 Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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),