OPP: Introduce dev_pm_opp_get_freq_indexed() API
authorManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Thu, 20 Jul 2023 05:40:53 +0000 (11:10 +0530)
committerViresh Kumar <viresh.kumar@linaro.org>
Mon, 24 Jul 2023 07:52:39 +0000 (13:22 +0530)
In the case of devices with multiple clocks, drivers need to specify the
frequency index for the OPP framework to get the specific frequency within
the required OPP. So let's introduce the dev_pm_opp_get_freq_indexed() API
accepting the frequency index as an argument.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
[ Viresh: Fixed potential access to NULL opp pointer ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
drivers/opp/core.c
include/linux/pm_opp.h

index cb4f47b341f958cebd33b9d5c5042c1a202a6e21..07341050d57f6678b7f3ee5a15dcf85625e1d3a1 100644 (file)
@@ -197,6 +197,26 @@ unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp)
 }
 EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq);
 
+/**
+ * dev_pm_opp_get_freq_indexed() - Gets the frequency corresponding to an
+ *                                available opp with specified index
+ * @opp: opp for which frequency has to be returned for
+ * @index: index of the frequency within the required opp
+ *
+ * Return: frequency in hertz corresponding to the opp with specified index,
+ * else return 0
+ */
+unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index)
+{
+       if (IS_ERR_OR_NULL(opp) || index >= opp->opp_table->clk_count) {
+               pr_err("%s: Invalid parameters\n", __func__);
+               return 0;
+       }
+
+       return opp->rates[index];
+}
+EXPORT_SYMBOL_GPL(dev_pm_opp_get_freq_indexed);
+
 /**
  * dev_pm_opp_get_level() - Gets the level corresponding to an available opp
  * @opp:       opp for which level value has to be returned for
index 2617f2c51f29da41e693ecdc44b9e7254a6b8ce3..a13a1705df57b5079445895690b05cfea526ad3b 100644 (file)
@@ -105,6 +105,8 @@ unsigned long dev_pm_opp_get_power(struct dev_pm_opp *opp);
 
 unsigned long dev_pm_opp_get_freq(struct dev_pm_opp *opp);
 
+unsigned long dev_pm_opp_get_freq_indexed(struct dev_pm_opp *opp, u32 index);
+
 unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp);
 
 unsigned int dev_pm_opp_get_required_pstate(struct dev_pm_opp *opp,
@@ -213,6 +215,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_freq_indexed(struct dev_pm_opp *opp, u32 index)
+{
+       return 0;
+}
+
 static inline unsigned int dev_pm_opp_get_level(struct dev_pm_opp *opp)
 {
        return 0;