3 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
6 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Marius Groeger <mgroeger@sysgo.de>
10 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
11 * Alex Zuepke <azu@sysgo.de>
13 * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
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.
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.
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
34 #include <asm/arch/pxa-regs.h>
36 DECLARE_GLOBAL_DATA_PTR;
38 #define FFUART_INDEX 0
39 #define BTUART_INDEX 1
40 #define STUART_INDEX 2
42 #ifndef CONFIG_SERIAL_MULTI
43 #if defined (CONFIG_FFUART)
44 #define UART_INDEX FFUART_INDEX
45 #elif defined (CONFIG_BTUART)
46 #define UART_INDEX BTUART_INDEX
47 #elif defined (CONFIG_STUART)
48 #define UART_INDEX STUART_INDEX
50 #error "Bad: you didn't configure serial ..."
54 void pxa_setbrg_dev (unsigned int uart_index)
56 unsigned int quot = 0;
58 if (gd->baudrate == 1200)
60 else if (gd->baudrate == 9600)
62 else if (gd->baudrate == 19200)
64 else if (gd->baudrate == 38400)
66 else if (gd->baudrate == 57600)
68 else if (gd->baudrate == 115200)
75 #ifdef CONFIG_CPU_MONAHANS
76 CKENA |= CKENA_22_FFUART;
79 #endif /* CONFIG_CPU_MONAHANS */
81 FFIER = 0; /* Disable for now */
82 FFFCR = 0; /* No fifos enabled */
85 FFLCR = LCR_WLS0 | LCR_WLS1 | LCR_DLAB;
88 FFLCR = LCR_WLS0 | LCR_WLS1;
90 FFIER = IER_UUE; /* Enable FFUART */
94 #ifdef CONFIG_CPU_MONAHANS
95 CKENA |= CKENA_21_BTUART;
98 #endif /* CONFIG_CPU_MONAHANS */
107 BTLCR = LCR_WLS0 | LCR_WLS1;
109 BTIER = IER_UUE; /* Enable BFUART */
114 #ifdef CONFIG_CPU_MONAHANS
115 CKENA |= CKENA_23_STUART;
117 CKEN |= CKEN5_STUART;
118 #endif /* CONFIG_CPU_MONAHANS */
127 STLCR = LCR_WLS0 | LCR_WLS1;
129 STIER = IER_UUE; /* Enable STUART */
139 * Initialise the serial port with the given baudrate. The settings
140 * are always 8 data bits, no parity, 1 stop bit, no start bits.
143 int pxa_init_dev (unsigned int uart_index)
145 pxa_setbrg_dev (uart_index);
152 * Output a single byte to the serial port.
154 void pxa_putc_dev (unsigned int uart_index,const char c)
156 switch (uart_index) {
158 /* wait for room in the tx FIFO on FFUART */
159 while ((FFLSR & LSR_TEMT) == 0)
160 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
165 while ((BTLSR & LSR_TEMT ) == 0 )
166 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
171 while ((STLSR & LSR_TEMT ) == 0 )
172 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
177 /* If \n, also do \r */
179 pxa_putc_dev (uart_index,'\r');
183 * Read a single byte from the serial port. Returns 1 on success, 0
184 * otherwise. When the function is succesfull, the character read is
185 * written into its argument c.
187 int pxa_tstc_dev (unsigned int uart_index)
189 switch (uart_index) {
191 return FFLSR & LSR_DR;
193 return BTLSR & LSR_DR;
195 return STLSR & LSR_DR;
201 * Read a single byte from the serial port. Returns 1 on success, 0
202 * otherwise. When the function is succesfull, the character read is
203 * written into its argument c.
205 int pxa_getc_dev (unsigned int uart_index)
207 switch (uart_index) {
209 while (!(FFLSR & LSR_DR))
210 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
211 return (char) FFRBR & 0xff;
214 while (!(BTLSR & LSR_DR))
215 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
216 return (char) BTRBR & 0xff;
218 while (!(STLSR & LSR_DR))
219 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
220 return (char) STRBR & 0xff;
226 pxa_puts_dev (unsigned int uart_index,const char *s)
229 pxa_putc_dev (uart_index,*s++);
233 #if defined (CONFIG_FFUART)
234 static int ffuart_init(void)
236 return pxa_init_dev(FFUART_INDEX);
239 static void ffuart_setbrg(void)
241 return pxa_setbrg_dev(FFUART_INDEX);
244 static void ffuart_putc(const char c)
246 return pxa_putc_dev(FFUART_INDEX,c);
249 static void ffuart_puts(const char *s)
251 return pxa_puts_dev(FFUART_INDEX,s);
254 static int ffuart_getc(void)
256 return pxa_getc_dev(FFUART_INDEX);
259 static int ffuart_tstc(void)
261 return pxa_tstc_dev(FFUART_INDEX);
264 struct serial_device serial_ffuart_device =
277 #if defined (CONFIG_BTUART)
278 static int btuart_init(void)
280 return pxa_init_dev(BTUART_INDEX);
283 static void btuart_setbrg(void)
285 return pxa_setbrg_dev(BTUART_INDEX);
288 static void btuart_putc(const char c)
290 return pxa_putc_dev(BTUART_INDEX,c);
293 static void btuart_puts(const char *s)
295 return pxa_puts_dev(BTUART_INDEX,s);
298 static int btuart_getc(void)
300 return pxa_getc_dev(BTUART_INDEX);
303 static int btuart_tstc(void)
305 return pxa_tstc_dev(BTUART_INDEX);
308 struct serial_device serial_btuart_device =
321 #if defined (CONFIG_STUART)
322 static int stuart_init(void)
324 return pxa_init_dev(STUART_INDEX);
327 static void stuart_setbrg(void)
329 return pxa_setbrg_dev(STUART_INDEX);
332 static void stuart_putc(const char c)
334 return pxa_putc_dev(STUART_INDEX,c);
337 static void stuart_puts(const char *s)
339 return pxa_puts_dev(STUART_INDEX,s);
342 static int stuart_getc(void)
344 return pxa_getc_dev(STUART_INDEX);
347 static int stuart_tstc(void)
349 return pxa_tstc_dev(STUART_INDEX);
352 struct serial_device serial_stuart_device =
366 #ifndef CONFIG_SERIAL_MULTI
367 inline int serial_init(void) {
368 return (pxa_init_dev(UART_INDEX));
370 void serial_setbrg(void) {
371 pxa_setbrg_dev(UART_INDEX);
373 int serial_getc(void) {
374 return(pxa_getc_dev(UART_INDEX));
376 int serial_tstc(void) {
377 return(pxa_tstc_dev(UART_INDEX));
379 void serial_putc(const char c) {
380 pxa_putc_dev(UART_INDEX,c);
382 void serial_puts(const char *s) {
383 pxa_puts_dev(UART_INDEX,s);
385 #endif /* CONFIG_SERIAL_MULTI */