[U-Boot] [PATCH] powerpc/usb: fix usb mode and phy_type

Shaohui Xie Shaohui.Xie at freescale.com
Fri Nov 4 09:48:23 CET 2011


Currently, to make usb work as different modes, we need to set its' dr_mode
string in 'hwconfig', and it will be handled by fdt_fixup_usb_mode_phy_type().
This API has a hardcoded compat which is "fsl-usb2-dr", so it should not
be called when handle the 'hwconfig' for 'usb1', 'usb1' has a compat of
"fsl-usb2-mph" in dts, otherwise, dr_mode of 'usb2' will be set when handling
'usb1', and this will cause error when handling 'usb2'.

Also, sometimes "phy_type" may need to be set for both USB controllers,
hardcoded compat is limited to handle this, so add compat "fsl-usb2-mph"
handle in the API.

Signed-off-by: Shaohui Xie <Shaohui.Xie at freescale.com>
---
 arch/powerpc/cpu/mpc8xxx/fdt.c |   40 +++++++++++++++++++---------------------
 1 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8xxx/fdt.c b/arch/powerpc/cpu/mpc8xxx/fdt.c
index 112c603..a2b56ae 100644
--- a/arch/powerpc/cpu/mpc8xxx/fdt.c
+++ b/arch/powerpc/cpu/mpc8xxx/fdt.c
@@ -88,9 +88,9 @@ void ft_fixup_num_cores(void *blob) {
 
 #ifdef CONFIG_HAS_FSL_DR_USB
 static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
-				const char *phy_type)
+				const char *phy_type, int port)
 {
-	const char *compat = "fsl-usb2-dr";
+	const char *compat[] = {"fsl-usb2-mph", "fsl-usb2-dr"};
 	const char *prop_mode = "dr_mode";
 	const char *prop_type = "phy_type";
 	static int start_offset = -1;
@@ -98,27 +98,27 @@ static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
 	int err;
 
 	node_offset = fdt_node_offset_by_compatible(blob,
-			start_offset, compat);
+			start_offset, compat[port]);
 	if (node_offset < 0) {
 		printf("WARNING: could not find compatible node %s: %s.\n",
-			compat, fdt_strerror(node_offset));
+			compat[port], fdt_strerror(node_offset));
 		return;
 	}
 
-	if (mode) {
+	if (strlen(mode)) {
 		err = fdt_setprop(blob, node_offset, prop_mode, mode,
 				  strlen(mode) + 1);
 		if (err < 0)
 			printf("WARNING: could not set %s for %s: %s.\n",
-			       prop_mode, compat, fdt_strerror(err));
+			       prop_mode, compat[port], fdt_strerror(err));
 	}
 
-	if (phy_type) {
+	if (strlen(phy_type)) {
 		err = fdt_setprop(blob, node_offset, prop_type, phy_type,
 				  strlen(phy_type) + 1);
 		if (err < 0)
 			printf("WARNING: could not set %s for %s: %s.\n",
-			       prop_type, compat, fdt_strerror(err));
+			       prop_type, compat[port], fdt_strerror(err));
 	}
 
 	start_offset = node_offset;
@@ -126,8 +126,8 @@ static void fdt_fixup_usb_mode_phy_type(void *blob, const char *mode,
 
 void fdt_fixup_dr_usb(void *blob, bd_t *bd)
 {
-	const char *modes[] = { "host", "peripheral", "otg" };
-	const char *phys[] = { "ulpi", "umti" };
+	const char *modes[] = { "", "host", "peripheral", "otg" };
+	const char *phys[] = { "", "ulpi", "umti" };
 	const char *mode = NULL;
 	const char *phy_type = NULL;
 	char usb1_defined = 0;
@@ -135,7 +135,7 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd)
 	int i, j;
 
 	for (i = 1; i <= FSL_MAX_NUM_USB_CTRLS; i++) {
-		int mode_idx = -1, phy_idx = -1;
+		int mode_idx = 0, phy_idx = 0;
 		sprintf(str, "%s%d", "usb", i);
 		if (hwconfig(str)) {
 			for (j = 0; j < sizeof(modes); j++) {
@@ -152,16 +152,14 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd)
 					break;
 				}
 			}
-			if (mode_idx >= 0)
-				fdt_fixup_usb_mode_phy_type(blob,
-					modes[mode_idx], NULL);
-			if (phy_idx >= 0)
-				fdt_fixup_usb_mode_phy_type(blob,
-					NULL, phys[phy_idx]);
-			if (!strcmp(str, "usb1"))
-				usb1_defined = 1;
-			if (mode_idx < 0 && phy_idx < 0)
+			if (!mode_idx && !phy_idx) {
 				printf("WARNING: invalid phy or mode\n");
+			} else {
+				fdt_fixup_usb_mode_phy_type(blob,
+					modes[mode_idx], phys[phy_idx], i - 1);
+				if (!strcmp(str, "usb1"))
+					usb1_defined = 1;
+			}
 		}
 	}
 	if (!usb1_defined) {
@@ -169,7 +167,7 @@ void fdt_fixup_dr_usb(void *blob, bd_t *bd)
 		phy_type = getenv("usb_phy_type");
 		if (!mode && !phy_type)
 			return;
-		fdt_fixup_usb_mode_phy_type(blob, mode, phy_type);
+		fdt_fixup_usb_mode_phy_type(blob, modes[1], phys[1], 0);
 	}
 }
 #endif /* CONFIG_HAS_FSL_DR_USB */
-- 
1.6.4




More information about the U-Boot mailing list