All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raul E Rangel <rrangel@chromium.org>
To: linux-acpi@vger.kernel.org, linux-input@vger.kernel.org
Cc: timvp@google.com, hdegoede@redhat.com,
	andriy.shevchenko@linux.intel.com, rafael@kernel.org,
	mario.limonciello@amd.com, jingle.wu@emc.com.tw,
	mika.westerberg@linux.intel.com, dmitry.torokhov@gmail.com,
	linus.walleij@linaro.org, Raul E Rangel <rrangel@chromium.org>,
	Alistair Francis <alistair@alistair23.me>,
	Angela Czubak <acz@semihalf.com>,
	Bartosz Szczepanek <bsz@semihalf.com>,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Kosina <jikos@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v4 01/13] HID: i2c-hid: Use PM subsystem to manage wake irq
Date: Mon, 19 Sep 2022 09:59:03 -0600	[thread overview]
Message-ID: <20220919095504.v4.1.Id4b4bdfe06e2caf2d5a3c9dd4a9b1080c38b539c@changeid> (raw)
In-Reply-To: <20220919155916.1044219-1-rrangel@chromium.org>

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@chromium.org>
---

(no changes since v3)

Changes in v3:
- Fixed typo in if condition

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..a2fa40dec04ea5 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 (!client->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.3.968.ga6b4b080e4-goog


  reply	other threads:[~2022-09-19 15:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-19 15:59 [PATCH v4 00/13] acpi: i2c: Use SharedAndWake and ExclusiveAndWake to enable wake irq Raul E Rangel
2022-09-19 15:59 ` Raul E Rangel [this message]
2022-09-19 15:59 ` [PATCH v4 02/13] Input: elan_i2c - Use PM subsystem to manage " Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 03/13] Input: elants_i2c " Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 04/13] Input: raydium_ts_i2c " Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 05/13] gpiolib: acpi: Add wake_capable variants of acpi_dev_gpio_irq_get Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 06/13] ACPI: resources: Add wake_capable parameter to acpi_dev_irq_flags Raul E Rangel
2022-09-20 12:35   ` Andy Shevchenko
2022-09-19 15:59 ` [PATCH v4 07/13] i2c: acpi: Use ACPI wake capability bit to set wake_irq Raul E Rangel
2022-09-20 12:32   ` Andy Shevchenko
2022-09-21 15:18     ` Raul Rangel
2022-09-22  9:44       ` Andy Shevchenko
2022-09-19 15:59 ` [PATCH v4 08/13] ACPI: PM: Take wake IRQ into consideration when entering suspend-to-idle Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 09/13] HID: i2c-hid: acpi: Stop setting wakeup_capable Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 10/13] HID: i2c-hid: Don't set wake_capable and wake_irq Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 11/13] Input: elan_i2c - " Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 12/13] Input: elants_i2c " Raul E Rangel
2022-09-19 15:59 ` [PATCH v4 13/13] Input: raydium_ts_i2c " Raul E Rangel
2022-09-20 10:42 ` [PATCH v4 00/13] acpi: i2c: Use SharedAndWake and ExclusiveAndWake to enable wake irq Benjamin Tissoires
2022-09-21 15:33   ` Raul Rangel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220919095504.v4.1.Id4b4bdfe06e2caf2d5a3c9dd4a9b1080c38b539c@changeid \
    --to=rrangel@chromium.org \
    --cc=acz@semihalf.com \
    --cc=alistair@alistair23.me \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=bsz@semihalf.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=jikos@kernel.org \
    --cc=jingle.wu@emc.com.tw \
    --cc=linus.walleij@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=timvp@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.