From: Junhui Liu Date: Fri, 10 Jan 2025 13:55:21 +0000 (+0800) Subject: usb: dwc2: Fix incorrect ULPI_UTMI_SEL bit setting X-Git-Tag: v2025.10-rc1~118^2~54^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94a1f8fe47e26250dd5704b2c2187622522eca6b;p=thirdparty%2Fu-boot.git usb: dwc2: Fix incorrect ULPI_UTMI_SEL bit setting The ULPI_UTMI_SEL bit in the DWC2 driver was set incorrectly. According to the datasheet [1], this bit should be set to 0 for UTMI interface and 1 for ULPI interface. The existing code had this logic reversed, causing the interface selection to be incorrect. This commit corrects the ULPI_UTMI_SEL bit setting to match the datasheet's description. Referencing the kernel's code [2] also confirms this fix. [1] https://rockchip.fr/RK312X%20TRM/chapter-26-usb-otg-2-0.pdf#page=30 [2] https://github.com/torvalds/linux/blob/v6.13-rc3/drivers/usb/dwc2/core.c#L1106 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-2-987f4fd6f8b2@pigmoral.tech Signed-off-by: Mattijs Korpershoek --- diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index b6c8b3d5a6b..609de18faa3 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -402,20 +402,22 @@ static void dwc_otg_core_init(struct udevice *dev) * soft reset so only program the first time. Do a soft reset * immediately after setting phyif. */ - usbcfg &= ~(DWC2_GUSBCFG_ULPI_UTMI_SEL | DWC2_GUSBCFG_PHYIF); - usbcfg |= DWC2_PHY_TYPE << DWC2_GUSBCFG_ULPI_UTMI_SEL_OFFSET; - - if (usbcfg & DWC2_GUSBCFG_ULPI_UTMI_SEL) { /* ULPI interface */ +#if (DWC2_PHY_TYPE == DWC2_PHY_TYPE_ULPI) + usbcfg |= DWC2_GUSBCFG_ULPI_UTMI_SEL; + usbcfg &= ~DWC2_GUSBCFG_PHYIF; #ifdef DWC2_PHY_ULPI_DDR - usbcfg |= DWC2_GUSBCFG_DDRSEL; + usbcfg |= DWC2_GUSBCFG_DDRSEL; #else - usbcfg &= ~DWC2_GUSBCFG_DDRSEL; -#endif - } else { /* UTMI+ interface */ + usbcfg &= ~DWC2_GUSBCFG_DDRSEL; +#endif /* DWC2_PHY_ULPI_DDR */ +#elif (DWC2_PHY_TYPE == DWC2_PHY_TYPE_UTMI) + usbcfg &= ~DWC2_GUSBCFG_ULPI_UTMI_SEL; #if (DWC2_UTMI_WIDTH == 16) - usbcfg |= DWC2_GUSBCFG_PHYIF; -#endif - } + usbcfg |= DWC2_GUSBCFG_PHYIF; +#else + usbcfg &= ~DWC2_GUSBCFG_PHYIF; +#endif /* DWC2_UTMI_WIDTH */ +#endif /* DWC2_PHY_TYPE */ writel(usbcfg, ®s->global_regs.gusbcfg);