[U-Boot] [PATCH 32/70] serial: powerpc: Implement CONFIG_SERIAL_MULTI into bmw serial driver

Marek Vasut
2012-09-29T00:30:49Z

Implement support for CONFIG_SERIAL_MULTI into bmw 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 bmw driver. Also, add a weak implementation
of default_serial_console() returning this driver.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Marek Vasut <marek.vasut@gmail.com>
Cc: Tom Rini <trini@ti.com>
Cc: Anatolij Gustschin <agust@denx.de>
Cc: Stefan Roese <sr@denx.de>
---
board/bmw/serial.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++-----
common/serial.c | 2 ++
2 files changed, 64 insertions(+), 6 deletions(-)

diff --git a/board/bmw/serial.c b/board/bmw/serial.c
index 0c97f12..569131f 100644
--- a/board/bmw/serial.c
+++ b/board/bmw/serial.c
@@ -22,6 +22,9 @@
*/

#include <common.h>
+#include <serial.h>
+#include <linux/compiler.h>
+
#include "ns16550.h"

DECLARE_GLOBAL_DATA_PTR;
@@ -38,7 +41,7 @@ static struct NS16550 *console =

extern ulong get_bus_freq (ulong);

-int serial_init (void)
+static int bmw_serial_init(void)
{
int clock_divisor = gd->bus_clk / 16 / gd->baudrate;

@@ -47,7 +50,7 @@ int serial_init (void)
return (0);
}

-void serial_putc (const char c)
+static void bmw_serial_putc(const char c)
{
if (c == '\n') {
serial_putc ('\r');
@@ -55,7 +58,7 @@ void serial_putc (const char c)
NS16550_putc (console, c);
}

-void serial_puts (const char *s)
+static void bmw_serial_puts(const char *s)
{
while (*s) {
serial_putc (*s++);
@@ -63,19 +66,72 @@ void serial_puts (const char *s)
}

-int serial_getc (void)
+static int bmw_serial_getc(void)
{
return NS16550_getc (console);
}

-int serial_tstc (void)
+static int bmw_serial_tstc(void)
{
return NS16550_tstc (console);
}

-void serial_setbrg (void)
+static void bmw_serial_setbrg(void)
{
int clock_divisor = get_bus_freq (0) / 16 / gd->baudrate;

NS16550_reinit (console, clock_divisor);
}
+
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device bmw_serial_drv = {
+ .name = "bmw_serial",
+ .start = bmw_serial_init,
+ .stop = NULL,
+ .setbrg = bmw_serial_setbrg,
+ .putc = bmw_serial_putc,
+ .puts = bmw_serial_puts,
+ .getc = bmw_serial_getc,
+ .tstc = bmw_serial_tstc,
+};
+
+void bmw_serial_initialize(void)
+{
+ serial_register(&bmw_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+ return &bmw_serial_drv;
+}
+#else
+int serial_init(void)
+{
+ return bmw_serial_init();
+}
+
+void serial_setbrg(void)
+{
+ bmw_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+ bmw_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+ bmw_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+ return bmw_serial_getc();
+}
+
+int serial_tstc(void)
+{
+ return bmw_serial_tstc();
+}
+#endif
diff --git a/common/serial.c b/common/serial.c
index 6a09139..19d3a6f 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -62,6 +62,7 @@ serial_initfunc(leon2_serial_initialize);
serial_initfunc(leon3_serial_initialize);
serial_initfunc(marvell_serial_initialize);
serial_initfunc(amirix_serial_initialize);
+serial_initfunc(bmw_serial_initialize);

void serial_register(struct serial_device *dev)
{
@@ -102,6 +103,7 @@ void serial_initialize(void)
leon3_serial_initialize();
marvell_serial_initialize();
amirix_serial_initialize();
+ bmw_serial_initialize();

serial_assign(default_serial_console()->name);
}
--
1.7.10.4