Skip to content

Commit e3943f0

Browse files
storulfvireshk
authored andcommitted
OPP: Introduce an OF helper function to inform if required-opps is used
As being shown from a subsequent change to genpd, it's useful to understand if a device's OF node has an OPP-table described and whether it contains OPP nodes that makes use of the required-opps DT property. For this reason, let's introduce an OPP OF helper function called dev_pm_opp_of_has_required_opp(). Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 0d86522 commit e3943f0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

drivers/opp/of.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,38 @@ int of_get_required_opp_performance_state(struct device_node *np, int index)
14431443
}
14441444
EXPORT_SYMBOL_GPL(of_get_required_opp_performance_state);
14451445

1446+
/**
1447+
* dev_pm_opp_of_has_required_opp - Find out if a required-opps exists.
1448+
* @dev: The device to investigate.
1449+
*
1450+
* Returns true if the device's node has a "operating-points-v2" property and if
1451+
* the corresponding node for the opp-table describes opp nodes that uses the
1452+
* "required-opps" property.
1453+
*
1454+
* Return: True if a required-opps is present, else false.
1455+
*/
1456+
bool dev_pm_opp_of_has_required_opp(struct device *dev)
1457+
{
1458+
struct device_node *opp_np, *np;
1459+
int count;
1460+
1461+
opp_np = _opp_of_get_opp_desc_node(dev->of_node, 0);
1462+
if (!opp_np)
1463+
return false;
1464+
1465+
np = of_get_next_available_child(opp_np, NULL);
1466+
of_node_put(opp_np);
1467+
if (!np) {
1468+
dev_warn(dev, "Empty OPP table\n");
1469+
return false;
1470+
}
1471+
1472+
count = of_count_phandle_with_args(np, "required-opps", NULL);
1473+
of_node_put(np);
1474+
1475+
return count > 0;
1476+
}
1477+
14461478
/**
14471479
* dev_pm_opp_get_of_node() - Gets the DT node corresponding to an opp
14481480
* @opp: opp for which DT node has to be returned for

include/linux/pm_opp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ int dev_pm_opp_of_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpuma
474474
struct device_node *dev_pm_opp_of_get_opp_desc_node(struct device *dev);
475475
struct device_node *dev_pm_opp_get_of_node(struct dev_pm_opp *opp);
476476
int of_get_required_opp_performance_state(struct device_node *np, int index);
477+
bool dev_pm_opp_of_has_required_opp(struct device *dev);
477478
int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table);
478479
int dev_pm_opp_of_register_em(struct device *dev, struct cpumask *cpus);
479480
int dev_pm_opp_calc_power(struct device *dev, unsigned long *uW,
@@ -552,6 +553,11 @@ static inline int of_get_required_opp_performance_state(struct device_node *np,
552553
return -EOPNOTSUPP;
553554
}
554555

556+
static inline bool dev_pm_opp_of_has_required_opp(struct device *dev)
557+
{
558+
return false;
559+
}
560+
555561
static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_table *opp_table)
556562
{
557563
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)