2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2001 Moxa Technologies (support@moxa.com.tw).
6 * This code is loosely based on the Linux serial driver, written by
7 * Linus Torvalds, Theodore T'so and others.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Original release 10/26/00
25 * 02/06/01 Support MOXA Industio family boards.
26 * 02/06/01 Support TIOCGICOUNT.
27 * 02/06/01 Fix the problem for connecting to serial mouse.
28 * 02/06/01 Fix the problem for H/W flow control.
29 * 02/06/01 Fix the compling warning when CONFIG_PCI
32 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
33 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
34 * - Fixed x86_64 cleanness
35 * - Fixed sleep with spinlock held in mxser_send_break
39 #include <linux/module.h>
40 #include <linux/errno.h>
41 #include <linux/signal.h>
42 #include <linux/sched.h>
43 #include <linux/timer.h>
44 #include <linux/interrupt.h>
45 #include <linux/tty.h>
46 #include <linux/tty_flip.h>
47 #include <linux/serial.h>
48 #include <linux/serial_reg.h>
49 #include <linux/major.h>
50 #include <linux/string.h>
51 #include <linux/fcntl.h>
52 #include <linux/ptrace.h>
53 #include <linux/gfp.h>
54 #include <linux/ioport.h>
56 #include <linux/delay.h>
57 #include <linux/pci.h>
58 #include <linux/bitops.h>
60 #include <asm/system.h>
63 #include <asm/uaccess.h>
67 #define MXSER_VERSION "1.8"
68 #define MXSERMAJOR 174
69 #define MXSERCUMAJOR 175
71 #define MXSER_EVENT_TXLOW 1
72 #define MXSER_EVENT_HANGUP 2
74 #define MXSER_BOARDS 4 /* Max. boards */
75 #define MXSER_PORTS 32 /* Max. ports */
76 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
77 #define MXSER_ISR_PASS_LIMIT 256
79 #define MXSER_ERR_IOADDR -1
80 #define MXSER_ERR_IRQ -2
81 #define MXSER_ERR_IRQ_CONFLIT -3
82 #define MXSER_ERR_VECTOR -4
84 #define WAKEUP_CHARS 256
86 #define UART_MCR_AFE 0x20
87 #define UART_LSR_SPECIAL 0x1E
90 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : IRQF_DISABLED)
92 #define C168_ASIC_ID 1
93 #define C104_ASIC_ID 2
94 #define C102_ASIC_ID 0xB
95 #define CI132_ASIC_ID 4
96 #define CI134_ASIC_ID 3
97 #define CI104J_ASIC_ID 5
100 MXSER_BOARD_C168_ISA
= 1,
101 MXSER_BOARD_C104_ISA
,
103 MXSER_BOARD_C168_PCI
,
104 MXSER_BOARD_C104_PCI
,
105 MXSER_BOARD_C102_ISA
,
123 static char *mxser_brdname
[] = {
141 "Moxa UC7000 Serial",
147 static int mxser_numports
[] = {
171 #define UART_TYPE_NUM 2
173 static const unsigned int Gmoxa_uart_id
[UART_TYPE_NUM
] = {
174 MOXA_MUST_MU150_HWID
,
178 /* This is only for PCI */
179 #define UART_INFO_NUM 3
180 struct mxpciuart_info
{
191 static const struct mxpciuart_info Gpci_uart_info
[UART_INFO_NUM
] = {
192 {MOXA_OTHER_UART
, 16, 16, 16, 14, 14, 1, 921600L},
193 {MOXA_MUST_MU150_HWID
, 64, 64, 64, 48, 48, 16, 230400L},
194 {MOXA_MUST_MU860_HWID
, 128, 128, 128, 96, 96, 32, 921600L}
200 static struct pci_device_id mxser_pcibrds
[] = {
201 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_C168
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_C168_PCI
},
202 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_C104
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_C104_PCI
},
203 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP132
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP132
},
204 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP114
},
205 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CT114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CT114
},
206 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102
},
207 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP104U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP104U
},
208 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP168U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP168U
},
209 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP132U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP132U
},
210 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP134U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP134U
},
211 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP104JU
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP104JU
},
212 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_RC7000
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_RC7000
},
213 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP118U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP118U
},
214 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102UL
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102UL
},
215 {PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_MOXA_CP102U
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, MXSER_BOARD_CP102U
},
219 MODULE_DEVICE_TABLE(pci
, mxser_pcibrds
);
224 typedef struct _moxa_pci_info
{
225 unsigned short busNum
;
226 unsigned short devNum
;
227 struct pci_dev
*pdev
; /* add by Victor Yu. 06-23-2003 */
230 static int ioaddr
[MXSER_BOARDS
] = { 0, 0, 0, 0 };
231 static int ttymajor
= MXSERMAJOR
;
232 static int calloutmajor
= MXSERCUMAJOR
;
233 static int verbose
= 0;
235 /* Variables for insmod */
237 MODULE_AUTHOR("Casper Yang");
238 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
239 module_param_array(ioaddr
, int, NULL
, 0);
240 module_param(ttymajor
, int, 0);
241 module_param(calloutmajor
, int, 0);
242 module_param(verbose
, bool, 0);
243 MODULE_LICENSE("GPL");
247 unsigned long rxcnt
[MXSER_PORTS
];
248 unsigned long txcnt
[MXSER_PORTS
];
255 unsigned long up_rxcnt
;
256 unsigned long up_txcnt
;
258 unsigned char hold_reason
;
261 struct mxser_mon_ext
{
262 unsigned long rx_cnt
[32];
263 unsigned long tx_cnt
[32];
264 unsigned long up_rxcnt
[32];
265 unsigned long up_txcnt
[32];
266 int modem_status
[32];
277 struct mxser_hwconf
{
284 int ioaddr
[MXSER_PORTS_PER_BOARD
];
285 int baud_base
[MXSER_PORTS_PER_BOARD
];
286 moxa_pci_info pciInfo
;
287 int IsMoxaMustChipFlag
; /* add by Victor Yu. 08-30-2002 */
288 int MaxCanSetBaudRate
[MXSER_PORTS_PER_BOARD
]; /* add by Victor Yu. 09-04-2002 */
289 int opmode_ioaddr
[MXSER_PORTS_PER_BOARD
]; /* add by Victor Yu. 01-05-2004 */
292 struct mxser_struct
{
294 int base
; /* port base address */
295 int irq
; /* port using irq no. */
296 int vector
; /* port irq vector */
297 int vectormask
; /* port vector mask */
299 int rx_trigger
; /* Rx fifo trigger level */
301 int baud_base
; /* max. speed */
302 int flags
; /* defined in tty.h */
303 int type
; /* UART type */
304 struct tty_struct
*tty
;
305 int read_status_mask
;
306 int ignore_status_mask
;
309 int x_char
; /* xon/xoff character */
311 unsigned short closing_wait
;
312 int IER
; /* Interrupt Enable Register */
313 int MCR
; /* Modem control register */
315 int count
; /* # of fd on device */
316 int blocked_open
; /* # of blocked opens */
317 unsigned char *xmit_buf
;
321 struct work_struct tqueue
;
322 struct ktermios normal_termios
;
323 struct ktermios callout_termios
;
324 wait_queue_head_t open_wait
;
325 wait_queue_head_t close_wait
;
326 wait_queue_head_t delta_msr_wait
;
327 struct async_icount icount
; /* kernel counters for the 4 input interrupts */
329 int IsMoxaMustChipFlag
; /* add by Victor Yu. 08-30-2002 */
330 int MaxCanSetBaudRate
; /* add by Victor Yu. 09-04-2002 */
331 int opmode_ioaddr
; /* add by Victor Yu. 01-05-2004 */
332 unsigned char stop_rx
;
333 unsigned char ldisc_stop_rx
;
335 struct mxser_mon mon_data
;
336 unsigned char err_shadow
;
340 struct mxser_mstatus
{
348 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
350 static int mxserBoardCAP
[MXSER_BOARDS
] = {
352 /* 0x180, 0x280, 0x200, 0x320 */
355 static struct tty_driver
*mxvar_sdriver
;
356 static struct mxser_struct mxvar_table
[MXSER_PORTS
];
357 static struct tty_struct
*mxvar_tty
[MXSER_PORTS
+ 1];
358 static struct ktermios
*mxvar_termios
[MXSER_PORTS
+ 1];
359 static struct ktermios
*mxvar_termios_locked
[MXSER_PORTS
+ 1];
360 static struct mxser_log mxvar_log
;
361 static int mxvar_diagflag
;
362 static unsigned char mxser_msr
[MXSER_PORTS
+ 1];
363 static struct mxser_mon_ext mon_data_ext
;
364 static int mxser_set_baud_method
[MXSER_PORTS
+ 1];
365 static spinlock_t gm_lock
;
368 * This is used to figure out the divisor speeds and the timeouts
371 static struct mxser_hwconf mxsercfg
[MXSER_BOARDS
];
377 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
);
378 static int mxser_init(void);
380 /* static void mxser_poll(unsigned long); */
381 static int mxser_get_ISA_conf(int, struct mxser_hwconf
*);
382 static void mxser_do_softint(struct work_struct
*);
383 static int mxser_open(struct tty_struct
*, struct file
*);
384 static void mxser_close(struct tty_struct
*, struct file
*);
385 static int mxser_write(struct tty_struct
*, const unsigned char *, int);
386 static int mxser_write_room(struct tty_struct
*);
387 static void mxser_flush_buffer(struct tty_struct
*);
388 static int mxser_chars_in_buffer(struct tty_struct
*);
389 static void mxser_flush_chars(struct tty_struct
*);
390 static void mxser_put_char(struct tty_struct
*, unsigned char);
391 static int mxser_ioctl(struct tty_struct
*, struct file
*, uint
, ulong
);
392 static int mxser_ioctl_special(unsigned int, void __user
*);
393 static void mxser_throttle(struct tty_struct
*);
394 static void mxser_unthrottle(struct tty_struct
*);
395 static void mxser_set_termios(struct tty_struct
*, struct ktermios
*);
396 static void mxser_stop(struct tty_struct
*);
397 static void mxser_start(struct tty_struct
*);
398 static void mxser_hangup(struct tty_struct
*);
399 static void mxser_rs_break(struct tty_struct
*, int);
400 static irqreturn_t
mxser_interrupt(int, void *);
401 static void mxser_receive_chars(struct mxser_struct
*, int *);
402 static void mxser_transmit_chars(struct mxser_struct
*);
403 static void mxser_check_modem_status(struct mxser_struct
*, int);
404 static int mxser_block_til_ready(struct tty_struct
*, struct file
*, struct mxser_struct
*);
405 static int mxser_startup(struct mxser_struct
*);
406 static void mxser_shutdown(struct mxser_struct
*);
407 static int mxser_change_speed(struct mxser_struct
*, struct ktermios
*old_termios
);
408 static int mxser_get_serial_info(struct mxser_struct
*, struct serial_struct __user
*);
409 static int mxser_set_serial_info(struct mxser_struct
*, struct serial_struct __user
*);
410 static int mxser_get_lsr_info(struct mxser_struct
*, unsigned int __user
*);
411 static void mxser_send_break(struct mxser_struct
*, int);
412 static int mxser_tiocmget(struct tty_struct
*, struct file
*);
413 static int mxser_tiocmset(struct tty_struct
*, struct file
*, unsigned int, unsigned int);
414 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
);
415 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
);
417 static void mxser_startrx(struct tty_struct
*tty
);
418 static void mxser_stoprx(struct tty_struct
*tty
);
421 static int CheckIsMoxaMust(int io
)
426 outb(0, io
+ UART_LCR
);
427 DISABLE_MOXA_MUST_ENCHANCE_MODE(io
);
428 oldmcr
= inb(io
+ UART_MCR
);
429 outb(0, io
+ UART_MCR
);
430 SET_MOXA_MUST_XON1_VALUE(io
, 0x11);
431 if ((hwid
= inb(io
+ UART_MCR
)) != 0) {
432 outb(oldmcr
, io
+ UART_MCR
);
433 return MOXA_OTHER_UART
;
436 GET_MOXA_MUST_HARDWARE_ID(io
, &hwid
);
437 for (i
= 0; i
< UART_TYPE_NUM
; i
++) {
438 if (hwid
== Gmoxa_uart_id
[i
])
441 return MOXA_OTHER_UART
;
445 /* above is modified by Victor Yu. 08-15-2002 */
447 static const struct tty_operations mxser_ops
= {
449 .close
= mxser_close
,
450 .write
= mxser_write
,
451 .put_char
= mxser_put_char
,
452 .flush_chars
= mxser_flush_chars
,
453 .write_room
= mxser_write_room
,
454 .chars_in_buffer
= mxser_chars_in_buffer
,
455 .flush_buffer
= mxser_flush_buffer
,
456 .ioctl
= mxser_ioctl
,
457 .throttle
= mxser_throttle
,
458 .unthrottle
= mxser_unthrottle
,
459 .set_termios
= mxser_set_termios
,
461 .start
= mxser_start
,
462 .hangup
= mxser_hangup
,
463 .break_ctl
= mxser_rs_break
,
464 .wait_until_sent
= mxser_wait_until_sent
,
465 .tiocmget
= mxser_tiocmget
,
466 .tiocmset
= mxser_tiocmset
,
470 * The MOXA Smartio/Industio serial driver boot-time initialization code!
473 static int __init
mxser_module_init(void)
478 printk(KERN_DEBUG
"Loading module mxser ...\n");
481 printk(KERN_DEBUG
"Done.\n");
485 static void __exit
mxser_module_exit(void)
490 printk(KERN_DEBUG
"Unloading module mxser ...\n");
492 err
= tty_unregister_driver(mxvar_sdriver
);
494 put_tty_driver(mxvar_sdriver
);
496 printk(KERN_ERR
"Couldn't unregister MOXA Smartio/Industio family serial driver\n");
498 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
499 struct pci_dev
*pdev
;
501 if (mxsercfg
[i
].board_type
== -1)
504 pdev
= mxsercfg
[i
].pciInfo
.pdev
;
505 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
506 if (pdev
!= NULL
) { /* PCI */
507 release_region(pci_resource_start(pdev
, 2), pci_resource_len(pdev
, 2));
508 release_region(pci_resource_start(pdev
, 3), pci_resource_len(pdev
, 3));
511 release_region(mxsercfg
[i
].ioaddr
[0], 8 * mxsercfg
[i
].ports
);
512 release_region(mxsercfg
[i
].vector
, 1);
517 printk(KERN_DEBUG
"Done.\n");
520 static void process_txrx_fifo(struct mxser_struct
*info
)
524 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
525 info
->rx_trigger
= 1;
526 info
->rx_high_water
= 1;
527 info
->rx_low_water
= 1;
528 info
->xmit_fifo_size
= 1;
530 for (i
= 0; i
< UART_INFO_NUM
; i
++) {
531 if (info
->IsMoxaMustChipFlag
== Gpci_uart_info
[i
].type
) {
532 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
533 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
534 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
535 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
542 static int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
544 struct mxser_struct
*info
;
548 n
= board
* MXSER_PORTS_PER_BOARD
;
549 info
= &mxvar_table
[n
];
551 printk(KERN_DEBUG
" ttyMI%d - ttyMI%d ",
552 n
, n
+ hwconf
->ports
- 1);
553 printk(" max. baud rate = %d bps.\n",
554 hwconf
->MaxCanSetBaudRate
[0]);
557 for (i
= 0; i
< hwconf
->ports
; i
++, n
++, info
++) {
559 info
->base
= hwconf
->ioaddr
[i
];
560 info
->irq
= hwconf
->irq
;
561 info
->vector
= hwconf
->vector
;
562 info
->vectormask
= hwconf
->vector_mask
;
563 info
->opmode_ioaddr
= hwconf
->opmode_ioaddr
[i
]; /* add by Victor Yu. 01-05-2004 */
565 info
->ldisc_stop_rx
= 0;
567 info
->IsMoxaMustChipFlag
= hwconf
->IsMoxaMustChipFlag
;
568 /* Enhance mode enabled here */
569 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
570 ENABLE_MOXA_MUST_ENCHANCE_MODE(info
->base
);
573 info
->flags
= ASYNC_SHARE_IRQ
;
574 info
->type
= hwconf
->uart_type
;
575 info
->baud_base
= hwconf
->baud_base
[i
];
577 info
->MaxCanSetBaudRate
= hwconf
->MaxCanSetBaudRate
[i
];
579 process_txrx_fifo(info
);
582 info
->custom_divisor
= hwconf
->baud_base
[i
] * 16;
583 info
->close_delay
= 5 * HZ
/ 10;
584 info
->closing_wait
= 30 * HZ
;
585 INIT_WORK(&info
->tqueue
, mxser_do_softint
);
586 info
->normal_termios
= mxvar_sdriver
->init_termios
;
587 init_waitqueue_head(&info
->open_wait
);
588 init_waitqueue_head(&info
->close_wait
);
589 init_waitqueue_head(&info
->delta_msr_wait
);
590 memset(&info
->mon_data
, 0, sizeof(struct mxser_mon
));
591 info
->err_shadow
= 0;
592 spin_lock_init(&info
->slock
);
595 * Allocate the IRQ if necessary
599 /* before set INT ISR, disable all int */
600 for (i
= 0; i
< hwconf
->ports
; i
++) {
601 outb(inb(hwconf
->ioaddr
[i
] + UART_IER
) & 0xf0,
602 hwconf
->ioaddr
[i
] + UART_IER
);
605 n
= board
* MXSER_PORTS_PER_BOARD
;
606 info
= &mxvar_table
[n
];
608 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
),
611 printk(KERN_ERR
"Board %d: %s",
612 board
, mxser_brdname
[hwconf
->board_type
- 1]);
613 printk(" Request irq failed, IRQ (%d) may conflict with"
614 " 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
)
629 /* unsigned int val; */
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),
640 for (i
= 0; i
< hwconf
->ports
; i
++)
641 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),
647 hwconf
->vector
= ioaddress
;
650 hwconf
->irq
= hwconf
->pciInfo
.pdev
->irq
;
652 hwconf
->IsMoxaMustChipFlag
= CheckIsMoxaMust(hwconf
->ioaddr
[0]);
653 hwconf
->uart_type
= PORT_16550A
;
654 hwconf
->vector_mask
= 0;
657 for (i
= 0; i
< hwconf
->ports
; i
++) {
658 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
659 if (Gpci_uart_info
[j
].type
== hwconf
->IsMoxaMustChipFlag
) {
660 hwconf
->MaxCanSetBaudRate
[i
] = Gpci_uart_info
[j
].max_baud
;
662 /* exception....CP-102 */
663 if (board_type
== MXSER_BOARD_CP102
)
664 hwconf
->MaxCanSetBaudRate
[i
] = 921600;
670 if (hwconf
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
) {
671 for (i
= 0; i
< hwconf
->ports
; i
++) {
673 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 4;
675 hwconf
->opmode_ioaddr
[i
] = ioaddress
+ 0x0c;
677 outb(0, ioaddress
+ 4); /* default set to RS232 mode */
678 outb(0, ioaddress
+ 0x0c); /* default set to RS232 mode */
681 for (i
= 0; i
< hwconf
->ports
; i
++) {
682 hwconf
->vector_mask
|= (1 << i
);
683 hwconf
->baud_base
[i
] = 921600;
689 static int mxser_init(void)
691 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",
709 /* Initialize the tty_driver structure */
710 memset(mxvar_sdriver
, 0, sizeof(struct tty_driver
));
711 mxvar_sdriver
->owner
= THIS_MODULE
;
712 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
713 mxvar_sdriver
->name
= "ttyMI";
714 mxvar_sdriver
->major
= ttymajor
;
715 mxvar_sdriver
->minor_start
= 0;
716 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
717 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
718 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
719 mxvar_sdriver
->init_termios
= tty_std_termios
;
720 mxvar_sdriver
->init_termios
.c_cflag
= B9600
|CS8
|CREAD
|HUPCL
|CLOCAL
;
721 mxvar_sdriver
->init_termios
.c_ispeed
= 9600;
722 mxvar_sdriver
->init_termios
.c_ospeed
= 9600;
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
++) {
743 if (!(cap
= mxserBoardCAP
[b
]))
746 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
749 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n",
750 mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
753 if (retval
== MXSER_ERR_IRQ
)
754 printk(KERN_ERR
"Invalid interrupt number, "
755 "board not configured\n");
756 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
757 printk(KERN_ERR
"Invalid interrupt number, "
758 "board not configured\n");
759 else if (retval
== MXSER_ERR_VECTOR
)
760 printk(KERN_ERR
"Invalid interrupt vector, "
761 "board not configured\n");
762 else if (retval
== MXSER_ERR_IOADDR
)
763 printk(KERN_ERR
"Invalid I/O address, "
764 "board not configured\n");
769 hwconf
.pciInfo
.busNum
= 0;
770 hwconf
.pciInfo
.devNum
= 0;
771 hwconf
.pciInfo
.pdev
= NULL
;
773 mxser_getcfg(m
, &hwconf
);
775 * init mxsercfg first,
776 * or mxsercfg data is not correct on ISR.
778 /* mxser_initbrd will hook ISR. */
779 if (mxser_initbrd(m
, &hwconf
) < 0)
785 /* Start finding ISA boards from module arg */
786 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
789 if (!(cap
= ioaddr
[b
]))
792 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
795 printk(KERN_INFO
"Found MOXA %s board (CAP=0x%x)\n",
796 mxser_brdname
[hwconf
.board_type
- 1], ioaddr
[b
]);
799 if (retval
== MXSER_ERR_IRQ
)
800 printk(KERN_ERR
"Invalid interrupt number, "
801 "board not configured\n");
802 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
803 printk(KERN_ERR
"Invalid interrupt number, "
804 "board not configured\n");
805 else if (retval
== MXSER_ERR_VECTOR
)
806 printk(KERN_ERR
"Invalid interrupt vector, "
807 "board not configured\n");
808 else if (retval
== MXSER_ERR_IOADDR
)
809 printk(KERN_ERR
"Invalid I/O address, "
810 "board not configured\n");
815 hwconf
.pciInfo
.busNum
= 0;
816 hwconf
.pciInfo
.devNum
= 0;
817 hwconf
.pciInfo
.pdev
= NULL
;
819 mxser_getcfg(m
, &hwconf
);
821 * init mxsercfg first,
822 * or mxsercfg data is not correct on ISR.
824 /* mxser_initbrd will hook ISR. */
825 if (mxser_initbrd(m
, &hwconf
) < 0)
831 /* start finding PCI board here */
833 n
= ARRAY_SIZE(mxser_pcibrds
) - 1;
837 pdev
= pci_get_device(mxser_pcibrds
[b
].vendor
,
838 mxser_pcibrds
[b
].device
, pdev
);
843 hwconf
.pciInfo
.busNum
= busnum
= pdev
->bus
->number
;
844 hwconf
.pciInfo
.devNum
= devnum
= PCI_SLOT(pdev
->devfn
) << 3;
845 hwconf
.pciInfo
.pdev
= pdev
;
846 printk(KERN_INFO
"Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
847 mxser_brdname
[(int) (mxser_pcibrds
[b
].driver_data
) - 1],
848 busnum
, devnum
>> 3);
850 if (m
>= MXSER_BOARDS
)
852 "Too many Smartio/Industio family boards find "
853 "(maximum %d), board not configured\n",
856 if (pci_enable_device(pdev
)) {
857 printk(KERN_ERR
"Moxa SmartI/O PCI enable "
861 retval
= mxser_get_PCI_conf(busnum
, devnum
,
862 (int)mxser_pcibrds
[b
].driver_data
,
865 if (retval
== MXSER_ERR_IRQ
)
867 "Invalid interrupt number, "
868 "board not configured\n");
869 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
871 "Invalid interrupt number, "
872 "board not configured\n");
873 else if (retval
== MXSER_ERR_VECTOR
)
875 "Invalid interrupt vector, "
876 "board not configured\n");
877 else if (retval
== MXSER_ERR_IOADDR
)
879 "Invalid I/O address, "
880 "board not configured\n");
883 mxser_getcfg(m
, &hwconf
);
884 /* init mxsercfg first,
885 * or mxsercfg data is not correct on ISR.
887 /* mxser_initbrd will hook ISR. */
888 if (mxser_initbrd(m
, &hwconf
) < 0)
891 /* Keep an extra reference if we succeeded. It will
892 be returned at unload time */
898 retval
= tty_register_driver(mxvar_sdriver
);
900 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family"
902 put_tty_driver(mxvar_sdriver
);
904 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
905 if (mxsercfg
[i
].board_type
== -1)
908 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
909 /* todo: release io, vector */
918 static void mxser_do_softint(struct work_struct
*work
)
920 struct mxser_struct
*info
=
921 container_of(work
, struct mxser_struct
, tqueue
);
922 struct tty_struct
*tty
;
927 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
))
929 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
))
934 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
, struct mxser_struct
*info
)
936 unsigned char status
= 0;
938 status
= inb(baseaddr
+ UART_MSR
);
940 mxser_msr
[port
] &= 0x0F;
941 mxser_msr
[port
] |= status
;
942 status
= mxser_msr
[port
];
950 * This routine is called whenever a serial port is opened. It
951 * enables interrupts for a serial port, linking in its async structure into
952 * the IRQ chain. It also performs the serial-specific
953 * initialization for the tty structure.
955 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
957 struct mxser_struct
*info
;
960 /* initialize driver_data in case something fails */
961 tty
->driver_data
= NULL
;
964 if (line
== MXSER_PORTS
)
966 if (line
< 0 || line
> MXSER_PORTS
)
968 info
= mxvar_table
+ line
;
972 tty
->driver_data
= info
;
975 * Start up serial port
977 retval
= mxser_startup(info
);
981 retval
= mxser_block_til_ready(tty
, filp
, info
);
987 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
988 if (tty
->driver
->subtype
== SERIAL_TYPE_NORMAL
)
989 *tty
->termios
= info
->normal_termios
;
991 *tty
->termios
= info
->callout_termios
;
992 mxser_change_speed(info
, NULL
);
996 status = mxser_get_msr(info->base, 0, info->port);
997 mxser_check_modem_status(info, status);
1000 /* unmark here for very high baud rate (ex. 921600 bps) used */
1001 tty
->low_latency
= 1;
1006 * This routine is called when the serial port gets closed. First, we
1007 * wait for the last remaining data to be sent. Then, we unlink its
1008 * async structure from the interrupt chain if necessary, and we free
1009 * that IRQ if nothing is left in the chain.
1011 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
1013 struct mxser_struct
*info
= tty
->driver_data
;
1015 unsigned long timeout
;
1016 unsigned long flags
;
1017 struct tty_ldisc
*ld
;
1019 if (tty
->index
== MXSER_PORTS
)
1024 spin_lock_irqsave(&info
->slock
, flags
);
1026 if (tty_hung_up_p(filp
)) {
1027 spin_unlock_irqrestore(&info
->slock
, flags
);
1030 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1032 * Uh, oh. tty->count is 1, which means that the tty
1033 * structure will be freed. Info->count should always
1034 * be one in these conditions. If it's greater than
1035 * one, we've got real problems, since it means the
1036 * serial port won't be shutdown.
1038 printk(KERN_ERR
"mxser_close: bad serial port count; "
1039 "tty->count is 1, info->count is %d\n", info
->count
);
1042 if (--info
->count
< 0) {
1043 printk(KERN_ERR
"mxser_close: bad serial port count for "
1044 "ttys%d: %d\n", info
->port
, info
->count
);
1048 spin_unlock_irqrestore(&info
->slock
, flags
);
1051 info
->flags
|= ASYNC_CLOSING
;
1052 spin_unlock_irqrestore(&info
->slock
, flags
);
1054 * Save the termios structure, since this port may have
1055 * separate termios for callout and dialin.
1057 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1058 info
->normal_termios
= *tty
->termios
;
1060 * Now we wait for the transmit buffer to clear; and we notify
1061 * the line discipline to only process XON/XOFF characters.
1064 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1065 tty_wait_until_sent(tty
, info
->closing_wait
);
1067 * At this point we stop accepting input. To do this, we
1068 * disable the receive line status interrupts, and tell the
1069 * interrupt driver to stop checking the data ready bit in the
1070 * line status register.
1072 info
->IER
&= ~UART_IER_RLSI
;
1073 if (info
->IsMoxaMustChipFlag
)
1074 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1076 info->read_status_mask &= ~UART_LSR_DR;
1078 if (info
->flags
& ASYNC_INITIALIZED
) {
1079 outb(info
->IER
, info
->base
+ UART_IER
);
1081 * Before we drop DTR, make sure the UART transmitter
1082 * has completely drained; this is especially
1083 * important if there is a transmit FIFO!
1085 timeout
= jiffies
+ HZ
;
1086 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
1087 schedule_timeout_interruptible(5);
1088 if (time_after(jiffies
, timeout
))
1092 mxser_shutdown(info
);
1094 if (tty
->driver
->flush_buffer
)
1095 tty
->driver
->flush_buffer(tty
);
1097 ld
= tty_ldisc_ref(tty
);
1099 if (ld
->flush_buffer
)
1100 ld
->flush_buffer(tty
);
1101 tty_ldisc_deref(ld
);
1107 if (info
->blocked_open
) {
1108 if (info
->close_delay
)
1109 schedule_timeout_interruptible(info
->close_delay
);
1110 wake_up_interruptible(&info
->open_wait
);
1113 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1114 wake_up_interruptible(&info
->close_wait
);
1118 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1121 struct mxser_struct
*info
= tty
->driver_data
;
1122 unsigned long flags
;
1124 if (!info
->xmit_buf
)
1128 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1129 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1133 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1134 spin_lock_irqsave(&info
->slock
, flags
);
1135 info
->xmit_head
= (info
->xmit_head
+ c
) &
1136 (SERIAL_XMIT_SIZE
- 1);
1137 info
->xmit_cnt
+= c
;
1138 spin_unlock_irqrestore(&info
->slock
, flags
);
1145 if (info
->xmit_cnt
&& !tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1146 if (!tty
->hw_stopped
||
1147 (info
->type
== PORT_16550A
) ||
1148 (info
->IsMoxaMustChipFlag
)) {
1149 spin_lock_irqsave(&info
->slock
, flags
);
1150 info
->IER
|= UART_IER_THRI
;
1151 outb(info
->IER
, info
->base
+ UART_IER
);
1152 spin_unlock_irqrestore(&info
->slock
, flags
);
1158 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1160 struct mxser_struct
*info
= tty
->driver_data
;
1161 unsigned long flags
;
1163 if (!info
->xmit_buf
)
1166 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1169 spin_lock_irqsave(&info
->slock
, flags
);
1170 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1171 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1173 spin_unlock_irqrestore(&info
->slock
, flags
);
1174 if (!tty
->stopped
&& !(info
->IER
& UART_IER_THRI
)) {
1175 if (!tty
->hw_stopped
||
1176 (info
->type
== PORT_16550A
) ||
1177 info
->IsMoxaMustChipFlag
) {
1178 spin_lock_irqsave(&info
->slock
, flags
);
1179 info
->IER
|= UART_IER_THRI
;
1180 outb(info
->IER
, info
->base
+ UART_IER
);
1181 spin_unlock_irqrestore(&info
->slock
, flags
);
1187 static void mxser_flush_chars(struct tty_struct
*tty
)
1189 struct mxser_struct
*info
= tty
->driver_data
;
1190 unsigned long flags
;
1192 if (info
->xmit_cnt
<= 0 ||
1196 (info
->type
!= PORT_16550A
) &&
1197 (!info
->IsMoxaMustChipFlag
)
1201 spin_lock_irqsave(&info
->slock
, flags
);
1203 info
->IER
|= UART_IER_THRI
;
1204 outb(info
->IER
, info
->base
+ UART_IER
);
1206 spin_unlock_irqrestore(&info
->slock
, flags
);
1209 static int mxser_write_room(struct tty_struct
*tty
)
1211 struct mxser_struct
*info
= tty
->driver_data
;
1214 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1220 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1222 struct mxser_struct
*info
= tty
->driver_data
;
1223 return info
->xmit_cnt
;
1226 static void mxser_flush_buffer(struct tty_struct
*tty
)
1228 struct mxser_struct
*info
= tty
->driver_data
;
1230 unsigned long flags
;
1233 spin_lock_irqsave(&info
->slock
, flags
);
1234 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1236 /* below added by shinhay */
1237 fcr
= inb(info
->base
+ UART_FCR
);
1238 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
1239 info
->base
+ UART_FCR
);
1240 outb(fcr
, info
->base
+ UART_FCR
);
1242 spin_unlock_irqrestore(&info
->slock
, flags
);
1243 /* above added by shinhay */
1248 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1250 struct mxser_struct
*info
= tty
->driver_data
;
1252 struct async_icount cprev
, cnow
; /* kernel counter temps */
1253 struct serial_icounter_struct __user
*p_cuser
;
1254 unsigned long templ
;
1255 unsigned long flags
;
1256 void __user
*argp
= (void __user
*)arg
;
1258 if (tty
->index
== MXSER_PORTS
)
1259 return mxser_ioctl_special(cmd
, argp
);
1261 /* following add by Victor Yu. 01-05-2004 */
1262 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1264 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1266 unsigned char val
, mask
;
1269 if (cmd
== MOXA_SET_OP_MODE
) {
1270 if (get_user(opmode
, (int __user
*) argp
))
1272 if (opmode
!= RS232_MODE
&&
1273 opmode
!= RS485_2WIRE_MODE
&&
1274 opmode
!= RS422_MODE
&&
1275 opmode
!= RS485_4WIRE_MODE
)
1279 val
= inb(info
->opmode_ioaddr
);
1281 val
|= (opmode
<< shiftbit
);
1282 outb(val
, info
->opmode_ioaddr
);
1285 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1286 opmode
&= OP_MODE_MASK
;
1287 if (copy_to_user(argp
, &opmode
, sizeof(int)))
1292 /* above add by Victor Yu. 01-05-2004 */
1294 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
1295 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1299 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1300 retval
= tty_check_change(tty
);
1303 tty_wait_until_sent(tty
, 0);
1305 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1307 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1308 retval
= tty_check_change(tty
);
1311 tty_wait_until_sent(tty
, 0);
1312 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1315 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*)argp
);
1317 if (get_user(templ
, (unsigned long __user
*) argp
))
1320 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
1323 return mxser_get_serial_info(info
, argp
);
1325 return mxser_set_serial_info(info
, argp
);
1326 case TIOCSERGETLSR
: /* Get line status register */
1327 return mxser_get_lsr_info(info
, argp
);
1329 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1330 * - mask passed in arg for lines of interest
1331 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1332 * Caller should use TIOCGICOUNT to see which one it was
1335 spin_lock_irqsave(&info
->slock
, flags
);
1336 cnow
= info
->icount
; /* note the counters on entry */
1337 spin_unlock_irqrestore(&info
->slock
, flags
);
1339 wait_event_interruptible(info
->delta_msr_wait
, ({
1341 spin_lock_irqsave(&info
->slock
, flags
);
1342 cnow
= info
->icount
; /* atomic copy */
1343 spin_unlock_irqrestore(&info
->slock
, flags
);
1345 ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1346 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1347 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1348 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
));
1352 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1353 * Return: write counters to the user passed counter struct
1354 * NB: both 1->0 and 0->1 transitions are counted except for
1355 * RI where only 0->1 is counted.
1358 spin_lock_irqsave(&info
->slock
, flags
);
1359 cnow
= info
->icount
;
1360 spin_unlock_irqrestore(&info
->slock
, flags
);
1362 /* modified by casper 1/11/2000 */
1363 if (put_user(cnow
.frame
, &p_cuser
->frame
))
1365 if (put_user(cnow
.brk
, &p_cuser
->brk
))
1367 if (put_user(cnow
.overrun
, &p_cuser
->overrun
))
1369 if (put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
))
1371 if (put_user(cnow
.parity
, &p_cuser
->parity
))
1373 if (put_user(cnow
.rx
, &p_cuser
->rx
))
1375 if (put_user(cnow
.tx
, &p_cuser
->tx
))
1377 put_user(cnow
.cts
, &p_cuser
->cts
);
1378 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1379 put_user(cnow
.rng
, &p_cuser
->rng
);
1380 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1382 case MOXA_HighSpeedOn
:
1383 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*)argp
);
1384 case MOXA_SDS_RSTICOUNTER
: {
1385 info
->mon_data
.rxcnt
= 0;
1386 info
->mon_data
.txcnt
= 0;
1389 /* (above) added by James. */
1390 case MOXA_ASPP_SETBAUD
:{
1392 if (get_user(baud
, (long __user
*)argp
))
1394 mxser_set_baud(info
, baud
);
1397 case MOXA_ASPP_GETBAUD
:
1398 if (copy_to_user(argp
, &info
->realbaud
, sizeof(long)))
1403 case MOXA_ASPP_OQUEUE
:{
1406 len
= mxser_chars_in_buffer(tty
);
1408 lsr
= inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
;
1410 len
+= (lsr
? 0 : 1);
1412 if (copy_to_user(argp
, &len
, sizeof(int)))
1417 case MOXA_ASPP_MON
: {
1420 /* info->mon_data.ser_param = tty->termios->c_cflag; */
1422 status
= mxser_get_msr(info
->base
, 1, info
->port
, info
);
1423 mxser_check_modem_status(info
, status
);
1425 mcr
= inb(info
->base
+ UART_MCR
);
1426 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1427 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1429 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1431 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1432 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1434 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1436 if (info
->tty
->hw_stopped
)
1437 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1439 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1441 if (copy_to_user(argp
, &info
->mon_data
,
1442 sizeof(struct mxser_mon
)))
1448 case MOXA_ASPP_LSTATUS
: {
1449 if (copy_to_user(argp
, &info
->err_shadow
,
1450 sizeof(unsigned char)))
1453 info
->err_shadow
= 0;
1456 case MOXA_SET_BAUD_METHOD
: {
1459 if (get_user(method
, (int __user
*)argp
))
1461 mxser_set_baud_method
[info
->port
] = method
;
1462 if (copy_to_user(argp
, &method
, sizeof(int)))
1468 return -ENOIOCTLCMD
;
1474 #define CMSPAR 010000000000
1477 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1479 int i
, result
, status
;
1483 if (copy_to_user(argp
, mxsercfg
,
1484 sizeof(struct mxser_hwconf
) * 4))
1487 case MOXA_GET_MAJOR
:
1488 if (copy_to_user(argp
, &ttymajor
, sizeof(int)))
1492 case MOXA_GET_CUMAJOR
:
1493 if (copy_to_user(argp
, &calloutmajor
, sizeof(int)))
1497 case MOXA_CHKPORTENABLE
:
1499 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1500 if (mxvar_table
[i
].base
)
1503 return put_user(result
, (unsigned long __user
*)argp
);
1504 case MOXA_GETDATACOUNT
:
1505 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1508 case MOXA_GETMSTATUS
:
1509 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1511 if (!mxvar_table
[i
].base
) {
1512 GMStatus
[i
].dcd
= 0;
1513 GMStatus
[i
].dsr
= 0;
1514 GMStatus
[i
].cts
= 0;
1518 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1519 GMStatus
[i
].cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1521 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1523 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1524 if (status
& 0x80 /*UART_MSR_DCD */ )
1525 GMStatus
[i
].dcd
= 1;
1527 GMStatus
[i
].dcd
= 0;
1529 if (status
& 0x20 /*UART_MSR_DSR */ )
1530 GMStatus
[i
].dsr
= 1;
1532 GMStatus
[i
].dsr
= 0;
1535 if (status
& 0x10 /*UART_MSR_CTS */ )
1536 GMStatus
[i
].cts
= 1;
1538 GMStatus
[i
].cts
= 0;
1540 if (copy_to_user(argp
, GMStatus
,
1541 sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1544 case MOXA_ASPP_MON_EXT
: {
1548 unsigned cflag
, iflag
;
1550 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1551 if (!mxvar_table
[i
].base
)
1554 status
= mxser_get_msr(mxvar_table
[i
].base
, 0,
1555 i
, &(mxvar_table
[i
]));
1557 mxser_check_modem_status(&mxvar_table[i],
1560 if (status
& UART_MSR_TERI
)
1561 mxvar_table
[i
].icount
.rng
++;
1562 if (status
& UART_MSR_DDSR
)
1563 mxvar_table
[i
].icount
.dsr
++;
1564 if (status
& UART_MSR_DDCD
)
1565 mxvar_table
[i
].icount
.dcd
++;
1566 if (status
& UART_MSR_DCTS
)
1567 mxvar_table
[i
].icount
.cts
++;
1569 mxvar_table
[i
].mon_data
.modem_status
= status
;
1570 mon_data_ext
.rx_cnt
[i
] = mxvar_table
[i
].mon_data
.rxcnt
;
1571 mon_data_ext
.tx_cnt
[i
] = mxvar_table
[i
].mon_data
.txcnt
;
1572 mon_data_ext
.up_rxcnt
[i
] = mxvar_table
[i
].mon_data
.up_rxcnt
;
1573 mon_data_ext
.up_txcnt
[i
] = mxvar_table
[i
].mon_data
.up_txcnt
;
1574 mon_data_ext
.modem_status
[i
] = mxvar_table
[i
].mon_data
.modem_status
;
1575 mon_data_ext
.baudrate
[i
] = mxvar_table
[i
].realbaud
;
1577 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
) {
1578 cflag
= mxvar_table
[i
].normal_termios
.c_cflag
;
1579 iflag
= mxvar_table
[i
].normal_termios
.c_iflag
;
1581 cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1582 iflag
= mxvar_table
[i
].tty
->termios
->c_iflag
;
1585 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1587 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1589 mon_data_ext
.parity
[i
] = cflag
& (PARENB
| PARODD
| CMSPAR
);
1591 mon_data_ext
.flowctrl
[i
] = 0x00;
1593 if (cflag
& CRTSCTS
)
1594 mon_data_ext
.flowctrl
[i
] |= 0x03;
1596 if (iflag
& (IXON
| IXOFF
))
1597 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1599 if (mxvar_table
[i
].type
== PORT_16550A
)
1600 mon_data_ext
.fifo
[i
] = 1;
1602 mon_data_ext
.fifo
[i
] = 0;
1606 opmode
= inb(mxvar_table
[i
].opmode_ioaddr
) >> shiftbit
;
1607 opmode
&= OP_MODE_MASK
;
1609 mon_data_ext
.iftype
[i
] = opmode
;
1612 if (copy_to_user(argp
, &mon_data_ext
, sizeof(struct mxser_mon_ext
)))
1619 return -ENOIOCTLCMD
;
1624 static void mxser_stoprx(struct tty_struct
*tty
)
1626 struct mxser_struct
*info
= tty
->driver_data
;
1627 /* unsigned long flags; */
1629 info
->ldisc_stop_rx
= 1;
1631 /* MX_LOCK(&info->slock); */
1632 /* following add by Victor Yu. 09-02-2002 */
1633 if (info
->IsMoxaMustChipFlag
) {
1634 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1635 outb(info
->IER
, info
->base
+ UART_IER
);
1637 /* above add by Victor Yu. 09-02-2002 */
1638 info
->x_char
= STOP_CHAR(tty
);
1639 /* mask by Victor Yu. 09-02-2002 */
1640 /* outb(info->IER, 0); */
1641 outb(0, info
->base
+ UART_IER
);
1642 info
->IER
|= UART_IER_THRI
;
1643 /* force Tx interrupt */
1644 outb(info
->IER
, info
->base
+ UART_IER
);
1645 } /* add by Victor Yu. 09-02-2002 */
1646 /* MX_UNLOCK(&info->slock); */
1649 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1650 /* MX_LOCK(&info->slock); */
1651 info
->MCR
&= ~UART_MCR_RTS
;
1652 outb(info
->MCR
, info
->base
+ UART_MCR
);
1653 /* MX_UNLOCK(&info->slock); */
1657 static void mxser_startrx(struct tty_struct
*tty
)
1659 struct mxser_struct
*info
= tty
->driver_data
;
1660 /* unsigned long flags; */
1662 info
->ldisc_stop_rx
= 0;
1667 /* MX_LOCK(&info->slock); */
1669 /* following add by Victor Yu. 09-02-2002 */
1670 if (info
->IsMoxaMustChipFlag
) {
1671 info
->IER
|= MOXA_MUST_RECV_ISR
;
1672 outb(info
->IER
, info
->base
+ UART_IER
);
1674 /* above add by Victor Yu. 09-02-2002 */
1676 info
->x_char
= START_CHAR(tty
);
1677 /* mask by Victor Yu. 09-02-2002 */
1678 /* outb(info->IER, 0); */
1679 /* add by Victor Yu. 09-02-2002 */
1680 outb(0, info
->base
+ UART_IER
);
1681 /* force Tx interrupt */
1682 info
->IER
|= UART_IER_THRI
;
1683 outb(info
->IER
, info
->base
+ UART_IER
);
1684 } /* add by Victor Yu. 09-02-2002 */
1685 /* MX_UNLOCK(&info->slock); */
1689 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1690 /* MX_LOCK(&info->slock); */
1691 info
->MCR
|= UART_MCR_RTS
;
1692 outb(info
->MCR
, info
->base
+ UART_MCR
);
1693 /* MX_UNLOCK(&info->slock); */
1698 * This routine is called by the upper-layer tty layer to signal that
1699 * incoming characters should be throttled.
1701 static void mxser_throttle(struct tty_struct
*tty
)
1703 /* struct mxser_struct *info = tty->driver_data; */
1704 /* unsigned long flags; */
1706 /* MX_LOCK(&info->slock); */
1708 /* MX_UNLOCK(&info->slock); */
1711 static void mxser_unthrottle(struct tty_struct
*tty
)
1713 /* struct mxser_struct *info = tty->driver_data; */
1714 /* unsigned long flags; */
1716 /* MX_LOCK(&info->slock); */
1718 /* MX_UNLOCK(&info->slock); */
1721 static void mxser_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
1723 struct mxser_struct
*info
= tty
->driver_data
;
1724 unsigned long flags
;
1726 mxser_change_speed(info
, old_termios
);
1728 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1729 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1730 tty
->hw_stopped
= 0;
1734 /* Handle sw stopped */
1735 if ((old_termios
->c_iflag
& IXON
) &&
1736 !(tty
->termios
->c_iflag
& IXON
)) {
1739 /* following add by Victor Yu. 09-02-2002 */
1740 if (info
->IsMoxaMustChipFlag
) {
1741 spin_lock_irqsave(&info
->slock
, flags
);
1742 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
1743 spin_unlock_irqrestore(&info
->slock
, flags
);
1745 /* above add by Victor Yu. 09-02-2002 */
1752 * mxser_stop() and mxser_start()
1754 * This routines are called before setting or resetting tty->stopped.
1755 * They enable or disable transmitter interrupts, as necessary.
1757 static void mxser_stop(struct tty_struct
*tty
)
1759 struct mxser_struct
*info
= tty
->driver_data
;
1760 unsigned long flags
;
1762 spin_lock_irqsave(&info
->slock
, flags
);
1763 if (info
->IER
& UART_IER_THRI
) {
1764 info
->IER
&= ~UART_IER_THRI
;
1765 outb(info
->IER
, info
->base
+ UART_IER
);
1767 spin_unlock_irqrestore(&info
->slock
, flags
);
1770 static void mxser_start(struct tty_struct
*tty
)
1772 struct mxser_struct
*info
= tty
->driver_data
;
1773 unsigned long flags
;
1775 spin_lock_irqsave(&info
->slock
, flags
);
1776 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
1777 info
->IER
|= UART_IER_THRI
;
1778 outb(info
->IER
, info
->base
+ UART_IER
);
1780 spin_unlock_irqrestore(&info
->slock
, flags
);
1784 * mxser_wait_until_sent() --- wait until the transmitter is empty
1786 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
1788 struct mxser_struct
*info
= tty
->driver_data
;
1789 unsigned long orig_jiffies
, char_time
;
1792 if (info
->type
== PORT_UNKNOWN
)
1795 if (info
->xmit_fifo_size
== 0)
1796 return; /* Just in case.... */
1798 orig_jiffies
= jiffies
;
1800 * Set the check interval to be 1/5 of the estimated time to
1801 * send a single character, and make it at least 1. The check
1802 * interval should also be less than the timeout.
1804 * Note: we have to use pretty tight timings here to satisfy
1807 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
1808 char_time
= char_time
/ 5;
1811 if (timeout
&& timeout
< char_time
)
1812 char_time
= timeout
;
1814 * If the transmitter hasn't cleared in twice the approximate
1815 * amount of time to send the entire FIFO, it probably won't
1816 * ever clear. This assumes the UART isn't doing flow
1817 * control, which is currently the case. Hence, if it ever
1818 * takes longer than info->timeout, this is probably due to a
1819 * UART bug of some kind. So, we clamp the timeout parameter at
1822 if (!timeout
|| timeout
> 2 * info
->timeout
)
1823 timeout
= 2 * info
->timeout
;
1824 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1825 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...",
1826 timeout
, char_time
);
1827 printk("jiff=%lu...", jiffies
);
1829 while (!((lsr
= inb(info
->base
+ UART_LSR
)) & UART_LSR_TEMT
)) {
1830 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1831 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
1833 schedule_timeout_interruptible(char_time
);
1834 if (signal_pending(current
))
1836 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
1839 set_current_state(TASK_RUNNING
);
1841 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1842 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
1848 * This routine is called by tty_hangup() when a hangup is signaled.
1850 void mxser_hangup(struct tty_struct
*tty
)
1852 struct mxser_struct
*info
= tty
->driver_data
;
1854 mxser_flush_buffer(tty
);
1855 mxser_shutdown(info
);
1858 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1860 wake_up_interruptible(&info
->open_wait
);
1864 /* added by James 03-12-2004. */
1866 * mxser_rs_break() --- routine which turns the break handling on or off
1868 static void mxser_rs_break(struct tty_struct
*tty
, int break_state
)
1870 struct mxser_struct
*info
= tty
->driver_data
;
1871 unsigned long flags
;
1873 spin_lock_irqsave(&info
->slock
, flags
);
1874 if (break_state
== -1)
1875 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
,
1876 info
->base
+ UART_LCR
);
1878 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
,
1879 info
->base
+ UART_LCR
);
1880 spin_unlock_irqrestore(&info
->slock
, flags
);
1883 /* (above) added by James. */
1887 * This is the serial driver's generic interrupt routine
1889 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
)
1892 struct mxser_struct
*info
;
1893 struct mxser_struct
*port
;
1894 int max
, irqbits
, bits
, msr
;
1895 int pass_counter
= 0;
1896 int handled
= IRQ_NONE
;
1899 /* spin_lock(&gm_lock); */
1901 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1902 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1908 if (i
== MXSER_BOARDS
)
1912 max
= mxser_numports
[mxsercfg
[i
].board_type
- 1];
1914 irqbits
= inb(port
->vector
) & port
->vectormask
;
1915 if (irqbits
== port
->vectormask
)
1918 handled
= IRQ_HANDLED
;
1919 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1920 if (irqbits
== port
->vectormask
)
1926 /* following add by Victor Yu. 09-13-2002 */
1927 iir
= inb(info
->base
+ UART_IIR
);
1928 if (iir
& UART_IIR_NO_INT
)
1930 iir
&= MOXA_MUST_IIR_MASK
;
1932 status
= inb(info
->base
+ UART_LSR
);
1933 outb(0x27, info
->base
+ UART_FCR
);
1934 inb(info
->base
+ UART_MSR
);
1938 /* mask by Victor Yu. 09-13-2002
1940 (inb(info->base + UART_IIR) & UART_IIR_NO_INT) )
1943 /* mask by Victor Yu. 09-02-2002
1944 status = inb(info->base + UART_LSR) & info->read_status_mask;
1947 /* following add by Victor Yu. 09-02-2002 */
1948 status
= inb(info
->base
+ UART_LSR
);
1950 if (status
& UART_LSR_PE
)
1951 info
->err_shadow
|= NPPI_NOTIFY_PARITY
;
1952 if (status
& UART_LSR_FE
)
1953 info
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
1954 if (status
& UART_LSR_OE
)
1955 info
->err_shadow
|= NPPI_NOTIFY_HW_OVERRUN
;
1956 if (status
& UART_LSR_BI
)
1957 info
->err_shadow
|= NPPI_NOTIFY_BREAK
;
1959 if (info
->IsMoxaMustChipFlag
) {
1961 if ( (status & 0x02) && !(status & 0x01) ) {
1962 outb(info->base+UART_FCR, 0x23);
1966 if (iir
== MOXA_MUST_IIR_GDA
||
1967 iir
== MOXA_MUST_IIR_RDA
||
1968 iir
== MOXA_MUST_IIR_RTO
||
1969 iir
== MOXA_MUST_IIR_LSR
)
1970 mxser_receive_chars(info
, &status
);
1973 /* above add by Victor Yu. 09-02-2002 */
1975 status
&= info
->read_status_mask
;
1976 if (status
& UART_LSR_DR
)
1977 mxser_receive_chars(info
, &status
);
1979 msr
= inb(info
->base
+ UART_MSR
);
1980 if (msr
& UART_MSR_ANY_DELTA
) {
1981 mxser_check_modem_status(info
, msr
);
1983 /* following add by Victor Yu. 09-13-2002 */
1984 if (info
->IsMoxaMustChipFlag
) {
1985 if ((iir
== 0x02) && (status
& UART_LSR_THRE
)) {
1986 mxser_transmit_chars(info
);
1989 /* above add by Victor Yu. 09-13-2002 */
1991 if (status
& UART_LSR_THRE
) {
1992 /* 8-2-99 by William
1993 if ( info->x_char || (info->xmit_cnt > 0) )
1995 mxser_transmit_chars(info
);
1999 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
2000 break; /* Prevent infinite loops */
2005 /* spin_unlock(&gm_lock); */
2009 static void mxser_receive_chars(struct mxser_struct
*info
, int *status
)
2011 struct tty_struct
*tty
= info
->tty
;
2012 unsigned char ch
, gdl
;
2017 unsigned long flags
;
2019 spin_lock_irqsave(&info
->slock
, flags
);
2021 recv_room
= tty
->receive_room
;
2022 if ((recv_room
== 0) && (!info
->ldisc_stop_rx
)) {
2023 /* mxser_throttle(tty); */
2028 /* following add by Victor Yu. 09-02-2002 */
2029 if (info
->IsMoxaMustChipFlag
!= MOXA_OTHER_UART
) {
2031 if (*status
& UART_LSR_SPECIAL
) {
2034 /* following add by Victor Yu. 02-11-2004 */
2035 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU860_HWID
&&
2036 (*status
& MOXA_MUST_LSR_RERR
))
2038 /* above add by Victor Yu. 02-14-2004 */
2039 if (*status
& MOXA_MUST_LSR_RERR
)
2042 gdl
= inb(info
->base
+ MOXA_MUST_GDL_REGISTER
);
2044 /* add by Victor Yu. 02-11-2004 */
2045 if (info
->IsMoxaMustChipFlag
== MOXA_MUST_MU150_HWID
)
2046 gdl
&= MOXA_MUST_GDL_MASK
;
2047 if (gdl
>= recv_room
) {
2048 if (!info
->ldisc_stop_rx
) {
2049 /* mxser_throttle(tty); */
2055 ch
= inb(info
->base
+ UART_RX
);
2056 tty_insert_flip_char(tty
, ch
, 0);
2059 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2068 /* above add by Victor Yu. 09-02-2002 */
2074 if ((cnt >= HI_WATER) && (info->stop_rx == 0)) {
2081 ch
= inb(info
->base
+ UART_RX
);
2082 /* following add by Victor Yu. 09-02-2002 */
2083 if (info
->IsMoxaMustChipFlag
&& (*status
& UART_LSR_OE
) /*&& !(*status&UART_LSR_DR) */ )
2084 outb(0x23, info
->base
+ UART_FCR
);
2085 *status
&= info
->read_status_mask
;
2086 /* above add by Victor Yu. 09-02-2002 */
2087 if (*status
& info
->ignore_status_mask
) {
2088 if (++ignored
> 100)
2092 if (*status
& UART_LSR_SPECIAL
) {
2093 if (*status
& UART_LSR_BI
) {
2095 /* added by casper 1/11/2000 */
2098 if (info
->flags
& ASYNC_SAK
)
2100 } else if (*status
& UART_LSR_PE
) {
2102 /* added by casper 1/11/2000 */
2103 info
->icount
.parity
++;
2105 } else if (*status
& UART_LSR_FE
) {
2107 /* added by casper 1/11/2000 */
2108 info
->icount
.frame
++;
2110 } else if (*status
& UART_LSR_OE
) {
2112 /* added by casper 1/11/2000 */
2113 info
->icount
.overrun
++;
2117 tty_insert_flip_char(tty
, ch
, flag
);
2119 if (cnt
>= recv_room
) {
2120 if (!info
->ldisc_stop_rx
) {
2121 /* mxser_throttle(tty); */
2129 /* following add by Victor Yu. 09-02-2002 */
2130 if (info
->IsMoxaMustChipFlag
)
2132 /* above add by Victor Yu. 09-02-2002 */
2134 /* mask by Victor Yu. 09-02-2002
2135 *status = inb(info->base + UART_LSR) & info->read_status_mask;
2137 /* following add by Victor Yu. 09-02-2002 */
2138 *status
= inb(info
->base
+ UART_LSR
);
2139 /* above add by Victor Yu. 09-02-2002 */
2140 } while (*status
& UART_LSR_DR
);
2142 end_intr
: /* add by Victor Yu. 09-02-2002 */
2143 mxvar_log
.rxcnt
[info
->port
] += cnt
;
2144 info
->mon_data
.rxcnt
+= cnt
;
2145 info
->mon_data
.up_rxcnt
+= cnt
;
2146 spin_unlock_irqrestore(&info
->slock
, flags
);
2148 tty_flip_buffer_push(tty
);
2151 static void mxser_transmit_chars(struct mxser_struct
*info
)
2154 unsigned long flags
;
2156 spin_lock_irqsave(&info
->slock
, flags
);
2159 outb(info
->x_char
, info
->base
+ UART_TX
);
2161 mxvar_log
.txcnt
[info
->port
]++;
2162 info
->mon_data
.txcnt
++;
2163 info
->mon_data
.up_txcnt
++;
2165 /* added by casper 1/11/2000 */
2168 spin_unlock_irqrestore(&info
->slock
, flags
);
2172 if (info
->xmit_buf
== 0) {
2173 spin_unlock_irqrestore(&info
->slock
, flags
);
2177 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
2178 (info
->tty
->hw_stopped
&&
2179 (info
->type
!= PORT_16550A
) &&
2180 (!info
->IsMoxaMustChipFlag
))) {
2181 info
->IER
&= ~UART_IER_THRI
;
2182 outb(info
->IER
, info
->base
+ UART_IER
);
2183 spin_unlock_irqrestore(&info
->slock
, flags
);
2187 cnt
= info
->xmit_cnt
;
2188 count
= info
->xmit_fifo_size
;
2190 outb(info
->xmit_buf
[info
->xmit_tail
++],
2191 info
->base
+ UART_TX
);
2192 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2193 if (--info
->xmit_cnt
<= 0)
2195 } while (--count
> 0);
2196 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
2198 /* added by James 03-12-2004. */
2199 info
->mon_data
.txcnt
+= (cnt
- info
->xmit_cnt
);
2200 info
->mon_data
.up_txcnt
+= (cnt
- info
->xmit_cnt
);
2201 /* (above) added by James. */
2203 /* added by casper 1/11/2000 */
2204 info
->icount
.tx
+= (cnt
- info
->xmit_cnt
);
2207 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
2208 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2209 schedule_work(&info
->tqueue
);
2211 if (info
->xmit_cnt
<= 0) {
2212 info
->IER
&= ~UART_IER_THRI
;
2213 outb(info
->IER
, info
->base
+ UART_IER
);
2215 spin_unlock_irqrestore(&info
->slock
, flags
);
2218 static void mxser_check_modem_status(struct mxser_struct
*info
, int status
)
2220 /* update input line counters */
2221 if (status
& UART_MSR_TERI
)
2223 if (status
& UART_MSR_DDSR
)
2225 if (status
& UART_MSR_DDCD
)
2227 if (status
& UART_MSR_DCTS
)
2229 info
->mon_data
.modem_status
= status
;
2230 wake_up_interruptible(&info
->delta_msr_wait
);
2232 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
2233 if (status
& UART_MSR_DCD
)
2234 wake_up_interruptible(&info
->open_wait
);
2235 schedule_work(&info
->tqueue
);
2238 if (info
->flags
& ASYNC_CTS_FLOW
) {
2239 if (info
->tty
->hw_stopped
) {
2240 if (status
& UART_MSR_CTS
) {
2241 info
->tty
->hw_stopped
= 0;
2243 if ((info
->type
!= PORT_16550A
) &&
2244 (!info
->IsMoxaMustChipFlag
)) {
2245 info
->IER
|= UART_IER_THRI
;
2246 outb(info
->IER
, info
->base
+ UART_IER
);
2248 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2249 schedule_work(&info
->tqueue
); }
2251 if (!(status
& UART_MSR_CTS
)) {
2252 info
->tty
->hw_stopped
= 1;
2253 if ((info
->type
!= PORT_16550A
) &&
2254 (!info
->IsMoxaMustChipFlag
)) {
2255 info
->IER
&= ~UART_IER_THRI
;
2256 outb(info
->IER
, info
->base
+ UART_IER
);
2263 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
, struct mxser_struct
*info
)
2265 DECLARE_WAITQUEUE(wait
, current
);
2268 unsigned long flags
;
2271 * If non-blocking mode is set, or the port is not enabled,
2272 * then make the check up front and then exit.
2274 if ((filp
->f_flags
& O_NONBLOCK
) || (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2275 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2279 if (tty
->termios
->c_cflag
& CLOCAL
)
2283 * Block waiting for the carrier detect and the line to become
2284 * free (i.e., not in use by the callout). While we are in
2285 * this loop, info->count is dropped by one, so that
2286 * mxser_close() knows when to free things. We restore it upon
2287 * exit, either normal or abnormal.
2290 add_wait_queue(&info
->open_wait
, &wait
);
2292 spin_lock_irqsave(&info
->slock
, flags
);
2293 if (!tty_hung_up_p(filp
))
2295 spin_unlock_irqrestore(&info
->slock
, flags
);
2296 info
->blocked_open
++;
2298 spin_lock_irqsave(&info
->slock
, flags
);
2299 outb(inb(info
->base
+ UART_MCR
) |
2300 UART_MCR_DTR
| UART_MCR_RTS
, info
->base
+ UART_MCR
);
2301 spin_unlock_irqrestore(&info
->slock
, flags
);
2302 set_current_state(TASK_INTERRUPTIBLE
);
2303 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
2304 if (info
->flags
& ASYNC_HUP_NOTIFY
)
2307 retval
= -ERESTARTSYS
;
2310 if (!(info
->flags
& ASYNC_CLOSING
) &&
2312 (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
2314 if (signal_pending(current
)) {
2315 retval
= -ERESTARTSYS
;
2320 set_current_state(TASK_RUNNING
);
2321 remove_wait_queue(&info
->open_wait
, &wait
);
2322 if (!tty_hung_up_p(filp
))
2324 info
->blocked_open
--;
2327 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2331 static int mxser_startup(struct mxser_struct
*info
)
2334 unsigned long flags
;
2336 page
= __get_free_page(GFP_KERNEL
);
2340 spin_lock_irqsave(&info
->slock
, flags
);
2342 if (info
->flags
& ASYNC_INITIALIZED
) {
2344 spin_unlock_irqrestore(&info
->slock
, flags
);
2348 if (!info
->base
|| !info
->type
) {
2350 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2352 spin_unlock_irqrestore(&info
->slock
, flags
);
2358 info
->xmit_buf
= (unsigned char *) page
;
2361 * Clear the FIFO buffers and disable them
2362 * (they will be reenabled in mxser_change_speed())
2364 if (info
->IsMoxaMustChipFlag
)
2365 outb((UART_FCR_CLEAR_RCVR
|
2366 UART_FCR_CLEAR_XMIT
|
2367 MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2369 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
2370 info
->base
+ UART_FCR
);
2373 * At this point there's no way the LSR could still be 0xFF;
2374 * if it is, then bail out, because there's likely no UART
2377 if (inb(info
->base
+ UART_LSR
) == 0xff) {
2378 spin_unlock_irqrestore(&info
->slock
, flags
);
2379 if (capable(CAP_SYS_ADMIN
)) {
2381 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2388 * Clear the interrupt registers.
2390 (void) inb(info
->base
+ UART_LSR
);
2391 (void) inb(info
->base
+ UART_RX
);
2392 (void) inb(info
->base
+ UART_IIR
);
2393 (void) inb(info
->base
+ UART_MSR
);
2396 * Now, initialize the UART
2398 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
2399 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
2400 outb(info
->MCR
, info
->base
+ UART_MCR
);
2403 * Finally, enable interrupts
2405 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
2406 /* info->IER = UART_IER_RLSI | UART_IER_RDI; */
2408 /* following add by Victor Yu. 08-30-2002 */
2409 if (info
->IsMoxaMustChipFlag
)
2410 info
->IER
|= MOXA_MUST_IER_EGDAI
;
2411 /* above add by Victor Yu. 08-30-2002 */
2412 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
2415 * And clear the interrupt registers again for luck.
2417 (void) inb(info
->base
+ UART_LSR
);
2418 (void) inb(info
->base
+ UART_RX
);
2419 (void) inb(info
->base
+ UART_IIR
);
2420 (void) inb(info
->base
+ UART_MSR
);
2423 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2424 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2427 * and set the speed of the serial port
2429 spin_unlock_irqrestore(&info
->slock
, flags
);
2430 mxser_change_speed(info
, NULL
);
2432 info
->flags
|= ASYNC_INITIALIZED
;
2437 * This routine will shutdown a serial port; interrupts maybe disabled, and
2438 * DTR is dropped if the hangup on close termio flag is on.
2440 static void mxser_shutdown(struct mxser_struct
*info
)
2442 unsigned long flags
;
2444 if (!(info
->flags
& ASYNC_INITIALIZED
))
2447 spin_lock_irqsave(&info
->slock
, flags
);
2450 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
2451 * here so the queue might never be waken up
2453 wake_up_interruptible(&info
->delta_msr_wait
);
2456 * Free the IRQ, if necessary
2458 if (info
->xmit_buf
) {
2459 free_page((unsigned long) info
->xmit_buf
);
2460 info
->xmit_buf
= NULL
;
2464 outb(0x00, info
->base
+ UART_IER
);
2466 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
2467 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
2468 outb(info
->MCR
, info
->base
+ UART_MCR
);
2470 /* clear Rx/Tx FIFO's */
2471 /* following add by Victor Yu. 08-30-2002 */
2472 if (info
->IsMoxaMustChipFlag
)
2473 outb((UART_FCR_CLEAR_RCVR
|
2474 UART_FCR_CLEAR_XMIT
|
2475 MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->base
+ UART_FCR
);
2477 /* above add by Victor Yu. 08-30-2002 */
2478 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
2479 info
->base
+ UART_FCR
);
2481 /* read data port to reset things */
2482 (void) inb(info
->base
+ UART_RX
);
2485 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2487 info
->flags
&= ~ASYNC_INITIALIZED
;
2489 /* following add by Victor Yu. 09-23-2002 */
2490 if (info
->IsMoxaMustChipFlag
)
2491 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->base
);
2492 /* above add by Victor Yu. 09-23-2002 */
2494 spin_unlock_irqrestore(&info
->slock
, flags
);
2498 * This routine is called to set the UART divisor registers to match
2499 * the specified baud rate for a serial port.
2501 static int mxser_change_speed(struct mxser_struct
*info
, struct ktermios
*old_termios
)
2503 unsigned cflag
, cval
, fcr
;
2505 unsigned char status
;
2507 unsigned long flags
;
2509 if (!info
->tty
|| !info
->tty
->termios
)
2511 cflag
= info
->tty
->termios
->c_cflag
;
2516 #define B921600 (B460800 +1)
2518 if (mxser_set_baud_method
[info
->port
] == 0) {
2519 baud
= tty_get_baud_rate(info
->tty
);
2520 mxser_set_baud(info
, baud
);
2523 /* byte size and parity */
2524 switch (cflag
& CSIZE
) {
2539 break; /* too keep GCC shut... */
2544 cval
|= UART_LCR_PARITY
;
2545 if (!(cflag
& PARODD
))
2546 cval
|= UART_LCR_EPAR
;
2548 cval
|= UART_LCR_SPAR
;
2550 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
2551 if (info
->IsMoxaMustChipFlag
) {
2552 fcr
= UART_FCR_ENABLE_FIFO
;
2553 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2554 SET_MOXA_MUST_FIFO_VALUE(info
);
2558 fcr
= UART_FCR_ENABLE_FIFO
;
2559 /* following add by Victor Yu. 08-30-2002 */
2560 if (info
->IsMoxaMustChipFlag
) {
2561 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
2562 SET_MOXA_MUST_FIFO_VALUE(info
);
2564 /* above add by Victor Yu. 08-30-2002 */
2565 switch (info
->rx_trigger
) {
2567 fcr
|= UART_FCR_TRIGGER_1
;
2570 fcr
|= UART_FCR_TRIGGER_4
;
2573 fcr
|= UART_FCR_TRIGGER_8
;
2576 fcr
|= UART_FCR_TRIGGER_14
;
2582 /* CTS flow control flag and modem status interrupts */
2583 info
->IER
&= ~UART_IER_MSI
;
2584 info
->MCR
&= ~UART_MCR_AFE
;
2585 if (cflag
& CRTSCTS
) {
2586 info
->flags
|= ASYNC_CTS_FLOW
;
2587 info
->IER
|= UART_IER_MSI
;
2588 if ((info
->type
== PORT_16550A
) || (info
->IsMoxaMustChipFlag
)) {
2589 info
->MCR
|= UART_MCR_AFE
;
2591 status
= inb(info
->base
+ UART_MSR
);
2592 if (info
->tty
->hw_stopped
) {
2593 if (status
& UART_MSR_CTS
) {
2594 info
->tty
->hw_stopped
= 0;
2595 if ((info
->type
!= PORT_16550A
) &&
2596 (!info
->IsMoxaMustChipFlag
)) {
2597 info
->IER
|= UART_IER_THRI
;
2598 outb(info
->IER
, info
->base
+ UART_IER
);
2600 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
2601 schedule_work(&info
->tqueue
); }
2603 if (!(status
& UART_MSR_CTS
)) {
2604 info
->tty
->hw_stopped
= 1;
2605 if ((info
->type
!= PORT_16550A
) &&
2606 (!info
->IsMoxaMustChipFlag
)) {
2607 info
->IER
&= ~UART_IER_THRI
;
2608 outb(info
->IER
, info
->base
+ UART_IER
);
2614 info
->flags
&= ~ASYNC_CTS_FLOW
;
2616 outb(info
->MCR
, info
->base
+ UART_MCR
);
2617 if (cflag
& CLOCAL
) {
2618 info
->flags
&= ~ASYNC_CHECK_CD
;
2620 info
->flags
|= ASYNC_CHECK_CD
;
2621 info
->IER
|= UART_IER_MSI
;
2623 outb(info
->IER
, info
->base
+ UART_IER
);
2626 * Set up parity check flag
2628 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2629 if (I_INPCK(info
->tty
))
2630 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2631 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2632 info
->read_status_mask
|= UART_LSR_BI
;
2634 info
->ignore_status_mask
= 0;
2636 if (I_IGNBRK(info
->tty
)) {
2637 info
->ignore_status_mask
|= UART_LSR_BI
;
2638 info
->read_status_mask
|= UART_LSR_BI
;
2640 * If we're ignore parity and break indicators, ignore
2641 * overruns too. (For real raw support).
2643 if (I_IGNPAR(info
->tty
)) {
2644 info
->ignore_status_mask
|=
2648 info
->read_status_mask
|=
2654 /* following add by Victor Yu. 09-02-2002 */
2655 if (info
->IsMoxaMustChipFlag
) {
2656 spin_lock_irqsave(&info
->slock
, flags
);
2657 SET_MOXA_MUST_XON1_VALUE(info
->base
, START_CHAR(info
->tty
));
2658 SET_MOXA_MUST_XOFF1_VALUE(info
->base
, STOP_CHAR(info
->tty
));
2659 if (I_IXON(info
->tty
)) {
2660 ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2662 DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(info
->base
);
2664 if (I_IXOFF(info
->tty
)) {
2665 ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2667 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info
->base
);
2670 if ( I_IXANY(info->tty) ) {
2671 info->MCR |= MOXA_MUST_MCR_XON_ANY;
2672 ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2674 info->MCR &= ~MOXA_MUST_MCR_XON_ANY;
2675 DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(info->base);
2678 spin_unlock_irqrestore(&info
->slock
, flags
);
2680 /* above add by Victor Yu. 09-02-2002 */
2683 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2684 outb(cval
, info
->base
+ UART_LCR
);
2690 static int mxser_set_baud(struct mxser_struct
*info
, long newspd
)
2695 unsigned long flags
;
2697 if (!info
->tty
|| !info
->tty
->termios
)
2703 if (newspd
> info
->MaxCanSetBaudRate
)
2706 info
->realbaud
= newspd
;
2707 if (newspd
== 134) {
2708 quot
= (2 * info
->baud_base
/ 269);
2709 } else if (newspd
) {
2710 quot
= info
->baud_base
/ newspd
;
2717 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
2718 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
2721 spin_lock_irqsave(&info
->slock
, flags
);
2722 info
->MCR
|= UART_MCR_DTR
;
2723 outb(info
->MCR
, info
->base
+ UART_MCR
);
2724 spin_unlock_irqrestore(&info
->slock
, flags
);
2726 spin_lock_irqsave(&info
->slock
, flags
);
2727 info
->MCR
&= ~UART_MCR_DTR
;
2728 outb(info
->MCR
, info
->base
+ UART_MCR
);
2729 spin_unlock_irqrestore(&info
->slock
, flags
);
2733 cval
= inb(info
->base
+ UART_LCR
);
2735 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2737 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2738 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2739 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2746 * ------------------------------------------------------------
2747 * friends of mxser_ioctl()
2748 * ------------------------------------------------------------
2750 static int mxser_get_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*retinfo
)
2752 struct serial_struct tmp
;
2756 memset(&tmp
, 0, sizeof(tmp
));
2757 tmp
.type
= info
->type
;
2758 tmp
.line
= info
->port
;
2759 tmp
.port
= info
->base
;
2760 tmp
.irq
= info
->irq
;
2761 tmp
.flags
= info
->flags
;
2762 tmp
.baud_base
= info
->baud_base
;
2763 tmp
.close_delay
= info
->close_delay
;
2764 tmp
.closing_wait
= info
->closing_wait
;
2765 tmp
.custom_divisor
= info
->custom_divisor
;
2767 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2772 static int mxser_set_serial_info(struct mxser_struct
*info
, struct serial_struct __user
*new_info
)
2774 struct serial_struct new_serial
;
2778 if (!new_info
|| !info
->base
)
2780 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2783 if ((new_serial
.irq
!= info
->irq
) ||
2784 (new_serial
.port
!= info
->base
) ||
2785 (new_serial
.custom_divisor
!= info
->custom_divisor
) ||
2786 (new_serial
.baud_base
!= info
->baud_base
))
2789 flags
= info
->flags
& ASYNC_SPD_MASK
;
2791 if (!capable(CAP_SYS_ADMIN
)) {
2792 if ((new_serial
.baud_base
!= info
->baud_base
) ||
2793 (new_serial
.close_delay
!= info
->close_delay
) ||
2794 ((new_serial
.flags
& ~ASYNC_USR_MASK
) != (info
->flags
& ~ASYNC_USR_MASK
)))
2796 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
2797 (new_serial
.flags
& ASYNC_USR_MASK
));
2800 * OK, past this point, all the error checking has been done.
2801 * At this point, we start making changes.....
2803 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
2804 (new_serial
.flags
& ASYNC_FLAGS
));
2805 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2806 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2807 info
->tty
->low_latency
=
2808 (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2809 info
->tty
->low_latency
= 0; /* (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0; */
2812 /* added by casper, 3/17/2000, for mouse */
2813 info
->type
= new_serial
.type
;
2815 process_txrx_fifo(info
);
2817 if (info
->flags
& ASYNC_INITIALIZED
) {
2818 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2819 mxser_change_speed(info
, NULL
);
2822 retval
= mxser_startup(info
);
2828 * mxser_get_lsr_info - get line status register info
2830 * Purpose: Let user call ioctl() to get info when the UART physically
2831 * is emptied. On bus types like RS485, the transmitter must
2832 * release the bus after transmitting. This must be done when
2833 * the transmit shift register is empty, not be done when the
2834 * transmit holding register is empty. This functionality
2835 * allows an RS485 driver to be written in user space.
2837 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int __user
*value
)
2839 unsigned char status
;
2840 unsigned int result
;
2841 unsigned long flags
;
2843 spin_lock_irqsave(&info
->slock
, flags
);
2844 status
= inb(info
->base
+ UART_LSR
);
2845 spin_unlock_irqrestore(&info
->slock
, flags
);
2846 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2847 return put_user(result
, value
);
2851 * This routine sends a break character out the serial port.
2853 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2855 unsigned long flags
;
2859 set_current_state(TASK_INTERRUPTIBLE
);
2860 spin_lock_irqsave(&info
->slock
, flags
);
2861 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
,
2862 info
->base
+ UART_LCR
);
2863 spin_unlock_irqrestore(&info
->slock
, flags
);
2864 schedule_timeout(duration
);
2865 spin_lock_irqsave(&info
->slock
, flags
);
2866 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
,
2867 info
->base
+ UART_LCR
);
2868 spin_unlock_irqrestore(&info
->slock
, flags
);
2871 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
2873 struct mxser_struct
*info
= tty
->driver_data
;
2874 unsigned char control
, status
;
2875 unsigned long flags
;
2878 if (tty
->index
== MXSER_PORTS
)
2879 return -ENOIOCTLCMD
;
2880 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2883 control
= info
->MCR
;
2885 spin_lock_irqsave(&info
->slock
, flags
);
2886 status
= inb(info
->base
+ UART_MSR
);
2887 if (status
& UART_MSR_ANY_DELTA
)
2888 mxser_check_modem_status(info
, status
);
2889 spin_unlock_irqrestore(&info
->slock
, flags
);
2890 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2891 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) |
2892 ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) |
2893 ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) |
2894 ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) |
2895 ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2898 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
, unsigned int set
, unsigned int clear
)
2900 struct mxser_struct
*info
= tty
->driver_data
;
2901 unsigned long flags
;
2904 if (tty
->index
== MXSER_PORTS
)
2905 return -ENOIOCTLCMD
;
2906 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2909 spin_lock_irqsave(&info
->slock
, flags
);
2911 if (set
& TIOCM_RTS
)
2912 info
->MCR
|= UART_MCR_RTS
;
2913 if (set
& TIOCM_DTR
)
2914 info
->MCR
|= UART_MCR_DTR
;
2916 if (clear
& TIOCM_RTS
)
2917 info
->MCR
&= ~UART_MCR_RTS
;
2918 if (clear
& TIOCM_DTR
)
2919 info
->MCR
&= ~UART_MCR_DTR
;
2921 outb(info
->MCR
, info
->base
+ UART_MCR
);
2922 spin_unlock_irqrestore(&info
->slock
, flags
);
2927 static int mxser_read_register(int, unsigned short *);
2928 static int mxser_program_mode(int);
2929 static void mxser_normal_mode(int);
2931 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2934 unsigned short regs
[16], irq
;
2935 unsigned char scratch
, scratch2
;
2937 hwconf
->IsMoxaMustChipFlag
= MOXA_OTHER_UART
;
2939 id
= mxser_read_register(cap
, regs
);
2940 if (id
== C168_ASIC_ID
) {
2941 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2943 } else if (id
== C104_ASIC_ID
) {
2944 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2946 } else if (id
== C102_ASIC_ID
) {
2947 hwconf
->board_type
= MXSER_BOARD_C102_ISA
;
2949 } else if (id
== CI132_ASIC_ID
) {
2950 hwconf
->board_type
= MXSER_BOARD_CI132
;
2952 } else if (id
== CI134_ASIC_ID
) {
2953 hwconf
->board_type
= MXSER_BOARD_CI134
;
2955 } else if (id
== CI104J_ASIC_ID
) {
2956 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2962 if (hwconf
->ports
== 2) {
2963 irq
= regs
[9] & 0xF000;
2964 irq
= irq
| (irq
>> 4);
2965 if (irq
!= (regs
[9] & 0xFF00))
2966 return MXSER_ERR_IRQ_CONFLIT
;
2967 } else if (hwconf
->ports
== 4) {
2968 irq
= regs
[9] & 0xF000;
2969 irq
= irq
| (irq
>> 4);
2970 irq
= irq
| (irq
>> 8);
2972 return MXSER_ERR_IRQ_CONFLIT
;
2973 } else if (hwconf
->ports
== 8) {
2974 irq
= regs
[9] & 0xF000;
2975 irq
= irq
| (irq
>> 4);
2976 irq
= irq
| (irq
>> 8);
2977 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
2978 return MXSER_ERR_IRQ_CONFLIT
;
2982 return MXSER_ERR_IRQ
;
2983 hwconf
->irq
= ((int)(irq
& 0xF000) >> 12);
2984 for (i
= 0; i
< 8; i
++)
2985 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
2986 if ((regs
[12] & 0x80) == 0)
2987 return MXSER_ERR_VECTOR
;
2988 hwconf
->vector
= (int)regs
[11]; /* interrupt vector */
2990 hwconf
->vector_mask
= 0x00FF;
2992 hwconf
->vector_mask
= 0x000F;
2993 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
2994 if (regs
[12] & bits
) {
2995 hwconf
->baud_base
[i
] = 921600;
2996 hwconf
->MaxCanSetBaudRate
[i
] = 921600; /* add by Victor Yu. 09-04-2002 */
2998 hwconf
->baud_base
[i
] = 115200;
2999 hwconf
->MaxCanSetBaudRate
[i
] = 115200; /* add by Victor Yu. 09-04-2002 */
3002 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
3003 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
3004 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
3005 outb(scratch2
, cap
+ UART_LCR
);
3006 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
3007 scratch
= inb(cap
+ UART_IIR
);
3010 hwconf
->uart_type
= PORT_16550A
;
3012 hwconf
->uart_type
= PORT_16450
;
3017 request_region(hwconf
->ioaddr
[0], 8 * hwconf
->ports
, "mxser(IO)");
3018 request_region(hwconf
->vector
, 1, "mxser(vector)");
3019 return hwconf
->ports
;
3022 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
3023 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
3024 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
3025 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
3026 #define EN_CCMD 0x000 /* Chip's command register */
3027 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
3028 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
3029 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
3030 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
3031 #define EN0_DCFG 0x00E /* Data configuration reg WR */
3032 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
3033 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
3034 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
3035 static int mxser_read_register(int port
, unsigned short *regs
)
3037 int i
, k
, value
, id
;
3040 id
= mxser_program_mode(port
);
3043 for (i
= 0; i
< 14; i
++) {
3044 k
= (i
& 0x3F) | 0x180;
3045 for (j
= 0x100; j
> 0; j
>>= 1) {
3046 outb(CHIP_CS
, port
);
3048 outb(CHIP_CS
| CHIP_DO
, port
);
3049 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
3051 outb(CHIP_CS
, port
);
3052 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
3057 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
3058 outb(CHIP_CS
, port
);
3059 outb(CHIP_CS
| CHIP_SK
, port
);
3060 if (inb(port
) & CHIP_DI
)
3066 mxser_normal_mode(port
);
3070 static int mxser_program_mode(int port
)
3073 /* unsigned long flags; */
3075 spin_lock(&gm_lock
);
3083 /* restore_flags(flags); */
3084 spin_unlock(&gm_lock
);
3086 id
= inb(port
+ 1) & 0x1F;
3087 if ((id
!= C168_ASIC_ID
) &&
3088 (id
!= C104_ASIC_ID
) &&
3089 (id
!= C102_ASIC_ID
) &&
3090 (id
!= CI132_ASIC_ID
) &&
3091 (id
!= CI134_ASIC_ID
) &&
3092 (id
!= CI104J_ASIC_ID
))
3094 for (i
= 0, j
= 0; i
< 4; i
++) {
3098 } else if ((j
== 1) && (n
== 1)) {
3109 static void mxser_normal_mode(int port
)
3113 outb(0xA5, port
+ 1);
3114 outb(0x80, port
+ 3);
3115 outb(12, port
+ 0); /* 9600 bps */
3117 outb(0x03, port
+ 3); /* 8 data bits */
3118 outb(0x13, port
+ 4); /* loop back mode */
3119 for (i
= 0; i
< 16; i
++) {
3121 if ((n
& 0x61) == 0x60)
3126 outb(0x00, port
+ 4);
3129 module_init(mxser_module_init
);
3130 module_exit(mxser_module_exit
);