From patchwork Mon Oct 13 14:02:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 38659 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7D74B2039B for ; Mon, 13 Oct 2014 14:02:32 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf2907990wiv.10 for ; Mon, 13 Oct 2014 07:02:31 -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=THC074x8EvvQP7InsEes4joD1H+mQ3AtjlLIA7HYiaw=; b=ia+UIdNOrbaz0mw6gMBjih+lAZGpNCrhhil0dCyTSSUAG1LBJSPuqTRfoetbplC0Fx Z9eWmewiEfWw5mVO3kwEST6cyJfpLLz5sNcD0q/rh2NbdCMX6Bmp+Tf2RNFwO/qNSG/y pejfBDDPxXWeRDtcjHf0hSOu9Al5/47cDC49p+WxACLkCh2594K9u+duWqT/JsaU09su dc8dyOru+ZOdmFA2eUBOA9yeewcYhc90ZZebGVNKp8TsGp9TCO2CYrbn9ZfsxevknX5Y 5qXAWBVSpSORQC6RE3sb3LF5InVbqjFQGDlMGOOZNWGGvqDOz+EV5j45fNDaMur9vBxI uN5Q== X-Gm-Message-State: ALoCoQleqamACQOI6mPeo+XZUs7/GPeESwVUCWWeBjHQmKb+dD8paP5m7Cebkf1RdK0KthahyWWX X-Received: by 10.180.85.8 with SMTP id d8mr189451wiz.7.1413208951645; Mon, 13 Oct 2014 07:02:31 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.227 with SMTP id i3ls412171lae.28.gmail; Mon, 13 Oct 2014 07:02:31 -0700 (PDT) X-Received: by 10.112.130.226 with SMTP id oh2mr3143639lbb.100.1413208951480; Mon, 13 Oct 2014 07:02:31 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com [209.85.217.182]) by mx.google.com with ESMTPS id gd7si22333023lbc.83.2014.10.13.07.02.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 07:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id z11so6330094lbi.41 for ; Mon, 13 Oct 2014 07:02:31 -0700 (PDT) X-Received: by 10.112.156.227 with SMTP id wh3mr23964480lbb.23.1413208951252; Mon, 13 Oct 2014 07:02:31 -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.84.229 with SMTP id c5csp220087lbz; Mon, 13 Oct 2014 07:02:30 -0700 (PDT) X-Received: by 10.194.78.76 with SMTP id z12mr20976229wjw.24.1413208950658; Mon, 13 Oct 2014 07:02:30 -0700 (PDT) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com [74.125.82.51]) by mx.google.com with ESMTPS id dy10si12669607wib.89.2014.10.13.07.02.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Oct 2014 07:02:30 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 74.125.82.51 as permitted sender) client-ip=74.125.82.51; Received: by mail-wg0-f51.google.com with SMTP id b13so8692185wgh.22 for ; Mon, 13 Oct 2014 07:02:30 -0700 (PDT) X-Received: by 10.180.97.199 with SMTP id ec7mr943650wib.29.1413208950368; Mon, 13 Oct 2014 07:02:30 -0700 (PDT) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id fq1sm1533474wib.12.2014.10.13.07.02.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Oct 2014 07:02:29 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , linux-pm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, Geert Uytterhoeven , Kevin Hilman , Alan Stern , Greg Kroah-Hartman , Tomasz Figa , Simon Horman , Magnus Damm , Ben Dooks , Kukjin Kim , Philipp Zabel , Mark Brown , Wolfram Sang , Russell King , Dmitry Torokhov , Jack Dai , Jinkun Hong , Aaron Lu , Sylwester Nawrocki , Ulf Hansson Subject: [PATCH v3 1/9] PM / Domains: Add dev_pm_domain_get|put() APIs Date: Mon, 13 Oct 2014 16:02:02 +0200 Message-Id: <1413208930-26019-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1413208930-26019-1-git-send-email-ulf.hansson@linaro.org> References: <1413208930-26019-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.182 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: , There may be more than one device in a PM domain which then will be probed at different points in time. Depending on timing and runtime PM support, in for the device related driver/subsystem, a PM domain may be advised to power off after a successful probe sequence. A general requirement for a device within a PM domain, is that the PM domain must stay powered during the probe sequence. To cope with such requirement, let's add the dev_pm_domain_get|put() APIs. These APIs are intended to be invoked from subsystem-level code and the calls between get/put needs to be balanced. dev_pm_domain_get(), tells the PM domain that it needs to increase a usage count and to keep supplying power. dev_pm_domain_put(), does the opposite. For a PM domain to support this feature, it must implement the optional ->get|put() callbacks. Signed-off-by: Ulf Hansson --- drivers/base/power/common.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/pm.h | 2 ++ include/linux/pm_domain.h | 4 ++++ 3 files changed, 46 insertions(+) diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c index b0f1388..b4f0c8c 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -134,3 +134,43 @@ void dev_pm_domain_detach(struct device *dev, bool power_off) dev->pm_domain->detach(dev, power_off); } EXPORT_SYMBOL_GPL(dev_pm_domain_detach); + +/** + * dev_pm_domain_get - Increase usage count to keep a PM domain powered. + * @domain: The PM domain to operate on. + * + * This function will not by itself increase the usage count, that's up to each + * PM domain implementation to support. Typically it should be invoked from + * subsystem level code prior drivers starts probing. + * + * Do note, it's optional to implement the ->get() callback for a PM domain. + * + * Returns 0 on successfully increased usage count or negative error code. + */ +int dev_pm_domain_get(struct dev_pm_domain *domain) +{ + int ret = 0; + + if (domain && domain->get) + ret = domain->get(domain); + + return ret; +} +EXPORT_SYMBOL_GPL(dev_pm_domain_get); + +/** + * dev_pm_domain_put - Decrease usage count to allow a PM domain to power off. + * @domain: The PM domain to operate on. + * + * This function will not by itself decrease the usage count, that's up to each + * PM domain implementation to support. Typically it should be invoked from + * subsystem level code after drivers has finished probing. + * + * Do note, it's optional to implement the ->put() callback for a PM domain. + */ +void dev_pm_domain_put(struct dev_pm_domain *domain) +{ + if (domain && domain->put) + domain->put(domain); +} +EXPORT_SYMBOL_GPL(dev_pm_domain_put); diff --git a/include/linux/pm.h b/include/linux/pm.h index 383fd68..f71900d 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -620,6 +620,8 @@ extern int dev_pm_put_subsys_data(struct device *dev); struct dev_pm_domain { struct dev_pm_ops ops; void (*detach)(struct device *dev, bool power_off); + int (*get)(struct dev_pm_domain *domain); + void (*put)(struct dev_pm_domain *domain); }; /* diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index 73e938b..8e2806f 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -304,12 +304,16 @@ static inline int of_genpd_add_provider_onecell(struct device_node *np, #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); +extern int dev_pm_domain_get(struct dev_pm_domain *domain); +extern void dev_pm_domain_put(struct dev_pm_domain *domain); #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) {} +static inline int dev_pm_domain_get(struct dev_pm_domain *domain) { return 0; } +static inline void dev_pm_domain_put(struct dev_pm_domain *domain) {} #endif #endif /* _LINUX_PM_DOMAIN_H */