]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - post/cpu/ppc4xx/uart.c
Merge branch 'master' of git://git.denx.de/u-boot-blackfin
[karo-tx-uboot.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  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
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.
16  *
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.
21  *
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,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <asm/ppc4xx.h>
30 #include <ns16550.h>
31 #include <asm/io.h>
32 #include <serial.h>
33
34 /*
35  * UART test
36  *
37  * The controllers are configured to loopback mode and several
38  * characters are transmitted.
39  */
40
41 #include <post.h>
42
43 #if CONFIG_POST & CONFIG_SYS_POST_UART
44
45 /*
46  * This table defines the UART's that should be tested and can
47  * be overridden in the board config file
48  */
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 }
53 #endif
54
55 DECLARE_GLOBAL_DATA_PTR;
56
57 static int test_ctlr (struct NS16550 *com_port, int index)
58 {
59         int res = -1;
60         char test_str[] = "*** UART Test String ***\r\n";
61         int i;
62         int divisor;
63
64         divisor = (get_serial_clock() + (gd->baudrate * (16 / 2))) /
65                 (16 * gd->baudrate);
66         NS16550_init(com_port, divisor);
67
68         /*
69          * Set internal loopback mode in UART
70          */
71         out_8(&com_port->mcr, in_8(&com_port->mcr) | UART_MCR_LOOP);
72
73         /* Reset FIFOs */
74         out_8(&com_port->fcr, UART_FCR_RXSR | UART_FCR_TXSR);
75         udelay(100);
76
77         /* Flush RX-FIFO */
78         while (NS16550_tstc(com_port))
79                 NS16550_getc(com_port);
80
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])
84                         goto done;
85         }
86         res = 0;
87 done:
88         if (res)
89                 post_log ("uart%d test failed\n", index);
90
91         return res;
92 }
93
94 int uart_post_test (int flags)
95 {
96         int i, res = 0;
97         static unsigned long base[] = CONFIG_SYS_POST_UART_TABLE;
98
99         for (i = 0; i < ARRAY_SIZE(base); i++) {
100                 if (test_ctlr((struct NS16550 *)base[i], i))
101                         res = -1;
102         }
103         serial_reinit_all ();
104
105         return res;
106 }
107
108 #endif /* CONFIG_POST & CONFIG_SYS_POST_UART */