[PATCH] usb: dwc3: respect role-switch-default-mode

Marek Vasut marex at denx.de
Mon Jun 24 02:33:34 CEST 2024


On 6/21/24 4:11 AM, Caleb Connolly wrote:
> * Factor out the common pattern of checking the dr_mode property on
>    the usb node and it's parent
> * Respect the usb-role-switch property, rather than requiring dr_mode be
>    set
> * Override OTG mode with the value in role-switch-default-mode
> 
> The devicetree bindings don't dictate that dr_mode is a required
> property, but the dwc3 driver would refuse to probe if it was unset
> (this breaks the Qualcomm RB2 board which doesn't set it).
> 
> Here, we update the driver to respect the other properties that can be
> used to describe the controller, and more gracefully handle some of the
> edge cases.
> 
> Signed-off-by: Caleb Connolly <caleb.connolly at linaro.org>
> ---
> Cc: Ilias Apalodimas <ilias.apalodimas at linaro.org>
> Cc: Neil Armstrong <neil.armstrong at linaro.org>
> ---
>   drivers/usb/dwc3/dwc3-generic.c | 56 +++++++++++++++++++++++++--------
>   1 file changed, 43 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
> index cbb5d61dfb0b..1cf8b90e8bbf 100644
> --- a/drivers/usb/dwc3/dwc3-generic.c
> +++ b/drivers/usb/dwc3/dwc3-generic.c
> @@ -49,8 +49,46 @@ struct dwc3_generic_host_priv {
>   	struct dwc3_generic_priv gen_priv;
>   	struct udevice *vbus_supply;
>   };
>   
> +/**
> + * dwc3_get_preferred_dr_mode() - Get the preferred DR mode for the USB node
> + *
> + * Since we don't support dynamic role switching yet in dwc3, this is a slightly
> + * opinionated wrapper around usb_get_dr_mode() which will respect the
> + * role-switch-default-mode property if it is present and the dr_mode is OTG.
> + *
> + * @child: Node to get the DR mode for
> + */
> +static enum usb_dr_mode dwc3_get_preferred_dr_mode(ofnode node)
> +{
> +	enum usb_dr_mode mode;
> +	bool is_role_switch = ofnode_has_property(node, "usb-role-switch");

The usb-role-switch DT property is not DWC3 specific, even in U-Boot it 
is used by e.g. STM32MP15xx which is DWC2. This should be added to core 
code.

Also, it would be really good to sync the DWC3 driver with more up to 
date Linux state, but that's out of the scope of this patch obviously.


More information about the U-Boot mailing list