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 DECLARE_GLOBAL_DATA_PTR;
34 /* 8 data, 1 stop, no parity
40 /* Clear & enable FIFOs
44 static void fpga_serial_wait (void);
45 static void fpga_serial_print (char c);
47 void fpga_serial_init (int baudrate)
49 int clock_divisor = 115200 / baudrate;
51 out8 (FPGA (INT, SERIAL_CONFIG), 0x24);
57 out8 (UART (LCR), LCRVAL | 0x80);
59 out8 (UART (DLL), clock_divisor & 0xff);
60 out8 (UART (DLM), clock_divisor >> 8);
62 out8 (UART (LCR), LCRVAL);
64 out8 (UART (MCR), MCRVAL);
65 out8 (UART (FCR), FCRVAL);
69 void fpga_serial_putc (char c)
72 fpga_serial_print (c);
76 void fpga_serial_puts (const char *s)
79 fpga_serial_print (*s++);
83 int fpga_serial_getc (void)
85 while ((in8 (UART (LSR)) & 0x01) == 0);
87 return in8 (UART (RBR));
90 int fpga_serial_tstc (void)
92 return (in8 (UART (LSR)) & 0x01) != 0;
95 void fpga_serial_setbrg (void)
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);