From patchwork Tue Sep 20 10:28:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jon Hunter X-Patchwork-Id: 9341419 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 9E3B6607D0 for ; Tue, 20 Sep 2016 10:29:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E7E629E91 for ; Tue, 20 Sep 2016 10:29:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 832B429EBB; Tue, 20 Sep 2016 10:29:18 +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 043C829E91 for ; Tue, 20 Sep 2016 10:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932708AbcITK2j (ORCPT ); Tue, 20 Sep 2016 06:28:39 -0400 Received: from hqemgate16.nvidia.com ([216.228.121.65]:18756 "EHLO hqemgate16.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753761AbcITK2d (ORCPT ); Tue, 20 Sep 2016 06:28:33 -0400 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Tue, 20 Sep 2016 03:28:29 -0700 Received: from HQMAIL108.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Tue, 20 Sep 2016 03:22:59 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Tue, 20 Sep 2016 03:22:59 -0700 Received: from HQMAIL106.nvidia.com (172.18.146.12) by HQMAIL108.nvidia.com (172.18.146.13) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 20 Sep 2016 10:27:54 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL106.nvidia.com (172.18.146.12) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 20 Sep 2016 10:27:54 +0000 Received: from jonathanh-lm.nvidia.com (Not Verified[10.21.132.118]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7, 5, 5, 8150) id ; Tue, 20 Sep 2016 03:27:54 -0700 From: Jon Hunter To: "Rafael J. Wysocki" , Kevin Hilman , Ulf Hansson CC: , , , Jon Hunter Subject: [RFC PATCH 1/3] PM / Domains: Add helper functions for finding and attaching PM domains Date: Tue, 20 Sep 2016 11:28:05 +0100 Message-ID: <1474367287-10402-2-git-send-email-jonathanh@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1474367287-10402-1-git-send-email-jonathanh@nvidia.com> References: <1474367287-10402-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 In preparation for supporting devices that require more than one PM domain, move the code for finding and attaching PM domains into local helper functions. Signed-off-by: Jon Hunter --- drivers/base/power/domain.c | 121 ++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 48 deletions(-) diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c index b0cf46dcae73..382735949591 100644 --- a/drivers/base/power/domain.c +++ b/drivers/base/power/domain.c @@ -1779,6 +1779,41 @@ struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) } EXPORT_SYMBOL_GPL(of_genpd_remove_last); +static struct generic_pm_domain *genpd_dev_pm_lookup(struct device *dev, + unsigned int index) +{ + struct of_phandle_args pd_args; + struct generic_pm_domain *pd; + int ret; + + ret = of_parse_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells", index, &pd_args); + if (ret < 0) { + if (ret != -ENOENT) + return ERR_PTR(ret); + + /* + * Try legacy Samsung-specific bindings + * (for backwards compatibility of DT ABI) + */ + pd_args.args_count = 0; + pd_args.np = of_parse_phandle(dev->of_node, + "samsung,power-domain", 0); + if (!pd_args.np) + return ERR_PTR(-ENOENT); + } + + pd = genpd_get_from_provider(&pd_args); + of_node_put(pd_args.np); + if (IS_ERR(pd)) { + dev_dbg(dev, "%s() failed to find PM domain: %ld\n", + __func__, PTR_ERR(pd)); + return ERR_PTR(-EPROBE_DEFER); + } + + return pd; +} + /** * genpd_dev_pm_detach - Detach a device from its PM domain. * @dev: Device to detach. @@ -1829,6 +1864,40 @@ static void genpd_dev_pm_sync(struct device *dev) genpd_queue_power_off_work(pd); } +static int genpd_dev_pm_attach_device(struct device *dev, + struct generic_pm_domain *pd) +{ + unsigned int i; + int ret; + + dev_dbg(dev, "adding to PM domain %s\n", pd->name); + + for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) { + ret = genpd_add_device(pd, dev, NULL); + if (ret != -EAGAIN) + break; + + mdelay(i); + cond_resched(); + } + + if (ret < 0) { + dev_err(dev, "failed to add to PM domain %s: %d", + pd->name, ret); + goto out; + } + + dev->pm_domain->detach = genpd_dev_pm_detach; + dev->pm_domain->sync = genpd_dev_pm_sync; + + mutex_lock(&pd->lock); + ret = genpd_poweron(pd, 0); + mutex_unlock(&pd->lock); +out: + return ret ? -EPROBE_DEFER : 0; + +} + /** * genpd_dev_pm_attach - Attach a device to its PM domain using DT. * @dev: Device to attach. @@ -1846,9 +1915,7 @@ static void genpd_dev_pm_sync(struct device *dev) */ int genpd_dev_pm_attach(struct device *dev) { - struct of_phandle_args pd_args; struct generic_pm_domain *pd; - unsigned int i; int ret; if (!dev->of_node) @@ -1857,59 +1924,17 @@ int genpd_dev_pm_attach(struct device *dev) if (dev->pm_domain) return -EEXIST; - ret = of_parse_phandle_with_args(dev->of_node, "power-domains", - "#power-domain-cells", 0, &pd_args); - if (ret < 0) { - if (ret != -ENOENT) - return ret; - - /* - * Try legacy Samsung-specific bindings - * (for backwards compatibility of DT ABI) - */ - pd_args.args_count = 0; - pd_args.np = of_parse_phandle(dev->of_node, - "samsung,power-domain", 0); - if (!pd_args.np) - return -ENOENT; - } - mutex_lock(&gpd_list_lock); - pd = genpd_get_from_provider(&pd_args); - of_node_put(pd_args.np); + pd = genpd_dev_pm_lookup(dev, 0); if (IS_ERR(pd)) { mutex_unlock(&gpd_list_lock); - dev_dbg(dev, "%s() failed to find PM domain: %ld\n", - __func__, PTR_ERR(pd)); return -EPROBE_DEFER; } - dev_dbg(dev, "adding to PM domain %s\n", pd->name); - - for (i = 1; i < GENPD_RETRY_MAX_MS; i <<= 1) { - ret = genpd_add_device(pd, dev, NULL); - if (ret != -EAGAIN) - break; - - mdelay(i); - cond_resched(); - } - mutex_unlock(&gpd_list_lock); - - if (ret < 0) { - dev_err(dev, "failed to add to PM domain %s: %d", - pd->name, ret); - goto out; - } - - dev->pm_domain->detach = genpd_dev_pm_detach; - dev->pm_domain->sync = genpd_dev_pm_sync; + ret = genpd_dev_pm_attach_device(dev, pd); + mutex_lock(&gpd_list_lock); - mutex_lock(&pd->lock); - ret = genpd_poweron(pd, 0); - mutex_unlock(&pd->lock); -out: - return ret ? -EPROBE_DEFER : 0; + return ret; } EXPORT_SYMBOL_GPL(genpd_dev_pm_attach); #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */