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: 635363 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 3rTY1T3Ptkz9t12 for ; Wed, 15 Jun 2016 01:08:13 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=QULs90ud; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751346AbcFNPIM (ORCPT ); Tue, 14 Jun 2016 11:08:12 -0400 Received: from mail-lf0-f52.google.com ([209.85.215.52]:34968 "EHLO mail-lf0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750968AbcFNPIL (ORCPT ); Tue, 14 Jun 2016 11:08:11 -0400 Received: by mail-lf0-f52.google.com with SMTP id u74so106498278lff.2 for ; Tue, 14 Jun 2016 08:08:10 -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=GkJCSqGa9atRnewaYGmVFO/Wa9TeOX3CbRE/4QpqhZsuEZd3ANkT9rLCOk13j984kD iduGyUBTswv/hu+K2Df7mdI+furvQtzONgO+vMUuUJd/8iaFKE9Ij1fFqaDMuYcoB4lt oQcx+mGsemY37cPfJJFCd+xN8aUiRMeVwyL8pKWTasiMHg7suwxpV+Qzh3/JBraxdhx1 IuorEvu3OPOPXVSyOxG3WwW15QVBok3pvIxneO81ZSCZIK8ssvSzhJk7QYAXzCWTN9bH 7ZOKoF3cSzPu5IvWmSB0qvKRBtEalr52VXmEiONZtk0gPU3PQ2hKtbgDgtNwv+DTOuUL 5p7A== X-Gm-Message-State: ALyK8tLyFFZbPwJDVA6snhdJB+tyuqiD+1zdZE3h9zDV9s/G0ax85lLLj3uGiXq58K1KMnRx 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-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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(-) 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)