On 06-12-19, 16:24, Saravana Kannan wrote: > 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 <saravanak@xxxxxxxxxx> > --- > drivers/opp/core.c | 301 +++++++++++++++++++++++++++++++++++------ > include/linux/pm_opp.h | 43 ++++++ > 2 files changed, 305 insertions(+), 39 deletions(-) > > diff --git a/drivers/opp/core.c b/drivers/opp/core.c > index c79bbfac7289..3ff33a08198e 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 peak bandwidth has to be returned for s/peak // > + * @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) Do you see this being NULL in practice ? If no, then we can make it mandatory for now ? > + *avg_bw = opp->avg_bw; > + > + return opp->peak_bw; > +} > +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 Hmm, I wasn't expecting this. So the interconnects will also have a suspend OPP ? > + * @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; > @@ -343,6 +394,40 @@ int dev_pm_opp_get_opp_count(struct device *dev) > } > EXPORT_SYMBOL_GPL(dev_pm_opp_get_opp_count); > I think we should add function header here instead of the helpers which get exact match for freq, bw or level. And then pass a enum value to it, which tells what we are looking to compare. After that rest of the routines will be just one liners, make them macros in header file itself. > +struct dev_pm_opp *dev_pm_opp_find_opp_exact(struct device *dev, > + struct dev_pm_opp *opp_key, > + bool available) -- viresh