From patchwork Mon Jul 8 07:15:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 13726242 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 C7402C3DA42 for ; Mon, 8 Jul 2024 07:16: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=mfZNK8ph0Z0kRXxMHVT8gSKe9yd3fBGYFdN7lqgFzvQ=; b=3lbihnwb39iRj7BmYPLGYl+L/8 K4QC+2SpXg2CbXlqc8vvlG7akxAVr2gxq+vi/CP1ZQcYyziCEhUU2+Byp3JLSEArbEIBkJFWYgkTw lAVgxJE5zt47Txk7hZ1EnxqWR6eU3a/5t01z7wLpOuYOyBQNyqRku9zgVgodSEOvLYq5lYzvcefoi GYskXEbd6WOC/Q/ZeSfDUhxjvvEocYeWRP5f7kmdpmnMoQMB8+k1KjMXNNmG0tT41aokpq9vsyHlH pReKUK0CCB0hGpUPBMfM6kR2CYmQoEq605lbHcRNzI2i1e7dVxTlTN51xWFr/Crua0eP4fmd2izEF KqAqhEHw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQibw-000000030HI-0dk6; Mon, 08 Jul 2024 07:16:32 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sQibY-000000030Ad-46iD for linux-arm-kernel@lists.infradead.org; Mon, 08 Jul 2024 07:16:10 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-367ac08f80fso1368121f8f.1 for ; Mon, 08 Jul 2024 00:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720422967; x=1721027767; 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=mfZNK8ph0Z0kRXxMHVT8gSKe9yd3fBGYFdN7lqgFzvQ=; b=Kmv8tyqGi4P2MPFqDOvxZ1VxF1poNCauZ4iXtYdWOOH5Vo1gVB7ApiTrPcpmZSGqHa aEIh43GKzmirHJaoz2zqdI6rYbibk+mO2yLrqsuk+j+bZrNXKvVZUzqt/55s/0ASlf8e xSecbVmb136LvDYnfZ04V4Gnmx27PKALcZoTrBOzdOvPMCPg1IaAdgKGMWhZpFDLTFFk 8r3DLL8NgRFVUV4AcgYNdDrb/MzaXxMywsAJ3bOXUBQp/phXsU+G8+vQ5mrojSNz8xO1 Z8HBr1oJhgPGVJrMzIoKVEdMQOgwNgruKdTDoYbanVxKAF2zJKPnZmaW6O26hW3Spovn bupQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720422967; x=1721027767; 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=mfZNK8ph0Z0kRXxMHVT8gSKe9yd3fBGYFdN7lqgFzvQ=; b=ssqFIjYew1hEJ3/q1qtPQJBLhgMX9BDKTEdhI9TAhakYeFtjXFBRDJ7mtQYJuWlV9c UxRzUmL471nLcKY/hDNmlikHfxqbjHM6AW1nppL5QThtBUbupHsyza1AYk2h8+tTfC5G RP8kP771iXkDekuOQj3pOQfslSHcoEUp2P9j8XL9D7h8PxmD2Xq09cnDwagfqSMsI+oY RI0tb8bT4M1Q0Pi/P1bis/TusVE0uyPClk9ePMwxXCujEWuCVccUVJnI923UvxS4ucRl qBOQpu99bmosJVOS91LBr6qtcUTVvPy+R447eQa2EahGdk4BbWHM08cSZbGSB/sOnqlQ S43Q== X-Forwarded-Encrypted: i=1; AJvYcCWJjixO6NYJKuPU10DXuWOcXWIxsh5awJHhoeqoGi2MVltibop70W0WycOsLQKddoPOpGmxy9LUx7B7z0ZVS+596tRzPqVhKXzvCLT2nI7IGQ9YHsk= X-Gm-Message-State: AOJu0YzMjX+tdmYXKC1XJ39j85e8JysUJqYqWqkHwXLX/rfdFQk1p+xS YkiwPlq3WijszQIduyCTj8fZotG+6ehlJ9aN/ZVuN/uJp9IY3KcF X-Google-Smtp-Source: AGHT+IEfXpYJIxjWfYoWwblocqz4NtB/iP3ACED3Sw9nHHRXtj08ueId6szvEj11L3N2y52np3X2sw== X-Received: by 2002:adf:a1da:0:b0:367:4dd7:288b with SMTP id ffacd0b85a97d-3679dd34fe1mr8019816f8f.29.1720422967317; Mon, 08 Jul 2024 00:16:07 -0700 (PDT) Received: from eichest-laptop.toradex.int ([2a02:168:af72:0:a786:d603:1c55:ced1]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3679dd5ea09sm9994564f8f.65.2024.07.08.00.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 00:16:07 -0700 (PDT) From: Stefan Eichenberger To: nick@shmanahar.org, dmitry.torokhov@gmail.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com, claudiu.beznea@tuxon.dev, linus.walleij@linaro.org, francesco.dolcini@toradex.com, joao.goncalves@toradex.com 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 v5 1/4] Input: atmel_mxt_ts - add power off and power on functions Date: Mon, 8 Jul 2024 09:15:48 +0200 Message-ID: <20240708071601.7571-2-eichest@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240708071601.7571-1-eichest@gmail.com> References: <20240708071601.7571-1-eichest@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240708_001609_046525_B0FC276F X-CRM114-Status: GOOD ( 17.22 ) 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 separate function for power off and power on instead of calling regulator_bulk_enable and regulator_bulk_disable directly. Signed-off-by: Stefan Eichenberger Reviewed-by: Joao Paulo Goncalves --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 +++++++++++++++--------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 8a606bd441ae6..4fc83a4cabd9b 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -1307,6 +1307,38 @@ static int mxt_soft_reset(struct mxt_data *data) return 0; } +static int mxt_power_on(struct mxt_data *data) +{ + int error; + + error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), + data->regulators); + if (error) { + dev_err(&data->client->dev, "failed to enable regulators: %d\n", + error); + return error; + } + + msleep(MXT_BACKUP_TIME); + + 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); + } + + return 0; +} + +static void mxt_power_off(struct mxt_data *data) +{ + if (data->reset_gpio) + gpiod_set_value(data->reset_gpio, 1); + + regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators); +} + static void mxt_update_crc(struct mxt_data *data, u8 cmd, u8 value) { /* @@ -3305,25 +3337,9 @@ static int mxt_probe(struct i2c_client *client) return error; } - error = regulator_bulk_enable(ARRAY_SIZE(data->regulators), - data->regulators); - if (error) { - dev_err(&client->dev, "failed to enable regulators: %d\n", - error); + error = mxt_power_on(data); + if (error) return error; - } - /* - * The device takes 40ms to come up after power-on according - * to the mXT224 datasheet, page 13. - */ - msleep(MXT_BACKUP_TIME); - - 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); - } /* * Controllers like mXT1386 have a dedicated WAKE line that could be @@ -3361,8 +3377,8 @@ static int mxt_probe(struct i2c_client *client) mxt_free_input_device(data); mxt_free_object_table(data); err_disable_regulators: - regulator_bulk_disable(ARRAY_SIZE(data->regulators), - data->regulators); + mxt_power_off(data); + return error; } @@ -3374,8 +3390,7 @@ static void mxt_remove(struct i2c_client *client) sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); mxt_free_input_device(data); mxt_free_object_table(data); - regulator_bulk_disable(ARRAY_SIZE(data->regulators), - data->regulators); + mxt_power_off(data); } static int mxt_suspend(struct device *dev)