Commit 5ed4cecd authored by Viresh Kumar's avatar Viresh Kumar

OPP: Pass OPP table to _of_add_opp_table_v{1|2}()

Both _of_add_opp_table_v1() and _of_add_opp_table_v2() contain similar
code to get the OPP table and their parent routine also parses the DT to
find the OPP table's node pointer. This can be simplified by getting the
OPP table in advance and then passing it as argument to these routines.
Tested-by: default avatarNiklas Cassel <niklas.cassel@linaro.org>
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 283d55e6
...@@ -399,18 +399,12 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev, ...@@ -399,18 +399,12 @@ static int _opp_add_static_v2(struct opp_table *opp_table, struct device *dev,
} }
/* Initializes OPP tables based on new bindings */ /* Initializes OPP tables based on new bindings */
static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, static int _of_add_opp_table_v2(struct device *dev, struct opp_table *opp_table)
int index)
{ {
struct device_node *np; struct device_node *np;
struct opp_table *opp_table;
int ret, count = 0, pstate_count = 0; int ret, count = 0, pstate_count = 0;
struct dev_pm_opp *opp; struct dev_pm_opp *opp;
opp_table = dev_pm_opp_get_opp_table_indexed(dev, index);
if (!opp_table)
return -ENOMEM;
/* OPP table is already initialized for the device */ /* OPP table is already initialized for the device */
if (opp_table->parsed_static_opps) { if (opp_table->parsed_static_opps) {
kref_get(&opp_table->list_kref); kref_get(&opp_table->list_kref);
...@@ -420,7 +414,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, ...@@ -420,7 +414,7 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np,
kref_init(&opp_table->list_kref); kref_init(&opp_table->list_kref);
/* We have opp-table node now, iterate over it and add OPPs */ /* We have opp-table node now, iterate over it and add OPPs */
for_each_available_child_of_node(opp_np, np) { for_each_available_child_of_node(opp_table->np, np) {
count++; count++;
ret = _opp_add_static_v2(opp_table, dev, np); ret = _opp_add_static_v2(opp_table, dev, np);
...@@ -458,15 +452,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np, ...@@ -458,15 +452,13 @@ static int _of_add_opp_table_v2(struct device *dev, struct device_node *opp_np,
put_list_kref: put_list_kref:
_put_opp_list_kref(opp_table); _put_opp_list_kref(opp_table);
dev_pm_opp_put_opp_table(opp_table);
return ret; return ret;
} }
/* Initializes OPP tables based on old-deprecated bindings */ /* Initializes OPP tables based on old-deprecated bindings */
static int _of_add_opp_table_v1(struct device *dev) static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
{ {
struct opp_table *opp_table;
const struct property *prop; const struct property *prop;
const __be32 *val; const __be32 *val;
int nr, ret = 0; int nr, ret = 0;
...@@ -487,10 +479,6 @@ static int _of_add_opp_table_v1(struct device *dev) ...@@ -487,10 +479,6 @@ static int _of_add_opp_table_v1(struct device *dev)
return -EINVAL; return -EINVAL;
} }
opp_table = dev_pm_opp_get_opp_table(dev);
if (!opp_table)
return -ENOMEM;
kref_init(&opp_table->list_kref); kref_init(&opp_table->list_kref);
val = prop->value; val = prop->value;
...@@ -503,7 +491,6 @@ static int _of_add_opp_table_v1(struct device *dev) ...@@ -503,7 +491,6 @@ static int _of_add_opp_table_v1(struct device *dev)
dev_err(dev, "%s: Failed to add OPP %ld (%d)\n", dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
__func__, freq, ret); __func__, freq, ret);
_put_opp_list_kref(opp_table); _put_opp_list_kref(opp_table);
dev_pm_opp_put_opp_table(opp_table);
return ret; return ret;
} }
nr -= 2; nr -= 2;
...@@ -531,24 +518,24 @@ static int _of_add_opp_table_v1(struct device *dev) ...@@ -531,24 +518,24 @@ static int _of_add_opp_table_v1(struct device *dev)
*/ */
int dev_pm_opp_of_add_table(struct device *dev) int dev_pm_opp_of_add_table(struct device *dev)
{ {
struct device_node *opp_np; struct opp_table *opp_table;
int ret; int ret;
opp_table = dev_pm_opp_get_opp_table_indexed(dev, 0);
if (!opp_table)
return -ENOMEM;
/* /*
* OPPs have two version of bindings now. The older one is deprecated, * OPPs have two version of bindings now. Also try the old (v1)
* try for the new binding first. * bindings for backward compatibility with older dtbs.
*/
opp_np = dev_pm_opp_of_get_opp_desc_node(dev);
if (!opp_np) {
/*
* Try old-deprecated bindings for backward compatibility with
* older dtbs.
*/ */
return _of_add_opp_table_v1(dev); if (opp_table->np)
} ret = _of_add_opp_table_v2(dev, opp_table);
else
ret = _of_add_opp_table_v1(dev, opp_table);
ret = _of_add_opp_table_v2(dev, opp_np, 0); if (ret)
of_node_put(opp_np); dev_pm_opp_put_opp_table(opp_table);
return ret; return ret;
} }
...@@ -575,28 +562,29 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table); ...@@ -575,28 +562,29 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_of_add_table);
*/ */
int dev_pm_opp_of_add_table_indexed(struct device *dev, int index) int dev_pm_opp_of_add_table_indexed(struct device *dev, int index)
{ {
struct device_node *opp_np; struct opp_table *opp_table;
int ret, count; int ret, count;
again: if (index) {
opp_np = _opp_of_get_opp_desc_node(dev->of_node, index);
if (!opp_np) {
/* /*
* If only one phandle is present, then the same OPP table * If only one phandle is present, then the same OPP table
* applies for all index requests. * applies for all index requests.
*/ */
count = of_count_phandle_with_args(dev->of_node, count = of_count_phandle_with_args(dev->of_node,
"operating-points-v2", NULL); "operating-points-v2", NULL);
if (count == 1 && index) { if (count != 1)
return -ENODEV;
index = 0; index = 0;
goto again;
} }
return -ENODEV; opp_table = dev_pm_opp_get_opp_table_indexed(dev, index);
} if (!opp_table)
return -ENOMEM;
ret = _of_add_opp_table_v2(dev, opp_np, index); ret = _of_add_opp_table_v2(dev, opp_table);
of_node_put(opp_np); if (ret)
dev_pm_opp_put_opp_table(opp_table);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment