From patchwork Tue Nov 1 10:14:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 4884 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id BF43523E08 for ; Tue, 1 Nov 2011 10:15:18 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id A5464A18404 for ; Tue, 1 Nov 2011 10:15:18 +0000 (UTC) Received: by faan26 with SMTP id n26so9726303faa.11 for ; Tue, 01 Nov 2011 03:15:18 -0700 (PDT) Received: by 10.223.76.27 with SMTP id a27mr35460006fak.12.1320142518416; Tue, 01 Nov 2011 03:15:18 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.14.103 with SMTP id o7cs3349lac; Tue, 1 Nov 2011 03:15:17 -0700 (PDT) Received: by 10.213.105.66 with SMTP id s2mr20329ebo.41.1320142516039; Tue, 01 Nov 2011 03:15:16 -0700 (PDT) Received: from eu1sys200aog105.obsmtp.com (eu1sys200aog105.obsmtp.com. [207.126.144.119]) by mx.google.com with SMTP id p49si5771746eef.93.2011.11.01.03.15.10 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 Nov 2011 03:15:16 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.119 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) client-ip=207.126.144.119; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.119 is neither permitted nor denied by best guess record for domain of ulf.hansson@stericsson.com) smtp.mail=ulf.hansson@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob105.postini.com ([207.126.147.11]) with SMTP; Tue, 01 Nov 2011 10:15:15 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id CFB3579; Tue, 1 Nov 2011 10:15:03 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 69BA34E; Tue, 1 Nov 2011 10:15:03 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 101C2A8094; Tue, 1 Nov 2011 11:14:59 +0100 (CET) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 1 Nov 2011 11:15:02 +0100 From: Ulf Hansson To: Russell King , Cc: , "Rafael J. Wysocki" , Magnus Damm , Ulf Hansson Subject: [PATCH V3] AMBA: Put devices into low-power state in suspend_noirq Date: Tue, 1 Nov 2011 11:14:57 +0100 Message-ID: <1320142497-16750-1-git-send-email-ulf.hansson@stericsson.com> X-Mailer: git-send-email 1.7.5.4 MIME-Version: 1.0 Previously it was possible for device drivers doing pm_runtime_suspend and pm_runtime_put_sync from their suspend callbacks. From the following commit, which solved a race issue, this is not possible anymore. PM: Limit race conditions between runtime PM and system sleep (v2) Therefore some devices might not be in full low-power state after device's suspend callbacks has been executed. To make sure this is done the suspend_noirq callback is used. In the resume_noirq the power is restored to the device if it were previously cut in suspend_noirq. This to make sure the device is put back into the same state as the device driver left it in from it's suspend callback. If a device is configured as wakeup device this will prevent the bus from putting it into low-power state during suspend_noirq. Signed-off-by: Ulf Hansson --- Changes in v3: - Fixup comments and commit message (including the header). Changes in v2: - Integrated code directly into suspend|resume_noirq and get rid of not needed ifdefs. - Prevent runtime suspend if device is configured as wakeup. --- drivers/amba/bus.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c index bd230e8..e3ecf66 100644 --- a/drivers/amba/bus.c +++ b/drivers/amba/bus.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,7 @@ static int amba_pm_suspend(struct device *dev) static int amba_pm_suspend_noirq(struct device *dev) { struct device_driver *drv = dev->driver; + bool is_suspended = pm_runtime_status_suspended(dev); int ret = 0; if (!drv) @@ -168,6 +170,15 @@ static int amba_pm_suspend_noirq(struct device *dev) ret = drv->pm->suspend_noirq(dev); } + /* + * If the device's power hasn't already been cut and the + * device doesn't need to generate wakeup requests, cut + * the power now. + */ + if (!ret && !is_suspended && !device_may_wakeup(dev)) + if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_suspend) + ret = dev->bus->pm->runtime_suspend(dev); + return ret; } @@ -192,6 +203,7 @@ static int amba_pm_resume(struct device *dev) static int amba_pm_resume_noirq(struct device *dev) { struct device_driver *drv = dev->driver; + bool is_suspended = pm_runtime_status_suspended(dev); int ret = 0; if (!drv) @@ -202,6 +214,14 @@ static int amba_pm_resume_noirq(struct device *dev) ret = drv->pm->resume_noirq(dev); } + /* + * If the device's power were cut during suspend_noirq + * restore the power to the device now. + */ + if (!ret && !is_suspended && !device_may_wakeup(dev)) + if (dev->bus && dev->bus->pm && dev->bus->pm->runtime_resume) + ret = dev->bus->pm->runtime_resume(dev); + return ret; }