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 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/ppc4xx.h>
21 * The controllers are configured to loopback mode and several
22 * characters are transmitted.
27 #if CONFIG_POST & CONFIG_SYS_POST_UART
30 * This table defines the UART's that should be tested and can
31 * be overridden in the board config file
33 #ifndef CONFIG_SYS_POST_UART_TABLE
34 #define CONFIG_SYS_POST_UART_TABLE { CONFIG_SYS_NS16550_COM1, \
35 CONFIG_SYS_NS16550_COM2, CONFIG_SYS_NS16550_COM3, \
36 CONFIG_SYS_NS16550_COM4 }
39 DECLARE_GLOBAL_DATA_PTR
;
41 static int test_ctlr (struct NS16550
*com_port
, int index
)
44 char test_str
[] = "*** UART Test String ***\r\n";
48 divisor
= (get_serial_clock() + (gd
->baudrate
* (16 / 2))) /
50 NS16550_init(com_port
, divisor
);
53 * Set internal loopback mode in UART
55 out_8(&com_port
->mcr
, in_8(&com_port
->mcr
) | UART_MCR_LOOP
);
58 out_8(&com_port
->fcr
, UART_FCR_RXSR
| UART_FCR_TXSR
);
62 while (NS16550_tstc(com_port
))
63 NS16550_getc(com_port
);
65 for (i
= 0; i
< sizeof (test_str
) - 1; i
++) {
66 NS16550_putc(com_port
, test_str
[i
]);
67 if (NS16550_getc(com_port
) != test_str
[i
])
73 post_log ("uart%d test failed\n", index
);
78 int uart_post_test (int flags
)
81 static unsigned long base
[] = CONFIG_SYS_POST_UART_TABLE
;
83 for (i
= 0; i
< ARRAY_SIZE(base
); i
++) {
84 if (test_ctlr((struct NS16550
*)base
[i
], i
))
92 #endif /* CONFIG_POST & CONFIG_SYS_POST_UART */