From patchwork Wed Sep 12 08:28:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 146522 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp4547242ljw; Wed, 12 Sep 2018 01:30:26 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbu5e2AtAY7PX9M8GhSNK0yP7FuU6UgTbo3HNYPywWEt1WrQIiPy1jYn/Yn8uxrti3m1wLL X-Received: by 2002:a17:902:9f90:: with SMTP id g16-v6mr925721plq.34.1536741026247; Wed, 12 Sep 2018 01:30:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536741026; cv=none; d=google.com; s=arc-20160816; b=LSFZILLxQ3KUgtVL3RcRH0ob8wwR4gXdnSdcKIcewkpGzIePwPUSW9704HuvaJVWFZ /RTbDR3fbDJqJMBK7h7QpGhLROkDUiztOkNPbcKrHUcQEb5461vfbeieOX72bsY4QqfP rToG1H0LzxjgxlDxpUHtLBQ3qGSe+xs+G5o406VBm2qhBJk3ZTaza5yT/J8gv1sxyP+4 H4nV76i4Y5/kjxYpz++VrgxiLq30aIEWRjSXPKpuD7ayCoYLuu5qYlSPsDOXsiPREox1 zwiWvxLFcuwzSM+PGG0SkCbDOYNJQlR/I7Xzw/+yYTMYamIZyMKLE8+sGxzSv3MUrXXN NOLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=LabDs4Ag3cbs9EteFoJpElF2B1erqsIywk8ijeAcC58Idczxn2TXCHEdaWKqBdnE5X 2DIF+6Li2Zy1slsbeB5WzvaWHvp2cLJlFqZuiHcWWuS5S3PGs4M7XXYBkvQUZUHCtcAO N37t+fBz9Oxs9KeDW5SCAPry+dCLR8cpQ4d9mNBJPRRhM6LIRsztpokipGim6ixt2bME Ud8pxN/W84x0/Pa+Jpb/lRMf4Xq3KRgrKNnAfv/Lxaje9DarrXrFe+B6LoK3XbENY0xo nACgvv/gcvYN963lnJ7IbPJ3tqwcPw2MR9H9FzbjajPi/J/XSc/67MaRZwm4Vz1ZXpl8 66hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZYIYY7ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d10-v6si415051pgg.341.2018.09.12.01.30.25; Wed, 12 Sep 2018 01:30:26 -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; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZYIYY7ie; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728245AbeILNdv (ORCPT + 32 others); Wed, 12 Sep 2018 09:33:51 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:33415 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727720AbeILNdt (ORCPT ); Wed, 12 Sep 2018 09:33:49 -0400 Received: by mail-pg1-f194.google.com with SMTP id s7-v6so684954pgc.0 for ; Wed, 12 Sep 2018 01:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=ZYIYY7ieWLdGVt4I6F0vJJS1u98pbm9AeIcLAbPEPv3NM6n6GzgEK0fO8XgqG3RjSH XlHtqBe8jU1G75F/nuFVayA16G6n+IIfEJQucSjZU4V+MAHRXxm1ThBVAw8GblqaCYfr +0jlr9QbEoX2NodKbHqhcIZhHeZwxn5QMkTKI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5qHARS78iPXhKZQpUWNSx9Hnn5Ojku3frnZML/qWdbg=; b=Npz5Pm7/kItoBE1iXRbUJLaN8o6VWUWmugQGR0Ka/YXplpTXMaz62MykF8aOyG43wq uRpDxcuKGN0SLDddiudx8aNCbGMnbyJUxUp8XNKRuzWOVV0BfYc7CJObzU8X+XSj08Y9 0PyxrZHR4HMoETzx01GcfvSSUmsnpPz4TiuzqLpNiiAdfQCkbQbYLcBC8GojwjSzsQot dbjhjuEfDZy/Jo3YpEFVfSOpqk9Wq5Lk7SpTBG/OjitFnhXaHz69X3oKQY6GKzfazoMY ZZZXaLN4RXtOq6uptmh+DhDryuE1h6ML02C5QAAqs00wS+Llmd47JXDKenftOzWigqwl J1HA== X-Gm-Message-State: APzg51DLavFMq8jdtCA7+aUB/qnSG7QtsnL9ORJawdFQlXKMV4GpZmnu Z8HkoJ/NiWYgZt5YHKxhTwSL1A== X-Received: by 2002:a63:fb07:: with SMTP id o7-v6mr877509pgh.333.1536741021653; Wed, 12 Sep 2018 01:30:21 -0700 (PDT) Received: from localhost ([122.171.64.45]) by smtp.gmail.com with ESMTPSA id 187-v6sm924302pfu.184.2018.09.12.01.30.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Sep 2018 01:30:21 -0700 (PDT) From: Viresh Kumar To: niklas.cassel@linaro.org, Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , linux-kernel@vger.kernel.org Subject: [PATCH 11/11] OPP: Pass OPP table to _of_add_opp_table_v{1|2}() Date: Wed, 12 Sep 2018 13:58:50 +0530 Message-Id: <5e869c96ac9fca2986dd7d82669b0593dc15c5c6.1536736872.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.18.0.rc1.242.g61856ae69a2c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Both _of_add_opp_table_v1() and _of_add_opp_table_v2() contain similar code to get the OPP table and their parent routine also parses the DT to find the OPP table's node pointer. This can be simplified by getting the OPP table in advance and then passing it as argument to these routines. Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 68 ++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) -- 2.18.0.rc1.242.g61856ae69a2c diff --git a/drivers/opp/of.c b/drivers/opp/of.c index db3e4d2b969e..c410ecc2c53d 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -399,18 +399,12 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, } /* Initializes OPP tables based on new bindings */ -static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, - int index) +static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table) { struct device_node *np; - struct opp_table *opp_table; int ret, count = 0, pstate_count = 0; struct dev_pm_opp *opp; - opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); - if (!opp_table) - return -ENOMEM; - /* OPP table is already initialized for the device */ if (opp_table->parsed_static_opps) { kref_get(&opp_table->list_kref); @@ -420,7 +414,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, kref_init(&opp_table->list_kref); /* We have opp-table node now, iterate over it and add OPPs */ - for_each_available_child_of_node(opp_np, np) { + for_each_available_child_of_node(opp_table->np, np) { count++; ret = _opp_add_static_v2(opp_table, dev, np); @@ -458,15 +452,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, put_list_kref: _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } /* Initializes OPP tables based on old-deprecated bindings */ -static int _of_add_opp_table_v1(struct device *dev) +static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table) { - struct opp_table *opp_table; const struct property *prop; const __be32 *val; int nr, ret = 0; @@ -487,10 +479,6 @@ static int _of_add_opp_table_v1(struct device *dev) return -EINVAL; } - opp_table = dev_pm_opp_get_opp_table(dev); - if (!opp_table) - return -ENOMEM; - kref_init(&opp_table->list_kref); val = prop->value; @@ -503,7 +491,6 @@ static int _of_add_opp_table_v1(struct device *dev) dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", __func__, freq, ret); _put_opp_list_kref(opp_table); - dev_pm_opp_put_opp_table(opp_table); return ret; } nr -= 2; @@ -531,24 +518,24 @@ static int _of_add_opp_table_v1(struct device *dev) */ int dev_pm_opp_of_add_table(struct device *dev) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret; + opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0); + if (!opp_table) + return -ENOMEM; + /* - * OPPs have two version of bindings now. The older one is deprecated, - * try for the new binding first. + * OPPs have two version of bindings now. Also try the old (v1) + * bindings for backward compatibility with older dtbs. */ - opp_np = dev_pm_opp_of_get_opp_desc_node(dev); - if (!opp_np) { - /* - * Try old-deprecated bindings for backward compatibility with - * older dtbs. - */ - return _of_add_opp_table_v1(dev); - } + if (opp_table->np) + ret = _of_add_opp_table_v2(dev, opp_table); + else + ret = _of_add_opp_table_v1(dev, opp_table); - ret = _of_add_opp_table_v2(dev, opp_np, 0); - of_node_put(opp_np); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; } @@ -575,28 +562,29 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); */ int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) { - struct device_node *opp_np; + struct opp_table *opp_table; int ret, count; -again: - opp_np = _opp_of_get_opp_desc_node(dev->of_node, index); - if (!opp_np) { + if (index) { /* * If only one phandle is present, then the same OPP table * applies for all index requests. */ count = of_count_phandle_with_args(dev->of_node, "operating-points-v2", NULL); - if (count == 1 && index) { - index = 0; - goto again; - } + if (count != 1) + return -ENODEV; - return -ENODEV; + index = 0; } - ret = _of_add_opp_table_v2(dev, opp_np, index); - of_node_put(opp_np); + opp_table = dev_pm_opp_get_opp_table_indexed(dev, index); + if (!opp_table) + return -ENOMEM; + + ret = _of_add_opp_table_v2(dev, opp_table); + if (ret) + dev_pm_opp_put_opp_table(opp_table); return ret; }