Module Name:    src
Committed By:   skrll
Date:           Sun Jun 12 08:04:07 UTC 2022

Modified Files:
        src/sys/dev/fdt: dwc3_fdt.c

Log Message:
Attach when dr_mode is "otg" and the controller has the "usb-role-switch" and
"role-switch-default-mode" as seen in the Apple M1 dts.

This assumes the controller is properly setup for host mode already.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/fdt/dwc3_fdt.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/dwc3_fdt.c
diff -u src/sys/dev/fdt/dwc3_fdt.c:1.19 src/sys/dev/fdt/dwc3_fdt.c:1.20
--- src/sys/dev/fdt/dwc3_fdt.c:1.19	Sun Nov  7 17:14:20 2021
+++ src/sys/dev/fdt/dwc3_fdt.c	Sun Jun 12 08:04:07 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $ */
+/* $NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.19 2021/11/07 17:14:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwc3_fdt.c,v 1.20 2022/06/12 08:04:07 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -256,9 +256,30 @@ dwc3_fdt_attach(device_t parent, device_
 		return;
 	}
 
-	/* Only host mode is supported */
+	/*
+	 * Only host mode is supported, but this includes otg devices
+	 * that have 'usb-role-switch' and 'role-switch-default-mode' of
+	 * 'host'
+	 */
 	const char *dr_mode = fdtbus_get_string(dwc3_phandle, "dr_mode");
-	if (dr_mode == NULL || strcmp(dr_mode, "host") != 0) {
+	if (dr_mode == NULL || strcmp(dr_mode, "otg") == 0) {
+		bool ok = false;
+		if (of_hasprop(dwc3_phandle, "usb-role-switch")) {
+			const char *rsdm = fdtbus_get_string(dwc3_phandle,
+			    "role-switch-default-mode");
+			if (rsdm != NULL && strcmp(rsdm, "host") == 0)
+				ok = true;
+
+			if (!ok) {
+				aprint_error(": host is not default mode\n");
+				return;
+			}
+		}
+		if (!ok) {
+			aprint_error(": cannot switch 'otg' mode to host\n");
+			return;
+		}
+	} else if (strcmp(dr_mode, "host") != 0) {
 		aprint_error(": '%s' not supported\n", dr_mode);
 		return;
 	}

Reply via email to