From patchwork Wed Nov 16 18:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 21214 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp288320wru; Wed, 16 Nov 2022 10:21:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf58/dRZ9rI5eZ4krzLgxUmD6xEdV21vca9MFuWPFsEG++n9YqEnLixFqb6k8cgdaBjNzjEo X-Received: by 2002:a17:906:7203:b0:7ae:664a:a7d2 with SMTP id m3-20020a170906720300b007ae664aa7d2mr18686155ejk.676.1668622867881; Wed, 16 Nov 2022 10:21:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668622867; cv=none; d=google.com; s=arc-20160816; b=rPSOeciHR2QcqqVtkf+Ez/1AlfhAiAxE+cftbXSZd+NqNMEgL8IJ457138rooWpaqh Q2KnLApYdjOirGsqkcV8AkrVtY79y3ZfniNCPVdXQpcUccgiJfmrsnFb+nIp/Kmwm3rz 4jkPNMXGuwKXuRxECGl720NaFoMt6E9qUYw17Q7cGGh08a3NZtiMyaso769sDZAzw2ud rbXd8P1QocOMo32FoClAwUHrtOoIOqHQQKNRfhpC3C499w10RtgbZNnK1P9bTGTR4JGr kyoDZLx1IFFqsHP/vHwqlXtawnB4WSCzhNt+XTOKEe142VOmeJaw2eqCRWDAUz05LqOU IGAg== 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=Ke8SX3YkUo66mAaTsSwgiKmnkB337F/QU3yPt4LuGObU9LePV/h+Jj2Z7AxGUxLBTx 8XOZBtgmG6y9LiegjAtR65aKqrzDahMUL/hyT68SZFiTFZWSZyQHg8jEJr6sXeQ3tY7X Y80oH3v8XUZgxLg9Eew7wOn7YuO4lt+47pMthVUG3/tbxEqeivS8V4dYDguKG4uW1dQf FU8QgqBthVFtUKv9aMhmjxe9k1pa1jJIlf5RZZU5/3Ogmeai7OQHWJrSu/swQUdYXv6w krnDSEUi81SajiRYUUmBn7wyXWyJNU4M8xs4rnifks7YZ0IBybmjAYI2hrKUGrx280Lv QFUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=Sf6m3og6; 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 nc33-20020a1709071c2100b0078d9db99f5esi16533246ejc.39.2022.11.16.10.20.44; Wed, 16 Nov 2022 10:21:07 -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=Sf6m3og6; 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 S239171AbiKPSSL (ORCPT + 99 others); Wed, 16 Nov 2022 13:18:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239149AbiKPSRx (ORCPT ); Wed, 16 Nov 2022 13:17:53 -0500 Received: from msg-4.mailo.com (msg-4.mailo.com [213.182.54.15]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ABCA663BB2; Wed, 16 Nov 2022 10:17:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668622655; 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=Sf6m3og6lVcyRNaYo3bWT7q2aMAl5PXqz7L5ExOC0aAEa0EsDFyEudN+7uBbnNEfA lVXaudQI0XC8NayisnlxBGxdqnB7uVsxFRfH9qTZ5adJjMXYl9ZyY2QtStqbDVkZJK H8MdrVIxGh3tYS9i+R2dECa6kRYx/LykNWAPUKBY= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via proxy.mailoo.org [213.182.55.207] Wed, 16 Nov 2022 19:17:35 +0100 (CET) X-EA-Auth: wSipETKokjIuLHYQAap4EutWqlFb8Chg4dUum3LiaGfQJEUzOPndPQvG4HoXEnvkzwAr0ky2eQAT/d1XZV0VT/Jaaw+ubZCLet9MeL0/NT0= 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 v5 1/2] dt-bindings: input: touchscreen: msg2638: Document keys support Date: Wed, 16 Nov 2022 19:17:11 +0100 Message-Id: <20221116181715.2118436-2-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116181715.2118436-1-vincent.knecht@mailoo.org> References: <20221116181715.2118436-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?1749677892096214549?= X-GMAIL-MSGID: =?utf-8?q?1749677892096214549?= 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 Wed Nov 16 18:17:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 21215 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp288362wru; Wed, 16 Nov 2022 10:21:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ISktBoBQFRCIUTSLrPzdU/vPFgwDwg2q+Wi+t1tvrhyjkrtKI4f19AHuZrWGHq+wX//iW X-Received: by 2002:a17:906:8587:b0:78d:b367:20c1 with SMTP id v7-20020a170906858700b0078db36720c1mr17747099ejx.530.1668622872955; Wed, 16 Nov 2022 10:21:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668622872; cv=none; d=google.com; s=arc-20160816; b=SvhDLCZ0V8t1MKwjzxuRG9oPSL85eNDbC3mqqgny4c2HZRZQ5Wfk0AdhxzDA5MIi/N eGpdK5kw/tX7MFT4YwooNbGAUldXUbg3bpWHbAo2XRG7HLebAOr8NRafZxo+GlNEX8kh zr8FVus+fvTMpXiIQwfFYIPywFPlvlPrIvCzwVCceheIc1U0/sf9hTb39LqlH+cI1jAu G1Xcjm02jf62B6UKzI4sBBYsqjYV8Pse5yoD4a6ALPhXGYyAg/vaS8Y0n6b+ftOs+LNQ pN4VSJu9bEcX0+WG5PLUTcI63hQtlzl0RdhDa2QounicnSqSBr0MWf2KsOqJbX6poRQV 6EYg== 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=9AUM6Jnx+sm2nAJH5xLK+LjJ2BVxQCGxjhiNxUWyC/Y=; b=YWG6zTA18wL3I81Gia3leW3iHxprvzo18pxZRzUizXtFlRg42G9R4lwWrcWH9uZyCd VMHtFm70MXR6bs+xZwCCA7XZKwK5SAPGM3gSVL7gXNwj6xb31HBdxdlY91d/HY/LFbM1 /rG9uAaZipadlFB1LDcOQjrxwGvgcmRh2ZaSa9ENXEWNKC9HJbLqR6EjHb266dHgoOcW AYJOPvBMf0PxmLdEamIOa+kXWYvrO3oiJ5LkHTUuhhFp2u3/pF5Iejqe/SBsTf3czF0I eupQsVyTIlZ86Ap4P6EQOami8ecN6KJwkfjdkJYupqPCB561D1DbC/+MINSkHCT3I6zw l6wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailoo.org header.s=mailo header.b=GXNh8juI; 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 q2-20020a056402248200b0046883aeffd8si2274466eda.278.2022.11.16.10.20.49; Wed, 16 Nov 2022 10:21:12 -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=GXNh8juI; 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 S239184AbiKPSSN (ORCPT + 99 others); Wed, 16 Nov 2022 13:18:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239176AbiKPSR4 (ORCPT ); Wed, 16 Nov 2022 13:17:56 -0500 Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A66863CE6; Wed, 16 Nov 2022 10:17:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1668622659; bh=hcz2B9lEKCAk88gmV72PQOmNIdy0PG680Bth19yXE6U=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=GXNh8juIZ3Cz5sv4wb28Z26R726K+3/mUhF/HDmyzW2wvEd5cmaKS5XwByNtCC2zA IZG+X54EyD/Zc3j/fTe3PFmNxJ0lf5lIcmBim7yhMSQBsTV7PCNlW9dgEZeUYUqMkY GN6EOafyzgdMyWgwS/4rYb8HiuPPjD/ih8JJd24c= Received: by b-3.in.mailobj.net [192.168.90.13] with ESMTP via proxy.mailoo.org [213.182.55.207] Wed, 16 Nov 2022 19:17:39 +0100 (CET) X-EA-Auth: lyQHpFsSWm9xEoOcRBj9Zc01ohbcEWw2i03/a6BHqD+m7Me2zxybFB2zhhIxm2+9bl+VVuY9SrQjXSwS+WosGerd5R/6ocDsZP70iRi53sQ= 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 v5 2/2] Input: msg2638 - Add support for msg2138 key events Date: Wed, 16 Nov 2022 19:17:12 +0100 Message-Id: <20221116181715.2118436-3-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221116181715.2118436-1-vincent.knecht@mailoo.org> References: <20221116181715.2118436-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?1749677897552289372?= X-GMAIL-MSGID: =?utf-8?q?1749677897552289372?= Some devices with msg2138 have back/menu/home keys. Add support for them. Signed-off-by: Vincent Knecht --- drivers/input/touchscreen/msg2638.c | 57 +++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c index 95b18563326a..a0f5e1ecd612 100644 --- a/drivers/input/touchscreen/msg2638.c +++ b/drivers/input/touchscreen/msg2638.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,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 +75,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 +90,18 @@ 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,9 +396,23 @@ static int msg2638_ts_probe(struct i2c_client *client) return error; } - error = msg2638_init_input_dev(msg2638); + msg2638->num_keycodes = fwnode_property_count_u32(dev->fwnode, "linux,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; + } else if (msg2638->num_keycodes > ARRAY_SIZE(msg2638->keycodes)) { + dev_warn(dev, "Found %d linux,keycodes but max is %ld, ignoring the rest\n", + msg2638->num_keycodes, ARRAY_SIZE(msg2638->keycodes)); + msg2638->num_keycodes = ARRAY_SIZE(msg2638->keycodes); + } + + error = fwnode_property_read_u32_array(dev->fwnode, "linux,keycodes", + msg2638->keycodes, msg2638->num_keycodes); if (error) { - dev_err(dev, "Failed to initialize input device: %d\n", error); + dev_err(dev, "Unable to read linux,keycodes values: %d\n", error); return error; } @@ -382,6 +425,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; }