usb: cdns3-starfive: Add extcon usb gadget state with always connected 36/297436/2
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 18 Aug 2023 06:34:10 +0000 (15:34 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Fri, 18 Aug 2023 09:18:10 +0000 (18:18 +0900)
Add extcon usb gadget state and set usb gadget state as connected.

The cdns3-starfive usb c port in visionfive2 board only has usb
d-/d+ lines and vbus and ground lines are used for power supply.
Because of the H/W limitation, it is not possible to detect usb
c port connected state.

In Tizen, deviced configures usb gadget functions only with the
usb connected state, so, to support usb gadget functionality,
the usb state should be set.

Change-Id: I3e3a25a726c7205b3d9a5fd96d8557562bfda81f
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/usb/cdns3/Kconfig
drivers/usb/cdns3/cdns3-starfive.c

index 0a514b5915272a000c0c313451e58c2fe012ac5d..b139e66dfbf3ede59e3fe9b2f032ce56165e166a 100644 (file)
@@ -131,3 +131,14 @@ config USB_CDNSP_HOST
          standard XHCI driver.
 
 endif
+
+if USB_CDNS3_STARFIVE
+
+config USB_CDNS3_STARFIVE_EXTCON
+       bool "Extcon USB state support on Cadence USB3 of Starfive SoC"
+       depends on EXTCON
+       help
+         Say Y here to enable external connector event of the StarFive SoC
+         platforms that contain Cadence USB3 controller core.
+
+endif
index a99f98f8523589c2de2a3ca6ed155cff3b919860..55ae4ac53cbf1cf5d4c89881bbdc6f278d1e3481 100644 (file)
@@ -19,6 +19,9 @@
 #include <linux/regmap.h>
 #include <linux/reset.h>
 #include <linux/usb/otg.h>
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+#include <linux/extcon-provider.h>
+#endif
 #include "core.h"
 
 #define USB_STRAP_HOST                 BIT(17)
@@ -55,6 +58,9 @@ struct cdns_starfive {
        u32 stg_offset_328;
        u32 stg_offset_500;
        bool usb2_only;
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+       struct extcon_dev               *edev;
+#endif
 };
 
 static int cdns_mode_init(struct platform_device *pdev,
@@ -163,11 +169,21 @@ err_clk_init:
        return ret;
 }
 
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+static const unsigned int supported_cable[] = {
+       EXTCON_USB,
+       EXTCON_NONE,
+};
+#endif
+
 static int cdns_starfive_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct device_node *node = pdev->dev.of_node;
        struct cdns_starfive *data;
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+       struct extcon_dev *edev;
+#endif
        unsigned int args[4];
        const char *dr_mode;
        int ret;
@@ -180,6 +196,21 @@ static int cdns_starfive_probe(struct platform_device *pdev)
 
        data->dev = dev;
 
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+       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;
+
+       /* Set starfive cdns3 usb always connected because of hw limitation */
+       extcon_set_state_sync(edev, EXTCON_USB, true);
+
+       data->edev = edev;
+#endif
+
        data->stg_syscon = syscon_regmap_lookup_by_phandle_args(pdev->dev.of_node,
                "starfive,stg-syscon", 4, args);