ad36d48
From 1a8fa60aedff8a2368ac357a51dc15357065fabe Mon Sep 17 00:00:00 2001
ad36d48
From: Peter Robinson <pbrobinson@gmail.com>
ad36d48
Date: Tue, 5 Dec 2017 00:11:54 +0000
ad36d48
Subject: [PATCH 3/5] usb kbd fixes
262b414
ad36d48
Signed-off-by: Peter Robinson <pbrobinson@gmail.com>
262b414
---
ad36d48
 common/usb_kbd.c  | 66 +++++++++++++++++++++++++++++++++++++++++--------------
262b414
 include/console.h |  2 --
ad36d48
 2 files changed, 50 insertions(+), 18 deletions(-)
262b414
262b414
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
ad36d48
index 8cbdba6ac2..82ad93f6ca 100644
262b414
--- a/common/usb_kbd.c
262b414
+++ b/common/usb_kbd.c
ad36d48
@@ -516,25 +516,59 @@ static int probe_usb_keyboard(struct usb_device *dev)
262b414
 		return error;
262b414
 
262b414
 	stdinname = env_get("stdin");
262b414
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
262b414
-	error = iomux_doenv(stdin, stdinname);
262b414
-	if (error)
262b414
-		return error;
262b414
-#else
262b414
-	/* Check if this is the standard input device. */
262b414
-	if (strcmp(stdinname, DEVNAME))
262b414
-		return 1;
262b414
+	if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
262b414
+		char *devname = DEVNAME;
262b414
+		char *newstdin = NULL;
262b414
+		/*
262b414
+		 * stdin might not be set yet.. either way, with console-
262b414
+		 * mux the sensible thing to do is add ourselves to the
262b414
+		 * list of stdio devices:
262b414
+		 */
262b414
+		if (stdinname && !strstr(stdinname, DEVNAME)) {
262b414
+			newstdin = malloc(strlen(stdinname) +
262b414
+					strlen(","DEVNAME) + 1);
262b414
+			sprintf(newstdin, "%s,"DEVNAME, stdinname);
262b414
+			stdinname = newstdin;
262b414
+		} else if (!stdinname) {
262b414
+			stdinname = devname;
262b414
+		}
262b414
+		error = iomux_doenv(stdin, stdinname);
262b414
+		free(newstdin);
262b414
+		if (error)
ad36d48
+			goto unregister_stdio;
262b414
+	} else {
262b414
+		/* Check if this is the standard input device. */
ad36d48
+		if (strcmp(stdinname, DEVNAME)) {
ad36d48
+			error = -1;
ad36d48
+			goto unregister_stdio;
ad36d48
+		}
262b414
 
262b414
-	/* Reassign the console */
262b414
-	if (overwrite_console())
262b414
-		return 1;
262b414
+		/* Reassign the console */
ad36d48
+		if (overwrite_console()) {
ad36d48
+			error = -1;
ad36d48
+			goto unregister_stdio;
ad36d48
+		}
262b414
 
262b414
-	error = console_assign(stdin, DEVNAME);
262b414
-	if (error)
262b414
-		return error;
262b414
-#endif
262b414
+		error = console_assign(stdin, DEVNAME);
262b414
+		if (error)
262b414
+			goto unregister_stdio;
ad36d48
+	}
262b414
+
ad36d48
+	return 0;
ad36d48
 
262b414
+unregister_stdio:
262b414
+	/*
262b414
+	 * If probe fails, the device will be removed.. leaving dangling
262b414
+	 * pointers if the stdio device is not unregistered.  If u-boot
262b414
+	 * is built without stdio_deregister(), just pretend to succeed
262b414
+	 * in order to avoid dangling pointers.
262b414
+	 */
262b414
+#if CONFIG_IS_ENABLED(SYS_STDIO_DEREGISTER)
262b414
+	stdio_deregister(DEVNAME, 1);
262b414
+	return error;
262b414
+#else
ad36d48
 	return 0;
262b414
+#endif
262b414
 }
262b414
 
262b414
 #ifndef CONFIG_DM_USB
ad36d48
@@ -640,7 +674,7 @@ static int usb_kbd_remove(struct udevice *dev)
d1eb73c
 
d1eb73c
 	return 0;
d1eb73c
 err:
d1eb73c
-	printf("%s: warning, ret=%d", __func__, ret);
d1eb73c
+	printf("%s: warning, ret=%d\n", __func__, ret);
d1eb73c
 	return ret;
d1eb73c
 }
d1eb73c
 
ad36d48
diff --git a/include/console.h b/include/console.h
ad36d48
index cea29ed6dc..7dfd36d7d1 100644
ad36d48
--- a/include/console.h
ad36d48
+++ b/include/console.h
ad36d48
@@ -57,8 +57,6 @@ int console_announce_r(void);
ad36d48
 /*
ad36d48
  * CONSOLE multiplexing.
ad36d48
  */
ad36d48
-#ifdef CONFIG_CONSOLE_MUX
ad36d48
 #include <iomux.h>
ad36d48
-#endif
ad36d48
 
ad36d48
 #endif
d1eb73c
-- 
ad36d48
2.14.3
ad36d48