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>
37 DECLARE_GLOBAL_DATA_PTR;
39 #define FFUART_INDEX 0
40 #define BTUART_INDEX 1
41 #define STUART_INDEX 2
43 #ifndef CONFIG_SERIAL_MULTI
44 #if defined (CONFIG_FFUART)
45 #define UART_INDEX FFUART_INDEX
46 #elif defined (CONFIG_BTUART)
47 #define UART_INDEX BTUART_INDEX
48 #elif defined (CONFIG_STUART)
49 #define UART_INDEX STUART_INDEX
51 #error "Bad: you didn't configure serial ..."
55 void pxa_setbrg_dev (unsigned int uart_index)
57 unsigned int quot = 0;
59 if (gd->baudrate == 1200)
61 else if (gd->baudrate == 9600)
63 else if (gd->baudrate == 19200)
65 else if (gd->baudrate == 38400)
67 else if (gd->baudrate == 57600)
69 else if (gd->baudrate == 115200)
76 #ifdef CONFIG_CPU_MONAHANS
77 writel(readl(CKENA) | CKENA_22_FFUART, CKENA);
79 writel(readl(CKEN) | CKEN6_FFUART, CKEN);
80 #endif /* CONFIG_CPU_MONAHANS */
82 writel(0, FFIER); /* Disable for now */
83 writel(0, FFFCR); /* No fifos enabled */
86 writel(LCR_WLS0 | LCR_WLS1 | LCR_DLAB, FFLCR);
87 writel(quot & 0xff, FFDLL);
88 writel(quot >> 8, FFDLH);
89 writel(LCR_WLS0 | LCR_WLS1, FFLCR);
91 writel(IER_UUE, FFIER); /* Enable FFUART */
95 #ifdef CONFIG_CPU_MONAHANS
96 writel(readl(CKENA) | CKENA_21_BTUART, CKENA);
98 writel(readl(CKEN) | CKEN7_BTUART, CKEN);
99 #endif /* CONFIG_CPU_MONAHANS */
105 writel(LCR_DLAB, BTLCR);
106 writel(quot & 0xff, BTDLL);
107 writel(quot >> 8, BTDLH);
108 writel(LCR_WLS0 | LCR_WLS1, BTLCR);
110 writel(IER_UUE, BTIER); /* Enable BFUART */
115 #ifdef CONFIG_CPU_MONAHANS
116 writel(readl(CKENA) | CKENA_23_STUART, CKENA);
118 writel(readl(CKEN) | CKEN5_STUART, CKEN);
119 #endif /* CONFIG_CPU_MONAHANS */
125 writel(LCR_DLAB, STLCR);
126 writel(quot & 0xff, STDLL);
127 writel(quot >> 8, STDLH);
128 writel(LCR_WLS0 | LCR_WLS1, STLCR);
130 writel(IER_UUE, STIER); /* Enable STUART */
140 * Initialise the serial port with the given baudrate. The settings
141 * are always 8 data bits, no parity, 1 stop bit, no start bits.
144 int pxa_init_dev (unsigned int uart_index)
146 pxa_setbrg_dev (uart_index);
153 * Output a single byte to the serial port.
155 void pxa_putc_dev (unsigned int uart_index,const char c)
157 switch (uart_index) {
159 /* wait for room in the tx FIFO on FFUART */
160 while ((readl(FFLSR) & LSR_TEMT) == 0)
161 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
166 while ((readl(BTLSR) & LSR_TEMT) == 0)
167 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
172 while ((readl(STLSR) & LSR_TEMT) == 0)
173 WATCHDOG_RESET (); /* Reset HW Watchdog, if needed */
178 /* If \n, also do \r */
180 pxa_putc_dev (uart_index,'\r');
184 * Read a single byte from the serial port. Returns 1 on success, 0
185 * otherwise. When the function is succesfull, the character read is
186 * written into its argument c.
188 int pxa_tstc_dev (unsigned int uart_index)
190 switch (uart_index) {
192 return readl(FFLSR) & LSR_DR;
194 return readl(BTLSR) & LSR_DR;
196 return readl(STLSR) & LSR_DR;
202 * Read a single byte from the serial port. Returns 1 on success, 0
203 * otherwise. When the function is succesfull, the character read is
204 * written into its argument c.
206 int pxa_getc_dev (unsigned int uart_index)
208 switch (uart_index) {
210 while (!(readl(FFLSR) & LSR_DR))
211 /* Reset HW Watchdog, if needed */
213 return (char) readl(FFRBR) & 0xff;
216 while (!(readl(BTLSR) & LSR_DR))
217 /* Reset HW Watchdog, if needed */
219 return (char) readl(BTRBR) & 0xff;
221 while (!(readl(STLSR) & LSR_DR))
222 /* Reset HW Watchdog, if needed */
224 return (char) readl(STRBR) & 0xff;
230 pxa_puts_dev (unsigned int uart_index,const char *s)
233 pxa_putc_dev (uart_index,*s++);
237 #if defined (CONFIG_FFUART)
238 static int ffuart_init(void)
240 return pxa_init_dev(FFUART_INDEX);
243 static void ffuart_setbrg(void)
245 return pxa_setbrg_dev(FFUART_INDEX);
248 static void ffuart_putc(const char c)
250 return pxa_putc_dev(FFUART_INDEX,c);
253 static void ffuart_puts(const char *s)
255 return pxa_puts_dev(FFUART_INDEX,s);
258 static int ffuart_getc(void)
260 return pxa_getc_dev(FFUART_INDEX);
263 static int ffuart_tstc(void)
265 return pxa_tstc_dev(FFUART_INDEX);
268 struct serial_device serial_ffuart_device =
282 #if defined (CONFIG_BTUART)
283 static int btuart_init(void)
285 return pxa_init_dev(BTUART_INDEX);
288 static void btuart_setbrg(void)
290 return pxa_setbrg_dev(BTUART_INDEX);
293 static void btuart_putc(const char c)
295 return pxa_putc_dev(BTUART_INDEX,c);
298 static void btuart_puts(const char *s)
300 return pxa_puts_dev(BTUART_INDEX,s);
303 static int btuart_getc(void)
305 return pxa_getc_dev(BTUART_INDEX);
308 static int btuart_tstc(void)
310 return pxa_tstc_dev(BTUART_INDEX);
313 struct serial_device serial_btuart_device =
327 #if defined (CONFIG_STUART)
328 static int stuart_init(void)
330 return pxa_init_dev(STUART_INDEX);
333 static void stuart_setbrg(void)
335 return pxa_setbrg_dev(STUART_INDEX);
338 static void stuart_putc(const char c)
340 return pxa_putc_dev(STUART_INDEX,c);
343 static void stuart_puts(const char *s)
345 return pxa_puts_dev(STUART_INDEX,s);
348 static int stuart_getc(void)
350 return pxa_getc_dev(STUART_INDEX);
353 static int stuart_tstc(void)
355 return pxa_tstc_dev(STUART_INDEX);
358 struct serial_device serial_stuart_device =
373 #ifndef CONFIG_SERIAL_MULTI
374 inline int serial_init(void) {
375 return (pxa_init_dev(UART_INDEX));
377 void serial_setbrg(void) {
378 pxa_setbrg_dev(UART_INDEX);
380 int serial_getc(void) {
381 return(pxa_getc_dev(UART_INDEX));
383 int serial_tstc(void) {
384 return(pxa_tstc_dev(UART_INDEX));
386 void serial_putc(const char c) {
387 pxa_putc_dev(UART_INDEX,c);
389 void serial_puts(const char *s) {
390 pxa_puts_dev(UART_INDEX,s);
392 #endif /* CONFIG_SERIAL_MULTI */