[U-Boot] [PATCH 1/3] serial: push default_serial_console to drivers

Mike Frysinger vapier at gentoo.org
Sat Apr 30 06:03:29 CEST 2011


Rather than sticking arch/board/driver specific logic in the common
serial code, push it all out to the respective drivers.  The serial
drivers declare these funcs weak so that boards can still override
things with their own definition.

Signed-off-by: Mike Frysinger <vapier at gentoo.org>
CC: Heiko Schocher <hs at denx.de>
CC: Anatolij Gustschin <agust at denx.de>
CC: Tom Rix <Tom.Rix at windriver.com>
CC: Minkyu Kang <mk7.kang at samsung.com>
CC: Craig Nauman <cnauman at diagraph.com>
CC: Prafulla Wadaskar <prafulla at marvell.com>
CC: Mahavir Jain <mjain at marvell.com>
---
note: while i've compiled tested all of these, i obviously can't
      runtime test them ... i have runtime tested the common code
      though on a Blackfin part ...

 arch/powerpc/cpu/mpc512x/serial.c  |   12 ++++++
 arch/powerpc/cpu/mpc5xxx/serial.c  |    6 +++
 arch/powerpc/cpu/mpc8xx/serial.c   |   10 +++++
 board/logicpd/zoom2/zoom2_serial.c |    5 +++
 common/serial.c                    |   68 ------------------------------------
 drivers/serial/serial.c            |   17 +++++++++
 drivers/serial/serial_s3c24x0.c    |   14 +++++++
 drivers/serial/serial_s5p.c        |   16 ++++++++
 8 files changed, 80 insertions(+), 68 deletions(-)

diff --git a/arch/powerpc/cpu/mpc512x/serial.c b/arch/powerpc/cpu/mpc512x/serial.c
index cb5bbf0..558e4e2 100644
--- a/arch/powerpc/cpu/mpc512x/serial.c
+++ b/arch/powerpc/cpu/mpc512x/serial.c
@@ -30,6 +30,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <asm/io.h>
 #include <asm/processor.h>
 #include <serial.h>
@@ -354,6 +355,17 @@ struct serial_device serial6_device =
 INIT_PSC_SERIAL_STRUCTURE(6, "psc6", "UART6");
 #endif
 
+__weak struct serial_device *default_serial_console(void)
+{
+#if (CONFIG_PSC_CONSOLE == 3)
+	return &serial3_device;
+#elif (CONFIG_PSC_CONSOLE == 6)
+	return &serial6_device;
+#else
+#error "invalid CONFIG_PSC_CONSOLE"
+#endif
+}
+
 #else
 
 void serial_setbrg(void)
diff --git a/arch/powerpc/cpu/mpc5xxx/serial.c b/arch/powerpc/cpu/mpc5xxx/serial.c
index 0127065..0e1a8ec 100644
--- a/arch/powerpc/cpu/mpc5xxx/serial.c
+++ b/arch/powerpc/cpu/mpc5xxx/serial.c
@@ -34,6 +34,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <mpc5xxx.h>
 
 #if defined (CONFIG_SERIAL_MULTI)
@@ -348,6 +349,11 @@ struct serial_device serial0_device =
 	serial0_puts,
 };
 
