2 * (C) Copyright 2008-2011 Michal Simek <monstr@monstr.eu>
3 * Clean driver and add xilinx constant from header file
5 * (C) Copyright 2004 Atmark Techno, Inc.
6 * Yasushi SHOJI <yashi@atmark-techno.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <linux/compiler.h>
33 #define SR_TX_FIFO_FULL 0x08 /* transmit FIFO full */
34 #define SR_RX_FIFO_VALID_DATA 0x01 /* data in receive FIFO */
35 #define SR_RX_FIFO_FULL 0x02 /* receive FIFO full */
43 static struct uartlite *userial_ports[4] = {
44 #ifdef XILINX_UARTLITE_BASEADDR
45 [0] = (struct uartlite *)XILINX_UARTLITE_BASEADDR,
47 #ifdef XILINX_UARTLITE_BASEADDR1
48 [1] = (struct uartlite *)XILINX_UARTLITE_BASEADDR1,
50 #ifdef XILINX_UARTLITE_BASEADDR2
51 [2] = (struct uartlite *)XILINX_UARTLITE_BASEADDR2,
53 #ifdef XILINX_UARTLITE_BASEADDR3
54 [3] = (struct uartlite *)XILINX_UARTLITE_BASEADDR3
58 void uartlite_serial_putc(const char c, const int port)
60 struct uartlite *regs = userial_ports[port];
63 uartlite_serial_putc('\r', port);
65 while (in_be32(®s->status) & SR_TX_FIFO_FULL)
67 out_be32(®s->tx_fifo, c & 0xff);
70 void uartlite_serial_puts(const char *s, const int port)
73 uartlite_serial_putc(*s++, port);
76 int uartlite_serial_getc(const int port)
78 struct uartlite *regs = userial_ports[port];
80 while (!(in_be32(®s->status) & SR_RX_FIFO_VALID_DATA))
82 return in_be32(®s->rx_fifo) & 0xff;
85 int uartlite_serial_tstc(const int port)
87 struct uartlite *regs = userial_ports[port];
89 return in_be32(®s->status) & SR_RX_FIFO_VALID_DATA;
92 #if !defined(CONFIG_SERIAL_MULTI)
95 /* FIXME: Nothing for now. We should initialize fifo, etc */
99 void serial_setbrg(void)
101 /* FIXME: what's this for? */
104 void serial_putc(const char c)
106 uartlite_serial_putc(c, 0);
109 void serial_puts(const char *s)
111 uartlite_serial_puts(s, 0);
114 int serial_getc(void)
116 return uartlite_serial_getc(0);
119 int serial_tstc(void)
121 return uartlite_serial_tstc(0);
125 #if defined(CONFIG_SERIAL_MULTI)
126 /* Multi serial device functions */
127 #define DECLARE_ESERIAL_FUNCTIONS(port) \
128 int userial##port##_init(void) \
130 void userial##port##_setbrg(void) {} \
131 int userial##port##_getc(void) \
132 { return uartlite_serial_getc(port); } \
133 int userial##port##_tstc(void) \
134 { return uartlite_serial_tstc(port); } \
135 void userial##port##_putc(const char c) \
136 { uartlite_serial_putc(c, port); } \
137 void userial##port##_puts(const char *s) \
138 { uartlite_serial_puts(s, port); }
140 /* Serial device descriptor */
141 #define INIT_ESERIAL_STRUCTURE(port, name) {\
143 userial##port##_init,\
145 userial##port##_setbrg,\
146 userial##port##_getc,\
147 userial##port##_tstc,\
148 userial##port##_putc,\
149 userial##port##_puts, }
151 DECLARE_ESERIAL_FUNCTIONS(0);
152 struct serial_device uartlite_serial0_device =
153 INIT_ESERIAL_STRUCTURE(0, "ttyUL0");
154 DECLARE_ESERIAL_FUNCTIONS(1);
155 struct serial_device uartlite_serial1_device =
156 INIT_ESERIAL_STRUCTURE(1, "ttyUL1");
157 DECLARE_ESERIAL_FUNCTIONS(2);
158 struct serial_device uartlite_serial2_device =
159 INIT_ESERIAL_STRUCTURE(2, "ttyUL2");
160 DECLARE_ESERIAL_FUNCTIONS(3);
161 struct serial_device uartlite_serial3_device =
162 INIT_ESERIAL_STRUCTURE(3, "ttyUL3");
164 __weak struct serial_device *default_serial_console(void)
166 # ifdef XILINX_UARTLITE_BASEADDR
167 return &uartlite_serial0_device;
168 # endif /* XILINX_UARTLITE_BASEADDR */
169 # ifdef XILINX_UARTLITE_BASEADDR1
170 return &uartlite_serial1_device;
171 # endif /* XILINX_UARTLITE_BASEADDR1 */
172 # ifdef XILINX_UARTLITE_BASEADDR2
173 return &uartlite_serial2_device;
174 # endif /* XILINX_UARTLITE_BASEADDR2 */
175 # ifdef XILINX_UARTLITE_BASEADDR3
176 return &uartlite_serial3_device;
177 # endif /* XILINX_UARTLITE_BASEADDR3 */
179 #endif /* CONFIG_SERIAL_MULTI */