Skip to content

Commit 7c97666

Browse files
committed
Merge branch 'pm-opp'
* pm-opp: PM / OPP: Return suspend_opp only if it is enabled PM / OPP: add dev_pm_opp_get_suspend_opp() helper
2 parents ae98207 + 1b2b90c commit 7c97666

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

drivers/base/power/opp.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,34 @@ unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
340340
}
341341
EXPORT_SYMBOL_GPL(dev_pm_opp_get_max_clock_latency);
342342

343+
/**
344+
* dev_pm_opp_get_suspend_opp() - Get suspend opp
345+
* @dev: device for which we do this operation
346+
*
347+
* Return: This function returns pointer to the suspend opp if it is
348+
* defined and available, otherwise it returns NULL.
349+
*
350+
* Locking: This function must be called under rcu_read_lock(). opp is a rcu
351+
* protected pointer. The reason for the same is that the opp pointer which is
352+
* returned will remain valid for use with opp_get_{voltage, freq} only while
353+
* under the locked area. The pointer returned must be used prior to unlocking
354+
* with rcu_read_unlock() to maintain the integrity of the pointer.
355+
*/
356+
struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev)
357+
{
358+
struct device_opp *dev_opp;
359+
360+
opp_rcu_lockdep_assert();
361+
362+
dev_opp = _find_device_opp(dev);
363+
if (IS_ERR(dev_opp) || !dev_opp->suspend_opp ||
364+
!dev_opp->suspend_opp->available)
365+
return NULL;
366+
367+
return dev_opp->suspend_opp;
368+
}
369+
EXPORT_SYMBOL_GPL(dev_pm_opp_get_suspend_opp);
370+
343371
/**
344372
* dev_pm_opp_get_opp_count() - Get number of opps available in the opp list
345373
* @dev: device for which we do this operation

include/linux/pm_opp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ bool dev_pm_opp_is_turbo(struct dev_pm_opp *opp);
3434

3535
int dev_pm_opp_get_opp_count(struct device *dev);
3636
unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev);
37+
struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev);
3738

3839
struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
3940
unsigned long freq,
@@ -80,6 +81,11 @@ static inline unsigned long dev_pm_opp_get_max_clock_latency(struct device *dev)
8081
return 0;
8182
}
8283

84+
static inline struct dev_pm_opp *dev_pm_opp_get_suspend_opp(struct device *dev)
85+
{
86+
return NULL;
87+
}
88+
8389
static inline struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
8490
unsigned long freq, bool available)
8591
{

0 commit comments

Comments
 (0)