1 /*****************************************************************************/
3 * mxser.c -- MOXA Smartio family multiport serial driver.
5 * Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com.tw).
7 * This code is loosely based on the Linux serial driver, written by
8 * Linus Torvalds, Theodore T'so and others.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * MOXA Smartio Family Serial Driver
28 * Copyright (C) 1999,2000 Moxa Technologies Co., LTD.
30 * for : LINUX 2.0.X, 2.2.X, 2.4.X
34 * Fixes for C104H/PCI by Tim Hockin <thockin@sun.com>
35 * Added support for: C102, CI-132, CI-134, CP-132, CP-114, CT-114 cards
36 * by Damian Wrobel <dwrobel@ertel.com.pl>
40 #include <linux/config.h>
41 #include <linux/module.h>
42 #include <linux/version.h>
43 #include <linux/errno.h>
44 #include <linux/signal.h>
45 #include <linux/sched.h>
46 #include <linux/timer.h>
47 #include <linux/interrupt.h>
48 #include <linux/tty.h>
49 #include <linux/tty_flip.h>
50 #include <linux/serial.h>
51 #include <linux/serial_reg.h>
52 #include <linux/major.h>
53 #include <linux/string.h>
54 #include <linux/fcntl.h>
55 #include <linux/ptrace.h>
56 #include <linux/ioport.h>
58 #include <linux/smp_lock.h>
59 #include <linux/pci.h>
61 #include <asm/system.h>
64 #include <asm/bitops.h>
65 #include <asm/uaccess.h>
67 #define MXSER_VERSION "1.2.1"
69 #define MXSERMAJOR 174
70 #define MXSERCUMAJOR 175
73 #define MXSER_EVENT_TXLOW 1
74 #define MXSER_EVENT_HANGUP 2
77 #define SERIAL_DO_RESTART
79 #define MXSER_BOARDS 4 /* Max. boards */
80 #define MXSER_PORTS 32 /* Max. ports */
81 #define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
82 #define MXSER_ISR_PASS_LIMIT 256
84 #define MXSER_ERR_IOADDR -1
85 #define MXSER_ERR_IRQ -2
86 #define MXSER_ERR_IRQ_CONFLIT -3
87 #define MXSER_ERR_VECTOR -4
89 #define SERIAL_TYPE_NORMAL 1
91 #define WAKEUP_CHARS 256
93 #define UART_MCR_AFE 0x20
94 #define UART_LSR_SPECIAL 0x1E
96 #define PORTNO(x) ((x)->index)
98 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
100 #define IRQ_T(info) ((info->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
103 #define MIN(a,b) ((a) < (b) ? (a) : (b))
107 * Define the Moxa PCI vendor and device IDs.
110 #ifndef PCI_VENDOR_ID_MOXA
111 #define PCI_VENDOR_ID_MOXA 0x1393
113 #ifndef PCI_DEVICE_ID_C168
114 #define PCI_DEVICE_ID_C168 0x1680
116 #ifndef PCI_DEVICE_ID_C104
117 #define PCI_DEVICE_ID_C104 0x1040
119 #ifndef PCI_DEVICE_ID_CP132
120 #define PCI_DEVICE_ID_CP132 0x1320
122 #ifndef PCI_DEVICE_ID_CP114
123 #define PCI_DEVICE_ID_CP114 0x1141
125 #ifndef PCI_DEVICE_ID_CT114
126 #define PCI_DEVICE_ID_CT114 0x1140
129 #define C168_ASIC_ID 1
130 #define C104_ASIC_ID 2
131 #define CI134_ASIC_ID 3
132 #define CI132_ASIC_ID 4
133 #define CI104J_ASIC_ID 5
134 #define C102_ASIC_ID 0xB
137 MXSER_BOARD_C168_ISA
= 0,
138 MXSER_BOARD_C104_ISA
,
140 MXSER_BOARD_C168_PCI
,
141 MXSER_BOARD_C104_PCI
,
142 MXSER_BOARD_C102_ISA
,
145 MXSER_BOARD_CP132_PCI
,
146 MXSER_BOARD_CP114_PCI
,
147 MXSER_BOARD_CT114_PCI
150 static char *mxser_brdname
[] =
165 static int mxser_numports
[] =
184 #define MOXA_GETDATACOUNT (MOXA + 23)
185 #define MOXA_GET_CONF (MOXA + 35)
186 #define MOXA_DIAGNOSE (MOXA + 50)
187 #define MOXA_CHKPORTENABLE (MOXA + 60)
188 #define MOXA_HighSpeedOn (MOXA + 61)
189 #define MOXA_GET_MAJOR (MOXA + 63)
190 #define MOXA_GET_CUMAJOR (MOXA + 64)
191 #define MOXA_GETMSTATUS (MOXA + 65)
193 static struct pci_device_id mxser_pcibrds
[] = {
194 { PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C168
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
195 MXSER_BOARD_C168_PCI
},
196 { PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_C104
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
197 MXSER_BOARD_C104_PCI
},
198 { PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_CP132
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
199 MXSER_BOARD_CP132_PCI
},
200 { PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_CP114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
201 MXSER_BOARD_CP114_PCI
},
202 { PCI_VENDOR_ID_MOXA
, PCI_DEVICE_ID_CT114
, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
203 MXSER_BOARD_CT114_PCI
},
206 MODULE_DEVICE_TABLE(pci
, mxser_pcibrds
);
208 static int ioaddr
[MXSER_BOARDS
];
209 static int ttymajor
= MXSERMAJOR
;
212 /* Variables for insmod */
214 MODULE_AUTHOR("William Chen");
215 MODULE_DESCRIPTION("MOXA Smartio Family Multiport Board Device Driver");
216 MODULE_LICENSE("GPL");
217 MODULE_PARM(ioaddr
, "1-4i");
218 MODULE_PARM(ttymajor
, "i");
219 MODULE_PARM(verbose
, "i");
221 struct mxser_hwconf
{
228 int ioaddr
[MXSER_PORTS_PER_BOARD
];
229 int baud_base
[MXSER_PORTS_PER_BOARD
];
230 struct pci_dev
*pdev
;
233 struct mxser_struct
{
235 int base
; /* port base address */
236 int irq
; /* port using irq no. */
237 int vector
; /* port irq vector */
238 int vectormask
; /* port vector mask */
239 int rx_trigger
; /* Rx fifo trigger level */
240 int baud_base
; /* max. speed */
241 int flags
; /* defined in tty.h */
242 int type
; /* UART type */
243 struct tty_struct
*tty
;
244 int read_status_mask
;
245 int ignore_status_mask
;
248 int x_char
; /* xon/xoff character */
250 unsigned short closing_wait
;
251 int IER
; /* Interrupt Enable Register */
252 int MCR
; /* Modem control register */
254 int count
; /* # of fd on device */
255 int blocked_open
; /* # of blocked opens */
256 unsigned char *xmit_buf
;
260 struct work_struct tqueue
;
262 wait_queue_head_t open_wait
;
263 wait_queue_head_t close_wait
;
264 wait_queue_head_t delta_msr_wait
;
265 struct async_icount icount
; /* kernel counters for the 4 input interrupts */
270 int rxcnt
[MXSER_PORTS
];
271 int txcnt
[MXSER_PORTS
];
274 struct mxser_mstatus
{
282 static struct mxser_mstatus GMStatus
[MXSER_PORTS
];
284 static int mxserBoardCAP
[MXSER_BOARDS
] =
287 /* 0x180, 0x280, 0x200, 0x320 */
291 static struct tty_driver
*mxvar_sdriver
;
292 static struct mxser_struct mxvar_table
[MXSER_PORTS
];
293 static struct mxser_log mxvar_log
;
294 static int mxvar_diagflag
;
296 * mxvar_tmp_buf is used as a temporary buffer by serial_write. We need
297 * to lock it in case the memcpy_fromfs blocks while swapping in a page,
298 * and some other program tries to do a serial write at the same time.
299 * Since the lock will only come under contention when the system is
300 * swapping and available memory is low, it makes sense to share one
301 * buffer across all the serial ports, since it significantly saves
302 * memory if large numbers of serial ports are open.
304 static unsigned char *mxvar_tmp_buf
;
305 static struct semaphore mxvar_tmp_buf_sem
;
308 * This is used to figure out the divisor speeds and the timeouts
310 static int mxvar_baud_table
[] =
312 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
313 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 0};
315 struct mxser_hwconf mxsercfg
[MXSER_BOARDS
];
321 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
);
322 static int mxser_get_ISA_conf(int, struct mxser_hwconf
*);
323 static int mxser_get_PCI_conf(struct pci_dev
*, int, struct mxser_hwconf
*);
324 static void mxser_do_softint(void *);
325 static int mxser_open(struct tty_struct
*, struct file
*);
326 static void mxser_close(struct tty_struct
*, struct file
*);
327 static int mxser_write(struct tty_struct
*, int, const unsigned char *, int);
328 static int mxser_write_room(struct tty_struct
*);
329 static void mxser_flush_buffer(struct tty_struct
*);
330 static int mxser_chars_in_buffer(struct tty_struct
*);
331 static void mxser_flush_chars(struct tty_struct
*);
332 static void mxser_put_char(struct tty_struct
*, unsigned char);
333 static int mxser_ioctl(struct tty_struct
*, struct file
*, uint
, ulong
);
334 static int mxser_ioctl_special(unsigned int, unsigned long);
335 static void mxser_throttle(struct tty_struct
*);
336 static void mxser_unthrottle(struct tty_struct
*);
337 static void mxser_set_termios(struct tty_struct
*, struct termios
*);
338 static void mxser_stop(struct tty_struct
*);
339 static void mxser_start(struct tty_struct
*);
340 static void mxser_hangup(struct tty_struct
*);
341 static irqreturn_t
mxser_interrupt(int, void *, struct pt_regs
*);
342 static inline void mxser_receive_chars(struct mxser_struct
*, int *);
343 static inline void mxser_transmit_chars(struct mxser_struct
*);
344 static inline void mxser_check_modem_status(struct mxser_struct
*, int);
345 static int mxser_block_til_ready(struct tty_struct
*, struct file
*, struct mxser_struct
*);
346 static int mxser_startup(struct mxser_struct
*);
347 static void mxser_shutdown(struct mxser_struct
*);
348 static int mxser_change_speed(struct mxser_struct
*, struct termios
*old_termios
);
349 static int mxser_get_serial_info(struct mxser_struct
*, struct serial_struct
*);
350 static int mxser_set_serial_info(struct mxser_struct
*, struct serial_struct
*);
351 static int mxser_get_lsr_info(struct mxser_struct
*, unsigned int *);
352 static void mxser_send_break(struct mxser_struct
*, int);
353 static int mxser_get_modem_info(struct mxser_struct
*, unsigned int *);
354 static int mxser_set_modem_info(struct mxser_struct
*, unsigned int, unsigned int *);
357 * The MOXA C168/C104 serial driver boot-time initialization code!
360 static void __exit
mxser_module_exit(void)
366 printk("Unloading module mxser ...\n");
367 if ((err
|= tty_unregister_driver(mxvar_sdriver
)))
368 printk("Couldn't unregister MOXA Smartio family serial driver\n");
369 put_tty_driver(mxvar_sdriver
);
371 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
372 if (mxsercfg
[i
].board_type
== -1)
375 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
384 int mxser_initbrd(int board
, struct mxser_hwconf
*hwconf
)
386 struct mxser_struct
*info
;
391 init_MUTEX(&mxvar_tmp_buf_sem
);
393 n
= board
* MXSER_PORTS_PER_BOARD
;
394 info
= &mxvar_table
[n
];
395 for (i
= 0; i
< hwconf
->ports
; i
++, n
++, info
++) {
397 printk(" ttyM%d/cum%d at 0x%04x ", n
, n
, hwconf
->ioaddr
[i
]);
398 if (hwconf
->baud_base
[i
] == 115200)
399 printk(" max. baud rate up to 115200 bps.\n");
401 printk(" max. baud rate up to 921600 bps.\n");
404 info
->base
= hwconf
->ioaddr
[i
];
405 info
->irq
= hwconf
->irq
;
406 info
->vector
= hwconf
->vector
;
407 info
->vectormask
= hwconf
->vector_mask
;
408 info
->rx_trigger
= 14;
409 info
->baud_base
= hwconf
->baud_base
[i
];
410 info
->flags
= ASYNC_SHARE_IRQ
;
411 info
->type
= hwconf
->uart_type
;
412 if ((info
->type
== PORT_16450
) || (info
->type
== PORT_8250
))
413 info
->xmit_fifo_size
= 1;
415 info
->xmit_fifo_size
= 16;
416 info
->custom_divisor
= hwconf
->baud_base
[i
] * 16;
417 info
->close_delay
= 5 * HZ
/ 10;
418 info
->closing_wait
= 30 * HZ
;
419 INIT_WORK(&info
->tqueue
, mxser_do_softint
, info
);
420 info
->cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
421 init_waitqueue_head(&info
->open_wait
);
422 init_waitqueue_head(&info
->close_wait
);
423 init_waitqueue_head(&info
->delta_msr_wait
);
427 * Allocate the IRQ if necessary
431 n
= board
* MXSER_PORTS_PER_BOARD
;
432 info
= &mxvar_table
[n
];
435 retval
= request_irq(hwconf
->irq
, mxser_interrupt
, IRQ_T(info
),
438 restore_flags(flags
);
439 printk("Board %d: %s", board
, mxser_brdname
[hwconf
->board_type
]);
440 printk(" Request irq fail,IRQ (%d) may be conflit with another device.\n", info
->irq
);
443 restore_flags(flags
);
449 static void mxser_getcfg(int board
, struct mxser_hwconf
*hwconf
)
451 mxsercfg
[board
] = *hwconf
;
454 static int mxser_get_PCI_conf(struct pci_dev
*pdev
, int board_type
, struct mxser_hwconf
*hwconf
)
457 unsigned int ioaddress
;
459 hwconf
->board_type
= board_type
;
460 hwconf
->ports
= mxser_numports
[board_type
];
461 ioaddress
= pci_resource_start (pdev
, 2);
462 for (i
= 0; i
< hwconf
->ports
; i
++)
463 hwconf
->ioaddr
[i
] = ioaddress
+ 8 * i
;
465 ioaddress
= pci_resource_start (pdev
, 3);
466 hwconf
->vector
= ioaddress
;
468 hwconf
->irq
= pdev
->irq
;
470 hwconf
->uart_type
= PORT_16550A
;
471 hwconf
->vector_mask
= 0;
472 for (i
= 0; i
< hwconf
->ports
; i
++) {
473 hwconf
->vector_mask
|= (1 << i
);
474 hwconf
->baud_base
[i
] = 921600;
479 static struct tty_operations mxser_ops
= {
481 .close
= mxser_close
,
482 .write
= mxser_write
,
483 .put_char
= mxser_put_char
,
484 .flush_chars
= mxser_flush_chars
,
485 .write_room
= mxser_write_room
,
486 .chars_in_buffer
= mxser_chars_in_buffer
,
487 .flush_buffer
= mxser_flush_buffer
,
488 .ioctl
= mxser_ioctl
,
489 .throttle
= mxser_throttle
,
490 .unthrottle
= mxser_unthrottle
,
491 .set_termios
= mxser_set_termios
,
493 .start
= mxser_start
,
494 .hangup
= mxser_hangup
,
497 static int __init
mxser_module_init(void)
502 struct mxser_hwconf hwconf
;
504 mxvar_sdriver
= alloc_tty_driver(MXSER_PORTS
+ 1);
508 printk("MOXA Smartio family driver version %s\n", MXSER_VERSION
);
510 /* Initialize the tty_driver structure */
512 mxvar_sdriver
->owner
= THIS_MODULE
;
513 mxvar_sdriver
->name
= "ttyM";
514 mxvar_sdriver
->major
= ttymajor
;
515 mxvar_sdriver
->minor_start
= 0;
516 mxvar_sdriver
->type
= TTY_DRIVER_TYPE_SERIAL
;
517 mxvar_sdriver
->subtype
= SERIAL_TYPE_NORMAL
;
518 mxvar_sdriver
->init_termios
= tty_std_termios
;
519 mxvar_sdriver
->init_termios
.c_cflag
= B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
520 mxvar_sdriver
->flags
= TTY_DRIVER_REAL_RAW
;
521 tty_set_operations(mxvar_sdriver
, &mxser_ops
);
522 printk("Tty devices major number = %d\n", ttymajor
);
525 memset(mxvar_table
, 0, MXSER_PORTS
* sizeof(struct mxser_struct
));
526 memset(&mxvar_log
, 0, sizeof(struct mxser_log
));
530 /* Start finding ISA boards here */
531 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
533 if (!(cap
= mxserBoardCAP
[b
]))
536 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
539 printk("Found MOXA %s board (CAP=0x%x)\n",
540 mxser_brdname
[hwconf
.board_type
],
544 if (retval
== MXSER_ERR_IRQ
)
545 printk("Invalid interrupt number,board not configured\n");
546 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
547 printk("Invalid interrupt number,board not configured\n");
548 else if (retval
== MXSER_ERR_VECTOR
)
549 printk("Invalid interrupt vector,board not configured\n");
550 else if (retval
== MXSER_ERR_IOADDR
)
551 printk("Invalid I/O address,board not configured\n");
557 if (mxser_initbrd(m
, &hwconf
) < 0)
560 mxser_getcfg(m
, &hwconf
);
565 /* Start finding ISA boards from module arg */
566 for (b
= 0; b
< MXSER_BOARDS
&& m
< MXSER_BOARDS
; b
++) {
568 if (!(cap
= ioaddr
[b
]))
571 retval
= mxser_get_ISA_conf(cap
, &hwconf
);
574 printk("Found MOXA %s board (CAP=0x%x)\n",
575 mxser_brdname
[hwconf
.board_type
],
579 if (retval
== MXSER_ERR_IRQ
)
580 printk("Invalid interrupt number,board not configured\n");
581 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
582 printk("Invalid interrupt number,board not configured\n");
583 else if (retval
== MXSER_ERR_VECTOR
)
584 printk("Invalid interrupt vector,board not configured\n");
585 else if (retval
== MXSER_ERR_IOADDR
)
586 printk("Invalid I/O address,board not configured\n");
592 if (mxser_initbrd(m
, &hwconf
) < 0)
595 mxser_getcfg(m
, &hwconf
);
600 /* start finding PCI board here */
604 struct pci_dev
*pdev
= NULL
;
606 n
= (sizeof(mxser_pcibrds
) / sizeof(mxser_pcibrds
[0])) - 1;
608 for (b
= 0; b
< n
; b
++) {
609 while ((pdev
= pci_find_device(mxser_pcibrds
[b
].vendor
, mxser_pcibrds
[b
].device
, pdev
)))
611 if (pci_enable_device(pdev
))
614 printk("Found MOXA %s board(BusNo=%d,DevNo=%d)\n",
615 mxser_brdname
[mxser_pcibrds
[b
].driver_data
],
616 pdev
->bus
->number
, PCI_SLOT(pdev
->devfn
));
617 if (m
>= MXSER_BOARDS
) {
618 printk("Too many Smartio family boards found (maximum %d),board not configured\n", MXSER_BOARDS
);
620 retval
= mxser_get_PCI_conf(pdev
, mxser_pcibrds
[b
].driver_data
, &hwconf
);
622 if (retval
== MXSER_ERR_IRQ
)
623 printk("Invalid interrupt number,board not configured\n");
624 else if (retval
== MXSER_ERR_IRQ_CONFLIT
)
625 printk("Invalid interrupt number,board not configured\n");
626 else if (retval
== MXSER_ERR_VECTOR
)
627 printk("Invalid interrupt vector,board not configured\n");
628 else if (retval
== MXSER_ERR_IOADDR
)
629 printk("Invalid I/O address,board not configured\n");
632 if (mxser_initbrd(m
, &hwconf
) < 0)
634 mxser_getcfg(m
, &hwconf
);
642 for (i
= m
; i
< MXSER_BOARDS
; i
++) {
643 mxsercfg
[i
].board_type
= -1;
647 if (!tty_register_driver(mxvar_sdriver
))
650 put_tty_driver(mxvar_sdriver
);
651 printk("Couldn't install MOXA Smartio family driver !\n");
653 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
654 if (mxsercfg
[i
].board_type
== -1)
656 free_irq(mxsercfg
[i
].irq
, &mxvar_table
[i
* MXSER_PORTS_PER_BOARD
]);
661 static void mxser_do_softint(void *private_
)
663 struct mxser_struct
*info
= (struct mxser_struct
*) private_
;
664 struct tty_struct
*tty
;
668 if (test_and_clear_bit(MXSER_EVENT_TXLOW
, &info
->event
)) {
669 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
670 tty
->ldisc
.write_wakeup
)
671 (tty
->ldisc
.write_wakeup
) (tty
);
672 wake_up_interruptible(&tty
->write_wait
);
674 if (test_and_clear_bit(MXSER_EVENT_HANGUP
, &info
->event
)) {
675 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
681 * This routine is called whenever a serial port is opened. It
682 * enables interrupts for a serial port, linking in its async structure into
683 * the IRQ chain. It also performs the serial-specific
684 * initialization for the tty structure.
687 static int mxser_open(struct tty_struct
*tty
, struct file
*filp
)
689 struct mxser_struct
*info
;
694 if (line
== MXSER_PORTS
)
696 if ((line
< 0) || (line
> MXSER_PORTS
))
698 info
= mxvar_table
+ line
;
703 tty
->driver_data
= info
;
706 if (!mxvar_tmp_buf
) {
707 page
= get_zeroed_page(GFP_KERNEL
);
713 mxvar_tmp_buf
= (unsigned char *) page
;
716 * Start up serial port
718 retval
= mxser_startup(info
);
722 return mxser_block_til_ready(tty
, filp
, info
);
726 * This routine is called when the serial port gets closed. First, we
727 * wait for the last remaining data to be sent. Then, we unlink its
728 * async structure from the interrupt chain if necessary, and we free
729 * that IRQ if nothing is left in the chain.
732 static void mxser_close(struct tty_struct
*tty
, struct file
*filp
)
734 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
736 unsigned long timeout
;
738 if (PORTNO(tty
) == MXSER_PORTS
)
746 if (tty_hung_up_p(filp
)) {
747 restore_flags(flags
);
750 if ((tty
->count
== 1) && (info
->count
!= 1)) {
752 * Uh, oh. tty->count is 1, which means that the tty
753 * structure will be freed. Info->count should always
754 * be one in these conditions. If it's greater than
755 * one, we've got real problems, since it means the
756 * serial port won't be shutdown.
758 printk("mxser_close: bad serial port count; tty->count is 1, "
759 "info->count is %d\n", info
->count
);
762 if (--info
->count
< 0) {
763 printk("mxser_close: bad serial port count for ttys%d: %d\n",
764 info
->port
, info
->count
);
768 restore_flags(flags
);
771 info
->flags
|= ASYNC_CLOSING
;
772 info
->cflag
= tty
->termios
->c_cflag
;
774 * Now we wait for the transmit buffer to clear; and we notify
775 * the line discipline to only process XON/XOFF characters.
778 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
779 tty_wait_until_sent(tty
, info
->closing_wait
);
781 * At this point we stop accepting input. To do this, we
782 * disable the receive line status interrupts, and tell the
783 * interrupt driver to stop checking the data ready bit in the
784 * line status register.
786 info
->IER
&= ~UART_IER_RLSI
;
788 info->read_status_mask &= ~UART_LSR_DR;
790 if (info
->flags
& ASYNC_INITIALIZED
) {
791 outb(info
->IER
, info
->base
+ UART_IER
);
793 * Before we drop DTR, make sure the UART transmitter
794 * has completely drained; this is especially
795 * important if there is a transmit FIFO!
797 timeout
= jiffies
+ HZ
;
798 while (!(inb(info
->base
+ UART_LSR
) & UART_LSR_TEMT
)) {
799 set_current_state(TASK_INTERRUPTIBLE
);
801 if (time_after(jiffies
, timeout
))
805 mxser_shutdown(info
);
806 if (tty
->driver
->flush_buffer
)
807 tty
->driver
->flush_buffer(tty
);
808 if (tty
->ldisc
.flush_buffer
)
809 tty
->ldisc
.flush_buffer(tty
);
813 if (info
->blocked_open
) {
814 if (info
->close_delay
) {
815 set_current_state(TASK_INTERRUPTIBLE
);
816 schedule_timeout(info
->close_delay
);
818 wake_up_interruptible(&info
->open_wait
);
820 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CLOSING
);
821 wake_up_interruptible(&info
->close_wait
);
822 restore_flags(flags
);
826 static int mxser_write(struct tty_struct
*tty
, int from_user
,
827 const unsigned char *buf
, int count
)
830 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
833 if (!tty
|| !info
->xmit_buf
|| !mxvar_tmp_buf
)
838 down(&mxvar_tmp_buf_sem
);
840 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
841 SERIAL_XMIT_SIZE
- info
->xmit_head
));
845 c
-= copy_from_user(mxvar_tmp_buf
, buf
, c
);
853 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
854 SERIAL_XMIT_SIZE
- info
->xmit_head
));
855 memcpy(info
->xmit_buf
+ info
->xmit_head
, mxvar_tmp_buf
, c
);
856 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
858 restore_flags(flags
);
864 up(&mxvar_tmp_buf_sem
);
868 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
869 SERIAL_XMIT_SIZE
- info
->xmit_head
));
871 restore_flags(flags
);
875 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
876 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
- 1);
878 restore_flags(flags
);
887 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
888 !(info
->IER
& UART_IER_THRI
)) {
889 info
->IER
|= UART_IER_THRI
;
890 outb(info
->IER
, info
->base
+ UART_IER
);
892 restore_flags(flags
);
896 static void mxser_put_char(struct tty_struct
*tty
, unsigned char ch
)
898 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
901 if (!tty
|| !info
->xmit_buf
)
906 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
907 restore_flags(flags
);
910 info
->xmit_buf
[info
->xmit_head
++] = ch
;
911 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
913 /********************************************** why ??? ***********
914 if ( !tty->stopped && !tty->hw_stopped &&
915 !(info->IER & UART_IER_THRI) ) {
916 info->IER |= UART_IER_THRI;
917 outb(info->IER, info->base + UART_IER);
919 *****************************************************************/
920 restore_flags(flags
);
923 static void mxser_flush_chars(struct tty_struct
*tty
)
925 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
928 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
934 info
->IER
|= UART_IER_THRI
;
935 outb(info
->IER
, info
->base
+ UART_IER
);
936 restore_flags(flags
);
939 static int mxser_write_room(struct tty_struct
*tty
)
941 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
944 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
950 static int mxser_chars_in_buffer(struct tty_struct
*tty
)
952 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
954 return (info
->xmit_cnt
);
957 static void mxser_flush_buffer(struct tty_struct
*tty
)
959 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
964 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
965 restore_flags(flags
);
966 wake_up_interruptible(&tty
->write_wait
);
967 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
968 tty
->ldisc
.write_wakeup
)
969 (tty
->ldisc
.write_wakeup
) (tty
);
972 static int mxser_ioctl(struct tty_struct
*tty
, struct file
*file
,
973 unsigned int cmd
, unsigned long arg
)
976 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
978 struct async_icount cprev
, cnow
; /* kernel counter temps */
979 struct serial_icounter_struct
*p_cuser
; /* user space */
982 if (PORTNO(tty
) == MXSER_PORTS
)
983 return (mxser_ioctl_special(cmd
, arg
));
984 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCMIWAIT
) &&
985 (cmd
!= TIOCGICOUNT
)) {
986 if (tty
->flags
& (1 << TTY_IO_ERROR
))
990 case TCSBRK
: /* SVID version: non-zero arg --> no break */
991 retval
= tty_check_change(tty
);
994 tty_wait_until_sent(tty
, 0);
996 mxser_send_break(info
, HZ
/ 4); /* 1/4 second */
998 case TCSBRKP
: /* support for POSIX tcsendbreak() */
999 retval
= tty_check_change(tty
);
1002 tty_wait_until_sent(tty
, 0);
1003 mxser_send_break(info
, arg
? arg
* (HZ
/ 10) : HZ
/ 4);
1006 return put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long *) arg
);
1008 if(get_user(templ
, (unsigned long *) arg
))
1011 tty
->termios
->c_cflag
= ((tty
->termios
->c_cflag
& ~CLOCAL
) |
1012 (arg
? CLOCAL
: 0));
1015 return (mxser_get_modem_info(info
, (unsigned int *) arg
));
1019 return (mxser_set_modem_info(info
, cmd
, (unsigned int *) arg
));
1021 return (mxser_get_serial_info(info
, (struct serial_struct
*) arg
));
1023 return (mxser_set_serial_info(info
, (struct serial_struct
*) arg
));
1024 case TIOCSERGETLSR
: /* Get line status register */
1025 return (mxser_get_lsr_info(info
, (unsigned int *) arg
));
1027 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
1028 * - mask passed in arg for lines of interest
1029 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
1030 * Caller should use TIOCGICOUNT to see which one it was
1035 cprev
= info
->icount
; /* note the counters on entry */
1036 restore_flags(flags
);
1038 interruptible_sleep_on(&info
->delta_msr_wait
);
1039 /* see if a signal did it */
1040 if (signal_pending(current
))
1041 return (-ERESTARTSYS
);
1044 cnow
= info
->icount
; /* atomic copy */
1045 restore_flags(flags
);
1046 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
1047 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
1048 return (-EIO
); /* no change => error */
1049 if (((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
1050 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
1051 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
1052 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
))) {
1059 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1060 * Return: write counters to the user passed counter struct
1061 * NB: both 1->0 and 0->1 transitions are counted except for
1062 * RI where only 0->1 is counted.
1067 cnow
= info
->icount
;
1068 restore_flags(flags
);
1069 p_cuser
= (struct serial_icounter_struct
*) arg
;
1070 if(put_user(cnow
.cts
, &p_cuser
->cts
))
1072 if(put_user(cnow
.dsr
, &p_cuser
->dsr
))
1074 if(put_user(cnow
.rng
, &p_cuser
->rng
))
1076 return put_user(cnow
.dcd
, &p_cuser
->dcd
);
1077 case MOXA_HighSpeedOn
:
1078 return put_user(info
->baud_base
!= 115200 ? 1 : 0, (int *) arg
);
1080 return (-ENOIOCTLCMD
);
1085 static int mxser_ioctl_special(unsigned int cmd
, unsigned long arg
)
1087 int i
, result
, status
;
1091 if(copy_to_user((struct mxser_hwconf
*) arg
, mxsercfg
,
1092 sizeof(struct mxser_hwconf
) * 4))
1095 case MOXA_GET_MAJOR
:
1096 if(copy_to_user((int *) arg
, &ttymajor
, sizeof(int)))
1100 case MOXA_GET_CUMAJOR
:
1102 if(copy_to_user((int *) arg
, &result
, sizeof(int)))
1106 case MOXA_CHKPORTENABLE
:
1108 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1109 if (mxvar_table
[i
].base
)
1112 return put_user(result
, (unsigned long *) arg
);
1113 case MOXA_GETDATACOUNT
:
1114 if(copy_to_user((struct mxser_log
*) arg
, &mxvar_log
, sizeof(mxvar_log
)))
1117 case MOXA_GETMSTATUS
:
1118 for (i
= 0; i
< MXSER_PORTS
; i
++) {
1120 if (!mxvar_table
[i
].base
) {
1121 GMStatus
[i
].dcd
= 0;
1122 GMStatus
[i
].dsr
= 0;
1123 GMStatus
[i
].cts
= 0;
1126 if (!mxvar_table
[i
].tty
|| !mxvar_table
[i
].tty
->termios
)
1127 GMStatus
[i
].cflag
= mxvar_table
[i
].cflag
;
1129 GMStatus
[i
].cflag
= mxvar_table
[i
].tty
->termios
->c_cflag
;
1131 status
= inb(mxvar_table
[i
].base
+ UART_MSR
);
1132 if (status
& 0x80 /*UART_MSR_DCD */ )
1133 GMStatus
[i
].dcd
= 1;
1135 GMStatus
[i
].dcd
= 0;
1137 if (status
& 0x20 /*UART_MSR_DSR */ )
1138 GMStatus
[i
].dsr
= 1;
1140 GMStatus
[i
].dsr
= 0;
1143 if (status
& 0x10 /*UART_MSR_CTS */ )
1144 GMStatus
[i
].cts
= 1;
1146 GMStatus
[i
].cts
= 0;
1148 if(copy_to_user((struct mxser_mstatus
*) arg
, GMStatus
,
1149 sizeof(struct mxser_mstatus
) * MXSER_PORTS
))
1153 return (-ENOIOCTLCMD
);
1159 * This routine is called by the upper-layer tty layer to signal that
1160 * incoming characters should be throttled.
1162 static void mxser_throttle(struct tty_struct
*tty
)
1164 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1165 unsigned long flags
;
1168 info
->x_char
= STOP_CHAR(tty
);
1172 info
->IER
|= UART_IER_THRI
;
1173 outb(info
->IER
, info
->base
+ UART_IER
); /* force Tx interrupt */
1174 restore_flags(flags
);
1176 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1177 info
->MCR
&= ~UART_MCR_RTS
;
1180 outb(info
->MCR
, info
->base
+ UART_MCR
);
1181 restore_flags(flags
);
1185 static void mxser_unthrottle(struct tty_struct
*tty
)
1187 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1188 unsigned long flags
;
1194 info
->x_char
= START_CHAR(tty
);
1198 info
->IER
|= UART_IER_THRI
; /* force Tx interrupt */
1199 outb(info
->IER
, info
->base
+ UART_IER
);
1200 restore_flags(flags
);
1203 if (info
->tty
->termios
->c_cflag
& CRTSCTS
) {
1204 info
->MCR
|= UART_MCR_RTS
;
1207 outb(info
->MCR
, info
->base
+ UART_MCR
);
1208 restore_flags(flags
);
1212 static void mxser_set_termios(struct tty_struct
*tty
,
1213 struct termios
*old_termios
)
1215 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1217 /* 8-2-99 by William
1218 if ( (tty->termios->c_cflag == old_termios->c_cflag) &&
1219 (RELEVANT_IFLAG(tty->termios->c_iflag) ==
1220 RELEVANT_IFLAG(old_termios->c_iflag)) )
1223 mxser_change_speed(info, old_termios);
1225 if ( (old_termios->c_cflag & CRTSCTS) &&
1226 !(tty->termios->c_cflag & CRTSCTS) ) {
1227 tty->hw_stopped = 0;
1231 if ((tty
->termios
->c_cflag
!= old_termios
->c_cflag
) ||
1232 (RELEVANT_IFLAG(tty
->termios
->c_iflag
) !=
1233 RELEVANT_IFLAG(old_termios
->c_iflag
))) {
1235 mxser_change_speed(info
, old_termios
);
1237 if ((old_termios
->c_cflag
& CRTSCTS
) &&
1238 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
1239 tty
->hw_stopped
= 0;
1243 /* Handle sw stopped */
1244 if ((old_termios
->c_iflag
& IXON
) &&
1245 !(tty
->termios
->c_iflag
& IXON
)) {
1252 * mxser_stop() and mxser_start()
1254 * This routines are called before setting or resetting tty->stopped.
1255 * They enable or disable transmitter interrupts, as necessary.
1257 static void mxser_stop(struct tty_struct
*tty
)
1259 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1260 unsigned long flags
;
1264 if (info
->IER
& UART_IER_THRI
) {
1265 info
->IER
&= ~UART_IER_THRI
;
1266 outb(info
->IER
, info
->base
+ UART_IER
);
1268 restore_flags(flags
);
1271 static void mxser_start(struct tty_struct
*tty
)
1273 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1274 unsigned long flags
;
1278 if (info
->xmit_cnt
&& info
->xmit_buf
&&
1279 !(info
->IER
& UART_IER_THRI
)) {
1280 info
->IER
|= UART_IER_THRI
;
1281 outb(info
->IER
, info
->base
+ UART_IER
);
1283 restore_flags(flags
);
1287 * This routine is called by tty_hangup() when a hangup is signaled.
1289 void mxser_hangup(struct tty_struct
*tty
)
1291 struct mxser_struct
*info
= (struct mxser_struct
*) tty
->driver_data
;
1293 mxser_flush_buffer(tty
);
1294 mxser_shutdown(info
);
1297 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1299 wake_up_interruptible(&info
->open_wait
);
1303 * This is the serial driver's generic interrupt routine
1305 static irqreturn_t
mxser_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1308 struct mxser_struct
*info
;
1309 struct mxser_struct
*port
;
1310 int max
, irqbits
, bits
, msr
;
1311 int pass_counter
= 0;
1315 for (i
= 0; i
< MXSER_BOARDS
; i
++) {
1316 if (dev_id
== &(mxvar_table
[i
* MXSER_PORTS_PER_BOARD
])) {
1322 if (i
== MXSER_BOARDS
)
1326 max
= mxser_numports
[mxsercfg
[i
].board_type
];
1329 irqbits
= inb(port
->vector
) & port
->vectormask
;
1330 if (irqbits
== port
->vectormask
)
1333 for (i
= 0, bits
= 1; i
< max
; i
++, irqbits
|= bits
, bits
<<= 1) {
1334 if (irqbits
== port
->vectormask
)
1340 (inb(info
->base
+ UART_IIR
) & UART_IIR_NO_INT
))
1342 status
= inb(info
->base
+ UART_LSR
) & info
->read_status_mask
;
1343 if (status
& UART_LSR_DR
)
1344 mxser_receive_chars(info
, &status
);
1345 msr
= inb(info
->base
+ UART_MSR
);
1346 if (msr
& UART_MSR_ANY_DELTA
)
1347 mxser_check_modem_status(info
, msr
);
1348 if (status
& UART_LSR_THRE
) {
1349 /* 8-2-99 by William
1350 if ( info->x_char || (info->xmit_cnt > 0) )
1352 mxser_transmit_chars(info
);
1355 if (pass_counter
++ > MXSER_ISR_PASS_LIMIT
) {
1357 printk("MOXA Smartio/Indusrtio family driver interrupt loop break\n");
1359 break; /* Prevent infinite loops */
1362 return IRQ_RETVAL(handled
);
1365 static inline void mxser_receive_chars(struct mxser_struct
*info
,
1368 struct tty_struct
*tty
= info
->tty
;
1374 ch
= inb(info
->base
+ UART_RX
);
1375 if (*status
& info
->ignore_status_mask
) {
1376 if (++ignored
> 100)
1379 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
1382 if (*status
& UART_LSR_SPECIAL
) {
1383 if (*status
& UART_LSR_BI
) {
1384 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
1385 if (info
->flags
& ASYNC_SAK
)
1387 } else if (*status
& UART_LSR_PE
) {
1388 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
1389 } else if (*status
& UART_LSR_FE
) {
1390 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
1391 } else if (*status
& UART_LSR_OE
) {
1392 *tty
->flip
.flag_buf_ptr
++ = TTY_OVERRUN
;
1394 *tty
->flip
.flag_buf_ptr
++ = 0;
1396 *tty
->flip
.flag_buf_ptr
++ = 0;
1397 *tty
->flip
.char_buf_ptr
++ = ch
;
1400 *status
= inb(info
->base
+ UART_LSR
) & info
->read_status_mask
;
1401 } while (*status
& UART_LSR_DR
);
1402 mxvar_log
.rxcnt
[info
->port
] += cnt
;
1403 schedule_delayed_work(&tty
->flip
.work
, 1);
1407 static inline void mxser_transmit_chars(struct mxser_struct
*info
)
1412 outb(info
->x_char
, info
->base
+ UART_TX
);
1414 mxvar_log
.txcnt
[info
->port
]++;
1417 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
1418 info
->tty
->hw_stopped
) {
1419 info
->IER
&= ~UART_IER_THRI
;
1420 outb(info
->IER
, info
->base
+ UART_IER
);
1423 cnt
= info
->xmit_cnt
;
1424 count
= info
->xmit_fifo_size
;
1426 outb(info
->xmit_buf
[info
->xmit_tail
++], info
->base
+ UART_TX
);
1427 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
- 1);
1428 if (--info
->xmit_cnt
<= 0)
1430 } while (--count
> 0);
1431 mxvar_log
.txcnt
[info
->port
] += (cnt
- info
->xmit_cnt
);
1433 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1434 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
1435 schedule_work(&info
->tqueue
);
1437 if (info
->xmit_cnt
<= 0) {
1438 info
->IER
&= ~UART_IER_THRI
;
1439 outb(info
->IER
, info
->base
+ UART_IER
);
1443 static inline void mxser_check_modem_status(struct mxser_struct
*info
,
1447 /* update input line counters */
1448 if (status
& UART_MSR_TERI
)
1450 if (status
& UART_MSR_DDSR
)
1452 if (status
& UART_MSR_DDCD
)
1454 if (status
& UART_MSR_DCTS
)
1456 wake_up_interruptible(&info
->delta_msr_wait
);
1458 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
1459 if (status
& UART_MSR_DCD
)
1460 wake_up_interruptible(&info
->open_wait
);
1462 set_bit(MXSER_EVENT_HANGUP
, &info
->event
);
1463 schedule_work(&info
->tqueue
);
1465 if (info
->flags
& ASYNC_CTS_FLOW
) {
1466 if (info
->tty
->hw_stopped
) {
1467 if (status
& UART_MSR_CTS
) {
1468 info
->tty
->hw_stopped
= 0;
1469 info
->IER
|= UART_IER_THRI
;
1470 outb(info
->IER
, info
->base
+ UART_IER
);
1472 set_bit(MXSER_EVENT_TXLOW
, &info
->event
);
1473 schedule_work(&info
->tqueue
);
1476 if (!(status
& UART_MSR_CTS
)) {
1477 info
->tty
->hw_stopped
= 1;
1478 info
->IER
&= ~UART_IER_THRI
;
1479 outb(info
->IER
, info
->base
+ UART_IER
);
1485 static int mxser_block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
1486 struct mxser_struct
*info
)
1488 DECLARE_WAITQUEUE(wait
, current
);
1489 unsigned long flags
;
1494 * If the device is in the middle of being closed, then block
1495 * until it's done, and then try again.
1497 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
1498 if (info
->flags
& ASYNC_CLOSING
)
1499 interruptible_sleep_on(&info
->close_wait
);
1500 #ifdef SERIAL_DO_RESTART
1501 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1504 return (-ERESTARTSYS
);
1510 * If non-blocking mode is set, or the port is not enabled,
1511 * then make the check up front and then exit.
1513 if ((filp
->f_flags
& O_NONBLOCK
) ||
1514 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
1515 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1518 if (tty
->termios
->c_cflag
& CLOCAL
)
1522 * Block waiting for the carrier detect and the line to become
1523 * free (i.e., not in use by the callout). While we are in
1524 * this loop, info->count is dropped by one, so that
1525 * mxser_close() knows when to free things. We restore it upon
1526 * exit, either normal or abnormal.
1529 add_wait_queue(&info
->open_wait
, &wait
);
1532 if (!tty_hung_up_p(filp
))
1534 restore_flags(flags
);
1535 info
->blocked_open
++;
1539 outb(inb(info
->base
+ UART_MCR
) | UART_MCR_DTR
| UART_MCR_RTS
,
1540 info
->base
+ UART_MCR
);
1541 restore_flags(flags
);
1542 set_current_state(TASK_INTERRUPTIBLE
);
1543 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)) {
1544 #ifdef SERIAL_DO_RESTART
1545 if (info
->flags
& ASYNC_HUP_NOTIFY
)
1548 retval
= -ERESTARTSYS
;
1554 if (!(info
->flags
& ASYNC_CLOSING
) &&
1555 (do_clocal
|| (inb(info
->base
+ UART_MSR
) & UART_MSR_DCD
)))
1557 if (signal_pending(current
)) {
1558 retval
= -ERESTARTSYS
;
1563 set_current_state(TASK_RUNNING
);
1564 remove_wait_queue(&info
->open_wait
, &wait
);
1565 if (!tty_hung_up_p(filp
))
1567 info
->blocked_open
--;
1570 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
1574 static int mxser_startup(struct mxser_struct
*info
)
1576 unsigned long flags
;
1579 page
= get_zeroed_page(GFP_KERNEL
);
1586 if (info
->flags
& ASYNC_INITIALIZED
) {
1588 restore_flags(flags
);
1591 if (!info
->base
|| !info
->type
) {
1593 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1595 restore_flags(flags
);
1601 info
->xmit_buf
= (unsigned char *) page
;
1604 * Clear the FIFO buffers and disable them
1605 * (they will be reenabled in mxser_change_speed())
1607 if (info
->xmit_fifo_size
== 16)
1608 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
),
1609 info
->base
+ UART_FCR
);
1612 * At this point there's no way the LSR could still be 0xFF;
1613 * if it is, then bail out, because there's likely no UART
1616 if (inb(info
->base
+ UART_LSR
) == 0xff) {
1617 restore_flags(flags
);
1618 if (capable(CAP_SYS_ADMIN
)) {
1620 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1626 * Clear the interrupt registers.
1628 (void) inb(info
->base
+ UART_LSR
);
1629 (void) inb(info
->base
+ UART_RX
);
1630 (void) inb(info
->base
+ UART_IIR
);
1631 (void) inb(info
->base
+ UART_MSR
);
1634 * Now, initialize the UART
1636 outb(UART_LCR_WLEN8
, info
->base
+ UART_LCR
); /* reset DLAB */
1637 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
1638 outb(info
->MCR
, info
->base
+ UART_MCR
);
1641 * Finally, enable interrupts
1643 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
1644 outb(info
->IER
, info
->base
+ UART_IER
); /* enable interrupts */
1647 * And clear the interrupt registers again for luck.
1649 (void) inb(info
->base
+ UART_LSR
);
1650 (void) inb(info
->base
+ UART_RX
);
1651 (void) inb(info
->base
+ UART_IIR
);
1652 (void) inb(info
->base
+ UART_MSR
);
1655 test_and_clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1657 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1660 * and set the speed of the serial port
1662 mxser_change_speed(info
, 0);
1664 info
->flags
|= ASYNC_INITIALIZED
;
1665 restore_flags(flags
);
1670 * This routine will shutdown a serial port; interrupts maybe disabled, and
1671 * DTR is dropped if the hangup on close termio flag is on.
1673 static void mxser_shutdown(struct mxser_struct
*info
)
1675 unsigned long flags
;
1677 if (!(info
->flags
& ASYNC_INITIALIZED
))
1681 cli(); /* Disable interrupts */
1684 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1685 * here so the queue might never be waken up
1687 wake_up_interruptible(&info
->delta_msr_wait
);
1690 * Free the IRQ, if necessary
1692 if (info
->xmit_buf
) {
1693 free_page((unsigned long) info
->xmit_buf
);
1697 outb(0x00, info
->base
+ UART_IER
); /* disable all intrs */
1699 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
1700 info
->MCR
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1701 outb(info
->MCR
, info
->base
+ UART_MCR
);
1703 /* clear Rx/Tx FIFO's */
1704 outb((UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
), info
->base
+ UART_FCR
);
1705 /* read data port to reset things */
1706 (void) inb(info
->base
+ UART_RX
);
1709 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1711 info
->flags
&= ~ASYNC_INITIALIZED
;
1712 restore_flags(flags
);
1716 * This routine is called to set the UART divisor registers to match
1717 * the specified baud rate for a serial port.
1719 static int mxser_change_speed(struct mxser_struct
*info
,
1720 struct termios
*old_termios
)
1723 unsigned cflag
, cval
, fcr
;
1726 unsigned long flags
;
1728 if (!info
->tty
|| !info
->tty
->termios
)
1730 cflag
= info
->tty
->termios
->c_cflag
;
1735 #define B921600 (B460800 +1)
1737 switch (cflag
& (CBAUD
| CBAUDEX
)) {
1804 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1805 i
= 16; /* 57600 bps */
1806 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1807 i
= 17; /* 115200 bps */
1809 #ifdef ASYNC_SPD_SHI
1810 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1814 #ifdef ASYNC_SPD_WARP
1815 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1819 if (mxvar_baud_table
[i
] == 134) {
1820 quot
= (2 * info
->baud_base
/ 269);
1821 } else if (mxvar_baud_table
[i
]) {
1822 quot
= info
->baud_base
/ mxvar_baud_table
[i
];
1823 if (!quot
&& old_termios
) {
1825 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1826 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1827 switch (info
->tty
->termios
->c_cflag
& (CBAUD
| CBAUDEX
)) {
1893 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1894 i
= 16; /* 57600 bps */
1895 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1896 i
= 17; /* 115200 bps */
1897 #ifdef ASYNC_SPD_SHI
1898 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1901 #ifdef ASYNC_SPD_WARP
1902 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1906 if (mxvar_baud_table
[i
] == 134) {
1907 quot
= (2 * info
->baud_base
/ 269);
1908 } else if (mxvar_baud_table
[i
]) {
1909 quot
= info
->baud_base
/ mxvar_baud_table
[i
];
1915 } else if (quot
== 0)
1922 info
->MCR
|= UART_MCR_DTR
;
1925 outb(info
->MCR
, info
->base
+ UART_MCR
);
1926 restore_flags(flags
);
1928 info
->MCR
&= ~UART_MCR_DTR
;
1931 outb(info
->MCR
, info
->base
+ UART_MCR
);
1932 restore_flags(flags
);
1935 /* byte size and parity */
1936 switch (cflag
& CSIZE
) {
1951 break; /* too keep GCC shut... */
1956 cval
|= UART_LCR_PARITY
;
1957 if (!(cflag
& PARODD
))
1958 cval
|= UART_LCR_EPAR
;
1959 if ((info
->type
== PORT_8250
) || (info
->type
== PORT_16450
)) {
1962 fcr
= UART_FCR_ENABLE_FIFO
;
1963 switch (info
->rx_trigger
) {
1965 fcr
|= UART_FCR_TRIGGER_1
;
1968 fcr
|= UART_FCR_TRIGGER_4
;
1971 fcr
|= UART_FCR_TRIGGER_8
;
1974 fcr
|= UART_FCR_TRIGGER_14
;
1978 /* CTS flow control flag and modem status interrupts */
1979 info
->IER
&= ~UART_IER_MSI
;
1980 info
->MCR
&= ~UART_MCR_AFE
;
1981 if (cflag
& CRTSCTS
) {
1982 info
->flags
|= ASYNC_CTS_FLOW
;
1983 info
->IER
|= UART_IER_MSI
;
1984 if (info
->type
== PORT_16550A
)
1985 info
->MCR
|= UART_MCR_AFE
;
1987 info
->flags
&= ~ASYNC_CTS_FLOW
;
1989 outb(info
->MCR
, info
->base
+ UART_MCR
);
1991 info
->flags
&= ~ASYNC_CHECK_CD
;
1993 info
->flags
|= ASYNC_CHECK_CD
;
1994 info
->IER
|= UART_IER_MSI
;
1996 outb(info
->IER
, info
->base
+ UART_IER
);
1999 * Set up parity check flag
2001 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2002 if (I_INPCK(info
->tty
))
2003 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2004 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
2005 info
->read_status_mask
|= UART_LSR_BI
;
2007 info
->ignore_status_mask
= 0;
2009 /* This should be safe, but for some broken bits of hardware... */
2010 if (I_IGNPAR(info
->tty
)) {
2011 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
2012 info
->read_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
2015 if (I_IGNBRK(info
->tty
)) {
2016 info
->ignore_status_mask
|= UART_LSR_BI
;
2017 info
->read_status_mask
|= UART_LSR_BI
;
2019 * If we're ignore parity and break indicators, ignore
2020 * overruns too. (For real raw support).
2022 if (I_IGNPAR(info
->tty
)) {
2023 info
->ignore_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2024 info
->read_status_mask
|= UART_LSR_OE
| UART_LSR_PE
| UART_LSR_FE
;
2029 outb(cval
| UART_LCR_DLAB
, info
->base
+ UART_LCR
); /* set DLAB */
2030 outb(quot
& 0xff, info
->base
+ UART_DLL
); /* LS of divisor */
2031 outb(quot
>> 8, info
->base
+ UART_DLM
); /* MS of divisor */
2032 outb(cval
, info
->base
+ UART_LCR
); /* reset DLAB */
2033 outb(fcr
, info
->base
+ UART_FCR
); /* set fcr */
2034 restore_flags(flags
);
2040 * ------------------------------------------------------------
2041 * friends of mxser_ioctl()
2042 * ------------------------------------------------------------
2044 static int mxser_get_serial_info(struct mxser_struct
*info
,
2045 struct serial_struct
*retinfo
)
2047 struct serial_struct tmp
;
2051 memset(&tmp
, 0, sizeof(tmp
));
2052 tmp
.type
= info
->type
;
2053 tmp
.line
= info
->port
;
2054 tmp
.port
= info
->base
;
2055 tmp
.irq
= info
->irq
;
2056 tmp
.flags
= info
->flags
;
2057 tmp
.baud_base
= info
->baud_base
;
2058 tmp
.close_delay
= info
->close_delay
;
2059 tmp
.closing_wait
= info
->closing_wait
;
2060 tmp
.custom_divisor
= info
->custom_divisor
;
2062 return copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)) ? -EFAULT
: 0;
2065 static int mxser_set_serial_info(struct mxser_struct
*info
,
2066 struct serial_struct
*new_info
)
2068 struct serial_struct new_serial
;
2072 if (!new_info
|| !info
->base
)
2074 if (copy_from_user(&new_serial
, new_info
, sizeof(new_serial
)))
2077 if ((new_serial
.irq
!= info
->irq
) ||
2078 (new_serial
.port
!= info
->base
) ||
2079 (new_serial
.type
!= info
->type
) ||
2080 (new_serial
.custom_divisor
!= info
->custom_divisor
) ||
2081 (new_serial
.baud_base
!= info
->baud_base
))
2084 flags
= info
->flags
& ASYNC_SPD_MASK
;
2086 if (!capable(CAP_SYS_ADMIN
)) {
2087 if ((new_serial
.baud_base
!= info
->baud_base
) ||
2088 (new_serial
.close_delay
!= info
->close_delay
) ||
2089 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
2090 (info
->flags
& ~ASYNC_USR_MASK
)))
2092 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
2093 (new_serial
.flags
& ASYNC_USR_MASK
));
2096 * OK, past this point, all the error checking has been done.
2097 * At this point, we start making changes.....
2099 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
2100 (new_serial
.flags
& ASYNC_FLAGS
));
2101 info
->close_delay
= new_serial
.close_delay
* HZ
/ 100;
2102 info
->closing_wait
= new_serial
.closing_wait
* HZ
/ 100;
2105 if (info
->flags
& ASYNC_INITIALIZED
) {
2106 if (flags
!= (info
->flags
& ASYNC_SPD_MASK
)) {
2107 mxser_change_speed(info
, 0);
2110 retval
= mxser_startup(info
);
2115 * mxser_get_lsr_info - get line status register info
2117 * Purpose: Let user call ioctl() to get info when the UART physically
2118 * is emptied. On bus types like RS485, the transmitter must
2119 * release the bus after transmitting. This must be done when
2120 * the transmit shift register is empty, not be done when the
2121 * transmit holding register is empty. This functionality
2122 * allows an RS485 driver to be written in user space.
2124 static int mxser_get_lsr_info(struct mxser_struct
*info
, unsigned int *value
)
2126 unsigned char status
;
2127 unsigned int result
;
2128 unsigned long flags
;
2132 status
= inb(info
->base
+ UART_LSR
);
2133 restore_flags(flags
);
2134 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2135 return put_user(result
, value
);
2139 * This routine sends a break character out the serial port.
2141 static void mxser_send_break(struct mxser_struct
*info
, int duration
)
2143 unsigned long flags
;
2146 set_current_state(TASK_INTERRUPTIBLE
);
2149 outb(inb(info
->base
+ UART_LCR
) | UART_LCR_SBC
, info
->base
+ UART_LCR
);
2150 schedule_timeout(duration
);
2151 outb(inb(info
->base
+ UART_LCR
) & ~UART_LCR_SBC
, info
->base
+ UART_LCR
);
2152 restore_flags(flags
);
2155 static int mxser_get_modem_info(struct mxser_struct
*info
,
2156 unsigned int *value
)
2158 unsigned char control
, status
;
2159 unsigned int result
;
2160 unsigned long flags
;
2162 control
= info
->MCR
;
2165 status
= inb(info
->base
+ UART_MSR
);
2166 if (status
& UART_MSR_ANY_DELTA
)
2167 mxser_check_modem_status(info
, status
);
2168 restore_flags(flags
);
2169 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0) |
2170 ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0) |
2171 ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0) |
2172 ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0) |
2173 ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0) |
2174 ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2175 return put_user(result
, value
);
2178 static int mxser_set_modem_info(struct mxser_struct
*info
, unsigned int cmd
,
2179 unsigned int *value
)
2182 unsigned long flags
;
2184 if(get_user(arg
, value
))
2188 if (arg
& TIOCM_RTS
)
2189 info
->MCR
|= UART_MCR_RTS
;
2190 if (arg
& TIOCM_DTR
)
2191 info
->MCR
|= UART_MCR_DTR
;
2194 if (arg
& TIOCM_RTS
)
2195 info
->MCR
&= ~UART_MCR_RTS
;
2196 if (arg
& TIOCM_DTR
)
2197 info
->MCR
&= ~UART_MCR_DTR
;
2200 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
| UART_MCR_DTR
)) |
2201 ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0) |
2202 ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
2209 outb(info
->MCR
, info
->base
+ UART_MCR
);
2210 restore_flags(flags
);
2214 static int mxser_read_register(int, unsigned short *);
2215 static int mxser_program_mode(int);
2216 static void mxser_normal_mode(int);
2218 static int mxser_get_ISA_conf(int cap
, struct mxser_hwconf
*hwconf
)
2221 unsigned short regs
[16], irq
;
2222 unsigned char scratch
, scratch2
;
2224 id
= mxser_read_register(cap
, regs
);
2225 if (id
== C168_ASIC_ID
)
2226 hwconf
->board_type
= MXSER_BOARD_C168_ISA
;
2227 else if (id
== C104_ASIC_ID
)
2228 hwconf
->board_type
= MXSER_BOARD_C104_ISA
;
2229 else if (id
== C102_ASIC_ID
)
2230 hwconf
->board_type
= MXSER_BOARD_C102_ISA
;
2231 else if (id
== CI132_ASIC_ID
)
2232 hwconf
->board_type
= MXSER_BOARD_CI132
;
2233 else if (id
== CI134_ASIC_ID
)
2234 hwconf
->board_type
= MXSER_BOARD_CI134
;
2235 else if (id
== CI104J_ASIC_ID
)
2236 hwconf
->board_type
= MXSER_BOARD_CI104J
;
2239 irq
= regs
[9] & 0x0F;
2240 irq
= irq
| (irq
<< 4);
2241 irq
= irq
| (irq
<< 8);
2242 if ((irq
!= regs
[9]) || ((id
== 1) && (irq
!= regs
[10]))) {
2243 return (MXSER_ERR_IRQ_CONFLIT
);
2246 return (MXSER_ERR_IRQ
);
2248 for (i
= 0; i
< 8; i
++)
2249 hwconf
->ioaddr
[i
] = (int) regs
[i
+ 1] & 0xFFF8;
2250 hwconf
->irq
= (int) (irq
& 0x0F);
2251 if ((regs
[12] & 0x80) == 0) {
2252 return (MXSER_ERR_VECTOR
);
2254 hwconf
->vector
= (int) regs
[11]; /* interrupt vector */
2256 hwconf
->vector_mask
= 0x00FF;
2258 hwconf
->vector_mask
= 0x000F;
2259 for (i
= 7, bits
= 0x0100; i
>= 0; i
--, bits
<<= 1) {
2260 if (regs
[12] & bits
)
2261 hwconf
->baud_base
[i
] = 921600;
2263 hwconf
->baud_base
[i
] = 115200;
2265 scratch2
= inb(cap
+ UART_LCR
) & (~UART_LCR_DLAB
);
2266 outb(scratch2
| UART_LCR_DLAB
, cap
+ UART_LCR
);
2267 outb(0, cap
+ UART_EFR
); /* EFR is the same as FCR */
2268 outb(scratch2
, cap
+ UART_LCR
);
2269 outb(UART_FCR_ENABLE_FIFO
, cap
+ UART_FCR
);
2270 scratch
= inb(cap
+ UART_IIR
);
2272 hwconf
->uart_type
= PORT_16550A
;
2274 hwconf
->uart_type
= PORT_16450
;
2279 return (hwconf
->ports
);
2282 #define CHIP_SK 0x01 /* Serial Data Clock in Eprom */
2283 #define CHIP_DO 0x02 /* Serial Data Output in Eprom */
2284 #define CHIP_CS 0x04 /* Serial Chip Select in Eprom */
2285 #define CHIP_DI 0x08 /* Serial Data Input in Eprom */
2286 #define EN_CCMD 0x000 /* Chip's command register */
2287 #define EN0_RSARLO 0x008 /* Remote start address reg 0 */
2288 #define EN0_RSARHI 0x009 /* Remote start address reg 1 */
2289 #define EN0_RCNTLO 0x00A /* Remote byte count reg WR */
2290 #define EN0_RCNTHI 0x00B /* Remote byte count reg WR */
2291 #define EN0_DCFG 0x00E /* Data configuration reg WR */
2292 #define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
2293 #define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
2294 #define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
2295 static int mxser_read_register(int port
, unsigned short *regs
)
2297 int i
, k
, value
, id
;
2300 id
= mxser_program_mode(port
);
2303 for (i
= 0; i
< 14; i
++) {
2304 k
= (i
& 0x3F) | 0x180;
2305 for (j
= 0x100; j
> 0; j
>>= 1) {
2306 outb(CHIP_CS
, port
);
2308 outb(CHIP_CS
| CHIP_DO
, port
);
2309 outb(CHIP_CS
| CHIP_DO
| CHIP_SK
, port
); /* A? bit of read */
2311 outb(CHIP_CS
, port
);
2312 outb(CHIP_CS
| CHIP_SK
, port
); /* A? bit of read */
2317 for (k
= 0, j
= 0x8000; k
< 16; k
++, j
>>= 1) {
2318 outb(CHIP_CS
, port
);
2319 outb(CHIP_CS
| CHIP_SK
, port
);
2320 if (inb(port
) & CHIP_DI
)
2326 mxser_normal_mode(port
);
2330 static int mxser_program_mode(int port
)
2333 unsigned long flags
;
2344 restore_flags(flags
);
2345 id
= inb(port
+ 1) & 0x1F;
2346 if ((id
!= C168_ASIC_ID
) && (id
!= C104_ASIC_ID
) && (id
!= CI104J_ASIC_ID
) &&
2347 (id
!= C102_ASIC_ID
) && (id
!= CI132_ASIC_ID
) && (id
!= CI134_ASIC_ID
))
2349 for (i
= 0, j
= 0; i
< 4; i
++) {
2353 } else if ((j
== 1) && (n
== 1)) {
2364 static void mxser_normal_mode(int port
)
2368 outb(0xA5, port
+ 1);
2369 outb(0x80, port
+ 3);
2370 outb(12, port
+ 0); /* 9600 bps */
2372 outb(0x03, port
+ 3); /* 8 data bits */
2373 outb(0x13, port
+ 4); /* loop back mode */
2374 for (i
= 0; i
< 16; i
++) {
2376 if ((n
& 0x61) == 0x60)
2381 outb(0x00, port
+ 4);
2384 module_init(mxser_module_init
);
2385 module_exit(mxser_module_exit
);