[PATCH] usb: dwc2: gadget: remove D+ pull-up while no vbus with usb-role-switch

Fabrice Gasnier posted 1 patch 3 years, 10 months ago
drivers/usb/dwc2/gadget.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] usb: dwc2: gadget: remove D+ pull-up while no vbus with usb-role-switch
Posted by Fabrice Gasnier 3 years, 10 months ago
From: Amelie Delaunay <amelie.delaunay@foss.st.com>

When using usb-role-switch, D+ pull-up is set as soon as DTCL_SFTDISCON is
cleared, whatever the vbus valid signal state is. The pull-up should not
be set when vbus isn't present (this is determined by the drd controller).

This patch ensures that B-Session (so Peripheral role + vbus valid signal)
is valid before clearing the DCTL_SFTDISCON bit when role switch is used.
Keep original behavior when usb-role-switch isn't used.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>
---
 drivers/usb/dwc2/gadget.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index fe2a58c758610..8b15742d9e8aa 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3594,7 +3594,8 @@ void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg)
 void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg)
 {
 	/* remove the soft-disconnect and let's go */
-	dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON);
+	if (!hsotg->role_sw || (dwc2_readl(hsotg, GOTGCTL) & GOTGCTL_BSESVLD))
+		dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON);
 }
 
 /**
-- 
2.25.1
Re: [PATCH] usb: dwc2: gadget: remove D+ pull-up while no vbus with usb-role-switch
Posted by Minas Harutyunyan 3 years, 9 months ago
On 6/22/2022 8:07 PM, Fabrice Gasnier wrote:
> From: Amelie Delaunay <amelie.delaunay@foss.st.com>
> 
> When using usb-role-switch, D+ pull-up is set as soon as DTCL_SFTDISCON is
> cleared, whatever the vbus valid signal state is. The pull-up should not
> be set when vbus isn't present (this is determined by the drd controller).
> 
> This patch ensures that B-Session (so Peripheral role + vbus valid signal)
> is valid before clearing the DCTL_SFTDISCON bit when role switch is used.
> Keep original behavior when usb-role-switch isn't used.
> 
> Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com>

Acked-by: Minas Harutyunyan <hminas@synopsys.com>

> ---
>   drivers/usb/dwc2/gadget.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index fe2a58c758610..8b15742d9e8aa 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -3594,7 +3594,8 @@ void dwc2_hsotg_core_disconnect(struct dwc2_hsotg *hsotg)
>   void dwc2_hsotg_core_connect(struct dwc2_hsotg *hsotg)
>   {
>   	/* remove the soft-disconnect and let's go */
> -	dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON);
> +	if (!hsotg->role_sw || (dwc2_readl(hsotg, GOTGCTL) & GOTGCTL_BSESVLD))
> +		dwc2_clear_bit(hsotg, DCTL, DCTL_SFTDISCON);
>   }
>   
>   /**