From patchwork Wed Feb 19 12:27:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 3680651 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DCD999F35F for ; Wed, 19 Feb 2014 12:29:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08AD920163 for ; Wed, 19 Feb 2014 12:29:19 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 04D7720035 for ; Wed, 19 Feb 2014 12:29:18 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WG6Ga-0003MT-ED; Wed, 19 Feb 2014 12:28:44 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WG6GQ-0006Wk-Ck; Wed, 19 Feb 2014 12:28:34 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WG6GI-0006Ul-TO for linux-arm-kernel@lists.infradead.org; Wed, 19 Feb 2014 12:28:29 +0000 Received: by mail-lb0-f181.google.com with SMTP id z11so239753lbi.12 for ; Wed, 19 Feb 2014 04:28:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VYZ3PotqJsvZAfRIaub2HwzPmxKnLwyn+pMY99gq5UQ=; b=CKdkn1SAyTYDqkEDN5VkOGC9rj4muEmpOQfVpzD8lRXQ5RmkXay0CcuzCN7Wn9Jsei U+J4Nuq7GVX+/3ywkAeA4wMhmgPs/bLHCfI72O1LA/18BiEHGyIrK5WJUqYkembVnAoW pkkoDlbKTvnu8eyeJnOVc3ySR5A4r1xT0N4kVt8qvSlqUtDd3y6PZR50U+GlBovPKEZY I+2bvtACKGH58VpDj/fBCyJ3lK52sTBDe55qSPtDSJh+kzGZAU3i3lodCOh0L+GZMgxS vJJi5o99Wz44irddCPTW2P1QVa8PHbitm7nN0EhiLZgzZUa0R+RpTI13L+0G83/zh7lf EQtA== X-Gm-Message-State: ALoCoQnKZAKDn5ZHSofQGwy2iOBIhAdww7VMhhIzYmTrGSTzAo8lyCJVsIkaMbrmG5N3ESgX1LNm X-Received: by 10.152.180.42 with SMTP id dl10mr1112519lac.62.1392812884441; Wed, 19 Feb 2014 04:28:04 -0800 (PST) Received: from linaro-ulf.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id jf8sm33933lbc.8.2014.02.19.04.28.02 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 04:28:03 -0800 (PST) From: Ulf Hansson To: Alessandro Rubini , Linus Walleij , Wolfram Sang , linux-i2c@vger.kernel.org Subject: [PATCH V4 17/17] i2c: nomadik: Fixup system suspend Date: Wed, 19 Feb 2014 13:27:59 +0100 Message-Id: <1392812879-19251-1-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140219_072827_170559_F7FFCF85 X-CRM114-Status: GOOD ( 15.59 ) X-Spam-Score: -2.6 (--) Cc: Ulf Hansson , Mark Brown , Russell King , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For !CONFIG_PM_RUNTIME, the device were never put back into active state while resuming. For CONFIG_PM_RUNTIME, we blindly trusted the device to be inactive while we were about to handle it at suspend late, which is just too optimistic. Even if the driver uses pm_runtime_put_sync() after each tranfer to return it's runtime PM resources, there are no guarantees this will actually mean the device will inactivated. The reason is that the PM core will prevent runtime suspend during system suspend, and thus when a transfer occurs during the early phases of system suspend the device will be kept active after the transfer. To handle both issues above, we need to re-use the runtime PM callbacks and check the runtime PM state of the device before proceeding with our operations for system suspend. Cc: Alessandro Rubini Cc: Linus Walleij Cc: Wolfram Sang Signed-off-by: Ulf Hansson --- Changes in v4: Rebased on top of v4 of patch 16. --- drivers/i2c/busses/i2c-nomadik.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index 8082f5c..267375f 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -879,18 +879,36 @@ static irqreturn_t i2c_irq_handler(int irq, void *arg) #ifdef CONFIG_PM_SLEEP static int nmk_i2c_suspend_late(struct device *dev) { - pinctrl_pm_select_sleep_state(dev); + if (!pm_runtime_status_suspended(dev)) { + int ret = 0; + if (dev->pm_domain && dev->pm_domain->ops.runtime_suspend) + ret = dev->pm_domain->ops.runtime_suspend(dev); + else + ret = dev->bus->pm->runtime_suspend(dev); + if (ret) + return ret; + + pm_runtime_set_suspended(dev); + } + pinctrl_pm_select_sleep_state(dev); return 0; } static int nmk_i2c_resume_early(struct device *dev) { - /* First go to the default state */ - pinctrl_pm_select_default_state(dev); - /* Then let's idle the pins until the next transfer happens */ - pinctrl_pm_select_idle_state(dev); + int ret = 0; + + if (dev->pm_domain && dev->pm_domain->ops.runtime_resume) + ret = dev->pm_domain->ops.runtime_resume(dev); + else + ret = dev->bus->pm->runtime_resume(dev); + if (ret) { + dev_err(dev, "problem resuming\n"); + return ret; + } + pm_runtime_set_active(dev); return 0; } #endif