[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20240708071601.7571-5-eichest@gmail.com>
Date: Mon, 8 Jul 2024 09:15:51 +0200
From: Stefan Eichenberger <eichest@...il.com>
To: nick@...anahar.org,
dmitry.torokhov@...il.com,
robh@...nel.org,
krzk+dt@...nel.org,
conor+dt@...nel.org,
nicolas.ferre@...rochip.com,
alexandre.belloni@...tlin.com,
claudiu.beznea@...on.dev,
linus.walleij@...aro.org,
francesco.dolcini@...adex.com,
joao.goncalves@...adex.com
Cc: linux-input@...r.kernel.org,
devicetree@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-kernel@...r.kernel.org,
Stefan Eichenberger <stefan.eichenberger@...adex.com>
Subject: [PATCH v5 4/4] Input: atmel_mxt_ts - add support for poweroff-sleep
From: Stefan Eichenberger <stefan.eichenberger@...adex.com>
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 <stefan.eichenberger@...adex.com>
---
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);
--
2.43.0
Powered by blists - more mailing lists