3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * Author: Igor Lisitsin <igor@emcraft.com>
7 * Copyright 2010, Stefan Roese, DENX Software Engineering, sr@denx.de
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 #include <asm/ppc4xx.h>
37 * The controllers are configured to loopback mode and several
38 * characters are transmitted.
43 #if CONFIG_POST & CONFIG_SYS_POST_UART
46 * This table defines the UART's that should be tested and can
47 * be overridden in the board config file
49 #ifndef CONFIG_SYS_POST_UART_TABLE
50 #define CONFIG_SYS_POST_UART_TABLE { CONFIG_SYS_NS16550_COM1, \
51 CONFIG_SYS_NS16550_COM2, CONFIG_SYS_NS16550_COM3, \
52 CONFIG_SYS_NS16550_COM4 }
55 DECLARE_GLOBAL_DATA_PTR;
57 static int test_ctlr (struct NS16550 *com_port, int index)
60 char test_str[] = "*** UART Test String ***\r\n";
64 divisor = (get_serial_clock() + (gd->baudrate * (16 / 2))) /
66 NS16550_init(com_port, divisor);
69 * Set internal loopback mode in UART
71 out_8(&com_port->mcr, in_8(&com_port->mcr) | UART_MCR_LOOP);
74 out_8(&com_port->fcr, UART_FCR_RXSR | UART_FCR_TXSR);
78 while (NS16550_tstc(com_port))
79 NS16550_getc(com_port);
81 for (i = 0; i < sizeof (test_str) - 1; i++) {
82 NS16550_putc(com_port, test_str[i]);
83 if (NS16550_getc(com_port) != test_str[i])
89 post_log ("uart%d test failed\n", index);
94 int uart_post_test (int flags)
97 static unsigned long base[] = CONFIG_SYS_POST_UART_TABLE;
99 for (i = 0; i < ARRAY_SIZE(base); i++) {
100 if (test_ctlr((struct NS16550 *)base[i], i))
103 serial_reinit_all ();
108 #endif /* CONFIG_POST & CONFIG_SYS_POST_UART */