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/bitops.h>
67 #include <asm/uaccess.h>
71 #define MXSER_VERSION "1.8"
72 #define MXSERMAJOR 174
73 #define MXSERCUMAJOR 175
75 #define MXSER_EVENT_TXLOW 1
76 #define MXSER_EVENT_HANGUP 2
78 #define MXSER_BOARDS 4 /* Max. boards */
79 #define MXSER_PORTS 32 /* Max. ports */
80 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
81 #define MXSER_ISR_PASS_LIMIT 256
83 #define MXSER_ERR_IOADDR -1
84 #define MXSER_ERR_IRQ -2
85 #define MXSER_ERR_IRQ_CONFLIT -3
86 #define MXSER_ERR_VECTOR -4
88 #define SERIAL_TYPE_NORMAL 1
89 #define SERIAL_TYPE_CALLOUT 2
91 #define WAKEUP_CHARS 256
93 #define UART_MCR_AFE 0x20
94 #define UART_LSR_SPECIAL 0x1E
96 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|IXON|IXOFF))
98 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
100 #define C168_ASIC_ID 1
101 #define C104_ASIC_ID 2
102 #define C102_ASIC_ID 0xB
103 #define CI132_ASIC_ID 4
104 #define CI134_ASIC_ID 3
105 #define CI104J_ASIC_ID 5
108 MXSER_BOARD_C168_ISA = 1,
109 MXSER_BOARD_C104_ISA,
111 MXSER_BOARD_C168_PCI,
112 MXSER_BOARD_C104_PCI,
113 MXSER_BOARD_C102_ISA,
131 static char *mxser_brdname[] = {
149 "Moxa UC7000 Serial",
155 static int mxser_numports[] = {
179 #define UART_TYPE_NUM 2
181 static const unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
182 MOXA_MUST_MU150_HWID,
186 // This is only for PCI
187 #define UART_INFO_NUM 3
188 struct mxpciuart_info {
199 static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
200 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
201 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
202 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
208 static struct pci_device_id mxser_pcibrds[] = {
209 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
210 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
211 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
212 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
213 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
214 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
215 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
216 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
217 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
218 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
219 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
220 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
221 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
222 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
223 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
227 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
232 typedef struct _moxa_pci_info {
233 unsigned short busNum;
234 unsigned short devNum;
235 struct pci_dev *pdev; // add by Victor Yu. 06-23-2003
238 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
239 static int ttymajor = MXSERMAJOR;
240 static int calloutmajor = MXSERCUMAJOR;
241 static int verbose = 0;
243 /* Variables for insmod */
245 MODULE_AUTHOR("Casper Yang");
246 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
247 MODULE_PARM(ioaddr, "1-4i");
248 MODULE_PARM(ttymajor, "i");
249 MODULE_PARM(calloutmajor, "i");
250 MODULE_PARM(verbose, "i");
251 MODULE_LICENSE("GPL");
255 unsigned long rxcnt[MXSER_PORTS];
256 unsigned long txcnt[MXSER_PORTS];
263 unsigned long up_rxcnt;
264 unsigned long up_txcnt;
266 unsigned char hold_reason;
269 struct mxser_mon_ext {
270 unsigned long rx_cnt[32];
271 unsigned long tx_cnt[32];
272 unsigned long up_rxcnt[32];
273 unsigned long up_txcnt[32];
274 int modem_status[32];
284 struct mxser_hwconf {
291 int ioaddr[MXSER_PORTS_PER_BOARD];
292 int baud_base[MXSER_PORTS_PER_BOARD];
293 moxa_pci_info pciInfo;
294 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
295 int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 09-04-2002
296 int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; // add by Victor Yu. 01-05-2004
299 struct mxser_struct {
301 int base; /* port base address */
302 int irq; /* port using irq no. */
303 int vector; /* port irq vector */
304 int vectormask; /* port vector mask */
306 int rx_trigger; /* Rx fifo trigger level */
308 int baud_base; /* max. speed */
309 int flags; /* defined in tty.h */
310 int type; /* UART type */
311 struct tty_struct *tty;
312 int read_status_mask;
313 int ignore_status_mask;
316 int x_char; /* xon/xoff character */
318 unsigned short closing_wait;
319 int IER; /* Interrupt Enable Register */
320 int MCR; /* Modem control register */
322 int count; /* # of fd on device */
323 int blocked_open; /* # of blocked opens */
324 long session; /* Session of opening process */
325 long pgrp; /* pgrp of opening process */
326 unsigned char *xmit_buf;
330 struct work_struct tqueue;
331 struct termios normal_termios;
332 struct termios callout_termios;
333 wait_queue_head_t open_wait;
334 wait_queue_head_t close_wait;
335 wait_queue_head_t delta_msr_wait;
336 struct async_icount icount; /* kernel counters for the 4 input interrupts */
338 int IsMoxaMustChipFlag; // add by Victor Yu. 08-30-2002
339 int MaxCanSetBaudRate; // add by Victor Yu. 09-04-2002
340 int opmode_ioaddr; // add by Victor Yu. 01-05-2004
341 unsigned char stop_rx;
342 unsigned char ldisc_stop_rx;
344 struct mxser_mon mon_data;
345 unsigned char err_shadow;
350 struct mxser_mstatus {
358 static struct mxser_mstatus GMStatus[MXSER_PORTS];
360 static int mxserBoardCAP[MXSER_BOARDS] = {
362 /* 0x180, 0x280, 0x200, 0x320 */
365 static struct tty_driver *mxvar_sdriver;
366 static struct mxser_struct mxvar_table[MXSER_PORTS];
367 static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
368 static struct termios *mxvar_termios[MXSER_PORTS + 1];
369 static struct termios *mxvar_termios_locked[MXSER_PORTS + 1];
370 static struct mxser_log mxvar_log;
371 static int mxvar_diagflag;
372 static unsigned char mxser_msr[MXSER_PORTS + 1];
373 static struct mxser_mon_ext mon_data_ext;
374 static int mxser_set_baud_method[MXSER_PORTS + 1];
375 static spinlock_t gm_lock;
378 * This is used to figure out the divisor speeds and the timeouts
381 static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
387 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
388 static int mxser_init(void);
390 //static void mxser_poll(unsigned long);
391 static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
392 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
393 static void mxser_do_softint(void *);
394 static int mxser_open(struct tty_struct *, struct file *);
395 static void mxser_close(struct tty_struct *, struct file *);
396 static int mxser_write(struct tty_struct *, const unsigned char *, int);
397 static int mxser_write_room(struct tty_struct *);
398 static void mxser_flush_buffer(struct tty_struct *);
399 static int mxser_chars_in_buffer(struct tty_struct *);
400 static void mxser_flush_chars(struct tty_struct *);
401 static void mxser_put_char(struct tty_struct *, unsigned char);
402 static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
403 static int mxser_ioctl_special(unsigned int, void __user *);
404 static void mxser_throttle(struct tty_struct *);
405 static void mxser_unthrottle(struct tty_struct *);
406 static void mxser_set_termios(struct tty_struct *, struct termios *);
407 static void mxser_stop(struct tty_struct *);
408 static void mxser_start(struct tty_struct *);
409 static void mxser_hangup(struct tty_struct *);
410 static void mxser_rs_break(struct tty_struct *, int);
411 static irqreturn_t mxser_interrupt(int, void *, struct pt_regs *);
412 static void mxser_receive_chars(struct mxser_struct *, int *);
413 static void mxser_transmit_chars(struct mxser_struct *);
414 static void mxser_check_modem_status(struct mxser_struct *, int);
415 static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
416 static int mxser_startup(struct mxser_struct *);
417 static void mxser_shutdown(struct mxser_struct *);
418 static int mxser_change_speed(struct mxser_struct *, struct termios *old_termios);
419 static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
420 static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
421 static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
422 static void mxser_send_break(struct mxser_struct *, int);
423 static int mxser_tiocmget(struct tty_struct *, struct file *);
424 static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
425 static int mxser_set_baud(struct mxser_struct *info, long newspd);
426 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
428 static void mxser_startrx(struct tty_struct *tty);
429 static void mxser_stoprx(struct tty_struct *tty);
432 static int CheckIsMoxaMust(int io)
437 outb(0, io + UART_LCR);
438 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
439 oldmcr = inb(io + UART_MCR);
440 outb(0, io + UART_MCR);
441 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
442 if ((hwid = inb(io + UART_MCR)) != 0) {
443 outb(oldmcr, io + UART_MCR);
444 return (MOXA_OTHER_UART);
447 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
448 for (i = 0; i < UART_TYPE_NUM; i++) {
449 if (hwid == Gmoxa_uart_id[i])
452 return MOXA_OTHER_UART;
455 // above is modified by Victor Yu. 08-15-2002
457 static struct tty_operations mxser_ops = {
459 .close = mxser_close,
460 .write = mxser_write,
461 .put_char = mxser_put_char,
462 .flush_chars = mxser_flush_chars,
463 .write_room = mxser_write_room,
464 .chars_in_buffer = mxser_chars_in_buffer,
465 .flush_buffer = mxser_flush_buffer,
466 .ioctl = mxser_ioctl,
467 .throttle = mxser_throttle,
468 .unthrottle = mxser_unthrottle,
469 .set_termios = mxser_set_termios,
471 .start = mxser_start,
472 .hangup = mxser_hangup,
473 .tiocmget = mxser_tiocmget,
474 .tiocmset = mxser_tiocmset,
478 * The MOXA Smartio/Industio serial driver boot-time initialization code!
481 static int __init mxser_module_init(void)
486 printk(KERN_DEBUG "Loading module mxser ...\n");
489 printk(KERN_DEBUG "Done.\n");
493 static void __exit mxser_module_exit(void)
498 printk(KERN_DEBUG "Unloading module mxser ...\n");
500 if ((err |= tty_unregister_driver(mxvar_sdriver)))
501 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
503 for (i = 0; i < MXSER_BOARDS; i++) {
504 struct pci_dev *pdev;
506 if (mxsercfg[i].board_type == -1)
509 pdev = mxsercfg[i].pciInfo.pdev;
510 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
511 if (pdev != NULL) { //PCI
512 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
513 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
515 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
516 release_region(mxsercfg[i].vector, 1);
521 printk(KERN_DEBUG "Done.\n");
525 static void process_txrx_fifo(struct mxser_struct *info)
529 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
530 info->rx_trigger = 1;
531 info->rx_high_water = 1;
532 info->rx_low_water = 1;
533 info->xmit_fifo_size = 1;
535 for (i = 0; i < UART_INFO_NUM; i++) {
536 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
537 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
538 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
539 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
540 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
547 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
549 struct mxser_struct *info;
553 n = board * MXSER_PORTS_PER_BOARD;
554 info = &mxvar_table[n];
556 printk(KERN_DEBUG " ttyM%d - ttyM%d ", n, n + hwconf->ports - 1);
557 printk(" max. baud rate = %d bps.\n", hwconf->MaxCanSetBaudRate[0]);
560 for (i = 0; i < hwconf->ports; i++, n++, info++) {
562 info->base = hwconf->ioaddr[i];
563 info->irq = hwconf->irq;
564 info->vector = hwconf->vector;
565 info->vectormask = hwconf->vector_mask;
566 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; // add by Victor Yu. 01-05-2004
568 info->ldisc_stop_rx = 0;
570 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
571 //Enhance mode enabled here
572 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
573 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
576 info->flags = ASYNC_SHARE_IRQ;
577 info->type = hwconf->uart_type;
578 info->baud_base = hwconf->baud_base[i];
580 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
582 process_txrx_fifo(info);
585 info->custom_divisor = hwconf->baud_base[i] * 16;
586 info->close_delay = 5 * HZ / 10;
587 info->closing_wait = 30 * HZ;
588 INIT_WORK(&info->tqueue, mxser_do_softint, info);
589 info->normal_termios = mxvar_sdriver->init_termios;
590 init_waitqueue_head(&info->open_wait);
591 init_waitqueue_head(&info->close_wait);
592 init_waitqueue_head(&info->delta_msr_wait);
593 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
594 info->err_shadow = 0;
595 spin_lock_init(&info->slock);
598 * Allocate the IRQ if necessary
602 /* before set INT ISR, disable all int */
603 for (i = 0; i < hwconf->ports; i++) {
604 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0, hwconf->ioaddr[i] + UART_IER);
607 n = board * MXSER_PORTS_PER_BOARD;
608 info = &mxvar_table[n];
610 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info), "mxser", info);
612 printk(KERN_ERR "Board %d: %s", board, mxser_brdname[hwconf->board_type - 1]);
613 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info->irq);
620 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
622 mxsercfg[board] = *hwconf;
626 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
630 unsigned int ioaddress;
631 struct pci_dev *pdev = hwconf->pciInfo.pdev;
634 hwconf->board_type = board_type;
635 hwconf->ports = mxser_numports[board_type - 1];
636 ioaddress = pci_resource_start(pdev, 2);
637 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2), "mxser(IO)");
639 for (i = 0; i < hwconf->ports; i++) {
640 hwconf->ioaddr[i] = ioaddress + 8 * i;
644 ioaddress = pci_resource_start(pdev, 3);
645 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3), "mxser(vector)");
646 hwconf->vector = ioaddress;
649 hwconf->irq = hwconf->pciInfo.pdev->irq;
651 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
652 hwconf->uart_type = PORT_16550A;
653 hwconf->vector_mask = 0;
656 for (i = 0; i < hwconf->ports; i++) {
657 for (j = 0; j < UART_INFO_NUM; j++) {
658 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
659 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
661 //exception....CP-102
662 if (board_type == MXSER_BOARD_CP102)
663 hwconf->MaxCanSetBaudRate[i] = 921600;
669 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
670 for (i = 0; i < hwconf->ports; i++) {
672 hwconf->opmode_ioaddr[i] = ioaddress + 4;
674 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
676 outb(0, ioaddress + 4); // default set to RS232 mode
677 outb(0, ioaddress + 0x0c); //default set to RS232 mode
680 for (i = 0; i < hwconf->ports; i++) {
681 hwconf->vector_mask |= (1 << i);
682 hwconf->baud_base[i] = 921600;
688 static int mxser_init(void)
690 int i, m, retval, b, n;
692 struct pci_dev *pdev = NULL;
694 unsigned char busnum, devnum;
695 struct mxser_hwconf hwconf;
697 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
700 spin_lock_init(&gm_lock);
702 for (i = 0; i < MXSER_BOARDS; i++) {
703 mxsercfg[i].board_type = -1;
706 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION);
708 /* Initialize the tty_driver structure */
709 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
710 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
711 mxvar_sdriver->name = "ttyM";
712 mxvar_sdriver->major = ttymajor;
713 mxvar_sdriver->minor_start = 0;
714 mxvar_sdriver->num = MXSER_PORTS + 1;
715 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
716 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
717 mxvar_sdriver->init_termios = tty_std_termios;
718 mxvar_sdriver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
719 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
720 tty_set_operations(mxvar_sdriver, &mxser_ops);
721 mxvar_sdriver->ttys = mxvar_tty;
722 mxvar_sdriver->termios = mxvar_termios;
723 mxvar_sdriver->termios_locked = mxvar_termios_locked;
725 mxvar_sdriver->open = mxser_open;
726 mxvar_sdriver->close = mxser_close;
727 mxvar_sdriver->write = mxser_write;
728 mxvar_sdriver->put_char = mxser_put_char;
729 mxvar_sdriver->flush_chars = mxser_flush_chars;
730 mxvar_sdriver->write_room = mxser_write_room;
731 mxvar_sdriver->chars_in_buffer = mxser_chars_in_buffer;
732 mxvar_sdriver->flush_buffer = mxser_flush_buffer;
733 mxvar_sdriver->ioctl = mxser_ioctl;
734 mxvar_sdriver->throttle = mxser_throttle;
735 mxvar_sdriver->unthrottle = mxser_unthrottle;
736 mxvar_sdriver->set_termios = mxser_set_termios;
737 mxvar_sdriver->stop = mxser_stop;
738 mxvar_sdriver->start = mxser_start;
739 mxvar_sdriver->hangup = mxser_hangup;
740 mxvar_sdriver->break_ctl = mxser_rs_break;
741 mxvar_sdriver->wait_until_sent = mxser_wait_until_sent;
744 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
745 memset(&mxvar_log, 0, sizeof(struct mxser_log));
747 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
748 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
749 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
750 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
753 /* Start finding ISA boards here */
754 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
756 if (!(cap = mxserBoardCAP[b]))
759 retval = mxser_get_ISA_conf(cap, &hwconf);
762 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
765 if (retval == MXSER_ERR_IRQ)
766 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
767 else if (retval == MXSER_ERR_IRQ_CONFLIT)
768 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
769 else if (retval == MXSER_ERR_VECTOR)
770 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
771 else if (retval == MXSER_ERR_IOADDR)
772 printk(KERN_ERR "Invalid I/O address,board not configured\n");
777 hwconf.pciInfo.busNum = 0;
778 hwconf.pciInfo.devNum = 0;
779 hwconf.pciInfo.pdev = NULL;
781 mxser_getcfg(m, &hwconf);
782 //init mxsercfg first, or mxsercfg data is not correct on ISR.
783 //mxser_initbrd will hook ISR.
784 if (mxser_initbrd(m, &hwconf) < 0)
791 /* Start finding ISA boards from module arg */
792 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
794 if (!(cap = ioaddr[b]))
797 retval = mxser_get_ISA_conf(cap, &hwconf);
800 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n", mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
803 if (retval == MXSER_ERR_IRQ)
804 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
805 else if (retval == MXSER_ERR_IRQ_CONFLIT)
806 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
807 else if (retval == MXSER_ERR_VECTOR)
808 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
809 else if (retval == MXSER_ERR_IOADDR)
810 printk(KERN_ERR "Invalid I/O address,board not configured\n");
815 hwconf.pciInfo.busNum = 0;
816 hwconf.pciInfo.devNum = 0;
817 hwconf.pciInfo.pdev = NULL;
819 mxser_getcfg(m, &hwconf);
820 //init mxsercfg first, or mxsercfg data is not correct on ISR.
821 //mxser_initbrd will hook ISR.
822 if (mxser_initbrd(m, &hwconf) < 0)
828 /* start finding PCI board here */
830 n = (sizeof(mxser_pcibrds) / sizeof(mxser_pcibrds[0])) - 1;
834 pdev = pci_find_device(mxser_pcibrds[b].vendor, mxser_pcibrds[b].device, pdev);
839 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
840 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
841 hwconf.pciInfo.pdev = pdev;
842 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1], busnum, devnum >> 3);
844 if (m >= MXSER_BOARDS) {
845 printk(KERN_ERR "Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS);
847 if (pci_enable_device(pdev)) {
848 printk(KERN_ERR "Moxa SmartI/O PCI enable fail !\n");
851 retval = mxser_get_PCI_conf(busnum, devnum, (int) mxser_pcibrds[b].driver_data, &hwconf);
853 if (retval == MXSER_ERR_IRQ)
854 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
855 else if (retval == MXSER_ERR_IRQ_CONFLIT)
856 printk(KERN_ERR "Invalid interrupt number,board not configured\n");
857 else if (retval == MXSER_ERR_VECTOR)
858 printk(KERN_ERR "Invalid interrupt vector,board not configured\n");
859 else if (retval == MXSER_ERR_IOADDR)
860 printk(KERN_ERR "Invalid I/O address,board not configured\n");
863 mxser_getcfg(m, &hwconf);
864 //init mxsercfg first, or mxsercfg data is not correct on ISR.
865 //mxser_initbrd will hook ISR.
866 if (mxser_initbrd(m, &hwconf) < 0)
874 if (!(ret1 = tty_register_driver(mxvar_sdriver))) {
877 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family driver !\n");
881 for (i = 0; i < MXSER_BOARDS; i++) {
882 if (mxsercfg[i].board_type == -1)
885 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
886 //todo: release io, vector
895 static void mxser_do_softint(void *private_)
897 struct mxser_struct *info = (struct mxser_struct *) private_;
898 struct tty_struct *tty;
903 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
905 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
910 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
912 unsigned char status = 0;
914 status = inb(baseaddr + UART_MSR);
916 mxser_msr[port] &= 0x0F;
917 mxser_msr[port] |= status;
918 status = mxser_msr[port];
926 * This routine is called whenever a serial port is opened. It
927 * enables interrupts for a serial port, linking in its async structure into
928 * the IRQ chain. It also performs the serial-specific
929 * initialization for the tty structure.
931 static int mxser_open(struct tty_struct *tty, struct file *filp)
933 struct mxser_struct *info;
937 if (line == MXSER_PORTS)
939 if (line < 0 || line > MXSER_PORTS)
941 info = mxvar_table + line;
945 tty->driver_data = info;
948 * Start up serial port
950 retval = mxser_startup(info);
954 retval = mxser_block_til_ready(tty, filp, info);
960 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
961 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
962 *tty->termios = info->normal_termios;
964 *tty->termios = info->callout_termios;
965 mxser_change_speed(info, NULL);
968 info->session = current->signal->session;
969 info->pgrp = process_group(current);
970 clear_bit(TTY_DONT_FLIP, &tty->flags);
972 //status = mxser_get_msr(info->base, 0, info->port);
973 //mxser_check_modem_status(info, status);
975 /* unmark here for very high baud rate (ex. 921600 bps) used
977 tty->low_latency = 1;
982 * This routine is called when the serial port gets closed. First, we
983 * wait for the last remaining data to be sent. Then, we unlink its
984 * async structure from the interrupt chain if necessary, and we free
985 * that IRQ if nothing is left in the chain.
987 static void mxser_close(struct tty_struct *tty, struct file *filp)
989 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
991 unsigned long timeout;
993 struct tty_ldisc *ld;
995 if (tty->index == MXSER_PORTS)
1000 spin_lock_irqsave(&info->slock, flags);
1002 if (tty_hung_up_p(filp)) {
1003 spin_unlock_irqrestore(&info->slock, flags);
1006 if ((tty->count == 1) && (info->count != 1)) {
1008 * Uh, oh. tty->count is 1, which means that the tty
1009 * structure will be freed. Info->count should always
1010 * be one in these conditions. If it's greater than
1011 * one, we've got real problems, since it means the
1012 * serial port won't be shutdown.
1014 printk(KERN_ERR "mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info->count);
1017 if (--info->count < 0) {
1018 printk(KERN_ERR "mxser_close: bad serial port count for ttys%d: %d\n", info->port, info->count);
1022 spin_unlock_irqrestore(&info->slock, flags);
1025 info->flags |= ASYNC_CLOSING;
1026 spin_unlock_irqrestore(&info->slock, flags);
1028 * Save the termios structure, since this port may have
1029 * separate termios for callout and dialin.
1031 if (info->flags & ASYNC_NORMAL_ACTIVE)
1032 info->normal_termios = *tty->termios;
1034 * Now we wait for the transmit buffer to clear; and we notify
1035 * the line discipline to only process XON/XOFF characters.
1038 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1039 tty_wait_until_sent(tty, info->closing_wait);
1041 * At this point we stop accepting input. To do this, we
1042 * disable the receive line status interrupts, and tell the
1043 * interrupt driver to stop checking the data ready bit in the
1044 * line status register.
1046 info->IER &= ~UART_IER_RLSI;
1047 if (info->IsMoxaMustChipFlag)
1048 info->IER &= ~MOXA_MUST_RECV_ISR;
1050 info->read_status_mask &= ~UART_LSR_DR;
1052 if (info->flags & ASYNC_INITIALIZED) {
1053 outb(info->IER, info->base + UART_IER);
1055 * Before we drop DTR, make sure the UART transmitter
1056 * has completely drained; this is especially
1057 * important if there is a transmit FIFO!
1059 timeout = jiffies + HZ;
1060 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1061 schedule_timeout_interruptible(5);
1062 if (time_after(jiffies, timeout))
1066 mxser_shutdown(info);
1068 if (tty->driver->flush_buffer)
1069 tty->driver->flush_buffer(tty);
1071 ld = tty_ldisc_ref(tty);
1073 if(ld->flush_buffer)
1074 ld->flush_buffer(tty);
1075 tty_ldisc_deref(ld);
1081 if (info->blocked_open) {
1082 if (info->close_delay)
1083 schedule_timeout_interruptible(info->close_delay);
1084 wake_up_interruptible(&info->open_wait);
1087 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1088 wake_up_interruptible(&info->close_wait);
1092 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1095 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1096 unsigned long flags;
1098 if (!tty || !info->xmit_buf)
1102 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1, SERIAL_XMIT_SIZE - info->xmit_head));
1106 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1107 spin_lock_irqsave(&info->slock, flags);
1108 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1109 info->xmit_cnt += c;
1110 spin_unlock_irqrestore(&info->slock, flags);
1118 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1119 if (!tty->hw_stopped || (info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
1120 spin_lock_irqsave(&info->slock, flags);
1121 info->IER |= UART_IER_THRI;
1122 outb(info->IER, info->base + UART_IER);
1123 spin_unlock_irqrestore(&info->slock, flags);
1129 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1131 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1132 unsigned long flags;
1134 if (!tty || !info->xmit_buf)
1137 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1140 spin_lock_irqsave(&info->slock, flags);
1141 info->xmit_buf[info->xmit_head++] = ch;
1142 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1144 spin_unlock_irqrestore(&info->slock, flags);
1145 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1146 if (!tty->hw_stopped || (info->type == PORT_16550A) || info->IsMoxaMustChipFlag) {
1147 spin_lock_irqsave(&info->slock, flags);
1148 info->IER |= UART_IER_THRI;
1149 outb(info->IER, info->base + UART_IER);
1150 spin_unlock_irqrestore(&info->slock, flags);
1156 static void mxser_flush_chars(struct tty_struct *tty)
1158 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1159 unsigned long flags;
1161 if (info->xmit_cnt <= 0 || tty->stopped || !info->xmit_buf || (tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)))
1164 spin_lock_irqsave(&info->slock, flags);
1166 info->IER |= UART_IER_THRI;
1167 outb(info->IER, info->base + UART_IER);
1169 spin_unlock_irqrestore(&info->slock, flags);
1172 static int mxser_write_room(struct tty_struct *tty)
1174 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1177 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1183 static int mxser_chars_in_buffer(struct tty_struct *tty)
1185 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1186 return info->xmit_cnt;
1189 static void mxser_flush_buffer(struct tty_struct *tty)
1191 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1193 unsigned long flags;
1196 spin_lock_irqsave(&info->slock, flags);
1197 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1199 /* below added by shinhay */
1200 fcr = inb(info->base + UART_FCR);
1201 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
1202 outb(fcr, info->base + UART_FCR);
1204 spin_unlock_irqrestore(&info->slock, flags);
1205 /* above added by shinhay */
1207 wake_up_interruptible(&tty->write_wait);
1208 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1209 (tty->ldisc.write_wakeup) (tty);
1212 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1214 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1216 struct async_icount cprev, cnow; /* kernel counter temps */
1217 struct serial_icounter_struct __user *p_cuser;
1218 unsigned long templ;
1219 unsigned long flags;
1220 void __user *argp = (void __user *)arg;
1222 if (tty->index == MXSER_PORTS)
1223 return (mxser_ioctl_special(cmd, argp));
1225 // following add by Victor Yu. 01-05-2004
1226 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1228 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1230 unsigned char val, mask;
1233 if (cmd == MOXA_SET_OP_MODE) {
1234 if (get_user(opmode, (int __user *) argp))
1236 if (opmode != RS232_MODE && opmode != RS485_2WIRE_MODE && opmode != RS422_MODE && opmode != RS485_4WIRE_MODE)
1240 val = inb(info->opmode_ioaddr);
1242 val |= (opmode << shiftbit);
1243 outb(val, info->opmode_ioaddr);
1246 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1247 opmode &= OP_MODE_MASK;
1248 if (copy_to_user(argp, &opmode, sizeof(int)))
1253 // above add by Victor Yu. 01-05-2004
1255 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1256 if (tty->flags & (1 << TTY_IO_ERROR))
1260 case TCSBRK: /* SVID version: non-zero arg --> no break */
1261 retval = tty_check_change(tty);
1264 tty_wait_until_sent(tty, 0);
1266 mxser_send_break(info, HZ / 4); /* 1/4 second */
1268 case TCSBRKP: /* support for POSIX tcsendbreak() */
1269 retval = tty_check_change(tty);
1272 tty_wait_until_sent(tty, 0);
1273 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1276 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp);
1278 if (get_user(templ, (unsigned long __user *) argp))
1281 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1284 return mxser_get_serial_info(info, argp);
1286 return mxser_set_serial_info(info, argp);
1287 case TIOCSERGETLSR: /* Get line status register */
1288 return mxser_get_lsr_info(info, argp);
1290 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1291 * - mask passed in arg for lines of interest
1292 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1293 * Caller should use TIOCGICOUNT to see which one it was
1296 DECLARE_WAITQUEUE(wait, current);
1298 spin_lock_irqsave(&info->slock, flags);
1299 cprev = info->icount; /* note the counters on entry */
1300 spin_unlock_irqrestore(&info->slock, flags);
1302 add_wait_queue(&info->delta_msr_wait, &wait);
1304 spin_lock_irqsave(&info->slock, flags);
1305 cnow = info->icount; /* atomic copy */
1306 spin_unlock_irqrestore(&info->slock, flags);
1308 set_current_state(TASK_INTERRUPTIBLE);
1309 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))) {
1313 /* see if a signal did it */
1314 if (signal_pending(current)) {
1320 current->state = TASK_RUNNING;
1321 remove_wait_queue(&info->delta_msr_wait, &wait);
1326 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1327 * Return: write counters to the user passed counter struct
1328 * NB: both 1->0 and 0->1 transitions are counted except for
1329 * RI where only 0->1 is counted.
1332 spin_lock_irqsave(&info->slock, flags);
1333 cnow = info->icount;
1334 spin_unlock_irqrestore(&info->slock, flags);
1336 /* modified by casper 1/11/2000 */
1337 if (put_user(cnow.frame, &p_cuser->frame))
1339 if (put_user(cnow.brk, &p_cuser->brk))
1341 if (put_user(cnow.overrun, &p_cuser->overrun))
1343 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1345 if (put_user(cnow.parity, &p_cuser->parity))
1347 if (put_user(cnow.rx, &p_cuser->rx))
1349 if (put_user(cnow.tx, &p_cuser->tx))
1351 put_user(cnow.cts, &p_cuser->cts);
1352 put_user(cnow.dsr, &p_cuser->dsr);
1353 put_user(cnow.rng, &p_cuser->rng);
1354 put_user(cnow.dcd, &p_cuser->dcd);
1358 case MOXA_HighSpeedOn:
1359 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *) argp);
1361 case MOXA_SDS_RSTICOUNTER:{
1362 info->mon_data.rxcnt = 0;
1363 info->mon_data.txcnt = 0;
1366 // (above) added by James.
1367 case MOXA_ASPP_SETBAUD:{
1369 if (get_user(baud, (long __user *) argp))
1371 mxser_set_baud(info, baud);
1374 case MOXA_ASPP_GETBAUD:
1375 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1380 case MOXA_ASPP_OQUEUE:{
1383 len = mxser_chars_in_buffer(tty);
1385 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1387 len += (lsr ? 0 : 1);
1389 if (copy_to_user(argp, &len, sizeof(int)))
1394 case MOXA_ASPP_MON:{
1396 // info->mon_data.ser_param = tty->termios->c_cflag;
1398 status = mxser_get_msr(info->base, 1, info->port, info);
1399 mxser_check_modem_status(info, status);
1401 mcr = inb(info->base + UART_MCR);
1402 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1403 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1405 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1407 if (mcr & MOXA_MUST_MCR_TX_XON)
1408 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1410 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1412 if (info->tty->hw_stopped)
1413 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1415 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1418 if (copy_to_user(argp, &info->mon_data, sizeof(struct mxser_mon)))
1425 case MOXA_ASPP_LSTATUS:{
1426 if (copy_to_user(argp, &info->err_shadow, sizeof(unsigned char)))
1429 info->err_shadow = 0;
1433 case MOXA_SET_BAUD_METHOD:{
1435 if (get_user(method, (int __user *) argp))
1437 mxser_set_baud_method[info->port] = method;
1438 if (copy_to_user(argp, &method, sizeof(int)))
1444 return -ENOIOCTLCMD;
1450 #define CMSPAR 010000000000
1453 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1455 int i, result, status;
1459 if (copy_to_user(argp, mxsercfg, sizeof(struct mxser_hwconf) * 4))
1462 case MOXA_GET_MAJOR:
1463 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1467 case MOXA_GET_CUMAJOR:
1468 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1472 case MOXA_CHKPORTENABLE:
1474 for (i = 0; i < MXSER_PORTS; i++) {
1475 if (mxvar_table[i].base)
1478 return put_user(result, (unsigned long __user *) argp);
1479 case MOXA_GETDATACOUNT:
1480 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1483 case MOXA_GETMSTATUS:
1484 for (i = 0; i < MXSER_PORTS; i++) {
1486 if (!mxvar_table[i].base) {
1487 GMStatus[i].dcd = 0;
1488 GMStatus[i].dsr = 0;
1489 GMStatus[i].cts = 0;
1493 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1494 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1496 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1498 status = inb(mxvar_table[i].base + UART_MSR);
1499 if (status & 0x80 /*UART_MSR_DCD */ )
1500 GMStatus[i].dcd = 1;
1502 GMStatus[i].dcd = 0;
1504 if (status & 0x20 /*UART_MSR_DSR */ )
1505 GMStatus[i].dsr = 1;
1507 GMStatus[i].dsr = 0;
1510 if (status & 0x10 /*UART_MSR_CTS */ )
1511 GMStatus[i].cts = 1;
1513 GMStatus[i].cts = 0;
1515 if (copy_to_user(argp, GMStatus, sizeof(struct mxser_mstatus) * MXSER_PORTS))
1518 case MOXA_ASPP_MON_EXT:{
1522 unsigned cflag, iflag;
1524 for (i = 0; i < MXSER_PORTS; i++) {
1526 if (!mxvar_table[i].base)
1529 status = mxser_get_msr(mxvar_table[i].base, 0, i, &(mxvar_table[i]));
1530 // mxser_check_modem_status(&mxvar_table[i], status);
1531 if (status & UART_MSR_TERI)
1532 mxvar_table[i].icount.rng++;
1533 if (status & UART_MSR_DDSR)
1534 mxvar_table[i].icount.dsr++;
1535 if (status & UART_MSR_DDCD)
1536 mxvar_table[i].icount.dcd++;
1537 if (status & UART_MSR_DCTS)
1538 mxvar_table[i].icount.cts++;
1540 mxvar_table[i].mon_data.modem_status = status;
1541 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1542 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1543 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1544 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1545 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1546 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1548 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1549 cflag = mxvar_table[i].normal_termios.c_cflag;
1550 iflag = mxvar_table[i].normal_termios.c_iflag;
1552 cflag = mxvar_table[i].tty->termios->c_cflag;
1553 iflag = mxvar_table[i].tty->termios->c_iflag;
1556 mon_data_ext.databits[i] = cflag & CSIZE;
1558 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1560 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1562 mon_data_ext.flowctrl[i] = 0x00;
1564 if (cflag & CRTSCTS)
1565 mon_data_ext.flowctrl[i] |= 0x03;
1567 if (iflag & (IXON | IXOFF))
1568 mon_data_ext.flowctrl[i] |= 0x0C;
1570 if (mxvar_table[i].type == PORT_16550A)
1571 mon_data_ext.fifo[i] = 1;
1573 mon_data_ext.fifo[i] = 0;
1577 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1578 opmode &= OP_MODE_MASK;
1580 mon_data_ext.iftype[i] = opmode;
1583 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1590 return -ENOIOCTLCMD;
1596 static void mxser_stoprx(struct tty_struct *tty)
1598 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1599 //unsigned long flags;
1602 info->ldisc_stop_rx = 1;
1605 //MX_LOCK(&info->slock);
1606 // following add by Victor Yu. 09-02-2002
1607 if (info->IsMoxaMustChipFlag) {
1608 info->IER &= ~MOXA_MUST_RECV_ISR;
1609 outb(info->IER, info->base + UART_IER);
1611 // above add by Victor Yu. 09-02-2002
1613 info->x_char = STOP_CHAR(tty);
1614 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1615 outb(0, info->base + UART_IER);
1616 info->IER |= UART_IER_THRI;
1617 outb(info->IER, info->base + UART_IER); /* force Tx interrupt */
1618 } // add by Victor Yu. 09-02-2002
1619 //MX_UNLOCK(&info->slock);
1622 if (info->tty->termios->c_cflag & CRTSCTS) {
1623 //MX_LOCK(&info->slock);
1624 info->MCR &= ~UART_MCR_RTS;
1625 outb(info->MCR, info->base + UART_MCR);
1626 //MX_UNLOCK(&info->slock);
1630 static void mxser_startrx(struct tty_struct *tty)
1632 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1633 //unsigned long flags;
1635 info->ldisc_stop_rx = 0;
1640 //MX_LOCK(&info->slock);
1642 // following add by Victor Yu. 09-02-2002
1643 if (info->IsMoxaMustChipFlag) {
1644 info->IER |= MOXA_MUST_RECV_ISR;
1645 outb(info->IER, info->base + UART_IER);
1647 // above add by Victor Yu. 09-02-2002
1649 info->x_char = START_CHAR(tty);
1650 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1651 outb(0, info->base + UART_IER); // add by Victor Yu. 09-02-2002
1652 info->IER |= UART_IER_THRI; /* force Tx interrupt */
1653 outb(info->IER, info->base + UART_IER);
1654 } // add by Victor Yu. 09-02-2002
1655 //MX_UNLOCK(&info->slock);
1659 if (info->tty->termios->c_cflag & CRTSCTS) {
1660 //MX_LOCK(&info->slock);
1661 info->MCR |= UART_MCR_RTS;
1662 outb(info->MCR, info->base + UART_MCR);
1663 //MX_UNLOCK(&info->slock);
1668 * This routine is called by the upper-layer tty layer to signal that
1669 * incoming characters should be throttled.
1671 static void mxser_throttle(struct tty_struct *tty)
1673 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1674 //unsigned long flags;
1675 //MX_LOCK(&info->slock);
1677 //MX_UNLOCK(&info->slock);
1680 static void mxser_unthrottle(struct tty_struct *tty)
1682 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1683 //unsigned long flags;
1684 //MX_LOCK(&info->slock);
1686 //MX_UNLOCK(&info->slock);
1689 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1691 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1692 unsigned long flags;
1694 if ((tty->termios->c_cflag != old_termios->c_cflag) || (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1696 mxser_change_speed(info, old_termios);
1698 if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
1699 tty->hw_stopped = 0;
1704 /* Handle sw stopped */
1705 if ((old_termios->c_iflag & IXON) && !(tty->termios->c_iflag & IXON)) {
1708 // following add by Victor Yu. 09-02-2002
1709 if (info->IsMoxaMustChipFlag) {
1710 spin_lock_irqsave(&info->slock, flags);
1711 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1712 spin_unlock_irqrestore(&info->slock, flags);
1714 // above add by Victor Yu. 09-02-2002
1721 * mxser_stop() and mxser_start()
1723 * This routines are called before setting or resetting tty->stopped.
1724 * They enable or disable transmitter interrupts, as necessary.
1726 static void mxser_stop(struct tty_struct *tty)
1728 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1729 unsigned long flags;
1731 spin_lock_irqsave(&info->slock, flags);
1732 if (info->IER & UART_IER_THRI) {
1733 info->IER &= ~UART_IER_THRI;
1734 outb(info->IER, info->base + UART_IER);
1736 spin_unlock_irqrestore(&info->slock, flags);
1739 static void mxser_start(struct tty_struct *tty)
1741 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1742 unsigned long flags;
1744 spin_lock_irqsave(&info->slock, flags);
1745 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1746 info->IER |= UART_IER_THRI;
1747 outb(info->IER, info->base + UART_IER);
1749 spin_unlock_irqrestore(&info->slock, flags);
1753 * mxser_wait_until_sent() --- wait until the transmitter is empty
1755 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1757 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1758 unsigned long orig_jiffies, char_time;
1761 if (info->type == PORT_UNKNOWN)
1764 if (info->xmit_fifo_size == 0)
1765 return; /* Just in case.... */
1767 orig_jiffies = jiffies;
1769 * Set the check interval to be 1/5 of the estimated time to
1770 * send a single character, and make it at least 1. The check
1771 * interval should also be less than the timeout.
1773 * Note: we have to use pretty tight timings here to satisfy
1776 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1777 char_time = char_time / 5;
1780 if (timeout && timeout < char_time)
1781 char_time = timeout;
1783 * If the transmitter hasn't cleared in twice the approximate
1784 * amount of time to send the entire FIFO, it probably won't
1785 * ever clear. This assumes the UART isn't doing flow
1786 * control, which is currently the case. Hence, if it ever
1787 * takes longer than info->timeout, this is probably due to a
1788 * UART bug of some kind. So, we clamp the timeout parameter at
1791 if (!timeout || timeout > 2 * info->timeout)
1792 timeout = 2 * info->timeout;
1793 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1794 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
1795 printk("jiff=%lu...", jiffies);
1797 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1798 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1799 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1801 schedule_timeout_interruptible(char_time);
1802 if (signal_pending(current))
1804 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1807 set_current_state(TASK_RUNNING);
1809 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1810 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1816 * This routine is called by tty_hangup() when a hangup is signaled.
1818 void mxser_hangup(struct tty_struct *tty)
1820 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1822 mxser_flush_buffer(tty);
1823 mxser_shutdown(info);
1826 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1828 wake_up_interruptible(&info->open_wait);
1832 // added by James 03-12-2004.
1834 * mxser_rs_break() --- routine which turns the break handling on or off
1836 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1838 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
1839 unsigned long flags;
1841 spin_lock_irqsave(&info->slock, flags);
1842 if (break_state == -1)
1843 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
1845 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
1846 spin_unlock_irqrestore(&info->slock, flags);
1849 // (above) added by James.
1853 * This is the serial driver's generic interrupt routine
1855 static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1858 struct mxser_struct *info;
1859 struct mxser_struct *port;
1860 int max, irqbits, bits, msr;
1861 int pass_counter = 0;
1862 int handled = IRQ_NONE;
1865 //spin_lock(&gm_lock);
1867 for (i = 0; i < MXSER_BOARDS; i++) {
1868 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1874 if (i == MXSER_BOARDS) {
1880 max = mxser_numports[mxsercfg[i].board_type - 1];
1882 irqbits = inb(port->vector) & port->vectormask;
1883 if (irqbits == port->vectormask) {
1887 handled = IRQ_HANDLED;
1888 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1889 if (irqbits == port->vectormask) {
1896 // following add by Victor Yu. 09-13-2002
1897 iir = inb(info->base + UART_IIR);
1898 if (iir & UART_IIR_NO_INT)
1900 iir &= MOXA_MUST_IIR_MASK;
1902 status = inb(info->base + UART_LSR);
1903 outb(0x27, info->base + UART_FCR);
1904 inb(info->base + UART_MSR);
1907 // above add by Victor Yu. 09-13-2002
1909 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1910 info->IER |= MOXA_MUST_RECV_ISR;
1911 outb(info->IER, info->base + UART_IER);
1916 /* mask by Victor Yu. 09-13-2002
1918 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1921 /* mask by Victor Yu. 09-02-2002
1922 status = inb(info->base + UART_LSR) & info->read_status_mask;
1925 // following add by Victor Yu. 09-02-2002
1926 status = inb(info->base + UART_LSR);
1928 if (status & UART_LSR_PE) {
1929 info->err_shadow |= NPPI_NOTIFY_PARITY;
1931 if (status & UART_LSR_FE) {
1932 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1934 if (status & UART_LSR_OE) {
1935 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1937 if (status & UART_LSR_BI)
1938 info->err_shadow |= NPPI_NOTIFY_BREAK;
1940 if (info->IsMoxaMustChipFlag) {
1942 if ( (status & 0x02) && !(status & 0x01) ) {
1943 outb(info->base+UART_FCR, 0x23);
1947 if (iir == MOXA_MUST_IIR_GDA || iir == MOXA_MUST_IIR_RDA || iir == MOXA_MUST_IIR_RTO || iir == MOXA_MUST_IIR_LSR)
1948 mxser_receive_chars(info, &status);
1951 // above add by Victor Yu. 09-02-2002
1953 status &= info->read_status_mask;
1954 if (status & UART_LSR_DR)
1955 mxser_receive_chars(info, &status);
1957 msr = inb(info->base + UART_MSR);
1958 if (msr & UART_MSR_ANY_DELTA) {
1959 mxser_check_modem_status(info, msr);
1961 // following add by Victor Yu. 09-13-2002
1962 if (info->IsMoxaMustChipFlag) {
1963 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
1964 mxser_transmit_chars(info);
1967 // above add by Victor Yu. 09-13-2002
1969 if (status & UART_LSR_THRE) {
1970 /* 8-2-99 by William
1971 if ( info->x_char || (info->xmit_cnt > 0) )
1973 mxser_transmit_chars(info);
1977 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
1978 break; /* Prevent infinite loops */
1983 //spin_unlock(&gm_lock);
1987 static void mxser_receive_chars(struct mxser_struct *info, int *status)
1989 struct tty_struct *tty = info->tty;
1990 unsigned char ch, gdl;
1995 unsigned long flags;
1997 spin_lock_irqsave(&info->slock, flags);
1999 recv_room = tty->ldisc.receive_room(tty);
2000 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2001 //mxser_throttle(tty);
2006 // following add by Victor Yu. 09-02-2002
2007 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2009 if (*status & UART_LSR_SPECIAL) {
2012 // following add by Victor Yu. 02-11-2004
2013 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID && (*status & MOXA_MUST_LSR_RERR))
2015 // above add by Victor Yu. 02-14-2004
2016 if (*status & MOXA_MUST_LSR_RERR)
2019 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2021 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID) // add by Victor Yu. 02-11-2004
2022 gdl &= MOXA_MUST_GDL_MASK;
2023 if (gdl >= recv_room) {
2024 if (!info->ldisc_stop_rx) {
2025 //mxser_throttle(tty);
2031 ch = inb(info->base + UART_RX);
2032 tty_insert_flip_char(tty, ch, 0);
2035 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2044 // above add by Victor Yu. 09-02-2002
2050 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2057 ch = inb(info->base + UART_RX);
2058 // following add by Victor Yu. 09-02-2002
2059 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2060 outb(0x23, info->base + UART_FCR);
2061 *status &= info->read_status_mask;
2062 // above add by Victor Yu. 09-02-2002
2063 if (*status & info->ignore_status_mask) {
2064 if (++ignored > 100)
2068 if (*status & UART_LSR_SPECIAL) {
2069 if (*status & UART_LSR_BI) {
2071 /* added by casper 1/11/2000 */
2074 if (info->flags & ASYNC_SAK)
2076 } else if (*status & UART_LSR_PE) {
2078 /* added by casper 1/11/2000 */
2079 info->icount.parity++;
2081 } else if (*status & UART_LSR_FE) {
2083 /* added by casper 1/11/2000 */
2084 info->icount.frame++;
2086 } else if (*status & UART_LSR_OE) {
2088 /* added by casper 1/11/2000 */
2089 info->icount.overrun++;
2093 tty_insert_flip_char(tty, ch, flag);
2095 if (cnt >= recv_room) {
2096 if (!info->ldisc_stop_rx) {
2097 //mxser_throttle(tty);
2105 // following add by Victor Yu. 09-02-2002
2106 if (info->IsMoxaMustChipFlag)
2108 // above add by Victor Yu. 09-02-2002
2110 /* mask by Victor Yu. 09-02-2002
2111 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2113 // following add by Victor Yu. 09-02-2002
2114 *status = inb(info->base + UART_LSR);
2115 // above add by Victor Yu. 09-02-2002
2116 } while (*status & UART_LSR_DR);
2118 end_intr: // add by Victor Yu. 09-02-2002
2120 mxvar_log.rxcnt[info->port] += cnt;
2121 info->mon_data.rxcnt += cnt;
2122 info->mon_data.up_rxcnt += cnt;
2123 spin_unlock_irqrestore(&info->slock, flags);
2125 tty_flip_buffer_push(tty);
2128 static void mxser_transmit_chars(struct mxser_struct *info)
2131 unsigned long flags;
2133 spin_lock_irqsave(&info->slock, flags);
2136 outb(info->x_char, info->base + UART_TX);
2138 mxvar_log.txcnt[info->port]++;
2139 info->mon_data.txcnt++;
2140 info->mon_data.up_txcnt++;
2142 /* added by casper 1/11/2000 */
2145 spin_unlock_irqrestore(&info->slock, flags);
2149 if (info->xmit_buf == 0) {
2150 spin_unlock_irqrestore(&info->slock, flags);
2154 if ((info->xmit_cnt <= 0) || info->tty->stopped || (info->tty->hw_stopped && (info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag))) {
2155 info->IER &= ~UART_IER_THRI;
2156 outb(info->IER, info->base + UART_IER);
2157 spin_unlock_irqrestore(&info->slock, flags);
2161 cnt = info->xmit_cnt;
2162 count = info->xmit_fifo_size;
2164 outb(info->xmit_buf[info->xmit_tail++], info->base + UART_TX);
2165 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2166 if (--info->xmit_cnt <= 0)
2168 } while (--count > 0);
2169 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2171 // added by James 03-12-2004.
2172 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2173 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2174 // (above) added by James.
2176 /* added by casper 1/11/2000 */
2177 info->icount.tx += (cnt - info->xmit_cnt);
2180 if (info->xmit_cnt < WAKEUP_CHARS) {
2181 set_bit(MXSER_EVENT_TXLOW, &info->event);
2182 schedule_work(&info->tqueue);
2184 if (info->xmit_cnt <= 0) {
2185 info->IER &= ~UART_IER_THRI;
2186 outb(info->IER, info->base + UART_IER);
2188 spin_unlock_irqrestore(&info->slock, flags);
2191 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2193 /* update input line counters */
2194 if (status & UART_MSR_TERI)
2196 if (status & UART_MSR_DDSR)
2198 if (status & UART_MSR_DDCD)
2200 if (status & UART_MSR_DCTS)
2202 info->mon_data.modem_status = status;
2203 wake_up_interruptible(&info->delta_msr_wait);
2206 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2207 if (status & UART_MSR_DCD)
2208 wake_up_interruptible(&info->open_wait);
2209 schedule_work(&info->tqueue);
2212 if (info->flags & ASYNC_CTS_FLOW) {
2213 if (info->tty->hw_stopped) {
2214 if (status & UART_MSR_CTS) {
2215 info->tty->hw_stopped = 0;
2217 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2218 info->IER |= UART_IER_THRI;
2219 outb(info->IER, info->base + UART_IER);
2221 set_bit(MXSER_EVENT_TXLOW, &info->event);
2222 schedule_work(&info->tqueue); }
2224 if (!(status & UART_MSR_CTS)) {
2225 info->tty->hw_stopped = 1;
2226 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2227 info->IER &= ~UART_IER_THRI;
2228 outb(info->IER, info->base + UART_IER);
2235 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2237 DECLARE_WAITQUEUE(wait, current);
2240 unsigned long flags;
2243 * If non-blocking mode is set, or the port is not enabled,
2244 * then make the check up front and then exit.
2246 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2247 info->flags |= ASYNC_NORMAL_ACTIVE;
2251 if (tty->termios->c_cflag & CLOCAL)
2255 * Block waiting for the carrier detect and the line to become
2256 * free (i.e., not in use by the callout). While we are in
2257 * this loop, info->count is dropped by one, so that
2258 * mxser_close() knows when to free things. We restore it upon
2259 * exit, either normal or abnormal.
2262 add_wait_queue(&info->open_wait, &wait);
2264 spin_lock_irqsave(&info->slock, flags);
2265 if (!tty_hung_up_p(filp))
2267 spin_unlock_irqrestore(&info->slock, flags);
2268 info->blocked_open++;
2270 spin_lock_irqsave(&info->slock, flags);
2271 outb(inb(info->base + UART_MCR) | UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2272 spin_unlock_irqrestore(&info->slock, flags);
2273 set_current_state(TASK_INTERRUPTIBLE);
2274 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2275 if (info->flags & ASYNC_HUP_NOTIFY)
2278 retval = -ERESTARTSYS;
2281 if (!(info->flags & ASYNC_CLOSING) && (do_clocal || (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2283 if (signal_pending(current)) {
2284 retval = -ERESTARTSYS;
2289 set_current_state(TASK_RUNNING);
2290 remove_wait_queue(&info->open_wait, &wait);
2291 if (!tty_hung_up_p(filp))
2293 info->blocked_open--;
2296 info->flags |= ASYNC_NORMAL_ACTIVE;
2300 static int mxser_startup(struct mxser_struct *info)
2304 unsigned long flags;
2306 page = __get_free_page(GFP_KERNEL);
2310 spin_lock_irqsave(&info->slock, flags);
2312 if (info->flags & ASYNC_INITIALIZED) {
2314 spin_unlock_irqrestore(&info->slock, flags);
2318 if (!info->base || !info->type) {
2320 set_bit(TTY_IO_ERROR, &info->tty->flags);
2322 spin_unlock_irqrestore(&info->slock, flags);
2328 info->xmit_buf = (unsigned char *) page;
2331 * Clear the FIFO buffers and disable them
2332 * (they will be reenabled in mxser_change_speed())
2334 if (info->IsMoxaMustChipFlag)
2335 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2337 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2340 * At this point there's no way the LSR could still be 0xFF;
2341 * if it is, then bail out, because there's likely no UART
2344 if (inb(info->base + UART_LSR) == 0xff) {
2345 spin_unlock_irqrestore(&info->slock, flags);
2346 if (capable(CAP_SYS_ADMIN)) {
2348 set_bit(TTY_IO_ERROR, &info->tty->flags);
2355 * Clear the interrupt registers.
2357 (void) inb(info->base + UART_LSR);
2358 (void) inb(info->base + UART_RX);
2359 (void) inb(info->base + UART_IIR);
2360 (void) inb(info->base + UART_MSR);
2363 * Now, initialize the UART
2365 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2366 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2367 outb(info->MCR, info->base + UART_MCR);
2370 * Finally, enable interrupts
2372 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2373 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2375 // following add by Victor Yu. 08-30-2002
2376 if (info->IsMoxaMustChipFlag)
2377 info->IER |= MOXA_MUST_IER_EGDAI;
2378 // above add by Victor Yu. 08-30-2002
2379 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2382 * And clear the interrupt registers again for luck.
2384 (void) inb(info->base + UART_LSR);
2385 (void) inb(info->base + UART_RX);
2386 (void) inb(info->base + UART_IIR);
2387 (void) inb(info->base + UART_MSR);
2390 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2391 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2394 * and set the speed of the serial port
2396 spin_unlock_irqrestore(&info->slock, flags);
2397 mxser_change_speed(info, NULL);
2399 info->flags |= ASYNC_INITIALIZED;
2404 * This routine will shutdown a serial port; interrupts maybe disabled, and
2405 * DTR is dropped if the hangup on close termio flag is on.
2407 static void mxser_shutdown(struct mxser_struct *info)
2409 unsigned long flags;
2411 if (!(info->flags & ASYNC_INITIALIZED))
2414 spin_lock_irqsave(&info->slock, flags);
2417 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2418 * here so the queue might never be waken up
2420 wake_up_interruptible(&info->delta_msr_wait);
2423 * Free the IRQ, if necessary
2425 if (info->xmit_buf) {
2426 free_page((unsigned long) info->xmit_buf);
2427 info->xmit_buf = NULL;
2431 outb(0x00, info->base + UART_IER);
2433 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2434 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2435 outb(info->MCR, info->base + UART_MCR);
2437 /* clear Rx/Tx FIFO's */
2438 // following add by Victor Yu. 08-30-2002
2439 if (info->IsMoxaMustChipFlag)
2440 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2442 // above add by Victor Yu. 08-30-2002
2443 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT), info->base + UART_FCR);
2445 /* read data port to reset things */
2446 (void) inb(info->base + UART_RX);
2449 set_bit(TTY_IO_ERROR, &info->tty->flags);
2451 info->flags &= ~ASYNC_INITIALIZED;
2453 // following add by Victor Yu. 09-23-2002
2454 if (info->IsMoxaMustChipFlag) {
2455 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2457 // above add by Victor Yu. 09-23-2002
2459 spin_unlock_irqrestore(&info->slock, flags);
2463 * This routine is called to set the UART divisor registers to match
2464 * the specified baud rate for a serial port.
2466 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2468 unsigned cflag, cval, fcr;
2470 unsigned char status;
2472 unsigned long flags;
2475 if (!info->tty || !info->tty->termios)
2477 cflag = info->tty->termios->c_cflag;
2483 #define B921600 (B460800 +1)
2485 if (mxser_set_baud_method[info->port] == 0) {
2486 switch (cflag & (CBAUD | CBAUDEX)) {
2551 mxser_set_baud(info, baud);
2554 /* byte size and parity */
2555 switch (cflag & CSIZE) {
2570 break; /* too keep GCC shut... */
2575 cval |= UART_LCR_PARITY;
2576 if (!(cflag & PARODD)) {
2577 cval |= UART_LCR_EPAR;
2580 cval |= UART_LCR_SPAR;
2582 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2583 if (info->IsMoxaMustChipFlag) {
2584 fcr = UART_FCR_ENABLE_FIFO;
2585 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2586 SET_MOXA_MUST_FIFO_VALUE(info);
2590 fcr = UART_FCR_ENABLE_FIFO;
2591 // following add by Victor Yu. 08-30-2002
2592 if (info->IsMoxaMustChipFlag) {
2593 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2594 SET_MOXA_MUST_FIFO_VALUE(info);
2596 // above add by Victor Yu. 08-30-2002
2598 switch (info->rx_trigger) {
2600 fcr |= UART_FCR_TRIGGER_1;
2603 fcr |= UART_FCR_TRIGGER_4;
2606 fcr |= UART_FCR_TRIGGER_8;
2609 fcr |= UART_FCR_TRIGGER_14;
2615 /* CTS flow control flag and modem status interrupts */
2616 info->IER &= ~UART_IER_MSI;
2617 info->MCR &= ~UART_MCR_AFE;
2618 if (cflag & CRTSCTS) {
2619 info->flags |= ASYNC_CTS_FLOW;
2620 info->IER |= UART_IER_MSI;
2621 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2622 info->MCR |= UART_MCR_AFE;
2623 //status = mxser_get_msr(info->base, 0, info->port);
2624 /* save_flags(flags);
2626 status = inb(baseaddr + UART_MSR);
2627 restore_flags(flags);*/
2628 //mxser_check_modem_status(info, status);
2630 //status = mxser_get_msr(info->base, 0, info->port);
2632 //MX_LOCK(&info->slock);
2633 status = inb(info->base + UART_MSR);
2634 //MX_UNLOCK(&info->slock);
2635 if (info->tty->hw_stopped) {
2636 if (status & UART_MSR_CTS) {
2637 info->tty->hw_stopped = 0;
2638 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2639 info->IER |= UART_IER_THRI;
2640 outb(info->IER, info->base + UART_IER);
2642 set_bit(MXSER_EVENT_TXLOW, &info->event);
2643 schedule_work(&info->tqueue); }
2645 if (!(status & UART_MSR_CTS)) {
2646 info->tty->hw_stopped = 1;
2647 if ((info->type != PORT_16550A) && (!info->IsMoxaMustChipFlag)) {
2648 info->IER &= ~UART_IER_THRI;
2649 outb(info->IER, info->base + UART_IER);
2655 info->flags &= ~ASYNC_CTS_FLOW;
2657 outb(info->MCR, info->base + UART_MCR);
2658 if (cflag & CLOCAL) {
2659 info->flags &= ~ASYNC_CHECK_CD;
2661 info->flags |= ASYNC_CHECK_CD;
2662 info->IER |= UART_IER_MSI;
2664 outb(info->IER, info->base + UART_IER);
2667 * Set up parity check flag
2669 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2670 if (I_INPCK(info->tty))
2671 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2672 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2673 info->read_status_mask |= UART_LSR_BI;
2675 info->ignore_status_mask = 0;
2677 if (I_IGNBRK(info->tty)) {
2678 info->ignore_status_mask |= UART_LSR_BI;
2679 info->read_status_mask |= UART_LSR_BI;
2681 * If we're ignore parity and break indicators, ignore
2682 * overruns too. (For real raw support).
2684 if (I_IGNPAR(info->tty)) {
2685 info->ignore_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
2686 info->read_status_mask |= UART_LSR_OE | UART_LSR_PE | UART_LSR_FE;
2689 // following add by Victor Yu. 09-02-2002
2690 if (info->IsMoxaMustChipFlag) {
2691 spin_lock_irqsave(&info->slock, flags);
2692 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2693 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2694 if (I_IXON(info->tty)) {
2695 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2697 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2699 if (I_IXOFF(info->tty)) {
2700 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2702 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2705 if ( I_IXANY(info->tty) ) {
2706 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2707 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2709 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2710 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2713 spin_unlock_irqrestore(&info->slock, flags);
2715 // above add by Victor Yu. 09-02-2002
2718 outb(fcr, info->base + UART_FCR); /* set fcr */
2719 outb(cval, info->base + UART_LCR);
2725 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2730 unsigned long flags;
2732 if (!info->tty || !info->tty->termios)
2738 if (newspd > info->MaxCanSetBaudRate)
2741 info->realbaud = newspd;
2742 if (newspd == 134) {
2743 quot = (2 * info->baud_base / 269);
2744 } else if (newspd) {
2745 quot = info->baud_base / newspd;
2754 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2755 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2758 spin_lock_irqsave(&info->slock, flags);
2759 info->MCR |= UART_MCR_DTR;
2760 outb(info->MCR, info->base + UART_MCR);
2761 spin_unlock_irqrestore(&info->slock, flags);
2763 spin_lock_irqsave(&info->slock, flags);
2764 info->MCR &= ~UART_MCR_DTR;
2765 outb(info->MCR, info->base + UART_MCR);
2766 spin_unlock_irqrestore(&info->slock, flags);
2770 cval = inb(info->base + UART_LCR);
2772 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2774 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2775 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2776 outb(cval, info->base + UART_LCR); /* reset DLAB */
2785 * ------------------------------------------------------------
2786 * friends of mxser_ioctl()
2787 * ------------------------------------------------------------
2789 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2791 struct serial_struct tmp;
2795 memset(&tmp, 0, sizeof(tmp));
2796 tmp.type = info->type;
2797 tmp.line = info->port;
2798 tmp.port = info->base;
2799 tmp.irq = info->irq;
2800 tmp.flags = info->flags;
2801 tmp.baud_base = info->baud_base;
2802 tmp.close_delay = info->close_delay;
2803 tmp.closing_wait = info->closing_wait;
2804 tmp.custom_divisor = info->custom_divisor;
2806 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2811 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2813 struct serial_struct new_serial;
2817 if (!new_info || !info->base)
2819 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2822 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))
2825 flags = info->flags & ASYNC_SPD_MASK;
2827 if (!capable(CAP_SYS_ADMIN)) {
2828 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)))
2830 info->flags = ((info->flags & ~ASYNC_USR_MASK) | (new_serial.flags & ASYNC_USR_MASK));
2833 * OK, past this point, all the error checking has been done.
2834 * At this point, we start making changes.....
2836 info->flags = ((info->flags & ~ASYNC_FLAGS) | (new_serial.flags & ASYNC_FLAGS));
2837 info->close_delay = new_serial.close_delay * HZ / 100;
2838 info->closing_wait = new_serial.closing_wait * HZ / 100;
2839 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2840 info->tty->low_latency = 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2843 /* added by casper, 3/17/2000, for mouse */
2844 info->type = new_serial.type;
2846 process_txrx_fifo(info);
2849 if (info->flags & ASYNC_INITIALIZED) {
2850 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2851 mxser_change_speed(info, NULL);
2854 retval = mxser_startup(info);
2860 * mxser_get_lsr_info - get line status register info
2862 * Purpose: Let user call ioctl() to get info when the UART physically
2863 * is emptied. On bus types like RS485, the transmitter must
2864 * release the bus after transmitting. This must be done when
2865 * the transmit shift register is empty, not be done when the
2866 * transmit holding register is empty. This functionality
2867 * allows an RS485 driver to be written in user space.
2869 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2871 unsigned char status;
2872 unsigned int result;
2873 unsigned long flags;
2875 spin_lock_irqsave(&info->slock, flags);
2876 status = inb(info->base + UART_LSR);
2877 spin_unlock_irqrestore(&info->slock, flags);
2878 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2879 return put_user(result, value);
2883 * This routine sends a break character out the serial port.
2885 static void mxser_send_break(struct mxser_struct *info, int duration)
2887 unsigned long flags;
2891 set_current_state(TASK_INTERRUPTIBLE);
2892 spin_lock_irqsave(&info->slock, flags);
2893 outb(inb(info->base + UART_LCR) | UART_LCR_SBC, info->base + UART_LCR);
2894 spin_unlock_irqrestore(&info->slock, flags);
2895 schedule_timeout(duration);
2896 spin_lock_irqsave(&info->slock, flags);
2897 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC, info->base + UART_LCR);
2898 spin_unlock_irqrestore(&info->slock, flags);
2901 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2903 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2904 unsigned char control, status;
2905 unsigned long flags;
2908 if (tty->index == MXSER_PORTS)
2909 return (-ENOIOCTLCMD);
2910 if (tty->flags & (1 << TTY_IO_ERROR))
2913 control = info->MCR;
2915 spin_lock_irqsave(&info->slock, flags);
2916 status = inb(info->base + UART_MSR);
2917 if (status & UART_MSR_ANY_DELTA)
2918 mxser_check_modem_status(info, status);
2919 spin_unlock_irqrestore(&info->slock, flags);
2920 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2921 ((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);
2924 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2926 struct mxser_struct *info = (struct mxser_struct *) tty->driver_data;
2927 unsigned long flags;
2930 if (tty->index == MXSER_PORTS)
2931 return -ENOIOCTLCMD;
2932 if (tty->flags & (1 << TTY_IO_ERROR))
2935 spin_lock_irqsave(&info->slock, flags);
2937 if (set & TIOCM_RTS)
2938 info->MCR |= UART_MCR_RTS;
2939 if (set & TIOCM_DTR)
2940 info->MCR |= UART_MCR_DTR;
2942 if (clear & TIOCM_RTS)
2943 info->MCR &= ~UART_MCR_RTS;
2944 if (clear & TIOCM_DTR)
2945 info->MCR &= ~UART_MCR_DTR;
2947 outb(info->MCR, info->base + UART_MCR);
2948 spin_unlock_irqrestore(&info->slock, flags);
2953 static int mxser_read_register(int, unsigned short *);
2954 static int mxser_program_mode(int);
2955 static void mxser_normal_mode(int);
2957 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2960 unsigned short regs[16], irq;
2961 unsigned char scratch, scratch2;
2963 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2965 id = mxser_read_register(cap, regs);
2966 if (id == C168_ASIC_ID) {
2967 hwconf->board_type = MXSER_BOARD_C168_ISA;
2969 } else if (id == C104_ASIC_ID) {
2970 hwconf->board_type = MXSER_BOARD_C104_ISA;
2972 } else if (id == C102_ASIC_ID) {
2973 hwconf->board_type = MXSER_BOARD_C102_ISA;
2975 } else if (id == CI132_ASIC_ID) {
2976 hwconf->board_type = MXSER_BOARD_CI132;
2978 } else if (id == CI134_ASIC_ID) {
2979 hwconf->board_type = MXSER_BOARD_CI134;
2981 } else if (id == CI104J_ASIC_ID) {
2982 hwconf->board_type = MXSER_BOARD_CI104J;
2988 if (hwconf->ports == 2) {
2989 irq = regs[9] & 0xF000;
2990 irq = irq | (irq >> 4);
2991 if (irq != (regs[9] & 0xFF00))
2992 return (MXSER_ERR_IRQ_CONFLIT);
2993 } else if (hwconf->ports == 4) {
2994 irq = regs[9] & 0xF000;
2995 irq = irq | (irq >> 4);
2996 irq = irq | (irq >> 8);
2998 return (MXSER_ERR_IRQ_CONFLIT);
2999 } else if (hwconf->ports == 8) {
3000 irq = regs[9] & 0xF000;
3001 irq = irq | (irq >> 4);
3002 irq = irq | (irq >> 8);
3003 if ((irq != regs[9]) || (irq != regs[10]))
3004 return (MXSER_ERR_IRQ_CONFLIT);
3008 return (MXSER_ERR_IRQ);
3010 hwconf->irq = ((int) (irq & 0xF000) >> 12);
3011 for (i = 0; i < 8; i++)
3012 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3013 if ((regs[12] & 0x80) == 0) {
3014 return (MXSER_ERR_VECTOR);
3016 hwconf->vector = (int) regs[11]; /* interrupt vector */
3018 hwconf->vector_mask = 0x00FF;
3020 hwconf->vector_mask = 0x000F;
3021 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3022 if (regs[12] & bits) {
3023 hwconf->baud_base[i] = 921600;
3024 hwconf->MaxCanSetBaudRate[i] = 921600; // add by Victor Yu. 09-04-2002
3026 hwconf->baud_base[i] = 115200;
3027 hwconf->MaxCanSetBaudRate[i] = 115200; // add by Victor Yu. 09-04-2002
3030 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3031 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3032 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3033 outb(scratch2, cap + UART_LCR);
3034 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3035 scratch = inb(cap + UART_IIR);
3038 hwconf->uart_type = PORT_16550A;
3040 hwconf->uart_type = PORT_16450;
3045 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3046 request_region(hwconf->vector, 1, "mxser(vector)");
3047 return (hwconf->ports);
3050 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3051 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3052 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3053 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3054 #define EN_CCMD 0x000 /* Chip's command register */
3055 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3056 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3057 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3058 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3059 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3060 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3061 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3062 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3063 static int mxser_read_register(int port, unsigned short *regs)
3065 int i, k, value, id;
3068 id = mxser_program_mode(port);
3071 for (i = 0; i < 14; i++) {
3072 k = (i & 0x3F) | 0x180;
3073 for (j = 0x100; j > 0; j >>= 1) {
3074 outb(CHIP_CS, port);
3076 outb(CHIP_CS | CHIP_DO, port);
3077 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3079 outb(CHIP_CS, port);
3080 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3085 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3086 outb(CHIP_CS, port);
3087 outb(CHIP_CS | CHIP_SK, port);
3088 if (inb(port) & CHIP_DI)
3094 mxser_normal_mode(port);
3098 static int mxser_program_mode(int port)
3101 //unsigned long flags;
3103 spin_lock(&gm_lock);
3111 //restore_flags(flags);
3112 spin_unlock(&gm_lock);
3114 id = inb(port + 1) & 0x1F;
3115 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))
3117 for (i = 0, j = 0; i < 4; i++) {
3121 } else if ((j == 1) && (n == 1)) {
3132 static void mxser_normal_mode(int port)
3136 outb(0xA5, port + 1);
3137 outb(0x80, port + 3);
3138 outb(12, port + 0); /* 9600 bps */
3140 outb(0x03, port + 3); /* 8 data bits */
3141 outb(0x13, port + 4); /* loop back mode */
3142 for (i = 0; i < 16; i++) {
3144 if ((n & 0x61) == 0x60)
3149 outb(0x00, port + 4);
3152 module_init(mxser_module_init);
3153 module_exit(mxser_module_exit);