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