From patchwork Fri Mar 13 15:43:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 45789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6BED6214BF for ; Fri, 13 Mar 2015 15:44:08 +0000 (UTC) Received: by lbiz11 with SMTP id z11sf17427227lbi.2 for ; Fri, 13 Mar 2015 08:44:07 -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=0q3DoGmnMtpLbP/BUk7SejJsZ0nWxs6XP6wjtN7QiAY=; b=kXrmtehSzYg80AFBPlemIMmPZCVHA4fDqd2EN3+e/ngoPZwhurQde93f5XEC8hpWBJ oRuMgFkrcnVSqC4WF2/iqAPhbKp8avkx3dcmssLzcoca7+3PuJtHFFDfekYPhbvA/U9U q9bVyQaSsMlMj6oq771zK4kxpT1/z8jrigwU9MV+/uWGVMOCIG8c1DuyBUwiGPORTlOW 5LU7vMUV02t+i0TFurcvwCvSBIGDWufmIw3B8pFOsxsAclhmDNR+yL0YKFmBmoSxAmtk XTFWO7rH4gB4Re6mwRVRi0U66WSrnhf2bjgBF+4Md42uC+bZBVmGShQAdTicj1FvIT43 UFyA== X-Gm-Message-State: ALoCoQmjZZXURx/WJbJdDYUnQurYGLk7Zd6kqvsgJl80wGDu6zW674EgeYF+OZeEDDRJlI2c1S3P X-Received: by 10.112.25.7 with SMTP id y7mr7226692lbf.21.1426261447474; Fri, 13 Mar 2015 08:44:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.45.6 with SMTP id i6ls427178lam.10.gmail; Fri, 13 Mar 2015 08:44:07 -0700 (PDT) X-Received: by 10.152.5.170 with SMTP id t10mr43657426lat.43.1426261447333; Fri, 13 Mar 2015 08:44:07 -0700 (PDT) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id w3si1635635lag.108.2015.03.13.08.44.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 08:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by lbdu14 with SMTP id u14so23719740lbd.0 for ; Fri, 13 Mar 2015 08:44:07 -0700 (PDT) X-Received: by 10.112.130.195 with SMTP id og3mr43178671lbb.112.1426261447242; Fri, 13 Mar 2015 08:44:07 -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.35.133 with SMTP id h5csp999931lbj; Fri, 13 Mar 2015 08:44:06 -0700 (PDT) X-Received: by 10.112.166.102 with SMTP id zf6mr39954258lbb.24.1426261446748; Fri, 13 Mar 2015 08:44:06 -0700 (PDT) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com. [209.85.217.177]) by mx.google.com with ESMTPS id b6si1644301lak.36.2015.03.13.08.44.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Mar 2015 08:44:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.217.177 as permitted sender) client-ip=209.85.217.177; Received: by lbiw7 with SMTP id w7so23678844lbi.6 for ; Fri, 13 Mar 2015 08:44:06 -0700 (PDT) X-Received: by 10.112.171.65 with SMTP id as1mr44045165lbc.45.1426261446593; Fri, 13 Mar 2015 08:44:06 -0700 (PDT) Received: from uffe-Latitude-E6430s.lan (90-231-160-185-no158.tbcn.telia.com. [90.231.160.185]) by mx.google.com with ESMTPSA id i9sm471248lbs.26.2015.03.13.08.44.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Mar 2015 08:44:04 -0700 (PDT) From: Ulf Hansson To: "Rafael J. Wysocki" , Len Brown , Pavel Machek , Kevin Hilman , linux-pm@vger.kernel.org Cc: Geert Uytterhoeven , Dmitry Torokhov , Russell King , Greg Kroah-Hartman , Mark Brown , Wolfram Sang , linux-arm-kernel@lists.infradead.org, Ulf Hansson Subject: [PATCH 1/9] PM / Domains: Add dev_pm_domain_get|put() APIs Date: Fri, 13 Mar 2015 16:43:41 +0100 Message-Id: <1426261429-31883-2-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426261429-31883-1-git-send-email-ulf.hansson@linaro.org> References: <1426261429-31883-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.180 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 f32b802..99225af 100644 --- a/drivers/base/power/common.c +++ b/drivers/base/power/common.c @@ -128,3 +128,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 e2f1be6..e62330b 100644 --- a/include/linux/pm.h +++ b/include/linux/pm.h @@ -607,6 +607,8 @@ extern void 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 080e778..c80d6ac 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -315,12 +315,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 */