3 * Lineo, Inc <www.lineo.com>
4 * Bernhard Kuhn <bkuhn@lineo.com>
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
11 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12 * Alex Zuepke <azu@sysgo.de>
14 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #ifndef CONFIG_AT91_LEGACY
36 #include <asm/arch/hardware.h>
37 #define CONFIG_AT91_LEGACY
38 #include <asm/arch-at91rm9200/AT91RM9200.h>
39 #warning Please update to use C structur SoC access !
41 #include <asm/arch/AT91RM9200.h>
44 DECLARE_GLOBAL_DATA_PTR;
46 #if !defined(CONFIG_DBGU) && !defined(CONFIG_USART0) && !defined(CONFIG_USART1)
47 #error must define one of CONFIG_DBGU or CONFIG_USART0 or CONFIG_USART1
52 AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU;
55 AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US0;
58 AT91PS_USART us = (AT91PS_USART) AT91C_BASE_US1;
61 void serial_setbrg (void)
65 if ((baudrate = gd->baudrate) <= 0)
66 baudrate = CONFIG_BAUDRATE;
67 /* MASTER_CLOCK/(16 * baudrate) */
68 us->US_BRGR = (AT91C_MASTER_CLOCK >> 4) / (unsigned)baudrate;
71 int serial_init (void)
73 /* make any port initializations specific to this port */
75 *AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD; /* PA 31 & 30 */
76 *AT91C_PMC_PCER = 1 << AT91C_ID_SYS; /* enable clock */
79 *AT91C_PIOA_PDR = AT91C_PA17_TXD0 | AT91C_PA18_RXD0;
80 *AT91C_PMC_PCER |= 1 << AT91C_ID_USART0; /* enable clock */
83 *AT91C_PIOB_PDR = AT91C_PB21_TXD1 | AT91C_PB20_RXD1;
84 *AT91C_PMC_PCER |= 1 << AT91C_ID_USART1; /* enable clock */
88 us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
89 us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
91 (AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS |
92 AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT);
97 void serial_exit (void)
99 us->US_CR = (AT91C_US_RSTRX | AT91C_US_RSTTX);
102 void serial_putc (const char c)
106 while ((us->US_CSR & AT91C_US_TXRDY) == 0);
110 void serial_puts (const char *s)
117 int serial_getc (void)
119 while ((us->US_CSR & AT91C_US_RXRDY) == 0);
123 int serial_tstc (void)
125 return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY);