From: Kongyang Liu Date: Fri, 10 Jan 2025 13:55:22 +0000 (+0800) Subject: usb: dwc2: Fix HBstLen setting for external DMA mode X-Git-Tag: v2025.10-rc1~118^2~54^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd6ef5097dd6c6219f12c0f2866ee4d578f190e9;p=thirdparty%2Fu-boot.git usb: dwc2: Fix HBstLen setting for external DMA mode The loop used to calculate HBstLen for extern DMA mode does not produce the correct result according to the datasheet [1]. Replacing that loop with a direct calculation using LOG2 to correctly assign the burst length in the GAHBCFG register for external DMA mode. [1] https://rockchip.fr/RK312X%20TRM/chapter-26-usb-otg-2-0.pdf#page=24 Signed-off-by: Kongyang Liu Reviewed-by: Marek Vasut Tested-by: Peter Robinson Reviewed-by: Mattijs Korpershoek Signed-off-by: Junhui Liu Link: https://lore.kernel.org/r/20250110-dwc2-dev-v4-3-987f4fd6f8b2@pigmoral.tech Signed-off-by: Mattijs Korpershoek --- diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index 609de18faa3..954650d856a 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -448,11 +448,8 @@ static void dwc_otg_core_init(struct udevice *dev) case DWC2_HWCFG2_ARCHITECTURE_SLAVE_ONLY: break; case DWC2_HWCFG2_ARCHITECTURE_EXT_DMA: - while (brst_sz > 1) { - ahbcfg |= ahbcfg + (1 << DWC2_GAHBCFG_HBURSTLEN_OFFSET); - ahbcfg &= DWC2_GAHBCFG_HBURSTLEN_MASK; - brst_sz >>= 1; - } + ahbcfg |= (LOG2(brst_sz >> 1) << DWC2_GAHBCFG_HBURSTLEN_OFFSET) & + DWC2_GAHBCFG_HBURSTLEN_MASK; #ifdef DWC2_DMA_ENABLE ahbcfg |= DWC2_GAHBCFG_DMAENABLE;