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 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;
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 termios *mxvar_termios[MXSER_PORTS + 1];
368 static struct termios *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(void *);
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 termios *);
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 *, struct pt_regs *);
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 termios *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 " ttyM%d - ttyM%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, info);
595 info->normal_termios = mxvar_sdriver->init_termios;
596 init_waitqueue_head(&info->open_wait);
597 init_waitqueue_head(&info->close_wait);
598 init_waitqueue_head(&info->delta_msr_wait);
599 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
600 info->err_shadow = 0;
601 spin_lock_init(&info->slock);
604 * Allocate the IRQ if necessary
608 /* before set INT ISR, disable all int */
609 for (i = 0; i < hwconf->ports; i++) {
610 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0,
611 hwconf->ioaddr[i] + UART_IER);
614 n = board * MXSER_PORTS_PER_BOARD;
615 info = &mxvar_table[n];
617 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info),
620 printk(KERN_ERR "Board %d: %s",
621 board, mxser_brdname[hwconf->board_type - 1]);
622 printk(" Request irq failed, IRQ (%d) may conflict with"
623 " another device.\n", info->irq);
629 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
631 mxsercfg[board] = *hwconf;
635 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
638 /* unsigned int val; */
639 unsigned int ioaddress;
640 struct pci_dev *pdev = hwconf->pciInfo.pdev;
643 hwconf->board_type = board_type;
644 hwconf->ports = mxser_numports[board_type - 1];
645 ioaddress = pci_resource_start(pdev, 2);
646 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2),
649 for (i = 0; i < hwconf->ports; i++)
650 hwconf->ioaddr[i] = ioaddress + 8 * i;
653 ioaddress = pci_resource_start(pdev, 3);
654 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3),
656 hwconf->vector = ioaddress;
659 hwconf->irq = hwconf->pciInfo.pdev->irq;
661 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
662 hwconf->uart_type = PORT_16550A;
663 hwconf->vector_mask = 0;
666 for (i = 0; i < hwconf->ports; i++) {
667 for (j = 0; j < UART_INFO_NUM; j++) {
668 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
669 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
671 /* exception....CP-102 */
672 if (board_type == MXSER_BOARD_CP102)
673 hwconf->MaxCanSetBaudRate[i] = 921600;
679 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
680 for (i = 0; i < hwconf->ports; i++) {
682 hwconf->opmode_ioaddr[i] = ioaddress + 4;
684 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
686 outb(0, ioaddress + 4); /* default set to RS232 mode */
687 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
690 for (i = 0; i < hwconf->ports; i++) {
691 hwconf->vector_mask |= (1 << i);
692 hwconf->baud_base[i] = 921600;
698 static int mxser_init(void)
700 int i, m, retval, b, n;
701 struct pci_dev *pdev = NULL;
703 unsigned char busnum, devnum;
704 struct mxser_hwconf hwconf;
706 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
709 spin_lock_init(&gm_lock);
711 for (i = 0; i < MXSER_BOARDS; i++) {
712 mxsercfg[i].board_type = -1;
715 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
718 /* Initialize the tty_driver structure */
719 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
720 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
721 mxvar_sdriver->name = "ttyM";
722 mxvar_sdriver->major = ttymajor;
723 mxvar_sdriver->minor_start = 0;
724 mxvar_sdriver->num = MXSER_PORTS + 1;
725 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
726 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
727 mxvar_sdriver->init_termios = tty_std_termios;
728 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
729 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
730 tty_set_operations(mxvar_sdriver, &mxser_ops);
731 mxvar_sdriver->ttys = mxvar_tty;
732 mxvar_sdriver->termios = mxvar_termios;
733 mxvar_sdriver->termios_locked = mxvar_termios_locked;
736 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
737 memset(&mxvar_log, 0, sizeof(struct mxser_log));
739 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
740 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
741 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
742 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
745 /* Start finding ISA boards here */
746 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
749 if (!(cap = mxserBoardCAP[b]))
752 retval = mxser_get_ISA_conf(cap, &hwconf);
755 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
756 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
759 if (retval == MXSER_ERR_IRQ)
760 printk(KERN_ERR "Invalid interrupt number, "
761 "board not configured\n");
762 else if (retval == MXSER_ERR_IRQ_CONFLIT)
763 printk(KERN_ERR "Invalid interrupt number, "
764 "board not configured\n");
765 else if (retval == MXSER_ERR_VECTOR)
766 printk(KERN_ERR "Invalid interrupt vector, "
767 "board not configured\n");
768 else if (retval == MXSER_ERR_IOADDR)
769 printk(KERN_ERR "Invalid I/O address, "
770 "board not configured\n");
775 hwconf.pciInfo.busNum = 0;
776 hwconf.pciInfo.devNum = 0;
777 hwconf.pciInfo.pdev = NULL;
779 mxser_getcfg(m, &hwconf);
781 * init mxsercfg first,
782 * or mxsercfg data is not correct on ISR.
784 /* mxser_initbrd will hook ISR. */
785 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++) {
795 if (!(cap = ioaddr[b]))
798 retval = mxser_get_ISA_conf(cap, &hwconf);
801 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
802 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
805 if (retval == MXSER_ERR_IRQ)
806 printk(KERN_ERR "Invalid interrupt number, "
807 "board not configured\n");
808 else if (retval == MXSER_ERR_IRQ_CONFLIT)
809 printk(KERN_ERR "Invalid interrupt number, "
810 "board not configured\n");
811 else if (retval == MXSER_ERR_VECTOR)
812 printk(KERN_ERR "Invalid interrupt vector, "
813 "board not configured\n");
814 else if (retval == MXSER_ERR_IOADDR)
815 printk(KERN_ERR "Invalid I/O address, "
816 "board not configured\n");
821 hwconf.pciInfo.busNum = 0;
822 hwconf.pciInfo.devNum = 0;
823 hwconf.pciInfo.pdev = NULL;
825 mxser_getcfg(m, &hwconf);
827 * init mxsercfg first,
828 * or mxsercfg data is not correct on ISR.
830 /* mxser_initbrd will hook ISR. */
831 if (mxser_initbrd(m, &hwconf) < 0)
837 /* start finding PCI board here */
839 n = ARRAY_SIZE(mxser_pcibrds) - 1;
843 pdev = pci_get_device(mxser_pcibrds[b].vendor,
844 mxser_pcibrds[b].device, pdev);
849 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
850 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
851 hwconf.pciInfo.pdev = pdev;
852 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
853 mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
854 busnum, devnum >> 3);
856 if (m >= MXSER_BOARDS)
858 "Too many Smartio/Industio family boards find "
859 "(maximum %d), board not configured\n",
862 if (pci_enable_device(pdev)) {
863 printk(KERN_ERR "Moxa SmartI/O PCI enable "
867 retval = mxser_get_PCI_conf(busnum, devnum,
868 (int)mxser_pcibrds[b].driver_data,
871 if (retval == MXSER_ERR_IRQ)
873 "Invalid interrupt number, "
874 "board not configured\n");
875 else if (retval == MXSER_ERR_IRQ_CONFLIT)
877 "Invalid interrupt number, "
878 "board not configured\n");
879 else if (retval == MXSER_ERR_VECTOR)
881 "Invalid interrupt vector, "
882 "board not configured\n");
883 else if (retval == MXSER_ERR_IOADDR)
885 "Invalid I/O address, "
886 "board not configured\n");
889 mxser_getcfg(m, &hwconf);
890 /* init mxsercfg first,
891 * or mxsercfg data is not correct on ISR.
893 /* mxser_initbrd will hook ISR. */
894 if (mxser_initbrd(m, &hwconf) < 0)
897 /* Keep an extra reference if we succeeded. It will
898 be returned at unload time */
904 retval = tty_register_driver(mxvar_sdriver);
906 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family"
908 put_tty_driver(mxvar_sdriver);
910 for (i = 0; i < MXSER_BOARDS; i++) {
911 if (mxsercfg[i].board_type == -1)
914 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
915 /* todo: release io, vector */
924 static void mxser_do_softint(void *private_)
926 struct mxser_struct *info = private_;
927 struct tty_struct *tty;
932 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
934 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
939 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
941 unsigned char status = 0;
943 status = inb(baseaddr + UART_MSR);
945 mxser_msr[port] &= 0x0F;
946 mxser_msr[port] |= status;
947 status = mxser_msr[port];
955 * This routine is called whenever a serial port is opened. It
956 * enables interrupts for a serial port, linking in its async structure into
957 * the IRQ chain. It also performs the serial-specific
958 * initialization for the tty structure.
960 static int mxser_open(struct tty_struct *tty, struct file *filp)
962 struct mxser_struct *info;
965 /* initialize driver_data in case something fails */
966 tty->driver_data = NULL;
969 if (line == MXSER_PORTS)
971 if (line < 0 || line > MXSER_PORTS)
973 info = mxvar_table + line;
977 tty->driver_data = info;
980 * Start up serial port
982 retval = mxser_startup(info);
986 retval = mxser_block_til_ready(tty, filp, info);
992 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
993 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
994 *tty->termios = info->normal_termios;
996 *tty->termios = info->callout_termios;
997 mxser_change_speed(info, NULL);
1000 info->session = current->signal->session;
1001 info->pgrp = process_group(current);
1004 status = mxser_get_msr(info->base, 0, info->port);
1005 mxser_check_modem_status(info, status);
1008 /* unmark here for very high baud rate (ex. 921600 bps) used */
1009 tty->low_latency = 1;
1014 * This routine is called when the serial port gets closed. First, we
1015 * wait for the last remaining data to be sent. Then, we unlink its
1016 * async structure from the interrupt chain if necessary, and we free
1017 * that IRQ if nothing is left in the chain.
1019 static void mxser_close(struct tty_struct *tty, struct file *filp)
1021 struct mxser_struct *info = tty->driver_data;
1023 unsigned long timeout;
1024 unsigned long flags;
1025 struct tty_ldisc *ld;
1027 if (tty->index == MXSER_PORTS)
1032 spin_lock_irqsave(&info->slock, flags);
1034 if (tty_hung_up_p(filp)) {
1035 spin_unlock_irqrestore(&info->slock, flags);
1038 if ((tty->count == 1) && (info->count != 1)) {
1040 * Uh, oh. tty->count is 1, which means that the tty
1041 * structure will be freed. Info->count should always
1042 * be one in these conditions. If it's greater than
1043 * one, we've got real problems, since it means the
1044 * serial port won't be shutdown.
1046 printk(KERN_ERR "mxser_close: bad serial port count; "
1047 "tty->count is 1, info->count is %d\n", info->count);
1050 if (--info->count < 0) {
1051 printk(KERN_ERR "mxser_close: bad serial port count for "
1052 "ttys%d: %d\n", info->port, info->count);
1056 spin_unlock_irqrestore(&info->slock, flags);
1059 info->flags |= ASYNC_CLOSING;
1060 spin_unlock_irqrestore(&info->slock, flags);
1062 * Save the termios structure, since this port may have
1063 * separate termios for callout and dialin.
1065 if (info->flags & ASYNC_NORMAL_ACTIVE)
1066 info->normal_termios = *tty->termios;
1068 * Now we wait for the transmit buffer to clear; and we notify
1069 * the line discipline to only process XON/XOFF characters.
1072 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1073 tty_wait_until_sent(tty, info->closing_wait);
1075 * At this point we stop accepting input. To do this, we
1076 * disable the receive line status interrupts, and tell the
1077 * interrupt driver to stop checking the data ready bit in the
1078 * line status register.
1080 info->IER &= ~UART_IER_RLSI;
1081 if (info->IsMoxaMustChipFlag)
1082 info->IER &= ~MOXA_MUST_RECV_ISR;
1084 info->read_status_mask &= ~UART_LSR_DR;
1086 if (info->flags & ASYNC_INITIALIZED) {
1087 outb(info->IER, info->base + UART_IER);
1089 * Before we drop DTR, make sure the UART transmitter
1090 * has completely drained; this is especially
1091 * important if there is a transmit FIFO!
1093 timeout = jiffies + HZ;
1094 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1095 schedule_timeout_interruptible(5);
1096 if (time_after(jiffies, timeout))
1100 mxser_shutdown(info);
1102 if (tty->driver->flush_buffer)
1103 tty->driver->flush_buffer(tty);
1105 ld = tty_ldisc_ref(tty);
1107 if (ld->flush_buffer)
1108 ld->flush_buffer(tty);
1109 tty_ldisc_deref(ld);
1115 if (info->blocked_open) {
1116 if (info->close_delay)
1117 schedule_timeout_interruptible(info->close_delay);
1118 wake_up_interruptible(&info->open_wait);
1121 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1122 wake_up_interruptible(&info->close_wait);
1126 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1129 struct mxser_struct *info = tty->driver_data;
1130 unsigned long flags;
1132 if (!info->xmit_buf)
1136 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1137 SERIAL_XMIT_SIZE - info->xmit_head));
1141 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1142 spin_lock_irqsave(&info->slock, flags);
1143 info->xmit_head = (info->xmit_head + c) &
1144 (SERIAL_XMIT_SIZE - 1);
1145 info->xmit_cnt += c;
1146 spin_unlock_irqrestore(&info->slock, flags);
1153 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1154 if (!tty->hw_stopped ||
1155 (info->type == PORT_16550A) ||
1156 (info->IsMoxaMustChipFlag)) {
1157 spin_lock_irqsave(&info->slock, flags);
1158 info->IER |= UART_IER_THRI;
1159 outb(info->IER, info->base + UART_IER);
1160 spin_unlock_irqrestore(&info->slock, flags);
1166 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1168 struct mxser_struct *info = tty->driver_data;
1169 unsigned long flags;
1171 if (!info->xmit_buf)
1174 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1177 spin_lock_irqsave(&info->slock, flags);
1178 info->xmit_buf[info->xmit_head++] = ch;
1179 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1181 spin_unlock_irqrestore(&info->slock, flags);
1182 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1183 if (!tty->hw_stopped ||
1184 (info->type == PORT_16550A) ||
1185 info->IsMoxaMustChipFlag) {
1186 spin_lock_irqsave(&info->slock, flags);
1187 info->IER |= UART_IER_THRI;
1188 outb(info->IER, info->base + UART_IER);
1189 spin_unlock_irqrestore(&info->slock, flags);
1195 static void mxser_flush_chars(struct tty_struct *tty)
1197 struct mxser_struct *info = tty->driver_data;
1198 unsigned long flags;
1200 if (info->xmit_cnt <= 0 ||
1204 (info->type != PORT_16550A) &&
1205 (!info->IsMoxaMustChipFlag)
1209 spin_lock_irqsave(&info->slock, flags);
1211 info->IER |= UART_IER_THRI;
1212 outb(info->IER, info->base + UART_IER);
1214 spin_unlock_irqrestore(&info->slock, flags);
1217 static int mxser_write_room(struct tty_struct *tty)
1219 struct mxser_struct *info = tty->driver_data;
1222 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1228 static int mxser_chars_in_buffer(struct tty_struct *tty)
1230 struct mxser_struct *info = tty->driver_data;
1231 return info->xmit_cnt;
1234 static void mxser_flush_buffer(struct tty_struct *tty)
1236 struct mxser_struct *info = tty->driver_data;
1238 unsigned long flags;
1241 spin_lock_irqsave(&info->slock, flags);
1242 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1244 /* below added by shinhay */
1245 fcr = inb(info->base + UART_FCR);
1246 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1247 info->base + UART_FCR);
1248 outb(fcr, info->base + UART_FCR);
1250 spin_unlock_irqrestore(&info->slock, flags);
1251 /* above added by shinhay */
1253 wake_up_interruptible(&tty->write_wait);
1254 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1255 (tty->ldisc.write_wakeup) (tty);
1258 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1260 struct mxser_struct *info = tty->driver_data;
1262 struct async_icount cprev, cnow; /* kernel counter temps */
1263 struct serial_icounter_struct __user *p_cuser;
1264 unsigned long templ;
1265 unsigned long flags;
1266 void __user *argp = (void __user *)arg;
1268 if (tty->index == MXSER_PORTS)
1269 return mxser_ioctl_special(cmd, argp);
1271 /* following add by Victor Yu. 01-05-2004 */
1272 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1274 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1276 unsigned char val, mask;
1279 if (cmd == MOXA_SET_OP_MODE) {
1280 if (get_user(opmode, (int __user *) argp))
1282 if (opmode != RS232_MODE &&
1283 opmode != RS485_2WIRE_MODE &&
1284 opmode != RS422_MODE &&
1285 opmode != RS485_4WIRE_MODE)
1289 val = inb(info->opmode_ioaddr);
1291 val |= (opmode << shiftbit);
1292 outb(val, info->opmode_ioaddr);
1295 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1296 opmode &= OP_MODE_MASK;
1297 if (copy_to_user(argp, &opmode, sizeof(int)))
1302 /* above add by Victor Yu. 01-05-2004 */
1304 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1305 if (tty->flags & (1 << TTY_IO_ERROR))
1309 case TCSBRK: /* SVID version: non-zero arg --> no break */
1310 retval = tty_check_change(tty);
1313 tty_wait_until_sent(tty, 0);
1315 mxser_send_break(info, HZ / 4); /* 1/4 second */
1317 case TCSBRKP: /* support for POSIX tcsendbreak() */
1318 retval = tty_check_change(tty);
1321 tty_wait_until_sent(tty, 0);
1322 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1325 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1327 if (get_user(templ, (unsigned long __user *) argp))
1330 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1333 return mxser_get_serial_info(info, argp);
1335 return mxser_set_serial_info(info, argp);
1336 case TIOCSERGETLSR: /* Get line status register */
1337 return mxser_get_lsr_info(info, argp);
1339 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1340 * - mask passed in arg for lines of interest
1341 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1342 * Caller should use TIOCGICOUNT to see which one it was
1345 DECLARE_WAITQUEUE(wait, current);
1347 spin_lock_irqsave(&info->slock, flags);
1348 cprev = info->icount; /* note the counters on entry */
1349 spin_unlock_irqrestore(&info->slock, flags);
1351 add_wait_queue(&info->delta_msr_wait, &wait);
1353 spin_lock_irqsave(&info->slock, flags);
1354 cnow = info->icount; /* atomic copy */
1355 spin_unlock_irqrestore(&info->slock, flags);
1357 set_current_state(TASK_INTERRUPTIBLE);
1358 if (((arg & TIOCM_RNG) &&
1359 (cnow.rng != cprev.rng)) ||
1360 ((arg & TIOCM_DSR) &&
1361 (cnow.dsr != cprev.dsr)) ||
1362 ((arg & TIOCM_CD) &&
1363 (cnow.dcd != cprev.dcd)) ||
1364 ((arg & TIOCM_CTS) &&
1365 (cnow.cts != cprev.cts))) {
1369 /* see if a signal did it */
1370 if (signal_pending(current)) {
1376 current->state = TASK_RUNNING;
1377 remove_wait_queue(&info->delta_msr_wait, &wait);
1382 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1383 * Return: write counters to the user passed counter struct
1384 * NB: both 1->0 and 0->1 transitions are counted except for
1385 * RI where only 0->1 is counted.
1388 spin_lock_irqsave(&info->slock, flags);
1389 cnow = info->icount;
1390 spin_unlock_irqrestore(&info->slock, flags);
1392 /* modified by casper 1/11/2000 */
1393 if (put_user(cnow.frame, &p_cuser->frame))
1395 if (put_user(cnow.brk, &p_cuser->brk))
1397 if (put_user(cnow.overrun, &p_cuser->overrun))
1399 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1401 if (put_user(cnow.parity, &p_cuser->parity))
1403 if (put_user(cnow.rx, &p_cuser->rx))
1405 if (put_user(cnow.tx, &p_cuser->tx))
1407 put_user(cnow.cts, &p_cuser->cts);
1408 put_user(cnow.dsr, &p_cuser->dsr);
1409 put_user(cnow.rng, &p_cuser->rng);
1410 put_user(cnow.dcd, &p_cuser->dcd);
1412 case MOXA_HighSpeedOn:
1413 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1414 case MOXA_SDS_RSTICOUNTER: {
1415 info->mon_data.rxcnt = 0;
1416 info->mon_data.txcnt = 0;
1419 /* (above) added by James. */
1420 case MOXA_ASPP_SETBAUD:{
1422 if (get_user(baud, (long __user *)argp))
1424 mxser_set_baud(info, baud);
1427 case MOXA_ASPP_GETBAUD:
1428 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1433 case MOXA_ASPP_OQUEUE:{
1436 len = mxser_chars_in_buffer(tty);
1438 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1440 len += (lsr ? 0 : 1);
1442 if (copy_to_user(argp, &len, sizeof(int)))
1447 case MOXA_ASPP_MON: {
1450 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1452 status = mxser_get_msr(info->base, 1, info->port, info);
1453 mxser_check_modem_status(info, status);
1455 mcr = inb(info->base + UART_MCR);
1456 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1457 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1459 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1461 if (mcr & MOXA_MUST_MCR_TX_XON)
1462 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1464 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1466 if (info->tty->hw_stopped)
1467 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1469 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1471 if (copy_to_user(argp, &info->mon_data,
1472 sizeof(struct mxser_mon)))
1478 case MOXA_ASPP_LSTATUS: {
1479 if (copy_to_user(argp, &info->err_shadow,
1480 sizeof(unsigned char)))
1483 info->err_shadow = 0;
1486 case MOXA_SET_BAUD_METHOD: {
1489 if (get_user(method, (int __user *)argp))
1491 mxser_set_baud_method[info->port] = method;
1492 if (copy_to_user(argp, &method, sizeof(int)))
1498 return -ENOIOCTLCMD;
1504 #define CMSPAR 010000000000
1507 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1509 int i, result, status;
1513 if (copy_to_user(argp, mxsercfg,
1514 sizeof(struct mxser_hwconf) * 4))
1517 case MOXA_GET_MAJOR:
1518 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1522 case MOXA_GET_CUMAJOR:
1523 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1527 case MOXA_CHKPORTENABLE:
1529 for (i = 0; i < MXSER_PORTS; i++) {
1530 if (mxvar_table[i].base)
1533 return put_user(result, (unsigned long __user *)argp);
1534 case MOXA_GETDATACOUNT:
1535 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1538 case MOXA_GETMSTATUS:
1539 for (i = 0; i < MXSER_PORTS; i++) {
1541 if (!mxvar_table[i].base) {
1542 GMStatus[i].dcd = 0;
1543 GMStatus[i].dsr = 0;
1544 GMStatus[i].cts = 0;
1548 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1549 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1551 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1553 status = inb(mxvar_table[i].base + UART_MSR);
1554 if (status & 0x80 /*UART_MSR_DCD */ )
1555 GMStatus[i].dcd = 1;
1557 GMStatus[i].dcd = 0;
1559 if (status & 0x20 /*UART_MSR_DSR */ )
1560 GMStatus[i].dsr = 1;
1562 GMStatus[i].dsr = 0;
1565 if (status & 0x10 /*UART_MSR_CTS */ )
1566 GMStatus[i].cts = 1;
1568 GMStatus[i].cts = 0;
1570 if (copy_to_user(argp, GMStatus,
1571 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1574 case MOXA_ASPP_MON_EXT: {
1578 unsigned cflag, iflag;
1580 for (i = 0; i < MXSER_PORTS; i++) {
1581 if (!mxvar_table[i].base)
1584 status = mxser_get_msr(mxvar_table[i].base, 0,
1585 i, &(mxvar_table[i]));
1587 mxser_check_modem_status(&mxvar_table[i],
1590 if (status & UART_MSR_TERI)
1591 mxvar_table[i].icount.rng++;
1592 if (status & UART_MSR_DDSR)
1593 mxvar_table[i].icount.dsr++;
1594 if (status & UART_MSR_DDCD)
1595 mxvar_table[i].icount.dcd++;
1596 if (status & UART_MSR_DCTS)
1597 mxvar_table[i].icount.cts++;
1599 mxvar_table[i].mon_data.modem_status = status;
1600 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1601 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1602 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1603 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1604 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1605 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1607 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1608 cflag = mxvar_table[i].normal_termios.c_cflag;
1609 iflag = mxvar_table[i].normal_termios.c_iflag;
1611 cflag = mxvar_table[i].tty->termios->c_cflag;
1612 iflag = mxvar_table[i].tty->termios->c_iflag;
1615 mon_data_ext.databits[i] = cflag & CSIZE;
1617 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1619 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1621 mon_data_ext.flowctrl[i] = 0x00;
1623 if (cflag & CRTSCTS)
1624 mon_data_ext.flowctrl[i] |= 0x03;
1626 if (iflag & (IXON | IXOFF))
1627 mon_data_ext.flowctrl[i] |= 0x0C;
1629 if (mxvar_table[i].type == PORT_16550A)
1630 mon_data_ext.fifo[i] = 1;
1632 mon_data_ext.fifo[i] = 0;
1636 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1637 opmode &= OP_MODE_MASK;
1639 mon_data_ext.iftype[i] = opmode;
1642 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1649 return -ENOIOCTLCMD;
1654 static void mxser_stoprx(struct tty_struct *tty)
1656 struct mxser_struct *info = tty->driver_data;
1657 /* unsigned long flags; */
1659 info->ldisc_stop_rx = 1;
1661 /* MX_LOCK(&info->slock); */
1662 /* following add by Victor Yu. 09-02-2002 */
1663 if (info->IsMoxaMustChipFlag) {
1664 info->IER &= ~MOXA_MUST_RECV_ISR;
1665 outb(info->IER, info->base + UART_IER);
1667 /* above add by Victor Yu. 09-02-2002 */
1668 info->x_char = STOP_CHAR(tty);
1669 /* mask by Victor Yu. 09-02-2002 */
1670 /* outb(info->IER, 0); */
1671 outb(0, info->base + UART_IER);
1672 info->IER |= UART_IER_THRI;
1673 /* force Tx interrupt */
1674 outb(info->IER, info->base + UART_IER);
1675 } /* add by Victor Yu. 09-02-2002 */
1676 /* MX_UNLOCK(&info->slock); */
1679 if (info->tty->termios->c_cflag & CRTSCTS) {
1680 /* MX_LOCK(&info->slock); */
1681 info->MCR &= ~UART_MCR_RTS;
1682 outb(info->MCR, info->base + UART_MCR);
1683 /* MX_UNLOCK(&info->slock); */
1687 static void mxser_startrx(struct tty_struct *tty)
1689 struct mxser_struct *info = tty->driver_data;
1690 /* unsigned long flags; */
1692 info->ldisc_stop_rx = 0;
1697 /* MX_LOCK(&info->slock); */
1699 /* following add by Victor Yu. 09-02-2002 */
1700 if (info->IsMoxaMustChipFlag) {
1701 info->IER |= MOXA_MUST_RECV_ISR;
1702 outb(info->IER, info->base + UART_IER);
1704 /* above add by Victor Yu. 09-02-2002 */
1706 info->x_char = START_CHAR(tty);
1707 /* mask by Victor Yu. 09-02-2002 */
1708 /* outb(info->IER, 0); */
1709 /* add by Victor Yu. 09-02-2002 */
1710 outb(0, info->base + UART_IER);
1711 /* force Tx interrupt */
1712 info->IER |= UART_IER_THRI;
1713 outb(info->IER, info->base + UART_IER);
1714 } /* add by Victor Yu. 09-02-2002 */
1715 /* MX_UNLOCK(&info->slock); */
1719 if (info->tty->termios->c_cflag & CRTSCTS) {
1720 /* MX_LOCK(&info->slock); */
1721 info->MCR |= UART_MCR_RTS;
1722 outb(info->MCR, info->base + UART_MCR);
1723 /* MX_UNLOCK(&info->slock); */
1728 * This routine is called by the upper-layer tty layer to signal that
1729 * incoming characters should be throttled.
1731 static void mxser_throttle(struct tty_struct *tty)
1733 /* struct mxser_struct *info = tty->driver_data; */
1734 /* unsigned long flags; */
1736 /* MX_LOCK(&info->slock); */
1738 /* MX_UNLOCK(&info->slock); */
1741 static void mxser_unthrottle(struct tty_struct *tty)
1743 /* struct mxser_struct *info = tty->driver_data; */
1744 /* unsigned long flags; */
1746 /* MX_LOCK(&info->slock); */
1748 /* MX_UNLOCK(&info->slock); */
1751 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1753 struct mxser_struct *info = tty->driver_data;
1754 unsigned long flags;
1756 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1757 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1759 mxser_change_speed(info, old_termios);
1761 if ((old_termios->c_cflag & CRTSCTS) &&
1762 !(tty->termios->c_cflag & CRTSCTS)) {
1763 tty->hw_stopped = 0;
1768 /* Handle sw stopped */
1769 if ((old_termios->c_iflag & IXON) &&
1770 !(tty->termios->c_iflag & IXON)) {
1773 /* following add by Victor Yu. 09-02-2002 */
1774 if (info->IsMoxaMustChipFlag) {
1775 spin_lock_irqsave(&info->slock, flags);
1776 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1777 spin_unlock_irqrestore(&info->slock, flags);
1779 /* above add by Victor Yu. 09-02-2002 */
1786 * mxser_stop() and mxser_start()
1788 * This routines are called before setting or resetting tty->stopped.
1789 * They enable or disable transmitter interrupts, as necessary.
1791 static void mxser_stop(struct tty_struct *tty)
1793 struct mxser_struct *info = tty->driver_data;
1794 unsigned long flags;
1796 spin_lock_irqsave(&info->slock, flags);
1797 if (info->IER & UART_IER_THRI) {
1798 info->IER &= ~UART_IER_THRI;
1799 outb(info->IER, info->base + UART_IER);
1801 spin_unlock_irqrestore(&info->slock, flags);
1804 static void mxser_start(struct tty_struct *tty)
1806 struct mxser_struct *info = tty->driver_data;
1807 unsigned long flags;
1809 spin_lock_irqsave(&info->slock, flags);
1810 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1811 info->IER |= UART_IER_THRI;
1812 outb(info->IER, info->base + UART_IER);
1814 spin_unlock_irqrestore(&info->slock, flags);
1818 * mxser_wait_until_sent() --- wait until the transmitter is empty
1820 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1822 struct mxser_struct *info = tty->driver_data;
1823 unsigned long orig_jiffies, char_time;
1826 if (info->type == PORT_UNKNOWN)
1829 if (info->xmit_fifo_size == 0)
1830 return; /* Just in case.... */
1832 orig_jiffies = jiffies;
1834 * Set the check interval to be 1/5 of the estimated time to
1835 * send a single character, and make it at least 1. The check
1836 * interval should also be less than the timeout.
1838 * Note: we have to use pretty tight timings here to satisfy
1841 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1842 char_time = char_time / 5;
1845 if (timeout && timeout < char_time)
1846 char_time = timeout;
1848 * If the transmitter hasn't cleared in twice the approximate
1849 * amount of time to send the entire FIFO, it probably won't
1850 * ever clear. This assumes the UART isn't doing flow
1851 * control, which is currently the case. Hence, if it ever
1852 * takes longer than info->timeout, this is probably due to a
1853 * UART bug of some kind. So, we clamp the timeout parameter at
1856 if (!timeout || timeout > 2 * info->timeout)
1857 timeout = 2 * info->timeout;
1858 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1859 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1860 timeout, char_time);
1861 printk("jiff=%lu...", jiffies);
1863 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1864 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1865 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1867 schedule_timeout_interruptible(char_time);
1868 if (signal_pending(current))
1870 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1873 set_current_state(TASK_RUNNING);
1875 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1876 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1882 * This routine is called by tty_hangup() when a hangup is signaled.
1884 void mxser_hangup(struct tty_struct *tty)
1886 struct mxser_struct *info = tty->driver_data;
1888 mxser_flush_buffer(tty);
1889 mxser_shutdown(info);
1892 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1894 wake_up_interruptible(&info->open_wait);
1898 /* added by James 03-12-2004. */
1900 * mxser_rs_break() --- routine which turns the break handling on or off
1902 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1904 struct mxser_struct *info = tty->driver_data;
1905 unsigned long flags;
1907 spin_lock_irqsave(&info->slock, flags);
1908 if (break_state == -1)
1909 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
1910 info->base + UART_LCR);
1912 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
1913 info->base + UART_LCR);
1914 spin_unlock_irqrestore(&info->slock, flags);
1917 /* (above) added by James. */
1921 * This is the serial driver's generic interrupt routine
1923 static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1926 struct mxser_struct *info;
1927 struct mxser_struct *port;
1928 int max, irqbits, bits, msr;
1929 int pass_counter = 0;
1930 int handled = IRQ_NONE;
1933 /* spin_lock(&gm_lock); */
1935 for (i = 0; i < MXSER_BOARDS; i++) {
1936 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1942 if (i == MXSER_BOARDS)
1946 max = mxser_numports[mxsercfg[i].board_type - 1];
1948 irqbits = inb(port->vector) & port->vectormask;
1949 if (irqbits == port->vectormask)
1952 handled = IRQ_HANDLED;
1953 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1954 if (irqbits == port->vectormask)
1960 /* following add by Victor Yu. 09-13-2002 */
1961 iir = inb(info->base + UART_IIR);
1962 if (iir & UART_IIR_NO_INT)
1964 iir &= MOXA_MUST_IIR_MASK;
1966 status = inb(info->base + UART_LSR);
1967 outb(0x27, info->base + UART_FCR);
1968 inb(info->base + UART_MSR);
1971 /* above add by Victor Yu. 09-13-2002 */
1973 if (info->tty->flip.count < TTY_FLIPBUF_SIZE / 4) {
1974 info->IER |= MOXA_MUST_RECV_ISR;
1975 outb(info->IER, info->base + UART_IER);
1980 /* mask by Victor Yu. 09-13-2002
1982 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1985 /* mask by Victor Yu. 09-02-2002
1986 status = inb(info->base + UART_LSR) & info->read_status_mask;
1989 /* following add by Victor Yu. 09-02-2002 */
1990 status = inb(info->base + UART_LSR);
1992 if (status & UART_LSR_PE)
1993 info->err_shadow |= NPPI_NOTIFY_PARITY;
1994 if (status & UART_LSR_FE)
1995 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1996 if (status & UART_LSR_OE)
1997 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1998 if (status & UART_LSR_BI)
1999 info->err_shadow |= NPPI_NOTIFY_BREAK;
2001 if (info->IsMoxaMustChipFlag) {
2003 if ( (status & 0x02) && !(status & 0x01) ) {
2004 outb(info->base+UART_FCR, 0x23);
2008 if (iir == MOXA_MUST_IIR_GDA ||
2009 iir == MOXA_MUST_IIR_RDA ||
2010 iir == MOXA_MUST_IIR_RTO ||
2011 iir == MOXA_MUST_IIR_LSR)
2012 mxser_receive_chars(info, &status);
2015 /* above add by Victor Yu. 09-02-2002 */
2017 status &= info->read_status_mask;
2018 if (status & UART_LSR_DR)
2019 mxser_receive_chars(info, &status);
2021 msr = inb(info->base + UART_MSR);
2022 if (msr & UART_MSR_ANY_DELTA) {
2023 mxser_check_modem_status(info, msr);
2025 /* following add by Victor Yu. 09-13-2002 */
2026 if (info->IsMoxaMustChipFlag) {
2027 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
2028 mxser_transmit_chars(info);
2031 /* above add by Victor Yu. 09-13-2002 */
2033 if (status & UART_LSR_THRE) {
2034 /* 8-2-99 by William
2035 if ( info->x_char || (info->xmit_cnt > 0) )
2037 mxser_transmit_chars(info);
2041 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
2042 break; /* Prevent infinite loops */
2047 /* spin_unlock(&gm_lock); */
2051 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2053 struct tty_struct *tty = info->tty;
2054 unsigned char ch, gdl;
2059 unsigned long flags;
2061 spin_lock_irqsave(&info->slock, flags);
2063 recv_room = tty->receive_room;
2064 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2065 /* mxser_throttle(tty); */
2070 /* following add by Victor Yu. 09-02-2002 */
2071 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2073 if (*status & UART_LSR_SPECIAL) {
2076 /* following add by Victor Yu. 02-11-2004 */
2077 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID &&
2078 (*status & MOXA_MUST_LSR_RERR))
2080 /* above add by Victor Yu. 02-14-2004 */
2081 if (*status & MOXA_MUST_LSR_RERR)
2084 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2086 /* add by Victor Yu. 02-11-2004 */
2087 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID)
2088 gdl &= MOXA_MUST_GDL_MASK;
2089 if (gdl >= recv_room) {
2090 if (!info->ldisc_stop_rx) {
2091 /* mxser_throttle(tty); */
2097 ch = inb(info->base + UART_RX);
2098 tty_insert_flip_char(tty, ch, 0);
2101 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2110 /* above add by Victor Yu. 09-02-2002 */
2116 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2123 ch = inb(info->base + UART_RX);
2124 /* following add by Victor Yu. 09-02-2002 */
2125 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2126 outb(0x23, info->base + UART_FCR);
2127 *status &= info->read_status_mask;
2128 /* above add by Victor Yu. 09-02-2002 */
2129 if (*status & info->ignore_status_mask) {
2130 if (++ignored > 100)
2134 if (*status & UART_LSR_SPECIAL) {
2135 if (*status & UART_LSR_BI) {
2137 /* added by casper 1/11/2000 */
2140 if (info->flags & ASYNC_SAK)
2142 } else if (*status & UART_LSR_PE) {
2144 /* added by casper 1/11/2000 */
2145 info->icount.parity++;
2147 } else if (*status & UART_LSR_FE) {
2149 /* added by casper 1/11/2000 */
2150 info->icount.frame++;
2152 } else if (*status & UART_LSR_OE) {
2154 /* added by casper 1/11/2000 */
2155 info->icount.overrun++;
2159 tty_insert_flip_char(tty, ch, flag);
2161 if (cnt >= recv_room) {
2162 if (!info->ldisc_stop_rx) {
2163 /* mxser_throttle(tty); */
2171 /* following add by Victor Yu. 09-02-2002 */
2172 if (info->IsMoxaMustChipFlag)
2174 /* above add by Victor Yu. 09-02-2002 */
2176 /* mask by Victor Yu. 09-02-2002
2177 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2179 /* following add by Victor Yu. 09-02-2002 */
2180 *status = inb(info->base + UART_LSR);
2181 /* above add by Victor Yu. 09-02-2002 */
2182 } while (*status & UART_LSR_DR);
2184 end_intr: /* add by Victor Yu. 09-02-2002 */
2185 mxvar_log.rxcnt[info->port] += cnt;
2186 info->mon_data.rxcnt += cnt;
2187 info->mon_data.up_rxcnt += cnt;
2188 spin_unlock_irqrestore(&info->slock, flags);
2190 tty_flip_buffer_push(tty);
2193 static void mxser_transmit_chars(struct mxser_struct *info)
2196 unsigned long flags;
2198 spin_lock_irqsave(&info->slock, flags);
2201 outb(info->x_char, info->base + UART_TX);
2203 mxvar_log.txcnt[info->port]++;
2204 info->mon_data.txcnt++;
2205 info->mon_data.up_txcnt++;
2207 /* added by casper 1/11/2000 */
2210 spin_unlock_irqrestore(&info->slock, flags);
2214 if (info->xmit_buf == 0) {
2215 spin_unlock_irqrestore(&info->slock, flags);
2219 if ((info->xmit_cnt <= 0) || info->tty->stopped ||
2220 (info->tty->hw_stopped &&
2221 (info->type != PORT_16550A) &&
2222 (!info->IsMoxaMustChipFlag))) {
2223 info->IER &= ~UART_IER_THRI;
2224 outb(info->IER, info->base + UART_IER);
2225 spin_unlock_irqrestore(&info->slock, flags);
2229 cnt = info->xmit_cnt;
2230 count = info->xmit_fifo_size;
2232 outb(info->xmit_buf[info->xmit_tail++],
2233 info->base + UART_TX);
2234 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2235 if (--info->xmit_cnt <= 0)
2237 } while (--count > 0);
2238 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2240 /* added by James 03-12-2004. */
2241 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2242 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2243 /* (above) added by James. */
2245 /* added by casper 1/11/2000 */
2246 info->icount.tx += (cnt - info->xmit_cnt);
2249 if (info->xmit_cnt < WAKEUP_CHARS) {
2250 set_bit(MXSER_EVENT_TXLOW, &info->event);
2251 schedule_work(&info->tqueue);
2253 if (info->xmit_cnt <= 0) {
2254 info->IER &= ~UART_IER_THRI;
2255 outb(info->IER, info->base + UART_IER);
2257 spin_unlock_irqrestore(&info->slock, flags);
2260 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2262 /* update input line counters */
2263 if (status & UART_MSR_TERI)
2265 if (status & UART_MSR_DDSR)
2267 if (status & UART_MSR_DDCD)
2269 if (status & UART_MSR_DCTS)
2271 info->mon_data.modem_status = status;
2272 wake_up_interruptible(&info->delta_msr_wait);
2274 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2275 if (status & UART_MSR_DCD)
2276 wake_up_interruptible(&info->open_wait);
2277 schedule_work(&info->tqueue);
2280 if (info->flags & ASYNC_CTS_FLOW) {
2281 if (info->tty->hw_stopped) {
2282 if (status & UART_MSR_CTS) {
2283 info->tty->hw_stopped = 0;
2285 if ((info->type != PORT_16550A) &&
2286 (!info->IsMoxaMustChipFlag)) {
2287 info->IER |= UART_IER_THRI;
2288 outb(info->IER, info->base + UART_IER);
2290 set_bit(MXSER_EVENT_TXLOW, &info->event);
2291 schedule_work(&info->tqueue); }
2293 if (!(status & UART_MSR_CTS)) {
2294 info->tty->hw_stopped = 1;
2295 if ((info->type != PORT_16550A) &&
2296 (!info->IsMoxaMustChipFlag)) {
2297 info->IER &= ~UART_IER_THRI;
2298 outb(info->IER, info->base + UART_IER);
2305 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2307 DECLARE_WAITQUEUE(wait, current);
2310 unsigned long flags;
2313 * If non-blocking mode is set, or the port is not enabled,
2314 * then make the check up front and then exit.
2316 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2317 info->flags |= ASYNC_NORMAL_ACTIVE;
2321 if (tty->termios->c_cflag & CLOCAL)
2325 * Block waiting for the carrier detect and the line to become
2326 * free (i.e., not in use by the callout). While we are in
2327 * this loop, info->count is dropped by one, so that
2328 * mxser_close() knows when to free things. We restore it upon
2329 * exit, either normal or abnormal.
2332 add_wait_queue(&info->open_wait, &wait);
2334 spin_lock_irqsave(&info->slock, flags);
2335 if (!tty_hung_up_p(filp))
2337 spin_unlock_irqrestore(&info->slock, flags);
2338 info->blocked_open++;
2340 spin_lock_irqsave(&info->slock, flags);
2341 outb(inb(info->base + UART_MCR) |
2342 UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2343 spin_unlock_irqrestore(&info->slock, flags);
2344 set_current_state(TASK_INTERRUPTIBLE);
2345 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2346 if (info->flags & ASYNC_HUP_NOTIFY)
2349 retval = -ERESTARTSYS;
2352 if (!(info->flags & ASYNC_CLOSING) &&
2354 (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2356 if (signal_pending(current)) {
2357 retval = -ERESTARTSYS;
2362 set_current_state(TASK_RUNNING);
2363 remove_wait_queue(&info->open_wait, &wait);
2364 if (!tty_hung_up_p(filp))
2366 info->blocked_open--;
2369 info->flags |= ASYNC_NORMAL_ACTIVE;
2373 static int mxser_startup(struct mxser_struct *info)
2376 unsigned long flags;
2378 page = __get_free_page(GFP_KERNEL);
2382 spin_lock_irqsave(&info->slock, flags);
2384 if (info->flags & ASYNC_INITIALIZED) {
2386 spin_unlock_irqrestore(&info->slock, flags);
2390 if (!info->base || !info->type) {
2392 set_bit(TTY_IO_ERROR, &info->tty->flags);
2394 spin_unlock_irqrestore(&info->slock, flags);
2400 info->xmit_buf = (unsigned char *) page;
2403 * Clear the FIFO buffers and disable them
2404 * (they will be reenabled in mxser_change_speed())
2406 if (info->IsMoxaMustChipFlag)
2407 outb((UART_FCR_CLEAR_RCVR |
2408 UART_FCR_CLEAR_XMIT |
2409 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2411 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2412 info->base + UART_FCR);
2415 * At this point there's no way the LSR could still be 0xFF;
2416 * if it is, then bail out, because there's likely no UART
2419 if (inb(info->base + UART_LSR) == 0xff) {
2420 spin_unlock_irqrestore(&info->slock, flags);
2421 if (capable(CAP_SYS_ADMIN)) {
2423 set_bit(TTY_IO_ERROR, &info->tty->flags);
2430 * Clear the interrupt registers.
2432 (void) inb(info->base + UART_LSR);
2433 (void) inb(info->base + UART_RX);
2434 (void) inb(info->base + UART_IIR);
2435 (void) inb(info->base + UART_MSR);
2438 * Now, initialize the UART
2440 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2441 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2442 outb(info->MCR, info->base + UART_MCR);
2445 * Finally, enable interrupts
2447 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2448 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2450 /* following add by Victor Yu. 08-30-2002 */
2451 if (info->IsMoxaMustChipFlag)
2452 info->IER |= MOXA_MUST_IER_EGDAI;
2453 /* above add by Victor Yu. 08-30-2002 */
2454 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2457 * And clear the interrupt registers again for luck.
2459 (void) inb(info->base + UART_LSR);
2460 (void) inb(info->base + UART_RX);
2461 (void) inb(info->base + UART_IIR);
2462 (void) inb(info->base + UART_MSR);
2465 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2466 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2469 * and set the speed of the serial port
2471 spin_unlock_irqrestore(&info->slock, flags);
2472 mxser_change_speed(info, NULL);
2474 info->flags |= ASYNC_INITIALIZED;
2479 * This routine will shutdown a serial port; interrupts maybe disabled, and
2480 * DTR is dropped if the hangup on close termio flag is on.
2482 static void mxser_shutdown(struct mxser_struct *info)
2484 unsigned long flags;
2486 if (!(info->flags & ASYNC_INITIALIZED))
2489 spin_lock_irqsave(&info->slock, flags);
2492 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2493 * here so the queue might never be waken up
2495 wake_up_interruptible(&info->delta_msr_wait);
2498 * Free the IRQ, if necessary
2500 if (info->xmit_buf) {
2501 free_page((unsigned long) info->xmit_buf);
2502 info->xmit_buf = NULL;
2506 outb(0x00, info->base + UART_IER);
2508 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2509 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2510 outb(info->MCR, info->base + UART_MCR);
2512 /* clear Rx/Tx FIFO's */
2513 /* following add by Victor Yu. 08-30-2002 */
2514 if (info->IsMoxaMustChipFlag)
2515 outb((UART_FCR_CLEAR_RCVR |
2516 UART_FCR_CLEAR_XMIT |
2517 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2519 /* above add by Victor Yu. 08-30-2002 */
2520 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2521 info->base + UART_FCR);
2523 /* read data port to reset things */
2524 (void) inb(info->base + UART_RX);
2527 set_bit(TTY_IO_ERROR, &info->tty->flags);
2529 info->flags &= ~ASYNC_INITIALIZED;
2531 /* following add by Victor Yu. 09-23-2002 */
2532 if (info->IsMoxaMustChipFlag)
2533 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2534 /* above add by Victor Yu. 09-23-2002 */
2536 spin_unlock_irqrestore(&info->slock, flags);
2540 * This routine is called to set the UART divisor registers to match
2541 * the specified baud rate for a serial port.
2543 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2545 unsigned cflag, cval, fcr;
2547 unsigned char status;
2549 unsigned long flags;
2551 if (!info->tty || !info->tty->termios)
2553 cflag = info->tty->termios->c_cflag;
2558 #define B921600 (B460800 +1)
2560 if (mxser_set_baud_method[info->port] == 0) {
2561 baud = tty_get_baud_rate(info->tty);
2562 mxser_set_baud(info, baud);
2565 /* byte size and parity */
2566 switch (cflag & CSIZE) {
2581 break; /* too keep GCC shut... */
2586 cval |= UART_LCR_PARITY;
2587 if (!(cflag & PARODD))
2588 cval |= UART_LCR_EPAR;
2590 cval |= UART_LCR_SPAR;
2592 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2593 if (info->IsMoxaMustChipFlag) {
2594 fcr = UART_FCR_ENABLE_FIFO;
2595 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2596 SET_MOXA_MUST_FIFO_VALUE(info);
2600 fcr = UART_FCR_ENABLE_FIFO;
2601 /* following add by Victor Yu. 08-30-2002 */
2602 if (info->IsMoxaMustChipFlag) {
2603 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2604 SET_MOXA_MUST_FIFO_VALUE(info);
2606 /* above add by Victor Yu. 08-30-2002 */
2607 switch (info->rx_trigger) {
2609 fcr |= UART_FCR_TRIGGER_1;
2612 fcr |= UART_FCR_TRIGGER_4;
2615 fcr |= UART_FCR_TRIGGER_8;
2618 fcr |= UART_FCR_TRIGGER_14;
2624 /* CTS flow control flag and modem status interrupts */
2625 info->IER &= ~UART_IER_MSI;
2626 info->MCR &= ~UART_MCR_AFE;
2627 if (cflag & CRTSCTS) {
2628 info->flags |= ASYNC_CTS_FLOW;
2629 info->IER |= UART_IER_MSI;
2630 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2631 info->MCR |= UART_MCR_AFE;
2632 /* status = mxser_get_msr(info->base, 0, info->port); */
2636 status = inb(baseaddr + UART_MSR);
2637 restore_flags(flags);
2639 /* mxser_check_modem_status(info, status); */
2641 /* status = mxser_get_msr(info->base, 0, info->port); */
2642 /* MX_LOCK(&info->slock); */
2643 status = inb(info->base + UART_MSR);
2644 /* MX_UNLOCK(&info->slock); */
2645 if (info->tty->hw_stopped) {
2646 if (status & UART_MSR_CTS) {
2647 info->tty->hw_stopped = 0;
2648 if ((info->type != PORT_16550A) &&
2649 (!info->IsMoxaMustChipFlag)) {
2650 info->IER |= UART_IER_THRI;
2651 outb(info->IER, info->base + UART_IER);
2653 set_bit(MXSER_EVENT_TXLOW, &info->event);
2654 schedule_work(&info->tqueue); }
2656 if (!(status & UART_MSR_CTS)) {
2657 info->tty->hw_stopped = 1;
2658 if ((info->type != PORT_16550A) &&
2659 (!info->IsMoxaMustChipFlag)) {
2660 info->IER &= ~UART_IER_THRI;
2661 outb(info->IER, info->base + UART_IER);
2667 info->flags &= ~ASYNC_CTS_FLOW;
2669 outb(info->MCR, info->base + UART_MCR);
2670 if (cflag & CLOCAL) {
2671 info->flags &= ~ASYNC_CHECK_CD;
2673 info->flags |= ASYNC_CHECK_CD;
2674 info->IER |= UART_IER_MSI;
2676 outb(info->IER, info->base + UART_IER);
2679 * Set up parity check flag
2681 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2682 if (I_INPCK(info->tty))
2683 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2684 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2685 info->read_status_mask |= UART_LSR_BI;
2687 info->ignore_status_mask = 0;
2689 if (I_IGNBRK(info->tty)) {
2690 info->ignore_status_mask |= UART_LSR_BI;
2691 info->read_status_mask |= UART_LSR_BI;
2693 * If we're ignore parity and break indicators, ignore
2694 * overruns too. (For real raw support).
2696 if (I_IGNPAR(info->tty)) {
2697 info->ignore_status_mask |=
2701 info->read_status_mask |=
2707 /* following add by Victor Yu. 09-02-2002 */
2708 if (info->IsMoxaMustChipFlag) {
2709 spin_lock_irqsave(&info->slock, flags);
2710 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2711 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2712 if (I_IXON(info->tty)) {
2713 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2715 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2717 if (I_IXOFF(info->tty)) {
2718 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2720 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2723 if ( I_IXANY(info->tty) ) {
2724 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2725 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2727 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2728 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2731 spin_unlock_irqrestore(&info->slock, flags);
2733 /* above add by Victor Yu. 09-02-2002 */
2736 outb(fcr, info->base + UART_FCR); /* set fcr */
2737 outb(cval, info->base + UART_LCR);
2743 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2748 unsigned long flags;
2750 if (!info->tty || !info->tty->termios)
2756 if (newspd > info->MaxCanSetBaudRate)
2759 info->realbaud = newspd;
2760 if (newspd == 134) {
2761 quot = (2 * info->baud_base / 269);
2762 } else if (newspd) {
2763 quot = info->baud_base / newspd;
2770 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2771 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2774 spin_lock_irqsave(&info->slock, flags);
2775 info->MCR |= UART_MCR_DTR;
2776 outb(info->MCR, info->base + UART_MCR);
2777 spin_unlock_irqrestore(&info->slock, flags);
2779 spin_lock_irqsave(&info->slock, flags);
2780 info->MCR &= ~UART_MCR_DTR;
2781 outb(info->MCR, info->base + UART_MCR);
2782 spin_unlock_irqrestore(&info->slock, flags);
2786 cval = inb(info->base + UART_LCR);
2788 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2790 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2791 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2792 outb(cval, info->base + UART_LCR); /* reset DLAB */
2799 * ------------------------------------------------------------
2800 * friends of mxser_ioctl()
2801 * ------------------------------------------------------------
2803 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2805 struct serial_struct tmp;
2809 memset(&tmp, 0, sizeof(tmp));
2810 tmp.type = info->type;
2811 tmp.line = info->port;
2812 tmp.port = info->base;
2813 tmp.irq = info->irq;
2814 tmp.flags = info->flags;
2815 tmp.baud_base = info->baud_base;
2816 tmp.close_delay = info->close_delay;
2817 tmp.closing_wait = info->closing_wait;
2818 tmp.custom_divisor = info->custom_divisor;
2820 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2825 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2827 struct serial_struct new_serial;
2831 if (!new_info || !info->base)
2833 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2836 if ((new_serial.irq != info->irq) ||
2837 (new_serial.port != info->base) ||
2838 (new_serial.custom_divisor != info->custom_divisor) ||
2839 (new_serial.baud_base != info->baud_base))
2842 flags = info->flags & ASYNC_SPD_MASK;
2844 if (!capable(CAP_SYS_ADMIN)) {
2845 if ((new_serial.baud_base != info->baud_base) ||
2846 (new_serial.close_delay != info->close_delay) ||
2847 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2849 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2850 (new_serial.flags & ASYNC_USR_MASK));
2853 * OK, past this point, all the error checking has been done.
2854 * At this point, we start making changes.....
2856 info->flags = ((info->flags & ~ASYNC_FLAGS) |
2857 (new_serial.flags & ASYNC_FLAGS));
2858 info->close_delay = new_serial.close_delay * HZ / 100;
2859 info->closing_wait = new_serial.closing_wait * HZ / 100;
2860 info->tty->low_latency =
2861 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2862 info->tty->low_latency = 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2865 /* added by casper, 3/17/2000, for mouse */
2866 info->type = new_serial.type;
2868 process_txrx_fifo(info);
2870 if (info->flags & ASYNC_INITIALIZED) {
2871 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2872 mxser_change_speed(info, NULL);
2875 retval = mxser_startup(info);
2881 * mxser_get_lsr_info - get line status register info
2883 * Purpose: Let user call ioctl() to get info when the UART physically
2884 * is emptied. On bus types like RS485, the transmitter must
2885 * release the bus after transmitting. This must be done when
2886 * the transmit shift register is empty, not be done when the
2887 * transmit holding register is empty. This functionality
2888 * allows an RS485 driver to be written in user space.
2890 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2892 unsigned char status;
2893 unsigned int result;
2894 unsigned long flags;
2896 spin_lock_irqsave(&info->slock, flags);
2897 status = inb(info->base + UART_LSR);
2898 spin_unlock_irqrestore(&info->slock, flags);
2899 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2900 return put_user(result, value);
2904 * This routine sends a break character out the serial port.
2906 static void mxser_send_break(struct mxser_struct *info, int duration)
2908 unsigned long flags;
2912 set_current_state(TASK_INTERRUPTIBLE);
2913 spin_lock_irqsave(&info->slock, flags);
2914 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
2915 info->base + UART_LCR);
2916 spin_unlock_irqrestore(&info->slock, flags);
2917 schedule_timeout(duration);
2918 spin_lock_irqsave(&info->slock, flags);
2919 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
2920 info->base + UART_LCR);
2921 spin_unlock_irqrestore(&info->slock, flags);
2924 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2926 struct mxser_struct *info = tty->driver_data;
2927 unsigned char control, status;
2928 unsigned long flags;
2931 if (tty->index == MXSER_PORTS)
2932 return -ENOIOCTLCMD;
2933 if (tty->flags & (1 << TTY_IO_ERROR))
2936 control = info->MCR;
2938 spin_lock_irqsave(&info->slock, flags);
2939 status = inb(info->base + UART_MSR);
2940 if (status & UART_MSR_ANY_DELTA)
2941 mxser_check_modem_status(info, status);
2942 spin_unlock_irqrestore(&info->slock, flags);
2943 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2944 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
2945 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
2946 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
2947 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
2948 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2951 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2953 struct mxser_struct *info = tty->driver_data;
2954 unsigned long flags;
2957 if (tty->index == MXSER_PORTS)
2958 return -ENOIOCTLCMD;
2959 if (tty->flags & (1 << TTY_IO_ERROR))
2962 spin_lock_irqsave(&info->slock, flags);
2964 if (set & TIOCM_RTS)
2965 info->MCR |= UART_MCR_RTS;
2966 if (set & TIOCM_DTR)
2967 info->MCR |= UART_MCR_DTR;
2969 if (clear & TIOCM_RTS)
2970 info->MCR &= ~UART_MCR_RTS;
2971 if (clear & TIOCM_DTR)
2972 info->MCR &= ~UART_MCR_DTR;
2974 outb(info->MCR, info->base + UART_MCR);
2975 spin_unlock_irqrestore(&info->slock, flags);
2980 static int mxser_read_register(int, unsigned short *);
2981 static int mxser_program_mode(int);
2982 static void mxser_normal_mode(int);
2984 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2987 unsigned short regs[16], irq;
2988 unsigned char scratch, scratch2;
2990 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2992 id = mxser_read_register(cap, regs);
2993 if (id == C168_ASIC_ID) {
2994 hwconf->board_type = MXSER_BOARD_C168_ISA;
2996 } else if (id == C104_ASIC_ID) {
2997 hwconf->board_type = MXSER_BOARD_C104_ISA;
2999 } else if (id == C102_ASIC_ID) {
3000 hwconf->board_type = MXSER_BOARD_C102_ISA;
3002 } else if (id == CI132_ASIC_ID) {
3003 hwconf->board_type = MXSER_BOARD_CI132;
3005 } else if (id == CI134_ASIC_ID) {
3006 hwconf->board_type = MXSER_BOARD_CI134;
3008 } else if (id == CI104J_ASIC_ID) {
3009 hwconf->board_type = MXSER_BOARD_CI104J;
3015 if (hwconf->ports == 2) {
3016 irq = regs[9] & 0xF000;
3017 irq = irq | (irq >> 4);
3018 if (irq != (regs[9] & 0xFF00))
3019 return MXSER_ERR_IRQ_CONFLIT;
3020 } else if (hwconf->ports == 4) {
3021 irq = regs[9] & 0xF000;
3022 irq = irq | (irq >> 4);
3023 irq = irq | (irq >> 8);
3025 return MXSER_ERR_IRQ_CONFLIT;
3026 } else if (hwconf->ports == 8) {
3027 irq = regs[9] & 0xF000;
3028 irq = irq | (irq >> 4);
3029 irq = irq | (irq >> 8);
3030 if ((irq != regs[9]) || (irq != regs[10]))
3031 return MXSER_ERR_IRQ_CONFLIT;
3035 return MXSER_ERR_IRQ;
3036 hwconf->irq = ((int)(irq & 0xF000) >> 12);
3037 for (i = 0; i < 8; i++)
3038 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3039 if ((regs[12] & 0x80) == 0)
3040 return MXSER_ERR_VECTOR;
3041 hwconf->vector = (int)regs[11]; /* interrupt vector */
3043 hwconf->vector_mask = 0x00FF;
3045 hwconf->vector_mask = 0x000F;
3046 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3047 if (regs[12] & bits) {
3048 hwconf->baud_base[i] = 921600;
3049 hwconf->MaxCanSetBaudRate[i] = 921600; /* add by Victor Yu. 09-04-2002 */
3051 hwconf->baud_base[i] = 115200;
3052 hwconf->MaxCanSetBaudRate[i] = 115200; /* add by Victor Yu. 09-04-2002 */
3055 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3056 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3057 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3058 outb(scratch2, cap + UART_LCR);
3059 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3060 scratch = inb(cap + UART_IIR);
3063 hwconf->uart_type = PORT_16550A;
3065 hwconf->uart_type = PORT_16450;
3070 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3071 request_region(hwconf->vector, 1, "mxser(vector)");
3072 return hwconf->ports;
3075 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3076 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3077 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3078 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3079 #define EN_CCMD 0x000 /* Chip's command register */
3080 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3081 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3082 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3083 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3084 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3085 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3086 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3087 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3088 static int mxser_read_register(int port, unsigned short *regs)
3090 int i, k, value, id;
3093 id = mxser_program_mode(port);
3096 for (i = 0; i < 14; i++) {
3097 k = (i & 0x3F) | 0x180;
3098 for (j = 0x100; j > 0; j >>= 1) {
3099 outb(CHIP_CS, port);
3101 outb(CHIP_CS | CHIP_DO, port);
3102 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3104 outb(CHIP_CS, port);
3105 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3110 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3111 outb(CHIP_CS, port);
3112 outb(CHIP_CS | CHIP_SK, port);
3113 if (inb(port) & CHIP_DI)
3119 mxser_normal_mode(port);
3123 static int mxser_program_mode(int port)
3126 /* unsigned long flags; */
3128 spin_lock(&gm_lock);
3136 /* restore_flags(flags); */
3137 spin_unlock(&gm_lock);
3139 id = inb(port + 1) & 0x1F;
3140 if ((id != C168_ASIC_ID) &&
3141 (id != C104_ASIC_ID) &&
3142 (id != C102_ASIC_ID) &&
3143 (id != CI132_ASIC_ID) &&
3144 (id != CI134_ASIC_ID) &&
3145 (id != CI104J_ASIC_ID))
3147 for (i = 0, j = 0; i < 4; i++) {
3151 } else if ((j == 1) && (n == 1)) {
3162 static void mxser_normal_mode(int port)
3166 outb(0xA5, port + 1);
3167 outb(0x80, port + 3);
3168 outb(12, port + 0); /* 9600 bps */
3170 outb(0x03, port + 3); /* 8 data bits */
3171 outb(0x13, port + 4); /* loop back mode */
3172 for (i = 0; i < 16; i++) {
3174 if ((n & 0x61) == 0x60)
3179 outb(0x00, port + 4);
3182 module_init(mxser_module_init);
3183 module_exit(mxser_module_exit);