diff mbox series

[v3,1/1] usb: dwc3: drd: Add support for usb-conn-gpio based usb-role-switch

Message ID 20211216134940.487518-1-alexander.stein@ew.tq-group.com (mailing list archive)
State Superseded
Headers show
Series [v3,1/1] usb: dwc3: drd: Add support for usb-conn-gpio based usb-role-switch | expand

Commit Message

Alexander Stein Dec. 16, 2021, 1:49 p.m. UTC
usb-conn-gpio devices are a subnode of the USB interface controller, which
needs to be populated.
This allows having a non-type-c connector providing dual-role.

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
Greg, thank you for your review.

This was tested on an imx8mp based board (TQMa8MPxL) which uses devicetree.
Unfortunately I have no non-imx platform available to test this on.

devm_of_platform_populate() _will_ fail on non-OF builds, so do not call this
on non-OF enabled platforms.
AFAICS on OF-platforms this call will only fail upon memory allocation errors.
If there are no subnodes, this call will not fail. So existing platform should
work as before.

Changes in v3:
* Unregister role-switch upon populating OF tree error
* Do not call devm_of_platform_populate() on non-OF platforms

Changes in v2:
* Added missing variable declaration

 drivers/usb/dwc3/drd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Greg Kroah-Hartman Dec. 21, 2021, 7:57 a.m. UTC | #1
On Thu, Dec 16, 2021 at 02:49:40PM +0100, Alexander Stein wrote:
> usb-conn-gpio devices are a subnode of the USB interface controller, which
> needs to be populated.
> This allows having a non-type-c connector providing dual-role.
> 
> Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
> ---
> Greg, thank you for your review.
> 
> This was tested on an imx8mp based board (TQMa8MPxL) which uses devicetree.
> Unfortunately I have no non-imx platform available to test this on.
> 
> devm_of_platform_populate() _will_ fail on non-OF builds, so do not call this
> on non-OF enabled platforms.
> AFAICS on OF-platforms this call will only fail upon memory allocation errors.
> If there are no subnodes, this call will not fail. So existing platform should
> work as before.
> 
> Changes in v3:
> * Unregister role-switch upon populating OF tree error
> * Do not call devm_of_platform_populate() on non-OF platforms
> 
> Changes in v2:
> * Added missing variable declaration
> 
>  drivers/usb/dwc3/drd.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index d7f76835137f..1dcce7a04b41 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c
> @@ -9,6 +9,7 @@
>  
>  #include <linux/extcon.h>
>  #include <linux/of_graph.h>
> +#include "linux/of_platform.h"

Why "" and not <>?
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index d7f76835137f..1dcce7a04b41 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -9,6 +9,7 @@ 
 
 #include <linux/extcon.h>
 #include <linux/of_graph.h>
+#include "linux/of_platform.h"
 #include <linux/platform_device.h>
 #include <linux/property.h>
 
@@ -559,6 +560,18 @@  static int dwc3_setup_role_switch(struct dwc3 *dwc)
 	if (IS_ERR(dwc->role_sw))
 		return PTR_ERR(dwc->role_sw);
 
+	if (IS_ENABLED(CONFIG_OF)) {
+		/* populate connector entry */
+		int ret = devm_of_platform_populate(dwc->dev);
+
+		if (ret) {
+			usb_role_switch_unregister(dwc->role_sw);
+			dwc->role_sw = NULL;
+			dev_err(dwc->dev, "DWC3 platform devices creation failed: %i\n", ret);
+			return ret;
+		}
+	}
+
 	dwc3_set_mode(dwc, mode);
 	return 0;
 }