[U-Boot] [PATCH 24/72] serial: powerpc: Implement CONFIG_SERIAL_MULTI into mpc8220 serial driver

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


Implement support for CONFIG_SERIAL_MULTI into mpc8220 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 mpc8220 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>
---
 arch/powerpc/cpu/mpc8220/uart.c |   67 +++++++++++++++++++++++++++++++++++----
 common/serial.c                 |    2 ++
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/arch/powerpc/cpu/mpc8220/uart.c b/arch/powerpc/cpu/mpc8220/uart.c
index 0c4b536..545c81a 100644
--- a/arch/powerpc/cpu/mpc8220/uart.c
+++ b/arch/powerpc/cpu/mpc8220/uart.c
@@ -29,13 +29,15 @@
 
 #include <common.h>
 #include <mpc8220.h>
+#include <serial.h>
+#include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 #define PSC_BASE   MMAP_PSC1
 
 #if defined(CONFIG_PSC_CONSOLE)
-int serial_init (void)
+static int mpc8220_serial_init(void)
 {
 	volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
 	u32 counter;
@@ -69,7 +71,7 @@ int serial_init (void)
 	return (0);
 }
 
-void serial_putc (const char c)
+static void mpc8220_serial_putc(const char c)
 {
 	volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
 
@@ -82,14 +84,14 @@ void serial_putc (const char c)
 	psc->xmitbuf[0] = c;
 }
 
-void serial_puts (const char *s)
+static void mpc8220_serial_puts(const char *s)
 {
 	while (*s) {
 		serial_putc (*s++);
 	}
 }
 
-int serial_getc (void)
+static int mpc8220_serial_getc(void)
 {
 	volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
 
@@ -98,14 +100,14 @@ int serial_getc (void)
 	return psc->xmitbuf[2];
 }
 
-int serial_tstc (void)
+static int mpc8220_serial_tstc(void)
 {
 	volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
 
 	return (psc->sr_csr & PSC_SR_RXRDY);
 }
 
-void serial_setbrg (void)
+static void mpc8220_serial_setbrg(void)
 {
 	volatile psc8220_t *psc = (psc8220_t *) PSC_BASE;
 	u32 counter;
@@ -123,4 +125,57 @@ void serial_setbrg (void)
 
 	psc->cr = PSC_CR_RX_ENABLE | PSC_CR_TX_ENABLE;
 }
+
+#ifdef CONFIG_SERIAL_MULTI
+static struct serial_device mpc8220_serial_drv = {
+	.name	= "mpc8220_serial",
+	.start	= mpc8220_serial_init,
+	.stop	= NULL,
+	.setbrg	= mpc8220_serial_setbrg,
+	.putc	= mpc8220_serial_putc,
+	.puts	= mpc8220_serial_puts,
+	.getc	= mpc8220_serial_getc,
+	.tstc	= mpc8220_serial_tstc,
+};
+
+void mpc8220_serial_initialize(void)
+{
+	serial_register(&mpc8220_serial_drv);
+}
+
+__weak struct serial_device *default_serial_console(void)
+{
+	return &mpc8220_serial_drv;
+}
+#else
+int serial_init(void)
+{
+	return mpc8220_serial_init();
+}
+
+void serial_setbrg(void)
+{
+	mpc8220_serial_setbrg();
+}
+
+void serial_putc(const char c)
+{
+	mpc8220_serial_putc(c);
+}
+
+void serial_puts(const char *s)
+{
+	mpc8220_serial_puts(s);
+}
+
+int serial_getc(void)
+{
+	return mpc8220_serial_getc();
+}
+
+int serial_tstc(void)
+{
+	return mpc8220_serial_tstc();
+}
+#endif
 #endif /* CONFIG_PSC_CONSOLE */
diff --git a/common/serial.c b/common/serial.c
index 69fa583..db06f97 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -53,6 +53,7 @@ serial_initfunc(au1x00_serial_initialize);
 serial_initfunc(asc_serial_initialize);
 serial_initfunc(jz_serial_initialize);
 serial_initfunc(mpc5xx_serial_initialize);
+serial_initfunc(mpc8220_serial_initialize);
 
 void serial_register(struct serial_device *dev)
 {
@@ -84,6 +85,7 @@ void serial_initialize(void)
 	asc_serial_initialize();
 	jz_serial_initialize();
 	mpc5xx_serial_initialize();
+	mpc8220_serial_initialize();
 
 	serial_assign(default_serial_console()->name);
 }
-- 
1.7.10.4



More information about the U-Boot mailing list