]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
USB: dwc3: get extcon device by OF graph bindings
authorAndrzej Hajda <a.hajda@samsung.com>
Tue, 15 May 2018 12:12:38 +0000 (14:12 +0200)
committerFelipe Balbi <felipe.balbi@linux.intel.com>
Wed, 16 May 2018 05:56:16 +0000 (08:56 +0300)
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>
drivers/usb/dwc3/drd.c

index 1d8c557e97e06f95653ac77d7a26d605f66ee40b..270682486f8217f8481b3f987d6e71c8b6693f10 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/extcon.h>
+#include <linux/of_graph.h>
 #include <linux/platform_device.h>
 
 #include "debug.h"
@@ -439,17 +440,38 @@ static int dwc3_drd_notifier(struct notifier_block *nb,
        return NOTIFY_DONE;
 }
 
+struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
+{
+       struct device *dev = dwc->dev;
+       struct device_node *np_phy, *np_conn;
+       struct extcon_dev *edev;
+
+       if (of_property_read_bool(dev->of_node, "extcon"))
+               return extcon_get_edev_by_phandle(dwc->dev, 0);
+
+       np_phy = of_parse_phandle(dev->of_node, "phys", 0);
+       np_conn = of_graph_get_remote_node(np_phy, -1, -1);
+
+       if (np_conn)
+               edev = extcon_find_edev_by_node(np_conn);
+       else
+               edev = NULL;
+
+       of_node_put(np_conn);
+       of_node_put(np_phy);
+
+       return edev;
+}
+
 int dwc3_drd_init(struct dwc3 *dwc)
 {
        int ret, irq;
 
-       if (dwc->dev->of_node &&
-           of_property_read_bool(dwc->dev->of_node, "extcon")) {
-               dwc->edev = extcon_get_edev_by_phandle(dwc->dev, 0);
-
-               if (IS_ERR(dwc->edev))
-                       return PTR_ERR(dwc->edev);
+       dwc->edev = dwc3_get_extcon(dwc);
+       if (IS_ERR(dwc->edev))
+               return PTR_ERR(dwc->edev);
 
+       if (dwc->edev) {
                dwc->edev_nb.notifier_call = dwc3_drd_notifier;
                ret = extcon_register_notifier(dwc->edev, EXTCON_USB_HOST,
                                               &dwc->edev_nb);