blob: 43e15535e6b6c7cc5e945631ee2417ccd20e64ae [file] [log] [blame]
wdenkdc7c9a12003-03-26 06:55:25 +00001/*
2 * (C) Copyright 2002
3 * Lineo, Inc <www.lineo.com>
4 * Bernhard Kuhn <bkuhn@lineo.com>
5 *
6 * (C) Copyright 2002
7 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
8 * Marius Groeger <mgroeger@sysgo.de>
9 *
10 * (C) Copyright 2002
11 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
12 * Alex Zuepke <azu@sysgo.de>
13 *
14 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
15 *
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.
20 *
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.
25 *
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
29 *
30 */
31
32#include <common.h>
wdenk85ec0bc2003-03-31 16:34:49 +000033#include <asm/io.h>
wdenkb783eda2003-06-25 22:26:29 +000034#include <asm/arch/hardware.h>
wdenkdc7c9a12003-03-26 06:55:25 +000035
36/* ggi thunder */
37AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU;
38
wdenkd9df1f42004-03-15 09:00:01 +000039void serial_setbrg (void)
40{
41 DECLARE_GLOBAL_DATA_PTR;
42 int baudrate;
wdenkdc7c9a12003-03-26 06:55:25 +000043
wdenkd9df1f42004-03-15 09:00:01 +000044 if ((baudrate = gd->bd->bi_baudrate) <= 0)
45 baudrate = CONFIG_BAUDRATE;
46 us->US_BRGR = CFG_AT91C_BRGR_DIVISOR; /* hardcode so no __divsi3 */
47}
wdenkdc7c9a12003-03-26 06:55:25 +000048
wdenkd9df1f42004-03-15 09:00:01 +000049int serial_init (void)
50{
51 /* make any port initializations specific to this port */
52 *AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD; /* PA 31 & 30 */
53 *AT91C_PMC_PCER = 1 << AT91C_ID_SYS; /* enable clock */
54 serial_setbrg ();
wdenkdc7c9a12003-03-26 06:55:25 +000055
wdenkd9df1f42004-03-15 09:00:01 +000056 us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
57 us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
58 us->US_MR =
59 (AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS |
60 AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT);
61 us->US_IMR = ~0ul;
62 return (0);
63}
wdenkdc7c9a12003-03-26 06:55:25 +000064
wdenkd9df1f42004-03-15 09:00:01 +000065void serial_putc (const char c)
66{
67 if (c == '\n')
68 serial_putc ('\r');
69 while ((us->US_CSR & AT91C_US_TXRDY) == 0);
70 us->US_THR = c;
71}
wdenkdc7c9a12003-03-26 06:55:25 +000072
wdenkd9df1f42004-03-15 09:00:01 +000073void serial_puts (const char *s)
74{
75 while (*s) {
76 serial_putc (*s++);
77 }
78}
wdenkdc7c9a12003-03-26 06:55:25 +000079
wdenkd9df1f42004-03-15 09:00:01 +000080int serial_getc (void)
81{
82 while ((us->US_CSR & AT91C_US_RXRDY) == 0);
83 return us->US_RHR;
84}
wdenkdc7c9a12003-03-26 06:55:25 +000085
wdenkd9df1f42004-03-15 09:00:01 +000086int serial_tstc (void)
87{
88 return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY);
89}