diff mbox series

[v2] usb: dwc3: gadget: fix writing NYET threshold

Message ID 20241209-dwc3-nyet-fix-v2-1-02755683345b@linaro.org (mailing list archive)
State Superseded
Headers show
Series [v2] usb: dwc3: gadget: fix writing NYET threshold | expand

Commit Message

André Draszik Dec. 9, 2024, 11:49 a.m. UTC
Before writing a new value to the register, the old value needs to be
masked out for the new value to be programmed as intended, because at
least in some cases the reset value of that field is 0xf (max value).

At the moment, the dwc3 core initialises the threshold to the maximum
value (0xf), with the option to override it via a DT. No upstream DTs
seem to override it, therefore this commit doesn't change behaviour for
any upstream platform. Nevertheless, the code should be fixed to have
the desired outcome.

Do so.

Fixes: 80caf7d21adc ("usb: dwc3: add lpm erratum support")
Cc: stable@vger.kernel.org # 5.10+ (needs adjustment for 5.4)
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
Changes in v2:
- change mask definitions to be consistent with other masks (Thinh)
- udpate commit message to clarify that in some cases the reset value
  is != 0
- Link to v1: https://lore.kernel.org/r/20241206-dwc3-nyet-fix-v1-1-293bc74f644f@linaro.org
---
For stable-5.4, the if() test is slightly different, so a separate
patch will be sent for it for the patch to apply.
---
 drivers/usb/dwc3/core.h   | 1 +
 drivers/usb/dwc3/gadget.c | 4 +++-
 2 files changed, 4 insertions(+), 1 deletion(-)


---
base-commit: c245a7a79602ccbee780c004c1e4abcda66aec32
change-id: 20241206-dwc3-nyet-fix-7085f6d71d04

Best regards,

Comments

Thinh Nguyen Dec. 10, 2024, 10:51 p.m. UTC | #1
On Mon, Dec 09, 2024, André Draszik wrote:
> Before writing a new value to the register, the old value needs to be
> masked out for the new value to be programmed as intended, because at
> least in some cases the reset value of that field is 0xf (max value).
> 
> At the moment, the dwc3 core initialises the threshold to the maximum
> value (0xf), with the option to override it via a DT. No upstream DTs
> seem to override it, therefore this commit doesn't change behaviour for
> any upstream platform. Nevertheless, the code should be fixed to have
> the desired outcome.
> 
> Do so.
> 
> Fixes: 80caf7d21adc ("usb: dwc3: add lpm erratum support")
> Cc: stable@vger.kernel.org # 5.10+ (needs adjustment for 5.4)
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
> ---
> Changes in v2:
> - change mask definitions to be consistent with other masks (Thinh)
> - udpate commit message to clarify that in some cases the reset value
>   is != 0
> - Link to v1: https://urldefense.com/v3/__https://lore.kernel.org/r/20241206-dwc3-nyet-fix-v1-1-293bc74f644f@linaro.org__;!!A4F2R9G_pg!exwT5XPAys9S8l6RyyVaky6AnKD2swNq-bjYs5za6qQvktfSS812CHZGh-U6oPOu1rIuJ-tPe9TWIEsIHYnbbOmsRfr7$ 
> ---
> For stable-5.4, the if() test is slightly different, so a separate
> patch will be sent for it for the patch to apply.
> ---
>  drivers/usb/dwc3/core.h   | 1 +
>  drivers/usb/dwc3/gadget.c | 4 +++-
>  2 files changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index ee73789326bc..f11570c8ffd0 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -464,6 +464,7 @@
>  #define DWC3_DCTL_TRGTULST_SS_INACT	(DWC3_DCTL_TRGTULST(6))
>  
>  /* These apply for core versions 1.94a and later */
> +#define DWC3_DCTL_NYET_THRES_MASK	(0xf << 20)
>  #define DWC3_DCTL_NYET_THRES(n)		(((n) & 0xf) << 20)
>  
>  #define DWC3_DCTL_KEEP_CONNECT		BIT(19)
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 83dc7304d701..31a654c6f15b 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -4195,8 +4195,10 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
>  		WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum,
>  				"LPM Erratum not available on dwc3 revisions < 2.40a\n");
>  
> -		if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A))
> +		if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) {
> +			reg &= ~DWC3_DCTL_NYET_THRES_MASK;
>  			reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold);
> +		}
>  
>  		dwc3_gadget_dctl_write_safe(dwc, reg);
>  	} else {
> 
> ---
> base-commit: c245a7a79602ccbee780c004c1e4abcda66aec32
> change-id: 20241206-dwc3-nyet-fix-7085f6d71d04
> 
> Best regards,
> -- 
> André Draszik <andre.draszik@linaro.org>
> 

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thanks,
Thinh
diff mbox series

Patch

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index ee73789326bc..f11570c8ffd0 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -464,6 +464,7 @@ 
 #define DWC3_DCTL_TRGTULST_SS_INACT	(DWC3_DCTL_TRGTULST(6))
 
 /* These apply for core versions 1.94a and later */
+#define DWC3_DCTL_NYET_THRES_MASK	(0xf << 20)
 #define DWC3_DCTL_NYET_THRES(n)		(((n) & 0xf) << 20)
 
 #define DWC3_DCTL_KEEP_CONNECT		BIT(19)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 83dc7304d701..31a654c6f15b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -4195,8 +4195,10 @@  static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc)
 		WARN_ONCE(DWC3_VER_IS_PRIOR(DWC3, 240A) && dwc->has_lpm_erratum,
 				"LPM Erratum not available on dwc3 revisions < 2.40a\n");
 
-		if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A))
+		if (dwc->has_lpm_erratum && !DWC3_VER_IS_PRIOR(DWC3, 240A)) {
+			reg &= ~DWC3_DCTL_NYET_THRES_MASK;
 			reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold);
+		}
 
 		dwc3_gadget_dctl_write_safe(dwc, reg);
 	} else {