The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: "Linux-sh list" <linux-sh@vger.kernel.org>
Cc: Linux PM list <linux-pm@vger.kernel.org>,
	Paul Mundt <lethal@linux-sh.org>,
	Simon Horman <horms@verge.net.au>,
	Magnus Damm <magnus.damm@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Cao Minh Hiep <hiepcm@gmail.com>
Subject: [PATCH 2/6] PM / Domains: Fix hibernation restore of devices
Date: Tue, 13 Mar 2012 01:24:59 +0100	[thread overview]
Message-ID: <201203130124.59376.rjw@sisk.pl> (raw)
In-Reply-To: <201203130123.16268.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

During resume from hibernation pm_genpd_restore_noirq() has to
deal with software state left by pm_genpd_suspend_noirq() and
unknown hardware state (the boot kernel may leave all PM domains and
devices in arbitrary states).  For this reason, make it attempt to
power cycle each domain when before resuming its first device to
possibly get rid of any unwanted hardware state that may interfere
with genpd_start_dev() later on.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/base/power/domain.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

Index: linux/drivers/base/power/domain.c
===================================================================
--- linux.orig/drivers/base/power/domain.c
+++ linux/drivers/base/power/domain.c
@@ -770,8 +770,10 @@ static int pm_genpd_prepare(struct devic
 
 	genpd_acquire_lock(genpd);
 
-	if (genpd->prepared_count++ == 0)
+	if (genpd->prepared_count++ == 0) {
+		genpd->suspended_count = 0;
 		genpd->suspend_power_off = genpd->status == GPD_STATE_POWER_OFF;
+	}
 
 	genpd_release_lock(genpd);
 
@@ -1103,20 +1105,24 @@ static int pm_genpd_restore_noirq(struct
 	 * Since all of the "noirq" callbacks are executed sequentially, it is
 	 * guaranteed that this function will never run twice in parallel for
 	 * the same PM domain, so it is not necessary to use locking here.
+	 *
+	 * At this point suspended_count == 0 means this routing is being run
+	 * for the first time for the given domain in the present cycle.
 	 */
-	genpd->status = GPD_STATE_POWER_OFF;
-	if (genpd->suspend_power_off) {
+	if (genpd->suspended_count++ == 0) {
 		/*
-		 * The boot kernel might put the domain into the power on state,
-		 * so make sure it really is powered off.
+		 * The boot kernel might put the domain into arbitrary state,
+		 * so make sure it is powered off.
 		 */
+		genpd->status = GPD_STATE_POWER_OFF;
 		if (genpd->power_off)
 			genpd->power_off(genpd);
-		return 0;
 	}
 
+	if (genpd->suspend_power_off)
+		return 0;
+
 	pm_genpd_poweron(genpd);
-	genpd->suspended_count--;
 
 	return genpd_start_dev(genpd, dev);
 }
@@ -1623,7 +1629,6 @@ void pm_genpd_init(struct generic_pm_dom
 	genpd->poweroff_task = NULL;
 	genpd->resume_count = 0;
 	genpd->device_count = 0;
-	genpd->suspended_count = 0;
 	genpd->max_off_time_ns = -1;
 	genpd->domain.ops.runtime_suspend = pm_genpd_runtime_suspend;
 	genpd->domain.ops.runtime_resume = pm_genpd_runtime_resume;


  parent reply	other threads:[~2012-03-13  0:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  0:23 [PATCH 0/6] PM / Domains: System suspend fixes and "always on" flag Rafael J. Wysocki
2012-03-13  0:24 ` [PATCH 1/6] PM / Domains: Fix handling of wakeup devices during system resume Rafael J. Wysocki
2012-03-13  0:24 ` Rafael J. Wysocki [this message]
2012-03-13 21:32   ` [Replacement][PATCH 2/6] PM / Domains: Fix hibernation restore of devices, v2 Rafael J. Wysocki
2012-03-15  9:39     ` Simon Horman
2012-03-15 21:00       ` Rafael J. Wysocki
2012-03-16  0:03         ` Simon Horman
2012-03-13  0:25 ` [PATCH 3/6] PM / Domains: Introduce "always on" device flag Rafael J. Wysocki
2012-03-13 21:34   ` [Update][PATCH " Rafael J. Wysocki
2012-03-13  0:26 ` [PATCH 4/6] PM / shmobile: Make TMU driver use pm_genpd_dev_always_on() Rafael J. Wysocki
2012-03-13  0:27 ` [PATCH 5/6] PM / shmobile: Make CMT " Rafael J. Wysocki
2012-03-13  0:28 ` [PATCH 6/6] PM / shmobile: Make MTU2 " Rafael J. Wysocki
2012-03-13  1:27 ` [PATCH 0/6] PM / Domains: System suspend fixes and "always on" flag Simon Horman
2012-03-13  1:44 ` Paul Mundt

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=201203130124.59376.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=hiepcm@gmail.com \
    --cc=horms@verge.net.au \
    --cc=lethal@linux-sh.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=magnus.damm@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox