2004-08-01 22:48:16 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#include <serial.h>
|
2009-05-16 10:14:54 +00:00
|
|
|
#include <stdio_dev.h>
|
2011-05-14 06:56:15 +00:00
|
|
|
#include <post.h>
|
|
|
|
#include <linux/compiler.h>
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
static struct serial_device *serial_devices;
|
|
|
|
static struct serial_device *serial_current;
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2012-09-12 15:49:58 +00:00
|
|
|
static void serial_null(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#define serial_initfunc(name) \
|
|
|
|
void name(void) \
|
|
|
|
__attribute__((weak, alias("serial_null")));
|
|
|
|
|
2012-09-12 11:50:56 +00:00
|
|
|
serial_initfunc(mpc8xx_serial_initialize);
|
2012-09-12 18:02:05 +00:00
|
|
|
serial_initfunc(ns16550_serial_initialize);
|
2012-09-12 11:57:58 +00:00
|
|
|
serial_initfunc(pxa_serial_initialize);
|
2012-09-12 14:01:16 +00:00
|
|
|
serial_initfunc(s3c24xx_serial_initialize);
|
2012-09-12 17:39:57 +00:00
|
|
|
serial_initfunc(s5p_serial_initialize);
|
2012-10-08 21:46:23 +00:00
|
|
|
serial_initfunc(zynq_serial_initalize);
|
2012-09-12 18:07:54 +00:00
|
|
|
serial_initfunc(bfin_serial_initialize);
|
2012-09-12 22:02:54 +00:00
|
|
|
serial_initfunc(bfin_jtag_initialize);
|
2012-09-12 17:50:18 +00:00
|
|
|
serial_initfunc(mpc512x_serial_initialize);
|
2012-09-12 17:45:58 +00:00
|
|
|
serial_initfunc(uartlite_serial_initialize);
|
2012-09-12 23:16:50 +00:00
|
|
|
serial_initfunc(au1x00_serial_initialize);
|
2012-09-12 23:20:07 +00:00
|
|
|
serial_initfunc(asc_serial_initialize);
|
2012-09-12 23:20:59 +00:00
|
|
|
serial_initfunc(jz_serial_initialize);
|
2012-09-12 23:26:42 +00:00
|
|
|
serial_initfunc(mpc5xx_serial_initialize);
|
2012-09-12 23:29:31 +00:00
|
|
|
serial_initfunc(mpc8220_serial_initialize);
|
2012-09-12 23:34:16 +00:00
|
|
|
serial_initfunc(mpc8260_scc_serial_initialize);
|
|
|
|
serial_initfunc(mpc8260_smc_serial_initialize);
|
2012-09-12 23:38:52 +00:00
|
|
|
serial_initfunc(mpc85xx_serial_initialize);
|
2012-09-12 23:40:33 +00:00
|
|
|
serial_initfunc(iop480_serial_initialize);
|
2012-09-13 10:25:07 +00:00
|
|
|
serial_initfunc(leon2_serial_initialize);
|
2012-09-13 10:25:48 +00:00
|
|
|
serial_initfunc(leon3_serial_initialize);
|
2012-09-13 10:26:39 +00:00
|
|
|
serial_initfunc(marvell_serial_initialize);
|
2012-09-13 10:27:37 +00:00
|
|
|
serial_initfunc(amirix_serial_initialize);
|
2012-09-13 10:28:07 +00:00
|
|
|
serial_initfunc(bmw_serial_initialize);
|
2012-09-13 10:29:31 +00:00
|
|
|
serial_initfunc(cogent_serial_initialize);
|
2012-09-13 10:32:56 +00:00
|
|
|
serial_initfunc(cpci750_serial_initialize);
|
2012-09-13 10:33:50 +00:00
|
|
|
serial_initfunc(evb64260_serial_initialize);
|
2012-09-13 10:34:24 +00:00
|
|
|
serial_initfunc(ml2_serial_initialize);
|
2012-09-13 10:34:49 +00:00
|
|
|
serial_initfunc(sconsole_serial_initialize);
|
2012-09-13 10:35:54 +00:00
|
|
|
serial_initfunc(p3mx_serial_initialize);
|
2012-09-13 14:48:50 +00:00
|
|
|
serial_initfunc(altera_jtag_serial_initialize);
|
2012-09-13 14:49:51 +00:00
|
|
|
serial_initfunc(altera_serial_initialize);
|
2012-09-13 14:50:30 +00:00
|
|
|
serial_initfunc(atmel_serial_initialize);
|
2012-09-13 14:51:02 +00:00
|
|
|
serial_initfunc(lpc32xx_serial_initialize);
|
2012-09-13 14:51:38 +00:00
|
|
|
serial_initfunc(mcf_serial_initialize);
|
2012-09-13 14:52:07 +00:00
|
|
|
serial_initfunc(ns9750_serial_initialize);
|
2012-09-13 14:52:38 +00:00
|
|
|
serial_initfunc(oc_serial_initialize);
|
2012-09-13 14:53:15 +00:00
|
|
|
serial_initfunc(s3c4510b_serial_initialize);
|
2012-09-13 14:53:49 +00:00
|
|
|
serial_initfunc(s3c64xx_serial_initialize);
|
2012-09-14 20:33:21 +00:00
|
|
|
serial_initfunc(sandbox_serial_initialize);
|
2012-09-14 20:34:22 +00:00
|
|
|
serial_initfunc(clps7111_serial_initialize);
|
2012-09-14 20:34:51 +00:00
|
|
|
serial_initfunc(imx_serial_initialize);
|
2012-09-14 20:35:14 +00:00
|
|
|
serial_initfunc(ixp_serial_initialize);
|
2012-09-14 20:35:43 +00:00
|
|
|
serial_initfunc(ks8695_serial_initialize);
|
2012-09-14 20:36:27 +00:00
|
|
|
serial_initfunc(lh7a40x_serial_initialize);
|
2012-09-14 20:36:50 +00:00
|
|
|
serial_initfunc(lpc2292_serial_initialize);
|
2012-09-14 20:37:17 +00:00
|
|
|
serial_initfunc(max3100_serial_initialize);
|
2012-09-14 20:37:43 +00:00
|
|
|
serial_initfunc(mxc_serial_initialize);
|
2012-09-14 20:38:09 +00:00
|
|
|
serial_initfunc(netarm_serial_initialize);
|
2012-09-14 20:38:46 +00:00
|
|
|
serial_initfunc(pl01x_serial_initialize);
|
2012-09-14 20:39:19 +00:00
|
|
|
serial_initfunc(s3c44b0_serial_initialize);
|
2012-09-14 20:39:44 +00:00
|
|
|
serial_initfunc(sa1100_serial_initialize);
|
2012-09-14 20:40:08 +00:00
|
|
|
serial_initfunc(sh_serial_initialize);
|
2012-09-12 11:50:56 +00:00
|
|
|
|
2011-04-29 18:03:30 +00:00
|
|
|
void serial_register(struct serial_device *dev)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2010-10-28 18:00:11 +00:00
|
|
|
#ifdef CONFIG_NEEDS_MANUAL_RELOC
|
2012-09-07 12:35:31 +00:00
|
|
|
dev->start += gd->reloc_off;
|
2004-08-01 22:48:16 +00:00
|
|
|
dev->setbrg += gd->reloc_off;
|
|
|
|
dev->getc += gd->reloc_off;
|
|
|
|
dev->tstc += gd->reloc_off;
|
|
|
|
dev->putc += gd->reloc_off;
|
|
|
|
dev->puts += gd->reloc_off;
|
2009-09-21 16:20:36 +00:00
|
|
|
#endif
|
2004-08-01 22:48:16 +00:00
|
|
|
|
|
|
|
dev->next = serial_devices;
|
|
|
|
serial_devices = dev;
|
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_initialize(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2012-09-12 11:50:56 +00:00
|
|
|
mpc8xx_serial_initialize();
|
2012-09-12 18:02:05 +00:00
|
|
|
ns16550_serial_initialize();
|
2012-09-12 11:57:58 +00:00
|
|
|
pxa_serial_initialize();
|
2012-09-12 14:01:16 +00:00
|
|
|
s3c24xx_serial_initialize();
|
2012-09-12 17:39:57 +00:00
|
|
|
s5p_serial_initialize();
|
2012-09-12 17:50:18 +00:00
|
|
|
mpc512x_serial_initialize();
|
2012-09-12 18:07:54 +00:00
|
|
|
bfin_serial_initialize();
|
2012-09-12 22:02:54 +00:00
|
|
|
bfin_jtag_initialize();
|
2012-09-12 17:45:58 +00:00
|
|
|
uartlite_serial_initialize();
|
2012-10-08 21:46:23 +00:00
|
|
|
zynq_serial_initalize();
|
2012-09-12 23:16:50 +00:00
|
|
|
au1x00_serial_initialize();
|
2012-09-12 23:20:07 +00:00
|
|
|
asc_serial_initialize();
|
2012-09-12 23:20:59 +00:00
|
|
|
jz_serial_initialize();
|
2012-09-12 23:26:42 +00:00
|
|
|
mpc5xx_serial_initialize();
|
2012-09-12 23:29:31 +00:00
|
|
|
mpc8220_serial_initialize();
|
2012-09-12 23:34:16 +00:00
|
|
|
mpc8260_scc_serial_initialize();
|
|
|
|
mpc8260_smc_serial_initialize();
|
2012-09-12 23:38:52 +00:00
|
|
|
mpc85xx_serial_initialize();
|
2012-09-12 23:40:33 +00:00
|
|
|
iop480_serial_initialize();
|
2012-09-13 10:25:07 +00:00
|
|
|
leon2_serial_initialize();
|
2012-09-13 10:25:48 +00:00
|
|
|
leon3_serial_initialize();
|
2012-09-13 10:26:39 +00:00
|
|
|
marvell_serial_initialize();
|
2012-09-13 10:27:37 +00:00
|
|
|
amirix_serial_initialize();
|
2012-09-13 10:28:07 +00:00
|
|
|
bmw_serial_initialize();
|
2012-09-13 10:29:31 +00:00
|
|
|
cogent_serial_initialize();
|
2012-09-13 10:32:56 +00:00
|
|
|
cpci750_serial_initialize();
|
2012-09-13 10:33:50 +00:00
|
|
|
evb64260_serial_initialize();
|
2012-09-13 10:34:24 +00:00
|
|
|
ml2_serial_initialize();
|
2012-09-13 10:34:49 +00:00
|
|
|
sconsole_serial_initialize();
|
2012-09-13 10:35:54 +00:00
|
|
|
p3mx_serial_initialize();
|
2012-09-13 14:48:50 +00:00
|
|
|
altera_jtag_serial_initialize();
|
2012-09-13 14:49:51 +00:00
|
|
|
altera_serial_initialize();
|
2012-09-13 14:50:30 +00:00
|
|
|
atmel_serial_initialize();
|
2012-09-13 14:51:02 +00:00
|
|
|
lpc32xx_serial_initialize();
|
2012-09-13 14:51:38 +00:00
|
|
|
mcf_serial_initialize();
|
2012-09-13 14:52:07 +00:00
|
|
|
ns9750_serial_initialize();
|
2012-09-13 14:52:38 +00:00
|
|
|
oc_serial_initialize();
|
2012-09-13 14:53:15 +00:00
|
|
|
s3c4510b_serial_initialize();
|
2012-09-13 14:53:49 +00:00
|
|
|
s3c64xx_serial_initialize();
|
2012-09-14 20:33:21 +00:00
|
|
|
sandbox_serial_initialize();
|
2012-09-14 20:34:22 +00:00
|
|
|
clps7111_serial_initialize();
|
2012-09-14 20:34:51 +00:00
|
|
|
imx_serial_initialize();
|
2012-09-14 20:35:14 +00:00
|
|
|
ixp_serial_initialize();
|
2012-09-14 20:35:43 +00:00
|
|
|
ks8695_serial_initialize();
|
2012-09-14 20:36:27 +00:00
|
|
|
lh7a40x_serial_initialize();
|
2012-09-14 20:36:50 +00:00
|
|
|
lpc2292_serial_initialize();
|
2012-09-14 20:37:17 +00:00
|
|
|
max3100_serial_initialize();
|
2012-09-14 20:37:43 +00:00
|
|
|
mxc_serial_initialize();
|
2012-09-14 20:38:09 +00:00
|
|
|
netarm_serial_initialize();
|
2012-09-14 20:38:46 +00:00
|
|
|
pl01x_serial_initialize();
|
2012-09-14 20:39:19 +00:00
|
|
|
s3c44b0_serial_initialize();
|
2012-09-14 20:39:44 +00:00
|
|
|
sa1100_serial_initialize();
|
2012-09-14 20:40:08 +00:00
|
|
|
sh_serial_initialize();
|
2012-09-12 23:16:50 +00:00
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
serial_assign(default_serial_console()->name);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_stdio_init(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2009-05-16 10:14:54 +00:00
|
|
|
struct stdio_dev dev;
|
2004-08-01 22:48:16 +00:00
|
|
|
struct serial_device *s = serial_devices;
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
while (s) {
|
2011-11-18 06:49:11 +00:00
|
|
|
memset(&dev, 0, sizeof(dev));
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
strcpy(dev.name, s->name);
|
2004-08-01 22:48:16 +00:00
|
|
|
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
|
|
|
|
|
2012-09-07 12:35:31 +00:00
|
|
|
dev.start = s->start;
|
|
|
|
dev.stop = s->stop;
|
2004-08-01 22:48:16 +00:00
|
|
|
dev.putc = s->putc;
|
|
|
|
dev.puts = s->puts;
|
|
|
|
dev.getc = s->getc;
|
|
|
|
dev.tstc = s->tstc;
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
stdio_register(&dev);
|
2004-08-01 22:48:16 +00:00
|
|
|
|
|
|
|
s = s->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:12 +00:00
|
|
|
int serial_assign(const char *name)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
struct serial_device *s;
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
for (s = serial_devices; s; s = s->next) {
|
2011-11-18 06:49:11 +00:00
|
|
|
if (strcmp(s->name, name) == 0) {
|
2004-08-01 22:48:16 +00:00
|
|
|
serial_current = s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_reinit_all(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
struct serial_device *s;
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
for (s = serial_devices; s; s = s->next)
|
2012-09-07 12:35:31 +00:00
|
|
|
s->start();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-08-19 11:09:43 +00:00
|
|
|
static struct serial_device *get_current(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
struct serial_device *dev;
|
2004-10-11 22:43:02 +00:00
|
|
|
|
2011-08-19 11:09:43 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
dev = default_serial_console();
|
|
|
|
|
|
|
|
/* We must have a console device */
|
2012-09-15 08:33:51 +00:00
|
|
|
if (!dev) {
|
|
|
|
#ifdef CONFIG_SPL_BUILD
|
|
|
|
puts("Cannot find console\n");
|
|
|
|
hang();
|
|
|
|
#else
|
|
|
|
panic("Cannot find console\n");
|
|
|
|
#endif
|
|
|
|
}
|
2011-08-19 11:09:43 +00:00
|
|
|
} else
|
|
|
|
dev = serial_current;
|
|
|
|
return dev;
|
|
|
|
}
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2011-08-19 11:09:43 +00:00
|
|
|
int serial_init(void)
|
|
|
|
{
|
2012-09-07 12:35:31 +00:00
|
|
|
return get_current()->start();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_setbrg(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
get_current()->setbrg();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
int serial_getc(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
return get_current()->getc();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
int serial_tstc(void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
return get_current()->tstc();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_putc(const char c)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
get_current()->putc(c);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 06:49:11 +00:00
|
|
|
void serial_puts(const char *s)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2011-08-19 11:09:43 +00:00
|
|
|
get_current()->puts(s);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
2011-05-14 06:56:15 +00:00
|
|
|
|
|
|
|
#if CONFIG_POST & CONFIG_SYS_POST_UART
|
|
|
|
static const int bauds[] = CONFIG_SYS_BAUDRATE_TABLE;
|
|
|
|
|
|
|
|
/* Mark weak until post/cpu/.../uart.c migrate over */
|
|
|
|
__weak
|
|
|
|
int uart_post_test(int flags)
|
|
|
|
{
|
|
|
|
unsigned char c;
|
|
|
|
int ret, saved_baud, b;
|
|
|
|
struct serial_device *saved_dev, *s;
|
|
|
|
bd_t *bd = gd->bd;
|
|
|
|
|
|
|
|
/* Save current serial state */
|
|
|
|
ret = 0;
|
|
|
|
saved_dev = serial_current;
|
|
|
|
saved_baud = bd->bi_baudrate;
|
|
|
|
|
|
|
|
for (s = serial_devices; s; s = s->next) {
|
|
|
|
/* If this driver doesn't support loop back, skip it */
|
|
|
|
if (!s->loop)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Test the next device */
|
|
|
|
serial_current = s;
|
|
|
|
|
|
|
|
ret = serial_init();
|
|
|
|
if (ret)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* Consume anything that happens to be queued */
|
|
|
|
while (serial_tstc())
|
|
|
|
serial_getc();
|
|
|
|
|
|
|
|
/* Enable loop back */
|
|
|
|
s->loop(1);
|
|
|
|
|
|
|
|
/* Test every available baud rate */
|
|
|
|
for (b = 0; b < ARRAY_SIZE(bauds); ++b) {
|
|
|
|
bd->bi_baudrate = bauds[b];
|
|
|
|
serial_setbrg();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stick to printable chars to avoid issues:
|
|
|
|
* - terminal corruption
|
|
|
|
* - serial program reacting to sequences and sending
|
|
|
|
* back random extra data
|
|
|
|
* - most serial drivers add in extra chars (like \r\n)
|
|
|
|
*/
|
|
|
|
for (c = 0x20; c < 0x7f; ++c) {
|
|
|
|
/* Send it out */
|
|
|
|
serial_putc(c);
|
|
|
|
|
|
|
|
/* Make sure it's the same one */
|
|
|
|
ret = (c != serial_getc());
|
|
|
|
if (ret) {
|
|
|
|
s->loop(0);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up the output in case it was sent */
|
|
|
|
serial_putc('\b');
|
|
|
|
ret = ('\b' != serial_getc());
|
|
|
|
if (ret) {
|
|
|
|
s->loop(0);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable loop back */
|
|
|
|
s->loop(0);
|
|
|
|
|
2012-09-07 12:35:31 +00:00
|
|
|
/* XXX: There is no serial_stop() !? */
|
|
|
|
if (s->stop)
|
|
|
|
s->stop();
|
2011-05-14 06:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* Restore previous serial state */
|
|
|
|
serial_current = saved_dev;
|
|
|
|
bd->bi_baudrate = saved_baud;
|
|
|
|
serial_reinit_all();
|
|
|
|
serial_setbrg();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|