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 }, { } };