38 #define MAX3100_MAJOR 204
39 #define MAX3100_MINOR 209
44 #include <linux/slab.h>
45 #include <linux/device.h>
46 #include <linux/module.h>
47 #include <linux/serial_core.h>
48 #include <linux/serial.h>
51 #include <linux/tty.h>
56 #define MAX3100_C (1<<14)
57 #define MAX3100_D (0<<14)
58 #define MAX3100_W (1<<15)
59 #define MAX3100_RX (0<<15)
61 #define MAX3100_WC (MAX3100_W | MAX3100_C)
62 #define MAX3100_RC (MAX3100_RX | MAX3100_C)
63 #define MAX3100_WD (MAX3100_W | MAX3100_D)
64 #define MAX3100_RD (MAX3100_RX | MAX3100_D)
65 #define MAX3100_CMD (3 << 14)
67 #define MAX3100_T (1<<14)
68 #define MAX3100_R (1<<15)
70 #define MAX3100_FEN (1<<13)
71 #define MAX3100_SHDN (1<<12)
72 #define MAX3100_TM (1<<11)
73 #define MAX3100_RM (1<<10)
74 #define MAX3100_PM (1<<9)
75 #define MAX3100_RAM (1<<8)
76 #define MAX3100_IR (1<<7)
77 #define MAX3100_ST (1<<6)
78 #define MAX3100_PE (1<<5)
79 #define MAX3100_L (1<<4)
80 #define MAX3100_BAUD (0xf)
82 #define MAX3100_TE (1<<10)
83 #define MAX3100_RAFE (1<<10)
84 #define MAX3100_RTS (1<<9)
85 #define MAX3100_CTS (1<<9)
86 #define MAX3100_PT (1<<8)
87 #define MAX3100_DATA (0xff)
89 #define MAX3100_RT (MAX3100_R | MAX3100_T)
90 #define MAX3100_RTC (MAX3100_RT | MAX3100_CTS | MAX3100_RAFE)
93 #define MAX3100_STATUS_PE 1
94 #define MAX3100_STATUS_FE 2
95 #define MAX3100_STATUS_OE 4
113 #define MAX3100_PARITY_ON 1
114 #define MAX3100_PARITY_ODD 2
115 #define MAX3100_7BIT 4
158 parity = parity ^ (
hweight8(c) & 1);
164 return max3100_do_parity(s, c) == ((c >> 8) & 1);
175 *c |= max3100_do_parity(s, *c) << 8;
187 static void max3100_timeout(
unsigned long data)
210 spi_message_add_tail(&tran, &
message);
213 dev_warn(&s->
spi->dev,
"error while calling spi_sync\n");
218 dev_dbg(&s->
spi->dev,
"%04x - %04x\n", tx, *rx);
224 unsigned int ch, flg, status = 0;
231 s->
port.icount.frame++;
236 if (max3100_check_parity(s, rx)) {
240 s->
port.icount.parity++;
287 rxchars += max3100_handlerx(s, rx);
291 rxchars += max3100_handlerx(s, rx);
295 if (s->
port.x_char) {
300 !uart_tx_stopped(&s->
port)) {
307 max3100_calc_parity(s, &tx);
309 max3100_sr(s, tx, &rx);
310 rxchars += max3100_handlerx(s, rx);
314 if (rxchars > 16 && s->
port.state->port.tty !=
NULL) {
325 !uart_tx_stopped(&s->
port))));
327 if (rxchars > 0 && s->
port.state->port.tty !=
NULL)
352 static void max3100_start_tx(
struct uart_port *port)
363 static void max3100_stop_rx(
struct uart_port *port)
379 static unsigned int max3100_tx_empty(
struct uart_port *port)
392 static unsigned int max3100_get_mctrl(
struct uart_port *port)
406 static void max3100_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
435 u32 param_new, param_mask, parity = 0;
498 cflag = (cflag & ~CSIZE) |
CS7;
526 s->
port.ignore_status_mask = 0;
528 s->
port.ignore_status_mask |=
533 s->
port.state->port.tty->low_latency = 1;
541 s->
conf = (s->
conf & ~param_mask) | (param_new & param_mask);
548 max3100_enable_ms(&s->
port);
551 static void max3100_shutdown(
struct uart_port *port)
582 max3100_sr(s, tx, &rx);
586 static int max3100_startup(
struct uart_port *port)
609 dev_warn(&s->
spi->dev,
"cannot create workqueue\n");
626 max3100_sr(s, tx, &rx);
636 max3100_enable_ms(&s->
port);
641 static const char *max3100_type(
struct uart_port *port)
652 static void max3100_release_port(
struct uart_port *port)
661 static void max3100_config_port(
struct uart_port *port,
int flags)
673 static int max3100_verify_port(
struct uart_port *port,
688 static void max3100_stop_tx(
struct uart_port *port)
697 static int max3100_request_port(
struct uart_port *port)
707 static void max3100_break_ctl(
struct uart_port *port,
int break_state)
716 static struct uart_ops max3100_ops = {
717 .tx_empty = max3100_tx_empty,
718 .set_mctrl = max3100_set_mctrl,
719 .get_mctrl = max3100_get_mctrl,
720 .stop_tx = max3100_stop_tx,
721 .start_tx = max3100_start_tx,
722 .stop_rx = max3100_stop_rx,
723 .enable_ms = max3100_enable_ms,
724 .break_ctl = max3100_break_ctl,
725 .startup = max3100_startup,
726 .shutdown = max3100_shutdown,
727 .set_termios = max3100_set_termios,
728 .type = max3100_type,
729 .release_port = max3100_release_port,
730 .request_port = max3100_request_port,
731 .config_port = max3100_config_port,
732 .verify_port = max3100_verify_port,
737 .driver_name =
"ttyMAX",
738 .dev_name =
"ttyMAX",
743 static int uart_driver_registered;
753 if (!uart_driver_registered) {
754 uart_driver_registered = 1;
766 if (i == MAX_MAX3100) {
775 "kmalloc for max3100 structure %d failed!\n", i);
783 pdata = spi->
dev.platform_data;
792 max3100s[
i]->
timer.function = max3100_timeout;
793 max3100s[
i]->
timer.data = (
unsigned long) max3100s[i];
795 dev_dbg(&spi->
dev,
"%s: adding port %d\n", __func__, i);
796 max3100s[
i]->
port.irq = max3100s[
i]->
irq;
797 max3100s[
i]->
port.uartclk = max3100s[
i]->
crystal ? 3686400 : 1843200;
798 max3100s[
i]->
port.fifosize = 16;
799 max3100s[
i]->
port.ops = &max3100_ops;
801 max3100s[
i]->
port.line =
i;
807 "uart_add_one_port failed for line %d with error %d\n",
815 max3100_sr(max3100s[i], tx, &rx);
830 if (max3100s[i] == s) {
831 dev_dbg(&spi->
dev,
"%s: removing port %d\n", __func__, i);
846 pr_debug(
"removing max3100 driver\n");
873 max3100_sr(s, tx, &rx);
899 #define max3100_suspend NULL
900 #define max3100_resume NULL
909 .probe = max3100_probe,