From patchwork Mon Feb 17 15:21:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 3663501 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F14C0BF13A for ; Mon, 17 Feb 2014 15:28:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29AB9201E7 for ; Mon, 17 Feb 2014 15:28:01 +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 3353A201DE for ; Mon, 17 Feb 2014 15:28:00 +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 1WFQ6t-0003pX-SM; Mon, 17 Feb 2014 15:27:56 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFQ6r-0001SQ-H4; Mon, 17 Feb 2014 15:27:53 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFQ6o-0001Rq-11 for linux-arm-kernel@lists.infradead.org; Mon, 17 Feb 2014 15:27:50 +0000 Received: by mail-la0-f41.google.com with SMTP id mc6so11578962lab.0 for ; Mon, 17 Feb 2014 07:27:27 -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=jnCLffIYWLIbeAASGcgdTPIftoncbZdQJEpCXGo662Y=; b=duUh1dxnenww3+qCOJf8PHe0yLFz+X7BHie+XF7JbfrqpzrZzb0Jz/SWnWt5KscmjH /8bfm+vUbYJJ6GsQbUpweG/jrdppLG7TmW4duW5MmJXarM0oQd3XWdWZRgRkxDVWb09j MWNew+fZkHr3w3ozRo0HAldbIE3AA1lWz942XDbMFYt4/OL7gPh9UeXLR1ZDNsd4mRqw +FAMVB6XZjEsshGyeak4aa89XPo8SW1ZasClLu9HNvOI9dZJ4Uq1d2Q2D3vidVl01kh1 efP3djbTAH+1gY/4595+WxNBNbQCmeSRt7lI5Oj3HHs2icYEblYgAu+Pc4M5z1vCWXqf yYsw== X-Gm-Message-State: ALoCoQl+IzDiZjAcW2FQhAARCMTTQS1NLfCs4WusCVN5E9KwOFo1EavlXo5DuqtSbJqMbpHOtOL4 X-Received: by 10.152.234.3 with SMTP id ua3mr1635148lac.63.1392650478345; Mon, 17 Feb 2014 07:21:18 -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 ya9sm19307613lbb.2.2014.02.17.07.21.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Feb 2014 07:21:17 -0800 (PST) From: Ulf Hansson To: Alessandro Rubini , Linus Walleij , Wolfram Sang , linux-i2c@vger.kernel.org Subject: [PATCH V3 17/17] i2c: nomadik: Fixup system suspend Date: Mon, 17 Feb 2014 16:21:14 +0100 Message-Id: <1392650474-14995-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-20140217_102750_214072_E856ABA6 X-CRM114-Status: GOOD ( 15.84 ) 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 --- drivers/i2c/busses/i2c-nomadik.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c index ceb3d05..650f5f9 100644 --- a/drivers/i2c/busses/i2c-nomadik.c +++ b/drivers/i2c/busses/i2c-nomadik.c @@ -879,21 +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) { - struct amba_device *adev = to_amba_device(dev); - struct nmk_i2c_dev *nmk_i2c = amba_get_drvdata(adev); + 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