2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2001 Moxa Technologies (support@moxa.com.tw).
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Original release 10/26/00
25 * 02/06/01 Support MOXA Industio family boards.
26 * 02/06/01 Support TIOCGICOUNT.
27 * 02/06/01 Fix the problem for connecting to serial mouse.
28 * 02/06/01 Fix the problem for H/W flow control.
29 * 02/06/01 Fix the compling warning when CONFIG_PCI
32 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
33 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
34 * - Fixed x86_64 cleanness
35 * - Fixed sleep with spinlock held in mxser_send_break
39 #include <linux/config.h>
40 #include <linux/module.h>
41 #include <linux/version.h>
42 #include <linux/autoconf.h>
43 #include <linux/errno.h>
44 #include <linux/signal.h>
45 #include <linux/sched.h>
46 #include <linux/timer.h>
47 #include <linux/interrupt.h>
48 #include <linux/tty.h>
49 #include <linux/tty_flip.h>
50 #include <linux/serial.h>
51 #include <linux/serial_reg.h>
52 #include <linux/major.h>
53 #include <linux/string.h>
54 #include <linux/fcntl.h>
55 #include <linux/ptrace.h>
56 #include <linux/gfp.h>
57 #include <linux/ioport.h>
59 #include <linux/smp_lock.h>
60 #include <linux/delay.h>
61 #include <linux/pci.h>
63 #include <asm/system.h>
66 #include <asm/bitops.h>
67 #include <asm/uaccess.h>
71 #define MXSER_VERSION "1.8"
72 #define MXSERMAJOR 174
73 #define MXSERCUMAJOR 175
75 #define MXSER_EVENT_TXLOW 1
76 #define MXSER_EVENT_HANGUP 2
78 #define MXSER_BOARDS 4 /* Max. boards */
79 #define MXSER_PORTS 32 /* Max. ports */
80 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
81 #define MXSER_ISR_PASS_LIMIT 256
83 #define MXSER_ERR_IOADDR -1
84 #define MXSER_ERR_IRQ -2
85 #define MXSER_ERR_IRQ_CONFLIT -3
86 #define MXSER_ERR_VECTOR -4
88 #define SERIAL_TYPE_NORMAL 1
89 #define SERIAL_TYPE_CALLOUT 2
91 #define WAKEUP_CHARS 256
93 #define UART_MCR_AFE 0x20
94 #define UART_LSR_SPECIAL 0x1E
96 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|IXON|IXOFF))
98 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
100 #define C168_ASIC_ID 1
101 #define C104_ASIC_ID 2
102 #define C102_ASIC_ID 0xB
103 #define CI132_ASIC_ID 4
104 #define CI134_ASIC_ID 3
105 #define CI104J_ASIC_ID 5
108 MXSER_BOARD_C168_ISA
= 1,
109 MXSER_BOARD_C104_ISA
,
111 MXSER_BOARD_C168_PCI
,
112 MXSER_BOARD_C104_PCI
,
113 MXSER_BOARD_C102_ISA
,
131 static char *mxser_brdname
[] = {
149 "Moxa UC7000 Serial",
155 static int mxser_numports
[] = {
179 #define UART_TYPE_NUM 2
181 static const unsigned int Gmoxa_uart_id
[UART_TYPE_NUM
] = {
182 MOXA_MUST_MU150_HWID
,
186 // This is only for PCI
187 #define UART_INFO_NUM 3
188 struct mxpciuart_info
{
199 static const struct mxpciuart_info Gpci_uart_info
[UART_INFO_NUM
] = {
200 {MOXA_OTHER_UART
, 16, 16, 16, 14, 14, 1, 921600L},
201 {MOXA_MUST_MU150_HWID
, 64, 64, 64, 48, 48, 16, 230400L},
202 {MOXA_MUST_MU860_HWID
, 128, 128, 128, 96, 96, 32, 921600L}
208 static struct pci_device_id mxser_pcibrds
[] = {
209 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_C168
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_C168_PCI
},
210 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_C104
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_C104_PCI
},
211 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP132
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP132
},
212 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP114
},
213 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CT114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CT114
},
214 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102
},
215 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP104U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP104U
},
216 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP168U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP168U
},
217 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP132U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP132U
},
218 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP134U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP134U
},
219 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP104JU
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP104JU
},
220 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_RC7000
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_RC7000
},
221 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP118U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP118U
},
222 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102UL
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102UL
},
223 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102U
},
227 MODULE_DEVICE_TABLE(pci
, mxser_pcibrds
);
232 typedef struct _moxa_pci_info
{
233 unsigned short busNum
;
234 unsigned short devNum
;
235 struct pci_dev
*pdev
; // add by Victor Yu. 06-23-2003
238 static int ioaddr
[MXSER_BOARDS
] = { 0, 0, 0, 0 };
239 static int ttymajor
= MXSERMAJOR
;
240 static int calloutmajor
= MXSERCUMAJOR
;
241 static int verbose
= 0;
243 /* Variables for insmod */
245 MODULE_AUTHOR("Casper Yang");
246 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
247 MODULE_PARM(ioaddr
, "1-4i");
248 MODULE_PARM(ttymajor
, "i");
249 MODULE_PARM(calloutmajor
, "i");
250 MODULE_PARM(verbose
, "i");
251 MODULE_LICENSE("GPL");
255 unsigned long rxcnt
[MXSER_PORTS
];
256 unsigned long txcnt
[MXSER_PORTS
];
263 unsigned long up_rxcnt
;
264 unsigned long up_txcnt
;
266 unsigned char hold_reason
;
269 struct mxser_mon_ext
{
270 unsigned long rx_cnt
[32];
271 unsigned long tx_cnt
[32];
272 unsigned long up_rxcnt
[32];
273 unsigned long up_txcnt
[32];
274 int modem_status
[32];
284 struct mxser_hwconf
{
291 int ioaddr
[MXSER_PORTS_PER_BOARD
];
292 int baud_base
[MXSER_PORTS_PER_BOARD
];
293 moxa_pci_info pciInfo
;
294 int IsMoxaMustChipFlag
; // add by Victor Yu. 08-30-2002
295 int MaxCanSetBaudRate
[MXSER_PORTS_PER_BOARD
]; // add by Victor Yu. 09-04-2002
296 int opmode_ioaddr
[MXSER_PORTS_PER_BOARD
]; // add by Victor Yu. 01-05-2004
299 struct mxser_struct
{
301 int base
; /* port base address */
302 int irq
; /* port using irq no. */
303 int vector
; /* port irq vector */
304 int vectormask
; /* port vector mask */
306 int rx_trigger
; /* Rx fifo trigger level */
308 int baud_base
; /* max. speed */
309 int flags
; /* defined in tty.h */
310 int type
; /* UART type */
311 struct tty_struct
*tty
;
312 int read_status_mask
;
313 int ignore_status_mask
;
316 int x_char
; /* xon/xoff character */
318 unsigned short closing_wait
;
319 int IER
; /* Interrupt Enable Register */
320 int MCR
; /* Modem control register */
322 int count
; /* # of fd on device */
323 int blocked_open
; /* # of blocked opens */
324 long session
; /* Session of opening process */
325 long pgrp
; /* pgrp of opening process */
326 unsigned char *xmit_buf
;
330 struct work_struct tqueue
;
331 struct termios normal_termios
;
332 struct termios callout_termios
;
333 wait_queue_head_t open_wait
;
334 wait_queue_head_t close_wait
;
335 wait_queue_head_t delta_msr_wait
;
336 struct async_icount icount
; /* kernel counters for the 4 input interrupts */
338 int IsMoxaMustChipFlag
; // add by Victor Yu. 08-30-2002
339 int MaxCanSetBaudRate
; // add by Victor Yu. 09-04-2002
340 int opmode_ioaddr
; // add by Victor Yu. 01-05-2004
341 unsigned char stop_rx
;
342 unsigned char ldisc_stop_rx
;
344 struct mxser_mon mon_data
;
345 unsigned char err_shadow
;
350 struct mxser_mstatus
{
358 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
360 static int mxserBoardCAP
[MXSER_BOARDS
] = {
362 /* 0x180, 0x280, 0x200, 0x320 */
365 static struct tty_driver
*mxvar_sdriver
;
366 static struct mxser_struct mxvar_table
[MXSER_PORTS
];
367 static struct tty_struct
*mxvar_tty
[MXSER_PORTS
+ 1];
368 static struct termios
*mxvar_termios
[MXSER_PORTS
+ 1];
369 static struct termios
*mxvar_termios_locked
[MXSER_PORTS
+ 1];
370 static struct mxser_log mxvar_log
;
371 static int mxvar_diagflag
;
372 static unsigned char mxser_msr
[MXSER_PORTS
+ 1];
373 static struct mxser_mon_ext mon_data_ext
;
374 static int mxser_set_baud_method
[MXSER_PORTS
+ 1];
375 static spinlock_t gm_lock
;
378 * This is used to figure out the divisor speeds and the timeouts
381 static struct mxser_hwconf mxsercfg
[MXSER_BOARDS
];
387 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
);
388 static int mxser_init(void);
390 //static void mxser_poll(unsigned long);
391 static int mxser_get_ISA_conf(int, struct mxser_hwconf
*);
392 static int mxser_get_PCI_conf(int, int, int, struct mxser_hwconf
*);
393 static void mxser_do_softint(void *);
394 static int mxser_open(struct tty_struct
*, struct file
*);
395 static void mxser_close(struct tty_struct
*, struct file
*);
396 static int mxser_write(struct tty_struct
*, const unsigned char *, int);
397 static int mxser_write_room(struct tty_struct
*);
398 static void mxser_flush_buffer(struct tty_struct
*);
399 static int mxser_chars_in_buffer(struct tty_struct
*);
400 static void mxser_flush_chars(struct tty_struct
*);
401 static void mxser_put_char(struct tty_struct
*, unsigned char);
402 static int mxser_ioctl(struct tty_struct
*, struct file
*, uint
, ulong
);
403 static int mxser_ioctl_special(unsigned int, void __user
*);
404 static void mxser_throttle(struct tty_struct
*);
405 static void mxser_unthrottle(struct tty_struct
*);
406 static void mxser_set_termios(struct tty_struct
*, struct termios
*);
407 static void mxser_stop(struct tty_struct
*);
408 static void mxser_start(struct tty_struct
*);
409 static void mxser_hangup(struct tty_struct
*);
410 static void mxser_rs_break(struct tty_struct
*, int);
411 static irqreturn_t
mxser_interrupt(int, void *, struct pt_regs
*);
412 static void mxser_receive_chars(struct mxser_struct
*, int *);
413 static void mxser_transmit_chars(struct mxser_struct
*);
414 static void mxser_check_modem_status(struct mxser_struct
*, int);
415 static int mxser_block_til_ready(struct tty_struct
*, struct file
*, struct mxser_struct
*);
416 static int mxser_startup(struct mxser_struct
*);
417 static void mxser_shutdown(struct mxser_struct
*);
418 static int mxser_change_speed(struct mxser_struct
*, struct termios
*old_termios
);
419 static int mxser_get_serial_info(struct mxser_struct
*, struct serial_struct __user
*);
420 static int mxser_set_serial_info(struct mxser_struct
*, struct serial_struct __user
*);
421 static int mxser_get_lsr_info(struct mxser_struct
*, unsigned int __user
*);
422 static void mxser_send_break(struct mxser_struct
*, int);
423 static int mxser_tiocmget(struct tty_struct
*, struct file
*);
424 static int mxser_tiocmset(struct tty_struct
*, struct file
*, unsigned int, unsigned int);
425 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
);
426 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
);
428 static void mxser_startrx(struct tty_struct
*tty
);
429 static void mxser_stoprx(struct tty_struct
*tty
);
432 static int CheckIsMoxaMust(int io
)
437 outb(0, io
+ UART_LCR
);
438 DISABLE_MOXA_MUST_ENCHANCE_MODE(io
);
439 oldmcr
= inb(io
+ UART_MCR
);
440 outb(0, io
+ UART_MCR
);
441 SET_MOXA_MUST_XON1_VALUE(io
, 0x11);
442 if ((hwid
= inb(io
+ UART_MCR
)) != 0) {
443 outb(oldmcr
, io
+ UART_MCR
);
444 return (MOXA_OTHER_UART
);
447 GET_MOXA_MUST_HARDWARE_ID(io
, &hwid
);
448 for (i
= 0; i
< UART_TYPE_NUM
; i
++) {
449 if (hwid
== Gmoxa_uart_id
[i
])
452 return MOXA_OTHER_UART
;
455 // above is modified by Victor Yu. 08-15-2002
457 static struct tty_operations mxser_ops
= {
459 .close
= mxser_close
,
460 .write
= mxser_write
,
461 .put_char
= mxser_put_char
,
462 .flush_chars
= mxser_flush_chars
,
463 .write_room
= mxser_write_room
,
464 .chars_in_buffer
= mxser_chars_in_buffer
,
465 .flush_buffer
= mxser_flush_buffer
,
466 .ioctl
= mxser_ioctl
,
467 .throttle
= mxser_throttle
,
468 .unthrottle
= mxser_unthrottle
,
469 .set_termios
= mxser_set_termios
,
471 .start
= mxser_start
,
472 .hangup
= mxser_hangup
,
473 .break_ctl
= mxser_rs_break
,
474 .wait_until_sent
= mxser_wait_until_sent
,
475 .tiocmget
= mxser_tiocmget
,
476 .tiocmset
= mxser_tiocmset
,
480 * The MOXA Smartio/Industio serial driver boot-time initialization code!
483 static int __init
mxser_module_init(void)
488 printk(KERN_DEBUG
"Loading module mxser ...\n");
491 printk(KERN_DEBUG
"Done.\n");
495 static void __exit
mxser_module_exit(void)
500 printk(KERN_DEBUG
"Unloading module mxser ...\n");
502 if ((err
|= tty_unregister_driver(mxvar_sdriver
)))
503 printk(KERN_ERR
"Couldn't unregister MOXA Smartio/Industio family serial driver\n");
505 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
506 struct pci_dev
*pdev
;
508 if (mxsercfg
[i
].board_type
== -1)
511 pdev
= mxsercfg
[i
].pciInfo
.pdev
;
512 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
513 if (pdev
!= NULL
) { //PCI
514 release_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
515 release_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3));
517 release_region(mxsercfg
[i
].ioaddr
[0], 8 * mxsercfg
[i
].ports
);
518 release_region(mxsercfg
[i
].vector
, 1);
523 printk(KERN_DEBUG
"Done.\n");
527 static void process_txrx_fifo(struct mxser_struct
*info
)
531 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
532 info
->rx_trigger
= 1;
533 info
->rx_high_water
= 1;
534 info
->rx_low_water
= 1;
535 info
->xmit_fifo_size
= 1;
537 for (i
= 0; i
< UART_INFO_NUM
; i
++) {
538 if (info
->IsMoxaMustChipFlag
== Gpci_uart_info
[i
].type
) {
539 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
540 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
541 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
542 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
549 static int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
551 struct mxser_struct
*info
;
555 n
= board
* MXSER_PORTS_PER_BOARD
;
556 info
= &mxvar_table
[n
];
558 printk(KERN_DEBUG
" ttyM%d - ttyM%d ", n
, n
+ hwconf
->ports
- 1);
559 printk(" max. baud rate = %d bps.\n", hwconf
->MaxCanSetBaudRate
[0]);
562 for (i
= 0; i
< hwconf
->ports
; i
++, n
++, info
++) {
564 info
->base
= hwconf
->ioaddr
[i
];
565 info
->irq
= hwconf
->irq
;
566 info
->vector
= hwconf
->vector
;
567 info
->vectormask
= hwconf
->vector_mask
;
568 info
->opmode_ioaddr
= hwconf
->opmode_ioaddr
[i
]; // add by Victor Yu. 01-05-2004
570 info
->ldisc_stop_rx
= 0;
572 info
->IsMoxaMustChipFlag
= hwconf
->IsMoxaMustChipFlag
;
573 //Enhance mode enabled here
574 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
575 ENABLE_MOXA_MUST_ENCHANCE_MODE(info
->base
);
578 info
->flags
= ASYNC_SHARE_IRQ
;
579 info
->type
= hwconf
->uart_type
;
580 info
->baud_base
= hwconf
->baud_base
[i
];
582 info
->MaxCanSetBaudRate
= hwconf
->MaxCanSetBaudRate
[i
];
584 process_txrx_fifo(info
);
587 info
->custom_divisor
= hwconf
->baud_base
[i
] * 16;
588 info
->close_delay
= 5 * HZ
/ 10;
589 info
->closing_wait
= 30 * HZ
;
590 INIT_WORK(&info
->tqueue
, mxser_do_softint
, info
);
591 info
->normal_termios
= mxvar_sdriver
->init_termios
;
592 init_waitqueue_head(&info
->open_wait
);
593 init_waitqueue_head(&info
->close_wait
);
594 init_waitqueue_head(&info
->delta_msr_wait
);
595 memset(&info
->mon_data
, 0, sizeof(struct mxser_mon
));
596 info
->err_shadow
= 0;
597 spin_lock_init(&info
->slock
);
600 * Allocate the IRQ if necessary
604 /* before set INT ISR, disable all int */
605 for (i
= 0; i
< hwconf
->ports
; i
++) {
606 outb(inb(hwconf
->ioaddr
[i
] + UART_IER
) & 0xf0, hwconf
->ioaddr
[i
] + UART_IER
);
609 n
= board
* MXSER_PORTS_PER_BOARD
;
610 info
= &mxvar_table
[n
];
612 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
), "mxser", info
);
614 printk(KERN_ERR
"Board %d: %s", board
, mxser_brdname
[hwconf
->board_type
- 1]);
615 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info
->irq
);
622 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
)
624 mxsercfg
[board
] = *hwconf
;
628 static int mxser_get_PCI_conf(int busnum
, int devnum
, int board_type
, struct mxser_hwconf
*hwconf
)
632 unsigned int ioaddress
;
633 struct pci_dev
*pdev
= hwconf
->pciInfo
.pdev
;
636 hwconf
->board_type
= board_type
;
637 hwconf
->ports
= mxser_numports
[board_type
- 1];
638 ioaddress
= pci_resource_start(pdev
, 2);
639 request_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2), "mxser(IO)");
641 for (i
= 0; i
< hwconf
->ports
; i
++) {
642 hwconf
->ioaddr
[i
] = ioaddress
+ 8 * i
;
646 ioaddress
= pci_resource_start(pdev
, 3);
647 request_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3), "mxser(vector)");
648 hwconf
->vector
= ioaddress
;
651 hwconf
->irq
= hwconf
->pciInfo
.pdev
->irq
;
653 hwconf
->IsMoxaMustChipFlag
= CheckIsMoxaMust(hwconf
->ioaddr
[0]);
654 hwconf
->uart_type
= PORT_16550A
;
655 hwconf
->vector_mask
= 0;
658 for (i
= 0; i
< hwconf
->ports
; i
++) {
659 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
660 if (Gpci_uart_info
[j
].type
== hwconf
->IsMoxaMustChipFlag
) {
661 hwconf
->MaxCanSetBaudRate
[i
] = Gpci_uart_info
[j
].max_baud
;
663 //exception....CP-102
664 if (board_type
== MXSER_BOARD_CP102
)
665 hwconf
->MaxCanSetBaudRate
[i
] = 921600;
671 if (hwconf
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
) {
672 for (i
= 0; i
< hwconf
->ports
; i
++) {
674 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 4;
676 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 0x0c;
678 outb(0, ioaddress
+ 4); // default set to RS232 mode
679 outb(0, ioaddress
+ 0x0c); //default set to RS232 mode
682 for (i
= 0; i
< hwconf
->ports
; i
++) {
683 hwconf
->vector_mask
|= (1 << i
);
684 hwconf
->baud_base
[i
] = 921600;
690 static int mxser_init(void)
692 int i
, m
, retval
, b
, n
;
694 struct pci_dev
*pdev
= NULL
;
696 unsigned char busnum
, devnum
;
697 struct mxser_hwconf hwconf
;
699 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
702 spin_lock_init(&gm_lock
);
704 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
705 mxsercfg
[i
].board_type
= -1;
708 printk(KERN_INFO
"MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION
);
710 /* Initialize the tty_driver structure */
711 memset(mxvar_sdriver
, 0, sizeof(struct tty_driver
));
712 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
713 mxvar_sdriver
->name
= "ttyM";
714 mxvar_sdriver
->major
= ttymajor
;
715 mxvar_sdriver
->minor_start
= 0;
716 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
717 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
718 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
719 mxvar_sdriver
->init_termios
= tty_std_termios
;
720 mxvar_sdriver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
721 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
;
722 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
723 mxvar_sdriver
->ttys
= mxvar_tty
;
724 mxvar_sdriver
->termios
= mxvar_termios
;
725 mxvar_sdriver
->termios_locked
= mxvar_termios_locked
;
728 memset(mxvar_table
, 0, MXSER_PORTS
* sizeof(struct mxser_struct
));
729 memset(&mxvar_log
, 0, sizeof(struct mxser_log
));
731 memset(&mxser_msr
, 0, sizeof(unsigned char) * (MXSER_PORTS
+ 1));
732 memset(&mon_data_ext
, 0, sizeof(struct mxser_mon_ext
));
733 memset(&mxser_set_baud_method
, 0, sizeof(int) * (MXSER_PORTS
+ 1));
734 memset(&hwconf
, 0, sizeof(struct mxser_hwconf
));
737 /* Start finding ISA boards here */
738 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
740 if (!(cap
= mxserBoardCAP
[b
]))
743 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
746 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
749 if (retval
== MXSER_ERR_IRQ
)
750 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
751 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
752 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
753 else if (retval
== MXSER_ERR_VECTOR
)
754 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
755 else if (retval
== MXSER_ERR_IOADDR
)
756 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
761 hwconf
.pciInfo
.busNum
= 0;
762 hwconf
.pciInfo
.devNum
= 0;
763 hwconf
.pciInfo
.pdev
= NULL
;
765 mxser_getcfg(m
, &hwconf
);
766 //init mxsercfg first, or mxsercfg data is not correct on ISR.
767 //mxser_initbrd will hook ISR.
768 if (mxser_initbrd(m
, &hwconf
) < 0)
775 /* Start finding ISA boards from module arg */
776 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
778 if (!(cap
= ioaddr
[b
]))
781 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
784 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
787 if (retval
== MXSER_ERR_IRQ
)
788 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
789 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
790 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
791 else if (retval
== MXSER_ERR_VECTOR
)
792 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
793 else if (retval
== MXSER_ERR_IOADDR
)
794 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
799 hwconf
.pciInfo
.busNum
= 0;
800 hwconf
.pciInfo
.devNum
= 0;
801 hwconf
.pciInfo
.pdev
= NULL
;
803 mxser_getcfg(m
, &hwconf
);
804 //init mxsercfg first, or mxsercfg data is not correct on ISR.
805 //mxser_initbrd will hook ISR.
806 if (mxser_initbrd(m
, &hwconf
) < 0)
812 /* start finding PCI board here */
814 n
= (sizeof(mxser_pcibrds
) / sizeof(mxser_pcibrds
[0])) - 1;
818 pdev
= pci_find_device(mxser_pcibrds
[b
].vendor
, mxser_pcibrds
[b
].device
, pdev
);
823 hwconf
.pciInfo
.busNum
= busnum
= pdev
->bus
->number
;
824 hwconf
.pciInfo
.devNum
= devnum
= PCI_SLOT(pdev
->devfn
) << 3;
825 hwconf
.pciInfo
.pdev
= pdev
;
826 printk(KERN_INFO
"Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname
[(int) (mxser_pcibrds
[b
].driver_data
) - 1], busnum
, devnum
>> 3);
828 if (m
>= MXSER_BOARDS
) {
829 printk(KERN_ERR
"Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS
);
831 if (pci_enable_device(pdev
)) {
832 printk(KERN_ERR
"Moxa SmartI/O PCI enable fail !\n");
835 retval
= mxser_get_PCI_conf(busnum
, devnum
, (int) mxser_pcibrds
[b
].driver_data
, &hwconf
);
837 if (retval
== MXSER_ERR_IRQ
)
838 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
839 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
840 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
841 else if (retval
== MXSER_ERR_VECTOR
)
842 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
843 else if (retval
== MXSER_ERR_IOADDR
)
844 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
847 mxser_getcfg(m
, &hwconf
);
848 //init mxsercfg first, or mxsercfg data is not correct on ISR.
849 //mxser_initbrd will hook ISR.
850 if (mxser_initbrd(m
, &hwconf
) < 0)
858 if (!(ret1
= tty_register_driver(mxvar_sdriver
))) {
861 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family driver !\n");
865 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
866 if (mxsercfg
[i
].board_type
== -1)
869 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
870 //todo: release io, vector
879 static void mxser_do_softint(void *private_
)
881 struct mxser_struct
*info
= (struct mxser_struct
*) private_
;
882 struct tty_struct
*tty
;
887 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
))
889 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
))
894 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
, struct mxser_struct
*info
)
896 unsigned char status
= 0;
898 status
= inb(baseaddr
+ UART_MSR
);
900 mxser_msr
[port
] &= 0x0F;
901 mxser_msr
[port
] |= status
;
902 status
= mxser_msr
[port
];
910 * This routine is called whenever a serial port is opened. It
911 * enables interrupts for a serial port, linking in its async structure into
912 * the IRQ chain. It also performs the serial-specific
913 * initialization for the tty structure.
915 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
917 struct mxser_struct
*info
;
921 if (line
== MXSER_PORTS
)
923 if (line
< 0 || line
> MXSER_PORTS
)
925 info
= mxvar_table
+ line
;
929 tty
->driver_data
= info
;
932 * Start up serial port
934 retval
= mxser_startup(info
);
938 retval
= mxser_block_til_ready(tty
, filp
, info
);
944 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
945 if (tty
->driver
->subtype
== SERIAL_TYPE_NORMAL
)
946 *tty
->termios
= info
->normal_termios
;
948 *tty
->termios
= info
->callout_termios
;
949 mxser_change_speed(info
, NULL
);
952 info
->session
= current
->signal
->session
;
953 info
->pgrp
= process_group(current
);
954 clear_bit(TTY_DONT_FLIP
, &tty
->flags
);
956 //status = mxser_get_msr(info->base, 0, info->port);
957 //mxser_check_modem_status(info, status);
959 /* unmark here for very high baud rate (ex. 921600 bps) used
961 tty
->low_latency
= 1;
966 * This routine is called when the serial port gets closed. First, we
967 * wait for the last remaining data to be sent. Then, we unlink its
968 * async structure from the interrupt chain if necessary, and we free
969 * that IRQ if nothing is left in the chain.
971 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
973 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
975 unsigned long timeout
;
977 struct tty_ldisc
*ld
;
979 if (tty
->index
== MXSER_PORTS
)
984 spin_lock_irqsave(&info
->slock
, flags
);
986 if (tty_hung_up_p(filp
)) {
987 spin_unlock_irqrestore(&info
->slock
, flags
);
990 if ((tty
->count
== 1) && (info
->count
!= 1)) {
992 * Uh, oh. tty->count is 1, which means that the tty
993 * structure will be freed. Info->count should always
994 * be one in these conditions. If it's greater than
995 * one, we've got real problems, since it means the
996 * serial port won't be shutdown.
998 printk(KERN_ERR
"mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info
->count
);
1001 if (--info
->count
< 0) {
1002 printk(KERN_ERR
"mxser_close: bad serial port count for ttys%d: %d\n", info
->port
, info
->count
);
1006 spin_unlock_irqrestore(&info
->slock
, flags
);
1009 info
->flags
|= ASYNC_CLOSING
;
1010 spin_unlock_irqrestore(&info
->slock
, flags
);
1012 * Save the termios structure, since this port may have
1013 * separate termios for callout and dialin.
1015 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1016 info
->normal_termios
= *tty
->termios
;
1018 * Now we wait for the transmit buffer to clear; and we notify
1019 * the line discipline to only process XON/XOFF characters.
1022 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1023 tty_wait_until_sent(tty
, info
->closing_wait
);
1025 * At this point we stop accepting input. To do this, we
1026 * disable the receive line status interrupts, and tell the
1027 * interrupt driver to stop checking the data ready bit in the
1028 * line status register.
1030 info
->IER
&= ~UART_IER_RLSI
;
1031 if (info
->IsMoxaMustChipFlag
)
1032 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1034 info->read_status_mask &= ~UART_LSR_DR;
1036 if (info
->flags
& ASYNC_INITIALIZED
) {
1037 outb(info
->IER
, info
->base
+ UART_IER
);
1039 * Before we drop DTR, make sure the UART transmitter
1040 * has completely drained; this is especially
1041 * important if there is a transmit FIFO!
1043 timeout
= jiffies
+ HZ
;
1044 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
1045 schedule_timeout_interruptible(5);
1046 if (time_after(jiffies
, timeout
))
1050 mxser_shutdown(info
);
1052 if (tty
->driver
->flush_buffer
)
1053 tty
->driver
->flush_buffer(tty
);
1055 ld
= tty_ldisc_ref(tty
);
1057 if(ld
->flush_buffer
)
1058 ld
->flush_buffer(tty
);
1059 tty_ldisc_deref(ld
);
1065 if (info
->blocked_open
) {
1066 if (info
->close_delay
)
1067 schedule_timeout_interruptible(info
->close_delay
);
1068 wake_up_interruptible(&info
->open_wait
);
1071 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1072 wake_up_interruptible(&info
->close_wait
);
1076 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1079 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1080 unsigned long flags
;
1082 if (!tty
|| !info
->xmit_buf
)
1086 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1, SERIAL_XMIT_SIZE
- info
->xmit_head
));
1090 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1091 spin_lock_irqsave(&info
->slock
, flags
);
1092 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
1093 info
->xmit_cnt
+= c
;
1094 spin_unlock_irqrestore(&info
->slock
, flags
);
1102 if (info
->xmit_cnt
&& !tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1103 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
1104 spin_lock_irqsave(&info
->slock
, flags
);
1105 info
->IER
|= UART_IER_THRI
;
1106 outb(info
->IER
, info
->base
+ UART_IER
);
1107 spin_unlock_irqrestore(&info
->slock
, flags
);
1113 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1115 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1116 unsigned long flags
;
1118 if (!tty
|| !info
->xmit_buf
)
1121 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1124 spin_lock_irqsave(&info
->slock
, flags
);
1125 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1126 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1128 spin_unlock_irqrestore(&info
->slock
, flags
);
1129 if (!tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1130 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || info
->IsMoxaMustChipFlag
) {
1131 spin_lock_irqsave(&info
->slock
, flags
);
1132 info
->IER
|= UART_IER_THRI
;
1133 outb(info
->IER
, info
->base
+ UART_IER
);
1134 spin_unlock_irqrestore(&info
->slock
, flags
);
1140 static void mxser_flush_chars(struct tty_struct
*tty
)
1142 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1143 unsigned long flags
;
1145 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| !info
->xmit_buf
|| (tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)))
1148 spin_lock_irqsave(&info
->slock
, flags
);
1150 info
->IER
|= UART_IER_THRI
;
1151 outb(info
->IER
, info
->base
+ UART_IER
);
1153 spin_unlock_irqrestore(&info
->slock
, flags
);
1156 static int mxser_write_room(struct tty_struct
*tty
)
1158 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1161 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1167 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1169 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1170 return info
->xmit_cnt
;
1173 static void mxser_flush_buffer(struct tty_struct
*tty
)
1175 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1177 unsigned long flags
;
1180 spin_lock_irqsave(&info
->slock
, flags
);
1181 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1183 /* below added by shinhay */
1184 fcr
= inb(info
->base
+ UART_FCR
);
1185 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
1186 outb(fcr
, info
->base
+ UART_FCR
);
1188 spin_unlock_irqrestore(&info
->slock
, flags
);
1189 /* above added by shinhay */
1191 wake_up_interruptible(&tty
->write_wait
);
1192 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) && tty
->ldisc
.write_wakeup
)
1193 (tty
->ldisc
.write_wakeup
) (tty
);
1196 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1198 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1200 struct async_icount cprev
, cnow
; /* kernel counter temps */
1201 struct serial_icounter_struct __user
*p_cuser
;
1202 unsigned long templ
;
1203 unsigned long flags
;
1204 void __user
*argp
= (void __user
*)arg
;
1206 if (tty
->index
== MXSER_PORTS
)
1207 return (mxser_ioctl_special(cmd
, argp
));
1209 // following add by Victor Yu. 01-05-2004
1210 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1212 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1214 unsigned char val
, mask
;
1217 if (cmd
== MOXA_SET_OP_MODE
) {
1218 if (get_user(opmode
, (int __user
*) argp
))
1220 if (opmode
!= RS232_MODE
&& opmode
!= RS485_2WIRE_MODE
&& opmode
!= RS422_MODE
&& opmode
!= RS485_4WIRE_MODE
)
1224 val
= inb(info
->opmode_ioaddr
);
1226 val
|= (opmode
<< shiftbit
);
1227 outb(val
, info
->opmode_ioaddr
);
1230 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1231 opmode
&= OP_MODE_MASK
;
1232 if (copy_to_user(argp
, &opmode
, sizeof(int)))
1237 // above add by Victor Yu. 01-05-2004
1239 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1240 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1244 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1245 retval
= tty_check_change(tty
);
1248 tty_wait_until_sent(tty
, 0);
1250 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1252 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1253 retval
= tty_check_change(tty
);
1256 tty_wait_until_sent(tty
, 0);
1257 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1260 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) argp
);
1262 if (get_user(templ
, (unsigned long __user
*) argp
))
1265 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1268 return mxser_get_serial_info(info
, argp
);
1270 return mxser_set_serial_info(info
, argp
);
1271 case TIOCSERGETLSR
: /* Get line status register */
1272 return mxser_get_lsr_info(info
, argp
);
1274 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1275 * - mask passed in arg for lines of interest
1276 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1277 * Caller should use TIOCGICOUNT to see which one it was
1280 DECLARE_WAITQUEUE(wait
, current
);
1282 spin_lock_irqsave(&info
->slock
, flags
);
1283 cprev
= info
->icount
; /* note the counters on entry */
1284 spin_unlock_irqrestore(&info
->slock
, flags
);
1286 add_wait_queue(&info
->delta_msr_wait
, &wait
);
1288 spin_lock_irqsave(&info
->slock
, flags
);
1289 cnow
= info
->icount
; /* atomic copy */
1290 spin_unlock_irqrestore(&info
->slock
, flags
);
1292 set_current_state(TASK_INTERRUPTIBLE
);
1293 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) || ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) || ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) || ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
1297 /* see if a signal did it */
1298 if (signal_pending(current
)) {
1304 current
->state
= TASK_RUNNING
;
1305 remove_wait_queue(&info
->delta_msr_wait
, &wait
);
1310 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1311 * Return: write counters to the user passed counter struct
1312 * NB: both 1->0 and 0->1 transitions are counted except for
1313 * RI where only 0->1 is counted.
1316 spin_lock_irqsave(&info
->slock
, flags
);
1317 cnow
= info
->icount
;
1318 spin_unlock_irqrestore(&info
->slock
, flags
);
1320 /* modified by casper 1/11/2000 */
1321 if (put_user(cnow
.frame
, &p_cuser
->frame
))
1323 if (put_user(cnow
.brk
, &p_cuser
->brk
))
1325 if (put_user(cnow
.overrun
, &p_cuser
->overrun
))
1327 if (put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
))
1329 if (put_user(cnow
.parity
, &p_cuser
->parity
))
1331 if (put_user(cnow
.rx
, &p_cuser
->rx
))
1333 if (put_user(cnow
.tx
, &p_cuser
->tx
))
1335 put_user(cnow
.cts
, &p_cuser
->cts
);
1336 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1337 put_user(cnow
.rng
, &p_cuser
->rng
);
1338 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1342 case MOXA_HighSpeedOn
:
1343 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*) argp
);
1345 case MOXA_SDS_RSTICOUNTER
:{
1346 info
->mon_data
.rxcnt
= 0;
1347 info
->mon_data
.txcnt
= 0;
1350 // (above) added by James.
1351 case MOXA_ASPP_SETBAUD
:{
1353 if (get_user(baud
, (long __user
*) argp
))
1355 mxser_set_baud(info
, baud
);
1358 case MOXA_ASPP_GETBAUD
:
1359 if (copy_to_user(argp
, &info
->realbaud
, sizeof(long)))
1364 case MOXA_ASPP_OQUEUE
:{
1367 len
= mxser_chars_in_buffer(tty
);
1369 lsr
= inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
;
1371 len
+= (lsr
? 0 : 1);
1373 if (copy_to_user(argp
, &len
, sizeof(int)))
1378 case MOXA_ASPP_MON
:{
1380 // info->mon_data.ser_param = tty->termios->c_cflag;
1382 status
= mxser_get_msr(info
->base
, 1, info
->port
, info
);
1383 mxser_check_modem_status(info
, status
);
1385 mcr
= inb(info
->base
+ UART_MCR
);
1386 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1387 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1389 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1391 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1392 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1394 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1396 if (info
->tty
->hw_stopped
)
1397 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1399 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1402 if (copy_to_user(argp
, &info
->mon_data
, sizeof(struct mxser_mon
)))
1409 case MOXA_ASPP_LSTATUS
:{
1410 if (copy_to_user(argp
, &info
->err_shadow
, sizeof(unsigned char)))
1413 info
->err_shadow
= 0;
1417 case MOXA_SET_BAUD_METHOD
:{
1419 if (get_user(method
, (int __user
*) argp
))
1421 mxser_set_baud_method
[info
->port
] = method
;
1422 if (copy_to_user(argp
, &method
, sizeof(int)))
1428 return -ENOIOCTLCMD
;
1434 #define CMSPAR 010000000000
1437 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1439 int i
, result
, status
;
1443 if (copy_to_user(argp
, mxsercfg
, sizeof(struct mxser_hwconf
) * 4))
1446 case MOXA_GET_MAJOR
:
1447 if (copy_to_user(argp
, &ttymajor
, sizeof(int)))
1451 case MOXA_GET_CUMAJOR
:
1452 if (copy_to_user(argp
, &calloutmajor
, sizeof(int)))
1456 case MOXA_CHKPORTENABLE
:
1458 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1459 if (mxvar_table
[i
].base
)
1462 return put_user(result
, (unsigned long __user
*) argp
);
1463 case MOXA_GETDATACOUNT
:
1464 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1467 case MOXA_GETMSTATUS
:
1468 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1470 if (!mxvar_table
[i
].base
) {
1471 GMStatus
[i
].dcd
= 0;
1472 GMStatus
[i
].dsr
= 0;
1473 GMStatus
[i
].cts
= 0;
1477 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1478 GMStatus
[i
].cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1480 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1482 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1483 if (status
& 0x80 /*UART_MSR_DCD */ )
1484 GMStatus
[i
].dcd
= 1;
1486 GMStatus
[i
].dcd
= 0;
1488 if (status
& 0x20 /*UART_MSR_DSR */ )
1489 GMStatus
[i
].dsr
= 1;
1491 GMStatus
[i
].dsr
= 0;
1494 if (status
& 0x10 /*UART_MSR_CTS */ )
1495 GMStatus
[i
].cts
= 1;
1497 GMStatus
[i
].cts
= 0;
1499 if (copy_to_user(argp
, GMStatus
, sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1502 case MOXA_ASPP_MON_EXT
:{
1506 unsigned cflag
, iflag
;
1508 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1510 if (!mxvar_table
[i
].base
)
1513 status
= mxser_get_msr(mxvar_table
[i
].base
, 0, i
, &(mxvar_table
[i
]));
1514 // mxser_check_modem_status(&mxvar_table[i], status);
1515 if (status
& UART_MSR_TERI
)
1516 mxvar_table
[i
].icount
.rng
++;
1517 if (status
& UART_MSR_DDSR
)
1518 mxvar_table
[i
].icount
.dsr
++;
1519 if (status
& UART_MSR_DDCD
)
1520 mxvar_table
[i
].icount
.dcd
++;
1521 if (status
& UART_MSR_DCTS
)
1522 mxvar_table
[i
].icount
.cts
++;
1524 mxvar_table
[i
].mon_data
.modem_status
= status
;
1525 mon_data_ext
.rx_cnt
[i
] = mxvar_table
[i
].mon_data
.rxcnt
;
1526 mon_data_ext
.tx_cnt
[i
] = mxvar_table
[i
].mon_data
.txcnt
;
1527 mon_data_ext
.up_rxcnt
[i
] = mxvar_table
[i
].mon_data
.up_rxcnt
;
1528 mon_data_ext
.up_txcnt
[i
] = mxvar_table
[i
].mon_data
.up_txcnt
;
1529 mon_data_ext
.modem_status
[i
] = mxvar_table
[i
].mon_data
.modem_status
;
1530 mon_data_ext
.baudrate
[i
] = mxvar_table
[i
].realbaud
;
1532 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
) {
1533 cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1534 iflag
= mxvar_table
[i
].normal_termios
.c_iflag
;
1536 cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1537 iflag
= mxvar_table
[i
].tty
->termios
->c_iflag
;
1540 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1542 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1544 mon_data_ext
.parity
[i
] = cflag
& (PARENB
| PARODD
| CMSPAR
);
1546 mon_data_ext
.flowctrl
[i
] = 0x00;
1548 if (cflag
& CRTSCTS
)
1549 mon_data_ext
.flowctrl
[i
] |= 0x03;
1551 if (iflag
& (IXON
| IXOFF
))
1552 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1554 if (mxvar_table
[i
].type
== PORT_16550A
)
1555 mon_data_ext
.fifo
[i
] = 1;
1557 mon_data_ext
.fifo
[i
] = 0;
1561 opmode
= inb(mxvar_table
[i
].opmode_ioaddr
) >> shiftbit
;
1562 opmode
&= OP_MODE_MASK
;
1564 mon_data_ext
.iftype
[i
] = opmode
;
1567 if (copy_to_user(argp
, &mon_data_ext
, sizeof(struct mxser_mon_ext
)))
1574 return -ENOIOCTLCMD
;
1580 static void mxser_stoprx(struct tty_struct
*tty
)
1582 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1583 //unsigned long flags;
1586 info
->ldisc_stop_rx
= 1;
1589 //MX_LOCK(&info->slock);
1590 // following add by Victor Yu. 09-02-2002
1591 if (info
->IsMoxaMustChipFlag
) {
1592 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1593 outb(info
->IER
, info
->base
+ UART_IER
);
1595 // above add by Victor Yu. 09-02-2002
1597 info
->x_char
= STOP_CHAR(tty
);
1598 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1599 outb(0, info
->base
+ UART_IER
);
1600 info
->IER
|= UART_IER_THRI
;
1601 outb(info
->IER
, info
->base
+ UART_IER
); /* force Tx interrupt */
1602 } // add by Victor Yu. 09-02-2002
1603 //MX_UNLOCK(&info->slock);
1606 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1607 //MX_LOCK(&info->slock);
1608 info
->MCR
&= ~UART_MCR_RTS
;
1609 outb(info
->MCR
, info
->base
+ UART_MCR
);
1610 //MX_UNLOCK(&info->slock);
1614 static void mxser_startrx(struct tty_struct
*tty
)
1616 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1617 //unsigned long flags;
1619 info
->ldisc_stop_rx
= 0;
1624 //MX_LOCK(&info->slock);
1626 // following add by Victor Yu. 09-02-2002
1627 if (info
->IsMoxaMustChipFlag
) {
1628 info
->IER
|= MOXA_MUST_RECV_ISR
;
1629 outb(info
->IER
, info
->base
+ UART_IER
);
1631 // above add by Victor Yu. 09-02-2002
1633 info
->x_char
= START_CHAR(tty
);
1634 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1635 outb(0, info
->base
+ UART_IER
); // add by Victor Yu. 09-02-2002
1636 info
->IER
|= UART_IER_THRI
; /* force Tx interrupt */
1637 outb(info
->IER
, info
->base
+ UART_IER
);
1638 } // add by Victor Yu. 09-02-2002
1639 //MX_UNLOCK(&info->slock);
1643 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1644 //MX_LOCK(&info->slock);
1645 info
->MCR
|= UART_MCR_RTS
;
1646 outb(info
->MCR
, info
->base
+ UART_MCR
);
1647 //MX_UNLOCK(&info->slock);
1652 * This routine is called by the upper-layer tty layer to signal that
1653 * incoming characters should be throttled.
1655 static void mxser_throttle(struct tty_struct
*tty
)
1657 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1658 //unsigned long flags;
1659 //MX_LOCK(&info->slock);
1661 //MX_UNLOCK(&info->slock);
1664 static void mxser_unthrottle(struct tty_struct
*tty
)
1666 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1667 //unsigned long flags;
1668 //MX_LOCK(&info->slock);
1670 //MX_UNLOCK(&info->slock);
1673 static void mxser_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1675 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1676 unsigned long flags
;
1678 if ((tty
->termios
->c_cflag
!= old_termios
->c_cflag
) || (RELEVANT_IFLAG(tty
->termios
->c_iflag
) != RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1680 mxser_change_speed(info
, old_termios
);
1682 if ((old_termios
->c_cflag
& CRTSCTS
) && !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1683 tty
->hw_stopped
= 0;
1688 /* Handle sw stopped */
1689 if ((old_termios
->c_iflag
& IXON
) && !(tty
->termios
->c_iflag
& IXON
)) {
1692 // following add by Victor Yu. 09-02-2002
1693 if (info
->IsMoxaMustChipFlag
) {
1694 spin_lock_irqsave(&info
->slock
, flags
);
1695 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
1696 spin_unlock_irqrestore(&info
->slock
, flags
);
1698 // above add by Victor Yu. 09-02-2002
1705 * mxser_stop() and mxser_start()
1707 * This routines are called before setting or resetting tty->stopped.
1708 * They enable or disable transmitter interrupts, as necessary.
1710 static void mxser_stop(struct tty_struct
*tty
)
1712 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1713 unsigned long flags
;
1715 spin_lock_irqsave(&info
->slock
, flags
);
1716 if (info
->IER
& UART_IER_THRI
) {
1717 info
->IER
&= ~UART_IER_THRI
;
1718 outb(info
->IER
, info
->base
+ UART_IER
);
1720 spin_unlock_irqrestore(&info
->slock
, flags
);
1723 static void mxser_start(struct tty_struct
*tty
)
1725 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1726 unsigned long flags
;
1728 spin_lock_irqsave(&info
->slock
, flags
);
1729 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
1730 info
->IER
|= UART_IER_THRI
;
1731 outb(info
->IER
, info
->base
+ UART_IER
);
1733 spin_unlock_irqrestore(&info
->slock
, flags
);
1737 * mxser_wait_until_sent() --- wait until the transmitter is empty
1739 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1741 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1742 unsigned long orig_jiffies
, char_time
;
1745 if (info
->type
== PORT_UNKNOWN
)
1748 if (info
->xmit_fifo_size
== 0)
1749 return; /* Just in case.... */
1751 orig_jiffies
= jiffies
;
1753 * Set the check interval to be 1/5 of the estimated time to
1754 * send a single character, and make it at least 1. The check
1755 * interval should also be less than the timeout.
1757 * Note: we have to use pretty tight timings here to satisfy
1760 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
1761 char_time
= char_time
/ 5;
1764 if (timeout
&& timeout
< char_time
)
1765 char_time
= timeout
;
1767 * If the transmitter hasn't cleared in twice the approximate
1768 * amount of time to send the entire FIFO, it probably won't
1769 * ever clear. This assumes the UART isn't doing flow
1770 * control, which is currently the case. Hence, if it ever
1771 * takes longer than info->timeout, this is probably due to a
1772 * UART bug of some kind. So, we clamp the timeout parameter at
1775 if (!timeout
|| timeout
> 2 * info
->timeout
)
1776 timeout
= 2 * info
->timeout
;
1777 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1778 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1779 printk("jiff=%lu...", jiffies
);
1781 while (!((lsr
= inb(info
->base
+ UART_LSR
)) & UART_LSR_TEMT
)) {
1782 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1783 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1785 schedule_timeout_interruptible(char_time
);
1786 if (signal_pending(current
))
1788 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1791 set_current_state(TASK_RUNNING
);
1793 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1794 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1800 * This routine is called by tty_hangup() when a hangup is signaled.
1802 void mxser_hangup(struct tty_struct
*tty
)
1804 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1806 mxser_flush_buffer(tty
);
1807 mxser_shutdown(info
);
1810 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1812 wake_up_interruptible(&info
->open_wait
);
1816 // added by James 03-12-2004.
1818 * mxser_rs_break() --- routine which turns the break handling on or off
1820 static void mxser_rs_break(struct tty_struct
*tty
, int break_state
)
1822 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1823 unsigned long flags
;
1825 spin_lock_irqsave(&info
->slock
, flags
);
1826 if (break_state
== -1)
1827 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
1829 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
1830 spin_unlock_irqrestore(&info
->slock
, flags
);
1833 // (above) added by James.
1837 * This is the serial driver's generic interrupt routine
1839 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1842 struct mxser_struct
*info
;
1843 struct mxser_struct
*port
;
1844 int max
, irqbits
, bits
, msr
;
1845 int pass_counter
= 0;
1846 int handled
= IRQ_NONE
;
1849 //spin_lock(&gm_lock);
1851 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1852 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1858 if (i
== MXSER_BOARDS
) {
1864 max
= mxser_numports
[mxsercfg
[i
].board_type
- 1];
1866 irqbits
= inb(port
->vector
) & port
->vectormask
;
1867 if (irqbits
== port
->vectormask
) {
1871 handled
= IRQ_HANDLED
;
1872 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1873 if (irqbits
== port
->vectormask
) {
1880 // following add by Victor Yu. 09-13-2002
1881 iir
= inb(info
->base
+ UART_IIR
);
1882 if (iir
& UART_IIR_NO_INT
)
1884 iir
&= MOXA_MUST_IIR_MASK
;
1886 status
= inb(info
->base
+ UART_LSR
);
1887 outb(0x27, info
->base
+ UART_FCR
);
1888 inb(info
->base
+ UART_MSR
);
1891 // above add by Victor Yu. 09-13-2002
1893 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1894 info->IER |= MOXA_MUST_RECV_ISR;
1895 outb(info->IER, info->base + UART_IER);
1900 /* mask by Victor Yu. 09-13-2002
1902 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1905 /* mask by Victor Yu. 09-02-2002
1906 status = inb(info->base + UART_LSR) & info->read_status_mask;
1909 // following add by Victor Yu. 09-02-2002
1910 status
= inb(info
->base
+ UART_LSR
);
1912 if (status
& UART_LSR_PE
) {
1913 info
->err_shadow
|= NPPI_NOTIFY_PARITY
;
1915 if (status
& UART_LSR_FE
) {
1916 info
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
1918 if (status
& UART_LSR_OE
) {
1919 info
->err_shadow
|= NPPI_NOTIFY_HW_OVERRUN
;
1921 if (status
& UART_LSR_BI
)
1922 info
->err_shadow
|= NPPI_NOTIFY_BREAK
;
1924 if (info
->IsMoxaMustChipFlag
) {
1926 if ( (status & 0x02) && !(status & 0x01) ) {
1927 outb(info->base+UART_FCR, 0x23);
1931 if (iir
== MOXA_MUST_IIR_GDA
|| iir
== MOXA_MUST_IIR_RDA
|| iir
== MOXA_MUST_IIR_RTO
|| iir
== MOXA_MUST_IIR_LSR
)
1932 mxser_receive_chars(info
, &status
);
1935 // above add by Victor Yu. 09-02-2002
1937 status
&= info
->read_status_mask
;
1938 if (status
& UART_LSR_DR
)
1939 mxser_receive_chars(info
, &status
);
1941 msr
= inb(info
->base
+ UART_MSR
);
1942 if (msr
& UART_MSR_ANY_DELTA
) {
1943 mxser_check_modem_status(info
, msr
);
1945 // following add by Victor Yu. 09-13-2002
1946 if (info
->IsMoxaMustChipFlag
) {
1947 if ((iir
== 0x02) && (status
& UART_LSR_THRE
)) {
1948 mxser_transmit_chars(info
);
1951 // above add by Victor Yu. 09-13-2002
1953 if (status
& UART_LSR_THRE
) {
1954 /* 8-2-99 by William
1955 if ( info->x_char || (info->xmit_cnt > 0) )
1957 mxser_transmit_chars(info
);
1961 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
1962 break; /* Prevent infinite loops */
1967 //spin_unlock(&gm_lock);
1971 static void mxser_receive_chars(struct mxser_struct
*info
, int *status
)
1973 struct tty_struct
*tty
= info
->tty
;
1974 unsigned char ch
, gdl
;
1979 unsigned long flags
;
1981 spin_lock_irqsave(&info
->slock
, flags
);
1983 recv_room
= tty
->ldisc
.receive_room(tty
);
1984 if ((recv_room
== 0) && (!info
->ldisc_stop_rx
)) {
1985 //mxser_throttle(tty);
1990 // following add by Victor Yu. 09-02-2002
1991 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
1993 if (*status
& UART_LSR_SPECIAL
) {
1996 // following add by Victor Yu. 02-11-2004
1997 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
&& (*status
& MOXA_MUST_LSR_RERR
))
1999 // above add by Victor Yu. 02-14-2004
2000 if (*status
& MOXA_MUST_LSR_RERR
)
2003 gdl
= inb(info
->base
+ MOXA_MUST_GDL_REGISTER
);
2005 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU150_HWID
) // add by Victor Yu. 02-11-2004
2006 gdl
&= MOXA_MUST_GDL_MASK
;
2007 if (gdl
>= recv_room
) {
2008 if (!info
->ldisc_stop_rx
) {
2009 //mxser_throttle(tty);
2015 ch
= inb(info
->base
+ UART_RX
);
2016 tty_insert_flip_char(tty
, ch
, 0);
2019 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2028 // above add by Victor Yu. 09-02-2002
2034 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2041 ch
= inb(info
->base
+ UART_RX
);
2042 // following add by Victor Yu. 09-02-2002
2043 if (info
->IsMoxaMustChipFlag
&& (*status
& UART_LSR_OE
) /*&& !(*status&UART_LSR_DR) */ )
2044 outb(0x23, info
->base
+ UART_FCR
);
2045 *status
&= info
->read_status_mask
;
2046 // above add by Victor Yu. 09-02-2002
2047 if (*status
& info
->ignore_status_mask
) {
2048 if (++ignored
> 100)
2052 if (*status
& UART_LSR_SPECIAL
) {
2053 if (*status
& UART_LSR_BI
) {
2055 /* added by casper 1/11/2000 */
2058 if (info
->flags
& ASYNC_SAK
)
2060 } else if (*status
& UART_LSR_PE
) {
2062 /* added by casper 1/11/2000 */
2063 info
->icount
.parity
++;
2065 } else if (*status
& UART_LSR_FE
) {
2067 /* added by casper 1/11/2000 */
2068 info
->icount
.frame
++;
2070 } else if (*status
& UART_LSR_OE
) {
2072 /* added by casper 1/11/2000 */
2073 info
->icount
.overrun
++;
2077 tty_insert_flip_char(tty
, ch
, flag
);
2079 if (cnt
>= recv_room
) {
2080 if (!info
->ldisc_stop_rx
) {
2081 //mxser_throttle(tty);
2089 // following add by Victor Yu. 09-02-2002
2090 if (info
->IsMoxaMustChipFlag
)
2092 // above add by Victor Yu. 09-02-2002
2094 /* mask by Victor Yu. 09-02-2002
2095 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2097 // following add by Victor Yu. 09-02-2002
2098 *status
= inb(info
->base
+ UART_LSR
);
2099 // above add by Victor Yu. 09-02-2002
2100 } while (*status
& UART_LSR_DR
);
2102 end_intr
: // add by Victor Yu. 09-02-2002
2104 mxvar_log
.rxcnt
[info
->port
] += cnt
;
2105 info
->mon_data
.rxcnt
+= cnt
;
2106 info
->mon_data
.up_rxcnt
+= cnt
;
2107 spin_unlock_irqrestore(&info
->slock
, flags
);
2109 tty_flip_buffer_push(tty
);
2112 static void mxser_transmit_chars(struct mxser_struct
*info
)
2115 unsigned long flags
;
2117 spin_lock_irqsave(&info
->slock
, flags
);
2120 outb(info
->x_char
, info
->base
+ UART_TX
);
2122 mxvar_log
.txcnt
[info
->port
]++;
2123 info
->mon_data
.txcnt
++;
2124 info
->mon_data
.up_txcnt
++;
2126 /* added by casper 1/11/2000 */
2129 spin_unlock_irqrestore(&info
->slock
, flags
);
2133 if (info
->xmit_buf
== 0) {
2134 spin_unlock_irqrestore(&info
->slock
, flags
);
2138 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| (info
->tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
))) {
2139 info
->IER
&= ~UART_IER_THRI
;
2140 outb(info
->IER
, info
->base
+ UART_IER
);
2141 spin_unlock_irqrestore(&info
->slock
, flags
);
2145 cnt
= info
->xmit_cnt
;
2146 count
= info
->xmit_fifo_size
;
2148 outb(info
->xmit_buf
[info
->xmit_tail
++], info
->base
+ UART_TX
);
2149 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2150 if (--info
->xmit_cnt
<= 0)
2152 } while (--count
> 0);
2153 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
2155 // added by James 03-12-2004.
2156 info
->mon_data
.txcnt
+= (cnt
- info
->xmit_cnt
);
2157 info
->mon_data
.up_txcnt
+= (cnt
- info
->xmit_cnt
);
2158 // (above) added by James.
2160 /* added by casper 1/11/2000 */
2161 info
->icount
.tx
+= (cnt
- info
->xmit_cnt
);
2164 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
2165 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2166 schedule_work(&info
->tqueue
);
2168 if (info
->xmit_cnt
<= 0) {
2169 info
->IER
&= ~UART_IER_THRI
;
2170 outb(info
->IER
, info
->base
+ UART_IER
);
2172 spin_unlock_irqrestore(&info
->slock
, flags
);
2175 static void mxser_check_modem_status(struct mxser_struct
*info
, int status
)
2177 /* update input line counters */
2178 if (status
& UART_MSR_TERI
)
2180 if (status
& UART_MSR_DDSR
)
2182 if (status
& UART_MSR_DDCD
)
2184 if (status
& UART_MSR_DCTS
)
2186 info
->mon_data
.modem_status
= status
;
2187 wake_up_interruptible(&info
->delta_msr_wait
);
2190 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
2191 if (status
& UART_MSR_DCD
)
2192 wake_up_interruptible(&info
->open_wait
);
2193 schedule_work(&info
->tqueue
);
2196 if (info
->flags
& ASYNC_CTS_FLOW
) {
2197 if (info
->tty
->hw_stopped
) {
2198 if (status
& UART_MSR_CTS
) {
2199 info
->tty
->hw_stopped
= 0;
2201 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2202 info
->IER
|= UART_IER_THRI
;
2203 outb(info
->IER
, info
->base
+ UART_IER
);
2205 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2206 schedule_work(&info
->tqueue
); }
2208 if (!(status
& UART_MSR_CTS
)) {
2209 info
->tty
->hw_stopped
= 1;
2210 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2211 info
->IER
&= ~UART_IER_THRI
;
2212 outb(info
->IER
, info
->base
+ UART_IER
);
2219 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, struct mxser_struct
*info
)
2221 DECLARE_WAITQUEUE(wait
, current
);
2224 unsigned long flags
;
2227 * If non-blocking mode is set, or the port is not enabled,
2228 * then make the check up front and then exit.
2230 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2231 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2235 if (tty
->termios
->c_cflag
& CLOCAL
)
2239 * Block waiting for the carrier detect and the line to become
2240 * free (i.e., not in use by the callout). While we are in
2241 * this loop, info->count is dropped by one, so that
2242 * mxser_close() knows when to free things. We restore it upon
2243 * exit, either normal or abnormal.
2246 add_wait_queue(&info
->open_wait
, &wait
);
2248 spin_lock_irqsave(&info
->slock
, flags
);
2249 if (!tty_hung_up_p(filp
))
2251 spin_unlock_irqrestore(&info
->slock
, flags
);
2252 info
->blocked_open
++;
2254 spin_lock_irqsave(&info
->slock
, flags
);
2255 outb(inb(info
->base
+ UART_MCR
) | UART_MCR_DTR
| UART_MCR_RTS
, info
->base
+ UART_MCR
);
2256 spin_unlock_irqrestore(&info
->slock
, flags
);
2257 set_current_state(TASK_INTERRUPTIBLE
);
2258 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
2259 if (info
->flags
& ASYNC_HUP_NOTIFY
)
2262 retval
= -ERESTARTSYS
;
2265 if (!(info
->flags
& ASYNC_CLOSING
) && (do_clocal
|| (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
2267 if (signal_pending(current
)) {
2268 retval
= -ERESTARTSYS
;
2273 set_current_state(TASK_RUNNING
);
2274 remove_wait_queue(&info
->open_wait
, &wait
);
2275 if (!tty_hung_up_p(filp
))
2277 info
->blocked_open
--;
2280 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2284 static int mxser_startup(struct mxser_struct
*info
)
2288 unsigned long flags
;
2290 page
= __get_free_page(GFP_KERNEL
);
2294 spin_lock_irqsave(&info
->slock
, flags
);
2296 if (info
->flags
& ASYNC_INITIALIZED
) {
2298 spin_unlock_irqrestore(&info
->slock
, flags
);
2302 if (!info
->base
|| !info
->type
) {
2304 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2306 spin_unlock_irqrestore(&info
->slock
, flags
);
2312 info
->xmit_buf
= (unsigned char *) page
;
2315 * Clear the FIFO buffers and disable them
2316 * (they will be reenabled in mxser_change_speed())
2318 if (info
->IsMoxaMustChipFlag
)
2319 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2321 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2324 * At this point there's no way the LSR could still be 0xFF;
2325 * if it is, then bail out, because there's likely no UART
2328 if (inb(info
->base
+ UART_LSR
) == 0xff) {
2329 spin_unlock_irqrestore(&info
->slock
, flags
);
2330 if (capable(CAP_SYS_ADMIN
)) {
2332 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2339 * Clear the interrupt registers.
2341 (void) inb(info
->base
+ UART_LSR
);
2342 (void) inb(info
->base
+ UART_RX
);
2343 (void) inb(info
->base
+ UART_IIR
);
2344 (void) inb(info
->base
+ UART_MSR
);
2347 * Now, initialize the UART
2349 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
2350 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
2351 outb(info
->MCR
, info
->base
+ UART_MCR
);
2354 * Finally, enable interrupts
2356 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
2357 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2359 // following add by Victor Yu. 08-30-2002
2360 if (info
->IsMoxaMustChipFlag
)
2361 info
->IER
|= MOXA_MUST_IER_EGDAI
;
2362 // above add by Victor Yu. 08-30-2002
2363 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
2366 * And clear the interrupt registers again for luck.
2368 (void) inb(info
->base
+ UART_LSR
);
2369 (void) inb(info
->base
+ UART_RX
);
2370 (void) inb(info
->base
+ UART_IIR
);
2371 (void) inb(info
->base
+ UART_MSR
);
2374 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2375 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2378 * and set the speed of the serial port
2380 spin_unlock_irqrestore(&info
->slock
, flags
);
2381 mxser_change_speed(info
, NULL
);
2383 info
->flags
|= ASYNC_INITIALIZED
;
2388 * This routine will shutdown a serial port; interrupts maybe disabled, and
2389 * DTR is dropped if the hangup on close termio flag is on.
2391 static void mxser_shutdown(struct mxser_struct
*info
)
2393 unsigned long flags
;
2395 if (!(info
->flags
& ASYNC_INITIALIZED
))
2398 spin_lock_irqsave(&info
->slock
, flags
);
2401 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2402 * here so the queue might never be waken up
2404 wake_up_interruptible(&info
->delta_msr_wait
);
2407 * Free the IRQ, if necessary
2409 if (info
->xmit_buf
) {
2410 free_page((unsigned long) info
->xmit_buf
);
2411 info
->xmit_buf
= NULL
;
2415 outb(0x00, info
->base
+ UART_IER
);
2417 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
2418 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
2419 outb(info
->MCR
, info
->base
+ UART_MCR
);
2421 /* clear Rx/Tx FIFO's */
2422 // following add by Victor Yu. 08-30-2002
2423 if (info
->IsMoxaMustChipFlag
)
2424 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2426 // above add by Victor Yu. 08-30-2002
2427 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2429 /* read data port to reset things */
2430 (void) inb(info
->base
+ UART_RX
);
2433 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2435 info
->flags
&= ~ASYNC_INITIALIZED
;
2437 // following add by Victor Yu. 09-23-2002
2438 if (info
->IsMoxaMustChipFlag
) {
2439 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->base
);
2441 // above add by Victor Yu. 09-23-2002
2443 spin_unlock_irqrestore(&info
->slock
, flags
);
2447 * This routine is called to set the UART divisor registers to match
2448 * the specified baud rate for a serial port.
2450 static int mxser_change_speed(struct mxser_struct
*info
, struct termios
*old_termios
)
2452 unsigned cflag
, cval
, fcr
;
2454 unsigned char status
;
2456 unsigned long flags
;
2459 if (!info
->tty
|| !info
->tty
->termios
)
2461 cflag
= info
->tty
->termios
->c_cflag
;
2467 #define B921600 (B460800 +1)
2469 if (mxser_set_baud_method
[info
->port
] == 0) {
2470 switch (cflag
& (CBAUD
| CBAUDEX
)) {
2535 mxser_set_baud(info
, baud
);
2538 /* byte size and parity */
2539 switch (cflag
& CSIZE
) {
2554 break; /* too keep GCC shut... */
2559 cval
|= UART_LCR_PARITY
;
2560 if (!(cflag
& PARODD
)) {
2561 cval
|= UART_LCR_EPAR
;
2564 cval
|= UART_LCR_SPAR
;
2566 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
2567 if (info
->IsMoxaMustChipFlag
) {
2568 fcr
= UART_FCR_ENABLE_FIFO
;
2569 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2570 SET_MOXA_MUST_FIFO_VALUE(info
);
2574 fcr
= UART_FCR_ENABLE_FIFO
;
2575 // following add by Victor Yu. 08-30-2002
2576 if (info
->IsMoxaMustChipFlag
) {
2577 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2578 SET_MOXA_MUST_FIFO_VALUE(info
);
2580 // above add by Victor Yu. 08-30-2002
2582 switch (info
->rx_trigger
) {
2584 fcr
|= UART_FCR_TRIGGER_1
;
2587 fcr
|= UART_FCR_TRIGGER_4
;
2590 fcr
|= UART_FCR_TRIGGER_8
;
2593 fcr
|= UART_FCR_TRIGGER_14
;
2599 /* CTS flow control flag and modem status interrupts */
2600 info
->IER
&= ~UART_IER_MSI
;
2601 info
->MCR
&= ~UART_MCR_AFE
;
2602 if (cflag
& CRTSCTS
) {
2603 info
->flags
|= ASYNC_CTS_FLOW
;
2604 info
->IER
|= UART_IER_MSI
;
2605 if ((info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
2606 info
->MCR
|= UART_MCR_AFE
;
2607 //status = mxser_get_msr(info->base, 0, info->port);
2608 /* save_flags(flags);
2610 status = inb(baseaddr + UART_MSR);
2611 restore_flags(flags);*/
2612 //mxser_check_modem_status(info, status);
2614 //status = mxser_get_msr(info->base, 0, info->port);
2616 //MX_LOCK(&info->slock);
2617 status
= inb(info
->base
+ UART_MSR
);
2618 //MX_UNLOCK(&info->slock);
2619 if (info
->tty
->hw_stopped
) {
2620 if (status
& UART_MSR_CTS
) {
2621 info
->tty
->hw_stopped
= 0;
2622 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2623 info
->IER
|= UART_IER_THRI
;
2624 outb(info
->IER
, info
->base
+ UART_IER
);
2626 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2627 schedule_work(&info
->tqueue
); }
2629 if (!(status
& UART_MSR_CTS
)) {
2630 info
->tty
->hw_stopped
= 1;
2631 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2632 info
->IER
&= ~UART_IER_THRI
;
2633 outb(info
->IER
, info
->base
+ UART_IER
);
2639 info
->flags
&= ~ASYNC_CTS_FLOW
;
2641 outb(info
->MCR
, info
->base
+ UART_MCR
);
2642 if (cflag
& CLOCAL
) {
2643 info
->flags
&= ~ASYNC_CHECK_CD
;
2645 info
->flags
|= ASYNC_CHECK_CD
;
2646 info
->IER
|= UART_IER_MSI
;
2648 outb(info
->IER
, info
->base
+ UART_IER
);
2651 * Set up parity check flag
2653 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2654 if (I_INPCK(info
->tty
))
2655 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2656 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2657 info
->read_status_mask
|= UART_LSR_BI
;
2659 info
->ignore_status_mask
= 0;
2661 if (I_IGNBRK(info
->tty
)) {
2662 info
->ignore_status_mask
|= UART_LSR_BI
;
2663 info
->read_status_mask
|= UART_LSR_BI
;
2665 * If we're ignore parity and break indicators, ignore
2666 * overruns too. (For real raw support).
2668 if (I_IGNPAR(info
->tty
)) {
2669 info
->ignore_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2670 info
->read_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2673 // following add by Victor Yu. 09-02-2002
2674 if (info
->IsMoxaMustChipFlag
) {
2675 spin_lock_irqsave(&info
->slock
, flags
);
2676 SET_MOXA_MUST_XON1_VALUE(info
->base
, START_CHAR(info
->tty
));
2677 SET_MOXA_MUST_XOFF1_VALUE(info
->base
, STOP_CHAR(info
->tty
));
2678 if (I_IXON(info
->tty
)) {
2679 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2681 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2683 if (I_IXOFF(info
->tty
)) {
2684 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2686 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2689 if ( I_IXANY(info->tty) ) {
2690 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2691 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2693 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2694 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2697 spin_unlock_irqrestore(&info
->slock
, flags
);
2699 // above add by Victor Yu. 09-02-2002
2702 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2703 outb(cval
, info
->base
+ UART_LCR
);
2709 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
)
2714 unsigned long flags
;
2716 if (!info
->tty
|| !info
->tty
->termios
)
2722 if (newspd
> info
->MaxCanSetBaudRate
)
2725 info
->realbaud
= newspd
;
2726 if (newspd
== 134) {
2727 quot
= (2 * info
->baud_base
/ 269);
2728 } else if (newspd
) {
2729 quot
= info
->baud_base
/ newspd
;
2738 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
2739 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2742 spin_lock_irqsave(&info
->slock
, flags
);
2743 info
->MCR
|= UART_MCR_DTR
;
2744 outb(info
->MCR
, info
->base
+ UART_MCR
);
2745 spin_unlock_irqrestore(&info
->slock
, flags
);
2747 spin_lock_irqsave(&info
->slock
, flags
);
2748 info
->MCR
&= ~UART_MCR_DTR
;
2749 outb(info
->MCR
, info
->base
+ UART_MCR
);
2750 spin_unlock_irqrestore(&info
->slock
, flags
);
2754 cval
= inb(info
->base
+ UART_LCR
);
2756 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2758 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2759 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2760 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2769 * ------------------------------------------------------------
2770 * friends of mxser_ioctl()
2771 * ------------------------------------------------------------
2773 static int mxser_get_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*retinfo
)
2775 struct serial_struct tmp
;
2779 memset(&tmp
, 0, sizeof(tmp
));
2780 tmp
.type
= info
->type
;
2781 tmp
.line
= info
->port
;
2782 tmp
.port
= info
->base
;
2783 tmp
.irq
= info
->irq
;
2784 tmp
.flags
= info
->flags
;
2785 tmp
.baud_base
= info
->baud_base
;
2786 tmp
.close_delay
= info
->close_delay
;
2787 tmp
.closing_wait
= info
->closing_wait
;
2788 tmp
.custom_divisor
= info
->custom_divisor
;
2790 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2795 static int mxser_set_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*new_info
)
2797 struct serial_struct new_serial
;
2801 if (!new_info
|| !info
->base
)
2803 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2806 if ((new_serial
.irq
!= info
->irq
) || (new_serial
.port
!= info
->base
) || (new_serial
.custom_divisor
!= info
->custom_divisor
) || (new_serial
.baud_base
!= info
->baud_base
))
2809 flags
= info
->flags
& ASYNC_SPD_MASK
;
2811 if (!capable(CAP_SYS_ADMIN
)) {
2812 if ((new_serial
.baud_base
!= info
->baud_base
) || (new_serial
.close_delay
!= info
->close_delay
) || ((new_serial
.flags
& ~ASYNC_USR_MASK
) != (info
->flags
& ~ASYNC_USR_MASK
)))
2814 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) | (new_serial
.flags
& ASYNC_USR_MASK
));
2817 * OK, past this point, all the error checking has been done.
2818 * At this point, we start making changes.....
2820 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) | (new_serial
.flags
& ASYNC_FLAGS
));
2821 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2822 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2823 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2824 info
->tty
->low_latency
= 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2827 /* added by casper, 3/17/2000, for mouse */
2828 info
->type
= new_serial
.type
;
2830 process_txrx_fifo(info
);
2833 if (info
->flags
& ASYNC_INITIALIZED
) {
2834 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2835 mxser_change_speed(info
, NULL
);
2838 retval
= mxser_startup(info
);
2844 * mxser_get_lsr_info - get line status register info
2846 * Purpose: Let user call ioctl() to get info when the UART physically
2847 * is emptied. On bus types like RS485, the transmitter must
2848 * release the bus after transmitting. This must be done when
2849 * the transmit shift register is empty, not be done when the
2850 * transmit holding register is empty. This functionality
2851 * allows an RS485 driver to be written in user space.
2853 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int __user
*value
)
2855 unsigned char status
;
2856 unsigned int result
;
2857 unsigned long flags
;
2859 spin_lock_irqsave(&info
->slock
, flags
);
2860 status
= inb(info
->base
+ UART_LSR
);
2861 spin_unlock_irqrestore(&info
->slock
, flags
);
2862 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2863 return put_user(result
, value
);
2867 * This routine sends a break character out the serial port.
2869 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2871 unsigned long flags
;
2875 set_current_state(TASK_INTERRUPTIBLE
);
2876 spin_lock_irqsave(&info
->slock
, flags
);
2877 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
2878 spin_unlock_irqrestore(&info
->slock
, flags
);
2879 schedule_timeout(duration
);
2880 spin_lock_irqsave(&info
->slock
, flags
);
2881 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
2882 spin_unlock_irqrestore(&info
->slock
, flags
);
2885 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2887 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2888 unsigned char control
, status
;
2889 unsigned long flags
;
2892 if (tty
->index
== MXSER_PORTS
)
2893 return (-ENOIOCTLCMD
);
2894 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2897 control
= info
->MCR
;
2899 spin_lock_irqsave(&info
->slock
, flags
);
2900 status
= inb(info
->base
+ UART_MSR
);
2901 if (status
& UART_MSR_ANY_DELTA
)
2902 mxser_check_modem_status(info
, status
);
2903 spin_unlock_irqrestore(&info
->slock
, flags
);
2904 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2905 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2908 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
, unsigned int set
, unsigned int clear
)
2910 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2911 unsigned long flags
;
2914 if (tty
->index
== MXSER_PORTS
)
2915 return -ENOIOCTLCMD
;
2916 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2919 spin_lock_irqsave(&info
->slock
, flags
);
2921 if (set
& TIOCM_RTS
)
2922 info
->MCR
|= UART_MCR_RTS
;
2923 if (set
& TIOCM_DTR
)
2924 info
->MCR
|= UART_MCR_DTR
;
2926 if (clear
& TIOCM_RTS
)
2927 info
->MCR
&= ~UART_MCR_RTS
;
2928 if (clear
& TIOCM_DTR
)
2929 info
->MCR
&= ~UART_MCR_DTR
;
2931 outb(info
->MCR
, info
->base
+ UART_MCR
);
2932 spin_unlock_irqrestore(&info
->slock
, flags
);
2937 static int mxser_read_register(int, unsigned short *);
2938 static int mxser_program_mode(int);
2939 static void mxser_normal_mode(int);
2941 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2944 unsigned short regs
[16], irq
;
2945 unsigned char scratch
, scratch2
;
2947 hwconf
->IsMoxaMustChipFlag
= MOXA_OTHER_UART
;
2949 id
= mxser_read_register(cap
, regs
);
2950 if (id
== C168_ASIC_ID
) {
2951 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2953 } else if (id
== C104_ASIC_ID
) {
2954 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2956 } else if (id
== C102_ASIC_ID
) {
2957 hwconf
->board_type
= MXSER_BOARD_C102_ISA
;
2959 } else if (id
== CI132_ASIC_ID
) {
2960 hwconf
->board_type
= MXSER_BOARD_CI132
;
2962 } else if (id
== CI134_ASIC_ID
) {
2963 hwconf
->board_type
= MXSER_BOARD_CI134
;
2965 } else if (id
== CI104J_ASIC_ID
) {
2966 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2972 if (hwconf
->ports
== 2) {
2973 irq
= regs
[9] & 0xF000;
2974 irq
= irq
| (irq
>> 4);
2975 if (irq
!= (regs
[9] & 0xFF00))
2976 return (MXSER_ERR_IRQ_CONFLIT
);
2977 } else if (hwconf
->ports
== 4) {
2978 irq
= regs
[9] & 0xF000;
2979 irq
= irq
| (irq
>> 4);
2980 irq
= irq
| (irq
>> 8);
2982 return (MXSER_ERR_IRQ_CONFLIT
);
2983 } else if (hwconf
->ports
== 8) {
2984 irq
= regs
[9] & 0xF000;
2985 irq
= irq
| (irq
>> 4);
2986 irq
= irq
| (irq
>> 8);
2987 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
2988 return (MXSER_ERR_IRQ_CONFLIT
);
2992 return (MXSER_ERR_IRQ
);
2994 hwconf
->irq
= ((int) (irq
& 0xF000) >> 12);
2995 for (i
= 0; i
< 8; i
++)
2996 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
2997 if ((regs
[12] & 0x80) == 0) {
2998 return (MXSER_ERR_VECTOR
);
3000 hwconf
->vector
= (int) regs
[11]; /* interrupt vector */
3002 hwconf
->vector_mask
= 0x00FF;
3004 hwconf
->vector_mask
= 0x000F;
3005 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
3006 if (regs
[12] & bits
) {
3007 hwconf
->baud_base
[i
] = 921600;
3008 hwconf
->MaxCanSetBaudRate
[i
] = 921600; // add by Victor Yu. 09-04-2002
3010 hwconf
->baud_base
[i
] = 115200;
3011 hwconf
->MaxCanSetBaudRate
[i
] = 115200; // add by Victor Yu. 09-04-2002
3014 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
3015 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
3016 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
3017 outb(scratch2
, cap
+ UART_LCR
);
3018 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
3019 scratch
= inb(cap
+ UART_IIR
);
3022 hwconf
->uart_type
= PORT_16550A
;
3024 hwconf
->uart_type
= PORT_16450
;
3029 request_region(hwconf
->ioaddr
[0], 8 * hwconf
->ports
, "mxser(IO)");
3030 request_region(hwconf
->vector
, 1, "mxser(vector)");
3031 return (hwconf
->ports
);
3034 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3035 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3036 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3037 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3038 #define EN_CCMD 0x000 /* Chip's command register */
3039 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3040 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3041 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3042 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3043 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3044 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3045 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3046 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3047 static int mxser_read_register(int port
, unsigned short *regs
)
3049 int i
, k
, value
, id
;
3052 id
= mxser_program_mode(port
);
3055 for (i
= 0; i
< 14; i
++) {
3056 k
= (i
& 0x3F) | 0x180;
3057 for (j
= 0x100; j
> 0; j
>>= 1) {
3058 outb(CHIP_CS
, port
);
3060 outb(CHIP_CS
| CHIP_DO
, port
);
3061 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
3063 outb(CHIP_CS
, port
);
3064 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
3069 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
3070 outb(CHIP_CS
, port
);
3071 outb(CHIP_CS
| CHIP_SK
, port
);
3072 if (inb(port
) & CHIP_DI
)
3078 mxser_normal_mode(port
);
3082 static int mxser_program_mode(int port
)
3085 //unsigned long flags;
3087 spin_lock(&gm_lock
);
3095 //restore_flags(flags);
3096 spin_unlock(&gm_lock
);
3098 id
= inb(port
+ 1) & 0x1F;
3099 if ((id
!= C168_ASIC_ID
) && (id
!= C104_ASIC_ID
) && (id
!= C102_ASIC_ID
) && (id
!= CI132_ASIC_ID
) && (id
!= CI134_ASIC_ID
) && (id
!= CI104J_ASIC_ID
))
3101 for (i
= 0, j
= 0; i
< 4; i
++) {
3105 } else if ((j
== 1) && (n
== 1)) {
3116 static void mxser_normal_mode(int port
)
3120 outb(0xA5, port
+ 1);
3121 outb(0x80, port
+ 3);
3122 outb(12, port
+ 0); /* 9600 bps */
3124 outb(0x03, port
+ 3); /* 8 data bits */
3125 outb(0x13, port
+ 4); /* loop back mode */
3126 for (i
= 0; i
< 16; i
++) {
3128 if ((n
& 0x61) == 0x60)
3133 outb(0x00, port
+ 4);
3136 module_init(mxser_module_init
);
3137 module_exit(mxser_module_exit
);