Serial loopback internal/external tests. Is based on my previous commit 078a9c4898e7802086b362baa44ad48b8ad1baed
Signed-off-by: Michael Zaidman <michael.zaid...@gmail.com> --- drivers/serial/serial.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ post/drivers/Makefile | 2 +- post/drivers/serial.c | 56 ++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletions(-) create mode 100644 post/drivers/serial.c diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 0b30ff4..10b5ab1 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -46,6 +46,7 @@ #include <common.h> #include <ns16550.h> +#include <asm/io.h> #ifdef CONFIG_NS87308 #include <ns87308.h> @@ -382,3 +383,89 @@ struct serial_device eserial6_device = INIT_ESERIAL_STRUCTURE(6,"eserial5","EUART6"); #endif /* CONFIG_SERIAL_MULTI */ +NS16550_t get_serial_port(int index) +{ + return serial_ports[index]; +} + +int get_number_of_serial_ports(void) +{ + return MAX_SER_DEV; +} + +static int __serial_test (int com_port, int loopback_mode) +{ + int i, loops, ret = 0; + NS16550_t port = serial_ports[com_port-1]; + + if (loopback_mode == 0) /* Set local loop-back mode */ + out_8(&port->mcr, (in_8(&port->mcr) | UART_MCR_LOOP)); + + for (i = 0; (i < 256) && !ret; i++) { + NS16550_putc(port, i); + for (loops = 1000; loops; loops --) { + if (NS16550_tstc(port)) { + if (NS16550_getc(port) != i) + ret = 1; + break; + } + udelay(100); /* tstc timeout = 1000 times * 100us */ + } + if (loops == 0) + ret = 1; + } + + if (loopback_mode == 0) /* Remove local loop-back mode */ + out_8(&port->mcr, (in_8(&port->mcr) & ~UART_MCR_LOOP)); + + return ret; +} +int serial_test(int com_port, int loopback_mode) __attribute__((weak, alias("__serial_test"))); + +int do_serial_test (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + int port; + int mode = 0; /* local loop-back mode */ + + if (argc < 3) { + printf("Err: Invalid number of arguments!\n\n"); + cmd_usage(cmdtp); + return 1; + } + + if (strcmp(argv[1],"external") == 0) { + mode = 1; + } + else + if (strcmp(argv[1],"internal") != 0) { + printf("Err: Invalid loop-back mode!\n\n"); + return 1; + } + + port = simple_strtoul(argv[2], NULL, 10); + if ((serial_ports[port-1] == NULL) || (port < 1) || (port > MAX_SER_DEV)) { + printf("Err: Invalid COM port number!\n\n"); + return 1; + } + + printf("Serial COM%d %s loop-back " + "test @%d bps ", port, argv[1], gd->baudrate); + if (port == CONFIG_CONS_INDEX) + udelay(10000); /* make sure the stdout has been finished */ + if (serial_test(port, mode) != 0) { + puts("FAILED\n"); + return 1; + } + + puts("PASSED\n"); + return 0; +} + +U_BOOT_CMD( + uartest, 255, 1, do_serial_test, + "Loop-back test for serial com port", + "<loop-back mode> <serial com port>\n" + " where, <loop-back mode> is \"internal\" or \"external\"\n" + " <com port> is number of serial com port (1..N)" +); + diff --git a/post/drivers/Makefile b/post/drivers/Makefile index 0b6cdf5..de82e93 100644 --- a/post/drivers/Makefile +++ b/post/drivers/Makefile @@ -24,6 +24,6 @@ include $(TOPDIR)/config.mk LIB = libpostdrivers.a -COBJS-$(CONFIG_HAS_POST) += i2c.o memory.o rtc.o +COBJS-$(CONFIG_HAS_POST) += i2c.o memory.o rtc.o serial.o include $(TOPDIR)/post/rules.mk diff --git a/post/drivers/serial.c b/post/drivers/serial.c new file mode 100644 index 0000000..4ace9d0 --- /dev/null +++ b/post/drivers/serial.c @@ -0,0 +1,56 @@ +/* + * (C) Copyright 2010 + * Eastman Kodak Company, <www.kodak.com> + * Michael Zaidman, <michael.zaid...@kodak.com> + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + */ + +#include <common.h> +#include <ns16550.h> +#include <post.h> + +#if CONFIG_POST & CONFIG_SYS_POST_UART + +extern int serial_test(int com_port, int loopback_mode); +extern int get_number_of_serial_ports(void); +extern NS16550_t get_serial_port(int index); + +DECLARE_GLOBAL_DATA_PTR; + +int __uart_post_test (int flags) +{ + int port; + int ret = 0; + + udelay(10000); /* make sure the stdout has been finished */ + for (port = 1; (get_serial_port(port-1) != NULL) && + (port <= get_number_of_serial_ports()); port++) { + if (serial_test(port, 0)) { + post_log("Serial COM%d internal loop-back " + "test @%d bps ", port, gd->baudrate); + ret = 1; + } + } + return ret; +} +int uart_post_test(int flags) __attribute__((weak, alias("__uart_post_test"))); + +#endif -- 1.6.3.3 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot