]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/xscale/serial.c
35302a776183873d839ed509597fc0723f99bc8d
[karo-tx-uboot.git] / cpu / xscale / serial.c
1 /*
2  * (C) Copyright 2002
3  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * (C) Copyright 2002
10  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11  * Alex Zuepke <azu@sysgo.de>
12  *
13  * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28  *
29  */
30
31 #include <common.h>
32 #include <asm/arch/pxa-regs.h>
33
34 void serial_setbrg (void)
35 {
36         DECLARE_GLOBAL_DATA_PTR;
37
38         unsigned int quot = 0;
39
40         if (gd->baudrate == 1200)
41                 quot = 192;
42         else if (gd->baudrate == 9600)
43                 quot = 96;
44         else if (gd->baudrate == 19200)
45                 quot = 48;
46         else if (gd->baudrate == 38400)
47                 quot = 24;
48         else if (gd->baudrate == 57600)
49                 quot = 16;
50         else if (gd->baudrate == 115200)
51                 quot = 8;
52         else
53                 hang ();
54
55 #ifdef CONFIG_FFUART
56
57         CKEN |= CKEN6_FFUART;
58
59         FFIER = 0;                                      /* Disable for now */
60         FFFCR = 0;                                      /* No fifos enabled */
61
62         /* set baud rate */
63         FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB;
64         FFDLL = quot & 0xff;
65         FFDLH = quot >> 8;
66         FFLCR = LCR_WLS0 | LCR_WLS1;
67
68         FFIER = IER_UUE;                        /* Enable FFUART */
69
70 #elif CONFIG_STUART
71 #error "Bad: not implemented yet!"
72 #else
73 #error "Bad: you didn't configured serial ..."
74 #endif
75 }
76
77
78 /*
79  * Initialise the serial port with the given baudrate. The settings
80  * are always 8 data bits, no parity, 1 stop bit, no start bits.
81  *
82  */
83 int serial_init (void)
84 {
85         serial_setbrg ();
86
87         return (0);
88 }
89
90
91 /*
92  * Output a single byte to the serial port.
93  */
94 void serial_putc (const char c)
95 {
96 #ifdef CONFIG_FFUART
97         /* wait for room in the tx FIFO on FFUART */
98         while ((FFLSR & LSR_TEMT) == 0);
99
100         FFTHR = c;
101 #elif CONFIG_STUART
102 #endif
103
104         /* If \n, also do \r */
105         if (c == '\n')
106                 serial_putc ('\r');
107 }
108
109 /*
110  * Read a single byte from the serial port. Returns 1 on success, 0
111  * otherwise. When the function is succesfull, the character read is
112  * written into its argument c.
113  */
114 int serial_tstc (void)
115 {
116 #ifdef CONFIG_FFUART
117         return FFLSR & LSR_DR;
118 #elif CONFIG_STUART
119 #endif
120 }
121
122 /*
123  * Read a single byte from the serial port. Returns 1 on success, 0
124  * otherwise. When the function is succesfull, the character read is
125  * written into its argument c.
126  */
127 int serial_getc (void)
128 {
129 #ifdef CONFIG_FFUART
130         while (!(FFLSR & LSR_DR));
131
132         return (char) FFRBR & 0xff;
133 #elif CONFIG_STUART
134 #endif
135 }
136
137 void
138 serial_puts (const char *s)
139 {
140         while (*s) {
141                 serial_putc (*s++);
142         }
143 }