Input: elants_i2c - use PM subsystem to manage wake irq
authorRaul E Rangel <rrangel@chromium.org>
Tue, 22 Nov 2022 21:44:22 +0000 (13:44 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Tue, 22 Nov 2022 21:58:48 +0000 (13:58 -0800)
The Elan 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@chromium.org>
Link: https://lore.kernel.org/r/20220929093200.v6.3.I5862429ee3e4de0f9ad5ba01ce07ad99eec10cf0@changeid
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/touchscreen/elants_i2c.c

index e1308e179dd6fb878a3218898ad98757f75ee16d..25009835bd5139e36c74352e5c745bb62335d590 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/input/touchscreen.h>
 #include <linux/acpi.h>
 #include <linux/of.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/gpio/consumer.h>
 #include <linux/regulator/consumer.h>
 #include <linux/uuid.h>
@@ -180,7 +181,6 @@ struct elants_data {
        u8 cmd_resp[HEADER_SIZE];
        struct completion cmd_done;
 
-       bool wake_irq_enabled;
        bool keep_power_in_suspend;
 
        /* Must be last to be used for DMA operations */
@@ -1571,6 +1571,15 @@ static int elants_i2c_probe(struct i2c_client *client)
        if (!client->dev.of_node)
                device_init_wakeup(&client->dev, true);
 
+       /*
+        * 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, &elants_attribute_group);
        if (error) {
                dev_err(&client->dev, "failed to create sysfs attributes: %d\n",
@@ -1602,7 +1611,7 @@ static int __maybe_unused elants_i2c_suspend(struct device *dev)
                 * The device will automatically enter idle mode
                 * that has reduced power consumption.
                 */
-               ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
+               return 0;
        } else if (ts->keep_power_in_suspend) {
                for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
                        error = elants_i2c_send(client, set_sleep_cmd,
@@ -1631,8 +1640,6 @@ static int __maybe_unused elants_i2c_resume(struct device *dev)
        int error;
 
        if (device_may_wakeup(dev)) {
-               if (ts->wake_irq_enabled)
-                       disable_irq_wake(client->irq);
                elants_i2c_sw_reset(client);
        } else if (ts->keep_power_in_suspend) {
                for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {