2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2001 Moxa Technologies (support@moxa.com.tw).
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Original release 10/26/00
25 * 02/06/01 Support MOXA Industio family boards.
26 * 02/06/01 Support TIOCGICOUNT.
27 * 02/06/01 Fix the problem for connecting to serial mouse.
28 * 02/06/01 Fix the problem for H/W flow control.
29 * 02/06/01 Fix the compling warning when CONFIG_PCI
32 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
33 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
34 * - Fixed x86_64 cleanness
35 * - Fixed sleep with spinlock held in mxser_send_break
39 #include <linux/module.h>
40 #include <linux/autoconf.h>
41 #include <linux/errno.h>
42 #include <linux/signal.h>
43 #include <linux/sched.h>
44 #include <linux/timer.h>
45 #include <linux/interrupt.h>
46 #include <linux/tty.h>
47 #include <linux/tty_flip.h>
48 #include <linux/serial.h>
49 #include <linux/serial_reg.h>
50 #include <linux/major.h>
51 #include <linux/string.h>
52 #include <linux/fcntl.h>
53 #include <linux/ptrace.h>
54 #include <linux/gfp.h>
55 #include <linux/ioport.h>
57 #include <linux/smp_lock.h>
58 #include <linux/delay.h>
59 #include <linux/pci.h>
61 #include <asm/system.h>
64 #include <asm/bitops.h>
65 #include <asm/uaccess.h>
69 #define MXSER_VERSION "1.8"
70 #define MXSERMAJOR 174
71 #define MXSERCUMAJOR 175
73 #define MXSER_EVENT_TXLOW 1
74 #define MXSER_EVENT_HANGUP 2
76 #define MXSER_BOARDS 4 /* Max. boards */
77 #define MXSER_PORTS 32 /* Max. ports */
78 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
79 #define MXSER_ISR_PASS_LIMIT 256
81 #define MXSER_ERR_IOADDR -1
82 #define MXSER_ERR_IRQ -2
83 #define MXSER_ERR_IRQ_CONFLIT -3
84 #define MXSER_ERR_VECTOR -4
86 #define SERIAL_TYPE_NORMAL 1
87 #define SERIAL_TYPE_CALLOUT 2
89 #define WAKEUP_CHARS 256
91 #define UART_MCR_AFE 0x20
92 #define UART_LSR_SPECIAL 0x1E
94 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|\
97 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED)
99 #define C168_ASIC_ID 1
100 #define C104_ASIC_ID 2
101 #define C102_ASIC_ID 0xB
102 #define CI132_ASIC_ID 4
103 #define CI134_ASIC_ID 3
104 #define CI104J_ASIC_ID 5
107 MXSER_BOARD_C168_ISA = 1,
108 MXSER_BOARD_C104_ISA,
110 MXSER_BOARD_C168_PCI,
111 MXSER_BOARD_C104_PCI,
112 MXSER_BOARD_C102_ISA,
130 static char *mxser_brdname[] = {
148 "Moxa UC7000 Serial",
154 static int mxser_numports[] = {
178 #define UART_TYPE_NUM 2
180 static const unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
181 MOXA_MUST_MU150_HWID,
185 /* This is only for PCI */
186 #define UART_INFO_NUM 3
187 struct mxpciuart_info {
198 static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
199 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
200 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
201 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
207 static struct pci_device_id mxser_pcibrds[] = {
208 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
209 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
210 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
211 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
212 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
213 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
214 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
215 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
216 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
217 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
218 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
219 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
220 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
221 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
222 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
226 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
231 typedef struct _moxa_pci_info {
232 unsigned short busNum;
233 unsigned short devNum;
234 struct pci_dev *pdev; /* add by Victor Yu. 06-23-2003 */
237 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
238 static int ttymajor = MXSERMAJOR;
239 static int calloutmajor = MXSERCUMAJOR;
240 static int verbose = 0;
242 /* Variables for insmod */
244 MODULE_AUTHOR("Casper Yang");
245 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
246 module_param_array(ioaddr, int, NULL, 0);
247 module_param(ttymajor, int, 0);
248 module_param(calloutmajor, int, 0);
249 module_param(verbose, bool, 0);
250 MODULE_LICENSE("GPL");
254 unsigned long rxcnt[MXSER_PORTS];
255 unsigned long txcnt[MXSER_PORTS];
262 unsigned long up_rxcnt;
263 unsigned long up_txcnt;
265 unsigned char hold_reason;
268 struct mxser_mon_ext {
269 unsigned long rx_cnt[32];
270 unsigned long tx_cnt[32];
271 unsigned long up_rxcnt[32];
272 unsigned long up_txcnt[32];
273 int modem_status[32];
284 struct mxser_hwconf {
291 int ioaddr[MXSER_PORTS_PER_BOARD];
292 int baud_base[MXSER_PORTS_PER_BOARD];
293 moxa_pci_info pciInfo;
294 int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
295 int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 09-04-2002 */
296 int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 01-05-2004 */
299 struct mxser_struct {
301 int base; /* port base address */
302 int irq; /* port using irq no. */
303 int vector; /* port irq vector */
304 int vectormask; /* port vector mask */
306 int rx_trigger; /* Rx fifo trigger level */
308 int baud_base; /* max. speed */
309 int flags; /* defined in tty.h */
310 int type; /* UART type */
311 struct tty_struct *tty;
312 int read_status_mask;
313 int ignore_status_mask;
316 int x_char; /* xon/xoff character */
318 unsigned short closing_wait;
319 int IER; /* Interrupt Enable Register */
320 int MCR; /* Modem control register */
322 int count; /* # of fd on device */
323 int blocked_open; /* # of blocked opens */
324 long session; /* Session of opening process */
325 long pgrp; /* pgrp of opening process */
326 unsigned char *xmit_buf;
330 struct work_struct tqueue;
331 struct termios normal_termios;
332 struct termios callout_termios;
333 wait_queue_head_t open_wait;
334 wait_queue_head_t close_wait;
335 wait_queue_head_t delta_msr_wait;
336 struct async_icount icount; /* kernel counters for the 4 input interrupts */
338 int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
339 int MaxCanSetBaudRate; /* add by Victor Yu. 09-04-2002 */
340 int opmode_ioaddr; /* add by Victor Yu. 01-05-2004 */
341 unsigned char stop_rx;
342 unsigned char ldisc_stop_rx;
344 struct mxser_mon mon_data;
345 unsigned char err_shadow;
349 struct mxser_mstatus {
357 static struct mxser_mstatus GMStatus[MXSER_PORTS];
359 static int mxserBoardCAP[MXSER_BOARDS] = {
361 /* 0x180, 0x280, 0x200, 0x320 */
364 static struct tty_driver *mxvar_sdriver;
365 static struct mxser_struct mxvar_table[MXSER_PORTS];
366 static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
367 static struct termios *mxvar_termios[MXSER_PORTS + 1];
368 static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
369 static struct mxser_log mxvar_log;
370 static int mxvar_diagflag;
371 static unsigned char mxser_msr[MXSER_PORTS + 1];
372 static struct mxser_mon_ext mon_data_ext;
373 static int mxser_set_baud_method[MXSER_PORTS + 1];
374 static spinlock_t gm_lock;
377 * This is used to figure out the divisor speeds and the timeouts
380 static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
386 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
387 static int mxser_init(void);
389 /* static void mxser_poll(unsigned long); */
390 static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
391 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
392 static void mxser_do_softint(struct work_struct *);
393 static int mxser_open(struct tty_struct *, struct file *);
394 static void mxser_close(struct tty_struct *, struct file *);
395 static int mxser_write(struct tty_struct *, const unsigned char *, int);
396 static int mxser_write_room(struct tty_struct *);
397 static void mxser_flush_buffer(struct tty_struct *);
398 static int mxser_chars_in_buffer(struct tty_struct *);
399 static void mxser_flush_chars(struct tty_struct *);
400 static void mxser_put_char(struct tty_struct *, unsigned char);
401 static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
402 static int mxser_ioctl_special(unsigned int, void __user *);
403 static void mxser_throttle(struct tty_struct *);
404 static void mxser_unthrottle(struct tty_struct *);
405 static void mxser_set_termios(struct tty_struct *, struct termios *);
406 static void mxser_stop(struct tty_struct *);
407 static void mxser_start(struct tty_struct *);
408 static void mxser_hangup(struct tty_struct *);
409 static void mxser_rs_break(struct tty_struct *, int);
410 static irqreturn_t mxser_interrupt(int, void *);
411 static void mxser_receive_chars(struct mxser_struct *, int *);
412 static void mxser_transmit_chars(struct mxser_struct *);
413 static void mxser_check_modem_status(struct mxser_struct *, int);
414 static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
415 static int mxser_startup(struct mxser_struct *);
416 static void mxser_shutdown(struct mxser_struct *);
417 static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
418 static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
419 static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
420 static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
421 static void mxser_send_break(struct mxser_struct *, int);
422 static int mxser_tiocmget(struct tty_struct *, struct file *);
423 static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
424 static int mxser_set_baud(struct mxser_struct *info, long newspd);
425 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
427 static void mxser_startrx(struct tty_struct *tty);
428 static void mxser_stoprx(struct tty_struct *tty);
431 static int CheckIsMoxaMust(int io)
436 outb(0, io + UART_LCR);
437 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
438 oldmcr = inb(io + UART_MCR);
439 outb(0, io + UART_MCR);
440 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
441 if ((hwid = inb(io + UART_MCR)) != 0) {
442 outb(oldmcr, io + UART_MCR);
443 return MOXA_OTHER_UART;
446 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
447 for (i = 0; i < UART_TYPE_NUM; i++) {
448 if (hwid == Gmoxa_uart_id[i])
451 return MOXA_OTHER_UART;
454 /* above is modified by Victor Yu. 08-15-2002 */
456 static const struct tty_operations mxser_ops = {
458 .close = mxser_close,
459 .write = mxser_write,
460 .put_char = mxser_put_char,
461 .flush_chars = mxser_flush_chars,
462 .write_room = mxser_write_room,
463 .chars_in_buffer = mxser_chars_in_buffer,
464 .flush_buffer = mxser_flush_buffer,
465 .ioctl = mxser_ioctl,
466 .throttle = mxser_throttle,
467 .unthrottle = mxser_unthrottle,
468 .set_termios = mxser_set_termios,
470 .start = mxser_start,
471 .hangup = mxser_hangup,
472 .break_ctl = mxser_rs_break,
473 .wait_until_sent = mxser_wait_until_sent,
474 .tiocmget = mxser_tiocmget,
475 .tiocmset = mxser_tiocmset,
479 * The MOXA Smartio/Industio serial driver boot-time initialization code!
482 static int __init mxser_module_init(void)
487 printk(KERN_DEBUG "Loading module mxser ...\n");
490 printk(KERN_DEBUG "Done.\n");
494 static void __exit mxser_module_exit(void)
499 printk(KERN_DEBUG "Unloading module mxser ...\n");
501 err = tty_unregister_driver(mxvar_sdriver);
503 put_tty_driver(mxvar_sdriver);
505 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
507 for (i = 0; i < MXSER_BOARDS; i++) {
508 struct pci_dev *pdev;
510 if (mxsercfg[i].board_type == -1)
513 pdev = mxsercfg[i].pciInfo.pdev;
514 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
515 if (pdev != NULL) { /* PCI */
516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
520 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
521 release_region(mxsercfg[i].vector, 1);
526 printk(KERN_DEBUG "Done.\n");
529 static void process_txrx_fifo(struct mxser_struct *info)
533 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
534 info->rx_trigger = 1;
535 info->rx_high_water = 1;
536 info->rx_low_water = 1;
537 info->xmit_fifo_size = 1;
539 for (i = 0; i < UART_INFO_NUM; i++) {
540 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
541 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
542 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
543 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
544 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
551 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
553 struct mxser_struct *info;
557 n = board * MXSER_PORTS_PER_BOARD;
558 info = &mxvar_table[n];
560 printk(KERN_DEBUG " ttyMI%d - ttyMI%d ",
561 n, n + hwconf->ports - 1);
562 printk(" max. baud rate = %d bps.\n",
563 hwconf->MaxCanSetBaudRate[0]);
566 for (i = 0; i < hwconf->ports; i++, n++, info++) {
568 info->base = hwconf->ioaddr[i];
569 info->irq = hwconf->irq;
570 info->vector = hwconf->vector;
571 info->vectormask = hwconf->vector_mask;
572 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; /* add by Victor Yu. 01-05-2004 */
574 info->ldisc_stop_rx = 0;
576 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
577 /* Enhance mode enabled here */
578 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
579 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
582 info->flags = ASYNC_SHARE_IRQ;
583 info->type = hwconf->uart_type;
584 info->baud_base = hwconf->baud_base[i];
586 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
588 process_txrx_fifo(info);
591 info->custom_divisor = hwconf->baud_base[i] * 16;
592 info->close_delay = 5 * HZ / 10;
593 info->closing_wait = 30 * HZ;
594 INIT_WORK(&info->tqueue, mxser_do_softint);
595 info->normal_termios = mxvar_sdriver->init_termios;
596 init_waitqueue_head(&info->open_wait);
597 init_waitqueue_head(&info->close_wait);
598 init_waitqueue_head(&info->delta_msr_wait);
599 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
600 info->err_shadow = 0;
601 spin_lock_init(&info->slock);
604 * Allocate the IRQ if necessary
608 /* before set INT ISR, disable all int */
609 for (i = 0; i < hwconf->ports; i++) {
610 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0,
611 hwconf->ioaddr[i] + UART_IER);
614 n = board * MXSER_PORTS_PER_BOARD;
615 info = &mxvar_table[n];
617 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info),
620 printk(KERN_ERR "Board %d: %s",
621 board, mxser_brdname[hwconf->board_type - 1]);
622 printk(" Request irq failed, IRQ (%d) may conflict with"
623 " another device.\n", info->irq);
629 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
631 mxsercfg[board] = *hwconf;
635 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
638 /* unsigned int val; */
639 unsigned int ioaddress;
640 struct pci_dev *pdev = hwconf->pciInfo.pdev;
643 hwconf->board_type = board_type;
644 hwconf->ports = mxser_numports[board_type - 1];
645 ioaddress = pci_resource_start(pdev, 2);
646 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2),
649 for (i = 0; i < hwconf->ports; i++)
650 hwconf->ioaddr[i] = ioaddress + 8 * i;
653 ioaddress = pci_resource_start(pdev, 3);
654 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3),
656 hwconf->vector = ioaddress;
659 hwconf->irq = hwconf->pciInfo.pdev->irq;
661 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
662 hwconf->uart_type = PORT_16550A;
663 hwconf->vector_mask = 0;
666 for (i = 0; i < hwconf->ports; i++) {
667 for (j = 0; j < UART_INFO_NUM; j++) {
668 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
669 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
671 /* exception....CP-102 */
672 if (board_type == MXSER_BOARD_CP102)
673 hwconf->MaxCanSetBaudRate[i] = 921600;
679 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
680 for (i = 0; i < hwconf->ports; i++) {
682 hwconf->opmode_ioaddr[i] = ioaddress + 4;
684 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
686 outb(0, ioaddress + 4); /* default set to RS232 mode */
687 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
690 for (i = 0; i < hwconf->ports; i++) {
691 hwconf->vector_mask |= (1 << i);
692 hwconf->baud_base[i] = 921600;
698 static int mxser_init(void)
700 int i, m, retval, b, n;
701 struct pci_dev *pdev = NULL;
703 unsigned char busnum, devnum;
704 struct mxser_hwconf hwconf;
706 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
709 spin_lock_init(&gm_lock);
711 for (i = 0; i < MXSER_BOARDS; i++) {
712 mxsercfg[i].board_type = -1;
715 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
718 /* Initialize the tty_driver structure */
719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
721 mxvar_sdriver->name = "ttyMI";
722 mxvar_sdriver->major = ttymajor;
723 mxvar_sdriver->minor_start = 0;
724 mxvar_sdriver->num = MXSER_PORTS + 1;
725 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
726 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
727 mxvar_sdriver->init_termios = tty_std_termios;
728 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
729 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
730 tty_set_operations(mxvar_sdriver, &mxser_ops);
731 mxvar_sdriver->ttys = mxvar_tty;
732 mxvar_sdriver->termios = mxvar_termios;
733 mxvar_sdriver->termios_locked = mxvar_termios_locked;
736 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
737 memset(&mxvar_log, 0, sizeof(struct mxser_log));
739 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
740 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
741 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
742 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
745 /* Start finding ISA boards here */
746 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
749 if (!(cap = mxserBoardCAP[b]))
752 retval = mxser_get_ISA_conf(cap, &hwconf);
755 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
756 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
759 if (retval == MXSER_ERR_IRQ)
760 printk(KERN_ERR "Invalid interrupt number, "
761 "board not configured\n");
762 else if (retval == MXSER_ERR_IRQ_CONFLIT)
763 printk(KERN_ERR "Invalid interrupt number, "
764 "board not configured\n");
765 else if (retval == MXSER_ERR_VECTOR)
766 printk(KERN_ERR "Invalid interrupt vector, "
767 "board not configured\n");
768 else if (retval == MXSER_ERR_IOADDR)
769 printk(KERN_ERR "Invalid I/O address, "
770 "board not configured\n");
775 hwconf.pciInfo.busNum = 0;
776 hwconf.pciInfo.devNum = 0;
777 hwconf.pciInfo.pdev = NULL;
779 mxser_getcfg(m, &hwconf);
781 * init mxsercfg first,
782 * or mxsercfg data is not correct on ISR.
784 /* mxser_initbrd will hook ISR. */
785 if (mxser_initbrd(m, &hwconf) < 0)
791 /* Start finding ISA boards from module arg */
792 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
795 if (!(cap = ioaddr[b]))
798 retval = mxser_get_ISA_conf(cap, &hwconf);
801 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
802 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
805 if (retval == MXSER_ERR_IRQ)
806 printk(KERN_ERR "Invalid interrupt number, "
807 "board not configured\n");
808 else if (retval == MXSER_ERR_IRQ_CONFLIT)
809 printk(KERN_ERR "Invalid interrupt number, "
810 "board not configured\n");
811 else if (retval == MXSER_ERR_VECTOR)
812 printk(KERN_ERR "Invalid interrupt vector, "
813 "board not configured\n");
814 else if (retval == MXSER_ERR_IOADDR)
815 printk(KERN_ERR "Invalid I/O address, "
816 "board not configured\n");
821 hwconf.pciInfo.busNum = 0;
822 hwconf.pciInfo.devNum = 0;
823 hwconf.pciInfo.pdev = NULL;
825 mxser_getcfg(m, &hwconf);
827 * init mxsercfg first,
828 * or mxsercfg data is not correct on ISR.
830 /* mxser_initbrd will hook ISR. */
831 if (mxser_initbrd(m, &hwconf) < 0)
837 /* start finding PCI board here */
839 n = ARRAY_SIZE(mxser_pcibrds) - 1;
843 pdev = pci_get_device(mxser_pcibrds[b].vendor,
844 mxser_pcibrds[b].device, pdev);
849 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
850 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
851 hwconf.pciInfo.pdev = pdev;
852 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
853 mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
854 busnum, devnum >> 3);
856 if (m >= MXSER_BOARDS)
858 "Too many Smartio/Industio family boards find "
859 "(maximum %d), board not configured\n",
862 if (pci_enable_device(pdev)) {
863 printk(KERN_ERR "Moxa SmartI/O PCI enable "
867 retval = mxser_get_PCI_conf(busnum, devnum,
868 (int)mxser_pcibrds[b].driver_data,
871 if (retval == MXSER_ERR_IRQ)
873 "Invalid interrupt number, "
874 "board not configured\n");
875 else if (retval == MXSER_ERR_IRQ_CONFLIT)
877 "Invalid interrupt number, "
878 "board not configured\n");
879 else if (retval == MXSER_ERR_VECTOR)
881 "Invalid interrupt vector, "
882 "board not configured\n");
883 else if (retval == MXSER_ERR_IOADDR)
885 "Invalid I/O address, "
886 "board not configured\n");
889 mxser_getcfg(m, &hwconf);
890 /* init mxsercfg first,
891 * or mxsercfg data is not correct on ISR.
893 /* mxser_initbrd will hook ISR. */
894 if (mxser_initbrd(m, &hwconf) < 0)
897 /* Keep an extra reference if we succeeded. It will
898 be returned at unload time */
904 retval = tty_register_driver(mxvar_sdriver);
906 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family"
908 put_tty_driver(mxvar_sdriver);
910 for (i = 0; i < MXSER_BOARDS; i++) {
911 if (mxsercfg[i].board_type == -1)
914 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
915 /* todo: release io, vector */
924 static void mxser_do_softint(struct work_struct *work)
926 struct mxser_struct *info =
927 container_of(work, struct mxser_struct, tqueue);
928 struct tty_struct *tty;
933 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
935 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
940 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
942 unsigned char status = 0;
944 status = inb(baseaddr + UART_MSR);
946 mxser_msr[port] &= 0x0F;
947 mxser_msr[port] |= status;
948 status = mxser_msr[port];
956 * This routine is called whenever a serial port is opened. It
957 * enables interrupts for a serial port, linking in its async structure into
958 * the IRQ chain. It also performs the serial-specific
959 * initialization for the tty structure.
961 static int mxser_open(struct tty_struct *tty, struct file *filp)
963 struct mxser_struct *info;
966 /* initialize driver_data in case something fails */
967 tty->driver_data = NULL;
970 if (line == MXSER_PORTS)
972 if (line < 0 || line > MXSER_PORTS)
974 info = mxvar_table + line;
978 tty->driver_data = info;
981 * Start up serial port
983 retval = mxser_startup(info);
987 retval = mxser_block_til_ready(tty, filp, info);
993 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
994 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
995 *tty->termios = info->normal_termios;
997 *tty->termios = info->callout_termios;
998 mxser_change_speed(info, NULL);
1001 info->session = process_session(current);
1002 info->pgrp = process_group(current);
1005 status = mxser_get_msr(info->base, 0, info->port);
1006 mxser_check_modem_status(info, status);
1009 /* unmark here for very high baud rate (ex. 921600 bps) used */
1010 tty->low_latency = 1;
1015 * This routine is called when the serial port gets closed. First, we
1016 * wait for the last remaining data to be sent. Then, we unlink its
1017 * async structure from the interrupt chain if necessary, and we free
1018 * that IRQ if nothing is left in the chain.
1020 static void mxser_close(struct tty_struct *tty, struct file *filp)
1022 struct mxser_struct *info = tty->driver_data;
1024 unsigned long timeout;
1025 unsigned long flags;
1026 struct tty_ldisc *ld;
1028 if (tty->index == MXSER_PORTS)
1033 spin_lock_irqsave(&info->slock, flags);
1035 if (tty_hung_up_p(filp)) {
1036 spin_unlock_irqrestore(&info->slock, flags);
1039 if ((tty->count == 1) && (info->count != 1)) {
1041 * Uh, oh. tty->count is 1, which means that the tty
1042 * structure will be freed. Info->count should always
1043 * be one in these conditions. If it's greater than
1044 * one, we've got real problems, since it means the
1045 * serial port won't be shutdown.
1047 printk(KERN_ERR "mxser_close: bad serial port count; "
1048 "tty->count is 1, info->count is %d\n", info->count);
1051 if (--info->count < 0) {
1052 printk(KERN_ERR "mxser_close: bad serial port count for "
1053 "ttys%d: %d\n", info->port, info->count);
1057 spin_unlock_irqrestore(&info->slock, flags);
1060 info->flags |= ASYNC_CLOSING;
1061 spin_unlock_irqrestore(&info->slock, flags);
1063 * Save the termios structure, since this port may have
1064 * separate termios for callout and dialin.
1066 if (info->flags & ASYNC_NORMAL_ACTIVE)
1067 info->normal_termios = *tty->termios;
1069 * Now we wait for the transmit buffer to clear; and we notify
1070 * the line discipline to only process XON/XOFF characters.
1073 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1074 tty_wait_until_sent(tty, info->closing_wait);
1076 * At this point we stop accepting input. To do this, we
1077 * disable the receive line status interrupts, and tell the
1078 * interrupt driver to stop checking the data ready bit in the
1079 * line status register.
1081 info->IER &= ~UART_IER_RLSI;
1082 if (info->IsMoxaMustChipFlag)
1083 info->IER &= ~MOXA_MUST_RECV_ISR;
1085 info->read_status_mask &= ~UART_LSR_DR;
1087 if (info->flags & ASYNC_INITIALIZED) {
1088 outb(info->IER, info->base + UART_IER);
1090 * Before we drop DTR, make sure the UART transmitter
1091 * has completely drained; this is especially
1092 * important if there is a transmit FIFO!
1094 timeout = jiffies + HZ;
1095 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1096 schedule_timeout_interruptible(5);
1097 if (time_after(jiffies, timeout))
1101 mxser_shutdown(info);
1103 if (tty->driver->flush_buffer)
1104 tty->driver->flush_buffer(tty);
1106 ld = tty_ldisc_ref(tty);
1108 if (ld->flush_buffer)
1109 ld->flush_buffer(tty);
1110 tty_ldisc_deref(ld);
1116 if (info->blocked_open) {
1117 if (info->close_delay)
1118 schedule_timeout_interruptible(info->close_delay);
1119 wake_up_interruptible(&info->open_wait);
1122 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1123 wake_up_interruptible(&info->close_wait);
1127 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1130 struct mxser_struct *info = tty->driver_data;
1131 unsigned long flags;
1133 if (!info->xmit_buf)
1137 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1138 SERIAL_XMIT_SIZE - info->xmit_head));
1142 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1143 spin_lock_irqsave(&info->slock, flags);
1144 info->xmit_head = (info->xmit_head + c) &
1145 (SERIAL_XMIT_SIZE - 1);
1146 info->xmit_cnt += c;
1147 spin_unlock_irqrestore(&info->slock, flags);
1154 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1155 if (!tty->hw_stopped ||
1156 (info->type == PORT_16550A) ||
1157 (info->IsMoxaMustChipFlag)) {
1158 spin_lock_irqsave(&info->slock, flags);
1159 info->IER |= UART_IER_THRI;
1160 outb(info->IER, info->base + UART_IER);
1161 spin_unlock_irqrestore(&info->slock, flags);
1167 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1169 struct mxser_struct *info = tty->driver_data;
1170 unsigned long flags;
1172 if (!info->xmit_buf)
1175 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1178 spin_lock_irqsave(&info->slock, flags);
1179 info->xmit_buf[info->xmit_head++] = ch;
1180 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1182 spin_unlock_irqrestore(&info->slock, flags);
1183 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1184 if (!tty->hw_stopped ||
1185 (info->type == PORT_16550A) ||
1186 info->IsMoxaMustChipFlag) {
1187 spin_lock_irqsave(&info->slock, flags);
1188 info->IER |= UART_IER_THRI;
1189 outb(info->IER, info->base + UART_IER);
1190 spin_unlock_irqrestore(&info->slock, flags);
1196 static void mxser_flush_chars(struct tty_struct *tty)
1198 struct mxser_struct *info = tty->driver_data;
1199 unsigned long flags;
1201 if (info->xmit_cnt <= 0 ||
1205 (info->type != PORT_16550A) &&
1206 (!info->IsMoxaMustChipFlag)
1210 spin_lock_irqsave(&info->slock, flags);
1212 info->IER |= UART_IER_THRI;
1213 outb(info->IER, info->base + UART_IER);
1215 spin_unlock_irqrestore(&info->slock, flags);
1218 static int mxser_write_room(struct tty_struct *tty)
1220 struct mxser_struct *info = tty->driver_data;
1223 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1229 static int mxser_chars_in_buffer(struct tty_struct *tty)
1231 struct mxser_struct *info = tty->driver_data;
1232 return info->xmit_cnt;
1235 static void mxser_flush_buffer(struct tty_struct *tty)
1237 struct mxser_struct *info = tty->driver_data;
1239 unsigned long flags;
1242 spin_lock_irqsave(&info->slock, flags);
1243 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1245 /* below added by shinhay */
1246 fcr = inb(info->base + UART_FCR);
1247 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1248 info->base + UART_FCR);
1249 outb(fcr, info->base + UART_FCR);
1251 spin_unlock_irqrestore(&info->slock, flags);
1252 /* above added by shinhay */
1254 wake_up_interruptible(&tty->write_wait);
1255 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1256 (tty->ldisc.write_wakeup) (tty);
1259 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1261 struct mxser_struct *info = tty->driver_data;
1263 struct async_icount cprev, cnow; /* kernel counter temps */
1264 struct serial_icounter_struct __user *p_cuser;
1265 unsigned long templ;
1266 unsigned long flags;
1267 void __user *argp = (void __user *)arg;
1269 if (tty->index == MXSER_PORTS)
1270 return mxser_ioctl_special(cmd, argp);
1272 /* following add by Victor Yu. 01-05-2004 */
1273 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1275 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1277 unsigned char val, mask;
1280 if (cmd == MOXA_SET_OP_MODE) {
1281 if (get_user(opmode, (int __user *) argp))
1283 if (opmode != RS232_MODE &&
1284 opmode != RS485_2WIRE_MODE &&
1285 opmode != RS422_MODE &&
1286 opmode != RS485_4WIRE_MODE)
1290 val = inb(info->opmode_ioaddr);
1292 val |= (opmode << shiftbit);
1293 outb(val, info->opmode_ioaddr);
1296 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1297 opmode &= OP_MODE_MASK;
1298 if (copy_to_user(argp, &opmode, sizeof(int)))
1303 /* above add by Victor Yu. 01-05-2004 */
1305 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1306 if (tty->flags & (1 << TTY_IO_ERROR))
1310 case TCSBRK: /* SVID version: non-zero arg --> no break */
1311 retval = tty_check_change(tty);
1314 tty_wait_until_sent(tty, 0);
1316 mxser_send_break(info, HZ / 4); /* 1/4 second */
1318 case TCSBRKP: /* support for POSIX tcsendbreak() */
1319 retval = tty_check_change(tty);
1322 tty_wait_until_sent(tty, 0);
1323 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1326 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1328 if (get_user(templ, (unsigned long __user *) argp))
1331 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1334 return mxser_get_serial_info(info, argp);
1336 return mxser_set_serial_info(info, argp);
1337 case TIOCSERGETLSR: /* Get line status register */
1338 return mxser_get_lsr_info(info, argp);
1340 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1341 * - mask passed in arg for lines of interest
1342 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1343 * Caller should use TIOCGICOUNT to see which one it was
1346 DECLARE_WAITQUEUE(wait, current);
1348 spin_lock_irqsave(&info->slock, flags);
1349 cprev = info->icount; /* note the counters on entry */
1350 spin_unlock_irqrestore(&info->slock, flags);
1352 add_wait_queue(&info->delta_msr_wait, &wait);
1354 spin_lock_irqsave(&info->slock, flags);
1355 cnow = info->icount; /* atomic copy */
1356 spin_unlock_irqrestore(&info->slock, flags);
1358 set_current_state(TASK_INTERRUPTIBLE);
1359 if (((arg & TIOCM_RNG) &&
1360 (cnow.rng != cprev.rng)) ||
1361 ((arg & TIOCM_DSR) &&
1362 (cnow.dsr != cprev.dsr)) ||
1363 ((arg & TIOCM_CD) &&
1364 (cnow.dcd != cprev.dcd)) ||
1365 ((arg & TIOCM_CTS) &&
1366 (cnow.cts != cprev.cts))) {
1370 /* see if a signal did it */
1371 if (signal_pending(current)) {
1377 current->state = TASK_RUNNING;
1378 remove_wait_queue(&info->delta_msr_wait, &wait);
1383 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1384 * Return: write counters to the user passed counter struct
1385 * NB: both 1->0 and 0->1 transitions are counted except for
1386 * RI where only 0->1 is counted.
1389 spin_lock_irqsave(&info->slock, flags);
1390 cnow = info->icount;
1391 spin_unlock_irqrestore(&info->slock, flags);
1393 /* modified by casper 1/11/2000 */
1394 if (put_user(cnow.frame, &p_cuser->frame))
1396 if (put_user(cnow.brk, &p_cuser->brk))
1398 if (put_user(cnow.overrun, &p_cuser->overrun))
1400 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1402 if (put_user(cnow.parity, &p_cuser->parity))
1404 if (put_user(cnow.rx, &p_cuser->rx))
1406 if (put_user(cnow.tx, &p_cuser->tx))
1408 put_user(cnow.cts, &p_cuser->cts);
1409 put_user(cnow.dsr, &p_cuser->dsr);
1410 put_user(cnow.rng, &p_cuser->rng);
1411 put_user(cnow.dcd, &p_cuser->dcd);
1413 case MOXA_HighSpeedOn:
1414 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1415 case MOXA_SDS_RSTICOUNTER: {
1416 info->mon_data.rxcnt = 0;
1417 info->mon_data.txcnt = 0;
1420 /* (above) added by James. */
1421 case MOXA_ASPP_SETBAUD:{
1423 if (get_user(baud, (long __user *)argp))
1425 mxser_set_baud(info, baud);
1428 case MOXA_ASPP_GETBAUD:
1429 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1434 case MOXA_ASPP_OQUEUE:{
1437 len = mxser_chars_in_buffer(tty);
1439 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1441 len += (lsr ? 0 : 1);
1443 if (copy_to_user(argp, &len, sizeof(int)))
1448 case MOXA_ASPP_MON: {
1451 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1453 status = mxser_get_msr(info->base, 1, info->port, info);
1454 mxser_check_modem_status(info, status);
1456 mcr = inb(info->base + UART_MCR);
1457 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1458 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1460 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1462 if (mcr & MOXA_MUST_MCR_TX_XON)
1463 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1465 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1467 if (info->tty->hw_stopped)
1468 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1470 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1472 if (copy_to_user(argp, &info->mon_data,
1473 sizeof(struct mxser_mon)))
1479 case MOXA_ASPP_LSTATUS: {
1480 if (copy_to_user(argp, &info->err_shadow,
1481 sizeof(unsigned char)))
1484 info->err_shadow = 0;
1487 case MOXA_SET_BAUD_METHOD: {
1490 if (get_user(method, (int __user *)argp))
1492 mxser_set_baud_method[info->port] = method;
1493 if (copy_to_user(argp, &method, sizeof(int)))
1499 return -ENOIOCTLCMD;
1505 #define CMSPAR 010000000000
1508 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1510 int i, result, status;
1514 if (copy_to_user(argp, mxsercfg,
1515 sizeof(struct mxser_hwconf) * 4))
1518 case MOXA_GET_MAJOR:
1519 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1523 case MOXA_GET_CUMAJOR:
1524 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1528 case MOXA_CHKPORTENABLE:
1530 for (i = 0; i < MXSER_PORTS; i++) {
1531 if (mxvar_table[i].base)
1534 return put_user(result, (unsigned long __user *)argp);
1535 case MOXA_GETDATACOUNT:
1536 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1539 case MOXA_GETMSTATUS:
1540 for (i = 0; i < MXSER_PORTS; i++) {
1542 if (!mxvar_table[i].base) {
1543 GMStatus[i].dcd = 0;
1544 GMStatus[i].dsr = 0;
1545 GMStatus[i].cts = 0;
1549 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1550 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1552 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1554 status = inb(mxvar_table[i].base + UART_MSR);
1555 if (status & 0x80 /*UART_MSR_DCD */ )
1556 GMStatus[i].dcd = 1;
1558 GMStatus[i].dcd = 0;
1560 if (status & 0x20 /*UART_MSR_DSR */ )
1561 GMStatus[i].dsr = 1;
1563 GMStatus[i].dsr = 0;
1566 if (status & 0x10 /*UART_MSR_CTS */ )
1567 GMStatus[i].cts = 1;
1569 GMStatus[i].cts = 0;
1571 if (copy_to_user(argp, GMStatus,
1572 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1575 case MOXA_ASPP_MON_EXT: {
1579 unsigned cflag, iflag;
1581 for (i = 0; i < MXSER_PORTS; i++) {
1582 if (!mxvar_table[i].base)
1585 status = mxser_get_msr(mxvar_table[i].base, 0,
1586 i, &(mxvar_table[i]));
1588 mxser_check_modem_status(&mxvar_table[i],
1591 if (status & UART_MSR_TERI)
1592 mxvar_table[i].icount.rng++;
1593 if (status & UART_MSR_DDSR)
1594 mxvar_table[i].icount.dsr++;
1595 if (status & UART_MSR_DDCD)
1596 mxvar_table[i].icount.dcd++;
1597 if (status & UART_MSR_DCTS)
1598 mxvar_table[i].icount.cts++;
1600 mxvar_table[i].mon_data.modem_status = status;
1601 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1602 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1603 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1604 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1605 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1606 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1608 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1609 cflag = mxvar_table[i].normal_termios.c_cflag;
1610 iflag = mxvar_table[i].normal_termios.c_iflag;
1612 cflag = mxvar_table[i].tty->termios->c_cflag;
1613 iflag = mxvar_table[i].tty->termios->c_iflag;
1616 mon_data_ext.databits[i] = cflag & CSIZE;
1618 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1620 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1622 mon_data_ext.flowctrl[i] = 0x00;
1624 if (cflag & CRTSCTS)
1625 mon_data_ext.flowctrl[i] |= 0x03;
1627 if (iflag & (IXON | IXOFF))
1628 mon_data_ext.flowctrl[i] |= 0x0C;
1630 if (mxvar_table[i].type == PORT_16550A)
1631 mon_data_ext.fifo[i] = 1;
1633 mon_data_ext.fifo[i] = 0;
1637 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1638 opmode &= OP_MODE_MASK;
1640 mon_data_ext.iftype[i] = opmode;
1643 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1650 return -ENOIOCTLCMD;
1655 static void mxser_stoprx(struct tty_struct *tty)
1657 struct mxser_struct *info = tty->driver_data;
1658 /* unsigned long flags; */
1660 info->ldisc_stop_rx = 1;
1662 /* MX_LOCK(&info->slock); */
1663 /* following add by Victor Yu. 09-02-2002 */
1664 if (info->IsMoxaMustChipFlag) {
1665 info->IER &= ~MOXA_MUST_RECV_ISR;
1666 outb(info->IER, info->base + UART_IER);
1668 /* above add by Victor Yu. 09-02-2002 */
1669 info->x_char = STOP_CHAR(tty);
1670 /* mask by Victor Yu. 09-02-2002 */
1671 /* outb(info->IER, 0); */
1672 outb(0, info->base + UART_IER);
1673 info->IER |= UART_IER_THRI;
1674 /* force Tx interrupt */
1675 outb(info->IER, info->base + UART_IER);
1676 } /* add by Victor Yu. 09-02-2002 */
1677 /* MX_UNLOCK(&info->slock); */
1680 if (info->tty->termios->c_cflag & CRTSCTS) {
1681 /* MX_LOCK(&info->slock); */
1682 info->MCR &= ~UART_MCR_RTS;
1683 outb(info->MCR, info->base + UART_MCR);
1684 /* MX_UNLOCK(&info->slock); */
1688 static void mxser_startrx(struct tty_struct *tty)
1690 struct mxser_struct *info = tty->driver_data;
1691 /* unsigned long flags; */
1693 info->ldisc_stop_rx = 0;
1698 /* MX_LOCK(&info->slock); */
1700 /* following add by Victor Yu. 09-02-2002 */
1701 if (info->IsMoxaMustChipFlag) {
1702 info->IER |= MOXA_MUST_RECV_ISR;
1703 outb(info->IER, info->base + UART_IER);
1705 /* above add by Victor Yu. 09-02-2002 */
1707 info->x_char = START_CHAR(tty);
1708 /* mask by Victor Yu. 09-02-2002 */
1709 /* outb(info->IER, 0); */
1710 /* add by Victor Yu. 09-02-2002 */
1711 outb(0, info->base + UART_IER);
1712 /* force Tx interrupt */
1713 info->IER |= UART_IER_THRI;
1714 outb(info->IER, info->base + UART_IER);
1715 } /* add by Victor Yu. 09-02-2002 */
1716 /* MX_UNLOCK(&info->slock); */
1720 if (info->tty->termios->c_cflag & CRTSCTS) {
1721 /* MX_LOCK(&info->slock); */
1722 info->MCR |= UART_MCR_RTS;
1723 outb(info->MCR, info->base + UART_MCR);
1724 /* MX_UNLOCK(&info->slock); */
1729 * This routine is called by the upper-layer tty layer to signal that
1730 * incoming characters should be throttled.
1732 static void mxser_throttle(struct tty_struct *tty)
1734 /* struct mxser_struct *info = tty->driver_data; */
1735 /* unsigned long flags; */
1737 /* MX_LOCK(&info->slock); */
1739 /* MX_UNLOCK(&info->slock); */
1742 static void mxser_unthrottle(struct tty_struct *tty)
1744 /* struct mxser_struct *info = tty->driver_data; */
1745 /* unsigned long flags; */
1747 /* MX_LOCK(&info->slock); */
1749 /* MX_UNLOCK(&info->slock); */
1752 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1754 struct mxser_struct *info = tty->driver_data;
1755 unsigned long flags;
1757 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1758 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1760 mxser_change_speed(info, old_termios);
1762 if ((old_termios->c_cflag & CRTSCTS) &&
1763 !(tty->termios->c_cflag & CRTSCTS)) {
1764 tty->hw_stopped = 0;
1769 /* Handle sw stopped */
1770 if ((old_termios->c_iflag & IXON) &&
1771 !(tty->termios->c_iflag & IXON)) {
1774 /* following add by Victor Yu. 09-02-2002 */
1775 if (info->IsMoxaMustChipFlag) {
1776 spin_lock_irqsave(&info->slock, flags);
1777 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1778 spin_unlock_irqrestore(&info->slock, flags);
1780 /* above add by Victor Yu. 09-02-2002 */
1787 * mxser_stop() and mxser_start()
1789 * This routines are called before setting or resetting tty->stopped.
1790 * They enable or disable transmitter interrupts, as necessary.
1792 static void mxser_stop(struct tty_struct *tty)
1794 struct mxser_struct *info = tty->driver_data;
1795 unsigned long flags;
1797 spin_lock_irqsave(&info->slock, flags);
1798 if (info->IER & UART_IER_THRI) {
1799 info->IER &= ~UART_IER_THRI;
1800 outb(info->IER, info->base + UART_IER);
1802 spin_unlock_irqrestore(&info->slock, flags);
1805 static void mxser_start(struct tty_struct *tty)
1807 struct mxser_struct *info = tty->driver_data;
1808 unsigned long flags;
1810 spin_lock_irqsave(&info->slock, flags);
1811 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1812 info->IER |= UART_IER_THRI;
1813 outb(info->IER, info->base + UART_IER);
1815 spin_unlock_irqrestore(&info->slock, flags);
1819 * mxser_wait_until_sent() --- wait until the transmitter is empty
1821 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1823 struct mxser_struct *info = tty->driver_data;
1824 unsigned long orig_jiffies, char_time;
1827 if (info->type == PORT_UNKNOWN)
1830 if (info->xmit_fifo_size == 0)
1831 return; /* Just in case.... */
1833 orig_jiffies = jiffies;
1835 * Set the check interval to be 1/5 of the estimated time to
1836 * send a single character, and make it at least 1. The check
1837 * interval should also be less than the timeout.
1839 * Note: we have to use pretty tight timings here to satisfy
1842 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1843 char_time = char_time / 5;
1846 if (timeout && timeout < char_time)
1847 char_time = timeout;
1849 * If the transmitter hasn't cleared in twice the approximate
1850 * amount of time to send the entire FIFO, it probably won't
1851 * ever clear. This assumes the UART isn't doing flow
1852 * control, which is currently the case. Hence, if it ever
1853 * takes longer than info->timeout, this is probably due to a
1854 * UART bug of some kind. So, we clamp the timeout parameter at
1857 if (!timeout || timeout > 2 * info->timeout)
1858 timeout = 2 * info->timeout;
1859 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1860 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1861 timeout, char_time);
1862 printk("jiff=%lu...", jiffies);
1864 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1865 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1866 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1868 schedule_timeout_interruptible(char_time);
1869 if (signal_pending(current))
1871 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1874 set_current_state(TASK_RUNNING);
1876 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1877 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1883 * This routine is called by tty_hangup() when a hangup is signaled.
1885 void mxser_hangup(struct tty_struct *tty)
1887 struct mxser_struct *info = tty->driver_data;
1889 mxser_flush_buffer(tty);
1890 mxser_shutdown(info);
1893 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1895 wake_up_interruptible(&info->open_wait);
1899 /* added by James 03-12-2004. */
1901 * mxser_rs_break() --- routine which turns the break handling on or off
1903 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1905 struct mxser_struct *info = tty->driver_data;
1906 unsigned long flags;
1908 spin_lock_irqsave(&info->slock, flags);
1909 if (break_state == -1)
1910 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
1911 info->base + UART_LCR);
1913 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
1914 info->base + UART_LCR);
1915 spin_unlock_irqrestore(&info->slock, flags);
1918 /* (above) added by James. */
1922 * This is the serial driver's generic interrupt routine
1924 static irqreturn_t mxser_interrupt(int irq, void *dev_id)
1927 struct mxser_struct *info;
1928 struct mxser_struct *port;
1929 int max, irqbits, bits, msr;
1930 int pass_counter = 0;
1931 int handled = IRQ_NONE;
1934 /* spin_lock(&gm_lock); */
1936 for (i = 0; i < MXSER_BOARDS; i++) {
1937 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1943 if (i == MXSER_BOARDS)
1947 max = mxser_numports[mxsercfg[i].board_type - 1];
1949 irqbits = inb(port->vector) & port->vectormask;
1950 if (irqbits == port->vectormask)
1953 handled = IRQ_HANDLED;
1954 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1955 if (irqbits == port->vectormask)
1961 /* following add by Victor Yu. 09-13-2002 */
1962 iir = inb(info->base + UART_IIR);
1963 if (iir & UART_IIR_NO_INT)
1965 iir &= MOXA_MUST_IIR_MASK;
1967 status = inb(info->base + UART_LSR);
1968 outb(0x27, info->base + UART_FCR);
1969 inb(info->base + UART_MSR);
1972 /* above add by Victor Yu. 09-13-2002 */
1974 if (info->tty->flip.count < TTY_FLIPBUF_SIZE / 4) {
1975 info->IER |= MOXA_MUST_RECV_ISR;
1976 outb(info->IER, info->base + UART_IER);
1981 /* mask by Victor Yu. 09-13-2002
1983 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1986 /* mask by Victor Yu. 09-02-2002
1987 status = inb(info->base + UART_LSR) & info->read_status_mask;
1990 /* following add by Victor Yu. 09-02-2002 */
1991 status = inb(info->base + UART_LSR);
1993 if (status & UART_LSR_PE)
1994 info->err_shadow |= NPPI_NOTIFY_PARITY;
1995 if (status & UART_LSR_FE)
1996 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1997 if (status & UART_LSR_OE)
1998 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1999 if (status & UART_LSR_BI)
2000 info->err_shadow |= NPPI_NOTIFY_BREAK;
2002 if (info->IsMoxaMustChipFlag) {
2004 if ( (status & 0x02) && !(status & 0x01) ) {
2005 outb(info->base+UART_FCR, 0x23);
2009 if (iir == MOXA_MUST_IIR_GDA ||
2010 iir == MOXA_MUST_IIR_RDA ||
2011 iir == MOXA_MUST_IIR_RTO ||
2012 iir == MOXA_MUST_IIR_LSR)
2013 mxser_receive_chars(info, &status);
2016 /* above add by Victor Yu. 09-02-2002 */
2018 status &= info->read_status_mask;
2019 if (status & UART_LSR_DR)
2020 mxser_receive_chars(info, &status);
2022 msr = inb(info->base + UART_MSR);
2023 if (msr & UART_MSR_ANY_DELTA) {
2024 mxser_check_modem_status(info, msr);
2026 /* following add by Victor Yu. 09-13-2002 */
2027 if (info->IsMoxaMustChipFlag) {
2028 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
2029 mxser_transmit_chars(info);
2032 /* above add by Victor Yu. 09-13-2002 */
2034 if (status & UART_LSR_THRE) {
2035 /* 8-2-99 by William
2036 if ( info->x_char || (info->xmit_cnt > 0) )
2038 mxser_transmit_chars(info);
2042 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
2043 break; /* Prevent infinite loops */
2048 /* spin_unlock(&gm_lock); */
2052 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2054 struct tty_struct *tty = info->tty;
2055 unsigned char ch, gdl;
2060 unsigned long flags;
2062 spin_lock_irqsave(&info->slock, flags);
2064 recv_room = tty->receive_room;
2065 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2066 /* mxser_throttle(tty); */
2071 /* following add by Victor Yu. 09-02-2002 */
2072 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2074 if (*status & UART_LSR_SPECIAL) {
2077 /* following add by Victor Yu. 02-11-2004 */
2078 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID &&
2079 (*status & MOXA_MUST_LSR_RERR))
2081 /* above add by Victor Yu. 02-14-2004 */
2082 if (*status & MOXA_MUST_LSR_RERR)
2085 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2087 /* add by Victor Yu. 02-11-2004 */
2088 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID)
2089 gdl &= MOXA_MUST_GDL_MASK;
2090 if (gdl >= recv_room) {
2091 if (!info->ldisc_stop_rx) {
2092 /* mxser_throttle(tty); */
2098 ch = inb(info->base + UART_RX);
2099 tty_insert_flip_char(tty, ch, 0);
2102 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2111 /* above add by Victor Yu. 09-02-2002 */
2117 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2124 ch = inb(info->base + UART_RX);
2125 /* following add by Victor Yu. 09-02-2002 */
2126 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2127 outb(0x23, info->base + UART_FCR);
2128 *status &= info->read_status_mask;
2129 /* above add by Victor Yu. 09-02-2002 */
2130 if (*status & info->ignore_status_mask) {
2131 if (++ignored > 100)
2135 if (*status & UART_LSR_SPECIAL) {
2136 if (*status & UART_LSR_BI) {
2138 /* added by casper 1/11/2000 */
2141 if (info->flags & ASYNC_SAK)
2143 } else if (*status & UART_LSR_PE) {
2145 /* added by casper 1/11/2000 */
2146 info->icount.parity++;
2148 } else if (*status & UART_LSR_FE) {
2150 /* added by casper 1/11/2000 */
2151 info->icount.frame++;
2153 } else if (*status & UART_LSR_OE) {
2155 /* added by casper 1/11/2000 */
2156 info->icount.overrun++;
2160 tty_insert_flip_char(tty, ch, flag);
2162 if (cnt >= recv_room) {
2163 if (!info->ldisc_stop_rx) {
2164 /* mxser_throttle(tty); */
2172 /* following add by Victor Yu. 09-02-2002 */
2173 if (info->IsMoxaMustChipFlag)
2175 /* above add by Victor Yu. 09-02-2002 */
2177 /* mask by Victor Yu. 09-02-2002
2178 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2180 /* following add by Victor Yu. 09-02-2002 */
2181 *status = inb(info->base + UART_LSR);
2182 /* above add by Victor Yu. 09-02-2002 */
2183 } while (*status & UART_LSR_DR);
2185 end_intr: /* add by Victor Yu. 09-02-2002 */
2186 mxvar_log.rxcnt[info->port] += cnt;
2187 info->mon_data.rxcnt += cnt;
2188 info->mon_data.up_rxcnt += cnt;
2189 spin_unlock_irqrestore(&info->slock, flags);
2191 tty_flip_buffer_push(tty);
2194 static void mxser_transmit_chars(struct mxser_struct *info)
2197 unsigned long flags;
2199 spin_lock_irqsave(&info->slock, flags);
2202 outb(info->x_char, info->base + UART_TX);
2204 mxvar_log.txcnt[info->port]++;
2205 info->mon_data.txcnt++;
2206 info->mon_data.up_txcnt++;
2208 /* added by casper 1/11/2000 */
2211 spin_unlock_irqrestore(&info->slock, flags);
2215 if (info->xmit_buf == 0) {
2216 spin_unlock_irqrestore(&info->slock, flags);
2220 if ((info->xmit_cnt <= 0) || info->tty->stopped ||
2221 (info->tty->hw_stopped &&
2222 (info->type != PORT_16550A) &&
2223 (!info->IsMoxaMustChipFlag))) {
2224 info->IER &= ~UART_IER_THRI;
2225 outb(info->IER, info->base + UART_IER);
2226 spin_unlock_irqrestore(&info->slock, flags);
2230 cnt = info->xmit_cnt;
2231 count = info->xmit_fifo_size;
2233 outb(info->xmit_buf[info->xmit_tail++],
2234 info->base + UART_TX);
2235 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2236 if (--info->xmit_cnt <= 0)
2238 } while (--count > 0);
2239 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2241 /* added by James 03-12-2004. */
2242 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2243 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2244 /* (above) added by James. */
2246 /* added by casper 1/11/2000 */
2247 info->icount.tx += (cnt - info->xmit_cnt);
2250 if (info->xmit_cnt < WAKEUP_CHARS) {
2251 set_bit(MXSER_EVENT_TXLOW, &info->event);
2252 schedule_work(&info->tqueue);
2254 if (info->xmit_cnt <= 0) {
2255 info->IER &= ~UART_IER_THRI;
2256 outb(info->IER, info->base + UART_IER);
2258 spin_unlock_irqrestore(&info->slock, flags);
2261 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2263 /* update input line counters */
2264 if (status & UART_MSR_TERI)
2266 if (status & UART_MSR_DDSR)
2268 if (status & UART_MSR_DDCD)
2270 if (status & UART_MSR_DCTS)
2272 info->mon_data.modem_status = status;
2273 wake_up_interruptible(&info->delta_msr_wait);
2275 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2276 if (status & UART_MSR_DCD)
2277 wake_up_interruptible(&info->open_wait);
2278 schedule_work(&info->tqueue);
2281 if (info->flags & ASYNC_CTS_FLOW) {
2282 if (info->tty->hw_stopped) {
2283 if (status & UART_MSR_CTS) {
2284 info->tty->hw_stopped = 0;
2286 if ((info->type != PORT_16550A) &&
2287 (!info->IsMoxaMustChipFlag)) {
2288 info->IER |= UART_IER_THRI;
2289 outb(info->IER, info->base + UART_IER);
2291 set_bit(MXSER_EVENT_TXLOW, &info->event);
2292 schedule_work(&info->tqueue); }
2294 if (!(status & UART_MSR_CTS)) {
2295 info->tty->hw_stopped = 1;
2296 if ((info->type != PORT_16550A) &&
2297 (!info->IsMoxaMustChipFlag)) {
2298 info->IER &= ~UART_IER_THRI;
2299 outb(info->IER, info->base + UART_IER);
2306 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2308 DECLARE_WAITQUEUE(wait, current);
2311 unsigned long flags;
2314 * If non-blocking mode is set, or the port is not enabled,
2315 * then make the check up front and then exit.
2317 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2318 info->flags |= ASYNC_NORMAL_ACTIVE;
2322 if (tty->termios->c_cflag & CLOCAL)
2326 * Block waiting for the carrier detect and the line to become
2327 * free (i.e., not in use by the callout). While we are in
2328 * this loop, info->count is dropped by one, so that
2329 * mxser_close() knows when to free things. We restore it upon
2330 * exit, either normal or abnormal.
2333 add_wait_queue(&info->open_wait, &wait);
2335 spin_lock_irqsave(&info->slock, flags);
2336 if (!tty_hung_up_p(filp))
2338 spin_unlock_irqrestore(&info->slock, flags);
2339 info->blocked_open++;
2341 spin_lock_irqsave(&info->slock, flags);
2342 outb(inb(info->base + UART_MCR) |
2343 UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2344 spin_unlock_irqrestore(&info->slock, flags);
2345 set_current_state(TASK_INTERRUPTIBLE);
2346 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2347 if (info->flags & ASYNC_HUP_NOTIFY)
2350 retval = -ERESTARTSYS;
2353 if (!(info->flags & ASYNC_CLOSING) &&
2355 (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2357 if (signal_pending(current)) {
2358 retval = -ERESTARTSYS;
2363 set_current_state(TASK_RUNNING);
2364 remove_wait_queue(&info->open_wait, &wait);
2365 if (!tty_hung_up_p(filp))
2367 info->blocked_open--;
2370 info->flags |= ASYNC_NORMAL_ACTIVE;
2374 static int mxser_startup(struct mxser_struct *info)
2377 unsigned long flags;
2379 page = __get_free_page(GFP_KERNEL);
2383 spin_lock_irqsave(&info->slock, flags);
2385 if (info->flags & ASYNC_INITIALIZED) {
2387 spin_unlock_irqrestore(&info->slock, flags);
2391 if (!info->base || !info->type) {
2393 set_bit(TTY_IO_ERROR, &info->tty->flags);
2395 spin_unlock_irqrestore(&info->slock, flags);
2401 info->xmit_buf = (unsigned char *) page;
2404 * Clear the FIFO buffers and disable them
2405 * (they will be reenabled in mxser_change_speed())
2407 if (info->IsMoxaMustChipFlag)
2408 outb((UART_FCR_CLEAR_RCVR |
2409 UART_FCR_CLEAR_XMIT |
2410 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2412 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2413 info->base + UART_FCR);
2416 * At this point there's no way the LSR could still be 0xFF;
2417 * if it is, then bail out, because there's likely no UART
2420 if (inb(info->base + UART_LSR) == 0xff) {
2421 spin_unlock_irqrestore(&info->slock, flags);
2422 if (capable(CAP_SYS_ADMIN)) {
2424 set_bit(TTY_IO_ERROR, &info->tty->flags);
2431 * Clear the interrupt registers.
2433 (void) inb(info->base + UART_LSR);
2434 (void) inb(info->base + UART_RX);
2435 (void) inb(info->base + UART_IIR);
2436 (void) inb(info->base + UART_MSR);
2439 * Now, initialize the UART
2441 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2442 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2443 outb(info->MCR, info->base + UART_MCR);
2446 * Finally, enable interrupts
2448 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2449 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2451 /* following add by Victor Yu. 08-30-2002 */
2452 if (info->IsMoxaMustChipFlag)
2453 info->IER |= MOXA_MUST_IER_EGDAI;
2454 /* above add by Victor Yu. 08-30-2002 */
2455 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2458 * And clear the interrupt registers again for luck.
2460 (void) inb(info->base + UART_LSR);
2461 (void) inb(info->base + UART_RX);
2462 (void) inb(info->base + UART_IIR);
2463 (void) inb(info->base + UART_MSR);
2466 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2467 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2470 * and set the speed of the serial port
2472 spin_unlock_irqrestore(&info->slock, flags);
2473 mxser_change_speed(info, NULL);
2475 info->flags |= ASYNC_INITIALIZED;
2480 * This routine will shutdown a serial port; interrupts maybe disabled, and
2481 * DTR is dropped if the hangup on close termio flag is on.
2483 static void mxser_shutdown(struct mxser_struct *info)
2485 unsigned long flags;
2487 if (!(info->flags & ASYNC_INITIALIZED))
2490 spin_lock_irqsave(&info->slock, flags);
2493 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2494 * here so the queue might never be waken up
2496 wake_up_interruptible(&info->delta_msr_wait);
2499 * Free the IRQ, if necessary
2501 if (info->xmit_buf) {
2502 free_page((unsigned long) info->xmit_buf);
2503 info->xmit_buf = NULL;
2507 outb(0x00, info->base + UART_IER);
2509 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2510 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2511 outb(info->MCR, info->base + UART_MCR);
2513 /* clear Rx/Tx FIFO's */
2514 /* following add by Victor Yu. 08-30-2002 */
2515 if (info->IsMoxaMustChipFlag)
2516 outb((UART_FCR_CLEAR_RCVR |
2517 UART_FCR_CLEAR_XMIT |
2518 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2520 /* above add by Victor Yu. 08-30-2002 */
2521 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2522 info->base + UART_FCR);
2524 /* read data port to reset things */
2525 (void) inb(info->base + UART_RX);
2528 set_bit(TTY_IO_ERROR, &info->tty->flags);
2530 info->flags &= ~ASYNC_INITIALIZED;
2532 /* following add by Victor Yu. 09-23-2002 */
2533 if (info->IsMoxaMustChipFlag)
2534 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2535 /* above add by Victor Yu. 09-23-2002 */
2537 spin_unlock_irqrestore(&info->slock, flags);
2541 * This routine is called to set the UART divisor registers to match
2542 * the specified baud rate for a serial port.
2544 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2546 unsigned cflag, cval, fcr;
2548 unsigned char status;
2550 unsigned long flags;
2552 if (!info->tty || !info->tty->termios)
2554 cflag = info->tty->termios->c_cflag;
2559 #define B921600 (B460800 +1)
2561 if (mxser_set_baud_method[info->port] == 0) {
2562 baud = tty_get_baud_rate(info->tty);
2563 mxser_set_baud(info, baud);
2566 /* byte size and parity */
2567 switch (cflag & CSIZE) {
2582 break; /* too keep GCC shut... */
2587 cval |= UART_LCR_PARITY;
2588 if (!(cflag & PARODD))
2589 cval |= UART_LCR_EPAR;
2591 cval |= UART_LCR_SPAR;
2593 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2594 if (info->IsMoxaMustChipFlag) {
2595 fcr = UART_FCR_ENABLE_FIFO;
2596 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2597 SET_MOXA_MUST_FIFO_VALUE(info);
2601 fcr = UART_FCR_ENABLE_FIFO;
2602 /* following add by Victor Yu. 08-30-2002 */
2603 if (info->IsMoxaMustChipFlag) {
2604 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2605 SET_MOXA_MUST_FIFO_VALUE(info);
2607 /* above add by Victor Yu. 08-30-2002 */
2608 switch (info->rx_trigger) {
2610 fcr |= UART_FCR_TRIGGER_1;
2613 fcr |= UART_FCR_TRIGGER_4;
2616 fcr |= UART_FCR_TRIGGER_8;
2619 fcr |= UART_FCR_TRIGGER_14;
2625 /* CTS flow control flag and modem status interrupts */
2626 info->IER &= ~UART_IER_MSI;
2627 info->MCR &= ~UART_MCR_AFE;
2628 if (cflag & CRTSCTS) {
2629 info->flags |= ASYNC_CTS_FLOW;
2630 info->IER |= UART_IER_MSI;
2631 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2632 info->MCR |= UART_MCR_AFE;
2633 /* status = mxser_get_msr(info->base, 0, info->port); */
2637 status = inb(baseaddr + UART_MSR);
2638 restore_flags(flags);
2640 /* mxser_check_modem_status(info, status); */
2642 /* status = mxser_get_msr(info->base, 0, info->port); */
2643 /* MX_LOCK(&info->slock); */
2644 status = inb(info->base + UART_MSR);
2645 /* MX_UNLOCK(&info->slock); */
2646 if (info->tty->hw_stopped) {
2647 if (status & UART_MSR_CTS) {
2648 info->tty->hw_stopped = 0;
2649 if ((info->type != PORT_16550A) &&
2650 (!info->IsMoxaMustChipFlag)) {
2651 info->IER |= UART_IER_THRI;
2652 outb(info->IER, info->base + UART_IER);
2654 set_bit(MXSER_EVENT_TXLOW, &info->event);
2655 schedule_work(&info->tqueue); }
2657 if (!(status & UART_MSR_CTS)) {
2658 info->tty->hw_stopped = 1;
2659 if ((info->type != PORT_16550A) &&
2660 (!info->IsMoxaMustChipFlag)) {
2661 info->IER &= ~UART_IER_THRI;
2662 outb(info->IER, info->base + UART_IER);
2668 info->flags &= ~ASYNC_CTS_FLOW;
2670 outb(info->MCR, info->base + UART_MCR);
2671 if (cflag & CLOCAL) {
2672 info->flags &= ~ASYNC_CHECK_CD;
2674 info->flags |= ASYNC_CHECK_CD;
2675 info->IER |= UART_IER_MSI;
2677 outb(info->IER, info->base + UART_IER);
2680 * Set up parity check flag
2682 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2683 if (I_INPCK(info->tty))
2684 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2685 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2686 info->read_status_mask |= UART_LSR_BI;
2688 info->ignore_status_mask = 0;
2690 if (I_IGNBRK(info->tty)) {
2691 info->ignore_status_mask |= UART_LSR_BI;
2692 info->read_status_mask |= UART_LSR_BI;
2694 * If we're ignore parity and break indicators, ignore
2695 * overruns too. (For real raw support).
2697 if (I_IGNPAR(info->tty)) {
2698 info->ignore_status_mask |=
2702 info->read_status_mask |=
2708 /* following add by Victor Yu. 09-02-2002 */
2709 if (info->IsMoxaMustChipFlag) {
2710 spin_lock_irqsave(&info->slock, flags);
2711 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2712 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2713 if (I_IXON(info->tty)) {
2714 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2716 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2718 if (I_IXOFF(info->tty)) {
2719 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2721 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2724 if ( I_IXANY(info->tty) ) {
2725 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2726 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2728 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2729 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2732 spin_unlock_irqrestore(&info->slock, flags);
2734 /* above add by Victor Yu. 09-02-2002 */
2737 outb(fcr, info->base + UART_FCR); /* set fcr */
2738 outb(cval, info->base + UART_LCR);
2744 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2749 unsigned long flags;
2751 if (!info->tty || !info->tty->termios)
2757 if (newspd > info->MaxCanSetBaudRate)
2760 info->realbaud = newspd;
2761 if (newspd == 134) {
2762 quot = (2 * info->baud_base / 269);
2763 } else if (newspd) {
2764 quot = info->baud_base / newspd;
2771 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2772 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2775 spin_lock_irqsave(&info->slock, flags);
2776 info->MCR |= UART_MCR_DTR;
2777 outb(info->MCR, info->base + UART_MCR);
2778 spin_unlock_irqrestore(&info->slock, flags);
2780 spin_lock_irqsave(&info->slock, flags);
2781 info->MCR &= ~UART_MCR_DTR;
2782 outb(info->MCR, info->base + UART_MCR);
2783 spin_unlock_irqrestore(&info->slock, flags);
2787 cval = inb(info->base + UART_LCR);
2789 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2791 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2792 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2793 outb(cval, info->base + UART_LCR); /* reset DLAB */
2800 * ------------------------------------------------------------
2801 * friends of mxser_ioctl()
2802 * ------------------------------------------------------------
2804 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2806 struct serial_struct tmp;
2810 memset(&tmp, 0, sizeof(tmp));
2811 tmp.type = info->type;
2812 tmp.line = info->port;
2813 tmp.port = info->base;
2814 tmp.irq = info->irq;
2815 tmp.flags = info->flags;
2816 tmp.baud_base = info->baud_base;
2817 tmp.close_delay = info->close_delay;
2818 tmp.closing_wait = info->closing_wait;
2819 tmp.custom_divisor = info->custom_divisor;
2821 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2826 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2828 struct serial_struct new_serial;
2832 if (!new_info || !info->base)
2834 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2837 if ((new_serial.irq != info->irq) ||
2838 (new_serial.port != info->base) ||
2839 (new_serial.custom_divisor != info->custom_divisor) ||
2840 (new_serial.baud_base != info->baud_base))
2843 flags = info->flags & ASYNC_SPD_MASK;
2845 if (!capable(CAP_SYS_ADMIN)) {
2846 if ((new_serial.baud_base != info->baud_base) ||
2847 (new_serial.close_delay != info->close_delay) ||
2848 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2850 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2851 (new_serial.flags & ASYNC_USR_MASK));
2854 * OK, past this point, all the error checking has been done.
2855 * At this point, we start making changes.....
2857 info->flags = ((info->flags & ~ASYNC_FLAGS) |
2858 (new_serial.flags & ASYNC_FLAGS));
2859 info->close_delay = new_serial.close_delay * HZ / 100;
2860 info->closing_wait = new_serial.closing_wait * HZ / 100;
2861 info->tty->low_latency =
2862 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2863 info->tty->low_latency = 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2866 /* added by casper, 3/17/2000, for mouse */
2867 info->type = new_serial.type;
2869 process_txrx_fifo(info);
2871 if (info->flags & ASYNC_INITIALIZED) {
2872 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2873 mxser_change_speed(info, NULL);
2876 retval = mxser_startup(info);
2882 * mxser_get_lsr_info - get line status register info
2884 * Purpose: Let user call ioctl() to get info when the UART physically
2885 * is emptied. On bus types like RS485, the transmitter must
2886 * release the bus after transmitting. This must be done when
2887 * the transmit shift register is empty, not be done when the
2888 * transmit holding register is empty. This functionality
2889 * allows an RS485 driver to be written in user space.
2891 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2893 unsigned char status;
2894 unsigned int result;
2895 unsigned long flags;
2897 spin_lock_irqsave(&info->slock, flags);
2898 status = inb(info->base + UART_LSR);
2899 spin_unlock_irqrestore(&info->slock, flags);
2900 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2901 return put_user(result, value);
2905 * This routine sends a break character out the serial port.
2907 static void mxser_send_break(struct mxser_struct *info, int duration)
2909 unsigned long flags;
2913 set_current_state(TASK_INTERRUPTIBLE);
2914 spin_lock_irqsave(&info->slock, flags);
2915 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
2916 info->base + UART_LCR);
2917 spin_unlock_irqrestore(&info->slock, flags);
2918 schedule_timeout(duration);
2919 spin_lock_irqsave(&info->slock, flags);
2920 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
2921 info->base + UART_LCR);
2922 spin_unlock_irqrestore(&info->slock, flags);
2925 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2927 struct mxser_struct *info = tty->driver_data;
2928 unsigned char control, status;
2929 unsigned long flags;
2932 if (tty->index == MXSER_PORTS)
2933 return -ENOIOCTLCMD;
2934 if (tty->flags & (1 << TTY_IO_ERROR))
2937 control = info->MCR;
2939 spin_lock_irqsave(&info->slock, flags);
2940 status = inb(info->base + UART_MSR);
2941 if (status & UART_MSR_ANY_DELTA)
2942 mxser_check_modem_status(info, status);
2943 spin_unlock_irqrestore(&info->slock, flags);
2944 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2945 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
2946 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
2947 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
2948 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
2949 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2952 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2954 struct mxser_struct *info = tty->driver_data;
2955 unsigned long flags;
2958 if (tty->index == MXSER_PORTS)
2959 return -ENOIOCTLCMD;
2960 if (tty->flags & (1 << TTY_IO_ERROR))
2963 spin_lock_irqsave(&info->slock, flags);
2965 if (set & TIOCM_RTS)
2966 info->MCR |= UART_MCR_RTS;
2967 if (set & TIOCM_DTR)
2968 info->MCR |= UART_MCR_DTR;
2970 if (clear & TIOCM_RTS)
2971 info->MCR &= ~UART_MCR_RTS;
2972 if (clear & TIOCM_DTR)
2973 info->MCR &= ~UART_MCR_DTR;
2975 outb(info->MCR, info->base + UART_MCR);
2976 spin_unlock_irqrestore(&info->slock, flags);
2981 static int mxser_read_register(int, unsigned short *);
2982 static int mxser_program_mode(int);
2983 static void mxser_normal_mode(int);
2985 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2988 unsigned short regs[16], irq;
2989 unsigned char scratch, scratch2;
2991 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2993 id = mxser_read_register(cap, regs);
2994 if (id == C168_ASIC_ID) {
2995 hwconf->board_type = MXSER_BOARD_C168_ISA;
2997 } else if (id == C104_ASIC_ID) {
2998 hwconf->board_type = MXSER_BOARD_C104_ISA;
3000 } else if (id == C102_ASIC_ID) {
3001 hwconf->board_type = MXSER_BOARD_C102_ISA;
3003 } else if (id == CI132_ASIC_ID) {
3004 hwconf->board_type = MXSER_BOARD_CI132;
3006 } else if (id == CI134_ASIC_ID) {
3007 hwconf->board_type = MXSER_BOARD_CI134;
3009 } else if (id == CI104J_ASIC_ID) {
3010 hwconf->board_type = MXSER_BOARD_CI104J;
3016 if (hwconf->ports == 2) {
3017 irq = regs[9] & 0xF000;
3018 irq = irq | (irq >> 4);
3019 if (irq != (regs[9] & 0xFF00))
3020 return MXSER_ERR_IRQ_CONFLIT;
3021 } else if (hwconf->ports == 4) {
3022 irq = regs[9] & 0xF000;
3023 irq = irq | (irq >> 4);
3024 irq = irq | (irq >> 8);
3026 return MXSER_ERR_IRQ_CONFLIT;
3027 } else if (hwconf->ports == 8) {
3028 irq = regs[9] & 0xF000;
3029 irq = irq | (irq >> 4);
3030 irq = irq | (irq >> 8);
3031 if ((irq != regs[9]) || (irq != regs[10]))
3032 return MXSER_ERR_IRQ_CONFLIT;
3036 return MXSER_ERR_IRQ;
3037 hwconf->irq = ((int)(irq & 0xF000) >> 12);
3038 for (i = 0; i < 8; i++)
3039 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3040 if ((regs[12] & 0x80) == 0)
3041 return MXSER_ERR_VECTOR;
3042 hwconf->vector = (int)regs[11]; /* interrupt vector */
3044 hwconf->vector_mask = 0x00FF;
3046 hwconf->vector_mask = 0x000F;
3047 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3048 if (regs[12] & bits) {
3049 hwconf->baud_base[i] = 921600;
3050 hwconf->MaxCanSetBaudRate[i] = 921600; /* add by Victor Yu. 09-04-2002 */
3052 hwconf->baud_base[i] = 115200;
3053 hwconf->MaxCanSetBaudRate[i] = 115200; /* add by Victor Yu. 09-04-2002 */
3056 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3057 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3058 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3059 outb(scratch2, cap + UART_LCR);
3060 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3061 scratch = inb(cap + UART_IIR);
3064 hwconf->uart_type = PORT_16550A;
3066 hwconf->uart_type = PORT_16450;
3071 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3072 request_region(hwconf->vector, 1, "mxser(vector)");
3073 return hwconf->ports;
3076 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3077 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3078 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3079 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3080 #define EN_CCMD 0x000 /* Chip's command register */
3081 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3082 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3083 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3084 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3085 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3086 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3087 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3088 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3089 static int mxser_read_register(int port, unsigned short *regs)
3091 int i, k, value, id;
3094 id = mxser_program_mode(port);
3097 for (i = 0; i < 14; i++) {
3098 k = (i & 0x3F) | 0x180;
3099 for (j = 0x100; j > 0; j >>= 1) {
3100 outb(CHIP_CS, port);
3102 outb(CHIP_CS | CHIP_DO, port);
3103 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3105 outb(CHIP_CS, port);
3106 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3111 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3112 outb(CHIP_CS, port);
3113 outb(CHIP_CS | CHIP_SK, port);
3114 if (inb(port) & CHIP_DI)
3120 mxser_normal_mode(port);
3124 static int mxser_program_mode(int port)
3127 /* unsigned long flags; */
3129 spin_lock(&gm_lock);
3137 /* restore_flags(flags); */
3138 spin_unlock(&gm_lock);
3140 id = inb(port + 1) & 0x1F;
3141 if ((id != C168_ASIC_ID) &&
3142 (id != C104_ASIC_ID) &&
3143 (id != C102_ASIC_ID) &&
3144 (id != CI132_ASIC_ID) &&
3145 (id != CI134_ASIC_ID) &&
3146 (id != CI104J_ASIC_ID))
3148 for (i = 0, j = 0; i < 4; i++) {
3152 } else if ((j == 1) && (n == 1)) {
3163 static void mxser_normal_mode(int port)
3167 outb(0xA5, port + 1);
3168 outb(0x80, port + 3);
3169 outb(12, port + 0); /* 9600 bps */
3171 outb(0x03, port + 3); /* 8 data bits */
3172 outb(0x13, port + 4); /* loop back mode */
3173 for (i = 0; i < 16; i++) {
3175 if ((n & 0x61) == 0x60)
3180 outb(0x00, port + 4);
3183 module_init(mxser_module_init);
3184 module_exit(mxser_module_exit);