30 #ifdef CONFIG_MAGIC_SYSRQ
34 #include <linux/module.h>
39 #include <linux/tty.h>
41 #include <linux/serial_core.h>
49 #define PR_FMT "mrst_max3110: "
51 #define UART_TX_NEEDED 1
52 #define CON_TX_NEEDED 2
53 #define BIT_IRQ_PENDING 3
81 unsigned short *
str,
int len);
86 const void *txbuf,
void *rxbuf,
unsigned len,
int always_fast)
103 x.speed_hz = max->
baud;
124 ret = max3110_write_then_read(max, obuf, ibuf, 2, 1);
131 receive_chars(max, ibuf, 1);
161 if (max3110_write_then_read(max, obuf, ibuf, blen, 1)) {
172 static void serial_m3110_con_putchar(
struct uart_port *
port,
int ch)
190 static void serial_m3110_con_write(
struct console *co,
191 const char *
s,
unsigned int count)
236 static struct console serial_m3110_console = {
238 .write = serial_m3110_con_write,
239 .device = serial_m3110_con_device,
240 .setup = serial_m3110_con_setup,
243 .data = &serial_m3110_reg,
246 static unsigned int serial_m3110_tx_empty(
struct uart_port *port)
251 static void serial_m3110_stop_tx(
struct uart_port *port)
257 static void serial_m3110_stop_rx(
struct uart_port *port)
262 #define WORDS_PER_XFER 128
268 int i, len, blen, dma_size,
left, ret = 0;
276 ibuf = buf + dma_size/2;
282 blen = len *
sizeof(
u16);
285 for (i = 0; i < len; i++) {
293 ret = max3110_write_then_read(max, obuf, ibuf, blen, 0);
298 receive_chars(max, ibuf, len);
300 max->
port.icount.tx += len;
316 send_circ_buf(max, xmit);
322 serial_m3110_stop_tx(port);
329 static void serial_m3110_start_tx(
struct uart_port *port)
354 for (r = 0, w = 0; r < len; r++) {
356 uart_handle_break(port))
363 buf[w++] = str[
r] & 0xff;
372 for (r = 0;
w; r += usable, w -= usable) {
375 tty_insert_flip_string(tty, buf + r, usable);
376 port->
icount.rx += usable;
395 static void max3110_con_receive(
struct uart_max3110 *max)
400 num = max3110_read_multi(max);
408 static int max3110_main_thread(
void *_max)
424 max3110_con_receive(max);
428 send_circ_buf(max, xmit);
455 static int max3110_read_thread(
void *_max)
466 max3110_con_receive(max);
477 static int serial_m3110_startup(
struct uart_port *port)
484 if (port->
line != 0) {
496 port->
state->port.tty->low_latency = 1;
514 kthread_run(max3110_read_thread, max,
"max3110_read");
523 ret = max3110_out(max, config);
537 static void serial_m3110_shutdown(
struct uart_port *port)
553 max3110_out(max, config);
556 static void serial_m3110_release_port(
struct uart_port *port)
560 static int serial_m3110_request_port(
struct uart_port *port)
565 static void serial_m3110_config_port(
struct uart_port *port,
int flags)
578 static const char *serial_m3110_type(
struct uart_port *port)
592 unsigned int baud, parity = 0;
691 if (!max3110_out(max, new_conf)) {
699 static unsigned int serial_m3110_get_mctrl(
struct uart_port *port)
704 static void serial_m3110_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
708 static void serial_m3110_break_ctl(
struct uart_port *port,
int break_state)
712 static void serial_m3110_pm(
struct uart_port *port,
unsigned int state,
713 unsigned int oldstate)
717 static void serial_m3110_enable_ms(
struct uart_port *port)
722 .tx_empty = serial_m3110_tx_empty,
723 .set_mctrl = serial_m3110_set_mctrl,
724 .get_mctrl = serial_m3110_get_mctrl,
725 .stop_tx = serial_m3110_stop_tx,
726 .start_tx = serial_m3110_start_tx,
727 .stop_rx = serial_m3110_stop_rx,
728 .enable_ms = serial_m3110_enable_ms,
729 .break_ctl = serial_m3110_break_ctl,
730 .startup = serial_m3110_startup,
731 .shutdown = serial_m3110_shutdown,
732 .set_termios = serial_m3110_set_termios,
733 .pm = serial_m3110_pm,
734 .type = serial_m3110_type,
735 .release_port = serial_m3110_release_port,
736 .request_port = serial_m3110_request_port,
737 .config_port = serial_m3110_config_port,
738 .verify_port = serial_m3110_verify_port,
743 .driver_name =
"MRST serial",
748 .cons = &serial_m3110_console,
772 #define serial_m3110_suspend NULL
773 #define serial_m3110_resume NULL
794 max->
port.fifosize = 2;
798 max->
port.uartclk = 115200;
816 ret = max3110_write_then_read(max, (
u8 *)&res, (
u8 *)&res, 2, 0);
817 if (ret < 0 || res == 0 || res == 0xffff) {
818 dev_dbg(&spi->
dev,
"MAX3111 deemed not present (conf reg %04x)",
836 max,
"max3110_main");
842 spi_set_drvdata(spi, max);
846 max->
port.membase = (
void *)0xff110000;
876 static struct spi_driver uart_max3110_driver = {
878 .name =
"spi_max3111",
881 .probe = serial_m3110_probe,
887 static int __init serial_m3110_init(
void)
902 static void __exit serial_m3110_exit(
void)
904 spi_unregister_driver(&uart_max3110_driver);