diff options
author | Mike Frysinger <vapier@gentoo.org> | 2011-05-14 06:56:15 +0000 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2011-07-26 16:39:03 +0200 |
commit | 7b826c2f3510eaf185c7b4b0d709b9e766831bd6 (patch) | |
tree | c4ce1e32b13bb7fb0095004db23602e8a9b2be85 /common/serial.c | |
parent | 1c9a5606d8ff0c664c9e83de38e93d5602312d79 (diff) | |
download | u-boot-7b826c2f3510eaf185c7b4b0d709b9e766831bd6.zip u-boot-7b826c2f3510eaf185c7b4b0d709b9e766831bd6.tar.gz u-boot-7b826c2f3510eaf185c7b4b0d709b9e766831bd6.tar.bz2 |
serial: implement common uart post test
The current arch/driver specific UART posts basically boil down to setting
the UART to loop back mode, then reading and writing data. If we ignore
the loop back part, the rest can be built upon the existing common serial
API. So let's do just that.
First add a call back for serial drivers to implement loop back control.
Then write a post test that walks all of the serial drivers, puts them
into loop back mode, and verifies that reading/writing at all the diff
baud rates is OK.
If a serial driver doesn't support loop back mode (either it can't or
it hasn't done so yet), then skip it. This should allow for people to
easily migrate to the new post test with existing serial drivers.
I haven't touched the few already existing uart post tests as I don't
the hardware or knowledge of converting them over. So I've marked the
new test as weak which will allow the existing tests to override the
default until they are converted.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'common/serial.c')
-rw-r--r-- | common/serial.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/common/serial.c b/common/serial.c index bf77409..748e5d5 100644 --- a/common/serial.c +++ b/common/serial.c @@ -24,6 +24,8 @@ #include <common.h> #include <serial.h> #include <stdio_dev.h> +#include <post.h> +#include <linux/compiler.h> DECLARE_GLOBAL_DATA_PTR; @@ -221,3 +223,91 @@ void serial_puts (const char *s) serial_current->puts (s); } + +#if CONFIG_POST & CONFIG_SYS_POST_UART +static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE; + +/* Mark weak until post/cpu/.../uart.c migrate over */ +__weak +int uart_post_test(int flags) +{ + unsigned char c; + int ret, saved_baud, b; + struct serial_device *saved_dev, *s; + bd_t *bd = gd->bd; + + /* Save current serial state */ + ret = 0; + saved_dev = serial_current; + saved_baud = bd->bi_baudrate; + + for (s = serial_devices; s; s = s->next) { + /* If this driver doesn't support loop back, skip it */ + if (!s->loop) + continue; + + /* Test the next device */ + serial_current = s; + + ret = serial_init(); + if (ret) + goto done; + + /* Consume anything that happens to be queued */ + while (serial_tstc()) + serial_getc(); + + /* Enable loop back */ + s->loop(1); + + /* Test every available baud rate */ + for (b = 0; b < ARRAY_SIZE(bauds); ++b) { + bd->bi_baudrate = bauds[b]; + serial_setbrg(); + + /* + * Stick to printable chars to avoid issues: + * - terminal corruption + * - serial program reacting to sequences and sending + * back random extra data + * - most serial drivers add in extra chars (like \r\n) + */ + for (c = 0x20; c < 0x7f; ++c) { + /* Send it out */ + serial_putc(c); + + /* Make sure it's the same one */ + ret = (c != serial_getc()); + if (ret) { + s->loop(0); + goto done; + } + + /* Clean up the output in case it was sent */ + serial_putc('\b'); + ret = ('\b' != serial_getc()); + if (ret) { + s->loop(0); + goto done; + } + } + } + + /* Disable loop back */ + s->loop(0); + + /* XXX: There is no serial_uninit() !? */ + if (s->uninit) + s->uninit(); + } + + done: + /* Restore previous serial state */ + serial_current = saved_dev; + bd->bi_baudrate = saved_baud; + serial_reinit_all(); + serial_setbrg(); + + return ret; +} +#endif |