From patchwork Tue Jun 14 15:07:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 70041 Delivered-To: patch@linaro.org Received: by 10.140.106.246 with SMTP id e109csp2098973qgf; Tue, 14 Jun 2016 08:08:31 -0700 (PDT) X-Received: by 10.66.76.226 with SMTP id n2mr28106364paw.17.1465916888074; Tue, 14 Jun 2016 08:08:08 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b188si39085517pfa.90.2016.06.14.08.08.07; Tue, 14 Jun 2016 08:08:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750789AbcFNPIG (ORCPT + 14 others); Tue, 14 Jun 2016 11:08:06 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:34968 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750968AbcFNPIG (ORCPT ); Tue, 14 Jun 2016 11:08:06 -0400 Received: by mail-lf0-f50.google.com with SMTP id u74so106498275lff.2 for ; Tue, 14 Jun 2016 08:08:05 -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=EIzShbB4e6HRvR/OuQGNd51PyAK4yhKaMLjqHxlcDz0=; b=QULs90uddVhE9ztGYztpHlfIpi+wqghlT9w/ZALf01vjZz4CDObm2n73N8VNucqM+g voDOcgztxrQWi1W8KJEqeunSvX8m8FEdbHUYFycyZ/byMk/p8UOEkCBWYT1SI7CyEDIn yXxXLfRToJgK9AKx6duPxXBk8hPuxIbBNuRvs= 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:in-reply-to :references; bh=EIzShbB4e6HRvR/OuQGNd51PyAK4yhKaMLjqHxlcDz0=; b=LEhUHQngt4KJ/6iCI243j9xjv11Kzz4i2X6lNB0kJrR27e49b2//Wb5QW6UIXiJSvN /5K1+7jjWZQiJIUo7LcrHeeDT5CkSbsaCNAw5hAMwThKHVUDNBkEN9/OJEpwEXNBzmso vg2kEJnCymkyKO2aMpBwujLTb05mo1obreKqsCbYLPOTz9RH+ENDTk1vyq8TTEnKKOiF S7HsgoJt31Lf9bcSoqCRPZrJys6VGMCImVJQUvU1LDLy5Q30g084A2Gobh8V2clvPUav b/PGtRlj5EG4Jr8GYLuhNphsIx9MoSWs+CeAg32FQp6v2Ij9q5ZavinUXio8pwi7Pvy2 05pA== X-Gm-Message-State: ALyK8tJ++IWFXwKjTedheBFojh4o/J+JIMsfd0lDVzQOv5nCEAQJiqkBeL3Y615zfKqHSDhK X-Received: by 10.25.83.199 with SMTP id h190mr2014542lfb.83.1465916881824; Tue, 14 Jun 2016 08:08:01 -0700 (PDT) Received: from localhost.localdomain (h-155-4-128-67.na.cust.bahnhof.se. [155.4.128.67]) by smtp.gmail.com with ESMTPSA id f195sm3477060lfb.47.2016.06.14.08.07.59 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 14 Jun 2016 08:08:00 -0700 (PDT) From: Ulf Hansson To: Wolfram Sang , linux-i2c@vger.kernel.org Cc: Jarkko Nikula , Andy Shevchenko , Mika Westerberg , John Stultz , Guodong Xu , linux-arm-kernel@lists.infradead.org, Ulf Hansson , "Rafael J. Wysocki" , Kevin Hilman , linux-pm@vger.kernel.org Subject: [PATCH 10/10] i2c: designware-platdrv: Rework system PM support Date: Tue, 14 Jun 2016 17:07:28 +0200 Message-Id: <1465916848-8207-11-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1465916848-8207-1-git-send-email-ulf.hansson@linaro.org> References: <1465916848-8207-1-git-send-email-ulf.hansson@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The current code that deploys the system PM support relies on the "direct_complete" feature supported by the PM core. The goal is to avoid performing unnecessary operations during the system PM sequence. Unfortunate in this case there are some drawbacks with this solution as explained below. 1) In case of the ->prepare() callback find the device runtime resumed it returns 0. The PM core will then run the regular set of the system PM callbacks for the device, to allow it to be suspended. Under these circumstances the device also becomes unconditionally resumed during the system PM resume sequence. It would be better to postpone the resume operations to be managed by runtime PM and thus only when actually needed. 2) It's good practice to keep the device's runtime PM status in sync with the the current state of the HW. In the same scenario as described in 1), the runtime PM status are RPM_ACTIVE the period in-between when the ->suspend() and ->resume() callbacks are invoked. This is wrong because the device has actually been put into a low power state. To address the limitation in 2) and to simplify the system PM code, let's convert to deploy the so called runtime PM centric approach. This is done by assigning the system PM ->suspend|resume() callbacks to the pm_runtime_force_suspend|resume() helper functions. In this way, the ->prepare() and ->complete() callbacks can also be removed. Currently pm_runtime_force_resume() is also unconditionally resuming the device, which is due to legacy reasons when CONFIG_PM_RUNTIME and CONFIG_PM_SLEEP co-existed. Changing that behaviour is a reasonable improvement to make and it would also resolve the limitation in 1). Cc: Rafael J. Wysocki Cc: Kevin Hilman Cc: linux-pm@vger.kernel.org Signed-off-by: Ulf Hansson --- drivers/i2c/busses/i2c-designware-platdrv.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index b2c6037..4c31ff3 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -291,24 +291,8 @@ 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); -} - -static void dw_i2c_plat_complete(struct device *dev) -{ - if (dev->power.direct_complete) - pm_request_resume(dev); -} -#else -#define dw_i2c_plat_prepare NULL -#define dw_i2c_plat_complete NULL -#endif - #ifdef CONFIG_PM -static int dw_i2c_plat_suspend(struct device *dev) +static int dw_i2c_plat_runtime_suspend(struct device *dev) { struct dw_i2c_dev *i_dev = dev_get_drvdata(dev); @@ -320,7 +304,7 @@ static int dw_i2c_plat_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 dw_i2c_dev *i_dev = dev_get_drvdata(dev); int ret; @@ -336,10 +320,11 @@ static int dw_i2c_plat_resume(struct device *dev) } static const struct dev_pm_ops dw_i2c_dev_pm_ops = { - .prepare = dw_i2c_plat_prepare, - .complete = dw_i2c_plat_complete, - SET_SYSTEM_SLEEP_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume) - SET_RUNTIME_PM_OPS(dw_i2c_plat_suspend, dw_i2c_plat_resume, NULL) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(dw_i2c_plat_runtime_suspend, + dw_i2c_plat_runtime_resume, + NULL) }; #define DW_I2C_DEV_PMOPS (&dw_i2c_dev_pm_ops)