Skip to content

Commit 6c591ee

Browse files
Saravana Kannanvireshk
authored andcommitted
OPP: Add helpers for reading the binding properties
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 <[email protected]> Signed-off-by: Georgi Djakov <[email protected]> Reviewed-by: Matthias Kaehlcke <[email protected]> Reviewed-by: Sibi Sankar <[email protected]> [ Viresh: Removed an unnecessary comment ] Signed-off-by: Viresh Kumar <[email protected]>
1 parent 45a4187 commit 6c591ee

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

drivers/opp/core.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,11 +1286,21 @@ static bool _opp_supported_by_regulators(struct dev_pm_opp *opp,
12861286
return true;
12871287
}
12881288

1289+
int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2)
1290+
{
1291+
if (opp1->rate != opp2->rate)
1292+
return opp1->rate < opp2->rate ? -1 : 1;
1293+
if (opp1->level != opp2->level)
1294+
return opp1->level < opp2->level ? -1 : 1;
1295+
return 0;
1296+
}
1297+
12891298
static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp,
12901299
struct opp_table *opp_table,
12911300
struct list_head **head)
12921301
{
12931302
struct dev_pm_opp *opp;
1303+
int opp_cmp;
12941304

12951305
/*
12961306
* Insert new OPP in order of increasing frequency and discard if
@@ -1301,12 +1311,13 @@ static int _opp_is_duplicate(struct device *dev, struct dev_pm_opp *new_opp,
13011311
* loop.
13021312
*/
13031313
list_for_each_entry(opp, &opp_table->opp_list, node) {
1304-
if (new_opp->rate > opp->rate) {
1314+
opp_cmp = _opp_compare_key(new_opp, opp);
1315+
if (opp_cmp > 0) {
13051316
*head = &opp->node;
13061317
continue;
13071318
}
13081319

1309-
if (new_opp->rate < opp->rate)
1320+
if (opp_cmp < 0)
13101321
return 0;
13111322

13121323
/* Duplicate OPPs */

drivers/opp/of.c

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,28 @@ void dev_pm_opp_of_remove_table(struct device *dev)
521521
}
522522
EXPORT_SYMBOL_GPL(dev_pm_opp_of_remove_table);
523523

524+
static int _read_opp_key(struct dev_pm_opp *new_opp, struct device_node *np,
525+
bool *rate_not_available)
526+
{
527+
u64 rate;
528+
int ret;
529+
530+
ret = of_property_read_u64(np, "opp-hz", &rate);
531+
if (!ret) {
532+
/*
533+
* Rate is defined as an unsigned long in clk API, and so
534+
* casting explicitly to its type. Must be fixed once rate is 64
535+
* bit guaranteed in clk API.
536+
*/
537+
new_opp->rate = (unsigned long)rate;
538+
}
539+
*rate_not_available = !!ret;
540+
541+
of_property_read_u32(np, "opp-level", &new_opp->level);
542+
543+
return ret;
544+
}
545+
524546
/**
525547
* _opp_add_static_v2() - Allocate static OPPs (As per 'v2' DT bindings)
526548
* @opp_table: OPP table
@@ -558,26 +580,12 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table,
558580
if (!new_opp)
559581
return ERR_PTR(-ENOMEM);
560582

561-
ret = of_property_read_u64(np, "opp-hz", &rate);
562-
if (ret < 0) {
563-
/* "opp-hz" is optional for devices like power domains. */
564-
if (!opp_table->is_genpd) {
565-
dev_err(dev, "%s: opp-hz not found\n", __func__);
566-
goto free_opp;
567-
}
568-
569-
rate_not_available = true;
570-
} else {
571-
/*
572-
* Rate is defined as an unsigned long in clk API, and so
573-
* casting explicitly to its type. Must be fixed once rate is 64
574-
* bit guaranteed in clk API.
575-
*/
576-
new_opp->rate = (unsigned long)rate;
583+
ret = _read_opp_key(new_opp, np, &rate_not_available);
584+
if (ret < 0 && !opp_table->is_genpd) {
585+
dev_err(dev, "%s: opp key field not found\n", __func__);
586+
goto free_opp;
577587
}
578588

579-
of_property_read_u32(np, "opp-level", &new_opp->level);
580-
581589
/* Check if the OPP supports hardware's hierarchy of versions or not */
582590
if (!_opp_is_supported(dev, opp_table, np)) {
583591
dev_dbg(dev, "OPP not supported by hardware: %llu\n", rate);

drivers/opp/opp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ struct opp_device *_add_opp_dev(const struct device *dev, struct opp_table *opp_
211211
void _dev_pm_opp_find_and_remove_table(struct device *dev);
212212
struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
213213
void _opp_free(struct dev_pm_opp *opp);
214+
int _opp_compare_key(struct dev_pm_opp *opp1, struct dev_pm_opp *opp2);
214215
int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table, bool rate_not_available);
215216
int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
216217
void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu);

0 commit comments

Comments
 (0)