aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/devfreq
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2015-11-10 06:31:07 -0500
committerMyungJoo Ham <myungjoo.ham@samsung.com>2016-05-02 22:20:06 -0400
commit8f510aeb223b26c4ffbece9fa92e4befea470f57 (patch)
treebf4fb4bad488510fab1baf43cbb42df08e0e2b7e /drivers/devfreq
parent72c160bda1dbe75d532502374a6cb6be28990093 (diff)
PM / devfreq: Add devfreq_get_devfreq_by_phandle()
This patch adds the new devfreq_get_devfreq_by_phandle() OF helper function which can find the instance of devfreq device by using phandle ("devfreq"). Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> [m.reichl and linux.amoon: Tested it on exynos4412-odroidu3 board] Tested-by: Markus Reichl <m.reichl@fivetechno.de> Tested-by: Anand Moon <linux.amoon@gmail.com> Acked-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Diffstat (limited to 'drivers/devfreq')
-rw-r--r--drivers/devfreq/devfreq.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 984c5e9e7bdd..20a9422c2552 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -25,6 +25,7 @@
25#include <linux/list.h> 25#include <linux/list.h>
26#include <linux/printk.h> 26#include <linux/printk.h>
27#include <linux/hrtimer.h> 27#include <linux/hrtimer.h>
28#include <linux/of.h>
28#include "governor.h" 29#include "governor.h"
29 30
30static struct class *devfreq_class; 31static struct class *devfreq_class;
@@ -639,6 +640,49 @@ struct devfreq *devm_devfreq_add_device(struct device *dev,
639} 640}
640EXPORT_SYMBOL(devm_devfreq_add_device); 641EXPORT_SYMBOL(devm_devfreq_add_device);
641 642
643#ifdef CONFIG_OF
644/*
645 * devfreq_get_devfreq_by_phandle - Get the devfreq device from devicetree
646 * @dev - instance to the given device
647 * @index - index into list of devfreq
648 *
649 * return the instance of devfreq device
650 */
651struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
652{
653 struct device_node *node;
654 struct devfreq *devfreq;
655
656 if (!dev)
657 return ERR_PTR(-EINVAL);
658
659 if (!dev->of_node)
660 return ERR_PTR(-EINVAL);
661
662 node = of_parse_phandle(dev->of_node, "devfreq", index);
663 if (!node)
664 return ERR_PTR(-ENODEV);
665
666 mutex_lock(&devfreq_list_lock);
667 list_for_each_entry(devfreq, &devfreq_list, node) {
668 if (devfreq->dev.parent
669 && devfreq->dev.parent->of_node == node) {
670 mutex_unlock(&devfreq_list_lock);
671 return devfreq;
672 }
673 }
674 mutex_unlock(&devfreq_list_lock);
675
676 return ERR_PTR(-EPROBE_DEFER);
677}
678#else
679struct devfreq *devfreq_get_devfreq_by_phandle(struct device *dev, int index)
680{
681 return ERR_PTR(-ENODEV);
682}
683#endif /* CONFIG_OF */
684EXPORT_SYMBOL_GPL(devfreq_get_devfreq_by_phandle);
685
642/** 686/**
643 * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device() 687 * devm_devfreq_remove_device() - Resource-managed devfreq_remove_device()
644 * @dev: the device to add devfreq feature. 688 * @dev: the device to add devfreq feature.