]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/at91rm9200/serial.c
* Patch by Arun Dharankar, 24 Mar 2003:
[karo-tx-uboot.git] / cpu / at91rm9200 / serial.c
1 /*
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>
33 #include <asm/io.h>
34
35 /* ggi thunder */
36 AT91PS_USART us = (AT91PS_USART) AT91C_BASE_DBGU;
37
38 void serial_setbrg(void)
39   {
40   DECLARE_GLOBAL_DATA_PTR;
41   int baudrate;
42
43   if ((baudrate = gd->bd->bi_baudrate) <= 0)
44     baudrate = CONFIG_BAUDRATE;
45   us->US_BRGR = 33 /* AT91C_MASTER_CLOCK / baudrate / 16 */; /* hardcode so no __divsi3 */
46   }
47
48 int serial_init(void)
49   {
50   /* make any port initializations specific to this port */
51   *AT91C_PIOA_PDR = AT91C_PA31_DTXD | AT91C_PA30_DRXD;  /* PA 31 & 30 */
52   *AT91C_PMC_PCER = 1 << AT91C_ID_SYS;  /* enable clock */
53   serial_setbrg();
54
55   us->US_CR = AT91C_US_RSTRX | AT91C_US_RSTTX;
56   us->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;
57   us->US_MR = ( AT91C_US_CLKS_CLOCK | AT91C_US_CHRL_8_BITS | AT91C_US_PAR_NONE | AT91C_US_NBSTOP_1_BIT );
58   us->US_IMR = ~0ul;
59   return (0);
60   }
61
62 void serial_putc(const char c)
63   {
64   if (c == '\n')
65     serial_putc('\r');
66   while( (us->US_CSR & AT91C_US_TXRDY) == 0 )
67     ;
68   us->US_THR=c;
69   }
70
71 void
72 serial_puts (const char *s)
73   {
74   while (*s)
75     {
76     serial_putc (*s++);
77     }
78   }
79
80 int serial_getc(void)
81   {
82   while( (us->US_CSR & AT91C_US_RXRDY) == 0 );
83   return us->US_RHR;
84   }
85
86 int serial_tstc(void)
87   {
88   return ((us->US_CSR & AT91C_US_RXRDY) == AT91C_US_RXRDY);
89   }