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,
132 static char *mxser_brdname[] = {
150 "Moxa UC7000 Serial",
156 static int mxser_numports[] = {
180 #define UART_TYPE_NUM 2
182 unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
183 MOXA_MUST_MU150_HWID,
187 // This is only for PCI
188 #define UART_INFO_NUM 3
189 struct mxpciuart_info {
200 struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
201 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
202 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
203 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
209 static struct pci_device_id mxser_pcibrds[] = {
210 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
211 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
212 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
213 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
214 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
215 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
216 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
217 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
218 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
219 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
220 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
221 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
222 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
223 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
224 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
228 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
233 typedef struct _moxa_pci_info {
234 unsigned short busNum;
235 unsigned short devNum;
236 struct pci_dev *pdev; // add by Victor Yu. 06-23-2003
239 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
240 static int ttymajor = MXSERMAJOR;
241 static int calloutmajor = MXSERCUMAJOR;
242 static int verbose = 0;
244 /* Variables for insmod */
246 MODULE_AUTHOR("Casper Yang");
247 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
248 MODULE_PARM(ioaddr, "1-4i");
249 MODULE_PARM(ttymajor, "i");
250 MODULE_PARM(calloutmajor, "i");
251 MODULE_PARM(verbose, "i");
252 MODULE_LICENSE("GPL");
256 unsigned long rxcnt[MXSER_PORTS];
257 unsigned long txcnt[MXSER_PORTS];
264 unsigned long up_rxcnt;
265 unsigned long up_txcnt;
267 unsigned char hold_reason;
270 struct mxser_mon_ext {
271 unsigned long rx_cnt[32];
272 unsigned long tx_cnt[32];
273 unsigned long up_rxcnt[32];
274 unsigned long up_txcnt[32];
275 int modem_status[32];
285 struct mxser_hwconf {
292 int ioaddr[MXSER_PORTS_PER_BOARD];
293 int baud_base[MXSER_PORTS_PER_BOARD];
294 moxa_pci_info pciInfo;
295 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
296 int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 09-04-2002
297 int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 01-05-2004
300 struct mxser_struct {
302 int base; /* port base address */
303 int irq; /* port using irq no. */
304 int vector; /* port irq vector */
305 int vectormask; /* port vector mask */
307 int rx_trigger; /* Rx fifo trigger level */
309 int baud_base; /* max. speed */
310 int flags; /* defined in tty.h */
311 int type; /* UART type */
312 struct tty_struct *tty;
313 int read_status_mask;
314 int ignore_status_mask;
317 int x_char; /* xon/xoff character */
319 unsigned short closing_wait;
320 int IER; /* Interrupt Enable Register */
321 int MCR; /* Modem control register */
323 int count; /* # of fd on device */
324 int blocked_open; /* # of blocked opens */
325 long session; /* Session of opening process */
326 long pgrp; /* pgrp of opening process */
327 unsigned char *xmit_buf;
331 struct work_struct tqueue;
332 struct termios normal_termios;
333 struct termios callout_termios;
334 wait_queue_head_t open_wait;
335 wait_queue_head_t close_wait;
336 wait_queue_head_t delta_msr_wait;
337 struct async_icount icount; /* kernel counters for the 4 input interrupts */
339 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
340 int MaxCanSetBaudRate; // add by Victor Yu. 09-04-2002
341 int opmode_ioaddr; // add by Victor Yu. 01-05-2004
342 unsigned char stop_rx;
343 unsigned char ldisc_stop_rx;
345 struct mxser_mon mon_data;
346 unsigned char err_shadow;
351 struct mxser_mstatus {
359 static struct mxser_mstatus GMStatus[MXSER_PORTS];
361 static int mxserBoardCAP[MXSER_BOARDS] = {
363 /* 0x180, 0x280, 0x200, 0x320 */
366 static struct tty_driver *mxvar_sdriver;
367 static struct mxser_struct mxvar_table[MXSER_PORTS];
368 static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
369 static struct termios *mxvar_termios[MXSER_PORTS + 1];
370 static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
371 static struct mxser_log mxvar_log;
372 static int mxvar_diagflag;
373 static unsigned char mxser_msr[MXSER_PORTS + 1];
374 static struct mxser_mon_ext mon_data_ext;
375 static int mxser_set_baud_method[MXSER_PORTS + 1];
376 static spinlock_t gm_lock;
379 * This is used to figure out the divisor speeds and the timeouts
382 static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
388 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
389 static int mxser_init(void);
391 //static void mxser_poll(unsigned long);
392 static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
393 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
394 static void mxser_do_softint(void *);
395 static int mxser_open(struct tty_struct *, struct file *);
396 static void mxser_close(struct tty_struct *, struct file *);
397 static int mxser_write(struct tty_struct *, const unsigned char *, int);
398 static int mxser_write_room(struct tty_struct *);
399 static void mxser_flush_buffer(struct tty_struct *);
400 static int mxser_chars_in_buffer(struct tty_struct *);
401 static void mxser_flush_chars(struct tty_struct *);
402 static void mxser_put_char(struct tty_struct *, unsigned char);
403 static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
404 static int mxser_ioctl_special(unsigned int, unsigned long);
405 static void mxser_throttle(struct tty_struct *);
406 static void mxser_unthrottle(struct tty_struct *);
407 static void mxser_set_termios(struct tty_struct *, struct termios *);
408 static void mxser_stop(struct tty_struct *);
409 static void mxser_start(struct tty_struct *);
410 static void mxser_hangup(struct tty_struct *);
411 static void mxser_rs_break(struct tty_struct *, int);
412 static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *);
413 static void mxser_receive_chars(struct mxser_struct *, int *);
414 static void mxser_transmit_chars(struct mxser_struct *);
415 static void mxser_check_modem_status(struct mxser_struct *, int);
416 static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
417 static int mxser_startup(struct mxser_struct *);
418 static void mxser_shutdown(struct mxser_struct *);
419 static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
420 static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct *);
421 static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct *);
422 static int mxser_get_lsr_info(struct mxser_struct *, unsigned int *);
423 static void mxser_send_break(struct mxser_struct *, int);
424 static int mxser_tiocmget(struct tty_struct *, struct file *);
425 static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
426 static int mxser_set_baud(struct mxser_struct *info, long newspd);
427 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
429 static void mxser_startrx(struct tty_struct *tty);
430 static void mxser_stoprx(struct tty_struct *tty);
433 static int CheckIsMoxaMust(int io)
438 outb(0, io + UART_LCR);
439 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
440 oldmcr = inb(io + UART_MCR);
441 outb(0, io + UART_MCR);
442 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
443 if ((hwid = inb(io + UART_MCR)) != 0) {
444 outb(oldmcr, io + UART_MCR);
445 return (MOXA_OTHER_UART);
448 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
449 for (i = 0; i < UART_TYPE_NUM; i++) {
450 if (hwid == Gmoxa_uart_id[i])
453 return MOXA_OTHER_UART;
456 // above is modified by Victor Yu. 08-15-2002
458 static struct tty_operations mxser_ops = {
460 .close = mxser_close,
461 .write = mxser_write,
462 .put_char = mxser_put_char,
463 .flush_chars = mxser_flush_chars,
464 .write_room = mxser_write_room,
465 .chars_in_buffer = mxser_chars_in_buffer,
466 .flush_buffer = mxser_flush_buffer,
467 .ioctl = mxser_ioctl,
468 .throttle = mxser_throttle,
469 .unthrottle = mxser_unthrottle,
470 .set_termios = mxser_set_termios,
472 .start = mxser_start,
473 .hangup = mxser_hangup,
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 if ((err |= tty_unregister_driver(mxvar_sdriver)))
502 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
504 for (i = 0; i < MXSER_BOARDS; i++) {
505 struct pci_dev *pdev;
507 if (mxsercfg[i].board_type == -1)
510 pdev = mxsercfg[i].pciInfo.pdev;
511 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
512 if (pdev != NULL) { //PCI
513 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
514 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
516 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
517 release_region(mxsercfg[i].vector, 1);
522 printk(KERN_DEBUG "Done.\n");
526 static void process_txrx_fifo(struct mxser_struct *info)
530 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
531 info->rx_trigger = 1;
532 info->rx_high_water = 1;
533 info->rx_low_water = 1;
534 info->xmit_fifo_size = 1;
536 for (i = 0; i < UART_INFO_NUM; i++) {
537 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
538 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
539 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
540 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
541 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
548 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
550 struct mxser_struct *info;
555 n = board * MXSER_PORTS_PER_BOARD;
556 info = &mxvar_table[n];
558 printk(KERN_DEBUG " ttyM%d - ttyM%d ", n, n + hwconf->ports - 1);
559 printk(KERN_DEBUG " max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
562 for (i = 0; i < hwconf->ports; i++, n++, info++) {
564 info->base = hwconf->ioaddr[i];
565 info->irq = hwconf->irq;
566 info->vector = hwconf->vector;
567 info->vectormask = hwconf->vector_mask;
568 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; // add by Victor Yu. 01-05-2004
570 info->ldisc_stop_rx = 0;
572 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
573 //Enhance mode enabled here
574 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
575 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
578 info->flags = ASYNC_SHARE_IRQ;
579 info->type = hwconf->uart_type;
580 info->baud_base = hwconf->baud_base[i];
582 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
584 process_txrx_fifo(info);
587 info->custom_divisor = hwconf->baud_base[i] * 16;
588 info->close_delay = 5 * HZ / 10;
589 info->closing_wait = 30 * HZ;
590 INIT_WORK(&info->tqueue, mxser_do_softint, info);
591 info->normal_termios = mxvar_sdriver->init_termios;
592 init_waitqueue_head(&info->open_wait);
593 init_waitqueue_head(&info->close_wait);
594 init_waitqueue_head(&info->delta_msr_wait);
595 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
596 info->err_shadow = 0;
597 spin_lock_init(&info->slock);
600 * Allocate the IRQ if necessary
604 /* before set INT ISR, disable all int */
605 for (i = 0; i < hwconf->ports; i++) {
606 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0, hwconf->ioaddr[i] + UART_IER);
609 n = board * MXSER_PORTS_PER_BOARD;
610 info = &mxvar_table[n];
612 spin_lock_irqsave(&info->slock, flags);
613 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info), "mxser", info);
615 spin_unlock_irqrestore(&info->slock, flags);
616 printk(KERN_ERR "Board %d: %s", board, mxser_brdname[hwconf->board_type - 1]);
617 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info->irq);
621 spin_unlock_irqrestore(&info->slock, flags);
628 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
630 mxsercfg[board] = *hwconf;
634 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
638 unsigned int ioaddress;
639 struct pci_dev *pdev = hwconf->pciInfo.pdev;
642 hwconf->board_type = board_type;
643 hwconf->ports = mxser_numports[board_type - 1];
644 ioaddress = pci_resource_start(pdev, 2);
645 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "mxser(IO)");
647 for (i = 0; i < hwconf->ports; i++) {
648 hwconf->ioaddr[i] = ioaddress + 8 * i;
652 ioaddress = pci_resource_start(pdev, 3);
653 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3), "mxser(vector)");
654 hwconf->vector = ioaddress;
657 hwconf->irq = hwconf->pciInfo.pdev->irq;
659 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
660 hwconf->uart_type = PORT_16550A;
661 hwconf->vector_mask = 0;
664 for (i = 0; i < hwconf->ports; i++) {
665 for (j = 0; j < UART_INFO_NUM; j++) {
666 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
667 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
669 //exception....CP-102
670 if (board_type == MXSER_BOARD_CP102)
671 hwconf->MaxCanSetBaudRate[i] = 921600;
677 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
678 for (i = 0; i < hwconf->ports; i++) {
680 hwconf->opmode_ioaddr[i] = ioaddress + 4;
682 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
684 outb(0, ioaddress + 4); // default set to RS232 mode
685 outb(0, ioaddress + 0x0c); //default set to RS232 mode
688 for (i = 0; i < hwconf->ports; i++) {
689 hwconf->vector_mask |= (1 << i);
690 hwconf->baud_base[i] = 921600;
696 static int mxser_init(void)
698 int i, m, retval, b, n;
700 struct pci_dev *pdev = NULL;
702 unsigned char busnum, devnum;
703 struct mxser_hwconf hwconf;
705 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
708 spin_lock_init(&gm_lock);
710 for (i = 0; i < MXSER_BOARDS; i++) {
711 mxsercfg[i].board_type = -1;
714 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION);
716 /* Initialize the tty_driver structure */
717 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
718 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
719 mxvar_sdriver->name = "ttyM";
720 mxvar_sdriver->major = ttymajor;
721 mxvar_sdriver->minor_start = 0;
722 mxvar_sdriver->num = MXSER_PORTS + 1;
723 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
724 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
725 mxvar_sdriver->init_termios = tty_std_termios;
726 mxvar_sdriver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
727 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
728 tty_set_operations(mxvar_sdriver, &mxser_ops);
729 mxvar_sdriver->ttys = mxvar_tty;
730 mxvar_sdriver->termios = mxvar_termios;
731 mxvar_sdriver->termios_locked = mxvar_termios_locked;
733 mxvar_sdriver->open = mxser_open;
734 mxvar_sdriver->close = mxser_close;
735 mxvar_sdriver->write = mxser_write;
736 mxvar_sdriver->put_char = mxser_put_char;
737 mxvar_sdriver->flush_chars = mxser_flush_chars;
738 mxvar_sdriver->write_room = mxser_write_room;
739 mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
740 mxvar_sdriver->flush_buffer = mxser_flush_buffer;
741 mxvar_sdriver->ioctl = mxser_ioctl;
742 mxvar_sdriver->throttle = mxser_throttle;
743 mxvar_sdriver->unthrottle = mxser_unthrottle;
744 mxvar_sdriver->set_termios = mxser_set_termios;
745 mxvar_sdriver->stop = mxser_stop;
746 mxvar_sdriver->start = mxser_start;
747 mxvar_sdriver->hangup = mxser_hangup;
748 mxvar_sdriver->break_ctl = mxser_rs_break;
749 mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
752 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
753 memset(&mxvar_log, 0, sizeof(struct mxser_log));
755 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
756 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
757 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
758 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
761 /* Start finding ISA boards here */
762 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
764 if (!(cap = mxserBoardCAP[b]))
767 retval = mxser_get_ISA_conf(cap, &hwconf);
770 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
773 if (retval == MXSER_ERR_IRQ)
774 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
775 else if (retval == MXSER_ERR_IRQ_CONFLIT)
776 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
777 else if (retval == MXSER_ERR_VECTOR)
778 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
779 else if (retval == MXSER_ERR_IOADDR)
780 printk(KERN_ERR "Invalid I/O address,board not configured\n");
785 hwconf.pciInfo.busNum = 0;
786 hwconf.pciInfo.devNum = 0;
787 hwconf.pciInfo.pdev = NULL;
789 mxser_getcfg(m, &hwconf);
790 //init mxsercfg first, or mxsercfg data is not correct on ISR.
791 //mxser_initbrd will hook ISR.
792 if (mxser_initbrd(m, &hwconf) < 0)
799 /* Start finding ISA boards from module arg */
800 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
802 if (!(cap = ioaddr[b]))
805 retval = mxser_get_ISA_conf(cap, &hwconf);
808 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
811 if (retval == MXSER_ERR_IRQ)
812 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
813 else if (retval == MXSER_ERR_IRQ_CONFLIT)
814 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
815 else if (retval == MXSER_ERR_VECTOR)
816 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
817 else if (retval == MXSER_ERR_IOADDR)
818 printk(KERN_ERR "Invalid I/O address,board not configured\n");
823 hwconf.pciInfo.busNum = 0;
824 hwconf.pciInfo.devNum = 0;
825 hwconf.pciInfo.pdev = NULL;
827 mxser_getcfg(m, &hwconf);
828 //init mxsercfg first, or mxsercfg data is not correct on ISR.
829 //mxser_initbrd will hook ISR.
830 if (mxser_initbrd(m, &hwconf) < 0)
836 /* start finding PCI board here */
837 n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
841 pdev = pci_find_device(mxser_pcibrds[b].vendor, mxser_pcibrds[b].device, pdev);
846 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
847 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
848 hwconf.pciInfo.pdev = pdev;
849 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1], busnum, devnum >> 3);
851 if (m >= MXSER_BOARDS) {
852 printk(KERN_ERR "Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS);
854 if (pci_enable_device(pdev)) {
855 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
858 retval = mxser_get_PCI_conf(busnum, devnum, (int) mxser_pcibrds[b].driver_data, &hwconf);
860 if (retval == MXSER_ERR_IRQ)
861 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
862 else if (retval == MXSER_ERR_IRQ_CONFLIT)
863 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
864 else if (retval == MXSER_ERR_VECTOR)
865 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
866 else if (retval == MXSER_ERR_IOADDR)
867 printk(KERN_ERR "Invalid I/O address,board not configured\n");
870 mxser_getcfg(m, &hwconf);
871 //init mxsercfg first, or mxsercfg data is not correct on ISR.
872 //mxser_initbrd will hook ISR.
873 if (mxser_initbrd(m, &hwconf) < 0)
880 if (!(ret1 = tty_register_driver(mxvar_sdriver))) {
883 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
887 for (i = 0; i < MXSER_BOARDS; i++) {
888 if (mxsercfg[i].board_type == -1)
891 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
892 //todo: release io, vector
901 static void mxser_do_softint(void *private_)
903 struct mxser_struct *info = (struct mxser_struct *) private_;
904 struct tty_struct *tty;
909 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
911 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
916 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
918 unsigned char status = 0;
920 status = inb(baseaddr + UART_MSR);
922 mxser_msr[port] &= 0x0F;
923 mxser_msr[port] |= status;
924 status = mxser_msr[port];
932 * This routine is called whenever a serial port is opened. It
933 * enables interrupts for a serial port, linking in its async structure into
934 * the IRQ chain. It also performs the serial-specific
935 * initialization for the tty structure.
937 static int mxser_open(struct tty_struct *tty, struct file *filp)
939 struct mxser_struct *info;
943 if (line == MXSER_PORTS)
945 if (line < 0 || line > MXSER_PORTS)
947 info = mxvar_table + line;
951 tty->driver_data = info;
954 * Start up serial port
956 retval = mxser_startup(info);
960 retval = mxser_block_til_ready(tty, filp, info);
966 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
967 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
968 *tty->termios = info->normal_termios;
970 *tty->termios = info->callout_termios;
971 mxser_change_speed(info, 0);
974 info->session = current->signal->session;
975 info->pgrp = process_group(current);
976 clear_bit(TTY_DONT_FLIP, &tty->flags);
978 //status = mxser_get_msr(info->base, 0, info->port);
979 //mxser_check_modem_status(info, status);
981 /* unmark here for very high baud rate (ex. 921600 bps) used
983 tty->low_latency = 1;
988 * This routine is called when the serial port gets closed. First, we
989 * wait for the last remaining data to be sent. Then, we unlink its
990 * async structure from the interrupt chain if necessary, and we free
991 * that IRQ if nothing is left in the chain.
993 static void mxser_close(struct tty_struct *tty, struct file *filp)
995 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
997 unsigned long timeout;
999 struct tty_ldisc *ld;
1001 if (tty->index == MXSER_PORTS)
1006 spin_lock_irqsave(&info->slock, flags);
1008 if (tty_hung_up_p(filp)) {
1009 spin_unlock_irqrestore(&info->slock, flags);
1012 if ((tty->count == 1) && (info->count != 1)) {
1014 * Uh, oh. tty->count is 1, which means that the tty
1015 * structure will be freed. Info->count should always
1016 * be one in these conditions. If it's greater than
1017 * one, we've got real problems, since it means the
1018 * serial port won't be shutdown.
1020 printk(KERN_ERR "mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info->count);
1023 if (--info->count < 0) {
1024 printk(KERN_ERR "mxser_close: bad serial port count for ttys%d: %d\n", info->port, info->count);
1028 spin_unlock_irqrestore(&info->slock, flags);
1031 info->flags |= ASYNC_CLOSING;
1032 spin_unlock_irqrestore(&info->slock, flags);
1034 * Save the termios structure, since this port may have
1035 * separate termios for callout and dialin.
1037 if (info->flags & ASYNC_NORMAL_ACTIVE)
1038 info->normal_termios = *tty->termios;
1040 * Now we wait for the transmit buffer to clear; and we notify
1041 * the line discipline to only process XON/XOFF characters.
1044 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1045 tty_wait_until_sent(tty, info->closing_wait);
1047 * At this point we stop accepting input. To do this, we
1048 * disable the receive line status interrupts, and tell the
1049 * interrupt driver to stop checking the data ready bit in the
1050 * line status register.
1052 info->IER &= ~UART_IER_RLSI;
1053 if (info->IsMoxaMustChipFlag)
1054 info->IER &= ~MOXA_MUST_RECV_ISR;
1056 info->read_status_mask &= ~UART_LSR_DR;
1058 if (info->flags & ASYNC_INITIALIZED) {
1059 outb(info->IER, info->base + UART_IER);
1061 * Before we drop DTR, make sure the UART transmitter
1062 * has completely drained; this is especially
1063 * important if there is a transmit FIFO!
1065 timeout = jiffies + HZ;
1066 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1067 set_current_state(TASK_INTERRUPTIBLE);
1068 schedule_timeout(5);
1069 if (time_after(jiffies, timeout))
1073 mxser_shutdown(info);
1075 if (tty->driver->flush_buffer)
1076 tty->driver->flush_buffer(tty);
1078 ld = tty_ldisc_ref(tty);
1080 if(ld->flush_buffer)
1081 ld->flush_buffer(tty);
1082 tty_ldisc_deref(ld);
1088 if (info->blocked_open) {
1089 if (info->close_delay) {
1090 set_current_state(TASK_INTERRUPTIBLE);
1091 schedule_timeout(info->close_delay);
1093 wake_up_interruptible(&info->open_wait);
1096 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1097 wake_up_interruptible(&info->close_wait);
1101 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1104 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1105 unsigned long flags;
1107 if (!tty || !info->xmit_buf)
1111 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, SERIAL_XMIT_SIZE - info->xmit_head));
1115 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1116 spin_lock_irqsave(&info->slock, flags);
1117 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1118 info->xmit_cnt += c;
1119 spin_unlock_irqrestore(&info->slock, flags);
1127 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1128 if (!tty->hw_stopped || (info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
1129 spin_lock_irqsave(&info->slock, flags);
1130 info->IER |= UART_IER_THRI;
1131 outb(info->IER, info->base + UART_IER);
1132 spin_unlock_irqrestore(&info->slock, flags);
1138 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1140 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1141 unsigned long flags;
1143 if (!tty || !info->xmit_buf)
1146 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1149 spin_lock_irqsave(&info->slock, flags);
1150 info->xmit_buf[info->xmit_head++] = ch;
1151 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1153 spin_unlock_irqrestore(&info->slock, flags);
1154 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1155 if (!tty->hw_stopped || (info->type == PORT_16550A) || info->IsMoxaMustChipFlag) {
1156 spin_lock_irqsave(&info->slock, flags);
1157 info->IER |= UART_IER_THRI;
1158 outb(info->IER, info->base + UART_IER);
1159 spin_unlock_irqrestore(&info->slock, flags);
1165 static void mxser_flush_chars(struct tty_struct *tty)
1167 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1168 unsigned long flags;
1170 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf || (tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)))
1173 spin_lock_irqsave(&info->slock, flags);
1175 info->IER |= UART_IER_THRI;
1176 outb(info->IER, info->base + UART_IER);
1178 spin_unlock_irqrestore(&info->slock, flags);
1181 static int mxser_write_room(struct tty_struct *tty)
1183 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1186 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1192 static int mxser_chars_in_buffer(struct tty_struct *tty)
1194 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1195 return info->xmit_cnt;
1198 static void mxser_flush_buffer(struct tty_struct *tty)
1200 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1202 unsigned long flags;
1205 spin_lock_irqsave(&info->slock, flags);
1206 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1208 /* below added by shinhay */
1209 fcr = inb(info->base + UART_FCR);
1210 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
1211 outb(fcr, info->base + UART_FCR);
1213 spin_unlock_irqrestore(&info->slock, flags);
1214 /* above added by shinhay */
1216 wake_up_interruptible(&tty->write_wait);
1217 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1218 (tty->ldisc.write_wakeup) (tty);
1221 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1223 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1225 struct async_icount cprev, cnow; /* kernel counter temps */
1226 struct serial_icounter_struct *p_cuser; /* user space */
1227 unsigned long templ;
1228 unsigned long flags;
1230 if (tty->index == MXSER_PORTS)
1231 return (mxser_ioctl_special(cmd, arg));
1233 // following add by Victor Yu. 01-05-2004
1234 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1236 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1238 unsigned char val, mask;
1241 if (cmd == MOXA_SET_OP_MODE) {
1242 if (get_user(opmode, (int *) arg))
1244 if (opmode != RS232_MODE && opmode != RS485_2WIRE_MODE && opmode != RS422_MODE && opmode != RS485_4WIRE_MODE)
1248 val = inb(info->opmode_ioaddr);
1250 val |= (opmode << shiftbit);
1251 outb(val, info->opmode_ioaddr);
1254 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1255 opmode &= OP_MODE_MASK;
1256 if (copy_to_user((int *) arg, &opmode, sizeof(int)))
1261 // above add by Victor Yu. 01-05-2004
1263 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1264 if (tty->flags & (1 << TTY_IO_ERROR))
1268 case TCSBRK: /* SVID version: non-zero arg --> no break */
1269 retval = tty_check_change(tty);
1272 tty_wait_until_sent(tty, 0);
1274 mxser_send_break(info, HZ / 4); /* 1/4 second */
1276 case TCSBRKP: /* support for POSIX tcsendbreak() */
1277 retval = tty_check_change(tty);
1280 tty_wait_until_sent(tty, 0);
1281 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1284 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long *) arg);
1286 if (get_user(templ, (unsigned long *) arg))
1289 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1292 return (mxser_get_serial_info(info, (struct serial_struct *) arg));
1294 return (mxser_set_serial_info(info, (struct serial_struct *) arg));
1295 case TIOCSERGETLSR: /* Get line status register */
1296 return (mxser_get_lsr_info(info, (unsigned int *) arg));
1298 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1299 * - mask passed in arg for lines of interest
1300 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1301 * Caller should use TIOCGICOUNT to see which one it was
1304 DECLARE_WAITQUEUE(wait, current);
1306 spin_lock_irqsave(&info->slock, flags);
1307 cprev = info->icount; /* note the counters on entry */
1308 spin_unlock_irqrestore(&info->slock, flags);
1310 add_wait_queue(&info->delta_msr_wait, &wait);
1312 spin_lock_irqsave(&info->slock, flags);
1313 cnow = info->icount; /* atomic copy */
1314 spin_unlock_irqrestore(&info->slock, flags);
1316 set_current_state(TASK_INTERRUPTIBLE);
1317 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))) {
1321 /* see if a signal did it */
1322 if (signal_pending(current)) {
1328 current->state = TASK_RUNNING;
1329 remove_wait_queue(&info->delta_msr_wait, &wait);
1334 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1335 * Return: write counters to the user passed counter struct
1336 * NB: both 1->0 and 0->1 transitions are counted except for
1337 * RI where only 0->1 is counted.
1340 spin_lock_irqsave(&info->slock, flags);
1341 cnow = info->icount;
1342 spin_unlock_irqrestore(&info->slock, flags);
1343 p_cuser = (struct serial_icounter_struct *) arg;
1344 /* modified by casper 1/11/2000 */
1345 if (put_user(cnow.frame, &p_cuser->frame))
1347 if (put_user(cnow.brk, &p_cuser->brk))
1349 if (put_user(cnow.overrun, &p_cuser->overrun))
1351 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1353 if (put_user(cnow.parity, &p_cuser->parity))
1355 if (put_user(cnow.rx, &p_cuser->rx))
1357 if (put_user(cnow.tx, &p_cuser->tx))
1359 put_user(cnow.cts, &p_cuser->cts);
1360 put_user(cnow.dsr, &p_cuser->dsr);
1361 put_user(cnow.rng, &p_cuser->rng);
1362 put_user(cnow.dcd, &p_cuser->dcd);
1366 case MOXA_HighSpeedOn:
1367 return put_user(info->baud_base != 115200 ? 1 : 0, (int *) arg);
1369 case MOXA_SDS_RSTICOUNTER:{
1370 info->mon_data.rxcnt = 0;
1371 info->mon_data.txcnt = 0;
1374 // (above) added by James.
1375 case MOXA_ASPP_SETBAUD:{
1377 if (get_user(baud, (long *) arg))
1379 mxser_set_baud(info, baud);
1382 case MOXA_ASPP_GETBAUD:
1383 if (copy_to_user((long *) arg, &info->realbaud, sizeof(long)))
1388 case MOXA_ASPP_OQUEUE:{
1391 len = mxser_chars_in_buffer(tty);
1393 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1395 len += (lsr ? 0 : 1);
1397 if (copy_to_user((int *) arg, &len, sizeof(int)))
1402 case MOXA_ASPP_MON:{
1404 // info->mon_data.ser_param = tty->termios->c_cflag;
1406 status = mxser_get_msr(info->base, 1, info->port, info);
1407 mxser_check_modem_status(info, status);
1409 mcr = inb(info->base + UART_MCR);
1410 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1411 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1413 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1415 if (mcr & MOXA_MUST_MCR_TX_XON)
1416 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1418 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1420 if (info->tty->hw_stopped)
1421 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1423 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1426 if (copy_to_user((struct mxser_mon *) arg, &(info->mon_data), sizeof(struct mxser_mon)))
1433 case MOXA_ASPP_LSTATUS:{
1434 if (copy_to_user((struct mxser_mon *) arg, &(info->err_shadow), sizeof(unsigned char)))
1437 info->err_shadow = 0;
1441 case MOXA_SET_BAUD_METHOD:{
1443 if (get_user(method, (int *) arg))
1445 mxser_set_baud_method[info->port] = method;
1446 if (copy_to_user((int *) arg, &method, sizeof(int)))
1452 return -ENOIOCTLCMD;
1457 static int mxser_ioctl_special(unsigned int cmd, unsigned long arg)
1459 int i, result, status;
1463 if (copy_to_user((struct mxser_hwconf *) arg, mxsercfg, sizeof(struct mxser_hwconf) * 4))
1466 case MOXA_GET_MAJOR:
1467 if (copy_to_user((int *) arg, &ttymajor, sizeof(int)))
1471 case MOXA_GET_CUMAJOR:
1472 if (copy_to_user((int *) arg, &calloutmajor, sizeof(int)))
1476 case MOXA_CHKPORTENABLE:
1478 for (i = 0; i < MXSER_PORTS; i++) {
1479 if (mxvar_table[i].base)
1482 return put_user(result, (unsigned long *) arg);
1483 case MOXA_GETDATACOUNT:
1484 if (copy_to_user((struct mxser_log *) arg, &mxvar_log, sizeof(mxvar_log)))
1487 case MOXA_GETMSTATUS:
1488 for (i = 0; i < MXSER_PORTS; i++) {
1490 if (!mxvar_table[i].base) {
1491 GMStatus[i].dcd = 0;
1492 GMStatus[i].dsr = 0;
1493 GMStatus[i].cts = 0;
1497 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1498 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1500 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1502 status = inb(mxvar_table[i].base + UART_MSR);
1503 if (status & 0x80 /*UART_MSR_DCD */ )
1504 GMStatus[i].dcd = 1;
1506 GMStatus[i].dcd = 0;
1508 if (status & 0x20 /*UART_MSR_DSR */ )
1509 GMStatus[i].dsr = 1;
1511 GMStatus[i].dsr = 0;
1514 if (status & 0x10 /*UART_MSR_CTS */ )
1515 GMStatus[i].cts = 1;
1517 GMStatus[i].cts = 0;
1519 if (copy_to_user((struct mxser_mstatus *) arg, GMStatus, sizeof(struct mxser_mstatus) * MXSER_PORTS))
1522 case MOXA_ASPP_MON_EXT:{
1526 unsigned cflag, iflag;
1528 for (i = 0; i < MXSER_PORTS; i++) {
1530 if (!mxvar_table[i].base)
1533 status = mxser_get_msr(mxvar_table[i].base, 0, i, &(mxvar_table[i]));
1534 // mxser_check_modem_status(&mxvar_table[i], status);
1535 if (status & UART_MSR_TERI)
1536 mxvar_table[i].icount.rng++;
1537 if (status & UART_MSR_DDSR)
1538 mxvar_table[i].icount.dsr++;
1539 if (status & UART_MSR_DDCD)
1540 mxvar_table[i].icount.dcd++;
1541 if (status & UART_MSR_DCTS)
1542 mxvar_table[i].icount.cts++;
1544 mxvar_table[i].mon_data.modem_status = status;
1545 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1546 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1547 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1548 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1549 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1550 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1552 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1553 cflag = mxvar_table[i].normal_termios.c_cflag;
1554 iflag = mxvar_table[i].normal_termios.c_iflag;
1556 cflag = mxvar_table[i].tty->termios->c_cflag;
1557 iflag = mxvar_table[i].tty->termios->c_iflag;
1560 mon_data_ext.databits[i] = cflag & CSIZE;
1562 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1564 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1566 mon_data_ext.flowctrl[i] = 0x00;
1568 if (cflag & CRTSCTS)
1569 mon_data_ext.flowctrl[i] |= 0x03;
1571 if (iflag & (IXON | IXOFF))
1572 mon_data_ext.flowctrl[i] |= 0x0C;
1574 if (mxvar_table[i].type == PORT_16550A)
1575 mon_data_ext.fifo[i] = 1;
1577 mon_data_ext.fifo[i] = 0;
1581 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1582 opmode &= OP_MODE_MASK;
1584 mon_data_ext.iftype[i] = opmode;
1587 if (copy_to_user((struct mxser_mon_ext *) arg, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1594 return -ENOIOCTLCMD;
1600 static void mxser_stoprx(struct tty_struct *tty)
1602 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1603 //unsigned long flags;
1606 info->ldisc_stop_rx = 1;
1609 //MX_LOCK(&info->slock);
1610 // following add by Victor Yu. 09-02-2002
1611 if (info->IsMoxaMustChipFlag) {
1612 info->IER &= ~MOXA_MUST_RECV_ISR;
1613 outb(info->IER, info->base + UART_IER);
1615 // above add by Victor Yu. 09-02-2002
1617 info->x_char = STOP_CHAR(tty);
1618 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1619 outb(0, info->base + UART_IER);
1620 info->IER |= UART_IER_THRI;
1621 outb(info->IER, info->base + UART_IER); /* force Tx interrupt */
1622 } // add by Victor Yu. 09-02-2002
1623 //MX_UNLOCK(&info->slock);
1626 if (info->tty->termios->c_cflag & CRTSCTS) {
1627 //MX_LOCK(&info->slock);
1628 info->MCR &= ~UART_MCR_RTS;
1629 outb(info->MCR, info->base + UART_MCR);
1630 //MX_UNLOCK(&info->slock);
1634 static void mxser_startrx(struct tty_struct *tty)
1636 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1637 //unsigned long flags;
1639 info->ldisc_stop_rx = 0;
1644 //MX_LOCK(&info->slock);
1646 // following add by Victor Yu. 09-02-2002
1647 if (info->IsMoxaMustChipFlag) {
1648 info->IER |= MOXA_MUST_RECV_ISR;
1649 outb(info->IER, info->base + UART_IER);
1651 // above add by Victor Yu. 09-02-2002
1653 info->x_char = START_CHAR(tty);
1654 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1655 outb(0, info->base + UART_IER); // add by Victor Yu. 09-02-2002
1656 info->IER |= UART_IER_THRI; /* force Tx interrupt */
1657 outb(info->IER, info->base + UART_IER);
1658 } // add by Victor Yu. 09-02-2002
1659 //MX_UNLOCK(&info->slock);
1663 if (info->tty->termios->c_cflag & CRTSCTS) {
1664 //MX_LOCK(&info->slock);
1665 info->MCR |= UART_MCR_RTS;
1666 outb(info->MCR, info->base + UART_MCR);
1667 //MX_UNLOCK(&info->slock);
1672 * This routine is called by the upper-layer tty layer to signal that
1673 * incoming characters should be throttled.
1675 static void mxser_throttle(struct tty_struct *tty)
1677 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1678 //unsigned long flags;
1679 //MX_LOCK(&info->slock);
1681 //MX_UNLOCK(&info->slock);
1684 static void mxser_unthrottle(struct tty_struct *tty)
1686 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1687 //unsigned long flags;
1688 //MX_LOCK(&info->slock);
1690 //MX_UNLOCK(&info->slock);
1693 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1695 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1696 unsigned long flags;
1698 if ((tty->termios->c_cflag != old_termios->c_cflag) || (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1700 mxser_change_speed(info, old_termios);
1702 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
1703 tty->hw_stopped = 0;
1708 /* Handle sw stopped */
1709 if ((old_termios->c_iflag & IXON) && !(tty->termios->c_iflag & IXON)) {
1712 // following add by Victor Yu. 09-02-2002
1713 if (info->IsMoxaMustChipFlag) {
1714 spin_lock_irqsave(&info->slock, flags);
1715 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1716 spin_unlock_irqrestore(&info->slock, flags);
1718 // above add by Victor Yu. 09-02-2002
1725 * mxser_stop() and mxser_start()
1727 * This routines are called before setting or resetting tty->stopped.
1728 * They enable or disable transmitter interrupts, as necessary.
1730 static void mxser_stop(struct tty_struct *tty)
1732 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1733 unsigned long flags;
1735 spin_lock_irqsave(&info->slock, flags);
1736 if (info->IER & UART_IER_THRI) {
1737 info->IER &= ~UART_IER_THRI;
1738 outb(info->IER, info->base + UART_IER);
1740 spin_unlock_irqrestore(&info->slock, flags);
1743 static void mxser_start(struct tty_struct *tty)
1745 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1746 unsigned long flags;
1748 spin_lock_irqsave(&info->slock, flags);
1749 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1750 info->IER |= UART_IER_THRI;
1751 outb(info->IER, info->base + UART_IER);
1753 spin_unlock_irqrestore(&info->slock, flags);
1757 * mxser_wait_until_sent() --- wait until the transmitter is empty
1759 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1761 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1762 unsigned long orig_jiffies, char_time;
1765 if (info->type == PORT_UNKNOWN)
1768 if (info->xmit_fifo_size == 0)
1769 return; /* Just in case.... */
1771 orig_jiffies = jiffies;
1773 * Set the check interval to be 1/5 of the estimated time to
1774 * send a single character, and make it at least 1. The check
1775 * interval should also be less than the timeout.
1777 * Note: we have to use pretty tight timings here to satisfy
1780 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1781 char_time = char_time / 5;
1784 if (timeout && timeout < char_time)
1785 char_time = timeout;
1787 * If the transmitter hasn't cleared in twice the approximate
1788 * amount of time to send the entire FIFO, it probably won't
1789 * ever clear. This assumes the UART isn't doing flow
1790 * control, which is currently the case. Hence, if it ever
1791 * takes longer than info->timeout, this is probably due to a
1792 * UART bug of some kind. So, we clamp the timeout parameter at
1795 if (!timeout || timeout > 2 * info->timeout)
1796 timeout = 2 * info->timeout;
1797 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1798 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1799 printk("jiff=%lu...", jiffies);
1801 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1802 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1803 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1805 set_current_state(TASK_INTERRUPTIBLE);
1806 schedule_timeout(char_time);
1807 if (signal_pending(current))
1809 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1812 set_current_state(TASK_RUNNING);
1814 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1815 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1821 * This routine is called by tty_hangup() when a hangup is signaled.
1823 void mxser_hangup(struct tty_struct *tty)
1825 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1827 mxser_flush_buffer(tty);
1828 mxser_shutdown(info);
1831 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1833 wake_up_interruptible(&info->open_wait);
1837 // added by James 03-12-2004.
1839 * mxser_rs_break() --- routine which turns the break handling on or off
1841 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1843 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1844 unsigned long flags;
1846 spin_lock_irqsave(&info->slock, flags);
1847 if (break_state == -1)
1848 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
1850 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
1851 spin_unlock_irqrestore(&info->slock, flags);
1854 // (above) added by James.
1858 * This is the serial driver's generic interrupt routine
1860 static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1863 struct mxser_struct *info;
1864 struct mxser_struct *port;
1865 int max, irqbits, bits, msr;
1866 int pass_counter = 0;
1867 int handled = IRQ_NONE;
1870 //spin_lock(&gm_lock);
1872 for (i = 0; i < MXSER_BOARDS; i++) {
1873 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1879 if (i == MXSER_BOARDS) {
1885 max = mxser_numports[mxsercfg[i].board_type - 1];
1887 irqbits = inb(port->vector) & port->vectormask;
1888 if (irqbits == port->vectormask) {
1892 handled = IRQ_HANDLED;
1893 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1894 if (irqbits == port->vectormask) {
1901 // following add by Victor Yu. 09-13-2002
1902 iir = inb(info->base + UART_IIR);
1903 if (iir & UART_IIR_NO_INT)
1905 iir &= MOXA_MUST_IIR_MASK;
1907 status = inb(info->base + UART_LSR);
1908 outb(0x27, info->base + UART_FCR);
1909 inb(info->base + UART_MSR);
1912 // above add by Victor Yu. 09-13-2002
1914 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1915 info->IER |= MOXA_MUST_RECV_ISR;
1916 outb(info->IER, info->base + UART_IER);
1921 /* mask by Victor Yu. 09-13-2002
1923 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1926 /* mask by Victor Yu. 09-02-2002
1927 status = inb(info->base + UART_LSR) & info->read_status_mask;
1930 // following add by Victor Yu. 09-02-2002
1931 status = inb(info->base + UART_LSR);
1933 if (status & UART_LSR_PE) {
1934 info->err_shadow |= NPPI_NOTIFY_PARITY;
1936 if (status & UART_LSR_FE) {
1937 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1939 if (status & UART_LSR_OE) {
1940 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1942 if (status & UART_LSR_BI)
1943 info->err_shadow |= NPPI_NOTIFY_BREAK;
1945 if (info->IsMoxaMustChipFlag) {
1947 if ( (status & 0x02) && !(status & 0x01) ) {
1948 outb(info->base+UART_FCR, 0x23);
1952 if (iir == MOXA_MUST_IIR_GDA || iir == MOXA_MUST_IIR_RDA || iir == MOXA_MUST_IIR_RTO || iir == MOXA_MUST_IIR_LSR)
1953 mxser_receive_chars(info, &status);
1956 // above add by Victor Yu. 09-02-2002
1958 status &= info->read_status_mask;
1959 if (status & UART_LSR_DR)
1960 mxser_receive_chars(info, &status);
1962 msr = inb(info->base + UART_MSR);
1963 if (msr & UART_MSR_ANY_DELTA) {
1964 mxser_check_modem_status(info, msr);
1966 // following add by Victor Yu. 09-13-2002
1967 if (info->IsMoxaMustChipFlag) {
1968 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
1969 mxser_transmit_chars(info);
1972 // above add by Victor Yu. 09-13-2002
1974 if (status & UART_LSR_THRE) {
1975 /* 8-2-99 by William
1976 if ( info->x_char || (info->xmit_cnt > 0) )
1978 mxser_transmit_chars(info);
1982 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
1983 break; /* Prevent infinite loops */
1988 //spin_unlock(&gm_lock);
1992 static void mxser_receive_chars(struct mxser_struct *info, int *status)
1994 struct tty_struct *tty = info->tty;
1995 unsigned char ch, gdl;
2003 unsigned long flags;
2005 spin_lock_irqsave(&info->slock, flags);
2007 recv_room = tty->ldisc.receive_room(tty);
2008 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2009 //mxser_throttle(tty);
2014 cp = tty->flip.char_buf;
2015 fp = tty->flip.flag_buf;
2018 // following add by Victor Yu. 09-02-2002
2019 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2021 if (*status & UART_LSR_SPECIAL) {
2024 // following add by Victor Yu. 02-11-2004
2025 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID && (*status & MOXA_MUST_LSR_RERR))
2027 // above add by Victor Yu. 02-14-2004
2028 if (*status & MOXA_MUST_LSR_RERR)
2031 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2033 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID) // add by Victor Yu. 02-11-2004
2034 gdl &= MOXA_MUST_GDL_MASK;
2035 if (gdl >= recv_room) {
2036 if (!info->ldisc_stop_rx) {
2037 //mxser_throttle(tty);
2043 ch = inb(info->base + UART_RX);
2049 if((count>=HI_WATER) && (info->stop_rx==0)){
2058 // above add by Victor Yu. 09-02-2002
2064 if((count>=HI_WATER) && (info->stop_rx==0)){
2071 ch = inb(info->base + UART_RX);
2072 // following add by Victor Yu. 09-02-2002
2073 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2074 outb(0x23, info->base + UART_FCR);
2075 *status &= info->read_status_mask;
2076 // above add by Victor Yu. 09-02-2002
2077 if (*status & info->ignore_status_mask) {
2078 if (++ignored > 100)
2082 if (*status & UART_LSR_SPECIAL) {
2083 if (*status & UART_LSR_BI) {
2085 /* added by casper 1/11/2000 */
2089 if (info->flags & ASYNC_SAK)
2091 } else if (*status & UART_LSR_PE) {
2093 /* added by casper 1/11/2000 */
2094 info->icount.parity++;
2096 } else if (*status & UART_LSR_FE) {
2098 /* added by casper 1/11/2000 */
2099 info->icount.frame++;
2101 } else if (*status & UART_LSR_OE) {
2102 *fp++ = TTY_OVERRUN;
2103 /* added by casper 1/11/2000 */
2104 info->icount.overrun++;
2112 if (cnt >= recv_room) {
2113 if (!info->ldisc_stop_rx) {
2114 //mxser_throttle(tty);
2122 // following add by Victor Yu. 09-02-2002
2123 if (info->IsMoxaMustChipFlag)
2125 // above add by Victor Yu. 09-02-2002
2127 /* mask by Victor Yu. 09-02-2002
2128 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2130 // following add by Victor Yu. 09-02-2002
2131 *status = inb(info->base + UART_LSR);
2132 // above add by Victor Yu. 09-02-2002
2133 } while (*status & UART_LSR_DR);
2135 end_intr: // add by Victor Yu. 09-02-2002
2137 mxvar_log.rxcnt[info->port] += cnt;
2138 info->mon_data.rxcnt += cnt;
2139 info->mon_data.up_rxcnt += cnt;
2141 tty->ldisc.receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
2142 spin_unlock_irqrestore(&info->slock, flags);
2146 static void mxser_transmit_chars(struct mxser_struct *info)
2149 unsigned long flags;
2151 spin_lock_irqsave(&info->slock, flags);
2154 outb(info->x_char, info->base + UART_TX);
2156 mxvar_log.txcnt[info->port]++;
2157 info->mon_data.txcnt++;
2158 info->mon_data.up_txcnt++;
2160 /* added by casper 1/11/2000 */
2163 spin_unlock_irqrestore(&info->slock, flags);
2167 if (info->xmit_buf == 0) {
2168 spin_unlock_irqrestore(&info->slock, flags);
2172 if ((info->xmit_cnt <= 0) || info->tty->stopped || (info->tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag))) {
2173 info->IER &= ~UART_IER_THRI;
2174 outb(info->IER, info->base + UART_IER);
2175 spin_unlock_irqrestore(&info->slock, flags);
2179 cnt = info->xmit_cnt;
2180 count = info->xmit_fifo_size;
2182 outb(info->xmit_buf[info->xmit_tail++], info->base + UART_TX);
2183 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2184 if (--info->xmit_cnt <= 0)
2186 } while (--count > 0);
2187 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2189 // added by James 03-12-2004.
2190 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2191 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2192 // (above) added by James.
2194 /* added by casper 1/11/2000 */
2195 info->icount.tx += (cnt - info->xmit_cnt);
2198 if (info->xmit_cnt < WAKEUP_CHARS) {
2199 set_bit(MXSER_EVENT_TXLOW, &info->event);
2200 schedule_work(&info->tqueue);
2202 if (info->xmit_cnt <= 0) {
2203 info->IER &= ~UART_IER_THRI;
2204 outb(info->IER, info->base + UART_IER);
2206 spin_unlock_irqrestore(&info->slock, flags);
2209 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2211 /* update input line counters */
2212 if (status & UART_MSR_TERI)
2214 if (status & UART_MSR_DDSR)
2216 if (status & UART_MSR_DDCD)
2218 if (status & UART_MSR_DCTS)
2220 info->mon_data.modem_status = status;
2221 wake_up_interruptible(&info->delta_msr_wait);
2224 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2225 if (status & UART_MSR_DCD)
2226 wake_up_interruptible(&info->open_wait);
2227 schedule_work(&info->tqueue);
2230 if (info->flags & ASYNC_CTS_FLOW) {
2231 if (info->tty->hw_stopped) {
2232 if (status & UART_MSR_CTS) {
2233 info->tty->hw_stopped = 0;
2235 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2236 info->IER |= UART_IER_THRI;
2237 outb(info->IER, info->base + UART_IER);
2239 set_bit(MXSER_EVENT_TXLOW, &info->event);
2240 schedule_work(&info->tqueue); }
2242 if (!(status & UART_MSR_CTS)) {
2243 info->tty->hw_stopped = 1;
2244 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2245 info->IER &= ~UART_IER_THRI;
2246 outb(info->IER, info->base + UART_IER);
2253 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2255 DECLARE_WAITQUEUE(wait, current);
2258 unsigned long flags;
2261 * If non-blocking mode is set, or the port is not enabled,
2262 * then make the check up front and then exit.
2264 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2265 info->flags |= ASYNC_NORMAL_ACTIVE;
2269 if (tty->termios->c_cflag & CLOCAL)
2273 * Block waiting for the carrier detect and the line to become
2274 * free (i.e., not in use by the callout). While we are in
2275 * this loop, info->count is dropped by one, so that
2276 * mxser_close() knows when to free things. We restore it upon
2277 * exit, either normal or abnormal.
2280 add_wait_queue(&info->open_wait, &wait);
2282 spin_lock_irqsave(&info->slock, flags);
2283 if (!tty_hung_up_p(filp))
2285 spin_unlock_irqrestore(&info->slock, flags);
2286 info->blocked_open++;
2288 spin_lock_irqsave(&info->slock, flags);
2289 outb(inb(info->base + UART_MCR) | UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2290 spin_unlock_irqrestore(&info->slock, flags);
2291 set_current_state(TASK_INTERRUPTIBLE);
2292 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2293 if (info->flags & ASYNC_HUP_NOTIFY)
2296 retval = -ERESTARTSYS;
2299 if (!(info->flags & ASYNC_CLOSING) && (do_clocal || (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2301 if (signal_pending(current)) {
2302 retval = -ERESTARTSYS;
2307 set_current_state(TASK_RUNNING);
2308 remove_wait_queue(&info->open_wait, &wait);
2309 if (!tty_hung_up_p(filp))
2311 info->blocked_open--;
2314 info->flags |= ASYNC_NORMAL_ACTIVE;
2318 static int mxser_startup(struct mxser_struct *info)
2322 unsigned long flags;
2324 page = __get_free_page(GFP_KERNEL);
2328 spin_lock_irqsave(&info->slock, flags);
2330 if (info->flags & ASYNC_INITIALIZED) {
2332 spin_unlock_irqrestore(&info->slock, flags);
2336 if (!info->base || !info->type) {
2338 set_bit(TTY_IO_ERROR, &info->tty->flags);
2340 spin_unlock_irqrestore(&info->slock, flags);
2346 info->xmit_buf = (unsigned char *) page;
2349 * Clear the FIFO buffers and disable them
2350 * (they will be reenabled in mxser_change_speed())
2352 if (info->IsMoxaMustChipFlag)
2353 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2355 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2358 * At this point there's no way the LSR could still be 0xFF;
2359 * if it is, then bail out, because there's likely no UART
2362 if (inb(info->base + UART_LSR) == 0xff) {
2363 spin_unlock_irqrestore(&info->slock, flags);
2364 if (capable(CAP_SYS_ADMIN)) {
2366 set_bit(TTY_IO_ERROR, &info->tty->flags);
2373 * Clear the interrupt registers.
2375 (void) inb(info->base + UART_LSR);
2376 (void) inb(info->base + UART_RX);
2377 (void) inb(info->base + UART_IIR);
2378 (void) inb(info->base + UART_MSR);
2381 * Now, initialize the UART
2383 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2384 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2385 outb(info->MCR, info->base + UART_MCR);
2388 * Finally, enable interrupts
2390 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2391 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2393 // following add by Victor Yu. 08-30-2002
2394 if (info->IsMoxaMustChipFlag)
2395 info->IER |= MOXA_MUST_IER_EGDAI;
2396 // above add by Victor Yu. 08-30-2002
2397 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2400 * And clear the interrupt registers again for luck.
2402 (void) inb(info->base + UART_LSR);
2403 (void) inb(info->base + UART_RX);
2404 (void) inb(info->base + UART_IIR);
2405 (void) inb(info->base + UART_MSR);
2408 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2409 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2412 * and set the speed of the serial port
2414 spin_unlock_irqrestore(&info->slock, flags);
2415 mxser_change_speed(info, 0);
2417 info->flags |= ASYNC_INITIALIZED;
2422 * This routine will shutdown a serial port; interrupts maybe disabled, and
2423 * DTR is dropped if the hangup on close termio flag is on.
2425 static void mxser_shutdown(struct mxser_struct *info)
2427 unsigned long flags;
2429 if (!(info->flags & ASYNC_INITIALIZED))
2432 spin_lock_irqsave(&info->slock, flags);
2435 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2436 * here so the queue might never be waken up
2438 wake_up_interruptible(&info->delta_msr_wait);
2441 * Free the IRQ, if necessary
2443 if (info->xmit_buf) {
2444 free_page((unsigned long) info->xmit_buf);
2449 outb(0x00, info->base + UART_IER);
2451 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2452 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2453 outb(info->MCR, info->base + UART_MCR);
2455 /* clear Rx/Tx FIFO's */
2456 // following add by Victor Yu. 08-30-2002
2457 if (info->IsMoxaMustChipFlag)
2458 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2460 // above add by Victor Yu. 08-30-2002
2461 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2463 /* read data port to reset things */
2464 (void) inb(info->base + UART_RX);
2467 set_bit(TTY_IO_ERROR, &info->tty->flags);
2469 info->flags &= ~ASYNC_INITIALIZED;
2471 // following add by Victor Yu. 09-23-2002
2472 if (info->IsMoxaMustChipFlag) {
2473 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2475 // above add by Victor Yu. 09-23-2002
2477 spin_unlock_irqrestore(&info->slock, flags);
2481 * This routine is called to set the UART divisor registers to match
2482 * the specified baud rate for a serial port.
2484 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2486 unsigned cflag, cval, fcr;
2488 unsigned char status;
2490 unsigned long flags;
2493 if (!info->tty || !info->tty->termios)
2495 cflag = info->tty->termios->c_cflag;
2501 #define B921600 (B460800 +1)
2503 if (mxser_set_baud_method[info->port] == 0) {
2504 switch (cflag & (CBAUD | CBAUDEX)) {
2569 mxser_set_baud(info, baud);
2572 /* byte size and parity */
2573 switch (cflag & CSIZE) {
2588 break; /* too keep GCC shut... */
2593 cval |= UART_LCR_PARITY;
2595 #define CMSPAR 010000000000
2597 if (!(cflag & PARODD)) {
2598 cval |= UART_LCR_EPAR;
2601 cval |= UART_LCR_SPAR;
2603 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2604 if (info->IsMoxaMustChipFlag) {
2605 fcr = UART_FCR_ENABLE_FIFO;
2606 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2607 SET_MOXA_MUST_FIFO_VALUE(info);
2611 fcr = UART_FCR_ENABLE_FIFO;
2612 // following add by Victor Yu. 08-30-2002
2613 if (info->IsMoxaMustChipFlag) {
2614 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2615 SET_MOXA_MUST_FIFO_VALUE(info);
2617 // above add by Victor Yu. 08-30-2002
2619 switch (info->rx_trigger) {
2621 fcr |= UART_FCR_TRIGGER_1;
2624 fcr |= UART_FCR_TRIGGER_4;
2627 fcr |= UART_FCR_TRIGGER_8;
2630 fcr |= UART_FCR_TRIGGER_14;
2636 /* CTS flow control flag and modem status interrupts */
2637 info->IER &= ~UART_IER_MSI;
2638 info->MCR &= ~UART_MCR_AFE;
2639 if (cflag & CRTSCTS) {
2640 info->flags |= ASYNC_CTS_FLOW;
2641 info->IER |= UART_IER_MSI;
2642 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2643 info->MCR |= UART_MCR_AFE;
2644 //status = mxser_get_msr(info->base, 0, info->port);
2645 /* save_flags(flags);
2647 status = inb(baseaddr + UART_MSR);
2648 restore_flags(flags);*/
2649 //mxser_check_modem_status(info, status);
2651 //status = mxser_get_msr(info->base, 0, info->port);
2653 //MX_LOCK(&info->slock);
2654 status = inb(info->base + UART_MSR);
2655 //MX_UNLOCK(&info->slock);
2656 if (info->tty->hw_stopped) {
2657 if (status & UART_MSR_CTS) {
2658 info->tty->hw_stopped = 0;
2659 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2660 info->IER |= UART_IER_THRI;
2661 outb(info->IER, info->base + UART_IER);
2663 set_bit(MXSER_EVENT_TXLOW, &info->event);
2664 schedule_work(&info->tqueue); }
2666 if (!(status & UART_MSR_CTS)) {
2667 info->tty->hw_stopped = 1;
2668 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2669 info->IER &= ~UART_IER_THRI;
2670 outb(info->IER, info->base + UART_IER);
2676 info->flags &= ~ASYNC_CTS_FLOW;
2678 outb(info->MCR, info->base + UART_MCR);
2679 if (cflag & CLOCAL) {
2680 info->flags &= ~ASYNC_CHECK_CD;
2682 info->flags |= ASYNC_CHECK_CD;
2683 info->IER |= UART_IER_MSI;
2685 outb(info->IER, info->base + UART_IER);
2688 * Set up parity check flag
2690 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2691 if (I_INPCK(info->tty))
2692 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2693 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2694 info->read_status_mask |= UART_LSR_BI;
2696 info->ignore_status_mask = 0;
2698 if (I_IGNBRK(info->tty)) {
2699 info->ignore_status_mask |= UART_LSR_BI;
2700 info->read_status_mask |= UART_LSR_BI;
2702 * If we're ignore parity and break indicators, ignore
2703 * overruns too. (For real raw support).
2705 if (I_IGNPAR(info->tty)) {
2706 info->ignore_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
2707 info->read_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
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;
2775 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2776 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2779 spin_lock_irqsave(&info->slock, flags);
2780 info->MCR |= UART_MCR_DTR;
2781 outb(info->MCR, info->base + UART_MCR);
2782 spin_unlock_irqrestore(&info->slock, flags);
2784 spin_lock_irqsave(&info->slock, flags);
2785 info->MCR &= ~UART_MCR_DTR;
2786 outb(info->MCR, info->base + UART_MCR);
2787 spin_unlock_irqrestore(&info->slock, flags);
2791 cval = inb(info->base + UART_LCR);
2793 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2795 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2796 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2797 outb(cval, info->base + UART_LCR); /* reset DLAB */
2806 * ------------------------------------------------------------
2807 * friends of mxser_ioctl()
2808 * ------------------------------------------------------------
2810 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct *retinfo)
2812 struct serial_struct tmp;
2816 memset(&tmp, 0, sizeof(tmp));
2817 tmp.type = info->type;
2818 tmp.line = info->port;
2819 tmp.port = info->base;
2820 tmp.irq = info->irq;
2821 tmp.flags = info->flags;
2822 tmp.baud_base = info->baud_base;
2823 tmp.close_delay = info->close_delay;
2824 tmp.closing_wait = info->closing_wait;
2825 tmp.custom_divisor = info->custom_divisor;
2827 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2832 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct *new_info)
2834 struct serial_struct new_serial;
2838 if (!new_info || !info->base)
2840 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2843 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))
2846 flags = info->flags & ASYNC_SPD_MASK;
2848 if (!capable(CAP_SYS_ADMIN)) {
2849 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)))
2851 info->flags = ((info->flags & ~ASYNC_USR_MASK) | (new_serial.flags & ASYNC_USR_MASK));
2854 * OK, past this point, all the error checking has been done.
2855 * At this point, we start making changes.....
2857 info->flags = ((info->flags & ~ASYNC_FLAGS) | (new_serial.flags & ASYNC_FLAGS));
2858 info->close_delay = new_serial.close_delay * HZ / 100;
2859 info->closing_wait = new_serial.closing_wait * HZ / 100;
2860 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2861 info->tty->low_latency = 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2864 /* added by casper, 3/17/2000, for mouse */
2865 info->type = new_serial.type;
2867 process_txrx_fifo(info);
2870 if (info->flags & ASYNC_INITIALIZED) {
2871 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2872 mxser_change_speed(info, 0);
2875 retval = mxser_startup(info);
2881 * mxser_get_lsr_info - get line status register info
2883 * Purpose: Let user call ioctl() to get info when the UART physically
2884 * is emptied. On bus types like RS485, the transmitter must
2885 * release the bus after transmitting. This must be done when
2886 * the transmit shift register is empty, not be done when the
2887 * transmit holding register is empty. This functionality
2888 * allows an RS485 driver to be written in user space.
2890 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int *value)
2892 unsigned char status;
2893 unsigned int result;
2894 unsigned long flags;
2896 spin_lock_irqsave(&info->slock, flags);
2897 status = inb(info->base + UART_LSR);
2898 spin_unlock_irqrestore(&info->slock, flags);
2899 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2900 return put_user(result, value);
2904 * This routine sends a break character out the serial port.
2906 static void mxser_send_break(struct mxser_struct *info, int duration)
2908 unsigned long flags;
2912 set_current_state(TASK_INTERRUPTIBLE);
2913 spin_lock_irqsave(&info->slock, flags);
2914 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
2915 spin_unlock_irqrestore(&info->slock, flags);
2916 schedule_timeout(duration);
2917 spin_lock_irqsave(&info->slock, flags);
2918 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
2919 spin_unlock_irqrestore(&info->slock, flags);
2922 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2924 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2925 unsigned char control, status;
2926 unsigned long flags;
2929 if (tty->index == MXSER_PORTS)
2930 return (-ENOIOCTLCMD);
2931 if (tty->flags & (1 << TTY_IO_ERROR))
2934 control = info->MCR;
2936 spin_lock_irqsave(&info->slock, flags);
2937 status = inb(info->base + UART_MSR);
2938 if (status & UART_MSR_ANY_DELTA)
2939 mxser_check_modem_status(info, status);
2940 spin_unlock_irqrestore(&info->slock, flags);
2941 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2942 ((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);
2945 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2947 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2948 unsigned long flags;
2951 if (tty->index == MXSER_PORTS)
2952 return -ENOIOCTLCMD;
2953 if (tty->flags & (1 << TTY_IO_ERROR))
2956 spin_lock_irqsave(&info->slock, flags);
2958 if (set & TIOCM_RTS)
2959 info->MCR |= UART_MCR_RTS;
2960 if (set & TIOCM_DTR)
2961 info->MCR |= UART_MCR_DTR;
2963 if (clear & TIOCM_RTS)
2964 info->MCR &= ~UART_MCR_RTS;
2965 if (clear & TIOCM_DTR)
2966 info->MCR &= ~UART_MCR_DTR;
2968 outb(info->MCR, info->base + UART_MCR);
2969 spin_unlock_irqrestore(&info->slock, flags);
2974 static int mxser_read_register(int, unsigned short *);
2975 static int mxser_program_mode(int);
2976 static void mxser_normal_mode(int);
2978 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2981 unsigned short regs[16], irq;
2982 unsigned char scratch, scratch2;
2984 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2986 id = mxser_read_register(cap, regs);
2987 if (id == C168_ASIC_ID) {
2988 hwconf->board_type = MXSER_BOARD_C168_ISA;
2990 } else if (id == C104_ASIC_ID) {
2991 hwconf->board_type = MXSER_BOARD_C104_ISA;
2993 } else if (id == C102_ASIC_ID) {
2994 hwconf->board_type = MXSER_BOARD_C102_ISA;
2996 } else if (id == CI132_ASIC_ID) {
2997 hwconf->board_type = MXSER_BOARD_CI132;
2999 } else if (id == CI134_ASIC_ID) {
3000 hwconf->board_type = MXSER_BOARD_CI134;
3002 } else if (id == CI104J_ASIC_ID) {
3003 hwconf->board_type = MXSER_BOARD_CI104J;
3009 if (hwconf->ports == 2) {
3010 irq = regs[9] & 0xF000;
3011 irq = irq | (irq >> 4);
3012 if (irq != (regs[9] & 0xFF00))
3013 return (MXSER_ERR_IRQ_CONFLIT);
3014 } else if (hwconf->ports == 4) {
3015 irq = regs[9] & 0xF000;
3016 irq = irq | (irq >> 4);
3017 irq = irq | (irq >> 8);
3019 return (MXSER_ERR_IRQ_CONFLIT);
3020 } else if (hwconf->ports == 8) {
3021 irq = regs[9] & 0xF000;
3022 irq = irq | (irq >> 4);
3023 irq = irq | (irq >> 8);
3024 if ((irq != regs[9]) || (irq != regs[10]))
3025 return (MXSER_ERR_IRQ_CONFLIT);
3029 return (MXSER_ERR_IRQ);
3031 hwconf->irq = ((int) (irq & 0xF000) >> 12);
3032 for (i = 0; i < 8; i++)
3033 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3034 if ((regs[12] & 0x80) == 0) {
3035 return (MXSER_ERR_VECTOR);
3037 hwconf->vector = (int) regs[11]; /* interrupt vector */
3039 hwconf->vector_mask = 0x00FF;
3041 hwconf->vector_mask = 0x000F;
3042 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3043 if (regs[12] & bits) {
3044 hwconf->baud_base[i] = 921600;
3045 hwconf->MaxCanSetBaudRate[i] = 921600; // add by Victor Yu. 09-04-2002
3047 hwconf->baud_base[i] = 115200;
3048 hwconf->MaxCanSetBaudRate[i] = 115200; // add by Victor Yu. 09-04-2002
3051 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3052 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3053 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3054 outb(scratch2, cap + UART_LCR);
3055 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3056 scratch = inb(cap + UART_IIR);
3059 hwconf->uart_type = PORT_16550A;
3061 hwconf->uart_type = PORT_16450;
3066 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3067 request_region(hwconf->vector, 1, "mxser(vector)");
3068 return (hwconf->ports);
3071 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3072 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3073 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3074 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3075 #define EN_CCMD 0x000 /* Chip's command register */
3076 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3077 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3078 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3079 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3080 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3081 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3082 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3083 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3084 static int mxser_read_register(int port, unsigned short *regs)
3086 int i, k, value, id;
3089 id = mxser_program_mode(port);
3092 for (i = 0; i < 14; i++) {
3093 k = (i & 0x3F) | 0x180;
3094 for (j = 0x100; j > 0; j >>= 1) {
3095 outb(CHIP_CS, port);
3097 outb(CHIP_CS | CHIP_DO, port);
3098 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3100 outb(CHIP_CS, port);
3101 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3106 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3107 outb(CHIP_CS, port);
3108 outb(CHIP_CS | CHIP_SK, port);
3109 if (inb(port) & CHIP_DI)
3115 mxser_normal_mode(port);
3119 static int mxser_program_mode(int port)
3122 //unsigned long flags;
3124 spin_lock(&gm_lock);
3132 //restore_flags(flags);
3133 spin_unlock(&gm_lock);
3135 id = inb(port + 1) & 0x1F;
3136 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))
3138 for (i = 0, j = 0; i < 4; i++) {
3142 } else if ((j == 1) && (n == 1)) {
3153 static void mxser_normal_mode(int port)
3157 outb(0xA5, port + 1);
3158 outb(0x80, port + 3);
3159 outb(12, port + 0); /* 9600 bps */
3161 outb(0x03, port + 3); /* 8 data bits */
3162 outb(0x13, port + 4); /* loop back mode */
3163 for (i = 0; i < 16; i++) {
3165 if ((n & 0x61) == 0x60)
3170 outb(0x00, port + 4);
3173 // added by James 03-05-2004.
3174 // for secure device server:
3175 // stat = 1, the port8 DTR is set to ON.
3176 // stat = 0, the port8 DTR is set to OFF.
3177 void SDS_PORT8_DTR(int stat)
3180 _sds_oldmcr = inb(mxvar_table[7].base + UART_MCR); // get old MCR
3182 outb(_sds_oldmcr | 0x01, mxvar_table[7].base + UART_MCR); // set DTR ON
3185 outb(_sds_oldmcr & 0xfe, mxvar_table[7].base + UART_MCR); // set DTR OFF
3190 module_init(mxser_module_init);
3191 module_exit(mxser_module_exit);