diff options
Diffstat (limited to 'drivers/extcon/extcon-class.c')
-rw-r--r-- | drivers/extcon/extcon-class.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 76322330cbd7..7ab21aa6eaa1 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/extcon.h> | 31 | #include <linux/extcon.h> |
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/sysfs.h> | 33 | #include <linux/sysfs.h> |
34 | #include <linux/of.h> | ||
34 | 35 | ||
35 | /* | 36 | /* |
36 | * extcon_cable_name suggests the standard cable names for commonly used | 37 | * extcon_cable_name suggests the standard cable names for commonly used |
@@ -818,6 +819,47 @@ void extcon_dev_unregister(struct extcon_dev *edev) | |||
818 | } | 819 | } |
819 | EXPORT_SYMBOL_GPL(extcon_dev_unregister); | 820 | EXPORT_SYMBOL_GPL(extcon_dev_unregister); |
820 | 821 | ||
822 | #ifdef CONFIG_OF | ||
823 | /* | ||
824 | * extcon_get_edev_by_phandle - Get the extcon device from devicetree | ||
825 | * @dev - instance to the given device | ||
826 | * @index - index into list of extcon_dev | ||
827 | * | ||
828 | * return the instance of extcon device | ||
829 | */ | ||
830 | struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) | ||
831 | { | ||
832 | struct device_node *node; | ||
833 | struct extcon_dev *edev; | ||
834 | |||
835 | if (!dev->of_node) { | ||
836 | dev_err(dev, "device does not have a device node entry\n"); | ||
837 | return ERR_PTR(-EINVAL); | ||
838 | } | ||
839 | |||
840 | node = of_parse_phandle(dev->of_node, "extcon", index); | ||
841 | if (!node) { | ||
842 | dev_err(dev, "failed to get phandle in %s node\n", | ||
843 | dev->of_node->full_name); | ||
844 | return ERR_PTR(-ENODEV); | ||
845 | } | ||
846 | |||
847 | edev = extcon_get_extcon_dev(node->name); | ||
848 | if (!edev) { | ||
849 | dev_err(dev, "unable to get extcon device : %s\n", node->name); | ||
850 | return ERR_PTR(-ENODEV); | ||
851 | } | ||
852 | |||
853 | return edev; | ||
854 | } | ||
855 | #else | ||
856 | struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) | ||
857 | { | ||
858 | return ERR_PTR(-ENOSYS); | ||
859 | } | ||
860 | #endif /* CONFIG_OF */ | ||
861 | EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); | ||
862 | |||
821 | static int __init extcon_class_init(void) | 863 | static int __init extcon_class_init(void) |
822 | { | 864 | { |
823 | return create_extcon_class(); | 865 | return create_extcon_class(); |