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>
|
2004-08-01 22:48:16 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2004-08-01 22:48:16 +00:00
|
|
|
static struct serial_device *serial_devices = NULL;
|
|
|
|
static struct serial_device *serial_current = NULL;
|
|
|
|
|
2007-08-30 20:57:04 +00:00
|
|
|
#if !defined(CONFIG_LWMON) && !defined(CONFIG_PXA27X)
|
2007-12-27 15:57:23 +00:00
|
|
|
struct serial_device *__default_serial_console (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
|
|
|
|
return &serial_smc_device;
|
|
|
|
#elif defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
|
|
|
|
|| defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
|
|
|
|
return &serial_scc_device;
|
2005-01-09 22:28:56 +00:00
|
|
|
#elif defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_440) \
|
2007-10-05 15:10:59 +00:00
|
|
|
|| defined(CONFIG_405EP) || defined(CONFIG_405EZ) || defined(CONFIG_405EX) \
|
2009-07-02 10:45:01 +00:00
|
|
|
|| defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC83xx) \
|
2010-04-23 14:05:47 +00:00
|
|
|
|| defined(CONFIG_MPC85xx) || defined(CONFIG_MPC86xx) \
|
|
|
|
|| defined(CONFIG_SYS_SC520)
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_CONS_INDEX) && defined(CONFIG_SYS_NS16550_SERIAL)
|
2006-08-30 21:02:10 +00:00
|
|
|
#if (CONFIG_CONS_INDEX==1)
|
|
|
|
return &eserial1_device;
|
|
|
|
#elif (CONFIG_CONS_INDEX==2)
|
|
|
|
return &eserial2_device;
|
|
|
|
#elif (CONFIG_CONS_INDEX==3)
|
|
|
|
return &eserial3_device;
|
|
|
|
#elif (CONFIG_CONS_INDEX==4)
|
|
|
|
return &eserial4_device;
|
|
|
|
#else
|
|
|
|
#error "Bad CONFIG_CONS_INDEX."
|
|
|
|
#endif
|
|
|
|
#elif defined(CONFIG_UART1_CONSOLE)
|
2006-06-30 14:30:46 +00:00
|
|
|
return &serial1_device;
|
|
|
|
#else
|
|
|
|
return &serial0_device;
|
|
|
|
#endif
|
2010-04-24 17:27:05 +00:00
|
|
|
#elif defined(CONFIG_MPC512X)
|
|
|
|
#if (CONFIG_PSC_CONSOLE == 3)
|
|
|
|
return &serial3_device;
|
|
|
|
#elif (CONFIG_PSC_CONSOLE == 6)
|
|
|
|
return &serial6_device;
|
|
|
|
#else
|
|
|
|
#error "Bad CONFIG_PSC_CONSOLE."
|
|
|
|
#endif
|
2007-12-19 13:24:40 +00:00
|
|
|
#elif defined(CONFIG_S3C2410)
|
|
|
|
#if defined(CONFIG_SERIAL1)
|
|
|
|
return &s3c24xx_serial0_device;
|
|
|
|
#elif defined(CONFIG_SERIAL2)
|
|
|
|
return &s3c24xx_serial1_device;
|
|
|
|
#elif defined(CONFIG_SERIAL3)
|
|
|
|
return &s3c24xx_serial2_device;
|
|
|
|
#else
|
|
|
|
#error "CONFIG_SERIAL? missing."
|
|
|
|
#endif
|
2009-10-01 08:20:28 +00:00
|
|
|
#elif defined(CONFIG_S5PC1XX)
|
|
|
|
#if defined(CONFIG_SERIAL0)
|
2010-03-24 07:59:30 +00:00
|
|
|
return &s5p_serial0_device;
|
2009-10-01 08:20:28 +00:00
|
|
|
#elif defined(CONFIG_SERIAL1)
|
2010-03-24 07:59:30 +00:00
|
|
|
return &s5p_serial1_device;
|
2009-10-01 08:20:28 +00:00
|
|
|
#elif defined(CONFIG_SERIAL2)
|
2010-03-24 07:59:30 +00:00
|
|
|
return &s5p_serial2_device;
|
2009-10-01 08:20:28 +00:00
|
|
|
#elif defined(CONFIG_SERIAL3)
|
2010-03-24 07:59:30 +00:00
|
|
|
return &s5p_serial3_device;
|
2009-10-01 08:20:28 +00:00
|
|
|
#else
|
|
|
|
#error "CONFIG_SERIAL? missing."
|
|
|
|
#endif
|
2009-05-31 10:44:37 +00:00
|
|
|
#elif defined(CONFIG_OMAP3_ZOOM2)
|
|
|
|
return ZOOM2_DEFAULT_SERIAL_DEVICE;
|
2004-08-01 22:48:16 +00:00
|
|
|
#else
|
|
|
|
#error No default console
|
|
|
|
#endif
|
|
|
|
}
|
2007-12-27 15:57:23 +00:00
|
|
|
|
|
|
|
struct serial_device *default_serial_console(void) __attribute__((weak, alias("__default_serial_console")));
|
2004-08-01 22:48:16 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-30 20:57:04 +00:00
|
|
|
int serial_register (struct serial_device *dev)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2009-09-21 16:20:36 +00:00
|
|
|
#ifndef CONFIG_RELOC_FIXUP_WORKS
|
2004-08-01 22:48:16 +00:00
|
|
|
dev->init += gd->reloc_off;
|
|
|
|
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;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
void serial_initialize (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_register (&serial_smc_device);
|
2004-08-01 22:48:16 +00:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_8xx_CONS_SCC1) || defined(CONFIG_8xx_CONS_SCC2) \
|
|
|
|
|| defined(CONFIG_8xx_CONS_SCC3) || defined(CONFIG_8xx_CONS_SCC4)
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_register (&serial_scc_device);
|
2004-08-01 22:48:16 +00:00
|
|
|
#endif
|
|
|
|
|
2005-01-09 22:28:56 +00:00
|
|
|
#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_440) \
|
2007-10-05 15:10:59 +00:00
|
|
|
|| defined(CONFIG_405EP) || defined(CONFIG_405EZ) || defined(CONFIG_405EX) \
|
|
|
|
|| defined(CONFIG_MPC5xxx)
|
2005-01-09 22:28:56 +00:00
|
|
|
serial_register(&serial0_device);
|
|
|
|
serial_register(&serial1_device);
|
|
|
|
#endif
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_NS16550_SERIAL)
|
|
|
|
#if defined(CONFIG_SYS_NS16550_COM1)
|
2006-08-30 21:02:10 +00:00
|
|
|
serial_register(&eserial1_device);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_NS16550_COM2)
|
2006-08-30 21:02:10 +00:00
|
|
|
serial_register(&eserial2_device);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_NS16550_COM3)
|
2006-08-30 21:02:10 +00:00
|
|
|
serial_register(&eserial3_device);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_NS16550_COM4)
|
2006-08-30 21:02:10 +00:00
|
|
|
serial_register(&eserial4_device);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_SYS_NS16550_SERIAL */
|
2007-08-30 20:57:04 +00:00
|
|
|
#if defined (CONFIG_FFUART)
|
|
|
|
serial_register(&serial_ffuart_device);
|
|
|
|
#endif
|
|
|
|
#if defined (CONFIG_BTUART)
|
|
|
|
serial_register(&serial_btuart_device);
|
|
|
|
#endif
|
|
|
|
#if defined (CONFIG_STUART)
|
|
|
|
serial_register(&serial_stuart_device);
|
2007-12-19 13:24:40 +00:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_S3C2410)
|
|
|
|
serial_register(&s3c24xx_serial0_device);
|
|
|
|
serial_register(&s3c24xx_serial1_device);
|
|
|
|
serial_register(&s3c24xx_serial2_device);
|
2009-10-01 08:20:28 +00:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_S5PC1XX)
|
2010-03-24 07:59:30 +00:00
|
|
|
serial_register(&s5p_serial0_device);
|
|
|
|
serial_register(&s5p_serial1_device);
|
|
|
|
serial_register(&s5p_serial2_device);
|
|
|
|
serial_register(&s5p_serial3_device);
|
2010-04-24 17:27:05 +00:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_MPC512X)
|
|
|
|
#if defined(CONFIG_SYS_PSC1)
|
|
|
|
serial_register(&serial1_device);
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SYS_PSC3)
|
|
|
|
serial_register(&serial3_device);
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SYS_PSC4)
|
|
|
|
serial_register(&serial4_device);
|
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_SYS_PSC6)
|
|
|
|
serial_register(&serial6_device);
|
|
|
|
#endif
|
2007-08-30 20:57:04 +00:00
|
|
|
#endif
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_assign (default_serial_console ()->name);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2009-05-16 10:14:54 +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) {
|
2004-08-01 22:48:16 +00:00
|
|
|
memset (&dev, 0, sizeof (dev));
|
|
|
|
|
|
|
|
strcpy (dev.name, s->name);
|
|
|
|
dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT;
|
|
|
|
|
|
|
|
dev.start = s->init;
|
2010-04-24 17:27:05 +00:00
|
|
|
dev.stop = s->uninit;
|
2004-08-01 22:48:16 +00:00
|
|
|
dev.putc = s->putc;
|
|
|
|
dev.puts = s->puts;
|
|
|
|
dev.getc = s->getc;
|
|
|
|
dev.tstc = s->tstc;
|
|
|
|
|
2009-05-16 10:14:54 +00:00
|
|
|
stdio_register (&dev);
|
2004-08-01 22:48:16 +00:00
|
|
|
|
|
|
|
s = s->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
int serial_assign (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) {
|
|
|
|
if (strcmp (s->name, name) == 0) {
|
2004-08-01 22:48:16 +00:00
|
|
|
serial_current = s;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
void serial_reinit_all (void)
|
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) {
|
|
|
|
s->init ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
int serial_init (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
return dev->init ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
return serial_current->init ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
void serial_setbrg (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
dev->setbrg ();
|
2004-08-01 22:48:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_current->setbrg ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
int serial_getc (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
return dev->getc ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
return serial_current->getc ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
int serial_tstc (void)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
return dev->tstc ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
return serial_current->tstc ();
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
void serial_putc (const char c)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
dev->putc (c);
|
2004-08-01 22:48:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_current->putc (c);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
void serial_puts (const char *s)
|
2004-08-01 22:48:16 +00:00
|
|
|
{
|
2004-10-11 22:43:02 +00:00
|
|
|
if (!(gd->flags & GD_FLG_RELOC) || !serial_current) {
|
|
|
|
struct serial_device *dev = default_serial_console ();
|
|
|
|
|
|
|
|
dev->puts (s);
|
2004-08-01 22:48:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-10-11 22:43:02 +00:00
|
|
|
serial_current->puts (s);
|
2004-08-01 22:48:16 +00:00
|
|
|
}
|