Serial driver fixes, sent to Linus.
[linux-2.6/linux-mips.git] / drivers / char / serial.c
blob105137a928174d7de6574f2efc09491ba038dfb5
1 /*
2 * linux/drivers/char/serial.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997,
6 * 1998, 1999 Theodore Ts'o
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the
11 * Accent Async board.
13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
20 * rs_set_termios fixed to look also for changes of the input
21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
22 * Bernd Anhäupl 05/17/96.
24 * 1/97: Extended dumb serial ports are a config option now.
25 * Saves 4k. Michael A. Griffith <grif@acm.org>
27 * 8/97: Fix bug in rs_set_termios with RTS
28 * Stanislav V. Voronyi <stas@uanet.kharkov.ua>
30 * 3/98: Change the IRQ detection, use of probe_irq_o*(),
31 * supress TIOCSERGWILD and TIOCSERSWILD
32 * Etienne Lorrain <etienne.lorrain@ibm.net>
34 * 4/98: Added changes to support the ARM architecture proposed by
35 * Russell King
37 * 5/99: Updated to include support for the XR16C850 and ST16C654
38 * uarts. Stuart MacDonald <stuartm@connecttech.com>
40 * 8/99: Generalized PCI support added. Theodore Ts'o
42 * 3/00: Rid circular buffer of redundant xmit_cnt. Fix a
43 * few races on freeing buffers too.
44 * Alan Modra <alan@linuxcare.com>
46 * 5/00: Support for the RSA-DV II/S card added.
47 * Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
49 * 6/00: Remove old-style timer, use timer_list
50 * Andrew Morton <andrewm@uow.edu.au>
52 * This module exports the following rs232 io functions:
54 * int rs_init(void);
57 static char *serial_version = "5.01";
58 static char *serial_revdate = "2000-05-29";
61 * Serial driver configuration section. Here are the various options:
63 * CONFIG_HUB6
64 * Enables support for the venerable Bell Technologies
65 * HUB6 card.
67 * CONFIG_SERIAL_MANY_PORTS
68 * Enables support for ports beyond the standard, stupid
69 * COM 1/2/3/4.
71 * CONFIG_SERIAL_MULTIPORT
72 * Enables support for special multiport board support.
74 * CONFIG_SERIAL_SHARE_IRQ
75 * Enables support for multiple serial ports on one IRQ
77 * CONFIG_SERIAL_DETECT_IRQ
78 * Enable the autodetection of IRQ on standart ports
80 * SERIAL_PARANOIA_CHECK
81 * Check the magic number for the async_structure where
82 * ever possible.
85 #include <linux/config.h>
86 #include <linux/version.h>
88 #undef SERIAL_PARANOIA_CHECK
89 #define CONFIG_SERIAL_NOPAUSE_IO
90 #define SERIAL_DO_RESTART
92 #if 0
93 /* These defines are normally controlled by the autoconf.h */
94 #define CONFIG_SERIAL_MANY_PORTS
95 #define CONFIG_SERIAL_SHARE_IRQ
96 #define CONFIG_SERIAL_DETECT_IRQ
97 #define CONFIG_SERIAL_MULTIPORT
98 #define CONFIG_HUB6
99 #endif
101 #ifdef CONFIG_PCI
102 #define ENABLE_SERIAL_PCI
103 #ifndef CONFIG_SERIAL_SHARE_IRQ
104 #define CONFIG_SERIAL_SHARE_IRQ
105 #endif
106 #ifndef CONFIG_SERIAL_MANY_PORTS
107 #define CONFIG_SERIAL_MANY_PORTS
108 #endif
109 #endif
111 #if defined(CONFIG_ISAPNP)|| (defined(CONFIG_ISAPNP_MODULE) && defined(MODULE))
112 #ifndef ENABLE_SERIAL_PNP
113 #define ENABLE_SERIAL_PNP
114 #endif
115 #endif
117 /* Set of debugging defines */
119 #undef SERIAL_DEBUG_INTR
120 #undef SERIAL_DEBUG_OPEN
121 #undef SERIAL_DEBUG_FLOW
122 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
123 #undef SERIAL_DEBUG_PCI
124 #undef SERIAL_DEBUG_AUTOCONF
126 /* Sanity checks */
128 #ifdef CONFIG_SERIAL_MULTIPORT
129 #ifndef CONFIG_SERIAL_SHARE_IRQ
130 #define CONFIG_SERIAL_SHARE_IRQ
131 #endif
132 #endif
134 #ifdef CONFIG_HUB6
135 #ifndef CONFIG_SERIAL_MANY_PORTS
136 #define CONFIG_SERIAL_MANY_PORTS
137 #endif
138 #ifndef CONFIG_SERIAL_SHARE_IRQ
139 #define CONFIG_SERIAL_SHARE_IRQ
140 #endif
141 #endif
143 #define CONFIG_SERIAL_RSA
145 #define RS_STROBE_TIME (10*HZ)
146 #define RS_ISR_PASS_LIMIT 256
148 #if defined(__i386__) && (defined(CONFIG_M386) || defined(CONFIG_M486))
149 #define SERIAL_INLINE
150 #endif
153 * End of serial driver configuration section.
156 #ifdef MODVERSIONS
157 #include <linux/modversions.h>
158 #endif
159 #include <linux/module.h>
161 #include <linux/types.h>
162 #ifdef LOCAL_HEADERS
163 #include "serial_local.h"
164 #else
165 #include <linux/serial.h>
166 #include <linux/serialP.h>
167 #include <linux/serial_reg.h>
168 #include <asm/serial.h>
169 #define LOCAL_VERSTRING ""
170 #endif
172 #include <linux/errno.h>
173 #include <linux/signal.h>
174 #include <linux/sched.h>
175 #include <linux/timer.h>
176 #include <linux/interrupt.h>
177 #include <linux/tty.h>
178 #include <linux/tty_flip.h>
179 #include <linux/major.h>
180 #include <linux/string.h>
181 #include <linux/fcntl.h>
182 #include <linux/ptrace.h>
183 #include <linux/ioport.h>
184 #include <linux/mm.h>
185 #include <linux/malloc.h>
186 #if (LINUX_VERSION_CODE >= 131343)
187 #include <linux/init.h>
188 #endif
189 #if (LINUX_VERSION_CODE >= 131336)
190 #include <asm/uaccess.h>
191 #endif
192 #include <linux/delay.h>
193 #ifdef CONFIG_SERIAL_CONSOLE
194 #include <linux/console.h>
195 #endif
196 #ifdef ENABLE_SERIAL_PCI
197 #include <linux/pci.h>
198 #endif
199 #ifdef ENABLE_SERIAL_PNP
200 #include <linux/isapnp.h>
201 #endif
202 #ifdef CONFIG_MAGIC_SYSRQ
203 #include <linux/sysrq.h>
204 #endif
207 * All of the compatibilty code so we can compile serial.c against
208 * older kernels is hidden in serial_compat.h
210 #if defined(LOCAL_HEADERS) || (LINUX_VERSION_CODE < 0x020317) /* 2.3.23 */
211 #include "serial_compat.h"
212 #endif
214 #include <asm/system.h>
215 #include <asm/io.h>
216 #include <asm/irq.h>
217 #include <asm/bitops.h>
219 #ifdef CONFIG_MAC_SERIAL
220 #define SERIAL_DEV_OFFSET 2
221 #else
222 #define SERIAL_DEV_OFFSET 0
223 #endif
225 #ifdef SERIAL_INLINE
226 #define _INLINE_ inline
227 #else
228 #define _INLINE_
229 #endif
231 static char *serial_name = "Serial driver";
233 static DECLARE_TASK_QUEUE(tq_serial);
235 static struct tty_driver serial_driver, callout_driver;
236 static int serial_refcount;
238 static struct timer_list serial_timer;
240 /* serial subtype definitions */
241 #ifndef SERIAL_TYPE_NORMAL
242 #define SERIAL_TYPE_NORMAL 1
243 #define SERIAL_TYPE_CALLOUT 2
244 #endif
246 /* number of characters left in xmit buffer before we ask for more */
247 #define WAKEUP_CHARS 256
250 * IRQ_timeout - How long the timeout should be for each IRQ
251 * should be after the IRQ has been active.
254 static struct async_struct *IRQ_ports[NR_IRQS];
255 #ifdef CONFIG_SERIAL_MULTIPORT
256 static struct rs_multiport_struct rs_multiport[NR_IRQS];
257 #endif
258 static int IRQ_timeout[NR_IRQS];
259 #ifdef CONFIG_SERIAL_CONSOLE
260 static struct console sercons;
261 #endif
262 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && !defined(MODULE)
263 static unsigned long break_pressed; /* break, really ... */
264 #endif
266 static unsigned detect_uart_irq (struct serial_state * state);
267 static void autoconfig(struct serial_state * state);
268 static void change_speed(struct async_struct *info, struct termios *old);
269 static void rs_wait_until_sent(struct tty_struct *tty, int timeout);
272 * Here we define the default xmit fifo size used for each type of
273 * UART
275 static struct serial_uart_config uart_config[] = {
276 { "unknown", 1, 0 },
277 { "8250", 1, 0 },
278 { "16450", 1, 0 },
279 { "16550", 1, 0 },
280 { "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
281 { "cirrus", 1, 0 }, /* usurped by cyclades.c */
282 { "ST16650", 1, UART_CLEAR_FIFO |UART_STARTECH },
283 { "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO |
284 UART_STARTECH },
285 { "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO},
286 { "Startech", 1, 0}, /* usurped by cyclades.c */
287 { "16C950/954", 128, UART_CLEAR_FIFO | UART_USE_FIFO},
288 { "ST16654", 64, UART_CLEAR_FIFO | UART_USE_FIFO |
289 UART_STARTECH },
290 { "XR16850", 128, UART_CLEAR_FIFO | UART_USE_FIFO |
291 UART_STARTECH },
292 { "RSA", 2048, UART_CLEAR_FIFO | UART_USE_FIFO },
293 { 0, 0}
296 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
298 #define PORT_RSA_MAX 4
299 static int probe_rsa[PORT_RSA_MAX];
300 static int force_rsa[PORT_RSA_MAX];
302 MODULE_PARM(probe_rsa, "1-" __MODULE_STRING(PORT_RSA_MAX) "i");
303 MODULE_PARM(force_rsa, "1-" __MODULE_STRING(PORT_RSA_MAX) "i");
304 #endif /* CONFIG_SERIAL_RSA */
306 static struct serial_state rs_table[RS_TABLE_SIZE] = {
307 SERIAL_PORT_DFNS /* Defined in serial.h */
310 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
312 #if (defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP))
313 #define NR_PCI_BOARDS 8
314 /* We don't unregister PCI boards right now */
315 static struct pci_board_inst serial_pci_board[NR_PCI_BOARDS];
316 static int serial_pci_board_idx = 0;
318 #ifndef IS_PCI_REGION_IOPORT
319 #define IS_PCI_REGION_IOPORT(dev, r) (pci_resource_flags((dev), (r)) & \
320 IORESOURCE_IO)
321 #endif
322 #ifndef PCI_IRQ_RESOURCE
323 #define PCI_IRQ_RESOURCE(dev, r) ((dev)->irq_resource[r].start)
324 #endif
325 #ifndef pci_get_subvendor
326 #define pci_get_subvendor(dev) ((dev)->subsystem_vendor)
327 #define pci_get_subdevice(dev) ((dev)->subsystem_device)
328 #endif
329 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
331 #ifndef PREPARE_FUNC
332 #define PREPARE_FUNC(dev) (dev->prepare)
333 #define ACTIVATE_FUNC(dev) (dev->activate)
334 #define DEACTIVATE_FUNC(dev) (dev->deactivate)
335 #endif
337 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
339 static struct tty_struct *serial_table[NR_PORTS];
340 static struct termios *serial_termios[NR_PORTS];
341 static struct termios *serial_termios_locked[NR_PORTS];
344 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
345 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
346 kdevname(tty->device), (info->flags), serial_refcount,info->count,tty->count,s)
347 #else
348 #define DBG_CNT(s)
349 #endif
352 * tmp_buf is used as a temporary buffer by serial_write. We need to
353 * lock it in case the copy_from_user blocks while swapping in a page,
354 * and some other program tries to do a serial write at the same time.
355 * Since the lock will only come under contention when the system is
356 * swapping and available memory is low, it makes sense to share one
357 * buffer across all the serial ports, since it significantly saves
358 * memory if large numbers of serial ports are open.
360 static unsigned char *tmp_buf;
361 #ifdef DECLARE_MUTEX
362 static DECLARE_MUTEX(tmp_buf_sem);
363 #else
364 static struct semaphore tmp_buf_sem = MUTEX;
365 #endif
368 static inline int serial_paranoia_check(struct async_struct *info,
369 kdev_t device, const char *routine)
371 #ifdef SERIAL_PARANOIA_CHECK
372 static const char *badmagic =
373 "Warning: bad magic number for serial struct (%s) in %s\n";
374 static const char *badinfo =
375 "Warning: null async_struct for (%s) in %s\n";
377 if (!info) {
378 printk(badinfo, kdevname(device), routine);
379 return 1;
381 if (info->magic != SERIAL_MAGIC) {
382 printk(badmagic, kdevname(device), routine);
383 return 1;
385 #endif
386 return 0;
389 static _INLINE_ unsigned int serial_in(struct async_struct *info, int offset)
391 switch (info->io_type) {
392 #ifdef CONFIG_HUB6
393 case SERIAL_IO_HUB6:
394 outb(info->hub6 - 1 + offset, info->port);
395 return inb(info->port+1);
396 #endif
397 case SERIAL_IO_MEM:
398 return readb((unsigned long) info->iomem_base +
399 (offset<<info->iomem_reg_shift));
400 #ifdef CONFIG_SERIAL_GSC
401 case SERIAL_IO_GSC:
402 return gsc_readb(info->iomem_base + offset);
403 #endif
404 default:
405 return inb(info->port + offset);
409 static _INLINE_ void serial_out(struct async_struct *info, int offset,
410 int value)
412 switch (info->io_type) {
413 #ifdef CONFIG_HUB6
414 case SERIAL_IO_HUB6:
415 outb(info->hub6 - 1 + offset, info->port);
416 outb(value, info->port+1);
417 break;
418 #endif
419 case SERIAL_IO_MEM:
420 writeb(value, (unsigned long) info->iomem_base +
421 (offset<<info->iomem_reg_shift));
422 break;
423 #ifdef CONFIG_SERIAL_GSC
424 case SERIAL_IO_GSC:
425 gsc_writeb(value, info->iomem_base + offset);
426 break;
427 #endif
428 default:
429 outb(value, info->port+offset);
434 * We used to support using pause I/O for certain machines. We
435 * haven't supported this for a while, but just in case it's badly
436 * needed for certain old 386 machines, I've left these #define's
437 * in....
439 #define serial_inp(info, offset) serial_in(info, offset)
440 #define serial_outp(info, offset, value) serial_out(info, offset, value)
444 * For the 16C950
446 void serial_icr_write(struct async_struct *info, int offset, int value)
448 serial_out(info, UART_SCR, offset);
449 serial_out(info, UART_ICR, value);
452 unsigned int serial_icr_read(struct async_struct *info, int offset)
454 int value;
456 serial_icr_write(info, UART_ACR, info->ACR | UART_ACR_ICRRD);
457 serial_out(info, UART_SCR, offset);
458 value = serial_in(info, UART_ICR);
459 serial_icr_write(info, UART_ACR, info->ACR);
460 return value;
464 * ------------------------------------------------------------
465 * rs_stop() and rs_start()
467 * This routines are called before setting or resetting tty->stopped.
468 * They enable or disable transmitter interrupts, as necessary.
469 * ------------------------------------------------------------
471 static void rs_stop(struct tty_struct *tty)
473 struct async_struct *info = (struct async_struct *)tty->driver_data;
474 unsigned long flags;
476 if (serial_paranoia_check(info, tty->device, "rs_stop"))
477 return;
479 save_flags(flags); cli();
480 if (info->IER & UART_IER_THRI) {
481 info->IER &= ~UART_IER_THRI;
482 serial_out(info, UART_IER, info->IER);
484 if (info->state->type == PORT_16C950) {
485 info->ACR |= UART_ACR_TXDIS;
486 serial_icr_write(info, UART_ACR, info->ACR);
488 restore_flags(flags);
491 static void rs_start(struct tty_struct *tty)
493 struct async_struct *info = (struct async_struct *)tty->driver_data;
494 unsigned long flags;
496 if (serial_paranoia_check(info, tty->device, "rs_start"))
497 return;
499 save_flags(flags); cli();
500 if (info->xmit.head != info->xmit.tail
501 && info->xmit.buf
502 && !(info->IER & UART_IER_THRI)) {
503 info->IER |= UART_IER_THRI;
504 serial_out(info, UART_IER, info->IER);
506 if (info->state->type == PORT_16C950) {
507 info->ACR &= ~UART_ACR_TXDIS;
508 serial_icr_write(info, UART_ACR, info->ACR);
510 restore_flags(flags);
514 * ----------------------------------------------------------------------
516 * Here starts the interrupt handling routines. All of the following
517 * subroutines are declared as inline and are folded into
518 * rs_interrupt(). They were separated out for readability's sake.
520 * Note: rs_interrupt() is a "fast" interrupt, which means that it
521 * runs with interrupts turned off. People who may want to modify
522 * rs_interrupt() should try to keep the interrupt handler as fast as
523 * possible. After you are done making modifications, it is not a bad
524 * idea to do:
526 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
528 * and look at the resulting assemble code in serial.s.
530 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
531 * -----------------------------------------------------------------------
535 * This routine is used by the interrupt handler to schedule
536 * processing in the software interrupt portion of the driver.
538 static _INLINE_ void rs_sched_event(struct async_struct *info,
539 int event)
541 info->event |= 1 << event;
542 queue_task(&info->tqueue, &tq_serial);
543 mark_bh(SERIAL_BH);
546 static _INLINE_ void receive_chars(struct async_struct *info,
547 int *status, struct pt_regs * regs)
549 struct tty_struct *tty = info->tty;
550 unsigned char ch;
551 int ignored = 0;
552 struct async_icount *icount;
554 icount = &info->state->icount;
555 do {
556 ch = serial_inp(info, UART_RX);
557 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
558 goto ignore_char;
559 *tty->flip.char_buf_ptr = ch;
560 icount->rx++;
562 #ifdef SERIAL_DEBUG_INTR
563 printk("DR%02x:%02x...", ch, *status);
564 #endif
565 *tty->flip.flag_buf_ptr = 0;
566 if (*status & (UART_LSR_BI | UART_LSR_PE |
567 UART_LSR_FE | UART_LSR_OE)) {
569 * For statistics only
571 if (*status & UART_LSR_BI) {
572 *status &= ~(UART_LSR_FE | UART_LSR_PE);
573 icount->brk++;
574 } else if (*status & UART_LSR_PE)
575 icount->parity++;
576 else if (*status & UART_LSR_FE)
577 icount->frame++;
578 if (*status & UART_LSR_OE)
579 icount->overrun++;
582 * Now check to see if character should be
583 * ignored, and mask off conditions which
584 * should be ignored.
586 if (*status & info->ignore_status_mask) {
587 if (++ignored > 100)
588 break;
589 goto ignore_char;
591 *status &= info->read_status_mask;
593 if (*status & (UART_LSR_BI)) {
594 #ifdef SERIAL_DEBUG_INTR
595 printk("handling break....");
596 #endif
597 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && !defined(MODULE)
598 if (info->line == sercons.index) {
599 if (!break_pressed) {
600 break_pressed = jiffies;
601 goto ignore_char;
603 break_pressed = 0;
605 #endif
606 *tty->flip.flag_buf_ptr = TTY_BREAK;
607 if (info->flags & ASYNC_SAK)
608 do_SAK(tty);
609 } else if (*status & UART_LSR_PE)
610 *tty->flip.flag_buf_ptr = TTY_PARITY;
611 else if (*status & UART_LSR_FE)
612 *tty->flip.flag_buf_ptr = TTY_FRAME;
613 if (*status & UART_LSR_OE) {
615 * Overrun is special, since it's
616 * reported immediately, and doesn't
617 * affect the current character
619 tty->flip.count++;
620 tty->flip.flag_buf_ptr++;
621 tty->flip.char_buf_ptr++;
622 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
623 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
624 goto ignore_char;
627 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && !defined(MODULE)
628 if (break_pressed && info->line == sercons.index) {
629 if (ch != 0 &&
630 time_before(jiffies, break_pressed + HZ*5)) {
631 handle_sysrq(ch, regs, NULL, NULL);
632 break_pressed = 0;
633 goto ignore_char;
635 break_pressed = 0;
637 #endif
638 tty->flip.flag_buf_ptr++;
639 tty->flip.char_buf_ptr++;
640 tty->flip.count++;
641 ignore_char:
642 *status = serial_inp(info, UART_LSR);
643 } while (*status & UART_LSR_DR);
644 #if (LINUX_VERSION_CODE > 131394) /* 2.1.66 */
645 tty_flip_buffer_push(tty);
646 #else
647 queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
648 #endif
651 static _INLINE_ void transmit_chars(struct async_struct *info, int *intr_done)
653 int count;
655 if (info->x_char) {
656 serial_outp(info, UART_TX, info->x_char);
657 info->state->icount.tx++;
658 info->x_char = 0;
659 if (intr_done)
660 *intr_done = 0;
661 return;
663 if (info->xmit.head == info->xmit.tail
664 || info->tty->stopped
665 || info->tty->hw_stopped) {
666 info->IER &= ~UART_IER_THRI;
667 serial_out(info, UART_IER, info->IER);
668 return;
671 count = info->xmit_fifo_size;
672 do {
673 serial_out(info, UART_TX, info->xmit.buf[info->xmit.tail]);
674 info->xmit.tail = (info->xmit.tail + 1) & (SERIAL_XMIT_SIZE-1);
675 info->state->icount.tx++;
676 if (info->xmit.head == info->xmit.tail)
677 break;
678 } while (--count > 0);
680 if (CIRC_CNT(info->xmit.head,
681 info->xmit.tail,
682 SERIAL_XMIT_SIZE) < WAKEUP_CHARS)
683 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
685 #ifdef SERIAL_DEBUG_INTR
686 printk("THRE...");
687 #endif
688 if (intr_done)
689 *intr_done = 0;
691 if (info->xmit.head == info->xmit.tail) {
692 info->IER &= ~UART_IER_THRI;
693 serial_out(info, UART_IER, info->IER);
697 static _INLINE_ void check_modem_status(struct async_struct *info)
699 int status;
700 struct async_icount *icount;
702 status = serial_in(info, UART_MSR);
704 if (status & UART_MSR_ANY_DELTA) {
705 icount = &info->state->icount;
706 /* update input line counters */
707 if (status & UART_MSR_TERI)
708 icount->rng++;
709 if (status & UART_MSR_DDSR)
710 icount->dsr++;
711 if (status & UART_MSR_DDCD) {
712 icount->dcd++;
713 #ifdef CONFIG_HARD_PPS
714 if ((info->flags & ASYNC_HARDPPS_CD) &&
715 (status & UART_MSR_DCD))
716 hardpps();
717 #endif
719 if (status & UART_MSR_DCTS)
720 icount->cts++;
721 wake_up_interruptible(&info->delta_msr_wait);
724 if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
725 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
726 printk("ttys%d CD now %s...", info->line,
727 (status & UART_MSR_DCD) ? "on" : "off");
728 #endif
729 if (status & UART_MSR_DCD)
730 wake_up_interruptible(&info->open_wait);
731 else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
732 (info->flags & ASYNC_CALLOUT_NOHUP))) {
733 #ifdef SERIAL_DEBUG_OPEN
734 printk("doing serial hangup...");
735 #endif
736 if (info->tty)
737 tty_hangup(info->tty);
740 if (info->flags & ASYNC_CTS_FLOW) {
741 if (info->tty->hw_stopped) {
742 if (status & UART_MSR_CTS) {
743 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
744 printk("CTS tx start...");
745 #endif
746 info->tty->hw_stopped = 0;
747 info->IER |= UART_IER_THRI;
748 serial_out(info, UART_IER, info->IER);
749 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
750 return;
752 } else {
753 if (!(status & UART_MSR_CTS)) {
754 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
755 printk("CTS tx stop...");
756 #endif
757 info->tty->hw_stopped = 1;
758 info->IER &= ~UART_IER_THRI;
759 serial_out(info, UART_IER, info->IER);
765 #ifdef CONFIG_SERIAL_SHARE_IRQ
767 * This is the serial driver's generic interrupt routine
769 static void rs_interrupt(int irq, void *dev_id, struct pt_regs * regs)
771 int status;
772 struct async_struct * info;
773 int pass_counter = 0;
774 struct async_struct *end_mark = 0;
775 #ifdef CONFIG_SERIAL_MULTIPORT
776 int first_multi = 0;
777 struct rs_multiport_struct *multi;
778 #endif
780 #ifdef SERIAL_DEBUG_INTR
781 printk("rs_interrupt(%d)...", irq);
782 #endif
784 info = IRQ_ports[irq];
785 if (!info)
786 return;
788 #ifdef CONFIG_SERIAL_MULTIPORT
789 multi = &rs_multiport[irq];
790 if (multi->port_monitor)
791 first_multi = inb(multi->port_monitor);
792 #endif
794 do {
795 if (!info->tty ||
796 (serial_in(info, UART_IIR) & UART_IIR_NO_INT)) {
797 if (!end_mark)
798 end_mark = info;
799 goto next;
801 end_mark = 0;
803 info->last_active = jiffies;
805 status = serial_inp(info, UART_LSR);
806 #ifdef SERIAL_DEBUG_INTR
807 printk("status = %x...", status);
808 #endif
809 if (status & UART_LSR_DR)
810 receive_chars(info, &status, regs);
811 check_modem_status(info);
812 if (status & UART_LSR_THRE)
813 transmit_chars(info, 0);
815 next:
816 info = info->next_port;
817 if (!info) {
818 info = IRQ_ports[irq];
819 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
820 #if 0
821 printk("rs loop break\n");
822 #endif
823 break; /* Prevent infinite loops */
825 continue;
827 } while (end_mark != info);
828 #ifdef CONFIG_SERIAL_MULTIPORT
829 if (multi->port_monitor)
830 printk("rs port monitor (normal) irq %d: 0x%x, 0x%x\n",
831 info->state->irq, first_multi,
832 inb(multi->port_monitor));
833 #endif
834 #ifdef SERIAL_DEBUG_INTR
835 printk("end.\n");
836 #endif
838 #endif /* #ifdef CONFIG_SERIAL_SHARE_IRQ */
842 * This is the serial driver's interrupt routine for a single port
844 static void rs_interrupt_single(int irq, void *dev_id, struct pt_regs * regs)
846 int status;
847 int pass_counter = 0;
848 struct async_struct * info;
849 #ifdef CONFIG_SERIAL_MULTIPORT
850 int first_multi = 0;
851 struct rs_multiport_struct *multi;
852 #endif
854 #ifdef SERIAL_DEBUG_INTR
855 printk("rs_interrupt_single(%d)...", irq);
856 #endif
858 info = IRQ_ports[irq];
859 if (!info || !info->tty)
860 return;
862 #ifdef CONFIG_SERIAL_MULTIPORT
863 multi = &rs_multiport[irq];
864 if (multi->port_monitor)
865 first_multi = inb(multi->port_monitor);
866 #endif
868 do {
869 status = serial_inp(info, UART_LSR);
870 #ifdef SERIAL_DEBUG_INTR
871 printk("status = %x...", status);
872 #endif
873 if (status & UART_LSR_DR)
874 receive_chars(info, &status, regs);
875 check_modem_status(info);
876 if (status & UART_LSR_THRE)
877 transmit_chars(info, 0);
878 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
879 #if 0
880 printk("rs_single loop break.\n");
881 #endif
882 break;
884 } while (!(serial_in(info, UART_IIR) & UART_IIR_NO_INT));
885 info->last_active = jiffies;
886 #ifdef CONFIG_SERIAL_MULTIPORT
887 if (multi->port_monitor)
888 printk("rs port monitor (single) irq %d: 0x%x, 0x%x\n",
889 info->state->irq, first_multi,
890 inb(multi->port_monitor));
891 #endif
892 #ifdef SERIAL_DEBUG_INTR
893 printk("end.\n");
894 #endif
897 #ifdef CONFIG_SERIAL_MULTIPORT
899 * This is the serial driver's for multiport boards
901 static void rs_interrupt_multi(int irq, void *dev_id, struct pt_regs * regs)
903 int status;
904 struct async_struct * info;
905 int pass_counter = 0;
906 int first_multi= 0;
907 struct rs_multiport_struct *multi;
909 #ifdef SERIAL_DEBUG_INTR
910 printk("rs_interrupt_multi(%d)...", irq);
911 #endif
913 info = IRQ_ports[irq];
914 if (!info)
915 return;
916 multi = &rs_multiport[irq];
917 if (!multi->port1) {
918 /* Should never happen */
919 printk("rs_interrupt_multi: NULL port1!\n");
920 return;
922 if (multi->port_monitor)
923 first_multi = inb(multi->port_monitor);
925 while (1) {
926 if (!info->tty ||
927 (serial_in(info, UART_IIR) & UART_IIR_NO_INT))
928 goto next;
930 info->last_active = jiffies;
932 status = serial_inp(info, UART_LSR);
933 #ifdef SERIAL_DEBUG_INTR
934 printk("status = %x...", status);
935 #endif
936 if (status & UART_LSR_DR)
937 receive_chars(info, &status, regs);
938 check_modem_status(info);
939 if (status & UART_LSR_THRE)
940 transmit_chars(info, 0);
942 next:
943 info = info->next_port;
944 if (info)
945 continue;
947 info = IRQ_ports[irq];
949 * The user was a bonehead, and misconfigured their
950 * multiport info. Rather than lock up the kernel
951 * in an infinite loop, if we loop too many times,
952 * print a message and break out of the loop.
954 if (pass_counter++ > RS_ISR_PASS_LIMIT) {
955 printk("Misconfigured multiport serial info "
956 "for irq %d. Breaking out irq loop\n", irq);
957 break;
959 if (multi->port_monitor)
960 printk("rs port monitor irq %d: 0x%x, 0x%x\n",
961 info->state->irq, first_multi,
962 inb(multi->port_monitor));
963 if ((inb(multi->port1) & multi->mask1) != multi->match1)
964 continue;
965 if (!multi->port2)
966 break;
967 if ((inb(multi->port2) & multi->mask2) != multi->match2)
968 continue;
969 if (!multi->port3)
970 break;
971 if ((inb(multi->port3) & multi->mask3) != multi->match3)
972 continue;
973 if (!multi->port4)
974 break;
975 if ((inb(multi->port4) & multi->mask4) != multi->match4)
976 continue;
977 break;
979 #ifdef SERIAL_DEBUG_INTR
980 printk("end.\n");
981 #endif
983 #endif
986 * -------------------------------------------------------------------
987 * Here ends the serial interrupt routines.
988 * -------------------------------------------------------------------
992 * This routine is used to handle the "bottom half" processing for the
993 * serial driver, known also the "software interrupt" processing.
994 * This processing is done at the kernel interrupt level, after the
995 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
996 * is where time-consuming activities which can not be done in the
997 * interrupt driver proper are done; the interrupt driver schedules
998 * them using rs_sched_event(), and they get done here.
1000 static void do_serial_bh(void)
1002 run_task_queue(&tq_serial);
1005 static void do_softint(void *private_)
1007 struct async_struct *info = (struct async_struct *) private_;
1008 struct tty_struct *tty;
1010 tty = info->tty;
1011 if (!tty)
1012 return;
1014 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
1015 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1016 tty->ldisc.write_wakeup)
1017 (tty->ldisc.write_wakeup)(tty);
1018 wake_up_interruptible(&tty->write_wait);
1019 #ifdef SERIAL_HAVE_POLL_WAIT
1020 wake_up_interruptible(&tty->poll_wait);
1021 #endif
1026 * This subroutine is called when the RS_TIMER goes off. It is used
1027 * by the serial driver to handle ports that do not have an interrupt
1028 * (irq=0). This doesn't work very well for 16450's, but gives barely
1029 * passable results for a 16550A. (Although at the expense of much
1030 * CPU overhead).
1032 static void rs_timer(unsigned long dummy)
1034 static unsigned long last_strobe = 0;
1035 struct async_struct *info;
1036 unsigned int i;
1037 unsigned long flags;
1039 if ((jiffies - last_strobe) >= RS_STROBE_TIME) {
1040 for (i=0; i < NR_IRQS; i++) {
1041 info = IRQ_ports[i];
1042 if (!info)
1043 continue;
1044 save_flags(flags); cli();
1045 #ifdef CONFIG_SERIAL_SHARE_IRQ
1046 if (info->next_port) {
1047 do {
1048 serial_out(info, UART_IER, 0);
1049 info->IER |= UART_IER_THRI;
1050 serial_out(info, UART_IER, info->IER);
1051 info = info->next_port;
1052 } while (info);
1053 #ifdef CONFIG_SERIAL_MULTIPORT
1054 if (rs_multiport[i].port1)
1055 rs_interrupt_multi(i, NULL, NULL);
1056 else
1057 #endif
1058 rs_interrupt(i, NULL, NULL);
1059 } else
1060 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1061 rs_interrupt_single(i, NULL, NULL);
1062 restore_flags(flags);
1065 last_strobe = jiffies;
1066 mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
1068 if (IRQ_ports[0]) {
1069 save_flags(flags); cli();
1070 #ifdef CONFIG_SERIAL_SHARE_IRQ
1071 rs_interrupt(0, NULL, NULL);
1072 #else
1073 rs_interrupt_single(0, NULL, NULL);
1074 #endif
1075 restore_flags(flags);
1077 mod_timer(&serial_timer, jiffies + IRQ_timeout[0] - 2);
1082 * ---------------------------------------------------------------
1083 * Low level utility subroutines for the serial driver: routines to
1084 * figure out the appropriate timeout for an interrupt chain, routines
1085 * to initialize and startup a serial port, and routines to shutdown a
1086 * serial port. Useful stuff like that.
1087 * ---------------------------------------------------------------
1091 * This routine figures out the correct timeout for a particular IRQ.
1092 * It uses the smallest timeout of all of the serial ports in a
1093 * particular interrupt chain. Now only used for IRQ 0....
1095 static void figure_IRQ_timeout(int irq)
1097 struct async_struct *info;
1098 int timeout = 60*HZ; /* 60 seconds === a long time :-) */
1100 info = IRQ_ports[irq];
1101 if (!info) {
1102 IRQ_timeout[irq] = 60*HZ;
1103 return;
1105 while (info) {
1106 if (info->timeout < timeout)
1107 timeout = info->timeout;
1108 info = info->next_port;
1110 if (!irq)
1111 timeout = timeout / 2;
1112 IRQ_timeout[irq] = timeout ? timeout : 1;
1115 #ifdef CONFIG_SERIAL_RSA
1116 /* Attempts to turn on the RSA FIFO. Returns zero on failure */
1117 static int enable_rsa(struct async_struct *info)
1119 unsigned char mode;
1120 int result;
1121 unsigned long flags;
1123 save_flags(flags); cli();
1124 mode = serial_inp(info, UART_RSA_MSR);
1125 result = mode & UART_RSA_MSR_FIFO;
1127 if (!result) {
1128 serial_outp(info, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
1129 mode = serial_inp(info, UART_RSA_MSR);
1130 result = mode & UART_RSA_MSR_FIFO;
1133 restore_flags(flags);
1134 return result;
1137 /* Attempts to turn off the RSA FIFO. Returns zero on failure */
1138 static int disable_rsa(struct async_struct *info)
1140 unsigned char mode;
1141 int result;
1142 unsigned long flags;
1144 save_flags(flags); cli();
1145 mode = serial_inp(info, UART_RSA_MSR);
1146 result = !(mode & UART_RSA_MSR_FIFO);
1148 if (!result) {
1149 serial_outp(info, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
1150 mode = serial_inp(info, UART_RSA_MSR);
1151 result = !(mode & UART_RSA_MSR_FIFO);
1154 restore_flags(flags);
1155 return result;
1157 #endif /* CONFIG_SERIAL_RSA */
1159 static int startup(struct async_struct * info)
1161 unsigned long flags;
1162 int retval=0;
1163 void (*handler)(int, void *, struct pt_regs *);
1164 struct serial_state *state= info->state;
1165 unsigned long page;
1166 #ifdef CONFIG_SERIAL_MANY_PORTS
1167 unsigned short ICP;
1168 #endif
1170 page = get_zeroed_page(GFP_KERNEL);
1171 if (!page)
1172 return -ENOMEM;
1174 save_flags(flags); cli();
1176 if (info->flags & ASYNC_INITIALIZED) {
1177 free_page(page);
1178 goto errout;
1181 if (!CONFIGURED_SERIAL_PORT(state) || !state->type) {
1182 if (info->tty)
1183 set_bit(TTY_IO_ERROR, &info->tty->flags);
1184 free_page(page);
1185 goto errout;
1187 if (info->xmit.buf)
1188 free_page(page);
1189 else
1190 info->xmit.buf = (unsigned char *) page;
1192 #ifdef SERIAL_DEBUG_OPEN
1193 printk("starting up ttys%d (irq %d)...", info->line, state->irq);
1194 #endif
1196 if (uart_config[state->type].flags & UART_STARTECH) {
1197 /* Wake up UART */
1198 serial_outp(info, UART_LCR, 0xBF);
1199 serial_outp(info, UART_EFR, UART_EFR_ECB);
1201 * Turn off LCR == 0xBF so we actually set the IER
1202 * register on the XR16C850
1204 serial_outp(info, UART_LCR, 0);
1205 serial_outp(info, UART_IER, 0);
1207 * Now reset LCR so we can turn off the ECB bit
1209 serial_outp(info, UART_LCR, 0xBF);
1210 serial_outp(info, UART_EFR, 0);
1212 * For a XR16C850, we need to set the trigger levels
1214 if (state->type == PORT_16850) {
1215 serial_outp(info, UART_FCTR, UART_FCTR_TRGD |
1216 UART_FCTR_RX);
1217 serial_outp(info, UART_TRG, UART_TRG_96);
1218 serial_outp(info, UART_FCTR, UART_FCTR_TRGD |
1219 UART_FCTR_TX);
1220 serial_outp(info, UART_TRG, UART_TRG_96);
1222 serial_outp(info, UART_LCR, 0);
1225 if (state->type == PORT_16750) {
1226 /* Wake up UART */
1227 serial_outp(info, UART_IER, 0);
1230 if (state->type == PORT_16C950) {
1231 /* Wake up and initialize UART */
1232 info->ACR = 0;
1233 serial_outp(info, UART_LCR, 0xBF);
1234 serial_outp(info, UART_EFR, UART_EFR_ECB);
1235 serial_outp(info, UART_IER, 0);
1236 serial_outp(info, UART_LCR, 0);
1237 serial_icr_write(info, UART_CSR, 0); /* Reset the UART */
1238 serial_outp(info, UART_LCR, 0xBF);
1239 serial_outp(info, UART_EFR, UART_EFR_ECB);
1240 serial_outp(info, UART_LCR, 0);
1243 #ifdef CONFIG_SERIAL_RSA
1245 * If this is an RSA port, see if we can kick it up to the
1246 * higher speed clock.
1248 if (state->type == PORT_RSA) {
1249 if (state->baud_base != SERIAL_RSA_BAUD_BASE &&
1250 enable_rsa(info))
1251 state->baud_base = SERIAL_RSA_BAUD_BASE;
1252 if (state->baud_base == SERIAL_RSA_BAUD_BASE)
1253 serial_outp(info, UART_RSA_FRR, 0);
1255 #endif
1258 * Clear the FIFO buffers and disable them
1259 * (they will be reenabled in change_speed())
1261 if (uart_config[state->type].flags & UART_CLEAR_FIFO) {
1262 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
1263 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
1264 UART_FCR_CLEAR_RCVR |
1265 UART_FCR_CLEAR_XMIT));
1266 serial_outp(info, UART_FCR, 0);
1270 * Clear the interrupt registers.
1272 (void) serial_inp(info, UART_LSR);
1273 (void) serial_inp(info, UART_RX);
1274 (void) serial_inp(info, UART_IIR);
1275 (void) serial_inp(info, UART_MSR);
1278 * At this point there's no way the LSR could still be 0xFF;
1279 * if it is, then bail out, because there's likely no UART
1280 * here.
1282 if (!(info->flags & ASYNC_BUGGY_UART) &&
1283 (serial_inp(info, UART_LSR) == 0xff)) {
1284 printk("LSR safety check engaged!\n");
1285 if (capable(CAP_SYS_ADMIN)) {
1286 if (info->tty)
1287 set_bit(TTY_IO_ERROR, &info->tty->flags);
1288 } else
1289 retval = -ENODEV;
1290 goto errout;
1294 * Allocate the IRQ if necessary
1296 if (state->irq && (!IRQ_ports[state->irq] ||
1297 !IRQ_ports[state->irq]->next_port)) {
1298 if (IRQ_ports[state->irq]) {
1299 #ifdef CONFIG_SERIAL_SHARE_IRQ
1300 free_irq(state->irq, &IRQ_ports[state->irq]);
1301 #ifdef CONFIG_SERIAL_MULTIPORT
1302 if (rs_multiport[state->irq].port1)
1303 handler = rs_interrupt_multi;
1304 else
1305 #endif
1306 handler = rs_interrupt;
1307 #else
1308 retval = -EBUSY;
1309 goto errout;
1310 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1311 } else
1312 handler = rs_interrupt_single;
1314 retval = request_irq(state->irq, handler, SA_SHIRQ,
1315 "serial", &IRQ_ports[state->irq]);
1316 if (retval) {
1317 if (capable(CAP_SYS_ADMIN)) {
1318 if (info->tty)
1319 set_bit(TTY_IO_ERROR,
1320 &info->tty->flags);
1321 retval = 0;
1323 goto errout;
1328 * Insert serial port into IRQ chain.
1330 info->prev_port = 0;
1331 info->next_port = IRQ_ports[state->irq];
1332 if (info->next_port)
1333 info->next_port->prev_port = info;
1334 IRQ_ports[state->irq] = info;
1335 figure_IRQ_timeout(state->irq);
1338 * Now, initialize the UART
1340 serial_outp(info, UART_LCR, UART_LCR_WLEN8); /* reset DLAB */
1342 info->MCR = 0;
1343 if (info->tty->termios->c_cflag & CBAUD)
1344 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
1345 #ifdef CONFIG_SERIAL_MANY_PORTS
1346 if (info->flags & ASYNC_FOURPORT) {
1347 if (state->irq == 0)
1348 info->MCR |= UART_MCR_OUT1;
1349 } else
1350 #endif
1352 if (state->irq != 0)
1353 info->MCR |= UART_MCR_OUT2;
1355 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
1356 serial_outp(info, UART_MCR, info->MCR);
1359 * Finally, enable interrupts
1361 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
1362 serial_outp(info, UART_IER, info->IER); /* enable interrupts */
1364 #ifdef CONFIG_SERIAL_MANY_PORTS
1365 if (info->flags & ASYNC_FOURPORT) {
1366 /* Enable interrupts on the AST Fourport board */
1367 ICP = (info->port & 0xFE0) | 0x01F;
1368 outb_p(0x80, ICP);
1369 (void) inb_p(ICP);
1371 #endif
1374 * And clear the interrupt registers again for luck.
1376 (void)serial_inp(info, UART_LSR);
1377 (void)serial_inp(info, UART_RX);
1378 (void)serial_inp(info, UART_IIR);
1379 (void)serial_inp(info, UART_MSR);
1381 if (info->tty)
1382 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1383 info->xmit.head = info->xmit.tail = 0;
1386 * Set up serial timers...
1388 mod_timer(&serial_timer, jiffies + 2*HZ/100);
1391 * Set up the tty->alt_speed kludge
1393 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
1394 if (info->tty) {
1395 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1396 info->tty->alt_speed = 57600;
1397 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1398 info->tty->alt_speed = 115200;
1399 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
1400 info->tty->alt_speed = 230400;
1401 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
1402 info->tty->alt_speed = 460800;
1404 #endif
1407 * and set the speed of the serial port
1409 change_speed(info, 0);
1411 info->flags |= ASYNC_INITIALIZED;
1412 restore_flags(flags);
1413 return 0;
1415 errout:
1416 restore_flags(flags);
1417 return retval;
1421 * This routine will shutdown a serial port; interrupts are disabled, and
1422 * DTR is dropped if the hangup on close termio flag is on.
1424 static void shutdown(struct async_struct * info)
1426 unsigned long flags;
1427 struct serial_state *state;
1428 int retval;
1430 if (!(info->flags & ASYNC_INITIALIZED))
1431 return;
1433 state = info->state;
1435 #ifdef SERIAL_DEBUG_OPEN
1436 printk("Shutting down serial port %d (irq %d)....", info->line,
1437 state->irq);
1438 #endif
1440 save_flags(flags); cli(); /* Disable interrupts */
1443 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1444 * here so the queue might never be waken up
1446 wake_up_interruptible(&info->delta_msr_wait);
1449 * First unlink the serial port from the IRQ chain...
1451 if (info->next_port)
1452 info->next_port->prev_port = info->prev_port;
1453 if (info->prev_port)
1454 info->prev_port->next_port = info->next_port;
1455 else
1456 IRQ_ports[state->irq] = info->next_port;
1457 figure_IRQ_timeout(state->irq);
1460 * Free the IRQ, if necessary
1462 if (state->irq && (!IRQ_ports[state->irq] ||
1463 !IRQ_ports[state->irq]->next_port)) {
1464 if (IRQ_ports[state->irq]) {
1465 free_irq(state->irq, &IRQ_ports[state->irq]);
1466 retval = request_irq(state->irq, rs_interrupt_single,
1467 SA_SHIRQ, "serial",
1468 &IRQ_ports[state->irq]);
1470 if (retval)
1471 printk("serial shutdown: request_irq: error %d"
1472 " Couldn't reacquire IRQ.\n", retval);
1473 } else
1474 free_irq(state->irq, &IRQ_ports[state->irq]);
1477 if (info->xmit.buf) {
1478 unsigned long pg = (unsigned long) info->xmit.buf;
1479 info->xmit.buf = 0;
1480 free_page(pg);
1483 info->IER = 0;
1484 serial_outp(info, UART_IER, 0x00); /* disable all intrs */
1485 #ifdef CONFIG_SERIAL_MANY_PORTS
1486 if (info->flags & ASYNC_FOURPORT) {
1487 /* reset interrupts on the AST Fourport board */
1488 (void) inb((info->port & 0xFE0) | 0x01F);
1489 info->MCR |= UART_MCR_OUT1;
1490 } else
1491 #endif
1492 info->MCR &= ~UART_MCR_OUT2;
1493 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
1495 /* disable break condition */
1496 serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
1498 if (!info->tty || (info->tty->termios->c_cflag & HUPCL))
1499 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1500 serial_outp(info, UART_MCR, info->MCR);
1502 /* disable FIFO's */
1503 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
1504 UART_FCR_CLEAR_RCVR |
1505 UART_FCR_CLEAR_XMIT));
1506 serial_outp(info, UART_FCR, 0);
1508 #ifdef CONFIG_SERIAL_RSA
1510 * Reset the RSA board back to 115kbps compat mode.
1512 if ((state->type == PORT_RSA) &&
1513 (state->baud_base == SERIAL_RSA_BAUD_BASE &&
1514 disable_rsa(info)))
1515 state->baud_base = SERIAL_RSA_BAUD_BASE_LO;
1516 #endif
1519 (void)serial_in(info, UART_RX); /* read data port to reset things */
1521 if (info->tty)
1522 set_bit(TTY_IO_ERROR, &info->tty->flags);
1524 if (uart_config[info->state->type].flags & UART_STARTECH) {
1525 /* Arrange to enter sleep mode */
1526 serial_outp(info, UART_LCR, 0xBF);
1527 serial_outp(info, UART_EFR, UART_EFR_ECB);
1528 serial_outp(info, UART_IER, UART_IERX_SLEEP);
1529 serial_outp(info, UART_LCR, 0);
1531 if (info->state->type == PORT_16750) {
1532 /* Arrange to enter sleep mode */
1533 serial_outp(info, UART_IER, UART_IERX_SLEEP);
1535 info->flags &= ~ASYNC_INITIALIZED;
1536 restore_flags(flags);
1539 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
1540 static int baud_table[] = {
1541 0, 50, 75, 110, 134, 150, 200, 300,
1542 600, 1200, 1800, 2400, 4800, 9600, 19200,
1543 38400, 57600, 115200, 230400, 460800, 0 };
1545 static int tty_get_baud_rate(struct tty_struct *tty)
1547 struct async_struct * info = (struct async_struct *)tty->driver_data;
1548 unsigned int cflag, i;
1550 cflag = tty->termios->c_cflag;
1552 i = cflag & CBAUD;
1553 if (i & CBAUDEX) {
1554 i &= ~CBAUDEX;
1555 if (i < 1 || i > 2)
1556 tty->termios->c_cflag &= ~CBAUDEX;
1557 else
1558 i += 15;
1560 if (i == 15) {
1561 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1562 i += 1;
1563 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1564 i += 2;
1566 return baud_table[i];
1568 #endif
1571 * This routine is called to set the UART divisor registers to match
1572 * the specified baud rate for a serial port.
1574 static void change_speed(struct async_struct *info,
1575 struct termios *old_termios)
1577 int quot = 0, baud_base, baud;
1578 unsigned cflag, cval, fcr = 0;
1579 int bits;
1580 unsigned long flags;
1582 if (!info->tty || !info->tty->termios)
1583 return;
1584 cflag = info->tty->termios->c_cflag;
1585 if (!CONFIGURED_SERIAL_PORT(info))
1586 return;
1588 /* byte size and parity */
1589 switch (cflag & CSIZE) {
1590 case CS5: cval = 0x00; bits = 7; break;
1591 case CS6: cval = 0x01; bits = 8; break;
1592 case CS7: cval = 0x02; bits = 9; break;
1593 case CS8: cval = 0x03; bits = 10; break;
1594 /* Never happens, but GCC is too dumb to figure it out */
1595 default: cval = 0x00; bits = 7; break;
1597 if (cflag & CSTOPB) {
1598 cval |= 0x04;
1599 bits++;
1601 if (cflag & PARENB) {
1602 cval |= UART_LCR_PARITY;
1603 bits++;
1605 if (!(cflag & PARODD))
1606 cval |= UART_LCR_EPAR;
1607 #ifdef CMSPAR
1608 if (cflag & CMSPAR)
1609 cval |= UART_LCR_SPAR;
1610 #endif
1612 /* Determine divisor based on baud rate */
1613 baud = tty_get_baud_rate(info->tty);
1614 if (!baud)
1615 baud = 9600; /* B0 transition handled in rs_set_termios */
1616 #ifdef CONFIG_SERIAL_RSA
1617 if ((info->state->type == PORT_RSA) &&
1618 (info->state->baud_base != SERIAL_RSA_BAUD_BASE) &&
1619 enable_rsa(info))
1620 info->state->baud_base = SERIAL_RSA_BAUD_BASE;
1621 #endif
1622 baud_base = info->state->baud_base;
1623 if (info->state->type == PORT_16C950) {
1624 if (baud <= baud_base)
1625 serial_icr_write(info, UART_TCR, 0);
1626 else if (baud <= 2*baud_base) {
1627 serial_icr_write(info, UART_TCR, 0x8);
1628 baud_base = baud_base * 2;
1629 } else if (baud <= 4*baud_base) {
1630 serial_icr_write(info, UART_TCR, 0x4);
1631 baud_base = baud_base * 4;
1632 } else
1633 serial_icr_write(info, UART_TCR, 0);
1635 if (baud == 38400 &&
1636 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1637 quot = info->state->custom_divisor;
1638 else {
1639 if (baud == 134)
1640 /* Special case since 134 is really 134.5 */
1641 quot = (2*baud_base / 269);
1642 else if (baud)
1643 quot = baud_base / baud;
1645 /* If the quotient is zero refuse the change */
1646 if (!quot && old_termios) {
1647 info->tty->termios->c_cflag &= ~CBAUD;
1648 info->tty->termios->c_cflag |= (old_termios->c_cflag & CBAUD);
1649 baud = tty_get_baud_rate(info->tty);
1650 if (!baud)
1651 baud = 9600;
1652 if (baud == 38400 &&
1653 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST))
1654 quot = info->state->custom_divisor;
1655 else {
1656 if (baud == 134)
1657 /* Special case since 134 is really 134.5 */
1658 quot = (2*baud_base / 269);
1659 else if (baud)
1660 quot = baud_base / baud;
1663 /* As a last resort, if the quotient is zero, default to 9600 bps */
1664 if (!quot)
1665 quot = baud_base / 9600;
1667 * Work around a bug in the Oxford Semiconductor 952 rev B
1668 * chip which causes it to seriously miscalculate baud rates
1669 * when DLL is 0.
1671 if (((quot & 0xFF) == 0) && (info->state->type == PORT_16C950) &&
1672 (info->state->revision == 0x5201))
1673 quot++;
1675 info->quot = quot;
1676 info->timeout = ((info->xmit_fifo_size*HZ*bits*quot) / baud_base);
1677 info->timeout += HZ/50; /* Add .02 seconds of slop */
1679 /* Set up FIFO's */
1680 if (uart_config[info->state->type].flags & UART_USE_FIFO) {
1681 if ((info->state->baud_base / quot) < 2400)
1682 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1683 #ifdef CONFIG_SERIAL_RSA
1684 else if (info->state->type == PORT_RSA)
1685 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;
1686 #endif
1687 else
1688 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
1690 if (info->state->type == PORT_16750)
1691 fcr |= UART_FCR7_64BYTE;
1693 /* CTS flow control flag and modem status interrupts */
1694 info->IER &= ~UART_IER_MSI;
1695 if (info->flags & ASYNC_HARDPPS_CD)
1696 info->IER |= UART_IER_MSI;
1697 if (cflag & CRTSCTS) {
1698 info->flags |= ASYNC_CTS_FLOW;
1699 info->IER |= UART_IER_MSI;
1700 } else
1701 info->flags &= ~ASYNC_CTS_FLOW;
1702 if (cflag & CLOCAL)
1703 info->flags &= ~ASYNC_CHECK_CD;
1704 else {
1705 info->flags |= ASYNC_CHECK_CD;
1706 info->IER |= UART_IER_MSI;
1708 serial_out(info, UART_IER, info->IER);
1711 * Set up parity check flag
1713 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1715 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
1716 if (I_INPCK(info->tty))
1717 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1718 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1719 info->read_status_mask |= UART_LSR_BI;
1722 * Characters to ignore
1724 info->ignore_status_mask = 0;
1725 if (I_IGNPAR(info->tty))
1726 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1727 if (I_IGNBRK(info->tty)) {
1728 info->ignore_status_mask |= UART_LSR_BI;
1730 * If we're ignore parity and break indicators, ignore
1731 * overruns too. (For real raw support).
1733 if (I_IGNPAR(info->tty))
1734 info->ignore_status_mask |= UART_LSR_OE;
1737 * !!! ignore all characters if CREAD is not set
1739 if ((cflag & CREAD) == 0)
1740 info->ignore_status_mask |= UART_LSR_DR;
1741 save_flags(flags); cli();
1742 if (uart_config[info->state->type].flags & UART_STARTECH) {
1743 serial_outp(info, UART_LCR, 0xBF);
1744 serial_outp(info, UART_EFR,
1745 (cflag & CRTSCTS) ? UART_EFR_CTS : 0);
1747 serial_outp(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
1748 serial_outp(info, UART_DLL, quot & 0xff); /* LS of divisor */
1749 serial_outp(info, UART_DLM, quot >> 8); /* MS of divisor */
1750 if (info->state->type == PORT_16750)
1751 serial_outp(info, UART_FCR, fcr); /* set fcr */
1752 serial_outp(info, UART_LCR, cval); /* reset DLAB */
1753 info->LCR = cval; /* Save LCR */
1754 if (info->state->type != PORT_16750) {
1755 if (fcr & UART_FCR_ENABLE_FIFO) {
1756 /* emulated UARTs (Lucent Venus 167x) need two steps */
1757 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
1759 serial_outp(info, UART_FCR, fcr); /* set fcr */
1761 restore_flags(flags);
1764 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
1766 struct async_struct *info = (struct async_struct *)tty->driver_data;
1767 unsigned long flags;
1769 if (serial_paranoia_check(info, tty->device, "rs_put_char"))
1770 return;
1772 if (!tty || !info->xmit.buf)
1773 return;
1775 save_flags(flags); cli();
1776 if (CIRC_SPACE(info->xmit.head,
1777 info->xmit.tail,
1778 SERIAL_XMIT_SIZE) == 0) {
1779 restore_flags(flags);
1780 return;
1783 info->xmit.buf[info->xmit.head] = ch;
1784 info->xmit.head = (info->xmit.head + 1) & (SERIAL_XMIT_SIZE-1);
1785 restore_flags(flags);
1788 static void rs_flush_chars(struct tty_struct *tty)
1790 struct async_struct *info = (struct async_struct *)tty->driver_data;
1791 unsigned long flags;
1793 if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1794 return;
1796 if (info->xmit.head == info->xmit.tail
1797 || tty->stopped
1798 || tty->hw_stopped
1799 || !info->xmit.buf)
1800 return;
1802 save_flags(flags); cli();
1803 info->IER |= UART_IER_THRI;
1804 serial_out(info, UART_IER, info->IER);
1805 restore_flags(flags);
1808 static int rs_write(struct tty_struct * tty, int from_user,
1809 const unsigned char *buf, int count)
1811 int c, ret = 0;
1812 struct async_struct *info = (struct async_struct *)tty->driver_data;
1813 unsigned long flags;
1815 if (serial_paranoia_check(info, tty->device, "rs_write"))
1816 return 0;
1818 if (!tty || !info->xmit.buf || !tmp_buf)
1819 return 0;
1821 save_flags(flags);
1822 if (from_user) {
1823 down(&tmp_buf_sem);
1824 while (1) {
1825 int c1;
1826 c = CIRC_SPACE_TO_END(info->xmit.head,
1827 info->xmit.tail,
1828 SERIAL_XMIT_SIZE);
1829 if (count < c)
1830 c = count;
1831 if (c <= 0)
1832 break;
1834 c -= copy_from_user(tmp_buf, buf, c);
1835 if (!c) {
1836 if (!ret)
1837 ret = -EFAULT;
1838 break;
1840 cli();
1841 c1 = CIRC_SPACE_TO_END(info->xmit.head,
1842 info->xmit.tail,
1843 SERIAL_XMIT_SIZE);
1844 if (c1 < c)
1845 c = c1;
1846 memcpy(info->xmit.buf + info->xmit.head, tmp_buf, c);
1847 info->xmit.head = ((info->xmit.head + c) &
1848 (SERIAL_XMIT_SIZE-1));
1849 restore_flags(flags);
1850 buf += c;
1851 count -= c;
1852 ret += c;
1854 up(&tmp_buf_sem);
1855 } else {
1856 cli();
1857 while (1) {
1858 c = CIRC_SPACE_TO_END(info->xmit.head,
1859 info->xmit.tail,
1860 SERIAL_XMIT_SIZE);
1861 if (count < c)
1862 c = count;
1863 if (c <= 0) {
1864 break;
1866 memcpy(info->xmit.buf + info->xmit.head, buf, c);
1867 info->xmit.head = ((info->xmit.head + c) &
1868 (SERIAL_XMIT_SIZE-1));
1869 buf += c;
1870 count -= c;
1871 ret += c;
1873 restore_flags(flags);
1875 if (info->xmit.head != info->xmit.tail
1876 && !tty->stopped
1877 && !tty->hw_stopped
1878 && !(info->IER & UART_IER_THRI)) {
1879 info->IER |= UART_IER_THRI;
1880 serial_out(info, UART_IER, info->IER);
1882 return ret;
1885 static int rs_write_room(struct tty_struct *tty)
1887 struct async_struct *info = (struct async_struct *)tty->driver_data;
1889 if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1890 return 0;
1891 return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
1894 static int rs_chars_in_buffer(struct tty_struct *tty)
1896 struct async_struct *info = (struct async_struct *)tty->driver_data;
1898 if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1899 return 0;
1900 return CIRC_CNT(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
1903 static void rs_flush_buffer(struct tty_struct *tty)
1905 struct async_struct *info = (struct async_struct *)tty->driver_data;
1906 unsigned long flags;
1908 if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1909 return;
1910 save_flags(flags); cli();
1911 info->xmit.head = info->xmit.tail = 0;
1912 restore_flags(flags);
1913 wake_up_interruptible(&tty->write_wait);
1914 #ifdef SERIAL_HAVE_POLL_WAIT
1915 wake_up_interruptible(&tty->poll_wait);
1916 #endif
1917 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1918 tty->ldisc.write_wakeup)
1919 (tty->ldisc.write_wakeup)(tty);
1923 * This function is used to send a high-priority XON/XOFF character to
1924 * the device
1926 static void rs_send_xchar(struct tty_struct *tty, char ch)
1928 struct async_struct *info = (struct async_struct *)tty->driver_data;
1930 if (serial_paranoia_check(info, tty->device, "rs_send_char"))
1931 return;
1933 info->x_char = ch;
1934 if (ch) {
1935 /* Make sure transmit interrupts are on */
1936 info->IER |= UART_IER_THRI;
1937 serial_out(info, UART_IER, info->IER);
1942 * ------------------------------------------------------------
1943 * rs_throttle()
1945 * This routine is called by the upper-layer tty layer to signal that
1946 * incoming characters should be throttled.
1947 * ------------------------------------------------------------
1949 static void rs_throttle(struct tty_struct * tty)
1951 struct async_struct *info = (struct async_struct *)tty->driver_data;
1952 unsigned long flags;
1953 #ifdef SERIAL_DEBUG_THROTTLE
1954 char buf[64];
1956 printk("throttle %s: %d....\n", tty_name(tty, buf),
1957 tty->ldisc.chars_in_buffer(tty));
1958 #endif
1960 if (serial_paranoia_check(info, tty->device, "rs_throttle"))
1961 return;
1963 if (I_IXOFF(tty))
1964 rs_send_xchar(tty, STOP_CHAR(tty));
1966 if (tty->termios->c_cflag & CRTSCTS)
1967 info->MCR &= ~UART_MCR_RTS;
1969 save_flags(flags); cli();
1970 serial_out(info, UART_MCR, info->MCR);
1971 restore_flags(flags);
1974 static void rs_unthrottle(struct tty_struct * tty)
1976 struct async_struct *info = (struct async_struct *)tty->driver_data;
1977 unsigned long flags;
1978 #ifdef SERIAL_DEBUG_THROTTLE
1979 char buf[64];
1981 printk("unthrottle %s: %d....\n", tty_name(tty, buf),
1982 tty->ldisc.chars_in_buffer(tty));
1983 #endif
1985 if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
1986 return;
1988 if (I_IXOFF(tty)) {
1989 if (info->x_char)
1990 info->x_char = 0;
1991 else
1992 rs_send_xchar(tty, START_CHAR(tty));
1994 if (tty->termios->c_cflag & CRTSCTS)
1995 info->MCR |= UART_MCR_RTS;
1996 save_flags(flags); cli();
1997 serial_out(info, UART_MCR, info->MCR);
1998 restore_flags(flags);
2002 * ------------------------------------------------------------
2003 * rs_ioctl() and friends
2004 * ------------------------------------------------------------
2007 static int get_serial_info(struct async_struct * info,
2008 struct serial_struct * retinfo)
2010 struct serial_struct tmp;
2011 struct serial_state *state = info->state;
2013 if (!retinfo)
2014 return -EFAULT;
2015 memset(&tmp, 0, sizeof(tmp));
2016 tmp.type = state->type;
2017 tmp.line = state->line;
2018 tmp.port = state->port;
2019 if (HIGH_BITS_OFFSET)
2020 tmp.port_high = state->port >> HIGH_BITS_OFFSET;
2021 else
2022 tmp.port_high = 0;
2023 tmp.irq = state->irq;
2024 tmp.flags = state->flags;
2025 tmp.xmit_fifo_size = state->xmit_fifo_size;
2026 tmp.baud_base = state->baud_base;
2027 tmp.close_delay = state->close_delay;
2028 tmp.closing_wait = state->closing_wait;
2029 tmp.custom_divisor = state->custom_divisor;
2030 tmp.hub6 = state->hub6;
2031 tmp.io_type = state->io_type;
2032 if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
2033 return -EFAULT;
2034 return 0;
2037 static int set_serial_info(struct async_struct * info,
2038 struct serial_struct * new_info)
2040 struct serial_struct new_serial;
2041 struct serial_state old_state, *state;
2042 unsigned int i,change_irq,change_port;
2043 int retval = 0;
2044 unsigned long new_port;
2046 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
2047 return -EFAULT;
2048 state = info->state;
2049 old_state = *state;
2051 new_port = new_serial.port;
2052 if (HIGH_BITS_OFFSET)
2053 new_port += (unsigned long) new_serial.port_high << HIGH_BITS_OFFSET;
2055 change_irq = new_serial.irq != state->irq;
2056 change_port = (new_port != ((int) state->port)) ||
2057 (new_serial.hub6 != state->hub6);
2059 if (!capable(CAP_SYS_ADMIN)) {
2060 if (change_irq || change_port ||
2061 (new_serial.baud_base != state->baud_base) ||
2062 (new_serial.type != state->type) ||
2063 (new_serial.close_delay != state->close_delay) ||
2064 (new_serial.xmit_fifo_size != state->xmit_fifo_size) ||
2065 ((new_serial.flags & ~ASYNC_USR_MASK) !=
2066 (state->flags & ~ASYNC_USR_MASK)))
2067 return -EPERM;
2068 state->flags = ((state->flags & ~ASYNC_USR_MASK) |
2069 (new_serial.flags & ASYNC_USR_MASK));
2070 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
2071 (new_serial.flags & ASYNC_USR_MASK));
2072 state->custom_divisor = new_serial.custom_divisor;
2073 goto check_and_exit;
2076 new_serial.irq = irq_cannonicalize(new_serial.irq);
2078 if ((new_serial.irq >= NR_IRQS) ||
2079 (new_serial.baud_base < 9600)|| (new_serial.type < PORT_UNKNOWN) ||
2080 (new_serial.type > PORT_MAX) || (new_serial.type == PORT_CIRRUS) ||
2081 (new_serial.type == PORT_STARTECH)) {
2082 return -EINVAL;
2085 if ((new_serial.type != state->type) ||
2086 (new_serial.xmit_fifo_size <= 0))
2087 new_serial.xmit_fifo_size =
2088 uart_config[new_serial.type].dfl_xmit_fifo_size;
2090 /* Make sure address is not already in use */
2091 if (new_serial.type) {
2092 for (i = 0 ; i < NR_PORTS; i++)
2093 if ((state != &rs_table[i]) &&
2094 (rs_table[i].port == new_port) &&
2095 rs_table[i].type)
2096 return -EADDRINUSE;
2099 if ((change_port || change_irq) && (state->count > 1))
2100 return -EBUSY;
2103 * OK, past this point, all the error checking has been done.
2104 * At this point, we start making changes.....
2107 state->baud_base = new_serial.baud_base;
2108 state->flags = ((state->flags & ~ASYNC_FLAGS) |
2109 (new_serial.flags & ASYNC_FLAGS));
2110 info->flags = ((state->flags & ~ASYNC_INTERNAL_FLAGS) |
2111 (info->flags & ASYNC_INTERNAL_FLAGS));
2112 state->custom_divisor = new_serial.custom_divisor;
2113 state->close_delay = new_serial.close_delay * HZ/100;
2114 state->closing_wait = new_serial.closing_wait * HZ/100;
2115 #if (LINUX_VERSION_CODE > 0x20100)
2116 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
2117 #endif
2118 info->xmit_fifo_size = state->xmit_fifo_size =
2119 new_serial.xmit_fifo_size;
2121 if ((state->type != PORT_UNKNOWN) && state->port) {
2122 #ifdef CONFIG_SERIAL_RSA
2123 if (old_state.type == PORT_RSA)
2124 release_region(state->port + UART_RSA_BASE, 16);
2125 else
2126 #endif
2127 release_region(state->port,8);
2129 state->type = new_serial.type;
2130 if (change_port || change_irq) {
2132 * We need to shutdown the serial port at the old
2133 * port/irq combination.
2135 shutdown(info);
2136 state->irq = new_serial.irq;
2137 info->port = state->port = new_port;
2138 info->hub6 = state->hub6 = new_serial.hub6;
2139 if (info->hub6)
2140 info->io_type = state->io_type = SERIAL_IO_HUB6;
2141 else if (info->io_type == SERIAL_IO_HUB6)
2142 info->io_type = state->io_type = SERIAL_IO_PORT;
2144 if ((state->type != PORT_UNKNOWN) && state->port) {
2145 #ifdef CONFIG_SERIAL_RSA
2146 if (state->type == PORT_RSA)
2147 request_region(state->port + UART_RSA_BASE,
2148 16, "serial_rsa(set)");
2149 else
2150 #endif
2151 request_region(state->port,8,"serial(set)");
2155 check_and_exit:
2156 if (!state->port || !state->type)
2157 return 0;
2158 if (info->flags & ASYNC_INITIALIZED) {
2159 if (((old_state.flags & ASYNC_SPD_MASK) !=
2160 (state->flags & ASYNC_SPD_MASK)) ||
2161 (old_state.custom_divisor != state->custom_divisor)) {
2162 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
2163 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2164 info->tty->alt_speed = 57600;
2165 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2166 info->tty->alt_speed = 115200;
2167 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2168 info->tty->alt_speed = 230400;
2169 if ((state->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2170 info->tty->alt_speed = 460800;
2171 #endif
2172 change_speed(info, 0);
2174 } else
2175 retval = startup(info);
2176 return retval;
2181 * get_lsr_info - get line status register info
2183 * Purpose: Let user call ioctl() to get info when the UART physically
2184 * is emptied. On bus types like RS485, the transmitter must
2185 * release the bus after transmitting. This must be done when
2186 * the transmit shift register is empty, not be done when the
2187 * transmit holding register is empty. This functionality
2188 * allows an RS485 driver to be written in user space.
2190 static int get_lsr_info(struct async_struct * info, unsigned int *value)
2192 unsigned char status;
2193 unsigned int result;
2194 unsigned long flags;
2196 save_flags(flags); cli();
2197 status = serial_in(info, UART_LSR);
2198 restore_flags(flags);
2199 result = ((status & UART_LSR_TEMT) ? TIOCSER_TEMT : 0);
2202 * If we're about to load something into the transmit
2203 * register, we'll pretend the transmitter isn't empty to
2204 * avoid a race condition (depending on when the transmit
2205 * interrupt happens).
2207 if (info->x_char ||
2208 ((CIRC_CNT(info->xmit.head, info->xmit.tail,
2209 SERIAL_XMIT_SIZE) > 0) &&
2210 !info->tty->stopped && !info->tty->hw_stopped))
2211 result &= TIOCSER_TEMT;
2213 if (copy_to_user(value, &result, sizeof(int)))
2214 return -EFAULT;
2215 return 0;
2219 static int get_modem_info(struct async_struct * info, unsigned int *value)
2221 unsigned char control, status;
2222 unsigned int result;
2223 unsigned long flags;
2225 control = info->MCR;
2226 save_flags(flags); cli();
2227 status = serial_in(info, UART_MSR);
2228 restore_flags(flags);
2229 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
2230 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
2231 #ifdef TIOCM_OUT1
2232 | ((control & UART_MCR_OUT1) ? TIOCM_OUT1 : 0)
2233 | ((control & UART_MCR_OUT2) ? TIOCM_OUT2 : 0)
2234 #endif
2235 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
2236 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
2237 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
2238 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
2240 if (copy_to_user(value, &result, sizeof(int)))
2241 return -EFAULT;
2242 return 0;
2245 static int set_modem_info(struct async_struct * info, unsigned int cmd,
2246 unsigned int *value)
2248 unsigned int arg;
2249 unsigned long flags;
2251 if (copy_from_user(&arg, value, sizeof(int)))
2252 return -EFAULT;
2254 switch (cmd) {
2255 case TIOCMBIS:
2256 if (arg & TIOCM_RTS)
2257 info->MCR |= UART_MCR_RTS;
2258 if (arg & TIOCM_DTR)
2259 info->MCR |= UART_MCR_DTR;
2260 #ifdef TIOCM_OUT1
2261 if (arg & TIOCM_OUT1)
2262 info->MCR |= UART_MCR_OUT1;
2263 if (arg & TIOCM_OUT2)
2264 info->MCR |= UART_MCR_OUT2;
2265 #endif
2266 if (arg & TIOCM_LOOP)
2267 info->MCR |= UART_MCR_LOOP;
2268 break;
2269 case TIOCMBIC:
2270 if (arg & TIOCM_RTS)
2271 info->MCR &= ~UART_MCR_RTS;
2272 if (arg & TIOCM_DTR)
2273 info->MCR &= ~UART_MCR_DTR;
2274 #ifdef TIOCM_OUT1
2275 if (arg & TIOCM_OUT1)
2276 info->MCR &= ~UART_MCR_OUT1;
2277 if (arg & TIOCM_OUT2)
2278 info->MCR &= ~UART_MCR_OUT2;
2279 #endif
2280 if (arg & TIOCM_LOOP)
2281 info->MCR &= ~UART_MCR_LOOP;
2282 break;
2283 case TIOCMSET:
2284 info->MCR = ((info->MCR & ~(UART_MCR_RTS |
2285 #ifdef TIOCM_OUT1
2286 UART_MCR_OUT1 |
2287 UART_MCR_OUT2 |
2288 #endif
2289 UART_MCR_LOOP |
2290 UART_MCR_DTR))
2291 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
2292 #ifdef TIOCM_OUT1
2293 | ((arg & TIOCM_OUT1) ? UART_MCR_OUT1 : 0)
2294 | ((arg & TIOCM_OUT2) ? UART_MCR_OUT2 : 0)
2295 #endif
2296 | ((arg & TIOCM_LOOP) ? UART_MCR_LOOP : 0)
2297 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
2298 break;
2299 default:
2300 return -EINVAL;
2302 save_flags(flags); cli();
2303 info->MCR |= ALPHA_KLUDGE_MCR; /* Don't ask */
2304 serial_out(info, UART_MCR, info->MCR);
2305 restore_flags(flags);
2306 return 0;
2309 static int do_autoconfig(struct async_struct * info)
2311 int retval;
2313 if (!capable(CAP_SYS_ADMIN))
2314 return -EPERM;
2316 if (info->state->count > 1)
2317 return -EBUSY;
2319 shutdown(info);
2321 autoconfig(info->state);
2322 if ((info->state->flags & ASYNC_AUTO_IRQ) &&
2323 (info->state->port != 0) &&
2324 (info->state->type != PORT_UNKNOWN))
2325 info->state->irq = detect_uart_irq(info->state);
2327 retval = startup(info);
2328 if (retval)
2329 return retval;
2330 return 0;
2334 * rs_break() --- routine which turns the break handling on or off
2336 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2337 static void send_break( struct async_struct * info, int duration)
2339 if (!CONFIGURED_SERIAL_PORT(info))
2340 return;
2341 current->state = TASK_INTERRUPTIBLE;
2342 current->timeout = jiffies + duration;
2343 cli();
2344 info->LCR |= UART_LCR_SBC;
2345 serial_out(info, UART_LCR, info->LCR);
2346 schedule();
2347 info->LCR &= ~UART_LCR_SBC;
2348 serial_out(info, UART_LCR, info->LCR);
2349 sti();
2351 #else
2352 static void rs_break(struct tty_struct *tty, int break_state)
2354 struct async_struct * info = (struct async_struct *)tty->driver_data;
2355 unsigned long flags;
2357 if (serial_paranoia_check(info, tty->device, "rs_break"))
2358 return;
2360 if (!CONFIGURED_SERIAL_PORT(info))
2361 return;
2362 save_flags(flags); cli();
2363 if (break_state == -1)
2364 info->LCR |= UART_LCR_SBC;
2365 else
2366 info->LCR &= ~UART_LCR_SBC;
2367 serial_out(info, UART_LCR, info->LCR);
2368 restore_flags(flags);
2370 #endif
2372 #ifdef CONFIG_SERIAL_MULTIPORT
2373 static int get_multiport_struct(struct async_struct * info,
2374 struct serial_multiport_struct *retinfo)
2376 struct serial_multiport_struct ret;
2377 struct rs_multiport_struct *multi;
2379 multi = &rs_multiport[info->state->irq];
2381 ret.port_monitor = multi->port_monitor;
2383 ret.port1 = multi->port1;
2384 ret.mask1 = multi->mask1;
2385 ret.match1 = multi->match1;
2387 ret.port2 = multi->port2;
2388 ret.mask2 = multi->mask2;
2389 ret.match2 = multi->match2;
2391 ret.port3 = multi->port3;
2392 ret.mask3 = multi->mask3;
2393 ret.match3 = multi->match3;
2395 ret.port4 = multi->port4;
2396 ret.mask4 = multi->mask4;
2397 ret.match4 = multi->match4;
2399 ret.irq = info->state->irq;
2401 if (copy_to_user(retinfo,&ret,sizeof(*retinfo)))
2402 return -EFAULT;
2403 return 0;
2406 static int set_multiport_struct(struct async_struct * info,
2407 struct serial_multiport_struct *in_multi)
2409 struct serial_multiport_struct new_multi;
2410 struct rs_multiport_struct *multi;
2411 struct serial_state *state;
2412 int was_multi, now_multi;
2413 int retval;
2414 void (*handler)(int, void *, struct pt_regs *);
2416 if (!capable(CAP_SYS_ADMIN))
2417 return -EPERM;
2418 state = info->state;
2420 if (copy_from_user(&new_multi, in_multi,
2421 sizeof(struct serial_multiport_struct)))
2422 return -EFAULT;
2424 if (new_multi.irq != state->irq || state->irq == 0 ||
2425 !IRQ_ports[state->irq])
2426 return -EINVAL;
2428 multi = &rs_multiport[state->irq];
2429 was_multi = (multi->port1 != 0);
2431 multi->port_monitor = new_multi.port_monitor;
2433 if (multi->port1)
2434 release_region(multi->port1,1);
2435 multi->port1 = new_multi.port1;
2436 multi->mask1 = new_multi.mask1;
2437 multi->match1 = new_multi.match1;
2438 if (multi->port1)
2439 request_region(multi->port1,1,"serial(multiport1)");
2441 if (multi->port2)
2442 release_region(multi->port2,1);
2443 multi->port2 = new_multi.port2;
2444 multi->mask2 = new_multi.mask2;
2445 multi->match2 = new_multi.match2;
2446 if (multi->port2)
2447 request_region(multi->port2,1,"serial(multiport2)");
2449 if (multi->port3)
2450 release_region(multi->port3,1);
2451 multi->port3 = new_multi.port3;
2452 multi->mask3 = new_multi.mask3;
2453 multi->match3 = new_multi.match3;
2454 if (multi->port3)
2455 request_region(multi->port3,1,"serial(multiport3)");
2457 if (multi->port4)
2458 release_region(multi->port4,1);
2459 multi->port4 = new_multi.port4;
2460 multi->mask4 = new_multi.mask4;
2461 multi->match4 = new_multi.match4;
2462 if (multi->port4)
2463 request_region(multi->port4,1,"serial(multiport4)");
2465 now_multi = (multi->port1 != 0);
2467 if (IRQ_ports[state->irq]->next_port &&
2468 (was_multi != now_multi)) {
2469 free_irq(state->irq, &IRQ_ports[state->irq]);
2470 if (now_multi)
2471 handler = rs_interrupt_multi;
2472 else
2473 handler = rs_interrupt;
2475 retval = request_irq(state->irq, handler, SA_SHIRQ,
2476 "serial", &IRQ_ports[state->irq]);
2477 if (retval) {
2478 printk("Couldn't reallocate serial interrupt "
2479 "driver!!\n");
2482 return 0;
2484 #endif
2486 static int rs_ioctl(struct tty_struct *tty, struct file * file,
2487 unsigned int cmd, unsigned long arg)
2489 struct async_struct * info = (struct async_struct *)tty->driver_data;
2490 struct async_icount cprev, cnow; /* kernel counter temps */
2491 struct serial_icounter_struct icount;
2492 unsigned long flags;
2493 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2494 int retval, tmp;
2495 #endif
2497 if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
2498 return -ENODEV;
2500 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2501 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
2502 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
2503 if (tty->flags & (1 << TTY_IO_ERROR))
2504 return -EIO;
2507 switch (cmd) {
2508 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2509 case TCSBRK: /* SVID version: non-zero arg --> no break */
2510 retval = tty_check_change(tty);
2511 if (retval)
2512 return retval;
2513 tty_wait_until_sent(tty, 0);
2514 if (signal_pending(current))
2515 return -EINTR;
2516 if (!arg) {
2517 send_break(info, HZ/4); /* 1/4 second */
2518 if (signal_pending(current))
2519 return -EINTR;
2521 return 0;
2522 case TCSBRKP: /* support for POSIX tcsendbreak() */
2523 retval = tty_check_change(tty);
2524 if (retval)
2525 return retval;
2526 tty_wait_until_sent(tty, 0);
2527 if (signal_pending(current))
2528 return -EINTR;
2529 send_break(info, arg ? arg*(HZ/10) : HZ/4);
2530 if (signal_pending(current))
2531 return -EINTR;
2532 return 0;
2533 case TIOCGSOFTCAR:
2534 tmp = C_CLOCAL(tty) ? 1 : 0;
2535 if (copy_to_user((void *)arg, &tmp, sizeof(int)))
2536 return -EFAULT;
2537 return 0;
2538 case TIOCSSOFTCAR:
2539 if (copy_from_user(&tmp, (void *)arg, sizeof(int)))
2540 return -EFAULT;
2542 tty->termios->c_cflag =
2543 ((tty->termios->c_cflag & ~CLOCAL) |
2544 (tmp ? CLOCAL : 0));
2545 return 0;
2546 #endif
2547 case TIOCMGET:
2548 return get_modem_info(info, (unsigned int *) arg);
2549 case TIOCMBIS:
2550 case TIOCMBIC:
2551 case TIOCMSET:
2552 return set_modem_info(info, cmd, (unsigned int *) arg);
2553 case TIOCGSERIAL:
2554 return get_serial_info(info,
2555 (struct serial_struct *) arg);
2556 case TIOCSSERIAL:
2557 return set_serial_info(info,
2558 (struct serial_struct *) arg);
2559 case TIOCSERCONFIG:
2560 return do_autoconfig(info);
2562 case TIOCSERGETLSR: /* Get line status register */
2563 return get_lsr_info(info, (unsigned int *) arg);
2565 case TIOCSERGSTRUCT:
2566 if (copy_to_user((struct async_struct *) arg,
2567 info, sizeof(struct async_struct)))
2568 return -EFAULT;
2569 return 0;
2571 #ifdef CONFIG_SERIAL_MULTIPORT
2572 case TIOCSERGETMULTI:
2573 return get_multiport_struct(info,
2574 (struct serial_multiport_struct *) arg);
2575 case TIOCSERSETMULTI:
2576 return set_multiport_struct(info,
2577 (struct serial_multiport_struct *) arg);
2578 #endif
2581 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2582 * - mask passed in arg for lines of interest
2583 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2584 * Caller should use TIOCGICOUNT to see which one it was
2586 case TIOCMIWAIT:
2587 save_flags(flags); cli();
2588 /* note the counters on entry */
2589 cprev = info->state->icount;
2590 restore_flags(flags);
2591 /* Force modem status interrupts on */
2592 info->IER |= UART_IER_MSI;
2593 serial_out(info, UART_IER, info->IER);
2594 while (1) {
2595 interruptible_sleep_on(&info->delta_msr_wait);
2596 /* see if a signal did it */
2597 if (signal_pending(current))
2598 return -ERESTARTSYS;
2599 save_flags(flags); cli();
2600 cnow = info->state->icount; /* atomic copy */
2601 restore_flags(flags);
2602 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2603 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
2604 return -EIO; /* no change => error */
2605 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
2606 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
2607 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
2608 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
2609 return 0;
2611 cprev = cnow;
2613 /* NOTREACHED */
2616 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2617 * Return: write counters to the user passed counter struct
2618 * NB: both 1->0 and 0->1 transitions are counted except for
2619 * RI where only 0->1 is counted.
2621 case TIOCGICOUNT:
2622 save_flags(flags); cli();
2623 cnow = info->state->icount;
2624 restore_flags(flags);
2625 icount.cts = cnow.cts;
2626 icount.dsr = cnow.dsr;
2627 icount.rng = cnow.rng;
2628 icount.dcd = cnow.dcd;
2629 icount.rx = cnow.rx;
2630 icount.tx = cnow.tx;
2631 icount.frame = cnow.frame;
2632 icount.overrun = cnow.overrun;
2633 icount.parity = cnow.parity;
2634 icount.brk = cnow.brk;
2635 icount.buf_overrun = cnow.buf_overrun;
2637 if (copy_to_user((void *)arg, &icount, sizeof(icount)))
2638 return -EFAULT;
2639 return 0;
2640 case TIOCSERGWILD:
2641 case TIOCSERSWILD:
2642 /* "setserial -W" is called in Debian boot */
2643 printk ("TIOCSER?WILD ioctl obsolete, ignored.\n");
2644 return 0;
2646 default:
2647 return -ENOIOCTLCMD;
2649 return 0;
2652 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
2654 struct async_struct *info = (struct async_struct *)tty->driver_data;
2655 unsigned long flags;
2656 unsigned int cflag = tty->termios->c_cflag;
2658 if ( (cflag == old_termios->c_cflag)
2659 && ( RELEVANT_IFLAG(tty->termios->c_iflag)
2660 == RELEVANT_IFLAG(old_termios->c_iflag)))
2661 return;
2663 change_speed(info, old_termios);
2665 /* Handle transition to B0 status */
2666 if ((old_termios->c_cflag & CBAUD) &&
2667 !(cflag & CBAUD)) {
2668 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
2669 save_flags(flags); cli();
2670 serial_out(info, UART_MCR, info->MCR);
2671 restore_flags(flags);
2674 /* Handle transition away from B0 status */
2675 if (!(old_termios->c_cflag & CBAUD) &&
2676 (cflag & CBAUD)) {
2677 info->MCR |= UART_MCR_DTR;
2678 if (!(tty->termios->c_cflag & CRTSCTS) ||
2679 !test_bit(TTY_THROTTLED, &tty->flags)) {
2680 info->MCR |= UART_MCR_RTS;
2682 save_flags(flags); cli();
2683 serial_out(info, UART_MCR, info->MCR);
2684 restore_flags(flags);
2687 /* Handle turning off CRTSCTS */
2688 if ((old_termios->c_cflag & CRTSCTS) &&
2689 !(tty->termios->c_cflag & CRTSCTS)) {
2690 tty->hw_stopped = 0;
2691 rs_start(tty);
2694 #if 0
2696 * No need to wake up processes in open wait, since they
2697 * sample the CLOCAL flag once, and don't recheck it.
2698 * XXX It's not clear whether the current behavior is correct
2699 * or not. Hence, this may change.....
2701 if (!(old_termios->c_cflag & CLOCAL) &&
2702 (tty->termios->c_cflag & CLOCAL))
2703 wake_up_interruptible(&info->open_wait);
2704 #endif
2708 * ------------------------------------------------------------
2709 * rs_close()
2711 * This routine is called when the serial port gets closed. First, we
2712 * wait for the last remaining data to be sent. Then, we unlink its
2713 * async structure from the interrupt chain if necessary, and we free
2714 * that IRQ if nothing is left in the chain.
2715 * ------------------------------------------------------------
2717 static void rs_close(struct tty_struct *tty, struct file * filp)
2719 struct async_struct * info = (struct async_struct *)tty->driver_data;
2720 struct serial_state *state;
2721 unsigned long flags;
2723 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
2724 return;
2726 state = info->state;
2728 save_flags(flags); cli();
2730 if (tty_hung_up_p(filp)) {
2731 DBG_CNT("before DEC-hung");
2732 MOD_DEC_USE_COUNT;
2733 restore_flags(flags);
2734 return;
2737 #ifdef SERIAL_DEBUG_OPEN
2738 printk("rs_close ttys%d, count = %d\n", info->line, state->count);
2739 #endif
2740 if ((tty->count == 1) && (state->count != 1)) {
2742 * Uh, oh. tty->count is 1, which means that the tty
2743 * structure will be freed. state->count should always
2744 * be one in these conditions. If it's greater than
2745 * one, we've got real problems, since it means the
2746 * serial port won't be shutdown.
2748 printk("rs_close: bad serial port count; tty->count is 1, "
2749 "state->count is %d\n", state->count);
2750 state->count = 1;
2752 if (--state->count < 0) {
2753 printk("rs_close: bad serial port count for ttys%d: %d\n",
2754 info->line, state->count);
2755 state->count = 0;
2757 if (state->count) {
2758 DBG_CNT("before DEC-2");
2759 MOD_DEC_USE_COUNT;
2760 restore_flags(flags);
2761 return;
2763 info->flags |= ASYNC_CLOSING;
2764 restore_flags(flags);
2766 * Save the termios structure, since this port may have
2767 * separate termios for callout and dialin.
2769 if (info->flags & ASYNC_NORMAL_ACTIVE)
2770 info->state->normal_termios = *tty->termios;
2771 if (info->flags & ASYNC_CALLOUT_ACTIVE)
2772 info->state->callout_termios = *tty->termios;
2774 * Now we wait for the transmit buffer to clear; and we notify
2775 * the line discipline to only process XON/XOFF characters.
2777 tty->closing = 1;
2778 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
2779 tty_wait_until_sent(tty, info->closing_wait);
2781 * At this point we stop accepting input. To do this, we
2782 * disable the receive line status interrupts, and tell the
2783 * interrupt driver to stop checking the data ready bit in the
2784 * line status register.
2786 info->IER &= ~UART_IER_RLSI;
2787 info->read_status_mask &= ~UART_LSR_DR;
2788 if (info->flags & ASYNC_INITIALIZED) {
2789 serial_out(info, UART_IER, info->IER);
2791 * Before we drop DTR, make sure the UART transmitter
2792 * has completely drained; this is especially
2793 * important if there is a transmit FIFO!
2795 rs_wait_until_sent(tty, info->timeout);
2797 shutdown(info);
2798 if (tty->driver.flush_buffer)
2799 tty->driver.flush_buffer(tty);
2800 if (tty->ldisc.flush_buffer)
2801 tty->ldisc.flush_buffer(tty);
2802 tty->closing = 0;
2803 info->event = 0;
2804 info->tty = 0;
2805 if (info->blocked_open) {
2806 if (info->close_delay) {
2807 set_current_state(TASK_INTERRUPTIBLE);
2808 schedule_timeout(info->close_delay);
2810 wake_up_interruptible(&info->open_wait);
2812 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
2813 ASYNC_CLOSING);
2814 wake_up_interruptible(&info->close_wait);
2815 MOD_DEC_USE_COUNT;
2819 * rs_wait_until_sent() --- wait until the transmitter is empty
2821 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
2823 struct async_struct * info = (struct async_struct *)tty->driver_data;
2824 unsigned long orig_jiffies, char_time;
2825 int lsr;
2827 if (serial_paranoia_check(info, tty->device, "rs_wait_until_sent"))
2828 return;
2830 if (info->state->type == PORT_UNKNOWN)
2831 return;
2833 if (info->xmit_fifo_size == 0)
2834 return; /* Just in case.... */
2836 orig_jiffies = jiffies;
2838 * Set the check interval to be 1/5 of the estimated time to
2839 * send a single character, and make it at least 1. The check
2840 * interval should also be less than the timeout.
2842 * Note: we have to use pretty tight timings here to satisfy
2843 * the NIST-PCTS.
2845 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
2846 char_time = char_time / 5;
2847 if (char_time == 0)
2848 char_time = 1;
2849 if (timeout && timeout < char_time)
2850 char_time = timeout;
2852 * If the transmitter hasn't cleared in twice the approximate
2853 * amount of time to send the entire FIFO, it probably won't
2854 * ever clear. This assumes the UART isn't doing flow
2855 * control, which is currently the case. Hence, if it ever
2856 * takes longer than info->timeout, this is probably due to a
2857 * UART bug of some kind. So, we clamp the timeout parameter at
2858 * 2*info->timeout.
2860 if (!timeout || timeout > 2*info->timeout)
2861 timeout = 2*info->timeout;
2862 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2863 printk("In rs_wait_until_sent(%d) check=%lu...", timeout, char_time);
2864 printk("jiff=%lu...", jiffies);
2865 #endif
2866 while (!((lsr = serial_inp(info, UART_LSR)) & UART_LSR_TEMT)) {
2867 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2868 printk("lsr = %d (jiff=%lu)...", lsr, jiffies);
2869 #endif
2870 set_current_state(TASK_INTERRUPTIBLE);
2871 schedule_timeout(char_time);
2872 if (signal_pending(current))
2873 break;
2874 if (timeout && time_after(jiffies, orig_jiffies + timeout))
2875 break;
2877 set_current_state(TASK_RUNNING);
2878 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2879 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
2880 #endif
2884 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2886 static void rs_hangup(struct tty_struct *tty)
2888 struct async_struct * info = (struct async_struct *)tty->driver_data;
2889 struct serial_state *state = info->state;
2891 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
2892 return;
2894 state = info->state;
2896 rs_flush_buffer(tty);
2897 if (info->flags & ASYNC_CLOSING)
2898 return;
2899 shutdown(info);
2900 info->event = 0;
2901 state->count = 0;
2902 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2903 info->tty = 0;
2904 wake_up_interruptible(&info->open_wait);
2908 * ------------------------------------------------------------
2909 * rs_open() and friends
2910 * ------------------------------------------------------------
2912 static int block_til_ready(struct tty_struct *tty, struct file * filp,
2913 struct async_struct *info)
2915 DECLARE_WAITQUEUE(wait, current);
2916 struct serial_state *state = info->state;
2917 int retval;
2918 int do_clocal = 0, extra_count = 0;
2919 unsigned long flags;
2922 * If the device is in the middle of being closed, then block
2923 * until it's done, and then try again.
2925 if (tty_hung_up_p(filp) ||
2926 (info->flags & ASYNC_CLOSING)) {
2927 if (info->flags & ASYNC_CLOSING)
2928 interruptible_sleep_on(&info->close_wait);
2929 #ifdef SERIAL_DO_RESTART
2930 return ((info->flags & ASYNC_HUP_NOTIFY) ?
2931 -EAGAIN : -ERESTARTSYS);
2932 #else
2933 return -EAGAIN;
2934 #endif
2938 * If this is a callout device, then just make sure the normal
2939 * device isn't being used.
2941 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
2942 if (info->flags & ASYNC_NORMAL_ACTIVE)
2943 return -EBUSY;
2944 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2945 (info->flags & ASYNC_SESSION_LOCKOUT) &&
2946 (info->session != current->session))
2947 return -EBUSY;
2948 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2949 (info->flags & ASYNC_PGRP_LOCKOUT) &&
2950 (info->pgrp != current->pgrp))
2951 return -EBUSY;
2952 info->flags |= ASYNC_CALLOUT_ACTIVE;
2953 return 0;
2957 * If non-blocking mode is set, or the port is not enabled,
2958 * then make the check up front and then exit.
2960 if ((filp->f_flags & O_NONBLOCK) ||
2961 (tty->flags & (1 << TTY_IO_ERROR))) {
2962 if (info->flags & ASYNC_CALLOUT_ACTIVE)
2963 return -EBUSY;
2964 info->flags |= ASYNC_NORMAL_ACTIVE;
2965 return 0;
2968 if (info->flags & ASYNC_CALLOUT_ACTIVE) {
2969 if (state->normal_termios.c_cflag & CLOCAL)
2970 do_clocal = 1;
2971 } else {
2972 if (tty->termios->c_cflag & CLOCAL)
2973 do_clocal = 1;
2977 * Block waiting for the carrier detect and the line to become
2978 * free (i.e., not in use by the callout). While we are in
2979 * this loop, state->count is dropped by one, so that
2980 * rs_close() knows when to free things. We restore it upon
2981 * exit, either normal or abnormal.
2983 retval = 0;
2984 add_wait_queue(&info->open_wait, &wait);
2985 #ifdef SERIAL_DEBUG_OPEN
2986 printk("block_til_ready before block: ttys%d, count = %d\n",
2987 state->line, state->count);
2988 #endif
2989 save_flags(flags); cli();
2990 if (!tty_hung_up_p(filp)) {
2991 extra_count = 1;
2992 state->count--;
2994 restore_flags(flags);
2995 info->blocked_open++;
2996 while (1) {
2997 save_flags(flags); cli();
2998 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
2999 (tty->termios->c_cflag & CBAUD))
3000 serial_out(info, UART_MCR,
3001 serial_inp(info, UART_MCR) |
3002 (UART_MCR_DTR | UART_MCR_RTS));
3003 restore_flags(flags);
3004 set_current_state(TASK_INTERRUPTIBLE);
3005 if (tty_hung_up_p(filp) ||
3006 !(info->flags & ASYNC_INITIALIZED)) {
3007 #ifdef SERIAL_DO_RESTART
3008 if (info->flags & ASYNC_HUP_NOTIFY)
3009 retval = -EAGAIN;
3010 else
3011 retval = -ERESTARTSYS;
3012 #else
3013 retval = -EAGAIN;
3014 #endif
3015 break;
3017 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
3018 !(info->flags & ASYNC_CLOSING) &&
3019 (do_clocal || (serial_in(info, UART_MSR) &
3020 UART_MSR_DCD)))
3021 break;
3022 if (signal_pending(current)) {
3023 retval = -ERESTARTSYS;
3024 break;
3026 #ifdef SERIAL_DEBUG_OPEN
3027 printk("block_til_ready blocking: ttys%d, count = %d\n",
3028 info->line, state->count);
3029 #endif
3030 schedule();
3032 set_current_state(TASK_RUNNING);
3033 remove_wait_queue(&info->open_wait, &wait);
3034 if (extra_count)
3035 state->count++;
3036 info->blocked_open--;
3037 #ifdef SERIAL_DEBUG_OPEN
3038 printk("block_til_ready after blocking: ttys%d, count = %d\n",
3039 info->line, state->count);
3040 #endif
3041 if (retval)
3042 return retval;
3043 info->flags |= ASYNC_NORMAL_ACTIVE;
3044 return 0;
3047 static int get_async_struct(int line, struct async_struct **ret_info)
3049 struct async_struct *info;
3050 struct serial_state *sstate;
3052 sstate = rs_table + line;
3053 sstate->count++;
3054 if (sstate->info) {
3055 *ret_info = sstate->info;
3056 return 0;
3058 info = kmalloc(sizeof(struct async_struct), GFP_KERNEL);
3059 if (!info) {
3060 sstate->count--;
3061 return -ENOMEM;
3063 memset(info, 0, sizeof(struct async_struct));
3064 init_waitqueue_head(&info->open_wait);
3065 init_waitqueue_head(&info->close_wait);
3066 init_waitqueue_head(&info->delta_msr_wait);
3067 info->magic = SERIAL_MAGIC;
3068 info->port = sstate->port;
3069 info->flags = sstate->flags;
3070 info->io_type = sstate->io_type;
3071 info->iomem_base = sstate->iomem_base;
3072 info->iomem_reg_shift = sstate->iomem_reg_shift;
3073 info->xmit_fifo_size = sstate->xmit_fifo_size;
3074 info->line = line;
3075 info->tqueue.routine = do_softint;
3076 info->tqueue.data = info;
3077 info->state = sstate;
3078 if (sstate->info) {
3079 kfree_s(info, sizeof(struct async_struct));
3080 *ret_info = sstate->info;
3081 return 0;
3083 *ret_info = sstate->info = info;
3084 return 0;
3088 * This routine is called whenever a serial port is opened. It
3089 * enables interrupts for a serial port, linking in its async structure into
3090 * the IRQ chain. It also performs the serial-specific
3091 * initialization for the tty structure.
3093 static int rs_open(struct tty_struct *tty, struct file * filp)
3095 struct async_struct *info;
3096 int retval, line;
3097 unsigned long page;
3099 MOD_INC_USE_COUNT;
3100 line = MINOR(tty->device) - tty->driver.minor_start;
3101 if ((line < 0) || (line >= NR_PORTS)) {
3102 MOD_DEC_USE_COUNT;
3103 return -ENODEV;
3105 retval = get_async_struct(line, &info);
3106 if (retval) {
3107 MOD_DEC_USE_COUNT;
3108 return retval;
3110 tty->driver_data = info;
3111 info->tty = tty;
3112 if (serial_paranoia_check(info, tty->device, "rs_open"))
3113 return -ENODEV;
3115 #ifdef SERIAL_DEBUG_OPEN
3116 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
3117 info->state->count);
3118 #endif
3119 #if (LINUX_VERSION_CODE > 0x20100)
3120 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
3121 #endif
3123 if (!tmp_buf) {
3124 page = get_zeroed_page(GFP_KERNEL);
3125 if (!page) {
3126 return -ENOMEM;
3128 if (tmp_buf)
3129 free_page(page);
3130 else
3131 tmp_buf = (unsigned char *) page;
3135 * If the port is the middle of closing, bail out now
3137 if (tty_hung_up_p(filp) ||
3138 (info->flags & ASYNC_CLOSING)) {
3139 if (info->flags & ASYNC_CLOSING)
3140 interruptible_sleep_on(&info->close_wait);
3141 #ifdef SERIAL_DO_RESTART
3142 return ((info->flags & ASYNC_HUP_NOTIFY) ?
3143 -EAGAIN : -ERESTARTSYS);
3144 #else
3145 return -EAGAIN;
3146 #endif
3150 * Start up serial port
3152 retval = startup(info);
3153 if (retval) {
3154 return retval;
3157 retval = block_til_ready(tty, filp, info);
3158 if (retval) {
3159 #ifdef SERIAL_DEBUG_OPEN
3160 printk("rs_open returning after block_til_ready with %d\n",
3161 retval);
3162 #endif
3163 return retval;
3166 if ((info->state->count == 1) &&
3167 (info->flags & ASYNC_SPLIT_TERMIOS)) {
3168 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
3169 *tty->termios = info->state->normal_termios;
3170 else
3171 *tty->termios = info->state->callout_termios;
3172 change_speed(info, 0);
3174 #ifdef CONFIG_SERIAL_CONSOLE
3175 if (sercons.cflag && sercons.index == line) {
3176 tty->termios->c_cflag = sercons.cflag;
3177 sercons.cflag = 0;
3178 change_speed(info, 0);
3180 #endif
3181 info->session = current->session;
3182 info->pgrp = current->pgrp;
3184 #ifdef SERIAL_DEBUG_OPEN
3185 printk("rs_open ttys%d successful...", info->line);
3186 #endif
3187 return 0;
3191 * /proc fs routines....
3194 static inline int line_info(char *buf, struct serial_state *state)
3196 struct async_struct *info = state->info, scr_info;
3197 char stat_buf[30], control, status;
3198 int ret;
3199 unsigned long flags;
3201 ret = sprintf(buf, "%d: uart:%s port:%lX irq:%d",
3202 state->line, uart_config[state->type].name,
3203 state->port, state->irq);
3205 if (!state->port || (state->type == PORT_UNKNOWN)) {
3206 ret += sprintf(buf+ret, "\n");
3207 return ret;
3211 * Figure out the current RS-232 lines
3213 if (!info) {
3214 info = &scr_info; /* This is just for serial_{in,out} */
3216 info->magic = SERIAL_MAGIC;
3217 info->port = state->port;
3218 info->flags = state->flags;
3219 info->quot = 0;
3220 info->tty = 0;
3222 save_flags(flags); cli();
3223 status = serial_in(info, UART_MSR);
3224 control = info != &scr_info ? info->MCR : serial_in(info, UART_MCR);
3225 restore_flags(flags);
3227 stat_buf[0] = 0;
3228 stat_buf[1] = 0;
3229 if (control & UART_MCR_RTS)
3230 strcat(stat_buf, "|RTS");
3231 if (status & UART_MSR_CTS)
3232 strcat(stat_buf, "|CTS");
3233 if (control & UART_MCR_DTR)
3234 strcat(stat_buf, "|DTR");
3235 if (status & UART_MSR_DSR)
3236 strcat(stat_buf, "|DSR");
3237 if (status & UART_MSR_DCD)
3238 strcat(stat_buf, "|CD");
3239 if (status & UART_MSR_RI)
3240 strcat(stat_buf, "|RI");
3242 if (info->quot) {
3243 ret += sprintf(buf+ret, " baud:%d",
3244 state->baud_base / info->quot);
3247 ret += sprintf(buf+ret, " tx:%d rx:%d",
3248 state->icount.tx, state->icount.rx);
3250 if (state->icount.frame)
3251 ret += sprintf(buf+ret, " fe:%d", state->icount.frame);
3253 if (state->icount.parity)
3254 ret += sprintf(buf+ret, " pe:%d", state->icount.parity);
3256 if (state->icount.brk)
3257 ret += sprintf(buf+ret, " brk:%d", state->icount.brk);
3259 if (state->icount.overrun)
3260 ret += sprintf(buf+ret, " oe:%d", state->icount.overrun);
3263 * Last thing is the RS-232 status lines
3265 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
3266 return ret;
3269 int rs_read_proc(char *page, char **start, off_t off, int count,
3270 int *eof, void *data)
3272 int i, len = 0, l;
3273 off_t begin = 0;
3275 len += sprintf(page, "serinfo:1.0 driver:%s%s revision:%s\n",
3276 serial_version, LOCAL_VERSTRING, serial_revdate);
3277 for (i = 0; i < NR_PORTS && len < 4000; i++) {
3278 l = line_info(page + len, &rs_table[i]);
3279 len += l;
3280 if (len+begin > off+count)
3281 goto done;
3282 if (len+begin < off) {
3283 begin += len;
3284 len = 0;
3287 *eof = 1;
3288 done:
3289 if (off >= len+begin)
3290 return 0;
3291 *start = page + (off-begin);
3292 return ((count < begin+len-off) ? count : begin+len-off);
3296 * ---------------------------------------------------------------------
3297 * rs_init() and friends
3299 * rs_init() is called at boot-time to initialize the serial driver.
3300 * ---------------------------------------------------------------------
3304 * This routine prints out the appropriate serial driver version
3305 * number, and identifies which options were configured into this
3306 * driver.
3308 static char serial_options[] __initdata =
3309 #ifdef CONFIG_HUB6
3310 " HUB-6"
3311 #define SERIAL_OPT
3312 #endif
3313 #ifdef CONFIG_SERIAL_MANY_PORTS
3314 " MANY_PORTS"
3315 #define SERIAL_OPT
3316 #endif
3317 #ifdef CONFIG_SERIAL_MULTIPORT
3318 " MULTIPORT"
3319 #define SERIAL_OPT
3320 #endif
3321 #ifdef CONFIG_SERIAL_SHARE_IRQ
3322 " SHARE_IRQ"
3323 #define SERIAL_OPT
3324 #endif
3325 #ifdef CONFIG_SERIAL_DETECT_IRQ
3326 " DETECT_IRQ"
3327 #define SERIAL_OPT
3328 #endif
3329 #ifdef ENABLE_SERIAL_PCI
3330 " SERIAL_PCI"
3331 #define SERIAL_OPT
3332 #endif
3333 #ifdef ENABLE_SERIAL_PNP
3334 " ISAPNP"
3335 #define SERIAL_OPT
3336 #endif
3337 #ifdef SERIAL_OPT
3338 " enabled\n";
3339 #else
3340 " no serial options enabled\n";
3341 #endif
3342 #undef SERIAL_OPT
3344 static _INLINE_ void show_serial_version(void)
3346 printk(KERN_INFO "%s version %s%s (%s) with%s", serial_name,
3347 serial_version, LOCAL_VERSTRING, serial_revdate,
3348 serial_options);
3352 * This routine detect the IRQ of a serial port by clearing OUT2 when
3353 * no UART interrupt are requested (IER = 0) (*GPL*). This seems to work at
3354 * each time, as long as no other device permanently request the IRQ.
3355 * If no IRQ is detected, or multiple IRQ appear, this function returns 0.
3356 * The variable "state" and the field "state->port" should not be null.
3358 static unsigned detect_uart_irq (struct serial_state * state)
3360 int irq;
3361 unsigned long irqs;
3362 unsigned char save_mcr, save_ier;
3363 struct async_struct scr_info; /* serial_{in,out} because HUB6 */
3365 #ifdef CONFIG_SERIAL_MANY_PORTS
3366 unsigned char save_ICP=0; /* no warning */
3367 unsigned short ICP=0;
3369 if (state->flags & ASYNC_FOURPORT) {
3370 ICP = (state->port & 0xFE0) | 0x01F;
3371 save_ICP = inb_p(ICP);
3372 outb_p(0x80, ICP);
3373 (void) inb_p(ICP);
3375 #endif
3376 scr_info.magic = SERIAL_MAGIC;
3377 scr_info.state = state;
3378 scr_info.port = state->port;
3379 scr_info.flags = state->flags;
3380 #ifdef CONFIG_HUB6
3381 scr_info.hub6 = state->hub6;
3382 #endif
3383 scr_info.io_type = state->io_type;
3384 scr_info.iomem_base = state->iomem_base;
3385 scr_info.iomem_reg_shift = state->iomem_reg_shift;
3387 /* forget possible initially masked and pending IRQ */
3388 probe_irq_off(probe_irq_on());
3389 save_mcr = serial_inp(&scr_info, UART_MCR);
3390 save_ier = serial_inp(&scr_info, UART_IER);
3391 serial_outp(&scr_info, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
3393 irqs = probe_irq_on();
3394 serial_outp(&scr_info, UART_MCR, 0);
3395 udelay (10);
3396 if (state->flags & ASYNC_FOURPORT) {
3397 serial_outp(&scr_info, UART_MCR,
3398 UART_MCR_DTR | UART_MCR_RTS);
3399 } else {
3400 serial_outp(&scr_info, UART_MCR,
3401 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
3403 serial_outp(&scr_info, UART_IER, 0x0f); /* enable all intrs */
3404 (void)serial_inp(&scr_info, UART_LSR);
3405 (void)serial_inp(&scr_info, UART_RX);
3406 (void)serial_inp(&scr_info, UART_IIR);
3407 (void)serial_inp(&scr_info, UART_MSR);
3408 serial_outp(&scr_info, UART_TX, 0xFF);
3409 udelay (20);
3410 irq = probe_irq_off(irqs);
3412 serial_outp(&scr_info, UART_MCR, save_mcr);
3413 serial_outp(&scr_info, UART_IER, save_ier);
3414 #ifdef CONFIG_SERIAL_MANY_PORTS
3415 if (state->flags & ASYNC_FOURPORT)
3416 outb_p(save_ICP, ICP);
3417 #endif
3418 return (irq > 0)? irq : 0;
3422 * This is a quickie test to see how big the FIFO is.
3423 * It doesn't work at all the time, more's the pity.
3425 static int size_fifo(struct async_struct *info)
3427 unsigned char old_fcr, old_mcr, old_dll, old_dlm;
3428 int count;
3430 old_fcr = serial_inp(info, UART_FCR);
3431 old_mcr = serial_inp(info, UART_MCR);
3432 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO |
3433 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
3434 serial_outp(info, UART_MCR, UART_MCR_LOOP);
3435 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3436 old_dll = serial_inp(info, UART_DLL);
3437 old_dlm = serial_inp(info, UART_DLM);
3438 serial_outp(info, UART_DLL, 0x01);
3439 serial_outp(info, UART_DLM, 0x00);
3440 serial_outp(info, UART_LCR, 0x03);
3441 for (count = 0; count < 256; count++)
3442 serial_outp(info, UART_TX, count);
3443 mdelay(20);
3444 for (count = 0; (serial_inp(info, UART_LSR) & UART_LSR_DR) &&
3445 (count < 256); count++)
3446 serial_inp(info, UART_RX);
3447 serial_outp(info, UART_FCR, old_fcr);
3448 serial_outp(info, UART_MCR, old_mcr);
3449 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3450 serial_outp(info, UART_DLL, old_dll);
3451 serial_outp(info, UART_DLM, old_dlm);
3453 return count;
3457 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
3458 * When this function is called we know it is at least a StarTech
3459 * 16650 V2, but it might be one of several StarTech UARTs, or one of
3460 * its clones. (We treat the broken original StarTech 16650 V1 as a
3461 * 16550, and why not? Startech doesn't seem to even acknowledge its
3462 * existence.)
3464 * What evil have men's minds wrought...
3466 static void autoconfig_startech_uarts(struct async_struct *info,
3467 struct serial_state *state,
3468 unsigned long flags)
3470 unsigned char scratch, scratch2, scratch3;
3473 * First we check to see if it's an Oxford Semiconductor UART.
3475 * If we have to do this here because some non-National
3476 * Semiconductor clone chips lock up if you try writing to the
3477 * LSR register (which serial_icr_read does)
3479 if (state->type == PORT_16550A) {
3481 * EFR [4] must be set else this test fails
3483 * This shouldn't be necessary, but Mike Hudson
3484 * (Exoray@isys.ca) claims that it's needed for 952
3485 * dual UART's (which are not recommended for new designs).
3487 serial_out(info, UART_LCR, 0xBF);
3488 serial_out(info, UART_EFR, 0x10);
3489 serial_out(info, UART_LCR, 0x00);
3490 /* Check for Oxford Semiconductor 16C950 */
3491 scratch = serial_icr_read(info, UART_ID1);
3492 scratch2 = serial_icr_read(info, UART_ID2);
3493 scratch3 = serial_icr_read(info, UART_ID3);
3495 if (scratch == 0x16 && scratch2 == 0xC9 &&
3496 (scratch3 == 0x50 || scratch3 == 0x52 ||
3497 scratch3 == 0x54)) {
3498 state->type = PORT_16C950;
3499 state->revision = serial_icr_read(info, UART_REV) |
3500 (scratch3 << 8);
3501 return;
3506 * We check for a XR16C850 by setting DLL and DLM to 0, and
3507 * then reading back DLL and DLM. If DLM reads back 0x10,
3508 * then the UART is a XR16C850 and the DLL contains the chip
3509 * revision. If DLM reads back 0x14, then the UART is a
3510 * XR16C854.
3513 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3514 serial_outp(info, UART_DLL, 0);
3515 serial_outp(info, UART_DLM, 0);
3516 state->revision = serial_inp(info, UART_DLL);
3517 scratch = serial_inp(info, UART_DLM);
3518 serial_outp(info, UART_LCR, 0);
3519 if (scratch == 0x10 || scratch == 0x14) {
3520 state->type = PORT_16850;
3521 return;
3525 * We distinguish between the '654 and the '650 by counting
3526 * how many bytes are in the FIFO. I'm using this for now,
3527 * since that's the technique that was sent to me in the
3528 * serial driver update, but I'm not convinced this works.
3529 * I've had problems doing this in the past. -TYT
3531 if (size_fifo(info) == 64)
3532 state->type = PORT_16654;
3533 else
3534 state->type = PORT_16650V2;
3538 * This routine is called by rs_init() to initialize a specific serial
3539 * port. It determines what type of UART chip this serial port is
3540 * using: 8250, 16450, 16550, 16550A. The important question is
3541 * whether or not this UART is a 16550A or not, since this will
3542 * determine whether or not we can use its FIFO features or not.
3544 static void autoconfig(struct serial_state * state)
3546 unsigned char status1, status2, scratch, scratch2, scratch3;
3547 unsigned char save_lcr, save_mcr;
3548 struct async_struct *info, scr_info;
3549 unsigned long flags;
3551 state->type = PORT_UNKNOWN;
3553 #ifdef SERIAL_DEBUG_AUTOCONF
3554 printk("Testing ttyS%d (0x%04lx, 0x%04x)...\n", state->line,
3555 state->port, (unsigned) state->iomem_base);
3556 #endif
3558 if (!CONFIGURED_SERIAL_PORT(state))
3559 return;
3561 info = &scr_info; /* This is just for serial_{in,out} */
3563 info->magic = SERIAL_MAGIC;
3564 info->state = state;
3565 info->port = state->port;
3566 info->flags = state->flags;
3567 #ifdef CONFIG_HUB6
3568 info->hub6 = state->hub6;
3569 #endif
3570 info->io_type = state->io_type;
3571 info->iomem_base = state->iomem_base;
3572 info->iomem_reg_shift = state->iomem_reg_shift;
3574 save_flags(flags); cli();
3576 if (!(state->flags & ASYNC_BUGGY_UART) &&
3577 !state->iomem_base) {
3579 * Do a simple existence test first; if we fail this,
3580 * there's no point trying anything else.
3582 * 0x80 is used as a nonsense port to prevent against
3583 * false positives due to ISA bus float. The
3584 * assumption is that 0x80 is a non-existent port;
3585 * which should be safe since include/asm/io.h also
3586 * makes this assumption.
3588 scratch = serial_inp(info, UART_IER);
3589 serial_outp(info, UART_IER, 0);
3590 #ifdef __i386__
3591 outb(0xff, 0x080);
3592 #endif
3593 scratch2 = serial_inp(info, UART_IER);
3594 serial_outp(info, UART_IER, 0x0F);
3595 #ifdef __i386__
3596 outb(0, 0x080);
3597 #endif
3598 scratch3 = serial_inp(info, UART_IER);
3599 serial_outp(info, UART_IER, scratch);
3600 if (scratch2 || scratch3 != 0x0F) {
3601 #ifdef SERIAL_DEBUG_AUTOCONF
3602 printk("serial: ttyS%d: simple autoconfig failed "
3603 "(%02x, %02x)\n", state->line,
3604 scratch2, scratch3);
3605 #endif
3606 restore_flags(flags);
3607 return; /* We failed; there's nothing here */
3611 save_mcr = serial_in(info, UART_MCR);
3612 save_lcr = serial_in(info, UART_LCR);
3615 * Check to see if a UART is really there. Certain broken
3616 * internal modems based on the Rockwell chipset fail this
3617 * test, because they apparently don't implement the loopback
3618 * test mode. So this test is skipped on the COM 1 through
3619 * COM 4 ports. This *should* be safe, since no board
3620 * manufacturer would be stupid enough to design a board
3621 * that conflicts with COM 1-4 --- we hope!
3623 if (!(state->flags & ASYNC_SKIP_TEST)) {
3624 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
3625 status1 = serial_inp(info, UART_MSR) & 0xF0;
3626 serial_outp(info, UART_MCR, save_mcr);
3627 if (status1 != 0x90) {
3628 #ifdef SERIAL_DEBUG_AUTOCONF
3629 printk("serial: ttyS%d: no UART loopback failed\n",
3630 state->line);
3631 #endif
3632 restore_flags(flags);
3633 return;
3636 serial_outp(info, UART_LCR, 0xBF); /* set up for StarTech test */
3637 serial_outp(info, UART_EFR, 0); /* EFR is the same as FCR */
3638 serial_outp(info, UART_LCR, 0);
3639 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3640 scratch = serial_in(info, UART_IIR) >> 6;
3641 switch (scratch) {
3642 case 0:
3643 state->type = PORT_16450;
3644 break;
3645 case 1:
3646 state->type = PORT_UNKNOWN;
3647 break;
3648 case 2:
3649 state->type = PORT_16550;
3650 break;
3651 case 3:
3652 state->type = PORT_16550A;
3653 break;
3655 if (state->type == PORT_16550A) {
3656 /* Check for Startech UART's */
3657 serial_outp(info, UART_LCR, UART_LCR_DLAB);
3658 if (serial_in(info, UART_EFR) == 0) {
3659 state->type = PORT_16650;
3660 } else {
3661 serial_outp(info, UART_LCR, 0xBF);
3662 if (serial_in(info, UART_EFR) == 0)
3663 autoconfig_startech_uarts(info, state, flags);
3666 if (state->type == PORT_16550A) {
3667 /* Check for TI 16750 */
3668 serial_outp(info, UART_LCR, save_lcr | UART_LCR_DLAB);
3669 serial_outp(info, UART_FCR,
3670 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
3671 scratch = serial_in(info, UART_IIR) >> 5;
3672 if (scratch == 7) {
3674 * If this is a 16750, and not a cheap UART
3675 * clone, then it should only go into 64 byte
3676 * mode if the UART_FCR7_64BYTE bit was set
3677 * while UART_LCR_DLAB was latched.
3679 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3680 serial_outp(info, UART_LCR, 0);
3681 serial_outp(info, UART_FCR,
3682 UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
3683 scratch = serial_in(info, UART_IIR) >> 5;
3684 if (scratch == 6)
3685 state->type = PORT_16750;
3687 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
3689 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
3690 if (state->type == PORT_16550A) {
3691 int i;
3693 for (i = 0 ; i < PORT_RSA_MAX ; ++i) {
3694 if (!probe_rsa[i] && !force_rsa[i])
3695 break;
3696 if (((probe_rsa[i] != state->port) ||
3697 check_region(state->port + UART_RSA_BASE, 16)) &&
3698 (force_rsa[i] != state->port))
3699 continue;
3700 if (!enable_rsa(info))
3701 continue;
3702 state->type = PORT_RSA;
3703 state->baud_base = SERIAL_RSA_BAUD_BASE;
3704 break;
3707 #endif
3708 serial_outp(info, UART_LCR, save_lcr);
3709 if (state->type == PORT_16450) {
3710 scratch = serial_in(info, UART_SCR);
3711 serial_outp(info, UART_SCR, 0xa5);
3712 status1 = serial_in(info, UART_SCR);
3713 serial_outp(info, UART_SCR, 0x5a);
3714 status2 = serial_in(info, UART_SCR);
3715 serial_outp(info, UART_SCR, scratch);
3717 if ((status1 != 0xa5) || (status2 != 0x5a))
3718 state->type = PORT_8250;
3720 state->xmit_fifo_size = uart_config[state->type].dfl_xmit_fifo_size;
3722 if (state->type == PORT_UNKNOWN) {
3723 restore_flags(flags);
3724 return;
3727 if (info->port) {
3728 #ifdef CONFIG_SERIAL_RSA
3729 if (state->type == PORT_RSA)
3730 request_region(info->port + UART_RSA_BASE, 16,
3731 "serial_rsa(auto)");
3732 else
3733 #endif
3734 request_region(info->port,8,"serial(auto)");
3738 * Reset the UART.
3740 #ifdef CONFIG_SERIAL_RSA
3741 if (state->type == PORT_RSA)
3742 serial_outp(info, UART_RSA_FRR, 0);
3743 #endif
3744 serial_outp(info, UART_MCR, save_mcr);
3745 serial_outp(info, UART_FCR, (UART_FCR_ENABLE_FIFO |
3746 UART_FCR_CLEAR_RCVR |
3747 UART_FCR_CLEAR_XMIT));
3748 serial_outp(info, UART_FCR, 0);
3749 (void)serial_in(info, UART_RX);
3750 serial_outp(info, UART_IER, 0);
3752 restore_flags(flags);
3755 int register_serial(struct serial_struct *req);
3756 void unregister_serial(int line);
3758 #if (LINUX_VERSION_CODE > 0x20100)
3759 EXPORT_SYMBOL(register_serial);
3760 EXPORT_SYMBOL(unregister_serial);
3761 #else
3762 static struct symbol_table serial_syms = {
3763 #include <linux/symtab_begin.h>
3764 X(register_serial),
3765 X(unregister_serial),
3766 #include <linux/symtab_end.h>
3768 #endif
3771 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
3773 static void __init printk_pnp_dev_id(unsigned short vendor,
3774 unsigned short device)
3776 printk("%c%c%c%x%x%x%x",
3777 'A' + ((vendor >> 2) & 0x3f) - 1,
3778 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
3779 'A' + ((vendor >> 8) & 0x1f) - 1,
3780 (device >> 4) & 0x0f,
3781 device & 0x0f,
3782 (device >> 12) & 0x0f,
3783 (device >> 8) & 0x0f);
3786 static _INLINE_ int get_pci_port(struct pci_dev *dev,
3787 struct pci_board *board,
3788 struct serial_struct *req,
3789 int idx)
3791 unsigned long port;
3792 int base_idx;
3793 int max_port;
3795 base_idx = SPCI_FL_GET_BASE(board->flags);
3796 if (board->flags & SPCI_FL_BASE_TABLE)
3797 base_idx += idx;
3799 if (board->flags & SPCI_FL_REGION_SZ_CAP) {
3800 max_port = pci_resource_len(dev, base_idx) / 8;
3801 if (idx >= max_port)
3802 return 1;
3805 port = pci_resource_start(dev, base_idx) + board->first_uart_offset;
3807 if ((board->flags & SPCI_FL_BASE_TABLE) == 0)
3808 port += idx * (board->uart_offset ? board->uart_offset : 8);
3810 if (IS_PCI_REGION_IOPORT(dev, base_idx)) {
3811 req->port = port;
3812 if (HIGH_BITS_OFFSET)
3813 req->port_high = port >> HIGH_BITS_OFFSET;
3814 else
3815 req->port_high = 0;
3816 return 0;
3818 req->io_type = SERIAL_IO_MEM;
3819 req->iomem_base = ioremap(port, board->uart_offset);
3820 req->iomem_reg_shift = board->reg_shift;
3821 req->port = 0;
3822 return 0;
3825 static _INLINE_ int get_pci_irq(struct pci_dev *dev,
3826 struct pci_board *board,
3827 int idx)
3829 int base_idx;
3831 if ((board->flags & SPCI_FL_IRQRESOURCE) == 0)
3832 return dev->irq;
3834 base_idx = SPCI_FL_GET_IRQBASE(board->flags);
3835 if (board->flags & SPCI_FL_IRQ_TABLE)
3836 base_idx += idx;
3838 return PCI_IRQ_RESOURCE(dev, base_idx);
3842 * Common enabler code shared by both PCI and ISAPNP probes
3844 static void __init start_pci_pnp_board(struct pci_dev *dev,
3845 struct pci_board *board)
3847 int k, line;
3848 struct serial_struct serial_req;
3849 int base_baud;
3851 if (PREPARE_FUNC(dev) && (PREPARE_FUNC(dev))(dev) < 0) {
3852 printk("serial: PNP device '");
3853 printk_pnp_dev_id(board->vendor, board->device);
3854 printk("' prepare failed\n");
3855 return;
3858 if (ACTIVATE_FUNC(dev) && (ACTIVATE_FUNC(dev))(dev) < 0) {
3859 printk("serial: PNP device '");
3860 printk_pnp_dev_id(board->vendor, board->device);
3861 printk("' activate failed\n");
3862 return;
3865 if (!(board->flags & SPCI_FL_ISPNP) && pci_enable_device(dev)) {
3866 printk("serial: PCI device enable failed\n");
3867 return;
3871 * Run the initialization function, if any
3873 if (board->init_fn && ((board->init_fn)(dev, board, 1) != 0))
3874 return;
3876 #ifdef MODULE
3878 * Register the serial board in the array if we need to
3879 * shutdown the board on a module unload.
3881 if (DEACTIVATE_FUNC(dev) || board->init_fn) {
3882 if (serial_pci_board_idx >= NR_PCI_BOARDS)
3883 return;
3884 serial_pci_board[serial_pci_board_idx].board = *board;
3885 serial_pci_board[serial_pci_board_idx].dev = dev;
3886 serial_pci_board_idx++;
3888 #endif
3890 base_baud = board->base_baud;
3891 if (!base_baud)
3892 base_baud = BASE_BAUD;
3893 memset(&serial_req, 0, sizeof(serial_req));
3895 for (k=0; k < board->num_ports; k++) {
3896 serial_req.irq = get_pci_irq(dev, board, k);
3897 if (get_pci_port(dev, board, &serial_req, k))
3898 break;
3899 serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE;
3900 #ifdef SERIAL_DEBUG_PCI
3901 printk("Setup PCI/PNP port: port %x, irq %d, type %d\n",
3902 serial_req.port, serial_req.irq, serial_req.io_type);
3903 #endif
3904 line = register_serial(&serial_req);
3905 if (line < 0)
3906 break;
3907 rs_table[line].baud_base = base_baud;
3910 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
3912 #ifdef ENABLE_SERIAL_PCI
3914 * Some PCI serial cards using the PLX 9050 PCI interface chip require
3915 * that the card interrupt be explicitly enabled or disabled. This
3916 * seems to be mainly needed on card using the PLX which also use I/O
3917 * mapped memory.
3919 static int
3920 #ifndef MODULE
3921 __init
3922 #endif
3923 pci_plx9050_fn(struct pci_dev *dev, struct pci_board *board, int enable)
3925 u8 data, *p, irq_config;
3926 int pci_config;
3928 irq_config = 0x41;
3929 pci_config = PCI_COMMAND_MEMORY;
3930 if (dev->vendor == PCI_VENDOR_ID_PANACOM)
3931 irq_config = 0x43;
3932 if ((dev->vendor == PCI_VENDOR_ID_PLX) &&
3933 (dev->device == PCI_VENDOR_ID_PLX_ROMULUS)) {
3935 * As the megawolf cards have the int pins active
3936 * high, and have 2 UART chips, both ints must be
3937 * enabled on the 9050. Also, the UARTS are set in
3938 * 16450 mode by default, so we have to enable the
3939 * 16C950 'enhanced' mode so that we can use the deep
3940 * FIFOs
3942 irq_config = 0x5b;
3943 pci_config = PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
3946 pci_read_config_byte(dev, PCI_COMMAND, &data);
3948 if (enable)
3949 pci_write_config_byte(dev, PCI_COMMAND,
3950 data | pci_config);
3952 /* enable/disable interrupts */
3953 p = ioremap(pci_resource_start(dev, 0), 0x80);
3954 writel(enable ? irq_config : 0x00, (unsigned long)p + 0x4c);
3955 iounmap(p);
3957 if (!enable)
3958 pci_write_config_byte(dev, PCI_COMMAND,
3959 data & ~pci_config);
3960 return 0;
3965 * SIIG serial cards have an PCI interface chip which also controls
3966 * the UART clocking frequency. Each UART can be clocked independently
3967 * (except cards equiped with 4 UARTs) and initial clocking settings
3968 * are stored in the EEPROM chip. It can cause problems because this
3969 * version of serial driver doesn't support differently clocked UART's
3970 * on single PCI card. To prevent this, initialization functions set
3971 * high frequency clocking for all UART's on given card. It is safe (I
3972 * hope) because it doesn't touch EEPROM settings to prevent conflicts
3973 * with other OSes (like M$ DOS).
3975 * SIIG support added by Andrey Panin <pazke@mail.tp.ru>, 10/1999
3977 * There is two family of SIIG serial cards with different PCI
3978 * interface chip and different configuration methods:
3979 * - 10x cards have control registers in IO and/or memory space;
3980 * - 20x cards have control registers in standard PCI configuration space.
3983 #define PCI_DEVICE_ID_SIIG_1S_10x (PCI_DEVICE_ID_SIIG_1S_10x_550 & 0xfffc)
3984 #define PCI_DEVICE_ID_SIIG_2S_10x (PCI_DEVICE_ID_SIIG_2S_10x_550 & 0xfff8)
3986 static int
3987 #ifndef MODULE
3988 __init
3989 #endif
3990 pci_siig10x_fn(struct pci_dev *dev, struct pci_board *board, int enable)
3992 u16 data, *p;
3994 if (!enable) return 0;
3996 p = ioremap(pci_resource_start(dev, 0), 0x80);
3998 switch (dev->device & 0xfff8) {
3999 case PCI_DEVICE_ID_SIIG_1S_10x: /* 1S */
4000 data = 0xffdf;
4001 break;
4002 case PCI_DEVICE_ID_SIIG_2S_10x: /* 2S, 2S1P */
4003 data = 0xf7ff;
4004 break;
4005 default: /* 1S1P, 4S */
4006 data = 0xfffb;
4007 break;
4010 writew(readw((unsigned long) p + 0x28) & data, (unsigned long) p + 0x28);
4011 iounmap(p);
4012 return 0;
4015 #define PCI_DEVICE_ID_SIIG_2S_20x (PCI_DEVICE_ID_SIIG_2S_20x_550 & 0xfffc)
4016 #define PCI_DEVICE_ID_SIIG_2S1P_20x (PCI_DEVICE_ID_SIIG_2S1P_20x_550 & 0xfffc)
4018 static int
4019 #ifndef MODULE
4020 __init
4021 #endif
4022 pci_siig20x_fn(struct pci_dev *dev, struct pci_board *board, int enable)
4024 u8 data;
4026 if (!enable) return 0;
4028 /* Change clock frequency for the first UART. */
4029 pci_read_config_byte(dev, 0x6f, &data);
4030 pci_write_config_byte(dev, 0x6f, data & 0xef);
4032 /* If this card has 2 UART, we have to do the same with second UART. */
4033 if (((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S_20x) ||
4034 ((dev->device & 0xfffc) == PCI_DEVICE_ID_SIIG_2S1P_20x)) {
4035 pci_read_config_byte(dev, 0x73, &data);
4036 pci_write_config_byte(dev, 0x73, data & 0xef);
4038 return 0;
4041 /* Added for EKF Intel i960 serial boards */
4042 static int
4043 #ifndef MODULE
4044 __init
4045 #endif
4046 pci_inteli960ni_fn(struct pci_dev *dev,
4047 struct pci_board *board,
4048 int enable)
4050 unsigned long oldval;
4052 if (!(board->subdevice & 0x1000))
4053 return(-1);
4055 if (!enable) /* is there something to deinit? */
4056 return(0);
4058 #ifdef SERIAL_DEBUG_PCI
4059 printk(KERN_DEBUG " Subsystem ID %lx (intel 960)\n",
4060 (unsigned long) board->subdevice);
4061 #endif
4062 /* is firmware started? */
4063 pci_read_config_dword(dev, 0x44, (void*) &oldval);
4064 if (oldval == 0x00001000L) { /* RESET value */
4065 printk(KERN_DEBUG "Local i960 firmware missing");
4066 return(-1);
4068 return(0);
4073 * This is the configuration table for all of the PCI serial boards
4074 * which we support.
4076 static struct pci_board pci_boards[] __initdata = {
4078 * Vendor ID, Device ID,
4079 * Subvendor ID, Subdevice ID,
4080 * PCI Flags, Number of Ports, Base (Maximum) Baud Rate,
4081 * Offset to get to next UART's registers,
4082 * Register shift to use for memory-mapped I/O,
4083 * Initialization function, first UART offset
4085 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4086 PCI_SUBVENDOR_ID_CONNECT_TECH,
4087 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232,
4088 SPCI_FL_BASE1, 8, 1382400 },
4089 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4090 PCI_SUBVENDOR_ID_CONNECT_TECH,
4091 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232,
4092 SPCI_FL_BASE1, 4, 1382400 },
4093 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4094 PCI_SUBVENDOR_ID_CONNECT_TECH,
4095 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232,
4096 SPCI_FL_BASE1, 2, 1382400 },
4097 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4098 PCI_SUBVENDOR_ID_CONNECT_TECH,
4099 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232,
4100 SPCI_FL_BASE1, 8, 1382400 },
4101 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4102 PCI_SUBVENDOR_ID_CONNECT_TECH,
4103 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232,
4104 SPCI_FL_BASE1, 4, 1382400 },
4105 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4106 PCI_SUBVENDOR_ID_CONNECT_TECH,
4107 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232,
4108 SPCI_FL_BASE1, 2, 1382400 },
4109 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4110 PCI_SUBVENDOR_ID_CONNECT_TECH,
4111 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485,
4112 SPCI_FL_BASE1, 8, 921600 },
4113 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4114 PCI_SUBVENDOR_ID_CONNECT_TECH,
4115 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4,
4116 SPCI_FL_BASE1, 8, 921600 },
4117 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4118 PCI_SUBVENDOR_ID_CONNECT_TECH,
4119 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485,
4120 SPCI_FL_BASE1, 4, 921600 },
4121 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4122 PCI_SUBVENDOR_ID_CONNECT_TECH,
4123 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2,
4124 SPCI_FL_BASE1, 4, 921600 },
4125 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960,
4126 PCI_SUBVENDOR_ID_CONNECT_TECH,
4127 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485,
4128 SPCI_FL_BASE1, 2, 921600 },
4129 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4130 PCI_SUBVENDOR_ID_CONNECT_TECH,
4131 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485,
4132 SPCI_FL_BASE1, 8, 921600 },
4133 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4134 PCI_SUBVENDOR_ID_CONNECT_TECH,
4135 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4,
4136 SPCI_FL_BASE1, 8, 921600 },
4137 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4138 PCI_SUBVENDOR_ID_CONNECT_TECH,
4139 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485,
4140 SPCI_FL_BASE1, 4, 921600 },
4141 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4142 PCI_SUBVENDOR_ID_CONNECT_TECH,
4143 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2,
4144 SPCI_FL_BASE1, 4, 921600 },
4145 { PCI_VENDOR_ID_V3, PCI_DEVICE_ID_V3_V960V2,
4146 PCI_SUBVENDOR_ID_CONNECT_TECH,
4147 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485,
4148 SPCI_FL_BASE1, 2, 921600 },
4149 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_U530,
4150 PCI_ANY_ID, PCI_ANY_ID,
4151 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 1, 115200 },
4152 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM2,
4153 PCI_ANY_ID, PCI_ANY_ID,
4154 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 115200 },
4155 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM422,
4156 PCI_ANY_ID, PCI_ANY_ID,
4157 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 115200 },
4158 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM232,
4159 PCI_ANY_ID, PCI_ANY_ID,
4160 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 115200 },
4161 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM4,
4162 PCI_ANY_ID, PCI_ANY_ID,
4163 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 115200 },
4164 { PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8,
4165 PCI_ANY_ID, PCI_ANY_ID,
4166 SPCI_FL_BASE2, 8, 115200 },
4167 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_GTEK_SERIAL2,
4168 PCI_ANY_ID, PCI_ANY_ID,
4169 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 115200 },
4170 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM200,
4171 PCI_ANY_ID, PCI_ANY_ID,
4172 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600 },
4173 /* VScom SPCOM800, from sl@s.pl */
4174 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM800,
4175 PCI_ANY_ID, PCI_ANY_ID,
4176 SPCI_FL_BASE2, 8, 921600 },
4177 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4178 PCI_SUBVENDOR_ID_KEYSPAN,
4179 PCI_SUBDEVICE_ID_KEYSPAN_SX2,
4180 SPCI_FL_BASE2, 2, 921600, /* IOMEM */
4181 0x400, 7, pci_plx9050_fn },
4182 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_QUADMODEM,
4183 PCI_ANY_ID, PCI_ANY_ID,
4184 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600,
4185 0x400, 7, pci_plx9050_fn },
4186 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_DUALMODEM,
4187 PCI_ANY_ID, PCI_ANY_ID,
4188 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4189 0x400, 7, pci_plx9050_fn },
4190 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4191 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4192 PCI_SUBDEVICE_ID_CHASE_PCIFAST4,
4193 SPCI_FL_BASE2, 4, 460800 },
4194 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4195 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4196 PCI_SUBDEVICE_ID_CHASE_PCIFAST8,
4197 SPCI_FL_BASE2, 8, 460800 },
4198 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4199 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4200 PCI_SUBDEVICE_ID_CHASE_PCIFAST16,
4201 SPCI_FL_BASE2, 16, 460800 },
4202 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4203 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
4204 PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC,
4205 SPCI_FL_BASE2, 16, 460800 },
4206 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4207 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
4208 PCI_SUBDEVICE_ID_CHASE_PCIRAS4,
4209 SPCI_FL_BASE2, 4, 460800 },
4210 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
4211 PCI_SUBVENDOR_ID_CHASE_PCIRAS,
4212 PCI_SUBDEVICE_ID_CHASE_PCIRAS8,
4213 SPCI_FL_BASE2, 8, 460800 },
4214 /* Megawolf Romulus PCI Serial Card, from Mike Hudson */
4215 /* (Exoray@isys.ca) */
4216 { PCI_VENDOR_ID_PLX, PCI_VENDOR_ID_PLX_ROMULUS,
4217 0x10b5, 0x106a,
4218 SPCI_FL_BASE2, 4, 921600,
4219 0x20, 2, pci_plx9050_fn, 0x03 },
4220 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_QSC100,
4221 PCI_ANY_ID, PCI_ANY_ID,
4222 SPCI_FL_BASE1, 4, 115200 },
4223 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_DSC100,
4224 PCI_ANY_ID, PCI_ANY_ID,
4225 SPCI_FL_BASE1, 2, 115200 },
4226 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100D,
4227 PCI_ANY_ID, PCI_ANY_ID,
4228 SPCI_FL_BASE1, 8, 115200 },
4229 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_ESC100M,
4230 PCI_ANY_ID, PCI_ANY_ID,
4231 SPCI_FL_BASE1, 8, 115200 },
4232 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_OXSEMI_16PCI954,
4233 PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4,
4234 SPCI_FL_BASE0 , 4, 921600 },
4235 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
4236 PCI_ANY_ID, PCI_ANY_ID,
4237 SPCI_FL_BASE0 , 4, 115200 },
4238 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952,
4239 PCI_ANY_ID, PCI_ANY_ID,
4240 SPCI_FL_BASE0 , 2, 115200 },
4241 /* This board uses the size of PCI Base region 0 to
4242 * signal now many ports are available */
4243 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI95N,
4244 PCI_ANY_ID, PCI_ANY_ID,
4245 SPCI_FL_BASE0 | SPCI_FL_REGION_SZ_CAP, 32, 115200 },
4246 { PCI_VENDOR_ID_TIMEDIA, PCI_DEVICE_ID_TIMEDIA_1889,
4247 PCI_ANY_ID, PCI_ANY_ID,
4248 SPCI_FL_BASE0 , 2, 921600 },
4249 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DSERIAL,
4250 PCI_ANY_ID, PCI_ANY_ID,
4251 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
4252 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_A,
4253 PCI_ANY_ID, PCI_ANY_ID,
4254 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
4255 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUATRO_B,
4256 PCI_ANY_ID, PCI_ANY_ID,
4257 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 },
4258 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_PLUS,
4259 PCI_ANY_ID, PCI_ANY_ID,
4260 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 460800 },
4261 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_A,
4262 PCI_ANY_ID, PCI_ANY_ID,
4263 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 460800 },
4264 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_QUAD_B,
4265 PCI_ANY_ID, PCI_ANY_ID,
4266 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 460800 },
4267 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_SSERIAL,
4268 PCI_ANY_ID, PCI_ANY_ID,
4269 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 },
4270 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PORT_650,
4271 PCI_ANY_ID, PCI_ANY_ID,
4272 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 460800 },
4273 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_550,
4274 PCI_ANY_ID, PCI_ANY_ID,
4275 SPCI_FL_BASE2, 1, 460800,
4276 0, 0, pci_siig10x_fn },
4277 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_650,
4278 PCI_ANY_ID, PCI_ANY_ID,
4279 SPCI_FL_BASE2, 1, 460800,
4280 0, 0, pci_siig10x_fn },
4281 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_10x_850,
4282 PCI_ANY_ID, PCI_ANY_ID,
4283 SPCI_FL_BASE2, 1, 460800,
4284 0, 0, pci_siig10x_fn },
4285 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550,
4286 PCI_ANY_ID, PCI_ANY_ID,
4287 SPCI_FL_BASE2, 1, 921600,
4288 0, 0, pci_siig10x_fn },
4289 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650,
4290 PCI_ANY_ID, PCI_ANY_ID,
4291 SPCI_FL_BASE2, 1, 921600,
4292 0, 0, pci_siig10x_fn },
4293 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850,
4294 PCI_ANY_ID, PCI_ANY_ID,
4295 SPCI_FL_BASE2, 1, 921600,
4296 0, 0, pci_siig10x_fn },
4297 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_550,
4298 PCI_ANY_ID, PCI_ANY_ID,
4299 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4300 0, 0, pci_siig10x_fn },
4301 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_650,
4302 PCI_ANY_ID, PCI_ANY_ID,
4303 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4304 0, 0, pci_siig10x_fn },
4305 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_10x_850,
4306 PCI_ANY_ID, PCI_ANY_ID,
4307 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4308 0, 0, pci_siig10x_fn },
4309 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550,
4310 PCI_ANY_ID, PCI_ANY_ID,
4311 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4312 0, 0, pci_siig10x_fn },
4313 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650,
4314 PCI_ANY_ID, PCI_ANY_ID,
4315 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4316 0, 0, pci_siig10x_fn },
4317 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850,
4318 PCI_ANY_ID, PCI_ANY_ID,
4319 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 921600,
4320 0, 0, pci_siig10x_fn },
4321 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_550,
4322 PCI_ANY_ID, PCI_ANY_ID,
4323 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600,
4324 0, 0, pci_siig10x_fn },
4325 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_650,
4326 PCI_ANY_ID, PCI_ANY_ID,
4327 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600,
4328 0, 0, pci_siig10x_fn },
4329 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_10x_850,
4330 PCI_ANY_ID, PCI_ANY_ID,
4331 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 4, 921600,
4332 0, 0, pci_siig10x_fn },
4333 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_550,
4334 PCI_ANY_ID, PCI_ANY_ID,
4335 SPCI_FL_BASE0, 1, 921600,
4336 0, 0, pci_siig20x_fn },
4337 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_650,
4338 PCI_ANY_ID, PCI_ANY_ID,
4339 SPCI_FL_BASE0, 1, 921600,
4340 0, 0, pci_siig20x_fn },
4341 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S_20x_850,
4342 PCI_ANY_ID, PCI_ANY_ID,
4343 SPCI_FL_BASE0, 1, 921600,
4344 0, 0, pci_siig20x_fn },
4345 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550,
4346 PCI_ANY_ID, PCI_ANY_ID,
4347 SPCI_FL_BASE0, 1, 921600,
4348 0, 0, pci_siig20x_fn },
4349 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650,
4350 PCI_ANY_ID, PCI_ANY_ID,
4351 SPCI_FL_BASE0, 1, 921600,
4352 0, 0, pci_siig20x_fn },
4353 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850,
4354 PCI_ANY_ID, PCI_ANY_ID,
4355 SPCI_FL_BASE0, 1, 921600,
4356 0, 0, pci_siig20x_fn },
4357 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550,
4358 PCI_ANY_ID, PCI_ANY_ID,
4359 SPCI_FL_BASE0, 1, 921600,
4360 0, 0, pci_siig20x_fn },
4361 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650,
4362 PCI_ANY_ID, PCI_ANY_ID,
4363 SPCI_FL_BASE0, 1, 921600,
4364 0, 0, pci_siig20x_fn },
4365 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850,
4366 PCI_ANY_ID, PCI_ANY_ID,
4367 SPCI_FL_BASE0, 1, 921600,
4368 0, 0, pci_siig20x_fn },
4369 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_550,
4370 PCI_ANY_ID, PCI_ANY_ID,
4371 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4372 0, 0, pci_siig20x_fn },
4373 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_650,
4374 PCI_ANY_ID, PCI_ANY_ID,
4375 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4376 0, 0, pci_siig20x_fn },
4377 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S_20x_850,
4378 PCI_ANY_ID, PCI_ANY_ID,
4379 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4380 0, 0, pci_siig20x_fn },
4381 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550,
4382 PCI_ANY_ID, PCI_ANY_ID,
4383 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4384 0, 0, pci_siig20x_fn },
4385 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650,
4386 PCI_ANY_ID, PCI_ANY_ID,
4387 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4388 0, 0, pci_siig20x_fn },
4389 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850,
4390 PCI_ANY_ID, PCI_ANY_ID,
4391 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 921600,
4392 0, 0, pci_siig20x_fn },
4393 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_550,
4394 PCI_ANY_ID, PCI_ANY_ID,
4395 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 4, 921600,
4396 0, 0, pci_siig20x_fn },
4397 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_650,
4398 PCI_ANY_ID, PCI_ANY_ID,
4399 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 4, 921600,
4400 0, 0, pci_siig20x_fn },
4401 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_4S_20x_850,
4402 PCI_ANY_ID, PCI_ANY_ID,
4403 SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 4, 921600,
4404 0, 0, pci_siig20x_fn },
4405 /* Computone devices submitted by Doug McNash dmcnash@computone.com */
4406 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4407 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG4,
4408 SPCI_FL_BASE0, 4, 921600, /* IOMEM */
4409 0x40, 2, NULL, 0x200 },
4410 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4411 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG8,
4412 SPCI_FL_BASE0, 8, 921600, /* IOMEM */
4413 0x40, 2, NULL, 0x200 },
4414 { PCI_VENDOR_ID_COMPUTONE, PCI_DEVICE_ID_COMPUTONE_PG,
4415 PCI_SUBVENDOR_ID_COMPUTONE, PCI_SUBDEVICE_ID_COMPUTONE_PG6,
4416 SPCI_FL_BASE0, 6, 921600, /* IOMEM */
4417 0x40, 2, NULL, 0x200 },
4418 /* Digitan DS560-558, from jimd@esoft.com */
4419 { PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_ATT_VENUS_MODEM,
4420 PCI_ANY_ID, PCI_ANY_ID,
4421 SPCI_FL_BASE1, 1, 115200 },
4422 /* 3Com US Robotics 56k Voice Internal PCI model 5610 */
4423 { PCI_VENDOR_ID_USR, 0x1008,
4424 PCI_ANY_ID, PCI_ANY_ID,
4425 SPCI_FL_BASE0, 1, 115200 },
4426 /* Titan Electronic cards */
4427 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100,
4428 PCI_ANY_ID, PCI_ANY_ID,
4429 SPCI_FL_BASE0, 1, 921600 },
4430 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200,
4431 PCI_ANY_ID, PCI_ANY_ID,
4432 SPCI_FL_BASE0, 2, 921600 },
4433 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400,
4434 PCI_ANY_ID, PCI_ANY_ID,
4435 SPCI_FL_BASE0, 4, 921600 },
4436 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800B,
4437 PCI_ANY_ID, PCI_ANY_ID,
4438 SPCI_FL_BASE0, 4, 921600 },
4439 /* EKF addition for i960 Boards form EKF with serial port */
4440 { PCI_VENDOR_ID_INTEL, 0x1960,
4441 0xE4BF, PCI_ANY_ID,
4442 SPCI_FL_BASE0, 32, 921600, /* max 256 ports */
4443 8<<2, 2, pci_inteli960ni_fn, 0x10000},
4444 /* RAStel 2 port modem, gerg@moreton.com.au */
4445 { PCI_VENDOR_ID_MORETON, PCI_DEVICE_ID_RASTEL_2PORT,
4446 PCI_ANY_ID, PCI_ANY_ID,
4447 SPCI_FL_BASE2 | SPCI_FL_BASE_TABLE, 2, 115200 },
4449 * Untested PCI modems, sent in from various folks...
4451 /* Elsa Model 56K PCI Modem, from Andreas Rath <arh@01019freenet.de> */
4452 { PCI_VENDOR_ID_ROCKWELL, 0x1004,
4453 0x1048, 0x1500,
4454 SPCI_FL_BASE1, 1, 115200 },
4455 #ifdef CONFIG_DDB5074
4457 * NEC Vrc-5074 (Nile 4) builtin UART.
4458 * Conditionally compiled in since this is a motherboard device.
4460 { PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_NILE4,
4461 PCI_ANY_ID, PCI_ANY_ID,
4462 SPCI_FL_BASE0, 1, 520833,
4463 64, 3, NULL, 0x300 },
4464 #endif
4465 /* Generic serial board */
4466 { 0, 0,
4467 0, 0,
4468 SPCI_FL_BASE0, 1, 115200 },
4472 * Given a complete unknown PCI device, try to use some heuristics to
4473 * guess what the configuration might be, based on the pitiful PCI
4474 * serial specs. Returns 0 on success, 1 on failure.
4476 static int _INLINE_ serial_pci_guess_board(struct pci_dev *dev,
4477 struct pci_board *board)
4479 int num_iomem = 0, num_port = 0, first_port = -1;
4480 int i;
4483 * If it is not a communications device or the programming
4484 * interface is greater than 6, give up.
4486 * (Should we try to make guesses for multiport serial devices
4487 * later?)
4489 if ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL ||
4490 (dev->class & 0xff) > 6)
4491 return 1;
4493 for (i=0; i < 6; i++) {
4494 if (IS_PCI_REGION_IOPORT(dev, i)) {
4495 num_port = 0;
4496 if (first_port == -1)
4497 first_port = i;
4498 } else {
4499 num_iomem++;
4504 * If there is 1 or 0 iomem regions, and exactly one port, use
4505 * it.
4507 if (num_iomem <= 1 && num_port == 1) {
4508 board->flags = first_port;
4509 return 0;
4511 return 1;
4517 * Query PCI space for known serial boards
4518 * If found, add them to the PCI device space in rs_table[]
4520 * Accept a maximum of eight boards
4523 static void __init probe_serial_pci(void)
4525 struct pci_dev *dev = NULL;
4526 struct pci_board *board;
4528 #ifdef SERIAL_DEBUG_PCI
4529 printk(KERN_DEBUG "Entered probe_serial_pci()\n");
4530 #endif
4532 pci_for_each_dev(dev) {
4533 for (board = pci_boards; board->vendor; board++) {
4534 if (board->vendor != (unsigned short) PCI_ANY_ID &&
4535 dev->vendor != board->vendor)
4536 continue;
4537 if (board->device != (unsigned short) PCI_ANY_ID &&
4538 dev->device != board->device)
4539 continue;
4540 if (board->subvendor != (unsigned short) PCI_ANY_ID &&
4541 pci_get_subvendor(dev) != board->subvendor)
4542 continue;
4543 if (board->subdevice != (unsigned short) PCI_ANY_ID &&
4544 pci_get_subdevice(dev) != board->subdevice)
4545 continue;
4546 break;
4549 if (board->vendor == 0 && serial_pci_guess_board(dev, board))
4550 continue;
4552 start_pci_pnp_board(dev, board);
4555 #ifdef SERIAL_DEBUG_PCI
4556 printk(KERN_DEBUG "Leaving probe_serial_pci() (probe finished)\n");
4557 #endif
4558 return;
4561 #endif /* ENABLE_SERIAL_PCI */
4563 #ifdef ENABLE_SERIAL_PNP
4565 struct pnp_board {
4566 unsigned short vendor;
4567 unsigned short device;
4570 static struct pnp_board pnp_devices[] __initdata = {
4571 /* Archtek America Corp. */
4572 /* Archtek SmartLink Modem 3334BT Plug & Play */
4573 { ISAPNP_VENDOR('A', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
4574 /* Anchor Datacomm BV */
4575 /* SXPro 144 External Data Fax Modem Plug & Play */
4576 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0001) },
4577 /* SXPro 288 External Data Fax Modem Plug & Play */
4578 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0002) },
4579 /* Rockwell 56K ACF II Fax+Data+Voice Modem */
4580 { ISAPNP_VENDOR('A', 'K', 'Y'), ISAPNP_DEVICE(0x1021) },
4581 /* AZT3005 PnP SOUND DEVICE */
4582 { ISAPNP_VENDOR('A', 'Z', 'T'), ISAPNP_DEVICE(0x4001) },
4583 /* Best Data Products Inc. Smart One 336F PnP Modem */
4584 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
4585 /* Boca Research */
4586 /* Boca Complete Ofc Communicator 14.4 Data-FAX */
4587 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
4588 /* Boca Research 33,600 ACF Modem */
4589 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x1400) },
4590 /* Boca 33.6 Kbps Internal FD34FSVD */
4591 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x3400) },
4592 /* Boca 33.6 Kbps Internal FD34FSVD */
4593 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
4594 /* Best Data Products Inc. Smart One 336F PnP Modem */
4595 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
4596 /* Computer Peripherals Inc */
4597 /* EuroViVa CommCenter-33.6 SP PnP */
4598 { ISAPNP_VENDOR('C', 'P', 'I'), ISAPNP_DEVICE(0x4050) },
4599 /* Creative Labs */
4600 /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
4601 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3001) },
4602 /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
4603 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3011) },
4604 /* Creative */
4605 /* Creative Modem Blaster Flash56 DI5601-1 */
4606 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x1032) },
4607 /* Creative Modem Blaster V.90 DI5660 */
4608 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x2001) },
4609 /* FUJITSU */
4610 /* Fujitsu 33600 PnP-I2 R Plug & Play */
4611 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0202) },
4612 /* Fujitsu FMV-FX431 Plug & Play */
4613 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0205) },
4614 /* Fujitsu 33600 PnP-I4 R Plug & Play */
4615 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0206) },
4616 /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
4617 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0209) },
4618 /* Archtek America Corp. */
4619 /* Archtek SmartLink Modem 3334BT Plug & Play */
4620 { ISAPNP_VENDOR('G', 'V', 'C'), ISAPNP_DEVICE(0x000F) },
4621 /* Hayes */
4622 /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
4623 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x0001) },
4624 /* Hayes Optima 336 V.34 + FAX + Voice PnP */
4625 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000C) },
4626 /* Hayes Optima 336B V.34 + FAX + Voice PnP */
4627 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000D) },
4628 /* Hayes Accura 56K Ext Fax Modem PnP */
4629 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5670) },
4630 /* Hayes Accura 56K Ext Fax Modem PnP */
4631 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5674) },
4632 /* Hayes Accura 56K Fax Modem PnP */
4633 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5675) },
4634 /* Hayes 288, V.34 + FAX */
4635 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF000) },
4636 /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
4637 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF001) },
4638 /* IBM */
4639 /* IBM Thinkpad 701 Internal Modem Voice */
4640 { ISAPNP_VENDOR('I', 'B', 'M'), ISAPNP_DEVICE(0x0033) },
4641 /* Intertex */
4642 /* Intertex 28k8 33k6 Voice EXT PnP */
4643 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC801) },
4644 /* Intertex 33k6 56k Voice EXT PnP */
4645 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC901) },
4646 /* Intertex 28k8 33k6 Voice SP EXT PnP */
4647 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD801) },
4648 /* Intertex 33k6 56k Voice SP EXT PnP */
4649 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD901) },
4650 /* Intertex 28k8 33k6 Voice SP INT PnP */
4651 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF401) },
4652 /* Intertex 28k8 33k6 Voice SP EXT PnP */
4653 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF801) },
4654 /* Intertex 33k6 56k Voice SP EXT PnP */
4655 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF901) },
4656 /* Kortex International */
4657 /* KORTEX 28800 Externe PnP */
4658 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0x4522) },
4659 /* KXPro 33.6 Vocal ASVD PnP */
4660 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0xF661) },
4661 /* Lasat */
4662 /* LASAT Internet 33600 PnP */
4663 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4040) },
4664 /* Lasat Safire 560 PnP */
4665 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4540) },
4666 /* Lasat Safire 336 PnP */
4667 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x5440) },
4668 /* Microcom, Inc. */
4669 /* Microcom TravelPorte FAST V.34 Plug & Play */
4670 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x281) },
4671 /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
4672 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0336) },
4673 /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
4674 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0339) },
4675 /* Microcom DeskPorte 28.8P Plug & Play */
4676 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0342) },
4677 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
4678 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
4679 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
4680 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
4681 /* Microcom DeskPorte 28.8S Internal Plug & Play */
4682 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0502) },
4683 /* Motorola */
4684 /* Motorola BitSURFR Plug & Play */
4685 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1105) },
4686 /* Motorola TA210 Plug & Play */
4687 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1111) },
4688 /* Motorola HMTA 200 (ISDN) Plug & Play */
4689 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1114) },
4690 /* Motorola BitSURFR Plug & Play */
4691 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1115) },
4692 /* Motorola Lifestyle 28.8 Internal */
4693 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1190) },
4694 /* Motorola V.3400 Plug & Play */
4695 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1501) },
4696 /* Motorola Lifestyle 28.8 V.34 Plug & Play */
4697 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1502) },
4698 /* Motorola Power 28.8 V.34 Plug & Play */
4699 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1505) },
4700 /* Motorola ModemSURFR External 28.8 Plug & Play */
4701 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1509) },
4702 /* Motorola Premier 33.6 Desktop Plug & Play */
4703 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150A) },
4704 /* Motorola VoiceSURFR 56K External PnP */
4705 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150F) },
4706 /* Motorola ModemSURFR 56K External PnP */
4707 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1510) },
4708 /* Motorola ModemSURFR 56K Internal PnP */
4709 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1550) },
4710 /* Motorola ModemSURFR Internal 28.8 Plug & Play */
4711 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1560) },
4712 /* Motorola Premier 33.6 Internal Plug & Play */
4713 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1580) },
4714 /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
4715 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15B0) },
4716 /* Motorola VoiceSURFR 56K Internal PnP */
4717 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15F0) },
4718 /* Com 1 */
4719 /* Deskline K56 Phone System PnP */
4720 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00A1) },
4721 /* PC Rider K56 Phone System PnP */
4722 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00F2) },
4723 /* Pace 56 Voice Internal Plug & Play Modem */
4724 { ISAPNP_VENDOR('P', 'M', 'C'), ISAPNP_DEVICE(0x2430) },
4725 /* Generic */
4726 /* Generic standard PC COM port */
4727 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
4728 /* Generic 16550A-compatible COM port */
4729 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
4730 /* Compaq 14400 Modem */
4731 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC000) },
4732 /* Compaq 2400/9600 Modem */
4733 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC001) },
4734 /* Dial-Up Networking Serial Cable between 2 PCs */
4735 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC031) },
4736 /* Dial-Up Networking Parallel Cable between 2 PCs */
4737 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC032) },
4738 /* Standard 9600 bps Modem */
4739 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC100) },
4740 /* Standard 14400 bps Modem */
4741 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC101) },
4742 /* Standard 28800 bps Modem*/
4743 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC102) },
4744 /* Standard Modem*/
4745 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC103) },
4746 /* Standard 9600 bps Modem*/
4747 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC104) },
4748 /* Standard 14400 bps Modem*/
4749 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC105) },
4750 /* Standard 28800 bps Modem*/
4751 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC106) },
4752 /* Standard Modem */
4753 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC107) },
4754 /* Standard 9600 bps Modem */
4755 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC108) },
4756 /* Standard 14400 bps Modem */
4757 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC109) },
4758 /* Standard 28800 bps Modem */
4759 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10A) },
4760 /* Standard Modem */
4761 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10B) },
4762 /* Standard 9600 bps Modem */
4763 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10C) },
4764 /* Standard 14400 bps Modem */
4765 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10D) },
4766 /* Standard 28800 bps Modem */
4767 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10E) },
4768 /* Standard Modem */
4769 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10F) },
4770 /* Standard PCMCIA Card Modem */
4771 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x2000) },
4772 /* Rockwell */
4773 /* Modular Technology */
4774 /* Rockwell 33.6 DPF Internal PnP */
4775 /* Modular Technology 33.6 Internal PnP */
4776 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0030) },
4777 /* Kortex International */
4778 /* KORTEX 14400 Externe PnP */
4779 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0100) },
4780 /* Viking Components, Inc */
4781 /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
4782 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x4920) },
4783 /* Rockwell */
4784 /* British Telecom */
4785 /* Modular Technology */
4786 /* Rockwell 33.6 DPF External PnP */
4787 /* BT Prologue 33.6 External PnP */
4788 /* Modular Technology 33.6 External PnP */
4789 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x00A0) },
4790 /* Viking 56K FAX INT */
4791 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x0262) },
4792 /* SupraExpress 28.8 Data/Fax PnP modem */
4793 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1310) },
4794 /* SupraExpress 33.6 Data/Fax PnP modem */
4795 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1421) },
4796 /* SupraExpress 33.6 Data/Fax PnP modem */
4797 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1590) },
4798 /* SupraExpress 33.6 Data/Fax PnP modem */
4799 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1760) },
4800 /* Phoebe Micro */
4801 /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
4802 { ISAPNP_VENDOR('T', 'E', 'X'), ISAPNP_DEVICE(0x0011) },
4803 /* Archtek America Corp. */
4804 /* Archtek SmartLink Modem 3334BT Plug & Play */
4805 { ISAPNP_VENDOR('U', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
4806 /* 3Com Corp. */
4807 /* Gateway Telepath IIvi 33.6 */
4808 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0000) },
4809 /* Sportster Vi 14.4 PnP FAX Voicemail */
4810 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0004) },
4811 /* U.S. Robotics 33.6K Voice INT PnP */
4812 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0006) },
4813 /* U.S. Robotics 33.6K Voice EXT PnP */
4814 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0007) },
4815 /* U.S. Robotics 33.6K Voice INT PnP */
4816 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2002) },
4817 /* U.S. Robotics 56K Voice INT PnP */
4818 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2070) },
4819 /* U.S. Robotics 56K Voice EXT PnP */
4820 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2080) },
4821 /* U.S. Robotics 56K FAX INT */
4822 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3031) },
4823 /* U.S. Robotics 56K Voice INT PnP */
4824 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3070) },
4825 /* U.S. Robotics 56K Voice EXT PnP */
4826 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3080) },
4827 /* U.S. Robotics 56K Voice INT PnP */
4828 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3090) },
4829 /* U.S. Robotics 56K Message */
4830 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9100) },
4831 /* U.S. Robotics 56K FAX EXT PnP*/
4832 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9160) },
4833 /* U.S. Robotics 56K FAX INT PnP*/
4834 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9170) },
4835 /* U.S. Robotics 56K Voice EXT PnP*/
4836 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9180) },
4837 /* U.S. Robotics 56K Voice INT PnP*/
4838 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9190) },
4839 { 0, }
4842 static void inline avoid_irq_share(struct pci_dev *dev)
4844 int i, map = 0x1FF8;
4845 struct serial_state *state = rs_table;
4846 struct isapnp_irq *irq;
4847 struct isapnp_resources *res = dev->sysdata;
4849 for (i = 0; i < NR_PORTS; i++) {
4850 if (state->type != PORT_UNKNOWN)
4851 clear_bit(state->irq, &map);
4852 state++;
4855 for ( ; res; res = res->alt)
4856 for(irq = res->irq; irq; irq = irq->next)
4857 irq->map = map;
4860 static char *modem_names[] __initdata = {
4861 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
4862 "56K", "56k", "K56", "33.6", "28.8", "14.4",
4863 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
4864 "33600", "28800", "14400", "V.90", "V.34", "V.32", 0
4867 static int __init check_name(char *name)
4869 char **tmp = modem_names;
4871 while (*tmp) {
4872 if (strstr(name, *tmp))
4873 return 1;
4874 tmp++;
4876 return 0;
4879 static int inline check_compatible_id(struct pci_dev *dev)
4881 int i;
4882 for (i = 0; i < DEVICE_COUNT_COMPATIBLE; i++)
4883 if ((dev->vendor_compatible[i] ==
4884 ISAPNP_VENDOR('P', 'N', 'P')) &&
4885 (swab16(dev->device_compatible[i]) >= 0xc000) &&
4886 (swab16(dev->device_compatible[i]) <= 0xdfff))
4887 return 0;
4888 return 1;
4892 * Given a complete unknown ISA PnP device, try to use some heuristics to
4893 * detect modems. Currently use such heuristic set:
4894 * - dev->name or dev->bus->name must contain "modem" substring;
4895 * - device must have only one IO region (8 byte long) with base adress
4896 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8.
4898 * Such detection looks very ugly, but can detect at least some of numerous
4899 * ISA PnP modems, alternatively we must hardcode all modems in pnp_devices[]
4900 * table.
4902 static int _INLINE_ serial_pnp_guess_board(struct pci_dev *dev,
4903 struct pci_board *board)
4905 struct isapnp_resources *res = (struct isapnp_resources *)dev->sysdata;
4906 struct isapnp_resources *resa;
4908 if (!(check_name(dev->name) || check_name(dev->bus->name)) &&
4909 !(check_compatible_id(dev)))
4910 return 1;
4912 if (!res || res->next)
4913 return 1;
4915 for (resa = res->alt; resa; resa = resa->alt) {
4916 struct isapnp_port *port;
4917 for (port = res->port; port; port = port->next)
4918 if ((port->size == 8) &&
4919 ((port->min == 0x2f8) ||
4920 (port->min == 0x3f8) ||
4921 (port->min == 0x2e8) ||
4922 (port->min == 0x3e8)))
4923 return 0;
4926 return 1;
4929 static void __init probe_serial_pnp(void)
4931 struct pci_dev *dev = NULL;
4932 struct pnp_board *pnp_board;
4933 struct pci_board board;
4935 #ifdef SERIAL_DEBUG_PNP
4936 printk("Entered probe_serial_pnp()\n");
4937 #endif
4938 if (!isapnp_present()) {
4939 #ifdef SERIAL_DEBUG_PNP
4940 printk("Leaving probe_serial_pnp() (no isapnp)\n");
4941 #endif
4942 return;
4945 isapnp_for_each_dev(dev) {
4946 if (dev->active)
4947 continue;
4949 memset(&board, 0, sizeof(board));
4950 board.flags = SPCI_FL_BASE0 | SPCI_FL_PNPDEFAULT;
4951 board.num_ports = 1;
4952 board.base_baud = 115200;
4954 for (pnp_board = pnp_devices; pnp_board->vendor; pnp_board++)
4955 if ((dev->vendor == pnp_board->vendor) &&
4956 (dev->device == pnp_board->device))
4957 break;
4959 if (pnp_board->vendor) {
4960 board.vendor = pnp_board->vendor;
4961 board.device = pnp_board->device;
4962 /* Special case that's more efficient to hardcode */
4963 if ((board.vendor == ISAPNP_VENDOR('A', 'K', 'Y') &&
4964 board.device == ISAPNP_DEVICE(0x1021)))
4965 board.flags |= SPCI_FL_NO_SHIRQ;
4966 } else {
4967 if (serial_pnp_guess_board(dev, &board))
4968 continue;
4971 if (board.flags & SPCI_FL_NO_SHIRQ)
4972 avoid_irq_share(dev);
4973 start_pci_pnp_board(dev, &board);
4976 #ifdef SERIAL_DEBUG_PNP
4977 printk("Leaving probe_serial_pnp() (probe finished)\n");
4978 #endif
4979 return;
4982 #endif /* ENABLE_SERIAL_PNP */
4985 * The serial driver boot-time initialization code!
4987 static int __init rs_init(void)
4989 int i;
4990 struct serial_state * state;
4992 if (serial_timer.function) {
4993 printk("RS_TIMER already set, another serial driver "
4994 "already loaded?\n");
4995 #ifdef MODULE
4996 printk("Can't load serial driver module over built-in "
4997 "serial driver\n");
4998 #endif
4999 return -EBUSY;
5002 init_bh(SERIAL_BH, do_serial_bh);
5003 init_timer(&serial_timer);
5004 serial_timer.function = rs_timer;
5005 mod_timer(&serial_timer, jiffies + RS_STROBE_TIME);
5007 for (i = 0; i < NR_IRQS; i++) {
5008 IRQ_ports[i] = 0;
5009 IRQ_timeout[i] = 0;
5010 #ifdef CONFIG_SERIAL_MULTIPORT
5011 memset(&rs_multiport[i], 0,
5012 sizeof(struct rs_multiport_struct));
5013 #endif
5015 #ifdef CONFIG_SERIAL_CONSOLE
5017 * The interrupt of the serial console port
5018 * can't be shared.
5020 if (sercons.flags & CON_CONSDEV) {
5021 for(i = 0; i < NR_PORTS; i++)
5022 if (i != sercons.index &&
5023 rs_table[i].irq == rs_table[sercons.index].irq)
5024 rs_table[i].irq = 0;
5026 #endif
5027 show_serial_version();
5029 /* Initialize the tty_driver structure */
5031 memset(&serial_driver, 0, sizeof(struct tty_driver));
5032 serial_driver.magic = TTY_DRIVER_MAGIC;
5033 #if (LINUX_VERSION_CODE > 0x20100)
5034 serial_driver.driver_name = "serial";
5035 #endif
5036 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5037 serial_driver.name = "tts/%d";
5038 #else
5039 serial_driver.name = "ttyS";
5040 #endif
5041 serial_driver.major = TTY_MAJOR;
5042 serial_driver.minor_start = 64 + SERIAL_DEV_OFFSET;
5043 serial_driver.num = NR_PORTS;
5044 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
5045 serial_driver.subtype = SERIAL_TYPE_NORMAL;
5046 serial_driver.init_termios = tty_std_termios;
5047 serial_driver.init_termios.c_cflag =
5048 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5049 serial_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
5050 serial_driver.refcount = &serial_refcount;
5051 serial_driver.table = serial_table;
5052 serial_driver.termios = serial_termios;
5053 serial_driver.termios_locked = serial_termios_locked;
5055 serial_driver.open = rs_open;
5056 serial_driver.close = rs_close;
5057 serial_driver.write = rs_write;
5058 serial_driver.put_char = rs_put_char;
5059 serial_driver.flush_chars = rs_flush_chars;
5060 serial_driver.write_room = rs_write_room;
5061 serial_driver.chars_in_buffer = rs_chars_in_buffer;
5062 serial_driver.flush_buffer = rs_flush_buffer;
5063 serial_driver.ioctl = rs_ioctl;
5064 serial_driver.throttle = rs_throttle;
5065 serial_driver.unthrottle = rs_unthrottle;
5066 serial_driver.set_termios = rs_set_termios;
5067 serial_driver.stop = rs_stop;
5068 serial_driver.start = rs_start;
5069 serial_driver.hangup = rs_hangup;
5070 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
5071 serial_driver.break_ctl = rs_break;
5072 #endif
5073 #if (LINUX_VERSION_CODE >= 131343)
5074 serial_driver.send_xchar = rs_send_xchar;
5075 serial_driver.wait_until_sent = rs_wait_until_sent;
5076 serial_driver.read_proc = rs_read_proc;
5077 #endif
5080 * The callout device is just like normal device except for
5081 * major number and the subtype code.
5083 callout_driver = serial_driver;
5084 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5085 callout_driver.name = "cua/%d";
5086 #else
5087 callout_driver.name = "cua";
5088 #endif
5089 callout_driver.major = TTYAUX_MAJOR;
5090 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
5091 #if (LINUX_VERSION_CODE >= 131343)
5092 callout_driver.read_proc = 0;
5093 callout_driver.proc_entry = 0;
5094 #endif
5096 if (tty_register_driver(&serial_driver))
5097 panic("Couldn't register serial driver\n");
5098 if (tty_register_driver(&callout_driver))
5099 panic("Couldn't register callout driver\n");
5101 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
5102 state->magic = SSTATE_MAGIC;
5103 state->line = i;
5104 state->type = PORT_UNKNOWN;
5105 state->custom_divisor = 0;
5106 state->close_delay = 5*HZ/10;
5107 state->closing_wait = 30*HZ;
5108 state->callout_termios = callout_driver.init_termios;
5109 state->normal_termios = serial_driver.init_termios;
5110 state->icount.cts = state->icount.dsr =
5111 state->icount.rng = state->icount.dcd = 0;
5112 state->icount.rx = state->icount.tx = 0;
5113 state->icount.frame = state->icount.parity = 0;
5114 state->icount.overrun = state->icount.brk = 0;
5115 state->irq = irq_cannonicalize(state->irq);
5116 if (state->hub6)
5117 state->io_type = SERIAL_IO_HUB6;
5118 if (state->port && check_region(state->port,8))
5119 continue;
5120 if (state->flags & ASYNC_BOOT_AUTOCONF)
5121 autoconfig(state);
5123 for (i = 0, state = rs_table; i < NR_PORTS; i++,state++) {
5124 if (state->type == PORT_UNKNOWN)
5125 continue;
5126 if ( (state->flags & ASYNC_BOOT_AUTOCONF)
5127 && (state->flags & ASYNC_AUTO_IRQ)
5128 && (state->port != 0))
5129 state->irq = detect_uart_irq(state);
5130 printk(KERN_INFO "ttyS%02d%s at 0x%04lx (irq = %d) is a %s\n",
5131 state->line + SERIAL_DEV_OFFSET,
5132 (state->flags & ASYNC_FOURPORT) ? " FourPort" : "",
5133 state->port, state->irq,
5134 uart_config[state->type].name);
5135 tty_register_devfs(&serial_driver, 0,
5136 serial_driver.minor_start + state->line);
5137 tty_register_devfs(&callout_driver, 0,
5138 callout_driver.minor_start + state->line);
5140 #ifdef ENABLE_SERIAL_PCI
5141 probe_serial_pci();
5142 #endif
5143 #ifdef ENABLE_SERIAL_PNP
5144 probe_serial_pnp();
5145 #endif
5146 return 0;
5150 * register_serial and unregister_serial allows for 16x50 serial ports to be
5151 * configured at run-time, to support PCMCIA modems.
5155 * register_serial - configure a 16x50 serial port at runtime
5156 * @req: request structure
5158 * Configure the serial port specified by the request. If the
5159 * port exists and is in use an error is returned. If the port
5160 * is not currently in the table it is added.
5162 * The port is then probed and if neccessary the IRQ is autodetected
5163 * If this fails an error is returned.
5165 * On success the port is ready to use and the line number is returned.
5168 int register_serial(struct serial_struct *req)
5170 int i;
5171 unsigned long flags;
5172 struct serial_state *state;
5173 struct async_struct *info;
5174 unsigned long port;
5176 port = req->port;
5177 if (HIGH_BITS_OFFSET)
5178 port += (unsigned long) req->port_high << HIGH_BITS_OFFSET;
5180 save_flags(flags); cli();
5181 for (i = 0; i < NR_PORTS; i++) {
5182 if ((rs_table[i].port == port) &&
5183 (rs_table[i].iomem_base == req->iomem_base))
5184 break;
5186 if (i == NR_PORTS) {
5187 for (i = 4; i < NR_PORTS; i++)
5188 if ((rs_table[i].type == PORT_UNKNOWN) &&
5189 (rs_table[i].count == 0))
5190 break;
5192 if (i == NR_PORTS) {
5193 for (i = 0; i < NR_PORTS; i++)
5194 if ((rs_table[i].type == PORT_UNKNOWN) &&
5195 (rs_table[i].count == 0))
5196 break;
5198 if (i == NR_PORTS) {
5199 restore_flags(flags);
5200 return -1;
5202 state = &rs_table[i];
5203 if (rs_table[i].count) {
5204 restore_flags(flags);
5205 printk("Couldn't configure serial #%d (port=%ld,irq=%d): "
5206 "device already open\n", i, port, req->irq);
5207 return -1;
5209 state->irq = req->irq;
5210 state->port = port;
5211 state->flags = req->flags;
5212 state->io_type = req->io_type;
5213 state->iomem_base = req->iomem_base;
5214 state->iomem_reg_shift = req->iomem_reg_shift;
5215 if (req->baud_base)
5216 state->baud_base = req->baud_base;
5217 if ((info = state->info) != NULL) {
5218 info->port = port;
5219 info->flags = req->flags;
5220 info->io_type = req->io_type;
5221 info->iomem_base = req->iomem_base;
5222 info->iomem_reg_shift = req->iomem_reg_shift;
5224 autoconfig(state);
5225 if (state->type == PORT_UNKNOWN) {
5226 restore_flags(flags);
5227 printk("register_serial(): autoconfig failed\n");
5228 return -1;
5230 restore_flags(flags);
5232 if ((state->flags & ASYNC_AUTO_IRQ) && CONFIGURED_SERIAL_PORT(state))
5233 state->irq = detect_uart_irq(state);
5235 printk(KERN_INFO "ttyS%02d at %s 0x%04lx (irq = %d) is a %s\n",
5236 state->line + SERIAL_DEV_OFFSET,
5237 state->iomem_base ? "iomem" : "port",
5238 state->iomem_base ? (unsigned long)state->iomem_base :
5239 state->port, state->irq, uart_config[state->type].name);
5240 tty_register_devfs(&serial_driver, 0,
5241 serial_driver.minor_start + state->line);
5242 tty_register_devfs(&callout_driver, 0,
5243 callout_driver.minor_start + state->line);
5244 return state->line + SERIAL_DEV_OFFSET;
5248 * unregister_serial - deconfigure a 16x50 serial port
5249 * @line: line to deconfigure
5251 * The port specified is deconfigured and its resources are freed. Any
5252 * user of the port is disconnected as if carrier was dropped. Line is
5253 * the port number returned by register_serial().
5256 void unregister_serial(int line)
5258 unsigned long flags;
5259 struct serial_state *state = &rs_table[line];
5261 save_flags(flags); cli();
5262 if (state->info && state->info->tty)
5263 tty_hangup(state->info->tty);
5264 state->type = PORT_UNKNOWN;
5265 printk(KERN_INFO "tty%02d unloaded\n", state->line);
5266 /* These will be hidden, because they are devices that will no longer
5267 * be available to the system. (ie, PCMCIA modems, once ejected)
5269 tty_unregister_devfs(&serial_driver,
5270 serial_driver.minor_start + state->line);
5271 tty_unregister_devfs(&callout_driver,
5272 callout_driver.minor_start + state->line);
5273 restore_flags(flags);
5276 static void __exit rs_fini(void)
5278 unsigned long flags;
5279 int e1, e2;
5280 int i;
5281 struct async_struct *info;
5283 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
5284 del_timer_sync(&serial_timer);
5285 save_flags(flags); cli();
5286 remove_bh(SERIAL_BH);
5287 if ((e1 = tty_unregister_driver(&serial_driver)))
5288 printk("serial: failed to unregister serial driver (%d)\n",
5289 e1);
5290 if ((e2 = tty_unregister_driver(&callout_driver)))
5291 printk("serial: failed to unregister callout driver (%d)\n",
5292 e2);
5293 restore_flags(flags);
5295 for (i = 0; i < NR_PORTS; i++) {
5296 if ((info = rs_table[i].info)) {
5297 rs_table[i].info = NULL;
5298 kfree_s(info, sizeof(struct async_struct));
5300 if ((rs_table[i].type != PORT_UNKNOWN) && rs_table[i].port) {
5301 #ifdef CONFIG_SERIAL_RSA
5302 if (rs_table[i].type == PORT_RSA)
5303 release_region(rs_table[i].port +
5304 UART_RSA_BASE, 16);
5305 else
5306 #endif
5307 release_region(rs_table[i].port, 8);
5309 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5310 if (rs_table[i].iomem_base)
5311 iounmap(rs_table[i].iomem_base);
5312 #endif
5314 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5315 for (i=0; i < serial_pci_board_idx; i++) {
5316 struct pci_board_inst *brd = &serial_pci_board[i];
5318 if (brd->board.init_fn)
5319 (brd->board.init_fn)(brd->dev, &brd->board, 0);
5321 if (DEACTIVATE_FUNC(brd->dev))
5322 (DEACTIVATE_FUNC(brd->dev))(brd->dev);
5324 #endif
5325 if (tmp_buf) {
5326 unsigned long pg = (unsigned long) tmp_buf;
5327 tmp_buf = NULL;
5328 free_page(pg);
5332 module_init(rs_init);
5333 module_exit(rs_fini);
5337 * ------------------------------------------------------------
5338 * Serial console driver
5339 * ------------------------------------------------------------
5341 #ifdef CONFIG_SERIAL_CONSOLE
5343 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
5345 static struct async_struct async_sercons;
5348 * Wait for transmitter & holding register to empty
5350 static inline void wait_for_xmitr(struct async_struct *info)
5352 unsigned int tmout = 1000000;
5354 while (--tmout &&
5355 ((serial_in(info, UART_LSR) & BOTH_EMPTY) != BOTH_EMPTY));
5360 * Print a string to the serial port trying not to disturb
5361 * any possible real use of the port...
5363 * The console_lock must be held when we get here.
5365 static void serial_console_write(struct console *co, const char *s,
5366 unsigned count)
5368 static struct async_struct *info = &async_sercons;
5369 int ier;
5370 unsigned i;
5373 * First save the IER then disable the interrupts
5375 ier = serial_in(info, UART_IER);
5376 serial_out(info, UART_IER, 0x00);
5379 * Now, do each character
5381 for (i = 0; i < count; i++, s++) {
5382 wait_for_xmitr(info);
5385 * Send the character out.
5386 * If a LF, also do CR...
5388 serial_out(info, UART_TX, *s);
5389 if (*s == 10) {
5390 wait_for_xmitr(info);
5391 serial_out(info, UART_TX, 13);
5396 * Finally, Wait for transmitter & holding register to empty
5397 * and restore the IER
5399 wait_for_xmitr(info);
5400 serial_out(info, UART_IER, ier);
5404 * Receive character from the serial port
5406 static int serial_console_wait_key(struct console *co)
5408 static struct async_struct *info;
5409 int ier, c;
5411 info = &async_sercons;
5414 * First save the IER then disable the interrupts so
5415 * that the real driver for the port does not get the
5416 * character.
5418 ier = serial_in(info, UART_IER);
5419 serial_out(info, UART_IER, 0x00);
5421 while ((serial_in(info, UART_LSR) & UART_LSR_DR) == 0);
5422 c = serial_in(info, UART_RX);
5425 * Restore the interrupts
5427 serial_out(info, UART_IER, ier);
5429 return c;
5432 static kdev_t serial_console_device(struct console *c)
5434 return MKDEV(TTY_MAJOR, 64 + c->index);
5438 * Setup initial baud/bits/parity. We do two things here:
5439 * - construct a cflag setting for the first rs_open()
5440 * - initialize the serial port
5441 * Return non-zero if we didn't find a serial port.
5443 static int __init serial_console_setup(struct console *co, char *options)
5445 static struct async_struct *info;
5446 struct serial_state *state;
5447 unsigned cval;
5448 int baud = 9600;
5449 int bits = 8;
5450 int parity = 'n';
5451 int cflag = CREAD | HUPCL | CLOCAL;
5452 int quot = 0;
5453 char *s;
5455 if (options) {
5456 baud = simple_strtoul(options, NULL, 10);
5457 s = options;
5458 while(*s >= '0' && *s <= '9')
5459 s++;
5460 if (*s) parity = *s++;
5461 if (*s) bits = *s - '0';
5465 * Now construct a cflag setting.
5467 switch(baud) {
5468 case 1200:
5469 cflag |= B1200;
5470 break;
5471 case 2400:
5472 cflag |= B2400;
5473 break;
5474 case 4800:
5475 cflag |= B4800;
5476 break;
5477 case 19200:
5478 cflag |= B19200;
5479 break;
5480 case 38400:
5481 cflag |= B38400;
5482 break;
5483 case 57600:
5484 cflag |= B57600;
5485 break;
5486 case 115200:
5487 cflag |= B115200;
5488 break;
5489 case 9600:
5490 default:
5491 cflag |= B9600;
5492 break;
5494 switch(bits) {
5495 case 7:
5496 cflag |= CS7;
5497 break;
5498 default:
5499 case 8:
5500 cflag |= CS8;
5501 break;
5503 switch(parity) {
5504 case 'o': case 'O':
5505 cflag |= PARODD;
5506 break;
5507 case 'e': case 'E':
5508 cflag |= PARENB;
5509 break;
5511 co->cflag = cflag;
5514 * Divisor, bytesize and parity
5516 state = rs_table + co->index;
5517 info = &async_sercons;
5518 info->magic = SERIAL_MAGIC;
5519 info->state = state;
5520 info->port = state->port;
5521 info->flags = state->flags;
5522 #ifdef CONFIG_HUB6
5523 info->hub6 = state->hub6;
5524 #endif
5525 info->io_type = state->io_type;
5526 info->iomem_base = state->iomem_base;
5527 info->iomem_reg_shift = state->iomem_reg_shift;
5528 quot = state->baud_base / baud;
5529 cval = cflag & (CSIZE | CSTOPB);
5530 #if defined(__powerpc__) || defined(__alpha__)
5531 cval >>= 8;
5532 #else /* !__powerpc__ && !__alpha__ */
5533 cval >>= 4;
5534 #endif /* !__powerpc__ && !__alpha__ */
5535 if (cflag & PARENB)
5536 cval |= UART_LCR_PARITY;
5537 if (!(cflag & PARODD))
5538 cval |= UART_LCR_EPAR;
5541 * Disable UART interrupts, set DTR and RTS high
5542 * and set speed.
5544 serial_out(info, UART_LCR, cval | UART_LCR_DLAB); /* set DLAB */
5545 serial_out(info, UART_DLL, quot & 0xff); /* LS of divisor */
5546 serial_out(info, UART_DLM, quot >> 8); /* MS of divisor */
5547 serial_out(info, UART_LCR, cval); /* reset DLAB */
5548 serial_out(info, UART_IER, 0);
5549 serial_out(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
5552 * If we read 0xff from the LSR, there is no UART here.
5554 if (serial_in(info, UART_LSR) == 0xff)
5555 return -1;
5557 return 0;
5560 static struct console sercons = {
5561 "ttyS",
5562 serial_console_write,
5563 NULL,
5564 serial_console_device,
5565 serial_console_wait_key,
5566 NULL,
5567 serial_console_setup,
5568 CON_PRINTBUFFER,
5571 NULL
5575 * Register console.
5577 void __init serial_console_init(void)
5579 register_console(&sercons);
5581 #endif
5584 Local variables:
5585 compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -pipe -fno-strength-reduce -march=i586 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -DEXPORT_SYMTAB -c serial.c"
5586 End: