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
21 #include <linux/module.h>
22 #include <linux/errno.h>
23 #include <linux/signal.h>
24 #include <linux/sched.h>
25 #include <linux/timer.h>
26 #include <linux/interrupt.h>
27 #include <linux/tty.h>
28 #include <linux/tty_flip.h>
29 #include <linux/serial.h>
30 #include <linux/serial_reg.h>
31 #include <linux/major.h>
32 #include <linux/string.h>
33 #include <linux/fcntl.h>
34 #include <linux/ptrace.h>
35 #include <linux/gfp.h>
36 #include <linux/ioport.h>
38 #include <linux/delay.h>
39 #include <linux/pci.h>
40 #include <linux/bitops.h>
42 #include <asm/system.h>
45 #include <asm/uaccess.h>
49 #define MXSER_VERSION "2.0.4" /* 1.12 */
50 #define MXSERMAJOR 174
51 #define MXSERCUMAJOR 175
53 #define MXSER_BOARDS 4 /* Max. boards */
54 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
55 #define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
56 #define MXSER_ISR_PASS_LIMIT 100
58 #define MXSER_ERR_IOADDR -1
59 #define MXSER_ERR_IRQ -2
60 #define MXSER_ERR_IRQ_CONFLIT -3
61 #define MXSER_ERR_VECTOR -4
63 /*CheckIsMoxaMust return value*/
64 #define MOXA_OTHER_UART 0x00
65 #define MOXA_MUST_MU150_HWID 0x01
66 #define MOXA_MUST_MU860_HWID 0x02
68 #define WAKEUP_CHARS 256
70 #define UART_MCR_AFE 0x20
71 #define UART_LSR_SPECIAL 0x1E
73 #define PCI_DEVICE_ID_POS104UL 0x1044
74 #define PCI_DEVICE_ID_CB108 0x1080
75 #define PCI_DEVICE_ID_CP102UF 0x1023
76 #define PCI_DEVICE_ID_CB114 0x1142
77 #define PCI_DEVICE_ID_CP114UL 0x1143
78 #define PCI_DEVICE_ID_CB134I 0x1341
79 #define PCI_DEVICE_ID_CP138U 0x1380
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, },
146 /*30*/ { "CP-102UF series", 2, }
149 /* driver_data correspond to the lines in the structure above
150 see also ISA probe function before you change something */
151 static struct pci_device_id mxser_pcibrds
[] = {
152 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_C168
), .driver_data
= 3 },
153 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_C104
), .driver_data
= 4 },
154 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP132
), .driver_data
= 8 },
155 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP114
), .driver_data
= 9 },
156 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CT114
), .driver_data
= 10 },
157 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102
), .driver_data
= 11 },
158 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104U
), .driver_data
= 12 },
159 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP168U
), .driver_data
= 13 },
160 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP132U
), .driver_data
= 14 },
161 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP134U
), .driver_data
= 15 },
162 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104JU
),.driver_data
= 16 },
163 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_RC7000
), .driver_data
= 17 },
164 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP118U
), .driver_data
= 18 },
165 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102UL
),.driver_data
= 19 },
166 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP102U
), .driver_data
= 20 },
167 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP118EL
),.driver_data
= 21 },
168 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP168EL
),.driver_data
= 22 },
169 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_MOXA_CP104EL
),.driver_data
= 23 },
170 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB108
), .driver_data
= 24 },
171 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB114
), .driver_data
= 25 },
172 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CB134I
), .driver_data
= 26 },
173 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CP138U
), .driver_data
= 27 },
174 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_POS104UL
), .driver_data
= 28 },
175 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CP114UL
), .driver_data
= 29 },
176 { PCI_VDEVICE(MOXA
, PCI_DEVICE_ID_CP102UF
), .driver_data
= 30 },
179 MODULE_DEVICE_TABLE(pci
, mxser_pcibrds
);
181 static int ioaddr
[MXSER_BOARDS
] = { 0, 0, 0, 0 };
182 static int ttymajor
= MXSERMAJOR
;
184 /* Variables for insmod */
186 MODULE_AUTHOR("Casper Yang");
187 MODULE_DESCRIPTION("MOXA Smartio/Industio Family Multiport Board Device Driver");
188 module_param_array(ioaddr
, int, NULL
, 0);
189 module_param(ttymajor
, int, 0);
190 MODULE_LICENSE("GPL");
194 unsigned long rxcnt
[MXSER_PORTS
];
195 unsigned long txcnt
[MXSER_PORTS
];
202 unsigned long up_rxcnt
;
203 unsigned long up_txcnt
;
205 unsigned char hold_reason
;
208 struct mxser_mon_ext
{
209 unsigned long rx_cnt
[32];
210 unsigned long tx_cnt
[32];
211 unsigned long up_rxcnt
[32];
212 unsigned long up_txcnt
[32];
213 int modem_status
[32];
227 struct tty_port port
;
228 struct mxser_board
*board
;
230 unsigned long ioaddr
;
231 unsigned long opmode_ioaddr
;
235 int rx_trigger
; /* Rx fifo trigger level */
237 int baud_base
; /* max. speed */
238 int type
; /* UART type */
240 int x_char
; /* xon/xoff character */
241 int IER
; /* Interrupt Enable Register */
242 int MCR
; /* Modem control register */
244 unsigned char stop_rx
;
245 unsigned char ldisc_stop_rx
;
248 unsigned char err_shadow
;
250 struct async_icount icount
; /* kernel counters for 4 input interrupts */
253 int read_status_mask
;
254 int ignore_status_mask
;
260 struct ktermios normal_termios
;
262 struct mxser_mon mon_data
;
265 wait_queue_head_t delta_msr_wait
;
271 const struct mxser_cardinfo
*info
;
272 unsigned long vector
;
273 unsigned long vector_mask
;
278 struct mxser_port ports
[MXSER_PORTS_PER_BOARD
];
281 struct mxser_mstatus
{
289 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
291 static int mxserBoardCAP
[MXSER_BOARDS
] = {
293 /* 0x180, 0x280, 0x200, 0x320 */
296 static struct mxser_board mxser_boards
[MXSER_BOARDS
];
297 static struct tty_driver
*mxvar_sdriver
;
298 static struct mxser_log mxvar_log
;
299 static int mxvar_diagflag
;
300 static unsigned char mxser_msr
[MXSER_PORTS
+ 1];
301 static struct mxser_mon_ext mon_data_ext
;
302 static int mxser_set_baud_method
[MXSER_PORTS
+ 1];
304 static void mxser_enable_must_enchance_mode(unsigned long baseio
)
309 oldlcr
= inb(baseio
+ UART_LCR
);
310 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
312 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
313 efr
|= MOXA_MUST_EFR_EFRB_ENABLE
;
315 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
316 outb(oldlcr
, baseio
+ UART_LCR
);
319 static void mxser_disable_must_enchance_mode(unsigned long baseio
)
324 oldlcr
= inb(baseio
+ UART_LCR
);
325 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
327 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
328 efr
&= ~MOXA_MUST_EFR_EFRB_ENABLE
;
330 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
331 outb(oldlcr
, baseio
+ UART_LCR
);
334 static void mxser_set_must_xon1_value(unsigned long baseio
, u8 value
)
339 oldlcr
= inb(baseio
+ UART_LCR
);
340 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
342 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
343 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
344 efr
|= MOXA_MUST_EFR_BANK0
;
346 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
347 outb(value
, baseio
+ MOXA_MUST_XON1_REGISTER
);
348 outb(oldlcr
, baseio
+ UART_LCR
);
351 static void mxser_set_must_xoff1_value(unsigned long baseio
, u8 value
)
356 oldlcr
= inb(baseio
+ UART_LCR
);
357 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
359 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
360 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
361 efr
|= MOXA_MUST_EFR_BANK0
;
363 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
364 outb(value
, baseio
+ MOXA_MUST_XOFF1_REGISTER
);
365 outb(oldlcr
, baseio
+ UART_LCR
);
368 static void mxser_set_must_fifo_value(struct mxser_port
*info
)
373 oldlcr
= inb(info
->ioaddr
+ UART_LCR
);
374 outb(MOXA_MUST_ENTER_ENCHANCE
, info
->ioaddr
+ UART_LCR
);
376 efr
= inb(info
->ioaddr
+ MOXA_MUST_EFR_REGISTER
);
377 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
378 efr
|= MOXA_MUST_EFR_BANK1
;
380 outb(efr
, info
->ioaddr
+ MOXA_MUST_EFR_REGISTER
);
381 outb((u8
)info
->rx_high_water
, info
->ioaddr
+ MOXA_MUST_RBRTH_REGISTER
);
382 outb((u8
)info
->rx_trigger
, info
->ioaddr
+ MOXA_MUST_RBRTI_REGISTER
);
383 outb((u8
)info
->rx_low_water
, info
->ioaddr
+ MOXA_MUST_RBRTL_REGISTER
);
384 outb(oldlcr
, info
->ioaddr
+ UART_LCR
);
387 static void mxser_set_must_enum_value(unsigned long baseio
, u8 value
)
392 oldlcr
= inb(baseio
+ UART_LCR
);
393 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
395 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
396 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
397 efr
|= MOXA_MUST_EFR_BANK2
;
399 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
400 outb(value
, baseio
+ MOXA_MUST_ENUM_REGISTER
);
401 outb(oldlcr
, baseio
+ UART_LCR
);
404 static void mxser_get_must_hardware_id(unsigned long baseio
, u8
*pId
)
409 oldlcr
= inb(baseio
+ UART_LCR
);
410 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
412 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
413 efr
&= ~MOXA_MUST_EFR_BANK_MASK
;
414 efr
|= MOXA_MUST_EFR_BANK2
;
416 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
417 *pId
= inb(baseio
+ MOXA_MUST_HWID_REGISTER
);
418 outb(oldlcr
, baseio
+ UART_LCR
);
421 static void SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(unsigned long baseio
)
426 oldlcr
= inb(baseio
+ UART_LCR
);
427 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
429 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
430 efr
&= ~MOXA_MUST_EFR_SF_MASK
;
432 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
433 outb(oldlcr
, baseio
+ UART_LCR
);
436 static void mxser_enable_must_tx_software_flow_control(unsigned long baseio
)
441 oldlcr
= inb(baseio
+ UART_LCR
);
442 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
444 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
445 efr
&= ~MOXA_MUST_EFR_SF_TX_MASK
;
446 efr
|= MOXA_MUST_EFR_SF_TX1
;
448 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
449 outb(oldlcr
, baseio
+ UART_LCR
);
452 static void mxser_disable_must_tx_software_flow_control(unsigned long baseio
)
457 oldlcr
= inb(baseio
+ UART_LCR
);
458 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
460 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
461 efr
&= ~MOXA_MUST_EFR_SF_TX_MASK
;
463 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
464 outb(oldlcr
, baseio
+ UART_LCR
);
467 static void mxser_enable_must_rx_software_flow_control(unsigned long baseio
)
472 oldlcr
= inb(baseio
+ UART_LCR
);
473 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
475 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
476 efr
&= ~MOXA_MUST_EFR_SF_RX_MASK
;
477 efr
|= MOXA_MUST_EFR_SF_RX1
;
479 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
480 outb(oldlcr
, baseio
+ UART_LCR
);
483 static void mxser_disable_must_rx_software_flow_control(unsigned long baseio
)
488 oldlcr
= inb(baseio
+ UART_LCR
);
489 outb(MOXA_MUST_ENTER_ENCHANCE
, baseio
+ UART_LCR
);
491 efr
= inb(baseio
+ MOXA_MUST_EFR_REGISTER
);
492 efr
&= ~MOXA_MUST_EFR_SF_RX_MASK
;
494 outb(efr
, baseio
+ MOXA_MUST_EFR_REGISTER
);
495 outb(oldlcr
, baseio
+ UART_LCR
);
499 static int __devinit
CheckIsMoxaMust(unsigned long io
)
504 outb(0, io
+ UART_LCR
);
505 mxser_disable_must_enchance_mode(io
);
506 oldmcr
= inb(io
+ UART_MCR
);
507 outb(0, io
+ UART_MCR
);
508 mxser_set_must_xon1_value(io
, 0x11);
509 if ((hwid
= inb(io
+ UART_MCR
)) != 0) {
510 outb(oldmcr
, io
+ UART_MCR
);
511 return MOXA_OTHER_UART
;
514 mxser_get_must_hardware_id(io
, &hwid
);
515 for (i
= 1; i
< UART_INFO_NUM
; i
++) { /* 0 = OTHER_UART */
516 if (hwid
== Gpci_uart_info
[i
].type
)
519 return MOXA_OTHER_UART
;
523 static void process_txrx_fifo(struct mxser_port
*info
)
527 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
)) {
528 info
->rx_trigger
= 1;
529 info
->rx_high_water
= 1;
530 info
->rx_low_water
= 1;
531 info
->xmit_fifo_size
= 1;
533 for (i
= 0; i
< UART_INFO_NUM
; i
++)
534 if (info
->board
->chip_flag
== Gpci_uart_info
[i
].type
) {
535 info
->rx_trigger
= Gpci_uart_info
[i
].rx_trigger
;
536 info
->rx_low_water
= Gpci_uart_info
[i
].rx_low_water
;
537 info
->rx_high_water
= Gpci_uart_info
[i
].rx_high_water
;
538 info
->xmit_fifo_size
= Gpci_uart_info
[i
].xmit_fifo_size
;
543 static unsigned char mxser_get_msr(int baseaddr
, int mode
, int port
)
545 unsigned char status
= 0;
547 status
= inb(baseaddr
+ UART_MSR
);
549 mxser_msr
[port
] &= 0x0F;
550 mxser_msr
[port
] |= status
;
551 status
= mxser_msr
[port
];
558 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
559 struct mxser_port
*port
)
561 DECLARE_WAITQUEUE(wait
, current
);
567 * If non-blocking mode is set, or the port is not enabled,
568 * then make the check up front and then exit.
570 if ((filp
->f_flags
& O_NONBLOCK
) ||
571 test_bit(TTY_IO_ERROR
, &tty
->flags
)) {
572 port
->port
.flags
|= ASYNC_NORMAL_ACTIVE
;
576 if (tty
->termios
->c_cflag
& CLOCAL
)
580 * Block waiting for the carrier detect and the line to become
581 * free (i.e., not in use by the callout). While we are in
582 * this loop, port->port.count is dropped by one, so that
583 * mxser_close() knows when to free things. We restore it upon
584 * exit, either normal or abnormal.
587 add_wait_queue(&port
->port
.open_wait
, &wait
);
589 spin_lock_irqsave(&port
->slock
, flags
);
590 if (!tty_hung_up_p(filp
))
592 spin_unlock_irqrestore(&port
->slock
, flags
);
593 port
->port
.blocked_open
++;
595 spin_lock_irqsave(&port
->slock
, flags
);
596 outb(inb(port
->ioaddr
+ UART_MCR
) |
597 UART_MCR_DTR
| UART_MCR_RTS
, port
->ioaddr
+ UART_MCR
);
598 spin_unlock_irqrestore(&port
->slock
, flags
);
599 set_current_state(TASK_INTERRUPTIBLE
);
600 if (tty_hung_up_p(filp
) || !(port
->port
.flags
& ASYNC_INITIALIZED
)) {
601 if (port
->port
.flags
& ASYNC_HUP_NOTIFY
)
604 retval
= -ERESTARTSYS
;
607 if (!(port
->port
.flags
& ASYNC_CLOSING
) &&
609 (inb(port
->ioaddr
+ UART_MSR
) & UART_MSR_DCD
)))
611 if (signal_pending(current
)) {
612 retval
= -ERESTARTSYS
;
617 set_current_state(TASK_RUNNING
);
618 remove_wait_queue(&port
->port
.open_wait
, &wait
);
619 if (!tty_hung_up_p(filp
))
621 port
->port
.blocked_open
--;
624 port
->port
.flags
|= ASYNC_NORMAL_ACTIVE
;
628 static int mxser_set_baud(struct mxser_port
*info
, long newspd
)
633 if (!info
->port
.tty
|| !info
->port
.tty
->termios
)
639 if (newspd
> info
->max_baud
)
643 quot
= 2 * info
->baud_base
/ 269;
644 tty_encode_baud_rate(info
->port
.tty
, 134, 134);
646 quot
= info
->baud_base
/ newspd
;
649 baud
= info
->baud_base
/quot
;
650 tty_encode_baud_rate(info
->port
.tty
, baud
, baud
);
655 info
->timeout
= ((info
->xmit_fifo_size
* HZ
* 10 * quot
) / info
->baud_base
);
656 info
->timeout
+= HZ
/ 50; /* Add .02 seconds of slop */
659 info
->MCR
|= UART_MCR_DTR
;
660 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
662 info
->MCR
&= ~UART_MCR_DTR
;
663 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
667 cval
= inb(info
->ioaddr
+ UART_LCR
);
669 outb(cval
| UART_LCR_DLAB
, info
->ioaddr
+ UART_LCR
); /* set DLAB */
671 outb(quot
& 0xff, info
->ioaddr
+ UART_DLL
); /* LS of divisor */
672 outb(quot
>> 8, info
->ioaddr
+ UART_DLM
); /* MS of divisor */
673 outb(cval
, info
->ioaddr
+ UART_LCR
); /* reset DLAB */
676 if (C_BAUD(info
->port
.tty
) == BOTHER
) {
677 quot
= info
->baud_base
% newspd
;
679 if (quot
% newspd
> newspd
/ 2) {
685 mxser_set_must_enum_value(info
->ioaddr
, quot
);
688 mxser_set_must_enum_value(info
->ioaddr
, 0);
694 * This routine is called to set the UART divisor registers to match
695 * the specified baud rate for a serial port.
697 static int mxser_change_speed(struct mxser_port
*info
,
698 struct ktermios
*old_termios
)
700 unsigned cflag
, cval
, fcr
;
702 unsigned char status
;
704 if (!info
->port
.tty
|| !info
->port
.tty
->termios
)
706 cflag
= info
->port
.tty
->termios
->c_cflag
;
710 if (mxser_set_baud_method
[info
->port
.tty
->index
] == 0)
711 mxser_set_baud(info
, tty_get_baud_rate(info
->port
.tty
));
713 /* byte size and parity */
714 switch (cflag
& CSIZE
) {
729 break; /* too keep GCC shut... */
734 cval
|= UART_LCR_PARITY
;
735 if (!(cflag
& PARODD
))
736 cval
|= UART_LCR_EPAR
;
738 cval
|= UART_LCR_SPAR
;
740 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
741 if (info
->board
->chip_flag
) {
742 fcr
= UART_FCR_ENABLE_FIFO
;
743 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
744 mxser_set_must_fifo_value(info
);
748 fcr
= UART_FCR_ENABLE_FIFO
;
749 if (info
->board
->chip_flag
) {
750 fcr
|= MOXA_MUST_FCR_GDA_MODE_ENABLE
;
751 mxser_set_must_fifo_value(info
);
753 switch (info
->rx_trigger
) {
755 fcr
|= UART_FCR_TRIGGER_1
;
758 fcr
|= UART_FCR_TRIGGER_4
;
761 fcr
|= UART_FCR_TRIGGER_8
;
764 fcr
|= UART_FCR_TRIGGER_14
;
770 /* CTS flow control flag and modem status interrupts */
771 info
->IER
&= ~UART_IER_MSI
;
772 info
->MCR
&= ~UART_MCR_AFE
;
773 if (cflag
& CRTSCTS
) {
774 info
->port
.flags
|= ASYNC_CTS_FLOW
;
775 info
->IER
|= UART_IER_MSI
;
776 if ((info
->type
== PORT_16550A
) || (info
->board
->chip_flag
)) {
777 info
->MCR
|= UART_MCR_AFE
;
779 status
= inb(info
->ioaddr
+ UART_MSR
);
780 if (info
->port
.tty
->hw_stopped
) {
781 if (status
& UART_MSR_CTS
) {
782 info
->port
.tty
->hw_stopped
= 0;
783 if (info
->type
!= PORT_16550A
&&
784 !info
->board
->chip_flag
) {
785 outb(info
->IER
& ~UART_IER_THRI
,
788 info
->IER
|= UART_IER_THRI
;
789 outb(info
->IER
, info
->ioaddr
+
792 tty_wakeup(info
->port
.tty
);
795 if (!(status
& UART_MSR_CTS
)) {
796 info
->port
.tty
->hw_stopped
= 1;
797 if ((info
->type
!= PORT_16550A
) &&
798 (!info
->board
->chip_flag
)) {
799 info
->IER
&= ~UART_IER_THRI
;
800 outb(info
->IER
, info
->ioaddr
+
807 info
->port
.flags
&= ~ASYNC_CTS_FLOW
;
809 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
810 if (cflag
& CLOCAL
) {
811 info
->port
.flags
&= ~ASYNC_CHECK_CD
;
813 info
->port
.flags
|= ASYNC_CHECK_CD
;
814 info
->IER
|= UART_IER_MSI
;
816 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
819 * Set up parity check flag
821 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
822 if (I_INPCK(info
->port
.tty
))
823 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
824 if (I_BRKINT(info
->port
.tty
) || I_PARMRK(info
->port
.tty
))
825 info
->read_status_mask
|= UART_LSR_BI
;
827 info
->ignore_status_mask
= 0;
829 if (I_IGNBRK(info
->port
.tty
)) {
830 info
->ignore_status_mask
|= UART_LSR_BI
;
831 info
->read_status_mask
|= UART_LSR_BI
;
833 * If we're ignore parity and break indicators, ignore
834 * overruns too. (For real raw support).
836 if (I_IGNPAR(info
->port
.tty
)) {
837 info
->ignore_status_mask
|=
841 info
->read_status_mask
|=
847 if (info
->board
->chip_flag
) {
848 mxser_set_must_xon1_value(info
->ioaddr
, START_CHAR(info
->port
.tty
));
849 mxser_set_must_xoff1_value(info
->ioaddr
, STOP_CHAR(info
->port
.tty
));
850 if (I_IXON(info
->port
.tty
)) {
851 mxser_enable_must_rx_software_flow_control(
854 mxser_disable_must_rx_software_flow_control(
857 if (I_IXOFF(info
->port
.tty
)) {
858 mxser_enable_must_tx_software_flow_control(
861 mxser_disable_must_tx_software_flow_control(
867 outb(fcr
, info
->ioaddr
+ UART_FCR
); /* set fcr */
868 outb(cval
, info
->ioaddr
+ UART_LCR
);
873 static void mxser_check_modem_status(struct mxser_port
*port
, int status
)
875 /* update input line counters */
876 if (status
& UART_MSR_TERI
)
878 if (status
& UART_MSR_DDSR
)
880 if (status
& UART_MSR_DDCD
)
882 if (status
& UART_MSR_DCTS
)
884 port
->mon_data
.modem_status
= status
;
885 wake_up_interruptible(&port
->delta_msr_wait
);
887 if ((port
->port
.flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
888 if (status
& UART_MSR_DCD
)
889 wake_up_interruptible(&port
->port
.open_wait
);
892 if (port
->port
.flags
& ASYNC_CTS_FLOW
) {
893 if (port
->port
.tty
->hw_stopped
) {
894 if (status
& UART_MSR_CTS
) {
895 port
->port
.tty
->hw_stopped
= 0;
897 if ((port
->type
!= PORT_16550A
) &&
898 (!port
->board
->chip_flag
)) {
899 outb(port
->IER
& ~UART_IER_THRI
,
900 port
->ioaddr
+ UART_IER
);
901 port
->IER
|= UART_IER_THRI
;
902 outb(port
->IER
, port
->ioaddr
+
905 tty_wakeup(port
->port
.tty
);
908 if (!(status
& UART_MSR_CTS
)) {
909 port
->port
.tty
->hw_stopped
= 1;
910 if (port
->type
!= PORT_16550A
&&
911 !port
->board
->chip_flag
) {
912 port
->IER
&= ~UART_IER_THRI
;
913 outb(port
->IER
, port
->ioaddr
+
921 static int mxser_startup(struct mxser_port
*info
)
926 page
= __get_free_page(GFP_KERNEL
);
930 spin_lock_irqsave(&info
->slock
, flags
);
932 if (info
->port
.flags
& ASYNC_INITIALIZED
) {
934 spin_unlock_irqrestore(&info
->slock
, flags
);
938 if (!info
->ioaddr
|| !info
->type
) {
940 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
942 spin_unlock_irqrestore(&info
->slock
, flags
);
945 if (info
->port
.xmit_buf
)
948 info
->port
.xmit_buf
= (unsigned char *) page
;
951 * Clear the FIFO buffers and disable them
952 * (they will be reenabled in mxser_change_speed())
954 if (info
->board
->chip_flag
)
955 outb((UART_FCR_CLEAR_RCVR
|
956 UART_FCR_CLEAR_XMIT
|
957 MOXA_MUST_FCR_GDA_MODE_ENABLE
), info
->ioaddr
+ UART_FCR
);
959 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
960 info
->ioaddr
+ UART_FCR
);
963 * At this point there's no way the LSR could still be 0xFF;
964 * if it is, then bail out, because there's likely no UART
967 if (inb(info
->ioaddr
+ UART_LSR
) == 0xff) {
968 spin_unlock_irqrestore(&info
->slock
, flags
);
969 if (capable(CAP_SYS_ADMIN
)) {
971 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
978 * Clear the interrupt registers.
980 (void) inb(info
->ioaddr
+ UART_LSR
);
981 (void) inb(info
->ioaddr
+ UART_RX
);
982 (void) inb(info
->ioaddr
+ UART_IIR
);
983 (void) inb(info
->ioaddr
+ UART_MSR
);
986 * Now, initialize the UART
988 outb(UART_LCR_WLEN8
, info
->ioaddr
+ UART_LCR
); /* reset DLAB */
989 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
990 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
993 * Finally, enable interrupts
995 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
997 if (info
->board
->chip_flag
)
998 info
->IER
|= MOXA_MUST_IER_EGDAI
;
999 outb(info
->IER
, info
->ioaddr
+ UART_IER
); /* enable interrupts */
1002 * And clear the interrupt registers again for luck.
1004 (void) inb(info
->ioaddr
+ UART_LSR
);
1005 (void) inb(info
->ioaddr
+ UART_RX
);
1006 (void) inb(info
->ioaddr
+ UART_IIR
);
1007 (void) inb(info
->ioaddr
+ UART_MSR
);
1010 clear_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1011 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1014 * and set the speed of the serial port
1016 mxser_change_speed(info
, NULL
);
1017 info
->port
.flags
|= ASYNC_INITIALIZED
;
1018 spin_unlock_irqrestore(&info
->slock
, flags
);
1024 * This routine will shutdown a serial port; interrupts maybe disabled, and
1025 * DTR is dropped if the hangup on close termio flag is on.
1027 static void mxser_shutdown(struct mxser_port
*info
)
1029 unsigned long flags
;
1031 if (!(info
->port
.flags
& ASYNC_INITIALIZED
))
1034 spin_lock_irqsave(&info
->slock
, flags
);
1037 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1038 * here so the queue might never be waken up
1040 wake_up_interruptible(&info
->delta_msr_wait
);
1043 * Free the IRQ, if necessary
1045 if (info
->port
.xmit_buf
) {
1046 free_page((unsigned long) info
->port
.xmit_buf
);
1047 info
->port
.xmit_buf
= NULL
;
1051 outb(0x00, info
->ioaddr
+ UART_IER
);
1053 if (!info
->port
.tty
|| (info
->port
.tty
->termios
->c_cflag
& HUPCL
))
1054 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1055 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
1057 /* clear Rx/Tx FIFO's */
1058 if (info
->board
->chip_flag
)
1059 outb(UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
|
1060 MOXA_MUST_FCR_GDA_MODE_ENABLE
,
1061 info
->ioaddr
+ UART_FCR
);
1063 outb(UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
,
1064 info
->ioaddr
+ UART_FCR
);
1066 /* read data port to reset things */
1067 (void) inb(info
->ioaddr
+ UART_RX
);
1070 set_bit(TTY_IO_ERROR
, &info
->port
.tty
->flags
);
1072 info
->port
.flags
&= ~ASYNC_INITIALIZED
;
1074 if (info
->board
->chip_flag
)
1075 SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(info
->ioaddr
);
1077 spin_unlock_irqrestore(&info
->slock
, flags
);
1081 * This routine is called whenever a serial port is opened. It
1082 * enables interrupts for a serial port, linking in its async structure into
1083 * the IRQ chain. It also performs the serial-specific
1084 * initialization for the tty structure.
1086 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
1088 struct mxser_port
*info
;
1089 unsigned long flags
;
1093 if (line
== MXSER_PORTS
)
1095 if (line
< 0 || line
> MXSER_PORTS
)
1097 info
= &mxser_boards
[line
/ MXSER_PORTS_PER_BOARD
].ports
[line
% MXSER_PORTS_PER_BOARD
];
1101 tty
->driver_data
= info
;
1102 info
->port
.tty
= tty
;
1104 * Start up serial port
1106 spin_lock_irqsave(&info
->slock
, flags
);
1108 spin_unlock_irqrestore(&info
->slock
, flags
);
1109 retval
= mxser_startup(info
);
1113 retval
= mxser_block_til_ready(tty
, filp
, info
);
1117 /* unmark here for very high baud rate (ex. 921600 bps) used */
1118 tty
->low_latency
= 1;
1122 static void mxser_flush_buffer(struct tty_struct
*tty
)
1124 struct mxser_port
*info
= tty
->driver_data
;
1126 unsigned long flags
;
1129 spin_lock_irqsave(&info
->slock
, flags
);
1130 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1132 fcr
= inb(info
->ioaddr
+ UART_FCR
);
1133 outb((fcr
| UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
1134 info
->ioaddr
+ UART_FCR
);
1135 outb(fcr
, info
->ioaddr
+ UART_FCR
);
1137 spin_unlock_irqrestore(&info
->slock
, flags
);
1144 * This routine is called when the serial port gets closed. First, we
1145 * wait for the last remaining data to be sent. Then, we unlink its
1146 * async structure from the interrupt chain if necessary, and we free
1147 * that IRQ if nothing is left in the chain.
1149 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
1151 struct mxser_port
*info
= tty
->driver_data
;
1153 unsigned long timeout
;
1154 unsigned long flags
;
1156 if (tty
->index
== MXSER_PORTS
)
1161 spin_lock_irqsave(&info
->slock
, flags
);
1163 if (tty_hung_up_p(filp
)) {
1164 spin_unlock_irqrestore(&info
->slock
, flags
);
1167 if ((tty
->count
== 1) && (info
->port
.count
!= 1)) {
1169 * Uh, oh. tty->count is 1, which means that the tty
1170 * structure will be freed. Info->port.count should always
1171 * be one in these conditions. If it's greater than
1172 * one, we've got real problems, since it means the
1173 * serial port won't be shutdown.
1175 printk(KERN_ERR
"mxser_close: bad serial port count; "
1176 "tty->count is 1, info->port.count is %d\n", info
->port
.count
);
1177 info
->port
.count
= 1;
1179 if (--info
->port
.count
< 0) {
1180 printk(KERN_ERR
"mxser_close: bad serial port count for "
1181 "ttys%d: %d\n", tty
->index
, info
->port
.count
);
1182 info
->port
.count
= 0;
1184 if (info
->port
.count
) {
1185 spin_unlock_irqrestore(&info
->slock
, flags
);
1188 info
->port
.flags
|= ASYNC_CLOSING
;
1189 spin_unlock_irqrestore(&info
->slock
, flags
);
1191 * Save the termios structure, since this port may have
1192 * separate termios for callout and dialin.
1194 if (info
->port
.flags
& ASYNC_NORMAL_ACTIVE
)
1195 info
->normal_termios
= *tty
->termios
;
1197 * Now we wait for the transmit buffer to clear; and we notify
1198 * the line discipline to only process XON/XOFF characters.
1201 if (info
->port
.closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1202 tty_wait_until_sent(tty
, info
->port
.closing_wait
);
1204 * At this point we stop accepting input. To do this, we
1205 * disable the receive line status interrupts, and tell the
1206 * interrupt driver to stop checking the data ready bit in the
1207 * line status register.
1209 info
->IER
&= ~UART_IER_RLSI
;
1210 if (info
->board
->chip_flag
)
1211 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1213 if (info
->port
.flags
& ASYNC_INITIALIZED
) {
1214 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1216 * Before we drop DTR, make sure the UART transmitter
1217 * has completely drained; this is especially
1218 * important if there is a transmit FIFO!
1220 timeout
= jiffies
+ HZ
;
1221 while (!(inb(info
->ioaddr
+ UART_LSR
) & UART_LSR_TEMT
)) {
1222 schedule_timeout_interruptible(5);
1223 if (time_after(jiffies
, timeout
))
1227 mxser_shutdown(info
);
1229 mxser_flush_buffer(tty
);
1230 tty_ldisc_flush(tty
);
1233 info
->port
.tty
= NULL
;
1234 if (info
->port
.blocked_open
) {
1235 if (info
->port
.close_delay
)
1236 schedule_timeout_interruptible(info
->port
.close_delay
);
1237 wake_up_interruptible(&info
->port
.open_wait
);
1240 info
->port
.flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
1243 static int mxser_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1246 struct mxser_port
*info
= tty
->driver_data
;
1247 unsigned long flags
;
1249 if (!info
->port
.xmit_buf
)
1253 c
= min_t(int, count
, min(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1254 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1258 memcpy(info
->port
.xmit_buf
+ info
->xmit_head
, buf
, c
);
1259 spin_lock_irqsave(&info
->slock
, flags
);
1260 info
->xmit_head
= (info
->xmit_head
+ c
) &
1261 (SERIAL_XMIT_SIZE
- 1);
1262 info
->xmit_cnt
+= c
;
1263 spin_unlock_irqrestore(&info
->slock
, flags
);
1270 if (info
->xmit_cnt
&& !tty
->stopped
) {
1271 if (!tty
->hw_stopped
||
1272 (info
->type
== PORT_16550A
) ||
1273 (info
->board
->chip_flag
)) {
1274 spin_lock_irqsave(&info
->slock
, flags
);
1275 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+
1277 info
->IER
|= UART_IER_THRI
;
1278 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1279 spin_unlock_irqrestore(&info
->slock
, flags
);
1285 static int mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
1287 struct mxser_port
*info
= tty
->driver_data
;
1288 unsigned long flags
;
1290 if (!info
->port
.xmit_buf
)
1293 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1)
1296 spin_lock_irqsave(&info
->slock
, flags
);
1297 info
->port
.xmit_buf
[info
->xmit_head
++] = ch
;
1298 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
1300 spin_unlock_irqrestore(&info
->slock
, flags
);
1301 if (!tty
->stopped
) {
1302 if (!tty
->hw_stopped
||
1303 (info
->type
== PORT_16550A
) ||
1304 info
->board
->chip_flag
) {
1305 spin_lock_irqsave(&info
->slock
, flags
);
1306 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
1307 info
->IER
|= UART_IER_THRI
;
1308 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1309 spin_unlock_irqrestore(&info
->slock
, flags
);
1316 static void mxser_flush_chars(struct tty_struct
*tty
)
1318 struct mxser_port
*info
= tty
->driver_data
;
1319 unsigned long flags
;
1321 if (info
->xmit_cnt
<= 0 ||
1323 !info
->port
.xmit_buf
||
1325 (info
->type
!= PORT_16550A
) &&
1326 (!info
->board
->chip_flag
)
1330 spin_lock_irqsave(&info
->slock
, flags
);
1332 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
1333 info
->IER
|= UART_IER_THRI
;
1334 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1336 spin_unlock_irqrestore(&info
->slock
, flags
);
1339 static int mxser_write_room(struct tty_struct
*tty
)
1341 struct mxser_port
*info
= tty
->driver_data
;
1344 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1350 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
1352 struct mxser_port
*info
= tty
->driver_data
;
1353 return info
->xmit_cnt
;
1357 * ------------------------------------------------------------
1358 * friends of mxser_ioctl()
1359 * ------------------------------------------------------------
1361 static int mxser_get_serial_info(struct mxser_port
*info
,
1362 struct serial_struct __user
*retinfo
)
1364 struct serial_struct tmp
= {
1366 .line
= info
->port
.tty
->index
,
1367 .port
= info
->ioaddr
,
1368 .irq
= info
->board
->irq
,
1369 .flags
= info
->port
.flags
,
1370 .baud_base
= info
->baud_base
,
1371 .close_delay
= info
->port
.close_delay
,
1372 .closing_wait
= info
->port
.closing_wait
,
1373 .custom_divisor
= info
->custom_divisor
,
1376 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
1381 static int mxser_set_serial_info(struct mxser_port
*info
,
1382 struct serial_struct __user
*new_info
)
1384 struct serial_struct new_serial
;
1386 unsigned long sl_flags
;
1390 if (!new_info
|| !info
->ioaddr
)
1392 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
1395 if (new_serial
.irq
!= info
->board
->irq
||
1396 new_serial
.port
!= info
->ioaddr
)
1399 flags
= info
->port
.flags
& ASYNC_SPD_MASK
;
1401 if (!capable(CAP_SYS_ADMIN
)) {
1402 if ((new_serial
.baud_base
!= info
->baud_base
) ||
1403 (new_serial
.close_delay
!= info
->port
.close_delay
) ||
1404 ((new_serial
.flags
& ~ASYNC_USR_MASK
) != (info
->port
.flags
& ~ASYNC_USR_MASK
)))
1406 info
->port
.flags
= ((info
->port
.flags
& ~ASYNC_USR_MASK
) |
1407 (new_serial
.flags
& ASYNC_USR_MASK
));
1410 * OK, past this point, all the error checking has been done.
1411 * At this point, we start making changes.....
1413 info
->port
.flags
= ((info
->port
.flags
& ~ASYNC_FLAGS
) |
1414 (new_serial
.flags
& ASYNC_FLAGS
));
1415 info
->port
.close_delay
= new_serial
.close_delay
* HZ
/ 100;
1416 info
->port
.closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
1417 info
->port
.tty
->low_latency
=
1418 (info
->port
.flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
1419 if ((info
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
&&
1420 (new_serial
.baud_base
!= info
->baud_base
||
1421 new_serial
.custom_divisor
!=
1422 info
->custom_divisor
)) {
1423 baud
= new_serial
.baud_base
/ new_serial
.custom_divisor
;
1424 tty_encode_baud_rate(info
->port
.tty
, baud
, baud
);
1428 info
->type
= new_serial
.type
;
1430 process_txrx_fifo(info
);
1432 if (info
->port
.flags
& ASYNC_INITIALIZED
) {
1433 if (flags
!= (info
->port
.flags
& ASYNC_SPD_MASK
)) {
1434 spin_lock_irqsave(&info
->slock
, sl_flags
);
1435 mxser_change_speed(info
, NULL
);
1436 spin_unlock_irqrestore(&info
->slock
, sl_flags
);
1439 retval
= mxser_startup(info
);
1445 * mxser_get_lsr_info - get line status register info
1447 * Purpose: Let user call ioctl() to get info when the UART physically
1448 * is emptied. On bus types like RS485, the transmitter must
1449 * release the bus after transmitting. This must be done when
1450 * the transmit shift register is empty, not be done when the
1451 * transmit holding register is empty. This functionality
1452 * allows an RS485 driver to be written in user space.
1454 static int mxser_get_lsr_info(struct mxser_port
*info
,
1455 unsigned int __user
*value
)
1457 unsigned char status
;
1458 unsigned int result
;
1459 unsigned long flags
;
1461 spin_lock_irqsave(&info
->slock
, flags
);
1462 status
= inb(info
->ioaddr
+ UART_LSR
);
1463 spin_unlock_irqrestore(&info
->slock
, flags
);
1464 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
1465 return put_user(result
, value
);
1468 static int mxser_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1470 struct mxser_port
*info
= tty
->driver_data
;
1471 unsigned char control
, status
;
1472 unsigned long flags
;
1475 if (tty
->index
== MXSER_PORTS
)
1476 return -ENOIOCTLCMD
;
1477 if (test_bit(TTY_IO_ERROR
, &tty
->flags
))
1480 control
= info
->MCR
;
1482 spin_lock_irqsave(&info
->slock
, flags
);
1483 status
= inb(info
->ioaddr
+ UART_MSR
);
1484 if (status
& UART_MSR_ANY_DELTA
)
1485 mxser_check_modem_status(info
, status
);
1486 spin_unlock_irqrestore(&info
->slock
, flags
);
1487 return ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
1488 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) |
1489 ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) |
1490 ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) |
1491 ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) |
1492 ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
1495 static int mxser_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1496 unsigned int set
, unsigned int clear
)
1498 struct mxser_port
*info
= tty
->driver_data
;
1499 unsigned long flags
;
1502 if (tty
->index
== MXSER_PORTS
)
1503 return -ENOIOCTLCMD
;
1504 if (test_bit(TTY_IO_ERROR
, &tty
->flags
))
1507 spin_lock_irqsave(&info
->slock
, flags
);
1509 if (set
& TIOCM_RTS
)
1510 info
->MCR
|= UART_MCR_RTS
;
1511 if (set
& TIOCM_DTR
)
1512 info
->MCR
|= UART_MCR_DTR
;
1514 if (clear
& TIOCM_RTS
)
1515 info
->MCR
&= ~UART_MCR_RTS
;
1516 if (clear
& TIOCM_DTR
)
1517 info
->MCR
&= ~UART_MCR_DTR
;
1519 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
1520 spin_unlock_irqrestore(&info
->slock
, flags
);
1524 static int __init
mxser_program_mode(int port
)
1536 id
= inb(port
+ 1) & 0x1F;
1537 if ((id
!= C168_ASIC_ID
) &&
1538 (id
!= C104_ASIC_ID
) &&
1539 (id
!= C102_ASIC_ID
) &&
1540 (id
!= CI132_ASIC_ID
) &&
1541 (id
!= CI134_ASIC_ID
) &&
1542 (id
!= CI104J_ASIC_ID
))
1544 for (i
= 0, j
= 0; i
< 4; i
++) {
1548 } else if ((j
== 1) && (n
== 1)) {
1559 static void __init
mxser_normal_mode(int port
)
1563 outb(0xA5, port
+ 1);
1564 outb(0x80, port
+ 3);
1565 outb(12, port
+ 0); /* 9600 bps */
1567 outb(0x03, port
+ 3); /* 8 data bits */
1568 outb(0x13, port
+ 4); /* loop back mode */
1569 for (i
= 0; i
< 16; i
++) {
1571 if ((n
& 0x61) == 0x60)
1576 outb(0x00, port
+ 4);
1579 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
1580 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
1581 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
1582 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
1583 #define EN_CCMD 0x000 /* Chip's command register */
1584 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
1585 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
1586 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
1587 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
1588 #define EN0_DCFG 0x00E /* Data configuration reg WR */
1589 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1590 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1591 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1592 static int __init
mxser_read_register(int port
, unsigned short *regs
)
1594 int i
, k
, value
, id
;
1597 id
= mxser_program_mode(port
);
1600 for (i
= 0; i
< 14; i
++) {
1601 k
= (i
& 0x3F) | 0x180;
1602 for (j
= 0x100; j
> 0; j
>>= 1) {
1603 outb(CHIP_CS
, port
);
1605 outb(CHIP_CS
| CHIP_DO
, port
);
1606 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
1608 outb(CHIP_CS
, port
);
1609 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
1614 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
1615 outb(CHIP_CS
, port
);
1616 outb(CHIP_CS
| CHIP_SK
, port
);
1617 if (inb(port
) & CHIP_DI
)
1623 mxser_normal_mode(port
);
1627 static int mxser_ioctl_special(unsigned int cmd
, void __user
*argp
)
1629 struct mxser_port
*port
;
1635 case MOXA_GET_MAJOR
:
1636 printk(KERN_WARNING
"mxser: '%s' uses deprecated ioctl %x, fix "
1637 "your userspace\n", current
->comm
, cmd
);
1638 return put_user(ttymajor
, (int __user
*)argp
);
1640 case MOXA_CHKPORTENABLE
:
1643 for (i
= 0; i
< MXSER_BOARDS
; i
++)
1644 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++)
1645 if (mxser_boards
[i
].ports
[j
].ioaddr
)
1648 return put_user(result
, (unsigned long __user
*)argp
);
1649 case MOXA_GETDATACOUNT
:
1651 if (copy_to_user(argp
, &mxvar_log
, sizeof(mxvar_log
)))
1655 case MOXA_GETMSTATUS
:
1657 for (i
= 0; i
< MXSER_BOARDS
; i
++)
1658 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++) {
1659 port
= &mxser_boards
[i
].ports
[j
];
1662 if (!port
->ioaddr
) {
1663 GMStatus
[i
].dcd
= 0;
1664 GMStatus
[i
].dsr
= 0;
1665 GMStatus
[i
].cts
= 0;
1669 if (!port
->port
.tty
|| !port
->port
.tty
->termios
)
1671 port
->normal_termios
.c_cflag
;
1674 port
->port
.tty
->termios
->c_cflag
;
1676 status
= inb(port
->ioaddr
+ UART_MSR
);
1677 if (status
& 0x80 /*UART_MSR_DCD */ )
1678 GMStatus
[i
].dcd
= 1;
1680 GMStatus
[i
].dcd
= 0;
1682 if (status
& 0x20 /*UART_MSR_DSR */ )
1683 GMStatus
[i
].dsr
= 1;
1685 GMStatus
[i
].dsr
= 0;
1688 if (status
& 0x10 /*UART_MSR_CTS */ )
1689 GMStatus
[i
].cts
= 1;
1691 GMStatus
[i
].cts
= 0;
1694 if (copy_to_user(argp
, GMStatus
,
1695 sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1698 case MOXA_ASPP_MON_EXT
: {
1700 unsigned long opmode
;
1701 unsigned cflag
, iflag
;
1704 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1705 for (j
= 0; j
< MXSER_PORTS_PER_BOARD
; j
++) {
1706 port
= &mxser_boards
[i
].ports
[j
];
1710 status
= mxser_get_msr(port
->ioaddr
, 0, i
);
1712 if (status
& UART_MSR_TERI
)
1714 if (status
& UART_MSR_DDSR
)
1716 if (status
& UART_MSR_DDCD
)
1718 if (status
& UART_MSR_DCTS
)
1721 port
->mon_data
.modem_status
= status
;
1722 mon_data_ext
.rx_cnt
[i
] = port
->mon_data
.rxcnt
;
1723 mon_data_ext
.tx_cnt
[i
] = port
->mon_data
.txcnt
;
1724 mon_data_ext
.up_rxcnt
[i
] =
1725 port
->mon_data
.up_rxcnt
;
1726 mon_data_ext
.up_txcnt
[i
] =
1727 port
->mon_data
.up_txcnt
;
1728 mon_data_ext
.modem_status
[i
] =
1729 port
->mon_data
.modem_status
;
1730 mon_data_ext
.baudrate
[i
] =
1731 tty_get_baud_rate(port
->port
.tty
);
1733 if (!port
->port
.tty
|| !port
->port
.tty
->termios
) {
1734 cflag
= port
->normal_termios
.c_cflag
;
1735 iflag
= port
->normal_termios
.c_iflag
;
1737 cflag
= port
->port
.tty
->termios
->c_cflag
;
1738 iflag
= port
->port
.tty
->termios
->c_iflag
;
1741 mon_data_ext
.databits
[i
] = cflag
& CSIZE
;
1743 mon_data_ext
.stopbits
[i
] = cflag
& CSTOPB
;
1745 mon_data_ext
.parity
[i
] =
1746 cflag
& (PARENB
| PARODD
| CMSPAR
);
1748 mon_data_ext
.flowctrl
[i
] = 0x00;
1750 if (cflag
& CRTSCTS
)
1751 mon_data_ext
.flowctrl
[i
] |= 0x03;
1753 if (iflag
& (IXON
| IXOFF
))
1754 mon_data_ext
.flowctrl
[i
] |= 0x0C;
1756 if (port
->type
== PORT_16550A
)
1757 mon_data_ext
.fifo
[i
] = 1;
1759 mon_data_ext
.fifo
[i
] = 0;
1763 opmode
= inb(port
->opmode_ioaddr
) >> shiftbit
;
1764 opmode
&= OP_MODE_MASK
;
1766 mon_data_ext
.iftype
[i
] = opmode
;
1771 if (copy_to_user(argp
, &mon_data_ext
,
1772 sizeof(mon_data_ext
)))
1777 return -ENOIOCTLCMD
;
1782 static int mxser_cflags_changed(struct mxser_port
*info
, unsigned long arg
,
1783 struct async_icount
*cprev
)
1785 struct async_icount cnow
;
1786 unsigned long flags
;
1789 spin_lock_irqsave(&info
->slock
, flags
);
1790 cnow
= info
->icount
; /* atomic copy */
1791 spin_unlock_irqrestore(&info
->slock
, flags
);
1793 ret
= ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
->rng
)) ||
1794 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
->dsr
)) ||
1795 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
->dcd
)) ||
1796 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
->cts
));
1803 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
,
1804 unsigned int cmd
, unsigned long arg
)
1806 struct mxser_port
*info
= tty
->driver_data
;
1807 struct async_icount cnow
;
1808 unsigned long flags
;
1809 void __user
*argp
= (void __user
*)arg
;
1812 if (tty
->index
== MXSER_PORTS
)
1813 return mxser_ioctl_special(cmd
, argp
);
1815 if (cmd
== MOXA_SET_OP_MODE
|| cmd
== MOXA_GET_OP_MODE
) {
1817 unsigned long opmode
;
1818 static unsigned char ModeMask
[] = { 0xfc, 0xf3, 0xcf, 0x3f };
1820 unsigned char val
, mask
;
1823 if (cmd
== MOXA_SET_OP_MODE
) {
1824 if (get_user(opmode
, (int __user
*) argp
))
1826 if (opmode
!= RS232_MODE
&&
1827 opmode
!= RS485_2WIRE_MODE
&&
1828 opmode
!= RS422_MODE
&&
1829 opmode
!= RS485_4WIRE_MODE
)
1834 val
= inb(info
->opmode_ioaddr
);
1836 val
|= (opmode
<< shiftbit
);
1837 outb(val
, info
->opmode_ioaddr
);
1842 opmode
= inb(info
->opmode_ioaddr
) >> shiftbit
;
1843 opmode
&= OP_MODE_MASK
;
1845 if (put_user(opmode
, (int __user
*)argp
))
1851 if (cmd
!= TIOCGSERIAL
&& cmd
!= TIOCMIWAIT
&& cmd
!= TIOCGICOUNT
&&
1852 test_bit(TTY_IO_ERROR
, &tty
->flags
))
1858 retval
= mxser_get_serial_info(info
, argp
);
1863 retval
= mxser_set_serial_info(info
, argp
);
1866 case TIOCSERGETLSR
: /* Get line status register */
1867 return mxser_get_lsr_info(info
, argp
);
1869 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1870 * - mask passed in arg for lines of interest
1871 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1872 * Caller should use TIOCGICOUNT to see which one it was
1875 spin_lock_irqsave(&info
->slock
, flags
);
1876 cnow
= info
->icount
; /* note the counters on entry */
1877 spin_unlock_irqrestore(&info
->slock
, flags
);
1879 return wait_event_interruptible(info
->delta_msr_wait
,
1880 mxser_cflags_changed(info
, arg
, &cnow
));
1882 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1883 * Return: write counters to the user passed counter struct
1884 * NB: both 1->0 and 0->1 transitions are counted except for
1885 * RI where only 0->1 is counted.
1888 struct serial_icounter_struct icnt
= { 0 };
1889 spin_lock_irqsave(&info
->slock
, flags
);
1890 cnow
= info
->icount
;
1891 spin_unlock_irqrestore(&info
->slock
, flags
);
1893 icnt
.frame
= cnow
.frame
;
1894 icnt
.brk
= cnow
.brk
;
1895 icnt
.overrun
= cnow
.overrun
;
1896 icnt
.buf_overrun
= cnow
.buf_overrun
;
1897 icnt
.parity
= cnow
.parity
;
1900 icnt
.cts
= cnow
.cts
;
1901 icnt
.dsr
= cnow
.dsr
;
1902 icnt
.rng
= cnow
.rng
;
1903 icnt
.dcd
= cnow
.dcd
;
1905 return copy_to_user(argp
, &icnt
, sizeof(icnt
)) ? -EFAULT
: 0;
1907 case MOXA_HighSpeedOn
:
1908 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int __user
*)argp
);
1909 case MOXA_SDS_RSTICOUNTER
:
1911 info
->mon_data
.rxcnt
= 0;
1912 info
->mon_data
.txcnt
= 0;
1916 case MOXA_ASPP_OQUEUE
:{
1920 len
= mxser_chars_in_buffer(tty
);
1921 lsr
= inb(info
->ioaddr
+ UART_LSR
) & UART_LSR_TEMT
;
1922 len
+= (lsr
? 0 : 1);
1925 return put_user(len
, (int __user
*)argp
);
1927 case MOXA_ASPP_MON
: {
1931 status
= mxser_get_msr(info
->ioaddr
, 1, tty
->index
);
1932 mxser_check_modem_status(info
, status
);
1934 mcr
= inb(info
->ioaddr
+ UART_MCR
);
1935 if (mcr
& MOXA_MUST_MCR_XON_FLAG
)
1936 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFHOLD
;
1938 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFHOLD
;
1940 if (mcr
& MOXA_MUST_MCR_TX_XON
)
1941 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_XOFFXENT
;
1943 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_XOFFXENT
;
1945 if (info
->port
.tty
->hw_stopped
)
1946 info
->mon_data
.hold_reason
|= NPPI_NOTIFY_CTSHOLD
;
1948 info
->mon_data
.hold_reason
&= ~NPPI_NOTIFY_CTSHOLD
;
1950 if (copy_to_user(argp
, &info
->mon_data
,
1951 sizeof(struct mxser_mon
)))
1956 case MOXA_ASPP_LSTATUS
: {
1957 if (put_user(info
->err_shadow
, (unsigned char __user
*)argp
))
1960 info
->err_shadow
= 0;
1963 case MOXA_SET_BAUD_METHOD
: {
1966 if (get_user(method
, (int __user
*)argp
))
1968 mxser_set_baud_method
[tty
->index
] = method
;
1969 return put_user(method
, (int __user
*)argp
);
1972 return -ENOIOCTLCMD
;
1977 static void mxser_stoprx(struct tty_struct
*tty
)
1979 struct mxser_port
*info
= tty
->driver_data
;
1981 info
->ldisc_stop_rx
= 1;
1983 if (info
->board
->chip_flag
) {
1984 info
->IER
&= ~MOXA_MUST_RECV_ISR
;
1985 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1987 info
->x_char
= STOP_CHAR(tty
);
1988 outb(0, info
->ioaddr
+ UART_IER
);
1989 info
->IER
|= UART_IER_THRI
;
1990 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
1994 if (info
->port
.tty
->termios
->c_cflag
& CRTSCTS
) {
1995 info
->MCR
&= ~UART_MCR_RTS
;
1996 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
2001 * This routine is called by the upper-layer tty layer to signal that
2002 * incoming characters should be throttled.
2004 static void mxser_throttle(struct tty_struct
*tty
)
2009 static void mxser_unthrottle(struct tty_struct
*tty
)
2011 struct mxser_port
*info
= tty
->driver_data
;
2014 info
->ldisc_stop_rx
= 0;
2019 if (info
->board
->chip_flag
) {
2020 info
->IER
|= MOXA_MUST_RECV_ISR
;
2021 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2023 info
->x_char
= START_CHAR(tty
);
2024 outb(0, info
->ioaddr
+ UART_IER
);
2025 info
->IER
|= UART_IER_THRI
;
2026 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2031 if (info
->port
.tty
->termios
->c_cflag
& CRTSCTS
) {
2032 info
->MCR
|= UART_MCR_RTS
;
2033 outb(info
->MCR
, info
->ioaddr
+ UART_MCR
);
2038 * mxser_stop() and mxser_start()
2040 * This routines are called before setting or resetting tty->stopped.
2041 * They enable or disable transmitter interrupts, as necessary.
2043 static void mxser_stop(struct tty_struct
*tty
)
2045 struct mxser_port
*info
= tty
->driver_data
;
2046 unsigned long flags
;
2048 spin_lock_irqsave(&info
->slock
, flags
);
2049 if (info
->IER
& UART_IER_THRI
) {
2050 info
->IER
&= ~UART_IER_THRI
;
2051 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2053 spin_unlock_irqrestore(&info
->slock
, flags
);
2056 static void mxser_start(struct tty_struct
*tty
)
2058 struct mxser_port
*info
= tty
->driver_data
;
2059 unsigned long flags
;
2061 spin_lock_irqsave(&info
->slock
, flags
);
2062 if (info
->xmit_cnt
&& info
->port
.xmit_buf
) {
2063 outb(info
->IER
& ~UART_IER_THRI
, info
->ioaddr
+ UART_IER
);
2064 info
->IER
|= UART_IER_THRI
;
2065 outb(info
->IER
, info
->ioaddr
+ UART_IER
);
2067 spin_unlock_irqrestore(&info
->slock
, flags
);
2070 static void mxser_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
2072 struct mxser_port
*info
= tty
->driver_data
;
2073 unsigned long flags
;
2075 spin_lock_irqsave(&info
->slock
, flags
);
2076 mxser_change_speed(info
, old_termios
);
2077 spin_unlock_irqrestore(&info
->slock
, flags
);
2079 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2080 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
2081 tty
->hw_stopped
= 0;
2085 /* Handle sw stopped */
2086 if ((old_termios
->c_iflag
& IXON
) &&
2087 !(tty
->termios
->c_iflag
& IXON
)) {
2090 if (info
->board
->chip_flag
) {
2091 spin_lock_irqsave(&info
->slock
, flags
);
2092 mxser_disable_must_rx_software_flow_control(
2094 spin_unlock_irqrestore(&info
->slock
, flags
);
2102 * mxser_wait_until_sent() --- wait until the transmitter is empty
2104 static void mxser_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2106 struct mxser_port
*info
= tty
->driver_data
;
2107 unsigned long orig_jiffies
, char_time
;
2110 if (info
->type
== PORT_UNKNOWN
)
2113 if (info
->xmit_fifo_size
== 0)
2114 return; /* Just in case.... */
2116 orig_jiffies
= jiffies
;
2118 * Set the check interval to be 1/5 of the estimated time to
2119 * send a single character, and make it at least 1. The check
2120 * interval should also be less than the timeout.
2122 * Note: we have to use pretty tight timings here to satisfy
2125 char_time
= (info
->timeout
- HZ
/ 50) / info
->xmit_fifo_size
;
2126 char_time
= char_time
/ 5;
2129 if (timeout
&& timeout
< char_time
)
2130 char_time
= timeout
;
2132 * If the transmitter hasn't cleared in twice the approximate
2133 * amount of time to send the entire FIFO, it probably won't
2134 * ever clear. This assumes the UART isn't doing flow
2135 * control, which is currently the case. Hence, if it ever
2136 * takes longer than info->timeout, this is probably due to a
2137 * UART bug of some kind. So, we clamp the timeout parameter at
2140 if (!timeout
|| timeout
> 2 * info
->timeout
)
2141 timeout
= 2 * info
->timeout
;
2142 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2143 printk(KERN_DEBUG
"In rs_wait_until_sent(%d) check=%lu...",
2144 timeout
, char_time
);
2145 printk("jiff=%lu...", jiffies
);
2148 while (!((lsr
= inb(info
->ioaddr
+ UART_LSR
)) & UART_LSR_TEMT
)) {
2149 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2150 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
2152 schedule_timeout_interruptible(char_time
);
2153 if (signal_pending(current
))
2155 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2158 set_current_state(TASK_RUNNING
);
2161 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2162 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
2167 * This routine is called by tty_hangup() when a hangup is signaled.
2169 static void mxser_hangup(struct tty_struct
*tty
)
2171 struct mxser_port
*info
= tty
->driver_data
;
2173 mxser_flush_buffer(tty
);
2174 mxser_shutdown(info
);
2175 info
->port
.count
= 0;
2176 info
->port
.flags
&= ~ASYNC_NORMAL_ACTIVE
;
2177 info
->port
.tty
= NULL
;
2178 wake_up_interruptible(&info
->port
.open_wait
);
2182 * mxser_rs_break() --- routine which turns the break handling on or off
2184 static int mxser_rs_break(struct tty_struct
*tty
, int break_state
)
2186 struct mxser_port
*info
= tty
->driver_data
;
2187 unsigned long flags
;
2189 spin_lock_irqsave(&info
->slock
, flags
);
2190 if (break_state
== -1)
2191 outb(inb(info
->ioaddr
+ UART_LCR
) | UART_LCR_SBC
,
2192 info
->ioaddr
+ UART_LCR
);
2194 outb(inb(info
->ioaddr
+ UART_LCR
) & ~UART_LCR_SBC
,
2195 info
->ioaddr
+ UART_LCR
);
2196 spin_unlock_irqrestore(&info
->slock
, flags
);
2200 static void mxser_receive_chars(struct mxser_port
*port
, int *status
)
2202 struct tty_struct
*tty
= port
->port
.tty
;
2203 unsigned char ch
, gdl
;
2209 recv_room
= tty
->receive_room
;
2210 if ((recv_room
== 0) && (!port
->ldisc_stop_rx
))
2213 if (port
->board
->chip_flag
!= MOXA_OTHER_UART
) {
2215 if (*status
& UART_LSR_SPECIAL
)
2217 if (port
->board
->chip_flag
== MOXA_MUST_MU860_HWID
&&
2218 (*status
& MOXA_MUST_LSR_RERR
))
2220 if (*status
& MOXA_MUST_LSR_RERR
)
2223 gdl
= inb(port
->ioaddr
+ MOXA_MUST_GDL_REGISTER
);
2225 if (port
->board
->chip_flag
== MOXA_MUST_MU150_HWID
)
2226 gdl
&= MOXA_MUST_GDL_MASK
;
2227 if (gdl
>= recv_room
) {
2228 if (!port
->ldisc_stop_rx
)
2232 ch
= inb(port
->ioaddr
+ UART_RX
);
2233 tty_insert_flip_char(tty
, ch
, 0);
2244 ch
= inb(port
->ioaddr
+ UART_RX
);
2245 if (port
->board
->chip_flag
&& (*status
& UART_LSR_OE
))
2246 outb(0x23, port
->ioaddr
+ UART_FCR
);
2247 *status
&= port
->read_status_mask
;
2248 if (*status
& port
->ignore_status_mask
) {
2249 if (++ignored
> 100)
2253 if (*status
& UART_LSR_SPECIAL
) {
2254 if (*status
& UART_LSR_BI
) {
2258 if (port
->port
.flags
& ASYNC_SAK
)
2260 } else if (*status
& UART_LSR_PE
) {
2262 port
->icount
.parity
++;
2263 } else if (*status
& UART_LSR_FE
) {
2265 port
->icount
.frame
++;
2266 } else if (*status
& UART_LSR_OE
) {
2268 port
->icount
.overrun
++;
2272 tty_insert_flip_char(tty
, ch
, flag
);
2274 if (cnt
>= recv_room
) {
2275 if (!port
->ldisc_stop_rx
)
2282 if (port
->board
->chip_flag
)
2285 *status
= inb(port
->ioaddr
+ UART_LSR
);
2286 } while (*status
& UART_LSR_DR
);
2289 mxvar_log
.rxcnt
[port
->port
.tty
->index
] += cnt
;
2290 port
->mon_data
.rxcnt
+= cnt
;
2291 port
->mon_data
.up_rxcnt
+= cnt
;
2294 * We are called from an interrupt context with &port->slock
2295 * being held. Drop it temporarily in order to prevent
2296 * recursive locking.
2298 spin_unlock(&port
->slock
);
2299 tty_flip_buffer_push(tty
);
2300 spin_lock(&port
->slock
);
2303 static void mxser_transmit_chars(struct mxser_port
*port
)
2308 outb(port
->x_char
, port
->ioaddr
+ UART_TX
);
2310 mxvar_log
.txcnt
[port
->port
.tty
->index
]++;
2311 port
->mon_data
.txcnt
++;
2312 port
->mon_data
.up_txcnt
++;
2317 if (port
->port
.xmit_buf
== NULL
)
2320 if ((port
->xmit_cnt
<= 0) || port
->port
.tty
->stopped
||
2321 (port
->port
.tty
->hw_stopped
&&
2322 (port
->type
!= PORT_16550A
) &&
2323 (!port
->board
->chip_flag
))) {
2324 port
->IER
&= ~UART_IER_THRI
;
2325 outb(port
->IER
, port
->ioaddr
+ UART_IER
);
2329 cnt
= port
->xmit_cnt
;
2330 count
= port
->xmit_fifo_size
;
2332 outb(port
->port
.xmit_buf
[port
->xmit_tail
++],
2333 port
->ioaddr
+ UART_TX
);
2334 port
->xmit_tail
= port
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
2335 if (--port
->xmit_cnt
<= 0)
2337 } while (--count
> 0);
2338 mxvar_log
.txcnt
[port
->port
.tty
->index
] += (cnt
- port
->xmit_cnt
);
2340 port
->mon_data
.txcnt
+= (cnt
- port
->xmit_cnt
);
2341 port
->mon_data
.up_txcnt
+= (cnt
- port
->xmit_cnt
);
2342 port
->icount
.tx
+= (cnt
- port
->xmit_cnt
);
2344 if (port
->xmit_cnt
< WAKEUP_CHARS
)
2345 tty_wakeup(port
->port
.tty
);
2347 if (port
->xmit_cnt
<= 0) {
2348 port
->IER
&= ~UART_IER_THRI
;
2349 outb(port
->IER
, port
->ioaddr
+ UART_IER
);
2354 * This is the serial driver's generic interrupt routine
2356 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
)
2359 struct mxser_board
*brd
= NULL
;
2360 struct mxser_port
*port
;
2361 int max
, irqbits
, bits
, msr
;
2362 unsigned int int_cnt
, pass_counter
= 0;
2363 int handled
= IRQ_NONE
;
2365 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2366 if (dev_id
== &mxser_boards
[i
]) {
2371 if (i
== MXSER_BOARDS
)
2375 max
= brd
->info
->nports
;
2376 while (pass_counter
++ < MXSER_ISR_PASS_LIMIT
) {
2377 irqbits
= inb(brd
->vector
) & brd
->vector_mask
;
2378 if (irqbits
== brd
->vector_mask
)
2381 handled
= IRQ_HANDLED
;
2382 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
2383 if (irqbits
== brd
->vector_mask
)
2387 port
= &brd
->ports
[i
];
2390 spin_lock(&port
->slock
);
2392 iir
= inb(port
->ioaddr
+ UART_IIR
);
2393 if (iir
& UART_IIR_NO_INT
)
2395 iir
&= MOXA_MUST_IIR_MASK
;
2396 if (!port
->port
.tty
||
2397 (port
->port
.flags
& ASYNC_CLOSING
) ||
2398 !(port
->port
.flags
&
2399 ASYNC_INITIALIZED
)) {
2400 status
= inb(port
->ioaddr
+ UART_LSR
);
2401 outb(0x27, port
->ioaddr
+ UART_FCR
);
2402 inb(port
->ioaddr
+ UART_MSR
);
2406 status
= inb(port
->ioaddr
+ UART_LSR
);
2408 if (status
& UART_LSR_PE
)
2409 port
->err_shadow
|= NPPI_NOTIFY_PARITY
;
2410 if (status
& UART_LSR_FE
)
2411 port
->err_shadow
|= NPPI_NOTIFY_FRAMING
;
2412 if (status
& UART_LSR_OE
)
2414 NPPI_NOTIFY_HW_OVERRUN
;
2415 if (status
& UART_LSR_BI
)
2416 port
->err_shadow
|= NPPI_NOTIFY_BREAK
;
2418 if (port
->board
->chip_flag
) {
2419 if (iir
== MOXA_MUST_IIR_GDA
||
2420 iir
== MOXA_MUST_IIR_RDA
||
2421 iir
== MOXA_MUST_IIR_RTO
||
2422 iir
== MOXA_MUST_IIR_LSR
)
2423 mxser_receive_chars(port
,
2427 status
&= port
->read_status_mask
;
2428 if (status
& UART_LSR_DR
)
2429 mxser_receive_chars(port
,
2432 msr
= inb(port
->ioaddr
+ UART_MSR
);
2433 if (msr
& UART_MSR_ANY_DELTA
)
2434 mxser_check_modem_status(port
, msr
);
2436 if (port
->board
->chip_flag
) {
2437 if (iir
== 0x02 && (status
&
2439 mxser_transmit_chars(port
);
2441 if (status
& UART_LSR_THRE
)
2442 mxser_transmit_chars(port
);
2444 } while (int_cnt
++ < MXSER_ISR_PASS_LIMIT
);
2445 spin_unlock(&port
->slock
);
2453 static const struct tty_operations mxser_ops
= {
2455 .close
= mxser_close
,
2456 .write
= mxser_write
,
2457 .put_char
= mxser_put_char
,
2458 .flush_chars
= mxser_flush_chars
,
2459 .write_room
= mxser_write_room
,
2460 .chars_in_buffer
= mxser_chars_in_buffer
,
2461 .flush_buffer
= mxser_flush_buffer
,
2462 .ioctl
= mxser_ioctl
,
2463 .throttle
= mxser_throttle
,
2464 .unthrottle
= mxser_unthrottle
,
2465 .set_termios
= mxser_set_termios
,
2467 .start
= mxser_start
,
2468 .hangup
= mxser_hangup
,
2469 .break_ctl
= mxser_rs_break
,
2470 .wait_until_sent
= mxser_wait_until_sent
,
2471 .tiocmget
= mxser_tiocmget
,
2472 .tiocmset
= mxser_tiocmset
,
2476 * The MOXA Smartio/Industio serial driver boot-time initialization code!
2479 static void mxser_release_res(struct mxser_board
*brd
, struct pci_dev
*pdev
,
2483 free_irq(brd
->irq
, brd
);
2484 if (pdev
!= NULL
) { /* PCI */
2486 pci_release_region(pdev
, 2);
2487 pci_release_region(pdev
, 3);
2490 release_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
);
2491 release_region(brd
->vector
, 1);
2495 static int __devinit
mxser_initbrd(struct mxser_board
*brd
,
2496 struct pci_dev
*pdev
)
2498 struct mxser_port
*info
;
2502 printk(KERN_INFO
"max. baud rate = %d bps.\n", brd
->ports
[0].max_baud
);
2504 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2505 info
= &brd
->ports
[i
];
2506 tty_port_init(&info
->port
);
2509 info
->ldisc_stop_rx
= 0;
2511 /* Enhance mode enabled here */
2512 if (brd
->chip_flag
!= MOXA_OTHER_UART
)
2513 mxser_enable_must_enchance_mode(info
->ioaddr
);
2515 info
->port
.flags
= ASYNC_SHARE_IRQ
;
2516 info
->type
= brd
->uart_type
;
2518 process_txrx_fifo(info
);
2520 info
->custom_divisor
= info
->baud_base
* 16;
2521 info
->port
.close_delay
= 5 * HZ
/ 10;
2522 info
->port
.closing_wait
= 30 * HZ
;
2523 info
->normal_termios
= mxvar_sdriver
->init_termios
;
2524 init_waitqueue_head(&info
->delta_msr_wait
);
2525 memset(&info
->mon_data
, 0, sizeof(struct mxser_mon
));
2526 info
->err_shadow
= 0;
2527 spin_lock_init(&info
->slock
);
2529 /* before set INT ISR, disable all int */
2530 outb(inb(info
->ioaddr
+ UART_IER
) & 0xf0,
2531 info
->ioaddr
+ UART_IER
);
2534 retval
= request_irq(brd
->irq
, mxser_interrupt
, IRQF_SHARED
, "mxser",
2537 printk(KERN_ERR
"Board %s: Request irq failed, IRQ (%d) may "
2538 "conflict with another device.\n",
2539 brd
->info
->name
, brd
->irq
);
2540 /* We hold resources, we need to release them. */
2541 mxser_release_res(brd
, pdev
, 0);
2546 static int __init
mxser_get_ISA_conf(int cap
, struct mxser_board
*brd
)
2549 unsigned short regs
[16], irq
;
2550 unsigned char scratch
, scratch2
;
2552 brd
->chip_flag
= MOXA_OTHER_UART
;
2554 id
= mxser_read_register(cap
, regs
);
2557 brd
->info
= &mxser_cards
[0];
2560 brd
->info
= &mxser_cards
[1];
2562 case CI104J_ASIC_ID
:
2563 brd
->info
= &mxser_cards
[2];
2566 brd
->info
= &mxser_cards
[5];
2569 brd
->info
= &mxser_cards
[6];
2572 brd
->info
= &mxser_cards
[7];
2579 /* some ISA cards have 2 ports, but we want to see them as 4-port (why?)
2580 Flag-hack checks if configuration should be read as 2-port here. */
2581 if (brd
->info
->nports
== 2 || (brd
->info
->flags
& MXSER_HAS2
)) {
2582 irq
= regs
[9] & 0xF000;
2583 irq
= irq
| (irq
>> 4);
2584 if (irq
!= (regs
[9] & 0xFF00))
2585 return MXSER_ERR_IRQ_CONFLIT
;
2586 } else if (brd
->info
->nports
== 4) {
2587 irq
= regs
[9] & 0xF000;
2588 irq
= irq
| (irq
>> 4);
2589 irq
= irq
| (irq
>> 8);
2591 return MXSER_ERR_IRQ_CONFLIT
;
2592 } else if (brd
->info
->nports
== 8) {
2593 irq
= regs
[9] & 0xF000;
2594 irq
= irq
| (irq
>> 4);
2595 irq
= irq
| (irq
>> 8);
2596 if ((irq
!= regs
[9]) || (irq
!= regs
[10]))
2597 return MXSER_ERR_IRQ_CONFLIT
;
2601 return MXSER_ERR_IRQ
;
2602 brd
->irq
= ((int)(irq
& 0xF000) >> 12);
2603 for (i
= 0; i
< 8; i
++)
2604 brd
->ports
[i
].ioaddr
= (int) regs
[i
+ 1] & 0xFFF8;
2605 if ((regs
[12] & 0x80) == 0)
2606 return MXSER_ERR_VECTOR
;
2607 brd
->vector
= (int)regs
[11]; /* interrupt vector */
2609 brd
->vector_mask
= 0x00FF;
2611 brd
->vector_mask
= 0x000F;
2612 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
2613 if (regs
[12] & bits
) {
2614 brd
->ports
[i
].baud_base
= 921600;
2615 brd
->ports
[i
].max_baud
= 921600;
2617 brd
->ports
[i
].baud_base
= 115200;
2618 brd
->ports
[i
].max_baud
= 115200;
2621 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
2622 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
2623 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
2624 outb(scratch2
, cap
+ UART_LCR
);
2625 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
2626 scratch
= inb(cap
+ UART_IIR
);
2629 brd
->uart_type
= PORT_16550A
;
2631 brd
->uart_type
= PORT_16450
;
2632 if (!request_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
,
2634 return MXSER_ERR_IOADDR
;
2635 if (!request_region(brd
->vector
, 1, "mxser(vector)")) {
2636 release_region(brd
->ports
[0].ioaddr
, 8 * brd
->info
->nports
);
2637 return MXSER_ERR_VECTOR
;
2639 return brd
->info
->nports
;
2642 static int __devinit
mxser_probe(struct pci_dev
*pdev
,
2643 const struct pci_device_id
*ent
)
2646 struct mxser_board
*brd
;
2648 unsigned long ioaddress
;
2649 int retval
= -EINVAL
;
2651 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2652 if (mxser_boards
[i
].info
== NULL
)
2655 if (i
>= MXSER_BOARDS
) {
2656 printk(KERN_ERR
"Too many Smartio/Industio family boards found "
2657 "(maximum %d), board not configured\n", MXSER_BOARDS
);
2661 brd
= &mxser_boards
[i
];
2662 brd
->idx
= i
* MXSER_PORTS_PER_BOARD
;
2663 printk(KERN_INFO
"Found MOXA %s board (BusNo=%d, DevNo=%d)\n",
2664 mxser_cards
[ent
->driver_data
].name
,
2665 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
));
2667 retval
= pci_enable_device(pdev
);
2669 printk(KERN_ERR
"Moxa SmartI/O PCI enable fail !\n");
2674 ioaddress
= pci_resource_start(pdev
, 2);
2675 retval
= pci_request_region(pdev
, 2, "mxser(IO)");
2679 brd
->info
= &mxser_cards
[ent
->driver_data
];
2680 for (i
= 0; i
< brd
->info
->nports
; i
++)
2681 brd
->ports
[i
].ioaddr
= ioaddress
+ 8 * i
;
2684 ioaddress
= pci_resource_start(pdev
, 3);
2685 retval
= pci_request_region(pdev
, 3, "mxser(vector)");
2688 brd
->vector
= ioaddress
;
2691 brd
->irq
= pdev
->irq
;
2693 brd
->chip_flag
= CheckIsMoxaMust(brd
->ports
[0].ioaddr
);
2694 brd
->uart_type
= PORT_16550A
;
2695 brd
->vector_mask
= 0;
2697 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2698 for (j
= 0; j
< UART_INFO_NUM
; j
++) {
2699 if (Gpci_uart_info
[j
].type
== brd
->chip_flag
) {
2700 brd
->ports
[i
].max_baud
=
2701 Gpci_uart_info
[j
].max_baud
;
2703 /* exception....CP-102 */
2704 if (brd
->info
->flags
& MXSER_HIGHBAUD
)
2705 brd
->ports
[i
].max_baud
= 921600;
2711 if (brd
->chip_flag
== MOXA_MUST_MU860_HWID
) {
2712 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2714 brd
->ports
[i
].opmode_ioaddr
= ioaddress
+ 4;
2716 brd
->ports
[i
].opmode_ioaddr
= ioaddress
+ 0x0c;
2718 outb(0, ioaddress
+ 4); /* default set to RS232 mode */
2719 outb(0, ioaddress
+ 0x0c); /* default set to RS232 mode */
2722 for (i
= 0; i
< brd
->info
->nports
; i
++) {
2723 brd
->vector_mask
|= (1 << i
);
2724 brd
->ports
[i
].baud_base
= 921600;
2727 /* mxser_initbrd will hook ISR. */
2728 retval
= mxser_initbrd(brd
, pdev
);
2732 for (i
= 0; i
< brd
->info
->nports
; i
++)
2733 tty_register_device(mxvar_sdriver
, brd
->idx
+ i
, &pdev
->dev
);
2735 pci_set_drvdata(pdev
, brd
);
2739 pci_release_region(pdev
, 2);
2749 static void __devexit
mxser_remove(struct pci_dev
*pdev
)
2751 struct mxser_board
*brd
= pci_get_drvdata(pdev
);
2754 for (i
= 0; i
< brd
->info
->nports
; i
++)
2755 tty_unregister_device(mxvar_sdriver
, brd
->idx
+ i
);
2757 mxser_release_res(brd
, pdev
, 1);
2761 static struct pci_driver mxser_driver
= {
2763 .id_table
= mxser_pcibrds
,
2764 .probe
= mxser_probe
,
2765 .remove
= __devexit_p(mxser_remove
)
2768 static int __init
mxser_module_init(void)
2770 struct mxser_board
*brd
;
2772 unsigned int i
, m
, isaloop
;
2775 pr_debug("Loading module mxser ...\n");
2777 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
2781 printk(KERN_INFO
"MOXA Smartio/Industio family driver version %s\n",
2784 /* Initialize the tty_driver structure */
2785 mxvar_sdriver
->owner
= THIS_MODULE
;
2786 mxvar_sdriver
->magic
= TTY_DRIVER_MAGIC
;
2787 mxvar_sdriver
->name
= "ttyMI";
2788 mxvar_sdriver
->major
= ttymajor
;
2789 mxvar_sdriver
->minor_start
= 0;
2790 mxvar_sdriver
->num
= MXSER_PORTS
+ 1;
2791 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
2792 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
2793 mxvar_sdriver
->init_termios
= tty_std_termios
;
2794 mxvar_sdriver
->init_termios
.c_cflag
= B9600
|CS8
|CREAD
|HUPCL
|CLOCAL
;
2795 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
|TTY_DRIVER_DYNAMIC_DEV
;
2796 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
2798 retval
= tty_register_driver(mxvar_sdriver
);
2800 printk(KERN_ERR
"Couldn't install MOXA Smartio/Industio family "
2808 /* Start finding ISA boards here */
2809 for (isaloop
= 0; isaloop
< 2; isaloop
++)
2810 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
2812 cap
= mxserBoardCAP
[b
]; /* predefined */
2814 cap
= ioaddr
[b
]; /* module param */
2819 brd
= &mxser_boards
[m
];
2820 retval
= mxser_get_ISA_conf(cap
, brd
);
2823 printk(KERN_INFO
"Found MOXA %s board "
2825 brd
->info
->name
, ioaddr
[b
]);
2828 if (retval
== MXSER_ERR_IRQ
)
2829 printk(KERN_ERR
"Invalid interrupt "
2830 "number, board not "
2832 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
2833 printk(KERN_ERR
"Invalid interrupt "
2834 "number, board not "
2836 else if (retval
== MXSER_ERR_VECTOR
)
2837 printk(KERN_ERR
"Invalid interrupt "
2838 "vector, board not "
2840 else if (retval
== MXSER_ERR_IOADDR
)
2841 printk(KERN_ERR
"Invalid I/O address, "
2842 "board not configured\n");
2848 /* mxser_initbrd will hook ISR. */
2849 if (mxser_initbrd(brd
, NULL
) < 0) {
2854 brd
->idx
= m
* MXSER_PORTS_PER_BOARD
;
2855 for (i
= 0; i
< brd
->info
->nports
; i
++)
2856 tty_register_device(mxvar_sdriver
, brd
->idx
+ i
,
2862 retval
= pci_register_driver(&mxser_driver
);
2864 printk(KERN_ERR
"Can't register pci driver\n");
2868 } /* else: we have some ISA cards under control */
2871 pr_debug("Done.\n");
2875 tty_unregister_driver(mxvar_sdriver
);
2877 put_tty_driver(mxvar_sdriver
);
2881 static void __exit
mxser_module_exit(void)
2885 pr_debug("Unloading module mxser ...\n");
2887 pci_unregister_driver(&mxser_driver
);
2889 for (i
= 0; i
< MXSER_BOARDS
; i
++) /* ISA remains */
2890 if (mxser_boards
[i
].info
!= NULL
)
2891 for (j
= 0; j
< mxser_boards
[i
].info
->nports
; j
++)
2892 tty_unregister_device(mxvar_sdriver
,
2893 mxser_boards
[i
].idx
+ j
);
2894 tty_unregister_driver(mxvar_sdriver
);
2895 put_tty_driver(mxvar_sdriver
);
2897 for (i
= 0; i
< MXSER_BOARDS
; i
++)
2898 if (mxser_boards
[i
].info
!= NULL
)
2899 mxser_release_res(&mxser_boards
[i
], NULL
, 1);
2901 pr_debug("Done.\n");
2904 module_init(mxser_module_init
);
2905 module_exit(mxser_module_exit
);