From patchwork Thu Nov 10 17:19:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 18236 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp271701wru; Thu, 10 Nov 2022 09:21:06 -0800 (PST) X-Google-Smtp-Source: AMsMyM7oJQ0dlk8DIU0JZfY7gxo8Xi/4JBcJYwwc5hAKI6bWNjOD8RvEs2nrHzyXodqR56+kusy4 X-Received: by 2002:a17:903:1381:b0:186:8bdb:6865 with SMTP id jx1-20020a170903138100b001868bdb6865mr64593476plb.166.1668100866387; Thu, 10 Nov 2022 09:21:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668100866; cv=none; d=google.com; s=arc-20160816; b=unqofDclWW3qfH821rMAREhNS7LY3ubBPzA7JpjCQdIiBo6wAidc8EnIg/ZkuTEf0V wC7zUU6rwySTM6UWQ20qEgTjDs7gtaXOxjraUFWMYYCB2i+sBjYgQ9gqUxLmwguAcw55 /6qb7HrV1+gfAdrC++BJlGGKVpnKbW+BUD3XhICyfK6V2DfHdw1vgZUa4xDo3Rjbcg5M oxA5qoGL2y+7s/KtGF+rpSAx7PWC6l6rYkuziIFaP4puR0lnlV3nA04uQ5+PaCeOvl0j xnBB+v0KG+yEtXcc7l+fUpCNbuomVL0nvrSNl+vwPbioZxnom8pjJ1lJE/jcFKpbxrsn 0n9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ucuD9gF41UYt8kfGtWQdbwpIGVa1GcQ8Dsz4fCe0SZ4=; b=Oe9BmXPEku9LaWVleLGjTHGGA0a0350PmFGzUsqA3nGxxxvNhsTFcKHVUxEboO+nDH rY6Jj+YYQT3exIS0YildNl/EsFywxSf/yuCiBnLCFNpCqZ+3Hq1ql8EXh+1K+FVfsRqI ++g/uQtNLbLqHT0MsVW59R6OruJdiC9AUwdI+lEm8cA8+YgihsfBKxHJQthvfSYw60WH +jekiYqW1FpePPu+jZTpsGXeJ9xxTu2rCXyItm22lfpz5UIt88bGH+qvoKXFtEB/mhv+ lxxsCHEfl4eseGg3f1YZGmkv7ba4dGd/bhftRDlY8Awb3bfaQkjNq8KQz364qxtcPKBq PKPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=ky3PU+IR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d6-20020a170903230600b00180d51f70cfsi24035122plh.107.2022.11.10.09.20.52; Thu, 10 Nov 2022 09:21:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=ky3PU+IR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbiKJRUe (ORCPT + 99 others); Thu, 10 Nov 2022 12:20:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229940AbiKJRU0 (ORCPT ); Thu, 10 Nov 2022 12:20:26 -0500 X-Greylist: delayed 81179 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 10 Nov 2022 09:20:20 PST Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 624F0A4; Thu, 10 Nov 2022 09:20:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668100809; bh=vZWdl4U5AIVvqtvaInt8viyZUhV0hsuZo7TtEgTSbBE=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=ky3PU+IRyZfUu/ZeE9r7bSdzq8mBI9fPXo4BXfaoFC80J1zLeA8zQzfS+v0WeZSsA KtRLMzN1mkXgxYwUMV6TGZqPk+OloKNco6xpCiRO17jreLqMJUkXhTxOvGaPS+W4Dv CzfveUKZAV/CsJ2tWhhu3AijzjwM8AHScTLi4wZo= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via proxy.mailoo.org [213.182.55.207] Thu, 10 Nov 2022 18:20:09 +0100 (CET) X-EA-Auth: xuvYD7bLq1ZEZG8yiJC4uzcXUmjumj407oSW8cgqC8cDlnWNOLsGn9ctkKv/TLXhkmKRof840q39uuQJxhX2JhoyOUH6AcG6TPnRm10Yh3k= From: Vincent Knecht To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: w.david0@protonmail.com, stephan@gerhold.net, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH v4 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Date: Thu, 10 Nov 2022 18:19:44 +0100 Message-Id: <20221110171952.34207-2-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110171952.34207-1-vincent.knecht@mailoo.org> References: <20221110171952.34207-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749130533720385288?= X-GMAIL-MSGID: =?utf-8?q?1749130533720385288?= This will allow us to add other MStar touchscreen variants' support. No functional change. Signed-off-by: Vincent Knecht --- drivers/input/touchscreen/msg2638.c | 40 +++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c index 75536bc88969..222adedf78bf 100644 --- a/drivers/input/touchscreen/msg2638.c +++ b/drivers/input/touchscreen/msg2638.c @@ -26,23 +26,28 @@ #define MODE_DATA_RAW 0x5A -#define MAX_SUPPORTED_FINGER_NUM 5 +#define MSG2638_MAX_FINGERS 5 #define CHIP_ON_DELAY_MS 15 #define FIRMWARE_ON_DELAY_MS 50 #define RESET_DELAY_MIN_US 10000 #define RESET_DELAY_MAX_US 11000 -struct packet { +struct msg_chip_data { + irq_handler_t irq_handler; + unsigned int max_fingers; +}; + +struct msg2638_packet { u8 xy_hi; /* higher bits of x and y coordinates */ u8 x_low; u8 y_low; u8 pressure; }; -struct touch_event { +struct msg2638_touch_event { u8 mode; - struct packet pkt[MAX_SUPPORTED_FINGER_NUM]; + struct msg2638_packet pkt[MSG2638_MAX_FINGERS]; u8 proximity; u8 checksum; }; @@ -53,6 +58,7 @@ struct msg2638_ts_data { struct touchscreen_properties prop; struct regulator_bulk_data supplies[2]; struct gpio_desc *reset_gpiod; + int max_fingers; }; static u8 msg2638_checksum(u8 *data, u32 length) @@ -71,7 +77,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler) struct msg2638_ts_data *msg2638 = msg2638_handler; struct i2c_client *client = msg2638->client; struct input_dev *input = msg2638->input_dev; - struct touch_event touch_event; + struct msg2638_touch_event touch_event; u32 len = sizeof(touch_event); struct i2c_msg msg[] = { { @@ -81,7 +87,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler) .buf = (u8 *)&touch_event, }, }; - struct packet *p; + struct msg2638_packet *p; u16 x, y; int ret; int i; @@ -103,7 +109,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler) goto out; } - for (i = 0; i < MAX_SUPPORTED_FINGER_NUM; i++) { + for (i = 0; i < msg2638->max_fingers; i++) { p = &touch_event.pkt[i]; /* Ignore non-pressed finger data */ @@ -215,7 +221,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638) return -EINVAL; } - error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM, + error = input_mt_init_slots(input_dev, msg2638->max_fingers, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); if (error) { dev_err(dev, "Failed to initialize MT slots: %d\n", error); @@ -233,6 +239,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638) static int msg2638_ts_probe(struct i2c_client *client) { + const struct msg_chip_data *chip_data; struct device *dev = &client->dev; struct msg2638_ts_data *msg2638; int error; @@ -249,6 +256,14 @@ static int msg2638_ts_probe(struct i2c_client *client) msg2638->client = client; i2c_set_clientdata(client, msg2638); + chip_data = device_get_match_data(&client->dev); + if (!chip_data || !chip_data->max_fingers) { + dev_err(dev, "Invalid or missing chip data\n"); + return -EINVAL; + } + + msg2638->max_fingers = chip_data->max_fingers; + msg2638->supplies[0].supply = "vdd"; msg2638->supplies[1].supply = "vddio"; error = devm_regulator_bulk_get(dev, ARRAY_SIZE(msg2638->supplies), @@ -272,7 +287,7 @@ static int msg2638_ts_probe(struct i2c_client *client) } error = devm_request_threaded_irq(dev, client->irq, - NULL, msg2638_ts_irq_handler, + NULL, chip_data->irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, client->name, msg2638); if (error) { @@ -316,8 +331,13 @@ static int __maybe_unused msg2638_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(msg2638_pm_ops, msg2638_suspend, msg2638_resume); +static const struct msg_chip_data msg2638_data = { + .irq_handler = msg2638_ts_irq_handler, + .max_fingers = MSG2638_MAX_FINGERS, +}; + static const struct of_device_id msg2638_of_match[] = { - { .compatible = "mstar,msg2638" }, + { .compatible = "mstar,msg2638", .data = &msg2638_data }, { } }; MODULE_DEVICE_TABLE(of, msg2638_of_match); From patchwork Thu Nov 10 17:19:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 18238 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp271854wru; Thu, 10 Nov 2022 09:21:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM5lMBJGkyjOZQ2mYunOyV5W9HbDokN+3n6N8WYMt0rFIv61JeMrU3oB/P6BwMuNPTmcYljn X-Received: by 2002:a17:90b:1d90:b0:213:c798:86f6 with SMTP id pf16-20020a17090b1d9000b00213c79886f6mr61893459pjb.84.1668100885955; Thu, 10 Nov 2022 09:21:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668100885; cv=none; d=google.com; s=arc-20160816; b=aoBQBVxW3i/Wp+8nFfDTVm/i/7PzkXn3iYYVvKJMQOQfI898622Sk2TlJDqAiWPG38 nxqU9JTvexNu3KBfMkL6gpZcpacftSkDY7Z5p2JpyGHdHw/NaiEf13ubo/ky8MAN+iQU CotDh843qjPLVrwG4RmV1WbsiFgAvu0DEG5OhCzh2hDxAM3wBsgQxScYzQdFkcuFEaAS neX4DG3m8sdQJ7Ffu5bFqqwJiDJ+QXOPv/WjhAg2D7+dWYAWUnra7beJ90lqW6baz/mi MW9FNvRWz3NY23AZA9y0MgJTpiyfF1EeezDpuWtYHH/Pvoa7Xp69tRebUWtfQlCkv8Wm 4vDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CgWO4AjbJt2I+9syVbbGJ3VrAU24WkLI+3lRqKH9TnM=; b=TyiNm4LOCqdDQ8adIjgkNINl/6zCcwNQwSsPjCgcp4YHyT8/H7JbQzkNAl8agU3iZc 0Yqkb9aaVhiOZ1axnNkg6Oii5qPCH+Lr6nUHXEIseMaN/5fyKYL1xpzsM1LAjZNndsuy XwzFa7EdiD2ZUpx3TzWwi9j9wJ+CnMoGzHVABCedhXqNGoDS/tp6HzFD71oaP7YJYZ7G QRJhaE5CplL2CLr6ffVYAbHpGwT+OqsW9LdG08Op5UNg2aYTrZv4cSq/DNyc4utj0C/l Ped6BFs8kGaIXj39EEaRAQhyHljwnAden0njrm2MKpmKYmsrEX88VQ9VJFei7pHtRoqe F/Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=LioxLxCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a170902b61400b00186ada5d4e2si20133592pls.215.2022.11.10.09.21.08; Thu, 10 Nov 2022 09:21:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=LioxLxCU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbiKJRUi (ORCPT + 99 others); Thu, 10 Nov 2022 12:20:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231341AbiKJRU2 (ORCPT ); Thu, 10 Nov 2022 12:20:28 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 652F41E8; Thu, 10 Nov 2022 09:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668100815; bh=l55fHkNn8Ed89kT7xAtVgMNLiNafpAVdJsmDgQTK+/8=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=LioxLxCUBHBZrWWy/b/IpoPERHBTwK7sC2b6qnEnhYps3GQttJ+gMcftoct6yhWXu PHwnyZbnHv9NFR/BS+bE5FhahtHzuAo7ISzakLYTe5Cf2Qk7PK+K7al6mMeSK13sEu s/EEW3p0Q1fIMqyc9YNMG8QxRjCCr5kIR9H+Z6AM= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via proxy.mailoo.org [213.182.55.207] Thu, 10 Nov 2022 18:20:15 +0100 (CET) X-EA-Auth: znNgnLi0uPOB+XwA8c325fqpkSkngoH5vtNXHzfQ94/jCIFwQcinGDBIxE0xn36YRvY3SFMZiYwk6pr6EnFUxvgy6J8TN3WiZrKvswbxTXU= From: Vincent Knecht To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: w.david0@protonmail.com, stephan@gerhold.net, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Rob Herring Subject: [PATCH v4 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Date: Thu, 10 Nov 2022 18:19:45 +0100 Message-Id: <20221110171952.34207-3-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110171952.34207-1-vincent.knecht@mailoo.org> References: <20221110171952.34207-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749130554452303226?= X-GMAIL-MSGID: =?utf-8?q?1749130554452303226?= Document msg2138 support by adding mstar,msg2138 compatible. Acked-by: Rob Herring Signed-off-by: Vincent Knecht --- .../devicetree/bindings/input/touchscreen/mstar,msg2638.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml index 3a42c23faf6f..2fb7e01bb65a 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml +++ b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml @@ -14,7 +14,9 @@ allOf: properties: compatible: - const: mstar,msg2638 + enum: + - mstar,msg2138 + - mstar,msg2638 reg: const: 0x26 From patchwork Thu Nov 10 17:19:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 18237 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp271794wru; Thu, 10 Nov 2022 09:21:18 -0800 (PST) X-Google-Smtp-Source: AMsMyM64C1qDf4hPyY2+AbpOVNnWlDVrZDDZpmQHx7KnVT+oDSXdoq5+MKKnazCC7fPlIEPzwimf X-Received: by 2002:a63:5d56:0:b0:452:8774:d5ab with SMTP id o22-20020a635d56000000b004528774d5abmr2929964pgm.74.1668100878172; Thu, 10 Nov 2022 09:21:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668100878; cv=none; d=google.com; s=arc-20160816; b=QDVW/r2KBSjM5y/p8403wa95fCd7Gfdi2JMH5TaPaGR8kPIQcDHviA75GvtngLFyh7 dZ/WqLOyrSlHsbpIEfF6bMBII6zDIq8gCSTV6ewAfRE26yCNHuOC8puTEdgZgVYNyDVa KJylqziexTcIzNkjAzicWaar6iAt2PJeAuqQWscYU1IO2+p2cXJGjswoGwHOmSD+yVnN CGJ0YMQihPRw/3Ysgxq8NxElFTROgzcRe688SNB4uJtdqVGa9p3rHCekaawSlOFcPcrD mhY12UtP3TlXzXkMKOg3Je55tvR3c+DvWaZec5saOA90X8f6Zo+qaghM+72WYPZFi4g5 lSXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dnD/kM0DslFcUnaQjTaWtKXVwfwFRvV/G26fqUbMnws=; b=ruV5eevbxmNxPmOBeqhHdIiAmlA/UQs8Wdqfp5waaATUsuNB8aLaA5rO30nS4KiopU nNNeMxaPeppBb+uF6occ/hBji/p8mqgQxBA6MITY9+4FFn37ClcZSYSAjlQmCefRHp8R iQLpUwgv50D+E3EmA5TRnk2TvGtd0bQ8l23Nkn97SCDtXeCSi+GrOaBVG5lsugBMxKN+ NgHmddXcRaqghJF2OajrsBYFxV1VWjoaH8RdJ/MYKQElak5BOVNEajXsaNF0N6JTBEgW WU9cpqso5X6NPnqgrdP7ZpljN9SnCo1E+2WqpI5+fl9CaxPpwtVqoB4aODLggjCS5D+3 1O/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=gUmm+U8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z64-20020a636543000000b0046f71a7292dsi21448714pgb.384.2022.11.10.09.21.03; Thu, 10 Nov 2022 09:21:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=gUmm+U8u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231659AbiKJRUl (ORCPT + 99 others); Thu, 10 Nov 2022 12:20:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231447AbiKJRUa (ORCPT ); Thu, 10 Nov 2022 12:20:30 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C208A4; Thu, 10 Nov 2022 09:20:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668100819; bh=BfMnzoCXhU0WRxUZKEPynpBofOMASUhpqpPL7tHyjf8=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=gUmm+U8u9/xOjYhulH+CKNCe7G5zeSobyUD6cytzrQxhiXxoaNTrbnlG32W9rWBwe RBPQ7HSU5lAugLiGZvxkeKyHEcj2voNMJqtuOXDWa/OltknKFMEMsQgbgOE4EH9Tmu Ft0c8CGcbq5XKl2vOHcnZk85WRSxKgACLCPHf5/A= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via proxy.mailoo.org [213.182.55.207] Thu, 10 Nov 2022 18:20:19 +0100 (CET) X-EA-Auth: CEwPyxhJgWkM9+ozqN5+L4Grm/OGTtQepuqi1ltfBBjPhYf2gumhRWVN7pPBc9WZBoZcH/6M7ObfE6KEV3wKJmaV4FL8q8T4X3PxZdX+6YA= From: Vincent Knecht To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: w.david0@protonmail.com, stephan@gerhold.net, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH v4 3/5] Input: msg2638 - Add support for msg2138 Date: Thu, 10 Nov 2022 18:19:46 +0100 Message-Id: <20221110171952.34207-4-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110171952.34207-1-vincent.knecht@mailoo.org> References: <20221110171952.34207-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749130546144048143?= X-GMAIL-MSGID: =?utf-8?q?1749130546144048143?= msg2138 only supports 2 fingers presses, and needs different processing since second finger press is encoded as a delta position wrt. first one and the packet/touch_event structs are not the same as msg2638. Add support for it by implementing distinct structs and irq handler. Signed-off-by: Vincent Knecht --- drivers/input/touchscreen/msg2638.c | 93 +++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c index 222adedf78bf..73e1b4d550fb 100644 --- a/drivers/input/touchscreen/msg2638.c +++ b/drivers/input/touchscreen/msg2638.c @@ -26,6 +26,7 @@ #define MODE_DATA_RAW 0x5A +#define MSG2138_MAX_FINGERS 2 #define MSG2638_MAX_FINGERS 5 #define CHIP_ON_DELAY_MS 15 @@ -38,6 +39,18 @@ struct msg_chip_data { unsigned int max_fingers; }; +struct msg2138_packet { + u8 xy_hi; /* higher bits of x and y coordinates */ + u8 x_low; + u8 y_low; +}; + +struct msg2138_touch_event { + u8 magic; + struct msg2138_packet pkt[MSG2138_MAX_FINGERS]; + u8 checksum; +}; + struct msg2638_packet { u8 xy_hi; /* higher bits of x and y coordinates */ u8 x_low; @@ -72,6 +85,80 @@ static u8 msg2638_checksum(u8 *data, u32 length) return (u8)((-sum) & 0xFF); } +static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler) +{ + struct msg2638_ts_data *msg2638 = msg2638_handler; + struct i2c_client *client = msg2638->client; + struct input_dev *input = msg2638->input_dev; + struct msg2138_touch_event touch_event; + u32 len = sizeof(touch_event); + struct i2c_msg msg[] = { + { + .addr = client->addr, + .flags = I2C_M_RD, + .len = sizeof(touch_event), + .buf = (u8 *)&touch_event, + }, + }; + struct msg2138_packet *p0, *p1; + u16 x, y, delta_x, delta_y; + int ret; + + ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); + if (ret != ARRAY_SIZE(msg)) { + dev_err(&client->dev, + "Failed I2C transfer in irq handler: %d\n", + ret < 0 ? ret : -EIO); + goto out; + } + + if (msg2638_checksum((u8 *)&touch_event, len - 1) != + touch_event.checksum) { + dev_err(&client->dev, "Failed checksum!\n"); + goto out; + } + + p0 = &touch_event.pkt[0]; + p1 = &touch_event.pkt[1]; + + /* Ignore non-pressed finger data */ + if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF) + goto report; + + x = (((p0->xy_hi & 0xF0) << 4) | p0->x_low); + y = (((p0->xy_hi & 0x0F) << 8) | p0->y_low); + + input_mt_slot(input, 0); + input_mt_report_slot_state(input, MT_TOOL_FINGER, true); + touchscreen_report_pos(input, &msg2638->prop, x, y, true); + + /* Ignore non-pressed finger data */ + if (p1->xy_hi == 0xFF && p1->x_low == 0xFF && p1->y_low == 0xFF) + goto report; + + /* Second finger is reported as a delta position */ + delta_x = (((p1->xy_hi & 0xF0) << 4) | p1->x_low); + delta_y = (((p1->xy_hi & 0x0F) << 8) | p1->y_low); + + /* Ignore second finger if both deltas equal 0 */ + if (delta_x == 0 && delta_y == 0) + goto report; + + x += delta_x; + y += delta_y; + + input_mt_slot(input, 1); + input_mt_report_slot_state(input, MT_TOOL_FINGER, true); + touchscreen_report_pos(input, &msg2638->prop, x, y, true); + +report: + input_mt_sync_frame(msg2638->input_dev); + input_sync(msg2638->input_dev); + +out: + return IRQ_HANDLED; +} + static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler) { struct msg2638_ts_data *msg2638 = msg2638_handler; @@ -331,12 +418,18 @@ static int __maybe_unused msg2638_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(msg2638_pm_ops, msg2638_suspend, msg2638_resume); +static const struct msg_chip_data msg2138_data = { + .irq_handler = msg2138_ts_irq_handler, + .max_fingers = MSG2138_MAX_FINGERS, +}; + static const struct msg_chip_data msg2638_data = { .irq_handler = msg2638_ts_irq_handler, .max_fingers = MSG2638_MAX_FINGERS, }; static const struct of_device_id msg2638_of_match[] = { + { .compatible = "mstar,msg2138", .data = &msg2138_data }, { .compatible = "mstar,msg2638", .data = &msg2638_data }, { } }; From patchwork Thu Nov 10 17:19:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 18239 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp276759wru; Thu, 10 Nov 2022 09:31:24 -0800 (PST) X-Google-Smtp-Source: AMsMyM4tKJQQf+qUazqWsz87ZrM8gUF2FJr3f/fBfT4UQXcosFVduqjlWuhGYnwMuuANYyK72BdI X-Received: by 2002:a17:90a:d901:b0:213:dc98:8b0d with SMTP id c1-20020a17090ad90100b00213dc988b0dmr59617642pjv.11.1668101484115; Thu, 10 Nov 2022 09:31:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668101484; cv=none; d=google.com; s=arc-20160816; b=pCYFbb6FKk/3Bh6foXYJTLRHzOUvvxQWISVI4iIxOjyT91qCSXjZ0uHGkKvJfwMFFt zKr3CxdV682VxYK+RPKCLCsLdTFOJKFa9MBF9H0j35D67howScvxju8QuvKxcLOjqb/j wLPkxZEbZCFcPQUwGBH8OV8ReTcTgMsHSLye6vE0ziVaAgcaHtn5Jgy5YH4PpeRzeGmb LkeGJ0SA59EPO1jJbBOqSGGWswD3mjp7WpKz1vCPG9IRc1rlLs8LhY8Nn1roc42hCg5P vfEM3X4wumxcCxWA4PFiUDy3fFERCowe51i+WGEa558UDB3AiLWDJ8dNAWSjmk8aHm/4 m/4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uUxsUZsXWsaOTUXobz95ziWWg/ylJwwusnusx3gtmoM=; b=sj/s3ztYDr6nVGzLWIgxWmligK6KRIBai9AeAuynoRmp14tYifhGTPh5D7wJP8Pw0n iyE/uttOtWF6Dcx+gxmOGxz1ECPrqt4udwQbnA/w4/5PsMbqeu/BOSSQUsmfWxdmUpWx AV6Subv/n/jeqytioa4grJoUUB0MrS1af6H1YjhGbq8P4ent+bKvuikWlcSv0PKW1lcr HhhLH3SVNticCPBkfIa5kB1xOPvv8RSYjNOG3cEoSXAT9M+d0ab+etrqQ4belCBe+14D keSFJJ2cyi1pbu3PyvvNx1i8RB9acscUBxa7JEGYij1dMCIP6NiOHoT7Faek0dB4VoMR amXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=aEZ2Tc2X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l9-20020a17090270c900b0018686834315si19033482plt.431.2022.11.10.09.31.08; Thu, 10 Nov 2022 09:31:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=aEZ2Tc2X; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbiKJRUv (ORCPT + 99 others); Thu, 10 Nov 2022 12:20:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231646AbiKJRUk (ORCPT ); Thu, 10 Nov 2022 12:20:40 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2203A63AC; Thu, 10 Nov 2022 09:20:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668100825; bh=BAISyk8kGHRtTm5nLUgo7ZXUxq/PfEWnuO/RpRSxSJk=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=aEZ2Tc2XPhB/sJ9oVVGxtgXRDVynZ0jq0L05wFnUCZ5aj7iCWErVerp352YycvC5E k8sRxTrPA7uL3rVKPAbyKKxMRwblzvLehzuniqntnkmLR47HUl+DArLTmtt+o/GnEQ i7joBDeEuyNjjjzqTIK/8/FF1PMo81SH2dIF56Z4= Received: by b-6.in.mailobj.net [192.168.90.16] with ESMTP via proxy.mailoo.org [213.182.55.207] Thu, 10 Nov 2022 18:20:24 +0100 (CET) X-EA-Auth: nZt5RN83dFv7IOPYvkYgydMf/UhJqFAk3c7g28jNZAqSRcoN0vZudhqoNEn63kIM8ne7CUiGZT8Y+0dO4TY0LF1L8eEW0FkOPhdLnmKsLjs= From: Vincent Knecht To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: w.david0@protonmail.com, stephan@gerhold.net, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, Rob Herring Subject: [PATCH v4 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Date: Thu, 10 Nov 2022 18:19:47 +0100 Message-Id: <20221110171952.34207-5-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110171952.34207-1-vincent.knecht@mailoo.org> References: <20221110171952.34207-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749131181746546139?= X-GMAIL-MSGID: =?utf-8?q?1749131181746546139?= Document optional linux,keycodes support. Acked-by: Rob Herring Signed-off-by: Vincent Knecht --- .../devicetree/bindings/input/touchscreen/mstar,msg2638.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml index 2fb7e01bb65a..af4f954de958 100644 --- a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml +++ b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml @@ -36,6 +36,10 @@ properties: touchscreen-size-x: true touchscreen-size-y: true + linux,keycodes: + minItems: 1 + maxItems: 4 + additionalProperties: false required: From patchwork Thu Nov 10 17:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 18240 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp279757wru; Thu, 10 Nov 2022 09:37:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM7X+rSLYxvPFZJtWT/pZDzvsUuCrCS/NW4Jst8lQaRal4pU8KJTLF+eu/OrDDDpvZ4B5nzS X-Received: by 2002:a17:90a:88f:b0:210:f235:1151 with SMTP id v15-20020a17090a088f00b00210f2351151mr1626216pjc.230.1668101852284; Thu, 10 Nov 2022 09:37:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668101852; cv=none; d=google.com; s=arc-20160816; b=rD7SNh7qjWujUuWo9S0XLgOQD5iN0oUIVMxCVE0Stb/EcNtb/1Kj1FDBpzUpWemxOi yQAgQ9umxMQnmbjpDaH5ZeMNeF3/FF3D7uotfY/GUe/dJtDQcQ0YJF1/OTMKHzsQQ2MB rJzOt3hUH5yUnW8L3ByokopxS9Ym+nFnf4VH4/YhaQc44yK3FUChfXnoYDi7F7RqUYsx B2Dz13ozCDsrDziYMfd/FI38JT/sBS0jcOL0c3rxhGhGF16hWtl/sqJoRjHJ1sVVz+sQ xzhoDckqJNAeVC4vTiH/IOjDdiLuGgsVlR3Baoqf903KgKR2ug/EEBONAhcEBuSDBH6V AtVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CWvLDuYF5vR7ut59+GmUvv/5iVfw6gYxVMUERPJZnh0=; b=MxM3wI5lJt5FXoMTkoExNu4FEfx73oUxcrkvVeuDTRJ1xW6AMa7N8EGJ54ZMwLAX8/ iejZerLD5IRxnDmcRcSj9g2kXB0+otS0cQheuxX86j+pMFxG9ZiHGkF4WKHtzFgCEHDt n7FDKc7KkPaLfhDk6bqfVwiXMhBhNWF5Sf0M87ZSoMJNSyptWbwqEbQCH/8CsFsPBiY4 iHx1jaPCeIYn6gwdmxLt8jw2lfG5Sv5KYeu0UO3/3zEq+q+OaWbIOS+vX9ICZXI+Ur/R /sUFT8tSBClHsnw3G2GnFCqmryc9TfhkQxVhuYoNkBuV8hxch3LpJExXc/PjXXtEbXGh seOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=fajgFlZh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a170903228a00b001780ba6c694si23876251plh.35.2022.11.10.09.37.16; Thu, 10 Nov 2022 09:37:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=fajgFlZh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231731AbiKJRUz (ORCPT + 99 others); Thu, 10 Nov 2022 12:20:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231702AbiKJRUt (ORCPT ); Thu, 10 Nov 2022 12:20:49 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EABFCF594; Thu, 10 Nov 2022 09:20:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668100832; bh=Kf0fNlGsDsRSuOjAAsDcc4gChjhmw9Z/lyP6jAa/dFA=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=fajgFlZhaaiXbLn7jT1pv3w2mXklLWRyqmN/a7uwL6sTKPFR1nUih3YozHVx7gxc7 CePbAwQ6ITgrxFCG/mc1CSOLPgu3k4X1o+eJDA1s3RYvsQvaeLxbwY2JhQL+EWxTI1 T2JUlGfuHLFswsFU+MsQG6buMnfzLAD6yQ3tKbIA= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via proxy.mailoo.org [213.182.55.207] Thu, 10 Nov 2022 18:20:31 +0100 (CET) X-EA-Auth: lcPdtQDwbd5WixXkQaMO8eww4IHjNcYBnAZRusvFKb7KqcKeV38ldXy9DypC7TYRab1ocfB4+uOgl1VWkSVrXkhWvjNPaZhZMTp/gIubwGY= From: Vincent Knecht To: Dmitry Torokhov , Rob Herring , Krzysztof Kozlowski , Vincent Knecht , linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: w.david0@protonmail.com, stephan@gerhold.net, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [PATCH v4 5/5] Input: msg2638 - Add support for msg2138 key events Date: Thu, 10 Nov 2022 18:19:48 +0100 Message-Id: <20221110171952.34207-6-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221110171952.34207-1-vincent.knecht@mailoo.org> References: <20221110171952.34207-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749131568013932018?= X-GMAIL-MSGID: =?utf-8?q?1749131568013932018?= Some devices with msg2138 have back/menu/home keys. Add support for them. Signed-off-by: Vincent Knecht --- drivers/input/touchscreen/msg2638.c | 53 +++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c index 73e1b4d550fb..36069b30ab9b 100644 --- a/drivers/input/touchscreen/msg2638.c +++ b/drivers/input/touchscreen/msg2638.c @@ -29,6 +29,8 @@ #define MSG2138_MAX_FINGERS 2 #define MSG2638_MAX_FINGERS 5 +#define MAX_BUTTONS 4 + #define CHIP_ON_DELAY_MS 15 #define FIRMWARE_ON_DELAY_MS 50 #define RESET_DELAY_MIN_US 10000 @@ -72,6 +74,8 @@ struct msg2638_ts_data { struct regulator_bulk_data supplies[2]; struct gpio_desc *reset_gpiod; int max_fingers; + u32 keycodes[MAX_BUTTONS]; + int num_keycodes; }; static u8 msg2638_checksum(u8 *data, u32 length) @@ -85,6 +89,19 @@ static u8 msg2638_checksum(u8 *data, u32 length) return (u8)((-sum) & 0xFF); } +static void msg2138_report_keys(struct msg2638_ts_data *msg2638, u8 keys) +{ + int i; + + /* keys can be 0x00 or 0xff when all keys have been released */ + if (keys == 0xff) + keys = 0; + + for (i = 0; i < msg2638->num_keycodes; ++i) + input_report_key(msg2638->input_dev, msg2638->keycodes[i], + !!(keys & BIT(i))); +} + static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler) { struct msg2638_ts_data *msg2638 = msg2638_handler; @@ -121,9 +138,12 @@ static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler) p0 = &touch_event.pkt[0]; p1 = &touch_event.pkt[1]; - /* Ignore non-pressed finger data */ - if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF) + /* Ignore non-pressed finger data, but check for key code */ + if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF) { + if (p1->xy_hi == 0xFF && p1->y_low == 0xFF) + msg2138_report_keys(msg2638, p1->x_low); goto report; + } x = (((p0->xy_hi & 0xF0) << 4) | p0->x_low); y = (((p0->xy_hi & 0x0F) << 8) | p0->y_low); @@ -283,6 +303,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638) struct device *dev = &msg2638->client->dev; struct input_dev *input_dev; int error; + int i; input_dev = devm_input_allocate_device(dev); if (!input_dev) { @@ -299,6 +320,14 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638) input_dev->open = msg2638_input_open; input_dev->close = msg2638_input_close; + if (msg2638->num_keycodes) { + input_dev->keycode = msg2638->keycodes; + input_dev->keycodemax = msg2638->num_keycodes; + input_dev->keycodesize = sizeof(msg2638->keycodes[0]); + for (i = 0; i < msg2638->num_keycodes; i++) + input_set_capability(input_dev, EV_KEY, msg2638->keycodes[i]); + } + input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X); input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y); @@ -367,10 +396,16 @@ static int msg2638_ts_probe(struct i2c_client *client) return error; } - error = msg2638_init_input_dev(msg2638); - if (error) { - dev_err(dev, "Failed to initialize input device: %d\n", error); - return error; + msg2638->num_keycodes = + of_property_read_variable_u32_array(dev->of_node, "linux,keycodes", + msg2638->keycodes, 0, + ARRAY_SIZE(msg2638->keycodes)); + if (msg2638->num_keycodes == -EINVAL) { + msg2638->num_keycodes = 0; + } else if (msg2638->num_keycodes < 0) { + dev_err(dev, "Unable to parse linux,keycodes property: %d\n", + msg2638->num_keycodes); + return msg2638->num_keycodes; } error = devm_request_threaded_irq(dev, client->irq, @@ -382,6 +417,12 @@ static int msg2638_ts_probe(struct i2c_client *client) return error; } + error = msg2638_init_input_dev(msg2638); + if (error) { + dev_err(dev, "Failed to initialize input device: %d\n", error); + return error; + } + return 0; }