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: 321040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B26672C00CC for ; Tue, 18 Feb 2014 02:21:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752702AbaBQPVU (ORCPT ); Mon, 17 Feb 2014 10:21:20 -0500 Received: from mail-lb0-f175.google.com ([209.85.217.175]:40872 "EHLO mail-lb0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752629AbaBQPVU (ORCPT ); Mon, 17 Feb 2014 10:21:20 -0500 Received: by mail-lb0-f175.google.com with SMTP id p9so11224845lbv.20 for ; Mon, 17 Feb 2014 07:21:18 -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=SUlfh2vrwJo1+qIolbKJ9InQruTUQ5EpjeFyrJwPE6gs5TfKUv43qZNfe1PlGaDaEp Q/7WswuyQmqWehtFJNNPLDrPMQjJFbaU6g5mA+5vYigMtCn0dhNEOvEvBhEpGFSeJC7g u8KPlNLJaQHgmOdaK6z6AxVzBXi1oYHDA9Gy0kvBHqeNfyHM90kUmFqgQbOBsI0b6Ff1 TkIzQJI9NDnaQkJIZjXkfNMLh+Bx+NfEuOCmbJxSPoKBdtvlJOxjjs4ST2UN7gn6F9PP wSP/G4P6REflmoPRB2GGw2MMHcBKsbnVfZgDR4+8JNdumRTX3JbFmj7mMNryWaw9RHWQ yQxA== X-Gm-Message-State: ALoCoQnnlXyix1o5e3qfNtJlCSZhiBpeNqlR3HwTsZSKv1gy7DfbCBMXpxO1KAB5JXw+QNUI9rhx 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 Cc: Russell King , linux-arm-kernel@lists.infradead.org, Mark Brown , Ulf Hansson 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 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org 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