2003-03-26 06:55:25 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Lineo, Inc <www.lineo.com>
|
|
|
|
* Bernhard Kuhn <bkuhn@lineo.com>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Marius Groeger <mgroeger@sysgo.de>
|
|
|
|
*
|
|
|
|
* (C) Copyright 2002
|
|
|
|
* Sysgo Real-Time Solutions, GmbH <www.elinos.com>
|
|
|
|
* Alex Zuepke <azu@sysgo.de>
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
|
|
|
|
*
|
|
|
|
* 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>
|
2003-03-31 16:34:49 +00:00
|
|
|
#include <asm/io.h>
|
2003-06-25 22:26:29 +00:00
|
|
|
#include <asm/arch/hardware.h>
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-10-10 17:05:18 +00:00
|
|
|
#if !defined(CONFIG_DBGU) && !defined(CONFIG_USART0) && !defined(CONFIG_USART1)
|
|
|
|
#error must define one of CONFIG_DBGU or CONFIG_USART0 or CONFIG_USART1
|
2004-09-21 23:33:32 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-26 06:55:25 +00:00
|
|
|
/* ggi thunder */
|
2004-09-21 23:33:32 +00:00
|
|
|
#ifdef CONFIG_DBGU
|
2003-03-26 06:55:25 +00:00
|
|
|
AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU;
|
2004-09-21 23:33:32 +00:00
|
|
|
#endif
|
2004-10-10 17:05:18 +00:00
|
|
|
#ifdef CONFIG_USART0
|
|
|
|
AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US0;
|
|
|
|
#endif
|
2004-09-21 23:33:32 +00:00
|
|
|
#ifdef CONFIG_USART1
|
|
|
|
AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US1;
|
|
|
|
#endif
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
void serial_setbrg (void)
|
|
|
|
{
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
int baudrate;
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-10-10 17:05:18 +00:00
|
|
|
if ((baudrate = gd->baudrate) <= 0)
|
2004-03-15 09:00:01 +00:00
|
|
|
baudrate = CONFIG_BAUDRATE;
|
2005-04-20 12:36:05 +00:00
|
|
|
/* MASTER_CLOCK/(16 * baudrate) */
|
2005-08-12 20:35:59 +00:00
|
|
|
us->US_BRGR = (AT91C_MASTER_CLOCK >> 4) / (unsigned)baudrate;
|
2004-03-15 09:00:01 +00:00
|
|
|
}
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
int serial_init (void)
|
|
|
|
{
|
|
|
|
/* make any port initializations specific to this port */
|
2004-09-21 23:33:32 +00:00
|
|
|
#ifdef CONFIG_DBGU
|
2004-03-15 09:00:01 +00:00
|
|
|
*AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD; /* PA 31 & 30 */
|
|
|
|
*AT91C_PMC_PCER = 1 << AT91C_ID_SYS; /* enable clock */
|
2004-09-21 23:33:32 +00:00
|
|
|
#endif
|
2004-10-10 17:05:18 +00:00
|
|
|
#ifdef CONFIG_USART0
|
|
|
|
*AT91C_PIOA_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
|
|
|
|
*AT91C_PMC_PCER |= 1 << AT91C_ID_USART0; /* enable clock */
|
|
|
|
#endif
|
2004-09-21 23:33:32 +00:00
|
|
|
#ifdef CONFIG_USART1
|
|
|
|
*AT91C_PIOB_PDR = AT91C_PB21_TXD1 | AT91C_PB20_RXD1;
|
|
|
|
*AT91C_PMC_PCER |= 1 << AT91C_ID_USART1; /* enable clock */
|
|
|
|
#endif
|
2004-03-15 09:00:01 +00:00
|
|
|
serial_setbrg ();
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
|
|
|
|
us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
|
|
|
|
us->US_MR =
|
|
|
|
(AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS |
|
|
|
|
AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT);
|
|
|
|
us->US_IMR = ~0ul;
|
|
|
|
return (0);
|
|
|
|
}
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
void serial_putc (const char c)
|
|
|
|
{
|
|
|
|
if (c == '\n')
|
|
|
|
serial_putc ('\r');
|
|
|
|
while ((us->US_CSR & AT91C_US_TXRDY) == 0);
|
|
|
|
us->US_THR = c;
|
|
|
|
}
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
void serial_puts (const char *s)
|
|
|
|
{
|
|
|
|
while (*s) {
|
|
|
|
serial_putc (*s++);
|
|
|
|
}
|
|
|
|
}
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
int serial_getc (void)
|
|
|
|
{
|
|
|
|
while ((us->US_CSR & AT91C_US_RXRDY) == 0);
|
|
|
|
return us->US_RHR;
|
|
|
|
}
|
2003-03-26 06:55:25 +00:00
|
|
|
|
2004-03-15 09:00:01 +00:00
|
|
|
int serial_tstc (void)
|
|
|
|
{
|
|
|
|
return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY);
|
|
|
|
}
|