2004-10-10 21:27:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2004, Psyent Corporation <www.psyent.com>
|
|
|
|
* Scott McNutt <smcnutt@psyent.com>
|
|
|
|
*
|
|
|
|
* 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 <watchdog.h>
|
2006-06-08 15:59:57 +00:00
|
|
|
#include <asm/io.h>
|
2004-10-10 21:27:30 +00:00
|
|
|
#include <nios2-io.h>
|
|
|
|
|
2006-03-31 16:32:53 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2004-10-10 21:27:30 +00:00
|
|
|
/*------------------------------------------------------------------
|
|
|
|
* JTAG acts as the serial port
|
|
|
|
*-----------------------------------------------------------------*/
|
|
|
|
#if defined(CONFIG_CONSOLE_JTAG)
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
|
2004-10-10 21:27:30 +00:00
|
|
|
|
|
|
|
void serial_setbrg( void ){ return; }
|
|
|
|
int serial_init( void ) { return(0);}
|
|
|
|
|
|
|
|
void serial_putc (char c)
|
|
|
|
{
|
|
|
|
unsigned val;
|
|
|
|
|
2006-06-08 15:59:57 +00:00
|
|
|
while (NIOS_JTAG_WSPACE ( readl (&jtag->control)) == 0)
|
2004-10-10 21:27:30 +00:00
|
|
|
WATCHDOG_RESET ();
|
2006-06-08 15:59:57 +00:00
|
|
|
writel (&jtag->data, (unsigned char)c);
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void serial_puts (const char *s)
|
|
|
|
{
|
|
|
|
while (*s != 0)
|
|
|
|
serial_putc (*s++);
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_tstc (void)
|
|
|
|
{
|
2006-06-08 15:59:57 +00:00
|
|
|
return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int serial_getc (void)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
unsigned val;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
WATCHDOG_RESET ();
|
2006-06-08 15:59:57 +00:00
|
|
|
val = readl (&jtag->data);
|
2004-10-10 21:27:30 +00:00
|
|
|
if (val & NIOS_JTAG_RVALID)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
c = val & 0x0ff;
|
|
|
|
return (c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------
|
|
|
|
* UART the serial port
|
|
|
|
*-----------------------------------------------------------------*/
|
|
|
|
#else
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
static nios_uart_t *uart = (nios_uart_t *) CONFIG_SYS_NIOS_CONSOLE;
|
2004-10-10 21:27:30 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_NIOS_FIXEDBAUD)
|
2004-10-10 21:27:30 +00:00
|
|
|
|
|
|
|
/* Everything's already setup for fixed-baud PTF
|
|
|
|
* assignment
|
|
|
|
*/
|
|
|
|
void serial_setbrg (void){ return; }
|
|
|
|
int serial_init (void) { return (0);}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void serial_setbrg (void)
|
|
|
|
{
|
|
|
|
unsigned div;
|
|
|
|
|
|
|
|
div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
|
2006-06-08 15:59:57 +00:00
|
|
|
writel (&uart->divisor,div);
|
2004-10-10 21:27:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_init (void)
|
|
|
|
{
|
|
|
|
serial_setbrg ();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
|
2004-10-10 21:27:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------------
|
|
|
|
* UART CONSOLE
|
|
|
|
*---------------------------------------------------------------------*/
|
|
|
|
void serial_putc (char c)
|
|
|
|
{
|
|
|
|
if (c == '\n')
|
|
|
|
serial_putc ('\r');
|
2006-06-08 15:59:57 +00:00
|
|
|
while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
|
2004-10-10 21:27:30 +00:00
|
|
|
WATCHDOG_RESET ();
|
2006-06-08 15:59:57 +00:00
|
|
|
writel (&uart->txdata,(unsigned char)c);
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void serial_puts (const char *s)
|
|
|
|
{
|
|
|
|
while (*s != 0) {
|
|
|
|
serial_putc (*s++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_tstc (void)
|
|
|
|
{
|
2006-06-08 15:59:57 +00:00
|
|
|
return (readl (&uart->status) & NIOS_UART_RRDY);
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int serial_getc (void)
|
|
|
|
{
|
|
|
|
while (serial_tstc () == 0)
|
|
|
|
WATCHDOG_RESET ();
|
2006-06-08 15:59:57 +00:00
|
|
|
return (readl (&uart->rxdata) & 0x00ff );
|
2004-10-10 21:27:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_JTAG_CONSOLE */
|