Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Sergei Poselenov | 3190dbe | 2007-07-05 08:17:37 +0200 | [diff] [blame] | 5 | * Author: Igor Lisitsin <igor@emcraft.com> |
| 6 | * |
Stefan Roese | d0c966a | 2010-09-14 09:38:18 +0200 | [diff] [blame] | 7 | * Copyright 2010, Stefan Roese, DENX Software Engineering, sr@denx.de |
| 8 | * |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 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> |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 29 | #include <asm/ppc4xx.h> |
Stefan Roese | d0c966a | 2010-09-14 09:38:18 +0200 | [diff] [blame] | 30 | #include <ns16550.h> |
| 31 | #include <asm/io.h> |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 32 | #include <serial.h> |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * UART test |
| 36 | * |
| 37 | * The controllers are configured to loopback mode and several |
| 38 | * characters are transmitted. |
| 39 | */ |
| 40 | |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 41 | #include <post.h> |
| 42 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | #if CONFIG_POST & CONFIG_SYS_POST_UART |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 44 | |
Stefan Roese | 32a444b | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 45 | /* |
| 46 | * This table defines the UART's that should be tested and can |
| 47 | * be overridden in the board config file |
| 48 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | #ifndef CONFIG_SYS_POST_UART_TABLE |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 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 } |
Stefan Roese | 32a444b | 2007-08-14 14:39:44 +0200 | [diff] [blame] | 53 | #endif |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 54 | |
Stefan Roese | d0c966a | 2010-09-14 09:38:18 +0200 | [diff] [blame] | 55 | DECLARE_GLOBAL_DATA_PTR; |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 56 | |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 57 | static int test_ctlr (struct NS16550 *com_port, int index) |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 58 | { |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 59 | int res = -1; |
| 60 | char test_str[] = "*** UART Test String ***\r\n"; |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 61 | int i; |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 62 | int divisor; |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 63 | |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 64 | divisor = (get_serial_clock() + (gd->baudrate * (16 / 2))) / |
| 65 | (16 * gd->baudrate); |
| 66 | NS16550_init(com_port, divisor); |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 67 | |
| 68 | /* |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 69 | * Set internal loopback mode in UART |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 70 | */ |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 71 | out_8(&com_port->mcr, in_8(&com_port->mcr) | UART_MCR_LOOP); |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 72 | |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 73 | /* Reset FIFOs */ |
| 74 | out_8(&com_port->fcr, UART_FCR_RXSR | UART_FCR_TXSR); |
| 75 | udelay(100); |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 76 | |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 77 | /* Flush RX-FIFO */ |
| 78 | while (NS16550_tstc(com_port)) |
| 79 | NS16550_getc(com_port); |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 80 | |
| 81 | for (i = 0; i < sizeof (test_str) - 1; i++) { |
Stefan Roese | a0a1479 | 2010-09-29 16:58:38 +0200 | [diff] [blame^] | 82 | NS16550_putc(com_port, test_str[i]); |
| 83 | if (NS16550_getc(com_port) != test_str[i]) |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 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; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | static unsigned long base[] = CONFIG_SYS_POST_UART_TABLE; |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 98 | |
Stefan Roese | d0c966a | 2010-09-14 09:38:18 +0200 | [diff] [blame] | 99 | for (i = 0; i < ARRAY_SIZE(base); i++) { |
| 100 | if (test_ctlr((struct NS16550 *)base[i], i)) |
Igor Lisitsin | 95bcd38 | 2007-03-28 19:06:19 +0400 | [diff] [blame] | 101 | res = -1; |
| 102 | } |
| 103 | serial_reinit_all (); |
| 104 | |
| 105 | return res; |
| 106 | } |
| 107 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | #endif /* CONFIG_POST & CONFIG_SYS_POST_UART */ |