2002-11-03 00:24:07 +00:00
|
|
|
/*
|
|
|
|
* Simple serial driver for Cogent motherboard serial ports
|
|
|
|
* for use during boot
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2013-11-11 01:30:20 +00:00
|
|
|
#include "serial.h"
|
2012-09-13 10:29:31 +00:00
|
|
|
#include <serial.h>
|
|
|
|
#include <linux/compiler.h>
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2002-11-03 00:24:07 +00:00
|
|
|
#if (CMA_MB_CAPS & CMA_MB_CAP_SERPAR)
|
|
|
|
|
|
|
|
#if (defined(CONFIG_8xx) && defined(CONFIG_8xx_CONS_NONE)) || \
|
2014-03-05 08:40:10 +00:00
|
|
|
(defined(CONFIG_MPC8260) && defined(CONFIG_CONS_NONE))
|
2002-11-03 00:24:07 +00:00
|
|
|
|
|
|
|
#if CONFIG_CONS_INDEX == 1
|
|
|
|
#define CMA_MB_SERIAL_BASE CMA_MB_SERIALA_BASE
|
|
|
|
#elif CONFIG_CONS_INDEX == 2
|
|
|
|
#define CMA_MB_SERIAL_BASE CMA_MB_SERIALB_BASE
|
|
|
|
#elif CONFIG_CONS_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
|
|
|
|
#define CMA_MB_SERIAL_BASE CMA_MB_SER2A_BASE
|
|
|
|
#elif CONFIG_CONS_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
|
|
|
|
#define CMA_MB_SERIAL_BASE CMA_MB_SER2B_BASE
|
|
|
|
#else
|
|
|
|
#error CONFIG_CONS_INDEX must be configured for Cogent motherboard serial
|
|
|
|
#endif
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static int cogent_serial_init(void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_reg_write (&mbsp->ser_ier, 0x00); /* turn off interrupts */
|
|
|
|
serial_setbrg ();
|
|
|
|
cma_mb_reg_write (&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_mcr, 0x03); /* RTS/DTR */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
return (0);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static void cogent_serial_setbrg(void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
|
|
|
|
unsigned int divisor;
|
|
|
|
unsigned char lcr;
|
|
|
|
|
|
|
|
if ((divisor = br_to_div (gd->baudrate)) == 0)
|
|
|
|
divisor = DEFDIV;
|
|
|
|
|
|
|
|
lcr = cma_mb_reg_read (&mbsp->ser_lcr);
|
|
|
|
cma_mb_reg_write (&mbsp->ser_lcr, lcr | 0x80); /* Access baud rate(set DLAB) */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_brl, divisor & 0xff);
|
|
|
|
cma_mb_reg_write (&mbsp->ser_brh, (divisor >> 8) & 0xff);
|
|
|
|
cma_mb_reg_write (&mbsp->ser_lcr, lcr); /* unset DLAB */
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static void cogent_serial_putc(const char c)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
if (c == '\n')
|
|
|
|
serial_putc ('\r');
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_THRE) == 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_reg_write (&mbsp->ser_thr, c);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static int cogent_serial_getc(void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) == 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
return ((int) cma_mb_reg_read (&mbsp->ser_rhr) & 0x7f);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static int cogent_serial_tstc(void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_SERIAL_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
return ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) != 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2012-09-13 10:29:31 +00:00
|
|
|
static struct serial_device cogent_serial_drv = {
|
|
|
|
.name = "cogent_serial",
|
|
|
|
.start = cogent_serial_init,
|
|
|
|
.stop = NULL,
|
|
|
|
.setbrg = cogent_serial_setbrg,
|
|
|
|
.putc = cogent_serial_putc,
|
2012-10-06 14:07:02 +00:00
|
|
|
.puts = default_serial_puts,
|
2012-09-13 10:29:31 +00:00
|
|
|
.getc = cogent_serial_getc,
|
|
|
|
.tstc = cogent_serial_tstc,
|
|
|
|
};
|
|
|
|
|
|
|
|
void cogent_serial_initialize(void)
|
|
|
|
{
|
|
|
|
serial_register(&cogent_serial_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak struct serial_device *default_serial_console(void)
|
|
|
|
{
|
|
|
|
return &cogent_serial_drv;
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
#endif /* CONS_NONE */
|
|
|
|
|
2007-07-09 23:19:09 +00:00
|
|
|
#if defined(CONFIG_CMD_KGDB) && \
|
2002-11-03 00:24:07 +00:00
|
|
|
defined(CONFIG_KGDB_NONE)
|
|
|
|
|
|
|
|
#if CONFIG_KGDB_INDEX == CONFIG_CONS_INDEX
|
|
|
|
#error Console and kgdb are on the same serial port - this is not supported
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_KGDB_INDEX == 1
|
|
|
|
#define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALA_BASE
|
|
|
|
#elif CONFIG_KGDB_INDEX == 2
|
|
|
|
#define CMA_MB_KGDB_SER_BASE CMA_MB_SERIALB_BASE
|
|
|
|
#elif CONFIG_KGDB_INDEX == 3 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
|
|
|
|
#define CMA_MB_KGDB_SER_BASE CMA_MB_SER2A_BASE
|
|
|
|
#elif CONFIG_KGDB_INDEX == 4 && (CMA_MB_CAPS & CMA_MB_CAP_SER2)
|
|
|
|
#define CMA_MB_KGDB_SER_BASE CMA_MB_SER2B_BASE
|
|
|
|
#else
|
|
|
|
#error CONFIG_KGDB_INDEX must be configured for Cogent motherboard serial
|
|
|
|
#endif
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
void kgdb_serial_init (void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
|
|
|
|
unsigned int divisor;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
if ((divisor = br_to_div (CONFIG_KGDB_BAUDRATE)) == 0)
|
|
|
|
divisor = DEFDIV;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_reg_write (&mbsp->ser_ier, 0x00); /* turn off interrupts */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_lcr, 0x80); /* Access baud rate(set DLAB) */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_brl, divisor & 0xff);
|
|
|
|
cma_mb_reg_write (&mbsp->ser_brh, (divisor >> 8) & 0xff);
|
|
|
|
cma_mb_reg_write (&mbsp->ser_lcr, 0x03); /* 8 data, 1 stop, no parity */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_mcr, 0x03); /* RTS/DTR */
|
|
|
|
cma_mb_reg_write (&mbsp->ser_fcr, 0x07); /* Clear & enable FIFOs */
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
printf ("[on cma10x serial port B] ");
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
void putDebugChar (int c)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_THRE) == 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_reg_write (&mbsp->ser_thr, c & 0xff);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
void putDebugStr (const char *str)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
while (*str != '\0') {
|
|
|
|
if (*str == '\n')
|
|
|
|
putDebugChar ('\r');
|
|
|
|
putDebugChar (*str++);
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
int getDebugChar (void)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
while ((cma_mb_reg_read (&mbsp->ser_lsr) & LSR_DR) == 0);
|
2002-11-03 00:24:07 +00:00
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
return ((int) cma_mb_reg_read (&mbsp->ser_rhr) & 0x7f);
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
void kgdb_interruptible (int yes)
|
2002-11-03 00:24:07 +00:00
|
|
|
{
|
2006-03-31 16:32:53 +00:00
|
|
|
cma_mb_serial *mbsp = (cma_mb_serial *) CMA_MB_KGDB_SER_BASE;
|
|
|
|
|
|
|
|
if (yes == 1) {
|
|
|
|
printf ("kgdb: turning serial ints on\n");
|
|
|
|
cma_mb_reg_write (&mbsp->ser_ier, 0xf);
|
|
|
|
} else {
|
|
|
|
printf ("kgdb: turning serial ints off\n");
|
|
|
|
cma_mb_reg_write (&mbsp->ser_ier, 0x0);
|
|
|
|
}
|
2002-11-03 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* KGDB && KGDB_NONE */
|
|
|
|
|
|
|
|
#endif /* CAPS & SERPAR */
|