Skip to content

Commit 7b38b7b

Browse files
cdleonardchanwoochoi
authored andcommitted
PM / devfreq: Add devfreq_get_devfreq_by_node function
Split off part of devfreq_get_devfreq_by_phandle into a separate function. This allows callers to fetch devfreq instances by enumerating devicetree instead of explicit phandles. Acked-by: Krzysztof Kozlowski <krzk@kernel.org> Reviewed-by: Lukasz Luba <lukasz.luba@arm.com> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com> [cw00.choi: Export devfreq_get_devfreq_by_node function and add function to devfreq.h when CONFIG_PM_DEVFREQ is enabled.] Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
1 parent a1b8638 commit 7b38b7b

2 files changed

Lines changed: 41 additions & 11 deletions

File tree

drivers/devfreq/devfreq.c

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,32 @@ struct devfreq *devm_devfreq_add_device(struct device *dev,
983983
EXPORT_SYMBOL(devm_devfreq_add_device);
984984

985985
#ifdef CONFIG_OF
986+
/*
987+
* devfreq_get_devfreq_by_node - Get the devfreq device from devicetree
988+
* @node - pointer to device_node
989+
*
990+
* return the instance of devfreq device
991+
*/
992+
struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node)
993+
{
994+
struct devfreq *devfreq;
995+
996+
if (!node)
997+
return ERR_PTR(-EINVAL);
998+
999+
mutex_lock(&devfreq_list_lock);
1000+
list_for_each_entry(devfreq, &devfreq_list, node) {
1001+
if (devfreq->dev.parent
1002+
&& devfreq->dev.parent->of_node == node) {
1003+
mutex_unlock(&devfreq_list_lock);
1004+
return devfreq;
1005+
}
1006+
}
1007+
mutex_unlock(&devfreq_list_lock);
1008+
1009+
return ERR_PTR(-ENODEV);
1010+
}
1011+
9861012
/*
9871013
* devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree
9881014
* @dev - instance to the given device
@@ -1005,26 +1031,24 @@ struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
10051031
if (!node)
10061032
return ERR_PTR(-ENODEV);
10071033

1008-
mutex_lock(&devfreq_list_lock);
1009-
list_for_each_entry(devfreq, &devfreq_list, node) {
1010-
if (devfreq->dev.parent
1011-
&& devfreq->dev.parent->of_node == node) {
1012-
mutex_unlock(&devfreq_list_lock);
1013-
of_node_put(node);
1014-
return devfreq;
1015-
}
1016-
}
1017-
mutex_unlock(&devfreq_list_lock);
1034+
devfreq = devfreq_get_devfreq_by_node(node);
10181035
of_node_put(node);
10191036

1020-
return ERR_PTR(-EPROBE_DEFER);
1037+
return devfreq;
10211038
}
1039+
10221040
#else
1041+
struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node)
1042+
{
1043+
return ERR_PTR(-ENODEV);
1044+
}
1045+
10231046
struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
10241047
{
10251048
return ERR_PTR(-ENODEV);
10261049
}
10271050
#endif /* CONFIG_OF */
1051+
EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_node);
10281052
EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_phandle);
10291053

10301054
/**

include/linux/devfreq.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ void devm_devfreq_unregister_notifier(struct device *dev,
261261
struct devfreq *devfreq,
262262
struct notifier_block *nb,
263263
unsigned int list);
264+
struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node);
264265
struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index);
265266

266267
#if IS_ENABLED(CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND)
@@ -414,6 +415,11 @@ static inline void devm_devfreq_unregister_notifier(struct device *dev,
414415
{
415416
}
416417

418+
static inline struct devfreq *devfreq_get_devfreq_by_node(struct device_node *node)
419+
{
420+
return ERR_PTR(-ENODEV);
421+
}
422+
417423
static inline struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev,
418424
int index)
419425
{

0 commit comments

Comments
 (0)