[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220912160931.v2.1.Id4b4bdfe06e2caf2d5a3c9dd4a9b1080c38b539c@changeid>
Date: Mon, 12 Sep 2022 16:13:05 -0600
From: Raul E Rangel <rrangel@...omium.org>
To: linux-acpi@...r.kernel.org, linux-input@...r.kernel.org
Cc: andriy.shevchenko@...ux.intel.com, jingle.wu@....com.tw,
mario.limonciello@....com, timvp@...gle.com,
linus.walleij@...aro.org, hdegoede@...hat.com, rafael@...nel.org,
Raul E Rangel <rrangel@...omium.org>,
Alistair Francis <alistair@...stair23.me>,
Angela Czubak <acz@...ihalf.com>,
Bartosz Szczepanek <bsz@...ihalf.com>,
Benjamin Tissoires <benjamin.tissoires@...hat.com>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
Jiri Kosina <jikos@...nel.org>,
Matthias Kaehlcke <mka@...omium.org>,
linux-kernel@...r.kernel.org
Subject: [PATCH v2 01/13] HID: i2c-hid: Use PM subsystem to manage wake irq
The I2C hid 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.
I tested this on an ACPI system that has a HID touchscreen and verified
the IRQ was armed for wake on suspend.
Signed-off-by: Raul E Rangel <rrangel@...omium.org>
---
Changes in v2:
- Set the wake_irq when not configured by the i2c-core. This is
different than v1, where the wake_irq was only set for non DT systems.
drivers/hid/i2c-hid/i2c-hid-core.c | 33 +++++++++++-------------------
1 file changed, 12 insertions(+), 21 deletions(-)
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index baa169fadd6632..57214549460043 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -26,6 +26,7 @@
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/pm.h>
+#include <linux/pm_wakeirq.h>
#include <linux/device.h>
#include <linux/wait.h>
#include <linux/err.h>
@@ -116,7 +117,6 @@ struct i2c_hid {
wait_queue_head_t wait; /* For waiting the interrupt */
- bool irq_wake_enabled;
struct mutex reset_lock;
struct i2chid_ops *ops;
@@ -1036,6 +1036,15 @@ int i2c_hid_core_probe(struct i2c_client *client, struct i2chid_ops *ops,
if (ret < 0)
goto err_powered;
+ /*
+ * 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 (!dev->power.wakeirq)
+ dev_pm_set_wake_irq(&client->dev, client->irq);
+
hid = hid_allocate_device();
if (IS_ERR(hid)) {
ret = PTR_ERR(hid);
@@ -1119,7 +1128,6 @@ static int i2c_hid_core_suspend(struct device *dev)
struct i2c_hid *ihid = i2c_get_clientdata(client);
struct hid_device *hid = ihid->hid;
int ret;
- int wake_status;
ret = hid_driver_suspend(hid, PMSG_SUSPEND);
if (ret < 0)
@@ -1130,16 +1138,8 @@ static int i2c_hid_core_suspend(struct device *dev)
disable_irq(client->irq);
- if (device_may_wakeup(&client->dev)) {
- wake_status = enable_irq_wake(client->irq);
- if (!wake_status)
- ihid->irq_wake_enabled = true;
- else
- hid_warn(hid, "Failed to enable irq wake: %d\n",
- wake_status);
- } else {
+ if (!device_may_wakeup(&client->dev))
i2c_hid_core_power_down(ihid);
- }
return 0;
}
@@ -1150,18 +1150,9 @@ static int i2c_hid_core_resume(struct device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct i2c_hid *ihid = i2c_get_clientdata(client);
struct hid_device *hid = ihid->hid;
- int wake_status;
- if (!device_may_wakeup(&client->dev)) {
+ if (!device_may_wakeup(&client->dev))
i2c_hid_core_power_up(ihid);
- } else if (ihid->irq_wake_enabled) {
- wake_status = disable_irq_wake(client->irq);
- if (!wake_status)
- ihid->irq_wake_enabled = false;
- else
- hid_warn(hid, "Failed to disable irq wake: %d\n",
- wake_status);
- }
enable_irq(client->irq);
--
2.37.2.789.g6183377224-goog
Powered by blists - more mailing lists