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/autoconf.h>
42 #include <linux/errno.h>
43 #include <linux/signal.h>
44 #include <linux/sched.h>
45 #include <linux/timer.h>
46 #include <linux/interrupt.h>
47 #include <linux/tty.h>
48 #include <linux/tty_flip.h>
49 #include <linux/serial.h>
50 #include <linux/serial_reg.h>
51 #include <linux/major.h>
52 #include <linux/string.h>
53 #include <linux/fcntl.h>
54 #include <linux/ptrace.h>
55 #include <linux/gfp.h>
56 #include <linux/ioport.h>
58 #include <linux/smp_lock.h>
59 #include <linux/delay.h>
60 #include <linux/pci.h>
62 #include <asm/system.h>
65 #include <asm/bitops.h>
66 #include <asm/uaccess.h>
70 #define MXSER_VERSION "1.8"
71 #define MXSERMAJOR 174
72 #define MXSERCUMAJOR 175
74 #define MXSER_EVENT_TXLOW 1
75 #define MXSER_EVENT_HANGUP 2
77 #define MXSER_BOARDS 4 /* Max. boards */
78 #define MXSER_PORTS 32 /* Max. ports */
79 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
80 #define MXSER_ISR_PASS_LIMIT 256
82 #define MXSER_ERR_IOADDR -1
83 #define MXSER_ERR_IRQ -2
84 #define MXSER_ERR_IRQ_CONFLIT -3
85 #define MXSER_ERR_VECTOR -4
87 #define SERIAL_TYPE_NORMAL 1
88 #define SERIAL_TYPE_CALLOUT 2
90 #define WAKEUP_CHARS 256
92 #define UART_MCR_AFE 0x20
93 #define UART_LSR_SPECIAL 0x1E
95 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK|IXON|IXOFF))
97 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
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_PARM(ioaddr
, "1-4i");
247 MODULE_PARM(ttymajor
, "i");
248 MODULE_PARM(calloutmajor
, "i");
249 MODULE_PARM(verbose
, "i");
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];
283 struct mxser_hwconf
{
290 int ioaddr
[MXSER_PORTS_PER_BOARD
];
291 int baud_base
[MXSER_PORTS_PER_BOARD
];
292 moxa_pci_info pciInfo
;
293 int IsMoxaMustChipFlag
; // add by Victor Yu. 08-30-2002
294 int MaxCanSetBaudRate
[MXSER_PORTS_PER_BOARD
]; // add by Victor Yu. 09-04-2002
295 int opmode_ioaddr
[MXSER_PORTS_PER_BOARD
]; // add by Victor Yu. 01-05-2004
298 struct mxser_struct
{
300 int base
; /* port base address */
301 int irq
; /* port using irq no. */
302 int vector
; /* port irq vector */
303 int vectormask
; /* port vector mask */
305 int rx_trigger
; /* Rx fifo trigger level */
307 int baud_base
; /* max. speed */
308 int flags
; /* defined in tty.h */
309 int type
; /* UART type */
310 struct tty_struct
*tty
;
311 int read_status_mask
;
312 int ignore_status_mask
;
315 int x_char
; /* xon/xoff character */
317 unsigned short closing_wait
;
318 int IER
; /* Interrupt Enable Register */
319 int MCR
; /* Modem control register */
321 int count
; /* # of fd on device */
322 int blocked_open
; /* # of blocked opens */
323 long session
; /* Session of opening process */
324 long pgrp
; /* pgrp of opening process */
325 unsigned char *xmit_buf
;
329 struct work_struct tqueue
;
330 struct termios normal_termios
;
331 struct termios callout_termios
;
332 wait_queue_head_t open_wait
;
333 wait_queue_head_t close_wait
;
334 wait_queue_head_t delta_msr_wait
;
335 struct async_icount icount
; /* kernel counters for the 4 input interrupts */
337 int IsMoxaMustChipFlag
; // add by Victor Yu. 08-30-2002
338 int MaxCanSetBaudRate
; // add by Victor Yu. 09-04-2002
339 int opmode_ioaddr
; // add by Victor Yu. 01-05-2004
340 unsigned char stop_rx
;
341 unsigned char ldisc_stop_rx
;
343 struct mxser_mon mon_data
;
344 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 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");
508 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
509 struct pci_dev
*pdev
;
511 if (mxsercfg
[i
].board_type
== -1)
514 pdev
= mxsercfg
[i
].pciInfo
.pdev
;
515 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
516 if (pdev
!= NULL
) { //PCI
517 release_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
518 release_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3));
520 release_region(mxsercfg
[i
].ioaddr
[0], 8 * mxsercfg
[i
].ports
);
521 release_region(mxsercfg
[i
].vector
, 1);
526 printk(KERN_DEBUG
"Done.\n");
530 static void process_txrx_fifo(struct mxser_struct
*info
)
534 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
535 info
->rx_trigger
= 1;
536 info
->rx_high_water
= 1;
537 info
->rx_low_water
= 1;
538 info
->xmit_fifo_size
= 1;
540 for (i
= 0; i
< UART_INFO_NUM
; i
++) {
541 if (info
->IsMoxaMustChipFlag
== Gpci_uart_info
[i
].type
) {
542 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
543 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
544 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
545 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
552 static int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
554 struct mxser_struct
*info
;
558 n
= board
* MXSER_PORTS_PER_BOARD
;
559 info
= &mxvar_table
[n
];
561 printk(KERN_DEBUG
" ttyM%d - ttyM%d ", n
, n
+ hwconf
->ports
- 1);
562 printk(" max. baud rate = %d bps.\n", 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, hwconf
->ioaddr
[i
] + UART_IER
);
612 n
= board
* MXSER_PORTS_PER_BOARD
;
613 info
= &mxvar_table
[n
];
615 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
), "mxser", info
);
617 printk(KERN_ERR
"Board %d: %s", board
, mxser_brdname
[hwconf
->board_type
- 1]);
618 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info
->irq
);
625 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
)
627 mxsercfg
[board
] = *hwconf
;
631 static int mxser_get_PCI_conf(int busnum
, int devnum
, int board_type
, struct mxser_hwconf
*hwconf
)
635 unsigned int ioaddress
;
636 struct pci_dev
*pdev
= hwconf
->pciInfo
.pdev
;
639 hwconf
->board_type
= board_type
;
640 hwconf
->ports
= mxser_numports
[board_type
- 1];
641 ioaddress
= pci_resource_start(pdev
, 2);
642 request_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2), "mxser(IO)");
644 for (i
= 0; i
< hwconf
->ports
; i
++) {
645 hwconf
->ioaddr
[i
] = ioaddress
+ 8 * i
;
649 ioaddress
= pci_resource_start(pdev
, 3);
650 request_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3), "mxser(vector)");
651 hwconf
->vector
= ioaddress
;
654 hwconf
->irq
= hwconf
->pciInfo
.pdev
->irq
;
656 hwconf
->IsMoxaMustChipFlag
= CheckIsMoxaMust(hwconf
->ioaddr
[0]);
657 hwconf
->uart_type
= PORT_16550A
;
658 hwconf
->vector_mask
= 0;
661 for (i
= 0; i
< hwconf
->ports
; i
++) {
662 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
663 if (Gpci_uart_info
[j
].type
== hwconf
->IsMoxaMustChipFlag
) {
664 hwconf
->MaxCanSetBaudRate
[i
] = Gpci_uart_info
[j
].max_baud
;
666 //exception....CP-102
667 if (board_type
== MXSER_BOARD_CP102
)
668 hwconf
->MaxCanSetBaudRate
[i
] = 921600;
674 if (hwconf
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
) {
675 for (i
= 0; i
< hwconf
->ports
; i
++) {
677 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 4;
679 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 0x0c;
681 outb(0, ioaddress
+ 4); // default set to RS232 mode
682 outb(0, ioaddress
+ 0x0c); //default set to RS232 mode
685 for (i
= 0; i
< hwconf
->ports
; i
++) {
686 hwconf
->vector_mask
|= (1 << i
);
687 hwconf
->baud_base
[i
] = 921600;
693 static int mxser_init(void)
695 int i
, m
, retval
, b
, n
;
696 struct pci_dev
*pdev
= NULL
;
698 unsigned char busnum
, devnum
;
699 struct mxser_hwconf hwconf
;
701 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
704 spin_lock_init(&gm_lock
);
706 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
707 mxsercfg
[i
].board_type
= -1;
710 printk(KERN_INFO
"MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION
);
712 /* Initialize the tty_driver structure */
713 memset(mxvar_sdriver
, 0, sizeof(struct tty_driver
));
714 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
715 mxvar_sdriver
->name
= "ttyM";
716 mxvar_sdriver
->major
= ttymajor
;
717 mxvar_sdriver
->minor_start
= 0;
718 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
719 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
720 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
721 mxvar_sdriver
->init_termios
= tty_std_termios
;
722 mxvar_sdriver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
723 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
;
724 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
725 mxvar_sdriver
->ttys
= mxvar_tty
;
726 mxvar_sdriver
->termios
= mxvar_termios
;
727 mxvar_sdriver
->termios_locked
= mxvar_termios_locked
;
730 memset(mxvar_table
, 0, MXSER_PORTS
* sizeof(struct mxser_struct
));
731 memset(&mxvar_log
, 0, sizeof(struct mxser_log
));
733 memset(&mxser_msr
, 0, sizeof(unsigned char) * (MXSER_PORTS
+ 1));
734 memset(&mon_data_ext
, 0, sizeof(struct mxser_mon_ext
));
735 memset(&mxser_set_baud_method
, 0, sizeof(int) * (MXSER_PORTS
+ 1));
736 memset(&hwconf
, 0, sizeof(struct mxser_hwconf
));
739 /* Start finding ISA boards here */
740 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
742 if (!(cap
= mxserBoardCAP
[b
]))
745 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
748 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
751 if (retval
== MXSER_ERR_IRQ
)
752 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
753 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
754 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
755 else if (retval
== MXSER_ERR_VECTOR
)
756 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
757 else if (retval
== MXSER_ERR_IOADDR
)
758 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
763 hwconf
.pciInfo
.busNum
= 0;
764 hwconf
.pciInfo
.devNum
= 0;
765 hwconf
.pciInfo
.pdev
= NULL
;
767 mxser_getcfg(m
, &hwconf
);
768 //init mxsercfg first, or mxsercfg data is not correct on ISR.
769 //mxser_initbrd will hook ISR.
770 if (mxser_initbrd(m
, &hwconf
) < 0)
777 /* Start finding ISA boards from module arg */
778 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
780 if (!(cap
= ioaddr
[b
]))
783 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
786 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
789 if (retval
== MXSER_ERR_IRQ
)
790 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
791 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
792 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
793 else if (retval
== MXSER_ERR_VECTOR
)
794 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
795 else if (retval
== MXSER_ERR_IOADDR
)
796 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
801 hwconf
.pciInfo
.busNum
= 0;
802 hwconf
.pciInfo
.devNum
= 0;
803 hwconf
.pciInfo
.pdev
= NULL
;
805 mxser_getcfg(m
, &hwconf
);
806 //init mxsercfg first, or mxsercfg data is not correct on ISR.
807 //mxser_initbrd will hook ISR.
808 if (mxser_initbrd(m
, &hwconf
) < 0)
814 /* start finding PCI board here */
816 n
= (sizeof(mxser_pcibrds
) / sizeof(mxser_pcibrds
[0])) - 1;
820 pdev
= pci_find_device(mxser_pcibrds
[b
].vendor
, mxser_pcibrds
[b
].device
, pdev
);
825 hwconf
.pciInfo
.busNum
= busnum
= pdev
->bus
->number
;
826 hwconf
.pciInfo
.devNum
= devnum
= PCI_SLOT(pdev
->devfn
) << 3;
827 hwconf
.pciInfo
.pdev
= pdev
;
828 printk(KERN_INFO
"Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname
[(int) (mxser_pcibrds
[b
].driver_data
) - 1], busnum
, devnum
>> 3);
830 if (m
>= MXSER_BOARDS
) {
831 printk(KERN_ERR
"Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS
);
833 if (pci_enable_device(pdev
)) {
834 printk(KERN_ERR
"Moxa SmartI/O PCI enable fail !\n");
837 retval
= mxser_get_PCI_conf(busnum
, devnum
, (int) mxser_pcibrds
[b
].driver_data
, &hwconf
);
839 if (retval
== MXSER_ERR_IRQ
)
840 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
841 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
842 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
843 else if (retval
== MXSER_ERR_VECTOR
)
844 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
845 else if (retval
== MXSER_ERR_IOADDR
)
846 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
849 mxser_getcfg(m
, &hwconf
);
850 //init mxsercfg first, or mxsercfg data is not correct on ISR.
851 //mxser_initbrd will hook ISR.
852 if (mxser_initbrd(m
, &hwconf
) < 0)
859 retval
= tty_register_driver(mxvar_sdriver
);
861 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family driver !\n");
862 put_tty_driver(mxvar_sdriver
);
864 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
865 if (mxsercfg
[i
].board_type
== -1)
868 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
869 //todo: release io, vector
878 static void mxser_do_softint(void *private_
)
880 struct mxser_struct
*info
= (struct mxser_struct
*) private_
;
881 struct tty_struct
*tty
;
886 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
))
888 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
))
893 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
, struct mxser_struct
*info
)
895 unsigned char status
= 0;
897 status
= inb(baseaddr
+ UART_MSR
);
899 mxser_msr
[port
] &= 0x0F;
900 mxser_msr
[port
] |= status
;
901 status
= mxser_msr
[port
];
909 * This routine is called whenever a serial port is opened. It
910 * enables interrupts for a serial port, linking in its async structure into
911 * the IRQ chain. It also performs the serial-specific
912 * initialization for the tty structure.
914 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
916 struct mxser_struct
*info
;
919 /* initialize driver_data in case something fails */
920 tty
->driver_data
= NULL
;
923 if (line
== MXSER_PORTS
)
925 if (line
< 0 || line
> MXSER_PORTS
)
927 info
= mxvar_table
+ line
;
931 tty
->driver_data
= info
;
934 * Start up serial port
936 retval
= mxser_startup(info
);
940 retval
= mxser_block_til_ready(tty
, filp
, info
);
946 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
947 if (tty
->driver
->subtype
== SERIAL_TYPE_NORMAL
)
948 *tty
->termios
= info
->normal_termios
;
950 *tty
->termios
= info
->callout_termios
;
951 mxser_change_speed(info
, NULL
);
954 info
->session
= current
->signal
->session
;
955 info
->pgrp
= process_group(current
);
956 clear_bit(TTY_DONT_FLIP
, &tty
->flags
);
958 //status = mxser_get_msr(info->base, 0, info->port);
959 //mxser_check_modem_status(info, status);
961 /* unmark here for very high baud rate (ex. 921600 bps) used
963 tty
->low_latency
= 1;
968 * This routine is called when the serial port gets closed. First, we
969 * wait for the last remaining data to be sent. Then, we unlink its
970 * async structure from the interrupt chain if necessary, and we free
971 * that IRQ if nothing is left in the chain.
973 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
975 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
977 unsigned long timeout
;
979 struct tty_ldisc
*ld
;
981 if (tty
->index
== MXSER_PORTS
)
986 spin_lock_irqsave(&info
->slock
, flags
);
988 if (tty_hung_up_p(filp
)) {
989 spin_unlock_irqrestore(&info
->slock
, flags
);
992 if ((tty
->count
== 1) && (info
->count
!= 1)) {
994 * Uh, oh. tty->count is 1, which means that the tty
995 * structure will be freed. Info->count should always
996 * be one in these conditions. If it's greater than
997 * one, we've got real problems, since it means the
998 * serial port won't be shutdown.
1000 printk(KERN_ERR
"mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info
->count
);
1003 if (--info
->count
< 0) {
1004 printk(KERN_ERR
"mxser_close: bad serial port count for ttys%d: %d\n", info
->port
, info
->count
);
1008 spin_unlock_irqrestore(&info
->slock
, flags
);
1011 info
->flags
|= ASYNC_CLOSING
;
1012 spin_unlock_irqrestore(&info
->slock
, flags
);
1014 * Save the termios structure, since this port may have
1015 * separate termios for callout and dialin.
1017 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1018 info
->normal_termios
= *tty
->termios
;
1020 * Now we wait for the transmit buffer to clear; and we notify
1021 * the line discipline to only process XON/XOFF characters.
1024 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1025 tty_wait_until_sent(tty
, info
->closing_wait
);
1027 * At this point we stop accepting input. To do this, we
1028 * disable the receive line status interrupts, and tell the
1029 * interrupt driver to stop checking the data ready bit in the
1030 * line status register.
1032 info
->IER
&= ~UART_IER_RLSI
;
1033 if (info
->IsMoxaMustChipFlag
)
1034 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1036 info->read_status_mask &= ~UART_LSR_DR;
1038 if (info
->flags
& ASYNC_INITIALIZED
) {
1039 outb(info
->IER
, info
->base
+ UART_IER
);
1041 * Before we drop DTR, make sure the UART transmitter
1042 * has completely drained; this is especially
1043 * important if there is a transmit FIFO!
1045 timeout
= jiffies
+ HZ
;
1046 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
1047 schedule_timeout_interruptible(5);
1048 if (time_after(jiffies
, timeout
))
1052 mxser_shutdown(info
);
1054 if (tty
->driver
->flush_buffer
)
1055 tty
->driver
->flush_buffer(tty
);
1057 ld
= tty_ldisc_ref(tty
);
1059 if(ld
->flush_buffer
)
1060 ld
->flush_buffer(tty
);
1061 tty_ldisc_deref(ld
);
1067 if (info
->blocked_open
) {
1068 if (info
->close_delay
)
1069 schedule_timeout_interruptible(info
->close_delay
);
1070 wake_up_interruptible(&info
->open_wait
);
1073 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1074 wake_up_interruptible(&info
->close_wait
);
1078 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1081 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1082 unsigned long flags
;
1084 if (!tty
|| !info
->xmit_buf
)
1088 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1, SERIAL_XMIT_SIZE
- info
->xmit_head
));
1092 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1093 spin_lock_irqsave(&info
->slock
, flags
);
1094 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
1095 info
->xmit_cnt
+= c
;
1096 spin_unlock_irqrestore(&info
->slock
, flags
);
1104 if (info
->xmit_cnt
&& !tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1105 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
1106 spin_lock_irqsave(&info
->slock
, flags
);
1107 info
->IER
|= UART_IER_THRI
;
1108 outb(info
->IER
, info
->base
+ UART_IER
);
1109 spin_unlock_irqrestore(&info
->slock
, flags
);
1115 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1117 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1118 unsigned long flags
;
1120 if (!tty
|| !info
->xmit_buf
)
1123 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1126 spin_lock_irqsave(&info
->slock
, flags
);
1127 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1128 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1130 spin_unlock_irqrestore(&info
->slock
, flags
);
1131 if (!tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1132 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || info
->IsMoxaMustChipFlag
) {
1133 spin_lock_irqsave(&info
->slock
, flags
);
1134 info
->IER
|= UART_IER_THRI
;
1135 outb(info
->IER
, info
->base
+ UART_IER
);
1136 spin_unlock_irqrestore(&info
->slock
, flags
);
1142 static void mxser_flush_chars(struct tty_struct
*tty
)
1144 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1145 unsigned long flags
;
1147 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| !info
->xmit_buf
|| (tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)))
1150 spin_lock_irqsave(&info
->slock
, flags
);
1152 info
->IER
|= UART_IER_THRI
;
1153 outb(info
->IER
, info
->base
+ UART_IER
);
1155 spin_unlock_irqrestore(&info
->slock
, flags
);
1158 static int mxser_write_room(struct tty_struct
*tty
)
1160 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1163 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1169 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1171 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1172 return info
->xmit_cnt
;
1175 static void mxser_flush_buffer(struct tty_struct
*tty
)
1177 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1179 unsigned long flags
;
1182 spin_lock_irqsave(&info
->slock
, flags
);
1183 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1185 /* below added by shinhay */
1186 fcr
= inb(info
->base
+ UART_FCR
);
1187 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
1188 outb(fcr
, info
->base
+ UART_FCR
);
1190 spin_unlock_irqrestore(&info
->slock
, flags
);
1191 /* above added by shinhay */
1193 wake_up_interruptible(&tty
->write_wait
);
1194 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) && tty
->ldisc
.write_wakeup
)
1195 (tty
->ldisc
.write_wakeup
) (tty
);
1198 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1200 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1202 struct async_icount cprev
, cnow
; /* kernel counter temps */
1203 struct serial_icounter_struct __user
*p_cuser
;
1204 unsigned long templ
;
1205 unsigned long flags
;
1206 void __user
*argp
= (void __user
*)arg
;
1208 if (tty
->index
== MXSER_PORTS
)
1209 return (mxser_ioctl_special(cmd
, argp
));
1211 // following add by Victor Yu. 01-05-2004
1212 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1214 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1216 unsigned char val
, mask
;
1219 if (cmd
== MOXA_SET_OP_MODE
) {
1220 if (get_user(opmode
, (int __user
*) argp
))
1222 if (opmode
!= RS232_MODE
&& opmode
!= RS485_2WIRE_MODE
&& opmode
!= RS422_MODE
&& opmode
!= RS485_4WIRE_MODE
)
1226 val
= inb(info
->opmode_ioaddr
);
1228 val
|= (opmode
<< shiftbit
);
1229 outb(val
, info
->opmode_ioaddr
);
1232 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1233 opmode
&= OP_MODE_MASK
;
1234 if (copy_to_user(argp
, &opmode
, sizeof(int)))
1239 // above add by Victor Yu. 01-05-2004
1241 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1242 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1246 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1247 retval
= tty_check_change(tty
);
1250 tty_wait_until_sent(tty
, 0);
1252 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1254 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1255 retval
= tty_check_change(tty
);
1258 tty_wait_until_sent(tty
, 0);
1259 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1262 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) argp
);
1264 if (get_user(templ
, (unsigned long __user
*) argp
))
1267 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1270 return mxser_get_serial_info(info
, argp
);
1272 return mxser_set_serial_info(info
, argp
);
1273 case TIOCSERGETLSR
: /* Get line status register */
1274 return mxser_get_lsr_info(info
, argp
);
1276 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1277 * - mask passed in arg for lines of interest
1278 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1279 * Caller should use TIOCGICOUNT to see which one it was
1282 DECLARE_WAITQUEUE(wait
, current
);
1284 spin_lock_irqsave(&info
->slock
, flags
);
1285 cprev
= info
->icount
; /* note the counters on entry */
1286 spin_unlock_irqrestore(&info
->slock
, flags
);
1288 add_wait_queue(&info
->delta_msr_wait
, &wait
);
1290 spin_lock_irqsave(&info
->slock
, flags
);
1291 cnow
= info
->icount
; /* atomic copy */
1292 spin_unlock_irqrestore(&info
->slock
, flags
);
1294 set_current_state(TASK_INTERRUPTIBLE
);
1295 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
))) {
1299 /* see if a signal did it */
1300 if (signal_pending(current
)) {
1306 current
->state
= TASK_RUNNING
;
1307 remove_wait_queue(&info
->delta_msr_wait
, &wait
);
1312 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1313 * Return: write counters to the user passed counter struct
1314 * NB: both 1->0 and 0->1 transitions are counted except for
1315 * RI where only 0->1 is counted.
1318 spin_lock_irqsave(&info
->slock
, flags
);
1319 cnow
= info
->icount
;
1320 spin_unlock_irqrestore(&info
->slock
, flags
);
1322 /* modified by casper 1/11/2000 */
1323 if (put_user(cnow
.frame
, &p_cuser
->frame
))
1325 if (put_user(cnow
.brk
, &p_cuser
->brk
))
1327 if (put_user(cnow
.overrun
, &p_cuser
->overrun
))
1329 if (put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
))
1331 if (put_user(cnow
.parity
, &p_cuser
->parity
))
1333 if (put_user(cnow
.rx
, &p_cuser
->rx
))
1335 if (put_user(cnow
.tx
, &p_cuser
->tx
))
1337 put_user(cnow
.cts
, &p_cuser
->cts
);
1338 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1339 put_user(cnow
.rng
, &p_cuser
->rng
);
1340 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1344 case MOXA_HighSpeedOn
:
1345 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*) argp
);
1347 case MOXA_SDS_RSTICOUNTER
:{
1348 info
->mon_data
.rxcnt
= 0;
1349 info
->mon_data
.txcnt
= 0;
1352 // (above) added by James.
1353 case MOXA_ASPP_SETBAUD
:{
1355 if (get_user(baud
, (long __user
*) argp
))
1357 mxser_set_baud(info
, baud
);
1360 case MOXA_ASPP_GETBAUD
:
1361 if (copy_to_user(argp
, &info
->realbaud
, sizeof(long)))
1366 case MOXA_ASPP_OQUEUE
:{
1369 len
= mxser_chars_in_buffer(tty
);
1371 lsr
= inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
;
1373 len
+= (lsr
? 0 : 1);
1375 if (copy_to_user(argp
, &len
, sizeof(int)))
1380 case MOXA_ASPP_MON
:{
1382 // info->mon_data.ser_param = tty->termios->c_cflag;
1384 status
= mxser_get_msr(info
->base
, 1, info
->port
, info
);
1385 mxser_check_modem_status(info
, status
);
1387 mcr
= inb(info
->base
+ UART_MCR
);
1388 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1389 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1391 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1393 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1394 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1396 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1398 if (info
->tty
->hw_stopped
)
1399 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1401 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1404 if (copy_to_user(argp
, &info
->mon_data
, sizeof(struct mxser_mon
)))
1411 case MOXA_ASPP_LSTATUS
:{
1412 if (copy_to_user(argp
, &info
->err_shadow
, sizeof(unsigned char)))
1415 info
->err_shadow
= 0;
1419 case MOXA_SET_BAUD_METHOD
:{
1421 if (get_user(method
, (int __user
*) argp
))
1423 mxser_set_baud_method
[info
->port
] = method
;
1424 if (copy_to_user(argp
, &method
, sizeof(int)))
1430 return -ENOIOCTLCMD
;
1436 #define CMSPAR 010000000000
1439 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1441 int i
, result
, status
;
1445 if (copy_to_user(argp
, mxsercfg
, sizeof(struct mxser_hwconf
) * 4))
1448 case MOXA_GET_MAJOR
:
1449 if (copy_to_user(argp
, &ttymajor
, sizeof(int)))
1453 case MOXA_GET_CUMAJOR
:
1454 if (copy_to_user(argp
, &calloutmajor
, sizeof(int)))
1458 case MOXA_CHKPORTENABLE
:
1460 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1461 if (mxvar_table
[i
].base
)
1464 return put_user(result
, (unsigned long __user
*) argp
);
1465 case MOXA_GETDATACOUNT
:
1466 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1469 case MOXA_GETMSTATUS
:
1470 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1472 if (!mxvar_table
[i
].base
) {
1473 GMStatus
[i
].dcd
= 0;
1474 GMStatus
[i
].dsr
= 0;
1475 GMStatus
[i
].cts
= 0;
1479 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1480 GMStatus
[i
].cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1482 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1484 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1485 if (status
& 0x80 /*UART_MSR_DCD */ )
1486 GMStatus
[i
].dcd
= 1;
1488 GMStatus
[i
].dcd
= 0;
1490 if (status
& 0x20 /*UART_MSR_DSR */ )
1491 GMStatus
[i
].dsr
= 1;
1493 GMStatus
[i
].dsr
= 0;
1496 if (status
& 0x10 /*UART_MSR_CTS */ )
1497 GMStatus
[i
].cts
= 1;
1499 GMStatus
[i
].cts
= 0;
1501 if (copy_to_user(argp
, GMStatus
, sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1504 case MOXA_ASPP_MON_EXT
:{
1508 unsigned cflag
, iflag
;
1510 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1512 if (!mxvar_table
[i
].base
)
1515 status
= mxser_get_msr(mxvar_table
[i
].base
, 0, i
, &(mxvar_table
[i
]));
1516 // mxser_check_modem_status(&mxvar_table[i], status);
1517 if (status
& UART_MSR_TERI
)
1518 mxvar_table
[i
].icount
.rng
++;
1519 if (status
& UART_MSR_DDSR
)
1520 mxvar_table
[i
].icount
.dsr
++;
1521 if (status
& UART_MSR_DDCD
)
1522 mxvar_table
[i
].icount
.dcd
++;
1523 if (status
& UART_MSR_DCTS
)
1524 mxvar_table
[i
].icount
.cts
++;
1526 mxvar_table
[i
].mon_data
.modem_status
= status
;
1527 mon_data_ext
.rx_cnt
[i
] = mxvar_table
[i
].mon_data
.rxcnt
;
1528 mon_data_ext
.tx_cnt
[i
] = mxvar_table
[i
].mon_data
.txcnt
;
1529 mon_data_ext
.up_rxcnt
[i
] = mxvar_table
[i
].mon_data
.up_rxcnt
;
1530 mon_data_ext
.up_txcnt
[i
] = mxvar_table
[i
].mon_data
.up_txcnt
;
1531 mon_data_ext
.modem_status
[i
] = mxvar_table
[i
].mon_data
.modem_status
;
1532 mon_data_ext
.baudrate
[i
] = mxvar_table
[i
].realbaud
;
1534 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
) {
1535 cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1536 iflag
= mxvar_table
[i
].normal_termios
.c_iflag
;
1538 cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1539 iflag
= mxvar_table
[i
].tty
->termios
->c_iflag
;
1542 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1544 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1546 mon_data_ext
.parity
[i
] = cflag
& (PARENB
| PARODD
| CMSPAR
);
1548 mon_data_ext
.flowctrl
[i
] = 0x00;
1550 if (cflag
& CRTSCTS
)
1551 mon_data_ext
.flowctrl
[i
] |= 0x03;
1553 if (iflag
& (IXON
| IXOFF
))
1554 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1556 if (mxvar_table
[i
].type
== PORT_16550A
)
1557 mon_data_ext
.fifo
[i
] = 1;
1559 mon_data_ext
.fifo
[i
] = 0;
1563 opmode
= inb(mxvar_table
[i
].opmode_ioaddr
) >> shiftbit
;
1564 opmode
&= OP_MODE_MASK
;
1566 mon_data_ext
.iftype
[i
] = opmode
;
1569 if (copy_to_user(argp
, &mon_data_ext
, sizeof(struct mxser_mon_ext
)))
1576 return -ENOIOCTLCMD
;
1582 static void mxser_stoprx(struct tty_struct
*tty
)
1584 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1585 //unsigned long flags;
1588 info
->ldisc_stop_rx
= 1;
1591 //MX_LOCK(&info->slock);
1592 // following add by Victor Yu. 09-02-2002
1593 if (info
->IsMoxaMustChipFlag
) {
1594 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1595 outb(info
->IER
, info
->base
+ UART_IER
);
1597 // above add by Victor Yu. 09-02-2002
1599 info
->x_char
= STOP_CHAR(tty
);
1600 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1601 outb(0, info
->base
+ UART_IER
);
1602 info
->IER
|= UART_IER_THRI
;
1603 outb(info
->IER
, info
->base
+ UART_IER
); /* force Tx interrupt */
1604 } // add by Victor Yu. 09-02-2002
1605 //MX_UNLOCK(&info->slock);
1608 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1609 //MX_LOCK(&info->slock);
1610 info
->MCR
&= ~UART_MCR_RTS
;
1611 outb(info
->MCR
, info
->base
+ UART_MCR
);
1612 //MX_UNLOCK(&info->slock);
1616 static void mxser_startrx(struct tty_struct
*tty
)
1618 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1619 //unsigned long flags;
1621 info
->ldisc_stop_rx
= 0;
1626 //MX_LOCK(&info->slock);
1628 // following add by Victor Yu. 09-02-2002
1629 if (info
->IsMoxaMustChipFlag
) {
1630 info
->IER
|= MOXA_MUST_RECV_ISR
;
1631 outb(info
->IER
, info
->base
+ UART_IER
);
1633 // above add by Victor Yu. 09-02-2002
1635 info
->x_char
= START_CHAR(tty
);
1636 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1637 outb(0, info
->base
+ UART_IER
); // add by Victor Yu. 09-02-2002
1638 info
->IER
|= UART_IER_THRI
; /* force Tx interrupt */
1639 outb(info
->IER
, info
->base
+ UART_IER
);
1640 } // add by Victor Yu. 09-02-2002
1641 //MX_UNLOCK(&info->slock);
1645 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1646 //MX_LOCK(&info->slock);
1647 info
->MCR
|= UART_MCR_RTS
;
1648 outb(info
->MCR
, info
->base
+ UART_MCR
);
1649 //MX_UNLOCK(&info->slock);
1654 * This routine is called by the upper-layer tty layer to signal that
1655 * incoming characters should be throttled.
1657 static void mxser_throttle(struct tty_struct
*tty
)
1659 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1660 //unsigned long flags;
1661 //MX_LOCK(&info->slock);
1663 //MX_UNLOCK(&info->slock);
1666 static void mxser_unthrottle(struct tty_struct
*tty
)
1668 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1669 //unsigned long flags;
1670 //MX_LOCK(&info->slock);
1672 //MX_UNLOCK(&info->slock);
1675 static void mxser_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1677 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1678 unsigned long flags
;
1680 if ((tty
->termios
->c_cflag
!= old_termios
->c_cflag
) || (RELEVANT_IFLAG(tty
->termios
->c_iflag
) != RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1682 mxser_change_speed(info
, old_termios
);
1684 if ((old_termios
->c_cflag
& CRTSCTS
) && !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1685 tty
->hw_stopped
= 0;
1690 /* Handle sw stopped */
1691 if ((old_termios
->c_iflag
& IXON
) && !(tty
->termios
->c_iflag
& IXON
)) {
1694 // following add by Victor Yu. 09-02-2002
1695 if (info
->IsMoxaMustChipFlag
) {
1696 spin_lock_irqsave(&info
->slock
, flags
);
1697 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
1698 spin_unlock_irqrestore(&info
->slock
, flags
);
1700 // above add by Victor Yu. 09-02-2002
1707 * mxser_stop() and mxser_start()
1709 * This routines are called before setting or resetting tty->stopped.
1710 * They enable or disable transmitter interrupts, as necessary.
1712 static void mxser_stop(struct tty_struct
*tty
)
1714 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1715 unsigned long flags
;
1717 spin_lock_irqsave(&info
->slock
, flags
);
1718 if (info
->IER
& UART_IER_THRI
) {
1719 info
->IER
&= ~UART_IER_THRI
;
1720 outb(info
->IER
, info
->base
+ UART_IER
);
1722 spin_unlock_irqrestore(&info
->slock
, flags
);
1725 static void mxser_start(struct tty_struct
*tty
)
1727 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1728 unsigned long flags
;
1730 spin_lock_irqsave(&info
->slock
, flags
);
1731 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
1732 info
->IER
|= UART_IER_THRI
;
1733 outb(info
->IER
, info
->base
+ UART_IER
);
1735 spin_unlock_irqrestore(&info
->slock
, flags
);
1739 * mxser_wait_until_sent() --- wait until the transmitter is empty
1741 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1743 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1744 unsigned long orig_jiffies
, char_time
;
1747 if (info
->type
== PORT_UNKNOWN
)
1750 if (info
->xmit_fifo_size
== 0)
1751 return; /* Just in case.... */
1753 orig_jiffies
= jiffies
;
1755 * Set the check interval to be 1/5 of the estimated time to
1756 * send a single character, and make it at least 1. The check
1757 * interval should also be less than the timeout.
1759 * Note: we have to use pretty tight timings here to satisfy
1762 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
1763 char_time
= char_time
/ 5;
1766 if (timeout
&& timeout
< char_time
)
1767 char_time
= timeout
;
1769 * If the transmitter hasn't cleared in twice the approximate
1770 * amount of time to send the entire FIFO, it probably won't
1771 * ever clear. This assumes the UART isn't doing flow
1772 * control, which is currently the case. Hence, if it ever
1773 * takes longer than info->timeout, this is probably due to a
1774 * UART bug of some kind. So, we clamp the timeout parameter at
1777 if (!timeout
|| timeout
> 2 * info
->timeout
)
1778 timeout
= 2 * info
->timeout
;
1779 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1780 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1781 printk("jiff=%lu...", jiffies
);
1783 while (!((lsr
= inb(info
->base
+ UART_LSR
)) & UART_LSR_TEMT
)) {
1784 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1785 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1787 schedule_timeout_interruptible(char_time
);
1788 if (signal_pending(current
))
1790 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1793 set_current_state(TASK_RUNNING
);
1795 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1796 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1802 * This routine is called by tty_hangup() when a hangup is signaled.
1804 void mxser_hangup(struct tty_struct
*tty
)
1806 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1808 mxser_flush_buffer(tty
);
1809 mxser_shutdown(info
);
1812 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1814 wake_up_interruptible(&info
->open_wait
);
1818 // added by James 03-12-2004.
1820 * mxser_rs_break() --- routine which turns the break handling on or off
1822 static void mxser_rs_break(struct tty_struct
*tty
, int break_state
)
1824 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1825 unsigned long flags
;
1827 spin_lock_irqsave(&info
->slock
, flags
);
1828 if (break_state
== -1)
1829 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
1831 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
1832 spin_unlock_irqrestore(&info
->slock
, flags
);
1835 // (above) added by James.
1839 * This is the serial driver's generic interrupt routine
1841 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1844 struct mxser_struct
*info
;
1845 struct mxser_struct
*port
;
1846 int max
, irqbits
, bits
, msr
;
1847 int pass_counter
= 0;
1848 int handled
= IRQ_NONE
;
1851 //spin_lock(&gm_lock);
1853 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1854 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1860 if (i
== MXSER_BOARDS
) {
1866 max
= mxser_numports
[mxsercfg
[i
].board_type
- 1];
1868 irqbits
= inb(port
->vector
) & port
->vectormask
;
1869 if (irqbits
== port
->vectormask
) {
1873 handled
= IRQ_HANDLED
;
1874 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1875 if (irqbits
== port
->vectormask
) {
1882 // following add by Victor Yu. 09-13-2002
1883 iir
= inb(info
->base
+ UART_IIR
);
1884 if (iir
& UART_IIR_NO_INT
)
1886 iir
&= MOXA_MUST_IIR_MASK
;
1888 status
= inb(info
->base
+ UART_LSR
);
1889 outb(0x27, info
->base
+ UART_FCR
);
1890 inb(info
->base
+ UART_MSR
);
1893 // above add by Victor Yu. 09-13-2002
1895 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1896 info->IER |= MOXA_MUST_RECV_ISR;
1897 outb(info->IER, info->base + UART_IER);
1902 /* mask by Victor Yu. 09-13-2002
1904 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1907 /* mask by Victor Yu. 09-02-2002
1908 status = inb(info->base + UART_LSR) & info->read_status_mask;
1911 // following add by Victor Yu. 09-02-2002
1912 status
= inb(info
->base
+ UART_LSR
);
1914 if (status
& UART_LSR_PE
) {
1915 info
->err_shadow
|= NPPI_NOTIFY_PARITY
;
1917 if (status
& UART_LSR_FE
) {
1918 info
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
1920 if (status
& UART_LSR_OE
) {
1921 info
->err_shadow
|= NPPI_NOTIFY_HW_OVERRUN
;
1923 if (status
& UART_LSR_BI
)
1924 info
->err_shadow
|= NPPI_NOTIFY_BREAK
;
1926 if (info
->IsMoxaMustChipFlag
) {
1928 if ( (status & 0x02) && !(status & 0x01) ) {
1929 outb(info->base+UART_FCR, 0x23);
1933 if (iir
== MOXA_MUST_IIR_GDA
|| iir
== MOXA_MUST_IIR_RDA
|| iir
== MOXA_MUST_IIR_RTO
|| iir
== MOXA_MUST_IIR_LSR
)
1934 mxser_receive_chars(info
, &status
);
1937 // above add by Victor Yu. 09-02-2002
1939 status
&= info
->read_status_mask
;
1940 if (status
& UART_LSR_DR
)
1941 mxser_receive_chars(info
, &status
);
1943 msr
= inb(info
->base
+ UART_MSR
);
1944 if (msr
& UART_MSR_ANY_DELTA
) {
1945 mxser_check_modem_status(info
, msr
);
1947 // following add by Victor Yu. 09-13-2002
1948 if (info
->IsMoxaMustChipFlag
) {
1949 if ((iir
== 0x02) && (status
& UART_LSR_THRE
)) {
1950 mxser_transmit_chars(info
);
1953 // above add by Victor Yu. 09-13-2002
1955 if (status
& UART_LSR_THRE
) {
1956 /* 8-2-99 by William
1957 if ( info->x_char || (info->xmit_cnt > 0) )
1959 mxser_transmit_chars(info
);
1963 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
1964 break; /* Prevent infinite loops */
1969 //spin_unlock(&gm_lock);
1973 static void mxser_receive_chars(struct mxser_struct
*info
, int *status
)
1975 struct tty_struct
*tty
= info
->tty
;
1976 unsigned char ch
, gdl
;
1981 unsigned long flags
;
1983 spin_lock_irqsave(&info
->slock
, flags
);
1985 recv_room
= tty
->ldisc
.receive_room(tty
);
1986 if ((recv_room
== 0) && (!info
->ldisc_stop_rx
)) {
1987 //mxser_throttle(tty);
1992 // following add by Victor Yu. 09-02-2002
1993 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
1995 if (*status
& UART_LSR_SPECIAL
) {
1998 // following add by Victor Yu. 02-11-2004
1999 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
&& (*status
& MOXA_MUST_LSR_RERR
))
2001 // above add by Victor Yu. 02-14-2004
2002 if (*status
& MOXA_MUST_LSR_RERR
)
2005 gdl
= inb(info
->base
+ MOXA_MUST_GDL_REGISTER
);
2007 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU150_HWID
) // add by Victor Yu. 02-11-2004
2008 gdl
&= MOXA_MUST_GDL_MASK
;
2009 if (gdl
>= recv_room
) {
2010 if (!info
->ldisc_stop_rx
) {
2011 //mxser_throttle(tty);
2017 ch
= inb(info
->base
+ UART_RX
);
2018 tty_insert_flip_char(tty
, ch
, 0);
2021 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2030 // above add by Victor Yu. 09-02-2002
2036 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2043 ch
= inb(info
->base
+ UART_RX
);
2044 // following add by Victor Yu. 09-02-2002
2045 if (info
->IsMoxaMustChipFlag
&& (*status
& UART_LSR_OE
) /*&& !(*status&UART_LSR_DR) */ )
2046 outb(0x23, info
->base
+ UART_FCR
);
2047 *status
&= info
->read_status_mask
;
2048 // above add by Victor Yu. 09-02-2002
2049 if (*status
& info
->ignore_status_mask
) {
2050 if (++ignored
> 100)
2054 if (*status
& UART_LSR_SPECIAL
) {
2055 if (*status
& UART_LSR_BI
) {
2057 /* added by casper 1/11/2000 */
2060 if (info
->flags
& ASYNC_SAK
)
2062 } else if (*status
& UART_LSR_PE
) {
2064 /* added by casper 1/11/2000 */
2065 info
->icount
.parity
++;
2067 } else if (*status
& UART_LSR_FE
) {
2069 /* added by casper 1/11/2000 */
2070 info
->icount
.frame
++;
2072 } else if (*status
& UART_LSR_OE
) {
2074 /* added by casper 1/11/2000 */
2075 info
->icount
.overrun
++;
2079 tty_insert_flip_char(tty
, ch
, flag
);
2081 if (cnt
>= recv_room
) {
2082 if (!info
->ldisc_stop_rx
) {
2083 //mxser_throttle(tty);
2091 // following add by Victor Yu. 09-02-2002
2092 if (info
->IsMoxaMustChipFlag
)
2094 // above add by Victor Yu. 09-02-2002
2096 /* mask by Victor Yu. 09-02-2002
2097 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2099 // following add by Victor Yu. 09-02-2002
2100 *status
= inb(info
->base
+ UART_LSR
);
2101 // above add by Victor Yu. 09-02-2002
2102 } while (*status
& UART_LSR_DR
);
2104 end_intr
: // add by Victor Yu. 09-02-2002
2106 mxvar_log
.rxcnt
[info
->port
] += cnt
;
2107 info
->mon_data
.rxcnt
+= cnt
;
2108 info
->mon_data
.up_rxcnt
+= cnt
;
2109 spin_unlock_irqrestore(&info
->slock
, flags
);
2111 tty_flip_buffer_push(tty
);
2114 static void mxser_transmit_chars(struct mxser_struct
*info
)
2117 unsigned long flags
;
2119 spin_lock_irqsave(&info
->slock
, flags
);
2122 outb(info
->x_char
, info
->base
+ UART_TX
);
2124 mxvar_log
.txcnt
[info
->port
]++;
2125 info
->mon_data
.txcnt
++;
2126 info
->mon_data
.up_txcnt
++;
2128 /* added by casper 1/11/2000 */
2131 spin_unlock_irqrestore(&info
->slock
, flags
);
2135 if (info
->xmit_buf
== 0) {
2136 spin_unlock_irqrestore(&info
->slock
, flags
);
2140 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| (info
->tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
))) {
2141 info
->IER
&= ~UART_IER_THRI
;
2142 outb(info
->IER
, info
->base
+ UART_IER
);
2143 spin_unlock_irqrestore(&info
->slock
, flags
);
2147 cnt
= info
->xmit_cnt
;
2148 count
= info
->xmit_fifo_size
;
2150 outb(info
->xmit_buf
[info
->xmit_tail
++], info
->base
+ UART_TX
);
2151 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2152 if (--info
->xmit_cnt
<= 0)
2154 } while (--count
> 0);
2155 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
2157 // added by James 03-12-2004.
2158 info
->mon_data
.txcnt
+= (cnt
- info
->xmit_cnt
);
2159 info
->mon_data
.up_txcnt
+= (cnt
- info
->xmit_cnt
);
2160 // (above) added by James.
2162 /* added by casper 1/11/2000 */
2163 info
->icount
.tx
+= (cnt
- info
->xmit_cnt
);
2166 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
2167 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2168 schedule_work(&info
->tqueue
);
2170 if (info
->xmit_cnt
<= 0) {
2171 info
->IER
&= ~UART_IER_THRI
;
2172 outb(info
->IER
, info
->base
+ UART_IER
);
2174 spin_unlock_irqrestore(&info
->slock
, flags
);
2177 static void mxser_check_modem_status(struct mxser_struct
*info
, int status
)
2179 /* update input line counters */
2180 if (status
& UART_MSR_TERI
)
2182 if (status
& UART_MSR_DDSR
)
2184 if (status
& UART_MSR_DDCD
)
2186 if (status
& UART_MSR_DCTS
)
2188 info
->mon_data
.modem_status
= status
;
2189 wake_up_interruptible(&info
->delta_msr_wait
);
2192 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
2193 if (status
& UART_MSR_DCD
)
2194 wake_up_interruptible(&info
->open_wait
);
2195 schedule_work(&info
->tqueue
);
2198 if (info
->flags
& ASYNC_CTS_FLOW
) {
2199 if (info
->tty
->hw_stopped
) {
2200 if (status
& UART_MSR_CTS
) {
2201 info
->tty
->hw_stopped
= 0;
2203 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2204 info
->IER
|= UART_IER_THRI
;
2205 outb(info
->IER
, info
->base
+ UART_IER
);
2207 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2208 schedule_work(&info
->tqueue
); }
2210 if (!(status
& UART_MSR_CTS
)) {
2211 info
->tty
->hw_stopped
= 1;
2212 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2213 info
->IER
&= ~UART_IER_THRI
;
2214 outb(info
->IER
, info
->base
+ UART_IER
);
2221 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, struct mxser_struct
*info
)
2223 DECLARE_WAITQUEUE(wait
, current
);
2226 unsigned long flags
;
2229 * If non-blocking mode is set, or the port is not enabled,
2230 * then make the check up front and then exit.
2232 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2233 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2237 if (tty
->termios
->c_cflag
& CLOCAL
)
2241 * Block waiting for the carrier detect and the line to become
2242 * free (i.e., not in use by the callout). While we are in
2243 * this loop, info->count is dropped by one, so that
2244 * mxser_close() knows when to free things. We restore it upon
2245 * exit, either normal or abnormal.
2248 add_wait_queue(&info
->open_wait
, &wait
);
2250 spin_lock_irqsave(&info
->slock
, flags
);
2251 if (!tty_hung_up_p(filp
))
2253 spin_unlock_irqrestore(&info
->slock
, flags
);
2254 info
->blocked_open
++;
2256 spin_lock_irqsave(&info
->slock
, flags
);
2257 outb(inb(info
->base
+ UART_MCR
) | UART_MCR_DTR
| UART_MCR_RTS
, info
->base
+ UART_MCR
);
2258 spin_unlock_irqrestore(&info
->slock
, flags
);
2259 set_current_state(TASK_INTERRUPTIBLE
);
2260 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
2261 if (info
->flags
& ASYNC_HUP_NOTIFY
)
2264 retval
= -ERESTARTSYS
;
2267 if (!(info
->flags
& ASYNC_CLOSING
) && (do_clocal
|| (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
2269 if (signal_pending(current
)) {
2270 retval
= -ERESTARTSYS
;
2275 set_current_state(TASK_RUNNING
);
2276 remove_wait_queue(&info
->open_wait
, &wait
);
2277 if (!tty_hung_up_p(filp
))
2279 info
->blocked_open
--;
2282 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2286 static int mxser_startup(struct mxser_struct
*info
)
2290 unsigned long flags
;
2292 page
= __get_free_page(GFP_KERNEL
);
2296 spin_lock_irqsave(&info
->slock
, flags
);
2298 if (info
->flags
& ASYNC_INITIALIZED
) {
2300 spin_unlock_irqrestore(&info
->slock
, flags
);
2304 if (!info
->base
|| !info
->type
) {
2306 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2308 spin_unlock_irqrestore(&info
->slock
, flags
);
2314 info
->xmit_buf
= (unsigned char *) page
;
2317 * Clear the FIFO buffers and disable them
2318 * (they will be reenabled in mxser_change_speed())
2320 if (info
->IsMoxaMustChipFlag
)
2321 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2323 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2326 * At this point there's no way the LSR could still be 0xFF;
2327 * if it is, then bail out, because there's likely no UART
2330 if (inb(info
->base
+ UART_LSR
) == 0xff) {
2331 spin_unlock_irqrestore(&info
->slock
, flags
);
2332 if (capable(CAP_SYS_ADMIN
)) {
2334 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2341 * Clear the interrupt registers.
2343 (void) inb(info
->base
+ UART_LSR
);
2344 (void) inb(info
->base
+ UART_RX
);
2345 (void) inb(info
->base
+ UART_IIR
);
2346 (void) inb(info
->base
+ UART_MSR
);
2349 * Now, initialize the UART
2351 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
2352 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
2353 outb(info
->MCR
, info
->base
+ UART_MCR
);
2356 * Finally, enable interrupts
2358 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
2359 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2361 // following add by Victor Yu. 08-30-2002
2362 if (info
->IsMoxaMustChipFlag
)
2363 info
->IER
|= MOXA_MUST_IER_EGDAI
;
2364 // above add by Victor Yu. 08-30-2002
2365 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
2368 * And clear the interrupt registers again for luck.
2370 (void) inb(info
->base
+ UART_LSR
);
2371 (void) inb(info
->base
+ UART_RX
);
2372 (void) inb(info
->base
+ UART_IIR
);
2373 (void) inb(info
->base
+ UART_MSR
);
2376 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2377 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2380 * and set the speed of the serial port
2382 spin_unlock_irqrestore(&info
->slock
, flags
);
2383 mxser_change_speed(info
, NULL
);
2385 info
->flags
|= ASYNC_INITIALIZED
;
2390 * This routine will shutdown a serial port; interrupts maybe disabled, and
2391 * DTR is dropped if the hangup on close termio flag is on.
2393 static void mxser_shutdown(struct mxser_struct
*info
)
2395 unsigned long flags
;
2397 if (!(info
->flags
& ASYNC_INITIALIZED
))
2400 spin_lock_irqsave(&info
->slock
, flags
);
2403 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2404 * here so the queue might never be waken up
2406 wake_up_interruptible(&info
->delta_msr_wait
);
2409 * Free the IRQ, if necessary
2411 if (info
->xmit_buf
) {
2412 free_page((unsigned long) info
->xmit_buf
);
2413 info
->xmit_buf
= NULL
;
2417 outb(0x00, info
->base
+ UART_IER
);
2419 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
2420 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
2421 outb(info
->MCR
, info
->base
+ UART_MCR
);
2423 /* clear Rx/Tx FIFO's */
2424 // following add by Victor Yu. 08-30-2002
2425 if (info
->IsMoxaMustChipFlag
)
2426 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2428 // above add by Victor Yu. 08-30-2002
2429 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2431 /* read data port to reset things */
2432 (void) inb(info
->base
+ UART_RX
);
2435 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2437 info
->flags
&= ~ASYNC_INITIALIZED
;
2439 // following add by Victor Yu. 09-23-2002
2440 if (info
->IsMoxaMustChipFlag
) {
2441 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->base
);
2443 // above add by Victor Yu. 09-23-2002
2445 spin_unlock_irqrestore(&info
->slock
, flags
);
2449 * This routine is called to set the UART divisor registers to match
2450 * the specified baud rate for a serial port.
2452 static int mxser_change_speed(struct mxser_struct
*info
, struct termios
*old_termios
)
2454 unsigned cflag
, cval
, fcr
;
2456 unsigned char status
;
2458 unsigned long flags
;
2461 if (!info
->tty
|| !info
->tty
->termios
)
2463 cflag
= info
->tty
->termios
->c_cflag
;
2469 #define B921600 (B460800 +1)
2471 if (mxser_set_baud_method
[info
->port
] == 0) {
2472 switch (cflag
& (CBAUD
| CBAUDEX
)) {
2537 mxser_set_baud(info
, baud
);
2540 /* byte size and parity */
2541 switch (cflag
& CSIZE
) {
2556 break; /* too keep GCC shut... */
2561 cval
|= UART_LCR_PARITY
;
2562 if (!(cflag
& PARODD
)) {
2563 cval
|= UART_LCR_EPAR
;
2566 cval
|= UART_LCR_SPAR
;
2568 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
2569 if (info
->IsMoxaMustChipFlag
) {
2570 fcr
= UART_FCR_ENABLE_FIFO
;
2571 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2572 SET_MOXA_MUST_FIFO_VALUE(info
);
2576 fcr
= UART_FCR_ENABLE_FIFO
;
2577 // following add by Victor Yu. 08-30-2002
2578 if (info
->IsMoxaMustChipFlag
) {
2579 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2580 SET_MOXA_MUST_FIFO_VALUE(info
);
2582 // above add by Victor Yu. 08-30-2002
2584 switch (info
->rx_trigger
) {
2586 fcr
|= UART_FCR_TRIGGER_1
;
2589 fcr
|= UART_FCR_TRIGGER_4
;
2592 fcr
|= UART_FCR_TRIGGER_8
;
2595 fcr
|= UART_FCR_TRIGGER_14
;
2601 /* CTS flow control flag and modem status interrupts */
2602 info
->IER
&= ~UART_IER_MSI
;
2603 info
->MCR
&= ~UART_MCR_AFE
;
2604 if (cflag
& CRTSCTS
) {
2605 info
->flags
|= ASYNC_CTS_FLOW
;
2606 info
->IER
|= UART_IER_MSI
;
2607 if ((info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
2608 info
->MCR
|= UART_MCR_AFE
;
2609 //status = mxser_get_msr(info->base, 0, info->port);
2610 /* save_flags(flags);
2612 status = inb(baseaddr + UART_MSR);
2613 restore_flags(flags);*/
2614 //mxser_check_modem_status(info, status);
2616 //status = mxser_get_msr(info->base, 0, info->port);
2618 //MX_LOCK(&info->slock);
2619 status
= inb(info
->base
+ UART_MSR
);
2620 //MX_UNLOCK(&info->slock);
2621 if (info
->tty
->hw_stopped
) {
2622 if (status
& UART_MSR_CTS
) {
2623 info
->tty
->hw_stopped
= 0;
2624 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2625 info
->IER
|= UART_IER_THRI
;
2626 outb(info
->IER
, info
->base
+ UART_IER
);
2628 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2629 schedule_work(&info
->tqueue
); }
2631 if (!(status
& UART_MSR_CTS
)) {
2632 info
->tty
->hw_stopped
= 1;
2633 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2634 info
->IER
&= ~UART_IER_THRI
;
2635 outb(info
->IER
, info
->base
+ UART_IER
);
2641 info
->flags
&= ~ASYNC_CTS_FLOW
;
2643 outb(info
->MCR
, info
->base
+ UART_MCR
);
2644 if (cflag
& CLOCAL
) {
2645 info
->flags
&= ~ASYNC_CHECK_CD
;
2647 info
->flags
|= ASYNC_CHECK_CD
;
2648 info
->IER
|= UART_IER_MSI
;
2650 outb(info
->IER
, info
->base
+ UART_IER
);
2653 * Set up parity check flag
2655 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2656 if (I_INPCK(info
->tty
))
2657 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2658 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2659 info
->read_status_mask
|= UART_LSR_BI
;
2661 info
->ignore_status_mask
= 0;
2663 if (I_IGNBRK(info
->tty
)) {
2664 info
->ignore_status_mask
|= UART_LSR_BI
;
2665 info
->read_status_mask
|= UART_LSR_BI
;
2667 * If we're ignore parity and break indicators, ignore
2668 * overruns too. (For real raw support).
2670 if (I_IGNPAR(info
->tty
)) {
2671 info
->ignore_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2672 info
->read_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2675 // following add by Victor Yu. 09-02-2002
2676 if (info
->IsMoxaMustChipFlag
) {
2677 spin_lock_irqsave(&info
->slock
, flags
);
2678 SET_MOXA_MUST_XON1_VALUE(info
->base
, START_CHAR(info
->tty
));
2679 SET_MOXA_MUST_XOFF1_VALUE(info
->base
, STOP_CHAR(info
->tty
));
2680 if (I_IXON(info
->tty
)) {
2681 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2683 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2685 if (I_IXOFF(info
->tty
)) {
2686 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2688 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2691 if ( I_IXANY(info->tty) ) {
2692 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2693 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2695 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2696 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2699 spin_unlock_irqrestore(&info
->slock
, flags
);
2701 // above add by Victor Yu. 09-02-2002
2704 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2705 outb(cval
, info
->base
+ UART_LCR
);
2711 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
)
2716 unsigned long flags
;
2718 if (!info
->tty
|| !info
->tty
->termios
)
2724 if (newspd
> info
->MaxCanSetBaudRate
)
2727 info
->realbaud
= newspd
;
2728 if (newspd
== 134) {
2729 quot
= (2 * info
->baud_base
/ 269);
2730 } else if (newspd
) {
2731 quot
= info
->baud_base
/ newspd
;
2740 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
2741 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2744 spin_lock_irqsave(&info
->slock
, flags
);
2745 info
->MCR
|= UART_MCR_DTR
;
2746 outb(info
->MCR
, info
->base
+ UART_MCR
);
2747 spin_unlock_irqrestore(&info
->slock
, flags
);
2749 spin_lock_irqsave(&info
->slock
, flags
);
2750 info
->MCR
&= ~UART_MCR_DTR
;
2751 outb(info
->MCR
, info
->base
+ UART_MCR
);
2752 spin_unlock_irqrestore(&info
->slock
, flags
);
2756 cval
= inb(info
->base
+ UART_LCR
);
2758 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2760 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2761 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2762 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2771 * ------------------------------------------------------------
2772 * friends of mxser_ioctl()
2773 * ------------------------------------------------------------
2775 static int mxser_get_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*retinfo
)
2777 struct serial_struct tmp
;
2781 memset(&tmp
, 0, sizeof(tmp
));
2782 tmp
.type
= info
->type
;
2783 tmp
.line
= info
->port
;
2784 tmp
.port
= info
->base
;
2785 tmp
.irq
= info
->irq
;
2786 tmp
.flags
= info
->flags
;
2787 tmp
.baud_base
= info
->baud_base
;
2788 tmp
.close_delay
= info
->close_delay
;
2789 tmp
.closing_wait
= info
->closing_wait
;
2790 tmp
.custom_divisor
= info
->custom_divisor
;
2792 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2797 static int mxser_set_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*new_info
)
2799 struct serial_struct new_serial
;
2803 if (!new_info
|| !info
->base
)
2805 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2808 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
))
2811 flags
= info
->flags
& ASYNC_SPD_MASK
;
2813 if (!capable(CAP_SYS_ADMIN
)) {
2814 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
)))
2816 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) | (new_serial
.flags
& ASYNC_USR_MASK
));
2819 * OK, past this point, all the error checking has been done.
2820 * At this point, we start making changes.....
2822 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) | (new_serial
.flags
& ASYNC_FLAGS
));
2823 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2824 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2825 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2826 info
->tty
->low_latency
= 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2829 /* added by casper, 3/17/2000, for mouse */
2830 info
->type
= new_serial
.type
;
2832 process_txrx_fifo(info
);
2835 if (info
->flags
& ASYNC_INITIALIZED
) {
2836 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2837 mxser_change_speed(info
, NULL
);
2840 retval
= mxser_startup(info
);
2846 * mxser_get_lsr_info - get line status register info
2848 * Purpose: Let user call ioctl() to get info when the UART physically
2849 * is emptied. On bus types like RS485, the transmitter must
2850 * release the bus after transmitting. This must be done when
2851 * the transmit shift register is empty, not be done when the
2852 * transmit holding register is empty. This functionality
2853 * allows an RS485 driver to be written in user space.
2855 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int __user
*value
)
2857 unsigned char status
;
2858 unsigned int result
;
2859 unsigned long flags
;
2861 spin_lock_irqsave(&info
->slock
, flags
);
2862 status
= inb(info
->base
+ UART_LSR
);
2863 spin_unlock_irqrestore(&info
->slock
, flags
);
2864 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2865 return put_user(result
, value
);
2869 * This routine sends a break character out the serial port.
2871 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2873 unsigned long flags
;
2877 set_current_state(TASK_INTERRUPTIBLE
);
2878 spin_lock_irqsave(&info
->slock
, flags
);
2879 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
2880 spin_unlock_irqrestore(&info
->slock
, flags
);
2881 schedule_timeout(duration
);
2882 spin_lock_irqsave(&info
->slock
, flags
);
2883 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
2884 spin_unlock_irqrestore(&info
->slock
, flags
);
2887 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2889 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2890 unsigned char control
, status
;
2891 unsigned long flags
;
2894 if (tty
->index
== MXSER_PORTS
)
2895 return (-ENOIOCTLCMD
);
2896 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2899 control
= info
->MCR
;
2901 spin_lock_irqsave(&info
->slock
, flags
);
2902 status
= inb(info
->base
+ UART_MSR
);
2903 if (status
& UART_MSR_ANY_DELTA
)
2904 mxser_check_modem_status(info
, status
);
2905 spin_unlock_irqrestore(&info
->slock
, flags
);
2906 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2907 ((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);
2910 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
, unsigned int set
, unsigned int clear
)
2912 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2913 unsigned long flags
;
2916 if (tty
->index
== MXSER_PORTS
)
2917 return -ENOIOCTLCMD
;
2918 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2921 spin_lock_irqsave(&info
->slock
, flags
);
2923 if (set
& TIOCM_RTS
)
2924 info
->MCR
|= UART_MCR_RTS
;
2925 if (set
& TIOCM_DTR
)
2926 info
->MCR
|= UART_MCR_DTR
;
2928 if (clear
& TIOCM_RTS
)
2929 info
->MCR
&= ~UART_MCR_RTS
;
2930 if (clear
& TIOCM_DTR
)
2931 info
->MCR
&= ~UART_MCR_DTR
;
2933 outb(info
->MCR
, info
->base
+ UART_MCR
);
2934 spin_unlock_irqrestore(&info
->slock
, flags
);
2939 static int mxser_read_register(int, unsigned short *);
2940 static int mxser_program_mode(int);
2941 static void mxser_normal_mode(int);
2943 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2946 unsigned short regs
[16], irq
;
2947 unsigned char scratch
, scratch2
;
2949 hwconf
->IsMoxaMustChipFlag
= MOXA_OTHER_UART
;
2951 id
= mxser_read_register(cap
, regs
);
2952 if (id
== C168_ASIC_ID
) {
2953 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2955 } else if (id
== C104_ASIC_ID
) {
2956 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2958 } else if (id
== C102_ASIC_ID
) {
2959 hwconf
->board_type
= MXSER_BOARD_C102_ISA
;
2961 } else if (id
== CI132_ASIC_ID
) {
2962 hwconf
->board_type
= MXSER_BOARD_CI132
;
2964 } else if (id
== CI134_ASIC_ID
) {
2965 hwconf
->board_type
= MXSER_BOARD_CI134
;
2967 } else if (id
== CI104J_ASIC_ID
) {
2968 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2974 if (hwconf
->ports
== 2) {
2975 irq
= regs
[9] & 0xF000;
2976 irq
= irq
| (irq
>> 4);
2977 if (irq
!= (regs
[9] & 0xFF00))
2978 return (MXSER_ERR_IRQ_CONFLIT
);
2979 } else if (hwconf
->ports
== 4) {
2980 irq
= regs
[9] & 0xF000;
2981 irq
= irq
| (irq
>> 4);
2982 irq
= irq
| (irq
>> 8);
2984 return (MXSER_ERR_IRQ_CONFLIT
);
2985 } else if (hwconf
->ports
== 8) {
2986 irq
= regs
[9] & 0xF000;
2987 irq
= irq
| (irq
>> 4);
2988 irq
= irq
| (irq
>> 8);
2989 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
2990 return (MXSER_ERR_IRQ_CONFLIT
);
2994 return (MXSER_ERR_IRQ
);
2996 hwconf
->irq
= ((int) (irq
& 0xF000) >> 12);
2997 for (i
= 0; i
< 8; i
++)
2998 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
2999 if ((regs
[12] & 0x80) == 0) {
3000 return (MXSER_ERR_VECTOR
);
3002 hwconf
->vector
= (int) regs
[11]; /* interrupt vector */
3004 hwconf
->vector_mask
= 0x00FF;
3006 hwconf
->vector_mask
= 0x000F;
3007 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
3008 if (regs
[12] & bits
) {
3009 hwconf
->baud_base
[i
] = 921600;
3010 hwconf
->MaxCanSetBaudRate
[i
] = 921600; // add by Victor Yu. 09-04-2002
3012 hwconf
->baud_base
[i
] = 115200;
3013 hwconf
->MaxCanSetBaudRate
[i
] = 115200; // add by Victor Yu. 09-04-2002
3016 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
3017 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
3018 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
3019 outb(scratch2
, cap
+ UART_LCR
);
3020 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
3021 scratch
= inb(cap
+ UART_IIR
);
3024 hwconf
->uart_type
= PORT_16550A
;
3026 hwconf
->uart_type
= PORT_16450
;
3031 request_region(hwconf
->ioaddr
[0], 8 * hwconf
->ports
, "mxser(IO)");
3032 request_region(hwconf
->vector
, 1, "mxser(vector)");
3033 return (hwconf
->ports
);
3036 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3037 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3038 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3039 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3040 #define EN_CCMD 0x000 /* Chip's command register */
3041 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3042 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3043 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3044 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3045 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3046 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3047 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3048 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3049 static int mxser_read_register(int port
, unsigned short *regs
)
3051 int i
, k
, value
, id
;
3054 id
= mxser_program_mode(port
);
3057 for (i
= 0; i
< 14; i
++) {
3058 k
= (i
& 0x3F) | 0x180;
3059 for (j
= 0x100; j
> 0; j
>>= 1) {
3060 outb(CHIP_CS
, port
);
3062 outb(CHIP_CS
| CHIP_DO
, port
);
3063 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
3065 outb(CHIP_CS
, port
);
3066 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
3071 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
3072 outb(CHIP_CS
, port
);
3073 outb(CHIP_CS
| CHIP_SK
, port
);
3074 if (inb(port
) & CHIP_DI
)
3080 mxser_normal_mode(port
);
3084 static int mxser_program_mode(int port
)
3087 //unsigned long flags;
3089 spin_lock(&gm_lock
);
3097 //restore_flags(flags);
3098 spin_unlock(&gm_lock
);
3100 id
= inb(port
+ 1) & 0x1F;
3101 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
))
3103 for (i
= 0, j
= 0; i
< 4; i
++) {
3107 } else if ((j
== 1) && (n
== 1)) {
3118 static void mxser_normal_mode(int port
)
3122 outb(0xA5, port
+ 1);
3123 outb(0x80, port
+ 3);
3124 outb(12, port
+ 0); /* 9600 bps */
3126 outb(0x03, port
+ 3); /* 8 data bits */
3127 outb(0x13, port
+ 4); /* loop back mode */
3128 for (i
= 0; i
< 16; i
++) {
3130 if ((n
& 0x61) == 0x60)
3135 outb(0x00, port
+ 4);
3138 module_init(mxser_module_init
);
3139 module_exit(mxser_module_exit
);