[U-Boot] [PATCH 52/72] serial: arm: Implement CONFIG_SERIAL_MULTI into ks8695 serial driver

Marek Vasut marex at denx.de
Sat Sep 29 23:52:45 CEST 2012


Implement support for CONFIG_SERIAL_MULTI into ks8695 serial driver.
This driver was so far only usable directly, but this patch also adds
support for the multi method. This allows using more than one serial
driver alongside the ks8695 driver. Also, add a weak implementation
of default_serial_console() returning this driver.

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Marek Vasut <marek.vasut at gmail.com>
Cc: Tom Rini <trini at ti.com>
---
 common/serial.c                |    2 ++
 drivers/serial/serial_ks8695.c |   73 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 66 insertions(+), 9 deletions(-)

diff --git a/common/serial.c b/common/serial.c
index 3d8fa7f..21c8ac3 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -82,6 +82,7 @@ serial_initfunc(sandbox_serial_initialize);
 serial_initfunc(clps7111_serial_initialize);
 serial_initfunc(imx_serial_initialize);
 serial_initfunc(ixp_serial_initialize);
+serial_initfunc(ks8695_serial_initialize);
 
 void serial_register(struct serial_device *dev)
 {
@@ -142,6 +143,7 @@ void serial_initialize(void)
 	clps7111_serial_initialize();
 	imx_serial_initialize();
 	ixp_serial_initialize();
+	ks8695_serial_initialize();
 
 	serial_assign(default_serial_console()->name);
 }
diff --git a/drivers/serial/serial_ks8695.c b/drivers/serial/serial_ks8695.c
index aacd1be..b3af388 100644
--- a/drivers/serial/serial_ks8695.c
+++ b/drivers/serial/serial_ks8695.c
@@ -20,6 +20,8 @@
 
 #include <common.h>
 #include <asm/arch/platform.h>
+#include <serial.h>
+#include <linux/compiler.h>
 
 #ifndef CONFIG_SERIAL1
 #error "Bad: you didn't configure serial ..."
@@ -54,7 +56,7 @@ struct ks8695uart {
 int serial_console = 1;
 
 
-void serial_setbrg(void)
+static void ks8695_serial_setbrg(void)
 {
 	volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
 
@@ -63,14 +65,14 @@ void serial_setbrg(void)
 	uartp->LCR = KS8695_UART_LINEC_WLEN8;
 }
 
-int serial_init(void)
+static int ks8695_serial_init(void)
 {
 	serial_console = 1;
 	serial_setbrg();
 	return 0;
 }
 
-void serial_raw_putc(const char c)
+static void ks8695_serial_raw_putc(const char c)
 {
 	volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
 	int i;
@@ -83,16 +85,16 @@ void serial_raw_putc(const char c)
 	uartp->TX = c;
 }
 
-void serial_putc(const char c)
+static void ks8695_serial_putc(const char c)
 {
 	if (serial_console) {
-		serial_raw_putc(c);
+		ks8695_serial_raw_putc(c);
 		if (c == '\n')
-			serial_raw_putc('\r');
+			ks8695_serial_raw_putc('\r');
 	}
 }
 
-int serial_tstc(void)
+static int ks8695_serial_tstc(void)
 {
 	volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
 	if (serial_console)
@@ -100,14 +102,14 @@ int serial_tstc(void)
 	return 0;
 }
 
-void serial_puts(const char *s)
+static void ks8695_serial_puts(const char *s)
 {
 	char c;
 	while ((c = *s++) != 0)
 		serial_putc(c);
 }
 
-int serial_getc(void)
+static int ks8695_serial_getc(void)
 {
 	volatile struct ks8695uart *uartp = KS8695_UART_ADDR;
 
@@ -115,3 +117,56 @@ int serial_getc(void)
 		;
 	return (uartp->RX);
 }
+
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device ks8695_serial_drv = {
+	.name	= "ks8695_serial",
+	.start	= ks8695_serial_init,
+	.stop	= NULL,
+	.setbrg	= ks8695_serial_setbrg,
+	.putc	= ks8695_serial_putc,
+	.puts	= ks8695_serial_puts,
+	.getc	= ks8695_serial_getc,
+	.tstc	= ks8695_serial_tstc,
+};
+
+void ks8695_serial_initialize(void)
+{
+	serial_register(&ks8695_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return &ks8695_serial_drv;
+}
+#else
+int serial_init(void)
+{
+	return ks8695_serial_init();
+}
+
+void serial_setbrg(void)
+{
+	ks8695_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+	ks8695_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+	ks8695_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+	return ks8695_serial_getc();
+}
+
+int serial_tstc(void)
+{
+	return ks8695_serial_tstc();
+}
+#endif
-- 
1.7.10.4



More information about the U-Boot mailing list