[U-Boot] [PATCH 53/71] serial: arm: Implement CONFIG_SERIAL_MULTI into lh7a40x serial driver

Marek Vasut marex at denx.de
Mon Sep 17 01:21:18 CEST 2012


Implement support for CONFIG_SERIAL_MULTI into lh7a40x 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 lh7a40x 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_lh7a40x.c |   66 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 61 insertions(+), 7 deletions(-)

diff --git a/common/serial.c b/common/serial.c
index 21c8ac3..59a8650 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -83,6 +83,7 @@ serial_initfunc(clps7111_serial_initialize);
 serial_initfunc(imx_serial_initialize);
 serial_initfunc(ixp_serial_initialize);
 serial_initfunc(ks8695_serial_initialize);
+serial_initfunc(lh7a40x_serial_initialize);
 
 void serial_register(struct serial_device *dev)
 {
@@ -144,6 +145,7 @@ void serial_initialize(void)
 	imx_serial_initialize();
 	ixp_serial_initialize();
 	ks8695_serial_initialize();
+	lh7a40x_serial_initialize();
 
 	serial_assign(default_serial_console()->name);
 }
diff --git a/drivers/serial/serial_lh7a40x.c b/drivers/serial/serial_lh7a40x.c
index 4767489..6b73606 100644
--- a/drivers/serial/serial_lh7a40x.c
+++ b/drivers/serial/serial_lh7a40x.c
@@ -33,7 +33,7 @@ DECLARE_GLOBAL_DATA_PTR;
 # error "No console configured ... "
 #endif
 
-void serial_setbrg (void)
+static void lh7a40x_serial_setbrg(void)
 {
 	lh7a40x_uart_t* uart = LH7A40X_UART_PTR(UART_CONSOLE);
 	int i;
@@ -61,7 +61,7 @@ void serial_setbrg (void)
  * are always 8 data bits, no parity, 1 stop bit, no start bits.
  *
  */
-int serial_init (void)
+static int lh7a40x_serial_init(void)
 {
 	lh7a40x_uart_t* uart = LH7A40X_UART_PTR(UART_CONSOLE);
 
@@ -95,7 +95,7 @@ int serial_init (void)
  * otherwise. When the function is succesfull, the character read is
  * written into its argument c.
  */
-int serial_getc (void)
+static int lh7a40x_serial_getc(void)
 {
 	lh7a40x_uart_t* uart = LH7A40X_UART_PTR(UART_CONSOLE);
 
@@ -141,7 +141,7 @@ void enable_putc(void)
 /*
  * Output a single byte to the serial port.
  */
-void serial_putc (const char c)
+static void lh7a40x_serial_putc(const char c)
 {
 	lh7a40x_uart_t* uart = LH7A40X_UART_PTR(UART_CONSOLE);
 
@@ -168,17 +168,69 @@ void serial_putc (const char c)
 /*
  * Test whether a character is in the RX buffer
  */
-int serial_tstc (void)
+static int lh7a40x_serial_tstc(void)
 {
 	lh7a40x_uart_t* uart = LH7A40X_UART_PTR(UART_CONSOLE);
 
 	return(!(uart->status & UART_RXFE));
 }
 
-void
-serial_puts (const char *s)
+static void lh7a40x_serial_puts(const char *s)
 {
 	while (*s) {
 		serial_putc (*s++);
 	}
 }
+
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device lh7a40x_serial_drv = {
+	.name	= "lh7a40x_serial",
+	.start	= lh7a40x_serial_init,
+	.stop	= NULL,
+	.setbrg	= lh7a40x_serial_setbrg,
+	.putc	= lh7a40x_serial_putc,
+	.puts	= lh7a40x_serial_puts,
+	.getc	= lh7a40x_serial_getc,
+	.tstc	= lh7a40x_serial_tstc,
+};
+
+void lh7a40x_serial_initialize(void)
+{
+	serial_register(&lh7a40x_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return &lh7a40x_serial_drv;
+}
+#else
+int serial_init(void)
+{
+	return lh7a40x_serial_init();
+}
+
+void serial_setbrg(void)
+{
+	lh7a40x_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+	lh7a40x_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+	lh7a40x_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+	return lh7a40x_serial_getc();
+}
+
+int serial_tstc(void)
+{
+	return lh7a40x_serial_tstc();
+}
+#endif
-- 
1.7.10.4



More information about the U-Boot mailing list