usb: dwc2: gadget: Set extcon state for usb cable as always true
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 18 Feb 2020 09:23:43 +0000 (18:23 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Mon, 24 Feb 2020 02:09:10 +0000 (11:09 +0900)
To inform to userspace as enable usb features always, set extcon
state for usb cable as connected permanently. To enable this, add
"g-extcon-always-on" property on dt.

Change-Id: I687ca1b098d007a5d0ca7ddf6d552605195cafcf
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
drivers/usb/dwc2/core.h
drivers/usb/dwc2/gadget.c

index dfd7d4c9f0f4147bba71855830473ad079283f8b..b3e4c21323d86083522cf7c1ee3df4ad7bef9ff6 100644 (file)
@@ -872,6 +872,9 @@ struct dwc2_hsotg {
        u32 g_rx_fifo_sz;
        u32 g_np_g_tx_fifo_sz;
        u32 g_tx_fifo_sz[MAX_EPS_CHANNELS];
+#if IS_ENABLED(CONFIG_EXTCON)
+       bool g_extcon_always_on;
+#endif
 #endif /* CONFIG_USB_DWC2_PERIPHERAL || CONFIG_USB_DWC2_DUAL_ROLE */
 };
 
index 7b1428cd51a86f3bfd38ba54db2da413dc5ab806..856ba0603d1c41c8f387c10fb5fd786b2e059e0c 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <linux/of_platform.h>
+#include <linux/extcon.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
@@ -3509,6 +3510,10 @@ static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg)
        /* Enable dma if requested in device tree */
        hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma");
 
+#if IS_ENABLED(CONFIG_EXTCON)
+       hsotg->g_extcon_always_on =
+               of_property_read_bool(np, "g-extcon-always-on");
+#endif
        /*
        * Register TX periodic fifo size per endpoint.
        * EP0 is excluded since it has no fifo configuration.
@@ -3666,6 +3671,25 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
        }
        dwc2_hsotg_dump(hsotg);
 
+#if IS_ENABLED(CONFIG_EXTCON)
+       if (hsotg->g_extcon_always_on) {
+               struct extcon_dev *edev;
+               static const unsigned int supported_cable[] = {
+                       EXTCON_USB,
+                       EXTCON_NONE,
+               };
+
+               edev = devm_extcon_dev_allocate(dev, supported_cable);
+               if (IS_ERR(edev))
+                       return PTR_ERR(edev);
+
+               ret = devm_extcon_dev_register(dev, edev);
+               if (ret)
+                       return ret;
+
+               extcon_set_cable_state_(edev, EXTCON_USB, true);
+       }
+#endif
        return 0;
 }