diff options
author | Kishon Vijay Abraham I <kishon@ti.com> | 2013-06-11 07:48:02 -0400 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2013-08-04 19:52:45 -0400 |
commit | 6eee5b3b493824731ed34ade0299241f91f04096 (patch) | |
tree | 7bb211aa395c43ef155373fe7049219fadd417dd /drivers/extcon | |
parent | 5ae90d8e467e625e447000cb4335c4db973b1095 (diff) |
extcon: Add an API to get extcon device from dt node
Added an API of_extcon_get_extcon_dev() to be used by drivers to get
extcon device in the case of dt boot (this can be used instead of
extcon_get_extcon_dev()).
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Signed-off-by: Myungjoo Ham <myungjoo.ham@samsung.com>
Diffstat (limited to 'drivers/extcon')
-rw-r--r-- | drivers/extcon/Kconfig | 4 | ||||
-rw-r--r-- | drivers/extcon/Makefile | 2 | ||||
-rw-r--r-- | drivers/extcon/extcon-class.c | 3 | ||||
-rw-r--r-- | drivers/extcon/of_extcon.c | 64 |
4 files changed, 72 insertions, 1 deletions
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 63f454e20576..f1d54a3985bd 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig | |||
@@ -14,6 +14,10 @@ if EXTCON | |||
14 | 14 | ||
15 | comment "Extcon Device Drivers" | 15 | comment "Extcon Device Drivers" |
16 | 16 | ||
17 | config OF_EXTCON | ||
18 | def_tristate y | ||
19 | depends on OF | ||
20 | |||
17 | config EXTCON_GPIO | 21 | config EXTCON_GPIO |
18 | tristate "GPIO extcon support" | 22 | tristate "GPIO extcon support" |
19 | depends on GPIOLIB | 23 | depends on GPIOLIB |
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 540e2c3a4431..759fdae46f95 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile | |||
@@ -2,6 +2,8 @@ | |||
2 | # Makefile for external connector class (extcon) devices | 2 | # Makefile for external connector class (extcon) devices |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_OF_EXTCON) += of_extcon.o | ||
6 | |||
5 | obj-$(CONFIG_EXTCON) += extcon-class.o | 7 | obj-$(CONFIG_EXTCON) += extcon-class.o |
6 | obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o | 8 | obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o |
7 | obj-$(CONFIG_EXTCON_ADC_JACK) += extcon-adc-jack.o | 9 | obj-$(CONFIG_EXTCON_ADC_JACK) += extcon-adc-jack.o |
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c index 18ccadef43fd..1446152bf2e9 100644 --- a/drivers/extcon/extcon-class.c +++ b/drivers/extcon/extcon-class.c | |||
@@ -602,7 +602,8 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev) | |||
602 | edev->dev->class = extcon_class; | 602 | edev->dev->class = extcon_class; |
603 | edev->dev->release = extcon_dev_release; | 603 | edev->dev->release = extcon_dev_release; |
604 | 604 | ||
605 | dev_set_name(edev->dev, "%s", edev->name ? edev->name : dev_name(dev)); | 605 | edev->name = edev->name ? edev->name : dev_name(dev); |
606 | dev_set_name(edev->dev, "%s", edev->name); | ||
606 | 607 | ||
607 | if (edev->max_supported) { | 608 | if (edev->max_supported) { |
608 | char buf[10]; | 609 | char buf[10]; |
diff --git a/drivers/extcon/of_extcon.c b/drivers/extcon/of_extcon.c new file mode 100644 index 000000000000..72173ecbb311 --- /dev/null +++ b/drivers/extcon/of_extcon.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * OF helpers for External connector (extcon) framework | ||
3 | * | ||
4 | * Copyright (C) 2013 Texas Instruments, Inc. | ||
5 | * Kishon Vijay Abraham I <kishon@ti.com> | ||
6 | * | ||
7 | * Copyright (C) 2013 Samsung Electronics | ||
8 | * Chanwoo Choi <cw00.choi@samsung.com> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/extcon.h> | ||
20 | #include <linux/of.h> | ||
21 | #include <linux/of_platform.h> | ||
22 | #include <linux/extcon/of_extcon.h> | ||
23 | |||
24 | /* | ||
25 | * of_extcon_get_extcon_dev - Get the name of extcon device from devicetree | ||
26 | * @dev - instance to the given device | ||
27 | * @index - index into list of extcon_dev | ||
28 | * | ||
29 | * return the instance of extcon device | ||
30 | */ | ||
31 | struct extcon_dev *of_extcon_get_extcon_dev(struct device *dev, int index) | ||
32 | { | ||
33 | struct device_node *node; | ||
34 | struct extcon_dev *edev; | ||
35 | struct platform_device *extcon_parent_dev; | ||
36 | |||
37 | if (!dev->of_node) { | ||
38 | dev_dbg(dev, "device does not have a device node entry\n"); | ||
39 | return ERR_PTR(-EINVAL); | ||
40 | } | ||
41 | |||
42 | node = of_parse_phandle(dev->of_node, "extcon", index); | ||
43 | if (!node) { | ||
44 | dev_dbg(dev, "failed to get phandle in %s node\n", | ||
45 | dev->of_node->full_name); | ||
46 | return ERR_PTR(-ENODEV); | ||
47 | } | ||
48 | |||
49 | extcon_parent_dev = of_find_device_by_node(node); | ||
50 | if (!extcon_parent_dev) { | ||
51 | dev_dbg(dev, "unable to find device by node\n"); | ||
52 | return ERR_PTR(-EPROBE_DEFER); | ||
53 | } | ||
54 | |||
55 | edev = extcon_get_extcon_dev(dev_name(&extcon_parent_dev->dev)); | ||
56 | if (!edev) { | ||
57 | dev_dbg(dev, "unable to get extcon device : %s\n", | ||
58 | dev_name(&extcon_parent_dev->dev)); | ||
59 | return ERR_PTR(-ENODEV); | ||
60 | } | ||
61 | |||
62 | return edev; | ||
63 | } | ||
64 | EXPORT_SYMBOL_GPL(of_extcon_get_extcon_dev); | ||