public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Junhui Liu <junhui.liu@pigmoral.tech>
To: Tom Rini <trini@konsulko.com>, Marek Vasut <marex@denx.de>,
	 Lukasz Majewski <lukma@denx.de>,
	 Mattijs Korpershoek <mkorpershoek@baylibre.com>
Cc: u-boot@lists.denx.de, seashell11234455@gmail.com,
	pbrobinson@gmail.com,  junhui.liu@pigmoral.tech
Subject: [PATCH v3 2/8] usb: dwc2: Fix incorrect ULPI_UTMI_SEL bit setting
Date: Sat, 04 Jan 2025 11:37:16 +0800	[thread overview]
Message-ID: <20250104-dwc2-dev-v3-2-d4b2bc1996e4@pigmoral.tech> (raw)
In-Reply-To: <20250104-dwc2-dev-v3-0-d4b2bc1996e4@pigmoral.tech>

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 <marex@denx.de>
Tested-by: Peter Robinson <pbrobinson@gmail.com>
Signed-off-by: Junhui Liu <junhui.liu@pigmoral.tech>
---
 drivers/usb/host/dwc2.c | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c
index b6c8b3d5a6bdf375f1adeb106d4832d92307f0db..609de18faa3abc5f4ecb0c23cf3590966bad7992 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, &regs->global_regs.gusbcfg);
 

-- 
2.47.1


  parent reply	other threads:[~2025-01-04 13:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-04  3:37 [PATCH v3 0/8] usb: dwc2: Refactor and update USB DWC2 driver Junhui Liu
2025-01-04  3:37 ` [PATCH v3 1/8] usb: dwc2: Extract register definitions to common header file Junhui Liu
2025-01-07  9:03   ` Mattijs Korpershoek
2025-01-04  3:37 ` Junhui Liu [this message]
2025-01-07  9:11   ` [PATCH v3 2/8] usb: dwc2: Fix incorrect ULPI_UTMI_SEL bit setting Mattijs Korpershoek
2025-01-04  3:37 ` [PATCH v3 3/8] USB: dwc2: Fix HBstLen setting for external DMA mode Junhui Liu
2025-01-07  9:16   ` Mattijs Korpershoek
2025-01-04  3:37 ` [PATCH v3 4/8] usb: dwc2: Clean up with bitfield macros Junhui Liu
2025-01-05 19:14   ` Marek Vasut
2025-01-07  9:22   ` Mattijs Korpershoek
2025-01-04  3:37 ` [PATCH v3 5/8] usb: dwc2: Align macros with Linux kernel definitions Junhui Liu
2025-01-07  9:26   ` Mattijs Korpershoek
2025-01-04  3:37 ` [PATCH v3 6/8] usb: dwc2: Extract macro definitions to common header Junhui Liu
2025-01-07  9:55   ` Mattijs Korpershoek
2025-01-07 12:52     ` Junhui Liu
2025-01-04  3:37 ` [PATCH v3 7/8] usb: dwc2: Unify flush and reset logic with v4.20a support Junhui Liu
2025-01-05 19:19   ` Marek Vasut
2025-01-06  9:14     ` Junhui Liu
2025-01-06 15:37       ` Marek Vasut
2025-01-07 12:39         ` Junhui Liu
2025-01-07 12:57           ` Marek Vasut
2025-01-04  3:37 ` [PATCH v3 8/8] usb: dwc2: Replace uint<x>_t types with u<x> Junhui Liu
2025-01-07  9:47 ` [PATCH v3 0/8] usb: dwc2: Refactor and update USB DWC2 driver Mattijs Korpershoek
2025-01-07 12:44   ` Junhui Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250104-dwc2-dev-v3-2-d4b2bc1996e4@pigmoral.tech \
    --to=junhui.liu@pigmoral.tech \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=mkorpershoek@baylibre.com \
    --cc=pbrobinson@gmail.com \
    --cc=seashell11234455@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox