usb: cdns3-starfive: Add extcon usb gadget state with always connected
authorJaehoon Chung <jh80.chung@samsung.com>
Thu, 21 Dec 2023 08:07:41 +0000 (17:07 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 19 Feb 2024 00:13:54 +0000 (09:13 +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: Ib951c105e3e8dfe5d1a2f0b921dabe6a7a8d61bc
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
drivers/usb/cdns3/Kconfig
drivers/usb/cdns3/cdns3-starfive.c

index 0a514b5..b139e66 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 a7265b8..89b6c1e 100644 (file)
@@ -18,6 +18,9 @@
 #include <linux/reset.h>
 #include <linux/regmap.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)
@@ -39,6 +42,9 @@ struct cdns_starfive {
        struct clk_bulk_data *clks;
        int num_clks;
        u32 stg_usb_mode;
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+       struct extcon_dev               *edev;
+#endif
 };
 
 static void cdns_mode_init(struct platform_device *pdev,
@@ -104,10 +110,20 @@ static void cdns_clk_rst_deinit(struct cdns_starfive *data)
        clk_bulk_disable_unprepare(data->num_clks, data->clks);
 }
 
+#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 cdns_starfive *data;
+#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON)
+       struct extcon_dev *edev;
+#endif
        unsigned int args;
        int ret;
 
@@ -116,6 +132,20 @@ static int cdns_starfive_probe(struct platform_device *pdev)
                return -ENOMEM;
 
        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,