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 .tiocmget
= mxser_tiocmget
,
474 .tiocmset
= mxser_tiocmset
,
478 * The MOXA Smartio/Industio serial driver boot-time initialization code!
481 static int __init
mxser_module_init(void)
486 printk(KERN_DEBUG
"Loading module mxser ...\n");
489 printk(KERN_DEBUG
"Done.\n");
493 static void __exit
mxser_module_exit(void)
498 printk(KERN_DEBUG
"Unloading module mxser ...\n");
500 if ((err
|= tty_unregister_driver(mxvar_sdriver
)))
501 printk(KERN_ERR
"Couldn't unregister MOXA Smartio/Industio family serial driver\n");
503 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
504 struct pci_dev
*pdev
;
506 if (mxsercfg
[i
].board_type
== -1)
509 pdev
= mxsercfg
[i
].pciInfo
.pdev
;
510 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
511 if (pdev
!= NULL
) { //PCI
512 release_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
513 release_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3));
515 release_region(mxsercfg
[i
].ioaddr
[0], 8 * mxsercfg
[i
].ports
);
516 release_region(mxsercfg
[i
].vector
, 1);
521 printk(KERN_DEBUG
"Done.\n");
525 static void process_txrx_fifo(struct mxser_struct
*info
)
529 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
530 info
->rx_trigger
= 1;
531 info
->rx_high_water
= 1;
532 info
->rx_low_water
= 1;
533 info
->xmit_fifo_size
= 1;
535 for (i
= 0; i
< UART_INFO_NUM
; i
++) {
536 if (info
->IsMoxaMustChipFlag
== Gpci_uart_info
[i
].type
) {
537 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
538 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
539 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
540 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
547 static int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
549 struct mxser_struct
*info
;
553 n
= board
* MXSER_PORTS_PER_BOARD
;
554 info
= &mxvar_table
[n
];
556 printk(KERN_DEBUG
" ttyM%d - ttyM%d ", n
, n
+ hwconf
->ports
- 1);
557 printk(" max. baud rate = %d bps.\n", hwconf
->MaxCanSetBaudRate
[0]);
560 for (i
= 0; i
< hwconf
->ports
; i
++, n
++, info
++) {
562 info
->base
= hwconf
->ioaddr
[i
];
563 info
->irq
= hwconf
->irq
;
564 info
->vector
= hwconf
->vector
;
565 info
->vectormask
= hwconf
->vector_mask
;
566 info
->opmode_ioaddr
= hwconf
->opmode_ioaddr
[i
]; // add by Victor Yu. 01-05-2004
568 info
->ldisc_stop_rx
= 0;
570 info
->IsMoxaMustChipFlag
= hwconf
->IsMoxaMustChipFlag
;
571 //Enhance mode enabled here
572 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
573 ENABLE_MOXA_MUST_ENCHANCE_MODE(info
->base
);
576 info
->flags
= ASYNC_SHARE_IRQ
;
577 info
->type
= hwconf
->uart_type
;
578 info
->baud_base
= hwconf
->baud_base
[i
];
580 info
->MaxCanSetBaudRate
= hwconf
->MaxCanSetBaudRate
[i
];
582 process_txrx_fifo(info
);
585 info
->custom_divisor
= hwconf
->baud_base
[i
] * 16;
586 info
->close_delay
= 5 * HZ
/ 10;
587 info
->closing_wait
= 30 * HZ
;
588 INIT_WORK(&info
->tqueue
, mxser_do_softint
, info
);
589 info
->normal_termios
= mxvar_sdriver
->init_termios
;
590 init_waitqueue_head(&info
->open_wait
);
591 init_waitqueue_head(&info
->close_wait
);
592 init_waitqueue_head(&info
->delta_msr_wait
);
593 memset(&info
->mon_data
, 0, sizeof(struct mxser_mon
));
594 info
->err_shadow
= 0;
595 spin_lock_init(&info
->slock
);
598 * Allocate the IRQ if necessary
602 /* before set INT ISR, disable all int */
603 for (i
= 0; i
< hwconf
->ports
; i
++) {
604 outb(inb(hwconf
->ioaddr
[i
] + UART_IER
) & 0xf0, hwconf
->ioaddr
[i
] + UART_IER
);
607 n
= board
* MXSER_PORTS_PER_BOARD
;
608 info
= &mxvar_table
[n
];
610 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
), "mxser", info
);
612 printk(KERN_ERR
"Board %d: %s", board
, mxser_brdname
[hwconf
->board_type
- 1]);
613 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info
->irq
);
620 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
)
622 mxsercfg
[board
] = *hwconf
;
626 static int mxser_get_PCI_conf(int busnum
, int devnum
, int board_type
, struct mxser_hwconf
*hwconf
)
630 unsigned int ioaddress
;
631 struct pci_dev
*pdev
= hwconf
->pciInfo
.pdev
;
634 hwconf
->board_type
= board_type
;
635 hwconf
->ports
= mxser_numports
[board_type
- 1];
636 ioaddress
= pci_resource_start(pdev
, 2);
637 request_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2), "mxser(IO)");
639 for (i
= 0; i
< hwconf
->ports
; i
++) {
640 hwconf
->ioaddr
[i
] = ioaddress
+ 8 * i
;
644 ioaddress
= pci_resource_start(pdev
, 3);
645 request_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3), "mxser(vector)");
646 hwconf
->vector
= ioaddress
;
649 hwconf
->irq
= hwconf
->pciInfo
.pdev
->irq
;
651 hwconf
->IsMoxaMustChipFlag
= CheckIsMoxaMust(hwconf
->ioaddr
[0]);
652 hwconf
->uart_type
= PORT_16550A
;
653 hwconf
->vector_mask
= 0;
656 for (i
= 0; i
< hwconf
->ports
; i
++) {
657 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
658 if (Gpci_uart_info
[j
].type
== hwconf
->IsMoxaMustChipFlag
) {
659 hwconf
->MaxCanSetBaudRate
[i
] = Gpci_uart_info
[j
].max_baud
;
661 //exception....CP-102
662 if (board_type
== MXSER_BOARD_CP102
)
663 hwconf
->MaxCanSetBaudRate
[i
] = 921600;
669 if (hwconf
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
) {
670 for (i
= 0; i
< hwconf
->ports
; i
++) {
672 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 4;
674 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 0x0c;
676 outb(0, ioaddress
+ 4); // default set to RS232 mode
677 outb(0, ioaddress
+ 0x0c); //default set to RS232 mode
680 for (i
= 0; i
< hwconf
->ports
; i
++) {
681 hwconf
->vector_mask
|= (1 << i
);
682 hwconf
->baud_base
[i
] = 921600;
688 static int mxser_init(void)
690 int i
, m
, retval
, b
, n
;
692 struct pci_dev
*pdev
= NULL
;
694 unsigned char busnum
, devnum
;
695 struct mxser_hwconf hwconf
;
697 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
700 spin_lock_init(&gm_lock
);
702 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
703 mxsercfg
[i
].board_type
= -1;
706 printk(KERN_INFO
"MOXA Smartio/Industio family driver version %s\n", MXSER_VERSION
);
708 /* Initialize the tty_driver structure */
709 memset(mxvar_sdriver
, 0, sizeof(struct tty_driver
));
710 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
711 mxvar_sdriver
->name
= "ttyM";
712 mxvar_sdriver
->major
= ttymajor
;
713 mxvar_sdriver
->minor_start
= 0;
714 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
715 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
716 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
717 mxvar_sdriver
->init_termios
= tty_std_termios
;
718 mxvar_sdriver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
719 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
;
720 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
721 mxvar_sdriver
->ttys
= mxvar_tty
;
722 mxvar_sdriver
->termios
= mxvar_termios
;
723 mxvar_sdriver
->termios_locked
= mxvar_termios_locked
;
725 mxvar_sdriver
->open
= mxser_open
;
726 mxvar_sdriver
->close
= mxser_close
;
727 mxvar_sdriver
->write
= mxser_write
;
728 mxvar_sdriver
->put_char
= mxser_put_char
;
729 mxvar_sdriver
->flush_chars
= mxser_flush_chars
;
730 mxvar_sdriver
->write_room
= mxser_write_room
;
731 mxvar_sdriver
->chars_in_buffer
= mxser_chars_in_buffer
;
732 mxvar_sdriver
->flush_buffer
= mxser_flush_buffer
;
733 mxvar_sdriver
->ioctl
= mxser_ioctl
;
734 mxvar_sdriver
->throttle
= mxser_throttle
;
735 mxvar_sdriver
->unthrottle
= mxser_unthrottle
;
736 mxvar_sdriver
->set_termios
= mxser_set_termios
;
737 mxvar_sdriver
->stop
= mxser_stop
;
738 mxvar_sdriver
->start
= mxser_start
;
739 mxvar_sdriver
->hangup
= mxser_hangup
;
740 mxvar_sdriver
->break_ctl
= mxser_rs_break
;
741 mxvar_sdriver
->wait_until_sent
= mxser_wait_until_sent
;
744 memset(mxvar_table
, 0, MXSER_PORTS
* sizeof(struct mxser_struct
));
745 memset(&mxvar_log
, 0, sizeof(struct mxser_log
));
747 memset(&mxser_msr
, 0, sizeof(unsigned char) * (MXSER_PORTS
+ 1));
748 memset(&mon_data_ext
, 0, sizeof(struct mxser_mon_ext
));
749 memset(&mxser_set_baud_method
, 0, sizeof(int) * (MXSER_PORTS
+ 1));
750 memset(&hwconf
, 0, sizeof(struct mxser_hwconf
));
753 /* Start finding ISA boards here */
754 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
756 if (!(cap
= mxserBoardCAP
[b
]))
759 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
762 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
765 if (retval
== MXSER_ERR_IRQ
)
766 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
767 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
768 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
769 else if (retval
== MXSER_ERR_VECTOR
)
770 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
771 else if (retval
== MXSER_ERR_IOADDR
)
772 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
777 hwconf
.pciInfo
.busNum
= 0;
778 hwconf
.pciInfo
.devNum
= 0;
779 hwconf
.pciInfo
.pdev
= NULL
;
781 mxser_getcfg(m
, &hwconf
);
782 //init mxsercfg first, or mxsercfg data is not correct on ISR.
783 //mxser_initbrd will hook ISR.
784 if (mxser_initbrd(m
, &hwconf
) < 0)
791 /* Start finding ISA boards from module arg */
792 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
794 if (!(cap
= ioaddr
[b
]))
797 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
800 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n", mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
803 if (retval
== MXSER_ERR_IRQ
)
804 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
805 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
806 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
807 else if (retval
== MXSER_ERR_VECTOR
)
808 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
809 else if (retval
== MXSER_ERR_IOADDR
)
810 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
815 hwconf
.pciInfo
.busNum
= 0;
816 hwconf
.pciInfo
.devNum
= 0;
817 hwconf
.pciInfo
.pdev
= NULL
;
819 mxser_getcfg(m
, &hwconf
);
820 //init mxsercfg first, or mxsercfg data is not correct on ISR.
821 //mxser_initbrd will hook ISR.
822 if (mxser_initbrd(m
, &hwconf
) < 0)
828 /* start finding PCI board here */
830 n
= (sizeof(mxser_pcibrds
) / sizeof(mxser_pcibrds
[0])) - 1;
834 pdev
= pci_find_device(mxser_pcibrds
[b
].vendor
, mxser_pcibrds
[b
].device
, pdev
);
839 hwconf
.pciInfo
.busNum
= busnum
= pdev
->bus
->number
;
840 hwconf
.pciInfo
.devNum
= devnum
= PCI_SLOT(pdev
->devfn
) << 3;
841 hwconf
.pciInfo
.pdev
= pdev
;
842 printk(KERN_INFO
"Found MOXA %s board(BusNo=%d,DevNo=%d)\n", mxser_brdname
[(int) (mxser_pcibrds
[b
].driver_data
) - 1], busnum
, devnum
>> 3);
844 if (m
>= MXSER_BOARDS
) {
845 printk(KERN_ERR
"Too many Smartio/Industio family boards find (maximum %d),board not configured\n", MXSER_BOARDS
);
847 if (pci_enable_device(pdev
)) {
848 printk(KERN_ERR
"Moxa SmartI/O PCI enable fail !\n");
851 retval
= mxser_get_PCI_conf(busnum
, devnum
, (int) mxser_pcibrds
[b
].driver_data
, &hwconf
);
853 if (retval
== MXSER_ERR_IRQ
)
854 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
855 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
856 printk(KERN_ERR
"Invalid interrupt number,board not configured\n");
857 else if (retval
== MXSER_ERR_VECTOR
)
858 printk(KERN_ERR
"Invalid interrupt vector,board not configured\n");
859 else if (retval
== MXSER_ERR_IOADDR
)
860 printk(KERN_ERR
"Invalid I/O address,board not configured\n");
863 mxser_getcfg(m
, &hwconf
);
864 //init mxsercfg first, or mxsercfg data is not correct on ISR.
865 //mxser_initbrd will hook ISR.
866 if (mxser_initbrd(m
, &hwconf
) < 0)
874 if (!(ret1
= tty_register_driver(mxvar_sdriver
))) {
877 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family driver !\n");
881 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
882 if (mxsercfg
[i
].board_type
== -1)
885 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
886 //todo: release io, vector
895 static void mxser_do_softint(void *private_
)
897 struct mxser_struct
*info
= (struct mxser_struct
*) private_
;
898 struct tty_struct
*tty
;
903 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
))
905 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
))
910 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
, struct mxser_struct
*info
)
912 unsigned char status
= 0;
914 status
= inb(baseaddr
+ UART_MSR
);
916 mxser_msr
[port
] &= 0x0F;
917 mxser_msr
[port
] |= status
;
918 status
= mxser_msr
[port
];
926 * This routine is called whenever a serial port is opened. It
927 * enables interrupts for a serial port, linking in its async structure into
928 * the IRQ chain. It also performs the serial-specific
929 * initialization for the tty structure.
931 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
933 struct mxser_struct
*info
;
937 if (line
== MXSER_PORTS
)
939 if (line
< 0 || line
> MXSER_PORTS
)
941 info
= mxvar_table
+ line
;
945 tty
->driver_data
= info
;
948 * Start up serial port
950 retval
= mxser_startup(info
);
954 retval
= mxser_block_til_ready(tty
, filp
, info
);
960 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
961 if (tty
->driver
->subtype
== SERIAL_TYPE_NORMAL
)
962 *tty
->termios
= info
->normal_termios
;
964 *tty
->termios
= info
->callout_termios
;
965 mxser_change_speed(info
, NULL
);
968 info
->session
= current
->signal
->session
;
969 info
->pgrp
= process_group(current
);
970 clear_bit(TTY_DONT_FLIP
, &tty
->flags
);
972 //status = mxser_get_msr(info->base, 0, info->port);
973 //mxser_check_modem_status(info, status);
975 /* unmark here for very high baud rate (ex. 921600 bps) used
977 tty
->low_latency
= 1;
982 * This routine is called when the serial port gets closed. First, we
983 * wait for the last remaining data to be sent. Then, we unlink its
984 * async structure from the interrupt chain if necessary, and we free
985 * that IRQ if nothing is left in the chain.
987 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
989 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
991 unsigned long timeout
;
993 struct tty_ldisc
*ld
;
995 if (tty
->index
== MXSER_PORTS
)
1000 spin_lock_irqsave(&info
->slock
, flags
);
1002 if (tty_hung_up_p(filp
)) {
1003 spin_unlock_irqrestore(&info
->slock
, flags
);
1006 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1008 * Uh, oh. tty->count is 1, which means that the tty
1009 * structure will be freed. Info->count should always
1010 * be one in these conditions. If it's greater than
1011 * one, we've got real problems, since it means the
1012 * serial port won't be shutdown.
1014 printk(KERN_ERR
"mxser_close: bad serial port count; tty->count is 1, " "info->count is %d\n", info
->count
);
1017 if (--info
->count
< 0) {
1018 printk(KERN_ERR
"mxser_close: bad serial port count for ttys%d: %d\n", info
->port
, info
->count
);
1022 spin_unlock_irqrestore(&info
->slock
, flags
);
1025 info
->flags
|= ASYNC_CLOSING
;
1026 spin_unlock_irqrestore(&info
->slock
, flags
);
1028 * Save the termios structure, since this port may have
1029 * separate termios for callout and dialin.
1031 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1032 info
->normal_termios
= *tty
->termios
;
1034 * Now we wait for the transmit buffer to clear; and we notify
1035 * the line discipline to only process XON/XOFF characters.
1038 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1039 tty_wait_until_sent(tty
, info
->closing_wait
);
1041 * At this point we stop accepting input. To do this, we
1042 * disable the receive line status interrupts, and tell the
1043 * interrupt driver to stop checking the data ready bit in the
1044 * line status register.
1046 info
->IER
&= ~UART_IER_RLSI
;
1047 if (info
->IsMoxaMustChipFlag
)
1048 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1050 info->read_status_mask &= ~UART_LSR_DR;
1052 if (info
->flags
& ASYNC_INITIALIZED
) {
1053 outb(info
->IER
, info
->base
+ UART_IER
);
1055 * Before we drop DTR, make sure the UART transmitter
1056 * has completely drained; this is especially
1057 * important if there is a transmit FIFO!
1059 timeout
= jiffies
+ HZ
;
1060 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
1061 set_current_state(TASK_INTERRUPTIBLE
);
1062 schedule_timeout(5);
1063 if (time_after(jiffies
, timeout
))
1067 mxser_shutdown(info
);
1069 if (tty
->driver
->flush_buffer
)
1070 tty
->driver
->flush_buffer(tty
);
1072 ld
= tty_ldisc_ref(tty
);
1074 if(ld
->flush_buffer
)
1075 ld
->flush_buffer(tty
);
1076 tty_ldisc_deref(ld
);
1082 if (info
->blocked_open
) {
1083 if (info
->close_delay
) {
1084 set_current_state(TASK_INTERRUPTIBLE
);
1085 schedule_timeout(info
->close_delay
);
1087 wake_up_interruptible(&info
->open_wait
);
1090 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1091 wake_up_interruptible(&info
->close_wait
);
1095 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1098 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1099 unsigned long flags
;
1101 if (!tty
|| !info
->xmit_buf
)
1105 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1, SERIAL_XMIT_SIZE
- info
->xmit_head
));
1109 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1110 spin_lock_irqsave(&info
->slock
, flags
);
1111 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
1112 info
->xmit_cnt
+= c
;
1113 spin_unlock_irqrestore(&info
->slock
, flags
);
1121 if (info
->xmit_cnt
&& !tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1122 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
1123 spin_lock_irqsave(&info
->slock
, flags
);
1124 info
->IER
|= UART_IER_THRI
;
1125 outb(info
->IER
, info
->base
+ UART_IER
);
1126 spin_unlock_irqrestore(&info
->slock
, flags
);
1132 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1134 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1135 unsigned long flags
;
1137 if (!tty
|| !info
->xmit_buf
)
1140 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1143 spin_lock_irqsave(&info
->slock
, flags
);
1144 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1145 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1147 spin_unlock_irqrestore(&info
->slock
, flags
);
1148 if (!tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1149 if (!tty
->hw_stopped
|| (info
->type
== PORT_16550A
) || info
->IsMoxaMustChipFlag
) {
1150 spin_lock_irqsave(&info
->slock
, flags
);
1151 info
->IER
|= UART_IER_THRI
;
1152 outb(info
->IER
, info
->base
+ UART_IER
);
1153 spin_unlock_irqrestore(&info
->slock
, flags
);
1159 static void mxser_flush_chars(struct tty_struct
*tty
)
1161 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1162 unsigned long flags
;
1164 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| !info
->xmit_buf
|| (tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)))
1167 spin_lock_irqsave(&info
->slock
, flags
);
1169 info
->IER
|= UART_IER_THRI
;
1170 outb(info
->IER
, info
->base
+ UART_IER
);
1172 spin_unlock_irqrestore(&info
->slock
, flags
);
1175 static int mxser_write_room(struct tty_struct
*tty
)
1177 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1180 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1186 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1188 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1189 return info
->xmit_cnt
;
1192 static void mxser_flush_buffer(struct tty_struct
*tty
)
1194 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1196 unsigned long flags
;
1199 spin_lock_irqsave(&info
->slock
, flags
);
1200 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1202 /* below added by shinhay */
1203 fcr
= inb(info
->base
+ UART_FCR
);
1204 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
1205 outb(fcr
, info
->base
+ UART_FCR
);
1207 spin_unlock_irqrestore(&info
->slock
, flags
);
1208 /* above added by shinhay */
1210 wake_up_interruptible(&tty
->write_wait
);
1211 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) && tty
->ldisc
.write_wakeup
)
1212 (tty
->ldisc
.write_wakeup
) (tty
);
1215 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1217 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1219 struct async_icount cprev
, cnow
; /* kernel counter temps */
1220 struct serial_icounter_struct __user
*p_cuser
;
1221 unsigned long templ
;
1222 unsigned long flags
;
1223 void __user
*argp
= (void __user
*)arg
;
1225 if (tty
->index
== MXSER_PORTS
)
1226 return (mxser_ioctl_special(cmd
, argp
));
1228 // following add by Victor Yu. 01-05-2004
1229 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1231 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1233 unsigned char val
, mask
;
1236 if (cmd
== MOXA_SET_OP_MODE
) {
1237 if (get_user(opmode
, (int __user
*) argp
))
1239 if (opmode
!= RS232_MODE
&& opmode
!= RS485_2WIRE_MODE
&& opmode
!= RS422_MODE
&& opmode
!= RS485_4WIRE_MODE
)
1243 val
= inb(info
->opmode_ioaddr
);
1245 val
|= (opmode
<< shiftbit
);
1246 outb(val
, info
->opmode_ioaddr
);
1249 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1250 opmode
&= OP_MODE_MASK
;
1251 if (copy_to_user(argp
, &opmode
, sizeof(int)))
1256 // above add by Victor Yu. 01-05-2004
1258 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1259 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1263 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1264 retval
= tty_check_change(tty
);
1267 tty_wait_until_sent(tty
, 0);
1269 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1271 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1272 retval
= tty_check_change(tty
);
1275 tty_wait_until_sent(tty
, 0);
1276 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1279 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) argp
);
1281 if (get_user(templ
, (unsigned long __user
*) argp
))
1284 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1287 return mxser_get_serial_info(info
, argp
);
1289 return mxser_set_serial_info(info
, argp
);
1290 case TIOCSERGETLSR
: /* Get line status register */
1291 return mxser_get_lsr_info(info
, argp
);
1293 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1294 * - mask passed in arg for lines of interest
1295 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1296 * Caller should use TIOCGICOUNT to see which one it was
1299 DECLARE_WAITQUEUE(wait
, current
);
1301 spin_lock_irqsave(&info
->slock
, flags
);
1302 cprev
= info
->icount
; /* note the counters on entry */
1303 spin_unlock_irqrestore(&info
->slock
, flags
);
1305 add_wait_queue(&info
->delta_msr_wait
, &wait
);
1307 spin_lock_irqsave(&info
->slock
, flags
);
1308 cnow
= info
->icount
; /* atomic copy */
1309 spin_unlock_irqrestore(&info
->slock
, flags
);
1311 set_current_state(TASK_INTERRUPTIBLE
);
1312 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
))) {
1316 /* see if a signal did it */
1317 if (signal_pending(current
)) {
1323 current
->state
= TASK_RUNNING
;
1324 remove_wait_queue(&info
->delta_msr_wait
, &wait
);
1329 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1330 * Return: write counters to the user passed counter struct
1331 * NB: both 1->0 and 0->1 transitions are counted except for
1332 * RI where only 0->1 is counted.
1335 spin_lock_irqsave(&info
->slock
, flags
);
1336 cnow
= info
->icount
;
1337 spin_unlock_irqrestore(&info
->slock
, flags
);
1339 /* modified by casper 1/11/2000 */
1340 if (put_user(cnow
.frame
, &p_cuser
->frame
))
1342 if (put_user(cnow
.brk
, &p_cuser
->brk
))
1344 if (put_user(cnow
.overrun
, &p_cuser
->overrun
))
1346 if (put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
))
1348 if (put_user(cnow
.parity
, &p_cuser
->parity
))
1350 if (put_user(cnow
.rx
, &p_cuser
->rx
))
1352 if (put_user(cnow
.tx
, &p_cuser
->tx
))
1354 put_user(cnow
.cts
, &p_cuser
->cts
);
1355 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1356 put_user(cnow
.rng
, &p_cuser
->rng
);
1357 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1361 case MOXA_HighSpeedOn
:
1362 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*) argp
);
1364 case MOXA_SDS_RSTICOUNTER
:{
1365 info
->mon_data
.rxcnt
= 0;
1366 info
->mon_data
.txcnt
= 0;
1369 // (above) added by James.
1370 case MOXA_ASPP_SETBAUD
:{
1372 if (get_user(baud
, (long __user
*) argp
))
1374 mxser_set_baud(info
, baud
);
1377 case MOXA_ASPP_GETBAUD
:
1378 if (copy_to_user(argp
, &info
->realbaud
, sizeof(long)))
1383 case MOXA_ASPP_OQUEUE
:{
1386 len
= mxser_chars_in_buffer(tty
);
1388 lsr
= inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
;
1390 len
+= (lsr
? 0 : 1);
1392 if (copy_to_user(argp
, &len
, sizeof(int)))
1397 case MOXA_ASPP_MON
:{
1399 // info->mon_data.ser_param = tty->termios->c_cflag;
1401 status
= mxser_get_msr(info
->base
, 1, info
->port
, info
);
1402 mxser_check_modem_status(info
, status
);
1404 mcr
= inb(info
->base
+ UART_MCR
);
1405 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1406 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1408 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1410 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1411 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1413 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1415 if (info
->tty
->hw_stopped
)
1416 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1418 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1421 if (copy_to_user(argp
, &info
->mon_data
, sizeof(struct mxser_mon
)))
1428 case MOXA_ASPP_LSTATUS
:{
1429 if (copy_to_user(argp
, &info
->err_shadow
, sizeof(unsigned char)))
1432 info
->err_shadow
= 0;
1436 case MOXA_SET_BAUD_METHOD
:{
1438 if (get_user(method
, (int __user
*) argp
))
1440 mxser_set_baud_method
[info
->port
] = method
;
1441 if (copy_to_user(argp
, &method
, sizeof(int)))
1447 return -ENOIOCTLCMD
;
1453 #define CMSPAR 010000000000
1456 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1458 int i
, result
, status
;
1462 if (copy_to_user(argp
, mxsercfg
, sizeof(struct mxser_hwconf
) * 4))
1465 case MOXA_GET_MAJOR
:
1466 if (copy_to_user(argp
, &ttymajor
, sizeof(int)))
1470 case MOXA_GET_CUMAJOR
:
1471 if (copy_to_user(argp
, &calloutmajor
, sizeof(int)))
1475 case MOXA_CHKPORTENABLE
:
1477 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1478 if (mxvar_table
[i
].base
)
1481 return put_user(result
, (unsigned long __user
*) argp
);
1482 case MOXA_GETDATACOUNT
:
1483 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1486 case MOXA_GETMSTATUS
:
1487 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1489 if (!mxvar_table
[i
].base
) {
1490 GMStatus
[i
].dcd
= 0;
1491 GMStatus
[i
].dsr
= 0;
1492 GMStatus
[i
].cts
= 0;
1496 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1497 GMStatus
[i
].cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1499 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1501 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1502 if (status
& 0x80 /*UART_MSR_DCD */ )
1503 GMStatus
[i
].dcd
= 1;
1505 GMStatus
[i
].dcd
= 0;
1507 if (status
& 0x20 /*UART_MSR_DSR */ )
1508 GMStatus
[i
].dsr
= 1;
1510 GMStatus
[i
].dsr
= 0;
1513 if (status
& 0x10 /*UART_MSR_CTS */ )
1514 GMStatus
[i
].cts
= 1;
1516 GMStatus
[i
].cts
= 0;
1518 if (copy_to_user(argp
, GMStatus
, sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1521 case MOXA_ASPP_MON_EXT
:{
1525 unsigned cflag
, iflag
;
1527 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1529 if (!mxvar_table
[i
].base
)
1532 status
= mxser_get_msr(mxvar_table
[i
].base
, 0, i
, &(mxvar_table
[i
]));
1533 // mxser_check_modem_status(&mxvar_table[i], status);
1534 if (status
& UART_MSR_TERI
)
1535 mxvar_table
[i
].icount
.rng
++;
1536 if (status
& UART_MSR_DDSR
)
1537 mxvar_table
[i
].icount
.dsr
++;
1538 if (status
& UART_MSR_DDCD
)
1539 mxvar_table
[i
].icount
.dcd
++;
1540 if (status
& UART_MSR_DCTS
)
1541 mxvar_table
[i
].icount
.cts
++;
1543 mxvar_table
[i
].mon_data
.modem_status
= status
;
1544 mon_data_ext
.rx_cnt
[i
] = mxvar_table
[i
].mon_data
.rxcnt
;
1545 mon_data_ext
.tx_cnt
[i
] = mxvar_table
[i
].mon_data
.txcnt
;
1546 mon_data_ext
.up_rxcnt
[i
] = mxvar_table
[i
].mon_data
.up_rxcnt
;
1547 mon_data_ext
.up_txcnt
[i
] = mxvar_table
[i
].mon_data
.up_txcnt
;
1548 mon_data_ext
.modem_status
[i
] = mxvar_table
[i
].mon_data
.modem_status
;
1549 mon_data_ext
.baudrate
[i
] = mxvar_table
[i
].realbaud
;
1551 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
) {
1552 cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1553 iflag
= mxvar_table
[i
].normal_termios
.c_iflag
;
1555 cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1556 iflag
= mxvar_table
[i
].tty
->termios
->c_iflag
;
1559 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1561 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1563 mon_data_ext
.parity
[i
] = cflag
& (PARENB
| PARODD
| CMSPAR
);
1565 mon_data_ext
.flowctrl
[i
] = 0x00;
1567 if (cflag
& CRTSCTS
)
1568 mon_data_ext
.flowctrl
[i
] |= 0x03;
1570 if (iflag
& (IXON
| IXOFF
))
1571 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1573 if (mxvar_table
[i
].type
== PORT_16550A
)
1574 mon_data_ext
.fifo
[i
] = 1;
1576 mon_data_ext
.fifo
[i
] = 0;
1580 opmode
= inb(mxvar_table
[i
].opmode_ioaddr
) >> shiftbit
;
1581 opmode
&= OP_MODE_MASK
;
1583 mon_data_ext
.iftype
[i
] = opmode
;
1586 if (copy_to_user(argp
, &mon_data_ext
, sizeof(struct mxser_mon_ext
)))
1593 return -ENOIOCTLCMD
;
1599 static void mxser_stoprx(struct tty_struct
*tty
)
1601 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1602 //unsigned long flags;
1605 info
->ldisc_stop_rx
= 1;
1608 //MX_LOCK(&info->slock);
1609 // following add by Victor Yu. 09-02-2002
1610 if (info
->IsMoxaMustChipFlag
) {
1611 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1612 outb(info
->IER
, info
->base
+ UART_IER
);
1614 // above add by Victor Yu. 09-02-2002
1616 info
->x_char
= STOP_CHAR(tty
);
1617 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1618 outb(0, info
->base
+ UART_IER
);
1619 info
->IER
|= UART_IER_THRI
;
1620 outb(info
->IER
, info
->base
+ UART_IER
); /* force Tx interrupt */
1621 } // add by Victor Yu. 09-02-2002
1622 //MX_UNLOCK(&info->slock);
1625 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1626 //MX_LOCK(&info->slock);
1627 info
->MCR
&= ~UART_MCR_RTS
;
1628 outb(info
->MCR
, info
->base
+ UART_MCR
);
1629 //MX_UNLOCK(&info->slock);
1633 static void mxser_startrx(struct tty_struct
*tty
)
1635 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1636 //unsigned long flags;
1638 info
->ldisc_stop_rx
= 0;
1643 //MX_LOCK(&info->slock);
1645 // following add by Victor Yu. 09-02-2002
1646 if (info
->IsMoxaMustChipFlag
) {
1647 info
->IER
|= MOXA_MUST_RECV_ISR
;
1648 outb(info
->IER
, info
->base
+ UART_IER
);
1650 // above add by Victor Yu. 09-02-2002
1652 info
->x_char
= START_CHAR(tty
);
1653 // outb(info->IER, 0); // mask by Victor Yu. 09-02-2002
1654 outb(0, info
->base
+ UART_IER
); // add by Victor Yu. 09-02-2002
1655 info
->IER
|= UART_IER_THRI
; /* force Tx interrupt */
1656 outb(info
->IER
, info
->base
+ UART_IER
);
1657 } // add by Victor Yu. 09-02-2002
1658 //MX_UNLOCK(&info->slock);
1662 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1663 //MX_LOCK(&info->slock);
1664 info
->MCR
|= UART_MCR_RTS
;
1665 outb(info
->MCR
, info
->base
+ UART_MCR
);
1666 //MX_UNLOCK(&info->slock);
1671 * This routine is called by the upper-layer tty layer to signal that
1672 * incoming characters should be throttled.
1674 static void mxser_throttle(struct tty_struct
*tty
)
1676 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1677 //unsigned long flags;
1678 //MX_LOCK(&info->slock);
1680 //MX_UNLOCK(&info->slock);
1683 static void mxser_unthrottle(struct tty_struct
*tty
)
1685 //struct mxser_struct *info = (struct mxser_struct *)tty->driver_data;
1686 //unsigned long flags;
1687 //MX_LOCK(&info->slock);
1689 //MX_UNLOCK(&info->slock);
1692 static void mxser_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
1694 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1695 unsigned long flags
;
1697 if ((tty
->termios
->c_cflag
!= old_termios
->c_cflag
) || (RELEVANT_IFLAG(tty
->termios
->c_iflag
) != RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1699 mxser_change_speed(info
, old_termios
);
1701 if ((old_termios
->c_cflag
& CRTSCTS
) && !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1702 tty
->hw_stopped
= 0;
1707 /* Handle sw stopped */
1708 if ((old_termios
->c_iflag
& IXON
) && !(tty
->termios
->c_iflag
& IXON
)) {
1711 // following add by Victor Yu. 09-02-2002
1712 if (info
->IsMoxaMustChipFlag
) {
1713 spin_lock_irqsave(&info
->slock
, flags
);
1714 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
1715 spin_unlock_irqrestore(&info
->slock
, flags
);
1717 // above add by Victor Yu. 09-02-2002
1724 * mxser_stop() and mxser_start()
1726 * This routines are called before setting or resetting tty->stopped.
1727 * They enable or disable transmitter interrupts, as necessary.
1729 static void mxser_stop(struct tty_struct
*tty
)
1731 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1732 unsigned long flags
;
1734 spin_lock_irqsave(&info
->slock
, flags
);
1735 if (info
->IER
& UART_IER_THRI
) {
1736 info
->IER
&= ~UART_IER_THRI
;
1737 outb(info
->IER
, info
->base
+ UART_IER
);
1739 spin_unlock_irqrestore(&info
->slock
, flags
);
1742 static void mxser_start(struct tty_struct
*tty
)
1744 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1745 unsigned long flags
;
1747 spin_lock_irqsave(&info
->slock
, flags
);
1748 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
1749 info
->IER
|= UART_IER_THRI
;
1750 outb(info
->IER
, info
->base
+ UART_IER
);
1752 spin_unlock_irqrestore(&info
->slock
, flags
);
1756 * mxser_wait_until_sent() --- wait until the transmitter is empty
1758 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1760 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1761 unsigned long orig_jiffies
, char_time
;
1764 if (info
->type
== PORT_UNKNOWN
)
1767 if (info
->xmit_fifo_size
== 0)
1768 return; /* Just in case.... */
1770 orig_jiffies
= jiffies
;
1772 * Set the check interval to be 1/5 of the estimated time to
1773 * send a single character, and make it at least 1. The check
1774 * interval should also be less than the timeout.
1776 * Note: we have to use pretty tight timings here to satisfy
1779 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
1780 char_time
= char_time
/ 5;
1783 if (timeout
&& timeout
< char_time
)
1784 char_time
= timeout
;
1786 * If the transmitter hasn't cleared in twice the approximate
1787 * amount of time to send the entire FIFO, it probably won't
1788 * ever clear. This assumes the UART isn't doing flow
1789 * control, which is currently the case. Hence, if it ever
1790 * takes longer than info->timeout, this is probably due to a
1791 * UART bug of some kind. So, we clamp the timeout parameter at
1794 if (!timeout
|| timeout
> 2 * info
->timeout
)
1795 timeout
= 2 * info
->timeout
;
1796 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1797 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
1798 printk("jiff=%lu...", jiffies
);
1800 while (!((lsr
= inb(info
->base
+ UART_LSR
)) & UART_LSR_TEMT
)) {
1801 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1802 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1804 set_current_state(TASK_INTERRUPTIBLE
);
1805 schedule_timeout(char_time
);
1806 if (signal_pending(current
))
1808 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1811 set_current_state(TASK_RUNNING
);
1813 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1814 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1820 * This routine is called by tty_hangup() when a hangup is signaled.
1822 void mxser_hangup(struct tty_struct
*tty
)
1824 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1826 mxser_flush_buffer(tty
);
1827 mxser_shutdown(info
);
1830 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1832 wake_up_interruptible(&info
->open_wait
);
1836 // added by James 03-12-2004.
1838 * mxser_rs_break() --- routine which turns the break handling on or off
1840 static void mxser_rs_break(struct tty_struct
*tty
, int break_state
)
1842 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1843 unsigned long flags
;
1845 spin_lock_irqsave(&info
->slock
, flags
);
1846 if (break_state
== -1)
1847 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
1849 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
1850 spin_unlock_irqrestore(&info
->slock
, flags
);
1853 // (above) added by James.
1857 * This is the serial driver's generic interrupt routine
1859 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1862 struct mxser_struct
*info
;
1863 struct mxser_struct
*port
;
1864 int max
, irqbits
, bits
, msr
;
1865 int pass_counter
= 0;
1866 int handled
= IRQ_NONE
;
1869 //spin_lock(&gm_lock);
1871 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1872 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1878 if (i
== MXSER_BOARDS
) {
1884 max
= mxser_numports
[mxsercfg
[i
].board_type
- 1];
1886 irqbits
= inb(port
->vector
) & port
->vectormask
;
1887 if (irqbits
== port
->vectormask
) {
1891 handled
= IRQ_HANDLED
;
1892 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1893 if (irqbits
== port
->vectormask
) {
1900 // following add by Victor Yu. 09-13-2002
1901 iir
= inb(info
->base
+ UART_IIR
);
1902 if (iir
& UART_IIR_NO_INT
)
1904 iir
&= MOXA_MUST_IIR_MASK
;
1906 status
= inb(info
->base
+ UART_LSR
);
1907 outb(0x27, info
->base
+ UART_FCR
);
1908 inb(info
->base
+ UART_MSR
);
1911 // above add by Victor Yu. 09-13-2002
1913 if ( info->tty->flip.count < TTY_FLIPBUF_SIZE/4 ){
1914 info->IER |= MOXA_MUST_RECV_ISR;
1915 outb(info->IER, info->base + UART_IER);
1920 /* mask by Victor Yu. 09-13-2002
1922 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1925 /* mask by Victor Yu. 09-02-2002
1926 status = inb(info->base + UART_LSR) & info->read_status_mask;
1929 // following add by Victor Yu. 09-02-2002
1930 status
= inb(info
->base
+ UART_LSR
);
1932 if (status
& UART_LSR_PE
) {
1933 info
->err_shadow
|= NPPI_NOTIFY_PARITY
;
1935 if (status
& UART_LSR_FE
) {
1936 info
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
1938 if (status
& UART_LSR_OE
) {
1939 info
->err_shadow
|= NPPI_NOTIFY_HW_OVERRUN
;
1941 if (status
& UART_LSR_BI
)
1942 info
->err_shadow
|= NPPI_NOTIFY_BREAK
;
1944 if (info
->IsMoxaMustChipFlag
) {
1946 if ( (status & 0x02) && !(status & 0x01) ) {
1947 outb(info->base+UART_FCR, 0x23);
1951 if (iir
== MOXA_MUST_IIR_GDA
|| iir
== MOXA_MUST_IIR_RDA
|| iir
== MOXA_MUST_IIR_RTO
|| iir
== MOXA_MUST_IIR_LSR
)
1952 mxser_receive_chars(info
, &status
);
1955 // above add by Victor Yu. 09-02-2002
1957 status
&= info
->read_status_mask
;
1958 if (status
& UART_LSR_DR
)
1959 mxser_receive_chars(info
, &status
);
1961 msr
= inb(info
->base
+ UART_MSR
);
1962 if (msr
& UART_MSR_ANY_DELTA
) {
1963 mxser_check_modem_status(info
, msr
);
1965 // following add by Victor Yu. 09-13-2002
1966 if (info
->IsMoxaMustChipFlag
) {
1967 if ((iir
== 0x02) && (status
& UART_LSR_THRE
)) {
1968 mxser_transmit_chars(info
);
1971 // above add by Victor Yu. 09-13-2002
1973 if (status
& UART_LSR_THRE
) {
1974 /* 8-2-99 by William
1975 if ( info->x_char || (info->xmit_cnt > 0) )
1977 mxser_transmit_chars(info
);
1981 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
1982 break; /* Prevent infinite loops */
1987 //spin_unlock(&gm_lock);
1991 static void mxser_receive_chars(struct mxser_struct
*info
, int *status
)
1993 struct tty_struct
*tty
= info
->tty
;
1994 unsigned char ch
, gdl
;
1999 unsigned long flags
;
2001 spin_lock_irqsave(&info
->slock
, flags
);
2003 recv_room
= tty
->ldisc
.receive_room(tty
);
2004 if ((recv_room
== 0) && (!info
->ldisc_stop_rx
)) {
2005 //mxser_throttle(tty);
2010 // following add by Victor Yu. 09-02-2002
2011 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
2013 if (*status
& UART_LSR_SPECIAL
) {
2016 // following add by Victor Yu. 02-11-2004
2017 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
&& (*status
& MOXA_MUST_LSR_RERR
))
2019 // above add by Victor Yu. 02-14-2004
2020 if (*status
& MOXA_MUST_LSR_RERR
)
2023 gdl
= inb(info
->base
+ MOXA_MUST_GDL_REGISTER
);
2025 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU150_HWID
) // add by Victor Yu. 02-11-2004
2026 gdl
&= MOXA_MUST_GDL_MASK
;
2027 if (gdl
>= recv_room
) {
2028 if (!info
->ldisc_stop_rx
) {
2029 //mxser_throttle(tty);
2035 ch
= inb(info
->base
+ UART_RX
);
2036 tty_insert_flip_char(tty
, ch
, 0);
2039 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2048 // above add by Victor Yu. 09-02-2002
2054 if((cnt>=HI_WATER) && (info->stop_rx==0)){
2061 ch
= inb(info
->base
+ UART_RX
);
2062 // following add by Victor Yu. 09-02-2002
2063 if (info
->IsMoxaMustChipFlag
&& (*status
& UART_LSR_OE
) /*&& !(*status&UART_LSR_DR) */ )
2064 outb(0x23, info
->base
+ UART_FCR
);
2065 *status
&= info
->read_status_mask
;
2066 // above add by Victor Yu. 09-02-2002
2067 if (*status
& info
->ignore_status_mask
) {
2068 if (++ignored
> 100)
2072 if (*status
& UART_LSR_SPECIAL
) {
2073 if (*status
& UART_LSR_BI
) {
2075 /* added by casper 1/11/2000 */
2078 if (info
->flags
& ASYNC_SAK
)
2080 } else if (*status
& UART_LSR_PE
) {
2082 /* added by casper 1/11/2000 */
2083 info
->icount
.parity
++;
2085 } else if (*status
& UART_LSR_FE
) {
2087 /* added by casper 1/11/2000 */
2088 info
->icount
.frame
++;
2090 } else if (*status
& UART_LSR_OE
) {
2092 /* added by casper 1/11/2000 */
2093 info
->icount
.overrun
++;
2097 tty_insert_flip_char(tty
, ch
, flag
);
2099 if (cnt
>= recv_room
) {
2100 if (!info
->ldisc_stop_rx
) {
2101 //mxser_throttle(tty);
2109 // following add by Victor Yu. 09-02-2002
2110 if (info
->IsMoxaMustChipFlag
)
2112 // above add by Victor Yu. 09-02-2002
2114 /* mask by Victor Yu. 09-02-2002
2115 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2117 // following add by Victor Yu. 09-02-2002
2118 *status
= inb(info
->base
+ UART_LSR
);
2119 // above add by Victor Yu. 09-02-2002
2120 } while (*status
& UART_LSR_DR
);
2122 end_intr
: // add by Victor Yu. 09-02-2002
2124 mxvar_log
.rxcnt
[info
->port
] += cnt
;
2125 info
->mon_data
.rxcnt
+= cnt
;
2126 info
->mon_data
.up_rxcnt
+= cnt
;
2127 spin_unlock_irqrestore(&info
->slock
, flags
);
2129 tty_flip_buffer_push(tty
);
2132 static void mxser_transmit_chars(struct mxser_struct
*info
)
2135 unsigned long flags
;
2137 spin_lock_irqsave(&info
->slock
, flags
);
2140 outb(info
->x_char
, info
->base
+ UART_TX
);
2142 mxvar_log
.txcnt
[info
->port
]++;
2143 info
->mon_data
.txcnt
++;
2144 info
->mon_data
.up_txcnt
++;
2146 /* added by casper 1/11/2000 */
2149 spin_unlock_irqrestore(&info
->slock
, flags
);
2153 if (info
->xmit_buf
== 0) {
2154 spin_unlock_irqrestore(&info
->slock
, flags
);
2158 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
|| (info
->tty
->hw_stopped
&& (info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
))) {
2159 info
->IER
&= ~UART_IER_THRI
;
2160 outb(info
->IER
, info
->base
+ UART_IER
);
2161 spin_unlock_irqrestore(&info
->slock
, flags
);
2165 cnt
= info
->xmit_cnt
;
2166 count
= info
->xmit_fifo_size
;
2168 outb(info
->xmit_buf
[info
->xmit_tail
++], info
->base
+ UART_TX
);
2169 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2170 if (--info
->xmit_cnt
<= 0)
2172 } while (--count
> 0);
2173 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
2175 // added by James 03-12-2004.
2176 info
->mon_data
.txcnt
+= (cnt
- info
->xmit_cnt
);
2177 info
->mon_data
.up_txcnt
+= (cnt
- info
->xmit_cnt
);
2178 // (above) added by James.
2180 /* added by casper 1/11/2000 */
2181 info
->icount
.tx
+= (cnt
- info
->xmit_cnt
);
2184 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
2185 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2186 schedule_work(&info
->tqueue
);
2188 if (info
->xmit_cnt
<= 0) {
2189 info
->IER
&= ~UART_IER_THRI
;
2190 outb(info
->IER
, info
->base
+ UART_IER
);
2192 spin_unlock_irqrestore(&info
->slock
, flags
);
2195 static void mxser_check_modem_status(struct mxser_struct
*info
, int status
)
2197 /* update input line counters */
2198 if (status
& UART_MSR_TERI
)
2200 if (status
& UART_MSR_DDSR
)
2202 if (status
& UART_MSR_DDCD
)
2204 if (status
& UART_MSR_DCTS
)
2206 info
->mon_data
.modem_status
= status
;
2207 wake_up_interruptible(&info
->delta_msr_wait
);
2210 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
2211 if (status
& UART_MSR_DCD
)
2212 wake_up_interruptible(&info
->open_wait
);
2213 schedule_work(&info
->tqueue
);
2216 if (info
->flags
& ASYNC_CTS_FLOW
) {
2217 if (info
->tty
->hw_stopped
) {
2218 if (status
& UART_MSR_CTS
) {
2219 info
->tty
->hw_stopped
= 0;
2221 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2222 info
->IER
|= UART_IER_THRI
;
2223 outb(info
->IER
, info
->base
+ UART_IER
);
2225 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2226 schedule_work(&info
->tqueue
); }
2228 if (!(status
& UART_MSR_CTS
)) {
2229 info
->tty
->hw_stopped
= 1;
2230 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2231 info
->IER
&= ~UART_IER_THRI
;
2232 outb(info
->IER
, info
->base
+ UART_IER
);
2239 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, struct mxser_struct
*info
)
2241 DECLARE_WAITQUEUE(wait
, current
);
2244 unsigned long flags
;
2247 * If non-blocking mode is set, or the port is not enabled,
2248 * then make the check up front and then exit.
2250 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2251 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2255 if (tty
->termios
->c_cflag
& CLOCAL
)
2259 * Block waiting for the carrier detect and the line to become
2260 * free (i.e., not in use by the callout). While we are in
2261 * this loop, info->count is dropped by one, so that
2262 * mxser_close() knows when to free things. We restore it upon
2263 * exit, either normal or abnormal.
2266 add_wait_queue(&info
->open_wait
, &wait
);
2268 spin_lock_irqsave(&info
->slock
, flags
);
2269 if (!tty_hung_up_p(filp
))
2271 spin_unlock_irqrestore(&info
->slock
, flags
);
2272 info
->blocked_open
++;
2274 spin_lock_irqsave(&info
->slock
, flags
);
2275 outb(inb(info
->base
+ UART_MCR
) | UART_MCR_DTR
| UART_MCR_RTS
, info
->base
+ UART_MCR
);
2276 spin_unlock_irqrestore(&info
->slock
, flags
);
2277 set_current_state(TASK_INTERRUPTIBLE
);
2278 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
2279 if (info
->flags
& ASYNC_HUP_NOTIFY
)
2282 retval
= -ERESTARTSYS
;
2285 if (!(info
->flags
& ASYNC_CLOSING
) && (do_clocal
|| (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
2287 if (signal_pending(current
)) {
2288 retval
= -ERESTARTSYS
;
2293 set_current_state(TASK_RUNNING
);
2294 remove_wait_queue(&info
->open_wait
, &wait
);
2295 if (!tty_hung_up_p(filp
))
2297 info
->blocked_open
--;
2300 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2304 static int mxser_startup(struct mxser_struct
*info
)
2308 unsigned long flags
;
2310 page
= __get_free_page(GFP_KERNEL
);
2314 spin_lock_irqsave(&info
->slock
, flags
);
2316 if (info
->flags
& ASYNC_INITIALIZED
) {
2318 spin_unlock_irqrestore(&info
->slock
, flags
);
2322 if (!info
->base
|| !info
->type
) {
2324 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2326 spin_unlock_irqrestore(&info
->slock
, flags
);
2332 info
->xmit_buf
= (unsigned char *) page
;
2335 * Clear the FIFO buffers and disable them
2336 * (they will be reenabled in mxser_change_speed())
2338 if (info
->IsMoxaMustChipFlag
)
2339 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2341 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2344 * At this point there's no way the LSR could still be 0xFF;
2345 * if it is, then bail out, because there's likely no UART
2348 if (inb(info
->base
+ UART_LSR
) == 0xff) {
2349 spin_unlock_irqrestore(&info
->slock
, flags
);
2350 if (capable(CAP_SYS_ADMIN
)) {
2352 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2359 * Clear the interrupt registers.
2361 (void) inb(info
->base
+ UART_LSR
);
2362 (void) inb(info
->base
+ UART_RX
);
2363 (void) inb(info
->base
+ UART_IIR
);
2364 (void) inb(info
->base
+ UART_MSR
);
2367 * Now, initialize the UART
2369 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
2370 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
2371 outb(info
->MCR
, info
->base
+ UART_MCR
);
2374 * Finally, enable interrupts
2376 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
2377 // info->IER = UART_IER_RLSI | UART_IER_RDI;
2379 // following add by Victor Yu. 08-30-2002
2380 if (info
->IsMoxaMustChipFlag
)
2381 info
->IER
|= MOXA_MUST_IER_EGDAI
;
2382 // above add by Victor Yu. 08-30-2002
2383 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
2386 * And clear the interrupt registers again for luck.
2388 (void) inb(info
->base
+ UART_LSR
);
2389 (void) inb(info
->base
+ UART_RX
);
2390 (void) inb(info
->base
+ UART_IIR
);
2391 (void) inb(info
->base
+ UART_MSR
);
2394 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2395 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2398 * and set the speed of the serial port
2400 spin_unlock_irqrestore(&info
->slock
, flags
);
2401 mxser_change_speed(info
, NULL
);
2403 info
->flags
|= ASYNC_INITIALIZED
;
2408 * This routine will shutdown a serial port; interrupts maybe disabled, and
2409 * DTR is dropped if the hangup on close termio flag is on.
2411 static void mxser_shutdown(struct mxser_struct
*info
)
2413 unsigned long flags
;
2415 if (!(info
->flags
& ASYNC_INITIALIZED
))
2418 spin_lock_irqsave(&info
->slock
, flags
);
2421 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2422 * here so the queue might never be waken up
2424 wake_up_interruptible(&info
->delta_msr_wait
);
2427 * Free the IRQ, if necessary
2429 if (info
->xmit_buf
) {
2430 free_page((unsigned long) info
->xmit_buf
);
2431 info
->xmit_buf
= NULL
;
2435 outb(0x00, info
->base
+ UART_IER
);
2437 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
2438 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
2439 outb(info
->MCR
, info
->base
+ UART_MCR
);
2441 /* clear Rx/Tx FIFO's */
2442 // following add by Victor Yu. 08-30-2002
2443 if (info
->IsMoxaMustChipFlag
)
2444 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
| MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2446 // above add by Victor Yu. 08-30-2002
2447 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
2449 /* read data port to reset things */
2450 (void) inb(info
->base
+ UART_RX
);
2453 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2455 info
->flags
&= ~ASYNC_INITIALIZED
;
2457 // following add by Victor Yu. 09-23-2002
2458 if (info
->IsMoxaMustChipFlag
) {
2459 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->base
);
2461 // above add by Victor Yu. 09-23-2002
2463 spin_unlock_irqrestore(&info
->slock
, flags
);
2467 * This routine is called to set the UART divisor registers to match
2468 * the specified baud rate for a serial port.
2470 static int mxser_change_speed(struct mxser_struct
*info
, struct termios
*old_termios
)
2472 unsigned cflag
, cval
, fcr
;
2474 unsigned char status
;
2476 unsigned long flags
;
2479 if (!info
->tty
|| !info
->tty
->termios
)
2481 cflag
= info
->tty
->termios
->c_cflag
;
2487 #define B921600 (B460800 +1)
2489 if (mxser_set_baud_method
[info
->port
] == 0) {
2490 switch (cflag
& (CBAUD
| CBAUDEX
)) {
2555 mxser_set_baud(info
, baud
);
2558 /* byte size and parity */
2559 switch (cflag
& CSIZE
) {
2574 break; /* too keep GCC shut... */
2579 cval
|= UART_LCR_PARITY
;
2580 if (!(cflag
& PARODD
)) {
2581 cval
|= UART_LCR_EPAR
;
2584 cval
|= UART_LCR_SPAR
;
2586 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
2587 if (info
->IsMoxaMustChipFlag
) {
2588 fcr
= UART_FCR_ENABLE_FIFO
;
2589 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2590 SET_MOXA_MUST_FIFO_VALUE(info
);
2594 fcr
= UART_FCR_ENABLE_FIFO
;
2595 // following add by Victor Yu. 08-30-2002
2596 if (info
->IsMoxaMustChipFlag
) {
2597 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2598 SET_MOXA_MUST_FIFO_VALUE(info
);
2600 // above add by Victor Yu. 08-30-2002
2602 switch (info
->rx_trigger
) {
2604 fcr
|= UART_FCR_TRIGGER_1
;
2607 fcr
|= UART_FCR_TRIGGER_4
;
2610 fcr
|= UART_FCR_TRIGGER_8
;
2613 fcr
|= UART_FCR_TRIGGER_14
;
2619 /* CTS flow control flag and modem status interrupts */
2620 info
->IER
&= ~UART_IER_MSI
;
2621 info
->MCR
&= ~UART_MCR_AFE
;
2622 if (cflag
& CRTSCTS
) {
2623 info
->flags
|= ASYNC_CTS_FLOW
;
2624 info
->IER
|= UART_IER_MSI
;
2625 if ((info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
2626 info
->MCR
|= UART_MCR_AFE
;
2627 //status = mxser_get_msr(info->base, 0, info->port);
2628 /* save_flags(flags);
2630 status = inb(baseaddr + UART_MSR);
2631 restore_flags(flags);*/
2632 //mxser_check_modem_status(info, status);
2634 //status = mxser_get_msr(info->base, 0, info->port);
2636 //MX_LOCK(&info->slock);
2637 status
= inb(info
->base
+ UART_MSR
);
2638 //MX_UNLOCK(&info->slock);
2639 if (info
->tty
->hw_stopped
) {
2640 if (status
& UART_MSR_CTS
) {
2641 info
->tty
->hw_stopped
= 0;
2642 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2643 info
->IER
|= UART_IER_THRI
;
2644 outb(info
->IER
, info
->base
+ UART_IER
);
2646 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2647 schedule_work(&info
->tqueue
); }
2649 if (!(status
& UART_MSR_CTS
)) {
2650 info
->tty
->hw_stopped
= 1;
2651 if ((info
->type
!= PORT_16550A
) && (!info
->IsMoxaMustChipFlag
)) {
2652 info
->IER
&= ~UART_IER_THRI
;
2653 outb(info
->IER
, info
->base
+ UART_IER
);
2659 info
->flags
&= ~ASYNC_CTS_FLOW
;
2661 outb(info
->MCR
, info
->base
+ UART_MCR
);
2662 if (cflag
& CLOCAL
) {
2663 info
->flags
&= ~ASYNC_CHECK_CD
;
2665 info
->flags
|= ASYNC_CHECK_CD
;
2666 info
->IER
|= UART_IER_MSI
;
2668 outb(info
->IER
, info
->base
+ UART_IER
);
2671 * Set up parity check flag
2673 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2674 if (I_INPCK(info
->tty
))
2675 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2676 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2677 info
->read_status_mask
|= UART_LSR_BI
;
2679 info
->ignore_status_mask
= 0;
2681 if (I_IGNBRK(info
->tty
)) {
2682 info
->ignore_status_mask
|= UART_LSR_BI
;
2683 info
->read_status_mask
|= UART_LSR_BI
;
2685 * If we're ignore parity and break indicators, ignore
2686 * overruns too. (For real raw support).
2688 if (I_IGNPAR(info
->tty
)) {
2689 info
->ignore_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2690 info
->read_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2693 // following add by Victor Yu. 09-02-2002
2694 if (info
->IsMoxaMustChipFlag
) {
2695 spin_lock_irqsave(&info
->slock
, flags
);
2696 SET_MOXA_MUST_XON1_VALUE(info
->base
, START_CHAR(info
->tty
));
2697 SET_MOXA_MUST_XOFF1_VALUE(info
->base
, STOP_CHAR(info
->tty
));
2698 if (I_IXON(info
->tty
)) {
2699 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2701 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2703 if (I_IXOFF(info
->tty
)) {
2704 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2706 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2709 if ( I_IXANY(info->tty) ) {
2710 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2711 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2713 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2714 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2717 spin_unlock_irqrestore(&info
->slock
, flags
);
2719 // above add by Victor Yu. 09-02-2002
2722 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2723 outb(cval
, info
->base
+ UART_LCR
);
2729 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
)
2734 unsigned long flags
;
2736 if (!info
->tty
|| !info
->tty
->termios
)
2742 if (newspd
> info
->MaxCanSetBaudRate
)
2745 info
->realbaud
= newspd
;
2746 if (newspd
== 134) {
2747 quot
= (2 * info
->baud_base
/ 269);
2748 } else if (newspd
) {
2749 quot
= info
->baud_base
/ newspd
;
2758 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
2759 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2762 spin_lock_irqsave(&info
->slock
, flags
);
2763 info
->MCR
|= UART_MCR_DTR
;
2764 outb(info
->MCR
, info
->base
+ UART_MCR
);
2765 spin_unlock_irqrestore(&info
->slock
, flags
);
2767 spin_lock_irqsave(&info
->slock
, flags
);
2768 info
->MCR
&= ~UART_MCR_DTR
;
2769 outb(info
->MCR
, info
->base
+ UART_MCR
);
2770 spin_unlock_irqrestore(&info
->slock
, flags
);
2774 cval
= inb(info
->base
+ UART_LCR
);
2776 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2778 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2779 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2780 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2789 * ------------------------------------------------------------
2790 * friends of mxser_ioctl()
2791 * ------------------------------------------------------------
2793 static int mxser_get_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*retinfo
)
2795 struct serial_struct tmp
;
2799 memset(&tmp
, 0, sizeof(tmp
));
2800 tmp
.type
= info
->type
;
2801 tmp
.line
= info
->port
;
2802 tmp
.port
= info
->base
;
2803 tmp
.irq
= info
->irq
;
2804 tmp
.flags
= info
->flags
;
2805 tmp
.baud_base
= info
->baud_base
;
2806 tmp
.close_delay
= info
->close_delay
;
2807 tmp
.closing_wait
= info
->closing_wait
;
2808 tmp
.custom_divisor
= info
->custom_divisor
;
2810 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2815 static int mxser_set_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*new_info
)
2817 struct serial_struct new_serial
;
2821 if (!new_info
|| !info
->base
)
2823 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2826 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
))
2829 flags
= info
->flags
& ASYNC_SPD_MASK
;
2831 if (!capable(CAP_SYS_ADMIN
)) {
2832 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
)))
2834 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) | (new_serial
.flags
& ASYNC_USR_MASK
));
2837 * OK, past this point, all the error checking has been done.
2838 * At this point, we start making changes.....
2840 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) | (new_serial
.flags
& ASYNC_FLAGS
));
2841 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2842 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2843 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2844 info
->tty
->low_latency
= 0; //(info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2847 /* added by casper, 3/17/2000, for mouse */
2848 info
->type
= new_serial
.type
;
2850 process_txrx_fifo(info
);
2853 if (info
->flags
& ASYNC_INITIALIZED
) {
2854 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2855 mxser_change_speed(info
, NULL
);
2858 retval
= mxser_startup(info
);
2864 * mxser_get_lsr_info - get line status register info
2866 * Purpose: Let user call ioctl() to get info when the UART physically
2867 * is emptied. On bus types like RS485, the transmitter must
2868 * release the bus after transmitting. This must be done when
2869 * the transmit shift register is empty, not be done when the
2870 * transmit holding register is empty. This functionality
2871 * allows an RS485 driver to be written in user space.
2873 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int __user
*value
)
2875 unsigned char status
;
2876 unsigned int result
;
2877 unsigned long flags
;
2879 spin_lock_irqsave(&info
->slock
, flags
);
2880 status
= inb(info
->base
+ UART_LSR
);
2881 spin_unlock_irqrestore(&info
->slock
, flags
);
2882 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2883 return put_user(result
, value
);
2887 * This routine sends a break character out the serial port.
2889 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2891 unsigned long flags
;
2895 set_current_state(TASK_INTERRUPTIBLE
);
2896 spin_lock_irqsave(&info
->slock
, flags
);
2897 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
2898 spin_unlock_irqrestore(&info
->slock
, flags
);
2899 schedule_timeout(duration
);
2900 spin_lock_irqsave(&info
->slock
, flags
);
2901 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
2902 spin_unlock_irqrestore(&info
->slock
, flags
);
2905 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2907 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2908 unsigned char control
, status
;
2909 unsigned long flags
;
2912 if (tty
->index
== MXSER_PORTS
)
2913 return (-ENOIOCTLCMD
);
2914 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2917 control
= info
->MCR
;
2919 spin_lock_irqsave(&info
->slock
, flags
);
2920 status
= inb(info
->base
+ UART_MSR
);
2921 if (status
& UART_MSR_ANY_DELTA
)
2922 mxser_check_modem_status(info
, status
);
2923 spin_unlock_irqrestore(&info
->slock
, flags
);
2924 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2925 ((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);
2928 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
, unsigned int set
, unsigned int clear
)
2930 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
2931 unsigned long flags
;
2934 if (tty
->index
== MXSER_PORTS
)
2935 return -ENOIOCTLCMD
;
2936 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2939 spin_lock_irqsave(&info
->slock
, flags
);
2941 if (set
& TIOCM_RTS
)
2942 info
->MCR
|= UART_MCR_RTS
;
2943 if (set
& TIOCM_DTR
)
2944 info
->MCR
|= UART_MCR_DTR
;
2946 if (clear
& TIOCM_RTS
)
2947 info
->MCR
&= ~UART_MCR_RTS
;
2948 if (clear
& TIOCM_DTR
)
2949 info
->MCR
&= ~UART_MCR_DTR
;
2951 outb(info
->MCR
, info
->base
+ UART_MCR
);
2952 spin_unlock_irqrestore(&info
->slock
, flags
);
2957 static int mxser_read_register(int, unsigned short *);
2958 static int mxser_program_mode(int);
2959 static void mxser_normal_mode(int);
2961 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2964 unsigned short regs
[16], irq
;
2965 unsigned char scratch
, scratch2
;
2967 hwconf
->IsMoxaMustChipFlag
= MOXA_OTHER_UART
;
2969 id
= mxser_read_register(cap
, regs
);
2970 if (id
== C168_ASIC_ID
) {
2971 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2973 } else if (id
== C104_ASIC_ID
) {
2974 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2976 } else if (id
== C102_ASIC_ID
) {
2977 hwconf
->board_type
= MXSER_BOARD_C102_ISA
;
2979 } else if (id
== CI132_ASIC_ID
) {
2980 hwconf
->board_type
= MXSER_BOARD_CI132
;
2982 } else if (id
== CI134_ASIC_ID
) {
2983 hwconf
->board_type
= MXSER_BOARD_CI134
;
2985 } else if (id
== CI104J_ASIC_ID
) {
2986 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2992 if (hwconf
->ports
== 2) {
2993 irq
= regs
[9] & 0xF000;
2994 irq
= irq
| (irq
>> 4);
2995 if (irq
!= (regs
[9] & 0xFF00))
2996 return (MXSER_ERR_IRQ_CONFLIT
);
2997 } else if (hwconf
->ports
== 4) {
2998 irq
= regs
[9] & 0xF000;
2999 irq
= irq
| (irq
>> 4);
3000 irq
= irq
| (irq
>> 8);
3002 return (MXSER_ERR_IRQ_CONFLIT
);
3003 } else if (hwconf
->ports
== 8) {
3004 irq
= regs
[9] & 0xF000;
3005 irq
= irq
| (irq
>> 4);
3006 irq
= irq
| (irq
>> 8);
3007 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
3008 return (MXSER_ERR_IRQ_CONFLIT
);
3012 return (MXSER_ERR_IRQ
);
3014 hwconf
->irq
= ((int) (irq
& 0xF000) >> 12);
3015 for (i
= 0; i
< 8; i
++)
3016 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
3017 if ((regs
[12] & 0x80) == 0) {
3018 return (MXSER_ERR_VECTOR
);
3020 hwconf
->vector
= (int) regs
[11]; /* interrupt vector */
3022 hwconf
->vector_mask
= 0x00FF;
3024 hwconf
->vector_mask
= 0x000F;
3025 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
3026 if (regs
[12] & bits
) {
3027 hwconf
->baud_base
[i
] = 921600;
3028 hwconf
->MaxCanSetBaudRate
[i
] = 921600; // add by Victor Yu. 09-04-2002
3030 hwconf
->baud_base
[i
] = 115200;
3031 hwconf
->MaxCanSetBaudRate
[i
] = 115200; // add by Victor Yu. 09-04-2002
3034 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
3035 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
3036 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
3037 outb(scratch2
, cap
+ UART_LCR
);
3038 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
3039 scratch
= inb(cap
+ UART_IIR
);
3042 hwconf
->uart_type
= PORT_16550A
;
3044 hwconf
->uart_type
= PORT_16450
;
3049 request_region(hwconf
->ioaddr
[0], 8 * hwconf
->ports
, "mxser(IO)");
3050 request_region(hwconf
->vector
, 1, "mxser(vector)");
3051 return (hwconf
->ports
);
3054 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3055 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3056 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3057 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3058 #define EN_CCMD 0x000 /* Chip's command register */
3059 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3060 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3061 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3062 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3063 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3064 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3065 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3066 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3067 static int mxser_read_register(int port
, unsigned short *regs
)
3069 int i
, k
, value
, id
;
3072 id
= mxser_program_mode(port
);
3075 for (i
= 0; i
< 14; i
++) {
3076 k
= (i
& 0x3F) | 0x180;
3077 for (j
= 0x100; j
> 0; j
>>= 1) {
3078 outb(CHIP_CS
, port
);
3080 outb(CHIP_CS
| CHIP_DO
, port
);
3081 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
3083 outb(CHIP_CS
, port
);
3084 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
3089 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
3090 outb(CHIP_CS
, port
);
3091 outb(CHIP_CS
| CHIP_SK
, port
);
3092 if (inb(port
) & CHIP_DI
)
3098 mxser_normal_mode(port
);
3102 static int mxser_program_mode(int port
)
3105 //unsigned long flags;
3107 spin_lock(&gm_lock
);
3115 //restore_flags(flags);
3116 spin_unlock(&gm_lock
);
3118 id
= inb(port
+ 1) & 0x1F;
3119 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
))
3121 for (i
= 0, j
= 0; i
< 4; i
++) {
3125 } else if ((j
== 1) && (n
== 1)) {
3136 static void mxser_normal_mode(int port
)
3140 outb(0xA5, port
+ 1);
3141 outb(0x80, port
+ 3);
3142 outb(12, port
+ 0); /* 9600 bps */
3144 outb(0x03, port
+ 3); /* 8 data bits */
3145 outb(0x13, port
+ 4); /* loop back mode */
3146 for (i
= 0; i
< 16; i
++) {
3148 if ((n
& 0x61) == 0x60)
3153 outb(0x00, port
+ 4);
3156 module_init(mxser_module_init
);
3157 module_exit(mxser_module_exit
);