From patchwork Mon Jul 8 07:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 811312 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DEA84224F2; Mon, 8 Jul 2024 07:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720422971; cv=none; b=YmZnysBWt6Y01iiZzG8vBzjgxItDqaLi/ZAgU90/oY+1FWYs32Q/ATsKvFWw/sqTEdGa3Ef1TML2EbFUwPvkj6XsBNIkN2hY+V96sbX3pOqLhCYVyf+ZnWEf+wPuFJk2SF3HwbRcMCiPUOO8+KoJDD0fW/+APGnFcZSIxR+tGEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720422971; c=relaxed/simple; bh=h3+KBOlt8omvXSrpwxNhfGFcHcpApPKjKBcqxJdbRQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iAh0KOH/XSDVEYpLTHnB2en5mWeVOV9KSq/ckePRNgDJsaZy/lqO/p9eWktrEajfRi5p3jLvDX86v1oJqN+aGBNBDJ5OKlADqlzMWWWjogdUIBGGf5v/QOpvjgcoU8/R9ROiBUW5O69BGA2uJoTnBGYmezLx1xfeywn3WqBL8tg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=bvqzMpH1; arc=none smtp.client-ip=209.85.221.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bvqzMpH1" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-367ab50a07aso1704955f8f.0; Mon, 08 Jul 2024 00:16:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720422968; x=1721027768; darn=vger.kernel.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=NSr6W9+kIBrExV7rAUXxvmIpCII4LVhMfKMFiF1UZnE=; b=bvqzMpH1wsRa8xnoFcwCbSmxK0Ik0l6A5bEMuPvAHyfpLaJnLoBZPKFnBVb85qeVIl Mm/fb8K4IDmoRkhgyZ7UysVV4kuQAZ+XbzsjYiqN/w4ReDeRixLRHpFNcxFU2tWPn6Gi gxhWn4xKejUkZCEJ4JxBJkTke/om0lLscEo594NgFXCMhPcuwKWWK7TeUYvTjD1g4HDd VtO1fiYx33M94dJfJvRRSyu/4Y3dBbK/je+cawHYfBAVYraC9JvgAv72CI8SZqNTzeLt kG+ENV02Y5+1M9Z5TdDxSMP7lDrFPNZui4ya+kmPPmnQ23+7eR576SEbwp86BpVJP7sl ky/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720422968; x=1721027768; 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=NSr6W9+kIBrExV7rAUXxvmIpCII4LVhMfKMFiF1UZnE=; b=ZLgChrphDUCilaSqKdg5DGziJNZIszYTaRwwAbJQDNXxb8WUFDbPbw2PlWIoSkLzaL yACBK0m5Op9B/xKKP2uawAWBy31nwEBNlEE8U5m2naaehfZxRIoAD4ZFrM1rU6T5OEFf dw4XQInKo+VjYYm48eUlHuLMSdyEBzJOgSatK5c2cZEf3QjHIbM4pZ+nm3IVu03Ffw1U puQsKeQ2G2afOw2HWt1Ut/ZfdDHAMsFJ0VTy9Ec0GxXRIY4D47u6o5b+fpepK8eD1y2l 0nSCP7GH061eqPSLvxjy5uakjxjuk6wRw5OpOuf2T9nE0POvez7I9IayLl5iX3NVBBHT wYgA== X-Forwarded-Encrypted: i=1; AJvYcCXLnCo9UlV12Whg3xPc7MLH1/3tdhhHTsGBdSptd0mCP8RoICgYBva/kCer3voVSdOXjL7EIrDoUhxpmiEZQhvxk1WaG8jNeDcM/m6P12RGxYm72p0G7iWTuzNB6JyMOA4k3xPuCbkDIg== X-Gm-Message-State: AOJu0YwBQgSToMiCCGqTnARI82GYCYlBpVpkA1oglrc9Isy2RemXp+B8 oln7eRSOuzE11mQscUtO5KGo4fV/xaYy9rrTawsgHnWdAhxnoyX4 X-Google-Smtp-Source: AGHT+IHrzhQu0plLHQSnW6EQAbhlLdpaa6G8qkl7Pllj+JcKaF9nRXS7gqQjM6Ofo0NmYv4Ov37Elw== X-Received: by 2002:adf:ecd2:0:b0:35f:1dce:8671 with SMTP id ffacd0b85a97d-3679dd29926mr7019361f8f.25.1720422968305; Mon, 08 Jul 2024 00:16:08 -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.07 (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 2/4] Input: atmel_mxt_ts - move calls to register the input device to separate function Date: Mon, 8 Jul 2024 09:15:49 +0200 Message-ID: <20240708071601.7571-3-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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefan Eichenberger The calls to register the input device are moved to a separate function so that we can call it without having to confiugre the device. This is necessary if we want to power on the device only when it is opened. Signed-off-by: Stefan Eichenberger Reviewed-by: Joao Paulo Goncalves --- drivers/input/touchscreen/atmel_mxt_ts.c | 34 +++++++++++++++++------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 4fc83a4cabd9b..85f3c685bf526 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -2277,6 +2277,28 @@ static void mxt_config_cb(const struct firmware *cfg, void *ctx) release_firmware(cfg); } +static void mxt_debug_init(struct mxt_data *data); + +static int mxt_device_register(struct mxt_data *data) +{ + int error; + + /* 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(&data->client->dev, "No touch object detected\n"); + } + + mxt_debug_init(data); + } + + return 0; +} + static int mxt_initialize(struct mxt_data *data) { struct i2c_client *client = data->client; @@ -2831,15 +2853,9 @@ 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"); - } - - mxt_debug_init(data); + error = mxt_device_register(data); + if (error) + return error; return 0; } From patchwork Mon Jul 8 07:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Eichenberger X-Patchwork-Id: 811311 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CC6D2C694; Mon, 8 Jul 2024 07:16:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720422973; cv=none; b=CBmC4MOccS+IFq91ysWchrWnCWPvONQj322p3Ko2a09CwTQ/xtb0SKNsArmw354cb4ML/YI+GoSffJjKuYAURMvCK3GorZlZBPtuW7Yf+J18YpC5YQGeOj+wRtzXz4ZcV+FdwBw8fcdv6UcfnQl0qkjSWfE6JPkiXweAE2eHzoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720422973; c=relaxed/simple; bh=yOX+W+4UFfjm7aIIDqbdd1jZIgnWT/b322lNMxg98U8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pCyQ5b8LSKINduhw+bNXgYbKqrNpDLJF6hExWFgtiY3+9D3KlmCf8jR9bW8nxORr4yJ2v0RUKqcFiMGimxuJAO2md9JjaEIjrxOlYjkvwgtUVmpeaz+88iVFtUQRBatFL2SmbBSfP3GTvA5NAUi+kQNR/GQcYEZhr9pn/LK02n4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RsiDSzZE; arc=none smtp.client-ip=209.85.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RsiDSzZE" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4255fa23f7bso23839925e9.2; Mon, 08 Jul 2024 00:16:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720422971; x=1721027771; darn=vger.kernel.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=FvhvTdVpDZ79yvlH1+XJiOzGxkpYhrLPBWh5+/JeQbw=; b=RsiDSzZEIkmDOvGFKwHp+z2k2I64b7beUeqsfRU0aEVmIcYIIEgwPum0yOW1gtS9Dp 6BC9HKpxpGVSu4HaZ/ogsU8LekaBQMmoXtsU8EMfMbVzcwpBmq56j/e2F9UPUd9q65un un4V/g1jKNN/DQyuFXz+PfkAKekx9oqlfiuxTL2Yn8jDZ+qgvJuHcARGMZTVbRfB0AsC 1wyS3sa4mmvYux8+N5+osjA+dRN1KjJ6VS5RRRJwHomMVYLfa4ei1+/CPw0S63sY9BwK 7TjxitDflv45UdAoQZiUK6PEPagVWYoxaEMS9f1RUbG7q+pTBOXr4XM6j4mFBf9OlkTe p1DA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720422971; x=1721027771; 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=FvhvTdVpDZ79yvlH1+XJiOzGxkpYhrLPBWh5+/JeQbw=; b=aLtFKF0xTx7/PR3kG/sJQSEyHzG9SZQPQdSW0vfiGKrtXf8Kwmx8+CHM1jNpMYsvFJ c/BXYM1R0KgdEdJDJElb+SyvXSFf0dvqjivHmNVg2hFif38tzJ5eLGkmpd6GX72BwbII Iy3AEEYkhsURjI3UsbEw4r96nGoxJiuq51XiRc0DOvgujuHvSr8N9qs+OYOC414/pD3e VA8JCMUCmxOUJDC7kjcDIXVZdKP8QNMT94oTH+eQNYNsAeJtoKJ2jeRw4uywRjqbofhF zf1rxqdlSAHOzCm12fGp7sASBxt5GVfgjMWYdzY+UrvK/18/y5fNQZqf8JGpyXZ5mmpg JXmQ== X-Forwarded-Encrypted: i=1; AJvYcCUChUwJdBRDJ1yBZOvSQpKdst3AI8LU9AK2jsNjPaJ/8J51yXx3bj/sO2R0nEOiI/CnF3sczka9vWROgYdCyZZ5QcLa2SQC/Qd1JYLT7OZyvkEr+Iu8peN2ywHDgxXU1b7JtVS8noE1Sw== X-Gm-Message-State: AOJu0YzxRJNwi65Ul8kA6q2AvTO9Fxqn6H4j6fdBJwjAx3picXgNwqrC 3nlPTAP3FmKTt1LEpTg+TtQfLY+4mBiQdWBCWNwO/3SrdXNirEwT X-Google-Smtp-Source: AGHT+IENCKvfCZxO2Rt6KDsB7M0kjjFGMdi6MvfCYZJU7eP3x5K0nZi26KF8OMrrBBbNgihafqwRFw== X-Received: by 2002:a05:600c:4f0f:b0:425:5ec3:570b with SMTP id 5b1f17b1804b1-4264a428ec4mr69226885e9.35.1720422970695; Mon, 08 Jul 2024 00:16:10 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 00:16:10 -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 4/4] Input: atmel_mxt_ts - add support for poweroff-sleep Date: Mon, 8 Jul 2024 09:15:51 +0200 Message-ID: <20240708071601.7571-5-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> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Stefan Eichenberger Add support for poweroff-sleep to the Atmel maXTouch driver. This allows us to power off the input device entirely and only power it on when it is opened. This will also automatically power it off when we suspend the system. Signed-off-by: Stefan Eichenberger --- drivers/input/touchscreen/atmel_mxt_ts.c | 59 ++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c index 85f3c685bf526..3bcdbb58a24e6 100644 --- a/drivers/input/touchscreen/atmel_mxt_ts.c +++ b/drivers/input/touchscreen/atmel_mxt_ts.c @@ -265,6 +265,7 @@ enum v4l_dbg_inputs { enum mxt_suspend_mode { MXT_SUSPEND_DEEP_SLEEP = 0, MXT_SUSPEND_T9_CTRL = 1, + MXT_SUSPEND_POWEROFF = 2, }; /* Config update context */ @@ -2273,8 +2274,38 @@ static int mxt_configure_objects(struct mxt_data *data, static void mxt_config_cb(const struct firmware *cfg, void *ctx) { + struct mxt_data *data = ctx; + mxt_configure_objects(ctx, cfg); release_firmware(cfg); + + if ((data->suspend_mode == MXT_SUSPEND_POWEROFF) && !data->in_bootloader) { + disable_irq(data->irq); + mxt_power_off(data); + } +} + +static void mxt_initialize_after_resume(struct mxt_data *data) +{ + int error; + + error = mxt_power_on(data); + if (error) { + dev_err(&data->client->dev, "Failed to power on device\n"); + return; + } + + error = mxt_acquire_irq(data); + if (error) { + dev_err(&data->client->dev, "Failed to acquire IRQ\n"); + return; + } + + error = mxt_configure_objects(data, NULL); + if (error) { + dev_err(&data->client->dev, "Failed to configure objects\n"); + return; + } } static void mxt_debug_init(struct mxt_data *data); @@ -3089,6 +3120,12 @@ static ssize_t mxt_update_fw_store(struct device *dev, struct mxt_data *data = dev_get_drvdata(dev); int error; + if ((data->suspend_mode == MXT_SUSPEND_POWEROFF) && !data->in_bootloader) { + error = mxt_power_on(data); + if (error) + return error; + } + error = mxt_load_fw(dev, MXT_FW_NAME); if (error) { dev_err(dev, "The firmware update failed(%d)\n", error); @@ -3123,7 +3160,10 @@ static const struct attribute_group mxt_attr_group = { static void mxt_start(struct mxt_data *data) { - mxt_wakeup_toggle(data->client, true, false); + if (data->suspend_mode == MXT_SUSPEND_POWEROFF) + mxt_initialize_after_resume(data); + else + mxt_wakeup_toggle(data->client, true, false); switch (data->suspend_mode) { case MXT_SUSPEND_T9_CTRL: @@ -3135,6 +3175,7 @@ static void mxt_start(struct mxt_data *data) MXT_TOUCH_MULTI_T9, MXT_T9_CTRL, 0x83); break; + case MXT_SUSPEND_POWEROFF: case MXT_SUSPEND_DEEP_SLEEP: default: mxt_set_t7_power_cfg(data, MXT_POWER_CFG_RUN); @@ -3160,7 +3201,12 @@ static void mxt_stop(struct mxt_data *data) break; } - mxt_wakeup_toggle(data->client, false, false); + if (data->suspend_mode == MXT_SUSPEND_POWEROFF) { + disable_irq(data->irq); + mxt_power_off(data); + } else { + mxt_wakeup_toggle(data->client, false, false); + } } static int mxt_input_open(struct input_dev *dev) @@ -3357,6 +3403,9 @@ static int mxt_probe(struct i2c_client *client) if (error) return error; + if (device_property_read_bool(&client->dev, "atmel,poweroff-sleep")) + data->suspend_mode = MXT_SUSPEND_POWEROFF; + /* * Controllers like mXT1386 have a dedicated WAKE line that could be * connected to a GPIO or to I2C SCL pin, or permanently asserted low. @@ -3406,7 +3455,8 @@ 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); - mxt_power_off(data); + if (!(data->suspend_mode == MXT_SUSPEND_POWEROFF)) + mxt_power_off(data); } static int mxt_suspend(struct device *dev) @@ -3439,7 +3489,8 @@ static int mxt_resume(struct device *dev) if (!input_dev) return 0; - enable_irq(data->irq); + if (!(data->suspend_mode == MXT_SUSPEND_POWEROFF)) + enable_irq(data->irq); mutex_lock(&input_dev->mutex);