+__weak struct serial_device *default_serial_console(void)
+{
+	return &serial0_device;
+}
+
 struct serial_device serial1_device =
 {
 	"serial1",
diff --git a/arch/powerpc/cpu/mpc8xx/serial.c b/arch/powerpc/cpu/mpc8xx/serial.c
index 9514c66..21803f5 100644
--- a/arch/powerpc/cpu/mpc8xx/serial.c
+++ b/arch/powerpc/cpu/mpc8xx/serial.c
@@ -26,6 +26,7 @@
 #include <command.h>
 #include <serial.h>
 #include <watchdog.h>
+#include <linux/compiler.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -673,6 +674,15 @@ struct serial_device serial_scc_device =
 
 #endif	/* CONFIG_8xx_CONS_SCCx */
 
+__weak struct serial_device *default_serial_console(void)
+{
+#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
+	return &serial_smc_device;
+#else
+	return &serial_scc_device;
+#endif
+}
+
 #ifdef CONFIG_MODEM_SUPPORT
 void disable_putc(void)
 {
diff --git a/board/logicpd/zoom2/zoom2_serial.c b/board/logicpd/zoom2/zoom2_serial.c
index fcfe624..74f165f 100644
--- a/board/logicpd/zoom2/zoom2_serial.c
+++ b/board/logicpd/zoom2/zoom2_serial.c
@@ -132,3 +132,8 @@ QUAD_INIT (0)
 QUAD_INIT (1)
 QUAD_INIT (2)
 QUAD_INIT (3)
+
+struct serial_device *default_serial_console(void)
+{
+	return ZOOM2_DEFAULT_SERIAL_DEVICE;
+}
diff --git a/common/serial.c b/common/serial.c
index 8ebf9a5..505c2c6 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -30,74 +30,6 @@ DECLARE_GLOBAL_DATA_PTR;
 static struct serial_device *serial_devices = NULL;
 static struct serial_device *serial_current = NULL;
 
-#if !defined(CONFIG_LWMON) && !defined(CONFIG_PXA250) && !defined(CONFIG_PXA27X)
-struct serial_device *__default_serial_console (void)
-{
-#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
-	return &serial_smc_device;
-#elif defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
-   || defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
-	return &serial_scc_device;
-#elif defined(CONFIG_4xx) \
-   || defined(CONFIG_MB86R0x) || defined(CONFIG_MPC5xxx) \
-   || defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) \
-   || defined(CONFIG_MPC86xx) || defined(CONFIG_SYS_SC520) \
-   || defined(CONFIG_TEGRA2)
-#if defined(CONFIG_CONS_INDEX) && defined(CONFIG_SYS_NS16550_SERIAL)
-#if (CONFIG_CONS_INDEX==1)
-	return &eserial1_device;
-#elif (CONFIG_CONS_INDEX==2)
-	return &eserial2_device;
-#elif (CONFIG_CONS_INDEX==3)
-	return &eserial3_device;
-#elif (CONFIG_CONS_INDEX==4)
-	return &eserial4_device;
-#else
-#error "Bad CONFIG_CONS_INDEX."
-#endif
-#else
-	return &serial0_device;
-#endif
-#elif defined(CONFIG_MPC512X)
-#if (CONFIG_PSC_CONSOLE == 3)
-		return &serial3_device;
-#elif (CONFIG_PSC_CONSOLE == 6)
-		return &serial6_device;
-#else
-#error "Bad CONFIG_PSC_CONSOLE."
-#endif
-#elif defined(CONFIG_S3C2410)
-#if defined(CONFIG_SERIAL1)
-	return &s3c24xx_serial0_device;
-#elif defined(CONFIG_SERIAL2)
-	return &s3c24xx_serial1_device;
-#elif defined(CONFIG_SERIAL3)
-	return &s3c24xx_serial2_device;
-#else
-#error "CONFIG_SERIAL? missing."
-#endif
-#elif defined(CONFIG_S5P)
-#if defined(CONFIG_SERIAL0)
-	return &s5p_serial0_device;
-#elif defined(CONFIG_SERIAL1)
-	return &s5p_serial1_device;
-#elif defined(CONFIG_SERIAL2)
-	return &s5p_serial2_device;
-#elif defined(CONFIG_SERIAL3)
-	return &s5p_serial3_device;
-#else
-#error "CONFIG_SERIAL? missing."
-#endif
-#elif defined(CONFIG_OMAP3_ZOOM2)
-		return ZOOM2_DEFAULT_SERIAL_DEVICE;
-#else
-#error No default console
-#endif
-}
-
-struct serial_device *default_serial_console(void) __attribute__((weak, alias("__default_serial_console")));
-#endif
-
 int serial_register (struct serial_device *dev)
 {
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c
index 4032dfd..4afdd41 100644
--- a/drivers/serial/serial.c
+++ b/drivers/serial/serial.c
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 
 #include <ns16550.h>
 #ifdef CONFIG_NS87308
@@ -335,4 +336,20 @@ struct serial_device eserial3_device =
 DECLARE_ESERIAL_FUNCTIONS(4);
 struct serial_device eserial4_device =
 	INIT_ESERIAL_STRUCTURE(4,"eserial3","EUART4");
+
+__weak struct serial_device *default_serial_console(void)
+{
+#if CONFIG_CONS_INDEX == 1
+	return &eserial1_device;
+#elif CONFIG_CONS_INDEX == 2
+	return &eserial2_device;
+#elif CONFIG_CONS_INDEX == 3
+	return &eserial3_device;
+#elif CONFIG_CONS_INDEX == 4
+	return &eserial4_device;
+#else
+#error "Bad CONFIG_CONS_INDEX."
+#endif
+}
+
 #endif /* CONFIG_SERIAL_MULTI */
diff --git a/drivers/serial/serial_s3c24x0.c b/drivers/serial/serial_s3c24x0.c
index f42b15e..ec1fe80 100644
--- a/drivers/serial/serial_s3c24x0.c
+++ b/drivers/serial/serial_s3c24x0.c
@@ -19,6 +19,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <asm/arch/s3c24x0_cpu.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -316,4 +317,17 @@ INIT_S3C_SERIAL_STRUCTURE(1, "s3ser1", "S3UART2");
 DECLARE_S3C_SERIAL_FUNCTIONS(2);
 struct serial_device s3c24xx_serial2_device =
 INIT_S3C_SERIAL_STRUCTURE(2, "s3ser2", "S3UART3");
+
+__weak struct serial_device *default_serial_console(void)
+{
+#if defined(CONFIG_SERIAL1)
+	return &s3c24xx_serial0_device;
+#elif defined(CONFIG_SERIAL2)
+	return &s3c24xx_serial1_device;
+#elif defined(CONFIG_SERIAL3)
+	return &s3c24xx_serial2_device;
+#else
+#error "CONFIG_SERIAL? missing."
+#endif
+}
 #endif /* CONFIG_SERIAL_MULTI */
diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
index f1ffa29..6604aa9 100644
--- a/drivers/serial/serial_s5p.c
+++ b/drivers/serial/serial_s5p.c
@@ -22,6 +22,7 @@
  */
 
 #include <common.h>
+#include <linux/compiler.h>
 #include <asm/io.h>
 #include <asm/arch/uart.h>
 #include <asm/arch/clk.h>
@@ -205,3 +206,18 @@ struct serial_device s5p_serial2_device =
 DECLARE_S5P_SERIAL_FUNCTIONS(3);
 struct serial_device s5p_serial3_device =
 	INIT_S5P_SERIAL_STRUCTURE(3, "s5pser3", "S5PUART3");
+
+__weak struct serial_device *default_serial_console(void)
+{
+#if defined(CONFIG_SERIAL0)
+	return &s5p_serial0_device;
+#elif defined(CONFIG_SERIAL1)
+	return &s5p_serial1_device;
+#elif defined(CONFIG_SERIAL2)
+	return &s5p_serial2_device;
+#elif defined(CONFIG_SERIAL3)
+	return &s5p_serial3_device;
+#else
+#error "CONFIG_SERIAL? missing."
+#endif
+}
-- 
1.7.5.rc3



More information about the U-Boot mailing list