Lock windcharger console input based on booting cmdline

Windcharger Port of
https://gfiber.googlesource.com/kernel/bruno/+/0f13018778de6540bf71b49c1ec777d4eb4a5485%5E%5E1%5E%5E1%5E!/

Change-Id: I878cede292959410445588e1a8c81fcd38ba6d5f
diff --git a/arch/mips/ath79/prom.c b/arch/mips/ath79/prom.c
index 2102df8..5a9b4d9 100644
--- a/arch/mips/ath79/prom.c
+++ b/arch/mips/ath79/prom.c
@@ -20,8 +20,14 @@
 
 #include "common.h"
 
+static int windcharger_lock_console_in = 1;
+
 static char ath79_cmdline_buf[COMMAND_LINE_SIZE] __initdata;
 
+int lock_console_in(void) {
+	return windcharger_lock_console_in;
+}
+
 static inline int is_valid_ram_addr(void *addr)
 {
 	if (((u32) addr > KSEG0) &&
@@ -184,6 +190,10 @@
 	if (strstr(arcs_cmdline, "board=750Gr3") ||
 	    strstr(arcs_cmdline, "board=2011L"))
 		ath79_prom_append_cmdline("console", "ttyS0,115200");
+
+	if (strstr(arcs_cmdline, "login=1") || strstr(arcs_cmdline, "debug=1")) {
+		windcharger_lock_console_in = 0;
+	}
 }
 
 void __init prom_free_prom_memory(void)
diff --git a/drivers/tty/serial/8250/8250.c b/drivers/tty/serial/8250/8250.c
index 0e2c703..4dfdecd 100644
--- a/drivers/tty/serial/8250/8250.c
+++ b/drivers/tty/serial/8250/8250.c
@@ -48,6 +48,10 @@
 #include "../suncore.h"
 #endif
 
+#ifdef CONFIG_ATH79_MACH_GF_WINDCHARGER
+#include "linux/ath79.h"
+#endif
+
 /*
  * Configuration:
  *   share_irqs - whether we pass IRQF_SHARED to request_irq().  This option
@@ -1419,6 +1423,11 @@
 				if (up->port.type == PORT_TEGRA)
 					clear_rx_fifo(up);
 
+#ifdef CONFIG_ATH79_MACH_GF_WINDCHARGER
+				if (lock_console_in()) {
+					goto ignore_char;
+				}
+#endif
 				/*
 				 * We do the SysRQ and SAK checking
 				 * here because otherwise the break
@@ -1447,6 +1456,12 @@
 			else if (lsr & UART_LSR_FE)
 				flag = TTY_FRAME;
 		}
+
+#ifdef CONFIG_ATH79_MACH_GF_WINDCHARGER
+		if (lock_console_in()) {
+			goto ignore_char;
+		}
+#endif
 		if (uart_handle_sysrq_char(&up->port, ch))
 			goto ignore_char;
 
diff --git a/include/linux/ath79.h b/include/linux/ath79.h
new file mode 100644
index 0000000..7f94d33
--- /dev/null
+++ b/include/linux/ath79.h
@@ -0,0 +1,14 @@
+/*
+ * include/linux/ath79.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _LINUX_ATH79_H_
+#define _LINUX_ATH79_H_
+
+int lock_console_in(void);
+
+#endif  /* _LINUX_ATH79_H */