]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
opp: core: implement dev_pm_opp_get_bw
authorNeil Armstrong <neil.armstrong@linaro.org>
Tue, 19 Nov 2024 17:56:36 +0000 (18:56 +0100)
committerViresh Kumar <viresh.kumar@linaro.org>
Mon, 23 Dec 2024 10:57:22 +0000 (16:27 +0530)
Add and implement dev_pm_opp_get_bw() to retrieve the OPP's
bandwidth in the same way as the dev_pm_opp_get_voltage() helper.

Retrieving bandwidth is required in the case of the Adreno GPU
where the GPU Management Unit can handle the Bandwidth scaling.

The helper can get the peak or average bandwidth for any of
the interconnect path.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
[ Viresh: Fixed commit log and a comment in code ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/opp/core.c
include/linux/pm_opp.h

index 0311b18319a458c6201a2aa54a8abf99e8c76aed..d4a0030a0228d6282d672e3ffe3aeea27e80822a 100644 (file)
@@ -106,6 +106,31 @@ static bool assert_single_clk(struct opp_table *opp_table)
        return !WARN_ON(opp_table->clk_count > 1);
 }
 
+/**
+ * dev_pm_opp_get_bw() - Gets the bandwidth corresponding to an opp
+ * @opp:       opp for which bandwidth has to be returned for
+ * @peak:      select peak or average bandwidth
+ * @index:     bandwidth index
+ *
+ * Return: bandwidth in kBps, else return 0
+ */
+unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
+{
+       if (IS_ERR_OR_NULL(opp)) {
+               pr_err("%s: Invalid parameters\n", __func__);
+               return 0;
+       }
+
+       if (index > opp->opp_table->path_count)
+               return 0;
+
+       if (!opp->bandwidth)
+               return 0;
+
+       return peak ? opp->bandwidth[index].peak : opp->bandwidth[index].avg;
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_get_bw);
+
 /**
  * dev_pm_opp_get_voltage() - Gets the voltage corresponding to an opp
  * @opp:       opp for which voltage has to be returned for
index 568183e3e641c35d1d4412979197349f38c74cc0..414146abfe81662dee4ae882de31edeb2b62b382 100644 (file)
@@ -102,6 +102,8 @@ struct dev_pm_opp_data {
 struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
 void dev_pm_opp_put_opp_table(struct opp_table *opp_table);
 
+unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index);
+
 unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp);
 
 int dev_pm_opp_get_supplies(struct dev_pm_opp *opp, struct dev_pm_opp_supply *supplies);
@@ -205,6 +207,11 @@ static inline struct opp_table *dev_pm_opp_get_opp_table_indexed(struct device *
 
 static inline void dev_pm_opp_put_opp_table(struct opp_table *opp_table) {}
 
+static inline unsigned long dev_pm_opp_get_bw(struct dev_pm_opp *opp, bool peak, int index)
+{
+       return 0;
+}
+
 static inline unsigned long dev_pm_opp_get_voltage(struct dev_pm_opp *opp)
 {
        return 0;