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));
519 release_region(mxsercfg[i].ioaddr[0], 8 * mxsercfg[i].ports);
520 release_region(mxsercfg[i].vector, 1);
525 printk(KERN_DEBUG "Done.\n");
528 static void process_txrx_fifo(struct mxser_struct *info)
532 if ((info->type == PORT_16450) || (info->type == PORT_8250)) {
533 info->rx_trigger = 1;
534 info->rx_high_water = 1;
535 info->rx_low_water = 1;
536 info->xmit_fifo_size = 1;
538 for (i = 0; i < UART_INFO_NUM; i++) {
539 if (info->IsMoxaMustChipFlag == Gpci_uart_info[i].type) {
540 info->rx_trigger = Gpci_uart_info[i].rx_trigger;
541 info->rx_low_water = Gpci_uart_info[i].rx_low_water;
542 info->rx_high_water = Gpci_uart_info[i].rx_high_water;
543 info->xmit_fifo_size = Gpci_uart_info[i].xmit_fifo_size;
550 static int mxser_initbrd(int board, struct mxser_hwconf *hwconf)
552 struct mxser_struct *info;
556 n = board * MXSER_PORTS_PER_BOARD;
557 info = &mxvar_table[n];
559 printk(KERN_DEBUG " ttyM%d - ttyM%d ",
560 n, n + hwconf->ports - 1);
561 printk(" max. baud rate = %d bps.\n",
562 hwconf->MaxCanSetBaudRate[0]);
565 for (i = 0; i < hwconf->ports; i++, n++, info++) {
567 info->base = hwconf->ioaddr[i];
568 info->irq = hwconf->irq;
569 info->vector = hwconf->vector;
570 info->vectormask = hwconf->vector_mask;
571 info->opmode_ioaddr = hwconf->opmode_ioaddr[i]; /* add by Victor Yu. 01-05-2004 */
573 info->ldisc_stop_rx = 0;
575 info->IsMoxaMustChipFlag = hwconf->IsMoxaMustChipFlag;
576 /* Enhance mode enabled here */
577 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
578 ENABLE_MOXA_MUST_ENCHANCE_MODE(info->base);
581 info->flags = ASYNC_SHARE_IRQ;
582 info->type = hwconf->uart_type;
583 info->baud_base = hwconf->baud_base[i];
585 info->MaxCanSetBaudRate = hwconf->MaxCanSetBaudRate[i];
587 process_txrx_fifo(info);
590 info->custom_divisor = hwconf->baud_base[i] * 16;
591 info->close_delay = 5 * HZ / 10;
592 info->closing_wait = 30 * HZ;
593 INIT_WORK(&info->tqueue, mxser_do_softint, info);
594 info->normal_termios = mxvar_sdriver->init_termios;
595 init_waitqueue_head(&info->open_wait);
596 init_waitqueue_head(&info->close_wait);
597 init_waitqueue_head(&info->delta_msr_wait);
598 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
599 info->err_shadow = 0;
600 spin_lock_init(&info->slock);
603 * Allocate the IRQ if necessary
607 /* before set INT ISR, disable all int */
608 for (i = 0; i < hwconf->ports; i++) {
609 outb(inb(hwconf->ioaddr[i] + UART_IER) & 0xf0,
610 hwconf->ioaddr[i] + UART_IER);
613 n = board * MXSER_PORTS_PER_BOARD;
614 info = &mxvar_table[n];
616 retval = request_irq(hwconf->irq, mxser_interrupt, IRQ_T(info),
619 printk(KERN_ERR "Board %d: %s",
620 board, mxser_brdname[hwconf->board_type - 1]);
621 printk(" Request irq failed, IRQ (%d) may conflict with"
622 " another device.\n", info->irq);
628 static void mxser_getcfg(int board, struct mxser_hwconf *hwconf)
630 mxsercfg[board] = *hwconf;
634 static int mxser_get_PCI_conf(int busnum, int devnum, int board_type, struct mxser_hwconf *hwconf)
637 /* unsigned int val; */
638 unsigned int ioaddress;
639 struct pci_dev *pdev = hwconf->pciInfo.pdev;
642 hwconf->board_type = board_type;
643 hwconf->ports = mxser_numports[board_type - 1];
644 ioaddress = pci_resource_start(pdev, 2);
645 request_region(pci_resource_start(pdev, 2), pci_resource_len(pdev, 2),
648 for (i = 0; i < hwconf->ports; i++)
649 hwconf->ioaddr[i] = ioaddress + 8 * i;
652 ioaddress = pci_resource_start(pdev, 3);
653 request_region(pci_resource_start(pdev, 3), pci_resource_len(pdev, 3),
655 hwconf->vector = ioaddress;
658 hwconf->irq = hwconf->pciInfo.pdev->irq;
660 hwconf->IsMoxaMustChipFlag = CheckIsMoxaMust(hwconf->ioaddr[0]);
661 hwconf->uart_type = PORT_16550A;
662 hwconf->vector_mask = 0;
665 for (i = 0; i < hwconf->ports; i++) {
666 for (j = 0; j < UART_INFO_NUM; j++) {
667 if (Gpci_uart_info[j].type == hwconf->IsMoxaMustChipFlag) {
668 hwconf->MaxCanSetBaudRate[i] = Gpci_uart_info[j].max_baud;
670 /* exception....CP-102 */
671 if (board_type == MXSER_BOARD_CP102)
672 hwconf->MaxCanSetBaudRate[i] = 921600;
678 if (hwconf->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID) {
679 for (i = 0; i < hwconf->ports; i++) {
681 hwconf->opmode_ioaddr[i] = ioaddress + 4;
683 hwconf->opmode_ioaddr[i] = ioaddress + 0x0c;
685 outb(0, ioaddress + 4); /* default set to RS232 mode */
686 outb(0, ioaddress + 0x0c); /* default set to RS232 mode */
689 for (i = 0; i < hwconf->ports; i++) {
690 hwconf->vector_mask |= (1 << i);
691 hwconf->baud_base[i] = 921600;
697 static int mxser_init(void)
699 int i, m, retval, b, n;
700 struct pci_dev *pdev = NULL;
702 unsigned char busnum, devnum;
703 struct mxser_hwconf hwconf;
705 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
708 spin_lock_init(&gm_lock);
710 for (i = 0; i < MXSER_BOARDS; i++) {
711 mxsercfg[i].board_type = -1;
714 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
717 /* Initialize the tty_driver structure */
718 memset(mxvar_sdriver, 0, sizeof(struct tty_driver));
719 mxvar_sdriver->magic = TTY_DRIVER_MAGIC;
720 mxvar_sdriver->name = "ttyM";
721 mxvar_sdriver->major = ttymajor;
722 mxvar_sdriver->minor_start = 0;
723 mxvar_sdriver->num = MXSER_PORTS + 1;
724 mxvar_sdriver->type = TTY_DRIVER_TYPE_SERIAL;
725 mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL;
726 mxvar_sdriver->init_termios = tty_std_termios;
727 mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
728 mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW;
729 tty_set_operations(mxvar_sdriver, &mxser_ops);
730 mxvar_sdriver->ttys = mxvar_tty;
731 mxvar_sdriver->termios = mxvar_termios;
732 mxvar_sdriver->termios_locked = mxvar_termios_locked;
735 memset(mxvar_table, 0, MXSER_PORTS * sizeof(struct mxser_struct));
736 memset(&mxvar_log, 0, sizeof(struct mxser_log));
738 memset(&mxser_msr, 0, sizeof(unsigned char) * (MXSER_PORTS + 1));
739 memset(&mon_data_ext, 0, sizeof(struct mxser_mon_ext));
740 memset(&mxser_set_baud_method, 0, sizeof(int) * (MXSER_PORTS + 1));
741 memset(&hwconf, 0, sizeof(struct mxser_hwconf));
744 /* Start finding ISA boards here */
745 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
748 if (!(cap = mxserBoardCAP[b]))
751 retval = mxser_get_ISA_conf(cap, &hwconf);
754 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
755 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
758 if (retval == MXSER_ERR_IRQ)
759 printk(KERN_ERR "Invalid interrupt number, "
760 "board not configured\n");
761 else if (retval == MXSER_ERR_IRQ_CONFLIT)
762 printk(KERN_ERR "Invalid interrupt number, "
763 "board not configured\n");
764 else if (retval == MXSER_ERR_VECTOR)
765 printk(KERN_ERR "Invalid interrupt vector, "
766 "board not configured\n");
767 else if (retval == MXSER_ERR_IOADDR)
768 printk(KERN_ERR "Invalid I/O address, "
769 "board not configured\n");
774 hwconf.pciInfo.busNum = 0;
775 hwconf.pciInfo.devNum = 0;
776 hwconf.pciInfo.pdev = NULL;
778 mxser_getcfg(m, &hwconf);
780 * init mxsercfg first,
781 * or mxsercfg data is not correct on ISR.
783 /* mxser_initbrd will hook ISR. */
784 if (mxser_initbrd(m, &hwconf) < 0)
790 /* Start finding ISA boards from module arg */
791 for (b = 0; b < MXSER_BOARDS && m < MXSER_BOARDS; b++) {
794 if (!(cap = ioaddr[b]))
797 retval = mxser_get_ISA_conf(cap, &hwconf);
800 printk(KERN_INFO "Found MOXA %s board (CAP=0x%x)\n",
801 mxser_brdname[hwconf.board_type - 1], ioaddr[b]);
804 if (retval == MXSER_ERR_IRQ)
805 printk(KERN_ERR "Invalid interrupt number, "
806 "board not configured\n");
807 else if (retval == MXSER_ERR_IRQ_CONFLIT)
808 printk(KERN_ERR "Invalid interrupt number, "
809 "board not configured\n");
810 else if (retval == MXSER_ERR_VECTOR)
811 printk(KERN_ERR "Invalid interrupt vector, "
812 "board not configured\n");
813 else if (retval == MXSER_ERR_IOADDR)
814 printk(KERN_ERR "Invalid I/O address, "
815 "board not configured\n");
820 hwconf.pciInfo.busNum = 0;
821 hwconf.pciInfo.devNum = 0;
822 hwconf.pciInfo.pdev = NULL;
824 mxser_getcfg(m, &hwconf);
826 * init mxsercfg first,
827 * or mxsercfg data is not correct on ISR.
829 /* mxser_initbrd will hook ISR. */
830 if (mxser_initbrd(m, &hwconf) < 0)
836 /* start finding PCI board here */
838 n = ARRAY_SIZE(mxser_pcibrds) - 1;
842 pdev = pci_find_device(mxser_pcibrds[b].vendor,
843 mxser_pcibrds[b].device, pdev);
848 hwconf.pciInfo.busNum = busnum = pdev->bus->number;
849 hwconf.pciInfo.devNum = devnum = PCI_SLOT(pdev->devfn) << 3;
850 hwconf.pciInfo.pdev = pdev;
851 printk(KERN_INFO "Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
852 mxser_brdname[(int) (mxser_pcibrds[b].driver_data) - 1],
853 busnum, devnum >> 3);
855 if (m >= MXSER_BOARDS)
857 "Too many Smartio/Industio family boards find "
858 "(maximum %d), board not configured\n",
861 if (pci_enable_device(pdev)) {
862 printk(KERN_ERR "Moxa SmartI/O PCI enable "
866 retval = mxser_get_PCI_conf(busnum, devnum,
867 (int)mxser_pcibrds[b].driver_data,
870 if (retval == MXSER_ERR_IRQ)
872 "Invalid interrupt number, "
873 "board not configured\n");
874 else if (retval == MXSER_ERR_IRQ_CONFLIT)
876 "Invalid interrupt number, "
877 "board not configured\n");
878 else if (retval == MXSER_ERR_VECTOR)
880 "Invalid interrupt vector, "
881 "board not configured\n");
882 else if (retval == MXSER_ERR_IOADDR)
884 "Invalid I/O address, "
885 "board not configured\n");
888 mxser_getcfg(m, &hwconf);
889 /* init mxsercfg first,
890 * or mxsercfg data is not correct on ISR.
892 /* mxser_initbrd will hook ISR. */
893 if (mxser_initbrd(m, &hwconf) < 0)
900 retval = tty_register_driver(mxvar_sdriver);
902 printk(KERN_ERR "Couldn't install MOXA Smartio/Industio family"
904 put_tty_driver(mxvar_sdriver);
906 for (i = 0; i < MXSER_BOARDS; i++) {
907 if (mxsercfg[i].board_type == -1)
910 free_irq(mxsercfg[i].irq, &mxvar_table[i * MXSER_PORTS_PER_BOARD]);
911 /* todo: release io, vector */
920 static void mxser_do_softint(void *private_)
922 struct mxser_struct *info = private_;
923 struct tty_struct *tty;
928 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
930 if (test_and_clear_bit(MXSER_EVENT_HANGUP, &info->event))
935 static unsigned char mxser_get_msr(int baseaddr, int mode, int port, struct mxser_struct *info)
937 unsigned char status = 0;
939 status = inb(baseaddr + UART_MSR);
941 mxser_msr[port] &= 0x0F;
942 mxser_msr[port] |= status;
943 status = mxser_msr[port];
951 * This routine is called whenever a serial port is opened. It
952 * enables interrupts for a serial port, linking in its async structure into
953 * the IRQ chain. It also performs the serial-specific
954 * initialization for the tty structure.
956 static int mxser_open(struct tty_struct *tty, struct file *filp)
958 struct mxser_struct *info;
961 /* initialize driver_data in case something fails */
962 tty->driver_data = NULL;
965 if (line == MXSER_PORTS)
967 if (line < 0 || line > MXSER_PORTS)
969 info = mxvar_table + line;
973 tty->driver_data = info;
976 * Start up serial port
978 retval = mxser_startup(info);
982 retval = mxser_block_til_ready(tty, filp, info);
988 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
989 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
990 *tty->termios = info->normal_termios;
992 *tty->termios = info->callout_termios;
993 mxser_change_speed(info, NULL);
996 info->session = current->signal->session;
997 info->pgrp = process_group(current);
1000 status = mxser_get_msr(info->base, 0, info->port);
1001 mxser_check_modem_status(info, status);
1004 /* unmark here for very high baud rate (ex. 921600 bps) used */
1005 tty->low_latency = 1;
1010 * This routine is called when the serial port gets closed. First, we
1011 * wait for the last remaining data to be sent. Then, we unlink its
1012 * async structure from the interrupt chain if necessary, and we free
1013 * that IRQ if nothing is left in the chain.
1015 static void mxser_close(struct tty_struct *tty, struct file *filp)
1017 struct mxser_struct *info = tty->driver_data;
1019 unsigned long timeout;
1020 unsigned long flags;
1021 struct tty_ldisc *ld;
1023 if (tty->index == MXSER_PORTS)
1028 spin_lock_irqsave(&info->slock, flags);
1030 if (tty_hung_up_p(filp)) {
1031 spin_unlock_irqrestore(&info->slock, flags);
1034 if ((tty->count == 1) && (info->count != 1)) {
1036 * Uh, oh. tty->count is 1, which means that the tty
1037 * structure will be freed. Info->count should always
1038 * be one in these conditions. If it's greater than
1039 * one, we've got real problems, since it means the
1040 * serial port won't be shutdown.
1042 printk(KERN_ERR "mxser_close: bad serial port count; "
1043 "tty->count is 1, info->count is %d\n", info->count);
1046 if (--info->count < 0) {
1047 printk(KERN_ERR "mxser_close: bad serial port count for "
1048 "ttys%d: %d\n", info->port, info->count);
1052 spin_unlock_irqrestore(&info->slock, flags);
1055 info->flags |= ASYNC_CLOSING;
1056 spin_unlock_irqrestore(&info->slock, flags);
1058 * Save the termios structure, since this port may have
1059 * separate termios for callout and dialin.
1061 if (info->flags & ASYNC_NORMAL_ACTIVE)
1062 info->normal_termios = *tty->termios;
1064 * Now we wait for the transmit buffer to clear; and we notify
1065 * the line discipline to only process XON/XOFF characters.
1068 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1069 tty_wait_until_sent(tty, info->closing_wait);
1071 * At this point we stop accepting input. To do this, we
1072 * disable the receive line status interrupts, and tell the
1073 * interrupt driver to stop checking the data ready bit in the
1074 * line status register.
1076 info->IER &= ~UART_IER_RLSI;
1077 if (info->IsMoxaMustChipFlag)
1078 info->IER &= ~MOXA_MUST_RECV_ISR;
1080 info->read_status_mask &= ~UART_LSR_DR;
1082 if (info->flags & ASYNC_INITIALIZED) {
1083 outb(info->IER, info->base + UART_IER);
1085 * Before we drop DTR, make sure the UART transmitter
1086 * has completely drained; this is especially
1087 * important if there is a transmit FIFO!
1089 timeout = jiffies + HZ;
1090 while (!(inb(info->base + UART_LSR) & UART_LSR_TEMT)) {
1091 schedule_timeout_interruptible(5);
1092 if (time_after(jiffies, timeout))
1096 mxser_shutdown(info);
1098 if (tty->driver->flush_buffer)
1099 tty->driver->flush_buffer(tty);
1101 ld = tty_ldisc_ref(tty);
1103 if (ld->flush_buffer)
1104 ld->flush_buffer(tty);
1105 tty_ldisc_deref(ld);
1111 if (info->blocked_open) {
1112 if (info->close_delay)
1113 schedule_timeout_interruptible(info->close_delay);
1114 wake_up_interruptible(&info->open_wait);
1117 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1118 wake_up_interruptible(&info->close_wait);
1122 static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
1125 struct mxser_struct *info = tty->driver_data;
1126 unsigned long flags;
1128 if (!info->xmit_buf)
1132 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1133 SERIAL_XMIT_SIZE - info->xmit_head));
1137 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1138 spin_lock_irqsave(&info->slock, flags);
1139 info->xmit_head = (info->xmit_head + c) &
1140 (SERIAL_XMIT_SIZE - 1);
1141 info->xmit_cnt += c;
1142 spin_unlock_irqrestore(&info->slock, flags);
1149 if (info->xmit_cnt && !tty->stopped && !(info->IER & UART_IER_THRI)) {
1150 if (!tty->hw_stopped ||
1151 (info->type == PORT_16550A) ||
1152 (info->IsMoxaMustChipFlag)) {
1153 spin_lock_irqsave(&info->slock, flags);
1154 info->IER |= UART_IER_THRI;
1155 outb(info->IER, info->base + UART_IER);
1156 spin_unlock_irqrestore(&info->slock, flags);
1162 static void mxser_put_char(struct tty_struct *tty, unsigned char ch)
1164 struct mxser_struct *info = tty->driver_data;
1165 unsigned long flags;
1167 if (!info->xmit_buf)
1170 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
1173 spin_lock_irqsave(&info->slock, flags);
1174 info->xmit_buf[info->xmit_head++] = ch;
1175 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
1177 spin_unlock_irqrestore(&info->slock, flags);
1178 if (!tty->stopped && !(info->IER & UART_IER_THRI)) {
1179 if (!tty->hw_stopped ||
1180 (info->type == PORT_16550A) ||
1181 info->IsMoxaMustChipFlag) {
1182 spin_lock_irqsave(&info->slock, flags);
1183 info->IER |= UART_IER_THRI;
1184 outb(info->IER, info->base + UART_IER);
1185 spin_unlock_irqrestore(&info->slock, flags);
1191 static void mxser_flush_chars(struct tty_struct *tty)
1193 struct mxser_struct *info = tty->driver_data;
1194 unsigned long flags;
1196 if (info->xmit_cnt <= 0 ||
1200 (info->type != PORT_16550A) &&
1201 (!info->IsMoxaMustChipFlag)
1205 spin_lock_irqsave(&info->slock, flags);
1207 info->IER |= UART_IER_THRI;
1208 outb(info->IER, info->base + UART_IER);
1210 spin_unlock_irqrestore(&info->slock, flags);
1213 static int mxser_write_room(struct tty_struct *tty)
1215 struct mxser_struct *info = tty->driver_data;
1218 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1224 static int mxser_chars_in_buffer(struct tty_struct *tty)
1226 struct mxser_struct *info = tty->driver_data;
1227 return info->xmit_cnt;
1230 static void mxser_flush_buffer(struct tty_struct *tty)
1232 struct mxser_struct *info = tty->driver_data;
1234 unsigned long flags;
1237 spin_lock_irqsave(&info->slock, flags);
1238 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1240 /* below added by shinhay */
1241 fcr = inb(info->base + UART_FCR);
1242 outb((fcr | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
1243 info->base + UART_FCR);
1244 outb(fcr, info->base + UART_FCR);
1246 spin_unlock_irqrestore(&info->slock, flags);
1247 /* above added by shinhay */
1249 wake_up_interruptible(&tty->write_wait);
1250 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1251 (tty->ldisc.write_wakeup) (tty);
1254 static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1256 struct mxser_struct *info = tty->driver_data;
1258 struct async_icount cprev, cnow; /* kernel counter temps */
1259 struct serial_icounter_struct __user *p_cuser;
1260 unsigned long templ;
1261 unsigned long flags;
1262 void __user *argp = (void __user *)arg;
1264 if (tty->index == MXSER_PORTS)
1265 return mxser_ioctl_special(cmd, argp);
1267 /* following add by Victor Yu. 01-05-2004 */
1268 if (cmd == MOXA_SET_OP_MODE || cmd == MOXA_GET_OP_MODE) {
1270 static unsigned char ModeMask[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1272 unsigned char val, mask;
1275 if (cmd == MOXA_SET_OP_MODE) {
1276 if (get_user(opmode, (int __user *) argp))
1278 if (opmode != RS232_MODE &&
1279 opmode != RS485_2WIRE_MODE &&
1280 opmode != RS422_MODE &&
1281 opmode != RS485_4WIRE_MODE)
1285 val = inb(info->opmode_ioaddr);
1287 val |= (opmode << shiftbit);
1288 outb(val, info->opmode_ioaddr);
1291 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1292 opmode &= OP_MODE_MASK;
1293 if (copy_to_user(argp, &opmode, sizeof(int)))
1298 /* above add by Victor Yu. 01-05-2004 */
1300 if ((cmd != TIOCGSERIAL) && (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1301 if (tty->flags & (1 << TTY_IO_ERROR))
1305 case TCSBRK: /* SVID version: non-zero arg --> no break */
1306 retval = tty_check_change(tty);
1309 tty_wait_until_sent(tty, 0);
1311 mxser_send_break(info, HZ / 4); /* 1/4 second */
1313 case TCSBRKP: /* support for POSIX tcsendbreak() */
1314 retval = tty_check_change(tty);
1317 tty_wait_until_sent(tty, 0);
1318 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1321 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
1323 if (get_user(templ, (unsigned long __user *) argp))
1326 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1329 return mxser_get_serial_info(info, argp);
1331 return mxser_set_serial_info(info, argp);
1332 case TIOCSERGETLSR: /* Get line status register */
1333 return mxser_get_lsr_info(info, argp);
1335 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1336 * - mask passed in arg for lines of interest
1337 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1338 * Caller should use TIOCGICOUNT to see which one it was
1341 DECLARE_WAITQUEUE(wait, current);
1343 spin_lock_irqsave(&info->slock, flags);
1344 cprev = info->icount; /* note the counters on entry */
1345 spin_unlock_irqrestore(&info->slock, flags);
1347 add_wait_queue(&info->delta_msr_wait, &wait);
1349 spin_lock_irqsave(&info->slock, flags);
1350 cnow = info->icount; /* atomic copy */
1351 spin_unlock_irqrestore(&info->slock, flags);
1353 set_current_state(TASK_INTERRUPTIBLE);
1354 if (((arg & TIOCM_RNG) &&
1355 (cnow.rng != cprev.rng)) ||
1356 ((arg & TIOCM_DSR) &&
1357 (cnow.dsr != cprev.dsr)) ||
1358 ((arg & TIOCM_CD) &&
1359 (cnow.dcd != cprev.dcd)) ||
1360 ((arg & TIOCM_CTS) &&
1361 (cnow.cts != cprev.cts))) {
1365 /* see if a signal did it */
1366 if (signal_pending(current)) {
1372 current->state = TASK_RUNNING;
1373 remove_wait_queue(&info->delta_msr_wait, &wait);
1378 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1379 * Return: write counters to the user passed counter struct
1380 * NB: both 1->0 and 0->1 transitions are counted except for
1381 * RI where only 0->1 is counted.
1384 spin_lock_irqsave(&info->slock, flags);
1385 cnow = info->icount;
1386 spin_unlock_irqrestore(&info->slock, flags);
1388 /* modified by casper 1/11/2000 */
1389 if (put_user(cnow.frame, &p_cuser->frame))
1391 if (put_user(cnow.brk, &p_cuser->brk))
1393 if (put_user(cnow.overrun, &p_cuser->overrun))
1395 if (put_user(cnow.buf_overrun, &p_cuser->buf_overrun))
1397 if (put_user(cnow.parity, &p_cuser->parity))
1399 if (put_user(cnow.rx, &p_cuser->rx))
1401 if (put_user(cnow.tx, &p_cuser->tx))
1403 put_user(cnow.cts, &p_cuser->cts);
1404 put_user(cnow.dsr, &p_cuser->dsr);
1405 put_user(cnow.rng, &p_cuser->rng);
1406 put_user(cnow.dcd, &p_cuser->dcd);
1408 case MOXA_HighSpeedOn:
1409 return put_user(info->baud_base != 115200 ? 1 : 0, (int __user *)argp);
1410 case MOXA_SDS_RSTICOUNTER: {
1411 info->mon_data.rxcnt = 0;
1412 info->mon_data.txcnt = 0;
1415 /* (above) added by James. */
1416 case MOXA_ASPP_SETBAUD:{
1418 if (get_user(baud, (long __user *)argp))
1420 mxser_set_baud(info, baud);
1423 case MOXA_ASPP_GETBAUD:
1424 if (copy_to_user(argp, &info->realbaud, sizeof(long)))
1429 case MOXA_ASPP_OQUEUE:{
1432 len = mxser_chars_in_buffer(tty);
1434 lsr = inb(info->base + UART_LSR) & UART_LSR_TEMT;
1436 len += (lsr ? 0 : 1);
1438 if (copy_to_user(argp, &len, sizeof(int)))
1443 case MOXA_ASPP_MON: {
1446 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1448 status = mxser_get_msr(info->base, 1, info->port, info);
1449 mxser_check_modem_status(info, status);
1451 mcr = inb(info->base + UART_MCR);
1452 if (mcr & MOXA_MUST_MCR_XON_FLAG)
1453 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFHOLD;
1455 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFHOLD;
1457 if (mcr & MOXA_MUST_MCR_TX_XON)
1458 info->mon_data.hold_reason &= ~NPPI_NOTIFY_XOFFXENT;
1460 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1462 if (info->tty->hw_stopped)
1463 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1465 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
1467 if (copy_to_user(argp, &info->mon_data,
1468 sizeof(struct mxser_mon)))
1474 case MOXA_ASPP_LSTATUS: {
1475 if (copy_to_user(argp, &info->err_shadow,
1476 sizeof(unsigned char)))
1479 info->err_shadow = 0;
1482 case MOXA_SET_BAUD_METHOD: {
1485 if (get_user(method, (int __user *)argp))
1487 mxser_set_baud_method[info->port] = method;
1488 if (copy_to_user(argp, &method, sizeof(int)))
1494 return -ENOIOCTLCMD;
1500 #define CMSPAR 010000000000
1503 static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1505 int i, result, status;
1509 if (copy_to_user(argp, mxsercfg,
1510 sizeof(struct mxser_hwconf) * 4))
1513 case MOXA_GET_MAJOR:
1514 if (copy_to_user(argp, &ttymajor, sizeof(int)))
1518 case MOXA_GET_CUMAJOR:
1519 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1523 case MOXA_CHKPORTENABLE:
1525 for (i = 0; i < MXSER_PORTS; i++) {
1526 if (mxvar_table[i].base)
1529 return put_user(result, (unsigned long __user *)argp);
1530 case MOXA_GETDATACOUNT:
1531 if (copy_to_user(argp, &mxvar_log, sizeof(mxvar_log)))
1534 case MOXA_GETMSTATUS:
1535 for (i = 0; i < MXSER_PORTS; i++) {
1537 if (!mxvar_table[i].base) {
1538 GMStatus[i].dcd = 0;
1539 GMStatus[i].dsr = 0;
1540 GMStatus[i].cts = 0;
1544 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios)
1545 GMStatus[i].cflag = mxvar_table[i].normal_termios.c_cflag;
1547 GMStatus[i].cflag = mxvar_table[i].tty->termios->c_cflag;
1549 status = inb(mxvar_table[i].base + UART_MSR);
1550 if (status & 0x80 /*UART_MSR_DCD */ )
1551 GMStatus[i].dcd = 1;
1553 GMStatus[i].dcd = 0;
1555 if (status & 0x20 /*UART_MSR_DSR */ )
1556 GMStatus[i].dsr = 1;
1558 GMStatus[i].dsr = 0;
1561 if (status & 0x10 /*UART_MSR_CTS */ )
1562 GMStatus[i].cts = 1;
1564 GMStatus[i].cts = 0;
1566 if (copy_to_user(argp, GMStatus,
1567 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1570 case MOXA_ASPP_MON_EXT: {
1574 unsigned cflag, iflag;
1576 for (i = 0; i < MXSER_PORTS; i++) {
1577 if (!mxvar_table[i].base)
1580 status = mxser_get_msr(mxvar_table[i].base, 0,
1581 i, &(mxvar_table[i]));
1583 mxser_check_modem_status(&mxvar_table[i],
1586 if (status & UART_MSR_TERI)
1587 mxvar_table[i].icount.rng++;
1588 if (status & UART_MSR_DDSR)
1589 mxvar_table[i].icount.dsr++;
1590 if (status & UART_MSR_DDCD)
1591 mxvar_table[i].icount.dcd++;
1592 if (status & UART_MSR_DCTS)
1593 mxvar_table[i].icount.cts++;
1595 mxvar_table[i].mon_data.modem_status = status;
1596 mon_data_ext.rx_cnt[i] = mxvar_table[i].mon_data.rxcnt;
1597 mon_data_ext.tx_cnt[i] = mxvar_table[i].mon_data.txcnt;
1598 mon_data_ext.up_rxcnt[i] = mxvar_table[i].mon_data.up_rxcnt;
1599 mon_data_ext.up_txcnt[i] = mxvar_table[i].mon_data.up_txcnt;
1600 mon_data_ext.modem_status[i] = mxvar_table[i].mon_data.modem_status;
1601 mon_data_ext.baudrate[i] = mxvar_table[i].realbaud;
1603 if (!mxvar_table[i].tty || !mxvar_table[i].tty->termios) {
1604 cflag = mxvar_table[i].normal_termios.c_cflag;
1605 iflag = mxvar_table[i].normal_termios.c_iflag;
1607 cflag = mxvar_table[i].tty->termios->c_cflag;
1608 iflag = mxvar_table[i].tty->termios->c_iflag;
1611 mon_data_ext.databits[i] = cflag & CSIZE;
1613 mon_data_ext.stopbits[i] = cflag & CSTOPB;
1615 mon_data_ext.parity[i] = cflag & (PARENB | PARODD | CMSPAR);
1617 mon_data_ext.flowctrl[i] = 0x00;
1619 if (cflag & CRTSCTS)
1620 mon_data_ext.flowctrl[i] |= 0x03;
1622 if (iflag & (IXON | IXOFF))
1623 mon_data_ext.flowctrl[i] |= 0x0C;
1625 if (mxvar_table[i].type == PORT_16550A)
1626 mon_data_ext.fifo[i] = 1;
1628 mon_data_ext.fifo[i] = 0;
1632 opmode = inb(mxvar_table[i].opmode_ioaddr) >> shiftbit;
1633 opmode &= OP_MODE_MASK;
1635 mon_data_ext.iftype[i] = opmode;
1638 if (copy_to_user(argp, &mon_data_ext, sizeof(struct mxser_mon_ext)))
1645 return -ENOIOCTLCMD;
1650 static void mxser_stoprx(struct tty_struct *tty)
1652 struct mxser_struct *info = tty->driver_data;
1653 /* unsigned long flags; */
1655 info->ldisc_stop_rx = 1;
1657 /* MX_LOCK(&info->slock); */
1658 /* following add by Victor Yu. 09-02-2002 */
1659 if (info->IsMoxaMustChipFlag) {
1660 info->IER &= ~MOXA_MUST_RECV_ISR;
1661 outb(info->IER, info->base + UART_IER);
1663 /* above add by Victor Yu. 09-02-2002 */
1664 info->x_char = STOP_CHAR(tty);
1665 /* mask by Victor Yu. 09-02-2002 */
1666 /* outb(info->IER, 0); */
1667 outb(0, info->base + UART_IER);
1668 info->IER |= UART_IER_THRI;
1669 /* force Tx interrupt */
1670 outb(info->IER, info->base + UART_IER);
1671 } /* add by Victor Yu. 09-02-2002 */
1672 /* MX_UNLOCK(&info->slock); */
1675 if (info->tty->termios->c_cflag & CRTSCTS) {
1676 /* MX_LOCK(&info->slock); */
1677 info->MCR &= ~UART_MCR_RTS;
1678 outb(info->MCR, info->base + UART_MCR);
1679 /* MX_UNLOCK(&info->slock); */
1683 static void mxser_startrx(struct tty_struct *tty)
1685 struct mxser_struct *info = tty->driver_data;
1686 /* unsigned long flags; */
1688 info->ldisc_stop_rx = 0;
1693 /* MX_LOCK(&info->slock); */
1695 /* following add by Victor Yu. 09-02-2002 */
1696 if (info->IsMoxaMustChipFlag) {
1697 info->IER |= MOXA_MUST_RECV_ISR;
1698 outb(info->IER, info->base + UART_IER);
1700 /* above add by Victor Yu. 09-02-2002 */
1702 info->x_char = START_CHAR(tty);
1703 /* mask by Victor Yu. 09-02-2002 */
1704 /* outb(info->IER, 0); */
1705 /* add by Victor Yu. 09-02-2002 */
1706 outb(0, info->base + UART_IER);
1707 /* force Tx interrupt */
1708 info->IER |= UART_IER_THRI;
1709 outb(info->IER, info->base + UART_IER);
1710 } /* add by Victor Yu. 09-02-2002 */
1711 /* MX_UNLOCK(&info->slock); */
1715 if (info->tty->termios->c_cflag & CRTSCTS) {
1716 /* MX_LOCK(&info->slock); */
1717 info->MCR |= UART_MCR_RTS;
1718 outb(info->MCR, info->base + UART_MCR);
1719 /* MX_UNLOCK(&info->slock); */
1724 * This routine is called by the upper-layer tty layer to signal that
1725 * incoming characters should be throttled.
1727 static void mxser_throttle(struct tty_struct *tty)
1729 /* struct mxser_struct *info = tty->driver_data; */
1730 /* unsigned long flags; */
1732 /* MX_LOCK(&info->slock); */
1734 /* MX_UNLOCK(&info->slock); */
1737 static void mxser_unthrottle(struct tty_struct *tty)
1739 /* struct mxser_struct *info = tty->driver_data; */
1740 /* unsigned long flags; */
1742 /* MX_LOCK(&info->slock); */
1744 /* MX_UNLOCK(&info->slock); */
1747 static void mxser_set_termios(struct tty_struct *tty, struct termios *old_termios)
1749 struct mxser_struct *info = tty->driver_data;
1750 unsigned long flags;
1752 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1753 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1755 mxser_change_speed(info, old_termios);
1757 if ((old_termios->c_cflag & CRTSCTS) &&
1758 !(tty->termios->c_cflag & CRTSCTS)) {
1759 tty->hw_stopped = 0;
1764 /* Handle sw stopped */
1765 if ((old_termios->c_iflag & IXON) &&
1766 !(tty->termios->c_iflag & IXON)) {
1769 /* following add by Victor Yu. 09-02-2002 */
1770 if (info->IsMoxaMustChipFlag) {
1771 spin_lock_irqsave(&info->slock, flags);
1772 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
1773 spin_unlock_irqrestore(&info->slock, flags);
1775 /* above add by Victor Yu. 09-02-2002 */
1782 * mxser_stop() and mxser_start()
1784 * This routines are called before setting or resetting tty->stopped.
1785 * They enable or disable transmitter interrupts, as necessary.
1787 static void mxser_stop(struct tty_struct *tty)
1789 struct mxser_struct *info = tty->driver_data;
1790 unsigned long flags;
1792 spin_lock_irqsave(&info->slock, flags);
1793 if (info->IER & UART_IER_THRI) {
1794 info->IER &= ~UART_IER_THRI;
1795 outb(info->IER, info->base + UART_IER);
1797 spin_unlock_irqrestore(&info->slock, flags);
1800 static void mxser_start(struct tty_struct *tty)
1802 struct mxser_struct *info = tty->driver_data;
1803 unsigned long flags;
1805 spin_lock_irqsave(&info->slock, flags);
1806 if (info->xmit_cnt && info->xmit_buf && !(info->IER & UART_IER_THRI)) {
1807 info->IER |= UART_IER_THRI;
1808 outb(info->IER, info->base + UART_IER);
1810 spin_unlock_irqrestore(&info->slock, flags);
1814 * mxser_wait_until_sent() --- wait until the transmitter is empty
1816 static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
1818 struct mxser_struct *info = tty->driver_data;
1819 unsigned long orig_jiffies, char_time;
1822 if (info->type == PORT_UNKNOWN)
1825 if (info->xmit_fifo_size == 0)
1826 return; /* Just in case.... */
1828 orig_jiffies = jiffies;
1830 * Set the check interval to be 1/5 of the estimated time to
1831 * send a single character, and make it at least 1. The check
1832 * interval should also be less than the timeout.
1834 * Note: we have to use pretty tight timings here to satisfy
1837 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
1838 char_time = char_time / 5;
1841 if (timeout && timeout < char_time)
1842 char_time = timeout;
1844 * If the transmitter hasn't cleared in twice the approximate
1845 * amount of time to send the entire FIFO, it probably won't
1846 * ever clear. This assumes the UART isn't doing flow
1847 * control, which is currently the case. Hence, if it ever
1848 * takes longer than info->timeout, this is probably due to a
1849 * UART bug of some kind. So, we clamp the timeout parameter at
1852 if (!timeout || timeout > 2 * info->timeout)
1853 timeout = 2 * info->timeout;
1854 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1855 printk(KERN_DEBUG "In rs_wait_until_sent(%d) check=%lu...",
1856 timeout, char_time);
1857 printk("jiff=%lu...", jiffies);
1859 while (!((lsr = inb(info->base + UART_LSR)) & UART_LSR_TEMT)) {
1860 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1861 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
1863 schedule_timeout_interruptible(char_time);
1864 if (signal_pending(current))
1866 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1869 set_current_state(TASK_RUNNING);
1871 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1872 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1878 * This routine is called by tty_hangup() when a hangup is signaled.
1880 void mxser_hangup(struct tty_struct *tty)
1882 struct mxser_struct *info = tty->driver_data;
1884 mxser_flush_buffer(tty);
1885 mxser_shutdown(info);
1888 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1890 wake_up_interruptible(&info->open_wait);
1894 /* added by James 03-12-2004. */
1896 * mxser_rs_break() --- routine which turns the break handling on or off
1898 static void mxser_rs_break(struct tty_struct *tty, int break_state)
1900 struct mxser_struct *info = tty->driver_data;
1901 unsigned long flags;
1903 spin_lock_irqsave(&info->slock, flags);
1904 if (break_state == -1)
1905 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
1906 info->base + UART_LCR);
1908 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
1909 info->base + UART_LCR);
1910 spin_unlock_irqrestore(&info->slock, flags);
1913 /* (above) added by James. */
1917 * This is the serial driver's generic interrupt routine
1919 static irqreturn_t mxser_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1922 struct mxser_struct *info;
1923 struct mxser_struct *port;
1924 int max, irqbits, bits, msr;
1925 int pass_counter = 0;
1926 int handled = IRQ_NONE;
1929 /* spin_lock(&gm_lock); */
1931 for (i = 0; i < MXSER_BOARDS; i++) {
1932 if (dev_id == &(mxvar_table[i * MXSER_PORTS_PER_BOARD])) {
1938 if (i == MXSER_BOARDS)
1942 max = mxser_numports[mxsercfg[i].board_type - 1];
1944 irqbits = inb(port->vector) & port->vectormask;
1945 if (irqbits == port->vectormask)
1948 handled = IRQ_HANDLED;
1949 for (i = 0, bits = 1; i < max; i++, irqbits |= bits, bits <<= 1) {
1950 if (irqbits == port->vectormask)
1956 /* following add by Victor Yu. 09-13-2002 */
1957 iir = inb(info->base + UART_IIR);
1958 if (iir & UART_IIR_NO_INT)
1960 iir &= MOXA_MUST_IIR_MASK;
1962 status = inb(info->base + UART_LSR);
1963 outb(0x27, info->base + UART_FCR);
1964 inb(info->base + UART_MSR);
1967 /* above add by Victor Yu. 09-13-2002 */
1969 if (info->tty->flip.count < TTY_FLIPBUF_SIZE / 4) {
1970 info->IER |= MOXA_MUST_RECV_ISR;
1971 outb(info->IER, info->base + UART_IER);
1976 /* mask by Victor Yu. 09-13-2002
1978 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1981 /* mask by Victor Yu. 09-02-2002
1982 status = inb(info->base + UART_LSR) & info->read_status_mask;
1985 /* following add by Victor Yu. 09-02-2002 */
1986 status = inb(info->base + UART_LSR);
1988 if (status & UART_LSR_PE)
1989 info->err_shadow |= NPPI_NOTIFY_PARITY;
1990 if (status & UART_LSR_FE)
1991 info->err_shadow |= NPPI_NOTIFY_FRAMING;
1992 if (status & UART_LSR_OE)
1993 info->err_shadow |= NPPI_NOTIFY_HW_OVERRUN;
1994 if (status & UART_LSR_BI)
1995 info->err_shadow |= NPPI_NOTIFY_BREAK;
1997 if (info->IsMoxaMustChipFlag) {
1999 if ( (status & 0x02) && !(status & 0x01) ) {
2000 outb(info->base+UART_FCR, 0x23);
2004 if (iir == MOXA_MUST_IIR_GDA ||
2005 iir == MOXA_MUST_IIR_RDA ||
2006 iir == MOXA_MUST_IIR_RTO ||
2007 iir == MOXA_MUST_IIR_LSR)
2008 mxser_receive_chars(info, &status);
2011 /* above add by Victor Yu. 09-02-2002 */
2013 status &= info->read_status_mask;
2014 if (status & UART_LSR_DR)
2015 mxser_receive_chars(info, &status);
2017 msr = inb(info->base + UART_MSR);
2018 if (msr & UART_MSR_ANY_DELTA) {
2019 mxser_check_modem_status(info, msr);
2021 /* following add by Victor Yu. 09-13-2002 */
2022 if (info->IsMoxaMustChipFlag) {
2023 if ((iir == 0x02) && (status & UART_LSR_THRE)) {
2024 mxser_transmit_chars(info);
2027 /* above add by Victor Yu. 09-13-2002 */
2029 if (status & UART_LSR_THRE) {
2030 /* 8-2-99 by William
2031 if ( info->x_char || (info->xmit_cnt > 0) )
2033 mxser_transmit_chars(info);
2037 if (pass_counter++ > MXSER_ISR_PASS_LIMIT) {
2038 break; /* Prevent infinite loops */
2043 /* spin_unlock(&gm_lock); */
2047 static void mxser_receive_chars(struct mxser_struct *info, int *status)
2049 struct tty_struct *tty = info->tty;
2050 unsigned char ch, gdl;
2055 unsigned long flags;
2057 spin_lock_irqsave(&info->slock, flags);
2059 recv_room = tty->receive_room;
2060 if ((recv_room == 0) && (!info->ldisc_stop_rx)) {
2061 /* mxser_throttle(tty); */
2066 /* following add by Victor Yu. 09-02-2002 */
2067 if (info->IsMoxaMustChipFlag != MOXA_OTHER_UART) {
2069 if (*status & UART_LSR_SPECIAL) {
2072 /* following add by Victor Yu. 02-11-2004 */
2073 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU860_HWID &&
2074 (*status & MOXA_MUST_LSR_RERR))
2076 /* above add by Victor Yu. 02-14-2004 */
2077 if (*status & MOXA_MUST_LSR_RERR)
2080 gdl = inb(info->base + MOXA_MUST_GDL_REGISTER);
2082 /* add by Victor Yu. 02-11-2004 */
2083 if (info->IsMoxaMustChipFlag == MOXA_MUST_MU150_HWID)
2084 gdl &= MOXA_MUST_GDL_MASK;
2085 if (gdl >= recv_room) {
2086 if (!info->ldisc_stop_rx) {
2087 /* mxser_throttle(tty); */
2093 ch = inb(info->base + UART_RX);
2094 tty_insert_flip_char(tty, ch, 0);
2097 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2106 /* above add by Victor Yu. 09-02-2002 */
2112 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2119 ch = inb(info->base + UART_RX);
2120 /* following add by Victor Yu. 09-02-2002 */
2121 if (info->IsMoxaMustChipFlag && (*status & UART_LSR_OE) /*&& !(*status&UART_LSR_DR) */ )
2122 outb(0x23, info->base + UART_FCR);
2123 *status &= info->read_status_mask;
2124 /* above add by Victor Yu. 09-02-2002 */
2125 if (*status & info->ignore_status_mask) {
2126 if (++ignored > 100)
2130 if (*status & UART_LSR_SPECIAL) {
2131 if (*status & UART_LSR_BI) {
2133 /* added by casper 1/11/2000 */
2136 if (info->flags & ASYNC_SAK)
2138 } else if (*status & UART_LSR_PE) {
2140 /* added by casper 1/11/2000 */
2141 info->icount.parity++;
2143 } else if (*status & UART_LSR_FE) {
2145 /* added by casper 1/11/2000 */
2146 info->icount.frame++;
2148 } else if (*status & UART_LSR_OE) {
2150 /* added by casper 1/11/2000 */
2151 info->icount.overrun++;
2155 tty_insert_flip_char(tty, ch, flag);
2157 if (cnt >= recv_room) {
2158 if (!info->ldisc_stop_rx) {
2159 /* mxser_throttle(tty); */
2167 /* following add by Victor Yu. 09-02-2002 */
2168 if (info->IsMoxaMustChipFlag)
2170 /* above add by Victor Yu. 09-02-2002 */
2172 /* mask by Victor Yu. 09-02-2002
2173 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2175 /* following add by Victor Yu. 09-02-2002 */
2176 *status = inb(info->base + UART_LSR);
2177 /* above add by Victor Yu. 09-02-2002 */
2178 } while (*status & UART_LSR_DR);
2180 end_intr: /* add by Victor Yu. 09-02-2002 */
2181 mxvar_log.rxcnt[info->port] += cnt;
2182 info->mon_data.rxcnt += cnt;
2183 info->mon_data.up_rxcnt += cnt;
2184 spin_unlock_irqrestore(&info->slock, flags);
2186 tty_flip_buffer_push(tty);
2189 static void mxser_transmit_chars(struct mxser_struct *info)
2192 unsigned long flags;
2194 spin_lock_irqsave(&info->slock, flags);
2197 outb(info->x_char, info->base + UART_TX);
2199 mxvar_log.txcnt[info->port]++;
2200 info->mon_data.txcnt++;
2201 info->mon_data.up_txcnt++;
2203 /* added by casper 1/11/2000 */
2206 spin_unlock_irqrestore(&info->slock, flags);
2210 if (info->xmit_buf == 0) {
2211 spin_unlock_irqrestore(&info->slock, flags);
2215 if ((info->xmit_cnt <= 0) || info->tty->stopped ||
2216 (info->tty->hw_stopped &&
2217 (info->type != PORT_16550A) &&
2218 (!info->IsMoxaMustChipFlag))) {
2219 info->IER &= ~UART_IER_THRI;
2220 outb(info->IER, info->base + UART_IER);
2221 spin_unlock_irqrestore(&info->slock, flags);
2225 cnt = info->xmit_cnt;
2226 count = info->xmit_fifo_size;
2228 outb(info->xmit_buf[info->xmit_tail++],
2229 info->base + UART_TX);
2230 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE - 1);
2231 if (--info->xmit_cnt <= 0)
2233 } while (--count > 0);
2234 mxvar_log.txcnt[info->port] += (cnt - info->xmit_cnt);
2236 /* added by James 03-12-2004. */
2237 info->mon_data.txcnt += (cnt - info->xmit_cnt);
2238 info->mon_data.up_txcnt += (cnt - info->xmit_cnt);
2239 /* (above) added by James. */
2241 /* added by casper 1/11/2000 */
2242 info->icount.tx += (cnt - info->xmit_cnt);
2245 if (info->xmit_cnt < WAKEUP_CHARS) {
2246 set_bit(MXSER_EVENT_TXLOW, &info->event);
2247 schedule_work(&info->tqueue);
2249 if (info->xmit_cnt <= 0) {
2250 info->IER &= ~UART_IER_THRI;
2251 outb(info->IER, info->base + UART_IER);
2253 spin_unlock_irqrestore(&info->slock, flags);
2256 static void mxser_check_modem_status(struct mxser_struct *info, int status)
2258 /* update input line counters */
2259 if (status & UART_MSR_TERI)
2261 if (status & UART_MSR_DDSR)
2263 if (status & UART_MSR_DDCD)
2265 if (status & UART_MSR_DCTS)
2267 info->mon_data.modem_status = status;
2268 wake_up_interruptible(&info->delta_msr_wait);
2270 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
2271 if (status & UART_MSR_DCD)
2272 wake_up_interruptible(&info->open_wait);
2273 schedule_work(&info->tqueue);
2276 if (info->flags & ASYNC_CTS_FLOW) {
2277 if (info->tty->hw_stopped) {
2278 if (status & UART_MSR_CTS) {
2279 info->tty->hw_stopped = 0;
2281 if ((info->type != PORT_16550A) &&
2282 (!info->IsMoxaMustChipFlag)) {
2283 info->IER |= UART_IER_THRI;
2284 outb(info->IER, info->base + UART_IER);
2286 set_bit(MXSER_EVENT_TXLOW, &info->event);
2287 schedule_work(&info->tqueue); }
2289 if (!(status & UART_MSR_CTS)) {
2290 info->tty->hw_stopped = 1;
2291 if ((info->type != PORT_16550A) &&
2292 (!info->IsMoxaMustChipFlag)) {
2293 info->IER &= ~UART_IER_THRI;
2294 outb(info->IER, info->base + UART_IER);
2301 static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp, struct mxser_struct *info)
2303 DECLARE_WAITQUEUE(wait, current);
2306 unsigned long flags;
2309 * If non-blocking mode is set, or the port is not enabled,
2310 * then make the check up front and then exit.
2312 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2313 info->flags |= ASYNC_NORMAL_ACTIVE;
2317 if (tty->termios->c_cflag & CLOCAL)
2321 * Block waiting for the carrier detect and the line to become
2322 * free (i.e., not in use by the callout). While we are in
2323 * this loop, info->count is dropped by one, so that
2324 * mxser_close() knows when to free things. We restore it upon
2325 * exit, either normal or abnormal.
2328 add_wait_queue(&info->open_wait, &wait);
2330 spin_lock_irqsave(&info->slock, flags);
2331 if (!tty_hung_up_p(filp))
2333 spin_unlock_irqrestore(&info->slock, flags);
2334 info->blocked_open++;
2336 spin_lock_irqsave(&info->slock, flags);
2337 outb(inb(info->base + UART_MCR) |
2338 UART_MCR_DTR | UART_MCR_RTS, info->base + UART_MCR);
2339 spin_unlock_irqrestore(&info->slock, flags);
2340 set_current_state(TASK_INTERRUPTIBLE);
2341 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)) {
2342 if (info->flags & ASYNC_HUP_NOTIFY)
2345 retval = -ERESTARTSYS;
2348 if (!(info->flags & ASYNC_CLOSING) &&
2350 (inb(info->base + UART_MSR) & UART_MSR_DCD)))
2352 if (signal_pending(current)) {
2353 retval = -ERESTARTSYS;
2358 set_current_state(TASK_RUNNING);
2359 remove_wait_queue(&info->open_wait, &wait);
2360 if (!tty_hung_up_p(filp))
2362 info->blocked_open--;
2365 info->flags |= ASYNC_NORMAL_ACTIVE;
2369 static int mxser_startup(struct mxser_struct *info)
2372 unsigned long flags;
2374 page = __get_free_page(GFP_KERNEL);
2378 spin_lock_irqsave(&info->slock, flags);
2380 if (info->flags & ASYNC_INITIALIZED) {
2382 spin_unlock_irqrestore(&info->slock, flags);
2386 if (!info->base || !info->type) {
2388 set_bit(TTY_IO_ERROR, &info->tty->flags);
2390 spin_unlock_irqrestore(&info->slock, flags);
2396 info->xmit_buf = (unsigned char *) page;
2399 * Clear the FIFO buffers and disable them
2400 * (they will be reenabled in mxser_change_speed())
2402 if (info->IsMoxaMustChipFlag)
2403 outb((UART_FCR_CLEAR_RCVR |
2404 UART_FCR_CLEAR_XMIT |
2405 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2407 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2408 info->base + UART_FCR);
2411 * At this point there's no way the LSR could still be 0xFF;
2412 * if it is, then bail out, because there's likely no UART
2415 if (inb(info->base + UART_LSR) == 0xff) {
2416 spin_unlock_irqrestore(&info->slock, flags);
2417 if (capable(CAP_SYS_ADMIN)) {
2419 set_bit(TTY_IO_ERROR, &info->tty->flags);
2426 * Clear the interrupt registers.
2428 (void) inb(info->base + UART_LSR);
2429 (void) inb(info->base + UART_RX);
2430 (void) inb(info->base + UART_IIR);
2431 (void) inb(info->base + UART_MSR);
2434 * Now, initialize the UART
2436 outb(UART_LCR_WLEN8, info->base + UART_LCR); /* reset DLAB */
2437 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
2438 outb(info->MCR, info->base + UART_MCR);
2441 * Finally, enable interrupts
2443 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
2444 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2446 /* following add by Victor Yu. 08-30-2002 */
2447 if (info->IsMoxaMustChipFlag)
2448 info->IER |= MOXA_MUST_IER_EGDAI;
2449 /* above add by Victor Yu. 08-30-2002 */
2450 outb(info->IER, info->base + UART_IER); /* enable interrupts */
2453 * And clear the interrupt registers again for luck.
2455 (void) inb(info->base + UART_LSR);
2456 (void) inb(info->base + UART_RX);
2457 (void) inb(info->base + UART_IIR);
2458 (void) inb(info->base + UART_MSR);
2461 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2462 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2465 * and set the speed of the serial port
2467 spin_unlock_irqrestore(&info->slock, flags);
2468 mxser_change_speed(info, NULL);
2470 info->flags |= ASYNC_INITIALIZED;
2475 * This routine will shutdown a serial port; interrupts maybe disabled, and
2476 * DTR is dropped if the hangup on close termio flag is on.
2478 static void mxser_shutdown(struct mxser_struct *info)
2480 unsigned long flags;
2482 if (!(info->flags & ASYNC_INITIALIZED))
2485 spin_lock_irqsave(&info->slock, flags);
2488 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2489 * here so the queue might never be waken up
2491 wake_up_interruptible(&info->delta_msr_wait);
2494 * Free the IRQ, if necessary
2496 if (info->xmit_buf) {
2497 free_page((unsigned long) info->xmit_buf);
2498 info->xmit_buf = NULL;
2502 outb(0x00, info->base + UART_IER);
2504 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
2505 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
2506 outb(info->MCR, info->base + UART_MCR);
2508 /* clear Rx/Tx FIFO's */
2509 /* following add by Victor Yu. 08-30-2002 */
2510 if (info->IsMoxaMustChipFlag)
2511 outb((UART_FCR_CLEAR_RCVR |
2512 UART_FCR_CLEAR_XMIT |
2513 MOXA_MUST_FCR_GDA_MODE_ENABLE), info->base + UART_FCR);
2515 /* above add by Victor Yu. 08-30-2002 */
2516 outb((UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT),
2517 info->base + UART_FCR);
2519 /* read data port to reset things */
2520 (void) inb(info->base + UART_RX);
2523 set_bit(TTY_IO_ERROR, &info->tty->flags);
2525 info->flags &= ~ASYNC_INITIALIZED;
2527 /* following add by Victor Yu. 09-23-2002 */
2528 if (info->IsMoxaMustChipFlag)
2529 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info->base);
2530 /* above add by Victor Yu. 09-23-2002 */
2532 spin_unlock_irqrestore(&info->slock, flags);
2536 * This routine is called to set the UART divisor registers to match
2537 * the specified baud rate for a serial port.
2539 static int mxser_change_speed(struct mxser_struct *info, struct termios *old_termios)
2541 unsigned cflag, cval, fcr;
2543 unsigned char status;
2545 unsigned long flags;
2547 if (!info->tty || !info->tty->termios)
2549 cflag = info->tty->termios->c_cflag;
2554 #define B921600 (B460800 +1)
2556 if (mxser_set_baud_method[info->port] == 0) {
2557 baud = tty_get_baud_rate(info->tty);
2558 mxser_set_baud(info, baud);
2561 /* byte size and parity */
2562 switch (cflag & CSIZE) {
2577 break; /* too keep GCC shut... */
2582 cval |= UART_LCR_PARITY;
2583 if (!(cflag & PARODD))
2584 cval |= UART_LCR_EPAR;
2586 cval |= UART_LCR_SPAR;
2588 if ((info->type == PORT_8250) || (info->type == PORT_16450)) {
2589 if (info->IsMoxaMustChipFlag) {
2590 fcr = UART_FCR_ENABLE_FIFO;
2591 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2592 SET_MOXA_MUST_FIFO_VALUE(info);
2596 fcr = UART_FCR_ENABLE_FIFO;
2597 /* following add by Victor Yu. 08-30-2002 */
2598 if (info->IsMoxaMustChipFlag) {
2599 fcr |= MOXA_MUST_FCR_GDA_MODE_ENABLE;
2600 SET_MOXA_MUST_FIFO_VALUE(info);
2602 /* above add by Victor Yu. 08-30-2002 */
2603 switch (info->rx_trigger) {
2605 fcr |= UART_FCR_TRIGGER_1;
2608 fcr |= UART_FCR_TRIGGER_4;
2611 fcr |= UART_FCR_TRIGGER_8;
2614 fcr |= UART_FCR_TRIGGER_14;
2620 /* CTS flow control flag and modem status interrupts */
2621 info->IER &= ~UART_IER_MSI;
2622 info->MCR &= ~UART_MCR_AFE;
2623 if (cflag & CRTSCTS) {
2624 info->flags |= ASYNC_CTS_FLOW;
2625 info->IER |= UART_IER_MSI;
2626 if ((info->type == PORT_16550A) || (info->IsMoxaMustChipFlag)) {
2627 info->MCR |= UART_MCR_AFE;
2628 /* status = mxser_get_msr(info->base, 0, info->port); */
2632 status = inb(baseaddr + UART_MSR);
2633 restore_flags(flags);
2635 /* mxser_check_modem_status(info, status); */
2637 /* status = mxser_get_msr(info->base, 0, info->port); */
2638 /* MX_LOCK(&info->slock); */
2639 status = inb(info->base + UART_MSR);
2640 /* MX_UNLOCK(&info->slock); */
2641 if (info->tty->hw_stopped) {
2642 if (status & UART_MSR_CTS) {
2643 info->tty->hw_stopped = 0;
2644 if ((info->type != PORT_16550A) &&
2645 (!info->IsMoxaMustChipFlag)) {
2646 info->IER |= UART_IER_THRI;
2647 outb(info->IER, info->base + UART_IER);
2649 set_bit(MXSER_EVENT_TXLOW, &info->event);
2650 schedule_work(&info->tqueue); }
2652 if (!(status & UART_MSR_CTS)) {
2653 info->tty->hw_stopped = 1;
2654 if ((info->type != PORT_16550A) &&
2655 (!info->IsMoxaMustChipFlag)) {
2656 info->IER &= ~UART_IER_THRI;
2657 outb(info->IER, info->base + UART_IER);
2663 info->flags &= ~ASYNC_CTS_FLOW;
2665 outb(info->MCR, info->base + UART_MCR);
2666 if (cflag & CLOCAL) {
2667 info->flags &= ~ASYNC_CHECK_CD;
2669 info->flags |= ASYNC_CHECK_CD;
2670 info->IER |= UART_IER_MSI;
2672 outb(info->IER, info->base + UART_IER);
2675 * Set up parity check flag
2677 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2678 if (I_INPCK(info->tty))
2679 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2680 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2681 info->read_status_mask |= UART_LSR_BI;
2683 info->ignore_status_mask = 0;
2685 if (I_IGNBRK(info->tty)) {
2686 info->ignore_status_mask |= UART_LSR_BI;
2687 info->read_status_mask |= UART_LSR_BI;
2689 * If we're ignore parity and break indicators, ignore
2690 * overruns too. (For real raw support).
2692 if (I_IGNPAR(info->tty)) {
2693 info->ignore_status_mask |=
2697 info->read_status_mask |=
2703 /* following add by Victor Yu. 09-02-2002 */
2704 if (info->IsMoxaMustChipFlag) {
2705 spin_lock_irqsave(&info->slock, flags);
2706 SET_MOXA_MUST_XON1_VALUE(info->base, START_CHAR(info->tty));
2707 SET_MOXA_MUST_XOFF1_VALUE(info->base, STOP_CHAR(info->tty));
2708 if (I_IXON(info->tty)) {
2709 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2711 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info->base);
2713 if (I_IXOFF(info->tty)) {
2714 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2716 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->base);
2719 if ( I_IXANY(info->tty) ) {
2720 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2721 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2723 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2724 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2727 spin_unlock_irqrestore(&info->slock, flags);
2729 /* above add by Victor Yu. 09-02-2002 */
2732 outb(fcr, info->base + UART_FCR); /* set fcr */
2733 outb(cval, info->base + UART_LCR);
2739 static int mxser_set_baud(struct mxser_struct *info, long newspd)
2744 unsigned long flags;
2746 if (!info->tty || !info->tty->termios)
2752 if (newspd > info->MaxCanSetBaudRate)
2755 info->realbaud = newspd;
2756 if (newspd == 134) {
2757 quot = (2 * info->baud_base / 269);
2758 } else if (newspd) {
2759 quot = info->baud_base / newspd;
2766 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
2767 info->timeout += HZ / 50; /* Add .02 seconds of slop */
2770 spin_lock_irqsave(&info->slock, flags);
2771 info->MCR |= UART_MCR_DTR;
2772 outb(info->MCR, info->base + UART_MCR);
2773 spin_unlock_irqrestore(&info->slock, flags);
2775 spin_lock_irqsave(&info->slock, flags);
2776 info->MCR &= ~UART_MCR_DTR;
2777 outb(info->MCR, info->base + UART_MCR);
2778 spin_unlock_irqrestore(&info->slock, flags);
2782 cval = inb(info->base + UART_LCR);
2784 outb(cval | UART_LCR_DLAB, info->base + UART_LCR); /* set DLAB */
2786 outb(quot & 0xff, info->base + UART_DLL); /* LS of divisor */
2787 outb(quot >> 8, info->base + UART_DLM); /* MS of divisor */
2788 outb(cval, info->base + UART_LCR); /* reset DLAB */
2795 * ------------------------------------------------------------
2796 * friends of mxser_ioctl()
2797 * ------------------------------------------------------------
2799 static int mxser_get_serial_info(struct mxser_struct *info, struct serial_struct __user *retinfo)
2801 struct serial_struct tmp;
2805 memset(&tmp, 0, sizeof(tmp));
2806 tmp.type = info->type;
2807 tmp.line = info->port;
2808 tmp.port = info->base;
2809 tmp.irq = info->irq;
2810 tmp.flags = info->flags;
2811 tmp.baud_base = info->baud_base;
2812 tmp.close_delay = info->close_delay;
2813 tmp.closing_wait = info->closing_wait;
2814 tmp.custom_divisor = info->custom_divisor;
2816 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2821 static int mxser_set_serial_info(struct mxser_struct *info, struct serial_struct __user *new_info)
2823 struct serial_struct new_serial;
2827 if (!new_info || !info->base)
2829 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
2832 if ((new_serial.irq != info->irq) ||
2833 (new_serial.port != info->base) ||
2834 (new_serial.custom_divisor != info->custom_divisor) ||
2835 (new_serial.baud_base != info->baud_base))
2838 flags = info->flags & ASYNC_SPD_MASK;
2840 if (!capable(CAP_SYS_ADMIN)) {
2841 if ((new_serial.baud_base != info->baud_base) ||
2842 (new_serial.close_delay != info->close_delay) ||
2843 ((new_serial.flags & ~ASYNC_USR_MASK) != (info->flags & ~ASYNC_USR_MASK)))
2845 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2846 (new_serial.flags & ASYNC_USR_MASK));
2849 * OK, past this point, all the error checking has been done.
2850 * At this point, we start making changes.....
2852 info->flags = ((info->flags & ~ASYNC_FLAGS) |
2853 (new_serial.flags & ASYNC_FLAGS));
2854 info->close_delay = new_serial.close_delay * HZ / 100;
2855 info->closing_wait = new_serial.closing_wait * HZ / 100;
2856 info->tty->low_latency =
2857 (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2858 info->tty->low_latency = 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2861 /* added by casper, 3/17/2000, for mouse */
2862 info->type = new_serial.type;
2864 process_txrx_fifo(info);
2866 if (info->flags & ASYNC_INITIALIZED) {
2867 if (flags != (info->flags & ASYNC_SPD_MASK)) {
2868 mxser_change_speed(info, NULL);
2871 retval = mxser_startup(info);
2877 * mxser_get_lsr_info - get line status register info
2879 * Purpose: Let user call ioctl() to get info when the UART physically
2880 * is emptied. On bus types like RS485, the transmitter must
2881 * release the bus after transmitting. This must be done when
2882 * the transmit shift register is empty, not be done when the
2883 * transmit holding register is empty. This functionality
2884 * allows an RS485 driver to be written in user space.
2886 static int mxser_get_lsr_info(struct mxser_struct *info, unsigned int __user *value)
2888 unsigned char status;
2889 unsigned int result;
2890 unsigned long flags;
2892 spin_lock_irqsave(&info->slock, flags);
2893 status = inb(info->base + UART_LSR);
2894 spin_unlock_irqrestore(&info->slock, flags);
2895 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2896 return put_user(result, value);
2900 * This routine sends a break character out the serial port.
2902 static void mxser_send_break(struct mxser_struct *info, int duration)
2904 unsigned long flags;
2908 set_current_state(TASK_INTERRUPTIBLE);
2909 spin_lock_irqsave(&info->slock, flags);
2910 outb(inb(info->base + UART_LCR) | UART_LCR_SBC,
2911 info->base + UART_LCR);
2912 spin_unlock_irqrestore(&info->slock, flags);
2913 schedule_timeout(duration);
2914 spin_lock_irqsave(&info->slock, flags);
2915 outb(inb(info->base + UART_LCR) & ~UART_LCR_SBC,
2916 info->base + UART_LCR);
2917 spin_unlock_irqrestore(&info->slock, flags);
2920 static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
2922 struct mxser_struct *info = tty->driver_data;
2923 unsigned char control, status;
2924 unsigned long flags;
2927 if (tty->index == MXSER_PORTS)
2928 return -ENOIOCTLCMD;
2929 if (tty->flags & (1 << TTY_IO_ERROR))
2932 control = info->MCR;
2934 spin_lock_irqsave(&info->slock, flags);
2935 status = inb(info->base + UART_MSR);
2936 if (status & UART_MSR_ANY_DELTA)
2937 mxser_check_modem_status(info, status);
2938 spin_unlock_irqrestore(&info->slock, flags);
2939 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
2940 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
2941 ((status & UART_MSR_DCD) ? TIOCM_CAR : 0) |
2942 ((status & UART_MSR_RI) ? TIOCM_RNG : 0) |
2943 ((status & UART_MSR_DSR) ? TIOCM_DSR : 0) |
2944 ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2947 static int mxser_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear)
2949 struct mxser_struct *info = tty->driver_data;
2950 unsigned long flags;
2953 if (tty->index == MXSER_PORTS)
2954 return -ENOIOCTLCMD;
2955 if (tty->flags & (1 << TTY_IO_ERROR))
2958 spin_lock_irqsave(&info->slock, flags);
2960 if (set & TIOCM_RTS)
2961 info->MCR |= UART_MCR_RTS;
2962 if (set & TIOCM_DTR)
2963 info->MCR |= UART_MCR_DTR;
2965 if (clear & TIOCM_RTS)
2966 info->MCR &= ~UART_MCR_RTS;
2967 if (clear & TIOCM_DTR)
2968 info->MCR &= ~UART_MCR_DTR;
2970 outb(info->MCR, info->base + UART_MCR);
2971 spin_unlock_irqrestore(&info->slock, flags);
2976 static int mxser_read_register(int, unsigned short *);
2977 static int mxser_program_mode(int);
2978 static void mxser_normal_mode(int);
2980 static int mxser_get_ISA_conf(int cap, struct mxser_hwconf *hwconf)
2983 unsigned short regs[16], irq;
2984 unsigned char scratch, scratch2;
2986 hwconf->IsMoxaMustChipFlag = MOXA_OTHER_UART;
2988 id = mxser_read_register(cap, regs);
2989 if (id == C168_ASIC_ID) {
2990 hwconf->board_type = MXSER_BOARD_C168_ISA;
2992 } else if (id == C104_ASIC_ID) {
2993 hwconf->board_type = MXSER_BOARD_C104_ISA;
2995 } else if (id == C102_ASIC_ID) {
2996 hwconf->board_type = MXSER_BOARD_C102_ISA;
2998 } else if (id == CI132_ASIC_ID) {
2999 hwconf->board_type = MXSER_BOARD_CI132;
3001 } else if (id == CI134_ASIC_ID) {
3002 hwconf->board_type = MXSER_BOARD_CI134;
3004 } else if (id == CI104J_ASIC_ID) {
3005 hwconf->board_type = MXSER_BOARD_CI104J;
3011 if (hwconf->ports == 2) {
3012 irq = regs[9] & 0xF000;
3013 irq = irq | (irq >> 4);
3014 if (irq != (regs[9] & 0xFF00))
3015 return MXSER_ERR_IRQ_CONFLIT;
3016 } else if (hwconf->ports == 4) {
3017 irq = regs[9] & 0xF000;
3018 irq = irq | (irq >> 4);
3019 irq = irq | (irq >> 8);
3021 return MXSER_ERR_IRQ_CONFLIT;
3022 } else if (hwconf->ports == 8) {
3023 irq = regs[9] & 0xF000;
3024 irq = irq | (irq >> 4);
3025 irq = irq | (irq >> 8);
3026 if ((irq != regs[9]) || (irq != regs[10]))
3027 return MXSER_ERR_IRQ_CONFLIT;
3031 return MXSER_ERR_IRQ;
3032 hwconf->irq = ((int)(irq & 0xF000) >> 12);
3033 for (i = 0; i < 8; i++)
3034 hwconf->ioaddr[i] = (int) regs[i + 1] & 0xFFF8;
3035 if ((regs[12] & 0x80) == 0)
3036 return MXSER_ERR_VECTOR;
3037 hwconf->vector = (int)regs[11]; /* interrupt vector */
3039 hwconf->vector_mask = 0x00FF;
3041 hwconf->vector_mask = 0x000F;
3042 for (i = 7, bits = 0x0100; i >= 0; i--, bits <<= 1) {
3043 if (regs[12] & bits) {
3044 hwconf->baud_base[i] = 921600;
3045 hwconf->MaxCanSetBaudRate[i] = 921600; /* add by Victor Yu. 09-04-2002 */
3047 hwconf->baud_base[i] = 115200;
3048 hwconf->MaxCanSetBaudRate[i] = 115200; /* add by Victor Yu. 09-04-2002 */
3051 scratch2 = inb(cap + UART_LCR) & (~UART_LCR_DLAB);
3052 outb(scratch2 | UART_LCR_DLAB, cap + UART_LCR);
3053 outb(0, cap + UART_EFR); /* EFR is the same as FCR */
3054 outb(scratch2, cap + UART_LCR);
3055 outb(UART_FCR_ENABLE_FIFO, cap + UART_FCR);
3056 scratch = inb(cap + UART_IIR);
3059 hwconf->uart_type = PORT_16550A;
3061 hwconf->uart_type = PORT_16450;
3066 request_region(hwconf->ioaddr[0], 8 * hwconf->ports, "mxser(IO)");
3067 request_region(hwconf->vector, 1, "mxser(vector)");
3068 return hwconf->ports;
3071 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3072 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3073 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3074 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3075 #define EN_CCMD 0x000 /* Chip's command register */
3076 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3077 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3078 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3079 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3080 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3081 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3082 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3083 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3084 static int mxser_read_register(int port, unsigned short *regs)
3086 int i, k, value, id;
3089 id = mxser_program_mode(port);
3092 for (i = 0; i < 14; i++) {
3093 k = (i & 0x3F) | 0x180;
3094 for (j = 0x100; j > 0; j >>= 1) {
3095 outb(CHIP_CS, port);
3097 outb(CHIP_CS | CHIP_DO, port);
3098 outb(CHIP_CS | CHIP_DO | CHIP_SK, port); /* A? bit of read */
3100 outb(CHIP_CS, port);
3101 outb(CHIP_CS | CHIP_SK, port); /* A? bit of read */
3106 for (k = 0, j = 0x8000; k < 16; k++, j >>= 1) {
3107 outb(CHIP_CS, port);
3108 outb(CHIP_CS | CHIP_SK, port);
3109 if (inb(port) & CHIP_DI)
3115 mxser_normal_mode(port);
3119 static int mxser_program_mode(int port)
3122 /* unsigned long flags; */
3124 spin_lock(&gm_lock);
3132 /* restore_flags(flags); */
3133 spin_unlock(&gm_lock);
3135 id = inb(port + 1) & 0x1F;
3136 if ((id != C168_ASIC_ID) &&
3137 (id != C104_ASIC_ID) &&
3138 (id != C102_ASIC_ID) &&
3139 (id != CI132_ASIC_ID) &&
3140 (id != CI134_ASIC_ID) &&
3141 (id != CI104J_ASIC_ID))
3143 for (i = 0, j = 0; i < 4; i++) {
3147 } else if ((j == 1) && (n == 1)) {
3158 static void mxser_normal_mode(int port)
3162 outb(0xA5, port + 1);
3163 outb(0x80, port + 3);
3164 outb(12, port + 0); /* 9600 bps */
3166 outb(0x03, port + 3); /* 8 data bits */
3167 outb(0x13, port + 4); /* loop back mode */
3168 for (i = 0; i < 16; i++) {
3170 if ((n & 0x61) == 0x60)
3175 outb(0x00, port + 4);
3178 module_init(mxser_module_init);
3179 module_exit(mxser_module_exit);