usb: dwc_otg: Set extcon state for usb cable as always true 72/248872/1
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 3 Dec 2020 03:53:43 +0000 (12:53 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 3 Dec 2020 03:56:36 +0000 (12:56 +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.

Note: ported from https://git.tizen.org/cgit/profile/common/platform/kernel/linux-artik7/commit/?h=tizen&id=f7e1e93b230f61d66d6a3bc58d09c53dcd305e21

Change-Id: I16fb629ccec54f0ae46e697b56750c3021f01ccb
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/amlogic/usb/dwc_otg/310/dwc_otg_driver.c

index 263ed2c1938fbd091b7a1e0ddafc68de95f1e981..df2746f82451aac90a91dd59abba149b0fa912a1 100644 (file)
@@ -75,6 +75,7 @@
 #ifdef CONFIG_AMLOGIC_LEGACY_EARLY_SUSPEND
 #include <linux/amlogic/pm.h>
 #endif
+#include <linux/extcon.h>
 
 #define DWC_DRIVER_VERSION     "3.10a 12-MAY-2014"
 #define DWC_DRIVER_DESC                "HS OTG USB Controller driver"
@@ -968,6 +969,9 @@ static int dwc_otg_driver_probe(struct platform_device *pdev)
        struct dwc_otg_driver_module_params *pcore_para;
        static int dcount;
        int controller_type = USB_NORMAL;
+#if IS_ENABLED(CONFIG_EXTCON)
+       bool g_extcon_always_on = false;
+#endif
 
        dev_dbg(&pdev->dev, "dwc_otg_driver_probe(%p)\n", pdev);
 
@@ -1069,6 +1073,11 @@ static int dwc_otg_driver_probe(struct platform_device *pdev)
                                        phy_interface = 2;
                        }
 
+#if IS_ENABLED(CONFIG_EXTCON)
+                       g_extcon_always_on =
+                               of_property_read_bool(of_node, "g-extcon-always-on");
+#endif
+
                        dwc_otg_module_params.host_rx_fifo_size = dwc_otg_module_params.data_fifo_size / 2;
                        DWC_PRINTF("dwc_otg: %s: type: %d speed: %d, ",
                                s_clock_name, port_type, port_speed);
@@ -1099,6 +1108,26 @@ static int dwc_otg_driver_probe(struct platform_device *pdev)
        memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
        dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
 
+#if IS_ENABLED(CONFIG_EXTCON)
+       if (g_extcon_always_on) {
+               struct extcon_dev *edev;
+               static const unsigned int supported_cable[] = {
+                       EXTCON_USB,
+                       EXTCON_NONE,
+               };
+
+               edev = devm_extcon_dev_allocate(&pdev->dev, supported_cable);
+               if (IS_ERR(edev))
+                       return PTR_ERR(edev);
+
+               retval = devm_extcon_dev_register(&pdev->dev, edev);
+               if (retval)
+                       return retval;
+
+               extcon_set_cable_state_(edev, EXTCON_USB, true);
+       }
+#endif
+
        /*
        * Map the DWC_otg Core memory into virtual address space.
        */