Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp6011208ybh; Wed, 7 Aug 2019 15:33:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBeB1DifadJvnB1jgFWMCVmzdmz7thX8mcm84ys7PO33xAylWenAbyGzJDds3Pfb4z0EFx X-Received: by 2002:a17:902:8d92:: with SMTP id v18mr10535374plo.211.1565217236108; Wed, 07 Aug 2019 15:33:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565217236; cv=none; d=google.com; s=arc-20160816; b=oaRgGfh3zT1bAb3d/eb+2ZnYYGVFqjc7go4q+HPH9Y56AntTDHGs+mzGUnwuMD51DB HeaU4ruBT3lW3L2hpkggszks1g6SiQ3my/SAvvNroFxQ7+TTg3pq/+S4+ymW5NtWwDbR OU70sfWXCh/qF/bmCq2K63eNT6dKJQvgKZa68MlMeNYrroVwen9a/W6y+BXuqH72m70m L9VsFUCUN9uALmUDQYN5Kj/ALv6yAnLPAlvLdKltMnAouelG13IBrswgRX61u2zxAiQV RktQbgkDMIkfyJGPjEf2Za5DkaDL6SgGC+nngVcnMylkMyWD5Y7b2t8y5e9WFjMMKiOM OuTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=DWjpwGhlXJQyl9FQAlOupUp/l9PizFz1wErEWTwJlag=; b=Ahy7L1pn4GmIG59htGTZAezFlqgVZ3OMwzzEryLVM0zejABT/8ppAmFEpNQCDFHDzT oh9do2UVmCfmFnuqk95FNbz6CDjz3Jey1RwBEZOiwXhyQW81D1ArEG5woxoCzEew/OCH 8r7zuyLkMmkJjN+sgiD+n4TeIf+CSF03SRDzP1YxMl/zICF1ozFaBRhlBYzhaB/IcaaB 12ve8LNUfAhrCXOFm3V+M0O2Bk3PeG7BHCxtsfPU2P469BlfFMoFShSSaMM/4n9d56qB AW+BgspSiy164YNRZHDjmYdBTqpuUUlG7ANA09hSUyb6YsLlEc0mtSrqGPKvDwas1/e1 mAJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=hcqK1rm2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si52780179pfo.266.2019.08.07.15.33.40; Wed, 07 Aug 2019 15:33:56 -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=@google.com header.s=20161025 header.b=hcqK1rm2; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389571AbfHGWb0 (ORCPT + 99 others); Wed, 7 Aug 2019 18:31:26 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:56593 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389542AbfHGWb0 (ORCPT ); Wed, 7 Aug 2019 18:31:26 -0400 Received: by mail-pg1-f201.google.com with SMTP id h5so56454260pgq.23 for ; Wed, 07 Aug 2019 15:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=DWjpwGhlXJQyl9FQAlOupUp/l9PizFz1wErEWTwJlag=; b=hcqK1rm2Kc81+PcpjarLbrP8P4J7ecqPay/pLa2ERjLIRU6yaHy83GRzwH5twgmz77 p6ZlJr/qRukqde30IsHj5KuzdQD1+nQbX6inahTdo+X9XUkKQKQAxeRMNTPIh4uf+PKe qGbHD86j7Qx3tpSx8Z/YKJ18+uSJXxnSMqkRxH41MDNar18DnUwL7cKQ6ANn7wa/rwPj c0l7uSoYS6zqTeEr/4qNtDEOtZX1eVO/p6LpbU9jkd+99x2d5iwz4Uwj9RJWdBNSZ/LU 0a4XqqsHxy0B4SUTTVPu/R3tdbcI+WpwFbgGAskVzLsXhIYf2naq9yFuR5HNsF4448om Z37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=DWjpwGhlXJQyl9FQAlOupUp/l9PizFz1wErEWTwJlag=; b=J4IYMDfwmG3mINKMGjeejUpwRmSnCmRs9fVck6L1WfeSz8q8bGvr3P0O3uOUFEb70z xH0mxbB4E8WGQXPxFzIOud/Z/j8eyNfDfR6DudRb4gEH+SUbdcRWuus++cXTmHkLxDr3 2YNLot+YzMwNdZsaE61+65HUImeT7MqpcNKWj/eIEpB+DYaALck+U9FMazA1MMLlMjA+ g8oDB1hIyUa2WfUMnt/OoIe79e7mMI2E95f4+8XQFfivsSp2NbCd46aXDXC6V7UDH0Pi XY/Npx1SzIz7EDsCM6s9uJUEltG99qcoFmT25N1wNu/anfhWFf+wagSE6/hHcbx3owln HROA== X-Gm-Message-State: APjAAAV9obwZ9ntQAYdE8kK52LSWcCDucayTAMejD82pZP0RVm+nbR5S v1mxlyDiIt9zKhbCBMWjvt4cBkiv5wSiM2E= X-Received: by 2002:a63:b102:: with SMTP id r2mr9553166pgf.370.1565217084491; Wed, 07 Aug 2019 15:31:24 -0700 (PDT) Date: Wed, 7 Aug 2019 15:31:11 -0700 In-Reply-To: <20190807223111.230846-1-saravanak@google.com> Message-Id: <20190807223111.230846-4-saravanak@google.com> Mime-Version: 1.0 References: <20190807223111.230846-1-saravanak@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH v5 3/3] OPP: Add helper function for bandwidth OPP tables From: Saravana Kannan To: Rob Herring , Mark Rutland , Viresh Kumar , Nishanth Menon , Stephen Boyd , "Rafael J. Wysocki" Cc: Saravana Kannan , Georgi Djakov , vincent.guittot@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, adharmap@codeaurora.org, Rajendra Nayak , sibis@codeaurora.org, bjorn.andersson@linaro.org, evgreen@chromium.org, kernel-team@android.com, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The frequency OPP tables have helper functions to search for entries in the table based on frequency and get the frequency values for a given (or suspend) OPP entry. Add similar helper functions for bandwidth OPP tables to search for entries in the table based on peak bandwidth and to get the peak and average bandwidth for a given (or suspend) OPP entry. Signed-off-by: Saravana Kannan --- drivers/opp/core.c | 51 ++++++++++++++++++++++++++++++++++++++++++ include/linux/pm_opp.h | 19 ++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 3b7ffd0234e9..22dcf22f908f 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -127,6 +127,29 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq); +/** + * dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an available opp + * @opp: opp for which frequency has to be returned for + * @avg_bw: Pointer where the corresponding average bandwidth is stored. + * Can be NULL. + * + * Return: Peak bandwidth in kBps corresponding to the opp, else + * return 0 + */ +unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, unsigned long *avg_bw) +{ + if (IS_ERR_OR_NULL(opp) || !opp->available) { + pr_err("%s: Invalid parameters\n", __func__); + return 0; + } + + if (avg_bw) + *avg_bw = opp->avg_bw; + + return opp->rate; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_bw); + /** * dev_pm_opp_get_level() - Gets the level corresponding to an available opp * @opp: opp for which level value has to be returned for @@ -299,6 +322,34 @@ unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) } EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_freq); +/** + * dev_pm_opp_get_suspend_opp_bw() - Get peak bandwidth of suspend opp in kBps + * @dev: device for which we do this operation + * @avg_bw: Pointer where the corresponding average bandwidth is stored. + * Can be NULL. + * + * Return: This function returns the peak bandwidth of the OPP marked as + * suspend_opp if one is available, else returns 0; + */ +unsigned long dev_pm_opp_get_suspend_opp_bw(struct device *dev, + unsigned long *avg_bw) +{ + struct opp_table *opp_table; + unsigned long peak_bw = 0; + + opp_table = _find_opp_table(dev); + if (IS_ERR(opp_table)) + return 0; + + if (opp_table->suspend_opp && opp_table->suspend_opp->available) + peak_bw = dev_pm_opp_get_bw(opp_table->suspend_opp, avg_bw); + + dev_pm_opp_put_opp_table(opp_table); + + return peak_bw; +} +EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp_bw); + int _get_opp_count(struct opp_table *opp_table) { struct dev_pm_opp *opp; diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index b8197ab014f2..f4e900f36414 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -82,6 +82,7 @@ void dev_pm_opp_put_opp_table(struct opp_table *opp_table); unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp); unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp); +unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, unsigned long *avg_bw); unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp); @@ -92,6 +93,8 @@ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev); unsigned long dev_pm_opp_get_max_volt_latency(struct device *dev); unsigned long dev_pm_opp_get_max_transition_latency(struct device *dev); unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev); +unsigned long dev_pm_opp_get_suspend_opp_bw(struct device *dev, + unsigned long *avg_bw); struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, @@ -160,6 +163,11 @@ static inline unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp) { return 0; } +static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, + unsigned long *avg_bw) +{ + return 0; +} static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp) { @@ -196,6 +204,12 @@ static inline unsigned long dev_pm_opp_get_suspend_opp_freq(struct device *dev) return 0; } +static inline unsigned long dev_pm_opp_get_suspend_opp_bw(struct device *dev, + unsigned long *avg_bw) +{ + return 0; +} + static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev, unsigned long freq, bool available) { @@ -337,6 +351,11 @@ static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask #endif /* CONFIG_PM_OPP */ +#define dev_pm_opp_find_peak_bw_exact dev_pm_opp_find_freq_exact +#define dev_pm_opp_find_peak_bw_floor dev_pm_opp_find_freq_floor +#define dev_pm_opp_find_peak_bw_ceil_by_volt dev_pm_opp_find_freq_ceil_by_volt +#define dev_pm_opp_find_peak_bw_ceil dev_pm_opp_find_freq_ceil + #if defined(CONFIG_PM_OPP) && defined(CONFIG_OF) int dev_pm_opp_of_add_table(struct device *dev); int dev_pm_opp_of_add_table_indexed(struct device *dev, int index); -- 2.23.0.rc1.153.gdeed80330f-goog