usb: dwc2: gadget: Set extcon state for usb cable as always true 52/306652/1
authorDongwoo Lee <dwoo08.lee@samsung.com>
Tue, 18 Feb 2020 04:36:40 +0000 (13:36 +0900)
committerMarek Szyprowski <m.szyprowski@samsung.com>
Fri, 23 Feb 2024 22:37:51 +0000 (23:37 +0100)
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.

Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
[mszyprow: ported and adapted to v6.6 kernel release]
Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Change-Id: Ib0e9982b426fda7deed510e482d6731a2f23d0b1

drivers/usb/dwc2/core.h
drivers/usb/dwc2/gadget.c
drivers/usb/dwc2/params.c

index c92a1da..faf40c1 100644 (file)
@@ -497,6 +497,9 @@ struct dwc2_core_params {
        u32 g_rx_fifo_size;
        u32 g_np_tx_fifo_size;
        u32 g_tx_fifo_size[MAX_EPS_CHANNELS];
+#if IS_ENABLED(CONFIG_EXTCON)
+       bool g_extcon_always_on;
+#endif
 
        bool change_speed_quirk;
 };
index b517a72..68292c2 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/extcon-provider.h>
 
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
@@ -5060,6 +5061,25 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg)
 
        dwc2_hsotg_dump(hsotg);
 
+#if IS_ENABLED(CONFIG_EXTCON)
+       if (hsotg->params.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_state_sync(edev, EXTCON_USB, true);
+       }
+#endif
        return 0;
 }
 
index 93f52e3..d0508a0 100644 (file)
@@ -546,6 +546,11 @@ static void dwc2_get_device_properties(struct dwc2_hsotg *hsotg)
                                         &p->g_np_tx_fifo_size);
 
                num = device_property_count_u32(hsotg->dev, "g-tx-fifo-size");
+#if IS_ENABLED(CONFIG_EXTCON)
+               if (of_find_property(hsotg->dev->of_node,
+                                       "g-extcon-always-on", NULL))
+                       p->g_extcon_always_on = 1;
+#endif
                if (num > 0) {
                        num = min(num, 15);
                        memset(p->g_tx_fifo_size, 0,