From patchwork Sun Feb 10 10:30:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yauhen Kharuzhy X-Patchwork-Id: 10804711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F1A9113B4 for ; Sun, 10 Feb 2019 10:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D8D072A00B for ; Sun, 10 Feb 2019 10:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAF202A01C; Sun, 10 Feb 2019 10:31:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 440562A00B for ; Sun, 10 Feb 2019 10:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726035AbfBJKbE (ORCPT ); Sun, 10 Feb 2019 05:31:04 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:40175 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726032AbfBJKbD (ORCPT ); Sun, 10 Feb 2019 05:31:03 -0500 Received: by mail-lf1-f67.google.com with SMTP id t14so5594677lfk.7 for ; Sun, 10 Feb 2019 02:31:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3PH37FoMb240qdggdTFdraGFoa8DgyXNxR3YW6EXPHY=; b=oz4mhGHiG3c79j26Rn8nC7pArz640K+lO7jz0cE/M/5fOEoZ/x+S5IEPJCyGtIi55a Jojfk7oC34YCq+U1CEL1SGztUNPzn2tGBm22iYKZuEwW1BmOvfkiA/D4mWf7vpF82Djr TmE55qN5rfDQFuH4jiTDgJ/xkPieTRobX2DfHKUjMgKENji2TVQphLZIQ3fbo8wMHfoX TvIuPktAO2nE7Ccoc/s9bGPN9JgN4rbTukDnmPxzmQbRFInfpYce7sEk7gWnuT8fSXO+ z3HuBtmiLtncqJFUNRvDj1FLXXln6vktMG420Ecg9Rc3s9Jz5N9yaDUiMiQcpjK4dfIY YzhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3PH37FoMb240qdggdTFdraGFoa8DgyXNxR3YW6EXPHY=; b=jXoNBI2UExUW+ZKPa/PokJM5ONXn5H2FAB+keCxkD2vMeRsjPNGbNbxsnZH+btlYXP AlTuOOVsJ09cOFcN33Ma2LTBBBhaE9qgH61kkv796OpfJww3ARdzx88wT0YPzjwgfUsL sRpP1FqSeo5Xj1FHyinS6/IKwiisXPJJPWw46czLVZ6mvHOZXB4RAc7QFcqSZ10Rq6Bj 692KhzLV2f2rX/FNUvPakFhq7L2Yz183WHAGXO6fdmFu8LXqVeyQj32UK0bPbv+7F3Ii DeZ8FvumINF9VCyPmYhepjOP7mVWGwmbywDQw8Buw5RPjerdMAVUpXOORLB9J7iPnxy2 YWaQ== X-Gm-Message-State: AHQUAuawtpqJVZK5w7fjFx+oChpQSs7wT41R4s0eBimIMkgmGjI+Q4y5 G7iMXtadaKjOjwrnrwqWe4+1idh+ X-Google-Smtp-Source: AHgI3IZqfGAEHbMKIYXKpfPpcFcu0OYy0jSm7TMzF51E0clYKM9p9vwnSgZwHGpFT1CHbZeEHwAtYA== X-Received: by 2002:ac2:434f:: with SMTP id o15mr18386527lfl.29.1549794660747; Sun, 10 Feb 2019 02:31:00 -0800 (PST) Received: from localhost.localdomain (mm-65-44-215-37.mfilial.dynamic.pppoe.byfly.by. [37.215.44.65]) by smtp.gmail.com with ESMTPSA id x25-v6sm1455124ljd.61.2019.02.10.02.30.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 10 Feb 2019 02:30:59 -0800 (PST) Received: from jek by localhost.localdomain with local (Exim 4.92-RC4) (envelope-from ) id 1gsmNz-00088J-DX; Sun, 10 Feb 2019 13:30:55 +0300 From: Yauhen Kharuzhy To: linux-input@vger.kernel.org Cc: Bastien Nocera , Yauhen Kharuzhy Subject: [PATCH] goodix touchscreen: Add support for 9-bytes reports Date: Sun, 10 Feb 2019 13:30:51 +0300 Message-Id: <20190210103051.31219-1-jekhor@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some variants of Goodix touchscreen firmwares use 9-bytes finger report format instead of common 8-bytes format. This report format may be present as: struct goodix_contact_data { uint8_t unknown1; uint8_t track_id; uint8_t unknown2; uint16_t x; uint16_t y; uint16_t w; }__attribute__((packed)); Add support for such format and use it for Lenovo Yoga Book notebook (which uses a Goodix touchpad as a touch keyboard). Signed-off-by: Yauhen Kharuzhy --- drivers/input/touchscreen/goodix.c | 58 +++++++++++++++++++++++++----- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c index f2d9c2c41885..f42860c788b9 100644 --- a/drivers/input/touchscreen/goodix.c +++ b/drivers/input/touchscreen/goodix.c @@ -54,6 +54,7 @@ struct goodix_ts_data { const char *cfg_name; struct completion firmware_loading_complete; unsigned long irq_flags; + unsigned int contact_size; }; #define GOODIX_GPIO_INT_NAME "irq" @@ -63,6 +64,7 @@ struct goodix_ts_data { #define GOODIX_MAX_WIDTH 4096 #define GOODIX_INT_TRIGGER 1 #define GOODIX_CONTACT_SIZE 8 +#define GOODIX_MAX_CONTACT_SIZE 9 #define GOODIX_MAX_CONTACTS 10 #define GOODIX_CONFIG_MAX_LENGTH 240 @@ -145,6 +147,19 @@ static const struct dmi_system_id rotated_screen[] = { {} }; +static const struct dmi_system_id nine_bytes_report[] = { +#if defined(CONFIG_DMI) && defined(CONFIG_X86) + { + .ident = "Lenovo YogaBook", + /* YB1-X91L/F and YB1-X90L/F */ + .matches = { + DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9") + } + }, +#endif + {} +}; + /** * goodix_i2c_read - read data from a register of the i2c slave device. * @@ -248,7 +263,7 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) max_timeout = jiffies + msecs_to_jiffies(GOODIX_BUFFER_STATUS_TIMEOUT); do { error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR, - data, GOODIX_CONTACT_SIZE + 1); + data, ts->contact_size + 1); if (error) { dev_err(&ts->client->dev, "I2C transfer error: %d\n", error); @@ -261,12 +276,12 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) return -EPROTO; if (touch_num > 1) { - data += 1 + GOODIX_CONTACT_SIZE; + data += 1 + ts->contact_size; error = goodix_i2c_read(ts->client, GOODIX_READ_COOR_ADDR + - 1 + GOODIX_CONTACT_SIZE, + 1 + ts->contact_size, data, - GOODIX_CONTACT_SIZE * + ts->contact_size * (touch_num - 1)); if (error) return error; @@ -285,7 +300,7 @@ static int goodix_ts_read_input_report(struct goodix_ts_data *ts, u8 *data) return 0; } -static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data) +static void goodix_ts_report_touch_8b(struct goodix_ts_data *ts, u8 *coor_data) { int id = coor_data[0] & 0x0F; int input_x = get_unaligned_le16(&coor_data[1]); @@ -300,6 +315,21 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data) input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); } +static void goodix_ts_report_touch_9b(struct goodix_ts_data *ts, u8 *coor_data) +{ + int id = coor_data[1] & 0x0F; + int input_x = get_unaligned_le16(&coor_data[3]); + int input_y = get_unaligned_le16(&coor_data[5]); + int input_w = get_unaligned_le16(&coor_data[7]); + + input_mt_slot(ts->input_dev, id); + input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true); + touchscreen_report_pos(ts->input_dev, &ts->prop, + input_x, input_y, true); + input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w); + input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, input_w); +} + /** * goodix_process_events - Process incoming events * @@ -310,7 +340,7 @@ static void goodix_ts_report_touch(struct goodix_ts_data *ts, u8 *coor_data) */ static void goodix_process_events(struct goodix_ts_data *ts) { - u8 point_data[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; + u8 point_data[1 + GOODIX_MAX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; int touch_num; int i; @@ -325,8 +355,12 @@ static void goodix_process_events(struct goodix_ts_data *ts) input_report_key(ts->input_dev, KEY_LEFTMETA, point_data[0] & BIT(4)); for (i = 0; i < touch_num; i++) - goodix_ts_report_touch(ts, - &point_data[1 + GOODIX_CONTACT_SIZE * i]); + if (ts->contact_size == 9) + goodix_ts_report_touch_9b(ts, + &point_data[1 + ts->contact_size * i]); + else + goodix_ts_report_touch_8b(ts, + &point_data[1 + ts->contact_size * i]); input_mt_sync_frame(ts->input_dev); input_sync(ts->input_dev); @@ -709,6 +743,13 @@ static int goodix_configure_dev(struct goodix_ts_data *ts) "Applying '180 degrees rotated screen' quirk\n"); } + if (dmi_check_system(nine_bytes_report)) { + ts->contact_size = 9; + + dev_dbg(&ts->client->dev, + "Non-standard 9-bytes report format quirk\n"); + } + error = input_mt_init_slots(ts->input_dev, ts->max_touch_num, INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); if (error) { @@ -781,6 +822,7 @@ static int goodix_ts_probe(struct i2c_client *client, ts->client = client; i2c_set_clientdata(client, ts); init_completion(&ts->firmware_loading_complete); + ts->contact_size = GOODIX_CONTACT_SIZE; error = goodix_get_gpio_config(ts); if (error)