From patchwork Fri Sep 19 18:27:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 37649 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 49B6520293 for ; Fri, 19 Sep 2014 18:28:09 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id l18sf71593wgh.8 for ; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) 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=7eJvWF2YyomBKwUpLJ3gbRvbk3mYMKd5yyKAWO0V/hA=; b=GWMCvScJ4WqJWhjF2KsDC3DZc7Hl8ZAAP61OdNWGkjt+hxTpDRlJsjb5bfO2eu50Yu ovzpW7oqH7dIwIUwgR595C0F1OoDzmwkbKHPjIarVynqfiJxR5AU9JbsPY4LUh6/OQst ctIVR96bkJaVEq9+63pmEtBDJz9b7Bfm9AA08Mv75DUzCbf/tSaii/uGExlPkBCwe0gY lFcjfi9S2Wv9RFqzd5Ig2OxS/8VdGKmDdh773r54H2d/+Snnx0p/dHNfkiXNW4dKNhD7 GD8kz/p+jdVCPQ1DI3fL01G7RfgFMlHe9eaAVL/1LHrqcjIW8b156C3hAY11PRvBEbIi 6c8Q== X-Gm-Message-State: ALoCoQnbpnGfvIcRwL5552j1sfcxEOCJlkpT2zIfbPsHRB/ic2k/IWKuMcl3OHoa6PM7/ACn4PoI X-Received: by 10.180.24.70 with SMTP id s6mr26754wif.3.1411151288527; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.206.4 with SMTP id lk4ls358631lac.41.gmail; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) X-Received: by 10.112.199.232 with SMTP id jn8mr8189126lbc.30.1411151288379; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com [209.85.217.176]) by mx.google.com with ESMTPS id r5si3698409lal.3.2014.09.19.11.28.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Sep 2014 11:28:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id z11so3623168lbi.7 for ; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) X-Received: by 10.152.246.6 with SMTP id xs6mr8620071lac.56.1411151288250; Fri, 19 Sep 2014 11:28:08 -0700 (PDT) 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.112.130.169 with SMTP id of9csp989497lbb; Fri, 19 Sep 2014 11:28:07 -0700 (PDT) X-Received: by 10.68.130.4 with SMTP id oa4mr2649705pbb.167.1411151284258; Fri, 19 Sep 2014 11:28:04 -0700 (PDT) Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by mx.google.com with ESMTPS id sl5si4151240pbc.164.2014.09.19.11.28.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 19 Sep 2014 11:28:04 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Received: by mail-pa0-f41.google.com with SMTP id ey11so678418pad.0 for ; Fri, 19 Sep 2014 11:28:03 -0700 (PDT) X-Received: by 10.66.97.41 with SMTP id dx9mr3974644pab.65.1411151283507; Fri, 19 Sep 2014 11:28:03 -0700 (PDT) Received: from localhost.localdomain ([38.126.120.10]) by mx.google.com with ESMTPSA id ki1sm2495071pdb.59.2014.09.19.11.27.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Sep 2014 11:28:02 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Greg Kroah-Hartman , linux-pm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-acpi@vger.kernel.org, Geert Uytterhoeven , Kevin Hilman , Alan Stern , Daniel Lezcano , Tomasz Figa , devicetree@vger.kernel.org, Linus Walleij , Simon Horman , Magnus Damm , Ben Dooks , Kukjin Kim , Stephen Boyd , Philipp Zabel , Mark Brown , Wolfram Sang , Chris Ball , Russell King , Dmitry Torokhov , Ulf Hansson Subject: [PATCH v5 04/11] PM / Domains: Add APIs to attach/detach a PM domain for a device Date: Fri, 19 Sep 2014 20:27:37 +0200 Message-Id: <1411151264-16245-5-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1411151264-16245-1-git-send-email-ulf.hansson@linaro.org> References: <1411151264-16245-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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) 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 maintain scalability let's add common methods to attach and detach a PM domain for a device, dev_pm_domain_attach|detach(). Typically dev_pm_domain_attach() shall be invoked from subsystem level code at the probe phase to try to attach a device to its PM domain. The reversed actions may be done a the remove phase and then by invoking dev_pm_domain_detach(). When attachment succeeds, the attach function should assign its corresponding detach function to a new ->detach() callback added in the struct dev_pm_domain. Signed-off-by: Ulf Hansson Tested-by: Philipp Zabel Reviewed-by: Kevin Hilman --- drivers/base/power/common.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 11 ++++++++++ 2 files changed, 63 insertions(+) diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index df2e5ee..a0a415d 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include /** * dev_pm_get_subsys_data - Create or refcount power.subsys_data for device. @@ -82,3 +84,53 @@ int dev_pm_put_subsys_data(struct device *dev) return ret; } EXPORT_SYMBOL_GPL(dev_pm_put_subsys_data); + +/** + * dev_pm_domain_attach - Attach a device to its PM domain. + * @dev: Device to attach. + * @power_on: Used to indicate whether we should power on the device. + * + * The @dev may only be attached to a single PM domain. By iterating through + * the available alternatives we try to find a valid PM domain for the device. + * As attachement succeeds, the ->detach() callback in the struct dev_pm_domain + * should be assigned by the corresponding attach function. + * + * This function should typically be invoked from subsystem level code during + * the probe phase. Especially for those that holds devices which requires + * power management through PM domains. + * + * Callers must ensure proper synchronization of this function with power + * management callbacks. + * + * Returns 0 on successfully attached PM domain or negative error code. + */ +int dev_pm_domain_attach(struct device *dev, bool power_on) +{ + int ret; + + ret = acpi_dev_pm_attach(dev, power_on); + if (ret) + ret = genpd_dev_pm_attach(dev); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_domain_attach); + +/** + * dev_pm_domain_detach - Detach a device from its PM domain. + * @dev: Device to attach. + * @power_off: Used to indicate whether we should power off the device. + * + * This functions will reverse the actions from dev_pm_domain_attach() and thus + * try to detach the @dev from its PM domain. Typically it should be invoked + * from subsystem level code during the remove phase. + * + * Callers must ensure proper synchronization of this function with power + * management callbacks. + */ +void dev_pm_domain_detach(struct device *dev, bool power_off) +{ + if (dev->pm_domain && dev->pm_domain->detach) + dev->pm_domain->detach(dev, power_off); +} +EXPORT_SYMBOL_GPL(dev_pm_domain_detach); diff --git a/include/linux/pm.h b/include/linux/pm.h index ef4e16f..ff6400d 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -622,6 +622,17 @@ struct dev_pm_domain { void (*detach)(struct device *, bool); }; +#ifdef CONFIG_PM +extern int dev_pm_domain_attach(struct device *dev, bool power_on); +extern void dev_pm_domain_detach(struct device *dev, bool power_off); +#else +static inline int dev_pm_domain_attach(struct device *dev, bool power_on) +{ + return -ENODEV; +} +static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} +#endif + /* * The PM_EVENT_ messages are also used by drivers implementing the legacy * suspend framework, based on the ->suspend() and ->resume() callbacks common