Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp765504ybz; Fri, 24 Apr 2020 08:56:10 -0700 (PDT) X-Google-Smtp-Source: APiQypLrCfkqiGOvOhBJGUWUjBpgjHs4/sMFhSxqSegjTeiD0caYVAa73T+Xaj3MY6UYSeNU71Li X-Received: by 2002:a17:906:32d8:: with SMTP id k24mr7999409ejk.2.1587743769746; Fri, 24 Apr 2020 08:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587743769; cv=none; d=google.com; s=arc-20160816; b=uVPlDrySQDbpcd92FiUgZyL67rMTn7RyKtxZL8YnrCYgSNAjc2cITdHkVm8IbksxEf yGWtEfN1cu6tsoJRnlt9ie1Dy/ree6SnARjSsr0hTPdTws2AipjVdh91YivojAKdXZ14 rjQppl5vWXZ6k5prKZAJfgzrMxONoYWj0AnShrTyDS4rR2/4Ax/6bK4q3BTmjbdnUILs U9lk8/7vmXEBsITtr/VbPNJfcO7ucQ1cWzv82vCCYw0lYRkeaOhYnBZvGOpSClDxMYxP 7BjTrs6BUhzEJjr3qemoLNrEajLyAYDOK9jatx0sDkEeIe7q7Fc7rAdKutduIwj8XO9J 8i3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rAju4fK7CHysmmIehKnpso2uJ6HDzME/JcC5AUO00iw=; b=nn6GR3UQ2sxoNJTQi06jzaMJb6iHIumu0z+c0oQ9EsE8FX5WqsU3NR+E9+nEv7ukbk LjHcFsS7PNdmRg7IjJ2XBWyEQSKXoFm50GvIjFt1G8G1r1xq71E4hOUvdrvhFYvt5Ma5 KDTU268ZoTmliHZ0xQRF6/mAoLgdTs3MZX/Bqp+r/vs4e0pYJH9i+EhfC9gfaevyZO/p fcihQwtJrQNO9KyOw85sR7EpZsNU21doZWPCkil8tIi7thcwzs86Xgj67Jw11uNja7Fu 2a+m+MPDG9s3+7yP5nw6pVfjNFPnokuxKyGwU6owL+MgWf8SxtHHxtSQL3ddB/eHxuTQ /ZcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zdAYSeJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id e8si3149180ejr.462.2020.04.24.08.55.46; Fri, 24 Apr 2020 08:56:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zdAYSeJU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728343AbgDXPyM (ORCPT + 99 others); Fri, 24 Apr 2020 11:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728233AbgDXPyL (ORCPT ); Fri, 24 Apr 2020 11:54:11 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A5C3C09B047 for ; Fri, 24 Apr 2020 08:54:10 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id i10so11458041wrv.10 for ; Fri, 24 Apr 2020 08:54:10 -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 :mime-version:content-transfer-encoding; bh=rAju4fK7CHysmmIehKnpso2uJ6HDzME/JcC5AUO00iw=; b=zdAYSeJUnlrn0u/CWL9bvvfbAzIdMiuDYYWEjaIXpg0UVkwGnTZkhLfX6mFLI0dtQ+ VZaOb8QgCMqjaiwqSDjdzFo+p2wDecCG0QhbJJmF4dLdmXcWODABwDUOgsBr1cw+e4n5 EPFaLHEZE4Df1w4lfx+RpyGIfJwqrQIGZl+Cis1xmYwCPqAEz2+Q3i5pSE7HTjmxjpkG 3bMnlK4ef0NtEUdV4HM/gQqhPmHMYwWeF7lXsiXYJZg8an+/r30H3vUrThk/shse2zvs OoWSFjivoCfmByw59njCQUamGSAGJvijh8iiWHG6YUsXvgaovXxTHNlSOd/xrG7Z8Llv ptzA== 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:mime-version:content-transfer-encoding; bh=rAju4fK7CHysmmIehKnpso2uJ6HDzME/JcC5AUO00iw=; b=uR4RJcdIpv9ALV2AVV3egQbCTtlrZw1gFrOYL/b/7wXGmg/4zY2WlcryRXTeXigP2M 1ioV46tNzTtfP3vK0iWaac09ekr3P3/FJ96EsriNUyIemPm7zMAHF8CWfjFf2E7Y6mu6 haxBIDCimn6PgkPcLL4ojtFmH3BLrpjztzSlgfALOCxfNajFX+TSMT8hGx5Bxcl4LOt1 lx6L3GWZyf4dmiuefg/SzEZlrVMIM0Z601EMHp4vgzq2iHcRF32txrJcvpNxOnCOCfAV 0s6mPVP/6AwV2lsO/sXKie2KX+PtSQkGczrwaWh+hrU9cjFLdpqvf6ouU7KL0HM9fG2H o3nw== X-Gm-Message-State: AGi0PuaWHqLNteygm+BI3WFEOoJrKvBJvlzXxqAR27f4LPjadhd9xs8Y ulFD4SLJMbtBK/+pnPOobCejfA== X-Received: by 2002:adf:db41:: with SMTP id f1mr11264741wrj.13.1587743649305; Fri, 24 Apr 2020 08:54:09 -0700 (PDT) Received: from localhost.localdomain ([87.120.218.65]) by smtp.googlemail.com with ESMTPSA id z76sm3923583wmc.9.2020.04.24.08.54.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 08:54:08 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, robh+dt@kernel.org, rjw@rjwysocki.net, saravanak@google.com, sibis@codeaurora.org Cc: rnayak@codeaurora.org, bjorn.andersson@linaro.org, vincent.guittot@linaro.org, jcrouse@codeaurora.org, evgreen@chromium.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v7 2/7] OPP: Add helpers for reading the binding properties Date: Fri, 24 Apr 2020 18:53:59 +0300 Message-Id: <20200424155404.10746-3-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424155404.10746-1-georgi.djakov@linaro.org> References: <20200424155404.10746-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Saravana Kannan The opp-hz DT property is not mandatory and we may use another property as a key in the OPP table. Add helper functions to simplify the reading and comparing the keys. Signed-off-by: Saravana Kannan Signed-off-by: Georgi Djakov --- v7: * Extracted just the helpers from patch v6, as Viresh advised to split it. v6: https://lore.kernel.org/r/20191207002424.201796-3-saravanak@google.com drivers/opp/core.c | 15 +++++++++++++-- drivers/opp/of.c | 42 ++++++++++++++++++++++++++---------------- drivers/opp/opp.h | 1 + 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index ba43e6a3dc0a..c9c1bbe6ae27 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -1272,11 +1272,21 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp, return true; } +int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2) +{ + if (opp1->rate != opp2->rate) + return opp1->rate < opp2->rate ? -1 : 1; + if (opp1->level != opp2->level) + return opp1->level < opp2->level ? -1 : 1; + return 0; +} + static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, struct list_head **head) { struct dev_pm_opp *opp; + int opp_cmp; /* * Insert new OPP in order of increasing frequency and discard if @@ -1287,12 +1297,13 @@ static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp, * loop. */ list_for_each_entry(opp, &opp_table->opp_list, node) { - if (new_opp->rate > opp->rate) { + opp_cmp = _opp_compare_key(new_opp, opp); + if (opp_cmp > 0) { *head = &opp->node; continue; } - if (new_opp->rate < opp->rate) + if (opp_cmp < 0) return 0; /* Duplicate OPPs */ diff --git a/drivers/opp/of.c b/drivers/opp/of.c index 9cd8f0adacae..e33169c7e045 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -521,6 +521,28 @@ void dev_pm_opp_of_remove_table(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table); +static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np, + bool *rate_not_available) +{ + u64 rate; + int ret; + + ret = of_property_read_u64(np, "opp-hz", &rate); + if (!ret) { + /* + * Rate is defined as an unsigned long in clk API, and so + * casting explicitly to its type. Must be fixed once rate is 64 + * bit guaranteed in clk API. + */ + new_opp->rate = (unsigned long)rate; + } + *rate_not_available = !!ret; + + of_property_read_u32(np, "opp-level", &new_opp->level); + + return ret; +} + /** * _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings) * @opp_table: OPP table @@ -558,26 +580,14 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, if (!new_opp) return ERR_PTR(-ENOMEM); - ret = of_property_read_u64(np, "opp-hz", &rate); + ret = _read_opp_key(new_opp, np, &rate_not_available); if (ret < 0) { - /* "opp-hz" is optional for devices like power domains. */ - if (!opp_table->is_genpd) { - dev_err(dev, "%s: opp-hz not found\n", __func__); - goto free_opp; - } + if (!opp_table->is_genpd) + dev_err(dev, "%s: opp key field not found\n", __func__); - rate_not_available = true; - } else { - /* - * Rate is defined as an unsigned long in clk API, and so - * casting explicitly to its type. Must be fixed once rate is 64 - * bit guaranteed in clk API. - */ - new_opp->rate = (unsigned long)rate; + goto free_opp; } - of_property_read_u32(np, "opp-level", &new_opp->level); - /* Check if the OPP supports hardware's hierarchy of versions or not */ if (!_opp_is_supported(dev, opp_table, np)) { dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate); diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index d14e27102730..bcadb1e328a4 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -211,6 +211,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_ void _dev_pm_opp_find_and_remove_table(struct device *dev); struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table); void _opp_free(struct dev_pm_opp *opp); +int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2); int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available); int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic); void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu);