PXA270: Add support for multiple serial ports.

This patch adds support for multiple serial ports to the PXA target.
FFUART, BTUART and STUART are supported.

Signed-off-by: Stefano Babic <sbabic@denx.de>
This commit is contained in:
stefano babic 2007-08-30 22:57:04 +02:00 committed by Wolfgang Denk
parent 28bb3f72c6
commit 80172c6181
4 changed files with 285 additions and 81 deletions

View file

@ -32,7 +32,7 @@ DECLARE_GLOBAL_DATA_PTR;
static struct serial_device *serial_devices = NULL; static struct serial_device *serial_devices = NULL;
static struct serial_device *serial_current = NULL; static struct serial_device *serial_current = NULL;
#ifndef CONFIG_LWMON #if !defined(CONFIG_LWMON) && !defined(CONFIG_PXA27X)
struct serial_device *default_serial_console (void) struct serial_device *default_serial_console (void)
{ {
#if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2) #if defined(CONFIG_8xx_CONS_SMC1) || defined(CONFIG_8xx_CONS_SMC2)
@ -65,7 +65,7 @@ struct serial_device *default_serial_console (void)
} }
#endif #endif
static int serial_register (struct serial_device *dev) int serial_register (struct serial_device *dev)
{ {
dev->init += gd->reloc_off; dev->init += gd->reloc_off;
dev->setbrg += gd->reloc_off; dev->setbrg += gd->reloc_off;
@ -110,6 +110,15 @@ void serial_initialize (void)
serial_register(&eserial4_device); serial_register(&eserial4_device);
#endif #endif
#endif /* CFG_NS16550_SERIAL */ #endif /* CFG_NS16550_SERIAL */
#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);
#endif
serial_assign (default_serial_console ()->name); serial_assign (default_serial_console ()->name);
} }

View file

@ -30,11 +30,28 @@
#include <common.h> #include <common.h>
#include <watchdog.h> #include <watchdog.h>
#include <serial.h>
#include <asm/arch/pxa-regs.h> #include <asm/arch/pxa-regs.h>
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
void serial_setbrg (void) #define FFUART 0
#define BTUART 1
#define STUART 2
#ifndef CONFIG_SERIAL_MULTI
#if defined (CONFIG_FFUART)
#define UART_INDEX FFUART
#elif defined (CONFIG_BTUART)
#define UART_INDEX BTUART
#elif defined (CONFIG_STUART)
#define UART_INDEX STUART
#else
#error "Bad: you didn't configure serial ..."
#endif
#endif
void pxa_setbrg_dev (unsigned int uart_index)
{ {
unsigned int quot = 0; unsigned int quot = 0;
@ -53,63 +70,68 @@ void serial_setbrg (void)
else else
hang (); hang ();
#ifdef CONFIG_FFUART switch (uart_index) {
case FFUART:
#ifdef CONFIG_CPU_MONAHANS #ifdef CONFIG_CPU_MONAHANS
CKENA |= CKENA_22_FFUART; CKENA |= CKENA_22_FFUART;
#else #else
CKEN |= CKEN6_FFUART; CKEN |= CKEN6_FFUART;
#endif /* CONFIG_CPU_MONAHANS */ #endif /* CONFIG_CPU_MONAHANS */
FFIER = 0; /* Disable for now */ FFIER = 0; /* Disable for now */
FFFCR = 0; /* No fifos enabled */ FFFCR = 0; /* No fifos enabled */
/* set baud rate */ /* set baud rate */
FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB; FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB;
FFDLL = quot & 0xff; FFDLL = quot & 0xff;
FFDLH = quot >> 8; FFDLH = quot >> 8;
FFLCR = LCR_WLS0 | LCR_WLS1; FFLCR = LCR_WLS0 | LCR_WLS1;
FFIER = IER_UUE; /* Enable FFUART */ FFIER = IER_UUE; /* Enable FFUART */
break;
#elif defined(CONFIG_BTUART) case BTUART:
#ifdef CONFIG_CPU_MONAHANS #ifdef CONFIG_CPU_MONAHANS
CKENA |= CKENA_21_BTUART; CKENA |= CKENA_21_BTUART;
#else #else
CKEN |= CKEN7_BTUART; CKEN |= CKEN7_BTUART;
#endif /* CONFIG_CPU_MONAHANS */ #endif /* CONFIG_CPU_MONAHANS */
BTIER = 0; BTIER = 0;
BTFCR = 0; BTFCR = 0;
/* set baud rate */ /* set baud rate */
BTLCR = LCR_DLAB; BTLCR = LCR_DLAB;
BTDLL = quot & 0xff; BTDLL = quot & 0xff;
BTDLH = quot >> 8; BTDLH = quot >> 8;
BTLCR = LCR_WLS0 | LCR_WLS1; BTLCR = LCR_WLS0 | LCR_WLS1;
BTIER = IER_UUE; /* Enable BFUART */ BTIER = IER_UUE; /* Enable BFUART */
#elif defined(CONFIG_STUART) break;
case STUART:
#ifdef CONFIG_CPU_MONAHANS #ifdef CONFIG_CPU_MONAHANS
CKENA |= CKENA_23_STUART; CKENA |= CKENA_23_STUART;
#else #else
CKEN |= CKEN5_STUART; CKEN |= CKEN5_STUART;
#endif /* CONFIG_CPU_MONAHANS */ #endif /* CONFIG_CPU_MONAHANS */
STIER = 0; STIER = 0;
STFCR = 0; STFCR = 0;
/* set baud rate */ /* set baud rate */
STLCR = LCR_DLAB; STLCR = LCR_DLAB;
STDLL = quot & 0xff; STDLL = quot & 0xff;
STDLH = quot >> 8; STDLH = quot >> 8;
STLCR = LCR_WLS0 | LCR_WLS1; STLCR = LCR_WLS0 | LCR_WLS1;
STIER = IER_UUE; /* Enable STUART */ STIER = IER_UUE; /* Enable STUART */
break;
#else default:
#error "Bad: you didn't configure serial ..." hang();
#endif }
} }
@ -118,9 +140,9 @@ void serial_setbrg (void)
* are always 8 data bits, no parity, 1 stop bit, no start bits. * are always 8 data bits, no parity, 1 stop bit, no start bits.
* *
*/ */
int serial_init (void) int pxa_init_dev (unsigned int uart_index)
{ {
serial_setbrg (); pxa_setbrg_dev (uart_index);
return (0); return (0);
} }
@ -129,26 +151,32 @@ int serial_init (void)
/* /*
* Output a single byte to the serial port. * Output a single byte to the serial port.
*/ */
void serial_putc (const char c) void pxa_putc_dev (unsigned int uart_index,const char c)
{ {
#ifdef CONFIG_FFUART switch (uart_index) {
/* wait for room in the tx FIFO on FFUART */ case FFUART:
while ((FFLSR & LSR_TEMT) == 0) /* wait for room in the tx FIFO on FFUART */
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ while ((FFLSR & LSR_TEMT) == 0)
FFTHR = c; WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
#elif defined(CONFIG_BTUART) FFTHR = c;
while ((BTLSR & LSR_TEMT ) == 0 ) break;
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
BTTHR = c; case BTUART:
#elif defined(CONFIG_STUART) while ((BTLSR & LSR_TEMT ) == 0 )
while ((STLSR & LSR_TEMT ) == 0 ) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ BTTHR = c;
STTHR = c; break;
#endif
case STUART:
while ((STLSR & LSR_TEMT ) == 0 )
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
STTHR = c;
break;
}
/* If \n, also do \r */ /* If \n, also do \r */
if (c == '\n') if (c == '\n')
serial_putc ('\r'); pxa_putc_dev (uart_index,'\r');
} }
/* /*
@ -156,15 +184,17 @@ void serial_putc (const char c)
* otherwise. When the function is succesfull, the character read is * otherwise. When the function is succesfull, the character read is
* written into its argument c. * written into its argument c.
*/ */
int serial_tstc (void) int pxa_tstc_dev (unsigned int uart_index)
{ {
#ifdef CONFIG_FFUART switch (uart_index) {
return FFLSR & LSR_DR; case FFUART:
#elif defined(CONFIG_BTUART) return FFLSR & LSR_DR;
return BTLSR & LSR_DR; case BTUART:
#elif defined(CONFIG_STUART) return BTLSR & LSR_DR;
return STLSR & LSR_DR; case STUART:
#endif return STLSR & LSR_DR;
}
return -1;
} }
/* /*
@ -172,27 +202,184 @@ int serial_tstc (void)
* otherwise. When the function is succesfull, the character read is * otherwise. When the function is succesfull, the character read is
* written into its argument c. * written into its argument c.
*/ */
int serial_getc (void) int pxa_getc_dev (unsigned int uart_index)
{ {
#ifdef CONFIG_FFUART switch (uart_index) {
while (!(FFLSR & LSR_DR)) case FFUART:
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ while (!(FFLSR & LSR_DR))
return (char) FFRBR & 0xff; WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
#elif defined(CONFIG_BTUART) return (char) FFRBR & 0xff;
while (!(BTLSR & LSR_DR))
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ case BTUART:
return (char) BTRBR & 0xff; while (!(BTLSR & LSR_DR))
#elif defined(CONFIG_STUART) WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
while (!(STLSR & LSR_DR)) return (char) BTRBR & 0xff;
WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */ case STUART:
return (char) STRBR & 0xff; while (!(STLSR & LSR_DR))
#endif WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
return (char) STRBR & 0xff;
}
return -1;
} }
void void
serial_puts (const char *s) pxa_puts_dev (unsigned int uart_index,const char *s)
{ {
while (*s) { while (*s) {
serial_putc (*s++); pxa_putc_dev (uart_index,*s++);
} }
} }
#if defined (CONFIG_FFUART)
static int ffuart_init(void)
{
return pxa_init_dev(FFUART);
}
static void ffuart_setbrg(void)
{
return pxa_setbrg_dev(FFUART);
}
static void ffuart_putc(const char c)
{
return pxa_putc_dev(FFUART,c);
}
static void ffuart_puts(const char *s)
{
return pxa_puts_dev(FFUART,s);
}
static int ffuart_getc(void)
{
return pxa_getc_dev(FFUART);
}
static int ffuart_tstc(void)
{
return pxa_tstc_dev(FFUART);
}
struct serial_device serial_ffuart_device =
{
"serial_ffuart",
"PXA",
ffuart_init,
ffuart_setbrg,
ffuart_getc,
ffuart_tstc,
ffuart_putc,
ffuart_puts,
};
#endif
#if defined (CONFIG_BTUART)
static int btuart_init(void)
{
return pxa_init_dev(BTUART);
}
static void btuart_setbrg(void)
{
return pxa_setbrg_dev(BTUART);
}
static void btuart_putc(const char c)
{
return pxa_putc_dev(BTUART,c);
}
static void btuart_puts(const char *s)
{
return pxa_puts_dev(BTUART,s);
}
static int btuart_getc(void)
{
return pxa_getc_dev(BTUART);
}
static int btuart_tstc(void)
{
return pxa_tstc_dev(BTUART);
}
struct serial_device serial_btuart_device =
{
"serial_btuart",
"PXA",
btuart_init,
btuart_setbrg,
btuart_getc,
btuart_tstc,
btuart_putc,
btuart_puts,
};
#endif
#if defined (CONFIG_STUART)
static int stuart_init(void)
{
return pxa_init_dev(STUART);
}
static void stuart_setbrg(void)
{
return pxa_setbrg_dev(STUART);
}
static void stuart_putc(const char c)
{
return pxa_putc_dev(STUART,c);
}
static void stuart_puts(const char *s)
{
return pxa_puts_dev(STUART,s);
}
static int stuart_getc(void)
{
return pxa_getc_dev(STUART);
}
static int stuart_tstc(void)
{
return pxa_tstc_dev(STUART);
}
struct serial_device serial_stuart_device =
{
"serial_stuart",
"PXA",
stuart_init,
stuart_setbrg,
stuart_getc,
stuart_tstc,
stuart_putc,
stuart_puts,
};
#endif
#ifndef CONFIG_SERIAL_MULTI
inline int serial_init(void) {
return (pxa_init_dev(UART_INDEX));
}
void serial_setbrg(void) {
pxa_setbrg_dev(UART_INDEX);
}
int serial_getc(void) {
return(pxa_getc_dev(UART_INDEX));
}
int serial_tstc(void) {
return(pxa_tstc_dev(UART_INDEX));
}
void serial_putc(const char c) {
pxa_putc_dev(UART_INDEX,c);
}
void serial_puts(const char *s) {
pxa_puts_dev(UART_INDEX,s);
}
#endif /* CONFIG_SERIAL_MULTI */

View file

@ -36,6 +36,10 @@ extern struct serial_device eserial4_device;
#endif #endif
extern struct serial_device serial_ffuart_device;
extern struct serial_device serial_btuart_device;
extern struct serial_device serial_stuart_device;
extern void serial_initialize(void); extern void serial_initialize(void);
extern void serial_devices_init(void); extern void serial_devices_init(void);
extern int serial_assign(char * name); extern int serial_assign(char * name);

View file

@ -314,6 +314,10 @@ void start_armboot (void)
drv_vfd_init(); drv_vfd_init();
#endif /* CONFIG_VFD */ #endif /* CONFIG_VFD */
#ifdef CONFIG_SERIAL_MULTI
serial_initialize();
#endif
/* IP Address */ /* IP Address */
gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr"); gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");