3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include "fpga_serial.h"
32 /* 8 data, 1 stop, no parity
38 /* Clear & enable FIFOs
42 static void fpga_serial_wait (void);
43 static void fpga_serial_print (char c);
45 void fpga_serial_init (int baudrate)
47 int clock_divisor = 115200 / baudrate;
49 out8 (FPGA (INT, SERIAL_CONFIG), 0x24);
55 out8 (UART (LCR), LCRVAL | 0x80);
57 out8 (UART (DLL), clock_divisor & 0xff);
58 out8 (UART (DLM), clock_divisor >> 8);
60 out8 (UART (LCR), LCRVAL);
62 out8 (UART (MCR), MCRVAL);
63 out8 (UART (FCR), FCRVAL);
67 void fpga_serial_putc (char c)
70 fpga_serial_print (c);
74 void fpga_serial_puts (const char *s)
77 fpga_serial_print (*s++);
81 int fpga_serial_getc (void)
83 while ((in8 (UART (LSR)) & 0x01) == 0);
85 return in8 (UART (RBR));
88 int fpga_serial_tstc (void)
90 return (in8 (UART (LSR)) & 0x01) != 0;
93 void fpga_serial_setbrg (void)
95 DECLARE_GLOBAL_DATA_PTR;
97 int clock_divisor = 115200 / gd->baudrate;
101 out8 (UART (LCR), LCRVAL | 0x80);
103 out8 (UART (DLL), clock_divisor & 0xff);
104 out8 (UART (DLM), clock_divisor >> 8);
106 out8 (UART (LCR), LCRVAL);
110 static void fpga_serial_wait (void)
112 while ((in8 (UART (LSR)) & 0x40) == 0);
115 static void fpga_serial_print (char c)
118 while ((in8 (UART (LSR)) & 0x20) == 0);
120 out8 (UART (THR), '\r');
124 while ((in8 (UART (LSR)) & 0x20) == 0);
126 out8 (UART (THR), c);