Skip to content

Commit

Permalink
opp: Allow multiple opp_tables to be mapped to a single device
Browse files Browse the repository at this point in the history
Introduce _find_opp_table_indexed_unlocked to allow for multiple
distinct opp_tables to be linked to a single device.

Signed-off-by: Sibi Sankar <sibis@codeaurora.org>
  • Loading branch information
Sibi Sankar committed Jan 9, 2020
1 parent 992b111 commit e1635c6
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions drivers/opp/core.c
Expand Up @@ -46,26 +46,44 @@ static struct opp_device *_find_opp_dev(const struct device *dev,
return NULL;
}

static struct opp_table *_find_opp_table_unlocked(struct device *dev)
static struct opp_table *_find_opp_table_indexed_unlocked(struct device *dev, int index)
{
struct opp_table *opp_table;
struct device_node *np;
bool found;

np = _opp_of_get_opp_desc_node(dev->of_node, index);

list_for_each_entry(opp_table, &opp_tables, node) {
mutex_lock(&opp_table->lock);
found = !!_find_opp_dev(dev, opp_table);
mutex_unlock(&opp_table->lock);

if (found) {
_get_opp_table_kref(opp_table);

return opp_table;
if (!np) {
_get_opp_table_kref(opp_table);
return opp_table;
}

if (opp_table->np == np) {
of_node_put(np);
_get_opp_table_kref(opp_table);
return opp_table;
}
}
}

if (np)
of_node_put(np);

return ERR_PTR(-ENODEV);
}

static struct opp_table *_find_opp_table_unlocked(struct device *dev)
{
return _find_opp_table_indexed_unlocked(dev, 0);
}

/**
* _find_opp_table() - find opp_table struct using device pointer
* @dev: device pointer used to lookup OPP table
Expand Down Expand Up @@ -1238,7 +1256,7 @@ static struct opp_table *_opp_get_opp_table(struct device *dev, int index)
/* Hold our table modification lock here */
mutex_lock(&opp_table_lock);

opp_table = _find_opp_table_unlocked(dev);
opp_table = _find_opp_table_indexed_unlocked(dev, index);
if (!IS_ERR(opp_table))
goto unlock;

Expand Down

0 comments on commit e1635c6

Please sign in to comment.