[U-Boot] [PATCH 33/72] serial: powerpc: Implement CONFIG_SERIAL_MULTI into cogent serial driver

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


Implement support for CONFIG_SERIAL_MULTI into cogent 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 cogent 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>
Cc: Anatolij Gustschin <agust at denx.de>
Cc: Stefan Roese <sr at denx.de>
---
 board/cogent/serial.c |   66 ++++++++++++++++++++++++++++++++++++++++++++-----
 common/serial.c       |    2 ++
 2 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/board/cogent/serial.c b/board/cogent/serial.c
index d9c27be..18a9dbf 100644
--- a/board/cogent/serial.c
+++ b/board/cogent/serial.c
@@ -5,6 +5,8 @@
 
 #include <common.h>
 #include <board/cogent/serial.h>
+#include <serial.h>
+#include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -25,7 +27,7 @@ DECLARE_GLOBAL_DATA_PTR;
 #error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial
 #endif
 
-int serial_init (void)
+static int cogent_serial_init(void)
 {
 	cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
 
@@ -38,7 +40,7 @@ int serial_init (void)
 	return (0);
 }
 
-void serial_setbrg (void)
+static void cogent_serial_setbrg(void)
 {
 	cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
 	unsigned int divisor;
@@ -54,7 +56,7 @@ void serial_setbrg (void)
 	cma_mb_reg_write (&mbsp->ser_lcr, lcr);	/* unset DLAB */
 }
 
-void serial_putc (const char c)
+static void cogent_serial_putc(const char c)
 {
 	cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
 
@@ -66,13 +68,13 @@ void serial_putc (const char c)
 	cma_mb_reg_write (&mbsp->ser_thr, c);
 }
 
-void serial_puts (const char *s)
+static void cogent_serial_puts(const char *s)
 {
 	while (*s != '\0')
 		serial_putc (*s++);
 }
 
-int serial_getc (void)
+static int cogent_serial_getc(void)
 {
 	cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
 
@@ -81,13 +83,65 @@ int serial_getc (void)
 	return ((int) cma_mb_reg_read (&mbsp->ser_rhr) & 0x7f);
 }
 
-int serial_tstc (void)
+static int cogent_serial_tstc(void)
 {
 	cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
 
 	return ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) != 0);
 }
 
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device cogent_serial_drv = {
+	.name	= "cogent_serial",
+	.start	= cogent_serial_init,
+	.stop	= NULL,
+	.setbrg	= cogent_serial_setbrg,
+	.putc	= cogent_serial_putc,
+	.puts	= cogent_serial_puts,
+	.getc	= cogent_serial_getc,
+	.tstc	= cogent_serial_tstc,
+};
+
+void cogent_serial_initialize(void)
+{
+	serial_register(&cogent_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return &cogent_serial_drv;
+}
+#else
+int serial_init(void)
+{
+	return cogent_serial_init();
+}
+
+void serial_setbrg(void)
+{
+	cogent_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+	cogent_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+	cogent_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+	return cogent_serial_getc();
+}
+
+int serial_tstc(void)
+{
+	return cogent_serial_tstc();
+}
+#endif
 #endif /* CONS_NONE */
 
 #if defined(CONFIG_CMD_KGDB) && \
diff --git a/common/serial.c b/common/serial.c
index 19d3a6f..a51ce99 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -63,6 +63,7 @@ serial_initfunc(leon3_serial_initialize);
 serial_initfunc(marvell_serial_initialize);
 serial_initfunc(amirix_serial_initialize);
 serial_initfunc(bmw_serial_initialize);
+serial_initfunc(cogent_serial_initialize);
 
 void serial_register(struct serial_device *dev)
 {
@@ -104,6 +105,7 @@ void serial_initialize(void)
 	marvell_serial_initialize();
 	amirix_serial_initialize();
 	bmw_serial_initialize();
+	cogent_serial_initialize();
 
 	serial_assign(default_serial_console()->name);
 }
-- 
1.7.10.4



More information about the U-Boot mailing list