Skip to content

Commit 6e41766

Browse files
committed
PM / Domain: Implement of_genpd_opp_to_performance_state()
This implements of_genpd_opp_to_performance_state() which can be used from the device drivers or the OPP core to find the performance state encoded in the "required-opps" property of a node. Normally this would be called only once for each OPP of the device for which the OPP table of the device is getting generated. Different platforms may encode the performance state differently using the OPP table (they may simply return value of opp-hz or opp-microvolt, or apply some algorithm on top of those values) and so a new callback ->opp_to_performance_state() is implemented to allow platform specific drivers to convert the power domain OPP to a performance state value. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Acked-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 6a0ae73 commit 6e41766

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

drivers/base/power/domain.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,54 @@ int of_genpd_parse_idle_states(struct device_node *dn,
24122412
}
24132413
EXPORT_SYMBOL_GPL(of_genpd_parse_idle_states);
24142414

2415+
/**
2416+
* of_genpd_opp_to_performance_state- Gets performance state of device's
2417+
* power domain corresponding to a DT node's "required-opps" property.
2418+
*
2419+
* @dev: Device for which the performance-state needs to be found.
2420+
* @opp_node: DT node where the "required-opps" property is present. This can be
2421+
* the device node itself (if it doesn't have an OPP table) or a node
2422+
* within the OPP table of a device (if device has an OPP table).
2423+
* @state: Pointer to return performance state.
2424+
*
2425+
* Returns performance state corresponding to the "required-opps" property of
2426+
* a DT node. This calls platform specific genpd->opp_to_performance_state()
2427+
* callback to translate power domain OPP to performance state.
2428+
*
2429+
* Returns performance state on success and 0 on failure.
2430+
*/
2431+
unsigned int of_genpd_opp_to_performance_state(struct device *dev,
2432+
struct device_node *opp_node)
2433+
{
2434+
struct generic_pm_domain *genpd;
2435+
struct dev_pm_opp *opp;
2436+
int state = 0;
2437+
2438+
genpd = dev_to_genpd(dev);
2439+
if (IS_ERR(genpd))
2440+
return 0;
2441+
2442+
if (unlikely(!genpd->set_performance_state))
2443+
return 0;
2444+
2445+
genpd_lock(genpd);
2446+
2447+
opp = of_dev_pm_opp_find_required_opp(&genpd->dev, opp_node);
2448+
if (IS_ERR(opp)) {
2449+
state = PTR_ERR(opp);
2450+
goto unlock;
2451+
}
2452+
2453+
state = genpd->opp_to_performance_state(genpd, opp);
2454+
dev_pm_opp_put(opp);
2455+
2456+
unlock:
2457+
genpd_unlock(genpd);
2458+
2459+
return state;
2460+
}
2461+
EXPORT_SYMBOL_GPL(of_genpd_opp_to_performance_state);
2462+
24152463
#endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
24162464

24172465

include/linux/pm_domain.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct genpd_power_state {
4747
};
4848

4949
struct genpd_lock_ops;
50+
struct dev_pm_opp;
5051

5152
struct generic_pm_domain {
5253
struct device dev;
@@ -68,6 +69,8 @@ struct generic_pm_domain {
6869
unsigned int performance_state; /* Aggregated max performance state */
6970
int (*power_off)(struct generic_pm_domain *domain);
7071
int (*power_on)(struct generic_pm_domain *domain);
72+
unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
73+
struct dev_pm_opp *opp);
7174
int (*set_performance_state)(struct generic_pm_domain *genpd,
7275
unsigned int state);
7376
struct gpd_dev_ops dev_ops;
@@ -244,6 +247,8 @@ extern int of_genpd_add_subdomain(struct of_phandle_args *parent,
244247
extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
245248
extern int of_genpd_parse_idle_states(struct device_node *dn,
246249
struct genpd_power_state **states, int *n);
250+
extern unsigned int of_genpd_opp_to_performance_state(struct device *dev,
251+
struct device_node *opp_node);
247252

248253
int genpd_dev_pm_attach(struct device *dev);
249254
#else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
@@ -279,6 +284,13 @@ static inline int of_genpd_parse_idle_states(struct device_node *dn,
279284
return -ENODEV;
280285
}
281286

287+
static inline unsigned int
288+
of_genpd_opp_to_performance_state(struct device *dev,
289+
struct device_node *opp_node)
290+
{
291+
return -ENODEV;
292+
}
293+
282294
static inline int genpd_dev_pm_attach(struct device *dev)
283295
{
284296
return -ENODEV;

0 commit comments

Comments
 (0)