~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/char/serial.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.