From patchwork Thu Dec 7 11:13:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13483171 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06572C4167B for ; Thu, 7 Dec 2023 11:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1txnnzbwAGdqxVQfgHehQz3QOtAl9Fx1u4qxXJ9yQKo=; b=GunjDd3yf4P0Xc 9uzc662Gat+4arCSkdZ2Fiy+L+n3sKqA+zw+41Ts8ap8XZ7I/8E6s4ex2ezc97BI3cUH72c+UMsYG /aVvOF0KePjTd0aLd70n46Vuv2NnCpPc6CTEUiqr45CPy1m68vD9VA6jwFd5RDsv7gPVUTuO4ohEq HQcW3Rm8m45xZq6YPNW7VijOBO5JDq9GnArTnhQyNQjWryC27YHF0e1bNkmZ9zYow4+gXfP1wVDKk ib7JYFhOFp4dDBxGZXjUxSeO9m5Zwg1kvL80psak6cB99vJTkFwdWyIxQkBlICdHjUwWupoQXvvBC tzFWmkZaw4isGCjBelsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBCK3-00CXnF-0j; Thu, 07 Dec 2023 11:13:39 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBCJx-00CXka-07 for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2023 11:13:34 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-33349b3f99aso793159f8f.0 for ; Thu, 07 Dec 2023 03:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701947611; x=1702552411; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q04tsDqW57p+9vja5pX6TrNQSbK8g1Bln9Plrgyuq6U=; b=i6T93JG0xn8b/hpnvDnmOrWzuGTP+P/OZTuf4WR2fscIskoC9pV/booHvSWAscLHID JvZdY+YJVFzDbTM8gXobosKpP+SoGEjL8kDfZavKYoq1v+RnAbYjtJlnGfDmeOQ8TWMz uUa3IWWxlnjkgClVPdmubi8eoIT1Y7WKfmxqfPTV1nRpk4KfZXoYt4l5E0Fqze5XflaQ 239jb9kjEX6JNnXCFsoEsaHvtQuEyRT7b1Vi1Dv7gJT7o9MAoWA4grqFwfiBDbmh46D9 sCJitV4VQ5mtZqcIOKn4MjIVwBu/gd6pJrpUdmCzmyqnYoAclDdM0hLs62zZdFsGX8LB D8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701947611; x=1702552411; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q04tsDqW57p+9vja5pX6TrNQSbK8g1Bln9Plrgyuq6U=; b=iJvhsqgXnrrBa+FEfITRAWSBZaGepqXMk+N4QzQlk5sGnD1i52cQuToOjkgvkrAr2y Zt1BDX+Jgso9p9h673LqeYD64A98/apwWUgkunVLYY8XoppswT2mxsONoQ7SCx/1GjMD ea9J6uugSq1gNBLRYsRExHLg1sq+A/2XlabXPRwn7cA1SoD92x+ExqR2zqFYrmRe02h7 MUGyxe9glYqOp+qi8s2STJgdK466EdS/NtLPUemdEMFj6sQhlsiYglvUIND3QJlzUKg/ 5wFWNPC8A+ZR4xtd2IqiGuCF1GEDg1Azl4tVBvxyTnuoBkWIbrzeAk7eQyfmncHY49vb PEOw== X-Gm-Message-State: AOJu0YzX6t1M8JxEoCDykZSg6+Yo+4h8X6zBcnEi7p2SxQE3GHQ8n3W6 1CxVJuqUr5vMPFKddzPdwxw= X-Google-Smtp-Source: AGHT+IGIblJChk3/pL0IMI6XnShQv+MynmhlcXWEswXA1HuxUjijixn0Wu0k1c5gVDlynwzhuQkODQ== X-Received: by 2002:a05:6000:1946:b0:332:d504:c131 with SMTP id e6-20020a056000194600b00332d504c131mr1266173wry.44.1701947611659; Thu, 07 Dec 2023 03:13:31 -0800 (PST) Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:5036:93fe:290b:56de]) by smtp.gmail.com with ESMTPSA id b10-20020a5d550a000000b003333541a5bdsm1166096wrv.80.2023.12.07.03.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 03:13:29 -0800 (PST) From: Stefan Eichenberger To: nick@shmanahar.org, dmitry.torokhov@gmail.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, linus.walleij@linaro.org Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Stefan Eichenberger Subject: [PATCH v1 2/2] Input: atmel_mxt_ts - support poweroff in suspend Date: Thu, 7 Dec 2023 12:13:00 +0100 Message-Id: <20231207111300.80581-3-eichest@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231207111300.80581-1-eichest@gmail.com> References: <20231207111300.80581-1-eichest@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_031333_074697_ED056359 X-CRM114-Status: GOOD ( 21.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Stefan Eichenberger Add a new device tree property to indicate that the device should be powered off in suspend mode. We have a shared regulator that powers the display, a USB hub and some other peripherals. The maxtouch doesn't normally disable the regulator in suspend mode, so our extra peripherals stay powered on. This is not desirable as it consumes more power. With this patch we add the option to disable the regulator in suspend mode for the maxtouch and accept the longer initialisation time. Signed-off-by: Stefan Eichenberger --- drivers/input/touchscreen/atmel_mxt_ts.c | 72 ++++++++++++++++++------ 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 20094b9899f0..7caa0d317d30 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -317,6 +317,7 @@ struct mxt_data { struct gpio_desc *reset_gpio; struct gpio_desc *wake_gpio; bool use_retrigen_workaround; + bool poweroff_in_suspend; /* Cached parameters from object table */ u16 T5_address; @@ -2799,15 +2800,18 @@ static int mxt_configure_objects(struct mxt_data *data, dev_warn(dev, "Error %d updating config\n", error); } - if (data->multitouch) { - error = mxt_initialize_input_device(data); - if (error) - return error; - } else { - dev_warn(dev, "No touch object detected\n"); - } + /* If input device is not already registered */ + if (!data->input_dev) { + if (data->multitouch) { + error = mxt_initialize_input_device(data); + if (error) + return error; + } else { + dev_warn(dev, "No touch object detected\n"); + } - mxt_debug_init(data); + mxt_debug_init(data); + } return 0; } @@ -3328,6 +3332,8 @@ static int mxt_probe(struct i2c_client *client) msleep(MXT_RESET_INVALID_CHG); } + data->poweroff_in_suspend = device_property_read_bool(&client->dev, + "atmel,poweroff-in-suspend"); /* * Controllers like mXT1386 have a dedicated WAKE line that could be * connected to a GPIO or to I2C SCL pin, or permanently asserted low. @@ -3390,12 +3396,21 @@ static int mxt_suspend(struct device *dev) if (!input_dev) return 0; - mutex_lock(&input_dev->mutex); + if (!device_may_wakeup(dev) && data->poweroff_in_suspend) { + if (data->reset_gpio) + gpiod_set_value(data->reset_gpio, 1); - if (input_device_enabled(input_dev)) - mxt_stop(data); + regulator_bulk_disable(ARRAY_SIZE(data->regulators), + data->regulators); + data->T44_address = 0; + } else { + mutex_lock(&input_dev->mutex); + + if (input_device_enabled(input_dev)) + mxt_stop(data); - mutex_unlock(&input_dev->mutex); + mutex_unlock(&input_dev->mutex); + } disable_irq(data->irq); @@ -3411,14 +3426,37 @@ static int mxt_resume(struct device *dev) if (!input_dev) return 0; - enable_irq(data->irq); + if (!device_may_wakeup(dev) && data->poweroff_in_suspend) { + int ret; - mutex_lock(&input_dev->mutex); + ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators), + data->regulators); + if (ret) { + dev_err(dev, "failed to enable regulators: %d\n", + ret); + return ret; + } + msleep(MXT_BACKUP_TIME); - if (input_device_enabled(input_dev)) - mxt_start(data); + if (data->reset_gpio) { + /* Wait a while and then de-assert the RESET GPIO line */ + msleep(MXT_RESET_GPIO_TIME); + gpiod_set_value(data->reset_gpio, 0); + msleep(MXT_RESET_INVALID_CHG); + } - mutex_unlock(&input_dev->mutex); + /* This also enables the irq again */ + mxt_initialize(data); + } else { + enable_irq(data->irq); + + mutex_lock(&input_dev->mutex); + + if (input_device_enabled(input_dev)) + mxt_start(data); + + mutex_unlock(&input_dev->mutex); + } return 0; }