From: Seung-Woo Kim Date: Fri, 18 Aug 2023 06:34:10 +0000 (+0900) Subject: usb: cdns3-starfive: Add extcon usb gadget state with always connected X-Git-Tag: accepted/tizen/unified/riscv/20230821.094308~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F297436%2F2;p=platform%2Fkernel%2Flinux-starfive.git usb: cdns3-starfive: Add extcon usb gadget state with always connected 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 --- diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig index 0a514b591527..b139e66dfbf3 100644 --- a/drivers/usb/cdns3/Kconfig +++ b/drivers/usb/cdns3/Kconfig @@ -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 diff --git a/drivers/usb/cdns3/cdns3-starfive.c b/drivers/usb/cdns3/cdns3-starfive.c index a99f98f85235..55ae4ac53cbf 100644 --- a/drivers/usb/cdns3/cdns3-starfive.c +++ b/drivers/usb/cdns3/cdns3-starfive.c @@ -19,6 +19,9 @@ #include #include #include +#if IS_ENABLED(CONFIG_USB_CDNS3_STARFIVE_EXTCON) +#include +#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);