From patchwork Sat Dec 5 05:33:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 338478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A0CDC2BB40 for ; Sat, 5 Dec 2020 05:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3792422D3E for ; Sat, 5 Dec 2020 05:35:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727511AbgLEFex (ORCPT ); Sat, 5 Dec 2020 00:34:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725730AbgLEFex (ORCPT ); Sat, 5 Dec 2020 00:34:53 -0500 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75D7CC061A4F; Fri, 4 Dec 2020 21:34:12 -0800 (PST) Received: by mail-lf1-x132.google.com with SMTP id a9so10651822lfh.2; Fri, 04 Dec 2020 21:34:12 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=w+OeAkZgNj+MXQ3DH4VONGYNB4R07iZ8IreFmZG+j/c=; b=u422r3rjlGqP3sR2ovIAgjx3vy6jdu69rhOhKvSz660wSjNqMVVfH6UeUcsYsDp6Ir v8DKkcedwpW7K/wTD0wRzjsotVNDQpRy+YkeU35IbR55+VbrhhkHM467mNnGQlo+oVSC 3LOqVEt4N40xs/9u0ELOvo5crFb1H2wNwbBiKbwSKmznxGkvhX9m8kZa2/nZRPkiOHOW NMxRtGDo4IzMU1QXiVsWRmtAx78gclw67JzsFBxnSpwMkuloKiJZmyCdHGUwWTwpbi93 Nrq5WmFp34T39fEW/ZuCK9gqzDxPKBMXbyF2BDlnzf83LucnzBpaRkbfBDsAsihGqFfG 05eA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=w+OeAkZgNj+MXQ3DH4VONGYNB4R07iZ8IreFmZG+j/c=; b=rpavMhLkNXY/S3Zv48WzrY1CmZLExXYt/I6GfO6x3Bx3HRvAqRp2Z4Kg0L/NOc9Ozn SkoEMTXgQOjePihGH2IXWICJ/F+NwYfd26DTbrYxzTYVttDI7nQaY0J5haPh5xNa9gn5 5DdZtkz9kba6EDXJMLZCmZvp+tbtxKvKDKAGhatp3xJXpgEG9WcNIzvGatgZ/KmMQD/p W8b1k/VgZP/5eOU6lv8YnB2snqMdfoKad+MoGBB41Pt6JV5z7gicMHN2Qrjn1kaRploE ZxcNIc8MHhYiPwxTuqwrYYr4VLHgNV4DeQ47woc3oU3TQn6kijGlF5QDLUaqGr1WiEVT 1kCQ== X-Gm-Message-State: AOAM533YTecyhmnHE5KyGnzx6Bow8ccn2Jki88UhkeCatZ39SuoxLrpj ZX3lKXKJD/JSs4iHRd0SE/o= X-Google-Smtp-Source: ABdhPJyUH0DzOcTH+Ceg+t3jp2tA/C4MOKub6f2dgD/N7C07/xDQypsbnC7PzM7w81+e68dQ8cMX9g== X-Received: by 2002:ac2:528b:: with SMTP id q11mr4658624lfm.60.1607146450638; Fri, 04 Dec 2020 21:34:10 -0800 (PST) Received: from localhost.localdomain (109-252-192-53.dynamic.spd-mgts.ru. [109.252.192.53]) by smtp.gmail.com with ESMTPSA id d25sm2289861lja.40.2020.12.04.21.34.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 21:34:10 -0800 (PST) From: Dmitry Osipenko To: Nick Dyer , Dmitry Torokhov , Rob Herring , Thierry Reding , Jonathan Hunter , Linus Walleij , Jiada Wang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/3] dt-bindings: input: atmel_mxt_ts: Document atmel, wakeup-method and wake-GPIO Date: Sat, 5 Dec 2020 08:33:26 +0300 Message-Id: <20201205053328.9535-2-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201205053328.9535-1-digetx@gmail.com> References: <20201205053328.9535-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Some Atmel touchscreen controllers have a WAKE line that needs to be asserted low in order to wake up controller from a deep sleep. Document the wakeup methods and the wake-GPIO properties. Signed-off-by: Dmitry Osipenko --- .../bindings/input/atmel,maxtouch.yaml | 26 +++++++++++++++++++ include/dt-bindings/input/atmel-maxtouch.h | 10 +++++++ 2 files changed, 36 insertions(+) create mode 100644 include/dt-bindings/input/atmel-maxtouch.h diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.yaml b/Documentation/devicetree/bindings/input/atmel,maxtouch.yaml index 8c6418f76e94..7924a16dc248 100644 --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.yaml +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.yaml @@ -39,6 +39,13 @@ properties: (active low). The line must be flagged with GPIO_ACTIVE_LOW. + wake-gpios: + maxItems: 1 + description: + Optional GPIO specifier for the touchscreen's wake pin + (active low). The line must be flagged with + GPIO_ACTIVE_LOW. + linux,gpio-keymap: $ref: /schemas/types.yaml#/definitions/uint32-array description: | @@ -53,6 +60,23 @@ properties: or experiment to determine which bit corresponds to which input. Use KEY_RESERVED for unused padding values. + atmel,wakeup-method: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + The WAKE line is an active-low input that is used to wake up the touch + controller from deep-sleep mode before communication with the controller + could be started. This feature used to minimize current consumption + when the controller is in deep sleep mode. + + The WAKE pin can be connected in one of the following ways: + 1) left permanently low + 2) connected to the I2C-compatible SCL pin + 3) connected to a GPIO pin on the host + enum: + - 0 # ATMEL_MXT_WAKEUP_NONE + - 1 # ATMEL_MXT_WAKEUP_I2C_SCL + - 2 # ATMEL_MXT_WAKEUP_GPIO + required: - compatible - reg @@ -63,6 +87,7 @@ additionalProperties: false examples: - | #include + #include #include i2c { #address-cells = <1>; @@ -75,6 +100,7 @@ examples: reset-gpios = <&gpio 27 GPIO_ACTIVE_LOW>; vdda-supply = <&ab8500_ldo_aux2_reg>; vdd-supply = <&ab8500_ldo_aux5_reg>; + atmel,wakeup-method = ; }; }; diff --git a/include/dt-bindings/input/atmel-maxtouch.h b/include/dt-bindings/input/atmel-maxtouch.h new file mode 100644 index 000000000000..7345ab32224d --- /dev/null +++ b/include/dt-bindings/input/atmel-maxtouch.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _DT_BINDINGS_ATMEL_MAXTOUCH_H +#define _DT_BINDINGS_ATMEL_MAXTOUCH_H + +#define ATMEL_MXT_WAKEUP_NONE 0 +#define ATMEL_MXT_WAKEUP_I2C_SCL 1 +#define ATMEL_MXT_WAKEUP_GPIO 2 + +#endif /* _DT_BINDINGS_ATMEL_MAXTOUCH_H */ From patchwork Sat Dec 5 05:33:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 338479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13B36C1B0D8 for ; Sat, 5 Dec 2020 05:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D52C422D2B for ; Sat, 5 Dec 2020 05:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728338AbgLEFez (ORCPT ); Sat, 5 Dec 2020 00:34:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727861AbgLEFex (ORCPT ); Sat, 5 Dec 2020 00:34:53 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AD1FC061A51; Fri, 4 Dec 2020 21:34:13 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id v14so10648372lfo.3; Fri, 04 Dec 2020 21:34:13 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=M/hQDIaO0AuDyCgkalUNOZfXF0lc3dn+UFvqJldeahQ=; b=MGLoQxk7CqU75nfwbmYKsZCyxZaCXyNn1YzSGCyFa4MVXFK0hMJVgrDEUCIl2UJ5KI YboFZgXyc3WcESs0gg+/C2Es9dndTQK20tV2uUo7RG7lLuDtn0usfTvwCFSIQw/QjipY +6tA0TSJj5yiP4IAn60hD+TvEtiS8s6wi0WAl8PQkztifCCCB76rjH0NAIz+F4Whoihr uMWmf1J3eOeU2mr5NraKEF535amJjasrlA0wI7Ji7/uod8oH/dCgBSYOz98tZtzApzM6 y765nQrRteEswRiBzxrs8p7JB2nFfQfBMV/yizTlNNrAvkxZVslxmO+R+frjADRq1zzm x57A== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/hQDIaO0AuDyCgkalUNOZfXF0lc3dn+UFvqJldeahQ=; b=o6UJUpmIIAiqn8qQ0vo9BB9KLcaXk3brarKsoOojqQSBzCSSxJGHiHDhUbApioGqeo n62rsVtVzuLuphUhrQheNJgRmuOk+Zc4khM6Oe/tgmiGmg8pXadSF2bgGS+FZdSPOhZH jRvbi6SU+v3FCV1HQn2iAJkLXoD0s5Qz+3bunOYf+z7cmJ8pRg57zzt7F/OqbEEWu85b BBNENhp+TGmy3bvZ5S/U+dGL2EtMSt/zMMS8FNKq5S+A8DYvU7fcahLRUtoYzDGAdeBs ehW9h6VE80/Dlps8DEzFNK4NM0Ba/cMl6q0wLAMO74YdYOfxcsBRCUDF8sh6DQB9w3XH 9r1Q== X-Gm-Message-State: AOAM532PnKioF+pqdGsEub+fWm+iCAeFEieQZ+uCK9wjOfBNMq2CbyOp qxVZCEtGQBsw3G48857cGzmsS/jAspY= X-Google-Smtp-Source: ABdhPJwCqU4imzCbAiiqD4IfIB8LFr3UPsNWisKCcwI2iE6uHTox8T4BZoWd7lTkDE78v4BwZwbZvA== X-Received: by 2002:ac2:4c07:: with SMTP id t7mr4655482lfq.458.1607146451755; Fri, 04 Dec 2020 21:34:11 -0800 (PST) Received: from localhost.localdomain (109-252-192-53.dynamic.spd-mgts.ru. [109.252.192.53]) by smtp.gmail.com with ESMTPSA id d25sm2289861lja.40.2020.12.04.21.34.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 21:34:11 -0800 (PST) From: Dmitry Osipenko To: Nick Dyer , Dmitry Torokhov , Rob Herring , Thierry Reding , Jonathan Hunter , Linus Walleij , Jiada Wang Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/3] Input: atmel_mxt_ts - support wakeup methods Date: Sat, 5 Dec 2020 08:33:27 +0300 Message-Id: <20201205053328.9535-3-digetx@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201205053328.9535-1-digetx@gmail.com> References: <20201205053328.9535-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org According to datasheets, chips like mXT1386 have a WAKE line, it is used to wake the chip up from deep sleep mode before communicating with it via the I2C-compatible interface. If the WAKE line is connected to a GPIO line, the line must be asserted 25 ms before the host attempts to communicate with the controller. If the WAKE line is connected to the SCL pin, the controller will send a NACK on the first attempt to address it, the host must then retry 25 ms later. Implement the wake-up methods in the driver. Touchscreen now works properly on devices like Acer A500 tablet, fixing problems like this: atmel_mxt_ts 0-004c: __mxt_read_reg: i2c transfer failed (-121) atmel_mxt_ts 0-004c: mxt_bootloader_read: i2c recv failed (-121) atmel_mxt_ts 0-004c: Trying alternate bootloader address atmel_mxt_ts 0-004c: mxt_bootloader_read: i2c recv failed (-121) atmel_mxt_ts: probe of 0-004c failed with error -121 Signed-off-by: Jiada Wang Signed-off-by: Dmitry Osipenko --- drivers/input/touchscreen/atmel_mxt_ts.c | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 2b3fff0822fe..c90f470bcc32 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -31,6 +31,7 @@ #include #include #include +#include /* Firmware files */ #define MXT_FW_NAME "maxtouch.fw" @@ -199,6 +200,7 @@ enum t100_type { #define MXT_CRC_TIMEOUT 1000 /* msec */ #define MXT_FW_RESET_TIME 3000 /* msec */ #define MXT_FW_CHG_TIMEOUT 300 /* msec */ +#define MXT_WAKEUP_TIME 25 /* msec */ /* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -312,6 +314,7 @@ struct mxt_data { struct mxt_dbg dbg; struct regulator_bulk_data regulators[2]; struct gpio_desc *reset_gpio; + struct gpio_desc *wake_gpio; bool use_retrigen_workaround; /* Cached parameters from object table */ @@ -342,6 +345,8 @@ struct mxt_data { unsigned int t19_num_keys; enum mxt_suspend_mode suspend_mode; + + u32 wakeup_method; }; struct mxt_vb2_buffer { @@ -626,10 +631,25 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock) return 0; } +static bool mxt_wake_up(struct i2c_client *client) +{ + struct mxt_data *data = i2c_get_clientdata(client); + + if (data->wakeup_method != ATMEL_MXT_WAKEUP_I2C_SCL) + return false; + + dev_dbg(&client->dev, "waking up controller\n"); + + msleep(MXT_WAKEUP_TIME); + + return true; +} + static int __mxt_read_reg(struct i2c_client *client, u16 reg, u16 len, void *val) { struct i2c_msg xfer[2]; + bool retried = false; u8 buf[2]; int ret; @@ -648,9 +668,13 @@ static int __mxt_read_reg(struct i2c_client *client, xfer[1].len = len; xfer[1].buf = val; +retry: ret = i2c_transfer(client->adapter, xfer, 2); if (ret == 2) { ret = 0; + } else if (!retried && mxt_wake_up(client)) { + retried = true; + goto retry; } else { if (ret >= 0) ret = -EIO; @@ -664,6 +688,7 @@ static int __mxt_read_reg(struct i2c_client *client, static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, const void *val) { + bool retried = false; u8 *buf; size_t count; int ret; @@ -677,9 +702,13 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, buf[1] = (reg >> 8) & 0xff; memcpy(&buf[2], val, len); +retry: ret = i2c_master_send(client, buf, count); if (ret == count) { ret = 0; + } else if (!retried && mxt_wake_up(client)) { + retried = true; + goto retry; } else { if (ret >= 0) ret = -EIO; @@ -3160,6 +3189,15 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) return error; } + /* Request the WAKE line as asserted so controller won't sleep */ + data->wake_gpio = devm_gpiod_get_optional(&client->dev, + "wake", GPIOD_OUT_HIGH); + if (IS_ERR(data->reset_gpio)) { + error = PTR_ERR(data->reset_gpio); + dev_err(&client->dev, "Failed to get wake gpio: %d\n", error); + return error; + } + error = devm_request_threaded_irq(&client->dev, client->irq, NULL, mxt_interrupt, IRQF_ONESHOT, client->name, data); @@ -3190,6 +3228,23 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id) msleep(MXT_RESET_INVALID_CHG); } + /* + * Controllers like mXT1386 have a dedicated WAKE line that could be + * connected to a GPIO or to I2C SCL pin, or permanently asserted low. + * + * This WAKE line is used for waking controller from a deep-sleep and + * it needs to be asserted low for 25 milliseconds before I2C transfers + * could be accepted by controller if it was in a deep-sleep mode. + * + * If WAKE line is connected to I2C SCL pin, then the first I2C transfer + * will get an instant NAK and transfer needs to be retried after 25ms. + * + * If WAKE line is connected to a GPIO line, the line must be asserted + * 25ms before the host attempts to communicate with the controller. + */ + device_property_read_u32(&client->dev, "atmel,wakeup-method", + &data->wakeup_method); + error = mxt_initialize(data); if (error) goto err_disable_regulators;