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/config.h>
40 #include <linux/module.h>
41 #include <linux/version.h>
42 #include <linux/autoconf.h>
43 #include <linux/errno.h>
44 #include <linux/signal.h>
45 #include <linux/sched.h>
46 #include <linux/timer.h>
47 #include <linux/interrupt.h>
48 #include <linux/tty.h>
49 #include <linux/tty_flip.h>
50 #include <linux/serial.h>
51 #include <linux/serial_reg.h>
52 #include <linux/major.h>
53 #include <linux/string.h>
54 #include <linux/fcntl.h>
55 #include <linux/ptrace.h>
56 #include <linux/gfp.h>
57 #include <linux/ioport.h>
59 #include <linux/smp_lock.h>
60 #include <linux/delay.h>
61 #include <linux/pci.h>
63 #include <asm/system.h>
66 #include <asm/segment.h>
67 #include <asm/bitops.h>
68 #include <asm/uaccess.h>
72 #define MXSER_VERSION "1.8"
73 #define MXSERMAJOR 174
74 #define MXSERCUMAJOR 175
76 #define MXSER_EVENT_TXLOW 1
77 #define MXSER_EVENT_HANGUP 2
79 #define MXSER_BOARDS 4 /* Max. boards */
80 #define MXSER_PORTS 32 /* Max. ports */
81 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
82 #define MXSER_ISR_PASS_LIMIT 256
84 #define MXSER_ERR_IOADDR -1
85 #define MXSER_ERR_IRQ -2
86 #define MXSER_ERR_IRQ_CONFLIT -3
87 #define MXSER_ERR_VECTOR -4
89 #define SERIAL_TYPE_NORMAL 1
90 #define SERIAL_TYPE_CALLOUT 2
92 #define WAKEUP_CHARS 256
94 #define UART_MCR_AFE 0x20
95 #define UART_LSR_SPECIAL 0x1E
97 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|IXON|IXOFF))
99 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
101 #define C168_ASIC_ID 1
102 #define C104_ASIC_ID 2
103 #define C102_ASIC_ID 0xB
104 #define CI132_ASIC_ID 4
105 #define CI134_ASIC_ID 3
106 #define CI104J_ASIC_ID 5
109 MXSER_BOARD_C168_ISA = 1,
110 MXSER_BOARD_C104_ISA,
112 MXSER_BOARD_C168_PCI,
113 MXSER_BOARD_C104_PCI,
114 MXSER_BOARD_C102_ISA,
133 static char *mxser_brdname[] = {
151 "Moxa UC7000 Serial",
158 static int mxser_numports[] = {
183 #define UART_TYPE_NUM 2
185 unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
186 MOXA_MUST_MU150_HWID,
190 // This is only for PCI
191 #define UART_INFO_NUM 3
192 struct mxpciuart_info {
203 struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
204 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
205 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
206 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
212 static struct pci_device_id mxser_pcibrds[] = {
214 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
215 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
216 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
217 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
218 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
219 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
220 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
221 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
222 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
223 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
224 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
225 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
226 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
227 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
228 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
230 {PCI_VENDOR_ID_MOXA, 0x1024, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102E},
234 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
239 typedef struct _moxa_pci_info {
240 unsigned short busNum;
241 unsigned short devNum;
242 struct pci_dev *pdev; // add by Victor Yu. 06-23-2003
245 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
246 static int ttymajor = MXSERMAJOR;
247 static int calloutmajor = MXSERCUMAJOR;
248 static int verbose = 0;
250 /* Variables for insmod */
252 MODULE_AUTHOR("Casper Yang");
253 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
254 MODULE_PARM(ioaddr, "1-4i");
255 MODULE_PARM(ttymajor, "i");
256 MODULE_PARM(calloutmajor, "i");
257 MODULE_PARM(verbose, "i");
258 MODULE_LICENSE("GPL");
262 unsigned long rxcnt[MXSER_PORTS];
263 unsigned long txcnt[MXSER_PORTS];
270 unsigned long up_rxcnt;
271 unsigned long up_txcnt;
273 unsigned char hold_reason;
276 struct mxser_mon_ext {
277 unsigned long rx_cnt[32];
278 unsigned long tx_cnt[32];
279 unsigned long up_rxcnt[32];
280 unsigned long up_txcnt[32];
281 int modem_status[32];
291 struct mxser_hwconf {
298 int ioaddr[MXSER_PORTS_PER_BOARD];
299 int baud_base[MXSER_PORTS_PER_BOARD];
300 moxa_pci_info pciInfo;
301 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
302 int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 09-04-2002
303 int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 01-05-2004
306 struct mxser_struct {
308 int base; /* port base address */
309 int irq; /* port using irq no. */
310 int vector; /* port irq vector */
311 int vectormask; /* port vector mask */
313 int rx_trigger; /* Rx fifo trigger level */
315 int baud_base; /* max. speed */
316 int flags; /* defined in tty.h */
317 int type; /* UART type */
318 struct tty_struct *tty;
319 int read_status_mask;
320 int ignore_status_mask;
323 int x_char; /* xon/xoff character */
325 unsigned short closing_wait;
326 int IER; /* Interrupt Enable Register */
327 int MCR; /* Modem control register */
329 int count; /* # of fd on device */
330 int blocked_open; /* # of blocked opens */
331 long session; /* Session of opening process */
332 long pgrp; /* pgrp of opening process */
333 unsigned char *xmit_buf;
337 struct work_struct tqueue;
338 struct termios normal_termios;
339 struct termios callout_termios;
340 wait_queue_head_t open_wait;
341 wait_queue_head_t close_wait;
342 wait_queue_head_t delta_msr_wait;
343 struct async_icount icount; /* kernel counters for the 4 input interrupts */
345 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
346 int MaxCanSetBaudRate; // add by Victor Yu. 09-04-2002
347 int opmode_ioaddr; // add by Victor Yu. 01-05-2004
348 unsigned char stop_rx;
349 unsigned char ldisc_stop_rx;
351 struct mxser_mon mon_data;
352 unsigned char err_shadow;
357 struct mxser_mstatus {
365 static struct mxser_mstatus GMStatus[MXSER_PORTS];
367 static int mxserBoardCAP[MXSER_BOARDS] = {
369 /* 0x180, 0x280, 0x200, 0x320 */
372 static struct tty_driver *mxvar_sdriver;
373 static struct mxser_struct mxvar_table[MXSER_PORTS];
374 static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
375 static struct termios *mxvar_termios[MXSER_PORTS + 1];
376 static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
377 static struct mxser_log mxvar_log;
378 static int mxvar_diagflag;
379 static unsigned char mxser_msr[MXSER_PORTS + 1];
380 static struct mxser_mon_ext mon_data_ext;
381 static int mxser_set_baud_method[MXSER_PORTS + 1];
382 static spinlock_t gm_lock;
385 * This is used to figure out the divisor speeds and the timeouts
388 static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
394 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
395 static int mxser_init(void);
397 //static void mxser_poll(unsigned long);
398 static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
399 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
400 static void mxser_do_softint(void *);
401 static int mxser_open(struct tty_struct *, struct file *);
402 static void mxser_close(struct tty_struct *, struct file *);
403 static int mxser_write(struct tty_struct *, const unsigned char *, int);
404 static int mxser_write_room(struct tty_struct *);
405 static void mxser_flush_buffer(struct tty_struct *);
406 static int mxser_chars_in_buffer(struct tty_struct *);
407 static void mxser_flush_chars(struct tty_struct *);
408 static void mxser_put_char(struct tty_struct *, unsigned char);
409 static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
410 static int mxser_ioctl_special(unsigned int, unsigned long);
411 static void mxser_throttle(struct tty_struct *);
412 static void mxser_unthrottle(struct tty_struct *);
413 static void mxser_set_termios(struct tty_struct *, struct termios *);
414 static void mxser_stop(struct tty_struct *);
415 static void mxser_start(struct tty_struct *);
416 static void mxser_hangup(struct tty_struct *);
417 static void mxser_rs_break(struct tty_struct *, int);
418 static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *);
419 static void mxser_receive_chars(struct mxser_struct *, int *);
420 static void mxser_transmit_chars(struct mxser_struct *);
421 static void mxser_check_modem_status(struct mxser_struct *, int);
422 static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
423 static int mxser_startup(struct mxser_struct *);
424 static void mxser_shutdown(struct mxser_struct *);
425 static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
426 static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct *);
427 static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct *);
428 static int mxser_get_lsr_info(struct mxser_struct *, unsigned int *);
429 static void mxser_send_break(struct mxser_struct *, int);
430 static int mxser_tiocmget(struct tty_struct *, struct file *);
431 static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
432 static int mxser_set_baud(struct mxser_struct *info, long newspd);
433 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
435 static void mxser_startrx(struct tty_struct *tty);
436 static void mxser_stoprx(struct tty_struct *tty);
439 static int CheckIsMoxaMust(int io)
444 outb(0, io + UART_LCR);
445 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
446 oldmcr = inb(io + UART_MCR);
447 outb(0, io + UART_MCR);
448 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
449 if ((hwid = inb(io + UART_MCR)) != 0) {
450 outb(oldmcr, io + UART_MCR);
451 return (MOXA_OTHER_UART);
454 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
455 for (i = 0; i < UART_TYPE_NUM; i++) {
456 if (hwid == Gmoxa_uart_id[i])
459 return MOXA_OTHER_UART;
462 // above is modified by Victor Yu. 08-15-2002
464 static struct tty_operations mxser_ops = {
466 .close = mxser_close,
467 .write = mxser_write,
468 .put_char = mxser_put_char,
469 .flush_chars = mxser_flush_chars,
470 .write_room = mxser_write_room,
471 .chars_in_buffer = mxser_chars_in_buffer,
472 .flush_buffer = mxser_flush_buffer,
473 .ioctl = mxser_ioctl,
474 .throttle = mxser_throttle,
475 .unthrottle = mxser_unthrottle,
476 .set_termios = mxser_set_termios,
478 .start = mxser_start,
479 .hangup = mxser_hangup,
480 .tiocmget = mxser_tiocmget,
481 .tiocmset = mxser_tiocmset,
485 * The MOXA Smartio/Industio serial driver boot-time initialization code!
488 static int __init mxser_module_init(void)
493 printk(KERN_DEBUG "Loading module mxser ...\n");
496 printk(KERN_DEBUG "Done.\n");
500 static void __exit mxser_module_exit(void)
505 printk(KERN_DEBUG "Unloading module mxser ...\n");
507 if ((err |= tty_unregister_driver(mxvar_sdriver)))
508 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
510 for (i = 0; i < MXSER_BOARDS; i++) {
511 struct pci_dev *pdev;
513 if (mxsercfg[i].board_type == -1)
516 pdev = mxsercfg[i].pciInfo.pdev;
517 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
518 if (pdev != NULL) { //PCI
519 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
520 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
522 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
523 release_region(mxsercfg[i].vector, 1);
528 printk(KERN_DEBUG "Done.\n");
532 static void process_txrx_fifo(struct mxser_struct *info)
536 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
537 info->rx_trigger = 1;
538 info->rx_high_water = 1;
539 info->rx_low_water = 1;
540 info->xmit_fifo_size = 1;
542 for (i = 0; i < UART_INFO_NUM; i++) {
543 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
544 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
545 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
546 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
547 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
554 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
556 struct mxser_struct *info;
561 n = board * MXSER_PORTS_PER_BOARD;
562 info = &mxvar_table[n];
564 printk(KERN_DEBUG " ttyM%d - ttyM%d ", n, n + hwconf->ports - 1);
565 printk(KERN_DEBUG " max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
568 for (i = 0; i < hwconf->ports; i++, n++, info++) {
570 info->base = hwconf->ioaddr[i];
571 info->irq = hwconf->irq;
572 info->vector = hwconf->vector;
573 info->vectormask = hwconf->vector_mask;
574 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; // add by Victor Yu. 01-05-2004
576 info->ldisc_stop_rx = 0;
578 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
579 //Enhance mode enabled here
580 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
581 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
584 info->flags = ASYNC_SHARE_IRQ;
585 info->type = hwconf->uart_type;
586 info->baud_base = hwconf->baud_base[i];
588 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
590 process_txrx_fifo(info);
593 info->custom_divisor = hwconf->baud_base[i] * 16;
594 info->close_delay = 5 * HZ / 10;
595 info->closing_wait = 30 * HZ;
596 INIT_WORK(&info->tqueue, mxser_do_softint, info);
597 info->normal_termios = mxvar_sdriver->init_termios;
598 init_waitqueue_head(&info->open_wait);
599 init_waitqueue_head(&info->close_wait);
600 init_waitqueue_head(&info->delta_msr_wait);
601 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
602 info->err_shadow = 0;
603 spin_lock_init(&info->slock);
606 * Allocate the IRQ if necessary
610 /* before set INT ISR, disable all int */
611 for (i = 0; i < hwconf->ports; i++) {
612 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0, hwconf->ioaddr[i] + UART_IER);
615 n = board * MXSER_PORTS_PER_BOARD;
616 info = &mxvar_table[n];
618 spin_lock_irqsave(&info->slock, flags);
619 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info), "mxser", info);
621 spin_unlock_irqrestore(&info->slock, flags);
622 printk(KERN_ERR "Board %d: %s", board, mxser_brdname[hwconf->board_type - 1]);
623 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info->irq);
627 spin_unlock_irqrestore(&info->slock, flags);
634 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
636 mxsercfg[board] = *hwconf;
640 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
644 unsigned int ioaddress;
645 struct pci_dev *pdev = hwconf->pciInfo.pdev;
648 hwconf->board_type = board_type;
649 hwconf->ports = mxser_numports[board_type - 1];
650 ioaddress = pci_resource_start(pdev, 2);
651 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "mxser(IO)");
653 for (i = 0; i < hwconf->ports; i++) {
654 hwconf->ioaddr[i] = ioaddress + 8 * i;
658 ioaddress = pci_resource_start(pdev, 3);
659 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3), "mxser(vector)");
660 hwconf->vector = ioaddress;
663 hwconf->irq = hwconf->pciInfo.pdev->irq;
665 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
666 hwconf->uart_type = PORT_16550A;
667 hwconf->vector_mask = 0;
670 for (i = 0; i < hwconf->ports; i++) {
671 for (j = 0; j < UART_INFO_NUM; j++) {
672 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
673 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
675 //exception....CP-102
676 if (board_type == MXSER_BOARD_CP102)
677 hwconf->MaxCanSetBaudRate[i] = 921600;
683 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
684 for (i = 0; i < hwconf->ports; i++) {
686 hwconf->opmode_ioaddr[i] = ioaddress + 4;
688 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
690 outb(0, ioaddress + 4); // default set to RS232 mode
691 outb(0, ioaddress + 0x0c); //default set to RS232 mode
694 for (i = 0; i < hwconf->ports; i++) {
695 hwconf->vector_mask |= (1 << i);
696 hwconf->baud_base[i] = 921600;
702 static int mxser_init(void)
704 int i, m, retval, b, n;
706 struct pci_dev *pdev = NULL;
708 unsigned char busnum, devnum;
709 struct mxser_hwconf hwconf;
711 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
714 spin_lock_init(&gm_lock);
716 for (i = 0; i < MXSER_BOARDS; i++) {
717 mxsercfg[i].board_type = -1;
720 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION);
722 /* Initialize the tty_driver structure */
723 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
724 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
725 mxvar_sdriver->name = "ttyM";
726 mxvar_sdriver->major = ttymajor;
727 mxvar_sdriver->minor_start = 0;
728 mxvar_sdriver->num = MXSER_PORTS + 1;
729 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
730 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
731 mxvar_sdriver->init_termios = tty_std_termios;
732 mxvar_sdriver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
733 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
734 tty_set_operations(mxvar_sdriver, &mxser_ops);
735 mxvar_sdriver->ttys = mxvar_tty;
736 mxvar_sdriver->termios = mxvar_termios;
737 mxvar_sdriver->termios_locked = mxvar_termios_locked;
739 mxvar_sdriver->open = mxser_open;
740 mxvar_sdriver->close = mxser_close;
741 mxvar_sdriver->write = mxser_write;
742 mxvar_sdriver->put_char = mxser_put_char;
743 mxvar_sdriver->flush_chars = mxser_flush_chars;
744 mxvar_sdriver->write_room = mxser_write_room;
745 mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
746 mxvar_sdriver->flush_buffer = mxser_flush_buffer;
747 mxvar_sdriver->ioctl = mxser_ioctl;
748 mxvar_sdriver->throttle = mxser_throttle;
749 mxvar_sdriver->unthrottle = mxser_unthrottle;
750 mxvar_sdriver->set_termios = mxser_set_termios;
751 mxvar_sdriver->stop = mxser_stop;
752 mxvar_sdriver->start = mxser_start;
753 mxvar_sdriver->hangup = mxser_hangup;
754 mxvar_sdriver->break_ctl = mxser_rs_break;
755 mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
758 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
759 memset(&mxvar_log, 0, sizeof(struct mxser_log));
761 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
762 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
763 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
764 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
767 /* Start finding ISA boards here */
768 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
770 if (!(cap = mxserBoardCAP[b]))
773 retval = mxser_get_ISA_conf(cap, &hwconf);
776 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
779 if (retval == MXSER_ERR_IRQ)
780 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
781 else if (retval == MXSER_ERR_IRQ_CONFLIT)
782 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
783 else if (retval == MXSER_ERR_VECTOR)
784 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
785 else if (retval == MXSER_ERR_IOADDR)
786 printk(KERN_ERR "Invalid I/O address,board not configured\n");
791 hwconf.pciInfo.busNum = 0;
792 hwconf.pciInfo.devNum = 0;
793 hwconf.pciInfo.pdev = NULL;
795 mxser_getcfg(m, &hwconf);
796 //init mxsercfg first, or mxsercfg data is not correct on ISR.
797 //mxser_initbrd will hook ISR.
798 if (mxser_initbrd(m, &hwconf) < 0)
805 /* Start finding ISA boards from module arg */
806 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
808 if (!(cap = ioaddr[b]))
811 retval = mxser_get_ISA_conf(cap, &hwconf);
814 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
817 if (retval == MXSER_ERR_IRQ)
818 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
819 else if (retval == MXSER_ERR_IRQ_CONFLIT)
820 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
821 else if (retval == MXSER_ERR_VECTOR)
822 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
823 else if (retval == MXSER_ERR_IOADDR)
824 printk(KERN_ERR "Invalid I/O address,board not configured\n");
829 hwconf.pciInfo.busNum = 0;
830 hwconf.pciInfo.devNum = 0;
831 hwconf.pciInfo.pdev = NULL;
833 mxser_getcfg(m, &hwconf);
834 //init mxsercfg first, or mxsercfg data is not correct on ISR.
835 //mxser_initbrd will hook ISR.
836 if (mxser_initbrd(m, &hwconf) < 0)
842 /* start finding PCI board here */
843 n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
847 pdev = pci_find_device(mxser_pcibrds[b].vendor, mxser_pcibrds[b].device, pdev);
852 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
853 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
854 hwconf.pciInfo.pdev = pdev;
855 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1], busnum, devnum >> 3);
857 if (m >= MXSER_BOARDS) {
858 printk(KERN_ERR "Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS);
860 if (pci_enable_device(pdev)) {
861 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
864 retval = mxser_get_PCI_conf(busnum, devnum, (int) mxser_pcibrds[b].driver_data, &hwconf);
866 if (retval == MXSER_ERR_IRQ)
867 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
868 else if (retval == MXSER_ERR_IRQ_CONFLIT)
869 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
870 else if (retval == MXSER_ERR_VECTOR)
871 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
872 else if (retval == MXSER_ERR_IOADDR)
873 printk(KERN_ERR "Invalid I/O address,board not configured\n");
876 mxser_getcfg(m, &hwconf);
877 //init mxsercfg first, or mxsercfg data is not correct on ISR.
878 //mxser_initbrd will hook ISR.
879 if (mxser_initbrd(m, &hwconf) < 0)
886 if (!(ret1 = tty_register_driver(mxvar_sdriver))) {
889 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
893 for (i = 0; i < MXSER_BOARDS; i++) {
894 if (mxsercfg[i].board_type == -1)
897 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
898 //todo: release io, vector
907 static void mxser_do_softint(void *private_)
909 struct mxser_struct *info = (struct mxser_struct *) private_;
910 struct tty_struct *tty;
915 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
917 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
922 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
924 unsigned char status = 0;
926 status = inb(baseaddr + UART_MSR);
928 mxser_msr[port] &= 0x0F;
929 mxser_msr[port] |= status;
930 status = mxser_msr[port];
938 * This routine is called whenever a serial port is opened. It
939 * enables interrupts for a serial port, linking in its async structure into
940 * the IRQ chain. It also performs the serial-specific
941 * initialization for the tty structure.
943 static int mxser_open(struct tty_struct *tty, struct file *filp)
945 struct mxser_struct *info;
949 if (line == MXSER_PORTS)
951 if (line < 0 || line > MXSER_PORTS)
953 info = mxvar_table + line;
957 tty->driver_data = info;
960 * Start up serial port
962 retval = mxser_startup(info);
966 retval = mxser_block_til_ready(tty, filp, info);
972 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
973 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
974 *tty->termios = info->normal_termios;
976 *tty->termios = info->callout_termios;
977 mxser_change_speed(info, 0);
980 info->session = current->signal->session;
981 info->pgrp = process_group(current);
982 clear_bit(TTY_DONT_FLIP, &tty->flags);
984 //status = mxser_get_msr(info->base, 0, info->port);
985 //mxser_check_modem_status(info, status);
987 /* unmark here for very high baud rate (ex. 921600 bps) used
989 tty->low_latency = 1;
994 * This routine is called when the serial port gets closed. First, we
995 * wait for the last remaining data to be sent. Then, we unlink its
996 * async structure from the interrupt chain if necessary, and we free
997 * that IRQ if nothing is left in the chain.
999 static void mxser_close(struct tty_struct *tty, struct file *filp)
1001 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1003 unsigned long timeout;
1004 unsigned long flags;
1005 struct tty_ldisc *ld;
1007 if (tty->index == MXSER_PORTS)
1012 spin_lock_irqsave(&info->slock, flags);
1014 if (tty_hung_up_p(filp)) {
1015 spin_unlock_irqrestore(&info->slock, flags);
1018 if ((tty->count == 1) && (info->count != 1)) {
1020 * Uh, oh. tty->count is 1, which means that the tty
1021 * structure will be freed. Info->count should always
1022 * be one in these conditions. If it's greater than
1023 * one, we've got real problems, since it means the
1024 * serial port won't be shutdown.
1026 printk(KERN_ERR "mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info->count);
1029 if (--info->count < 0) {
1030 printk(KERN_ERR "mxser_close: bad serial port count for ttys%d: %d\n", info->port, info->count);
1034 spin_unlock_irqrestore(&info->slock, flags);
1037 info->flags |= ASYNC_CLOSING;
1038 spin_unlock_irqrestore(&info->slock, flags);
1040 * Save the termios structure, since this port may have
1041 * separate termios for callout and dialin.
1043 if (info->flags & ASYNC_NORMAL_ACTIVE)
1044 info->normal_termios = *tty->termios;
1046 * Now we wait for the transmit buffer to clear; and we notify
1047 * the line discipline to only process XON/XOFF characters.
1050 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1051 tty_wait_until_sent(tty, info->closing_wait);
1053 * At this point we stop accepting input. To do this, we
1054 * disable the receive line status interrupts, and tell the
1055 * interrupt driver to stop checking the data ready bit in the
1056 * line status register.
1058 info->IER &= ~UART_IER_RLSI;
1059 if (info->IsMoxaMustChipFlag)
1060 info->IER &= ~MOXA_MUST_RECV_ISR;
1062 info->read_status_mask &= ~UART_LSR_DR;
1064 if (info->flags & ASYNC_INITIALIZED) {
1065 outb(info->IER, info->base + UART_IER);
1067 * Before we drop DTR, make sure the UART transmitter
1068 * has completely drained; this is especially
1069 * important if there is a transmit FIFO!
1071 timeout = jiffies + HZ;
1072 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1073 set_current_state(TASK_INTERRUPTIBLE);
1074 schedule_timeout(5);
1075 if (time_after(jiffies, timeout))
1079 mxser_shutdown(info);
1081 if (tty->driver->flush_buffer)
1082 tty->driver->flush_buffer(tty);
1084 ld = tty_ldisc_ref(tty);
1086 if(ld->flush_buffer)
1087 ld->flush_buffer(tty);
1088 tty_ldisc_deref(ld);
1094 if (info->blocked_open) {
1095 if (info->close_delay) {
1096 set_current_state(TASK_INTERRUPTIBLE);
1097 schedule_timeout(info->close_delay);
1099 wake_up_interruptible(&info->open_wait);
1102 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1103 wake_up_interruptible(&info->close_wait);
1107 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1110 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1111 unsigned long flags;
1113 if (!tty || !info->xmit_buf)
1117 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, SERIAL_XMIT_SIZE - info->xmit_head));
1121 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1122 spin_lock_irqsave(&info->slock, flags);
1123 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1124 info->xmit_cnt += c;
1125 spin_unlock_irqrestore(&info->slock, flags);
1133 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1134 if (!tty->hw_stopped || (info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
1135 spin_lock_irqsave(&info->slock, flags);
1136 info->IER |= UART_IER_THRI;
1137 outb(info->IER, info->base + UART_IER);
1138 spin_unlock_irqrestore(&info->slock, flags);
1144 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1146 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1147 unsigned long flags;
1149 if (!tty || !info->xmit_buf)
1152 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1155 spin_lock_irqsave(&info->slock, flags);
1156 info->xmit_buf[info->xmit_head++] = ch;
1157 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1159 spin_unlock_irqrestore(&info->slock, flags);
1160 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1161 if (!tty->hw_stopped || (info->type == PORT_16550A) || info->IsMoxaMustChipFlag) {
1162 spin_lock_irqsave(&info->slock, flags);
1163 info->IER |= UART_IER_THRI;
1164 outb(info->IER, info->base + UART_IER);
1165 spin_unlock_irqrestore(&info->slock, flags);
1171 static void mxser_flush_chars(struct tty_struct *tty)
1173 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1174 unsigned long flags;
1176 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf || (tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)))
1179 spin_lock_irqsave(&info->slock, flags);
1181 info->IER |= UART_IER_THRI;
1182 outb(info->IER, info->base + UART_IER);
1184 spin_unlock_irqrestore(&info->slock, flags);
1187 static int mxser_write_room(struct tty_struct *tty)
1189 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1192 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1198 static int mxser_chars_in_buffer(struct tty_struct *tty)
1200 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1201 return info->xmit_cnt;
1204 static void mxser_flush_buffer(struct tty_struct *tty)
1206 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1208 unsigned long flags;
1211 spin_lock_irqsave(&info->slock, flags);
1212 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1214 /* below added by shinhay */
1215 fcr = inb(info->base + UART_FCR);
1216 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
1217 outb(fcr, info->base + UART_FCR);
1219 spin_unlock_irqrestore(&info->slock, flags);
1220 /* above added by shinhay */
1222 wake_up_interruptible(&tty->write_wait);
1223 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1224 (tty->ldisc.write_wakeup) (tty);
1227 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1229 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1231 struct async_icount cprev, cnow; /* kernel counter temps */
1232 struct serial_icounter_struct *p_cuser; /* user space */
1233 unsigned long templ;
1234 unsigned long flags;
1236 if (tty->index == MXSER_PORTS)
1237 return (mxser_ioctl_special(cmd, arg));
1239 // following add by Victor Yu. 01-05-2004
1240 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1242 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1244 unsigned char val, mask;
1247 if (cmd == MOXA_SET_OP_MODE) {
1248 if (get_user(opmode, (int *) arg))
1250 if (opmode != RS232_MODE && opmode != RS485_2WIRE_MODE && opmode != RS422_MODE && opmode != RS485_4WIRE_MODE)
1254 val = inb(info->opmode_ioaddr);
1256 val |= (opmode << shiftbit);
1257 outb(val, info->opmode_ioaddr);
1260 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1261 opmode &= OP_MODE_MASK;
1262 if (copy_to_user((int *) arg, &opmode, sizeof(int)))
1267 // above add by Victor Yu. 01-05-2004
1269 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1270 if (tty->flags & (1 << TTY_IO_ERROR))
1274 case TCSBRK: /* SVID version: non-zero arg --> no break */
1275 retval = tty_check_change(tty);
1278 tty_wait_until_sent(tty, 0);
1280 mxser_send_break(info, HZ / 4); /* 1/4 second */
1282 case TCSBRKP: /* support for POSIX tcsendbreak() */
1283 retval = tty_check_change(tty);
1286 tty_wait_until_sent(tty, 0);
1287 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1290 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1292 if (get_user(templ, (unsigned long *) arg))
1295 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1298 return (mxser_get_serial_info(info, (struct serial_struct *) arg));
1300 return (mxser_set_serial_info(info, (struct serial_struct *) arg));
1301 case TIOCSERGETLSR: /* Get line status register */
1302 return (mxser_get_lsr_info(info, (unsigned int *) arg));
1304 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1305 * - mask passed in arg for lines of interest
1306 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1307 * Caller should use TIOCGICOUNT to see which one it was
1310 DECLARE_WAITQUEUE(wait, current);
1312 spin_lock_irqsave(&info->slock, flags);
1313 cprev = info->icount; /* note the counters on entry */
1314 spin_unlock_irqrestore(&info->slock, flags);
1316 add_wait_queue(&info->delta_msr_wait, &wait);
1318 spin_lock_irqsave(&info->slock, flags);
1319 cnow = info->icount; /* atomic copy */
1320 spin_unlock_irqrestore(&info->slock, flags);
1322 set_current_state(TASK_INTERRUPTIBLE);
1323 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) || ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
1327 /* see if a signal did it */
1328 if (signal_pending(current)) {
1334 current->state = TASK_RUNNING;
1335 remove_wait_queue(&info->delta_msr_wait, &wait);
1340 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1341 * Return: write counters to the user passed counter struct
1342 * NB: both 1->0 and 0->1 transitions are counted except for
1343 * RI where only 0->1 is counted.
1346 spin_lock_irqsave(&info->slock, flags);
1347 cnow = info->icount;
1348 spin_unlock_irqrestore(&info->slock, flags);
1349 p_cuser = (struct serial_icounter_struct *) arg;
1350 /* modified by casper 1/11/2000 */
1351 if (put_user(cnow.frame, &p_cuser->frame))
1353 if (put_user(cnow.brk, &p_cuser->brk))
1355 if (put_user(cnow.overrun, &p_cuser->overrun))
1357 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1359 if (put_user(cnow.parity, &p_cuser->parity))
1361 if (put_user(cnow.rx, &p_cuser->rx))
1363 if (put_user(cnow.tx, &p_cuser->tx))
1365 put_user(cnow.cts, &p_cuser->cts);
1366 put_user(cnow.dsr, &p_cuser->dsr);
1367 put_user(cnow.rng, &p_cuser->rng);
1368 put_user(cnow.dcd, &p_cuser->dcd);
1372 case MOXA_HighSpeedOn:
1373 return put_user(info->baud_base != 115200 ? 1 : 0, (int *) arg);
1375 case MOXA_SDS_RSTICOUNTER:{
1376 info->mon_data.rxcnt = 0;
1377 info->mon_data.txcnt = 0;
1380 // (above) added by James.
1381 case MOXA_ASPP_SETBAUD:{
1383 if (get_user(baud, (long *) arg))
1385 mxser_set_baud(info, baud);
1388 case MOXA_ASPP_GETBAUD:
1389 if (copy_to_user((long *) arg, &info->realbaud, sizeof(long)))
1394 case MOXA_ASPP_OQUEUE:{
1397 len = mxser_chars_in_buffer(tty);
1399 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1401 len += (lsr ? 0 : 1);
1403 if (copy_to_user((int *) arg, &len, sizeof(int)))
1408 case MOXA_ASPP_MON:{
1410 // info->mon_data.ser_param = tty->termios->c_cflag;
1412 status = mxser_get_msr(info->base, 1, info->port, info);
1413 mxser_check_modem_status(info, status);
1415 mcr = inb(info->base + UART_MCR);
1416 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1417 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1419 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1421 if (mcr & MOXA_MUST_MCR_TX_XON)
1422 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1424 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1426 if (info->tty->hw_stopped)
1427 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1429 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1432 if (copy_to_user((struct mxser_mon *) arg, &(info->mon_data), sizeof(struct mxser_mon)))
1439 case MOXA_ASPP_LSTATUS:{
1440 if (copy_to_user((struct mxser_mon *) arg, &(info->err_shadow), sizeof(unsigned char)))
1443 info->err_shadow = 0;
1447 case MOXA_SET_BAUD_METHOD:{
1449 if (get_user(method, (int *) arg))
1451 mxser_set_baud_method[info->port] = method;
1452 if (copy_to_user((int *) arg, &method, sizeof(int)))
1458 return -ENOIOCTLCMD;
1463 static int mxser_ioctl_special(unsigned int cmd, unsigned long arg)
1465 int i, result, status;
1469 if (copy_to_user((struct mxser_hwconf *) arg, mxsercfg, sizeof(struct mxser_hwconf) * 4))
1472 case MOXA_GET_MAJOR:
1473 if (copy_to_user((int *) arg, &ttymajor, sizeof(int)))
1477 case MOXA_GET_CUMAJOR:
1478 if (copy_to_user((int *) arg, &calloutmajor, sizeof(int)))
1482 case MOXA_CHKPORTENABLE:
1484 for (i = 0; i < MXSER_PORTS; i++) {
1485 if (mxvar_table[i].base)
1488 return put_user(result, (unsigned long *) arg);
1489 case MOXA_GETDATACOUNT:
1490 if (copy_to_user((struct mxser_log *) arg, &mxvar_log, sizeof(mxvar_log)))
1493 case MOXA_GETMSTATUS:
1494 for (i = 0; i < MXSER_PORTS; i++) {
1496 if (!mxvar_table[i].base) {
1497 GMStatus[i].dcd = 0;
1498 GMStatus[i].dsr = 0;
1499 GMStatus[i].cts = 0;
1503 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1504 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1506 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1508 status = inb(mxvar_table[i].base + UART_MSR);
1509 if (status & 0x80 /*UART_MSR_DCD */ )
1510 GMStatus[i].dcd = 1;
1512 GMStatus[i].dcd = 0;
1514 if (status & 0x20 /*UART_MSR_DSR */ )
1515 GMStatus[i].dsr = 1;
1517 GMStatus[i].dsr = 0;
1520 if (status & 0x10 /*UART_MSR_CTS */ )
1521 GMStatus[i].cts = 1;
1523 GMStatus[i].cts = 0;
1525 if (copy_to_user((struct mxser_mstatus *) arg, GMStatus, sizeof(struct mxser_mstatus) * MXSER_PORTS))
1528 case MOXA_ASPP_MON_EXT:{
1532 unsigned cflag, iflag;
1534 for (i = 0; i < MXSER_PORTS; i++) {
1536 if (!mxvar_table[i].base)
1539 status = mxser_get_msr(mxvar_table[i].base, 0, i, &(mxvar_table[i]));
1540 // mxser_check_modem_status(&mxvar_table[i], status);
1541 if (status & UART_MSR_TERI)
1542 mxvar_table[i].icount.rng++;
1543 if (status & UART_MSR_DDSR)
1544 mxvar_table[i].icount.dsr++;
1545 if (status & UART_MSR_DDCD)
1546 mxvar_table[i].icount.dcd++;
1547 if (status & UART_MSR_DCTS)
1548 mxvar_table[i].icount.cts++;
1550 mxvar_table[i].mon_data.modem_status = status;
1551 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1552 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1553 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1554 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1555 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1556 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1558 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1559 cflag = mxvar_table[i].normal_termios.c_cflag;
1560 iflag = mxvar_table[i].normal_termios.c_iflag;
1562 cflag = mxvar_table[i].tty->termios->c_cflag;
1563 iflag = mxvar_table[i].tty->termios->c_iflag;
1566 mon_data_ext.databits[i] = cflag & CSIZE;
1568 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1570 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1572 mon_data_ext.flowctrl[i] = 0x00;
1574 if (cflag & CRTSCTS)
1575 mon_data_ext.flowctrl[i] |= 0x03;
1577 if (iflag & (IXON | IXOFF))
1578 mon_data_ext.flowctrl[i] |= 0x0C;
1580 if (mxvar_table[i].type == PORT_16550A)
1581 mon_data_ext.fifo[i] = 1;
1583 mon_data_ext.fifo[i] = 0;
1587 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1588 opmode &= OP_MODE_MASK;
1590 mon_data_ext.iftype[i] = opmode;
1593 if (copy_to_user((struct mxser_mon_ext *) arg, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1600 return -ENOIOCTLCMD;
1606 static void mxser_stoprx(struct tty_struct *tty)
1608 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1609 //unsigned long flags;
1612 info->ldisc_stop_rx = 1;
1615 //MX_LOCK(&info->slock);
1616 // following add by Victor Yu. 09-02-2002
1617 if (info->IsMoxaMustChipFlag) {
1618 info->IER &= ~MOXA_MUST_RECV_ISR;
1619 outb(info->IER, info->base + UART_IER);
1621 // above add by Victor Yu. 09-02-2002
1623 info->x_char = STOP_CHAR(tty);
1624 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1625 outb(0, info->base + UART_IER);
1626 info->IER |= UART_IER_THRI;
1627 outb(info->IER, info->base + UART_IER); /* force Tx interrupt */
1628 } // add by Victor Yu. 09-02-2002
1629 //MX_UNLOCK(&info->slock);
1632 if (info->tty->termios->c_cflag & CRTSCTS) {
1633 //MX_LOCK(&info->slock);
1634 info->MCR &= ~UART_MCR_RTS;
1635 outb(info->MCR, info->base + UART_MCR);
1636 //MX_UNLOCK(&info->slock);
1640 static void mxser_startrx(struct tty_struct *tty)
1642 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1643 //unsigned long flags;
1645 info->ldisc_stop_rx = 0;
1650 //MX_LOCK(&info->slock);
1652 // following add by Victor Yu. 09-02-2002
1653 if (info->IsMoxaMustChipFlag) {
1654 info->IER |= MOXA_MUST_RECV_ISR;
1655 outb(info->IER, info->base + UART_IER);
1657 // above add by Victor Yu. 09-02-2002
1659 info->x_char = START_CHAR(tty);
1660 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1661 outb(0, info->base + UART_IER); // add by Victor Yu. 09-02-2002
1662 info->IER |= UART_IER_THRI; /* force Tx interrupt */
1663 outb(info->IER, info->base + UART_IER);
1664 } // add by Victor Yu. 09-02-2002
1665 //MX_UNLOCK(&info->slock);
1669 if (info->tty->termios->c_cflag & CRTSCTS) {
1670 //MX_LOCK(&info->slock);
1671 info->MCR |= UART_MCR_RTS;
1672 outb(info->MCR, info->base + UART_MCR);
1673 //MX_UNLOCK(&info->slock);
1678 * This routine is called by the upper-layer tty layer to signal that
1679 * incoming characters should be throttled.
1681 static void mxser_throttle(struct tty_struct *tty)
1683 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1684 //unsigned long flags;
1685 //MX_LOCK(&info->slock);
1687 //MX_UNLOCK(&info->slock);
1690 static void mxser_unthrottle(struct tty_struct *tty)
1692 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1693 //unsigned long flags;
1694 //MX_LOCK(&info->slock);
1696 //MX_UNLOCK(&info->slock);
1699 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1701 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1702 unsigned long flags;
1704 if ((tty->termios->c_cflag != old_termios->c_cflag) || (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1706 mxser_change_speed(info, old_termios);
1708 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
1709 tty->hw_stopped = 0;
1714 /* Handle sw stopped */
1715 if ((old_termios->c_iflag & IXON) && !(tty->termios->c_iflag & IXON)) {
1718 // following add by Victor Yu. 09-02-2002
1719 if (info->IsMoxaMustChipFlag) {
1720 spin_lock_irqsave(&info->slock, flags);
1721 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1722 spin_unlock_irqrestore(&info->slock, flags);
1724 // above add by Victor Yu. 09-02-2002
1731 * mxser_stop() and mxser_start()
1733 * This routines are called before setting or resetting tty->stopped.
1734 * They enable or disable transmitter interrupts, as necessary.
1736 static void mxser_stop(struct tty_struct *tty)
1738 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1739 unsigned long flags;
1741 spin_lock_irqsave(&info->slock, flags);
1742 if (info->IER & UART_IER_THRI) {
1743 info->IER &= ~UART_IER_THRI;
1744 outb(info->IER, info->base + UART_IER);
1746 spin_unlock_irqrestore(&info->slock, flags);
1749 static void mxser_start(struct tty_struct *tty)
1751 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1752 unsigned long flags;
1754 spin_lock_irqsave(&info->slock, flags);
1755 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1756 info->IER |= UART_IER_THRI;
1757 outb(info->IER, info->base + UART_IER);
1759 spin_unlock_irqrestore(&info->slock, flags);
1763 * mxser_wait_until_sent() --- wait until the transmitter is empty
1765 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1767 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1768 unsigned long orig_jiffies, char_time;
1771 if (info->type == PORT_UNKNOWN)
1774 if (info->xmit_fifo_size == 0)
1775 return; /* Just in case.... */
1777 orig_jiffies = jiffies;
1779 * Set the check interval to be 1/5 of the estimated time to
1780 * send a single character, and make it at least 1. The check
1781 * interval should also be less than the timeout.
1783 * Note: we have to use pretty tight timings here to satisfy
1786 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1787 char_time = char_time / 5;
1790 if (timeout && timeout < char_time)
1791 char_time = timeout;
1793 * If the transmitter hasn't cleared in twice the approximate
1794 * amount of time to send the entire FIFO, it probably won't
1795 * ever clear. This assumes the UART isn't doing flow
1796 * control, which is currently the case. Hence, if it ever
1797 * takes longer than info->timeout, this is probably due to a
1798 * UART bug of some kind. So, we clamp the timeout parameter at
1801 if (!timeout || timeout > 2 * info->timeout)
1802 timeout = 2 * info->timeout;
1803 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1804 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1805 printk("jiff=%lu...", jiffies);
1807 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1808 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1809 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1811 set_current_state(TASK_INTERRUPTIBLE);
1812 schedule_timeout(char_time);
1813 if (signal_pending(current))
1815 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1818 set_current_state(TASK_RUNNING);
1820 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1821 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1827 * This routine is called by tty_hangup() when a hangup is signaled.
1829 void mxser_hangup(struct tty_struct *tty)
1831 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1833 mxser_flush_buffer(tty);
1834 mxser_shutdown(info);
1837 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1839 wake_up_interruptible(&info->open_wait);
1843 // added by James 03-12-2004.
1845 * mxser_rs_break() --- routine which turns the break handling on or off
1847 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1849 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1850 unsigned long flags;
1852 spin_lock_irqsave(&info->slock, flags);
1853 if (break_state == -1)
1854 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
1856 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
1857 spin_unlock_irqrestore(&info->slock, flags);
1860 // (above) added by James.
1864 * This is the serial driver's generic interrupt routine
1866 static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1869 struct mxser_struct *info;
1870 struct mxser_struct *port;
1871 int max, irqbits, bits, msr;
1872 int pass_counter = 0;
1873 int handled = IRQ_NONE;
1876 //spin_lock(&gm_lock);
1878 for (i = 0; i < MXSER_BOARDS; i++) {
1879 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1885 if (i == MXSER_BOARDS) {
1891 max = mxser_numports[mxsercfg[i].board_type - 1];
1893 irqbits = inb(port->vector) & port->vectormask;
1894 if (irqbits == port->vectormask) {
1898 handled = IRQ_HANDLED;
1899 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1900 if (irqbits == port->vectormask) {
1907 // following add by Victor Yu. 09-13-2002
1908 iir = inb(info->base + UART_IIR);
1909 if (iir & UART_IIR_NO_INT)
1911 iir &= MOXA_MUST_IIR_MASK;
1913 status = inb(info->base + UART_LSR);
1914 outb(0x27, info->base + UART_FCR);
1915 inb(info->base + UART_MSR);
1918 // above add by Victor Yu. 09-13-2002
1920 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1921 info->IER |= MOXA_MUST_RECV_ISR;
1922 outb(info->IER, info->base + UART_IER);
1927 /* mask by Victor Yu. 09-13-2002
1929 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1932 /* mask by Victor Yu. 09-02-2002
1933 status = inb(info->base + UART_LSR) & info->read_status_mask;
1936 // following add by Victor Yu. 09-02-2002
1937 status = inb(info->base + UART_LSR);
1939 if (status & UART_LSR_PE) {
1940 info->err_shadow |= NPPI_NOTIFY_PARITY;
1942 if (status & UART_LSR_FE) {
1943 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1945 if (status & UART_LSR_OE) {
1946 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1948 if (status & UART_LSR_BI)
1949 info->err_shadow |= NPPI_NOTIFY_BREAK;
1951 if (info->IsMoxaMustChipFlag) {
1953 if ( (status & 0x02) && !(status & 0x01) ) {
1954 outb(info->base+UART_FCR, 0x23);
1958 if (iir == MOXA_MUST_IIR_GDA || iir == MOXA_MUST_IIR_RDA || iir == MOXA_MUST_IIR_RTO || iir == MOXA_MUST_IIR_LSR)
1959 mxser_receive_chars(info, &status);
1962 // above add by Victor Yu. 09-02-2002
1964 status &= info->read_status_mask;
1965 if (status & UART_LSR_DR)
1966 mxser_receive_chars(info, &status);
1968 msr = inb(info->base + UART_MSR);
1969 if (msr & UART_MSR_ANY_DELTA) {
1970 mxser_check_modem_status(info, msr);
1972 // following add by Victor Yu. 09-13-2002
1973 if (info->IsMoxaMustChipFlag) {
1974 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
1975 mxser_transmit_chars(info);
1978 // above add by Victor Yu. 09-13-2002
1980 if (status & UART_LSR_THRE) {
1981 /* 8-2-99 by William
1982 if ( info->x_char || (info->xmit_cnt > 0) )
1984 mxser_transmit_chars(info);
1988 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
1989 break; /* Prevent infinite loops */
1994 //spin_unlock(&gm_lock);
1998 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2000 struct tty_struct *tty = info->tty;
2001 unsigned char ch, gdl;
2009 unsigned long flags;
2011 spin_lock_irqsave(&info->slock, flags);
2013 recv_room = tty->ldisc.receive_room(tty);
2014 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2015 //mxser_throttle(tty);
2020 cp = tty->flip.char_buf;
2021 fp = tty->flip.flag_buf;
2024 // following add by Victor Yu. 09-02-2002
2025 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2027 if (*status & UART_LSR_SPECIAL) {
2030 // following add by Victor Yu. 02-11-2004
2031 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID && (*status & MOXA_MUST_LSR_RERR))
2033 // above add by Victor Yu. 02-14-2004
2034 if (*status & MOXA_MUST_LSR_RERR)
2037 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2039 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID) // add by Victor Yu. 02-11-2004
2040 gdl &= MOXA_MUST_GDL_MASK;
2041 if (gdl >= recv_room) {
2042 if (!info->ldisc_stop_rx) {
2043 //mxser_throttle(tty);
2049 ch = inb(info->base + UART_RX);
2055 if((count>=HI_WATER) && (info->stop_rx==0)){
2064 // above add by Victor Yu. 09-02-2002
2070 if((count>=HI_WATER) && (info->stop_rx==0)){
2077 ch = inb(info->base + UART_RX);
2078 // following add by Victor Yu. 09-02-2002
2079 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2080 outb(0x23, info->base + UART_FCR);
2081 *status &= info->read_status_mask;
2082 // above add by Victor Yu. 09-02-2002
2083 if (*status & info->ignore_status_mask) {
2084 if (++ignored > 100)
2088 if (*status & UART_LSR_SPECIAL) {
2089 if (*status & UART_LSR_BI) {
2091 /* added by casper 1/11/2000 */
2095 if (info->flags & ASYNC_SAK)
2097 } else if (*status & UART_LSR_PE) {
2099 /* added by casper 1/11/2000 */
2100 info->icount.parity++;
2102 } else if (*status & UART_LSR_FE) {
2104 /* added by casper 1/11/2000 */
2105 info->icount.frame++;
2107 } else if (*status & UART_LSR_OE) {
2108 *fp++ = TTY_OVERRUN;
2109 /* added by casper 1/11/2000 */
2110 info->icount.overrun++;
2118 if (cnt >= recv_room) {
2119 if (!info->ldisc_stop_rx) {
2120 //mxser_throttle(tty);
2128 // following add by Victor Yu. 09-02-2002
2129 if (info->IsMoxaMustChipFlag)
2131 // above add by Victor Yu. 09-02-2002
2133 /* mask by Victor Yu. 09-02-2002
2134 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2136 // following add by Victor Yu. 09-02-2002
2137 *status = inb(info->base + UART_LSR);
2138 // above add by Victor Yu. 09-02-2002
2139 } while (*status & UART_LSR_DR);
2141 end_intr: // add by Victor Yu. 09-02-2002
2143 mxvar_log.rxcnt[info->port] += cnt;
2144 info->mon_data.rxcnt += cnt;
2145 info->mon_data.up_rxcnt += cnt;
2147 tty->ldisc.receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
2148 spin_unlock_irqrestore(&info->slock, flags);
2152 static void mxser_transmit_chars(struct mxser_struct *info)
2155 unsigned long flags;
2157 spin_lock_irqsave(&info->slock, flags);
2160 outb(info->x_char, info->base + UART_TX);
2162 mxvar_log.txcnt[info->port]++;
2163 info->mon_data.txcnt++;
2164 info->mon_data.up_txcnt++;
2166 /* added by casper 1/11/2000 */
2169 spin_unlock_irqrestore(&info->slock, flags);
2173 if (info->xmit_buf == 0) {
2174 spin_unlock_irqrestore(&info->slock, flags);
2178 if ((info->xmit_cnt <= 0) || info->tty->stopped || (info->tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag))) {
2179 info->IER &= ~UART_IER_THRI;
2180 outb(info->IER, info->base + UART_IER);
2181 spin_unlock_irqrestore(&info->slock, flags);
2185 cnt = info->xmit_cnt;
2186 count = info->xmit_fifo_size;
2188 outb(info->xmit_buf[info->xmit_tail++], info->base + UART_TX);
2189 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2190 if (--info->xmit_cnt <= 0)
2192 } while (--count > 0);
2193 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2195 // added by James 03-12-2004.
2196 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2197 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2198 // (above) added by James.
2200 /* added by casper 1/11/2000 */
2201 info->icount.tx += (cnt - info->xmit_cnt);
2204 if (info->xmit_cnt < WAKEUP_CHARS) {
2205 set_bit(MXSER_EVENT_TXLOW, &info->event);
2206 schedule_work(&info->tqueue);
2208 if (info->xmit_cnt <= 0) {
2209 info->IER &= ~UART_IER_THRI;
2210 outb(info->IER, info->base + UART_IER);
2212 spin_unlock_irqrestore(&info->slock, flags);
2215 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2217 /* update input line counters */
2218 if (status & UART_MSR_TERI)
2220 if (status & UART_MSR_DDSR)
2222 if (status & UART_MSR_DDCD)
2224 if (status & UART_MSR_DCTS)
2226 info->mon_data.modem_status = status;
2227 wake_up_interruptible(&info->delta_msr_wait);
2230 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2231 if (status & UART_MSR_DCD)
2232 wake_up_interruptible(&info->open_wait);
2233 schedule_work(&info->tqueue);
2236 if (info->flags & ASYNC_CTS_FLOW) {
2237 if (info->tty->hw_stopped) {
2238 if (status & UART_MSR_CTS) {
2239 info->tty->hw_stopped = 0;
2241 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2242 info->IER |= UART_IER_THRI;
2243 outb(info->IER, info->base + UART_IER);
2245 set_bit(MXSER_EVENT_TXLOW, &info->event);
2246 schedule_work(&info->tqueue); }
2248 if (!(status & UART_MSR_CTS)) {
2249 info->tty->hw_stopped = 1;
2250 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2251 info->IER &= ~UART_IER_THRI;
2252 outb(info->IER, info->base + UART_IER);
2259 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2261 DECLARE_WAITQUEUE(wait, current);
2264 unsigned long flags;
2267 * If non-blocking mode is set, or the port is not enabled,
2268 * then make the check up front and then exit.
2270 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2271 info->flags |= ASYNC_NORMAL_ACTIVE;
2275 if (tty->termios->c_cflag & CLOCAL)
2279 * Block waiting for the carrier detect and the line to become
2280 * free (i.e., not in use by the callout). While we are in
2281 * this loop, info->count is dropped by one, so that
2282 * mxser_close() knows when to free things. We restore it upon
2283 * exit, either normal or abnormal.
2286 add_wait_queue(&info->open_wait, &wait);
2288 spin_lock_irqsave(&info->slock, flags);
2289 if (!tty_hung_up_p(filp))
2291 spin_unlock_irqrestore(&info->slock, flags);
2292 info->blocked_open++;
2294 spin_lock_irqsave(&info->slock, flags);
2295 outb(inb(info->base + UART_MCR) | UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2296 spin_unlock_irqrestore(&info->slock, flags);
2297 set_current_state(TASK_INTERRUPTIBLE);
2298 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2299 if (info->flags & ASYNC_HUP_NOTIFY)
2302 retval = -ERESTARTSYS;
2305 if (!(info->flags & ASYNC_CLOSING) && (do_clocal || (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2307 if (signal_pending(current)) {
2308 retval = -ERESTARTSYS;
2313 set_current_state(TASK_RUNNING);
2314 remove_wait_queue(&info->open_wait, &wait);
2315 if (!tty_hung_up_p(filp))
2317 info->blocked_open--;
2320 info->flags |= ASYNC_NORMAL_ACTIVE;
2324 static int mxser_startup(struct mxser_struct *info)
2328 unsigned long flags;
2330 page = __get_free_page(GFP_KERNEL);
2334 spin_lock_irqsave(&info->slock, flags);
2336 if (info->flags & ASYNC_INITIALIZED) {
2338 spin_unlock_irqrestore(&info->slock, flags);
2342 if (!info->base || !info->type) {
2344 set_bit(TTY_IO_ERROR, &info->tty->flags);
2346 spin_unlock_irqrestore(&info->slock, flags);
2352 info->xmit_buf = (unsigned char *) page;
2355 * Clear the FIFO buffers and disable them
2356 * (they will be reenabled in mxser_change_speed())
2358 if (info->IsMoxaMustChipFlag)
2359 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2361 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2364 * At this point there's no way the LSR could still be 0xFF;
2365 * if it is, then bail out, because there's likely no UART
2368 if (inb(info->base + UART_LSR) == 0xff) {
2369 spin_unlock_irqrestore(&info->slock, flags);
2370 if (capable(CAP_SYS_ADMIN)) {
2372 set_bit(TTY_IO_ERROR, &info->tty->flags);
2379 * Clear the interrupt registers.
2381 (void) inb(info->base + UART_LSR);
2382 (void) inb(info->base + UART_RX);
2383 (void) inb(info->base + UART_IIR);
2384 (void) inb(info->base + UART_MSR);
2387 * Now, initialize the UART
2389 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2390 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2391 outb(info->MCR, info->base + UART_MCR);
2394 * Finally, enable interrupts
2396 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2397 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2399 // following add by Victor Yu. 08-30-2002
2400 if (info->IsMoxaMustChipFlag)
2401 info->IER |= MOXA_MUST_IER_EGDAI;
2402 // above add by Victor Yu. 08-30-2002
2403 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2406 * And clear the interrupt registers again for luck.
2408 (void) inb(info->base + UART_LSR);
2409 (void) inb(info->base + UART_RX);
2410 (void) inb(info->base + UART_IIR);
2411 (void) inb(info->base + UART_MSR);
2414 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2415 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2418 * and set the speed of the serial port
2420 spin_unlock_irqrestore(&info->slock, flags);
2421 mxser_change_speed(info, 0);
2423 info->flags |= ASYNC_INITIALIZED;
2428 * This routine will shutdown a serial port; interrupts maybe disabled, and
2429 * DTR is dropped if the hangup on close termio flag is on.
2431 static void mxser_shutdown(struct mxser_struct *info)
2433 unsigned long flags;
2435 if (!(info->flags & ASYNC_INITIALIZED))
2438 spin_lock_irqsave(&info->slock, flags);
2441 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2442 * here so the queue might never be waken up
2444 wake_up_interruptible(&info->delta_msr_wait);
2447 * Free the IRQ, if necessary
2449 if (info->xmit_buf) {
2450 free_page((unsigned long) info->xmit_buf);
2455 outb(0x00, info->base + UART_IER);
2457 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2458 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2459 outb(info->MCR, info->base + UART_MCR);
2461 /* clear Rx/Tx FIFO's */
2462 // following add by Victor Yu. 08-30-2002
2463 if (info->IsMoxaMustChipFlag)
2464 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2466 // above add by Victor Yu. 08-30-2002
2467 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2469 /* read data port to reset things */
2470 (void) inb(info->base + UART_RX);
2473 set_bit(TTY_IO_ERROR, &info->tty->flags);
2475 info->flags &= ~ASYNC_INITIALIZED;
2477 // following add by Victor Yu. 09-23-2002
2478 if (info->IsMoxaMustChipFlag) {
2479 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2481 // above add by Victor Yu. 09-23-2002
2483 spin_unlock_irqrestore(&info->slock, flags);
2487 * This routine is called to set the UART divisor registers to match
2488 * the specified baud rate for a serial port.
2490 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2492 unsigned cflag, cval, fcr;
2494 unsigned char status;
2496 unsigned long flags;
2499 if (!info->tty || !info->tty->termios)
2501 cflag = info->tty->termios->c_cflag;
2507 #define B921600 (B460800 +1)
2509 if (mxser_set_baud_method[info->port] == 0) {
2510 switch (cflag & (CBAUD | CBAUDEX)) {
2575 mxser_set_baud(info, baud);
2578 /* byte size and parity */
2579 switch (cflag & CSIZE) {
2594 break; /* too keep GCC shut... */
2599 cval |= UART_LCR_PARITY;
2601 #define CMSPAR 010000000000
2603 if (!(cflag & PARODD)) {
2604 cval |= UART_LCR_EPAR;
2607 cval |= UART_LCR_SPAR;
2609 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2610 if (info->IsMoxaMustChipFlag) {
2611 fcr = UART_FCR_ENABLE_FIFO;
2612 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2613 SET_MOXA_MUST_FIFO_VALUE(info);
2617 fcr = UART_FCR_ENABLE_FIFO;
2618 // following add by Victor Yu. 08-30-2002
2619 if (info->IsMoxaMustChipFlag) {
2620 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2621 SET_MOXA_MUST_FIFO_VALUE(info);
2623 // above add by Victor Yu. 08-30-2002
2625 switch (info->rx_trigger) {
2627 fcr |= UART_FCR_TRIGGER_1;
2630 fcr |= UART_FCR_TRIGGER_4;
2633 fcr |= UART_FCR_TRIGGER_8;
2636 fcr |= UART_FCR_TRIGGER_14;
2642 /* CTS flow control flag and modem status interrupts */
2643 info->IER &= ~UART_IER_MSI;
2644 info->MCR &= ~UART_MCR_AFE;
2645 if (cflag & CRTSCTS) {
2646 info->flags |= ASYNC_CTS_FLOW;
2647 info->IER |= UART_IER_MSI;
2648 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2649 info->MCR |= UART_MCR_AFE;
2650 //status = mxser_get_msr(info->base, 0, info->port);
2651 /* save_flags(flags);
2653 status = inb(baseaddr + UART_MSR);
2654 restore_flags(flags);*/
2655 //mxser_check_modem_status(info, status);
2657 //status = mxser_get_msr(info->base, 0, info->port);
2659 //MX_LOCK(&info->slock);
2660 status = inb(info->base + UART_MSR);
2661 //MX_UNLOCK(&info->slock);
2662 if (info->tty->hw_stopped) {
2663 if (status & UART_MSR_CTS) {
2664 info->tty->hw_stopped = 0;
2665 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2666 info->IER |= UART_IER_THRI;
2667 outb(info->IER, info->base + UART_IER);
2669 set_bit(MXSER_EVENT_TXLOW, &info->event);
2670 schedule_work(&info->tqueue); }
2672 if (!(status & UART_MSR_CTS)) {
2673 info->tty->hw_stopped = 1;
2674 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2675 info->IER &= ~UART_IER_THRI;
2676 outb(info->IER, info->base + UART_IER);
2682 info->flags &= ~ASYNC_CTS_FLOW;
2684 outb(info->MCR, info->base + UART_MCR);
2685 if (cflag & CLOCAL) {
2686 info->flags &= ~ASYNC_CHECK_CD;
2688 info->flags |= ASYNC_CHECK_CD;
2689 info->IER |= UART_IER_MSI;
2691 outb(info->IER, info->base + UART_IER);
2694 * Set up parity check flag
2696 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2697 if (I_INPCK(info->tty))
2698 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2699 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2700 info->read_status_mask |= UART_LSR_BI;
2702 info->ignore_status_mask = 0;
2704 if (I_IGNBRK(info->tty)) {
2705 info->ignore_status_mask |= UART_LSR_BI;
2706 info->read_status_mask |= UART_LSR_BI;
2708 * If we're ignore parity and break indicators, ignore
2709 * overruns too. (For real raw support).
2711 if (I_IGNPAR(info->tty)) {
2712 info->ignore_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
2713 info->read_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
2716 // following add by Victor Yu. 09-02-2002
2717 if (info->IsMoxaMustChipFlag) {
2718 spin_lock_irqsave(&info->slock, flags);
2719 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2720 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2721 if (I_IXON(info->tty)) {
2722 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2724 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2726 if (I_IXOFF(info->tty)) {
2727 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2729 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2732 if ( I_IXANY(info->tty) ) {
2733 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2734 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2736 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2737 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2740 spin_unlock_irqrestore(&info->slock, flags);
2742 // above add by Victor Yu. 09-02-2002
2745 outb(fcr, info->base + UART_FCR); /* set fcr */
2746 outb(cval, info->base + UART_LCR);
2752 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2757 unsigned long flags;
2759 if (!info->tty || !info->tty->termios)
2765 if (newspd > info->MaxCanSetBaudRate)
2768 info->realbaud = newspd;
2769 if (newspd == 134) {
2770 quot = (2 * info->baud_base / 269);
2771 } else if (newspd) {
2772 quot = info->baud_base / newspd;
2781 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2782 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2785 spin_lock_irqsave(&info->slock, flags);
2786 info->MCR |= UART_MCR_DTR;
2787 outb(info->MCR, info->base + UART_MCR);
2788 spin_unlock_irqrestore(&info->slock, flags);
2790 spin_lock_irqsave(&info->slock, flags);
2791 info->MCR &= ~UART_MCR_DTR;
2792 outb(info->MCR, info->base + UART_MCR);
2793 spin_unlock_irqrestore(&info->slock, flags);
2797 cval = inb(info->base + UART_LCR);
2799 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2801 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2802 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2803 outb(cval, info->base + UART_LCR); /* reset DLAB */
2812 * ------------------------------------------------------------
2813 * friends of mxser_ioctl()
2814 * ------------------------------------------------------------
2816 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct *retinfo)
2818 struct serial_struct tmp;
2822 memset(&tmp, 0, sizeof(tmp));
2823 tmp.type = info->type;
2824 tmp.line = info->port;
2825 tmp.port = info->base;
2826 tmp.irq = info->irq;
2827 tmp.flags = info->flags;
2828 tmp.baud_base = info->baud_base;
2829 tmp.close_delay = info->close_delay;
2830 tmp.closing_wait = info->closing_wait;
2831 tmp.custom_divisor = info->custom_divisor;
2833 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2838 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct *new_info)
2840 struct serial_struct new_serial;
2844 if (!new_info || !info->base)
2846 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2849 if ((new_serial.irq != info->irq) || (new_serial.port != info->base) || (new_serial.custom_divisor != info->custom_divisor) || (new_serial.baud_base != info->baud_base))
2852 flags = info->flags & ASYNC_SPD_MASK;
2854 if (!capable(CAP_SYS_ADMIN)) {
2855 if ((new_serial.baud_base != info->baud_base) || (new_serial.close_delay != info->close_delay) || ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2857 info->flags = ((info->flags & ~ASYNC_USR_MASK) | (new_serial.flags & ASYNC_USR_MASK));
2860 * OK, past this point, all the error checking has been done.
2861 * At this point, we start making changes.....
2863 info->flags = ((info->flags & ~ASYNC_FLAGS) | (new_serial.flags & ASYNC_FLAGS));
2864 info->close_delay = new_serial.close_delay * HZ / 100;
2865 info->closing_wait = new_serial.closing_wait * HZ / 100;
2866 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2867 info->tty->low_latency = 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2870 /* added by casper, 3/17/2000, for mouse */
2871 info->type = new_serial.type;
2873 process_txrx_fifo(info);
2876 if (info->flags & ASYNC_INITIALIZED) {
2877 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2878 mxser_change_speed(info, 0);
2881 retval = mxser_startup(info);
2887 * mxser_get_lsr_info - get line status register info
2889 * Purpose: Let user call ioctl() to get info when the UART physically
2890 * is emptied. On bus types like RS485, the transmitter must
2891 * release the bus after transmitting. This must be done when
2892 * the transmit shift register is empty, not be done when the
2893 * transmit holding register is empty. This functionality
2894 * allows an RS485 driver to be written in user space.
2896 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int *value)
2898 unsigned char status;
2899 unsigned int result;
2900 unsigned long flags;
2902 spin_lock_irqsave(&info->slock, flags);
2903 status = inb(info->base + UART_LSR);
2904 spin_unlock_irqrestore(&info->slock, flags);
2905 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2906 return put_user(result, value);
2910 * This routine sends a break character out the serial port.
2912 static void mxser_send_break(struct mxser_struct *info, int duration)
2914 unsigned long flags;
2918 set_current_state(TASK_INTERRUPTIBLE);
2919 spin_lock_irqsave(&info->slock, flags);
2920 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
2921 spin_unlock_irqrestore(&info->slock, flags);
2922 schedule_timeout(duration);
2923 spin_lock_irqsave(&info->slock, flags);
2924 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
2925 spin_unlock_irqrestore(&info->slock, flags);
2928 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2930 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2931 unsigned char control, status;
2932 unsigned long flags;
2935 if (tty->index == MXSER_PORTS)
2936 return (-ENOIOCTLCMD);
2937 if (tty->flags & (1 << TTY_IO_ERROR))
2940 control = info->MCR;
2942 spin_lock_irqsave(&info->slock, flags);
2943 status = inb(info->base + UART_MSR);
2944 if (status & UART_MSR_ANY_DELTA)
2945 mxser_check_modem_status(info, status);
2946 spin_unlock_irqrestore(&info->slock, flags);
2947 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2948 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) | ((status & UART_MSR_RI) ? TIOCM_RNG : 0) | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2951 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2953 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2954 unsigned long flags;
2957 if (tty->index == MXSER_PORTS)
2958 return -ENOIOCTLCMD;
2959 if (tty->flags & (1 << TTY_IO_ERROR))
2962 spin_lock_irqsave(&info->slock, flags);
2964 if (set & TIOCM_RTS)
2965 info->MCR |= UART_MCR_RTS;
2966 if (set & TIOCM_DTR)
2967 info->MCR |= UART_MCR_DTR;
2969 if (clear & TIOCM_RTS)
2970 info->MCR &= ~UART_MCR_RTS;
2971 if (clear & TIOCM_DTR)
2972 info->MCR &= ~UART_MCR_DTR;
2974 outb(info->MCR, info->base + UART_MCR);
2975 spin_unlock_irqrestore(&info->slock, flags);
2980 static int mxser_read_register(int, unsigned short *);
2981 static int mxser_program_mode(int);
2982 static void mxser_normal_mode(int);
2984 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2987 unsigned short regs[16], irq;
2988 unsigned char scratch, scratch2;
2990 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2992 id = mxser_read_register(cap, regs);
2993 if (id == C168_ASIC_ID) {
2994 hwconf->board_type = MXSER_BOARD_C168_ISA;
2996 } else if (id == C104_ASIC_ID) {
2997 hwconf->board_type = MXSER_BOARD_C104_ISA;
2999 } else if (id == C102_ASIC_ID) {
3000 hwconf->board_type = MXSER_BOARD_C102_ISA;
3002 } else if (id == CI132_ASIC_ID) {
3003 hwconf->board_type = MXSER_BOARD_CI132;
3005 } else if (id == CI134_ASIC_ID) {
3006 hwconf->board_type = MXSER_BOARD_CI134;
3008 } else if (id == CI104J_ASIC_ID) {
3009 hwconf->board_type = MXSER_BOARD_CI104J;
3015 if (hwconf->ports == 2) {
3016 irq = regs[9] & 0xF000;
3017 irq = irq | (irq >> 4);
3018 if (irq != (regs[9] & 0xFF00))
3019 return (MXSER_ERR_IRQ_CONFLIT);
3020 } else if (hwconf->ports == 4) {
3021 irq = regs[9] & 0xF000;
3022 irq = irq | (irq >> 4);
3023 irq = irq | (irq >> 8);
3025 return (MXSER_ERR_IRQ_CONFLIT);
3026 } else if (hwconf->ports == 8) {
3027 irq = regs[9] & 0xF000;
3028 irq = irq | (irq >> 4);
3029 irq = irq | (irq >> 8);
3030 if ((irq != regs[9]) || (irq != regs[10]))
3031 return (MXSER_ERR_IRQ_CONFLIT);
3035 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);
3043 hwconf->vector = (int) regs[11]; /* interrupt vector */
3045 hwconf->vector_mask = 0x00FF;
3047 hwconf->vector_mask = 0x000F;
3048 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3049 if (regs[12] & bits) {
3050 hwconf->baud_base[i] = 921600;
3051 hwconf->MaxCanSetBaudRate[i] = 921600; // add by Victor Yu. 09-04-2002
3053 hwconf->baud_base[i] = 115200;
3054 hwconf->MaxCanSetBaudRate[i] = 115200; // add by Victor Yu. 09-04-2002
3057 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3058 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3059 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3060 outb(scratch2, cap + UART_LCR);
3061 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3062 scratch = inb(cap + UART_IIR);
3065 hwconf->uart_type = PORT_16550A;
3067 hwconf->uart_type = PORT_16450;
3072 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3073 request_region(hwconf->vector, 1, "mxser(vector)");
3074 return (hwconf->ports);
3077 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3078 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3079 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3080 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3081 #define EN_CCMD 0x000 /* Chip's command register */
3082 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3083 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3084 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3085 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3086 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3087 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3088 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3089 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3090 static int mxser_read_register(int port, unsigned short *regs)
3092 int i, k, value, id;
3095 id = mxser_program_mode(port);
3098 for (i = 0; i < 14; i++) {
3099 k = (i & 0x3F) | 0x180;
3100 for (j = 0x100; j > 0; j >>= 1) {
3101 outb(CHIP_CS, port);
3103 outb(CHIP_CS | CHIP_DO, port);
3104 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3106 outb(CHIP_CS, port);
3107 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3112 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3113 outb(CHIP_CS, port);
3114 outb(CHIP_CS | CHIP_SK, port);
3115 if (inb(port) & CHIP_DI)
3121 mxser_normal_mode(port);
3125 static int mxser_program_mode(int port)
3128 //unsigned long flags;
3130 spin_lock(&gm_lock);
3138 //restore_flags(flags);
3139 spin_unlock(&gm_lock);
3141 id = inb(port + 1) & 0x1F;
3142 if ((id != C168_ASIC_ID) && (id != C104_ASIC_ID) && (id != C102_ASIC_ID) && (id != CI132_ASIC_ID) && (id != CI134_ASIC_ID) && (id != CI104J_ASIC_ID))
3144 for (i = 0, j = 0; i < 4; i++) {
3148 } else if ((j == 1) && (n == 1)) {
3159 static void mxser_normal_mode(int port)
3163 outb(0xA5, port + 1);
3164 outb(0x80, port + 3);
3165 outb(12, port + 0); /* 9600 bps */
3167 outb(0x03, port + 3); /* 8 data bits */
3168 outb(0x13, port + 4); /* loop back mode */
3169 for (i = 0; i < 16; i++) {
3171 if ((n & 0x61) == 0x60)
3176 outb(0x00, port + 4);
3179 // added by James 03-05-2004.
3180 // for secure device server:
3181 // stat = 1, the port8 DTR is set to ON.
3182 // stat = 0, the port8 DTR is set to OFF.
3183 void SDS_PORT8_DTR(int stat)
3186 _sds_oldmcr = inb(mxvar_table[7].base + UART_MCR); // get old MCR
3188 outb(_sds_oldmcr | 0x01, mxvar_table[7].base + UART_MCR); // set DTR ON
3191 outb(_sds_oldmcr & 0xfe, mxvar_table[7].base + UART_MCR); // set DTR OFF
3196 module_init(mxser_module_init);
3197 module_exit(mxser_module_exit);