13 #if defined(CONFIG_SERIAL_GRLIB_GAISLER_APBUART_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
17 #include <linux/module.h>
18 #include <linux/tty.h>
22 #include <linux/serial.h>
26 #include <linux/device.h>
33 #include <linux/serial_core.h>
38 #define SERIAL_APBUART_MAJOR TTY_MAJOR
39 #define SERIAL_APBUART_MINOR 64
40 #define UART_DUMMY_RSR_RX 0x8000
62 apbuart_tx_chars(port);
65 static void apbuart_stop_rx(
struct uart_port *port)
74 static void apbuart_enable_ms(
struct uart_port *port)
79 static void apbuart_rx_chars(
struct uart_port *port)
83 unsigned int max_chars = port->
fifosize;
101 if (uart_handle_break(port))
113 if (rsr & UART_STATUS_PE)
115 else if (rsr & UART_STATUS_FE)
132 static void apbuart_tx_chars(
struct uart_port *port)
145 apbuart_stop_tx(port);
157 }
while (--count > 0);
163 apbuart_stop_tx(port);
171 spin_lock(&port->
lock);
175 apbuart_rx_chars(port);
177 apbuart_tx_chars(port);
179 spin_unlock(&port->
lock);
184 static unsigned int apbuart_tx_empty(
struct uart_port *port)
190 static unsigned int apbuart_get_mctrl(
struct uart_port *port)
196 static void apbuart_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
201 static void apbuart_break_ctl(
struct uart_port *port,
int break_state)
206 static int apbuart_startup(
struct uart_port *port)
225 static void apbuart_shutdown(
struct uart_port *port)
239 static void apbuart_set_termios(
struct uart_port *port,
244 unsigned int baud, quot;
289 spin_unlock_irqrestore(&port->
lock, flags);
292 static const char *apbuart_type(
struct uart_port *port)
297 static void apbuart_release_port(
struct uart_port *port)
302 static int apbuart_request_port(
struct uart_port *port)
310 static void apbuart_config_port(
struct uart_port *port,
int flags)
314 apbuart_request_port(port);
319 static int apbuart_verify_port(
struct uart_port *port,
332 static struct uart_ops grlib_apbuart_ops = {
333 .tx_empty = apbuart_tx_empty,
334 .set_mctrl = apbuart_set_mctrl,
335 .get_mctrl = apbuart_get_mctrl,
336 .stop_tx = apbuart_stop_tx,
337 .start_tx = apbuart_start_tx,
338 .stop_rx = apbuart_stop_rx,
339 .enable_ms = apbuart_enable_ms,
340 .break_ctl = apbuart_break_ctl,
341 .startup = apbuart_startup,
342 .shutdown = apbuart_shutdown,
343 .set_termios = apbuart_set_termios,
344 .type = apbuart_type,
345 .release_port = apbuart_release_port,
346 .request_port = apbuart_request_port,
347 .config_port = apbuart_config_port,
348 .verify_port = apbuart_verify_port,
354 static int apbuart_scan_fifo_size(
struct uart_port *port,
int portnumber)
394 while (((status >> 20) & 0x3F) == fifosize) {
411 static void apbuart_flush_fifo(
struct uart_port *port)
415 for (i = 0; i < port->
fifosize; i++)
424 #ifdef CONFIG_SERIAL_GRLIB_GAISLER_APBUART_CONSOLE
426 static void apbuart_console_putchar(
struct uart_port *port,
int ch)
436 apbuart_console_write(
struct console *co,
const char *
s,
unsigned int count)
439 unsigned int status, old_cr, new_cr;
459 apbuart_console_get_options(
struct uart_port *port,
int *baud,
460 int *parity,
int *
bits)
464 unsigned int quot,
status;
477 *baud = port->
uartclk / (16 * (quot + 1));
489 pr_debug(
"apbuart_console_setup co=%p, co->index=%i, options=%s\n",
490 co, co->
index, options);
497 if (co->
index >= grlib_apbuart_port_nr)
500 port = &grlib_apbuart_ports[co->
index];
507 apbuart_console_get_options(port, &baud, &parity, &bits);
514 static struct console grlib_apbuart_console = {
516 .write = apbuart_console_write,
518 .setup = apbuart_console_setup,
521 .data = &grlib_apbuart_driver,
525 static int grlib_apbuart_configure(
void);
527 static int __init apbuart_console_init(
void)
529 if (grlib_apbuart_configure())
537 #define APBUART_CONSOLE (&grlib_apbuart_console)
539 #define APBUART_CONSOLE NULL
544 .driver_name =
"serial",
562 for (i = 0; i < grlib_apbuart_port_nr; i++) {
563 if (op->
dev.of_node == grlib_apbuart_nodes[i])
567 port = &grlib_apbuart_ports[
i];
573 apbuart_flush_fifo((
struct uart_port *) port);
576 (
unsigned long long) port->
mapbase, port->
irq);
582 .name =
"GAISLER_APBUART",
591 .probe = apbuart_probe,
594 .name =
"grlib-apbuart",
595 .of_match_table = apbuart_match,
600 static int __init grlib_apbuart_configure(
void)
605 for_each_matching_node(np, apbuart_match) {
613 if (ampopts && (*ampopts == 0))
619 if (!regs || !freq_hz || (*freq_hz == 0))
622 grlib_apbuart_nodes[
line] = np;
626 port = &grlib_apbuart_ports[
line];
632 port->
ops = &grlib_apbuart_ops;
644 grlib_apbuart_driver.
nr = grlib_apbuart_port_nr =
line;
645 return line ? 0 : -
ENODEV;
648 static int __init grlib_apbuart_init(
void)
653 ret = grlib_apbuart_configure();
670 "%s: platform_driver_register failed (%i)\n",
679 static void __exit grlib_apbuart_exit(
void)
683 for (i = 0; i < grlib_apbuart_port_nr; i++)
685 &grlib_apbuart_ports[i]);