All of lore.kernel.org
 help / color / mirror / Atom feed
From: Doug Anderson <dianders@chromium.org>
To: Jiri Kosina <jkosina@suse.cz>,
	Andrew Duggan <aduggan@synaptics.com>,
	Vincent Huang <vincent.huang@tw.synaptics.com>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Doug Anderson <dianders@chromium.org>,
	jmaneyrol@invensense.com, borneo.antonio@gmail.com,
	seth.forshee@canonical.com, archana.patni@linux.intel.com,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended
Date: Mon,  9 Mar 2015 12:44:47 -0700	[thread overview]
Message-ID: <1425930287-4615-1-git-send-email-dianders@chromium.org> (raw)

If the i2c-hid device was runtime suspended and then the system
suspended itself we'd end up disabling interrupts twice (in
i2c_hid_runtime_suspend and i2c_hid_suspend) and not reenabling them
until later when the i2c-hid device was runtime resumed.
Unfortunately the i2c_hid_resume() calls i2c_hid_hwreset() and that
only works properly if interrupts are enabled.

We can fix this by taking the advice from "runtime_pm.txt".
Specifically we'll change i2c-hid to always resume to full power.
This only works if our parents are also resumed to full power, but
given the suggestion in "runtime_pm.txt" this seems a reasonable
assumption.

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
Note that this was tested on a 3.14 kernel with backports.  Any
testing that folks can do on ToT is appreciated.

Changes in v2:
- Move pm_runtime_enable() higher in resume

 drivers/hid/i2c-hid/i2c-hid.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index ab4dd95..9e013f6 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -1090,15 +1090,18 @@ static int i2c_hid_suspend(struct device *dev)
 	struct hid_device *hid = ihid->hid;
 	int ret = 0;
 
-	disable_irq(ihid->irq);
-	if (device_may_wakeup(&client->dev))
-		enable_irq_wake(ihid->irq);
+	if (!pm_runtime_suspended(dev)) {
+		/* Save some power */
+		i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
+
+		disable_irq(ihid->irq);
+	}
 
 	if (hid->driver && hid->driver->suspend)
 		ret = hid->driver->suspend(hid, PMSG_SUSPEND);
 
-	/* Save some power */
-	i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
+	if (device_may_wakeup(&client->dev))
+		enable_irq_wake(ihid->irq);
 
 	return ret;
 }
@@ -1110,6 +1113,11 @@ static int i2c_hid_resume(struct device *dev)
 	struct i2c_hid *ihid = i2c_get_clientdata(client);
 	struct hid_device *hid = ihid->hid;
 
+	/* We'll resume to full power */
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+
 	enable_irq(ihid->irq);
 	ret = i2c_hid_hwreset(client);
 	if (ret)
-- 
2.2.0.rc0.207.ga3a616c


             reply	other threads:[~2015-03-09 19:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-09 19:44 Doug Anderson [this message]
2015-03-10 12:23 ` [PATCH v2] HID: i2c-hid: Fix suspend/resume when already runtime suspended Mika Westerberg
2015-03-10 16:12   ` Doug Anderson
2015-03-11 11:20     ` Mika Westerberg
2015-03-11 15:06       ` Doug Anderson
2015-03-12  9:10         ` Mika Westerberg
2015-03-12 11:19           ` Mika Westerberg
2015-03-12 15:24           ` Doug Anderson
2015-03-12 15:28             ` Mika Westerberg

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=1425930287-4615-1-git-send-email-dianders@chromium.org \
    --to=dianders@chromium.org \
    --cc=aduggan@synaptics.com \
    --cc=archana.patni@linux.intel.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=borneo.antonio@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jkosina@suse.cz \
    --cc=jmaneyrol@invensense.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=seth.forshee@canonical.com \
    --cc=vincent.huang@tw.synaptics.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.