summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2011-08-19 11:09:43 +0000
committerWolfgang Denk <wd@denx.de>2011-10-01 21:52:48 +0200
commit857c283e9bfbafdd550970602c2dcc072579ae6e (patch)
tree5abaca81ca051d1b4a8233bc9c100a7bade87dde /common
parent025421eab453fd41a3cc14a0fc48115b0dc4c287 (diff)
downloadu-boot-imx-857c283e9bfbafdd550970602c2dcc072579ae6e.zip
u-boot-imx-857c283e9bfbafdd550970602c2dcc072579ae6e.tar.gz
u-boot-imx-857c283e9bfbafdd550970602c2dcc072579ae6e.tar.bz2
Small refactor to remove duplicate serial code
This tidies up duplicate code, and checks that default_serial_console() does in fact produce a device. Signed-off-by: Simon Glass <sjg@chromium.org> Acked-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'common')
-rw-r--r--common/serial.c64
1 files changed, 20 insertions, 44 deletions
diff --git a/common/serial.c b/common/serial.c
index 995d268..7bfc861 100644
--- a/common/serial.c
+++ b/common/serial.c
@@ -158,73 +158,49 @@ void serial_reinit_all (void)
}
}
-int serial_init (void)
+static struct serial_device *get_current(void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
+ struct serial_device *dev;
- return dev->init ();
- }
+ if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
+ dev = default_serial_console();
+
+ /* We must have a console device */
+ if (!dev)
+ panic("Cannot find console");
+ } else
+ dev = serial_current;
+ return dev;
+}
- return serial_current->init ();
+int serial_init(void)
+{
+ return get_current()->init();
}
void serial_setbrg (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->setbrg ();
- return;
- }
-
- serial_current->setbrg ();
+ get_current()->setbrg();
}
int serial_getc (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- return dev->getc ();
- }
-
- return serial_current->getc ();
+ return get_current()->getc();
}
int serial_tstc (void)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- return dev->tstc ();
- }
-
- return serial_current->tstc ();
+ return get_current()->tstc();
}
void serial_putc (const char c)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->putc (c);
- return;
- }
-
- serial_current->putc (c);
+ get_current()->putc(c);
}
void serial_puts (const char *s)
{
- if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
- struct serial_device *dev = default_serial_console ();
-
- dev->puts (s);
- return;
- }
-
- serial_current->puts (s);
+ get_current()->puts(s);
}
#if CONFIG_POST & CONFIG_SYS_POST_UART