aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/devfreq/devfreq.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/devfreq/devfreq.c')
-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.