2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2001 Moxa Technologies (support@moxa.com.tw).
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Original release 10/26/00
25 * 02/06/01 Support MOXA Industio family boards.
26 * 02/06/01 Support TIOCGICOUNT.
27 * 02/06/01 Fix the problem for connecting to serial mouse.
28 * 02/06/01 Fix the problem for H/W flow control.
29 * 02/06/01 Fix the compling warning when CONFIG_PCI
32 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
33 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
34 * - Fixed x86_64 cleanness
35 * - Fixed sleep with spinlock held in mxser_send_break
39 #include <linux/module.h>
40 #include <linux/autoconf.h>
41 #include <linux/errno.h>
42 #include <linux/signal.h>
43 #include <linux/sched.h>
44 #include <linux/timer.h>
45 #include <linux/interrupt.h>
46 #include <linux/tty.h>
47 #include <linux/tty_flip.h>
48 #include <linux/serial.h>
49 #include <linux/serial_reg.h>
50 #include <linux/major.h>
51 #include <linux/string.h>
52 #include <linux/fcntl.h>
53 #include <linux/ptrace.h>
54 #include <linux/gfp.h>
55 #include <linux/ioport.h>
57 #include <linux/smp_lock.h>
58 #include <linux/delay.h>
59 #include <linux/pci.h>
61 #include <asm/system.h>
64 #include <asm/bitops.h>
65 #include <asm/uaccess.h>
69 #define MXSER_VERSION "1.8"
70 #define MXSERMAJOR 174
71 #define MXSERCUMAJOR 175
73 #define MXSER_EVENT_TXLOW 1
74 #define MXSER_EVENT_HANGUP 2
76 #define MXSER_BOARDS 4 /* Max. boards */
77 #define MXSER_PORTS 32 /* Max. ports */
78 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
79 #define MXSER_ISR_PASS_LIMIT 256
81 #define MXSER_ERR_IOADDR -1
82 #define MXSER_ERR_IRQ -2
83 #define MXSER_ERR_IRQ_CONFLIT -3
84 #define MXSER_ERR_VECTOR -4
86 #define SERIAL_TYPE_NORMAL 1
87 #define SERIAL_TYPE_CALLOUT 2
89 #define WAKEUP_CHARS 256
91 #define UART_MCR_AFE 0x20
92 #define UART_LSR_SPECIAL 0x1E
94 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|\
97 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED)
99 #define C168_ASIC_ID 1
100 #define C104_ASIC_ID 2
101 #define C102_ASIC_ID 0xB
102 #define CI132_ASIC_ID 4
103 #define CI134_ASIC_ID 3
104 #define CI104J_ASIC_ID 5
107 MXSER_BOARD_C168_ISA = 1,
108 MXSER_BOARD_C104_ISA,
110 MXSER_BOARD_C168_PCI,
111 MXSER_BOARD_C104_PCI,
112 MXSER_BOARD_C102_ISA,
130 static char *mxser_brdname[] = {
148 "Moxa UC7000 Serial",
154 static int mxser_numports[] = {
178 #define UART_TYPE_NUM 2
180 static const unsigned int Gmoxa_uart_id[UART_TYPE_NUM] = {
181 MOXA_MUST_MU150_HWID,
185 /* This is only for PCI */
186 #define UART_INFO_NUM 3
187 struct mxpciuart_info {
198 static const struct mxpciuart_info Gpci_uart_info[UART_INFO_NUM] = {
199 {MOXA_OTHER_UART, 16, 16, 16, 14, 14, 1, 921600L},
200 {MOXA_MUST_MU150_HWID, 64, 64, 64, 48, 48, 16, 230400L},
201 {MOXA_MUST_MU860_HWID, 128, 128, 128, 96, 96, 32, 921600L}
207 static struct pci_device_id mxser_pcibrds[] = {
208 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C168, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C168_PCI},
209 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_C104_PCI},
210 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132},
211 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP114},
212 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CT114, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CT114},
213 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102},
214 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104U},
215 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP168U},
216 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP132U},
217 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP134U},
218 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104JU, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP104JU},
219 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_RC7000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_RC7000},
220 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP118U},
221 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102UL, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102UL},
222 {PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102U, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MXSER_BOARD_CP102U},
226 MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
231 typedef struct _moxa_pci_info {
232 unsigned short busNum;
233 unsigned short devNum;
234 struct pci_dev *pdev; /* add by Victor Yu. 06-23-2003 */
237 static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
238 static int ttymajor = MXSERMAJOR;
239 static int calloutmajor = MXSERCUMAJOR;
240 static int verbose = 0;
242 /* Variables for insmod */
244 MODULE_AUTHOR("Casper Yang");
245 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
246 module_param_array(ioaddr, int, NULL, 0);
247 module_param(ttymajor, int, 0);
248 module_param(calloutmajor, int, 0);
249 module_param(verbose, bool, 0);
250 MODULE_LICENSE("GPL");
254 unsigned long rxcnt[MXSER_PORTS];
255 unsigned long txcnt[MXSER_PORTS];
262 unsigned long up_rxcnt;
263 unsigned long up_txcnt;
265 unsigned char hold_reason;
268 struct mxser_mon_ext {
269 unsigned long rx_cnt[32];
270 unsigned long tx_cnt[32];
271 unsigned long up_rxcnt[32];
272 unsigned long up_txcnt[32];
273 int modem_status[32];
284 struct mxser_hwconf {
291 int ioaddr[MXSER_PORTS_PER_BOARD];
292 int baud_base[MXSER_PORTS_PER_BOARD];
293 moxa_pci_info pciInfo;
294 int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
295 int MaxCanSetBaudRate[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 09-04-2002 */
296 int opmode_ioaddr[MXSER_PORTS_PER_BOARD]; /* add by Victor Yu. 01-05-2004 */
299 struct mxser_struct {
301 int base; /* port base address */
302 int irq; /* port using irq no. */
303 int vector; /* port irq vector */
304 int vectormask; /* port vector mask */
306 int rx_trigger; /* Rx fifo trigger level */
308 int baud_base; /* max. speed */
309 int flags; /* defined in tty.h */
310 int type; /* UART type */
311 struct tty_struct *tty;
312 int read_status_mask;
313 int ignore_status_mask;
316 int x_char; /* xon/xoff character */
318 unsigned short closing_wait;
319 int IER; /* Interrupt Enable Register */
320 int MCR; /* Modem control register */
322 int count; /* # of fd on device */
323 int blocked_open; /* # of blocked opens */
324 long session; /* Session of opening process */
325 long pgrp; /* pgrp of opening process */
326 unsigned char *xmit_buf;
330 struct work_struct tqueue;
331 struct ktermios normal_termios;
332 struct ktermios callout_termios;
333 wait_queue_head_t open_wait;
334 wait_queue_head_t close_wait;
335 wait_queue_head_t delta_msr_wait;
336 struct async_icount icount; /* kernel counters for the 4 input interrupts */
338 int IsMoxaMustChipFlag; /* add by Victor Yu. 08-30-2002 */
339 int MaxCanSetBaudRate; /* add by Victor Yu. 09-04-2002 */
340 int opmode_ioaddr; /* add by Victor Yu. 01-05-2004 */
341 unsigned char stop_rx;
342 unsigned char ldisc_stop_rx;
344 struct mxser_mon mon_data;
345 unsigned char err_shadow;
349 struct mxser_mstatus {
357 static struct mxser_mstatus GMStatus[MXSER_PORTS];
359 static int mxserBoardCAP[MXSER_BOARDS] = {
361 /* 0x180, 0x280, 0x200, 0x320 */
364 static struct tty_driver *mxvar_sdriver;
365 static struct mxser_struct mxvar_table[MXSER_PORTS];
366 static struct tty_struct *mxvar_tty[MXSER_PORTS + 1];
367 static struct ktermios *mxvar_termios[MXSER_PORTS + 1];
368 static struct ktermios *mxvar_termios_locked[MXSER_PORTS + 1];
369 static struct mxser_log mxvar_log;
370 static int mxvar_diagflag;
371 static unsigned char mxser_msr[MXSER_PORTS + 1];
372 static struct mxser_mon_ext mon_data_ext;
373 static int mxser_set_baud_method[MXSER_PORTS + 1];
374 static spinlock_t gm_lock;
377 * This is used to figure out the divisor speeds and the timeouts
380 static struct mxser_hwconf mxsercfg[MXSER_BOARDS];
386 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf);
387 static int mxser_init(void);
389 /* static void mxser_poll(unsigned long); */
390 static int mxser_get_ISA_conf(int, struct mxser_hwconf *);
391 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf *);
392 static void mxser_do_softint(struct work_struct *);
393 static int mxser_open(struct tty_struct *, struct file *);
394 static void mxser_close(struct tty_struct *, struct file *);
395 static int mxser_write(struct tty_struct *, const unsigned char *, int);
396 static int mxser_write_room(struct tty_struct *);
397 static void mxser_flush_buffer(struct tty_struct *);
398 static int mxser_chars_in_buffer(struct tty_struct *);
399 static void mxser_flush_chars(struct tty_struct *);
400 static void mxser_put_char(struct tty_struct *, unsigned char);
401 static int mxser_ioctl(struct tty_struct *, struct file *, uint, ulong);
402 static int mxser_ioctl_special(unsigned int, void __user *);
403 static void mxser_throttle(struct tty_struct *);
404 static void mxser_unthrottle(struct tty_struct *);
405 static void mxser_set_termios(struct tty_struct *, struct ktermios *);
406 static void mxser_stop(struct tty_struct *);
407 static void mxser_start(struct tty_struct *);
408 static void mxser_hangup(struct tty_struct *);
409 static void mxser_rs_break(struct tty_struct *, int);
410 static irqreturn_t mxser_interrupt(int, void *);
411 static void mxser_receive_chars(struct mxser_struct *, int *);
412 static void mxser_transmit_chars(struct mxser_struct *);
413 static void mxser_check_modem_status(struct mxser_struct *, int);
414 static int mxser_block_til_ready(struct tty_struct *, struct file *, struct mxser_struct *);
415 static int mxser_startup(struct mxser_struct *);
416 static void mxser_shutdown(struct mxser_struct *);
417 static int mxser_change_speed(struct mxser_struct *, struct ktermios *old_termios);
418 static int mxser_get_serial_info(struct mxser_struct *, struct serial_struct __user *);
419 static int mxser_set_serial_info(struct mxser_struct *, struct serial_struct __user *);
420 static int mxser_get_lsr_info(struct mxser_struct *, unsigned int __user *);
421 static void mxser_send_break(struct mxser_struct *, int);
422 static int mxser_tiocmget(struct tty_struct *, struct file *);
423 static int mxser_tiocmset(struct tty_struct *, struct file *, unsigned int, unsigned int);
424 static int mxser_set_baud(struct mxser_struct *info, long newspd);
425 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout);
427 static void mxser_startrx(struct tty_struct *tty);
428 static void mxser_stoprx(struct tty_struct *tty);
431 static int CheckIsMoxaMust(int io)
436 outb(0, io + UART_LCR);
437 DISABLE_MOXA_MUST_ENCHANCE_MODE(io);
438 oldmcr = inb(io + UART_MCR);
439 outb(0, io + UART_MCR);
440 SET_MOXA_MUST_XON1_VALUE(io, 0x11);
441 if ((hwid = inb(io + UART_MCR)) != 0) {
442 outb(oldmcr, io + UART_MCR);
443 return MOXA_OTHER_UART;
446 GET_MOXA_MUST_HARDWARE_ID(io, &hwid);
447 for (i = 0; i < UART_TYPE_NUM; i++) {
448 if (hwid == Gmoxa_uart_id[i])
451 return MOXA_OTHER_UART;
454 /* above is modified by Victor Yu. 08-15-2002 */
456 static const struct tty_operations mxser_ops = {
458 .close = mxser_close,
459 .write = mxser_write,
460 .put_char = mxser_put_char,
461 .flush_chars = mxser_flush_chars,
462 .write_room = mxser_write_room,
463 .chars_in_buffer = mxser_chars_in_buffer,
464 .flush_buffer = mxser_flush_buffer,
465 .ioctl = mxser_ioctl,
466 .throttle = mxser_throttle,
467 .unthrottle = mxser_unthrottle,
468 .set_termios = mxser_set_termios,
470 .start = mxser_start,
471 .hangup = mxser_hangup,
472 .break_ctl = mxser_rs_break,
473 .wait_until_sent = mxser_wait_until_sent,
474 .tiocmget = mxser_tiocmget,
475 .tiocmset = mxser_tiocmset,
479 * The MOXA Smartio/Industio serial driver boot-time initialization code!
482 static int __init mxser_module_init(void)
487 printk(KERN_DEBUG "Loading module mxser ...\n");
490 printk(KERN_DEBUG "Done.\n");
494 static void __exit mxser_module_exit(void)
499 printk(KERN_DEBUG "Unloading module mxser ...\n");
501 err = tty_unregister_driver(mxvar_sdriver);
503 put_tty_driver(mxvar_sdriver);
505 printk(KERN_ERR "Couldn't unregister MOXA Smartio/Industio family serial driver\n");
507 for (i = 0; i < MXSER_BOARDS; i++) {
508 struct pci_dev *pdev;
510 if (mxsercfg[i].board_type == -1)
513 pdev = mxsercfg[i].pciInfo.pdev;
514 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
515 if (pdev != NULL) { /* PCI */
516 release_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2));
517 release_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3));
520 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
521 release_region(mxsercfg[i].vector, 1);
526 printk(KERN_DEBUG "Done.\n");
529 static void process_txrx_fifo(struct mxser_struct *info)
533 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
534 info->rx_trigger = 1;
535 info->rx_high_water = 1;
536 info->rx_low_water = 1;
537 info->xmit_fifo_size = 1;
539 for (i = 0; i < UART_INFO_NUM; i++) {
540 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
541 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
542 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
543 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
544 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
551 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
553 struct mxser_struct *info;
557 n = board * MXSER_PORTS_PER_BOARD;
558 info = &mxvar_table[n];
560 printk(KERN_DEBUG " ttyMI%d - ttyMI%d ",
561 n, n + hwconf->ports - 1);
562 printk(" max. baud rate = %d bps.\n",
563 hwconf->MaxCanSetBaudRate[0]);
566 for (i = 0; i < hwconf->ports; i++, n++, info++) {
568 info->base = hwconf->ioaddr[i];
569 info->irq = hwconf->irq;
570 info->vector = hwconf->vector;
571 info->vectormask = hwconf->vector_mask;
572 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; /* add by Victor Yu. 01-05-2004 */
574 info->ldisc_stop_rx = 0;
576 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
577 /* Enhance mode enabled here */
578 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
579 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
582 info->flags = ASYNC_SHARE_IRQ;
583 info->type = hwconf->uart_type;
584 info->baud_base = hwconf->baud_base[i];
586 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
588 process_txrx_fifo(info);
591 info->custom_divisor = hwconf->baud_base[i] * 16;
592 info->close_delay = 5 * HZ / 10;
593 info->closing_wait = 30 * HZ;
594 INIT_WORK(&info->tqueue, mxser_do_softint);
595 info->normal_termios = mxvar_sdriver->init_termios;
596 init_waitqueue_head(&info->open_wait);
597 init_waitqueue_head(&info->close_wait);
598 init_waitqueue_head(&info->delta_msr_wait);
599 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
600 info->err_shadow = 0;
601 spin_lock_init(&info->slock);
604 * Allocate the IRQ if necessary
608 /* before set INT ISR, disable all int */
609 for (i = 0; i < hwconf->ports; i++) {
610 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0,
611 hwconf->ioaddr[i] + UART_IER);
614 n = board * MXSER_PORTS_PER_BOARD;
615 info = &mxvar_table[n];
617 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info),
620 printk(KERN_ERR "Board %d: %s",
621 board, mxser_brdname[hwconf->board_type - 1]);
622 printk(" Request irq failed, IRQ (%d) may conflict with"
623 " another device.\n", info->irq);
629 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
631 mxsercfg[board] = *hwconf;
635 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
638 /* unsigned int val; */
639 unsigned int ioaddress;
640 struct pci_dev *pdev = hwconf->pciInfo.pdev;
643 hwconf->board_type = board_type;
644 hwconf->ports = mxser_numports[board_type - 1];
645 ioaddress = pci_resource_start(pdev, 2);
646 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2),
649 for (i = 0; i < hwconf->ports; i++)
650 hwconf->ioaddr[i] = ioaddress + 8 * i;
653 ioaddress = pci_resource_start(pdev, 3);
654 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3),
656 hwconf->vector = ioaddress;
659 hwconf->irq = hwconf->pciInfo.pdev->irq;
661 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
662 hwconf->uart_type = PORT_16550A;
663 hwconf->vector_mask = 0;
666 for (i = 0; i < hwconf->ports; i++) {
667 for (j = 0; j < UART_INFO_NUM; j++) {
668 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
669 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
671 /* exception....CP-102 */
672 if (board_type == MXSER_BOARD_CP102)
673 hwconf->MaxCanSetBaudRate[i] = 921600;
679 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
680 for (i = 0; i < hwconf->ports; i++) {
682 hwconf->opmode_ioaddr[i] = ioaddress + 4;
684 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
686 outb(0, ioaddress + 4); /* default set to RS232 mode */
687 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
690 for (i = 0; i < hwconf->ports; i++) {
691 hwconf->vector_mask |= (1 << i);
692 hwconf->baud_base[i] = 921600;
698 static int mxser_init(void)
700 int i, m, retval, b, n;
701 struct pci_dev *pdev = NULL;
703 unsigned char busnum, devnum;
704 struct mxser_hwconf hwconf;
706 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
709 spin_lock_init(&gm_lock);
711 for (i = 0; i < MXSER_BOARDS; i++) {
712 mxsercfg[i].board_type = -1;
715 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
718 /* Initialize the tty_driver structure */
719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
720 mxvar_sdriver->owner = THIS_MODULE;
721 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
722 mxvar_sdriver->name = "ttyMI";
723 mxvar_sdriver->major = ttymajor;
724 mxvar_sdriver->minor_start = 0;
725 mxvar_sdriver->num = MXSER_PORTS + 1;
726 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
727 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
728 mxvar_sdriver->init_termios = tty_std_termios;
729 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
730 mxvar_sdriver->init_termios.c_ispeed = 9600;
731 mxvar_sdriver->init_termios.c_ospeed = 9600;
732 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
733 tty_set_operations(mxvar_sdriver, &mxser_ops);
734 mxvar_sdriver->ttys = mxvar_tty;
735 mxvar_sdriver->termios = mxvar_termios;
736 mxvar_sdriver->termios_locked = mxvar_termios_locked;
739 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
740 memset(&mxvar_log, 0, sizeof(struct mxser_log));
742 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
743 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
744 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
745 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
748 /* Start finding ISA boards here */
749 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
752 if (!(cap = mxserBoardCAP[b]))
755 retval = mxser_get_ISA_conf(cap, &hwconf);
758 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
759 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
762 if (retval == MXSER_ERR_IRQ)
763 printk(KERN_ERR "Invalid interrupt number, "
764 "board not configured\n");
765 else if (retval == MXSER_ERR_IRQ_CONFLIT)
766 printk(KERN_ERR "Invalid interrupt number, "
767 "board not configured\n");
768 else if (retval == MXSER_ERR_VECTOR)
769 printk(KERN_ERR "Invalid interrupt vector, "
770 "board not configured\n");
771 else if (retval == MXSER_ERR_IOADDR)
772 printk(KERN_ERR "Invalid I/O address, "
773 "board not configured\n");
778 hwconf.pciInfo.busNum = 0;
779 hwconf.pciInfo.devNum = 0;
780 hwconf.pciInfo.pdev = NULL;
782 mxser_getcfg(m, &hwconf);
784 * init mxsercfg first,
785 * or mxsercfg data is not correct on ISR.
787 /* mxser_initbrd will hook ISR. */
788 if (mxser_initbrd(m, &hwconf) < 0)
794 /* Start finding ISA boards from module arg */
795 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
798 if (!(cap = ioaddr[b]))
801 retval = mxser_get_ISA_conf(cap, &hwconf);
804 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
805 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
808 if (retval == MXSER_ERR_IRQ)
809 printk(KERN_ERR "Invalid interrupt number, "
810 "board not configured\n");
811 else if (retval == MXSER_ERR_IRQ_CONFLIT)
812 printk(KERN_ERR "Invalid interrupt number, "
813 "board not configured\n");
814 else if (retval == MXSER_ERR_VECTOR)
815 printk(KERN_ERR "Invalid interrupt vector, "
816 "board not configured\n");
817 else if (retval == MXSER_ERR_IOADDR)
818 printk(KERN_ERR "Invalid I/O address, "
819 "board not configured\n");
824 hwconf.pciInfo.busNum = 0;
825 hwconf.pciInfo.devNum = 0;
826 hwconf.pciInfo.pdev = NULL;
828 mxser_getcfg(m, &hwconf);
830 * init mxsercfg first,
831 * or mxsercfg data is not correct on ISR.
833 /* mxser_initbrd will hook ISR. */
834 if (mxser_initbrd(m, &hwconf) < 0)
840 /* start finding PCI board here */
842 n = ARRAY_SIZE(mxser_pcibrds) - 1;
846 pdev = pci_get_device(mxser_pcibrds[b].vendor,
847 mxser_pcibrds[b].device, pdev);
852 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
853 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
854 hwconf.pciInfo.pdev = pdev;
855 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
856 mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
857 busnum, devnum >> 3);
859 if (m >= MXSER_BOARDS)
861 "Too many Smartio/Industio family boards find "
862 "(maximum %d), board not configured\n",
865 if (pci_enable_device(pdev)) {
866 printk(KERN_ERR "Moxa SmartI/O PCI enable "
870 retval = mxser_get_PCI_conf(busnum, devnum,
871 (int)mxser_pcibrds[b].driver_data,
874 if (retval == MXSER_ERR_IRQ)
876 "Invalid interrupt number, "
877 "board not configured\n");
878 else if (retval == MXSER_ERR_IRQ_CONFLIT)
880 "Invalid interrupt number, "
881 "board not configured\n");
882 else if (retval == MXSER_ERR_VECTOR)
884 "Invalid interrupt vector, "
885 "board not configured\n");
886 else if (retval == MXSER_ERR_IOADDR)
888 "Invalid I/O address, "
889 "board not configured\n");
892 mxser_getcfg(m, &hwconf);
893 /* init mxsercfg first,
894 * or mxsercfg data is not correct on ISR.
896 /* mxser_initbrd will hook ISR. */
897 if (mxser_initbrd(m, &hwconf) < 0)
900 /* Keep an extra reference if we succeeded. It will
901 be returned at unload time */
907 retval = tty_register_driver(mxvar_sdriver);
909 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family"
911 put_tty_driver(mxvar_sdriver);
913 for (i = 0; i < MXSER_BOARDS; i++) {
914 if (mxsercfg[i].board_type == -1)
917 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
918 /* todo: release io, vector */
927 static void mxser_do_softint(struct work_struct *work)
929 struct mxser_struct *info =
930 container_of(work, struct mxser_struct, tqueue);
931 struct tty_struct *tty;
936 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
938 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
943 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
945 unsigned char status = 0;
947 status = inb(baseaddr + UART_MSR);
949 mxser_msr[port] &= 0x0F;
950 mxser_msr[port] |= status;
951 status = mxser_msr[port];
959 * This routine is called whenever a serial port is opened. It
960 * enables interrupts for a serial port, linking in its async structure into
961 * the IRQ chain. It also performs the serial-specific
962 * initialization for the tty structure.
964 static int mxser_open(struct tty_struct *tty, struct file *filp)
966 struct mxser_struct *info;
969 /* initialize driver_data in case something fails */
970 tty->driver_data = NULL;
973 if (line == MXSER_PORTS)
975 if (line < 0 || line > MXSER_PORTS)
977 info = mxvar_table + line;
981 tty->driver_data = info;
984 * Start up serial port
986 retval = mxser_startup(info);
990 retval = mxser_block_til_ready(tty, filp, info);
996 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
997 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
998 *tty->termios = info->normal_termios;
1000 *tty->termios = info->callout_termios;
1001 mxser_change_speed(info, NULL);
1004 info->session = process_session(current);
1005 info->pgrp = process_group(current);
1008 status = mxser_get_msr(info->base, 0, info->port);
1009 mxser_check_modem_status(info, status);
1012 /* unmark here for very high baud rate (ex. 921600 bps) used */
1013 tty->low_latency = 1;
1018 * This routine is called when the serial port gets closed. First, we
1019 * wait for the last remaining data to be sent. Then, we unlink its
1020 * async structure from the interrupt chain if necessary, and we free
1021 * that IRQ if nothing is left in the chain.
1023 static void mxser_close(struct tty_struct *tty, struct file *filp)
1025 struct mxser_struct *info = tty->driver_data;
1027 unsigned long timeout;
1028 unsigned long flags;
1029 struct tty_ldisc *ld;
1031 if (tty->index == MXSER_PORTS)
1036 spin_lock_irqsave(&info->slock, flags);
1038 if (tty_hung_up_p(filp)) {
1039 spin_unlock_irqrestore(&info->slock, flags);
1042 if ((tty->count == 1) && (info->count != 1)) {
1044 * Uh, oh. tty->count is 1, which means that the tty
1045 * structure will be freed. Info->count should always
1046 * be one in these conditions. If it's greater than
1047 * one, we've got real problems, since it means the
1048 * serial port won't be shutdown.
1050 printk(KERN_ERR "mxser_close: bad serial port count; "
1051 "tty->count is 1, info->count is %d\n", info->count);
1054 if (--info->count < 0) {
1055 printk(KERN_ERR "mxser_close: bad serial port count for "
1056 "ttys%d: %d\n", info->port, info->count);
1060 spin_unlock_irqrestore(&info->slock, flags);
1063 info->flags |= ASYNC_CLOSING;
1064 spin_unlock_irqrestore(&info->slock, flags);
1066 * Save the termios structure, since this port may have
1067 * separate termios for callout and dialin.
1069 if (info->flags & ASYNC_NORMAL_ACTIVE)
1070 info->normal_termios = *tty->termios;
1072 * Now we wait for the transmit buffer to clear; and we notify
1073 * the line discipline to only process XON/XOFF characters.
1076 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1077 tty_wait_until_sent(tty, info->closing_wait);
1079 * At this point we stop accepting input. To do this, we
1080 * disable the receive line status interrupts, and tell the
1081 * interrupt driver to stop checking the data ready bit in the
1082 * line status register.
1084 info->IER &= ~UART_IER_RLSI;
1085 if (info->IsMoxaMustChipFlag)
1086 info->IER &= ~MOXA_MUST_RECV_ISR;
1088 info->read_status_mask &= ~UART_LSR_DR;
1090 if (info->flags & ASYNC_INITIALIZED) {
1091 outb(info->IER, info->base + UART_IER);
1093 * Before we drop DTR, make sure the UART transmitter
1094 * has completely drained; this is especially
1095 * important if there is a transmit FIFO!
1097 timeout = jiffies + HZ;
1098 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1099 schedule_timeout_interruptible(5);
1100 if (time_after(jiffies, timeout))
1104 mxser_shutdown(info);
1106 if (tty->driver->flush_buffer)
1107 tty->driver->flush_buffer(tty);
1109 ld = tty_ldisc_ref(tty);
1111 if (ld->flush_buffer)
1112 ld->flush_buffer(tty);
1113 tty_ldisc_deref(ld);
1119 if (info->blocked_open) {
1120 if (info->close_delay)
1121 schedule_timeout_interruptible(info->close_delay);
1122 wake_up_interruptible(&info->open_wait);
1125 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1126 wake_up_interruptible(&info->close_wait);
1130 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1133 struct mxser_struct *info = tty->driver_data;
1134 unsigned long flags;
1136 if (!info->xmit_buf)
1140 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1141 SERIAL_XMIT_SIZE - info->xmit_head));
1145 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1146 spin_lock_irqsave(&info->slock, flags);
1147 info->xmit_head = (info->xmit_head + c) &
1148 (SERIAL_XMIT_SIZE - 1);
1149 info->xmit_cnt += c;
1150 spin_unlock_irqrestore(&info->slock, flags);
1157 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1158 if (!tty->hw_stopped ||
1159 (info->type == PORT_16550A) ||
1160 (info->IsMoxaMustChipFlag)) {
1161 spin_lock_irqsave(&info->slock, flags);
1162 info->IER |= UART_IER_THRI;
1163 outb(info->IER, info->base + UART_IER);
1164 spin_unlock_irqrestore(&info->slock, flags);
1170 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1172 struct mxser_struct *info = tty->driver_data;
1173 unsigned long flags;
1175 if (!info->xmit_buf)
1178 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1181 spin_lock_irqsave(&info->slock, flags);
1182 info->xmit_buf[info->xmit_head++] = ch;
1183 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1185 spin_unlock_irqrestore(&info->slock, flags);
1186 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1187 if (!tty->hw_stopped ||
1188 (info->type == PORT_16550A) ||
1189 info->IsMoxaMustChipFlag) {
1190 spin_lock_irqsave(&info->slock, flags);
1191 info->IER |= UART_IER_THRI;
1192 outb(info->IER, info->base + UART_IER);
1193 spin_unlock_irqrestore(&info->slock, flags);
1199 static void mxser_flush_chars(struct tty_struct *tty)
1201 struct mxser_struct *info = tty->driver_data;
1202 unsigned long flags;
1204 if (info->xmit_cnt <= 0 ||
1208 (info->type != PORT_16550A) &&
1209 (!info->IsMoxaMustChipFlag)
1213 spin_lock_irqsave(&info->slock, flags);
1215 info->IER |= UART_IER_THRI;
1216 outb(info->IER, info->base + UART_IER);
1218 spin_unlock_irqrestore(&info->slock, flags);
1221 static int mxser_write_room(struct tty_struct *tty)
1223 struct mxser_struct *info = tty->driver_data;
1226 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1232 static int mxser_chars_in_buffer(struct tty_struct *tty)
1234 struct mxser_struct *info = tty->driver_data;
1235 return info->xmit_cnt;
1238 static void mxser_flush_buffer(struct tty_struct *tty)
1240 struct mxser_struct *info = tty->driver_data;
1242 unsigned long flags;
1245 spin_lock_irqsave(&info->slock, flags);
1246 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1248 /* below added by shinhay */
1249 fcr = inb(info->base + UART_FCR);
1250 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1251 info->base + UART_FCR);
1252 outb(fcr, info->base + UART_FCR);
1254 spin_unlock_irqrestore(&info->slock, flags);
1255 /* above added by shinhay */
1260 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1262 struct mxser_struct *info = tty->driver_data;
1264 struct async_icount cprev, cnow; /* kernel counter temps */
1265 struct serial_icounter_struct __user *p_cuser;
1266 unsigned long templ;
1267 unsigned long flags;
1268 void __user *argp = (void __user *)arg;
1270 if (tty->index == MXSER_PORTS)
1271 return mxser_ioctl_special(cmd, argp);
1273 /* following add by Victor Yu. 01-05-2004 */
1274 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1276 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1278 unsigned char val, mask;
1281 if (cmd == MOXA_SET_OP_MODE) {
1282 if (get_user(opmode, (int __user *) argp))
1284 if (opmode != RS232_MODE &&
1285 opmode != RS485_2WIRE_MODE &&
1286 opmode != RS422_MODE &&
1287 opmode != RS485_4WIRE_MODE)
1291 val = inb(info->opmode_ioaddr);
1293 val |= (opmode << shiftbit);
1294 outb(val, info->opmode_ioaddr);
1297 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1298 opmode &= OP_MODE_MASK;
1299 if (copy_to_user(argp, &opmode, sizeof(int)))
1304 /* above add by Victor Yu. 01-05-2004 */
1306 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1307 if (tty->flags & (1 << TTY_IO_ERROR))
1311 case TCSBRK: /* SVID version: non-zero arg --> no break */
1312 retval = tty_check_change(tty);
1315 tty_wait_until_sent(tty, 0);
1317 mxser_send_break(info, HZ / 4); /* 1/4 second */
1319 case TCSBRKP: /* support for POSIX tcsendbreak() */
1320 retval = tty_check_change(tty);
1323 tty_wait_until_sent(tty, 0);
1324 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1327 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1329 if (get_user(templ, (unsigned long __user *) argp))
1332 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1335 return mxser_get_serial_info(info, argp);
1337 return mxser_set_serial_info(info, argp);
1338 case TIOCSERGETLSR: /* Get line status register */
1339 return mxser_get_lsr_info(info, argp);
1341 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1342 * - mask passed in arg for lines of interest
1343 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1344 * Caller should use TIOCGICOUNT to see which one it was
1347 DECLARE_WAITQUEUE(wait, current);
1349 spin_lock_irqsave(&info->slock, flags);
1350 cprev = info->icount; /* note the counters on entry */
1351 spin_unlock_irqrestore(&info->slock, flags);
1353 add_wait_queue(&info->delta_msr_wait, &wait);
1355 spin_lock_irqsave(&info->slock, flags);
1356 cnow = info->icount; /* atomic copy */
1357 spin_unlock_irqrestore(&info->slock, flags);
1359 set_current_state(TASK_INTERRUPTIBLE);
1360 if (((arg & TIOCM_RNG) &&
1361 (cnow.rng != cprev.rng)) ||
1362 ((arg & TIOCM_DSR) &&
1363 (cnow.dsr != cprev.dsr)) ||
1364 ((arg & TIOCM_CD) &&
1365 (cnow.dcd != cprev.dcd)) ||
1366 ((arg & TIOCM_CTS) &&
1367 (cnow.cts != cprev.cts))) {
1371 /* see if a signal did it */
1372 if (signal_pending(current)) {
1378 current->state = TASK_RUNNING;
1379 remove_wait_queue(&info->delta_msr_wait, &wait);
1384 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1385 * Return: write counters to the user passed counter struct
1386 * NB: both 1->0 and 0->1 transitions are counted except for
1387 * RI where only 0->1 is counted.
1390 spin_lock_irqsave(&info->slock, flags);
1391 cnow = info->icount;
1392 spin_unlock_irqrestore(&info->slock, flags);
1394 /* modified by casper 1/11/2000 */
1395 if (put_user(cnow.frame, &p_cuser->frame))
1397 if (put_user(cnow.brk, &p_cuser->brk))
1399 if (put_user(cnow.overrun, &p_cuser->overrun))
1401 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1403 if (put_user(cnow.parity, &p_cuser->parity))
1405 if (put_user(cnow.rx, &p_cuser->rx))
1407 if (put_user(cnow.tx, &p_cuser->tx))
1409 put_user(cnow.cts, &p_cuser->cts);
1410 put_user(cnow.dsr, &p_cuser->dsr);
1411 put_user(cnow.rng, &p_cuser->rng);
1412 put_user(cnow.dcd, &p_cuser->dcd);
1414 case MOXA_HighSpeedOn:
1415 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1416 case MOXA_SDS_RSTICOUNTER: {
1417 info->mon_data.rxcnt = 0;
1418 info->mon_data.txcnt = 0;
1421 /* (above) added by James. */
1422 case MOXA_ASPP_SETBAUD:{
1424 if (get_user(baud, (long __user *)argp))
1426 mxser_set_baud(info, baud);
1429 case MOXA_ASPP_GETBAUD:
1430 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1435 case MOXA_ASPP_OQUEUE:{
1438 len = mxser_chars_in_buffer(tty);
1440 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1442 len += (lsr ? 0 : 1);
1444 if (copy_to_user(argp, &len, sizeof(int)))
1449 case MOXA_ASPP_MON: {
1452 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1454 status = mxser_get_msr(info->base, 1, info->port, info);
1455 mxser_check_modem_status(info, status);
1457 mcr = inb(info->base + UART_MCR);
1458 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1459 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1461 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1463 if (mcr & MOXA_MUST_MCR_TX_XON)
1464 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1466 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1468 if (info->tty->hw_stopped)
1469 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1471 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1473 if (copy_to_user(argp, &info->mon_data,
1474 sizeof(struct mxser_mon)))
1480 case MOXA_ASPP_LSTATUS: {
1481 if (copy_to_user(argp, &info->err_shadow,
1482 sizeof(unsigned char)))
1485 info->err_shadow = 0;
1488 case MOXA_SET_BAUD_METHOD: {
1491 if (get_user(method, (int __user *)argp))
1493 mxser_set_baud_method[info->port] = method;
1494 if (copy_to_user(argp, &method, sizeof(int)))
1500 return -ENOIOCTLCMD;
1506 #define CMSPAR 010000000000
1509 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1511 int i, result, status;
1515 if (copy_to_user(argp, mxsercfg,
1516 sizeof(struct mxser_hwconf) * 4))
1519 case MOXA_GET_MAJOR:
1520 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1524 case MOXA_GET_CUMAJOR:
1525 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1529 case MOXA_CHKPORTENABLE:
1531 for (i = 0; i < MXSER_PORTS; i++) {
1532 if (mxvar_table[i].base)
1535 return put_user(result, (unsigned long __user *)argp);
1536 case MOXA_GETDATACOUNT:
1537 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1540 case MOXA_GETMSTATUS:
1541 for (i = 0; i < MXSER_PORTS; i++) {
1543 if (!mxvar_table[i].base) {
1544 GMStatus[i].dcd = 0;
1545 GMStatus[i].dsr = 0;
1546 GMStatus[i].cts = 0;
1550 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1551 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1553 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1555 status = inb(mxvar_table[i].base + UART_MSR);
1556 if (status & 0x80 /*UART_MSR_DCD */ )
1557 GMStatus[i].dcd = 1;
1559 GMStatus[i].dcd = 0;
1561 if (status & 0x20 /*UART_MSR_DSR */ )
1562 GMStatus[i].dsr = 1;
1564 GMStatus[i].dsr = 0;
1567 if (status & 0x10 /*UART_MSR_CTS */ )
1568 GMStatus[i].cts = 1;
1570 GMStatus[i].cts = 0;
1572 if (copy_to_user(argp, GMStatus,
1573 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1576 case MOXA_ASPP_MON_EXT: {
1580 unsigned cflag, iflag;
1582 for (i = 0; i < MXSER_PORTS; i++) {
1583 if (!mxvar_table[i].base)
1586 status = mxser_get_msr(mxvar_table[i].base, 0,
1587 i, &(mxvar_table[i]));
1589 mxser_check_modem_status(&mxvar_table[i],
1592 if (status & UART_MSR_TERI)
1593 mxvar_table[i].icount.rng++;
1594 if (status & UART_MSR_DDSR)
1595 mxvar_table[i].icount.dsr++;
1596 if (status & UART_MSR_DDCD)
1597 mxvar_table[i].icount.dcd++;
1598 if (status & UART_MSR_DCTS)
1599 mxvar_table[i].icount.cts++;
1601 mxvar_table[i].mon_data.modem_status = status;
1602 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1603 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1604 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1605 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1606 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1607 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1609 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1610 cflag = mxvar_table[i].normal_termios.c_cflag;
1611 iflag = mxvar_table[i].normal_termios.c_iflag;
1613 cflag = mxvar_table[i].tty->termios->c_cflag;
1614 iflag = mxvar_table[i].tty->termios->c_iflag;
1617 mon_data_ext.databits[i] = cflag & CSIZE;
1619 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1621 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1623 mon_data_ext.flowctrl[i] = 0x00;
1625 if (cflag & CRTSCTS)
1626 mon_data_ext.flowctrl[i] |= 0x03;
1628 if (iflag & (IXON | IXOFF))
1629 mon_data_ext.flowctrl[i] |= 0x0C;
1631 if (mxvar_table[i].type == PORT_16550A)
1632 mon_data_ext.fifo[i] = 1;
1634 mon_data_ext.fifo[i] = 0;
1638 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1639 opmode &= OP_MODE_MASK;
1641 mon_data_ext.iftype[i] = opmode;
1644 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1651 return -ENOIOCTLCMD;
1656 static void mxser_stoprx(struct tty_struct *tty)
1658 struct mxser_struct *info = tty->driver_data;
1659 /* unsigned long flags; */
1661 info->ldisc_stop_rx = 1;
1663 /* MX_LOCK(&info->slock); */
1664 /* following add by Victor Yu. 09-02-2002 */
1665 if (info->IsMoxaMustChipFlag) {
1666 info->IER &= ~MOXA_MUST_RECV_ISR;
1667 outb(info->IER, info->base + UART_IER);
1669 /* above add by Victor Yu. 09-02-2002 */
1670 info->x_char = STOP_CHAR(tty);
1671 /* mask by Victor Yu. 09-02-2002 */
1672 /* outb(info->IER, 0); */
1673 outb(0, info->base + UART_IER);
1674 info->IER |= UART_IER_THRI;
1675 /* force Tx interrupt */
1676 outb(info->IER, info->base + UART_IER);
1677 } /* add by Victor Yu. 09-02-2002 */
1678 /* MX_UNLOCK(&info->slock); */
1681 if (info->tty->termios->c_cflag & CRTSCTS) {
1682 /* MX_LOCK(&info->slock); */
1683 info->MCR &= ~UART_MCR_RTS;
1684 outb(info->MCR, info->base + UART_MCR);
1685 /* MX_UNLOCK(&info->slock); */
1689 static void mxser_startrx(struct tty_struct *tty)
1691 struct mxser_struct *info = tty->driver_data;
1692 /* unsigned long flags; */
1694 info->ldisc_stop_rx = 0;
1699 /* MX_LOCK(&info->slock); */
1701 /* following add by Victor Yu. 09-02-2002 */
1702 if (info->IsMoxaMustChipFlag) {
1703 info->IER |= MOXA_MUST_RECV_ISR;
1704 outb(info->IER, info->base + UART_IER);
1706 /* above add by Victor Yu. 09-02-2002 */
1708 info->x_char = START_CHAR(tty);
1709 /* mask by Victor Yu. 09-02-2002 */
1710 /* outb(info->IER, 0); */
1711 /* add by Victor Yu. 09-02-2002 */
1712 outb(0, info->base + UART_IER);
1713 /* force Tx interrupt */
1714 info->IER |= UART_IER_THRI;
1715 outb(info->IER, info->base + UART_IER);
1716 } /* add by Victor Yu. 09-02-2002 */
1717 /* MX_UNLOCK(&info->slock); */
1721 if (info->tty->termios->c_cflag & CRTSCTS) {
1722 /* MX_LOCK(&info->slock); */
1723 info->MCR |= UART_MCR_RTS;
1724 outb(info->MCR, info->base + UART_MCR);
1725 /* MX_UNLOCK(&info->slock); */
1730 * This routine is called by the upper-layer tty layer to signal that
1731 * incoming characters should be throttled.
1733 static void mxser_throttle(struct tty_struct *tty)
1735 /* struct mxser_struct *info = tty->driver_data; */
1736 /* unsigned long flags; */
1738 /* MX_LOCK(&info->slock); */
1740 /* MX_UNLOCK(&info->slock); */
1743 static void mxser_unthrottle(struct tty_struct *tty)
1745 /* struct mxser_struct *info = tty->driver_data; */
1746 /* unsigned long flags; */
1748 /* MX_LOCK(&info->slock); */
1750 /* MX_UNLOCK(&info->slock); */
1753 static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1755 struct mxser_struct *info = tty->driver_data;
1756 unsigned long flags;
1758 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1759 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1761 mxser_change_speed(info, old_termios);
1763 if ((old_termios->c_cflag & CRTSCTS) &&
1764 !(tty->termios->c_cflag & CRTSCTS)) {
1765 tty->hw_stopped = 0;
1770 /* Handle sw stopped */
1771 if ((old_termios->c_iflag & IXON) &&
1772 !(tty->termios->c_iflag & IXON)) {
1775 /* following add by Victor Yu. 09-02-2002 */
1776 if (info->IsMoxaMustChipFlag) {
1777 spin_lock_irqsave(&info->slock, flags);
1778 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1779 spin_unlock_irqrestore(&info->slock, flags);
1781 /* above add by Victor Yu. 09-02-2002 */
1788 * mxser_stop() and mxser_start()
1790 * This routines are called before setting or resetting tty->stopped.
1791 * They enable or disable transmitter interrupts, as necessary.
1793 static void mxser_stop(struct tty_struct *tty)
1795 struct mxser_struct *info = tty->driver_data;
1796 unsigned long flags;
1798 spin_lock_irqsave(&info->slock, flags);
1799 if (info->IER & UART_IER_THRI) {
1800 info->IER &= ~UART_IER_THRI;
1801 outb(info->IER, info->base + UART_IER);
1803 spin_unlock_irqrestore(&info->slock, flags);
1806 static void mxser_start(struct tty_struct *tty)
1808 struct mxser_struct *info = tty->driver_data;
1809 unsigned long flags;
1811 spin_lock_irqsave(&info->slock, flags);
1812 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1813 info->IER |= UART_IER_THRI;
1814 outb(info->IER, info->base + UART_IER);
1816 spin_unlock_irqrestore(&info->slock, flags);
1820 * mxser_wait_until_sent() --- wait until the transmitter is empty
1822 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1824 struct mxser_struct *info = tty->driver_data;
1825 unsigned long orig_jiffies, char_time;
1828 if (info->type == PORT_UNKNOWN)
1831 if (info->xmit_fifo_size == 0)
1832 return; /* Just in case.... */
1834 orig_jiffies = jiffies;
1836 * Set the check interval to be 1/5 of the estimated time to
1837 * send a single character, and make it at least 1. The check
1838 * interval should also be less than the timeout.
1840 * Note: we have to use pretty tight timings here to satisfy
1843 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1844 char_time = char_time / 5;
1847 if (timeout && timeout < char_time)
1848 char_time = timeout;
1850 * If the transmitter hasn't cleared in twice the approximate
1851 * amount of time to send the entire FIFO, it probably won't
1852 * ever clear. This assumes the UART isn't doing flow
1853 * control, which is currently the case. Hence, if it ever
1854 * takes longer than info->timeout, this is probably due to a
1855 * UART bug of some kind. So, we clamp the timeout parameter at
1858 if (!timeout || timeout > 2 * info->timeout)
1859 timeout = 2 * info->timeout;
1860 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1861 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1862 timeout, char_time);
1863 printk("jiff=%lu...", jiffies);
1865 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1866 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1867 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1869 schedule_timeout_interruptible(char_time);
1870 if (signal_pending(current))
1872 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1875 set_current_state(TASK_RUNNING);
1877 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1878 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1884 * This routine is called by tty_hangup() when a hangup is signaled.
1886 void mxser_hangup(struct tty_struct *tty)
1888 struct mxser_struct *info = tty->driver_data;
1890 mxser_flush_buffer(tty);
1891 mxser_shutdown(info);
1894 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1896 wake_up_interruptible(&info->open_wait);
1900 /* added by James 03-12-2004. */
1902 * mxser_rs_break() --- routine which turns the break handling on or off
1904 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1906 struct mxser_struct *info = tty->driver_data;
1907 unsigned long flags;
1909 spin_lock_irqsave(&info->slock, flags);
1910 if (break_state == -1)
1911 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
1912 info->base + UART_LCR);
1914 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
1915 info->base + UART_LCR);
1916 spin_unlock_irqrestore(&info->slock, flags);
1919 /* (above) added by James. */
1923 * This is the serial driver's generic interrupt routine
1925 static irqreturn_t mxser_interrupt(int irq, void *dev_id)
1928 struct mxser_struct *info;
1929 struct mxser_struct *port;
1930 int max, irqbits, bits, msr;
1931 int pass_counter = 0;
1932 int handled = IRQ_NONE;
1935 /* spin_lock(&gm_lock); */
1937 for (i = 0; i < MXSER_BOARDS; i++) {
1938 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1944 if (i == MXSER_BOARDS)
1948 max = mxser_numports[mxsercfg[i].board_type - 1];
1950 irqbits = inb(port->vector) & port->vectormask;
1951 if (irqbits == port->vectormask)
1954 handled = IRQ_HANDLED;
1955 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1956 if (irqbits == port->vectormask)
1962 /* following add by Victor Yu. 09-13-2002 */
1963 iir = inb(info->base + UART_IIR);
1964 if (iir & UART_IIR_NO_INT)
1966 iir &= MOXA_MUST_IIR_MASK;
1968 status = inb(info->base + UART_LSR);
1969 outb(0x27, info->base + UART_FCR);
1970 inb(info->base + UART_MSR);
1973 /* above add by Victor Yu. 09-13-2002 */
1975 if (info->tty->flip.count < TTY_FLIPBUF_SIZE / 4) {
1976 info->IER |= MOXA_MUST_RECV_ISR;
1977 outb(info->IER, info->base + UART_IER);
1982 /* mask by Victor Yu. 09-13-2002
1984 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1987 /* mask by Victor Yu. 09-02-2002
1988 status = inb(info->base + UART_LSR) & info->read_status_mask;
1991 /* following add by Victor Yu. 09-02-2002 */
1992 status = inb(info->base + UART_LSR);
1994 if (status & UART_LSR_PE)
1995 info->err_shadow |= NPPI_NOTIFY_PARITY;
1996 if (status & UART_LSR_FE)
1997 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1998 if (status & UART_LSR_OE)
1999 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
2000 if (status & UART_LSR_BI)
2001 info->err_shadow |= NPPI_NOTIFY_BREAK;
2003 if (info->IsMoxaMustChipFlag) {
2005 if ( (status & 0x02) && !(status & 0x01) ) {
2006 outb(info->base+UART_FCR, 0x23);
2010 if (iir == MOXA_MUST_IIR_GDA ||
2011 iir == MOXA_MUST_IIR_RDA ||
2012 iir == MOXA_MUST_IIR_RTO ||
2013 iir == MOXA_MUST_IIR_LSR)
2014 mxser_receive_chars(info, &status);
2017 /* above add by Victor Yu. 09-02-2002 */
2019 status &= info->read_status_mask;
2020 if (status & UART_LSR_DR)
2021 mxser_receive_chars(info, &status);
2023 msr = inb(info->base + UART_MSR);
2024 if (msr & UART_MSR_ANY_DELTA) {
2025 mxser_check_modem_status(info, msr);
2027 /* following add by Victor Yu. 09-13-2002 */
2028 if (info->IsMoxaMustChipFlag) {
2029 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
2030 mxser_transmit_chars(info);
2033 /* above add by Victor Yu. 09-13-2002 */
2035 if (status & UART_LSR_THRE) {
2036 /* 8-2-99 by William
2037 if ( info->x_char || (info->xmit_cnt > 0) )
2039 mxser_transmit_chars(info);
2043 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
2044 break; /* Prevent infinite loops */
2049 /* spin_unlock(&gm_lock); */
2053 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2055 struct tty_struct *tty = info->tty;
2056 unsigned char ch, gdl;
2061 unsigned long flags;
2063 spin_lock_irqsave(&info->slock, flags);
2065 recv_room = tty->receive_room;
2066 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2067 /* mxser_throttle(tty); */
2072 /* following add by Victor Yu. 09-02-2002 */
2073 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2075 if (*status & UART_LSR_SPECIAL) {
2078 /* following add by Victor Yu. 02-11-2004 */
2079 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID &&
2080 (*status & MOXA_MUST_LSR_RERR))
2082 /* above add by Victor Yu. 02-14-2004 */
2083 if (*status & MOXA_MUST_LSR_RERR)
2086 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2088 /* add by Victor Yu. 02-11-2004 */
2089 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID)
2090 gdl &= MOXA_MUST_GDL_MASK;
2091 if (gdl >= recv_room) {
2092 if (!info->ldisc_stop_rx) {
2093 /* mxser_throttle(tty); */
2099 ch = inb(info->base + UART_RX);
2100 tty_insert_flip_char(tty, ch, 0);
2103 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2112 /* above add by Victor Yu. 09-02-2002 */
2118 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2125 ch = inb(info->base + UART_RX);
2126 /* following add by Victor Yu. 09-02-2002 */
2127 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2128 outb(0x23, info->base + UART_FCR);
2129 *status &= info->read_status_mask;
2130 /* above add by Victor Yu. 09-02-2002 */
2131 if (*status & info->ignore_status_mask) {
2132 if (++ignored > 100)
2136 if (*status & UART_LSR_SPECIAL) {
2137 if (*status & UART_LSR_BI) {
2139 /* added by casper 1/11/2000 */
2142 if (info->flags & ASYNC_SAK)
2144 } else if (*status & UART_LSR_PE) {
2146 /* added by casper 1/11/2000 */
2147 info->icount.parity++;
2149 } else if (*status & UART_LSR_FE) {
2151 /* added by casper 1/11/2000 */
2152 info->icount.frame++;
2154 } else if (*status & UART_LSR_OE) {
2156 /* added by casper 1/11/2000 */
2157 info->icount.overrun++;
2161 tty_insert_flip_char(tty, ch, flag);
2163 if (cnt >= recv_room) {
2164 if (!info->ldisc_stop_rx) {
2165 /* mxser_throttle(tty); */
2173 /* following add by Victor Yu. 09-02-2002 */
2174 if (info->IsMoxaMustChipFlag)
2176 /* above add by Victor Yu. 09-02-2002 */
2178 /* mask by Victor Yu. 09-02-2002
2179 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2181 /* following add by Victor Yu. 09-02-2002 */
2182 *status = inb(info->base + UART_LSR);
2183 /* above add by Victor Yu. 09-02-2002 */
2184 } while (*status & UART_LSR_DR);
2186 end_intr: /* add by Victor Yu. 09-02-2002 */
2187 mxvar_log.rxcnt[info->port] += cnt;
2188 info->mon_data.rxcnt += cnt;
2189 info->mon_data.up_rxcnt += cnt;
2190 spin_unlock_irqrestore(&info->slock, flags);
2192 tty_flip_buffer_push(tty);
2195 static void mxser_transmit_chars(struct mxser_struct *info)
2198 unsigned long flags;
2200 spin_lock_irqsave(&info->slock, flags);
2203 outb(info->x_char, info->base + UART_TX);
2205 mxvar_log.txcnt[info->port]++;
2206 info->mon_data.txcnt++;
2207 info->mon_data.up_txcnt++;
2209 /* added by casper 1/11/2000 */
2212 spin_unlock_irqrestore(&info->slock, flags);
2216 if (info->xmit_buf == 0) {
2217 spin_unlock_irqrestore(&info->slock, flags);
2221 if ((info->xmit_cnt <= 0) || info->tty->stopped ||
2222 (info->tty->hw_stopped &&
2223 (info->type != PORT_16550A) &&
2224 (!info->IsMoxaMustChipFlag))) {
2225 info->IER &= ~UART_IER_THRI;
2226 outb(info->IER, info->base + UART_IER);
2227 spin_unlock_irqrestore(&info->slock, flags);
2231 cnt = info->xmit_cnt;
2232 count = info->xmit_fifo_size;
2234 outb(info->xmit_buf[info->xmit_tail++],
2235 info->base + UART_TX);
2236 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2237 if (--info->xmit_cnt <= 0)
2239 } while (--count > 0);
2240 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2242 /* added by James 03-12-2004. */
2243 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2244 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2245 /* (above) added by James. */
2247 /* added by casper 1/11/2000 */
2248 info->icount.tx += (cnt - info->xmit_cnt);
2251 if (info->xmit_cnt < WAKEUP_CHARS) {
2252 set_bit(MXSER_EVENT_TXLOW, &info->event);
2253 schedule_work(&info->tqueue);
2255 if (info->xmit_cnt <= 0) {
2256 info->IER &= ~UART_IER_THRI;
2257 outb(info->IER, info->base + UART_IER);
2259 spin_unlock_irqrestore(&info->slock, flags);
2262 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2264 /* update input line counters */
2265 if (status & UART_MSR_TERI)
2267 if (status & UART_MSR_DDSR)
2269 if (status & UART_MSR_DDCD)
2271 if (status & UART_MSR_DCTS)
2273 info->mon_data.modem_status = status;
2274 wake_up_interruptible(&info->delta_msr_wait);
2276 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2277 if (status & UART_MSR_DCD)
2278 wake_up_interruptible(&info->open_wait);
2279 schedule_work(&info->tqueue);
2282 if (info->flags & ASYNC_CTS_FLOW) {
2283 if (info->tty->hw_stopped) {
2284 if (status & UART_MSR_CTS) {
2285 info->tty->hw_stopped = 0;
2287 if ((info->type != PORT_16550A) &&
2288 (!info->IsMoxaMustChipFlag)) {
2289 info->IER |= UART_IER_THRI;
2290 outb(info->IER, info->base + UART_IER);
2292 set_bit(MXSER_EVENT_TXLOW, &info->event);
2293 schedule_work(&info->tqueue); }
2295 if (!(status & UART_MSR_CTS)) {
2296 info->tty->hw_stopped = 1;
2297 if ((info->type != PORT_16550A) &&
2298 (!info->IsMoxaMustChipFlag)) {
2299 info->IER &= ~UART_IER_THRI;
2300 outb(info->IER, info->base + UART_IER);
2307 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2309 DECLARE_WAITQUEUE(wait, current);
2312 unsigned long flags;
2315 * If non-blocking mode is set, or the port is not enabled,
2316 * then make the check up front and then exit.
2318 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2319 info->flags |= ASYNC_NORMAL_ACTIVE;
2323 if (tty->termios->c_cflag & CLOCAL)
2327 * Block waiting for the carrier detect and the line to become
2328 * free (i.e., not in use by the callout). While we are in
2329 * this loop, info->count is dropped by one, so that
2330 * mxser_close() knows when to free things. We restore it upon
2331 * exit, either normal or abnormal.
2334 add_wait_queue(&info->open_wait, &wait);
2336 spin_lock_irqsave(&info->slock, flags);
2337 if (!tty_hung_up_p(filp))
2339 spin_unlock_irqrestore(&info->slock, flags);
2340 info->blocked_open++;
2342 spin_lock_irqsave(&info->slock, flags);
2343 outb(inb(info->base + UART_MCR) |
2344 UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2345 spin_unlock_irqrestore(&info->slock, flags);
2346 set_current_state(TASK_INTERRUPTIBLE);
2347 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2348 if (info->flags & ASYNC_HUP_NOTIFY)
2351 retval = -ERESTARTSYS;
2354 if (!(info->flags & ASYNC_CLOSING) &&
2356 (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2358 if (signal_pending(current)) {
2359 retval = -ERESTARTSYS;
2364 set_current_state(TASK_RUNNING);
2365 remove_wait_queue(&info->open_wait, &wait);
2366 if (!tty_hung_up_p(filp))
2368 info->blocked_open--;
2371 info->flags |= ASYNC_NORMAL_ACTIVE;
2375 static int mxser_startup(struct mxser_struct *info)
2378 unsigned long flags;
2380 page = __get_free_page(GFP_KERNEL);
2384 spin_lock_irqsave(&info->slock, flags);
2386 if (info->flags & ASYNC_INITIALIZED) {
2388 spin_unlock_irqrestore(&info->slock, flags);
2392 if (!info->base || !info->type) {
2394 set_bit(TTY_IO_ERROR, &info->tty->flags);
2396 spin_unlock_irqrestore(&info->slock, flags);
2402 info->xmit_buf = (unsigned char *) page;
2405 * Clear the FIFO buffers and disable them
2406 * (they will be reenabled in mxser_change_speed())
2408 if (info->IsMoxaMustChipFlag)
2409 outb((UART_FCR_CLEAR_RCVR |
2410 UART_FCR_CLEAR_XMIT |
2411 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2413 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2414 info->base + UART_FCR);
2417 * At this point there's no way the LSR could still be 0xFF;
2418 * if it is, then bail out, because there's likely no UART
2421 if (inb(info->base + UART_LSR) == 0xff) {
2422 spin_unlock_irqrestore(&info->slock, flags);
2423 if (capable(CAP_SYS_ADMIN)) {
2425 set_bit(TTY_IO_ERROR, &info->tty->flags);
2432 * Clear the interrupt registers.
2434 (void) inb(info->base + UART_LSR);
2435 (void) inb(info->base + UART_RX);
2436 (void) inb(info->base + UART_IIR);
2437 (void) inb(info->base + UART_MSR);
2440 * Now, initialize the UART
2442 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2443 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2444 outb(info->MCR, info->base + UART_MCR);
2447 * Finally, enable interrupts
2449 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2450 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2452 /* following add by Victor Yu. 08-30-2002 */
2453 if (info->IsMoxaMustChipFlag)
2454 info->IER |= MOXA_MUST_IER_EGDAI;
2455 /* above add by Victor Yu. 08-30-2002 */
2456 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2459 * And clear the interrupt registers again for luck.
2461 (void) inb(info->base + UART_LSR);
2462 (void) inb(info->base + UART_RX);
2463 (void) inb(info->base + UART_IIR);
2464 (void) inb(info->base + UART_MSR);
2467 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2468 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2471 * and set the speed of the serial port
2473 spin_unlock_irqrestore(&info->slock, flags);
2474 mxser_change_speed(info, NULL);
2476 info->flags |= ASYNC_INITIALIZED;
2481 * This routine will shutdown a serial port; interrupts maybe disabled, and
2482 * DTR is dropped if the hangup on close termio flag is on.
2484 static void mxser_shutdown(struct mxser_struct *info)
2486 unsigned long flags;
2488 if (!(info->flags & ASYNC_INITIALIZED))
2491 spin_lock_irqsave(&info->slock, flags);
2494 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2495 * here so the queue might never be waken up
2497 wake_up_interruptible(&info->delta_msr_wait);
2500 * Free the IRQ, if necessary
2502 if (info->xmit_buf) {
2503 free_page((unsigned long) info->xmit_buf);
2504 info->xmit_buf = NULL;
2508 outb(0x00, info->base + UART_IER);
2510 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2511 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2512 outb(info->MCR, info->base + UART_MCR);
2514 /* clear Rx/Tx FIFO's */
2515 /* following add by Victor Yu. 08-30-2002 */
2516 if (info->IsMoxaMustChipFlag)
2517 outb((UART_FCR_CLEAR_RCVR |
2518 UART_FCR_CLEAR_XMIT |
2519 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2521 /* above add by Victor Yu. 08-30-2002 */
2522 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2523 info->base + UART_FCR);
2525 /* read data port to reset things */
2526 (void) inb(info->base + UART_RX);
2529 set_bit(TTY_IO_ERROR, &info->tty->flags);
2531 info->flags &= ~ASYNC_INITIALIZED;
2533 /* following add by Victor Yu. 09-23-2002 */
2534 if (info->IsMoxaMustChipFlag)
2535 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2536 /* above add by Victor Yu. 09-23-2002 */
2538 spin_unlock_irqrestore(&info->slock, flags);
2542 * This routine is called to set the UART divisor registers to match
2543 * the specified baud rate for a serial port.
2545 static int mxser_change_speed(struct mxser_struct *info, struct ktermios *old_termios)
2547 unsigned cflag, cval, fcr;
2549 unsigned char status;
2551 unsigned long flags;
2553 if (!info->tty || !info->tty->termios)
2555 cflag = info->tty->termios->c_cflag;
2560 #define B921600 (B460800 +1)
2562 if (mxser_set_baud_method[info->port] == 0) {
2563 baud = tty_get_baud_rate(info->tty);
2564 mxser_set_baud(info, baud);
2567 /* byte size and parity */
2568 switch (cflag & CSIZE) {
2583 break; /* too keep GCC shut... */
2588 cval |= UART_LCR_PARITY;
2589 if (!(cflag & PARODD))
2590 cval |= UART_LCR_EPAR;
2592 cval |= UART_LCR_SPAR;
2594 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2595 if (info->IsMoxaMustChipFlag) {
2596 fcr = UART_FCR_ENABLE_FIFO;
2597 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2598 SET_MOXA_MUST_FIFO_VALUE(info);
2602 fcr = UART_FCR_ENABLE_FIFO;
2603 /* following add by Victor Yu. 08-30-2002 */
2604 if (info->IsMoxaMustChipFlag) {
2605 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2606 SET_MOXA_MUST_FIFO_VALUE(info);
2608 /* above add by Victor Yu. 08-30-2002 */
2609 switch (info->rx_trigger) {
2611 fcr |= UART_FCR_TRIGGER_1;
2614 fcr |= UART_FCR_TRIGGER_4;
2617 fcr |= UART_FCR_TRIGGER_8;
2620 fcr |= UART_FCR_TRIGGER_14;
2626 /* CTS flow control flag and modem status interrupts */
2627 info->IER &= ~UART_IER_MSI;
2628 info->MCR &= ~UART_MCR_AFE;
2629 if (cflag & CRTSCTS) {
2630 info->flags |= ASYNC_CTS_FLOW;
2631 info->IER |= UART_IER_MSI;
2632 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2633 info->MCR |= UART_MCR_AFE;
2634 /* status = mxser_get_msr(info->base, 0, info->port); */
2638 status = inb(baseaddr + UART_MSR);
2639 restore_flags(flags);
2641 /* mxser_check_modem_status(info, status); */
2643 /* status = mxser_get_msr(info->base, 0, info->port); */
2644 /* MX_LOCK(&info->slock); */
2645 status = inb(info->base + UART_MSR);
2646 /* MX_UNLOCK(&info->slock); */
2647 if (info->tty->hw_stopped) {
2648 if (status & UART_MSR_CTS) {
2649 info->tty->hw_stopped = 0;
2650 if ((info->type != PORT_16550A) &&
2651 (!info->IsMoxaMustChipFlag)) {
2652 info->IER |= UART_IER_THRI;
2653 outb(info->IER, info->base + UART_IER);
2655 set_bit(MXSER_EVENT_TXLOW, &info->event);
2656 schedule_work(&info->tqueue); }
2658 if (!(status & UART_MSR_CTS)) {
2659 info->tty->hw_stopped = 1;
2660 if ((info->type != PORT_16550A) &&
2661 (!info->IsMoxaMustChipFlag)) {
2662 info->IER &= ~UART_IER_THRI;
2663 outb(info->IER, info->base + UART_IER);
2669 info->flags &= ~ASYNC_CTS_FLOW;
2671 outb(info->MCR, info->base + UART_MCR);
2672 if (cflag & CLOCAL) {
2673 info->flags &= ~ASYNC_CHECK_CD;
2675 info->flags |= ASYNC_CHECK_CD;
2676 info->IER |= UART_IER_MSI;
2678 outb(info->IER, info->base + UART_IER);
2681 * Set up parity check flag
2683 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2684 if (I_INPCK(info->tty))
2685 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2686 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2687 info->read_status_mask |= UART_LSR_BI;
2689 info->ignore_status_mask = 0;
2691 if (I_IGNBRK(info->tty)) {
2692 info->ignore_status_mask |= UART_LSR_BI;
2693 info->read_status_mask |= UART_LSR_BI;
2695 * If we're ignore parity and break indicators, ignore
2696 * overruns too. (For real raw support).
2698 if (I_IGNPAR(info->tty)) {
2699 info->ignore_status_mask |=
2703 info->read_status_mask |=
2709 /* following add by Victor Yu. 09-02-2002 */
2710 if (info->IsMoxaMustChipFlag) {
2711 spin_lock_irqsave(&info->slock, flags);
2712 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2713 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2714 if (I_IXON(info->tty)) {
2715 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2717 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2719 if (I_IXOFF(info->tty)) {
2720 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2722 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2725 if ( I_IXANY(info->tty) ) {
2726 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2727 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2729 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2730 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2733 spin_unlock_irqrestore(&info->slock, flags);
2735 /* above add by Victor Yu. 09-02-2002 */
2738 outb(fcr, info->base + UART_FCR); /* set fcr */
2739 outb(cval, info->base + UART_LCR);
2745 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2750 unsigned long flags;
2752 if (!info->tty || !info->tty->termios)
2758 if (newspd > info->MaxCanSetBaudRate)
2761 info->realbaud = newspd;
2762 if (newspd == 134) {
2763 quot = (2 * info->baud_base / 269);
2764 } else if (newspd) {
2765 quot = info->baud_base / newspd;
2772 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2773 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2776 spin_lock_irqsave(&info->slock, flags);
2777 info->MCR |= UART_MCR_DTR;
2778 outb(info->MCR, info->base + UART_MCR);
2779 spin_unlock_irqrestore(&info->slock, flags);
2781 spin_lock_irqsave(&info->slock, flags);
2782 info->MCR &= ~UART_MCR_DTR;
2783 outb(info->MCR, info->base + UART_MCR);
2784 spin_unlock_irqrestore(&info->slock, flags);
2788 cval = inb(info->base + UART_LCR);
2790 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2792 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2793 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2794 outb(cval, info->base + UART_LCR); /* reset DLAB */
2801 * ------------------------------------------------------------
2802 * friends of mxser_ioctl()
2803 * ------------------------------------------------------------
2805 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2807 struct serial_struct tmp;
2811 memset(&tmp, 0, sizeof(tmp));
2812 tmp.type = info->type;
2813 tmp.line = info->port;
2814 tmp.port = info->base;
2815 tmp.irq = info->irq;
2816 tmp.flags = info->flags;
2817 tmp.baud_base = info->baud_base;
2818 tmp.close_delay = info->close_delay;
2819 tmp.closing_wait = info->closing_wait;
2820 tmp.custom_divisor = info->custom_divisor;
2822 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2827 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2829 struct serial_struct new_serial;
2833 if (!new_info || !info->base)
2835 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2838 if ((new_serial.irq != info->irq) ||
2839 (new_serial.port != info->base) ||
2840 (new_serial.custom_divisor != info->custom_divisor) ||
2841 (new_serial.baud_base != info->baud_base))
2844 flags = info->flags & ASYNC_SPD_MASK;
2846 if (!capable(CAP_SYS_ADMIN)) {
2847 if ((new_serial.baud_base != info->baud_base) ||
2848 (new_serial.close_delay != info->close_delay) ||
2849 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2851 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2852 (new_serial.flags & ASYNC_USR_MASK));
2855 * OK, past this point, all the error checking has been done.
2856 * At this point, we start making changes.....
2858 info->flags = ((info->flags & ~ASYNC_FLAGS) |
2859 (new_serial.flags & ASYNC_FLAGS));
2860 info->close_delay = new_serial.close_delay * HZ / 100;
2861 info->closing_wait = new_serial.closing_wait * HZ / 100;
2862 info->tty->low_latency =
2863 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2864 info->tty->low_latency = 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2867 /* added by casper, 3/17/2000, for mouse */
2868 info->type = new_serial.type;
2870 process_txrx_fifo(info);
2872 if (info->flags & ASYNC_INITIALIZED) {
2873 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2874 mxser_change_speed(info, NULL);
2877 retval = mxser_startup(info);
2883 * mxser_get_lsr_info - get line status register info
2885 * Purpose: Let user call ioctl() to get info when the UART physically
2886 * is emptied. On bus types like RS485, the transmitter must
2887 * release the bus after transmitting. This must be done when
2888 * the transmit shift register is empty, not be done when the
2889 * transmit holding register is empty. This functionality
2890 * allows an RS485 driver to be written in user space.
2892 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2894 unsigned char status;
2895 unsigned int result;
2896 unsigned long flags;
2898 spin_lock_irqsave(&info->slock, flags);
2899 status = inb(info->base + UART_LSR);
2900 spin_unlock_irqrestore(&info->slock, flags);
2901 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2902 return put_user(result, value);
2906 * This routine sends a break character out the serial port.
2908 static void mxser_send_break(struct mxser_struct *info, int duration)
2910 unsigned long flags;
2914 set_current_state(TASK_INTERRUPTIBLE);
2915 spin_lock_irqsave(&info->slock, flags);
2916 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
2917 info->base + UART_LCR);
2918 spin_unlock_irqrestore(&info->slock, flags);
2919 schedule_timeout(duration);
2920 spin_lock_irqsave(&info->slock, flags);
2921 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
2922 info->base + UART_LCR);
2923 spin_unlock_irqrestore(&info->slock, flags);
2926 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2928 struct mxser_struct *info = tty->driver_data;
2929 unsigned char control, status;
2930 unsigned long flags;
2933 if (tty->index == MXSER_PORTS)
2934 return -ENOIOCTLCMD;
2935 if (tty->flags & (1 << TTY_IO_ERROR))
2938 control = info->MCR;
2940 spin_lock_irqsave(&info->slock, flags);
2941 status = inb(info->base + UART_MSR);
2942 if (status & UART_MSR_ANY_DELTA)
2943 mxser_check_modem_status(info, status);
2944 spin_unlock_irqrestore(&info->slock, flags);
2945 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2946 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
2947 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
2948 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
2949 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
2950 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2953 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2955 struct mxser_struct *info = tty->driver_data;
2956 unsigned long flags;
2959 if (tty->index == MXSER_PORTS)
2960 return -ENOIOCTLCMD;
2961 if (tty->flags & (1 << TTY_IO_ERROR))
2964 spin_lock_irqsave(&info->slock, flags);
2966 if (set & TIOCM_RTS)
2967 info->MCR |= UART_MCR_RTS;
2968 if (set & TIOCM_DTR)
2969 info->MCR |= UART_MCR_DTR;
2971 if (clear & TIOCM_RTS)
2972 info->MCR &= ~UART_MCR_RTS;
2973 if (clear & TIOCM_DTR)
2974 info->MCR &= ~UART_MCR_DTR;
2976 outb(info->MCR, info->base + UART_MCR);
2977 spin_unlock_irqrestore(&info->slock, flags);
2982 static int mxser_read_register(int, unsigned short *);
2983 static int mxser_program_mode(int);
2984 static void mxser_normal_mode(int);
2986 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2989 unsigned short regs[16], irq;
2990 unsigned char scratch, scratch2;
2992 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2994 id = mxser_read_register(cap, regs);
2995 if (id == C168_ASIC_ID) {
2996 hwconf->board_type = MXSER_BOARD_C168_ISA;
2998 } else if (id == C104_ASIC_ID) {
2999 hwconf->board_type = MXSER_BOARD_C104_ISA;
3001 } else if (id == C102_ASIC_ID) {
3002 hwconf->board_type = MXSER_BOARD_C102_ISA;
3004 } else if (id == CI132_ASIC_ID) {
3005 hwconf->board_type = MXSER_BOARD_CI132;
3007 } else if (id == CI134_ASIC_ID) {
3008 hwconf->board_type = MXSER_BOARD_CI134;
3010 } else if (id == CI104J_ASIC_ID) {
3011 hwconf->board_type = MXSER_BOARD_CI104J;
3017 if (hwconf->ports == 2) {
3018 irq = regs[9] & 0xF000;
3019 irq = irq | (irq >> 4);
3020 if (irq != (regs[9] & 0xFF00))
3021 return MXSER_ERR_IRQ_CONFLIT;
3022 } else if (hwconf->ports == 4) {
3023 irq = regs[9] & 0xF000;
3024 irq = irq | (irq >> 4);
3025 irq = irq | (irq >> 8);
3027 return MXSER_ERR_IRQ_CONFLIT;
3028 } else if (hwconf->ports == 8) {
3029 irq = regs[9] & 0xF000;
3030 irq = irq | (irq >> 4);
3031 irq = irq | (irq >> 8);
3032 if ((irq != regs[9]) || (irq != regs[10]))
3033 return MXSER_ERR_IRQ_CONFLIT;
3037 return MXSER_ERR_IRQ;
3038 hwconf->irq = ((int)(irq & 0xF000) >> 12);
3039 for (i = 0; i < 8; i++)
3040 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3041 if ((regs[12] & 0x80) == 0)
3042 return MXSER_ERR_VECTOR;
3043 hwconf->vector = (int)regs[11]; /* interrupt vector */
3045 hwconf->vector_mask = 0x00FF;
3047 hwconf->vector_mask = 0x000F;
3048 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3049 if (regs[12] & bits) {
3050 hwconf->baud_base[i] = 921600;
3051 hwconf->MaxCanSetBaudRate[i] = 921600; /* add by Victor Yu. 09-04-2002 */
3053 hwconf->baud_base[i] = 115200;
3054 hwconf->MaxCanSetBaudRate[i] = 115200; /* add by Victor Yu. 09-04-2002 */
3057 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3058 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3059 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3060 outb(scratch2, cap + UART_LCR);
3061 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3062 scratch = inb(cap + UART_IIR);
3065 hwconf->uart_type = PORT_16550A;
3067 hwconf->uart_type = PORT_16450;
3072 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3073 request_region(hwconf->vector, 1, "mxser(vector)");
3074 return hwconf->ports;
3077 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3078 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3079 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3080 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3081 #define EN_CCMD 0x000 /* Chip's command register */
3082 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3083 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3084 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3085 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3086 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3087 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3088 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3089 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3090 static int mxser_read_register(int port, unsigned short *regs)
3092 int i, k, value, id;
3095 id = mxser_program_mode(port);
3098 for (i = 0; i < 14; i++) {
3099 k = (i & 0x3F) | 0x180;
3100 for (j = 0x100; j > 0; j >>= 1) {
3101 outb(CHIP_CS, port);
3103 outb(CHIP_CS | CHIP_DO, port);
3104 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3106 outb(CHIP_CS, port);
3107 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3112 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3113 outb(CHIP_CS, port);
3114 outb(CHIP_CS | CHIP_SK, port);
3115 if (inb(port) & CHIP_DI)
3121 mxser_normal_mode(port);
3125 static int mxser_program_mode(int port)
3128 /* unsigned long flags; */
3130 spin_lock(&gm_lock);
3138 /* restore_flags(flags); */
3139 spin_unlock(&gm_lock);
3141 id = inb(port + 1) & 0x1F;
3142 if ((id != C168_ASIC_ID) &&
3143 (id != C104_ASIC_ID) &&
3144 (id != C102_ASIC_ID) &&
3145 (id != CI132_ASIC_ID) &&
3146 (id != CI134_ASIC_ID) &&
3147 (id != CI104J_ASIC_ID))
3149 for (i = 0, j = 0; i < 4; i++) {
3153 } else if ((j == 1) && (n == 1)) {
3164 static void mxser_normal_mode(int port)
3168 outb(0xA5, port + 1);
3169 outb(0x80, port + 3);
3170 outb(12, port + 0); /* 9600 bps */
3172 outb(0x03, port + 3); /* 8 data bits */
3173 outb(0x13, port + 4); /* loop back mode */
3174 for (i = 0; i < 16; i++) {
3176 if ((n & 0x61) == 0x60)
3181 outb(0x00, port + 4);
3184 module_init(mxser_module_init);
3185 module_exit(mxser_module_exit);