2007-03-28 15:06:19 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2007
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2007-07-05 06:17:37 +00:00
|
|
|
* Author: Igor Lisitsin <igor@emcraft.com>
|
|
|
|
*
|
2010-09-14 07:38:18 +00:00
|
|
|
* Copyright 2010, Stefan Roese, DENX Software Engineering, sr@denx.de
|
|
|
|
*
|
2007-03-28 15:06:19 +00:00
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
|
|
|
* MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2010-09-29 14:58:38 +00:00
|
|
|
#include <asm/ppc4xx.h>
|
2010-09-14 07:38:18 +00:00
|
|
|
#include <ns16550.h>
|
|
|
|
#include <asm/io.h>
|
2010-09-29 14:58:38 +00:00
|
|
|
#include <serial.h>
|
2007-03-28 15:06:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* UART test
|
|
|
|
*
|
|
|
|
* The controllers are configured to loopback mode and several
|
|
|
|
* characters are transmitted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <post.h>
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if CONFIG_POST & CONFIG_SYS_POST_UART
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2007-08-14 12:39:44 +00:00
|
|
|
/*
|
|
|
|
* This table defines the UART's that should be tested and can
|
|
|
|
* be overridden in the board config file
|
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
#ifndef CONFIG_SYS_POST_UART_TABLE
|
2010-09-29 14:58:38 +00:00
|
|
|
#define CONFIG_SYS_POST_UART_TABLE { CONFIG_SYS_NS16550_COM1, \
|
|
|
|
CONFIG_SYS_NS16550_COM2, CONFIG_SYS_NS16550_COM3, \
|
|
|
|
CONFIG_SYS_NS16550_COM4 }
|
2007-08-14 12:39:44 +00:00
|
|
|
#endif
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2010-09-14 07:38:18 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2010-09-29 14:58:38 +00:00
|
|
|
static int test_ctlr (struct NS16550 *com_port, int index)
|
2007-03-28 15:06:19 +00:00
|
|
|
{
|
2010-09-29 14:58:38 +00:00
|
|
|
int res = -1;
|
|
|
|
char test_str[] = "*** UART Test String ***\r\n";
|
2007-03-28 15:06:19 +00:00
|
|
|
int i;
|
2010-09-29 14:58:38 +00:00
|
|
|
int divisor;
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2010-09-29 14:58:38 +00:00
|
|
|
divisor = (get_serial_clock() + (gd->baudrate * (16 / 2))) /
|
|
|
|
(16 * gd->baudrate);
|
|
|
|
NS16550_init(com_port, divisor);
|
2007-03-28 15:06:19 +00:00
|
|
|
|
|
|
|
/*
|
2010-09-29 14:58:38 +00:00
|
|
|
* Set internal loopback mode in UART
|
2007-03-28 15:06:19 +00:00
|
|
|
*/
|
2010-09-29 14:58:38 +00:00
|
|
|
out_8(&com_port->mcr, in_8(&com_port->mcr) | UART_MCR_LOOP);
|
2010-09-14 07:38:18 +00:00
|
|
|
|
2010-09-29 14:58:38 +00:00
|
|
|
/* Reset FIFOs */
|
|
|
|
out_8(&com_port->fcr, UART_FCR_RXSR | UART_FCR_TXSR);
|
|
|
|
udelay(100);
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2010-09-29 14:58:38 +00:00
|
|
|
/* Flush RX-FIFO */
|
|
|
|
while (NS16550_tstc(com_port))
|
|
|
|
NS16550_getc(com_port);
|
2007-03-28 15:06:19 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof (test_str) - 1; i++) {
|
2010-09-29 14:58:38 +00:00
|
|
|
NS16550_putc(com_port, test_str[i]);
|
|
|
|
if (NS16550_getc(com_port) != test_str[i])
|
2007-03-28 15:06:19 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
res = 0;
|
|
|
|
done:
|
|
|
|
if (res)
|
|
|
|
post_log ("uart%d test failed\n", index);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int uart_post_test (int flags)
|
|
|
|
{
|
|
|
|
int i, res = 0;
|
2008-10-16 13:01:15 +00:00
|
|
|
static unsigned long base[] = CONFIG_SYS_POST_UART_TABLE;
|
2007-03-28 15:06:19 +00:00
|
|
|
|
2010-09-14 07:38:18 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(base); i++) {
|
|
|
|
if (test_ctlr((struct NS16550 *)base[i], i))
|
2007-03-28 15:06:19 +00:00
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
serial_reinit_all ();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_POST & CONFIG_SYS_POST_UART */
|