2 * mxser.c -- MOXA Smartio/Industio family multiport serial driver.
4 * Copyright (C) 1999-2006 Moxa Technologies (support@moxa.com).
5 * Copyright (C) 2006-2008 Jiri Slaby <jirislaby@gmail.com>
7 * This code is loosely based on the 1.8 moxa driver which is based on
8 * Linux serial driver, written by Linus Torvalds, Theodore T'so and
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * Fed through a cleanup, indent and remove of non 2.6 code by Alan Cox
17 * <alan@redhat.com>. The original 1.8 code is available on www.moxa.com.
18 * - Fixed x86_64 cleanness
19 * - Fixed sleep with spinlock held in mxser_send_break
22 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/interrupt.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/serial.h>
31 #include <linux/serial_reg.h>
32 #include <linux/major.h>
33 #include <linux/string.h>
34 #include <linux/fcntl.h>
35 #include <linux/ptrace.h>
36 #include <linux/gfp.h>
37 #include <linux/ioport.h>
39 #include <linux/delay.h>
40 #include <linux/pci.h>
41 #include <linux/bitops.h>
43 #include <asm/system.h>
46 #include <asm/uaccess.h>
50 #define MXSER_VERSION "2.0.3" /* 1.11 */
51 #define MXSERMAJOR 174
52 #define MXSERCUMAJOR 175
54 #define MXSER_BOARDS 4 /* Max. boards */
55 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
56 #define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
57 #define MXSER_ISR_PASS_LIMIT 100
59 #define MXSER_ERR_IOADDR -1
60 #define MXSER_ERR_IRQ -2
61 #define MXSER_ERR_IRQ_CONFLIT -3
62 #define MXSER_ERR_VECTOR -4
64 /*CheckIsMoxaMust return value*/
65 #define MOXA_OTHER_UART 0x00
66 #define MOXA_MUST_MU150_HWID 0x01
67 #define MOXA_MUST_MU860_HWID 0x02
69 #define WAKEUP_CHARS 256
71 #define UART_MCR_AFE 0x20
72 #define UART_LSR_SPECIAL 0x1E
74 #define PCI_DEVICE_ID_CB108 0x1080
75 #define PCI_DEVICE_ID_CB114 0x1142
76 #define PCI_DEVICE_ID_CP114UL 0x1143
77 #define PCI_DEVICE_ID_CB134I 0x1341
78 #define PCI_DEVICE_ID_CP138U 0x1380
79 #define PCI_DEVICE_ID_POS104UL 0x1044
82 #define C168_ASIC_ID 1
83 #define C104_ASIC_ID 2
84 #define C102_ASIC_ID 0xB
85 #define CI132_ASIC_ID 4
86 #define CI134_ASIC_ID 3
87 #define CI104J_ASIC_ID 5
89 #define MXSER_HIGHBAUD 1
92 /* This is only for PCI */
102 } Gpci_uart_info
[] = {
103 {MOXA_OTHER_UART
, 16, 16, 16, 14, 14, 1, 921600L},
104 {MOXA_MUST_MU150_HWID
, 64, 64, 64, 48, 48, 16, 230400L},
105 {MOXA_MUST_MU860_HWID
, 128, 128, 128, 96, 96, 32, 921600L}
107 #define UART_INFO_NUM ARRAY_SIZE(Gpci_uart_info)
109 struct mxser_cardinfo
{
115 static const struct mxser_cardinfo mxser_cards
[] = {
116 /* 0*/ { "C168 series", 8, },
117 { "C104 series", 4, },
118 { "CI-104J series", 4, },
119 { "C168H/PCI series", 8, },
120 { "C104H/PCI series", 4, },
121 /* 5*/ { "C102 series", 4, MXSER_HAS2
}, /* C102-ISA */
122 { "CI-132 series", 4, MXSER_HAS2
},
123 { "CI-134 series", 4, },
124 { "CP-132 series", 2, },
125 { "CP-114 series", 4, },
126 /*10*/ { "CT-114 series", 4, },
127 { "CP-102 series", 2, MXSER_HIGHBAUD
},
128 { "CP-104U series", 4, },
129 { "CP-168U series", 8, },
130 { "CP-132U series", 2, },
131 /*15*/ { "CP-134U series", 4, },
132 { "CP-104JU series", 4, },
133 { "Moxa UC7000 Serial", 8, }, /* RC7000 */
134 { "CP-118U series", 8, },
135 { "CP-102UL series", 2, },
136 /*20*/ { "CP-102U series", 2, },
137 { "CP-118EL series", 8, },
138 { "CP-168EL series", 8, },
139 { "CP-104EL series", 4, },
140 { "CB-108 series", 8, },
141 /*25*/ { "CB-114 series", 4, },
142 { "CB-134I series", 4, },
143 { "CP-138U series", 8, },
144 { "POS-104UL series", 4, },
145 { "CP-114UL series", 4, }
148 /* driver_data correspond to the lines in the structure above
149 see also ISA probe function before you change something */
150 static struct pci_device_id mxser_pcibrds
[] = {
151 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_C168
), .driver_data
= 3 },
152 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_C104
), .driver_data
= 4 },
153 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP132
), .driver_data
= 8 },
154 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP114
), .driver_data
= 9 },
155 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CT114
), .driver_data
= 10 },
156 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102
), .driver_data
= 11 },
157 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104U
), .driver_data
= 12 },
158 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP168U
), .driver_data
= 13 },
159 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP132U
), .driver_data
= 14 },
160 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP134U
), .driver_data
= 15 },
161 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104JU
),.driver_data
= 16 },
162 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_RC7000
), .driver_data
= 17 },
163 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP118U
), .driver_data
= 18 },
164 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102UL
),.driver_data
= 19 },
165 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102U
), .driver_data
= 20 },
166 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP118EL
),.driver_data
= 21 },
167 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP168EL
),.driver_data
= 22 },
168 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104EL
),.driver_data
= 23 },
169 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB108
), .driver_data
= 24 },
170 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB114
), .driver_data
= 25 },
171 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB134I
), .driver_data
= 26 },
172 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CP138U
), .driver_data
= 27 },
173 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_POS104UL
), .driver_data
= 28 },
174 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CP114UL
), .driver_data
= 29 },
177 MODULE_DEVICE_TABLE(pci
, mxser_pcibrds
);
179 static int ioaddr
[MXSER_BOARDS
] = { 0, 0, 0, 0 };
180 static int ttymajor
= MXSERMAJOR
;
182 /* Variables for insmod */
184 MODULE_AUTHOR("Casper Yang");
185 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
186 module_param_array(ioaddr
, int, NULL
, 0);
187 module_param(ttymajor
, int, 0);
188 MODULE_LICENSE("GPL");
192 unsigned long rxcnt
[MXSER_PORTS
];
193 unsigned long txcnt
[MXSER_PORTS
];
200 unsigned long up_rxcnt
;
201 unsigned long up_txcnt
;
203 unsigned char hold_reason
;
206 struct mxser_mon_ext
{
207 unsigned long rx_cnt
[32];
208 unsigned long tx_cnt
[32];
209 unsigned long up_rxcnt
[32];
210 unsigned long up_txcnt
[32];
211 int modem_status
[32];
225 struct mxser_board
*board
;
226 struct tty_struct
*tty
;
228 unsigned long ioaddr
;
229 unsigned long opmode_ioaddr
;
233 int rx_trigger
; /* Rx fifo trigger level */
235 int baud_base
; /* max. speed */
236 int type
; /* UART type */
237 int flags
; /* defined in tty.h */
239 int x_char
; /* xon/xoff character */
240 int IER
; /* Interrupt Enable Register */
241 int MCR
; /* Modem control register */
243 unsigned char stop_rx
;
244 unsigned char ldisc_stop_rx
;
248 unsigned short closing_wait
;
249 unsigned char err_shadow
;
252 int count
; /* # of fd on device */
253 int blocked_open
; /* # of blocked opens */
254 struct async_icount icount
; /* kernel counters for 4 input interrupts */
257 int read_status_mask
;
258 int ignore_status_mask
;
260 unsigned char *xmit_buf
;
265 struct ktermios normal_termios
;
267 struct mxser_mon mon_data
;
270 wait_queue_head_t open_wait
;
271 wait_queue_head_t delta_msr_wait
;
277 const struct mxser_cardinfo
*info
;
278 unsigned long vector
;
279 unsigned long vector_mask
;
284 struct mxser_port ports
[MXSER_PORTS_PER_BOARD
];
287 struct mxser_mstatus
{
295 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
297 static int mxserBoardCAP
[MXSER_BOARDS
] = {
299 /* 0x180, 0x280, 0x200, 0x320 */
302 static struct mxser_board mxser_boards
[MXSER_BOARDS
];
303 static struct tty_driver
*mxvar_sdriver
;
304 static struct mxser_log mxvar_log
;
305 static int mxvar_diagflag
;
306 static unsigned char mxser_msr
[MXSER_PORTS
+ 1];
307 static struct mxser_mon_ext mon_data_ext
;
308 static int mxser_set_baud_method
[MXSER_PORTS
+ 1];
310 static void mxser_enable_must_enchance_mode(unsigned long baseio
)
315 oldlcr
= inb(baseio
+ UART_LCR
);
316 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
318 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
319 efr
|= MOXA_MUST_EFR_EFRB_ENABLE
;
321 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
322 outb(oldlcr
, baseio
+ UART_LCR
);
325 static void mxser_disable_must_enchance_mode(unsigned long baseio
)
330 oldlcr
= inb(baseio
+ UART_LCR
);
331 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
333 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
334 efr
&= ~MOXA_MUST_EFR_EFRB_ENABLE
;
336 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
337 outb(oldlcr
, baseio
+ UART_LCR
);
340 static void mxser_set_must_xon1_value(unsigned long baseio
, u8 value
)
345 oldlcr
= inb(baseio
+ UART_LCR
);
346 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
348 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
349 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
350 efr
|= MOXA_MUST_EFR_BANK0
;
352 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
353 outb(value
, baseio
+ MOXA_MUST_XON1_REGISTER
);
354 outb(oldlcr
, baseio
+ UART_LCR
);
357 static void mxser_set_must_xoff1_value(unsigned long baseio
, u8 value
)
362 oldlcr
= inb(baseio
+ UART_LCR
);
363 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
365 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
366 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
367 efr
|= MOXA_MUST_EFR_BANK0
;
369 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
370 outb(value
, baseio
+ MOXA_MUST_XOFF1_REGISTER
);
371 outb(oldlcr
, baseio
+ UART_LCR
);
374 static void mxser_set_must_fifo_value(struct mxser_port
*info
)
379 oldlcr
= inb(info
->ioaddr
+ UART_LCR
);
380 outb(MOXA_MUST_ENTER_ENCHANCE
, info
->ioaddr
+ UART_LCR
);
382 efr
= inb(info
->ioaddr
+ MOXA_MUST_EFR_REGISTER
);
383 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
384 efr
|= MOXA_MUST_EFR_BANK1
;
386 outb(efr
, info
->ioaddr
+ MOXA_MUST_EFR_REGISTER
);
387 outb((u8
)info
->rx_high_water
, info
->ioaddr
+ MOXA_MUST_RBRTH_REGISTER
);
388 outb((u8
)info
->rx_trigger
, info
->ioaddr
+ MOXA_MUST_RBRTI_REGISTER
);
389 outb((u8
)info
->rx_low_water
, info
->ioaddr
+ MOXA_MUST_RBRTL_REGISTER
);
390 outb(oldlcr
, info
->ioaddr
+ UART_LCR
);
393 static void mxser_set_must_enum_value(unsigned long baseio
, u8 value
)
398 oldlcr
= inb(baseio
+ UART_LCR
);
399 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
401 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
402 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
403 efr
|= MOXA_MUST_EFR_BANK2
;
405 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
406 outb(value
, baseio
+ MOXA_MUST_ENUM_REGISTER
);
407 outb(oldlcr
, baseio
+ UART_LCR
);
410 static void mxser_get_must_hardware_id(unsigned long baseio
, u8
*pId
)
415 oldlcr
= inb(baseio
+ UART_LCR
);
416 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
418 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
419 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
420 efr
|= MOXA_MUST_EFR_BANK2
;
422 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
423 *pId
= inb(baseio
+ MOXA_MUST_HWID_REGISTER
);
424 outb(oldlcr
, baseio
+ UART_LCR
);
427 static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio
)
432 oldlcr
= inb(baseio
+ UART_LCR
);
433 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
435 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
436 efr
&= ~MOXA_MUST_EFR_SF_MASK
;
438 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
439 outb(oldlcr
, baseio
+ UART_LCR
);
442 static void mxser_enable_must_tx_software_flow_control(unsigned long baseio
)
447 oldlcr
= inb(baseio
+ UART_LCR
);
448 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
450 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
451 efr
&= ~MOXA_MUST_EFR_SF_TX_MASK
;
452 efr
|= MOXA_MUST_EFR_SF_TX1
;
454 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
455 outb(oldlcr
, baseio
+ UART_LCR
);
458 static void mxser_disable_must_tx_software_flow_control(unsigned long baseio
)
463 oldlcr
= inb(baseio
+ UART_LCR
);
464 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
466 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
467 efr
&= ~MOXA_MUST_EFR_SF_TX_MASK
;
469 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
470 outb(oldlcr
, baseio
+ UART_LCR
);
473 static void mxser_enable_must_rx_software_flow_control(unsigned long baseio
)
478 oldlcr
= inb(baseio
+ UART_LCR
);
479 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
481 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
482 efr
&= ~MOXA_MUST_EFR_SF_RX_MASK
;
483 efr
|= MOXA_MUST_EFR_SF_RX1
;
485 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
486 outb(oldlcr
, baseio
+ UART_LCR
);
489 static void mxser_disable_must_rx_software_flow_control(unsigned long baseio
)
494 oldlcr
= inb(baseio
+ UART_LCR
);
495 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
497 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
498 efr
&= ~MOXA_MUST_EFR_SF_RX_MASK
;
500 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
501 outb(oldlcr
, baseio
+ UART_LCR
);
505 static int __devinit
CheckIsMoxaMust(unsigned long io
)
510 outb(0, io
+ UART_LCR
);
511 mxser_disable_must_enchance_mode(io
);
512 oldmcr
= inb(io
+ UART_MCR
);
513 outb(0, io
+ UART_MCR
);
514 mxser_set_must_xon1_value(io
, 0x11);
515 if ((hwid
= inb(io
+ UART_MCR
)) != 0) {
516 outb(oldmcr
, io
+ UART_MCR
);
517 return MOXA_OTHER_UART
;
520 mxser_get_must_hardware_id(io
, &hwid
);
521 for (i
= 1; i
< UART_INFO_NUM
; i
++) { /* 0 = OTHER_UART */
522 if (hwid
== Gpci_uart_info
[i
].type
)
525 return MOXA_OTHER_UART
;
529 static void process_txrx_fifo(struct mxser_port
*info
)
533 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
534 info
->rx_trigger
= 1;
535 info
->rx_high_water
= 1;
536 info
->rx_low_water
= 1;
537 info
->xmit_fifo_size
= 1;
539 for (i
= 0; i
< UART_INFO_NUM
; i
++)
540 if (info
->board
->chip_flag
== Gpci_uart_info
[i
].type
) {
541 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
542 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
543 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
544 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
549 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
)
551 unsigned char status
= 0;
553 status
= inb(baseaddr
+ UART_MSR
);
555 mxser_msr
[port
] &= 0x0F;
556 mxser_msr
[port
] |= status
;
557 status
= mxser_msr
[port
];
564 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
565 struct mxser_port
*port
)
567 DECLARE_WAITQUEUE(wait
, current
);
573 * If non-blocking mode is set, or the port is not enabled,
574 * then make the check up front and then exit.
576 if ((filp
->f_flags
& O_NONBLOCK
) ||
577 test_bit(TTY_IO_ERROR
, &tty
->flags
)) {
578 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
582 if (tty
->termios
->c_cflag
& CLOCAL
)
586 * Block waiting for the carrier detect and the line to become
587 * free (i.e., not in use by the callout). While we are in
588 * this loop, port->count is dropped by one, so that
589 * mxser_close() knows when to free things. We restore it upon
590 * exit, either normal or abnormal.
593 add_wait_queue(&port
->open_wait
, &wait
);
595 spin_lock_irqsave(&port
->slock
, flags
);
596 if (!tty_hung_up_p(filp
))
598 spin_unlock_irqrestore(&port
->slock
, flags
);
599 port
->blocked_open
++;
601 spin_lock_irqsave(&port
->slock
, flags
);
602 outb(inb(port
->ioaddr
+ UART_MCR
) |
603 UART_MCR_DTR
| UART_MCR_RTS
, port
->ioaddr
+ UART_MCR
);
604 spin_unlock_irqrestore(&port
->slock
, flags
);
605 set_current_state(TASK_INTERRUPTIBLE
);
606 if (tty_hung_up_p(filp
) || !(port
->flags
& ASYNC_INITIALIZED
)) {
607 if (port
->flags
& ASYNC_HUP_NOTIFY
)
610 retval
= -ERESTARTSYS
;
613 if (!(port
->flags
& ASYNC_CLOSING
) &&
615 (inb(port
->ioaddr
+ UART_MSR
) & UART_MSR_DCD
)))
617 if (signal_pending(current
)) {
618 retval
= -ERESTARTSYS
;
623 set_current_state(TASK_RUNNING
);
624 remove_wait_queue(&port
->open_wait
, &wait
);
625 if (!tty_hung_up_p(filp
))
627 port
->blocked_open
--;
630 port
->flags
|= ASYNC_NORMAL_ACTIVE
;
634 static int mxser_set_baud(struct mxser_port
*info
, long newspd
)
639 if (!info
->tty
|| !info
->tty
->termios
)
645 if (newspd
> info
->max_baud
)
649 quot
= 2 * info
->baud_base
/ 269;
650 tty_encode_baud_rate(info
->tty
, 134, 134);
652 quot
= info
->baud_base
/ newspd
;
655 baud
= info
->baud_base
/quot
;
656 tty_encode_baud_rate(info
->tty
, baud
, baud
);
661 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
662 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
665 info
->MCR
|= UART_MCR_DTR
;
666 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
668 info
->MCR
&= ~UART_MCR_DTR
;
669 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
673 cval
= inb(info
->ioaddr
+ UART_LCR
);
675 outb(cval
| UART_LCR_DLAB
, info
->ioaddr
+ UART_LCR
); /* set DLAB */
677 outb(quot
& 0xff, info
->ioaddr
+ UART_DLL
); /* LS of divisor */
678 outb(quot
>> 8, info
->ioaddr
+ UART_DLM
); /* MS of divisor */
679 outb(cval
, info
->ioaddr
+ UART_LCR
); /* reset DLAB */
682 if (C_BAUD(info
->tty
) == BOTHER
) {
683 quot
= info
->baud_base
% newspd
;
685 if (quot
% newspd
> newspd
/ 2) {
691 mxser_set_must_enum_value(info
->ioaddr
, quot
);
694 mxser_set_must_enum_value(info
->ioaddr
, 0);
700 * This routine is called to set the UART divisor registers to match
701 * the specified baud rate for a serial port.
703 static int mxser_change_speed(struct mxser_port
*info
,
704 struct ktermios
*old_termios
)
706 unsigned cflag
, cval
, fcr
;
708 unsigned char status
;
710 if (!info
->tty
|| !info
->tty
->termios
)
712 cflag
= info
->tty
->termios
->c_cflag
;
716 if (mxser_set_baud_method
[info
->tty
->index
] == 0)
717 mxser_set_baud(info
, tty_get_baud_rate(info
->tty
));
719 /* byte size and parity */
720 switch (cflag
& CSIZE
) {
735 break; /* too keep GCC shut... */
740 cval
|= UART_LCR_PARITY
;
741 if (!(cflag
& PARODD
))
742 cval
|= UART_LCR_EPAR
;
744 cval
|= UART_LCR_SPAR
;
746 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
747 if (info
->board
->chip_flag
) {
748 fcr
= UART_FCR_ENABLE_FIFO
;
749 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
750 mxser_set_must_fifo_value(info
);
754 fcr
= UART_FCR_ENABLE_FIFO
;
755 if (info
->board
->chip_flag
) {
756 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
757 mxser_set_must_fifo_value(info
);
759 switch (info
->rx_trigger
) {
761 fcr
|= UART_FCR_TRIGGER_1
;
764 fcr
|= UART_FCR_TRIGGER_4
;
767 fcr
|= UART_FCR_TRIGGER_8
;
770 fcr
|= UART_FCR_TRIGGER_14
;
776 /* CTS flow control flag and modem status interrupts */
777 info
->IER
&= ~UART_IER_MSI
;
778 info
->MCR
&= ~UART_MCR_AFE
;
779 if (cflag
& CRTSCTS
) {
780 info
->flags
|= ASYNC_CTS_FLOW
;
781 info
->IER
|= UART_IER_MSI
;
782 if ((info
->type
== PORT_16550A
) || (info
->board
->chip_flag
)) {
783 info
->MCR
|= UART_MCR_AFE
;
785 status
= inb(info
->ioaddr
+ UART_MSR
);
786 if (info
->tty
->hw_stopped
) {
787 if (status
& UART_MSR_CTS
) {
788 info
->tty
->hw_stopped
= 0;
789 if (info
->type
!= PORT_16550A
&&
790 !info
->board
->chip_flag
) {
791 outb(info
->IER
& ~UART_IER_THRI
,
794 info
->IER
|= UART_IER_THRI
;
795 outb(info
->IER
, info
->ioaddr
+
798 tty_wakeup(info
->tty
);
801 if (!(status
& UART_MSR_CTS
)) {
802 info
->tty
->hw_stopped
= 1;
803 if ((info
->type
!= PORT_16550A
) &&
804 (!info
->board
->chip_flag
)) {
805 info
->IER
&= ~UART_IER_THRI
;
806 outb(info
->IER
, info
->ioaddr
+
813 info
->flags
&= ~ASYNC_CTS_FLOW
;
815 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
816 if (cflag
& CLOCAL
) {
817 info
->flags
&= ~ASYNC_CHECK_CD
;
819 info
->flags
|= ASYNC_CHECK_CD
;
820 info
->IER
|= UART_IER_MSI
;
822 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
825 * Set up parity check flag
827 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
828 if (I_INPCK(info
->tty
))
829 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
830 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
831 info
->read_status_mask
|= UART_LSR_BI
;
833 info
->ignore_status_mask
= 0;
835 if (I_IGNBRK(info
->tty
)) {
836 info
->ignore_status_mask
|= UART_LSR_BI
;
837 info
->read_status_mask
|= UART_LSR_BI
;
839 * If we're ignore parity and break indicators, ignore
840 * overruns too. (For real raw support).
842 if (I_IGNPAR(info
->tty
)) {
843 info
->ignore_status_mask
|=
847 info
->read_status_mask
|=
853 if (info
->board
->chip_flag
) {
854 mxser_set_must_xon1_value(info
->ioaddr
, START_CHAR(info
->tty
));
855 mxser_set_must_xoff1_value(info
->ioaddr
, STOP_CHAR(info
->tty
));
856 if (I_IXON(info
->tty
)) {
857 mxser_enable_must_rx_software_flow_control(
860 mxser_disable_must_rx_software_flow_control(
863 if (I_IXOFF(info
->tty
)) {
864 mxser_enable_must_tx_software_flow_control(
867 mxser_disable_must_tx_software_flow_control(
873 outb(fcr
, info
->ioaddr
+ UART_FCR
); /* set fcr */
874 outb(cval
, info
->ioaddr
+ UART_LCR
);
879 static void mxser_check_modem_status(struct mxser_port
*port
, int status
)
881 /* update input line counters */
882 if (status
& UART_MSR_TERI
)
884 if (status
& UART_MSR_DDSR
)
886 if (status
& UART_MSR_DDCD
)
888 if (status
& UART_MSR_DCTS
)
890 port
->mon_data
.modem_status
= status
;
891 wake_up_interruptible(&port
->delta_msr_wait
);
893 if ((port
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
894 if (status
& UART_MSR_DCD
)
895 wake_up_interruptible(&port
->open_wait
);
898 if (port
->flags
& ASYNC_CTS_FLOW
) {
899 if (port
->tty
->hw_stopped
) {
900 if (status
& UART_MSR_CTS
) {
901 port
->tty
->hw_stopped
= 0;
903 if ((port
->type
!= PORT_16550A
) &&
904 (!port
->board
->chip_flag
)) {
905 outb(port
->IER
& ~UART_IER_THRI
,
906 port
->ioaddr
+ UART_IER
);
907 port
->IER
|= UART_IER_THRI
;
908 outb(port
->IER
, port
->ioaddr
+
911 tty_wakeup(port
->tty
);
914 if (!(status
& UART_MSR_CTS
)) {
915 port
->tty
->hw_stopped
= 1;
916 if (port
->type
!= PORT_16550A
&&
917 !port
->board
->chip_flag
) {
918 port
->IER
&= ~UART_IER_THRI
;
919 outb(port
->IER
, port
->ioaddr
+
927 static int mxser_startup(struct mxser_port
*info
)
932 page
= __get_free_page(GFP_KERNEL
);
936 spin_lock_irqsave(&info
->slock
, flags
);
938 if (info
->flags
& ASYNC_INITIALIZED
) {
940 spin_unlock_irqrestore(&info
->slock
, flags
);
944 if (!info
->ioaddr
|| !info
->type
) {
946 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
948 spin_unlock_irqrestore(&info
->slock
, flags
);
954 info
->xmit_buf
= (unsigned char *) page
;
957 * Clear the FIFO buffers and disable them
958 * (they will be reenabled in mxser_change_speed())
960 if (info
->board
->chip_flag
)
961 outb((UART_FCR_CLEAR_RCVR
|
962 UART_FCR_CLEAR_XMIT
|
963 MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->ioaddr
+ UART_FCR
);
965 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
966 info
->ioaddr
+ UART_FCR
);
969 * At this point there's no way the LSR could still be 0xFF;
970 * if it is, then bail out, because there's likely no UART
973 if (inb(info
->ioaddr
+ UART_LSR
) == 0xff) {
974 spin_unlock_irqrestore(&info
->slock
, flags
);
975 if (capable(CAP_SYS_ADMIN
)) {
977 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
984 * Clear the interrupt registers.
986 (void) inb(info
->ioaddr
+ UART_LSR
);
987 (void) inb(info
->ioaddr
+ UART_RX
);
988 (void) inb(info
->ioaddr
+ UART_IIR
);
989 (void) inb(info
->ioaddr
+ UART_MSR
);
992 * Now, initialize the UART
994 outb(UART_LCR_WLEN8
, info
->ioaddr
+ UART_LCR
); /* reset DLAB */
995 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
996 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
999 * Finally, enable interrupts
1001 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
1003 if (info
->board
->chip_flag
)
1004 info
->IER
|= MOXA_MUST_IER_EGDAI
;
1005 outb(info
->IER
, info
->ioaddr
+ UART_IER
); /* enable interrupts */
1008 * And clear the interrupt registers again for luck.
1010 (void) inb(info
->ioaddr
+ UART_LSR
);
1011 (void) inb(info
->ioaddr
+ UART_RX
);
1012 (void) inb(info
->ioaddr
+ UART_IIR
);
1013 (void) inb(info
->ioaddr
+ UART_MSR
);
1016 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1017 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1020 * and set the speed of the serial port
1022 mxser_change_speed(info
, NULL
);
1023 info
->flags
|= ASYNC_INITIALIZED
;
1024 spin_unlock_irqrestore(&info
->slock
, flags
);
1030 * This routine will shutdown a serial port; interrupts maybe disabled, and
1031 * DTR is dropped if the hangup on close termio flag is on.
1033 static void mxser_shutdown(struct mxser_port
*info
)
1035 unsigned long flags
;
1037 if (!(info
->flags
& ASYNC_INITIALIZED
))
1040 spin_lock_irqsave(&info
->slock
, flags
);
1043 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1044 * here so the queue might never be waken up
1046 wake_up_interruptible(&info
->delta_msr_wait
);
1049 * Free the IRQ, if necessary
1051 if (info
->xmit_buf
) {
1052 free_page((unsigned long) info
->xmit_buf
);
1053 info
->xmit_buf
= NULL
;
1057 outb(0x00, info
->ioaddr
+ UART_IER
);
1059 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
1060 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1061 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
1063 /* clear Rx/Tx FIFO's */
1064 if (info
->board
->chip_flag
)
1065 outb(UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
|
1066 MOXA_MUST_FCR_GDA_MODE_ENABLE
,
1067 info
->ioaddr
+ UART_FCR
);
1069 outb(UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
,
1070 info
->ioaddr
+ UART_FCR
);
1072 /* read data port to reset things */
1073 (void) inb(info
->ioaddr
+ UART_RX
);
1076 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1078 info
->flags
&= ~ASYNC_INITIALIZED
;
1080 if (info
->board
->chip_flag
)
1081 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->ioaddr
);
1083 spin_unlock_irqrestore(&info
->slock
, flags
);
1087 * This routine is called whenever a serial port is opened. It
1088 * enables interrupts for a serial port, linking in its async structure into
1089 * the IRQ chain. It also performs the serial-specific
1090 * initialization for the tty structure.
1092 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
1094 struct mxser_port
*info
;
1095 unsigned long flags
;
1099 if (line
== MXSER_PORTS
)
1101 if (line
< 0 || line
> MXSER_PORTS
)
1103 info
= &mxser_boards
[line
/ MXSER_PORTS_PER_BOARD
].ports
[line
% MXSER_PORTS_PER_BOARD
];
1107 tty
->driver_data
= info
;
1110 * Start up serial port
1112 spin_lock_irqsave(&info
->slock
, flags
);
1114 spin_unlock_irqrestore(&info
->slock
, flags
);
1115 retval
= mxser_startup(info
);
1119 retval
= mxser_block_til_ready(tty
, filp
, info
);
1123 /* unmark here for very high baud rate (ex. 921600 bps) used */
1124 tty
->low_latency
= 1;
1128 static void mxser_flush_buffer(struct tty_struct
*tty
)
1130 struct mxser_port
*info
= tty
->driver_data
;
1132 unsigned long flags
;
1135 spin_lock_irqsave(&info
->slock
, flags
);
1136 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1138 fcr
= inb(info
->ioaddr
+ UART_FCR
);
1139 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
1140 info
->ioaddr
+ UART_FCR
);
1141 outb(fcr
, info
->ioaddr
+ UART_FCR
);
1143 spin_unlock_irqrestore(&info
->slock
, flags
);
1150 * This routine is called when the serial port gets closed. First, we
1151 * wait for the last remaining data to be sent. Then, we unlink its
1152 * async structure from the interrupt chain if necessary, and we free
1153 * that IRQ if nothing is left in the chain.
1155 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
1157 struct mxser_port
*info
= tty
->driver_data
;
1159 unsigned long timeout
;
1160 unsigned long flags
;
1162 if (tty
->index
== MXSER_PORTS
)
1167 spin_lock_irqsave(&info
->slock
, flags
);
1169 if (tty_hung_up_p(filp
)) {
1170 spin_unlock_irqrestore(&info
->slock
, flags
);
1173 if ((tty
->count
== 1) && (info
->count
!= 1)) {
1175 * Uh, oh. tty->count is 1, which means that the tty
1176 * structure will be freed. Info->count should always
1177 * be one in these conditions. If it's greater than
1178 * one, we've got real problems, since it means the
1179 * serial port won't be shutdown.
1181 printk(KERN_ERR
"mxser_close: bad serial port count; "
1182 "tty->count is 1, info->count is %d\n", info
->count
);
1185 if (--info
->count
< 0) {
1186 printk(KERN_ERR
"mxser_close: bad serial port count for "
1187 "ttys%d: %d\n", tty
->index
, info
->count
);
1191 spin_unlock_irqrestore(&info
->slock
, flags
);
1194 info
->flags
|= ASYNC_CLOSING
;
1195 spin_unlock_irqrestore(&info
->slock
, flags
);
1197 * Save the termios structure, since this port may have
1198 * separate termios for callout and dialin.
1200 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
1201 info
->normal_termios
= *tty
->termios
;
1203 * Now we wait for the transmit buffer to clear; and we notify
1204 * the line discipline to only process XON/XOFF characters.
1207 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1208 tty_wait_until_sent(tty
, info
->closing_wait
);
1210 * At this point we stop accepting input. To do this, we
1211 * disable the receive line status interrupts, and tell the
1212 * interrupt driver to stop checking the data ready bit in the
1213 * line status register.
1215 info
->IER
&= ~UART_IER_RLSI
;
1216 if (info
->board
->chip_flag
)
1217 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1219 if (info
->flags
& ASYNC_INITIALIZED
) {
1220 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1222 * Before we drop DTR, make sure the UART transmitter
1223 * has completely drained; this is especially
1224 * important if there is a transmit FIFO!
1226 timeout
= jiffies
+ HZ
;
1227 while (!(inb(info
->ioaddr
+ UART_LSR
) & UART_LSR_TEMT
)) {
1228 schedule_timeout_interruptible(5);
1229 if (time_after(jiffies
, timeout
))
1233 mxser_shutdown(info
);
1235 mxser_flush_buffer(tty
);
1236 tty_ldisc_flush(tty
);
1241 if (info
->blocked_open
) {
1242 if (info
->close_delay
)
1243 schedule_timeout_interruptible(info
->close_delay
);
1244 wake_up_interruptible(&info
->open_wait
);
1247 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1250 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1253 struct mxser_port
*info
= tty
->driver_data
;
1254 unsigned long flags
;
1256 if (!info
->xmit_buf
)
1260 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1261 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1265 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1266 spin_lock_irqsave(&info
->slock
, flags
);
1267 info
->xmit_head
= (info
->xmit_head
+ c
) &
1268 (SERIAL_XMIT_SIZE
- 1);
1269 info
->xmit_cnt
+= c
;
1270 spin_unlock_irqrestore(&info
->slock
, flags
);
1277 if (info
->xmit_cnt
&& !tty
->stopped
) {
1278 if (!tty
->hw_stopped
||
1279 (info
->type
== PORT_16550A
) ||
1280 (info
->board
->chip_flag
)) {
1281 spin_lock_irqsave(&info
->slock
, flags
);
1282 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+
1284 info
->IER
|= UART_IER_THRI
;
1285 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1286 spin_unlock_irqrestore(&info
->slock
, flags
);
1292 static int mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1294 struct mxser_port
*info
= tty
->driver_data
;
1295 unsigned long flags
;
1297 if (!info
->xmit_buf
)
1300 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1303 spin_lock_irqsave(&info
->slock
, flags
);
1304 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1305 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1307 spin_unlock_irqrestore(&info
->slock
, flags
);
1308 if (!tty
->stopped
) {
1309 if (!tty
->hw_stopped
||
1310 (info
->type
== PORT_16550A
) ||
1311 info
->board
->chip_flag
) {
1312 spin_lock_irqsave(&info
->slock
, flags
);
1313 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
1314 info
->IER
|= UART_IER_THRI
;
1315 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1316 spin_unlock_irqrestore(&info
->slock
, flags
);
1323 static void mxser_flush_chars(struct tty_struct
*tty
)
1325 struct mxser_port
*info
= tty
->driver_data
;
1326 unsigned long flags
;
1328 if (info
->xmit_cnt
<= 0 ||
1332 (info
->type
!= PORT_16550A
) &&
1333 (!info
->board
->chip_flag
)
1337 spin_lock_irqsave(&info
->slock
, flags
);
1339 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
1340 info
->IER
|= UART_IER_THRI
;
1341 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1343 spin_unlock_irqrestore(&info
->slock
, flags
);
1346 static int mxser_write_room(struct tty_struct
*tty
)
1348 struct mxser_port
*info
= tty
->driver_data
;
1351 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1357 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1359 struct mxser_port
*info
= tty
->driver_data
;
1360 return info
->xmit_cnt
;
1364 * ------------------------------------------------------------
1365 * friends of mxser_ioctl()
1366 * ------------------------------------------------------------
1368 static int mxser_get_serial_info(struct mxser_port
*info
,
1369 struct serial_struct __user
*retinfo
)
1371 struct serial_struct tmp
= {
1373 .line
= info
->tty
->index
,
1374 .port
= info
->ioaddr
,
1375 .irq
= info
->board
->irq
,
1376 .flags
= info
->flags
,
1377 .baud_base
= info
->baud_base
,
1378 .close_delay
= info
->close_delay
,
1379 .closing_wait
= info
->closing_wait
,
1380 .custom_divisor
= info
->custom_divisor
,
1383 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
1388 static int mxser_set_serial_info(struct mxser_port
*info
,
1389 struct serial_struct __user
*new_info
)
1391 struct serial_struct new_serial
;
1393 unsigned long sl_flags
;
1397 if (!new_info
|| !info
->ioaddr
)
1399 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
1402 if (new_serial
.irq
!= info
->board
->irq
||
1403 new_serial
.port
!= info
->ioaddr
)
1406 flags
= info
->flags
& ASYNC_SPD_MASK
;
1408 if (!capable(CAP_SYS_ADMIN
)) {
1409 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1410 (new_serial
.close_delay
!= info
->close_delay
) ||
1411 ((new_serial
.flags
& ~ASYNC_USR_MASK
) != (info
->flags
& ~ASYNC_USR_MASK
)))
1413 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
1414 (new_serial
.flags
& ASYNC_USR_MASK
));
1417 * OK, past this point, all the error checking has been done.
1418 * At this point, we start making changes.....
1420 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
1421 (new_serial
.flags
& ASYNC_FLAGS
));
1422 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
1423 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
1424 info
->tty
->low_latency
=
1425 (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
1426 info
->tty
->low_latency
= 0;
1427 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
&&
1428 (new_serial
.baud_base
!= info
->baud_base
||
1429 new_serial
.custom_divisor
!=
1430 info
->custom_divisor
)) {
1431 baud
= new_serial
.baud_base
/ new_serial
.custom_divisor
;
1432 tty_encode_baud_rate(info
->tty
, baud
, baud
);
1436 info
->type
= new_serial
.type
;
1438 process_txrx_fifo(info
);
1440 if (info
->flags
& ASYNC_INITIALIZED
) {
1441 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
1442 spin_lock_irqsave(&info
->slock
, sl_flags
);
1443 mxser_change_speed(info
, NULL
);
1444 spin_unlock_irqrestore(&info
->slock
, sl_flags
);
1447 retval
= mxser_startup(info
);
1453 * mxser_get_lsr_info - get line status register info
1455 * Purpose: Let user call ioctl() to get info when the UART physically
1456 * is emptied. On bus types like RS485, the transmitter must
1457 * release the bus after transmitting. This must be done when
1458 * the transmit shift register is empty, not be done when the
1459 * transmit holding register is empty. This functionality
1460 * allows an RS485 driver to be written in user space.
1462 static int mxser_get_lsr_info(struct mxser_port
*info
,
1463 unsigned int __user
*value
)
1465 unsigned char status
;
1466 unsigned int result
;
1467 unsigned long flags
;
1469 spin_lock_irqsave(&info
->slock
, flags
);
1470 status
= inb(info
->ioaddr
+ UART_LSR
);
1471 spin_unlock_irqrestore(&info
->slock
, flags
);
1472 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1473 return put_user(result
, value
);
1477 * This routine sends a break character out the serial port.
1479 static void mxser_send_break(struct mxser_port
*info
, int duration
)
1481 unsigned long flags
;
1485 set_current_state(TASK_INTERRUPTIBLE
);
1486 spin_lock_irqsave(&info
->slock
, flags
);
1487 outb(inb(info
->ioaddr
+ UART_LCR
) | UART_LCR_SBC
,
1488 info
->ioaddr
+ UART_LCR
);
1489 spin_unlock_irqrestore(&info
->slock
, flags
);
1490 schedule_timeout(duration
);
1491 spin_lock_irqsave(&info
->slock
, flags
);
1492 outb(inb(info
->ioaddr
+ UART_LCR
) & ~UART_LCR_SBC
,
1493 info
->ioaddr
+ UART_LCR
);
1494 spin_unlock_irqrestore(&info
->slock
, flags
);
1497 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1499 struct mxser_port
*info
= tty
->driver_data
;
1500 unsigned char control
, status
;
1501 unsigned long flags
;
1504 if (tty
->index
== MXSER_PORTS
)
1505 return -ENOIOCTLCMD
;
1506 if (test_bit(TTY_IO_ERROR
, &tty
->flags
))
1509 control
= info
->MCR
;
1511 spin_lock_irqsave(&info
->slock
, flags
);
1512 status
= inb(info
->ioaddr
+ UART_MSR
);
1513 if (status
& UART_MSR_ANY_DELTA
)
1514 mxser_check_modem_status(info
, status
);
1515 spin_unlock_irqrestore(&info
->slock
, flags
);
1516 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
1517 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) |
1518 ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) |
1519 ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) |
1520 ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) |
1521 ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1524 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1525 unsigned int set
, unsigned int clear
)
1527 struct mxser_port
*info
= tty
->driver_data
;
1528 unsigned long flags
;
1531 if (tty
->index
== MXSER_PORTS
)
1532 return -ENOIOCTLCMD
;
1533 if (test_bit(TTY_IO_ERROR
, &tty
->flags
))
1536 spin_lock_irqsave(&info
->slock
, flags
);
1538 if (set
& TIOCM_RTS
)
1539 info
->MCR
|= UART_MCR_RTS
;
1540 if (set
& TIOCM_DTR
)
1541 info
->MCR
|= UART_MCR_DTR
;
1543 if (clear
& TIOCM_RTS
)
1544 info
->MCR
&= ~UART_MCR_RTS
;
1545 if (clear
& TIOCM_DTR
)
1546 info
->MCR
&= ~UART_MCR_DTR
;
1548 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
1549 spin_unlock_irqrestore(&info
->slock
, flags
);
1553 static int __init
mxser_program_mode(int port
)
1565 id
= inb(port
+ 1) & 0x1F;
1566 if ((id
!= C168_ASIC_ID
) &&
1567 (id
!= C104_ASIC_ID
) &&
1568 (id
!= C102_ASIC_ID
) &&
1569 (id
!= CI132_ASIC_ID
) &&
1570 (id
!= CI134_ASIC_ID
) &&
1571 (id
!= CI104J_ASIC_ID
))
1573 for (i
= 0, j
= 0; i
< 4; i
++) {
1577 } else if ((j
== 1) && (n
== 1)) {
1588 static void __init
mxser_normal_mode(int port
)
1592 outb(0xA5, port
+ 1);
1593 outb(0x80, port
+ 3);
1594 outb(12, port
+ 0); /* 9600 bps */
1596 outb(0x03, port
+ 3); /* 8 data bits */
1597 outb(0x13, port
+ 4); /* loop back mode */
1598 for (i
= 0; i
< 16; i
++) {
1600 if ((n
& 0x61) == 0x60)
1605 outb(0x00, port
+ 4);
1608 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
1609 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
1610 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
1611 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
1612 #define EN_CCMD 0x000 /* Chip's command register */
1613 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
1614 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
1615 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
1616 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
1617 #define EN0_DCFG 0x00E /* Data configuration reg WR */
1618 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1619 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1620 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1621 static int __init
mxser_read_register(int port
, unsigned short *regs
)
1623 int i
, k
, value
, id
;
1626 id
= mxser_program_mode(port
);
1629 for (i
= 0; i
< 14; i
++) {
1630 k
= (i
& 0x3F) | 0x180;
1631 for (j
= 0x100; j
> 0; j
>>= 1) {
1632 outb(CHIP_CS
, port
);
1634 outb(CHIP_CS
| CHIP_DO
, port
);
1635 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
1637 outb(CHIP_CS
, port
);
1638 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
1643 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
1644 outb(CHIP_CS
, port
);
1645 outb(CHIP_CS
| CHIP_SK
, port
);
1646 if (inb(port
) & CHIP_DI
)
1652 mxser_normal_mode(port
);
1656 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1658 struct mxser_port
*port
;
1664 case MOXA_GET_MAJOR
:
1665 return put_user(ttymajor
, (int __user
*)argp
);
1667 case MOXA_CHKPORTENABLE
:
1670 for (i
= 0; i
< MXSER_BOARDS
; i
++)
1671 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++)
1672 if (mxser_boards
[i
].ports
[j
].ioaddr
)
1675 return put_user(result
, (unsigned long __user
*)argp
);
1676 case MOXA_GETDATACOUNT
:
1678 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1682 case MOXA_GETMSTATUS
:
1684 for (i
= 0; i
< MXSER_BOARDS
; i
++)
1685 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++) {
1686 port
= &mxser_boards
[i
].ports
[j
];
1689 if (!port
->ioaddr
) {
1690 GMStatus
[i
].dcd
= 0;
1691 GMStatus
[i
].dsr
= 0;
1692 GMStatus
[i
].cts
= 0;
1696 if (!port
->tty
|| !port
->tty
->termios
)
1698 port
->normal_termios
.c_cflag
;
1701 port
->tty
->termios
->c_cflag
;
1703 status
= inb(port
->ioaddr
+ UART_MSR
);
1704 if (status
& 0x80 /*UART_MSR_DCD */ )
1705 GMStatus
[i
].dcd
= 1;
1707 GMStatus
[i
].dcd
= 0;
1709 if (status
& 0x20 /*UART_MSR_DSR */ )
1710 GMStatus
[i
].dsr
= 1;
1712 GMStatus
[i
].dsr
= 0;
1715 if (status
& 0x10 /*UART_MSR_CTS */ )
1716 GMStatus
[i
].cts
= 1;
1718 GMStatus
[i
].cts
= 0;
1721 if (copy_to_user(argp
, GMStatus
,
1722 sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1725 case MOXA_ASPP_MON_EXT
: {
1727 unsigned long opmode
;
1728 unsigned cflag
, iflag
;
1731 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1732 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++) {
1733 port
= &mxser_boards
[i
].ports
[j
];
1737 status
= mxser_get_msr(port
->ioaddr
, 0, i
);
1739 if (status
& UART_MSR_TERI
)
1741 if (status
& UART_MSR_DDSR
)
1743 if (status
& UART_MSR_DDCD
)
1745 if (status
& UART_MSR_DCTS
)
1748 port
->mon_data
.modem_status
= status
;
1749 mon_data_ext
.rx_cnt
[i
] = port
->mon_data
.rxcnt
;
1750 mon_data_ext
.tx_cnt
[i
] = port
->mon_data
.txcnt
;
1751 mon_data_ext
.up_rxcnt
[i
] =
1752 port
->mon_data
.up_rxcnt
;
1753 mon_data_ext
.up_txcnt
[i
] =
1754 port
->mon_data
.up_txcnt
;
1755 mon_data_ext
.modem_status
[i
] =
1756 port
->mon_data
.modem_status
;
1757 mon_data_ext
.baudrate
[i
] =
1758 tty_get_baud_rate(port
->tty
);
1760 if (!port
->tty
|| !port
->tty
->termios
) {
1761 cflag
= port
->normal_termios
.c_cflag
;
1762 iflag
= port
->normal_termios
.c_iflag
;
1764 cflag
= port
->tty
->termios
->c_cflag
;
1765 iflag
= port
->tty
->termios
->c_iflag
;
1768 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1770 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1772 mon_data_ext
.parity
[i
] =
1773 cflag
& (PARENB
| PARODD
| CMSPAR
);
1775 mon_data_ext
.flowctrl
[i
] = 0x00;
1777 if (cflag
& CRTSCTS
)
1778 mon_data_ext
.flowctrl
[i
] |= 0x03;
1780 if (iflag
& (IXON
| IXOFF
))
1781 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1783 if (port
->type
== PORT_16550A
)
1784 mon_data_ext
.fifo
[i
] = 1;
1786 mon_data_ext
.fifo
[i
] = 0;
1790 opmode
= inb(port
->opmode_ioaddr
) >> shiftbit
;
1791 opmode
&= OP_MODE_MASK
;
1793 mon_data_ext
.iftype
[i
] = opmode
;
1798 if (copy_to_user(argp
, &mon_data_ext
,
1799 sizeof(mon_data_ext
)))
1804 return -ENOIOCTLCMD
;
1809 static int mxser_cflags_changed(struct mxser_port
*info
, unsigned long arg
,
1810 struct async_icount
*cprev
)
1812 struct async_icount cnow
;
1813 unsigned long flags
;
1816 spin_lock_irqsave(&info
->slock
, flags
);
1817 cnow
= info
->icount
; /* atomic copy */
1818 spin_unlock_irqrestore(&info
->slock
, flags
);
1820 ret
= ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
->rng
)) ||
1821 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
->dsr
)) ||
1822 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
->dcd
)) ||
1823 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
->cts
));
1830 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
,
1831 unsigned int cmd
, unsigned long arg
)
1833 struct mxser_port
*info
= tty
->driver_data
;
1834 struct async_icount cnow
;
1835 struct serial_icounter_struct __user
*p_cuser
;
1836 unsigned long flags
;
1837 void __user
*argp
= (void __user
*)arg
;
1840 if (tty
->index
== MXSER_PORTS
)
1841 return mxser_ioctl_special(cmd
, argp
);
1843 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1845 unsigned long opmode
;
1846 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1848 unsigned char val
, mask
;
1851 if (cmd
== MOXA_SET_OP_MODE
) {
1852 if (get_user(opmode
, (int __user
*) argp
))
1854 if (opmode
!= RS232_MODE
&&
1855 opmode
!= RS485_2WIRE_MODE
&&
1856 opmode
!= RS422_MODE
&&
1857 opmode
!= RS485_4WIRE_MODE
)
1862 val
= inb(info
->opmode_ioaddr
);
1864 val
|= (opmode
<< shiftbit
);
1865 outb(val
, info
->opmode_ioaddr
);
1870 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1871 opmode
&= OP_MODE_MASK
;
1873 if (put_user(opmode
, (int __user
*)argp
))
1879 if (cmd
!= TIOCGSERIAL
&& cmd
!= TIOCMIWAIT
&& cmd
!= TIOCGICOUNT
&&
1880 test_bit(TTY_IO_ERROR
, &tty
->flags
))
1884 case TCSBRK
: /* SVID version: non-zero arg --> no break */
1885 retval
= tty_check_change(tty
);
1888 tty_wait_until_sent(tty
, 0);
1890 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
1892 case TCSBRKP
: /* support for POSIX tcsendbreak() */
1893 retval
= tty_check_change(tty
);
1896 tty_wait_until_sent(tty
, 0);
1897 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1901 retval
= mxser_get_serial_info(info
, argp
);
1906 retval
= mxser_set_serial_info(info
, argp
);
1909 case TIOCSERGETLSR
: /* Get line status register */
1910 return mxser_get_lsr_info(info
, argp
);
1912 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1913 * - mask passed in arg for lines of interest
1914 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1915 * Caller should use TIOCGICOUNT to see which one it was
1918 spin_lock_irqsave(&info
->slock
, flags
);
1919 cnow
= info
->icount
; /* note the counters on entry */
1920 spin_unlock_irqrestore(&info
->slock
, flags
);
1922 return wait_event_interruptible(info
->delta_msr_wait
,
1923 mxser_cflags_changed(info
, arg
, &cnow
));
1925 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1926 * Return: write counters to the user passed counter struct
1927 * NB: both 1->0 and 0->1 transitions are counted except for
1928 * RI where only 0->1 is counted.
1931 spin_lock_irqsave(&info
->slock
, flags
);
1932 cnow
= info
->icount
;
1933 spin_unlock_irqrestore(&info
->slock
, flags
);
1935 if (put_user(cnow
.frame
, &p_cuser
->frame
))
1937 if (put_user(cnow
.brk
, &p_cuser
->brk
))
1939 if (put_user(cnow
.overrun
, &p_cuser
->overrun
))
1941 if (put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
))
1943 if (put_user(cnow
.parity
, &p_cuser
->parity
))
1945 if (put_user(cnow
.rx
, &p_cuser
->rx
))
1947 if (put_user(cnow
.tx
, &p_cuser
->tx
))
1949 put_user(cnow
.cts
, &p_cuser
->cts
);
1950 put_user(cnow
.dsr
, &p_cuser
->dsr
);
1951 put_user(cnow
.rng
, &p_cuser
->rng
);
1952 put_user(cnow
.dcd
, &p_cuser
->dcd
);
1954 case MOXA_HighSpeedOn
:
1955 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*)argp
);
1956 case MOXA_SDS_RSTICOUNTER
:
1958 info
->mon_data
.rxcnt
= 0;
1959 info
->mon_data
.txcnt
= 0;
1963 case MOXA_ASPP_OQUEUE
:{
1967 len
= mxser_chars_in_buffer(tty
);
1968 lsr
= inb(info
->ioaddr
+ UART_LSR
) & UART_LSR_TEMT
;
1969 len
+= (lsr
? 0 : 1);
1972 return put_user(len
, (int __user
*)argp
);
1974 case MOXA_ASPP_MON
: {
1978 status
= mxser_get_msr(info
->ioaddr
, 1, tty
->index
);
1979 mxser_check_modem_status(info
, status
);
1981 mcr
= inb(info
->ioaddr
+ UART_MCR
);
1982 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1983 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1985 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1987 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1988 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1990 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1992 if (info
->tty
->hw_stopped
)
1993 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1995 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1997 if (copy_to_user(argp
, &info
->mon_data
,
1998 sizeof(struct mxser_mon
)))
2003 case MOXA_ASPP_LSTATUS
: {
2004 if (put_user(info
->err_shadow
, (unsigned char __user
*)argp
))
2007 info
->err_shadow
= 0;
2010 case MOXA_SET_BAUD_METHOD
: {
2013 if (get_user(method
, (int __user
*)argp
))
2015 mxser_set_baud_method
[tty
->index
] = method
;
2016 return put_user(method
, (int __user
*)argp
);
2019 return -ENOIOCTLCMD
;
2024 static void mxser_stoprx(struct tty_struct
*tty
)
2026 struct mxser_port
*info
= tty
->driver_data
;
2028 info
->ldisc_stop_rx
= 1;
2030 if (info
->board
->chip_flag
) {
2031 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
2032 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2034 info
->x_char
= STOP_CHAR(tty
);
2035 outb(0, info
->ioaddr
+ UART_IER
);
2036 info
->IER
|= UART_IER_THRI
;
2037 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2041 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
2042 info
->MCR
&= ~UART_MCR_RTS
;
2043 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
2048 * This routine is called by the upper-layer tty layer to signal that
2049 * incoming characters should be throttled.
2051 static void mxser_throttle(struct tty_struct
*tty
)
2056 static void mxser_unthrottle(struct tty_struct
*tty
)
2058 struct mxser_port
*info
= tty
->driver_data
;
2061 info
->ldisc_stop_rx
= 0;
2066 if (info
->board
->chip_flag
) {
2067 info
->IER
|= MOXA_MUST_RECV_ISR
;
2068 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2070 info
->x_char
= START_CHAR(tty
);
2071 outb(0, info
->ioaddr
+ UART_IER
);
2072 info
->IER
|= UART_IER_THRI
;
2073 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2078 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
2079 info
->MCR
|= UART_MCR_RTS
;
2080 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
2085 * mxser_stop() and mxser_start()
2087 * This routines are called before setting or resetting tty->stopped.
2088 * They enable or disable transmitter interrupts, as necessary.
2090 static void mxser_stop(struct tty_struct
*tty
)
2092 struct mxser_port
*info
= tty
->driver_data
;
2093 unsigned long flags
;
2095 spin_lock_irqsave(&info
->slock
, flags
);
2096 if (info
->IER
& UART_IER_THRI
) {
2097 info
->IER
&= ~UART_IER_THRI
;
2098 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2100 spin_unlock_irqrestore(&info
->slock
, flags
);
2103 static void mxser_start(struct tty_struct
*tty
)
2105 struct mxser_port
*info
= tty
->driver_data
;
2106 unsigned long flags
;
2108 spin_lock_irqsave(&info
->slock
, flags
);
2109 if (info
->xmit_cnt
&& info
->xmit_buf
) {
2110 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
2111 info
->IER
|= UART_IER_THRI
;
2112 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2114 spin_unlock_irqrestore(&info
->slock
, flags
);
2117 static void mxser_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
2119 struct mxser_port
*info
= tty
->driver_data
;
2120 unsigned long flags
;
2122 spin_lock_irqsave(&info
->slock
, flags
);
2123 mxser_change_speed(info
, old_termios
);
2124 spin_unlock_irqrestore(&info
->slock
, flags
);
2126 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2127 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
2128 tty
->hw_stopped
= 0;
2132 /* Handle sw stopped */
2133 if ((old_termios
->c_iflag
& IXON
) &&
2134 !(tty
->termios
->c_iflag
& IXON
)) {
2137 if (info
->board
->chip_flag
) {
2138 spin_lock_irqsave(&info
->slock
, flags
);
2139 mxser_disable_must_rx_software_flow_control(
2141 spin_unlock_irqrestore(&info
->slock
, flags
);
2149 * mxser_wait_until_sent() --- wait until the transmitter is empty
2151 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2153 struct mxser_port
*info
= tty
->driver_data
;
2154 unsigned long orig_jiffies
, char_time
;
2157 if (info
->type
== PORT_UNKNOWN
)
2160 if (info
->xmit_fifo_size
== 0)
2161 return; /* Just in case.... */
2163 orig_jiffies
= jiffies
;
2165 * Set the check interval to be 1/5 of the estimated time to
2166 * send a single character, and make it at least 1. The check
2167 * interval should also be less than the timeout.
2169 * Note: we have to use pretty tight timings here to satisfy
2172 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
2173 char_time
= char_time
/ 5;
2176 if (timeout
&& timeout
< char_time
)
2177 char_time
= timeout
;
2179 * If the transmitter hasn't cleared in twice the approximate
2180 * amount of time to send the entire FIFO, it probably won't
2181 * ever clear. This assumes the UART isn't doing flow
2182 * control, which is currently the case. Hence, if it ever
2183 * takes longer than info->timeout, this is probably due to a
2184 * UART bug of some kind. So, we clamp the timeout parameter at
2187 if (!timeout
|| timeout
> 2 * info
->timeout
)
2188 timeout
= 2 * info
->timeout
;
2189 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2190 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...",
2191 timeout
, char_time
);
2192 printk("jiff=%lu...", jiffies
);
2195 while (!((lsr
= inb(info
->ioaddr
+ UART_LSR
)) & UART_LSR_TEMT
)) {
2196 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2197 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
2199 schedule_timeout_interruptible(char_time
);
2200 if (signal_pending(current
))
2202 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2205 set_current_state(TASK_RUNNING
);
2208 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2209 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
2214 * This routine is called by tty_hangup() when a hangup is signaled.
2216 static void mxser_hangup(struct tty_struct
*tty
)
2218 struct mxser_port
*info
= tty
->driver_data
;
2220 mxser_flush_buffer(tty
);
2221 mxser_shutdown(info
);
2224 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
2226 wake_up_interruptible(&info
->open_wait
);
2230 * mxser_rs_break() --- routine which turns the break handling on or off
2232 static void mxser_rs_break(struct tty_struct
*tty
, int break_state
)
2234 struct mxser_port
*info
= tty
->driver_data
;
2235 unsigned long flags
;
2237 spin_lock_irqsave(&info
->slock
, flags
);
2238 if (break_state
== -1)
2239 outb(inb(info
->ioaddr
+ UART_LCR
) | UART_LCR_SBC
,
2240 info
->ioaddr
+ UART_LCR
);
2242 outb(inb(info
->ioaddr
+ UART_LCR
) & ~UART_LCR_SBC
,
2243 info
->ioaddr
+ UART_LCR
);
2244 spin_unlock_irqrestore(&info
->slock
, flags
);
2247 static void mxser_receive_chars(struct mxser_port
*port
, int *status
)
2249 struct tty_struct
*tty
= port
->tty
;
2250 unsigned char ch
, gdl
;
2256 recv_room
= tty
->receive_room
;
2257 if ((recv_room
== 0) && (!port
->ldisc_stop_rx
))
2260 if (port
->board
->chip_flag
!= MOXA_OTHER_UART
) {
2262 if (*status
& UART_LSR_SPECIAL
)
2264 if (port
->board
->chip_flag
== MOXA_MUST_MU860_HWID
&&
2265 (*status
& MOXA_MUST_LSR_RERR
))
2267 if (*status
& MOXA_MUST_LSR_RERR
)
2270 gdl
= inb(port
->ioaddr
+ MOXA_MUST_GDL_REGISTER
);
2272 if (port
->board
->chip_flag
== MOXA_MUST_MU150_HWID
)
2273 gdl
&= MOXA_MUST_GDL_MASK
;
2274 if (gdl
>= recv_room
) {
2275 if (!port
->ldisc_stop_rx
)
2279 ch
= inb(port
->ioaddr
+ UART_RX
);
2280 tty_insert_flip_char(tty
, ch
, 0);
2291 ch
= inb(port
->ioaddr
+ UART_RX
);
2292 if (port
->board
->chip_flag
&& (*status
& UART_LSR_OE
))
2293 outb(0x23, port
->ioaddr
+ UART_FCR
);
2294 *status
&= port
->read_status_mask
;
2295 if (*status
& port
->ignore_status_mask
) {
2296 if (++ignored
> 100)
2300 if (*status
& UART_LSR_SPECIAL
) {
2301 if (*status
& UART_LSR_BI
) {
2305 if (port
->flags
& ASYNC_SAK
)
2307 } else if (*status
& UART_LSR_PE
) {
2309 port
->icount
.parity
++;
2310 } else if (*status
& UART_LSR_FE
) {
2312 port
->icount
.frame
++;
2313 } else if (*status
& UART_LSR_OE
) {
2315 port
->icount
.overrun
++;
2319 tty_insert_flip_char(tty
, ch
, flag
);
2321 if (cnt
>= recv_room
) {
2322 if (!port
->ldisc_stop_rx
)
2329 if (port
->board
->chip_flag
)
2332 *status
= inb(port
->ioaddr
+ UART_LSR
);
2333 } while (*status
& UART_LSR_DR
);
2336 mxvar_log
.rxcnt
[port
->tty
->index
] += cnt
;
2337 port
->mon_data
.rxcnt
+= cnt
;
2338 port
->mon_data
.up_rxcnt
+= cnt
;
2341 * We are called from an interrupt context with &port->slock
2342 * being held. Drop it temporarily in order to prevent
2343 * recursive locking.
2345 spin_unlock(&port
->slock
);
2346 tty_flip_buffer_push(tty
);
2347 spin_lock(&port
->slock
);
2350 static void mxser_transmit_chars(struct mxser_port
*port
)
2355 outb(port
->x_char
, port
->ioaddr
+ UART_TX
);
2357 mxvar_log
.txcnt
[port
->tty
->index
]++;
2358 port
->mon_data
.txcnt
++;
2359 port
->mon_data
.up_txcnt
++;
2364 if (port
->xmit_buf
== NULL
)
2367 if ((port
->xmit_cnt
<= 0) || port
->tty
->stopped
||
2368 (port
->tty
->hw_stopped
&&
2369 (port
->type
!= PORT_16550A
) &&
2370 (!port
->board
->chip_flag
))) {
2371 port
->IER
&= ~UART_IER_THRI
;
2372 outb(port
->IER
, port
->ioaddr
+ UART_IER
);
2376 cnt
= port
->xmit_cnt
;
2377 count
= port
->xmit_fifo_size
;
2379 outb(port
->xmit_buf
[port
->xmit_tail
++],
2380 port
->ioaddr
+ UART_TX
);
2381 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2382 if (--port
->xmit_cnt
<= 0)
2384 } while (--count
> 0);
2385 mxvar_log
.txcnt
[port
->tty
->index
] += (cnt
- port
->xmit_cnt
);
2387 port
->mon_data
.txcnt
+= (cnt
- port
->xmit_cnt
);
2388 port
->mon_data
.up_txcnt
+= (cnt
- port
->xmit_cnt
);
2389 port
->icount
.tx
+= (cnt
- port
->xmit_cnt
);
2391 if (port
->xmit_cnt
< WAKEUP_CHARS
)
2392 tty_wakeup(port
->tty
);
2394 if (port
->xmit_cnt
<= 0) {
2395 port
->IER
&= ~UART_IER_THRI
;
2396 outb(port
->IER
, port
->ioaddr
+ UART_IER
);
2401 * This is the serial driver's generic interrupt routine
2403 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
)
2406 struct mxser_board
*brd
= NULL
;
2407 struct mxser_port
*port
;
2408 int max
, irqbits
, bits
, msr
;
2409 unsigned int int_cnt
, pass_counter
= 0;
2410 int handled
= IRQ_NONE
;
2412 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2413 if (dev_id
== &mxser_boards
[i
]) {
2418 if (i
== MXSER_BOARDS
)
2422 max
= brd
->info
->nports
;
2423 while (pass_counter
++ < MXSER_ISR_PASS_LIMIT
) {
2424 irqbits
= inb(brd
->vector
) & brd
->vector_mask
;
2425 if (irqbits
== brd
->vector_mask
)
2428 handled
= IRQ_HANDLED
;
2429 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
2430 if (irqbits
== brd
->vector_mask
)
2434 port
= &brd
->ports
[i
];
2437 spin_lock(&port
->slock
);
2439 iir
= inb(port
->ioaddr
+ UART_IIR
);
2440 if (iir
& UART_IIR_NO_INT
)
2442 iir
&= MOXA_MUST_IIR_MASK
;
2444 (port
->flags
& ASYNC_CLOSING
) ||
2446 ASYNC_INITIALIZED
)) {
2447 status
= inb(port
->ioaddr
+ UART_LSR
);
2448 outb(0x27, port
->ioaddr
+ UART_FCR
);
2449 inb(port
->ioaddr
+ UART_MSR
);
2453 status
= inb(port
->ioaddr
+ UART_LSR
);
2455 if (status
& UART_LSR_PE
)
2456 port
->err_shadow
|= NPPI_NOTIFY_PARITY
;
2457 if (status
& UART_LSR_FE
)
2458 port
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
2459 if (status
& UART_LSR_OE
)
2461 NPPI_NOTIFY_HW_OVERRUN
;
2462 if (status
& UART_LSR_BI
)
2463 port
->err_shadow
|= NPPI_NOTIFY_BREAK
;
2465 if (port
->board
->chip_flag
) {
2466 if (iir
== MOXA_MUST_IIR_GDA
||
2467 iir
== MOXA_MUST_IIR_RDA
||
2468 iir
== MOXA_MUST_IIR_RTO
||
2469 iir
== MOXA_MUST_IIR_LSR
)
2470 mxser_receive_chars(port
,
2474 status
&= port
->read_status_mask
;
2475 if (status
& UART_LSR_DR
)
2476 mxser_receive_chars(port
,
2479 msr
= inb(port
->ioaddr
+ UART_MSR
);
2480 if (msr
& UART_MSR_ANY_DELTA
)
2481 mxser_check_modem_status(port
, msr
);
2483 if (port
->board
->chip_flag
) {
2484 if (iir
== 0x02 && (status
&
2486 mxser_transmit_chars(port
);
2488 if (status
& UART_LSR_THRE
)
2489 mxser_transmit_chars(port
);
2491 } while (int_cnt
++ < MXSER_ISR_PASS_LIMIT
);
2492 spin_unlock(&port
->slock
);
2500 static const struct tty_operations mxser_ops
= {
2502 .close
= mxser_close
,
2503 .write
= mxser_write
,
2504 .put_char
= mxser_put_char
,
2505 .flush_chars
= mxser_flush_chars
,
2506 .write_room
= mxser_write_room
,
2507 .chars_in_buffer
= mxser_chars_in_buffer
,
2508 .flush_buffer
= mxser_flush_buffer
,
2509 .ioctl
= mxser_ioctl
,
2510 .throttle
= mxser_throttle
,
2511 .unthrottle
= mxser_unthrottle
,
2512 .set_termios
= mxser_set_termios
,
2514 .start
= mxser_start
,
2515 .hangup
= mxser_hangup
,
2516 .break_ctl
= mxser_rs_break
,
2517 .wait_until_sent
= mxser_wait_until_sent
,
2518 .tiocmget
= mxser_tiocmget
,
2519 .tiocmset
= mxser_tiocmset
,
2523 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2526 static void mxser_release_res(struct mxser_board
*brd
, struct pci_dev
*pdev
,
2530 free_irq(brd
->irq
, brd
);
2531 if (pdev
!= NULL
) { /* PCI */
2533 pci_release_region(pdev
, 2);
2534 pci_release_region(pdev
, 3);
2537 release_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
);
2538 release_region(brd
->vector
, 1);
2542 static int __devinit
mxser_initbrd(struct mxser_board
*brd
,
2543 struct pci_dev
*pdev
)
2545 struct mxser_port
*info
;
2549 printk(KERN_INFO
"max. baud rate = %d bps.\n", brd
->ports
[0].max_baud
);
2551 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2552 info
= &brd
->ports
[i
];
2555 info
->ldisc_stop_rx
= 0;
2557 /* Enhance mode enabled here */
2558 if (brd
->chip_flag
!= MOXA_OTHER_UART
)
2559 mxser_enable_must_enchance_mode(info
->ioaddr
);
2561 info
->flags
= ASYNC_SHARE_IRQ
;
2562 info
->type
= brd
->uart_type
;
2564 process_txrx_fifo(info
);
2566 info
->custom_divisor
= info
->baud_base
* 16;
2567 info
->close_delay
= 5 * HZ
/ 10;
2568 info
->closing_wait
= 30 * HZ
;
2569 info
->normal_termios
= mxvar_sdriver
->init_termios
;
2570 init_waitqueue_head(&info
->open_wait
);
2571 init_waitqueue_head(&info
->delta_msr_wait
);
2572 memset(&info
->mon_data
, 0, sizeof(struct mxser_mon
));
2573 info
->err_shadow
= 0;
2574 spin_lock_init(&info
->slock
);
2576 /* before set INT ISR, disable all int */
2577 outb(inb(info
->ioaddr
+ UART_IER
) & 0xf0,
2578 info
->ioaddr
+ UART_IER
);
2581 retval
= request_irq(brd
->irq
, mxser_interrupt
, IRQF_SHARED
, "mxser",
2584 printk(KERN_ERR
"Board %s: Request irq failed, IRQ (%d) may "
2585 "conflict with another device.\n",
2586 brd
->info
->name
, brd
->irq
);
2587 /* We hold resources, we need to release them. */
2588 mxser_release_res(brd
, pdev
, 0);
2593 static int __init
mxser_get_ISA_conf(int cap
, struct mxser_board
*brd
)
2596 unsigned short regs
[16], irq
;
2597 unsigned char scratch
, scratch2
;
2599 brd
->chip_flag
= MOXA_OTHER_UART
;
2601 id
= mxser_read_register(cap
, regs
);
2604 brd
->info
= &mxser_cards
[0];
2607 brd
->info
= &mxser_cards
[1];
2609 case CI104J_ASIC_ID
:
2610 brd
->info
= &mxser_cards
[2];
2613 brd
->info
= &mxser_cards
[5];
2616 brd
->info
= &mxser_cards
[6];
2619 brd
->info
= &mxser_cards
[7];
2626 /* some ISA cards have 2 ports, but we want to see them as 4-port (why?)
2627 Flag-hack checks if configuration should be read as 2-port here. */
2628 if (brd
->info
->nports
== 2 || (brd
->info
->flags
& MXSER_HAS2
)) {
2629 irq
= regs
[9] & 0xF000;
2630 irq
= irq
| (irq
>> 4);
2631 if (irq
!= (regs
[9] & 0xFF00))
2632 return MXSER_ERR_IRQ_CONFLIT
;
2633 } else if (brd
->info
->nports
== 4) {
2634 irq
= regs
[9] & 0xF000;
2635 irq
= irq
| (irq
>> 4);
2636 irq
= irq
| (irq
>> 8);
2638 return MXSER_ERR_IRQ_CONFLIT
;
2639 } else if (brd
->info
->nports
== 8) {
2640 irq
= regs
[9] & 0xF000;
2641 irq
= irq
| (irq
>> 4);
2642 irq
= irq
| (irq
>> 8);
2643 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
2644 return MXSER_ERR_IRQ_CONFLIT
;
2648 return MXSER_ERR_IRQ
;
2649 brd
->irq
= ((int)(irq
& 0xF000) >> 12);
2650 for (i
= 0; i
< 8; i
++)
2651 brd
->ports
[i
].ioaddr
= (int) regs
[i
+ 1] & 0xFFF8;
2652 if ((regs
[12] & 0x80) == 0)
2653 return MXSER_ERR_VECTOR
;
2654 brd
->vector
= (int)regs
[11]; /* interrupt vector */
2656 brd
->vector_mask
= 0x00FF;
2658 brd
->vector_mask
= 0x000F;
2659 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
2660 if (regs
[12] & bits
) {
2661 brd
->ports
[i
].baud_base
= 921600;
2662 brd
->ports
[i
].max_baud
= 921600;
2664 brd
->ports
[i
].baud_base
= 115200;
2665 brd
->ports
[i
].max_baud
= 115200;
2668 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
2669 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
2670 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
2671 outb(scratch2
, cap
+ UART_LCR
);
2672 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
2673 scratch
= inb(cap
+ UART_IIR
);
2676 brd
->uart_type
= PORT_16550A
;
2678 brd
->uart_type
= PORT_16450
;
2679 if (!request_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
,
2681 return MXSER_ERR_IOADDR
;
2682 if (!request_region(brd
->vector
, 1, "mxser(vector)")) {
2683 release_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
);
2684 return MXSER_ERR_VECTOR
;
2686 return brd
->info
->nports
;
2689 static int __devinit
mxser_probe(struct pci_dev
*pdev
,
2690 const struct pci_device_id
*ent
)
2693 struct mxser_board
*brd
;
2695 unsigned long ioaddress
;
2696 int retval
= -EINVAL
;
2698 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2699 if (mxser_boards
[i
].info
== NULL
)
2702 if (i
>= MXSER_BOARDS
) {
2703 printk(KERN_ERR
"Too many Smartio/Industio family boards found "
2704 "(maximum %d), board not configured\n", MXSER_BOARDS
);
2708 brd
= &mxser_boards
[i
];
2709 brd
->idx
= i
* MXSER_PORTS_PER_BOARD
;
2710 printk(KERN_INFO
"Found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2711 mxser_cards
[ent
->driver_data
].name
,
2712 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
));
2714 retval
= pci_enable_device(pdev
);
2716 printk(KERN_ERR
"Moxa SmartI/O PCI enable fail !\n");
2721 ioaddress
= pci_resource_start(pdev
, 2);
2722 retval
= pci_request_region(pdev
, 2, "mxser(IO)");
2726 brd
->info
= &mxser_cards
[ent
->driver_data
];
2727 for (i
= 0; i
< brd
->info
->nports
; i
++)
2728 brd
->ports
[i
].ioaddr
= ioaddress
+ 8 * i
;
2731 ioaddress
= pci_resource_start(pdev
, 3);
2732 retval
= pci_request_region(pdev
, 3, "mxser(vector)");
2735 brd
->vector
= ioaddress
;
2738 brd
->irq
= pdev
->irq
;
2740 brd
->chip_flag
= CheckIsMoxaMust(brd
->ports
[0].ioaddr
);
2741 brd
->uart_type
= PORT_16550A
;
2742 brd
->vector_mask
= 0;
2744 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2745 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
2746 if (Gpci_uart_info
[j
].type
== brd
->chip_flag
) {
2747 brd
->ports
[i
].max_baud
=
2748 Gpci_uart_info
[j
].max_baud
;
2750 /* exception....CP-102 */
2751 if (brd
->info
->flags
& MXSER_HIGHBAUD
)
2752 brd
->ports
[i
].max_baud
= 921600;
2758 if (brd
->chip_flag
== MOXA_MUST_MU860_HWID
) {
2759 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2761 brd
->ports
[i
].opmode_ioaddr
= ioaddress
+ 4;
2763 brd
->ports
[i
].opmode_ioaddr
= ioaddress
+ 0x0c;
2765 outb(0, ioaddress
+ 4); /* default set to RS232 mode */
2766 outb(0, ioaddress
+ 0x0c); /* default set to RS232 mode */
2769 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2770 brd
->vector_mask
|= (1 << i
);
2771 brd
->ports
[i
].baud_base
= 921600;
2774 /* mxser_initbrd will hook ISR. */
2775 retval
= mxser_initbrd(brd
, pdev
);
2779 for (i
= 0; i
< brd
->info
->nports
; i
++)
2780 tty_register_device(mxvar_sdriver
, brd
->idx
+ i
, &pdev
->dev
);
2782 pci_set_drvdata(pdev
, brd
);
2786 pci_release_region(pdev
, 2);
2796 static void __devexit
mxser_remove(struct pci_dev
*pdev
)
2798 struct mxser_board
*brd
= pci_get_drvdata(pdev
);
2801 for (i
= 0; i
< brd
->info
->nports
; i
++)
2802 tty_unregister_device(mxvar_sdriver
, brd
->idx
+ i
);
2804 mxser_release_res(brd
, pdev
, 1);
2808 static struct pci_driver mxser_driver
= {
2810 .id_table
= mxser_pcibrds
,
2811 .probe
= mxser_probe
,
2812 .remove
= __devexit_p(mxser_remove
)
2815 static int __init
mxser_module_init(void)
2817 struct mxser_board
*brd
;
2819 unsigned int i
, m
, isaloop
;
2822 pr_debug("Loading module mxser ...\n");
2824 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
2828 printk(KERN_INFO
"MOXA Smartio/Industio family driver version %s\n",
2831 /* Initialize the tty_driver structure */
2832 mxvar_sdriver
->owner
= THIS_MODULE
;
2833 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
2834 mxvar_sdriver
->name
= "ttyMI";
2835 mxvar_sdriver
->major
= ttymajor
;
2836 mxvar_sdriver
->minor_start
= 0;
2837 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
2838 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2839 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
2840 mxvar_sdriver
->init_termios
= tty_std_termios
;
2841 mxvar_sdriver
->init_termios
.c_cflag
= B9600
|CS8
|CREAD
|HUPCL
|CLOCAL
;
2842 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
|TTY_DRIVER_DYNAMIC_DEV
;
2843 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
2845 retval
= tty_register_driver(mxvar_sdriver
);
2847 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family "
2855 /* Start finding ISA boards here */
2856 for (isaloop
= 0; isaloop
< 2; isaloop
++)
2857 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
2859 cap
= mxserBoardCAP
[b
]; /* predefined */
2861 cap
= ioaddr
[b
]; /* module param */
2866 brd
= &mxser_boards
[m
];
2867 retval
= mxser_get_ISA_conf(cap
, brd
);
2870 printk(KERN_INFO
"Found MOXA %s board "
2872 brd
->info
->name
, ioaddr
[b
]);
2875 if (retval
== MXSER_ERR_IRQ
)
2876 printk(KERN_ERR
"Invalid interrupt "
2877 "number, board not "
2879 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
2880 printk(KERN_ERR
"Invalid interrupt "
2881 "number, board not "
2883 else if (retval
== MXSER_ERR_VECTOR
)
2884 printk(KERN_ERR
"Invalid interrupt "
2885 "vector, board not "
2887 else if (retval
== MXSER_ERR_IOADDR
)
2888 printk(KERN_ERR
"Invalid I/O address, "
2889 "board not configured\n");
2895 /* mxser_initbrd will hook ISR. */
2896 if (mxser_initbrd(brd
, NULL
) < 0) {
2901 brd
->idx
= m
* MXSER_PORTS_PER_BOARD
;
2902 for (i
= 0; i
< brd
->info
->nports
; i
++)
2903 tty_register_device(mxvar_sdriver
, brd
->idx
+ i
,
2909 retval
= pci_register_driver(&mxser_driver
);
2911 printk(KERN_ERR
"Can't register pci driver\n");
2915 } /* else: we have some ISA cards under control */
2918 pr_debug("Done.\n");
2922 tty_unregister_driver(mxvar_sdriver
);
2924 put_tty_driver(mxvar_sdriver
);
2928 static void __exit
mxser_module_exit(void)
2932 pr_debug("Unloading module mxser ...\n");
2934 pci_unregister_driver(&mxser_driver
);
2936 for (i
= 0; i
< MXSER_BOARDS
; i
++) /* ISA remains */
2937 if (mxser_boards
[i
].info
!= NULL
)
2938 for (j
= 0; j
< mxser_boards
[i
].info
->nports
; j
++)
2939 tty_unregister_device(mxvar_sdriver
,
2940 mxser_boards
[i
].idx
+ j
);
2941 tty_unregister_driver(mxvar_sdriver
);
2942 put_tty_driver(mxvar_sdriver
);
2944 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2945 if (mxser_boards
[i
].info
!= NULL
)
2946 mxser_release_res(&mxser_boards
[i
], NULL
, 1);
2948 pr_debug("Done.\n");
2951 module_init(mxser_module_init
);
2952 module_exit(mxser_module_exit
);