13 #include <linux/module.h>
15 #include <linux/serial.h>
16 #include <linux/serial_core.h>
17 #include <linux/tty.h>
28 #define ULITE_NAME "ttyUL"
29 #define ULITE_MAJOR 204
30 #define ULITE_MINOR 187
31 #define ULITE_NR_UARTS 4
42 #define ULITE_STATUS 0x08
43 #define ULITE_CONTROL 0x0c
45 #define ULITE_REGION 16
47 #define ULITE_STATUS_RXVALID 0x01
48 #define ULITE_STATUS_RXFULL 0x02
49 #define ULITE_STATUS_TXEMPTY 0x04
50 #define ULITE_STATUS_TXFULL 0x08
51 #define ULITE_STATUS_IE 0x10
52 #define ULITE_STATUS_OVERRUN 0x20
53 #define ULITE_STATUS_FRAME 0x40
54 #define ULITE_STATUS_PARITY 0x80
56 #define ULITE_CONTROL_RST_TX 0x01
57 #define ULITE_CONTROL_RST_RX 0x02
58 #define ULITE_CONTROL_IE 0x10
95 stat &= ~ULITE_STATUS_RXVALID;
99 if (stat & ULITE_STATUS_PARITY)
105 if (stat & ULITE_STATUS_RXVALID)
106 tty_insert_flip_char(tty, ch, flag);
108 if (stat & ULITE_STATUS_FRAME)
111 if (stat & ULITE_STATUS_OVERRUN)
117 static int ulite_transmit(
struct uart_port *port,
int stat)
152 busy = ulite_receive(port, stat);
153 busy |= ulite_transmit(port, stat);
166 static unsigned int ulite_tx_empty(
struct uart_port *port)
173 spin_unlock_irqrestore(&port->
lock, flags);
178 static unsigned int ulite_get_mctrl(
struct uart_port *port)
183 static void ulite_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
188 static void ulite_stop_tx(
struct uart_port *port)
193 static void ulite_start_tx(
struct uart_port *port)
198 static void ulite_stop_rx(
struct uart_port *port)
205 static void ulite_enable_ms(
struct uart_port *port)
210 static void ulite_break_ctl(
struct uart_port *port,
int ctl)
215 static int ulite_startup(
struct uart_port *port)
230 static void ulite_shutdown(
struct uart_port *port)
260 ULITE_STATUS_RXVALID | ULITE_STATUS_PARITY
267 spin_unlock_irqrestore(&port->
lock, flags);
270 static const char *ulite_type(
struct uart_port *port)
275 static void ulite_release_port(
struct uart_port *port)
282 static int ulite_request_port(
struct uart_port *port)
284 pr_debug(
"ulite console: port=%p; port->mapbase=%llx\n",
285 port, (
unsigned long long) port->
mapbase);
294 dev_err(port->
dev,
"Unable to map registers\n");
302 static void ulite_config_port(
struct uart_port *port,
int flags)
304 if (!ulite_request_port(port))
314 #ifdef CONFIG_CONSOLE_POLL
315 static int ulite_get_poll_char(
struct uart_port *port)
318 & ULITE_STATUS_RXVALID))
324 static void ulite_put_poll_char(
struct uart_port *port,
unsigned char ch)
334 static struct uart_ops ulite_ops = {
335 .tx_empty = ulite_tx_empty,
336 .set_mctrl = ulite_set_mctrl,
337 .get_mctrl = ulite_get_mctrl,
338 .stop_tx = ulite_stop_tx,
339 .start_tx = ulite_start_tx,
340 .stop_rx = ulite_stop_rx,
341 .enable_ms = ulite_enable_ms,
342 .break_ctl = ulite_break_ctl,
343 .startup = ulite_startup,
344 .shutdown = ulite_shutdown,
345 .set_termios = ulite_set_termios,
347 .release_port = ulite_release_port,
348 .request_port = ulite_request_port,
349 .config_port = ulite_config_port,
350 .verify_port = ulite_verify_port,
351 #ifdef CONFIG_CONSOLE_POLL
352 .poll_get_char = ulite_get_poll_char,
353 .poll_put_char = ulite_put_poll_char,
361 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
362 static void ulite_console_wait_tx(
struct uart_port *port)
368 for (i = 0; i < 100000; i++) {
370 if ((val & ULITE_STATUS_TXFULL) == 0)
376 static void ulite_console_putchar(
struct uart_port *port,
int ch)
378 ulite_console_wait_tx(port);
382 static void ulite_console_write(
struct console *co,
const char *
s,
401 ulite_console_wait_tx(port);
408 spin_unlock_irqrestore(&port->
lock, flags);
422 port = &ulite_ports[co->
index];
432 if (ulite_request_port(port))
444 static struct console ulite_console = {
446 .write = ulite_console_write,
448 .setup = ulite_console_setup,
451 .data = &ulite_uart_driver,
454 static int __init ulite_console_init(
void)
466 .driver_name =
"uartlite",
471 #ifdef CONFIG_SERIAL_UARTLITE_CONSOLE
472 .cons = &ulite_console,
497 if (ulite_ports[
id].
mapbase == 0)
505 if ((ulite_ports[
id].
mapbase) && (ulite_ports[
id].mapbase != base)) {
506 dev_err(dev,
"cannot assign to %s%i; it is already in use\n",
511 port = &ulite_ports[
id];
520 port->
ops = &ulite_ops;
532 dev_err(dev,
"uart_add_one_port() failed; err=%i\n", rc);
563 #if defined(CONFIG_OF)
566 { .compatible =
"xlnx,opb-uartlite-1.00.b", },
567 { .compatible =
"xlnx,xps-uartlite-1.00.a", },
593 return ulite_assign(&pdev->
dev,
id, res->
start, res2->
start);
598 return ulite_release(&pdev->
dev);
605 .probe = ulite_probe,
622 pr_debug(
"uartlite: calling uart_register_driver()\n");
627 pr_debug(
"uartlite: calling platform_driver_register()\n");
637 printk(
KERN_ERR "registering uartlite driver failed: err=%i", ret);