From patchwork Wed Nov 27 15:34:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 21813 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DCEDE23FE8 for ; Wed, 27 Nov 2013 15:35:24 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id e14sf23736093iej.0 for ; Wed, 27 Nov 2013 07:35:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=QRxv15BBwdPQZeiz7OUtX8gogSfXEwG41WmCmJiGrJE=; b=HbwhKI5gjl5sYup0EBLjWh29jg8+Jm8I3zyTQFQSVYdNq+w3ZCUyU3T4vuuONYxQ/q kS3kgb+nw62JDNAdvjEDRn8fKaXR38lUS1sh6xjyYApd6hjb1yujIqsIWLMVrVEzrdnp hCa3drwNp9BysMaQ5bfbBZFuSVdq7GDnpGDtFr7vYub2rTzTS5C0t+5rEGLOtcXo2D7P bIaeID4JJqLRo+OFJCLMfkt6IUgh/fPmlY0KGf3PNRsobt6hmJNxeeFFkfgmkFgZC0rh hGdlWHyVBqR9MdF1azJH/PxrFTp00Jv1RET7B15tVo9Ehujj063v5dytWXmBg0ZQb6/S Kvwg== X-Gm-Message-State: ALoCoQlVlHj1gnTwNh1gOaCoGrwVmgfxmlazzIjOGrsEJyy7gYFDiMksSXGZPICAZ1d1XqcOFggY X-Received: by 10.50.109.193 with SMTP id hu1mr10087196igb.6.1385566524328; Wed, 27 Nov 2013 07:35:24 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.49.10 with SMTP id q10ls1355571qen.0.gmail; Wed, 27 Nov 2013 07:35:24 -0800 (PST) X-Received: by 10.58.255.233 with SMTP id at9mr14817219ved.20.1385566524226; Wed, 27 Nov 2013 07:35:24 -0800 (PST) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by mx.google.com with ESMTPS id c1si21255710vcs.103.2013.11.27.07.35.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Nov 2013 07:35:24 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.43; Received: by mail-vb0-f43.google.com with SMTP id q12so4914327vbe.2 for ; Wed, 27 Nov 2013 07:35:24 -0800 (PST) X-Received: by 10.52.52.137 with SMTP id t9mr16486122vdo.22.1385566524098; Wed, 27 Nov 2013 07:35:24 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp294096vcz; Wed, 27 Nov 2013 07:35:23 -0800 (PST) X-Received: by 10.112.141.166 with SMTP id rp6mr1932310lbb.39.1385566522812; Wed, 27 Nov 2013 07:35:22 -0800 (PST) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx.google.com with ESMTPS id h4si12580720lam.131.2013.11.27.07.35.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Nov 2013 07:35:22 -0800 (PST) Received-SPF: neutral (google.com: 209.85.215.47 is neither permitted nor denied by best guess record for domain of ulf.hansson@linaro.org) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id ep20so5318468lab.34 for ; Wed, 27 Nov 2013 07:35:22 -0800 (PST) X-Received: by 10.112.143.3 with SMTP id sa3mr28519283lbb.12.1385566522240; Wed, 27 Nov 2013 07:35:22 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id c15sm8352568lbq.11.2013.11.27.07.35.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 27 Nov 2013 07:35:21 -0800 (PST) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Cc: Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ulf Hansson , Kevin Hilman , Alan Stern Subject: [PATCH 1/5] PM / Sleep: Add pm_generic functions to re-use runtime PM callbacks Date: Wed, 27 Nov 2013 16:34:56 +0100 Message-Id: <1385566500-7666-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1385566500-7666-1-git-send-email-ulf.hansson@linaro.org> References: <1385566500-7666-1-git-send-email-ulf.hansson@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ulf.hansson@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.43 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , To put devices into low power state during sleep, it sometimes makes sense at subsystem-level to re-use the runtime PM callbacks. The PM core will at device_suspend_late disable runtime PM, after that we can safely operate on these callbacks. At suspend_late the device will be put into low power state by invoking the runtime_suspend callbacks, unless the runtime status is already suspended. At resume_early the state is restored by invoking the runtime_resume callbacks. Soon after the PM core will re-enable runtime PM before returning from device_resume_early. The new pm_generic functions are named pm_generic_suspend_late_runtime and pm_generic_resume_early_runtime, they are supposed to be used in pairs. Do note that these new generic callbacks will work smothly even with and without CONFIG_PM_RUNTIME, as long as the runtime PM callbacks are implemented inside CONFIG_PM instead of CONFIG_PM_RUNTIME. A special thanks to Alan Stern who came up with this idea. Cc: Kevin Hilman Cc: Alan Stern Signed-off-by: Ulf Hansson --- drivers/base/power/generic_ops.c | 86 ++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 2 + 2 files changed, 88 insertions(+) diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c index 5ee030a..8e78ad1 100644 --- a/drivers/base/power/generic_ops.c +++ b/drivers/base/power/generic_ops.c @@ -93,6 +93,49 @@ int pm_generic_suspend_late(struct device *dev) EXPORT_SYMBOL_GPL(pm_generic_suspend_late); /** + * pm_generic_suspend_late_runtime - Generic suspend_late callback for drivers + * @dev: Device to suspend. + * Use to invoke runtime_suspend callbacks at suspend_late. + */ +int pm_generic_suspend_late_runtime(struct device *dev) +{ + int (*callback)(struct device *); + int ret = 0; + + /* + * PM core has disabled runtime PM in device_suspend_late, thus we can + * safely check the device's runtime status and decide whether + * additional actions are needed to put the device into low power state. + * If so, we invoke the runtime_suspend callbacks. + * For the !CONFIG_PM_RUNTIME case, pm_runtime_status_suspended() always + * returns false and therefore the runtime_suspend callback will be + * invoked. + */ + if (pm_runtime_status_suspended(dev)) + return 0; + + if (dev->pm_domain) + callback = dev->pm_domain->ops.runtime_suspend; + else if (dev->type && dev->type->pm) + callback = dev->type->pm->runtime_suspend; + else if (dev->class && dev->class->pm) + callback = dev->class->pm->runtime_suspend; + else if (dev->bus && dev->bus->pm) + callback = dev->bus->pm->runtime_suspend; + else + callback = NULL; + + if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_suspend; + + if (callback) + ret = callback(dev); + + return ret; +} +EXPORT_SYMBOL_GPL(pm_generic_suspend_late_runtime); + +/** * pm_generic_suspend - Generic suspend callback for subsystems. * @dev: Device to suspend. */ @@ -237,6 +280,49 @@ int pm_generic_resume_early(struct device *dev) EXPORT_SYMBOL_GPL(pm_generic_resume_early); /** + * pm_generic_resume_early_runtime - Generic resume_early callback for drivers + * @dev: Device to resume. + * Use to invoke runtime_resume callbacks at resume_early. + */ +int pm_generic_resume_early_runtime(struct device *dev) +{ + int (*callback)(struct device *); + int ret = 0; + + /* + * PM core has not yet enabled runtime PM in device_resume_early, + * thus we can safely check the device's runtime status and restore the + * previous state we had in device_suspend_late. If restore is needed + * we invoke the runtime_resume callbacks. + * For the !CONFIG_PM_RUNTIME case, pm_runtime_status_suspended() always + * returns false and therefore the runtime_resume callback will be + * invoked. + */ + if (pm_runtime_status_suspended(dev)) + return 0; + + if (dev->pm_domain) + callback = dev->pm_domain->ops.runtime_resume; + else if (dev->type && dev->type->pm) + callback = dev->type->pm->runtime_resume; + else if (dev->class && dev->class->pm) + callback = dev->class->pm->runtime_resume; + else if (dev->bus && dev->bus->pm) + callback = dev->bus->pm->runtime_resume; + else + callback = NULL; + + if (!callback && dev->driver && dev->driver->pm) + callback = dev->driver->pm->runtime_resume; + + if (callback) + ret = callback(dev); + + return ret; +} +EXPORT_SYMBOL_GPL(pm_generic_resume_early_runtime); + +/** * pm_generic_resume - Generic resume callback for subsystems. * @dev: Device to resume. */ diff --git a/include/linux/pm.h b/include/linux/pm.h index a224c7f..5bce0d4 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -656,9 +656,11 @@ extern void dpm_for_each_dev(void *data, void (*fn)(struct device *, void *)); extern int pm_generic_prepare(struct device *dev); extern int pm_generic_suspend_late(struct device *dev); +extern int pm_generic_suspend_late_runtime(struct device *dev); extern int pm_generic_suspend_noirq(struct device *dev); extern int pm_generic_suspend(struct device *dev); extern int pm_generic_resume_early(struct device *dev); +extern int pm_generic_resume_early_runtime(struct device *dev); extern int pm_generic_resume_noirq(struct device *dev); extern int pm_generic_resume(struct device *dev); extern int pm_generic_freeze_noirq(struct device *dev);