From patchwork Tue Aug 11 10:34:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 52297 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 29EF222FEC for ; Tue, 11 Aug 2015 10:35:10 +0000 (UTC) Received: by labth1 with SMTP id th1sf71111308lab.2 for ; Tue, 11 Aug 2015 03:35:08 -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:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=7mk313dNKcMZiF3Y9x8KYyZxAw4ZkrFjwhDZM6hfnQA=; b=K4HgPLxGsy6u9yueHXhCExwv9+p7uQ/hX3PNjYEGPwn1Ue1xEWohSB8lggSOLNUZk/ XHTErNHJ4qOdVixgk2Q7HrjmotK9KrAfgd7GbKKfzrppw34kFER+L1WrTvla9NOmLUd7 dAC+uhdg4ricRvjBiW2lm9o41y44PW5ydTernVnl1s1GihafjXuUmae/FToMAf/hwGrG RqVmJUzrADw19ElXgFXUtLWrwv5YAy+0bULv8QTJUpkdJZhhckJ+jfBmHslIBooT2/K8 H0NpCuZcP2lw1pQMsNvug4nPt3/rHsxg3pom++WQf/N5wGNQ82UxAupXAO4X0k2X2KYH Mm0Q== X-Gm-Message-State: ALoCoQmvH7iXGClV/vPSOowPKDCa7Sjr3lB3tNXNLs3RPWDKVpKreci+KSswD0UJJp4tGHWsN/G7 X-Received: by 10.112.98.42 with SMTP id ef10mr7757233lbb.18.1439289308317; Tue, 11 Aug 2015 03:35:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.23.74 with SMTP id k10ls862845laf.30.gmail; Tue, 11 Aug 2015 03:35:08 -0700 (PDT) X-Received: by 10.112.13.134 with SMTP id h6mr25794065lbc.15.1439289308010; Tue, 11 Aug 2015 03:35:08 -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 ln3si1026818lac.152.2015.08.11.03.35.07 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Aug 2015 03:35: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 lbcbn3 with SMTP id bn3so16035054lbc.2 for ; Tue, 11 Aug 2015 03:35:07 -0700 (PDT) X-Received: by 10.152.44.196 with SMTP id g4mr7180479lam.56.1439289307888; Tue, 11 Aug 2015 03:35:07 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.7.198 with SMTP id l6csp2434155lba; Tue, 11 Aug 2015 03:35:06 -0700 (PDT) X-Received: by 10.70.52.226 with SMTP id w2mr22270897pdo.88.1439289305615; Tue, 11 Aug 2015 03:35:05 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cb3si2745162pbc.68.2015.08.11.03.35.04; Tue, 11 Aug 2015 03:35:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964871AbbHKKe6 (ORCPT + 28 others); Tue, 11 Aug 2015 06:34:58 -0400 Received: from mail-pa0-f48.google.com ([209.85.220.48]:33701 "EHLO mail-pa0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934318AbbHKKey (ORCPT ); Tue, 11 Aug 2015 06:34:54 -0400 Received: by pabyb7 with SMTP id yb7so127677212pab.0 for ; Tue, 11 Aug 2015 03:34:53 -0700 (PDT) X-Received: by 10.66.249.1 with SMTP id yq1mr53986430pac.3.1439289293515; Tue, 11 Aug 2015 03:34:53 -0700 (PDT) Received: from localhost ([122.171.186.190]) by smtp.gmail.com with ESMTPSA id fv2sm2101753pbd.54.2015.08.11.03.34.52 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 11 Aug 2015 03:34:52 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , nm@ti.com, sboyd@codeaurora.org Cc: linaro-kernel@lists.linaro.org, linux-pm@vger.kernel.org, khilman@linaro.org, Viresh Kumar , Greg Kroah-Hartman , Len Brown , linux-kernel@vger.kernel.org (open list), Pavel Machek Subject: [PATCH V2 2/6] PM / OPP: reuse of_parse_phandle() Date: Tue, 11 Aug 2015 16:04:35 +0530 Message-Id: <023db57fcc8095f824c10cf893e73855a0d7ab81.1439288881.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.4.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: viresh.kumar@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.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , We already have a better API to get the opp descriptor block's node from cpu-node. Lets reuse that instead of creating our own routines for the same stuff. That cleans the code a lot. This also kills a check we had earlier (as we are using the generic API now). Earlier we used to check if the operating-points-v2 property contained multiple phandles instead of a single phandle. Killing this check isn't an issue because, we only parse the first entry with of_parse_phandle(). So, if a user passes multiple phandles, its really his problem :) Signed-off-by: Viresh Kumar --- drivers/base/power/opp.c | 72 ++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 54 deletions(-) diff --git a/drivers/base/power/opp.c b/drivers/base/power/opp.c index bcbd92c3b717..7527de217edb 100644 --- a/drivers/base/power/opp.c +++ b/drivers/base/power/opp.c @@ -1250,69 +1250,33 @@ void of_cpumask_free_opp_table(cpumask_var_t cpumask) } EXPORT_SYMBOL_GPL(of_cpumask_free_opp_table); -/* Returns opp descriptor node from its phandle. Caller must do of_node_put() */ -static struct device_node * -_of_get_opp_desc_node_from_prop(struct device *dev, const struct property *prop) -{ - struct device_node *opp_np; - - opp_np = of_find_node_by_phandle(be32_to_cpup(prop->value)); - if (!opp_np) { - dev_err(dev, "%s: Prop: %s contains invalid opp desc phandle\n", - __func__, prop->name); - return ERR_PTR(-EINVAL); - } - - return opp_np; -} - -/* Returns opp descriptor node for a device. Caller must do of_node_put() */ +/* Returns opp descriptor node for a device, caller must do of_node_put() */ static struct device_node *_of_get_opp_desc_node(struct device *dev) { - const struct property *prop; - - prop = of_find_property(dev->of_node, "operating-points-v2", NULL); - if (!prop) - return ERR_PTR(-ENODEV); - if (!prop->value) - return ERR_PTR(-ENODATA); - /* * TODO: Support for multiple OPP tables. * * There should be only ONE phandle present in "operating-points-v2" * property. */ - if (prop->length != sizeof(__be32)) { - dev_err(dev, "%s: Invalid opp desc phandle\n", __func__); - return ERR_PTR(-EINVAL); - } - return _of_get_opp_desc_node_from_prop(dev, prop); + return of_parse_phandle(dev->of_node, "operating-points-v2", 0); } /* Initializes OPP tables based on new bindings */ static int _of_init_opp_table_v2(struct device *dev, - const struct property *prop) + struct device_node *opp_np) { - struct device_node *opp_np, *np; + struct device_node *np; struct device_opp *dev_opp; int ret = 0, count = 0; - if (!prop->value) - return -ENODATA; - - /* Get opp node */ - opp_np = _of_get_opp_desc_node_from_prop(dev, prop); - if (IS_ERR(opp_np)) - return PTR_ERR(opp_np); - dev_opp = _managed_opp(opp_np); if (dev_opp) { /* OPPs are already managed */ if (!_add_list_dev(dev, dev_opp)) ret = -ENOMEM; - goto put_opp_np; + return ret; } /* We have opp-list node now, iterate over it and add OPPs */ @@ -1328,10 +1292,8 @@ static int _of_init_opp_table_v2(struct device *dev, } /* There should be one of more OPP defined */ - if (WARN_ON(!count)) { - ret = -ENOENT; - goto put_opp_np; - } + if (WARN_ON(!count)) + return -ENOENT; dev_opp = _find_device_opp(dev); if (WARN_ON(IS_ERR(dev_opp))) { @@ -1342,12 +1304,10 @@ static int _of_init_opp_table_v2(struct device *dev, dev_opp->np = opp_np; dev_opp->shared_opp = of_property_read_bool(opp_np, "opp-shared"); - goto put_opp_np; + return 0; free_table: of_free_opp_table(dev); -put_opp_np: - of_node_put(opp_np); return ret; } @@ -1414,14 +1374,15 @@ static int _of_init_opp_table_v1(struct device *dev) */ int of_init_opp_table(struct device *dev) { - const struct property *prop; + struct device_node *opp_np; + int ret; /* * OPPs have two version of bindings now. The older one is deprecated, * try for the new binding first. */ - prop = of_find_property(dev->of_node, "operating-points-v2", NULL); - if (!prop) { + opp_np = _of_get_opp_desc_node(dev); + if (!opp_np) { /* * Try old-deprecated bindings for backward compatibility with * older dtbs. @@ -1429,7 +1390,10 @@ int of_init_opp_table(struct device *dev) return _of_init_opp_table_v1(dev); } - return _of_init_opp_table_v2(dev, prop); + ret = _of_init_opp_table_v2(dev, opp_np); + of_node_put(opp_np); + + return ret; } EXPORT_SYMBOL_GPL(of_init_opp_table); @@ -1518,7 +1482,7 @@ int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask) /* Get OPP descriptor node */ np = _of_get_opp_desc_node(cpu_dev); - if (IS_ERR(np)) { + if (!np) { dev_dbg(cpu_dev, "%s: Couldn't find opp node: %ld\n", __func__, PTR_ERR(np)); return -ENOENT; @@ -1542,7 +1506,7 @@ int of_get_cpus_sharing_opps(struct device *cpu_dev, cpumask_var_t cpumask) /* Get OPP descriptor node */ tmp_np = _of_get_opp_desc_node(tcpu_dev); - if (IS_ERR(tmp_np)) { + if (!tmp_np) { dev_err(tcpu_dev, "%s: Couldn't find opp node: %ld\n", __func__, PTR_ERR(tmp_np)); ret = PTR_ERR(tmp_np);