Char: mxser, simplify mxser_get_serial_info
[linux-2.6/verdex.git] / drivers / char / mxser_new.c
blob937c101db905aef1c0b126a51286c6787f676605
1 /*
2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com.tw).
5 * Copyright (C) 2006-2007 Jiri Slaby <jirislaby@gmail.com>
7 * This code is loosely based on the 1.8 moxa driver which is based on
8 * Linux serial driver, written by Linus Torvalds, Theodore T'so and
9 * others.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
18 * - Fixed x86_64 cleanness
19 * - Fixed sleep with spinlock held in mxser_send_break
22 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/interrupt.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/serial.h>
31 #include <linux/serial_reg.h>
32 #include <linux/major.h>
33 #include <linux/string.h>
34 #include <linux/fcntl.h>
35 #include <linux/ptrace.h>
36 #include <linux/gfp.h>
37 #include <linux/ioport.h>
38 #include <linux/mm.h>
39 #include <linux/delay.h>
40 #include <linux/pci.h>
41 #include <linux/bitops.h>
43 #include <asm/system.h>
44 #include <asm/io.h>
45 #include <asm/irq.h>
46 #include <asm/uaccess.h>
48 #include "mxser_new.h"
50 #define MXSER_VERSION "2.0.2" /* 1.10 */
51 #define MXSERMAJOR 174
52 #define MXSERCUMAJOR 175
54 #define MXSER_BOARDS 4 /* Max. boards */
55 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
56 #define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
57 #define MXSER_ISR_PASS_LIMIT 100
59 #define MXSER_ERR_IOADDR -1
60 #define MXSER_ERR_IRQ -2
61 #define MXSER_ERR_IRQ_CONFLIT -3
62 #define MXSER_ERR_VECTOR -4
64 /*CheckIsMoxaMust return value*/
65 #define MOXA_OTHER_UART 0x00
66 #define MOXA_MUST_MU150_HWID 0x01
67 #define MOXA_MUST_MU860_HWID 0x02
69 #define WAKEUP_CHARS 256
71 #define UART_MCR_AFE 0x20
72 #define UART_LSR_SPECIAL 0x1E
74 #define PCI_DEVICE_ID_CB108 0x1080
75 #define PCI_DEVICE_ID_CB114 0x1142
76 #define PCI_DEVICE_ID_CB134I 0x1341
77 #define PCI_DEVICE_ID_CP138U 0x1380
78 #define PCI_DEVICE_ID_POS104UL 0x1044
81 #define C168_ASIC_ID 1
82 #define C104_ASIC_ID 2
83 #define C102_ASIC_ID 0xB
84 #define CI132_ASIC_ID 4
85 #define CI134_ASIC_ID 3
86 #define CI104J_ASIC_ID 5
88 #define MXSER_HIGHBAUD 1
89 #define MXSER_HAS2 2
91 /* This is only for PCI */
92 static const struct {
93 int type;
94 int tx_fifo;
95 int rx_fifo;
96 int xmit_fifo_size;
97 int rx_high_water;
98 int rx_trigger;
99 int rx_low_water;
100 long max_baud;
101 } Gpci_uart_info[] = {
102 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
103 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
104 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
106 #define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
108 struct mxser_cardinfo {
109 char *name;
110 unsigned int nports;
111 unsigned int flags;
114 static const struct mxser_cardinfo mxser_cards[] = {
115 /* 0*/ { "C168 series", 8, },
116 { "C104 series", 4, },
117 { "CI-104J series", 4, },
118 { "C168H/PCI series", 8, },
119 { "C104H/PCI series", 4, },
120 /* 5*/ { "C102 series", 4, MXSER_HAS2 }, /* C102-ISA */
121 { "CI-132 series", 4, MXSER_HAS2 },
122 { "CI-134 series", 4, },
123 { "CP-132 series", 2, },
124 { "CP-114 series", 4, },
125 /*10*/ { "CT-114 series", 4, },
126 { "CP-102 series", 2, MXSER_HIGHBAUD },
127 { "CP-104U series", 4, },
128 { "CP-168U series", 8, },
129 { "CP-132U series", 2, },
130 /*15*/ { "CP-134U series", 4, },
131 { "CP-104JU series", 4, },
132 { "Moxa UC7000 Serial", 8, }, /* RC7000 */
133 { "CP-118U series", 8, },
134 { "CP-102UL series", 2, },
135 /*20*/ { "CP-102U series", 2, },
136 { "CP-118EL series", 8, },
137 { "CP-168EL series", 8, },
138 { "CP-104EL series", 4, },
139 { "CB-108 series", 8, },
140 /*25*/ { "CB-114 series", 4, },
141 { "CB-134I series", 4, },
142 { "CP-138U series", 8, },
143 { "POS-104UL series", 4, }
146 /* driver_data correspond to the lines in the structure above
147 see also ISA probe function before you change something */
148 static struct pci_device_id mxser_pcibrds[] = {
149 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168), .driver_data = 3 },
150 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104), .driver_data = 4 },
151 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132), .driver_data = 8 },
152 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114), .driver_data = 9 },
153 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CT114), .driver_data = 10 },
154 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102), .driver_data = 11 },
155 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U), .driver_data = 12 },
156 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U), .driver_data = 13 },
157 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U), .driver_data = 14 },
158 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U), .driver_data = 15 },
159 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104JU),.driver_data = 16 },
160 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_RC7000), .driver_data = 17 },
161 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U), .driver_data = 18 },
162 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),.driver_data = 19 },
163 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U), .driver_data = 20 },
164 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL),.driver_data = 21 },
165 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL),.driver_data = 22 },
166 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL),.driver_data = 23 },
167 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB108), .driver_data = 24 },
168 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB114), .driver_data = 25 },
169 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CB134I), .driver_data = 26 },
170 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U), .driver_data = 27 },
171 { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_POS104UL), .driver_data = 28 },
174 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
176 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
177 static int ttymajor = MXSERMAJOR;
178 static int calloutmajor = MXSERCUMAJOR;
180 /* Variables for insmod */
182 MODULE_AUTHOR("Casper Yang");
183 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
184 module_param_array(ioaddr, int, NULL, 0);
185 module_param(ttymajor, int, 0);
186 MODULE_LICENSE("GPL");
188 struct mxser_log {
189 int tick;
190 unsigned long rxcnt[MXSER_PORTS];
191 unsigned long txcnt[MXSER_PORTS];
195 struct mxser_mon {
196 unsigned long rxcnt;
197 unsigned long txcnt;
198 unsigned long up_rxcnt;
199 unsigned long up_txcnt;
200 int modem_status;
201 unsigned char hold_reason;
204 struct mxser_mon_ext {
205 unsigned long rx_cnt[32];
206 unsigned long tx_cnt[32];
207 unsigned long up_rxcnt[32];
208 unsigned long up_txcnt[32];
209 int modem_status[32];
211 long baudrate[32];
212 int databits[32];
213 int stopbits[32];
214 int parity[32];
215 int flowctrl[32];
216 int fifo[32];
217 int iftype[32];
220 struct mxser_board;
222 struct mxser_port {
223 struct mxser_board *board;
224 struct tty_struct *tty;
226 unsigned long ioaddr;
227 unsigned long opmode_ioaddr;
228 int max_baud;
230 int rx_high_water;
231 int rx_trigger; /* Rx fifo trigger level */
232 int rx_low_water;
233 int baud_base; /* max. speed */
234 int type; /* UART type */
235 int flags; /* defined in tty.h */
237 int x_char; /* xon/xoff character */
238 int IER; /* Interrupt Enable Register */
239 int MCR; /* Modem control register */
241 unsigned char stop_rx;
242 unsigned char ldisc_stop_rx;
244 int custom_divisor;
245 int close_delay;
246 unsigned short closing_wait;
247 unsigned char err_shadow;
248 unsigned long event;
250 int count; /* # of fd on device */
251 int blocked_open; /* # of blocked opens */
252 struct async_icount icount; /* kernel counters for 4 input interrupts */
253 int timeout;
255 int read_status_mask;
256 int ignore_status_mask;
257 int xmit_fifo_size;
258 unsigned char *xmit_buf;
259 int xmit_head;
260 int xmit_tail;
261 int xmit_cnt;
263 struct ktermios normal_termios;
265 struct mxser_mon mon_data;
267 spinlock_t slock;
268 wait_queue_head_t open_wait;
269 wait_queue_head_t delta_msr_wait;
272 struct mxser_board {
273 unsigned int idx;
274 int irq;
275 const struct mxser_cardinfo *info;
276 unsigned long vector;
277 unsigned long vector_mask;
279 int chip_flag;
280 int uart_type;
282 struct mxser_port ports[MXSER_PORTS_PER_BOARD];
285 struct mxser_mstatus {
286 tcflag_t cflag;
287 int cts;
288 int dsr;
289 int ri;
290 int dcd;
293 static struct mxser_mstatus GMStatus[MXSER_PORTS];
295 static int mxserBoardCAP[MXSER_BOARDS] = {
296 0, 0, 0, 0
297 /* 0x180, 0x280, 0x200, 0x320 */
300 static struct mxser_board mxser_boards[MXSER_BOARDS];
301 static struct tty_driver *mxvar_sdriver;
302 static struct mxser_log mxvar_log;
303 static int mxvar_diagflag;
304 static unsigned char mxser_msr[MXSER_PORTS + 1];
305 static struct mxser_mon_ext mon_data_ext;
306 static int mxser_set_baud_method[MXSER_PORTS + 1];
308 #ifdef CONFIG_PCI
309 static int __devinit CheckIsMoxaMust(unsigned long io)
311 u8 oldmcr, hwid;
312 int i;
314 outb(0, io + UART_LCR);
315 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
316 oldmcr = inb(io + UART_MCR);
317 outb(0, io + UART_MCR);
318 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
319 if ((hwid = inb(io + UART_MCR)) != 0) {
320 outb(oldmcr, io + UART_MCR);
321 return MOXA_OTHER_UART;
324 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
325 for (i = 1; i < UART_INFO_NUM; i++) { /* 0 = OTHER_UART */
326 if (hwid == Gpci_uart_info[i].type)
327 return (int)hwid;
329 return MOXA_OTHER_UART;
331 #endif
333 static void process_txrx_fifo(struct mxser_port *info)
335 int i;
337 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
338 info->rx_trigger = 1;
339 info->rx_high_water = 1;
340 info->rx_low_water = 1;
341 info->xmit_fifo_size = 1;
342 } else
343 for (i = 0; i < UART_INFO_NUM; i++)
344 if (info->board->chip_flag == Gpci_uart_info[i].type) {
345 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
346 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
347 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
348 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
349 break;
353 static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
355 unsigned char status = 0;
357 status = inb(baseaddr + UART_MSR);
359 mxser_msr[port] &= 0x0F;
360 mxser_msr[port] |= status;
361 status = mxser_msr[port];
362 if (mode)
363 mxser_msr[port] = 0;
365 return status;
368 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
369 struct mxser_port *port)
371 DECLARE_WAITQUEUE(wait, current);
372 int retval;
373 int do_clocal = 0;
374 unsigned long flags;
377 * If non-blocking mode is set, or the port is not enabled,
378 * then make the check up front and then exit.
380 if ((filp->f_flags & O_NONBLOCK) ||
381 test_bit(TTY_IO_ERROR, &tty->flags)) {
382 port->flags |= ASYNC_NORMAL_ACTIVE;
383 return 0;
386 if (tty->termios->c_cflag & CLOCAL)
387 do_clocal = 1;
390 * Block waiting for the carrier detect and the line to become
391 * free (i.e., not in use by the callout). While we are in
392 * this loop, port->count is dropped by one, so that
393 * mxser_close() knows when to free things. We restore it upon
394 * exit, either normal or abnormal.
396 retval = 0;
397 add_wait_queue(&port->open_wait, &wait);
399 spin_lock_irqsave(&port->slock, flags);
400 if (!tty_hung_up_p(filp))
401 port->count--;
402 spin_unlock_irqrestore(&port->slock, flags);
403 port->blocked_open++;
404 while (1) {
405 spin_lock_irqsave(&port->slock, flags);
406 outb(inb(port->ioaddr + UART_MCR) |
407 UART_MCR_DTR | UART_MCR_RTS, port->ioaddr + UART_MCR);
408 spin_unlock_irqrestore(&port->slock, flags);
409 set_current_state(TASK_INTERRUPTIBLE);
410 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
411 if (port->flags & ASYNC_HUP_NOTIFY)
412 retval = -EAGAIN;
413 else
414 retval = -ERESTARTSYS;
415 break;
417 if (!(port->flags & ASYNC_CLOSING) &&
418 (do_clocal ||
419 (inb(port->ioaddr + UART_MSR) & UART_MSR_DCD)))
420 break;
421 if (signal_pending(current)) {
422 retval = -ERESTARTSYS;
423 break;
425 schedule();
427 set_current_state(TASK_RUNNING);
428 remove_wait_queue(&port->open_wait, &wait);
429 if (!tty_hung_up_p(filp))
430 port->count++;
431 port->blocked_open--;
432 if (retval)
433 return retval;
434 port->flags |= ASYNC_NORMAL_ACTIVE;
435 return 0;
438 static int mxser_set_baud(struct mxser_port *info, long newspd)
440 int quot = 0, baud;
441 unsigned char cval;
443 if (!info->tty || !info->tty->termios)
444 return -1;
446 if (!(info->ioaddr))
447 return -1;
449 if (newspd > info->max_baud)
450 return -1;
452 if (newspd == 134) {
453 quot = 2 * info->baud_base / 269;
454 tty_encode_baud_rate(info->tty, 134, 134);
455 } else if (newspd) {
456 quot = info->baud_base / newspd;
457 if (quot == 0)
458 quot = 1;
459 baud = info->baud_base/quot;
460 tty_encode_baud_rate(info->tty, baud, baud);
461 } else {
462 quot = 0;
465 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
466 info->timeout += HZ / 50; /* Add .02 seconds of slop */
468 if (quot) {
469 info->MCR |= UART_MCR_DTR;
470 outb(info->MCR, info->ioaddr + UART_MCR);
471 } else {
472 info->MCR &= ~UART_MCR_DTR;
473 outb(info->MCR, info->ioaddr + UART_MCR);
474 return 0;
477 cval = inb(info->ioaddr + UART_LCR);
479 outb(cval | UART_LCR_DLAB, info->ioaddr + UART_LCR); /* set DLAB */
481 outb(quot & 0xff, info->ioaddr + UART_DLL); /* LS of divisor */
482 outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
483 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
485 #ifdef BOTHER
486 if (C_BAUD(info->tty) == BOTHER) {
487 quot = info->baud_base % newspd;
488 quot *= 8;
489 if (quot % newspd > newspd / 2) {
490 quot /= newspd;
491 quot++;
492 } else
493 quot /= newspd;
495 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, quot);
496 } else
497 #endif
498 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, 0);
500 return 0;
504 * This routine is called to set the UART divisor registers to match
505 * the specified baud rate for a serial port.
507 static int mxser_change_speed(struct mxser_port *info,
508 struct ktermios *old_termios)
510 unsigned cflag, cval, fcr;
511 int ret = 0;
512 unsigned char status;
514 if (!info->tty || !info->tty->termios)
515 return ret;
516 cflag = info->tty->termios->c_cflag;
517 if (!(info->ioaddr))
518 return ret;
520 if (mxser_set_baud_method[info->tty->index] == 0)
521 mxser_set_baud(info, tty_get_baud_rate(info->tty));
523 /* byte size and parity */
524 switch (cflag & CSIZE) {
525 case CS5:
526 cval = 0x00;
527 break;
528 case CS6:
529 cval = 0x01;
530 break;
531 case CS7:
532 cval = 0x02;
533 break;
534 case CS8:
535 cval = 0x03;
536 break;
537 default:
538 cval = 0x00;
539 break; /* too keep GCC shut... */
541 if (cflag & CSTOPB)
542 cval |= 0x04;
543 if (cflag & PARENB)
544 cval |= UART_LCR_PARITY;
545 if (!(cflag & PARODD))
546 cval |= UART_LCR_EPAR;
547 if (cflag & CMSPAR)
548 cval |= UART_LCR_SPAR;
550 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
551 if (info->board->chip_flag) {
552 fcr = UART_FCR_ENABLE_FIFO;
553 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
554 SET_MOXA_MUST_FIFO_VALUE(info);
555 } else
556 fcr = 0;
557 } else {
558 fcr = UART_FCR_ENABLE_FIFO;
559 if (info->board->chip_flag) {
560 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
561 SET_MOXA_MUST_FIFO_VALUE(info);
562 } else {
563 switch (info->rx_trigger) {
564 case 1:
565 fcr |= UART_FCR_TRIGGER_1;
566 break;
567 case 4:
568 fcr |= UART_FCR_TRIGGER_4;
569 break;
570 case 8:
571 fcr |= UART_FCR_TRIGGER_8;
572 break;
573 default:
574 fcr |= UART_FCR_TRIGGER_14;
575 break;
580 /* CTS flow control flag and modem status interrupts */
581 info->IER &= ~UART_IER_MSI;
582 info->MCR &= ~UART_MCR_AFE;
583 if (cflag & CRTSCTS) {
584 info->flags |= ASYNC_CTS_FLOW;
585 info->IER |= UART_IER_MSI;
586 if ((info->type == PORT_16550A) || (info->board->chip_flag)) {
587 info->MCR |= UART_MCR_AFE;
588 } else {
589 status = inb(info->ioaddr + UART_MSR);
590 if (info->tty->hw_stopped) {
591 if (status & UART_MSR_CTS) {
592 info->tty->hw_stopped = 0;
593 if (info->type != PORT_16550A &&
594 !info->board->chip_flag) {
595 outb(info->IER & ~UART_IER_THRI,
596 info->ioaddr +
597 UART_IER);
598 info->IER |= UART_IER_THRI;
599 outb(info->IER, info->ioaddr +
600 UART_IER);
602 tty_wakeup(info->tty);
604 } else {
605 if (!(status & UART_MSR_CTS)) {
606 info->tty->hw_stopped = 1;
607 if ((info->type != PORT_16550A) &&
608 (!info->board->chip_flag)) {
609 info->IER &= ~UART_IER_THRI;
610 outb(info->IER, info->ioaddr +
611 UART_IER);
616 } else {
617 info->flags &= ~ASYNC_CTS_FLOW;
619 outb(info->MCR, info->ioaddr + UART_MCR);
620 if (cflag & CLOCAL) {
621 info->flags &= ~ASYNC_CHECK_CD;
622 } else {
623 info->flags |= ASYNC_CHECK_CD;
624 info->IER |= UART_IER_MSI;
626 outb(info->IER, info->ioaddr + UART_IER);
629 * Set up parity check flag
631 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
632 if (I_INPCK(info->tty))
633 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
634 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
635 info->read_status_mask |= UART_LSR_BI;
637 info->ignore_status_mask = 0;
639 if (I_IGNBRK(info->tty)) {
640 info->ignore_status_mask |= UART_LSR_BI;
641 info->read_status_mask |= UART_LSR_BI;
643 * If we're ignore parity and break indicators, ignore
644 * overruns too. (For real raw support).
646 if (I_IGNPAR(info->tty)) {
647 info->ignore_status_mask |=
648 UART_LSR_OE |
649 UART_LSR_PE |
650 UART_LSR_FE;
651 info->read_status_mask |=
652 UART_LSR_OE |
653 UART_LSR_PE |
654 UART_LSR_FE;
657 if (info->board->chip_flag) {
658 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty));
659 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty));
660 if (I_IXON(info->tty)) {
661 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
662 } else {
663 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
665 if (I_IXOFF(info->tty)) {
666 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
667 } else {
668 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
673 outb(fcr, info->ioaddr + UART_FCR); /* set fcr */
674 outb(cval, info->ioaddr + UART_LCR);
676 return ret;
679 static void mxser_check_modem_status(struct mxser_port *port, int status)
681 /* update input line counters */
682 if (status & UART_MSR_TERI)
683 port->icount.rng++;
684 if (status & UART_MSR_DDSR)
685 port->icount.dsr++;
686 if (status & UART_MSR_DDCD)
687 port->icount.dcd++;
688 if (status & UART_MSR_DCTS)
689 port->icount.cts++;
690 port->mon_data.modem_status = status;
691 wake_up_interruptible(&port->delta_msr_wait);
693 if ((port->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
694 if (status & UART_MSR_DCD)
695 wake_up_interruptible(&port->open_wait);
698 if (port->flags & ASYNC_CTS_FLOW) {
699 if (port->tty->hw_stopped) {
700 if (status & UART_MSR_CTS) {
701 port->tty->hw_stopped = 0;
703 if ((port->type != PORT_16550A) &&
704 (!port->board->chip_flag)) {
705 outb(port->IER & ~UART_IER_THRI,
706 port->ioaddr + UART_IER);
707 port->IER |= UART_IER_THRI;
708 outb(port->IER, port->ioaddr +
709 UART_IER);
711 tty_wakeup(port->tty);
713 } else {
714 if (!(status & UART_MSR_CTS)) {
715 port->tty->hw_stopped = 1;
716 if (port->type != PORT_16550A &&
717 !port->board->chip_flag) {
718 port->IER &= ~UART_IER_THRI;
719 outb(port->IER, port->ioaddr +
720 UART_IER);
727 static int mxser_startup(struct mxser_port *info)
729 unsigned long page;
730 unsigned long flags;
732 page = __get_free_page(GFP_KERNEL);
733 if (!page)
734 return -ENOMEM;
736 spin_lock_irqsave(&info->slock, flags);
738 if (info->flags & ASYNC_INITIALIZED) {
739 free_page(page);
740 spin_unlock_irqrestore(&info->slock, flags);
741 return 0;
744 if (!info->ioaddr || !info->type) {
745 if (info->tty)
746 set_bit(TTY_IO_ERROR, &info->tty->flags);
747 free_page(page);
748 spin_unlock_irqrestore(&info->slock, flags);
749 return 0;
751 if (info->xmit_buf)
752 free_page(page);
753 else
754 info->xmit_buf = (unsigned char *) page;
757 * Clear the FIFO buffers and disable them
758 * (they will be reenabled in mxser_change_speed())
760 if (info->board->chip_flag)
761 outb((UART_FCR_CLEAR_RCVR |
762 UART_FCR_CLEAR_XMIT |
763 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->ioaddr + UART_FCR);
764 else
765 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
766 info->ioaddr + UART_FCR);
769 * At this point there's no way the LSR could still be 0xFF;
770 * if it is, then bail out, because there's likely no UART
771 * here.
773 if (inb(info->ioaddr + UART_LSR) == 0xff) {
774 spin_unlock_irqrestore(&info->slock, flags);
775 if (capable(CAP_SYS_ADMIN)) {
776 if (info->tty)
777 set_bit(TTY_IO_ERROR, &info->tty->flags);
778 return 0;
779 } else
780 return -ENODEV;
784 * Clear the interrupt registers.
786 (void) inb(info->ioaddr + UART_LSR);
787 (void) inb(info->ioaddr + UART_RX);
788 (void) inb(info->ioaddr + UART_IIR);
789 (void) inb(info->ioaddr + UART_MSR);
792 * Now, initialize the UART
794 outb(UART_LCR_WLEN8, info->ioaddr + UART_LCR); /* reset DLAB */
795 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
796 outb(info->MCR, info->ioaddr + UART_MCR);
799 * Finally, enable interrupts
801 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
803 if (info->board->chip_flag)
804 info->IER |= MOXA_MUST_IER_EGDAI;
805 outb(info->IER, info->ioaddr + UART_IER); /* enable interrupts */
808 * And clear the interrupt registers again for luck.
810 (void) inb(info->ioaddr + UART_LSR);
811 (void) inb(info->ioaddr + UART_RX);
812 (void) inb(info->ioaddr + UART_IIR);
813 (void) inb(info->ioaddr + UART_MSR);
815 if (info->tty)
816 clear_bit(TTY_IO_ERROR, &info->tty->flags);
817 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
820 * and set the speed of the serial port
822 mxser_change_speed(info, NULL);
823 info->flags |= ASYNC_INITIALIZED;
824 spin_unlock_irqrestore(&info->slock, flags);
826 return 0;
830 * This routine will shutdown a serial port; interrupts maybe disabled, and
831 * DTR is dropped if the hangup on close termio flag is on.
833 static void mxser_shutdown(struct mxser_port *info)
835 unsigned long flags;
837 if (!(info->flags & ASYNC_INITIALIZED))
838 return;
840 spin_lock_irqsave(&info->slock, flags);
843 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
844 * here so the queue might never be waken up
846 wake_up_interruptible(&info->delta_msr_wait);
849 * Free the IRQ, if necessary
851 if (info->xmit_buf) {
852 free_page((unsigned long) info->xmit_buf);
853 info->xmit_buf = NULL;
856 info->IER = 0;
857 outb(0x00, info->ioaddr + UART_IER);
859 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
860 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
861 outb(info->MCR, info->ioaddr + UART_MCR);
863 /* clear Rx/Tx FIFO's */
864 if (info->board->chip_flag)
865 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT |
866 MOXA_MUST_FCR_GDA_MODE_ENABLE,
867 info->ioaddr + UART_FCR);
868 else
869 outb(UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT,
870 info->ioaddr + UART_FCR);
872 /* read data port to reset things */
873 (void) inb(info->ioaddr + UART_RX);
875 if (info->tty)
876 set_bit(TTY_IO_ERROR, &info->tty->flags);
878 info->flags &= ~ASYNC_INITIALIZED;
880 if (info->board->chip_flag)
881 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->ioaddr);
883 spin_unlock_irqrestore(&info->slock, flags);
887 * This routine is called whenever a serial port is opened. It
888 * enables interrupts for a serial port, linking in its async structure into
889 * the IRQ chain. It also performs the serial-specific
890 * initialization for the tty structure.
892 static int mxser_open(struct tty_struct *tty, struct file *filp)
894 struct mxser_port *info;
895 unsigned long flags;
896 int retval, line;
898 line = tty->index;
899 if (line == MXSER_PORTS)
900 return 0;
901 if (line < 0 || line > MXSER_PORTS)
902 return -ENODEV;
903 info = &mxser_boards[line / MXSER_PORTS_PER_BOARD].ports[line % MXSER_PORTS_PER_BOARD];
904 if (!info->ioaddr)
905 return -ENODEV;
907 tty->driver_data = info;
908 info->tty = tty;
910 * Start up serial port
912 spin_lock_irqsave(&info->slock, flags);
913 info->count++;
914 spin_unlock_irqrestore(&info->slock, flags);
915 retval = mxser_startup(info);
916 if (retval)
917 return retval;
919 retval = mxser_block_til_ready(tty, filp, info);
920 if (retval)
921 return retval;
923 /* unmark here for very high baud rate (ex. 921600 bps) used */
924 tty->low_latency = 1;
925 return 0;
929 * This routine is called when the serial port gets closed. First, we
930 * wait for the last remaining data to be sent. Then, we unlink its
931 * async structure from the interrupt chain if necessary, and we free
932 * that IRQ if nothing is left in the chain.
934 static void mxser_close(struct tty_struct *tty, struct file *filp)
936 struct mxser_port *info = tty->driver_data;
938 unsigned long timeout;
939 unsigned long flags;
941 if (tty->index == MXSER_PORTS)
942 return;
943 if (!info)
944 return;
946 spin_lock_irqsave(&info->slock, flags);
948 if (tty_hung_up_p(filp)) {
949 spin_unlock_irqrestore(&info->slock, flags);
950 return;
952 if ((tty->count == 1) && (info->count != 1)) {
954 * Uh, oh. tty->count is 1, which means that the tty
955 * structure will be freed. Info->count should always
956 * be one in these conditions. If it's greater than
957 * one, we've got real problems, since it means the
958 * serial port won't be shutdown.
960 printk(KERN_ERR "mxser_close: bad serial port count; "
961 "tty->count is 1, info->count is %d\n", info->count);
962 info->count = 1;
964 if (--info->count < 0) {
965 printk(KERN_ERR "mxser_close: bad serial port count for "
966 "ttys%d: %d\n", tty->index, info->count);
967 info->count = 0;
969 if (info->count) {
970 spin_unlock_irqrestore(&info->slock, flags);
971 return;
973 info->flags |= ASYNC_CLOSING;
974 spin_unlock_irqrestore(&info->slock, flags);
976 * Save the termios structure, since this port may have
977 * separate termios for callout and dialin.
979 if (info->flags & ASYNC_NORMAL_ACTIVE)
980 info->normal_termios = *tty->termios;
982 * Now we wait for the transmit buffer to clear; and we notify
983 * the line discipline to only process XON/XOFF characters.
985 tty->closing = 1;
986 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
987 tty_wait_until_sent(tty, info->closing_wait);
989 * At this point we stop accepting input. To do this, we
990 * disable the receive line status interrupts, and tell the
991 * interrupt driver to stop checking the data ready bit in the
992 * line status register.
994 info->IER &= ~UART_IER_RLSI;
995 if (info->board->chip_flag)
996 info->IER &= ~MOXA_MUST_RECV_ISR;
998 if (info->flags & ASYNC_INITIALIZED) {
999 outb(info->IER, info->ioaddr + UART_IER);
1001 * Before we drop DTR, make sure the UART transmitter
1002 * has completely drained; this is especially
1003 * important if there is a transmit FIFO!
1005 timeout = jiffies + HZ;
1006 while (!(inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT)) {
1007 schedule_timeout_interruptible(5);
1008 if (time_after(jiffies, timeout))
1009 break;
1012 mxser_shutdown(info);
1014 if (tty->driver->flush_buffer)
1015 tty->driver->flush_buffer(tty);
1017 tty_ldisc_flush(tty);
1019 tty->closing = 0;
1020 info->event = 0;
1021 info->tty = NULL;
1022 if (info->blocked_open) {
1023 if (info->close_delay)
1024 schedule_timeout_interruptible(info->close_delay);
1025 wake_up_interruptible(&info->open_wait);
1028 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1031 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1033 int c, total = 0;
1034 struct mxser_port *info = tty->driver_data;
1035 unsigned long flags;
1037 if (!info->xmit_buf)
1038 return 0;
1040 while (1) {
1041 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1042 SERIAL_XMIT_SIZE - info->xmit_head));
1043 if (c <= 0)
1044 break;
1046 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1047 spin_lock_irqsave(&info->slock, flags);
1048 info->xmit_head = (info->xmit_head + c) &
1049 (SERIAL_XMIT_SIZE - 1);
1050 info->xmit_cnt += c;
1051 spin_unlock_irqrestore(&info->slock, flags);
1053 buf += c;
1054 count -= c;
1055 total += c;
1058 if (info->xmit_cnt && !tty->stopped) {
1059 if (!tty->hw_stopped ||
1060 (info->type == PORT_16550A) ||
1061 (info->board->chip_flag)) {
1062 spin_lock_irqsave(&info->slock, flags);
1063 outb(info->IER & ~UART_IER_THRI, info->ioaddr +
1064 UART_IER);
1065 info->IER |= UART_IER_THRI;
1066 outb(info->IER, info->ioaddr + UART_IER);
1067 spin_unlock_irqrestore(&info->slock, flags);
1070 return total;
1073 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1075 struct mxser_port *info = tty->driver_data;
1076 unsigned long flags;
1078 if (!info->xmit_buf)
1079 return;
1081 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1082 return;
1084 spin_lock_irqsave(&info->slock, flags);
1085 info->xmit_buf[info->xmit_head++] = ch;
1086 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1087 info->xmit_cnt++;
1088 spin_unlock_irqrestore(&info->slock, flags);
1089 if (!tty->stopped) {
1090 if (!tty->hw_stopped ||
1091 (info->type == PORT_16550A) ||
1092 info->board->chip_flag) {
1093 spin_lock_irqsave(&info->slock, flags);
1094 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1095 info->IER |= UART_IER_THRI;
1096 outb(info->IER, info->ioaddr + UART_IER);
1097 spin_unlock_irqrestore(&info->slock, flags);
1103 static void mxser_flush_chars(struct tty_struct *tty)
1105 struct mxser_port *info = tty->driver_data;
1106 unsigned long flags;
1108 if (info->xmit_cnt <= 0 ||
1109 tty->stopped ||
1110 !info->xmit_buf ||
1111 (tty->hw_stopped &&
1112 (info->type != PORT_16550A) &&
1113 (!info->board->chip_flag)
1115 return;
1117 spin_lock_irqsave(&info->slock, flags);
1119 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1120 info->IER |= UART_IER_THRI;
1121 outb(info->IER, info->ioaddr + UART_IER);
1123 spin_unlock_irqrestore(&info->slock, flags);
1126 static int mxser_write_room(struct tty_struct *tty)
1128 struct mxser_port *info = tty->driver_data;
1129 int ret;
1131 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1132 if (ret < 0)
1133 ret = 0;
1134 return ret;
1137 static int mxser_chars_in_buffer(struct tty_struct *tty)
1139 struct mxser_port *info = tty->driver_data;
1140 return info->xmit_cnt;
1143 static void mxser_flush_buffer(struct tty_struct *tty)
1145 struct mxser_port *info = tty->driver_data;
1146 char fcr;
1147 unsigned long flags;
1150 spin_lock_irqsave(&info->slock, flags);
1151 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1153 fcr = inb(info->ioaddr + UART_FCR);
1154 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1155 info->ioaddr + UART_FCR);
1156 outb(fcr, info->ioaddr + UART_FCR);
1158 spin_unlock_irqrestore(&info->slock, flags);
1160 tty_wakeup(tty);
1164 * ------------------------------------------------------------
1165 * friends of mxser_ioctl()
1166 * ------------------------------------------------------------
1168 static int mxser_get_serial_info(struct mxser_port *info,
1169 struct serial_struct __user *retinfo)
1171 struct serial_struct tmp = {
1172 .type = info->type,
1173 .line = info->tty->index,
1174 .port = info->ioaddr,
1175 .irq = info->board->irq,
1176 .flags = info->flags,
1177 .baud_base = info->baud_base,
1178 .close_delay = info->close_delay,
1179 .closing_wait = info->closing_wait,
1180 .custom_divisor = info->custom_divisor,
1181 .hub6 = 0
1183 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
1184 return -EFAULT;
1185 return 0;
1188 static int mxser_set_serial_info(struct mxser_port *info,
1189 struct serial_struct __user *new_info)
1191 struct serial_struct new_serial;
1192 unsigned long sl_flags;
1193 unsigned int flags;
1194 int retval = 0;
1196 if (!new_info || !info->ioaddr)
1197 return -EFAULT;
1198 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1199 return -EFAULT;
1201 if ((new_serial.irq != info->board->irq) ||
1202 (new_serial.port != info->ioaddr) ||
1203 (new_serial.custom_divisor != info->custom_divisor) ||
1204 (new_serial.baud_base != info->baud_base))
1205 return -EPERM;
1207 flags = info->flags & ASYNC_SPD_MASK;
1209 if (!capable(CAP_SYS_ADMIN)) {
1210 if ((new_serial.baud_base != info->baud_base) ||
1211 (new_serial.close_delay != info->close_delay) ||
1212 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
1213 return -EPERM;
1214 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1215 (new_serial.flags & ASYNC_USR_MASK));
1216 } else {
1218 * OK, past this point, all the error checking has been done.
1219 * At this point, we start making changes.....
1221 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1222 (new_serial.flags & ASYNC_FLAGS));
1223 info->close_delay = new_serial.close_delay * HZ / 100;
1224 info->closing_wait = new_serial.closing_wait * HZ / 100;
1225 info->tty->low_latency =
1226 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1227 info->tty->low_latency = 0;
1230 info->type = new_serial.type;
1232 process_txrx_fifo(info);
1234 if (info->flags & ASYNC_INITIALIZED) {
1235 if (flags != (info->flags & ASYNC_SPD_MASK)) {
1236 spin_lock_irqsave(&info->slock, sl_flags);
1237 mxser_change_speed(info, NULL);
1238 spin_unlock_irqrestore(&info->slock, sl_flags);
1240 } else
1241 retval = mxser_startup(info);
1243 return retval;
1247 * mxser_get_lsr_info - get line status register info
1249 * Purpose: Let user call ioctl() to get info when the UART physically
1250 * is emptied. On bus types like RS485, the transmitter must
1251 * release the bus after transmitting. This must be done when
1252 * the transmit shift register is empty, not be done when the
1253 * transmit holding register is empty. This functionality
1254 * allows an RS485 driver to be written in user space.
1256 static int mxser_get_lsr_info(struct mxser_port *info,
1257 unsigned int __user *value)
1259 unsigned char status;
1260 unsigned int result;
1261 unsigned long flags;
1263 spin_lock_irqsave(&info->slock, flags);
1264 status = inb(info->ioaddr + UART_LSR);
1265 spin_unlock_irqrestore(&info->slock, flags);
1266 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
1267 return put_user(result, value);
1271 * This routine sends a break character out the serial port.
1273 static void mxser_send_break(struct mxser_port *info, int duration)
1275 unsigned long flags;
1277 if (!info->ioaddr)
1278 return;
1279 set_current_state(TASK_INTERRUPTIBLE);
1280 spin_lock_irqsave(&info->slock, flags);
1281 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
1282 info->ioaddr + UART_LCR);
1283 spin_unlock_irqrestore(&info->slock, flags);
1284 schedule_timeout(duration);
1285 spin_lock_irqsave(&info->slock, flags);
1286 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
1287 info->ioaddr + UART_LCR);
1288 spin_unlock_irqrestore(&info->slock, flags);
1291 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1293 struct mxser_port *info = tty->driver_data;
1294 unsigned char control, status;
1295 unsigned long flags;
1298 if (tty->index == MXSER_PORTS)
1299 return -ENOIOCTLCMD;
1300 if (test_bit(TTY_IO_ERROR, &tty->flags))
1301 return -EIO;
1303 control = info->MCR;
1305 spin_lock_irqsave(&info->slock, flags);
1306 status = inb(info->ioaddr + UART_MSR);
1307 if (status & UART_MSR_ANY_DELTA)
1308 mxser_check_modem_status(info, status);
1309 spin_unlock_irqrestore(&info->slock, flags);
1310 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
1311 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
1312 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
1313 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
1314 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
1315 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1318 static int mxser_tiocmset(struct tty_struct *tty, struct file *file,
1319 unsigned int set, unsigned int clear)
1321 struct mxser_port *info = tty->driver_data;
1322 unsigned long flags;
1325 if (tty->index == MXSER_PORTS)
1326 return -ENOIOCTLCMD;
1327 if (test_bit(TTY_IO_ERROR, &tty->flags))
1328 return -EIO;
1330 spin_lock_irqsave(&info->slock, flags);
1332 if (set & TIOCM_RTS)
1333 info->MCR |= UART_MCR_RTS;
1334 if (set & TIOCM_DTR)
1335 info->MCR |= UART_MCR_DTR;
1337 if (clear & TIOCM_RTS)
1338 info->MCR &= ~UART_MCR_RTS;
1339 if (clear & TIOCM_DTR)
1340 info->MCR &= ~UART_MCR_DTR;
1342 outb(info->MCR, info->ioaddr + UART_MCR);
1343 spin_unlock_irqrestore(&info->slock, flags);
1344 return 0;
1347 static int __init mxser_program_mode(int port)
1349 int id, i, j, n;
1351 outb(0, port);
1352 outb(0, port);
1353 outb(0, port);
1354 (void)inb(port);
1355 (void)inb(port);
1356 outb(0, port);
1357 (void)inb(port);
1359 id = inb(port + 1) & 0x1F;
1360 if ((id != C168_ASIC_ID) &&
1361 (id != C104_ASIC_ID) &&
1362 (id != C102_ASIC_ID) &&
1363 (id != CI132_ASIC_ID) &&
1364 (id != CI134_ASIC_ID) &&
1365 (id != CI104J_ASIC_ID))
1366 return -1;
1367 for (i = 0, j = 0; i < 4; i++) {
1368 n = inb(port + 2);
1369 if (n == 'M') {
1370 j = 1;
1371 } else if ((j == 1) && (n == 1)) {
1372 j = 2;
1373 break;
1374 } else
1375 j = 0;
1377 if (j != 2)
1378 id = -2;
1379 return id;
1382 static void __init mxser_normal_mode(int port)
1384 int i, n;
1386 outb(0xA5, port + 1);
1387 outb(0x80, port + 3);
1388 outb(12, port + 0); /* 9600 bps */
1389 outb(0, port + 1);
1390 outb(0x03, port + 3); /* 8 data bits */
1391 outb(0x13, port + 4); /* loop back mode */
1392 for (i = 0; i < 16; i++) {
1393 n = inb(port + 5);
1394 if ((n & 0x61) == 0x60)
1395 break;
1396 if ((n & 1) == 1)
1397 (void)inb(port);
1399 outb(0x00, port + 4);
1402 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
1403 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
1404 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
1405 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
1406 #define EN_CCMD 0x000 /* Chip's command register */
1407 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
1408 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
1409 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
1410 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
1411 #define EN0_DCFG 0x00E /* Data configuration reg WR */
1412 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1413 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1414 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1415 static int __init mxser_read_register(int port, unsigned short *regs)
1417 int i, k, value, id;
1418 unsigned int j;
1420 id = mxser_program_mode(port);
1421 if (id < 0)
1422 return id;
1423 for (i = 0; i < 14; i++) {
1424 k = (i & 0x3F) | 0x180;
1425 for (j = 0x100; j > 0; j >>= 1) {
1426 outb(CHIP_CS, port);
1427 if (k & j) {
1428 outb(CHIP_CS | CHIP_DO, port);
1429 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
1430 } else {
1431 outb(CHIP_CS, port);
1432 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
1435 (void)inb(port);
1436 value = 0;
1437 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
1438 outb(CHIP_CS, port);
1439 outb(CHIP_CS | CHIP_SK, port);
1440 if (inb(port) & CHIP_DI)
1441 value |= j;
1443 regs[i] = value;
1444 outb(0, port);
1446 mxser_normal_mode(port);
1447 return id;
1450 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1452 struct mxser_port *port;
1453 int result, status;
1454 unsigned int i, j;
1456 switch (cmd) {
1457 case MOXA_GET_CONF:
1458 /* if (copy_to_user(argp, mxsercfg,
1459 sizeof(struct mxser_hwconf) * 4))
1460 return -EFAULT;
1461 return 0;*/
1462 return -ENXIO;
1463 case MOXA_GET_MAJOR:
1464 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1465 return -EFAULT;
1466 return 0;
1468 case MOXA_GET_CUMAJOR:
1469 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1470 return -EFAULT;
1471 return 0;
1473 case MOXA_CHKPORTENABLE:
1474 result = 0;
1476 for (i = 0; i < MXSER_BOARDS; i++)
1477 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++)
1478 if (mxser_boards[i].ports[j].ioaddr)
1479 result |= (1 << i);
1481 return put_user(result, (unsigned long __user *)argp);
1482 case MOXA_GETDATACOUNT:
1483 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1484 return -EFAULT;
1485 return 0;
1486 case MOXA_GETMSTATUS:
1487 for (i = 0; i < MXSER_BOARDS; i++)
1488 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1489 port = &mxser_boards[i].ports[j];
1491 GMStatus[i].ri = 0;
1492 if (!port->ioaddr) {
1493 GMStatus[i].dcd = 0;
1494 GMStatus[i].dsr = 0;
1495 GMStatus[i].cts = 0;
1496 continue;
1499 if (!port->tty || !port->tty->termios)
1500 GMStatus[i].cflag =
1501 port->normal_termios.c_cflag;
1502 else
1503 GMStatus[i].cflag =
1504 port->tty->termios->c_cflag;
1506 status = inb(port->ioaddr + UART_MSR);
1507 if (status & 0x80 /*UART_MSR_DCD */ )
1508 GMStatus[i].dcd = 1;
1509 else
1510 GMStatus[i].dcd = 0;
1512 if (status & 0x20 /*UART_MSR_DSR */ )
1513 GMStatus[i].dsr = 1;
1514 else
1515 GMStatus[i].dsr = 0;
1518 if (status & 0x10 /*UART_MSR_CTS */ )
1519 GMStatus[i].cts = 1;
1520 else
1521 GMStatus[i].cts = 0;
1523 if (copy_to_user(argp, GMStatus,
1524 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1525 return -EFAULT;
1526 return 0;
1527 case MOXA_ASPP_MON_EXT: {
1528 int p, shiftbit;
1529 unsigned long opmode;
1530 unsigned cflag, iflag;
1532 for (i = 0; i < MXSER_BOARDS; i++)
1533 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1534 port = &mxser_boards[i].ports[j];
1535 if (!port->ioaddr)
1536 continue;
1538 status = mxser_get_msr(port->ioaddr, 0, i);
1540 if (status & UART_MSR_TERI)
1541 port->icount.rng++;
1542 if (status & UART_MSR_DDSR)
1543 port->icount.dsr++;
1544 if (status & UART_MSR_DDCD)
1545 port->icount.dcd++;
1546 if (status & UART_MSR_DCTS)
1547 port->icount.cts++;
1549 port->mon_data.modem_status = status;
1550 mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt;
1551 mon_data_ext.tx_cnt[i] = port->mon_data.txcnt;
1552 mon_data_ext.up_rxcnt[i] =
1553 port->mon_data.up_rxcnt;
1554 mon_data_ext.up_txcnt[i] =
1555 port->mon_data.up_txcnt;
1556 mon_data_ext.modem_status[i] =
1557 port->mon_data.modem_status;
1558 mon_data_ext.baudrate[i] =
1559 tty_get_baud_rate(port->tty);
1561 if (!port->tty || !port->tty->termios) {
1562 cflag = port->normal_termios.c_cflag;
1563 iflag = port->normal_termios.c_iflag;
1564 } else {
1565 cflag = port->tty->termios->c_cflag;
1566 iflag = port->tty->termios->c_iflag;
1569 mon_data_ext.databits[i] = cflag & CSIZE;
1571 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1573 mon_data_ext.parity[i] =
1574 cflag & (PARENB | PARODD | CMSPAR);
1576 mon_data_ext.flowctrl[i] = 0x00;
1578 if (cflag & CRTSCTS)
1579 mon_data_ext.flowctrl[i] |= 0x03;
1581 if (iflag & (IXON | IXOFF))
1582 mon_data_ext.flowctrl[i] |= 0x0C;
1584 if (port->type == PORT_16550A)
1585 mon_data_ext.fifo[i] = 1;
1586 else
1587 mon_data_ext.fifo[i] = 0;
1589 p = i % 4;
1590 shiftbit = p * 2;
1591 opmode = inb(port->opmode_ioaddr) >> shiftbit;
1592 opmode &= OP_MODE_MASK;
1594 mon_data_ext.iftype[i] = opmode;
1597 if (copy_to_user(argp, &mon_data_ext,
1598 sizeof(mon_data_ext)))
1599 return -EFAULT;
1601 return 0;
1603 } default:
1604 return -ENOIOCTLCMD;
1606 return 0;
1609 static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1610 unsigned int cmd, unsigned long arg)
1612 struct mxser_port *info = tty->driver_data;
1613 struct async_icount cprev, cnow; /* kernel counter temps */
1614 struct serial_icounter_struct __user *p_cuser;
1615 unsigned long templ;
1616 unsigned long flags;
1617 void __user *argp = (void __user *)arg;
1618 int retval;
1620 if (tty->index == MXSER_PORTS)
1621 return mxser_ioctl_special(cmd, argp);
1623 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1624 int p;
1625 unsigned long opmode;
1626 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1627 int shiftbit;
1628 unsigned char val, mask;
1630 p = tty->index % 4;
1631 if (cmd == MOXA_SET_OP_MODE) {
1632 if (get_user(opmode, (int __user *) argp))
1633 return -EFAULT;
1634 if (opmode != RS232_MODE &&
1635 opmode != RS485_2WIRE_MODE &&
1636 opmode != RS422_MODE &&
1637 opmode != RS485_4WIRE_MODE)
1638 return -EFAULT;
1639 mask = ModeMask[p];
1640 shiftbit = p * 2;
1641 val = inb(info->opmode_ioaddr);
1642 val &= mask;
1643 val |= (opmode << shiftbit);
1644 outb(val, info->opmode_ioaddr);
1645 } else {
1646 shiftbit = p * 2;
1647 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1648 opmode &= OP_MODE_MASK;
1649 if (copy_to_user(argp, &opmode, sizeof(int)))
1650 return -EFAULT;
1652 return 0;
1655 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT &&
1656 test_bit(TTY_IO_ERROR, &tty->flags))
1657 return -EIO;
1659 switch (cmd) {
1660 case TCSBRK: /* SVID version: non-zero arg --> no break */
1661 retval = tty_check_change(tty);
1662 if (retval)
1663 return retval;
1664 tty_wait_until_sent(tty, 0);
1665 if (!arg)
1666 mxser_send_break(info, HZ / 4); /* 1/4 second */
1667 return 0;
1668 case TCSBRKP: /* support for POSIX tcsendbreak() */
1669 retval = tty_check_change(tty);
1670 if (retval)
1671 return retval;
1672 tty_wait_until_sent(tty, 0);
1673 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1674 return 0;
1675 case TIOCGSOFTCAR:
1676 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1677 case TIOCSSOFTCAR:
1678 if (get_user(templ, (unsigned long __user *) argp))
1679 return -EFAULT;
1680 arg = templ;
1681 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1682 return 0;
1683 case TIOCGSERIAL:
1684 return mxser_get_serial_info(info, argp);
1685 case TIOCSSERIAL:
1686 return mxser_set_serial_info(info, argp);
1687 case TIOCSERGETLSR: /* Get line status register */
1688 return mxser_get_lsr_info(info, argp);
1690 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1691 * - mask passed in arg for lines of interest
1692 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1693 * Caller should use TIOCGICOUNT to see which one it was
1695 case TIOCMIWAIT:
1696 spin_lock_irqsave(&info->slock, flags);
1697 cnow = info->icount; /* note the counters on entry */
1698 spin_unlock_irqrestore(&info->slock, flags);
1700 wait_event_interruptible(info->delta_msr_wait, ({
1701 cprev = cnow;
1702 spin_lock_irqsave(&info->slock, flags);
1703 cnow = info->icount; /* atomic copy */
1704 spin_unlock_irqrestore(&info->slock, flags);
1706 ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1707 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1708 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1709 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts));
1710 }));
1711 break;
1713 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1714 * Return: write counters to the user passed counter struct
1715 * NB: both 1->0 and 0->1 transitions are counted except for
1716 * RI where only 0->1 is counted.
1718 case TIOCGICOUNT:
1719 spin_lock_irqsave(&info->slock, flags);
1720 cnow = info->icount;
1721 spin_unlock_irqrestore(&info->slock, flags);
1722 p_cuser = argp;
1723 if (put_user(cnow.frame, &p_cuser->frame))
1724 return -EFAULT;
1725 if (put_user(cnow.brk, &p_cuser->brk))
1726 return -EFAULT;
1727 if (put_user(cnow.overrun, &p_cuser->overrun))
1728 return -EFAULT;
1729 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1730 return -EFAULT;
1731 if (put_user(cnow.parity, &p_cuser->parity))
1732 return -EFAULT;
1733 if (put_user(cnow.rx, &p_cuser->rx))
1734 return -EFAULT;
1735 if (put_user(cnow.tx, &p_cuser->tx))
1736 return -EFAULT;
1737 put_user(cnow.cts, &p_cuser->cts);
1738 put_user(cnow.dsr, &p_cuser->dsr);
1739 put_user(cnow.rng, &p_cuser->rng);
1740 put_user(cnow.dcd, &p_cuser->dcd);
1741 return 0;
1742 case MOXA_HighSpeedOn:
1743 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1744 case MOXA_SDS_RSTICOUNTER:
1745 info->mon_data.rxcnt = 0;
1746 info->mon_data.txcnt = 0;
1747 return 0;
1749 case MOXA_ASPP_OQUEUE:{
1750 int len, lsr;
1752 len = mxser_chars_in_buffer(tty);
1754 lsr = inb(info->ioaddr + UART_LSR) & UART_LSR_TEMT;
1756 len += (lsr ? 0 : 1);
1758 if (copy_to_user(argp, &len, sizeof(int)))
1759 return -EFAULT;
1761 return 0;
1763 case MOXA_ASPP_MON: {
1764 int mcr, status;
1766 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1767 mxser_check_modem_status(info, status);
1769 mcr = inb(info->ioaddr + UART_MCR);
1770 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1771 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1772 else
1773 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1775 if (mcr & MOXA_MUST_MCR_TX_XON)
1776 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1777 else
1778 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1780 if (info->tty->hw_stopped)
1781 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1782 else
1783 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1785 if (copy_to_user(argp, &info->mon_data,
1786 sizeof(struct mxser_mon)))
1787 return -EFAULT;
1789 return 0;
1791 case MOXA_ASPP_LSTATUS: {
1792 if (copy_to_user(argp, &info->err_shadow,
1793 sizeof(unsigned char)))
1794 return -EFAULT;
1796 info->err_shadow = 0;
1797 return 0;
1799 case MOXA_SET_BAUD_METHOD: {
1800 int method;
1802 if (get_user(method, (int __user *)argp))
1803 return -EFAULT;
1804 mxser_set_baud_method[tty->index] = method;
1805 if (copy_to_user(argp, &method, sizeof(int)))
1806 return -EFAULT;
1808 return 0;
1810 default:
1811 return -ENOIOCTLCMD;
1813 return 0;
1816 static void mxser_stoprx(struct tty_struct *tty)
1818 struct mxser_port *info = tty->driver_data;
1820 info->ldisc_stop_rx = 1;
1821 if (I_IXOFF(tty)) {
1822 if (info->board->chip_flag) {
1823 info->IER &= ~MOXA_MUST_RECV_ISR;
1824 outb(info->IER, info->ioaddr + UART_IER);
1825 } else {
1826 info->x_char = STOP_CHAR(tty);
1827 outb(0, info->ioaddr + UART_IER);
1828 info->IER |= UART_IER_THRI;
1829 outb(info->IER, info->ioaddr + UART_IER);
1833 if (info->tty->termios->c_cflag & CRTSCTS) {
1834 info->MCR &= ~UART_MCR_RTS;
1835 outb(info->MCR, info->ioaddr + UART_MCR);
1840 * This routine is called by the upper-layer tty layer to signal that
1841 * incoming characters should be throttled.
1843 static void mxser_throttle(struct tty_struct *tty)
1845 mxser_stoprx(tty);
1848 static void mxser_unthrottle(struct tty_struct *tty)
1850 struct mxser_port *info = tty->driver_data;
1852 /* startrx */
1853 info->ldisc_stop_rx = 0;
1854 if (I_IXOFF(tty)) {
1855 if (info->x_char)
1856 info->x_char = 0;
1857 else {
1858 if (info->board->chip_flag) {
1859 info->IER |= MOXA_MUST_RECV_ISR;
1860 outb(info->IER, info->ioaddr + UART_IER);
1861 } else {
1862 info->x_char = START_CHAR(tty);
1863 outb(0, info->ioaddr + UART_IER);
1864 info->IER |= UART_IER_THRI;
1865 outb(info->IER, info->ioaddr + UART_IER);
1870 if (info->tty->termios->c_cflag & CRTSCTS) {
1871 info->MCR |= UART_MCR_RTS;
1872 outb(info->MCR, info->ioaddr + UART_MCR);
1877 * mxser_stop() and mxser_start()
1879 * This routines are called before setting or resetting tty->stopped.
1880 * They enable or disable transmitter interrupts, as necessary.
1882 static void mxser_stop(struct tty_struct *tty)
1884 struct mxser_port *info = tty->driver_data;
1885 unsigned long flags;
1887 spin_lock_irqsave(&info->slock, flags);
1888 if (info->IER & UART_IER_THRI) {
1889 info->IER &= ~UART_IER_THRI;
1890 outb(info->IER, info->ioaddr + UART_IER);
1892 spin_unlock_irqrestore(&info->slock, flags);
1895 static void mxser_start(struct tty_struct *tty)
1897 struct mxser_port *info = tty->driver_data;
1898 unsigned long flags;
1900 spin_lock_irqsave(&info->slock, flags);
1901 if (info->xmit_cnt && info->xmit_buf) {
1902 outb(info->IER & ~UART_IER_THRI, info->ioaddr + UART_IER);
1903 info->IER |= UART_IER_THRI;
1904 outb(info->IER, info->ioaddr + UART_IER);
1906 spin_unlock_irqrestore(&info->slock, flags);
1909 static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1911 struct mxser_port *info = tty->driver_data;
1912 unsigned long flags;
1914 spin_lock_irqsave(&info->slock, flags);
1915 mxser_change_speed(info, old_termios);
1916 spin_unlock_irqrestore(&info->slock, flags);
1918 if ((old_termios->c_cflag & CRTSCTS) &&
1919 !(tty->termios->c_cflag & CRTSCTS)) {
1920 tty->hw_stopped = 0;
1921 mxser_start(tty);
1924 /* Handle sw stopped */
1925 if ((old_termios->c_iflag & IXON) &&
1926 !(tty->termios->c_iflag & IXON)) {
1927 tty->stopped = 0;
1929 if (info->board->chip_flag) {
1930 spin_lock_irqsave(&info->slock, flags);
1931 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
1932 spin_unlock_irqrestore(&info->slock, flags);
1935 mxser_start(tty);
1940 * mxser_wait_until_sent() --- wait until the transmitter is empty
1942 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1944 struct mxser_port *info = tty->driver_data;
1945 unsigned long orig_jiffies, char_time;
1946 int lsr;
1948 if (info->type == PORT_UNKNOWN)
1949 return;
1951 if (info->xmit_fifo_size == 0)
1952 return; /* Just in case.... */
1954 orig_jiffies = jiffies;
1956 * Set the check interval to be 1/5 of the estimated time to
1957 * send a single character, and make it at least 1. The check
1958 * interval should also be less than the timeout.
1960 * Note: we have to use pretty tight timings here to satisfy
1961 * the NIST-PCTS.
1963 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1964 char_time = char_time / 5;
1965 if (char_time == 0)
1966 char_time = 1;
1967 if (timeout && timeout < char_time)
1968 char_time = timeout;
1970 * If the transmitter hasn't cleared in twice the approximate
1971 * amount of time to send the entire FIFO, it probably won't
1972 * ever clear. This assumes the UART isn't doing flow
1973 * control, which is currently the case. Hence, if it ever
1974 * takes longer than info->timeout, this is probably due to a
1975 * UART bug of some kind. So, we clamp the timeout parameter at
1976 * 2*info->timeout.
1978 if (!timeout || timeout > 2 * info->timeout)
1979 timeout = 2 * info->timeout;
1980 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1981 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1982 timeout, char_time);
1983 printk("jiff=%lu...", jiffies);
1984 #endif
1985 while (!((lsr = inb(info->ioaddr + UART_LSR)) & UART_LSR_TEMT)) {
1986 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1987 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1988 #endif
1989 schedule_timeout_interruptible(char_time);
1990 if (signal_pending(current))
1991 break;
1992 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1993 break;
1995 set_current_state(TASK_RUNNING);
1997 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1998 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1999 #endif
2003 * This routine is called by tty_hangup() when a hangup is signaled.
2005 static void mxser_hangup(struct tty_struct *tty)
2007 struct mxser_port *info = tty->driver_data;
2009 mxser_flush_buffer(tty);
2010 mxser_shutdown(info);
2011 info->event = 0;
2012 info->count = 0;
2013 info->flags &= ~ASYNC_NORMAL_ACTIVE;
2014 info->tty = NULL;
2015 wake_up_interruptible(&info->open_wait);
2019 * mxser_rs_break() --- routine which turns the break handling on or off
2021 static void mxser_rs_break(struct tty_struct *tty, int break_state)
2023 struct mxser_port *info = tty->driver_data;
2024 unsigned long flags;
2026 spin_lock_irqsave(&info->slock, flags);
2027 if (break_state == -1)
2028 outb(inb(info->ioaddr + UART_LCR) | UART_LCR_SBC,
2029 info->ioaddr + UART_LCR);
2030 else
2031 outb(inb(info->ioaddr + UART_LCR) & ~UART_LCR_SBC,
2032 info->ioaddr + UART_LCR);
2033 spin_unlock_irqrestore(&info->slock, flags);
2036 static void mxser_receive_chars(struct mxser_port *port, int *status)
2038 struct tty_struct *tty = port->tty;
2039 unsigned char ch, gdl;
2040 int ignored = 0;
2041 int cnt = 0;
2042 int recv_room;
2043 int max = 256;
2045 recv_room = tty->receive_room;
2046 if ((recv_room == 0) && (!port->ldisc_stop_rx))
2047 mxser_stoprx(tty);
2049 if (port->board->chip_flag != MOXA_OTHER_UART) {
2051 if (*status & UART_LSR_SPECIAL)
2052 goto intr_old;
2053 if (port->board->chip_flag == MOXA_MUST_MU860_HWID &&
2054 (*status & MOXA_MUST_LSR_RERR))
2055 goto intr_old;
2056 if (*status & MOXA_MUST_LSR_RERR)
2057 goto intr_old;
2059 gdl = inb(port->ioaddr + MOXA_MUST_GDL_REGISTER);
2061 if (port->board->chip_flag == MOXA_MUST_MU150_HWID)
2062 gdl &= MOXA_MUST_GDL_MASK;
2063 if (gdl >= recv_room) {
2064 if (!port->ldisc_stop_rx)
2065 mxser_stoprx(tty);
2067 while (gdl--) {
2068 ch = inb(port->ioaddr + UART_RX);
2069 tty_insert_flip_char(tty, ch, 0);
2070 cnt++;
2072 goto end_intr;
2074 intr_old:
2076 do {
2077 if (max-- < 0)
2078 break;
2080 ch = inb(port->ioaddr + UART_RX);
2081 if (port->board->chip_flag && (*status & UART_LSR_OE))
2082 outb(0x23, port->ioaddr + UART_FCR);
2083 *status &= port->read_status_mask;
2084 if (*status & port->ignore_status_mask) {
2085 if (++ignored > 100)
2086 break;
2087 } else {
2088 char flag = 0;
2089 if (*status & UART_LSR_SPECIAL) {
2090 if (*status & UART_LSR_BI) {
2091 flag = TTY_BREAK;
2092 port->icount.brk++;
2094 if (port->flags & ASYNC_SAK)
2095 do_SAK(tty);
2096 } else if (*status & UART_LSR_PE) {
2097 flag = TTY_PARITY;
2098 port->icount.parity++;
2099 } else if (*status & UART_LSR_FE) {
2100 flag = TTY_FRAME;
2101 port->icount.frame++;
2102 } else if (*status & UART_LSR_OE) {
2103 flag = TTY_OVERRUN;
2104 port->icount.overrun++;
2105 } else
2106 flag = TTY_BREAK;
2108 tty_insert_flip_char(tty, ch, flag);
2109 cnt++;
2110 if (cnt >= recv_room) {
2111 if (!port->ldisc_stop_rx)
2112 mxser_stoprx(tty);
2113 break;
2118 if (port->board->chip_flag)
2119 break;
2121 *status = inb(port->ioaddr + UART_LSR);
2122 } while (*status & UART_LSR_DR);
2124 end_intr:
2125 mxvar_log.rxcnt[port->tty->index] += cnt;
2126 port->mon_data.rxcnt += cnt;
2127 port->mon_data.up_rxcnt += cnt;
2130 * We are called from an interrupt context with &port->slock
2131 * being held. Drop it temporarily in order to prevent
2132 * recursive locking.
2134 spin_unlock(&port->slock);
2135 tty_flip_buffer_push(tty);
2136 spin_lock(&port->slock);
2139 static void mxser_transmit_chars(struct mxser_port *port)
2141 int count, cnt;
2143 if (port->x_char) {
2144 outb(port->x_char, port->ioaddr + UART_TX);
2145 port->x_char = 0;
2146 mxvar_log.txcnt[port->tty->index]++;
2147 port->mon_data.txcnt++;
2148 port->mon_data.up_txcnt++;
2149 port->icount.tx++;
2150 return;
2153 if (port->xmit_buf == NULL)
2154 return;
2156 if ((port->xmit_cnt <= 0) || port->tty->stopped ||
2157 (port->tty->hw_stopped &&
2158 (port->type != PORT_16550A) &&
2159 (!port->board->chip_flag))) {
2160 port->IER &= ~UART_IER_THRI;
2161 outb(port->IER, port->ioaddr + UART_IER);
2162 return;
2165 cnt = port->xmit_cnt;
2166 count = port->xmit_fifo_size;
2167 do {
2168 outb(port->xmit_buf[port->xmit_tail++],
2169 port->ioaddr + UART_TX);
2170 port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2171 if (--port->xmit_cnt <= 0)
2172 break;
2173 } while (--count > 0);
2174 mxvar_log.txcnt[port->tty->index] += (cnt - port->xmit_cnt);
2176 port->mon_data.txcnt += (cnt - port->xmit_cnt);
2177 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2178 port->icount.tx += (cnt - port->xmit_cnt);
2180 if (port->xmit_cnt < WAKEUP_CHARS)
2181 tty_wakeup(port->tty);
2183 if (port->xmit_cnt <= 0) {
2184 port->IER &= ~UART_IER_THRI;
2185 outb(port->IER, port->ioaddr + UART_IER);
2190 * This is the serial driver's generic interrupt routine
2192 static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2194 int status, iir, i;
2195 struct mxser_board *brd = NULL;
2196 struct mxser_port *port;
2197 int max, irqbits, bits, msr;
2198 unsigned int int_cnt, pass_counter = 0;
2199 int handled = IRQ_NONE;
2201 for (i = 0; i < MXSER_BOARDS; i++)
2202 if (dev_id == &mxser_boards[i]) {
2203 brd = dev_id;
2204 break;
2207 if (i == MXSER_BOARDS)
2208 goto irq_stop;
2209 if (brd == NULL)
2210 goto irq_stop;
2211 max = brd->info->nports;
2212 while (pass_counter++ < MXSER_ISR_PASS_LIMIT) {
2213 irqbits = inb(brd->vector) & brd->vector_mask;
2214 if (irqbits == brd->vector_mask)
2215 break;
2217 handled = IRQ_HANDLED;
2218 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
2219 if (irqbits == brd->vector_mask)
2220 break;
2221 if (bits & irqbits)
2222 continue;
2223 port = &brd->ports[i];
2225 int_cnt = 0;
2226 spin_lock(&port->slock);
2227 do {
2228 iir = inb(port->ioaddr + UART_IIR);
2229 if (iir & UART_IIR_NO_INT)
2230 break;
2231 iir &= MOXA_MUST_IIR_MASK;
2232 if (!port->tty ||
2233 (port->flags & ASYNC_CLOSING) ||
2234 !(port->flags &
2235 ASYNC_INITIALIZED)) {
2236 status = inb(port->ioaddr + UART_LSR);
2237 outb(0x27, port->ioaddr + UART_FCR);
2238 inb(port->ioaddr + UART_MSR);
2239 break;
2242 status = inb(port->ioaddr + UART_LSR);
2244 if (status & UART_LSR_PE)
2245 port->err_shadow |= NPPI_NOTIFY_PARITY;
2246 if (status & UART_LSR_FE)
2247 port->err_shadow |= NPPI_NOTIFY_FRAMING;
2248 if (status & UART_LSR_OE)
2249 port->err_shadow |=
2250 NPPI_NOTIFY_HW_OVERRUN;
2251 if (status & UART_LSR_BI)
2252 port->err_shadow |= NPPI_NOTIFY_BREAK;
2254 if (port->board->chip_flag) {
2255 if (iir == MOXA_MUST_IIR_GDA ||
2256 iir == MOXA_MUST_IIR_RDA ||
2257 iir == MOXA_MUST_IIR_RTO ||
2258 iir == MOXA_MUST_IIR_LSR)
2259 mxser_receive_chars(port,
2260 &status);
2262 } else {
2263 status &= port->read_status_mask;
2264 if (status & UART_LSR_DR)
2265 mxser_receive_chars(port,
2266 &status);
2268 msr = inb(port->ioaddr + UART_MSR);
2269 if (msr & UART_MSR_ANY_DELTA)
2270 mxser_check_modem_status(port, msr);
2272 if (port->board->chip_flag) {
2273 if (iir == 0x02 && (status &
2274 UART_LSR_THRE))
2275 mxser_transmit_chars(port);
2276 } else {
2277 if (status & UART_LSR_THRE)
2278 mxser_transmit_chars(port);
2280 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
2281 spin_unlock(&port->slock);
2285 irq_stop:
2286 return handled;
2289 static const struct tty_operations mxser_ops = {
2290 .open = mxser_open,
2291 .close = mxser_close,
2292 .write = mxser_write,
2293 .put_char = mxser_put_char,
2294 .flush_chars = mxser_flush_chars,
2295 .write_room = mxser_write_room,
2296 .chars_in_buffer = mxser_chars_in_buffer,
2297 .flush_buffer = mxser_flush_buffer,
2298 .ioctl = mxser_ioctl,
2299 .throttle = mxser_throttle,
2300 .unthrottle = mxser_unthrottle,
2301 .set_termios = mxser_set_termios,
2302 .stop = mxser_stop,
2303 .start = mxser_start,
2304 .hangup = mxser_hangup,
2305 .break_ctl = mxser_rs_break,
2306 .wait_until_sent = mxser_wait_until_sent,
2307 .tiocmget = mxser_tiocmget,
2308 .tiocmset = mxser_tiocmset,
2312 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2315 static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev,
2316 unsigned int irq)
2318 if (irq)
2319 free_irq(brd->irq, brd);
2320 if (pdev != NULL) { /* PCI */
2321 #ifdef CONFIG_PCI
2322 pci_release_region(pdev, 2);
2323 pci_release_region(pdev, 3);
2324 #endif
2325 } else {
2326 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2327 release_region(brd->vector, 1);
2331 static int __devinit mxser_initbrd(struct mxser_board *brd,
2332 struct pci_dev *pdev)
2334 struct mxser_port *info;
2335 unsigned int i;
2336 int retval;
2338 printk(KERN_INFO "max. baud rate = %d bps.\n", brd->ports[0].max_baud);
2340 for (i = 0; i < brd->info->nports; i++) {
2341 info = &brd->ports[i];
2342 info->board = brd;
2343 info->stop_rx = 0;
2344 info->ldisc_stop_rx = 0;
2346 /* Enhance mode enabled here */
2347 if (brd->chip_flag != MOXA_OTHER_UART)
2348 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->ioaddr);
2350 info->flags = ASYNC_SHARE_IRQ;
2351 info->type = brd->uart_type;
2353 process_txrx_fifo(info);
2355 info->custom_divisor = info->baud_base * 16;
2356 info->close_delay = 5 * HZ / 10;
2357 info->closing_wait = 30 * HZ;
2358 info->normal_termios = mxvar_sdriver->init_termios;
2359 init_waitqueue_head(&info->open_wait);
2360 init_waitqueue_head(&info->delta_msr_wait);
2361 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
2362 info->err_shadow = 0;
2363 spin_lock_init(&info->slock);
2365 /* before set INT ISR, disable all int */
2366 outb(inb(info->ioaddr + UART_IER) & 0xf0,
2367 info->ioaddr + UART_IER);
2370 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser",
2371 brd);
2372 if (retval) {
2373 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2374 "conflict with another device.\n",
2375 brd->info->name, brd->irq);
2376 /* We hold resources, we need to release them. */
2377 mxser_release_res(brd, pdev, 0);
2379 return retval;
2382 static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
2384 int id, i, bits;
2385 unsigned short regs[16], irq;
2386 unsigned char scratch, scratch2;
2388 brd->chip_flag = MOXA_OTHER_UART;
2390 id = mxser_read_register(cap, regs);
2391 switch (id) {
2392 case C168_ASIC_ID:
2393 brd->info = &mxser_cards[0];
2394 break;
2395 case C104_ASIC_ID:
2396 brd->info = &mxser_cards[1];
2397 break;
2398 case CI104J_ASIC_ID:
2399 brd->info = &mxser_cards[2];
2400 break;
2401 case C102_ASIC_ID:
2402 brd->info = &mxser_cards[5];
2403 break;
2404 case CI132_ASIC_ID:
2405 brd->info = &mxser_cards[6];
2406 break;
2407 case CI134_ASIC_ID:
2408 brd->info = &mxser_cards[7];
2409 break;
2410 default:
2411 return 0;
2414 irq = 0;
2415 /* some ISA cards have 2 ports, but we want to see them as 4-port (why?)
2416 Flag-hack checks if configuration should be read as 2-port here. */
2417 if (brd->info->nports == 2 || (brd->info->flags & MXSER_HAS2)) {
2418 irq = regs[9] & 0xF000;
2419 irq = irq | (irq >> 4);
2420 if (irq != (regs[9] & 0xFF00))
2421 return MXSER_ERR_IRQ_CONFLIT;
2422 } else if (brd->info->nports == 4) {
2423 irq = regs[9] & 0xF000;
2424 irq = irq | (irq >> 4);
2425 irq = irq | (irq >> 8);
2426 if (irq != regs[9])
2427 return MXSER_ERR_IRQ_CONFLIT;
2428 } else if (brd->info->nports == 8) {
2429 irq = regs[9] & 0xF000;
2430 irq = irq | (irq >> 4);
2431 irq = irq | (irq >> 8);
2432 if ((irq != regs[9]) || (irq != regs[10]))
2433 return MXSER_ERR_IRQ_CONFLIT;
2436 if (!irq)
2437 return MXSER_ERR_IRQ;
2438 brd->irq = ((int)(irq & 0xF000) >> 12);
2439 for (i = 0; i < 8; i++)
2440 brd->ports[i].ioaddr = (int) regs[i + 1] & 0xFFF8;
2441 if ((regs[12] & 0x80) == 0)
2442 return MXSER_ERR_VECTOR;
2443 brd->vector = (int)regs[11]; /* interrupt vector */
2444 if (id == 1)
2445 brd->vector_mask = 0x00FF;
2446 else
2447 brd->vector_mask = 0x000F;
2448 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
2449 if (regs[12] & bits) {
2450 brd->ports[i].baud_base = 921600;
2451 brd->ports[i].max_baud = 921600;
2452 } else {
2453 brd->ports[i].baud_base = 115200;
2454 brd->ports[i].max_baud = 115200;
2457 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
2458 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
2459 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
2460 outb(scratch2, cap + UART_LCR);
2461 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
2462 scratch = inb(cap + UART_IIR);
2464 if (scratch & 0xC0)
2465 brd->uart_type = PORT_16550A;
2466 else
2467 brd->uart_type = PORT_16450;
2468 if (!request_region(brd->ports[0].ioaddr, 8 * brd->info->nports,
2469 "mxser(IO)"))
2470 return MXSER_ERR_IOADDR;
2471 if (!request_region(brd->vector, 1, "mxser(vector)")) {
2472 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
2473 return MXSER_ERR_VECTOR;
2475 return brd->info->nports;
2478 static int __devinit mxser_probe(struct pci_dev *pdev,
2479 const struct pci_device_id *ent)
2481 #ifdef CONFIG_PCI
2482 struct mxser_board *brd;
2483 unsigned int i, j;
2484 unsigned long ioaddress;
2485 int retval = -EINVAL;
2487 for (i = 0; i < MXSER_BOARDS; i++)
2488 if (mxser_boards[i].info == NULL)
2489 break;
2491 if (i >= MXSER_BOARDS) {
2492 printk(KERN_ERR "Too many Smartio/Industio family boards found "
2493 "(maximum %d), board not configured\n", MXSER_BOARDS);
2494 goto err;
2497 brd = &mxser_boards[i];
2498 brd->idx = i * MXSER_PORTS_PER_BOARD;
2499 printk(KERN_INFO "Found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2500 mxser_cards[ent->driver_data].name,
2501 pdev->bus->number, PCI_SLOT(pdev->devfn));
2503 retval = pci_enable_device(pdev);
2504 if (retval) {
2505 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
2506 goto err;
2509 /* io address */
2510 ioaddress = pci_resource_start(pdev, 2);
2511 retval = pci_request_region(pdev, 2, "mxser(IO)");
2512 if (retval)
2513 goto err;
2515 brd->info = &mxser_cards[ent->driver_data];
2516 for (i = 0; i < brd->info->nports; i++)
2517 brd->ports[i].ioaddr = ioaddress + 8 * i;
2519 /* vector */
2520 ioaddress = pci_resource_start(pdev, 3);
2521 retval = pci_request_region(pdev, 3, "mxser(vector)");
2522 if (retval)
2523 goto err_relio;
2524 brd->vector = ioaddress;
2526 /* irq */
2527 brd->irq = pdev->irq;
2529 brd->chip_flag = CheckIsMoxaMust(brd->ports[0].ioaddr);
2530 brd->uart_type = PORT_16550A;
2531 brd->vector_mask = 0;
2533 for (i = 0; i < brd->info->nports; i++) {
2534 for (j = 0; j < UART_INFO_NUM; j++) {
2535 if (Gpci_uart_info[j].type == brd->chip_flag) {
2536 brd->ports[i].max_baud =
2537 Gpci_uart_info[j].max_baud;
2539 /* exception....CP-102 */
2540 if (brd->info->flags & MXSER_HIGHBAUD)
2541 brd->ports[i].max_baud = 921600;
2542 break;
2547 if (brd->chip_flag == MOXA_MUST_MU860_HWID) {
2548 for (i = 0; i < brd->info->nports; i++) {
2549 if (i < 4)
2550 brd->ports[i].opmode_ioaddr = ioaddress + 4;
2551 else
2552 brd->ports[i].opmode_ioaddr = ioaddress + 0x0c;
2554 outb(0, ioaddress + 4); /* default set to RS232 mode */
2555 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
2558 for (i = 0; i < brd->info->nports; i++) {
2559 brd->vector_mask |= (1 << i);
2560 brd->ports[i].baud_base = 921600;
2563 /* mxser_initbrd will hook ISR. */
2564 retval = mxser_initbrd(brd, pdev);
2565 if (retval)
2566 goto err_null;
2568 for (i = 0; i < brd->info->nports; i++)
2569 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
2571 pci_set_drvdata(pdev, brd);
2573 return 0;
2574 err_relio:
2575 pci_release_region(pdev, 2);
2576 err_null:
2577 brd->info = NULL;
2578 err:
2579 return retval;
2580 #else
2581 return -ENODEV;
2582 #endif
2585 static void __devexit mxser_remove(struct pci_dev *pdev)
2587 struct mxser_board *brd = pci_get_drvdata(pdev);
2588 unsigned int i;
2590 for (i = 0; i < brd->info->nports; i++)
2591 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2593 mxser_release_res(brd, pdev, 1);
2594 brd->info = NULL;
2597 static struct pci_driver mxser_driver = {
2598 .name = "mxser",
2599 .id_table = mxser_pcibrds,
2600 .probe = mxser_probe,
2601 .remove = __devexit_p(mxser_remove)
2604 static int __init mxser_module_init(void)
2606 struct mxser_board *brd;
2607 unsigned long cap;
2608 unsigned int i, m, isaloop;
2609 int retval, b;
2611 pr_debug("Loading module mxser ...\n");
2613 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
2614 if (!mxvar_sdriver)
2615 return -ENOMEM;
2617 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
2618 MXSER_VERSION);
2620 /* Initialize the tty_driver structure */
2621 mxvar_sdriver->owner = THIS_MODULE;
2622 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
2623 mxvar_sdriver->name = "ttyMI";
2624 mxvar_sdriver->major = ttymajor;
2625 mxvar_sdriver->minor_start = 0;
2626 mxvar_sdriver->num = MXSER_PORTS + 1;
2627 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
2628 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
2629 mxvar_sdriver->init_termios = tty_std_termios;
2630 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
2631 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV;
2632 tty_set_operations(mxvar_sdriver, &mxser_ops);
2634 retval = tty_register_driver(mxvar_sdriver);
2635 if (retval) {
2636 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family "
2637 "tty driver !\n");
2638 goto err_put;
2641 mxvar_diagflag = 0;
2643 m = 0;
2644 /* Start finding ISA boards here */
2645 for (isaloop = 0; isaloop < 2; isaloop++)
2646 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
2647 if (!isaloop)
2648 cap = mxserBoardCAP[b]; /* predefined */
2649 else
2650 cap = ioaddr[b]; /* module param */
2652 if (!cap)
2653 continue;
2655 brd = &mxser_boards[m];
2656 retval = mxser_get_ISA_conf(cap, brd);
2658 if (retval != 0)
2659 printk(KERN_INFO "Found MOXA %s board "
2660 "(CAP=0x%x)\n",
2661 brd->info->name, ioaddr[b]);
2663 if (retval <= 0) {
2664 if (retval == MXSER_ERR_IRQ)
2665 printk(KERN_ERR "Invalid interrupt "
2666 "number, board not "
2667 "configured\n");
2668 else if (retval == MXSER_ERR_IRQ_CONFLIT)
2669 printk(KERN_ERR "Invalid interrupt "
2670 "number, board not "
2671 "configured\n");
2672 else if (retval == MXSER_ERR_VECTOR)
2673 printk(KERN_ERR "Invalid interrupt "
2674 "vector, board not "
2675 "configured\n");
2676 else if (retval == MXSER_ERR_IOADDR)
2677 printk(KERN_ERR "Invalid I/O address, "
2678 "board not configured\n");
2680 brd->info = NULL;
2681 continue;
2684 /* mxser_initbrd will hook ISR. */
2685 if (mxser_initbrd(brd, NULL) < 0) {
2686 brd->info = NULL;
2687 continue;
2690 brd->idx = m * MXSER_PORTS_PER_BOARD;
2691 for (i = 0; i < brd->info->nports; i++)
2692 tty_register_device(mxvar_sdriver, brd->idx + i,
2693 NULL);
2695 m++;
2698 retval = pci_register_driver(&mxser_driver);
2699 if (retval) {
2700 printk(KERN_ERR "Can't register pci driver\n");
2701 if (!m) {
2702 retval = -ENODEV;
2703 goto err_unr;
2704 } /* else: we have some ISA cards under control */
2707 pr_debug("Done.\n");
2709 return 0;
2710 err_unr:
2711 tty_unregister_driver(mxvar_sdriver);
2712 err_put:
2713 put_tty_driver(mxvar_sdriver);
2714 return retval;
2717 static void __exit mxser_module_exit(void)
2719 unsigned int i, j;
2721 pr_debug("Unloading module mxser ...\n");
2723 pci_unregister_driver(&mxser_driver);
2725 for (i = 0; i < MXSER_BOARDS; i++) /* ISA remains */
2726 if (mxser_boards[i].info != NULL)
2727 for (j = 0; j < mxser_boards[i].info->nports; j++)
2728 tty_unregister_device(mxvar_sdriver,
2729 mxser_boards[i].idx + j);
2730 tty_unregister_driver(mxvar_sdriver);
2731 put_tty_driver(mxvar_sdriver);
2733 for (i = 0; i < MXSER_BOARDS; i++)
2734 if (mxser_boards[i].info != NULL)
2735 mxser_release_res(&mxser_boards[i], NULL, 1);
2737 pr_debug("Done.\n");
2740 module_init(mxser_module_init);
2741 module_exit(mxser_module_exit);