From patchwork Tue Mar 28 14:14:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Hunter X-Patchwork-Id: 9649781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9CEE460113 for ; Tue, 28 Mar 2017 14:16:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89F091FF35 for ; Tue, 28 Mar 2017 14:16:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E07F223C7; Tue, 28 Mar 2017 14:16:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E43721FF35 for ; Tue, 28 Mar 2017 14:16:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752550AbdC1OPu (ORCPT ); Tue, 28 Mar 2017 10:15:50 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:10496 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752146AbdC1OPt (ORCPT ); Tue, 28 Mar 2017 10:15:49 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Tue, 28 Mar 2017 07:15:27 -0700 Received: from HQMAIL103.nvidia.com ([172.20.13.39]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 28 Mar 2017 07:15:23 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 28 Mar 2017 07:15:23 -0700 Received: from HQMAIL112.nvidia.com (172.18.146.18) by HQMAIL103.nvidia.com (172.20.187.11) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 28 Mar 2017 14:15:23 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL112.nvidia.com (172.18.146.18) with Microsoft SMTP Server (TLS) id 15.0.1263.5; Tue, 28 Mar 2017 14:15:23 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1263.5 via Frontend Transport; Tue, 28 Mar 2017 14:15:22 +0000 Received: from goldfinger.nvidia.com (Not Verified[10.21.132.162]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7, 5, 5, 8150) id ; Tue, 28 Mar 2017 07:15:22 -0700 From: Jon Hunter To: "Rafael J . Wysocki" , Kevin Hilman , Ulf Hansson , , CC: , , Marek Szyprowski , , , , Jon Hunter Subject: [RFC PATCH 3/4] PM / Domains: Add OF helpers for getting PM domains Date: Tue, 28 Mar 2017 15:14:02 +0100 Message-ID: <1490710443-27425-4-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490710443-27425-1-git-send-email-jonathanh@nvidia.com> References: <1490710443-27425-1-git-send-email-jonathanh@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add helper functions for getting PM domains via device-tree that are to be controlled explicitly via the pm_genpd_poweron/off() APIs. PM domains can be retrieved by either index or name. Retrieving a PM domain by name requires that the 'power-domain-names' property is present for the consumer. Signed-off-by: Jon Hunter --- drivers/base/power/domain.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_domain.h | 17 +++++++++++ 2 files changed, 89 insertions(+) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index 4980ec157750..77516b2b3e58 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -2285,6 +2285,78 @@ int of_genpd_parse_idle_states(struct device_node *dn, return 0; } EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states); + +static struct generic_pm_domain *genpd_get(struct device_node *np, int index) +{ + struct of_phandle_args genpdspec; + struct generic_pm_domain *genpd; + int ret; + + if (index < 0) + return ERR_PTR(-EINVAL); + + ret = of_parse_phandle_with_args(np, "power-domains", + "#power-domain-cells", index, + &genpdspec); + if (ret) + return ERR_PTR(ret); + + mutex_lock(&gpd_list_lock); + + genpd = genpd_get_from_provider(&genpdspec); + of_node_put(genpdspec.np); + + if (!IS_ERR(genpd)) { + genpd_lock(genpd); + genpd->device_count++; + genpd->suspended_count++; + genpd_unlock(genpd); + } + + mutex_unlock(&gpd_list_lock); + + return genpd; +} + +/** + * of_genpd_get() - Get a PM domain by index using a device node + * @np: pointer to PM domain consumer node + * @index: index reference for a PM domain in the consumer node + * + * This function parses the 'power-domains' property using the index + * provided to look up a PM domain from the registered list of PM domain + * providers. + */ +struct generic_pm_domain *of_genpd_get(struct device_node *np, int index) +{ + return genpd_get(np, index); +} +EXPORT_SYMBOL(of_genpd_get); + +/** + * of_genpd_get_by_name() - Get a PM domain by name using a device node + * @np: pointer to PM domain consumer node + * @name: name reference for a PM domain in the consumer node + * + * This function parses the 'power-domains' and 'power-domain-names' + * properties, and uses them to look up a PM domain from the registered + * list of PM domain providers. + */ +struct generic_pm_domain *of_genpd_get_by_name(struct device_node *np, + const char *name) +{ + int index; + + if (!np || !name) + return ERR_PTR(-EINVAL); + + index = of_property_match_string(np, "power-domain-names", name); + if (index < 0) + return ERR_PTR(index); + + return genpd_get(np, index); +} +EXPORT_SYMBOL(of_genpd_get_by_name); #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h index b3aa1f237d96..d0183d96a1b3 100644 --- a/include/linux/pm_domain.h +++ b/include/linux/pm_domain.h @@ -240,6 +240,10 @@ extern int of_genpd_add_subdomain(struct of_phandle_args *parent, extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); extern int of_genpd_parse_idle_states(struct device_node *dn, struct genpd_power_state **states, int *n); +extern struct generic_pm_domain *of_genpd_get(struct device_node *np, + int index); +extern struct generic_pm_domain *of_genpd_get_by_name(struct device_node *np, + const char *name); int genpd_dev_pm_attach(struct device *dev); #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ @@ -285,6 +289,19 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) { return ERR_PTR(-ENOTSUPP); } + +static inline +struct generic_pm_domain *of_genpd_get(struct device_node *np, int index) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline +struct generic_pm_domain *of_genpd_get_by_name(struct device_node *np, + const char *name) +{ + return ERR_PTR(-ENOTSUPP); +} #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ #ifdef CONFIG_PM