Skip to content

Commit 142e17c

Browse files
Mani-Sadhasivamvireshk
authored andcommitted
OPP: Introduce dev_pm_opp_find_freq_{ceil/floor}_indexed() APIs
In the case of devices with multiple clocks, drivers need to specify the clock index for the OPP framework to find the OPP corresponding to the floor/ceil of the supplied frequency. So let's introduce the two new APIs accepting the clock index as an argument. These APIs use the exising _find_key_ceil() helper by supplying the clock index to it. Signed-off-by: Manivannan Sadhasivam <[email protected]> [ Viresh: Rearranged definitions in pm_opp.h ] Signed-off-by: Viresh Kumar <[email protected]>
1 parent 754833b commit 142e17c

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

drivers/opp/core.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
658658
}
659659
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil);
660660

661+
/**
662+
* dev_pm_opp_find_freq_ceil_indexed() - Search for a rounded ceil freq for the
663+
* clock corresponding to the index
664+
* @dev: Device for which we do this operation
665+
* @freq: Start frequency
666+
* @index: Clock index
667+
*
668+
* Search for the matching ceil *available* OPP for the clock corresponding to
669+
* the specified index from a starting freq for a device.
670+
*
671+
* Return: matching *opp and refreshes *freq accordingly, else returns
672+
* ERR_PTR in case of error and should be handled using IS_ERR. Error return
673+
* values can be:
674+
* EINVAL: for bad pointer
675+
* ERANGE: no match found for search
676+
* ENODEV: if device not found in list of registered devices
677+
*
678+
* The callers are required to call dev_pm_opp_put() for the returned OPP after
679+
* use.
680+
*/
681+
struct dev_pm_opp *
682+
dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq,
683+
u32 index)
684+
{
685+
return _find_key_ceil(dev, freq, index, true, _read_freq, NULL);
686+
}
687+
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_ceil_indexed);
688+
661689
/**
662690
* dev_pm_opp_find_freq_floor() - Search for a rounded floor freq
663691
* @dev: device for which we do this operation
@@ -683,6 +711,34 @@ struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
683711
}
684712
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor);
685713

714+
/**
715+
* dev_pm_opp_find_freq_floor_indexed() - Search for a rounded floor freq for the
716+
* clock corresponding to the index
717+
* @dev: Device for which we do this operation
718+
* @freq: Start frequency
719+
* @index: Clock index
720+
*
721+
* Search for the matching floor *available* OPP for the clock corresponding to
722+
* the specified index from a starting freq for a device.
723+
*
724+
* Return: matching *opp and refreshes *freq accordingly, else returns
725+
* ERR_PTR in case of error and should be handled using IS_ERR. Error return
726+
* values can be:
727+
* EINVAL: for bad pointer
728+
* ERANGE: no match found for search
729+
* ENODEV: if device not found in list of registered devices
730+
*
731+
* The callers are required to call dev_pm_opp_put() for the returned OPP after
732+
* use.
733+
*/
734+
struct dev_pm_opp *
735+
dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq,
736+
u32 index)
737+
{
738+
return _find_key_floor(dev, freq, index, true, _read_freq, NULL);
739+
}
740+
EXPORT_SYMBOL_GPL(dev_pm_opp_find_freq_floor_indexed);
741+
686742
/**
687743
* dev_pm_opp_find_level_exact() - search for an exact level
688744
* @dev: device for which we do this operation

include/linux/pm_opp.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ struct dev_pm_opp *dev_pm_opp_find_freq_exact(struct device *dev,
125125
struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
126126
unsigned long *freq);
127127

128+
struct dev_pm_opp *dev_pm_opp_find_freq_floor_indexed(struct device *dev,
129+
unsigned long *freq, u32 index);
130+
128131
struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
129132
unsigned long *freq);
130133

134+
struct dev_pm_opp *dev_pm_opp_find_freq_ceil_indexed(struct device *dev,
135+
unsigned long *freq, u32 index);
136+
131137
struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
132138
unsigned int level);
133139

@@ -261,12 +267,24 @@ static inline struct dev_pm_opp *dev_pm_opp_find_freq_floor(struct device *dev,
261267
return ERR_PTR(-EOPNOTSUPP);
262268
}
263269

270+
static inline struct dev_pm_opp *
271+
dev_pm_opp_find_freq_floor_indexed(struct device *dev, unsigned long *freq, u32 index)
272+
{
273+
return ERR_PTR(-EOPNOTSUPP);
274+
}
275+
264276
static inline struct dev_pm_opp *dev_pm_opp_find_freq_ceil(struct device *dev,
265277
unsigned long *freq)
266278
{
267279
return ERR_PTR(-EOPNOTSUPP);
268280
}
269281

282+
static inline struct dev_pm_opp *
283+
dev_pm_opp_find_freq_ceil_indexed(struct device *dev, unsigned long *freq, u32 index)
284+
{
285+
return ERR_PTR(-EOPNOTSUPP);
286+
}
287+
270288
static inline struct dev_pm_opp *dev_pm_opp_find_level_exact(struct device *dev,
271289
unsigned int level)
272290
{

0 commit comments

Comments
 (0)