Skip to content

Commit 5f0b74e

Browse files
Andrzej HajdaFelipe Balbi
authored andcommitted
USB: dwc3: get extcon device by OF graph bindings
extcon device is used to detect host/device connection. Since extcon OF property is deprecated, alternative method should be added. This method uses OF graph bindings to locate extcon. Signed-off-by: Andrzej Hajda <a.hajda@samsung.com> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
1 parent fe8abf3 commit 5f0b74e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

drivers/usb/dwc3/drd.c

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include <linux/extcon.h>
11+
#include <linux/of_graph.h>
1112
#include <linux/platform_device.h>
1213

1314
#include "debug.h"
@@ -439,17 +440,38 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
439440
return NOTIFY_DONE;
440441
}
441442

443+
struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
444+
{
445+
struct device *dev = dwc->dev;
446+
struct device_node *np_phy, *np_conn;
447+
struct extcon_dev *edev;
448+
449+
if (of_property_read_bool(dev->of_node, "extcon"))
450+
return extcon_get_edev_by_phandle(dwc->dev, 0);
451+
452+
np_phy = of_parse_phandle(dev->of_node, "phys", 0);
453+
np_conn = of_graph_get_remote_node(np_phy, -1, -1);
454+
455+
if (np_conn)
456+
edev = extcon_find_edev_by_node(np_conn);
457+
else
458+
edev = NULL;
459+
460+
of_node_put(np_conn);
461+
of_node_put(np_phy);
462+
463+
return edev;
464+
}
465+
442466
int dwc3_drd_init(struct dwc3 *dwc)
443467
{
444468
int ret, irq;
445469

446-
if (dwc->dev->of_node &&
447-
of_property_read_bool(dwc->dev->of_node, "extcon")) {
448-
dwc->edev = extcon_get_edev_by_phandle(dwc->dev, 0);
449-
450-
if (IS_ERR(dwc->edev))
451-
return PTR_ERR(dwc->edev);
470+
dwc->edev = dwc3_get_extcon(dwc);
471+
if (IS_ERR(dwc->edev))
472+
return PTR_ERR(dwc->edev);
452473

474+
if (dwc->edev) {
453475
dwc->edev_nb.notifier_call = dwc3_drd_notifier;
454476
ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
455477
&dwc->edev_nb);

0 commit comments

Comments
 (0)