From patchwork Fri Feb 9 10:50:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13551041 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 950C7C48297 for ; Fri, 9 Feb 2024 10:50:39 +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=a2UnJCGbcY+hsYS8AJDrGPyXChhKvfvKEZC1y4JdokY=; b=rOyvuZJxCkmD2l LWLFH6yCExRhkzEjqwB5n4K4OBtO2hOVuEIPK7NqOz6iZJ6a+lfkZkp4CMkzLpgc8c/wuijrnZJML eCIpJiIHiiyPN30Uh/ftY7FWFuoKQI6AZ+jboIAB3PclRCUHK1asa66Jbu9YJKYi0M9ojFZ73Ic5u Z3XvzBmwGDGO7BYd1Wc8jJuG8YH3IWaDcVNVFYJPH2Ux9GWFOHctOAbLeeTxT6aU0DcTWvh2NBhNP XHWmBHnRg+58vDh0Cjc2MOPhUqtLdpGFMIxW0WnlJIb/9UYU19DiGsHac3DHZ5swJGZqa0XZOFcwX ErMOkXmVRioZUvdw+nhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rYOSh-0000000GlKl-0ASP; Fri, 09 Feb 2024 10:50:27 +0000 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rYOSa-0000000GlGl-3ReG for linux-arm-kernel@lists.infradead.org; Fri, 09 Feb 2024 10:50:22 +0000 Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-4101d4c5772so4568985e9.0 for ; Fri, 09 Feb 2024 02:50:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707475818; x=1708080618; 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=mVc4M1YbGvNb8ipoFp9BUg+QNpL61/sf2CwDTAOM2wc=; b=nj9/gv4TYzyF/ziNqAMgTLLtb1wTBaEOy0j2hAudBq0k5xKawOswhKGGzLliGgm97m r+QPWiG4s28+KQCTzIpQE9tysn+E6BFvDfliqTZm7Om4fdo9deWlOejsCrR/N+QaKkrl V+pP7CR5ZJ93qMMECUUJKM9j62kZ2B/Vwjk0pv5hnOdIRbjMDgUDJ2OpA/ZX1Y6Udzpw T2YvIRBNnxM36OPpPA7yb1mHZobmR80GbMhVPI4RopFTVxlgJCART5+B1KHwoaRLs/DP mF005tgpqjzaWD8RTwE215McqngO9sjAIdat9R6XA4lVzhXGwBw8tJSYGsSH2Jf4XxLO EZtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707475818; x=1708080618; 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=mVc4M1YbGvNb8ipoFp9BUg+QNpL61/sf2CwDTAOM2wc=; b=ESs8DB4iB8ldn2UaiunhQ1OsxD6uaVoFkDnRu0G/mefVmRSpnX9s+xq+iuvba7cZq0 JWmPKLMl98L8TpSOUsd4z41KxiLy0D7Dt8YDn6TmJUFXK2avv3cwcZqNCJ8NMY3vWQyV 5DwsKYXlYIRv4GEV8OxW9tEDern+r59wvYGoQz5B38EEU9J/6t/86nXOgbfkjSwKvzDv ZGvTW25BQVclUzwO/jrvtk8B60QWkslt3bYAHMCd/QiBzcDoXfGvml7L8/Ll4DqwMhnc x/mff7N1RreUUv/XfRVscMRoCWJyv3em3i0CuNar9FLET8/kkgOxjOBhKVschZsbzpCK gyUw== X-Gm-Message-State: AOJu0YyN7n4dJ6EODWdoip3oF5od7tUZl9lRKGmAQToKWiXSiYlxRWZQ HAHtiZ/AAxepWgkluFlNm3er6QhHOGBKZ0nO3aVWqQhyyBnXuBqr X-Google-Smtp-Source: AGHT+IGnXDekBiujHQv+XLsrfkX6e5Wxmu2GVzrddWdHW02pTuApjf//3c2Wh7SIkpQ3tD9pirwNqQ== X-Received: by 2002:a05:600c:46cf:b0:410:4b4:dc7f with SMTP id q15-20020a05600c46cf00b0041004b4dc7fmr655530wmo.4.1707475818274; Fri, 09 Feb 2024 02:50:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCX4eE7ROrtmTolbB2S5sYVQJ9RixDkW0mR4Btlqzf15LrqUXDitF7gsevS5eTiwsbNuxPR71Y1KDWbB3QNk5IqGsbkC0HTatgMlq/J3EqoobkPpk6emEaggcm0BhrA1njJEBLBPEvvDi0Uo62kUPwy/c8LQIDME/BemJ/Ls4s0B8/LG0if0oQAYfbXTT+s4dxTQhvrcDPy3mtFz+7hDvHppzmvLJAjj4xZF+rSCTJ+vZGDwSUKwfpcWqoAstwU+pmtcwOMNjoFpr3vfnYPUExNYbKRTUg+ZfUnJyrEtZFtroX8c8hWxcq9wB4URcHIk+WoWWC6HxDKDFTc/LXy11APlURRec/O8h7DPe3/i6hm7nqIse9FjOgVjHir4B8ltDe8BcBJgmK/bwVqCjs7qKXE4TmbnJ+iKvGeSNZYjgkgkiadgj9qdwno7FjMA4BNf/FKSrrCXQfaX9GcvX2hFwjNcADTuwpKVkXOKV/Urug3uRR0cUEDxWoEwWpgwfoI6zGvfTMsjNXCMNMTvo3N9Xuff7gzulNWxLR6S1HVxUVAR/hLoBx/2 Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:765:2268:762e:2748]) by smtp.gmail.com with ESMTPSA id t18-20020a05600c199200b0040fc26183e8sm253627wmq.8.2024.02.09.02.50.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 02:50:17 -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, francesco.dolcini@toradex.com, Stefan Eichenberger Subject: [PATCH RESEND v3 2/2] Input: atmel_mxt_ts - support poweroff in suspend Date: Fri, 9 Feb 2024 11:50:12 +0100 Message-Id: <20240209105012.22470-3-eichest@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209105012.22470-1-eichest@gmail.com> References: <20240209105012.22470-1-eichest@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240209_025020_892607_5D4DE638 X-CRM114-Status: GOOD ( 21.35 ) 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 controller 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 542a31448c8f..2d5655385702 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_sleep; /* 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; } @@ -3325,6 +3329,8 @@ static int mxt_probe(struct i2c_client *client) msleep(MXT_RESET_INVALID_CHG); } + data->poweroff_sleep = device_property_read_bool(&client->dev, + "atmel,poweroff-sleep"); /* * Controllers like mXT1386 have a dedicated WAKE line that could be * connected to a GPIO or to I2C SCL pin, or permanently asserted low. @@ -3387,12 +3393,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_sleep) { + 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); @@ -3408,14 +3423,37 @@ static int mxt_resume(struct device *dev) if (!input_dev) return 0; - enable_irq(data->irq); + if (!device_may_wakeup(dev) && data->poweroff_sleep) { + 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; }