git: 0e87f58bd7e5 - main - usb/dwc3: Read the full IDs/version

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Wed, 16 Nov 2022 10:58:40 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=0e87f58bd7e566d2b7d50cf0ab636e745af591fc

commit 0e87f58bd7e566d2b7d50cf0ab636e745af591fc
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2022-11-15 10:22:23 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2022-11-16 10:58:31 +0000

    usb/dwc3: Read the full IDs/version
    
    We need to enable some quirks based on the version so read it.
    
    Reviewed by:    andrew
    Differential Revision:  https://reviews.freebsd.org/D37393
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
---
 sys/dev/usb/controller/dwc3.c | 30 ++++++++++++++++++++++++++++--
 sys/dev/usb/controller/dwc3.h | 12 ++++++++++++
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/sys/dev/usb/controller/dwc3.c b/sys/dev/usb/controller/dwc3.c
index eaea4d57a764..40405927685e 100644
--- a/sys/dev/usb/controller/dwc3.c
+++ b/sys/dev/usb/controller/dwc3.c
@@ -86,6 +86,9 @@ struct snps_dwc3_softc {
 	bus_space_tag_t		bst;
 	bus_space_handle_t	bsh;
 	uint32_t		snpsid;
+	uint32_t		snpsversion;
+	uint32_t		snpsrevision;
+	uint32_t		snpsversion_type;
 #ifdef FDT
 	clk_t			clk_ref;
 	clk_t			clk_suspend;
@@ -389,8 +392,31 @@ snps_dwc3_common_attach(device_t dev, bool is_fdt)
 	sc->bsh = rman_get_bushandle(sc->mem_res);
 
 	sc->snpsid = DWC3_READ(sc, DWC3_GSNPSID);
-	if (bootverbose)
-		device_printf(sc->dev, "snps id: %#012x\n", sc->snpsid);
+	sc->snpsversion = DWC3_VERSION(sc->snpsid);
+	sc->snpsrevision = DWC3_REVISION(sc->snpsid);
+	if (sc->snpsversion == DWC3_1_IP_ID ||
+	    sc->snpsversion == DWC3_2_IP_ID) {
+		sc->snpsrevision = DWC3_READ(sc, DWC3_1_VER_NUMBER);
+		sc->snpsversion_type = DWC3_READ(sc, DWC3_1_VER_TYPE);
+	}
+	if (bootverbose) {
+		switch (sc->snpsversion) {
+		case DWC3_IP_ID:
+			device_printf(sc->dev, "SNPS Version: DWC3 (%x %x)\n",
+			    sc->snpsversion, sc->snpsrevision);
+			break;
+		case DWC3_1_IP_ID:
+			device_printf(sc->dev, "SNPS Version: DWC3.1 (%x %x %x)\n",
+			    sc->snpsversion, sc->snpsrevision,
+			    sc->snpsversion_type);
+			break;
+		case DWC3_2_IP_ID:
+			device_printf(sc->dev, "SNPS Version: DWC3.2 (%x %x %x)\n",
+			    sc->snpsversion, sc->snpsrevision,
+			    sc->snpsversion_type);
+			break;
+		}
+	}
 #ifdef DWC3_DEBUG
 	snps_dwc3_dump_ctrlparams(sc);
 #endif
diff --git a/sys/dev/usb/controller/dwc3.h b/sys/dev/usb/controller/dwc3.h
index 21a87a1917ee..c69672072209 100644
--- a/sys/dev/usb/controller/dwc3.h
+++ b/sys/dev/usb/controller/dwc3.h
@@ -31,6 +31,15 @@
 #ifndef _DWC3_H_
 #define	_DWC3_H_
 
+#define	DWC3_IP_ID		0x5533
+#define	DWC3_1_IP_ID		0x3331
+#define	DWC3_2_IP_ID		0x3332
+
+#define	DWC3_VERSION_MASK	0xFFFF0000
+#define	DWC3_REVISION_MASK	0xFFFF
+#define	DWC3_VERSION(x)		(((x) & DWC3_VERSION_MASK) >> 16)
+#define	DWC3_REVISION(x)	((x) & DWC3_REVISION_MASK)
+
 #define	DWC3_GSBUSCFG0		0xc100
 #define	DWC3_GSBUSCFG1		0xc104
 #define	DWC3_GTXTHRCFG		0xc108
@@ -80,6 +89,9 @@
 #define	DWC3_GPRTBIMAP_HSLO	0xc180
 #define	DWC3_GPRTBIMAP_FSLO	0xc188
 
+#define	DWC3_1_VER_NUMBER	0xc1a0
+#define	DWC3_1_VER_TYPE		0xc1a4
+
 #define	DWC3_GUSB2PHYCFG0	0xc200
 #define	 DWC3_GUSB2PHYCFG0_PHYSOFTRST		(1 << 31)
 #define	 DWC3_GUSB2PHYCFG0_U2_FREECLK_EXISTS	(1 << 30)