[PATCH v2 04/13] Input: raydium_ts_i2c - Use PM subsystem to manage wake irq

From: Raul E Rangel
Date: Mon Sep 12 2022 - 18:14:47 EST


The raydium I2C touchscreen driver is currently manually managing the
wake IRQ. This change removes the explicit enable_irq_wake /
disable_irq_wake and instead relies on the PM subsystem. This is done by
calling dev_pm_set_wake_irq.

i2c_device_probe already calls dev_pm_set_wake_irq when using device
tree, and i2c_device_remove also already calls dev_pm_clear_wake_irq.
There could be some device tree systems that have incorrectly declared
`wake` capabilities, so this change will set the wake irq if one is
missing. This matches the previous behavior.

Signed-off-by: Raul E Rangel <rrangel@xxxxxxxxxxxx>
---

Changes in v2:
- Added raydium_ts_i2c to series

drivers/input/touchscreen/raydium_i2c_ts.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/input/touchscreen/raydium_i2c_ts.c b/drivers/input/touchscreen/raydium_i2c_ts.c
index 3a4952935366f9..66c5b577b791d4 100644
--- a/drivers/input/touchscreen/raydium_i2c_ts.c
+++ b/drivers/input/touchscreen/raydium_i2c_ts.c
@@ -21,6 +21,7 @@
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/pm_wakeirq.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <asm/unaligned.h>
@@ -134,8 +135,6 @@ struct raydium_data {
u8 pkg_size;

enum raydium_boot_mode boot_mode;
-
- bool wake_irq_enabled;
};

/*
@@ -1186,6 +1185,15 @@ static int raydium_i2c_probe(struct i2c_client *client,
return error;
}

+ /*
+ * The wake IRQ should be declared via device tree instead of assuming
+ * the IRQ can wake the system. This is here for legacy reasons and
+ * will be removed once the i2c-core supports querying ACPI for wake
+ * capabilities.
+ */
+ if (!client->dev.power.wakeirq)
+ dev_pm_set_wake_irq(&client->dev, client->irq);
+
error = devm_device_add_group(&client->dev,
&raydium_i2c_attribute_group);
if (error) {
@@ -1222,8 +1230,6 @@ static int __maybe_unused raydium_i2c_suspend(struct device *dev)

if (device_may_wakeup(dev)) {
raydium_enter_sleep(client);
-
- ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
} else {
raydium_i2c_power_off(ts);
}
@@ -1237,8 +1243,6 @@ static int __maybe_unused raydium_i2c_resume(struct device *dev)
struct raydium_data *ts = i2c_get_clientdata(client);

if (device_may_wakeup(dev)) {
- if (ts->wake_irq_enabled)
- disable_irq_wake(client->irq);
raydium_i2c_sw_reset(client);
} else {
raydium_i2c_power_on(ts);
--
2.37.2.789.g6183377224-goog