From patchwork Wed Sep 19 22:20:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 147057 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1233122ljw; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYBJIeaQYmhjnrZlKtk3Mlf9Zty/wvPzL9s78hwJrWJxfKS2pybgQS/D64y+mWgVkXW3Xn+ X-Received: by 2002:a17:902:bd44:: with SMTP id b4-v6mr25530251plx.144.1537395664306; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537395664; cv=none; d=google.com; s=arc-20160816; b=geQXBqvZZIAa7/ouP2m7HxFYt+QkxppDb7B61elzBKTHz3/ITZpH2Q7nMFgCp/iFFT 402ppIj9DEkfUp6zJAfindpunm5rnIFxIqs9avisc5yxchDx/xHHmbbn4l5TpjOcSQVu rC162IlfltWIcquVLigkA/QGqHLehYrW6Cs2Sna4VNgKaTdK82XhEOoBDgMPYENBSVqt YZzbvMMi3+yt51BGxcAzU6OTO5k/PeUIVfkLPPopq5pORv76NAL12Pg2MCD40Yo+GcRS dzPT0uUQG+WMYqz8Ta+AVt43ffNXzf57gmHV/W3K2Egj0o8V2mUOQrpcPaazJqz7HgYN FKNg== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=tcl1nmg48DaC9i1KrMB/XgkqbE0+pNwV9qx27U5jomUxc1D2dvScZ3RfmafC6UAyy8 8fK6hXCGGGEO7LUVWOeSyFPNNqkf1ScO4azNK4MCgJLNAqfSAa971pde8f4Wt3hWPeB9 QHcEMAmQMmbFcn7G8o5oThZ1IuO25L0Ch1mrRG0tDew/mC2qrt9xoGI1RXZjYYsgfUSu X2oC0Mfl/gXeX8m7E6nXUg4RdqXcs1XZn5hdLXdTYldlSI1eht3sR5E3iOcbBYt3gjpl 7/6SVU/i36Iyu7q5/WcmPNG0YvsQQ3CbEDL5jbWtcAADdLfdo61SORq4hMQ2NcUL+t4C FHYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hhjieuyC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 c125-v6si22234558pga.268.2018.09.19.15.21.04; Wed, 19 Sep 2018 15:21:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=hhjieuyC; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S2387546AbeITEBC (ORCPT + 10 others); Thu, 20 Sep 2018 00:01:02 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:38693 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387400AbeITEBC (ORCPT ); Thu, 20 Sep 2018 00:01:02 -0400 Received: by mail-pg1-f193.google.com with SMTP id t84-v6so3394264pgb.5 for ; Wed, 19 Sep 2018 15:21:01 -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 :in-reply-to:references; bh=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=hhjieuyCFF5O3dZJ7hBHeN+t4o6LV6wzvk0nAfJBO0tOBLRhitxoGt/uNlyTwgFAuj kiEIPcaxjMAEuTNiHupwpORBRBSIM7YeX/KHhHiOdiowaviDkLmFjis0/ewTbtRkZHdz B12lgvkMKp8upAfDAPVWxk8hzgd7wJ8l19sXg= 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:in-reply-to:references; bh=44j3swOjLZRMj7KYCCHURncUQcQCot+MmDdSGHfeDPA=; b=i6FPanH4fsscoFl3RcE0dFDbQt+DI9fpNA7Alv91huc49OTqIK02kIlBpo5C12cARd Fr4zRAhcLU9cE4ZDriZfdA49lOXF6hDAkzwU5yp5JM1Su/dsfRkUz6M9W+Y0diGdReLl LNb5EMXGsKSpHZpi3I+RHWjmTwVczidPzoAWhTiY6ouuFiagqzGmlNvx48qbWUggBIuf C5AEzqVFE5JhDS+7UBIwXbRsWd3nUvVy/O2GafaYGhmaIGH+sfn3ps2rhhI4SS7/945R Krgu6RmwuTWnLVY2/90ofxYsCDo0zvWLdtkl53TvfL++4kYT1aRcI7FQKDaKpQuc2mlS t8wg== X-Gm-Message-State: APzg51CQ7Wc/NSnZyacvPZJ+QcRjJ1mw/b4o0IPHS1kYLaS1F9DQq2za ESxzWa3u0KV0VWZW04Pmt1phLQ== X-Received: by 2002:a63:8648:: with SMTP id x69-v6mr32605489pgd.268.1537395661604; Wed, 19 Sep 2018 15:21:01 -0700 (PDT) Received: from localhost ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id h130-v6sm27647724pgc.88.2018.09.19.15.21.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 19 Sep 2018 15:21:00 -0700 (PDT) From: Viresh Kumar To: Viresh Kumar , Nishanth Menon , Stephen Boyd Cc: Viresh Kumar , Rafael Wysocki , linux-pm@vger.kernel.org, Vincent Guittot , Niklas Cassel , linux-kernel@vger.kernel.org Subject: [PATCH V2 12/12] OPP: Pass OPP table to _of_add_opp_table_v{1|2}() Date: Wed, 19 Sep 2018 15:20:31 -0700 Message-Id: <9ea47a1cc5f08797e6c854c234acbe269b98405a.1537394233.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@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. Tested-by: Niklas Cassel Signed-off-by: Viresh Kumar --- drivers/opp/of.c | 68 +++++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) -- 2.14.1 diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 1ddef52c27fd..a71ff3acca0f 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; }