From patchwork Tue Nov 23 08:14:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 12633647 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 84ADDC2BB1D for ; Tue, 23 Nov 2021 08:14:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234042AbhKWISC (ORCPT ); Tue, 23 Nov 2021 03:18:02 -0500 Received: from ip-16.mailobj.net ([213.182.54.16]:37336 "EHLO msg-6.mailo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231654AbhKWIR7 (ORCPT ); Tue, 23 Nov 2021 03:17:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1637655278; bh=iT0rl7fH7xnXfFgOdGFIwgUFiQzXwXtySjcxfbbb3Gk=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=YFeFGvhqJKmAOkS29AP+eHEWq3IKlMXo3cP7PL4DifCW2ZMVihRFmhC/oEdwflBEU lQaaOwwKMY+fgxMZB8GoI2dsy6Kzuy4atk3hxxzd5FQPAH+AQPalpmKUIcY0fZmn98 l4Gtm3xQDnPMEu4AFdIAzpbj9Ho7VaxovYTIZ5Z4= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via proxy.mailoo.org [213.182.55.207] Tue, 23 Nov 2021 09:14:38 +0100 (CET) X-EA-Auth: LazUKC4TQ+R3k21SkQzrFBO6Bo+IYrtV3YCsRlAWzAA08lMgc9JUJvp9XaeXQj8CtbswR3Gp5TG6fxfo0smM+4gG+KYsR02N+ubaNW5AJFU= From: Vincent Knecht To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, stephan@gerhold.net, vincent.knecht@mailoo.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [RESEND PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Date: Tue, 23 Nov 2021 09:14:29 +0100 Message-Id: <20211123081433.2797395-2-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211123081433.2797395-1-vincent.knecht@mailoo.org> References: <20211123081433.2797395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 Tue Nov 23 08:14:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 12633643 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 EEECBC4167D for ; Tue, 23 Nov 2021 08:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232588AbhKWISA (ORCPT ); Tue, 23 Nov 2021 03:18:00 -0500 Received: from msg-1.mailo.com ([213.182.54.11]:32848 "EHLO msg-1.mailo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbhKWIR7 (ORCPT ); Tue, 23 Nov 2021 03:17:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1637655279; bh=ZwzXkb7VIVdxLCW5G29KqfRqnSdsTMlAwEou3+9HlHU=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=P7ezOnX36U5pCWSpX5yAwrkaplxRVmWQTysAFkkv7xucS6KHchhBZI4lg8Hzeu2O9 ReA5TLsAnW3smVRT3QgCRkRPBJQy2TOwVxQXJ6oWQoGAnfnrsRniuffgR35QBzWd1j ZlDADUNanq/4B2jUTblnddl2TXXHk7B8VNTHyU7U= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via proxy.mailoo.org [213.182.55.207] Tue, 23 Nov 2021 09:14:39 +0100 (CET) X-EA-Auth: /RwhYz0QmzDyOu0Mab/Gl2HLnGb2fjjS+A9AEGk4uT5+XSEF3AQllxiYneAMpH54bwkArtfO5d8a6HvqNo2ElatayAP3KH8AZvW75rxawy8= From: Vincent Knecht To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, stephan@gerhold.net, vincent.knecht@mailoo.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [RESEND PATCH 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Date: Tue, 23 Nov 2021 09:14:30 +0100 Message-Id: <20211123081433.2797395-3-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211123081433.2797395-1-vincent.knecht@mailoo.org> References: <20211123081433.2797395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Document msg2138 support by adding mstar,msg2138 compatible. Signed-off-by: Vincent Knecht Acked-by: Rob Herring --- .../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 Tue Nov 23 08:14:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 12633645 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 F0949C001B6 for ; Tue, 23 Nov 2021 08:14:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233234AbhKWISB (ORCPT ); Tue, 23 Nov 2021 03:18:01 -0500 Received: from msg-1.mailo.com ([213.182.54.11]:32850 "EHLO msg-1.mailo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231240AbhKWIR7 (ORCPT ); Tue, 23 Nov 2021 03:17:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1637655279; bh=MASZqEgxsq7WyBCo873lD4NA/nT59nBDoAYAKnJD8IQ=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=ZYFEWDLtpxZ09/1axJuhkzlAm3HT9Srx3T3HyyLYzVnEXh8nOOOY8zvvOMxAMBw+h HAHKgT3/wHuRVa1Otor2oTr+Q5i//9/QbVyZBzrG2g02nwDWx0JBLnv+prPoeqB8xx v34YNsqxOwhZNQhTc04Ojzoi22f6bKhFzux8oDQY= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via proxy.mailoo.org [213.182.55.207] Tue, 23 Nov 2021 09:14:39 +0100 (CET) X-EA-Auth: BCzOoqWL/GI3NtOW8NjK4mX0xRXWR5Kc59MqofBykz1Wbu0Hcx/B220cL9gOTB1EuDnRQW0PiYM/YuQCx/BXyqVHBmYpM3tYMIOMq/XQQuQ= From: Vincent Knecht To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, stephan@gerhold.net, vincent.knecht@mailoo.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [RESEND PATCH 3/5] Input: msg2638 - Add support for msg2138 Date: Tue, 23 Nov 2021 09:14:31 +0100 Message-Id: <20211123081433.2797395-4-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211123081433.2797395-1-vincent.knecht@mailoo.org> References: <20211123081433.2797395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 Tue Nov 23 08:14:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 12633639 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 16EEDC433F5 for ; Tue, 23 Nov 2021 08:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231764AbhKWIR7 (ORCPT ); Tue, 23 Nov 2021 03:17:59 -0500 Received: from msg-1.mailo.com ([213.182.54.11]:32846 "EHLO msg-1.mailo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231158AbhKWIR6 (ORCPT ); Tue, 23 Nov 2021 03:17:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1637655280; bh=1ik2lIfFWQwygKDFBz1wycmemRjU/mep6maZiu4NSAU=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=YmO1gcScKVg/BTHwIa5MUH5JH846VDcV/b6h/l99uHGlIOfdUiUzEfJvhfUKpoVAd 7LbkmddVoLUdJwTmP/a8RapIhsF9MsZSfRisH7Nd0nwIKjD7AHLYx0yeWLhkfrMmKt rR0I4bO+qkM+2625+z1yyLiMJ8TyzDZ8RP90uxZg= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via proxy.mailoo.org [213.182.55.207] Tue, 23 Nov 2021 09:14:39 +0100 (CET) X-EA-Auth: 5x2kE+nod+nU2crg9xqb15IIOzLPW3JahqhomVKn7nqfdmvrGHev0sjKvK5VprcHN8+2xKdt25rN/BhBgAwm0HvuDVR0PSNBgcC5DqiE4fg= From: Vincent Knecht To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, stephan@gerhold.net, vincent.knecht@mailoo.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [RESEND PATCH 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Date: Tue, 23 Nov 2021 09:14:32 +0100 Message-Id: <20211123081433.2797395-5-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211123081433.2797395-1-vincent.knecht@mailoo.org> References: <20211123081433.2797395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Document optional linux,keycodes support. Signed-off-by: Vincent Knecht Acked-by: Rob Herring --- .../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 Tue Nov 23 08:42:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Knecht X-Patchwork-Id: 12633761 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 3E88FC433F5 for ; Tue, 23 Nov 2021 08:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234665AbhKWIp7 (ORCPT ); Tue, 23 Nov 2021 03:45:59 -0500 Received: from ip-15.mailobj.net ([213.182.54.15]:41036 "EHLO msg-4.mailo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234521AbhKWIp6 (ORCPT ); Tue, 23 Nov 2021 03:45:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailoo.org; s=mailo; t=1637656964; bh=9tJuT8H6s5pFq5Bsc3kMzvOhJLx8R8WnmS8tZXkO6zU=; h=X-EA-Auth:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=E0CuYQKjmxz8YEialj+tsYeK0J3cg19238Y53lzxqGOkjxXHjjA97QdMBwEKo7Wxw I9c4DhS5mkhKVLhO+DKULQqoct7wNyXFcd27vrXIT5AJ9JMmQXGyGh+1/w48ht40CS /HEvYAyvgmk1ygp1JZDgBXVafWf8lV9aU7D5aeTY= Received: by b-4.in.mailobj.net [192.168.90.14] with ESMTP via proxy.mailoo.org [213.182.55.207] Tue, 23 Nov 2021 09:42:44 +0100 (CET) X-EA-Auth: 1ykj/Cbkf1585m1hLxziGLgbj+5OxOzG6vWm+C3nGiqaS5LrYreSiRls5aTPtSWFDvP0KsWeL31/x3naS4MbheCNqy4A6CrDAgKn9vuJxcY= From: Vincent Knecht To: dmitry.torokhov@gmail.com, robh+dt@kernel.org, stephan@gerhold.net, vincent.knecht@mailoo.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht Subject: [RESEND PATCH 5/5] Input: msg2638 - Add support for msg2138 key events Date: Tue, 23 Nov 2021 09:42:34 +0100 Message-Id: <20211123084234.2809198-1-vincent.knecht@mailoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211123081433.2797395-1-vincent.knecht@mailoo.org> References: <20211123081433.2797395-1-vincent.knecht@mailoo.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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; }