]> git.ipfire.org Git - people/ms/u-boot.git/blob - post/cpu/ppc4xx/uart.c
drivers, block: remove sil680 driver
[people/ms/u-boot.git] / post / cpu / ppc4xx / uart.c
1 /*
2 * (C) Copyright 2007
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Author: Igor Lisitsin <igor@emcraft.com>
6 *
7 * Copyright 2010, Stefan Roese, DENX Software Engineering, sr@denx.de
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
12 #include <common.h>
13 #include <asm/ppc4xx.h>
14 #include <ns16550.h>
15 #include <asm/io.h>
16 #include <serial.h>
17
18 /*
19 * UART test
20 *
21 * The controllers are configured to loopback mode and several
22 * characters are transmitted.
23 */
24
25 #include <post.h>
26
27 #if CONFIG_POST & CONFIG_SYS_POST_UART
28
29 /*
30 * This table defines the UART's that should be tested and can
31 * be overridden in the board config file
32 */
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 }
37 #endif
38
39 DECLARE_GLOBAL_DATA_PTR;
40
41 static int test_ctlr (struct NS16550 *com_port, int index)
42 {
43 int res = -1;
44 char test_str[] = "*** UART Test String ***\r\n";
45 int i;
46 int divisor;
47
48 divisor = (get_serial_clock() + (gd->baudrate * (16 / 2))) /
49 (16 * gd->baudrate);
50 NS16550_init(com_port, divisor);
51
52 /*
53 * Set internal loopback mode in UART
54 */
55 out_8(&com_port->mcr, in_8(&com_port->mcr) | UART_MCR_LOOP);
56
57 /* Reset FIFOs */
58 out_8(&com_port->fcr, UART_FCR_RXSR | UART_FCR_TXSR);
59 udelay(100);
60
61 /* Flush RX-FIFO */
62 while (NS16550_tstc(com_port))
63 NS16550_getc(com_port);
64
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])
68 goto done;
69 }
70 res = 0;
71 done:
72 if (res)
73 post_log ("uart%d test failed\n", index);
74
75 return res;
76 }
77
78 int uart_post_test (int flags)
79 {
80 int i, res = 0;
81 static unsigned long base[] = CONFIG_SYS_POST_UART_TABLE;
82
83 for (i = 0; i < ARRAY_SIZE(base); i++) {
84 if (test_ctlr((struct NS16550 *)base[i], i))
85 res = -1;
86 }
87 serial_reinit_all ();
88
89 return res;
90 }
91
92 #endif /* CONFIG_POST & CONFIG_SYS_POST_UART */