16 #include <linux/kernel.h>
20 #include <linux/module.h>
22 #include <linux/tty.h>
24 #include <linux/serial.h>
25 #include <linux/serial_core.h>
31 #define DRV_NAME "altera_uart"
32 #define SERIAL_ALTERA_MAJOR 204
33 #define SERIAL_ALTERA_MINOR 213
40 #define ALTERA_UART_SIZE 32
42 #define ALTERA_UART_RXDATA_REG 0
43 #define ALTERA_UART_TXDATA_REG 4
44 #define ALTERA_UART_STATUS_REG 8
45 #define ALTERA_UART_CONTROL_REG 12
46 #define ALTERA_UART_DIVISOR_REG 16
47 #define ALTERA_UART_EOP_REG 20
49 #define ALTERA_UART_STATUS_PE_MSK 0x0001
50 #define ALTERA_UART_STATUS_FE_MSK 0x0002
51 #define ALTERA_UART_STATUS_BRK_MSK 0x0004
52 #define ALTERA_UART_STATUS_ROE_MSK 0x0008
53 #define ALTERA_UART_STATUS_TOE_MSK 0x0010
54 #define ALTERA_UART_STATUS_TMT_MSK 0x0020
55 #define ALTERA_UART_STATUS_TRDY_MSK 0x0040
56 #define ALTERA_UART_STATUS_RRDY_MSK 0x0080
57 #define ALTERA_UART_STATUS_E_MSK 0x0100
58 #define ALTERA_UART_STATUS_DCTS_MSK 0x0400
59 #define ALTERA_UART_STATUS_CTS_MSK 0x0800
60 #define ALTERA_UART_STATUS_EOP_MSK 0x1000
63 #define ALTERA_UART_CONTROL_PE_MSK 0x0001
64 #define ALTERA_UART_CONTROL_FE_MSK 0x0002
65 #define ALTERA_UART_CONTROL_BRK_MSK 0x0004
66 #define ALTERA_UART_CONTROL_ROE_MSK 0x0008
67 #define ALTERA_UART_CONTROL_TOE_MSK 0x0010
68 #define ALTERA_UART_CONTROL_TMT_MSK 0x0020
69 #define ALTERA_UART_CONTROL_TRDY_MSK 0x0040
70 #define ALTERA_UART_CONTROL_RRDY_MSK 0x0080
71 #define ALTERA_UART_CONTROL_E_MSK 0x0100
73 #define ALTERA_UART_CONTROL_TRBK_MSK 0x0200
74 #define ALTERA_UART_CONTROL_DCTS_MSK 0x0400
75 #define ALTERA_UART_CONTROL_RTS_MSK 0x0800
76 #define ALTERA_UART_CONTROL_EOP_MSK 0x1000
98 static unsigned int altera_uart_tx_empty(
struct uart_port *
port)
104 static unsigned int altera_uart_get_mctrl(
struct uart_port *port)
116 static void altera_uart_set_mctrl(
struct uart_port *port,
unsigned int sigs)
128 static void altera_uart_start_tx(
struct uart_port *port)
136 static void altera_uart_stop_tx(
struct uart_port *port)
144 static void altera_uart_stop_rx(
struct uart_port *port)
152 static void altera_uart_break_ctl(
struct uart_port *port,
int break_state)
158 if (break_state == -1)
163 spin_unlock_irqrestore(&port->
lock, flags);
166 static void altera_uart_enable_ms(
struct uart_port *port)
170 static void altera_uart_set_termios(
struct uart_port *port,
175 unsigned int baud, baudclk;
187 spin_unlock_irqrestore(&port->
lock, flags);
190 static void altera_uart_rx_chars(
struct altera_uart *pp)
193 unsigned char ch,
flag;
203 altera_uart_writel(port, status,
208 if (uart_handle_break(port))
220 if (status & ALTERA_UART_STATUS_BRK_MSK)
222 else if (status & ALTERA_UART_STATUS_PE_MSK)
224 else if (status & ALTERA_UART_STATUS_FE_MSK)
237 static void altera_uart_tx_chars(
struct altera_uart *pp)
254 altera_uart_writel(port, xmit->
buf[xmit->
tail],
277 spin_lock(&port->
lock);
278 if (isr & ALTERA_UART_STATUS_RRDY_MSK)
279 altera_uart_rx_chars(pp);
280 if (isr & ALTERA_UART_STATUS_TRDY_MSK)
281 altera_uart_tx_chars(pp);
282 spin_unlock(&port->
lock);
287 static void altera_uart_timer(
unsigned long data)
292 altera_uart_interrupt(0, port);
296 static void altera_uart_config_port(
struct uart_port *port,
int flags)
306 static int altera_uart_startup(
struct uart_port *port)
322 "interrupt vector=%d\n", port->
line, port->
irq);
332 spin_unlock_irqrestore(&port->
lock, flags);
337 static void altera_uart_shutdown(
struct uart_port *port)
348 spin_unlock_irqrestore(&port->
lock, flags);
356 static const char *altera_uart_type(
struct uart_port *port)
361 static int altera_uart_request_port(
struct uart_port *port)
367 static void altera_uart_release_port(
struct uart_port *port)
372 static int altera_uart_verify_port(
struct uart_port *port,
380 #ifdef CONFIG_CONSOLE_POLL
381 static int altera_uart_poll_get_char(
struct uart_port *port)
384 ALTERA_UART_STATUS_RRDY_MSK))
390 static void altera_uart_poll_put_char(
struct uart_port *port,
unsigned char c)
393 ALTERA_UART_STATUS_TRDY_MSK))
403 static struct uart_ops altera_uart_ops = {
404 .tx_empty = altera_uart_tx_empty,
405 .get_mctrl = altera_uart_get_mctrl,
406 .set_mctrl = altera_uart_set_mctrl,
407 .start_tx = altera_uart_start_tx,
408 .stop_tx = altera_uart_stop_tx,
409 .stop_rx = altera_uart_stop_rx,
410 .enable_ms = altera_uart_enable_ms,
411 .break_ctl = altera_uart_break_ctl,
412 .startup = altera_uart_startup,
413 .shutdown = altera_uart_shutdown,
414 .set_termios = altera_uart_set_termios,
415 .type = altera_uart_type,
416 .request_port = altera_uart_request_port,
417 .release_port = altera_uart_release_port,
418 .config_port = altera_uart_config_port,
419 .verify_port = altera_uart_verify_port,
420 #ifdef CONFIG_CONSOLE_POLL
421 .poll_get_char = altera_uart_poll_get_char,
422 .poll_put_char = altera_uart_poll_put_char,
426 static struct altera_uart altera_uart_ports[CONFIG_SERIAL_ALTERA_UART_MAXPORTS];
428 #if defined(CONFIG_SERIAL_ALTERA_UART_CONSOLE)
430 static void altera_uart_console_putc(
struct uart_port *port,
const char c)
433 ALTERA_UART_STATUS_TRDY_MSK))
439 static void altera_uart_console_write(
struct console *co,
const char *
s,
444 for (;
count; count--, s++) {
445 altera_uart_console_putc(port, *s);
447 altera_uart_console_putc(port,
'\r');
454 int baud = CONFIG_SERIAL_ALTERA_UART_BAUDRATE;
459 if (co->
index < 0 || co->
index >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
461 port = &altera_uart_ports[co->
index].port;
473 static struct console altera_uart_console = {
475 .write = altera_uart_console_write,
477 .setup = altera_uart_console_setup,
480 .data = &altera_uart_driver,
483 static int __init altera_uart_console_init(
void)
491 #define ALTERA_UART_CONSOLE (&altera_uart_console)
495 #define ALTERA_UART_CONSOLE NULL
508 .nr = CONFIG_SERIAL_ALTERA_UART_MAXPORTS,
520 if (!clk || len <
sizeof(
__be32))
546 for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS; i++)
547 if (altera_uart_ports[i].port.
mapbase == 0)
551 if (i < 0 || i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
554 port = &altera_uart_ports[
i].port;
574 ret = altera_uart_get_of_uartclk(pdev, port);
591 port->
ops = &altera_uart_ops;
594 platform_set_drvdata(pdev, port);
603 struct uart_port *port = platform_get_drvdata(pdev);
607 platform_set_drvdata(pdev,
NULL);
623 .probe = altera_uart_probe,
632 static int __init altera_uart_init(
void)
647 static void __exit altera_uart_exit(
void)