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: 5076691 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D4ED1C11AC for ; Mon, 13 Oct 2014 14:06:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E564E201FE for ; Mon, 13 Oct 2014 14:06:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EA102201F7 for ; Mon, 13 Oct 2014 14:06:24 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XdgDB-0007X6-07; Mon, 13 Oct 2014 14:02:57 +0000 Received: from mail-wg0-f50.google.com ([74.125.82.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XdgD6-0007RX-52 for linux-arm-kernel@lists.infradead.org; Mon, 13 Oct 2014 14:02:52 +0000 Received: by mail-wg0-f50.google.com with SMTP id a1so8670316wgh.33 for ; Mon, 13 Oct 2014 07:02:30 -0700 (PDT) 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=THC074x8EvvQP7InsEes4joD1H+mQ3AtjlLIA7HYiaw=; b=aX4yagIy8774cE+1yDWMN7/XgTYkc7voFIZF+GKHU1Z/FeQs90/ONAvkozplrYSG2s TzhzU20Q/PpL91cEprf6FaqK+fBeNAhP2itB1LIYG89P4LO9Qu0atw4bDk+BMdmFiIcm nxjVlLolmR6Uw83sQYGTOa3CUncwjyKyudeBjicytyejrGUl7a4B6mUOftqDiw2L2gz1 /O3BwbZbHaNOSycAUR+77EP74ogX7c6+2i+qOAGE4l2+uCdRMegC/M9n2d/9BdBkF07D ufLp3kFMvuTaw6LCzTzE+q0TYiyvno7gHeun5PzD6qRKJp1xW7zvUh8wYveRs1d2Znts rezg== X-Gm-Message-State: ALoCoQmzqDBf9Fcpo/9VgECMTQaFXWemik/xUa+aA+u8XAWigfXiObbOLd3dyE3QTL8hvgyxUzJV 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 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141013_070252_346353_97456C66 X-CRM114-Status: GOOD ( 18.49 ) X-Spam-Score: -0.7 (/) Cc: Simon Horman , Ulf Hansson , Kevin Hilman , Russell King , Philipp Zabel , Geert Uytterhoeven , Wolfram Sang , Greg Kroah-Hartman , Mark Brown , Dmitry Torokhov , Magnus Damm , Tomasz Figa , linux-samsung-soc@vger.kernel.org, Alan Stern , Ben Dooks , Jinkun Hong , Kukjin Kim , Sylwester Nawrocki , Aaron Lu , Jack Dai , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 */