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 ktermios normal_termios;
332 struct ktermios 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 ktermios *mxvar_termios[MXSER_PORTS + 1];
368 static struct ktermios *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 ktermios *);
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 ktermios *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->init_termios.c_ispeed = 9600;
730 mxvar_sdriver->init_termios.c_ospeed = 9600;
731 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
732 tty_set_operations(mxvar_sdriver, &mxser_ops);
733 mxvar_sdriver->ttys = mxvar_tty;
734 mxvar_sdriver->termios = mxvar_termios;
735 mxvar_sdriver->termios_locked = mxvar_termios_locked;
738 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
739 memset(&mxvar_log, 0, sizeof(struct mxser_log));
741 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
742 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
743 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
744 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
747 /* Start finding ISA boards here */
748 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
751 if (!(cap = mxserBoardCAP[b]))
754 retval = mxser_get_ISA_conf(cap, &hwconf);
757 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
758 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
761 if (retval == MXSER_ERR_IRQ)
762 printk(KERN_ERR "Invalid interrupt number, "
763 "board not configured\n");
764 else if (retval == MXSER_ERR_IRQ_CONFLIT)
765 printk(KERN_ERR "Invalid interrupt number, "
766 "board not configured\n");
767 else if (retval == MXSER_ERR_VECTOR)
768 printk(KERN_ERR "Invalid interrupt vector, "
769 "board not configured\n");
770 else if (retval == MXSER_ERR_IOADDR)
771 printk(KERN_ERR "Invalid I/O address, "
772 "board not configured\n");
777 hwconf.pciInfo.busNum = 0;
778 hwconf.pciInfo.devNum = 0;
779 hwconf.pciInfo.pdev = NULL;
781 mxser_getcfg(m, &hwconf);
783 * init mxsercfg first,
784 * or mxsercfg data is not correct on ISR.
786 /* mxser_initbrd will hook ISR. */
787 if (mxser_initbrd(m, &hwconf) < 0)
793 /* Start finding ISA boards from module arg */
794 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
797 if (!(cap = ioaddr[b]))
800 retval = mxser_get_ISA_conf(cap, &hwconf);
803 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
804 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
807 if (retval == MXSER_ERR_IRQ)
808 printk(KERN_ERR "Invalid interrupt number, "
809 "board not configured\n");
810 else if (retval == MXSER_ERR_IRQ_CONFLIT)
811 printk(KERN_ERR "Invalid interrupt number, "
812 "board not configured\n");
813 else if (retval == MXSER_ERR_VECTOR)
814 printk(KERN_ERR "Invalid interrupt vector, "
815 "board not configured\n");
816 else if (retval == MXSER_ERR_IOADDR)
817 printk(KERN_ERR "Invalid I/O address, "
818 "board not configured\n");
823 hwconf.pciInfo.busNum = 0;
824 hwconf.pciInfo.devNum = 0;
825 hwconf.pciInfo.pdev = NULL;
827 mxser_getcfg(m, &hwconf);
829 * init mxsercfg first,
830 * or mxsercfg data is not correct on ISR.
832 /* mxser_initbrd will hook ISR. */
833 if (mxser_initbrd(m, &hwconf) < 0)
839 /* start finding PCI board here */
841 n = ARRAY_SIZE(mxser_pcibrds) - 1;
845 pdev = pci_get_device(mxser_pcibrds[b].vendor,
846 mxser_pcibrds[b].device, pdev);
851 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
852 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
853 hwconf.pciInfo.pdev = pdev;
854 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
855 mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
856 busnum, devnum >> 3);
858 if (m >= MXSER_BOARDS)
860 "Too many Smartio/Industio family boards find "
861 "(maximum %d), board not configured\n",
864 if (pci_enable_device(pdev)) {
865 printk(KERN_ERR "Moxa SmartI/O PCI enable "
869 retval = mxser_get_PCI_conf(busnum, devnum,
870 (int)mxser_pcibrds[b].driver_data,
873 if (retval == MXSER_ERR_IRQ)
875 "Invalid interrupt number, "
876 "board not configured\n");
877 else if (retval == MXSER_ERR_IRQ_CONFLIT)
879 "Invalid interrupt number, "
880 "board not configured\n");
881 else if (retval == MXSER_ERR_VECTOR)
883 "Invalid interrupt vector, "
884 "board not configured\n");
885 else if (retval == MXSER_ERR_IOADDR)
887 "Invalid I/O address, "
888 "board not configured\n");
891 mxser_getcfg(m, &hwconf);
892 /* init mxsercfg first,
893 * or mxsercfg data is not correct on ISR.
895 /* mxser_initbrd will hook ISR. */
896 if (mxser_initbrd(m, &hwconf) < 0)
899 /* Keep an extra reference if we succeeded. It will
900 be returned at unload time */
906 retval = tty_register_driver(mxvar_sdriver);
908 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family"
910 put_tty_driver(mxvar_sdriver);
912 for (i = 0; i < MXSER_BOARDS; i++) {
913 if (mxsercfg[i].board_type == -1)
916 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
917 /* todo: release io, vector */
926 static void mxser_do_softint(struct work_struct *work)
928 struct mxser_struct *info =
929 container_of(work, struct mxser_struct, tqueue);
930 struct tty_struct *tty;
935 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
937 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
942 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
944 unsigned char status = 0;
946 status = inb(baseaddr + UART_MSR);
948 mxser_msr[port] &= 0x0F;
949 mxser_msr[port] |= status;
950 status = mxser_msr[port];
958 * This routine is called whenever a serial port is opened. It
959 * enables interrupts for a serial port, linking in its async structure into
960 * the IRQ chain. It also performs the serial-specific
961 * initialization for the tty structure.
963 static int mxser_open(struct tty_struct *tty, struct file *filp)
965 struct mxser_struct *info;
968 /* initialize driver_data in case something fails */
969 tty->driver_data = NULL;
972 if (line == MXSER_PORTS)
974 if (line < 0 || line > MXSER_PORTS)
976 info = mxvar_table + line;
980 tty->driver_data = info;
983 * Start up serial port
985 retval = mxser_startup(info);
989 retval = mxser_block_til_ready(tty, filp, info);
995 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
996 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
997 *tty->termios = info->normal_termios;
999 *tty->termios = info->callout_termios;
1000 mxser_change_speed(info, NULL);
1003 info->session = process_session(current);
1004 info->pgrp = process_group(current);
1007 status = mxser_get_msr(info->base, 0, info->port);
1008 mxser_check_modem_status(info, status);
1011 /* unmark here for very high baud rate (ex. 921600 bps) used */
1012 tty->low_latency = 1;
1017 * This routine is called when the serial port gets closed. First, we
1018 * wait for the last remaining data to be sent. Then, we unlink its
1019 * async structure from the interrupt chain if necessary, and we free
1020 * that IRQ if nothing is left in the chain.
1022 static void mxser_close(struct tty_struct *tty, struct file *filp)
1024 struct mxser_struct *info = tty->driver_data;
1026 unsigned long timeout;
1027 unsigned long flags;
1028 struct tty_ldisc *ld;
1030 if (tty->index == MXSER_PORTS)
1035 spin_lock_irqsave(&info->slock, flags);
1037 if (tty_hung_up_p(filp)) {
1038 spin_unlock_irqrestore(&info->slock, flags);
1041 if ((tty->count == 1) && (info->count != 1)) {
1043 * Uh, oh. tty->count is 1, which means that the tty
1044 * structure will be freed. Info->count should always
1045 * be one in these conditions. If it's greater than
1046 * one, we've got real problems, since it means the
1047 * serial port won't be shutdown.
1049 printk(KERN_ERR "mxser_close: bad serial port count; "
1050 "tty->count is 1, info->count is %d\n", info->count);
1053 if (--info->count < 0) {
1054 printk(KERN_ERR "mxser_close: bad serial port count for "
1055 "ttys%d: %d\n", info->port, info->count);
1059 spin_unlock_irqrestore(&info->slock, flags);
1062 info->flags |= ASYNC_CLOSING;
1063 spin_unlock_irqrestore(&info->slock, flags);
1065 * Save the termios structure, since this port may have
1066 * separate termios for callout and dialin.
1068 if (info->flags & ASYNC_NORMAL_ACTIVE)
1069 info->normal_termios = *tty->termios;
1071 * Now we wait for the transmit buffer to clear; and we notify
1072 * the line discipline to only process XON/XOFF characters.
1075 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1076 tty_wait_until_sent(tty, info->closing_wait);
1078 * At this point we stop accepting input. To do this, we
1079 * disable the receive line status interrupts, and tell the
1080 * interrupt driver to stop checking the data ready bit in the
1081 * line status register.
1083 info->IER &= ~UART_IER_RLSI;
1084 if (info->IsMoxaMustChipFlag)
1085 info->IER &= ~MOXA_MUST_RECV_ISR;
1087 info->read_status_mask &= ~UART_LSR_DR;
1089 if (info->flags & ASYNC_INITIALIZED) {
1090 outb(info->IER, info->base + UART_IER);
1092 * Before we drop DTR, make sure the UART transmitter
1093 * has completely drained; this is especially
1094 * important if there is a transmit FIFO!
1096 timeout = jiffies + HZ;
1097 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1098 schedule_timeout_interruptible(5);
1099 if (time_after(jiffies, timeout))
1103 mxser_shutdown(info);
1105 if (tty->driver->flush_buffer)
1106 tty->driver->flush_buffer(tty);
1108 ld = tty_ldisc_ref(tty);
1110 if (ld->flush_buffer)
1111 ld->flush_buffer(tty);
1112 tty_ldisc_deref(ld);
1118 if (info->blocked_open) {
1119 if (info->close_delay)
1120 schedule_timeout_interruptible(info->close_delay);
1121 wake_up_interruptible(&info->open_wait);
1124 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1125 wake_up_interruptible(&info->close_wait);
1129 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1132 struct mxser_struct *info = tty->driver_data;
1133 unsigned long flags;
1135 if (!info->xmit_buf)
1139 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1140 SERIAL_XMIT_SIZE - info->xmit_head));
1144 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1145 spin_lock_irqsave(&info->slock, flags);
1146 info->xmit_head = (info->xmit_head + c) &
1147 (SERIAL_XMIT_SIZE - 1);
1148 info->xmit_cnt += c;
1149 spin_unlock_irqrestore(&info->slock, flags);
1156 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1157 if (!tty->hw_stopped ||
1158 (info->type == PORT_16550A) ||
1159 (info->IsMoxaMustChipFlag)) {
1160 spin_lock_irqsave(&info->slock, flags);
1161 info->IER |= UART_IER_THRI;
1162 outb(info->IER, info->base + UART_IER);
1163 spin_unlock_irqrestore(&info->slock, flags);
1169 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1171 struct mxser_struct *info = tty->driver_data;
1172 unsigned long flags;
1174 if (!info->xmit_buf)
1177 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1180 spin_lock_irqsave(&info->slock, flags);
1181 info->xmit_buf[info->xmit_head++] = ch;
1182 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1184 spin_unlock_irqrestore(&info->slock, flags);
1185 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1186 if (!tty->hw_stopped ||
1187 (info->type == PORT_16550A) ||
1188 info->IsMoxaMustChipFlag) {
1189 spin_lock_irqsave(&info->slock, flags);
1190 info->IER |= UART_IER_THRI;
1191 outb(info->IER, info->base + UART_IER);
1192 spin_unlock_irqrestore(&info->slock, flags);
1198 static void mxser_flush_chars(struct tty_struct *tty)
1200 struct mxser_struct *info = tty->driver_data;
1201 unsigned long flags;
1203 if (info->xmit_cnt <= 0 ||
1207 (info->type != PORT_16550A) &&
1208 (!info->IsMoxaMustChipFlag)
1212 spin_lock_irqsave(&info->slock, flags);
1214 info->IER |= UART_IER_THRI;
1215 outb(info->IER, info->base + UART_IER);
1217 spin_unlock_irqrestore(&info->slock, flags);
1220 static int mxser_write_room(struct tty_struct *tty)
1222 struct mxser_struct *info = tty->driver_data;
1225 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1231 static int mxser_chars_in_buffer(struct tty_struct *tty)
1233 struct mxser_struct *info = tty->driver_data;
1234 return info->xmit_cnt;
1237 static void mxser_flush_buffer(struct tty_struct *tty)
1239 struct mxser_struct *info = tty->driver_data;
1241 unsigned long flags;
1244 spin_lock_irqsave(&info->slock, flags);
1245 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1247 /* below added by shinhay */
1248 fcr = inb(info->base + UART_FCR);
1249 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1250 info->base + UART_FCR);
1251 outb(fcr, info->base + UART_FCR);
1253 spin_unlock_irqrestore(&info->slock, flags);
1254 /* above added by shinhay */
1256 wake_up_interruptible(&tty->write_wait);
1257 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1258 (tty->ldisc.write_wakeup) (tty);
1261 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1263 struct mxser_struct *info = tty->driver_data;
1265 struct async_icount cprev, cnow; /* kernel counter temps */
1266 struct serial_icounter_struct __user *p_cuser;
1267 unsigned long templ;
1268 unsigned long flags;
1269 void __user *argp = (void __user *)arg;
1271 if (tty->index == MXSER_PORTS)
1272 return mxser_ioctl_special(cmd, argp);
1274 /* following add by Victor Yu. 01-05-2004 */
1275 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1277 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1279 unsigned char val, mask;
1282 if (cmd == MOXA_SET_OP_MODE) {
1283 if (get_user(opmode, (int __user *) argp))
1285 if (opmode != RS232_MODE &&
1286 opmode != RS485_2WIRE_MODE &&
1287 opmode != RS422_MODE &&
1288 opmode != RS485_4WIRE_MODE)
1292 val = inb(info->opmode_ioaddr);
1294 val |= (opmode << shiftbit);
1295 outb(val, info->opmode_ioaddr);
1298 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1299 opmode &= OP_MODE_MASK;
1300 if (copy_to_user(argp, &opmode, sizeof(int)))
1305 /* above add by Victor Yu. 01-05-2004 */
1307 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1308 if (tty->flags & (1 << TTY_IO_ERROR))
1312 case TCSBRK: /* SVID version: non-zero arg --> no break */
1313 retval = tty_check_change(tty);
1316 tty_wait_until_sent(tty, 0);
1318 mxser_send_break(info, HZ / 4); /* 1/4 second */
1320 case TCSBRKP: /* support for POSIX tcsendbreak() */
1321 retval = tty_check_change(tty);
1324 tty_wait_until_sent(tty, 0);
1325 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1328 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1330 if (get_user(templ, (unsigned long __user *) argp))
1333 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1336 return mxser_get_serial_info(info, argp);
1338 return mxser_set_serial_info(info, argp);
1339 case TIOCSERGETLSR: /* Get line status register */
1340 return mxser_get_lsr_info(info, argp);
1342 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1343 * - mask passed in arg for lines of interest
1344 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1345 * Caller should use TIOCGICOUNT to see which one it was
1348 DECLARE_WAITQUEUE(wait, current);
1350 spin_lock_irqsave(&info->slock, flags);
1351 cprev = info->icount; /* note the counters on entry */
1352 spin_unlock_irqrestore(&info->slock, flags);
1354 add_wait_queue(&info->delta_msr_wait, &wait);
1356 spin_lock_irqsave(&info->slock, flags);
1357 cnow = info->icount; /* atomic copy */
1358 spin_unlock_irqrestore(&info->slock, flags);
1360 set_current_state(TASK_INTERRUPTIBLE);
1361 if (((arg & TIOCM_RNG) &&
1362 (cnow.rng != cprev.rng)) ||
1363 ((arg & TIOCM_DSR) &&
1364 (cnow.dsr != cprev.dsr)) ||
1365 ((arg & TIOCM_CD) &&
1366 (cnow.dcd != cprev.dcd)) ||
1367 ((arg & TIOCM_CTS) &&
1368 (cnow.cts != cprev.cts))) {
1372 /* see if a signal did it */
1373 if (signal_pending(current)) {
1379 current->state = TASK_RUNNING;
1380 remove_wait_queue(&info->delta_msr_wait, &wait);
1385 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1386 * Return: write counters to the user passed counter struct
1387 * NB: both 1->0 and 0->1 transitions are counted except for
1388 * RI where only 0->1 is counted.
1391 spin_lock_irqsave(&info->slock, flags);
1392 cnow = info->icount;
1393 spin_unlock_irqrestore(&info->slock, flags);
1395 /* modified by casper 1/11/2000 */
1396 if (put_user(cnow.frame, &p_cuser->frame))
1398 if (put_user(cnow.brk, &p_cuser->brk))
1400 if (put_user(cnow.overrun, &p_cuser->overrun))
1402 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1404 if (put_user(cnow.parity, &p_cuser->parity))
1406 if (put_user(cnow.rx, &p_cuser->rx))
1408 if (put_user(cnow.tx, &p_cuser->tx))
1410 put_user(cnow.cts, &p_cuser->cts);
1411 put_user(cnow.dsr, &p_cuser->dsr);
1412 put_user(cnow.rng, &p_cuser->rng);
1413 put_user(cnow.dcd, &p_cuser->dcd);
1415 case MOXA_HighSpeedOn:
1416 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1417 case MOXA_SDS_RSTICOUNTER: {
1418 info->mon_data.rxcnt = 0;
1419 info->mon_data.txcnt = 0;
1422 /* (above) added by James. */
1423 case MOXA_ASPP_SETBAUD:{
1425 if (get_user(baud, (long __user *)argp))
1427 mxser_set_baud(info, baud);
1430 case MOXA_ASPP_GETBAUD:
1431 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1436 case MOXA_ASPP_OQUEUE:{
1439 len = mxser_chars_in_buffer(tty);
1441 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1443 len += (lsr ? 0 : 1);
1445 if (copy_to_user(argp, &len, sizeof(int)))
1450 case MOXA_ASPP_MON: {
1453 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1455 status = mxser_get_msr(info->base, 1, info->port, info);
1456 mxser_check_modem_status(info, status);
1458 mcr = inb(info->base + UART_MCR);
1459 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1460 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1462 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1464 if (mcr & MOXA_MUST_MCR_TX_XON)
1465 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1467 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1469 if (info->tty->hw_stopped)
1470 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1472 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1474 if (copy_to_user(argp, &info->mon_data,
1475 sizeof(struct mxser_mon)))
1481 case MOXA_ASPP_LSTATUS: {
1482 if (copy_to_user(argp, &info->err_shadow,
1483 sizeof(unsigned char)))
1486 info->err_shadow = 0;
1489 case MOXA_SET_BAUD_METHOD: {
1492 if (get_user(method, (int __user *)argp))
1494 mxser_set_baud_method[info->port] = method;
1495 if (copy_to_user(argp, &method, sizeof(int)))
1501 return -ENOIOCTLCMD;
1507 #define CMSPAR 010000000000
1510 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1512 int i, result, status;
1516 if (copy_to_user(argp, mxsercfg,
1517 sizeof(struct mxser_hwconf) * 4))
1520 case MOXA_GET_MAJOR:
1521 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1525 case MOXA_GET_CUMAJOR:
1526 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1530 case MOXA_CHKPORTENABLE:
1532 for (i = 0; i < MXSER_PORTS; i++) {
1533 if (mxvar_table[i].base)
1536 return put_user(result, (unsigned long __user *)argp);
1537 case MOXA_GETDATACOUNT:
1538 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1541 case MOXA_GETMSTATUS:
1542 for (i = 0; i < MXSER_PORTS; i++) {
1544 if (!mxvar_table[i].base) {
1545 GMStatus[i].dcd = 0;
1546 GMStatus[i].dsr = 0;
1547 GMStatus[i].cts = 0;
1551 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1552 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1554 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1556 status = inb(mxvar_table[i].base + UART_MSR);
1557 if (status & 0x80 /*UART_MSR_DCD */ )
1558 GMStatus[i].dcd = 1;
1560 GMStatus[i].dcd = 0;
1562 if (status & 0x20 /*UART_MSR_DSR */ )
1563 GMStatus[i].dsr = 1;
1565 GMStatus[i].dsr = 0;
1568 if (status & 0x10 /*UART_MSR_CTS */ )
1569 GMStatus[i].cts = 1;
1571 GMStatus[i].cts = 0;
1573 if (copy_to_user(argp, GMStatus,
1574 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1577 case MOXA_ASPP_MON_EXT: {
1581 unsigned cflag, iflag;
1583 for (i = 0; i < MXSER_PORTS; i++) {
1584 if (!mxvar_table[i].base)
1587 status = mxser_get_msr(mxvar_table[i].base, 0,
1588 i, &(mxvar_table[i]));
1590 mxser_check_modem_status(&mxvar_table[i],
1593 if (status & UART_MSR_TERI)
1594 mxvar_table[i].icount.rng++;
1595 if (status & UART_MSR_DDSR)
1596 mxvar_table[i].icount.dsr++;
1597 if (status & UART_MSR_DDCD)
1598 mxvar_table[i].icount.dcd++;
1599 if (status & UART_MSR_DCTS)
1600 mxvar_table[i].icount.cts++;
1602 mxvar_table[i].mon_data.modem_status = status;
1603 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1604 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1605 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1606 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1607 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1608 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1610 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1611 cflag = mxvar_table[i].normal_termios.c_cflag;
1612 iflag = mxvar_table[i].normal_termios.c_iflag;
1614 cflag = mxvar_table[i].tty->termios->c_cflag;
1615 iflag = mxvar_table[i].tty->termios->c_iflag;
1618 mon_data_ext.databits[i] = cflag & CSIZE;
1620 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1622 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1624 mon_data_ext.flowctrl[i] = 0x00;
1626 if (cflag & CRTSCTS)
1627 mon_data_ext.flowctrl[i] |= 0x03;
1629 if (iflag & (IXON | IXOFF))
1630 mon_data_ext.flowctrl[i] |= 0x0C;
1632 if (mxvar_table[i].type == PORT_16550A)
1633 mon_data_ext.fifo[i] = 1;
1635 mon_data_ext.fifo[i] = 0;
1639 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1640 opmode &= OP_MODE_MASK;
1642 mon_data_ext.iftype[i] = opmode;
1645 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1652 return -ENOIOCTLCMD;
1657 static void mxser_stoprx(struct tty_struct *tty)
1659 struct mxser_struct *info = tty->driver_data;
1660 /* unsigned long flags; */
1662 info->ldisc_stop_rx = 1;
1664 /* MX_LOCK(&info->slock); */
1665 /* following add by Victor Yu. 09-02-2002 */
1666 if (info->IsMoxaMustChipFlag) {
1667 info->IER &= ~MOXA_MUST_RECV_ISR;
1668 outb(info->IER, info->base + UART_IER);
1670 /* above add by Victor Yu. 09-02-2002 */
1671 info->x_char = STOP_CHAR(tty);
1672 /* mask by Victor Yu. 09-02-2002 */
1673 /* outb(info->IER, 0); */
1674 outb(0, info->base + UART_IER);
1675 info->IER |= UART_IER_THRI;
1676 /* force Tx interrupt */
1677 outb(info->IER, info->base + UART_IER);
1678 } /* add by Victor Yu. 09-02-2002 */
1679 /* MX_UNLOCK(&info->slock); */
1682 if (info->tty->termios->c_cflag & CRTSCTS) {
1683 /* MX_LOCK(&info->slock); */
1684 info->MCR &= ~UART_MCR_RTS;
1685 outb(info->MCR, info->base + UART_MCR);
1686 /* MX_UNLOCK(&info->slock); */
1690 static void mxser_startrx(struct tty_struct *tty)
1692 struct mxser_struct *info = tty->driver_data;
1693 /* unsigned long flags; */
1695 info->ldisc_stop_rx = 0;
1700 /* MX_LOCK(&info->slock); */
1702 /* following add by Victor Yu. 09-02-2002 */
1703 if (info->IsMoxaMustChipFlag) {
1704 info->IER |= MOXA_MUST_RECV_ISR;
1705 outb(info->IER, info->base + UART_IER);
1707 /* above add by Victor Yu. 09-02-2002 */
1709 info->x_char = START_CHAR(tty);
1710 /* mask by Victor Yu. 09-02-2002 */
1711 /* outb(info->IER, 0); */
1712 /* add by Victor Yu. 09-02-2002 */
1713 outb(0, info->base + UART_IER);
1714 /* force Tx interrupt */
1715 info->IER |= UART_IER_THRI;
1716 outb(info->IER, info->base + UART_IER);
1717 } /* add by Victor Yu. 09-02-2002 */
1718 /* MX_UNLOCK(&info->slock); */
1722 if (info->tty->termios->c_cflag & CRTSCTS) {
1723 /* MX_LOCK(&info->slock); */
1724 info->MCR |= UART_MCR_RTS;
1725 outb(info->MCR, info->base + UART_MCR);
1726 /* MX_UNLOCK(&info->slock); */
1731 * This routine is called by the upper-layer tty layer to signal that
1732 * incoming characters should be throttled.
1734 static void mxser_throttle(struct tty_struct *tty)
1736 /* struct mxser_struct *info = tty->driver_data; */
1737 /* unsigned long flags; */
1739 /* MX_LOCK(&info->slock); */
1741 /* MX_UNLOCK(&info->slock); */
1744 static void mxser_unthrottle(struct tty_struct *tty)
1746 /* struct mxser_struct *info = tty->driver_data; */
1747 /* unsigned long flags; */
1749 /* MX_LOCK(&info->slock); */
1751 /* MX_UNLOCK(&info->slock); */
1754 static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1756 struct mxser_struct *info = tty->driver_data;
1757 unsigned long flags;
1759 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1760 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1762 mxser_change_speed(info, old_termios);
1764 if ((old_termios->c_cflag & CRTSCTS) &&
1765 !(tty->termios->c_cflag & CRTSCTS)) {
1766 tty->hw_stopped = 0;
1771 /* Handle sw stopped */
1772 if ((old_termios->c_iflag & IXON) &&
1773 !(tty->termios->c_iflag & IXON)) {
1776 /* following add by Victor Yu. 09-02-2002 */
1777 if (info->IsMoxaMustChipFlag) {
1778 spin_lock_irqsave(&info->slock, flags);
1779 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1780 spin_unlock_irqrestore(&info->slock, flags);
1782 /* above add by Victor Yu. 09-02-2002 */
1789 * mxser_stop() and mxser_start()
1791 * This routines are called before setting or resetting tty->stopped.
1792 * They enable or disable transmitter interrupts, as necessary.
1794 static void mxser_stop(struct tty_struct *tty)
1796 struct mxser_struct *info = tty->driver_data;
1797 unsigned long flags;
1799 spin_lock_irqsave(&info->slock, flags);
1800 if (info->IER & UART_IER_THRI) {
1801 info->IER &= ~UART_IER_THRI;
1802 outb(info->IER, info->base + UART_IER);
1804 spin_unlock_irqrestore(&info->slock, flags);
1807 static void mxser_start(struct tty_struct *tty)
1809 struct mxser_struct *info = tty->driver_data;
1810 unsigned long flags;
1812 spin_lock_irqsave(&info->slock, flags);
1813 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1814 info->IER |= UART_IER_THRI;
1815 outb(info->IER, info->base + UART_IER);
1817 spin_unlock_irqrestore(&info->slock, flags);
1821 * mxser_wait_until_sent() --- wait until the transmitter is empty
1823 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1825 struct mxser_struct *info = tty->driver_data;
1826 unsigned long orig_jiffies, char_time;
1829 if (info->type == PORT_UNKNOWN)
1832 if (info->xmit_fifo_size == 0)
1833 return; /* Just in case.... */
1835 orig_jiffies = jiffies;
1837 * Set the check interval to be 1/5 of the estimated time to
1838 * send a single character, and make it at least 1. The check
1839 * interval should also be less than the timeout.
1841 * Note: we have to use pretty tight timings here to satisfy
1844 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1845 char_time = char_time / 5;
1848 if (timeout && timeout < char_time)
1849 char_time = timeout;
1851 * If the transmitter hasn't cleared in twice the approximate
1852 * amount of time to send the entire FIFO, it probably won't
1853 * ever clear. This assumes the UART isn't doing flow
1854 * control, which is currently the case. Hence, if it ever
1855 * takes longer than info->timeout, this is probably due to a
1856 * UART bug of some kind. So, we clamp the timeout parameter at
1859 if (!timeout || timeout > 2 * info->timeout)
1860 timeout = 2 * info->timeout;
1861 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1862 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1863 timeout, char_time);
1864 printk("jiff=%lu...", jiffies);
1866 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1867 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1868 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1870 schedule_timeout_interruptible(char_time);
1871 if (signal_pending(current))
1873 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1876 set_current_state(TASK_RUNNING);
1878 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1879 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1885 * This routine is called by tty_hangup() when a hangup is signaled.
1887 void mxser_hangup(struct tty_struct *tty)
1889 struct mxser_struct *info = tty->driver_data;
1891 mxser_flush_buffer(tty);
1892 mxser_shutdown(info);
1895 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1897 wake_up_interruptible(&info->open_wait);
1901 /* added by James 03-12-2004. */
1903 * mxser_rs_break() --- routine which turns the break handling on or off
1905 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1907 struct mxser_struct *info = tty->driver_data;
1908 unsigned long flags;
1910 spin_lock_irqsave(&info->slock, flags);
1911 if (break_state == -1)
1912 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
1913 info->base + UART_LCR);
1915 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
1916 info->base + UART_LCR);
1917 spin_unlock_irqrestore(&info->slock, flags);
1920 /* (above) added by James. */
1924 * This is the serial driver's generic interrupt routine
1926 static irqreturn_t mxser_interrupt(int irq, void *dev_id)
1929 struct mxser_struct *info;
1930 struct mxser_struct *port;
1931 int max, irqbits, bits, msr;
1932 int pass_counter = 0;
1933 int handled = IRQ_NONE;
1936 /* spin_lock(&gm_lock); */
1938 for (i = 0; i < MXSER_BOARDS; i++) {
1939 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1945 if (i == MXSER_BOARDS)
1949 max = mxser_numports[mxsercfg[i].board_type - 1];
1951 irqbits = inb(port->vector) & port->vectormask;
1952 if (irqbits == port->vectormask)
1955 handled = IRQ_HANDLED;
1956 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1957 if (irqbits == port->vectormask)
1963 /* following add by Victor Yu. 09-13-2002 */
1964 iir = inb(info->base + UART_IIR);
1965 if (iir & UART_IIR_NO_INT)
1967 iir &= MOXA_MUST_IIR_MASK;
1969 status = inb(info->base + UART_LSR);
1970 outb(0x27, info->base + UART_FCR);
1971 inb(info->base + UART_MSR);
1974 /* above add by Victor Yu. 09-13-2002 */
1976 if (info->tty->flip.count < TTY_FLIPBUF_SIZE / 4) {
1977 info->IER |= MOXA_MUST_RECV_ISR;
1978 outb(info->IER, info->base + UART_IER);
1983 /* mask by Victor Yu. 09-13-2002
1985 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1988 /* mask by Victor Yu. 09-02-2002
1989 status = inb(info->base + UART_LSR) & info->read_status_mask;
1992 /* following add by Victor Yu. 09-02-2002 */
1993 status = inb(info->base + UART_LSR);
1995 if (status & UART_LSR_PE)
1996 info->err_shadow |= NPPI_NOTIFY_PARITY;
1997 if (status & UART_LSR_FE)
1998 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1999 if (status & UART_LSR_OE)
2000 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
2001 if (status & UART_LSR_BI)
2002 info->err_shadow |= NPPI_NOTIFY_BREAK;
2004 if (info->IsMoxaMustChipFlag) {
2006 if ( (status & 0x02) && !(status & 0x01) ) {
2007 outb(info->base+UART_FCR, 0x23);
2011 if (iir == MOXA_MUST_IIR_GDA ||
2012 iir == MOXA_MUST_IIR_RDA ||
2013 iir == MOXA_MUST_IIR_RTO ||
2014 iir == MOXA_MUST_IIR_LSR)
2015 mxser_receive_chars(info, &status);
2018 /* above add by Victor Yu. 09-02-2002 */
2020 status &= info->read_status_mask;
2021 if (status & UART_LSR_DR)
2022 mxser_receive_chars(info, &status);
2024 msr = inb(info->base + UART_MSR);
2025 if (msr & UART_MSR_ANY_DELTA) {
2026 mxser_check_modem_status(info, msr);
2028 /* following add by Victor Yu. 09-13-2002 */
2029 if (info->IsMoxaMustChipFlag) {
2030 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
2031 mxser_transmit_chars(info);
2034 /* above add by Victor Yu. 09-13-2002 */
2036 if (status & UART_LSR_THRE) {
2037 /* 8-2-99 by William
2038 if ( info->x_char || (info->xmit_cnt > 0) )
2040 mxser_transmit_chars(info);
2044 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
2045 break; /* Prevent infinite loops */
2050 /* spin_unlock(&gm_lock); */
2054 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2056 struct tty_struct *tty = info->tty;
2057 unsigned char ch, gdl;
2062 unsigned long flags;
2064 spin_lock_irqsave(&info->slock, flags);
2066 recv_room = tty->receive_room;
2067 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2068 /* mxser_throttle(tty); */
2073 /* following add by Victor Yu. 09-02-2002 */
2074 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2076 if (*status & UART_LSR_SPECIAL) {
2079 /* following add by Victor Yu. 02-11-2004 */
2080 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID &&
2081 (*status & MOXA_MUST_LSR_RERR))
2083 /* above add by Victor Yu. 02-14-2004 */
2084 if (*status & MOXA_MUST_LSR_RERR)
2087 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2089 /* add by Victor Yu. 02-11-2004 */
2090 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID)
2091 gdl &= MOXA_MUST_GDL_MASK;
2092 if (gdl >= recv_room) {
2093 if (!info->ldisc_stop_rx) {
2094 /* mxser_throttle(tty); */
2100 ch = inb(info->base + UART_RX);
2101 tty_insert_flip_char(tty, ch, 0);
2104 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2113 /* above add by Victor Yu. 09-02-2002 */
2119 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2126 ch = inb(info->base + UART_RX);
2127 /* following add by Victor Yu. 09-02-2002 */
2128 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2129 outb(0x23, info->base + UART_FCR);
2130 *status &= info->read_status_mask;
2131 /* above add by Victor Yu. 09-02-2002 */
2132 if (*status & info->ignore_status_mask) {
2133 if (++ignored > 100)
2137 if (*status & UART_LSR_SPECIAL) {
2138 if (*status & UART_LSR_BI) {
2140 /* added by casper 1/11/2000 */
2143 if (info->flags & ASYNC_SAK)
2145 } else if (*status & UART_LSR_PE) {
2147 /* added by casper 1/11/2000 */
2148 info->icount.parity++;
2150 } else if (*status & UART_LSR_FE) {
2152 /* added by casper 1/11/2000 */
2153 info->icount.frame++;
2155 } else if (*status & UART_LSR_OE) {
2157 /* added by casper 1/11/2000 */
2158 info->icount.overrun++;
2162 tty_insert_flip_char(tty, ch, flag);
2164 if (cnt >= recv_room) {
2165 if (!info->ldisc_stop_rx) {
2166 /* mxser_throttle(tty); */
2174 /* following add by Victor Yu. 09-02-2002 */
2175 if (info->IsMoxaMustChipFlag)
2177 /* above add by Victor Yu. 09-02-2002 */
2179 /* mask by Victor Yu. 09-02-2002
2180 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2182 /* following add by Victor Yu. 09-02-2002 */
2183 *status = inb(info->base + UART_LSR);
2184 /* above add by Victor Yu. 09-02-2002 */
2185 } while (*status & UART_LSR_DR);
2187 end_intr: /* add by Victor Yu. 09-02-2002 */
2188 mxvar_log.rxcnt[info->port] += cnt;
2189 info->mon_data.rxcnt += cnt;
2190 info->mon_data.up_rxcnt += cnt;
2191 spin_unlock_irqrestore(&info->slock, flags);
2193 tty_flip_buffer_push(tty);
2196 static void mxser_transmit_chars(struct mxser_struct *info)
2199 unsigned long flags;
2201 spin_lock_irqsave(&info->slock, flags);
2204 outb(info->x_char, info->base + UART_TX);
2206 mxvar_log.txcnt[info->port]++;
2207 info->mon_data.txcnt++;
2208 info->mon_data.up_txcnt++;
2210 /* added by casper 1/11/2000 */
2213 spin_unlock_irqrestore(&info->slock, flags);
2217 if (info->xmit_buf == 0) {
2218 spin_unlock_irqrestore(&info->slock, flags);
2222 if ((info->xmit_cnt <= 0) || info->tty->stopped ||
2223 (info->tty->hw_stopped &&
2224 (info->type != PORT_16550A) &&
2225 (!info->IsMoxaMustChipFlag))) {
2226 info->IER &= ~UART_IER_THRI;
2227 outb(info->IER, info->base + UART_IER);
2228 spin_unlock_irqrestore(&info->slock, flags);
2232 cnt = info->xmit_cnt;
2233 count = info->xmit_fifo_size;
2235 outb(info->xmit_buf[info->xmit_tail++],
2236 info->base + UART_TX);
2237 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2238 if (--info->xmit_cnt <= 0)
2240 } while (--count > 0);
2241 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2243 /* added by James 03-12-2004. */
2244 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2245 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2246 /* (above) added by James. */
2248 /* added by casper 1/11/2000 */
2249 info->icount.tx += (cnt - info->xmit_cnt);
2252 if (info->xmit_cnt < WAKEUP_CHARS) {
2253 set_bit(MXSER_EVENT_TXLOW, &info->event);
2254 schedule_work(&info->tqueue);
2256 if (info->xmit_cnt <= 0) {
2257 info->IER &= ~UART_IER_THRI;
2258 outb(info->IER, info->base + UART_IER);
2260 spin_unlock_irqrestore(&info->slock, flags);
2263 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2265 /* update input line counters */
2266 if (status & UART_MSR_TERI)
2268 if (status & UART_MSR_DDSR)
2270 if (status & UART_MSR_DDCD)
2272 if (status & UART_MSR_DCTS)
2274 info->mon_data.modem_status = status;
2275 wake_up_interruptible(&info->delta_msr_wait);
2277 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2278 if (status & UART_MSR_DCD)
2279 wake_up_interruptible(&info->open_wait);
2280 schedule_work(&info->tqueue);
2283 if (info->flags & ASYNC_CTS_FLOW) {
2284 if (info->tty->hw_stopped) {
2285 if (status & UART_MSR_CTS) {
2286 info->tty->hw_stopped = 0;
2288 if ((info->type != PORT_16550A) &&
2289 (!info->IsMoxaMustChipFlag)) {
2290 info->IER |= UART_IER_THRI;
2291 outb(info->IER, info->base + UART_IER);
2293 set_bit(MXSER_EVENT_TXLOW, &info->event);
2294 schedule_work(&info->tqueue); }
2296 if (!(status & UART_MSR_CTS)) {
2297 info->tty->hw_stopped = 1;
2298 if ((info->type != PORT_16550A) &&
2299 (!info->IsMoxaMustChipFlag)) {
2300 info->IER &= ~UART_IER_THRI;
2301 outb(info->IER, info->base + UART_IER);
2308 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2310 DECLARE_WAITQUEUE(wait, current);
2313 unsigned long flags;
2316 * If non-blocking mode is set, or the port is not enabled,
2317 * then make the check up front and then exit.
2319 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2320 info->flags |= ASYNC_NORMAL_ACTIVE;
2324 if (tty->termios->c_cflag & CLOCAL)
2328 * Block waiting for the carrier detect and the line to become
2329 * free (i.e., not in use by the callout). While we are in
2330 * this loop, info->count is dropped by one, so that
2331 * mxser_close() knows when to free things. We restore it upon
2332 * exit, either normal or abnormal.
2335 add_wait_queue(&info->open_wait, &wait);
2337 spin_lock_irqsave(&info->slock, flags);
2338 if (!tty_hung_up_p(filp))
2340 spin_unlock_irqrestore(&info->slock, flags);
2341 info->blocked_open++;
2343 spin_lock_irqsave(&info->slock, flags);
2344 outb(inb(info->base + UART_MCR) |
2345 UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2346 spin_unlock_irqrestore(&info->slock, flags);
2347 set_current_state(TASK_INTERRUPTIBLE);
2348 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2349 if (info->flags & ASYNC_HUP_NOTIFY)
2352 retval = -ERESTARTSYS;
2355 if (!(info->flags & ASYNC_CLOSING) &&
2357 (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2359 if (signal_pending(current)) {
2360 retval = -ERESTARTSYS;
2365 set_current_state(TASK_RUNNING);
2366 remove_wait_queue(&info->open_wait, &wait);
2367 if (!tty_hung_up_p(filp))
2369 info->blocked_open--;
2372 info->flags |= ASYNC_NORMAL_ACTIVE;
2376 static int mxser_startup(struct mxser_struct *info)
2379 unsigned long flags;
2381 page = __get_free_page(GFP_KERNEL);
2385 spin_lock_irqsave(&info->slock, flags);
2387 if (info->flags & ASYNC_INITIALIZED) {
2389 spin_unlock_irqrestore(&info->slock, flags);
2393 if (!info->base || !info->type) {
2395 set_bit(TTY_IO_ERROR, &info->tty->flags);
2397 spin_unlock_irqrestore(&info->slock, flags);
2403 info->xmit_buf = (unsigned char *) page;
2406 * Clear the FIFO buffers and disable them
2407 * (they will be reenabled in mxser_change_speed())
2409 if (info->IsMoxaMustChipFlag)
2410 outb((UART_FCR_CLEAR_RCVR |
2411 UART_FCR_CLEAR_XMIT |
2412 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2414 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2415 info->base + UART_FCR);
2418 * At this point there's no way the LSR could still be 0xFF;
2419 * if it is, then bail out, because there's likely no UART
2422 if (inb(info->base + UART_LSR) == 0xff) {
2423 spin_unlock_irqrestore(&info->slock, flags);
2424 if (capable(CAP_SYS_ADMIN)) {
2426 set_bit(TTY_IO_ERROR, &info->tty->flags);
2433 * Clear the interrupt registers.
2435 (void) inb(info->base + UART_LSR);
2436 (void) inb(info->base + UART_RX);
2437 (void) inb(info->base + UART_IIR);
2438 (void) inb(info->base + UART_MSR);
2441 * Now, initialize the UART
2443 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2444 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2445 outb(info->MCR, info->base + UART_MCR);
2448 * Finally, enable interrupts
2450 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2451 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2453 /* following add by Victor Yu. 08-30-2002 */
2454 if (info->IsMoxaMustChipFlag)
2455 info->IER |= MOXA_MUST_IER_EGDAI;
2456 /* above add by Victor Yu. 08-30-2002 */
2457 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2460 * And clear the interrupt registers again for luck.
2462 (void) inb(info->base + UART_LSR);
2463 (void) inb(info->base + UART_RX);
2464 (void) inb(info->base + UART_IIR);
2465 (void) inb(info->base + UART_MSR);
2468 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2469 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2472 * and set the speed of the serial port
2474 spin_unlock_irqrestore(&info->slock, flags);
2475 mxser_change_speed(info, NULL);
2477 info->flags |= ASYNC_INITIALIZED;
2482 * This routine will shutdown a serial port; interrupts maybe disabled, and
2483 * DTR is dropped if the hangup on close termio flag is on.
2485 static void mxser_shutdown(struct mxser_struct *info)
2487 unsigned long flags;
2489 if (!(info->flags & ASYNC_INITIALIZED))
2492 spin_lock_irqsave(&info->slock, flags);
2495 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2496 * here so the queue might never be waken up
2498 wake_up_interruptible(&info->delta_msr_wait);
2501 * Free the IRQ, if necessary
2503 if (info->xmit_buf) {
2504 free_page((unsigned long) info->xmit_buf);
2505 info->xmit_buf = NULL;
2509 outb(0x00, info->base + UART_IER);
2511 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2512 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2513 outb(info->MCR, info->base + UART_MCR);
2515 /* clear Rx/Tx FIFO's */
2516 /* following add by Victor Yu. 08-30-2002 */
2517 if (info->IsMoxaMustChipFlag)
2518 outb((UART_FCR_CLEAR_RCVR |
2519 UART_FCR_CLEAR_XMIT |
2520 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2522 /* above add by Victor Yu. 08-30-2002 */
2523 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2524 info->base + UART_FCR);
2526 /* read data port to reset things */
2527 (void) inb(info->base + UART_RX);
2530 set_bit(TTY_IO_ERROR, &info->tty->flags);
2532 info->flags &= ~ASYNC_INITIALIZED;
2534 /* following add by Victor Yu. 09-23-2002 */
2535 if (info->IsMoxaMustChipFlag)
2536 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2537 /* above add by Victor Yu. 09-23-2002 */
2539 spin_unlock_irqrestore(&info->slock, flags);
2543 * This routine is called to set the UART divisor registers to match
2544 * the specified baud rate for a serial port.
2546 static int mxser_change_speed(struct mxser_struct *info, struct ktermios *old_termios)
2548 unsigned cflag, cval, fcr;
2550 unsigned char status;
2552 unsigned long flags;
2554 if (!info->tty || !info->tty->termios)
2556 cflag = info->tty->termios->c_cflag;
2561 #define B921600 (B460800 +1)
2563 if (mxser_set_baud_method[info->port] == 0) {
2564 baud = tty_get_baud_rate(info->tty);
2565 mxser_set_baud(info, baud);
2568 /* byte size and parity */
2569 switch (cflag & CSIZE) {
2584 break; /* too keep GCC shut... */
2589 cval |= UART_LCR_PARITY;
2590 if (!(cflag & PARODD))
2591 cval |= UART_LCR_EPAR;
2593 cval |= UART_LCR_SPAR;
2595 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2596 if (info->IsMoxaMustChipFlag) {
2597 fcr = UART_FCR_ENABLE_FIFO;
2598 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2599 SET_MOXA_MUST_FIFO_VALUE(info);
2603 fcr = UART_FCR_ENABLE_FIFO;
2604 /* following add by Victor Yu. 08-30-2002 */
2605 if (info->IsMoxaMustChipFlag) {
2606 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2607 SET_MOXA_MUST_FIFO_VALUE(info);
2609 /* above add by Victor Yu. 08-30-2002 */
2610 switch (info->rx_trigger) {
2612 fcr |= UART_FCR_TRIGGER_1;
2615 fcr |= UART_FCR_TRIGGER_4;
2618 fcr |= UART_FCR_TRIGGER_8;
2621 fcr |= UART_FCR_TRIGGER_14;
2627 /* CTS flow control flag and modem status interrupts */
2628 info->IER &= ~UART_IER_MSI;
2629 info->MCR &= ~UART_MCR_AFE;
2630 if (cflag & CRTSCTS) {
2631 info->flags |= ASYNC_CTS_FLOW;
2632 info->IER |= UART_IER_MSI;
2633 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2634 info->MCR |= UART_MCR_AFE;
2635 /* status = mxser_get_msr(info->base, 0, info->port); */
2639 status = inb(baseaddr + UART_MSR);
2640 restore_flags(flags);
2642 /* mxser_check_modem_status(info, status); */
2644 /* status = mxser_get_msr(info->base, 0, info->port); */
2645 /* MX_LOCK(&info->slock); */
2646 status = inb(info->base + UART_MSR);
2647 /* MX_UNLOCK(&info->slock); */
2648 if (info->tty->hw_stopped) {
2649 if (status & UART_MSR_CTS) {
2650 info->tty->hw_stopped = 0;
2651 if ((info->type != PORT_16550A) &&
2652 (!info->IsMoxaMustChipFlag)) {
2653 info->IER |= UART_IER_THRI;
2654 outb(info->IER, info->base + UART_IER);
2656 set_bit(MXSER_EVENT_TXLOW, &info->event);
2657 schedule_work(&info->tqueue); }
2659 if (!(status & UART_MSR_CTS)) {
2660 info->tty->hw_stopped = 1;
2661 if ((info->type != PORT_16550A) &&
2662 (!info->IsMoxaMustChipFlag)) {
2663 info->IER &= ~UART_IER_THRI;
2664 outb(info->IER, info->base + UART_IER);
2670 info->flags &= ~ASYNC_CTS_FLOW;
2672 outb(info->MCR, info->base + UART_MCR);
2673 if (cflag & CLOCAL) {
2674 info->flags &= ~ASYNC_CHECK_CD;
2676 info->flags |= ASYNC_CHECK_CD;
2677 info->IER |= UART_IER_MSI;
2679 outb(info->IER, info->base + UART_IER);
2682 * Set up parity check flag
2684 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2685 if (I_INPCK(info->tty))
2686 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2687 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2688 info->read_status_mask |= UART_LSR_BI;
2690 info->ignore_status_mask = 0;
2692 if (I_IGNBRK(info->tty)) {
2693 info->ignore_status_mask |= UART_LSR_BI;
2694 info->read_status_mask |= UART_LSR_BI;
2696 * If we're ignore parity and break indicators, ignore
2697 * overruns too. (For real raw support).
2699 if (I_IGNPAR(info->tty)) {
2700 info->ignore_status_mask |=
2704 info->read_status_mask |=
2710 /* following add by Victor Yu. 09-02-2002 */
2711 if (info->IsMoxaMustChipFlag) {
2712 spin_lock_irqsave(&info->slock, flags);
2713 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2714 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2715 if (I_IXON(info->tty)) {
2716 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2718 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2720 if (I_IXOFF(info->tty)) {
2721 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2723 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2726 if ( I_IXANY(info->tty) ) {
2727 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2728 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2730 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2731 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2734 spin_unlock_irqrestore(&info->slock, flags);
2736 /* above add by Victor Yu. 09-02-2002 */
2739 outb(fcr, info->base + UART_FCR); /* set fcr */
2740 outb(cval, info->base + UART_LCR);
2746 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2751 unsigned long flags;
2753 if (!info->tty || !info->tty->termios)
2759 if (newspd > info->MaxCanSetBaudRate)
2762 info->realbaud = newspd;
2763 if (newspd == 134) {
2764 quot = (2 * info->baud_base / 269);
2765 } else if (newspd) {
2766 quot = info->baud_base / newspd;
2773 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2774 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2777 spin_lock_irqsave(&info->slock, flags);
2778 info->MCR |= UART_MCR_DTR;
2779 outb(info->MCR, info->base + UART_MCR);
2780 spin_unlock_irqrestore(&info->slock, flags);
2782 spin_lock_irqsave(&info->slock, flags);
2783 info->MCR &= ~UART_MCR_DTR;
2784 outb(info->MCR, info->base + UART_MCR);
2785 spin_unlock_irqrestore(&info->slock, flags);
2789 cval = inb(info->base + UART_LCR);
2791 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2793 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2794 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2795 outb(cval, info->base + UART_LCR); /* reset DLAB */
2802 * ------------------------------------------------------------
2803 * friends of mxser_ioctl()
2804 * ------------------------------------------------------------
2806 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2808 struct serial_struct tmp;
2812 memset(&tmp, 0, sizeof(tmp));
2813 tmp.type = info->type;
2814 tmp.line = info->port;
2815 tmp.port = info->base;
2816 tmp.irq = info->irq;
2817 tmp.flags = info->flags;
2818 tmp.baud_base = info->baud_base;
2819 tmp.close_delay = info->close_delay;
2820 tmp.closing_wait = info->closing_wait;
2821 tmp.custom_divisor = info->custom_divisor;
2823 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2828 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2830 struct serial_struct new_serial;
2834 if (!new_info || !info->base)
2836 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2839 if ((new_serial.irq != info->irq) ||
2840 (new_serial.port != info->base) ||
2841 (new_serial.custom_divisor != info->custom_divisor) ||
2842 (new_serial.baud_base != info->baud_base))
2845 flags = info->flags & ASYNC_SPD_MASK;
2847 if (!capable(CAP_SYS_ADMIN)) {
2848 if ((new_serial.baud_base != info->baud_base) ||
2849 (new_serial.close_delay != info->close_delay) ||
2850 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2852 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2853 (new_serial.flags & ASYNC_USR_MASK));
2856 * OK, past this point, all the error checking has been done.
2857 * At this point, we start making changes.....
2859 info->flags = ((info->flags & ~ASYNC_FLAGS) |
2860 (new_serial.flags & ASYNC_FLAGS));
2861 info->close_delay = new_serial.close_delay * HZ / 100;
2862 info->closing_wait = new_serial.closing_wait * HZ / 100;
2863 info->tty->low_latency =
2864 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2865 info->tty->low_latency = 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2868 /* added by casper, 3/17/2000, for mouse */
2869 info->type = new_serial.type;
2871 process_txrx_fifo(info);
2873 if (info->flags & ASYNC_INITIALIZED) {
2874 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2875 mxser_change_speed(info, NULL);
2878 retval = mxser_startup(info);
2884 * mxser_get_lsr_info - get line status register info
2886 * Purpose: Let user call ioctl() to get info when the UART physically
2887 * is emptied. On bus types like RS485, the transmitter must
2888 * release the bus after transmitting. This must be done when
2889 * the transmit shift register is empty, not be done when the
2890 * transmit holding register is empty. This functionality
2891 * allows an RS485 driver to be written in user space.
2893 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2895 unsigned char status;
2896 unsigned int result;
2897 unsigned long flags;
2899 spin_lock_irqsave(&info->slock, flags);
2900 status = inb(info->base + UART_LSR);
2901 spin_unlock_irqrestore(&info->slock, flags);
2902 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2903 return put_user(result, value);
2907 * This routine sends a break character out the serial port.
2909 static void mxser_send_break(struct mxser_struct *info, int duration)
2911 unsigned long flags;
2915 set_current_state(TASK_INTERRUPTIBLE);
2916 spin_lock_irqsave(&info->slock, flags);
2917 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
2918 info->base + UART_LCR);
2919 spin_unlock_irqrestore(&info->slock, flags);
2920 schedule_timeout(duration);
2921 spin_lock_irqsave(&info->slock, flags);
2922 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
2923 info->base + UART_LCR);
2924 spin_unlock_irqrestore(&info->slock, flags);
2927 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2929 struct mxser_struct *info = tty->driver_data;
2930 unsigned char control, status;
2931 unsigned long flags;
2934 if (tty->index == MXSER_PORTS)
2935 return -ENOIOCTLCMD;
2936 if (tty->flags & (1 << TTY_IO_ERROR))
2939 control = info->MCR;
2941 spin_lock_irqsave(&info->slock, flags);
2942 status = inb(info->base + UART_MSR);
2943 if (status & UART_MSR_ANY_DELTA)
2944 mxser_check_modem_status(info, status);
2945 spin_unlock_irqrestore(&info->slock, flags);
2946 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2947 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
2948 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
2949 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
2950 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
2951 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2954 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2956 struct mxser_struct *info = tty->driver_data;
2957 unsigned long flags;
2960 if (tty->index == MXSER_PORTS)
2961 return -ENOIOCTLCMD;
2962 if (tty->flags & (1 << TTY_IO_ERROR))
2965 spin_lock_irqsave(&info->slock, flags);
2967 if (set & TIOCM_RTS)
2968 info->MCR |= UART_MCR_RTS;
2969 if (set & TIOCM_DTR)
2970 info->MCR |= UART_MCR_DTR;
2972 if (clear & TIOCM_RTS)
2973 info->MCR &= ~UART_MCR_RTS;
2974 if (clear & TIOCM_DTR)
2975 info->MCR &= ~UART_MCR_DTR;
2977 outb(info->MCR, info->base + UART_MCR);
2978 spin_unlock_irqrestore(&info->slock, flags);
2983 static int mxser_read_register(int, unsigned short *);
2984 static int mxser_program_mode(int);
2985 static void mxser_normal_mode(int);
2987 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2990 unsigned short regs[16], irq;
2991 unsigned char scratch, scratch2;
2993 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2995 id = mxser_read_register(cap, regs);
2996 if (id == C168_ASIC_ID) {
2997 hwconf->board_type = MXSER_BOARD_C168_ISA;
2999 } else if (id == C104_ASIC_ID) {
3000 hwconf->board_type = MXSER_BOARD_C104_ISA;
3002 } else if (id == C102_ASIC_ID) {
3003 hwconf->board_type = MXSER_BOARD_C102_ISA;
3005 } else if (id == CI132_ASIC_ID) {
3006 hwconf->board_type = MXSER_BOARD_CI132;
3008 } else if (id == CI134_ASIC_ID) {
3009 hwconf->board_type = MXSER_BOARD_CI134;
3011 } else if (id == CI104J_ASIC_ID) {
3012 hwconf->board_type = MXSER_BOARD_CI104J;
3018 if (hwconf->ports == 2) {
3019 irq = regs[9] & 0xF000;
3020 irq = irq | (irq >> 4);
3021 if (irq != (regs[9] & 0xFF00))
3022 return MXSER_ERR_IRQ_CONFLIT;
3023 } else if (hwconf->ports == 4) {
3024 irq = regs[9] & 0xF000;
3025 irq = irq | (irq >> 4);
3026 irq = irq | (irq >> 8);
3028 return MXSER_ERR_IRQ_CONFLIT;
3029 } else if (hwconf->ports == 8) {
3030 irq = regs[9] & 0xF000;
3031 irq = irq | (irq >> 4);
3032 irq = irq | (irq >> 8);
3033 if ((irq != regs[9]) || (irq != regs[10]))
3034 return MXSER_ERR_IRQ_CONFLIT;
3038 return MXSER_ERR_IRQ;
3039 hwconf->irq = ((int)(irq & 0xF000) >> 12);
3040 for (i = 0; i < 8; i++)
3041 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3042 if ((regs[12] & 0x80) == 0)
3043 return MXSER_ERR_VECTOR;
3044 hwconf->vector = (int)regs[11]; /* interrupt vector */
3046 hwconf->vector_mask = 0x00FF;
3048 hwconf->vector_mask = 0x000F;
3049 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3050 if (regs[12] & bits) {
3051 hwconf->baud_base[i] = 921600;
3052 hwconf->MaxCanSetBaudRate[i] = 921600; /* add by Victor Yu. 09-04-2002 */
3054 hwconf->baud_base[i] = 115200;
3055 hwconf->MaxCanSetBaudRate[i] = 115200; /* add by Victor Yu. 09-04-2002 */
3058 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3059 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3060 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3061 outb(scratch2, cap + UART_LCR);
3062 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3063 scratch = inb(cap + UART_IIR);
3066 hwconf->uart_type = PORT_16550A;
3068 hwconf->uart_type = PORT_16450;
3073 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3074 request_region(hwconf->vector, 1, "mxser(vector)");
3075 return hwconf->ports;
3078 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3079 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3080 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3081 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3082 #define EN_CCMD 0x000 /* Chip's command register */
3083 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3084 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3085 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3086 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3087 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3088 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3089 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3090 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3091 static int mxser_read_register(int port, unsigned short *regs)
3093 int i, k, value, id;
3096 id = mxser_program_mode(port);
3099 for (i = 0; i < 14; i++) {
3100 k = (i & 0x3F) | 0x180;
3101 for (j = 0x100; j > 0; j >>= 1) {
3102 outb(CHIP_CS, port);
3104 outb(CHIP_CS | CHIP_DO, port);
3105 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3107 outb(CHIP_CS, port);
3108 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3113 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3114 outb(CHIP_CS, port);
3115 outb(CHIP_CS | CHIP_SK, port);
3116 if (inb(port) & CHIP_DI)
3122 mxser_normal_mode(port);
3126 static int mxser_program_mode(int port)
3129 /* unsigned long flags; */
3131 spin_lock(&gm_lock);
3139 /* restore_flags(flags); */
3140 spin_unlock(&gm_lock);
3142 id = inb(port + 1) & 0x1F;
3143 if ((id != C168_ASIC_ID) &&
3144 (id != C104_ASIC_ID) &&
3145 (id != C102_ASIC_ID) &&
3146 (id != CI132_ASIC_ID) &&
3147 (id != CI134_ASIC_ID) &&
3148 (id != CI104J_ASIC_ID))
3150 for (i = 0, j = 0; i < 4; i++) {
3154 } else if ((j == 1) && (n == 1)) {
3165 static void mxser_normal_mode(int port)
3169 outb(0xA5, port + 1);
3170 outb(0x80, port + 3);
3171 outb(12, port + 0); /* 9600 bps */
3173 outb(0x03, port + 3); /* 8 data bits */
3174 outb(0x13, port + 4); /* loop back mode */
3175 for (i = 0; i < 16; i++) {
3177 if ((n & 0x61) == 0x60)
3182 outb(0x00, port + 4);
3185 module_init(mxser_module_init);
3186 module_exit(mxser_module_exit);