From patchwork Wed Aug 23 14:42:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 9917509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AF9CC60327 for ; Wed, 23 Aug 2017 14:42:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A18A8285C2 for ; Wed, 23 Aug 2017 14:42:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95F5F289A7; Wed, 23 Aug 2017 14:42:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CFFA289A5 for ; Wed, 23 Aug 2017 14:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932135AbdHWOmd (ORCPT ); Wed, 23 Aug 2017 10:42:33 -0400 Received: from mail-lf0-f48.google.com ([209.85.215.48]:37882 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754156AbdHWOmb (ORCPT ); Wed, 23 Aug 2017 10:42:31 -0400 Received: by mail-lf0-f48.google.com with SMTP id f7so1390107lfg.4 for ; Wed, 23 Aug 2017 07:42:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lDIBk2NR58Z+N9ZpbXrSJrmZ7UOKAB/wzTiHNYC4zVk=; b=Ai6rmE0GDUJZyyYfHdMRzCny0jgZX8/RltAQdC+ktGqJ4msDwneXh/j8w/laUg1YWf Y3Uo4ywzczswim9hVcioLIn/Z47UZpEmPtutnHElpXyINa7kVUIMD5eD102Udya28BO8 0nEvu6vc6pjKPSN4DDhHNNzU5NLcruOUc9H34= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lDIBk2NR58Z+N9ZpbXrSJrmZ7UOKAB/wzTiHNYC4zVk=; b=qsBBCmE7jplzrJXqmtHi4CsqE+pTSB+G3ufJTmtOWPp6xTnVkkV/UdPU7unO3GXl96 /cbx5n814aW7Jl0t2OepiR7BEykT23tw+a0Om+XAloNdlVZDMMwIZBawZZ2ZtaRCFiRT /nJFC2Z/k/pfhEy/9OHbCJ1bKn2T8Jj8qg0VpHLZ/3eJeaMmbESXPzdTIvyiGOVpvN/u D8Behzi8vB2uCkG60leYZ+vAjex/9SQtzI4y2vv+kZyQ9zfOMP9uB4z46itYx3L58KTJ 1zDYBGGEkxwmSpI/oaMMtomsktLP0Wl+Y0HW9NalQ+XwBGvjNMuAgvCI998zwteThJ4w 4I0A== X-Gm-Message-State: AHYfb5iIIKWoytLUTEUuo2oZwPBiCGz0QsYsK/AybVqabCXQXYVmHDXx XJqGk3IH3XEU5zJK X-Received: by 10.25.17.218 with SMTP id 87mr1134207lfr.129.1503499349823; Wed, 23 Aug 2017 07:42:29 -0700 (PDT) Received: from localhost.localdomain (h-158-174-22-67.NA.cust.bahnhof.se. [158.174.22.67]) by smtp.gmail.com with ESMTPSA id c89sm287593lfb.78.2017.08.23.07.42.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Aug 2017 07:42:29 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , "Rafael J . Wysocki" , Len Brown , linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org Cc: Kevin Hilman , Jarkko Nikula , Andy Shevchenko , Mika Westerberg , Jisheng Zhang , John Stultz , Guodong Xu , Sumit Semwal , Haojian Zhuang , linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org, Ulf Hansson Subject: [PATCH v2 9/9] i2c: designware: Deploy the runtime PM centric approach for system sleep Date: Wed, 23 Aug 2017 16:42:09 +0200 Message-Id: <1503499329-28834-10-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> References: <1503499329-28834-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently the device is runtime resumed in the i2c-dw-plat driver's ->suspend() callback, which is needed to manage system sleep properly. The particular reason for the runtime resume is because the PM core may unset the direct_complete flag for a parent device, in case its child device are being system suspended before. This leads to that the i2c-dw-plat driver's ->suspend() callback can be invoked when the device is runtime suspended. Runtime resuming the device in this scenario may be unnecessary, in case when the device is already in its proper lower power state for system sleep. This behaviour increases the time it takes to put the device into low power state, but means also a waste of power. Let's fix the behaviour by deploying the runtime PM centric path for system sleep, via assigning the pm_runtime_force_suspend|resume() helpers as the system sleep callbacks for the i2c-dw-plat driver. To deploy this, we must also make sure that the direct_complete path isn't used for the device. Therefore we drop the ->prepare() callback from the i2c-dw-plat driver and we inform the ACPI PM domain to not try out the direct_complete path for the device, as that is the default behaviour for the ACPI PM domain. Along with the runtime PM centric path, we also get some additional improvements of the behaviour during system sleep. More precisely: *) In case the device is/gets runtime resumed before the device_suspend() phase is entered, the PM core doesn't run the direct_complete path for the device during system sleep. During system resume, this lead to that the device will always be brought back to full power when the i2c-dw-plat driver's ->resume() callback is invoked. This may not be necessary, thus increasing the resume time for the device and wasting power. In the runtime PM centric path, the pm_runtime_force_resume() helper takes better care, as it resumes the device only in case it's really needed. Normally this means it can be postponed to be dealt with via regular calls to runtime PM (pm_runtime_get*()) instead. In other words, the device remains in its low power state until someone request a new i2c transfer, whenever that may be. **) In case the device is runtime suspended when the ->prepare() callback is invoked, the direct_complete path is tried by the PM core. If it succeeds, this leads to disabling runtime PM for the device in the device_suspend() phase. That is a problem in cases when others may need the device to be operational, as to be able send i2c transfers during the entire device_suspend() phase. By using the runtime PM centric path, we postpones runtime PM to be disabled for the device by the PM core to the regular device_suspend_late() phase. Signed-off-by: Ulf Hansson --- Changes in v2: - Rebased. - Clarify changelog. --- drivers/i2c/busses/i2c-designware-platdrv.c | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index fc6b99f..e0cbf5e 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -372,6 +372,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) if (ret) goto exit_probe; + acpi_dev_disable_direct_complete(&pdev->dev); return ret; exit_probe: @@ -387,6 +388,7 @@ static int dw_i2c_plat_remove(struct platform_device *pdev) { struct dw_i2c_dev *dev = platform_get_drvdata(pdev); + acpi_dev_enable_direct_complete(&pdev->dev); pm_runtime_get_sync(&pdev->dev); i2c_del_adapter(&dev->adapter); @@ -413,15 +415,6 @@ static const struct of_device_id dw_i2c_of_match[] = { MODULE_DEVICE_TABLE(of, dw_i2c_of_match); #endif -#ifdef CONFIG_PM_SLEEP -static int dw_i2c_plat_prepare(struct device *dev) -{ - return pm_runtime_suspended(dev); -} -#else -#define dw_i2c_plat_prepare NULL -#endif - #ifdef CONFIG_PM static int dw_i2c_plat_runtime_suspend(struct device *dev) { @@ -434,7 +427,7 @@ static int dw_i2c_plat_runtime_suspend(struct device *dev) return 0; } -static int dw_i2c_plat_resume(struct device *dev) +static int dw_i2c_plat_runtime_resume(struct device *dev) { struct platform_device *pdev = to_platform_device(dev); struct dw_i2c_dev *i_dev = platform_get_drvdata(pdev); @@ -445,19 +438,11 @@ static int dw_i2c_plat_resume(struct device *dev) return 0; } -#ifdef CONFIG_PM_SLEEP -static int dw_i2c_plat_suspend(struct device *dev) -{ - pm_runtime_resume(dev); - return dw_i2c_plat_runtime_suspend(dev); -} -#endif - static const struct dev_pm_ops dw_i2c_dev_pm_ops = { - .prepare = dw_i2c_plat_prepare, - SET_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) + SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) SET_RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, - dw_i2c_plat_resume, + dw_i2c_plat_runtime_resume, NULL) };