2 * linux/drivers/char/serial.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997,
6 * 1998, 1999 Theodore Ts'o
8 * Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92. Now
9 * much more extensible to support other serial cards based on the
10 * 16450/16550A UART's. Added support for the AST FourPort and the
13 * set_serial_info fixed to set the flags, custom divisor, and uart
14 * type fields. Fix suggested by Michael K. Johnson 12/12/92.
16 * 11/95: TIOCMIWAIT, TIOCGICOUNT by Angelo Haritsis <ah@doc.ic.ac.uk>
18 * 03/96: Modularised by Angelo Haritsis <ah@doc.ic.ac.uk>
20 * rs_set_termios fixed to look also for changes of the input
21 * flags INPCK, BRKINT, PARMRK, IGNPAR and IGNBRK.
22 * Bernd Anhäupl 05/17/96.
24 * 1/97: Extended dumb serial ports are a config option now.
25 * Saves 4k. Michael A. Griffith <grif@acm.org>
27 * 8/97: Fix bug in rs_set_termios with RTS
28 * Stanislav V. Voronyi <stas@uanet.kharkov.ua>
30 * 3/98: Change the IRQ detection, use of probe_irq_o*(),
31 * supress TIOCSERGWILD and TIOCSERSWILD
32 * Etienne Lorrain <etienne.lorrain@ibm.net>
34 * 4/98: Added changes to support the ARM architecture proposed by
37 * 5/99: Updated to include support for the XR16C850 and ST16C654
38 * uarts. Stuart MacDonald <stuartm@connecttech.com>
40 * 8/99: Generalized PCI support added. Theodore Ts'o
42 * 3/00: Rid circular buffer of redundant xmit_cnt. Fix a
43 * few races on freeing buffers too.
44 * Alan Modra <alan@linuxcare.com>
46 * 5/00: Support for the RSA-DV II/S card added.
47 * Kiyokazu SUTO <suto@ks-and-ks.ne.jp>
49 * This module exports the following rs232 io functions:
54 static char *serial_version
= "5.01";
55 static char *serial_revdate
= "2000-05-29";
58 * Serial driver configuration section. Here are the various options:
61 * Enables support for the venerable Bell Technologies
64 * CONFIG_SERIAL_MANY_PORTS
65 * Enables support for ports beyond the standard, stupid
68 * CONFIG_SERIAL_MULTIPORT
69 * Enables support for special multiport board support.
71 * CONFIG_SERIAL_SHARE_IRQ
72 * Enables support for multiple serial ports on one IRQ
74 * CONFIG_SERIAL_DETECT_IRQ
75 * Enable the autodetection of IRQ on standart ports
77 * SERIAL_PARANOIA_CHECK
78 * Check the magic number for the async_structure where
82 #include <linux/config.h>
83 #include <linux/version.h>
85 #undef SERIAL_PARANOIA_CHECK
86 #define CONFIG_SERIAL_NOPAUSE_IO
87 #define SERIAL_DO_RESTART
90 /* These defines are normally controlled by the autoconf.h */
91 #define CONFIG_SERIAL_MANY_PORTS
92 #define CONFIG_SERIAL_SHARE_IRQ
93 #define CONFIG_SERIAL_DETECT_IRQ
94 #define CONFIG_SERIAL_MULTIPORT
99 #define ENABLE_SERIAL_PCI
100 #ifndef CONFIG_SERIAL_SHARE_IRQ
101 #define CONFIG_SERIAL_SHARE_IRQ
103 #ifndef CONFIG_SERIAL_MANY_PORTS
104 #define CONFIG_SERIAL_MANY_PORTS
108 #if defined(CONFIG_ISAPNP)|| (defined(CONFIG_ISAPNP_MODULE) && defined(MODULE))
109 #ifndef ENABLE_SERIAL_PNP
110 #define ENABLE_SERIAL_PNP
114 /* Set of debugging defines */
116 #undef SERIAL_DEBUG_INTR
117 #undef SERIAL_DEBUG_OPEN
118 #undef SERIAL_DEBUG_FLOW
119 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
120 #undef SERIAL_DEBUG_PCI
121 #undef SERIAL_DEBUG_AUTOCONF
125 #ifdef CONFIG_SERIAL_MULTIPORT
126 #ifndef CONFIG_SERIAL_SHARE_IRQ
127 #define CONFIG_SERIAL_SHARE_IRQ
132 #ifndef CONFIG_SERIAL_MANY_PORTS
133 #define CONFIG_SERIAL_MANY_PORTS
135 #ifndef CONFIG_SERIAL_SHARE_IRQ
136 #define CONFIG_SERIAL_SHARE_IRQ
140 #define CONFIG_SERIAL_RSA
142 #define RS_STROBE_TIME (10*HZ)
143 #define RS_ISR_PASS_LIMIT 256
145 #if defined(__i386__) && (defined(CONFIG_M386) || defined(CONFIG_M486))
146 #define SERIAL_INLINE
150 * End of serial driver configuration section.
154 #include <linux/modversions.h>
156 #include <linux/module.h>
158 #include <linux/types.h>
160 #include "serial_local.h"
162 #include <linux/serial.h>
163 #include <linux/serialP.h>
164 #include <linux/serial_reg.h>
165 #include <asm/serial.h>
166 #define LOCAL_VERSTRING ""
169 #include <linux/errno.h>
170 #include <linux/signal.h>
171 #include <linux/sched.h>
172 #include <linux/timer.h>
173 #include <linux/interrupt.h>
174 #include <linux/tty.h>
175 #include <linux/tty_flip.h>
176 #include <linux/major.h>
177 #include <linux/string.h>
178 #include <linux/fcntl.h>
179 #include <linux/ptrace.h>
180 #include <linux/ioport.h>
181 #include <linux/mm.h>
182 #include <linux/malloc.h>
183 #if (LINUX_VERSION_CODE >= 131343)
184 #include <linux/init.h>
186 #if (LINUX_VERSION_CODE >= 131336)
187 #include <asm/uaccess.h>
189 #include <linux/delay.h>
190 #ifdef CONFIG_SERIAL_CONSOLE
191 #include <linux/console.h>
193 #ifdef ENABLE_SERIAL_PCI
194 #include <linux/pci.h>
196 #ifdef ENABLE_SERIAL_PNP
197 #include <linux/isapnp.h>
199 #ifdef CONFIG_MAGIC_SYSRQ
200 #include <linux/sysrq.h>
204 * All of the compatibilty code so we can compile serial.c against
205 * older kernels is hidden in serial_compat.h
207 #if defined(LOCAL_HEADERS) || (LINUX_VERSION_CODE < 0x020317) /* 2.3.23 */
208 #include "serial_compat.h"
211 #include <asm/system.h>
214 #include <asm/bitops.h>
216 #ifdef CONFIG_MAC_SERIAL
217 #define SERIAL_DEV_OFFSET 2
219 #define SERIAL_DEV_OFFSET 0
223 #define _INLINE_ inline
228 static char *serial_name
= "Serial driver";
230 static DECLARE_TASK_QUEUE(tq_serial
);
232 static struct tty_driver serial_driver
, callout_driver
;
233 static int serial_refcount
;
235 /* serial subtype definitions */
236 #ifndef SERIAL_TYPE_NORMAL
237 #define SERIAL_TYPE_NORMAL 1
238 #define SERIAL_TYPE_CALLOUT 2
241 /* number of characters left in xmit buffer before we ask for more */
242 #define WAKEUP_CHARS 256
245 * IRQ_timeout - How long the timeout should be for each IRQ
246 * should be after the IRQ has been active.
249 static struct async_struct
*IRQ_ports
[NR_IRQS
];
250 #ifdef CONFIG_SERIAL_MULTIPORT
251 static struct rs_multiport_struct rs_multiport
[NR_IRQS
];
253 static int IRQ_timeout
[NR_IRQS
];
254 #ifdef CONFIG_SERIAL_CONSOLE
255 static struct console sercons
;
256 static unsigned long break_pressed
; /* break, really ... */
259 static unsigned detect_uart_irq (struct serial_state
* state
);
260 static void autoconfig(struct serial_state
* state
);
261 static void change_speed(struct async_struct
*info
, struct termios
*old
);
262 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
265 * Here we define the default xmit fifo size used for each type of
268 static struct serial_uart_config uart_config
[] = {
273 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
274 { "cirrus", 1, 0 }, /* usurped by cyclades.c */
275 { "ST16650", 1, UART_CLEAR_FIFO
|UART_STARTECH
},
276 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
278 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
279 { "Startech", 1, 0}, /* usurped by cyclades.c */
280 { "16C950/954", 128, UART_CLEAR_FIFO
| UART_USE_FIFO
},
281 { "ST16654", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
|
283 { "XR16850", 128, UART_CLEAR_FIFO
| UART_USE_FIFO
|
285 { "RSA", 2048, UART_CLEAR_FIFO
| UART_USE_FIFO
},
289 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
291 #define PORT_RSA_MAX 4
292 static int probe_rsa
[PORT_RSA_MAX
];
293 static int force_rsa
[PORT_RSA_MAX
];
295 MODULE_PARM(probe_rsa
, "1-" __MODULE_STRING(PORT_RSA_MAX
) "i");
296 MODULE_PARM(force_rsa
, "1-" __MODULE_STRING(PORT_RSA_MAX
) "i");
297 #endif /* CONFIG_SERIAL_RSA */
299 static struct serial_state rs_table
[RS_TABLE_SIZE
] = {
300 SERIAL_PORT_DFNS
/* Defined in serial.h */
303 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
305 #if (defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP))
306 #define NR_PCI_BOARDS 8
308 /* We don't unregister PCI boards right now */
309 static struct pci_board_inst serial_pci_board
[NR_PCI_BOARDS
];
310 static int serial_pci_board_idx
= 0;
312 #ifndef IS_PCI_REGION_IOPORT
313 #define IS_PCI_REGION_IOPORT(dev, r) (pci_resource_flags((dev), (r)) & \
316 #ifndef PCI_IRQ_RESOURCE
317 #define PCI_IRQ_RESOURCE(dev, r) ((dev)->irq_resource[r].start)
319 #ifndef pci_get_subvendor
320 #define pci_get_subvendor(dev) ((dev)->subsystem_vendor)
321 #define pci_get_subdevice(dev) ((dev)->subsystem_device)
323 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
326 #define PREPARE_FUNC(dev) (dev->prepare)
327 #define ACTIVATE_FUNC(dev) (dev->activate)
328 #define DEACTIVATE_FUNC(dev) (dev->deactivate)
331 #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
333 static struct tty_struct
*serial_table
[NR_PORTS
];
334 static struct termios
*serial_termios
[NR_PORTS
];
335 static struct termios
*serial_termios_locked
[NR_PORTS
];
338 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
339 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
340 kdevname(tty->device), (info->flags), serial_refcount,info->count,tty->count,s)
346 * tmp_buf is used as a temporary buffer by serial_write. We need to
347 * lock it in case the copy_from_user blocks while swapping in a page,
348 * and some other program tries to do a serial write at the same time.
349 * Since the lock will only come under contention when the system is
350 * swapping and available memory is low, it makes sense to share one
351 * buffer across all the serial ports, since it significantly saves
352 * memory if large numbers of serial ports are open.
354 static unsigned char *tmp_buf
;
356 static DECLARE_MUTEX(tmp_buf_sem
);
358 static struct semaphore tmp_buf_sem
= MUTEX
;
362 static inline int serial_paranoia_check(struct async_struct
*info
,
363 kdev_t device
, const char *routine
)
365 #ifdef SERIAL_PARANOIA_CHECK
366 static const char *badmagic
=
367 "Warning: bad magic number for serial struct (%s) in %s\n";
368 static const char *badinfo
=
369 "Warning: null async_struct for (%s) in %s\n";
372 printk(badinfo
, kdevname(device
), routine
);
375 if (info
->magic
!= SERIAL_MAGIC
) {
376 printk(badmagic
, kdevname(device
), routine
);
383 static _INLINE_
unsigned int serial_in(struct async_struct
*info
, int offset
)
385 switch (info
->io_type
) {
388 outb(info
->hub6
- 1 + offset
, info
->port
);
389 return inb(info
->port
+1);
392 return readb((unsigned long) info
->iomem_base
+
393 (offset
<<info
->iomem_reg_shift
));
394 #ifdef CONFIG_SERIAL_GSC
396 return gsc_readb(info
->iomem_base
+ offset
);
399 return inb(info
->port
+ offset
);
403 static _INLINE_
void serial_out(struct async_struct
*info
, int offset
,
406 switch (info
->io_type
) {
409 outb(info
->hub6
- 1 + offset
, info
->port
);
410 outb(value
, info
->port
+1);
414 writeb(value
, (unsigned long) info
->iomem_base
+
415 (offset
<<info
->iomem_reg_shift
));
417 #ifdef CONFIG_SERIAL_GSC
419 gsc_writeb(value
, info
->iomem_base
+ offset
);
423 outb(value
, info
->port
+offset
);
428 * We used to support using pause I/O for certain machines. We
429 * haven't supported this for a while, but just in case it's badly
430 * needed for certain old 386 machines, I've left these #define's
433 #define serial_inp(info, offset) serial_in(info, offset)
434 #define serial_outp(info, offset, value) serial_out(info, offset, value)
440 void serial_icr_write(struct async_struct
*info
, int offset
, int value
)
442 serial_out(info
, UART_SCR
, offset
);
443 serial_out(info
, UART_ICR
, value
);
446 unsigned int serial_icr_read(struct async_struct
*info
, int offset
)
450 serial_icr_write(info
, UART_ACR
, info
->ACR
| UART_ACR_ICRRD
);
451 serial_out(info
, UART_SCR
, offset
);
452 value
= serial_in(info
, UART_ICR
);
453 serial_icr_write(info
, UART_ACR
, info
->ACR
);
458 * ------------------------------------------------------------
459 * rs_stop() and rs_start()
461 * This routines are called before setting or resetting tty->stopped.
462 * They enable or disable transmitter interrupts, as necessary.
463 * ------------------------------------------------------------
465 static void rs_stop(struct tty_struct
*tty
)
467 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
470 if (serial_paranoia_check(info
, tty
->device
, "rs_stop"))
473 save_flags(flags
); cli();
474 if (info
->IER
& UART_IER_THRI
) {
475 info
->IER
&= ~UART_IER_THRI
;
476 serial_out(info
, UART_IER
, info
->IER
);
478 if (info
->state
->type
== PORT_16C950
) {
479 info
->ACR
|= UART_ACR_TXDIS
;
480 serial_icr_write(info
, UART_ACR
, info
->ACR
);
482 restore_flags(flags
);
485 static void rs_start(struct tty_struct
*tty
)
487 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
490 if (serial_paranoia_check(info
, tty
->device
, "rs_start"))
493 save_flags(flags
); cli();
494 if (info
->xmit
.head
!= info
->xmit
.tail
496 && !(info
->IER
& UART_IER_THRI
)) {
497 info
->IER
|= UART_IER_THRI
;
498 serial_out(info
, UART_IER
, info
->IER
);
500 if (info
->state
->type
== PORT_16C950
) {
501 info
->ACR
&= ~UART_ACR_TXDIS
;
502 serial_icr_write(info
, UART_ACR
, info
->ACR
);
504 restore_flags(flags
);
508 * ----------------------------------------------------------------------
510 * Here starts the interrupt handling routines. All of the following
511 * subroutines are declared as inline and are folded into
512 * rs_interrupt(). They were separated out for readability's sake.
514 * Note: rs_interrupt() is a "fast" interrupt, which means that it
515 * runs with interrupts turned off. People who may want to modify
516 * rs_interrupt() should try to keep the interrupt handler as fast as
517 * possible. After you are done making modifications, it is not a bad
520 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
522 * and look at the resulting assemble code in serial.s.
524 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
525 * -----------------------------------------------------------------------
529 * This routine is used by the interrupt handler to schedule
530 * processing in the software interrupt portion of the driver.
532 static _INLINE_
void rs_sched_event(struct async_struct
*info
,
535 info
->event
|= 1 << event
;
536 queue_task(&info
->tqueue
, &tq_serial
);
540 static _INLINE_
void receive_chars(struct async_struct
*info
,
541 int *status
, struct pt_regs
* regs
)
543 struct tty_struct
*tty
= info
->tty
;
546 struct async_icount
*icount
;
548 icount
= &info
->state
->icount
;
550 ch
= serial_inp(info
, UART_RX
);
551 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
553 *tty
->flip
.char_buf_ptr
= ch
;
556 #ifdef SERIAL_DEBUG_INTR
557 printk("DR%02x:%02x...", ch
, *status
);
559 *tty
->flip
.flag_buf_ptr
= 0;
560 if (*status
& (UART_LSR_BI
| UART_LSR_PE
|
561 UART_LSR_FE
| UART_LSR_OE
)) {
563 * For statistics only
565 if (*status
& UART_LSR_BI
) {
566 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
568 } else if (*status
& UART_LSR_PE
)
570 else if (*status
& UART_LSR_FE
)
572 if (*status
& UART_LSR_OE
)
576 * Now check to see if character should be
577 * ignored, and mask off conditions which
580 if (*status
& info
->ignore_status_mask
) {
585 *status
&= info
->read_status_mask
;
587 if (*status
& (UART_LSR_BI
)) {
588 #ifdef SERIAL_DEBUG_INTR
589 printk("handling break....");
591 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && !defined(MODULE)
592 if (info
->line
== sercons
.index
) {
593 if (!break_pressed
) {
594 break_pressed
= jiffies
;
600 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
601 if (info
->flags
& ASYNC_SAK
)
603 } else if (*status
& UART_LSR_PE
)
604 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
605 else if (*status
& UART_LSR_FE
)
606 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
607 if (*status
& UART_LSR_OE
) {
609 * Overrun is special, since it's
610 * reported immediately, and doesn't
611 * affect the current character
614 tty
->flip
.flag_buf_ptr
++;
615 tty
->flip
.char_buf_ptr
++;
616 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
617 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
621 #if defined(CONFIG_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) && !defined(MODULE)
622 if (break_pressed
&& info
->line
== sercons
.index
) {
624 time_before(jiffies
, break_pressed
+ HZ
*5)) {
625 handle_sysrq(ch
, regs
, NULL
, NULL
);
632 tty
->flip
.flag_buf_ptr
++;
633 tty
->flip
.char_buf_ptr
++;
636 *status
= serial_inp(info
, UART_LSR
);
637 } while (*status
& UART_LSR_DR
);
638 #if (LINUX_VERSION_CODE > 131394) /* 2.1.66 */
639 tty_flip_buffer_push(tty
);
641 queue_task_irq_off(&tty
->flip
.tqueue
, &tq_timer
);
645 static _INLINE_
void transmit_chars(struct async_struct
*info
, int *intr_done
)
650 serial_outp(info
, UART_TX
, info
->x_char
);
651 info
->state
->icount
.tx
++;
657 if (info
->xmit
.head
== info
->xmit
.tail
658 || info
->tty
->stopped
659 || info
->tty
->hw_stopped
) {
660 info
->IER
&= ~UART_IER_THRI
;
661 serial_out(info
, UART_IER
, info
->IER
);
665 count
= info
->xmit_fifo_size
;
667 serial_out(info
, UART_TX
, info
->xmit
.buf
[info
->xmit
.tail
]);
668 info
->xmit
.tail
= (info
->xmit
.tail
+ 1) & (SERIAL_XMIT_SIZE
-1);
669 info
->state
->icount
.tx
++;
670 if (info
->xmit
.head
== info
->xmit
.tail
)
672 } while (--count
> 0);
674 if (CIRC_CNT(info
->xmit
.head
,
676 SERIAL_XMIT_SIZE
) < WAKEUP_CHARS
)
677 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
679 #ifdef SERIAL_DEBUG_INTR
685 if (info
->xmit
.head
== info
->xmit
.tail
) {
686 info
->IER
&= ~UART_IER_THRI
;
687 serial_out(info
, UART_IER
, info
->IER
);
691 static _INLINE_
void check_modem_status(struct async_struct
*info
)
694 struct async_icount
*icount
;
696 status
= serial_in(info
, UART_MSR
);
698 if (status
& UART_MSR_ANY_DELTA
) {
699 icount
= &info
->state
->icount
;
700 /* update input line counters */
701 if (status
& UART_MSR_TERI
)
703 if (status
& UART_MSR_DDSR
)
705 if (status
& UART_MSR_DDCD
) {
707 #ifdef CONFIG_HARD_PPS
708 if ((info
->flags
& ASYNC_HARDPPS_CD
) &&
709 (status
& UART_MSR_DCD
))
713 if (status
& UART_MSR_DCTS
)
715 wake_up_interruptible(&info
->delta_msr_wait
);
718 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
719 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
720 printk("ttys%d CD now %s...", info
->line
,
721 (status
& UART_MSR_DCD
) ? "on" : "off");
723 if (status
& UART_MSR_DCD
)
724 wake_up_interruptible(&info
->open_wait
);
725 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
726 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
727 #ifdef SERIAL_DEBUG_OPEN
728 printk("doing serial hangup...");
731 tty_hangup(info
->tty
);
734 if (info
->flags
& ASYNC_CTS_FLOW
) {
735 if (info
->tty
->hw_stopped
) {
736 if (status
& UART_MSR_CTS
) {
737 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
738 printk("CTS tx start...");
740 info
->tty
->hw_stopped
= 0;
741 info
->IER
|= UART_IER_THRI
;
742 serial_out(info
, UART_IER
, info
->IER
);
743 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
747 if (!(status
& UART_MSR_CTS
)) {
748 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
749 printk("CTS tx stop...");
751 info
->tty
->hw_stopped
= 1;
752 info
->IER
&= ~UART_IER_THRI
;
753 serial_out(info
, UART_IER
, info
->IER
);
759 #ifdef CONFIG_SERIAL_SHARE_IRQ
761 * This is the serial driver's generic interrupt routine
763 static void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
766 struct async_struct
* info
;
767 int pass_counter
= 0;
768 struct async_struct
*end_mark
= 0;
769 #ifdef CONFIG_SERIAL_MULTIPORT
771 struct rs_multiport_struct
*multi
;
774 #ifdef SERIAL_DEBUG_INTR
775 printk("rs_interrupt(%d)...", irq
);
778 info
= IRQ_ports
[irq
];
782 #ifdef CONFIG_SERIAL_MULTIPORT
783 multi
= &rs_multiport
[irq
];
784 if (multi
->port_monitor
)
785 first_multi
= inb(multi
->port_monitor
);
790 (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
)) {
797 info
->last_active
= jiffies
;
799 status
= serial_inp(info
, UART_LSR
);
800 #ifdef SERIAL_DEBUG_INTR
801 printk("status = %x...", status
);
803 if (status
& UART_LSR_DR
)
804 receive_chars(info
, &status
, regs
);
805 check_modem_status(info
);
806 if (status
& UART_LSR_THRE
)
807 transmit_chars(info
, 0);
810 info
= info
->next_port
;
812 info
= IRQ_ports
[irq
];
813 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
815 printk("rs loop break\n");
817 break; /* Prevent infinite loops */
821 } while (end_mark
!= info
);
822 #ifdef CONFIG_SERIAL_MULTIPORT
823 if (multi
->port_monitor
)
824 printk("rs port monitor (normal) irq %d: 0x%x, 0x%x\n",
825 info
->state
->irq
, first_multi
,
826 inb(multi
->port_monitor
));
828 #ifdef SERIAL_DEBUG_INTR
832 #endif /* #ifdef CONFIG_SERIAL_SHARE_IRQ */
836 * This is the serial driver's interrupt routine for a single port
838 static void rs_interrupt_single(int irq
, void *dev_id
, struct pt_regs
* regs
)
841 int pass_counter
= 0;
842 struct async_struct
* info
;
843 #ifdef CONFIG_SERIAL_MULTIPORT
845 struct rs_multiport_struct
*multi
;
848 #ifdef SERIAL_DEBUG_INTR
849 printk("rs_interrupt_single(%d)...", irq
);
852 info
= IRQ_ports
[irq
];
853 if (!info
|| !info
->tty
)
856 #ifdef CONFIG_SERIAL_MULTIPORT
857 multi
= &rs_multiport
[irq
];
858 if (multi
->port_monitor
)
859 first_multi
= inb(multi
->port_monitor
);
863 status
= serial_inp(info
, UART_LSR
);
864 #ifdef SERIAL_DEBUG_INTR
865 printk("status = %x...", status
);
867 if (status
& UART_LSR_DR
)
868 receive_chars(info
, &status
, regs
);
869 check_modem_status(info
);
870 if (status
& UART_LSR_THRE
)
871 transmit_chars(info
, 0);
872 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
874 printk("rs_single loop break.\n");
878 } while (!(serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
));
879 info
->last_active
= jiffies
;
880 #ifdef CONFIG_SERIAL_MULTIPORT
881 if (multi
->port_monitor
)
882 printk("rs port monitor (single) irq %d: 0x%x, 0x%x\n",
883 info
->state
->irq
, first_multi
,
884 inb(multi
->port_monitor
));
886 #ifdef SERIAL_DEBUG_INTR
891 #ifdef CONFIG_SERIAL_MULTIPORT
893 * This is the serial driver's for multiport boards
895 static void rs_interrupt_multi(int irq
, void *dev_id
, struct pt_regs
* regs
)
898 struct async_struct
* info
;
899 int pass_counter
= 0;
901 struct rs_multiport_struct
*multi
;
903 #ifdef SERIAL_DEBUG_INTR
904 printk("rs_interrupt_multi(%d)...", irq
);
907 info
= IRQ_ports
[irq
];
910 multi
= &rs_multiport
[irq
];
912 /* Should never happen */
913 printk("rs_interrupt_multi: NULL port1!\n");
916 if (multi
->port_monitor
)
917 first_multi
= inb(multi
->port_monitor
);
921 (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
))
924 info
->last_active
= jiffies
;
926 status
= serial_inp(info
, UART_LSR
);
927 #ifdef SERIAL_DEBUG_INTR
928 printk("status = %x...", status
);
930 if (status
& UART_LSR_DR
)
931 receive_chars(info
, &status
, regs
);
932 check_modem_status(info
);
933 if (status
& UART_LSR_THRE
)
934 transmit_chars(info
, 0);
937 info
= info
->next_port
;
941 info
= IRQ_ports
[irq
];
943 * The user was a bonehead, and misconfigured their
944 * multiport info. Rather than lock up the kernel
945 * in an infinite loop, if we loop too many times,
946 * print a message and break out of the loop.
948 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
949 printk("Misconfigured multiport serial info "
950 "for irq %d. Breaking out irq loop\n", irq
);
953 if (multi
->port_monitor
)
954 printk("rs port monitor irq %d: 0x%x, 0x%x\n",
955 info
->state
->irq
, first_multi
,
956 inb(multi
->port_monitor
));
957 if ((inb(multi
->port1
) & multi
->mask1
) != multi
->match1
)
961 if ((inb(multi
->port2
) & multi
->mask2
) != multi
->match2
)
965 if ((inb(multi
->port3
) & multi
->mask3
) != multi
->match3
)
969 if ((inb(multi
->port4
) & multi
->mask4
) != multi
->match4
)
973 #ifdef SERIAL_DEBUG_INTR
980 * -------------------------------------------------------------------
981 * Here ends the serial interrupt routines.
982 * -------------------------------------------------------------------
986 * This routine is used to handle the "bottom half" processing for the
987 * serial driver, known also the "software interrupt" processing.
988 * This processing is done at the kernel interrupt level, after the
989 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
990 * is where time-consuming activities which can not be done in the
991 * interrupt driver proper are done; the interrupt driver schedules
992 * them using rs_sched_event(), and they get done here.
994 static void do_serial_bh(void)
996 run_task_queue(&tq_serial
);
999 static void do_softint(void *private_
)
1001 struct async_struct
*info
= (struct async_struct
*) private_
;
1002 struct tty_struct
*tty
;
1008 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
1009 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1010 tty
->ldisc
.write_wakeup
)
1011 (tty
->ldisc
.write_wakeup
)(tty
);
1012 wake_up_interruptible(&tty
->write_wait
);
1013 #ifdef SERIAL_HAVE_POLL_WAIT
1014 wake_up_interruptible(&tty
->poll_wait
);
1020 * This subroutine is called when the RS_TIMER goes off. It is used
1021 * by the serial driver to handle ports that do not have an interrupt
1022 * (irq=0). This doesn't work very well for 16450's, but gives barely
1023 * passable results for a 16550A. (Although at the expense of much
1026 static void rs_timer(void)
1028 static unsigned long last_strobe
= 0;
1029 struct async_struct
*info
;
1031 unsigned long flags
;
1033 if ((jiffies
- last_strobe
) >= RS_STROBE_TIME
) {
1034 for (i
=0; i
< NR_IRQS
; i
++) {
1035 info
= IRQ_ports
[i
];
1038 save_flags(flags
); cli();
1039 #ifdef CONFIG_SERIAL_SHARE_IRQ
1040 if (info
->next_port
) {
1042 serial_out(info
, UART_IER
, 0);
1043 info
->IER
|= UART_IER_THRI
;
1044 serial_out(info
, UART_IER
, info
->IER
);
1045 info
= info
->next_port
;
1047 #ifdef CONFIG_SERIAL_MULTIPORT
1048 if (rs_multiport
[i
].port1
)
1049 rs_interrupt_multi(i
, NULL
, NULL
);
1052 rs_interrupt(i
, NULL
, NULL
);
1054 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1055 rs_interrupt_single(i
, NULL
, NULL
);
1056 restore_flags(flags
);
1059 last_strobe
= jiffies
;
1060 timer_table
[RS_TIMER
].expires
= jiffies
+ RS_STROBE_TIME
;
1061 timer_active
|= 1 << RS_TIMER
;
1064 save_flags(flags
); cli();
1065 #ifdef CONFIG_SERIAL_SHARE_IRQ
1066 rs_interrupt(0, NULL
, NULL
);
1068 rs_interrupt_single(0, NULL
, NULL
);
1070 restore_flags(flags
);
1072 timer_table
[RS_TIMER
].expires
= jiffies
+ IRQ_timeout
[0] - 2;
1077 * ---------------------------------------------------------------
1078 * Low level utility subroutines for the serial driver: routines to
1079 * figure out the appropriate timeout for an interrupt chain, routines
1080 * to initialize and startup a serial port, and routines to shutdown a
1081 * serial port. Useful stuff like that.
1082 * ---------------------------------------------------------------
1086 * This routine figures out the correct timeout for a particular IRQ.
1087 * It uses the smallest timeout of all of the serial ports in a
1088 * particular interrupt chain. Now only used for IRQ 0....
1090 static void figure_IRQ_timeout(int irq
)
1092 struct async_struct
*info
;
1093 int timeout
= 60*HZ
; /* 60 seconds === a long time :-) */
1095 info
= IRQ_ports
[irq
];
1097 IRQ_timeout
[irq
] = 60*HZ
;
1101 if (info
->timeout
< timeout
)
1102 timeout
= info
->timeout
;
1103 info
= info
->next_port
;
1106 timeout
= timeout
/ 2;
1107 IRQ_timeout
[irq
] = timeout
? timeout
: 1;
1110 #ifdef CONFIG_SERIAL_RSA
1111 /* Attempts to turn on the RSA FIFO. Returns zero on failure */
1112 static int enable_rsa(struct async_struct
*info
)
1116 unsigned long flags
;
1118 save_flags(flags
); cli();
1119 mode
= serial_inp(info
, UART_RSA_MSR
);
1120 result
= mode
& UART_RSA_MSR_FIFO
;
1123 serial_outp(info
, UART_RSA_MSR
, mode
| UART_RSA_MSR_FIFO
);
1124 mode
= serial_inp(info
, UART_RSA_MSR
);
1125 result
= mode
& UART_RSA_MSR_FIFO
;
1128 restore_flags(flags
);
1132 /* Attempts to turn off the RSA FIFO. Returns zero on failure */
1133 static int disable_rsa(struct async_struct
*info
)
1137 unsigned long flags
;
1139 save_flags(flags
); cli();
1140 mode
= serial_inp(info
, UART_RSA_MSR
);
1141 result
= !(mode
& UART_RSA_MSR_FIFO
);
1144 serial_outp(info
, UART_RSA_MSR
, mode
& ~UART_RSA_MSR_FIFO
);
1145 mode
= serial_inp(info
, UART_RSA_MSR
);
1146 result
= !(mode
& UART_RSA_MSR_FIFO
);
1149 restore_flags(flags
);
1152 #endif /* CONFIG_SERIAL_RSA */
1154 static int startup(struct async_struct
* info
)
1156 unsigned long flags
;
1158 void (*handler
)(int, void *, struct pt_regs
*);
1159 struct serial_state
*state
= info
->state
;
1161 #ifdef CONFIG_SERIAL_MANY_PORTS
1165 page
= get_zeroed_page(GFP_KERNEL
);
1169 save_flags(flags
); cli();
1171 if (info
->flags
& ASYNC_INITIALIZED
) {
1176 if (!CONFIGURED_SERIAL_PORT(state
) || !state
->type
) {
1178 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1185 info
->xmit
.buf
= (unsigned char *) page
;
1187 #ifdef SERIAL_DEBUG_OPEN
1188 printk("starting up ttys%d (irq %d)...", info
->line
, state
->irq
);
1191 if (uart_config
[state
->type
].flags
& UART_STARTECH
) {
1193 serial_outp(info
, UART_LCR
, 0xBF);
1194 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1196 * Turn off LCR == 0xBF so we actually set the IER
1197 * register on the XR16C850
1199 serial_outp(info
, UART_LCR
, 0);
1200 serial_outp(info
, UART_IER
, 0);
1202 * Now reset LCR so we can turn off the ECB bit
1204 serial_outp(info
, UART_LCR
, 0xBF);
1205 serial_outp(info
, UART_EFR
, 0);
1207 * For a XR16C850, we need to set the trigger levels
1209 if (state
->type
== PORT_16850
) {
1210 serial_outp(info
, UART_FCTR
, UART_FCTR_TRGD
|
1212 serial_outp(info
, UART_TRG
, UART_TRG_96
);
1213 serial_outp(info
, UART_FCTR
, UART_FCTR_TRGD
|
1215 serial_outp(info
, UART_TRG
, UART_TRG_96
);
1217 serial_outp(info
, UART_LCR
, 0);
1220 if (state
->type
== PORT_16750
) {
1222 serial_outp(info
, UART_IER
, 0);
1225 if (state
->type
== PORT_16C950
) {
1226 /* Wake up and initialize UART */
1228 serial_outp(info
, UART_LCR
, 0xBF);
1229 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1230 serial_outp(info
, UART_IER
, 0);
1231 serial_outp(info
, UART_LCR
, 0);
1232 serial_icr_write(info
, UART_CSR
, 0); /* Reset the UART */
1233 serial_outp(info
, UART_LCR
, 0xBF);
1234 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1235 serial_outp(info
, UART_LCR
, 0);
1238 #ifdef CONFIG_SERIAL_RSA
1240 * If this is an RSA port, see if we can kick it up to the
1241 * higher speed clock.
1243 if (state
->type
== PORT_RSA
) {
1244 if (state
->baud_base
!= SERIAL_RSA_BAUD_BASE
&&
1246 state
->baud_base
= SERIAL_RSA_BAUD_BASE
;
1247 if (state
->baud_base
== SERIAL_RSA_BAUD_BASE
)
1248 serial_outp(info
, UART_RSA_FRR
, 0);
1253 * Clear the FIFO buffers and disable them
1254 * (they will be reenabled in change_speed())
1256 if (uart_config
[state
->type
].flags
& UART_CLEAR_FIFO
) {
1257 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1258 serial_outp(info
, UART_FCR
, (UART_FCR_ENABLE_FIFO
|
1259 UART_FCR_CLEAR_RCVR
|
1260 UART_FCR_CLEAR_XMIT
));
1261 serial_outp(info
, UART_FCR
, 0);
1265 * Clear the interrupt registers.
1267 (void) serial_inp(info
, UART_LSR
);
1268 (void) serial_inp(info
, UART_RX
);
1269 (void) serial_inp(info
, UART_IIR
);
1270 (void) serial_inp(info
, UART_MSR
);
1273 * At this point there's no way the LSR could still be 0xFF;
1274 * if it is, then bail out, because there's likely no UART
1277 if (!(info
->flags
& ASYNC_BUGGY_UART
) &&
1278 (serial_inp(info
, UART_LSR
) == 0xff)) {
1279 printk("LSR safety check engaged!\n");
1280 if (capable(CAP_SYS_ADMIN
)) {
1282 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1289 * Allocate the IRQ if necessary
1291 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
1292 !IRQ_ports
[state
->irq
]->next_port
)) {
1293 if (IRQ_ports
[state
->irq
]) {
1294 #ifdef CONFIG_SERIAL_SHARE_IRQ
1295 free_irq(state
->irq
, &IRQ_ports
[state
->irq
]);
1296 #ifdef CONFIG_SERIAL_MULTIPORT
1297 if (rs_multiport
[state
->irq
].port1
)
1298 handler
= rs_interrupt_multi
;
1301 handler
= rs_interrupt
;
1305 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1307 handler
= rs_interrupt_single
;
1309 retval
= request_irq(state
->irq
, handler
, SA_SHIRQ
,
1310 "serial", &IRQ_ports
[state
->irq
]);
1312 if (capable(CAP_SYS_ADMIN
)) {
1314 set_bit(TTY_IO_ERROR
,
1323 * Insert serial port into IRQ chain.
1325 info
->prev_port
= 0;
1326 info
->next_port
= IRQ_ports
[state
->irq
];
1327 if (info
->next_port
)
1328 info
->next_port
->prev_port
= info
;
1329 IRQ_ports
[state
->irq
] = info
;
1330 figure_IRQ_timeout(state
->irq
);
1333 * Now, initialize the UART
1335 serial_outp(info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
1338 if (info
->tty
->termios
->c_cflag
& CBAUD
)
1339 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
1340 #ifdef CONFIG_SERIAL_MANY_PORTS
1341 if (info
->flags
& ASYNC_FOURPORT
) {
1342 if (state
->irq
== 0)
1343 info
->MCR
|= UART_MCR_OUT1
;
1347 if (state
->irq
!= 0)
1348 info
->MCR
|= UART_MCR_OUT2
;
1350 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
1351 serial_outp(info
, UART_MCR
, info
->MCR
);
1354 * Finally, enable interrupts
1356 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
1357 serial_outp(info
, UART_IER
, info
->IER
); /* enable interrupts */
1359 #ifdef CONFIG_SERIAL_MANY_PORTS
1360 if (info
->flags
& ASYNC_FOURPORT
) {
1361 /* Enable interrupts on the AST Fourport board */
1362 ICP
= (info
->port
& 0xFE0) | 0x01F;
1369 * And clear the interrupt registers again for luck.
1371 (void)serial_inp(info
, UART_LSR
);
1372 (void)serial_inp(info
, UART_RX
);
1373 (void)serial_inp(info
, UART_IIR
);
1374 (void)serial_inp(info
, UART_MSR
);
1377 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1378 info
->xmit
.head
= info
->xmit
.tail
= 0;
1381 * Set up serial timers...
1383 timer_table
[RS_TIMER
].expires
= jiffies
+ 2*HZ
/100;
1384 timer_active
|= 1 << RS_TIMER
;
1387 * Set up the tty->alt_speed kludge
1389 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
1391 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1392 info
->tty
->alt_speed
= 57600;
1393 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1394 info
->tty
->alt_speed
= 115200;
1395 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1396 info
->tty
->alt_speed
= 230400;
1397 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1398 info
->tty
->alt_speed
= 460800;
1403 * and set the speed of the serial port
1405 change_speed(info
, 0);
1407 info
->flags
|= ASYNC_INITIALIZED
;
1408 restore_flags(flags
);
1412 restore_flags(flags
);
1417 * This routine will shutdown a serial port; interrupts are disabled, and
1418 * DTR is dropped if the hangup on close termio flag is on.
1420 static void shutdown(struct async_struct
* info
)
1422 unsigned long flags
;
1423 struct serial_state
*state
;
1426 if (!(info
->flags
& ASYNC_INITIALIZED
))
1429 state
= info
->state
;
1431 #ifdef SERIAL_DEBUG_OPEN
1432 printk("Shutting down serial port %d (irq %d)....", info
->line
,
1436 save_flags(flags
); cli(); /* Disable interrupts */
1439 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1440 * here so the queue might never be waken up
1442 wake_up_interruptible(&info
->delta_msr_wait
);
1445 * First unlink the serial port from the IRQ chain...
1447 if (info
->next_port
)
1448 info
->next_port
->prev_port
= info
->prev_port
;
1449 if (info
->prev_port
)
1450 info
->prev_port
->next_port
= info
->next_port
;
1452 IRQ_ports
[state
->irq
] = info
->next_port
;
1453 figure_IRQ_timeout(state
->irq
);
1456 * Free the IRQ, if necessary
1458 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
1459 !IRQ_ports
[state
->irq
]->next_port
)) {
1460 if (IRQ_ports
[state
->irq
]) {
1461 free_irq(state
->irq
, &IRQ_ports
[state
->irq
]);
1462 retval
= request_irq(state
->irq
, rs_interrupt_single
,
1464 &IRQ_ports
[state
->irq
]);
1467 printk("serial shutdown: request_irq: error %d"
1468 " Couldn't reacquire IRQ.\n", retval
);
1470 free_irq(state
->irq
, &IRQ_ports
[state
->irq
]);
1473 if (info
->xmit
.buf
) {
1474 unsigned long pg
= (unsigned long) info
->xmit
.buf
;
1480 serial_outp(info
, UART_IER
, 0x00); /* disable all intrs */
1481 #ifdef CONFIG_SERIAL_MANY_PORTS
1482 if (info
->flags
& ASYNC_FOURPORT
) {
1483 /* reset interrupts on the AST Fourport board */
1484 (void) inb((info
->port
& 0xFE0) | 0x01F);
1485 info
->MCR
|= UART_MCR_OUT1
;
1488 info
->MCR
&= ~UART_MCR_OUT2
;
1489 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
1491 /* disable break condition */
1492 serial_out(info
, UART_LCR
, serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
1494 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
1495 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1496 serial_outp(info
, UART_MCR
, info
->MCR
);
1498 /* disable FIFO's */
1499 serial_outp(info
, UART_FCR
, (UART_FCR_ENABLE_FIFO
|
1500 UART_FCR_CLEAR_RCVR
|
1501 UART_FCR_CLEAR_XMIT
));
1502 serial_outp(info
, UART_FCR
, 0);
1504 #ifdef CONFIG_SERIAL_RSA
1506 * Reset the RSA board back to 115kbps compat mode.
1508 if ((state
->type
== PORT_RSA
) &&
1509 (state
->baud_base
== SERIAL_RSA_BAUD_BASE
&&
1511 state
->baud_base
= SERIAL_RSA_BAUD_BASE_LO
;
1515 (void)serial_in(info
, UART_RX
); /* read data port to reset things */
1518 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1520 if (uart_config
[info
->state
->type
].flags
& UART_STARTECH
) {
1521 /* Arrange to enter sleep mode */
1522 serial_outp(info
, UART_LCR
, 0xBF);
1523 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1524 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
1525 serial_outp(info
, UART_LCR
, 0);
1527 if (info
->state
->type
== PORT_16750
) {
1528 /* Arrange to enter sleep mode */
1529 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
1531 info
->flags
&= ~ASYNC_INITIALIZED
;
1532 restore_flags(flags
);
1535 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
1536 static int baud_table
[] = {
1537 0, 50, 75, 110, 134, 150, 200, 300,
1538 600, 1200, 1800, 2400, 4800, 9600, 19200,
1539 38400, 57600, 115200, 230400, 460800, 0 };
1541 static int tty_get_baud_rate(struct tty_struct
*tty
)
1543 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
1544 unsigned int cflag
, i
;
1546 cflag
= tty
->termios
->c_cflag
;
1552 tty
->termios
->c_cflag
&= ~CBAUDEX
;
1557 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1559 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1562 return baud_table
[i
];
1567 * This routine is called to set the UART divisor registers to match
1568 * the specified baud rate for a serial port.
1570 static void change_speed(struct async_struct
*info
,
1571 struct termios
*old_termios
)
1573 int quot
= 0, baud_base
, baud
;
1574 unsigned cflag
, cval
, fcr
= 0;
1576 unsigned long flags
;
1578 if (!info
->tty
|| !info
->tty
->termios
)
1580 cflag
= info
->tty
->termios
->c_cflag
;
1581 if (!CONFIGURED_SERIAL_PORT(info
))
1584 /* byte size and parity */
1585 switch (cflag
& CSIZE
) {
1586 case CS5
: cval
= 0x00; bits
= 7; break;
1587 case CS6
: cval
= 0x01; bits
= 8; break;
1588 case CS7
: cval
= 0x02; bits
= 9; break;
1589 case CS8
: cval
= 0x03; bits
= 10; break;
1590 /* Never happens, but GCC is too dumb to figure it out */
1591 default: cval
= 0x00; bits
= 7; break;
1593 if (cflag
& CSTOPB
) {
1597 if (cflag
& PARENB
) {
1598 cval
|= UART_LCR_PARITY
;
1601 if (!(cflag
& PARODD
))
1602 cval
|= UART_LCR_EPAR
;
1605 cval
|= UART_LCR_SPAR
;
1608 /* Determine divisor based on baud rate */
1609 baud
= tty_get_baud_rate(info
->tty
);
1611 baud
= 9600; /* B0 transition handled in rs_set_termios */
1612 #ifdef CONFIG_SERIAL_RSA
1613 if ((info
->state
->type
== PORT_RSA
) &&
1614 (info
->state
->baud_base
!= SERIAL_RSA_BAUD_BASE
) &&
1616 info
->state
->baud_base
= SERIAL_RSA_BAUD_BASE
;
1618 baud_base
= info
->state
->baud_base
;
1619 if (info
->state
->type
== PORT_16C950
) {
1620 if (baud
<= baud_base
)
1621 serial_icr_write(info
, UART_TCR
, 0);
1622 else if (baud
<= 2*baud_base
) {
1623 serial_icr_write(info
, UART_TCR
, 0x8);
1624 baud_base
= baud_base
* 2;
1625 } else if (baud
<= 4*baud_base
) {
1626 serial_icr_write(info
, UART_TCR
, 0x4);
1627 baud_base
= baud_base
* 4;
1629 serial_icr_write(info
, UART_TCR
, 0);
1631 if (baud
== 38400 &&
1632 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1633 quot
= info
->state
->custom_divisor
;
1636 /* Special case since 134 is really 134.5 */
1637 quot
= (2*baud_base
/ 269);
1639 quot
= baud_base
/ baud
;
1641 /* If the quotient is zero refuse the change */
1642 if (!quot
&& old_termios
) {
1643 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1644 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1645 baud
= tty_get_baud_rate(info
->tty
);
1648 if (baud
== 38400 &&
1649 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1650 quot
= info
->state
->custom_divisor
;
1653 /* Special case since 134 is really 134.5 */
1654 quot
= (2*baud_base
/ 269);
1656 quot
= baud_base
/ baud
;
1659 /* As a last resort, if the quotient is zero, default to 9600 bps */
1661 quot
= baud_base
/ 9600;
1663 * Work around a bug in the Oxford Semiconductor 952 rev B
1664 * chip which causes it to seriously miscalculate baud rates
1667 if (((quot
& 0xFF) == 0) && (info
->state
->type
== PORT_16C950
) &&
1668 (info
->state
->revision
== 0x5201))
1672 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
*quot
) / baud_base
);
1673 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
1676 if (uart_config
[info
->state
->type
].flags
& UART_USE_FIFO
) {
1677 if ((info
->state
->baud_base
/ quot
) < 2400)
1678 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
1679 #ifdef CONFIG_SERIAL_RSA
1680 else if (info
->state
->type
== PORT_RSA
)
1681 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_14
;
1684 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
1686 if (info
->state
->type
== PORT_16750
)
1687 fcr
|= UART_FCR7_64BYTE
;
1689 /* CTS flow control flag and modem status interrupts */
1690 info
->IER
&= ~UART_IER_MSI
;
1691 if (info
->flags
& ASYNC_HARDPPS_CD
)
1692 info
->IER
|= UART_IER_MSI
;
1693 if (cflag
& CRTSCTS
) {
1694 info
->flags
|= ASYNC_CTS_FLOW
;
1695 info
->IER
|= UART_IER_MSI
;
1697 info
->flags
&= ~ASYNC_CTS_FLOW
;
1699 info
->flags
&= ~ASYNC_CHECK_CD
;
1701 info
->flags
|= ASYNC_CHECK_CD
;
1702 info
->IER
|= UART_IER_MSI
;
1704 serial_out(info
, UART_IER
, info
->IER
);
1707 * Set up parity check flag
1709 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1711 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
1712 if (I_INPCK(info
->tty
))
1713 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
1714 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
1715 info
->read_status_mask
|= UART_LSR_BI
;
1718 * Characters to ignore
1720 info
->ignore_status_mask
= 0;
1721 if (I_IGNPAR(info
->tty
))
1722 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
1723 if (I_IGNBRK(info
->tty
)) {
1724 info
->ignore_status_mask
|= UART_LSR_BI
;
1726 * If we're ignore parity and break indicators, ignore
1727 * overruns too. (For real raw support).
1729 if (I_IGNPAR(info
->tty
))
1730 info
->ignore_status_mask
|= UART_LSR_OE
;
1733 * !!! ignore all characters if CREAD is not set
1735 if ((cflag
& CREAD
) == 0)
1736 info
->ignore_status_mask
|= UART_LSR_DR
;
1737 save_flags(flags
); cli();
1738 if (uart_config
[info
->state
->type
].flags
& UART_STARTECH
) {
1739 serial_outp(info
, UART_LCR
, 0xBF);
1740 serial_outp(info
, UART_EFR
,
1741 (cflag
& CRTSCTS
) ? UART_EFR_CTS
: 0);
1743 serial_outp(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
1744 serial_outp(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
1745 serial_outp(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
1746 if (info
->state
->type
== PORT_16750
)
1747 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1748 serial_outp(info
, UART_LCR
, cval
); /* reset DLAB */
1749 info
->LCR
= cval
; /* Save LCR */
1750 if (info
->state
->type
!= PORT_16750
) {
1751 if (fcr
& UART_FCR_ENABLE_FIFO
) {
1752 /* emulated UARTs (Lucent Venus 167x) need two steps */
1753 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1755 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1757 restore_flags(flags
);
1760 static void rs_put_char(struct tty_struct
*tty
, unsigned char ch
)
1762 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1763 unsigned long flags
;
1765 if (serial_paranoia_check(info
, tty
->device
, "rs_put_char"))
1768 if (!tty
|| !info
->xmit
.buf
)
1771 save_flags(flags
); cli();
1772 if (CIRC_SPACE(info
->xmit
.head
,
1774 SERIAL_XMIT_SIZE
) == 0) {
1775 restore_flags(flags
);
1779 info
->xmit
.buf
[info
->xmit
.head
] = ch
;
1780 info
->xmit
.head
= (info
->xmit
.head
+ 1) & (SERIAL_XMIT_SIZE
-1);
1781 restore_flags(flags
);
1784 static void rs_flush_chars(struct tty_struct
*tty
)
1786 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1787 unsigned long flags
;
1789 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_chars"))
1792 if (info
->xmit
.head
== info
->xmit
.tail
1798 save_flags(flags
); cli();
1799 info
->IER
|= UART_IER_THRI
;
1800 serial_out(info
, UART_IER
, info
->IER
);
1801 restore_flags(flags
);
1804 static int rs_write(struct tty_struct
* tty
, int from_user
,
1805 const unsigned char *buf
, int count
)
1808 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1809 unsigned long flags
;
1811 if (serial_paranoia_check(info
, tty
->device
, "rs_write"))
1814 if (!tty
|| !info
->xmit
.buf
|| !tmp_buf
)
1822 c
= CIRC_SPACE_TO_END(info
->xmit
.head
,
1830 c
-= copy_from_user(tmp_buf
, buf
, c
);
1837 c1
= CIRC_SPACE_TO_END(info
->xmit
.head
,
1842 memcpy(info
->xmit
.buf
+ info
->xmit
.head
, tmp_buf
, c
);
1843 info
->xmit
.head
= ((info
->xmit
.head
+ c
) &
1844 (SERIAL_XMIT_SIZE
-1));
1845 restore_flags(flags
);
1854 c
= CIRC_SPACE_TO_END(info
->xmit
.head
,
1862 memcpy(info
->xmit
.buf
+ info
->xmit
.head
, buf
, c
);
1863 info
->xmit
.head
= ((info
->xmit
.head
+ c
) &
1864 (SERIAL_XMIT_SIZE
-1));
1869 restore_flags(flags
);
1871 if (info
->xmit
.head
!= info
->xmit
.tail
1874 && !(info
->IER
& UART_IER_THRI
)) {
1875 info
->IER
|= UART_IER_THRI
;
1876 serial_out(info
, UART_IER
, info
->IER
);
1881 static int rs_write_room(struct tty_struct
*tty
)
1883 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1885 if (serial_paranoia_check(info
, tty
->device
, "rs_write_room"))
1887 return CIRC_SPACE(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
1890 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1892 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1894 if (serial_paranoia_check(info
, tty
->device
, "rs_chars_in_buffer"))
1896 return CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
, SERIAL_XMIT_SIZE
);
1899 static void rs_flush_buffer(struct tty_struct
*tty
)
1901 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1902 unsigned long flags
;
1904 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_buffer"))
1906 save_flags(flags
); cli();
1907 info
->xmit
.head
= info
->xmit
.tail
= 0;
1908 restore_flags(flags
);
1909 wake_up_interruptible(&tty
->write_wait
);
1910 #ifdef SERIAL_HAVE_POLL_WAIT
1911 wake_up_interruptible(&tty
->poll_wait
);
1913 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1914 tty
->ldisc
.write_wakeup
)
1915 (tty
->ldisc
.write_wakeup
)(tty
);
1919 * This function is used to send a high-priority XON/XOFF character to
1922 static void rs_send_xchar(struct tty_struct
*tty
, char ch
)
1924 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1926 if (serial_paranoia_check(info
, tty
->device
, "rs_send_char"))
1931 /* Make sure transmit interrupts are on */
1932 info
->IER
|= UART_IER_THRI
;
1933 serial_out(info
, UART_IER
, info
->IER
);
1938 * ------------------------------------------------------------
1941 * This routine is called by the upper-layer tty layer to signal that
1942 * incoming characters should be throttled.
1943 * ------------------------------------------------------------
1945 static void rs_throttle(struct tty_struct
* tty
)
1947 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1948 unsigned long flags
;
1949 #ifdef SERIAL_DEBUG_THROTTLE
1952 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1953 tty
->ldisc
.chars_in_buffer(tty
));
1956 if (serial_paranoia_check(info
, tty
->device
, "rs_throttle"))
1960 rs_send_xchar(tty
, STOP_CHAR(tty
));
1962 if (tty
->termios
->c_cflag
& CRTSCTS
)
1963 info
->MCR
&= ~UART_MCR_RTS
;
1965 save_flags(flags
); cli();
1966 serial_out(info
, UART_MCR
, info
->MCR
);
1967 restore_flags(flags
);
1970 static void rs_unthrottle(struct tty_struct
* tty
)
1972 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1973 unsigned long flags
;
1974 #ifdef SERIAL_DEBUG_THROTTLE
1977 printk("unthrottle %s: %d....\n", tty_name(tty
, buf
),
1978 tty
->ldisc
.chars_in_buffer(tty
));
1981 if (serial_paranoia_check(info
, tty
->device
, "rs_unthrottle"))
1988 rs_send_xchar(tty
, START_CHAR(tty
));
1990 if (tty
->termios
->c_cflag
& CRTSCTS
)
1991 info
->MCR
|= UART_MCR_RTS
;
1992 save_flags(flags
); cli();
1993 serial_out(info
, UART_MCR
, info
->MCR
);
1994 restore_flags(flags
);
1998 * ------------------------------------------------------------
1999 * rs_ioctl() and friends
2000 * ------------------------------------------------------------
2003 static int get_serial_info(struct async_struct
* info
,
2004 struct serial_struct
* retinfo
)
2006 struct serial_struct tmp
;
2007 struct serial_state
*state
= info
->state
;
2011 memset(&tmp
, 0, sizeof(tmp
));
2012 tmp
.type
= state
->type
;
2013 tmp
.line
= state
->line
;
2014 tmp
.port
= state
->port
;
2015 if (HIGH_BITS_OFFSET
)
2016 tmp
.port_high
= state
->port
>> HIGH_BITS_OFFSET
;
2019 tmp
.irq
= state
->irq
;
2020 tmp
.flags
= state
->flags
;
2021 tmp
.xmit_fifo_size
= state
->xmit_fifo_size
;
2022 tmp
.baud_base
= state
->baud_base
;
2023 tmp
.close_delay
= state
->close_delay
;
2024 tmp
.closing_wait
= state
->closing_wait
;
2025 tmp
.custom_divisor
= state
->custom_divisor
;
2026 tmp
.hub6
= state
->hub6
;
2027 tmp
.io_type
= state
->io_type
;
2028 if (copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)))
2033 static int set_serial_info(struct async_struct
* info
,
2034 struct serial_struct
* new_info
)
2036 struct serial_struct new_serial
;
2037 struct serial_state old_state
, *state
;
2038 unsigned int i
,change_irq
,change_port
;
2040 unsigned long new_port
;
2042 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
2044 state
= info
->state
;
2047 new_port
= new_serial
.port
;
2048 if (HIGH_BITS_OFFSET
)
2049 new_port
+= new_serial
.port_high
<< HIGH_BITS_OFFSET
;
2051 change_irq
= new_serial
.irq
!= state
->irq
;
2052 change_port
= (new_port
!= ((int) state
->port
)) ||
2053 (new_serial
.hub6
!= state
->hub6
);
2055 if (!capable(CAP_SYS_ADMIN
)) {
2056 if (change_irq
|| change_port
||
2057 (new_serial
.baud_base
!= state
->baud_base
) ||
2058 (new_serial
.type
!= state
->type
) ||
2059 (new_serial
.close_delay
!= state
->close_delay
) ||
2060 (new_serial
.xmit_fifo_size
!= state
->xmit_fifo_size
) ||
2061 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
2062 (state
->flags
& ~ASYNC_USR_MASK
)))
2064 state
->flags
= ((state
->flags
& ~ASYNC_USR_MASK
) |
2065 (new_serial
.flags
& ASYNC_USR_MASK
));
2066 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
2067 (new_serial
.flags
& ASYNC_USR_MASK
));
2068 state
->custom_divisor
= new_serial
.custom_divisor
;
2069 goto check_and_exit
;
2072 new_serial
.irq
= irq_cannonicalize(new_serial
.irq
);
2074 if ((new_serial
.irq
>= NR_IRQS
) ||
2075 (new_serial
.baud_base
< 9600)|| (new_serial
.type
< PORT_UNKNOWN
) ||
2076 (new_serial
.type
> PORT_MAX
) || (new_serial
.type
== PORT_CIRRUS
) ||
2077 (new_serial
.type
== PORT_STARTECH
)) {
2081 if ((new_serial
.type
!= state
->type
) ||
2082 (new_serial
.xmit_fifo_size
<= 0))
2083 new_serial
.xmit_fifo_size
=
2084 uart_config
[new_serial
.type
].dfl_xmit_fifo_size
;
2086 /* Make sure address is not already in use */
2087 if (new_serial
.type
) {
2088 for (i
= 0 ; i
< NR_PORTS
; i
++)
2089 if ((state
!= &rs_table
[i
]) &&
2090 (rs_table
[i
].port
== new_port
) &&
2095 if ((change_port
|| change_irq
) && (state
->count
> 1))
2099 * OK, past this point, all the error checking has been done.
2100 * At this point, we start making changes.....
2103 state
->baud_base
= new_serial
.baud_base
;
2104 state
->flags
= ((state
->flags
& ~ASYNC_FLAGS
) |
2105 (new_serial
.flags
& ASYNC_FLAGS
));
2106 info
->flags
= ((state
->flags
& ~ASYNC_INTERNAL_FLAGS
) |
2107 (info
->flags
& ASYNC_INTERNAL_FLAGS
));
2108 state
->custom_divisor
= new_serial
.custom_divisor
;
2109 state
->close_delay
= new_serial
.close_delay
* HZ
/100;
2110 state
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
2111 #if (LINUX_VERSION_CODE > 0x20100)
2112 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2114 info
->xmit_fifo_size
= state
->xmit_fifo_size
=
2115 new_serial
.xmit_fifo_size
;
2117 if ((state
->type
!= PORT_UNKNOWN
) && state
->port
) {
2118 #ifdef CONFIG_SERIAL_RSA
2119 if (old_state
.type
== PORT_RSA
)
2120 release_region(state
->port
+ UART_RSA_BASE
, 16);
2123 release_region(state
->port
,8);
2125 state
->type
= new_serial
.type
;
2126 if (change_port
|| change_irq
) {
2128 * We need to shutdown the serial port at the old
2129 * port/irq combination.
2132 state
->irq
= new_serial
.irq
;
2133 info
->port
= state
->port
= new_port
;
2134 info
->hub6
= state
->hub6
= new_serial
.hub6
;
2136 info
->io_type
= state
->io_type
= SERIAL_IO_HUB6
;
2137 else if (info
->io_type
== SERIAL_IO_HUB6
)
2138 info
->io_type
= state
->io_type
= SERIAL_IO_PORT
;
2140 if ((state
->type
!= PORT_UNKNOWN
) && state
->port
) {
2141 #ifdef CONFIG_SERIAL_RSA
2142 if (state
->type
== PORT_RSA
)
2143 request_region(state
->port
+ UART_RSA_BASE
,
2144 16, "serial_rsa(set)");
2147 request_region(state
->port
,8,"serial(set)");
2152 if (!state
->port
|| !state
->type
)
2154 if (info
->flags
& ASYNC_INITIALIZED
) {
2155 if (((old_state
.flags
& ASYNC_SPD_MASK
) !=
2156 (state
->flags
& ASYNC_SPD_MASK
)) ||
2157 (old_state
.custom_divisor
!= state
->custom_divisor
)) {
2158 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
2159 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
2160 info
->tty
->alt_speed
= 57600;
2161 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
2162 info
->tty
->alt_speed
= 115200;
2163 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
2164 info
->tty
->alt_speed
= 230400;
2165 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
2166 info
->tty
->alt_speed
= 460800;
2168 change_speed(info
, 0);
2171 retval
= startup(info
);
2177 * get_lsr_info - get line status register info
2179 * Purpose: Let user call ioctl() to get info when the UART physically
2180 * is emptied. On bus types like RS485, the transmitter must
2181 * release the bus after transmitting. This must be done when
2182 * the transmit shift register is empty, not be done when the
2183 * transmit holding register is empty. This functionality
2184 * allows an RS485 driver to be written in user space.
2186 static int get_lsr_info(struct async_struct
* info
, unsigned int *value
)
2188 unsigned char status
;
2189 unsigned int result
;
2190 unsigned long flags
;
2192 save_flags(flags
); cli();
2193 status
= serial_in(info
, UART_LSR
);
2194 restore_flags(flags
);
2195 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2198 * If we're about to load something into the transmit
2199 * register, we'll pretend the transmitter isn't empty to
2200 * avoid a race condition (depending on when the transmit
2201 * interrupt happens).
2204 ((CIRC_CNT(info
->xmit
.head
, info
->xmit
.tail
,
2205 SERIAL_XMIT_SIZE
) > 0) &&
2206 !info
->tty
->stopped
&& !info
->tty
->hw_stopped
))
2207 result
&= TIOCSER_TEMT
;
2209 if (copy_to_user(value
, &result
, sizeof(int)))
2215 static int get_modem_info(struct async_struct
* info
, unsigned int *value
)
2217 unsigned char control
, status
;
2218 unsigned int result
;
2219 unsigned long flags
;
2221 control
= info
->MCR
;
2222 save_flags(flags
); cli();
2223 status
= serial_in(info
, UART_MSR
);
2224 restore_flags(flags
);
2225 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
2226 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
2228 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
2229 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
2231 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
2232 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
2233 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
2234 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2236 if (copy_to_user(value
, &result
, sizeof(int)))
2241 static int set_modem_info(struct async_struct
* info
, unsigned int cmd
,
2242 unsigned int *value
)
2245 unsigned long flags
;
2247 if (copy_from_user(&arg
, value
, sizeof(int)))
2252 if (arg
& TIOCM_RTS
)
2253 info
->MCR
|= UART_MCR_RTS
;
2254 if (arg
& TIOCM_DTR
)
2255 info
->MCR
|= UART_MCR_DTR
;
2257 if (arg
& TIOCM_OUT1
)
2258 info
->MCR
|= UART_MCR_OUT1
;
2259 if (arg
& TIOCM_OUT2
)
2260 info
->MCR
|= UART_MCR_OUT2
;
2262 if (arg
& TIOCM_LOOP
)
2263 info
->MCR
|= UART_MCR_LOOP
;
2266 if (arg
& TIOCM_RTS
)
2267 info
->MCR
&= ~UART_MCR_RTS
;
2268 if (arg
& TIOCM_DTR
)
2269 info
->MCR
&= ~UART_MCR_DTR
;
2271 if (arg
& TIOCM_OUT1
)
2272 info
->MCR
&= ~UART_MCR_OUT1
;
2273 if (arg
& TIOCM_OUT2
)
2274 info
->MCR
&= ~UART_MCR_OUT2
;
2276 if (arg
& TIOCM_LOOP
)
2277 info
->MCR
&= ~UART_MCR_LOOP
;
2280 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
|
2287 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
2289 | ((arg
& TIOCM_OUT1
) ? UART_MCR_OUT1
: 0)
2290 | ((arg
& TIOCM_OUT2
) ? UART_MCR_OUT2
: 0)
2292 | ((arg
& TIOCM_LOOP
) ? UART_MCR_LOOP
: 0)
2293 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
2298 save_flags(flags
); cli();
2299 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
2300 serial_out(info
, UART_MCR
, info
->MCR
);
2301 restore_flags(flags
);
2305 static int do_autoconfig(struct async_struct
* info
)
2309 if (!capable(CAP_SYS_ADMIN
))
2312 if (info
->state
->count
> 1)
2317 autoconfig(info
->state
);
2318 if ((info
->state
->flags
& ASYNC_AUTO_IRQ
) &&
2319 (info
->state
->port
!= 0) &&
2320 (info
->state
->type
!= PORT_UNKNOWN
))
2321 info
->state
->irq
= detect_uart_irq(info
->state
);
2323 retval
= startup(info
);
2330 * rs_break() --- routine which turns the break handling on or off
2332 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2333 static void send_break( struct async_struct
* info
, int duration
)
2335 if (!CONFIGURED_SERIAL_PORT(info
))
2337 current
->state
= TASK_INTERRUPTIBLE
;
2338 current
->timeout
= jiffies
+ duration
;
2340 info
->LCR
|= UART_LCR_SBC
;
2341 serial_out(info
, UART_LCR
, info
->LCR
);
2343 info
->LCR
&= ~UART_LCR_SBC
;
2344 serial_out(info
, UART_LCR
, info
->LCR
);
2348 static void rs_break(struct tty_struct
*tty
, int break_state
)
2350 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2351 unsigned long flags
;
2353 if (serial_paranoia_check(info
, tty
->device
, "rs_break"))
2356 if (!CONFIGURED_SERIAL_PORT(info
))
2358 save_flags(flags
); cli();
2359 if (break_state
== -1)
2360 info
->LCR
|= UART_LCR_SBC
;
2362 info
->LCR
&= ~UART_LCR_SBC
;
2363 serial_out(info
, UART_LCR
, info
->LCR
);
2364 restore_flags(flags
);
2368 #ifdef CONFIG_SERIAL_MULTIPORT
2369 static int get_multiport_struct(struct async_struct
* info
,
2370 struct serial_multiport_struct
*retinfo
)
2372 struct serial_multiport_struct ret
;
2373 struct rs_multiport_struct
*multi
;
2375 multi
= &rs_multiport
[info
->state
->irq
];
2377 ret
.port_monitor
= multi
->port_monitor
;
2379 ret
.port1
= multi
->port1
;
2380 ret
.mask1
= multi
->mask1
;
2381 ret
.match1
= multi
->match1
;
2383 ret
.port2
= multi
->port2
;
2384 ret
.mask2
= multi
->mask2
;
2385 ret
.match2
= multi
->match2
;
2387 ret
.port3
= multi
->port3
;
2388 ret
.mask3
= multi
->mask3
;
2389 ret
.match3
= multi
->match3
;
2391 ret
.port4
= multi
->port4
;
2392 ret
.mask4
= multi
->mask4
;
2393 ret
.match4
= multi
->match4
;
2395 ret
.irq
= info
->state
->irq
;
2397 if (copy_to_user(retinfo
,&ret
,sizeof(*retinfo
)))
2402 static int set_multiport_struct(struct async_struct
* info
,
2403 struct serial_multiport_struct
*in_multi
)
2405 struct serial_multiport_struct new_multi
;
2406 struct rs_multiport_struct
*multi
;
2407 struct serial_state
*state
;
2408 int was_multi
, now_multi
;
2410 void (*handler
)(int, void *, struct pt_regs
*);
2412 if (!capable(CAP_SYS_ADMIN
))
2414 state
= info
->state
;
2416 if (copy_from_user(&new_multi
, in_multi
,
2417 sizeof(struct serial_multiport_struct
)))
2420 if (new_multi
.irq
!= state
->irq
|| state
->irq
== 0 ||
2421 !IRQ_ports
[state
->irq
])
2424 multi
= &rs_multiport
[state
->irq
];
2425 was_multi
= (multi
->port1
!= 0);
2427 multi
->port_monitor
= new_multi
.port_monitor
;
2430 release_region(multi
->port1
,1);
2431 multi
->port1
= new_multi
.port1
;
2432 multi
->mask1
= new_multi
.mask1
;
2433 multi
->match1
= new_multi
.match1
;
2435 request_region(multi
->port1
,1,"serial(multiport1)");
2438 release_region(multi
->port2
,1);
2439 multi
->port2
= new_multi
.port2
;
2440 multi
->mask2
= new_multi
.mask2
;
2441 multi
->match2
= new_multi
.match2
;
2443 request_region(multi
->port2
,1,"serial(multiport2)");
2446 release_region(multi
->port3
,1);
2447 multi
->port3
= new_multi
.port3
;
2448 multi
->mask3
= new_multi
.mask3
;
2449 multi
->match3
= new_multi
.match3
;
2451 request_region(multi
->port3
,1,"serial(multiport3)");
2454 release_region(multi
->port4
,1);
2455 multi
->port4
= new_multi
.port4
;
2456 multi
->mask4
= new_multi
.mask4
;
2457 multi
->match4
= new_multi
.match4
;
2459 request_region(multi
->port4
,1,"serial(multiport4)");
2461 now_multi
= (multi
->port1
!= 0);
2463 if (IRQ_ports
[state
->irq
]->next_port
&&
2464 (was_multi
!= now_multi
)) {
2465 free_irq(state
->irq
, &IRQ_ports
[state
->irq
]);
2467 handler
= rs_interrupt_multi
;
2469 handler
= rs_interrupt
;
2471 retval
= request_irq(state
->irq
, handler
, SA_SHIRQ
,
2472 "serial", &IRQ_ports
[state
->irq
]);
2474 printk("Couldn't reallocate serial interrupt "
2482 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
2483 unsigned int cmd
, unsigned long arg
)
2485 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2486 struct async_icount cprev
, cnow
; /* kernel counter temps */
2487 struct serial_icounter_struct icount
;
2488 unsigned long flags
;
2489 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2493 if (serial_paranoia_check(info
, tty
->device
, "rs_ioctl"))
2496 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
2497 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
2498 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
2499 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2504 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2505 case TCSBRK
: /* SVID version: non-zero arg --> no break */
2506 retval
= tty_check_change(tty
);
2509 tty_wait_until_sent(tty
, 0);
2510 if (signal_pending(current
))
2513 send_break(info
, HZ
/4); /* 1/4 second */
2514 if (signal_pending(current
))
2518 case TCSBRKP
: /* support for POSIX tcsendbreak() */
2519 retval
= tty_check_change(tty
);
2522 tty_wait_until_sent(tty
, 0);
2523 if (signal_pending(current
))
2525 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
2526 if (signal_pending(current
))
2530 tmp
= C_CLOCAL(tty
) ? 1 : 0;
2531 if (copy_to_user((void *)arg
, &tmp
, sizeof(int)))
2535 if (copy_from_user(&tmp
, (void *)arg
, sizeof(int)))
2538 tty
->termios
->c_cflag
=
2539 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
2540 (tmp
? CLOCAL
: 0));
2544 return get_modem_info(info
, (unsigned int *) arg
);
2548 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
2550 return get_serial_info(info
,
2551 (struct serial_struct
*) arg
);
2553 return set_serial_info(info
,
2554 (struct serial_struct
*) arg
);
2556 return do_autoconfig(info
);
2558 case TIOCSERGETLSR
: /* Get line status register */
2559 return get_lsr_info(info
, (unsigned int *) arg
);
2561 case TIOCSERGSTRUCT
:
2562 if (copy_to_user((struct async_struct
*) arg
,
2563 info
, sizeof(struct async_struct
)))
2567 #ifdef CONFIG_SERIAL_MULTIPORT
2568 case TIOCSERGETMULTI
:
2569 return get_multiport_struct(info
,
2570 (struct serial_multiport_struct
*) arg
);
2571 case TIOCSERSETMULTI
:
2572 return set_multiport_struct(info
,
2573 (struct serial_multiport_struct
*) arg
);
2577 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2578 * - mask passed in arg for lines of interest
2579 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2580 * Caller should use TIOCGICOUNT to see which one it was
2583 save_flags(flags
); cli();
2584 /* note the counters on entry */
2585 cprev
= info
->state
->icount
;
2586 restore_flags(flags
);
2587 /* Force modem status interrupts on */
2588 info
->IER
|= UART_IER_MSI
;
2589 serial_out(info
, UART_IER
, info
->IER
);
2591 interruptible_sleep_on(&info
->delta_msr_wait
);
2592 /* see if a signal did it */
2593 if (signal_pending(current
))
2594 return -ERESTARTSYS
;
2595 save_flags(flags
); cli();
2596 cnow
= info
->state
->icount
; /* atomic copy */
2597 restore_flags(flags
);
2598 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2599 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2600 return -EIO
; /* no change => error */
2601 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2602 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2603 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2604 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2612 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2613 * Return: write counters to the user passed counter struct
2614 * NB: both 1->0 and 0->1 transitions are counted except for
2615 * RI where only 0->1 is counted.
2618 save_flags(flags
); cli();
2619 cnow
= info
->state
->icount
;
2620 restore_flags(flags
);
2621 icount
.cts
= cnow
.cts
;
2622 icount
.dsr
= cnow
.dsr
;
2623 icount
.rng
= cnow
.rng
;
2624 icount
.dcd
= cnow
.dcd
;
2625 icount
.rx
= cnow
.rx
;
2626 icount
.tx
= cnow
.tx
;
2627 icount
.frame
= cnow
.frame
;
2628 icount
.overrun
= cnow
.overrun
;
2629 icount
.parity
= cnow
.parity
;
2630 icount
.brk
= cnow
.brk
;
2631 icount
.buf_overrun
= cnow
.buf_overrun
;
2633 if (copy_to_user((void *)arg
, &icount
, sizeof(icount
)))
2638 /* "setserial -W" is called in Debian boot */
2639 printk ("TIOCSER?WILD ioctl obsolete, ignored.\n");
2643 return -ENOIOCTLCMD
;
2648 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
2650 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
2651 unsigned long flags
;
2652 unsigned int cflag
= tty
->termios
->c_cflag
;
2654 if ( (cflag
== old_termios
->c_cflag
)
2655 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
2656 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
2659 change_speed(info
, old_termios
);
2661 /* Handle transition to B0 status */
2662 if ((old_termios
->c_cflag
& CBAUD
) &&
2664 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
2665 save_flags(flags
); cli();
2666 serial_out(info
, UART_MCR
, info
->MCR
);
2667 restore_flags(flags
);
2670 /* Handle transition away from B0 status */
2671 if (!(old_termios
->c_cflag
& CBAUD
) &&
2673 info
->MCR
|= UART_MCR_DTR
;
2674 if (!(tty
->termios
->c_cflag
& CRTSCTS
) ||
2675 !test_bit(TTY_THROTTLED
, &tty
->flags
)) {
2676 info
->MCR
|= UART_MCR_RTS
;
2678 save_flags(flags
); cli();
2679 serial_out(info
, UART_MCR
, info
->MCR
);
2680 restore_flags(flags
);
2683 /* Handle turning off CRTSCTS */
2684 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2685 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
2686 tty
->hw_stopped
= 0;
2692 * No need to wake up processes in open wait, since they
2693 * sample the CLOCAL flag once, and don't recheck it.
2694 * XXX It's not clear whether the current behavior is correct
2695 * or not. Hence, this may change.....
2697 if (!(old_termios
->c_cflag
& CLOCAL
) &&
2698 (tty
->termios
->c_cflag
& CLOCAL
))
2699 wake_up_interruptible(&info
->open_wait
);
2704 * ------------------------------------------------------------
2707 * This routine is called when the serial port gets closed. First, we
2708 * wait for the last remaining data to be sent. Then, we unlink its
2709 * async structure from the interrupt chain if necessary, and we free
2710 * that IRQ if nothing is left in the chain.
2711 * ------------------------------------------------------------
2713 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
2715 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2716 struct serial_state
*state
;
2717 unsigned long flags
;
2719 if (!info
|| serial_paranoia_check(info
, tty
->device
, "rs_close"))
2722 state
= info
->state
;
2724 save_flags(flags
); cli();
2726 if (tty_hung_up_p(filp
)) {
2727 DBG_CNT("before DEC-hung");
2729 restore_flags(flags
);
2733 #ifdef SERIAL_DEBUG_OPEN
2734 printk("rs_close ttys%d, count = %d\n", info
->line
, state
->count
);
2736 if ((tty
->count
== 1) && (state
->count
!= 1)) {
2738 * Uh, oh. tty->count is 1, which means that the tty
2739 * structure will be freed. state->count should always
2740 * be one in these conditions. If it's greater than
2741 * one, we've got real problems, since it means the
2742 * serial port won't be shutdown.
2744 printk("rs_close: bad serial port count; tty->count is 1, "
2745 "state->count is %d\n", state
->count
);
2748 if (--state
->count
< 0) {
2749 printk("rs_close: bad serial port count for ttys%d: %d\n",
2750 info
->line
, state
->count
);
2754 DBG_CNT("before DEC-2");
2756 restore_flags(flags
);
2759 info
->flags
|= ASYNC_CLOSING
;
2760 restore_flags(flags
);
2762 * Save the termios structure, since this port may have
2763 * separate termios for callout and dialin.
2765 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2766 info
->state
->normal_termios
= *tty
->termios
;
2767 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2768 info
->state
->callout_termios
= *tty
->termios
;
2770 * Now we wait for the transmit buffer to clear; and we notify
2771 * the line discipline to only process XON/XOFF characters.
2774 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
2775 tty_wait_until_sent(tty
, info
->closing_wait
);
2777 * At this point we stop accepting input. To do this, we
2778 * disable the receive line status interrupts, and tell the
2779 * interrupt driver to stop checking the data ready bit in the
2780 * line status register.
2782 info
->IER
&= ~UART_IER_RLSI
;
2783 info
->read_status_mask
&= ~UART_LSR_DR
;
2784 if (info
->flags
& ASYNC_INITIALIZED
) {
2785 serial_out(info
, UART_IER
, info
->IER
);
2787 * Before we drop DTR, make sure the UART transmitter
2788 * has completely drained; this is especially
2789 * important if there is a transmit FIFO!
2791 rs_wait_until_sent(tty
, info
->timeout
);
2794 if (tty
->driver
.flush_buffer
)
2795 tty
->driver
.flush_buffer(tty
);
2796 if (tty
->ldisc
.flush_buffer
)
2797 tty
->ldisc
.flush_buffer(tty
);
2801 if (info
->blocked_open
) {
2802 if (info
->close_delay
) {
2803 set_current_state(TASK_INTERRUPTIBLE
);
2804 schedule_timeout(info
->close_delay
);
2806 wake_up_interruptible(&info
->open_wait
);
2808 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
2810 wake_up_interruptible(&info
->close_wait
);
2815 * rs_wait_until_sent() --- wait until the transmitter is empty
2817 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2819 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2820 unsigned long orig_jiffies
, char_time
;
2823 if (serial_paranoia_check(info
, tty
->device
, "rs_wait_until_sent"))
2826 if (info
->state
->type
== PORT_UNKNOWN
)
2829 if (info
->xmit_fifo_size
== 0)
2830 return; /* Just in case.... */
2832 orig_jiffies
= jiffies
;
2834 * Set the check interval to be 1/5 of the estimated time to
2835 * send a single character, and make it at least 1. The check
2836 * interval should also be less than the timeout.
2838 * Note: we have to use pretty tight timings here to satisfy
2841 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2842 char_time
= char_time
/ 5;
2845 if (timeout
&& timeout
< char_time
)
2846 char_time
= timeout
;
2848 * If the transmitter hasn't cleared in twice the approximate
2849 * amount of time to send the entire FIFO, it probably won't
2850 * ever clear. This assumes the UART isn't doing flow
2851 * control, which is currently the case. Hence, if it ever
2852 * takes longer than info->timeout, this is probably due to a
2853 * UART bug of some kind. So, we clamp the timeout parameter at
2856 if (!timeout
|| timeout
> 2*info
->timeout
)
2857 timeout
= 2*info
->timeout
;
2858 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2859 printk("In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2860 printk("jiff=%lu...", jiffies
);
2862 while (!((lsr
= serial_inp(info
, UART_LSR
)) & UART_LSR_TEMT
)) {
2863 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2864 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
2866 set_current_state(TASK_INTERRUPTIBLE
);
2867 schedule_timeout(char_time
);
2868 if (signal_pending(current
))
2870 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2873 set_current_state(TASK_RUNNING
);
2874 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2875 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
2880 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2882 static void rs_hangup(struct tty_struct
*tty
)
2884 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2885 struct serial_state
*state
= info
->state
;
2887 if (serial_paranoia_check(info
, tty
->device
, "rs_hangup"))
2890 state
= info
->state
;
2892 rs_flush_buffer(tty
);
2893 if (info
->flags
& ASYNC_CLOSING
)
2898 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
2900 wake_up_interruptible(&info
->open_wait
);
2904 * ------------------------------------------------------------
2905 * rs_open() and friends
2906 * ------------------------------------------------------------
2908 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2909 struct async_struct
*info
)
2911 DECLARE_WAITQUEUE(wait
, current
);
2912 struct serial_state
*state
= info
->state
;
2914 int do_clocal
= 0, extra_count
= 0;
2915 unsigned long flags
;
2918 * If the device is in the middle of being closed, then block
2919 * until it's done, and then try again.
2921 if (tty_hung_up_p(filp
) ||
2922 (info
->flags
& ASYNC_CLOSING
)) {
2923 if (info
->flags
& ASYNC_CLOSING
)
2924 interruptible_sleep_on(&info
->close_wait
);
2925 #ifdef SERIAL_DO_RESTART
2926 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2927 -EAGAIN
: -ERESTARTSYS
);
2934 * If this is a callout device, then just make sure the normal
2935 * device isn't being used.
2937 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
2938 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2940 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2941 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
2942 (info
->session
!= current
->session
))
2944 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2945 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
2946 (info
->pgrp
!= current
->pgrp
))
2948 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
2953 * If non-blocking mode is set, or the port is not enabled,
2954 * then make the check up front and then exit.
2956 if ((filp
->f_flags
& O_NONBLOCK
) ||
2957 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2958 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2960 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2964 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
2965 if (state
->normal_termios
.c_cflag
& CLOCAL
)
2968 if (tty
->termios
->c_cflag
& CLOCAL
)
2973 * Block waiting for the carrier detect and the line to become
2974 * free (i.e., not in use by the callout). While we are in
2975 * this loop, state->count is dropped by one, so that
2976 * rs_close() knows when to free things. We restore it upon
2977 * exit, either normal or abnormal.
2980 add_wait_queue(&info
->open_wait
, &wait
);
2981 #ifdef SERIAL_DEBUG_OPEN
2982 printk("block_til_ready before block: ttys%d, count = %d\n",
2983 state
->line
, state
->count
);
2985 save_flags(flags
); cli();
2986 if (!tty_hung_up_p(filp
)) {
2990 restore_flags(flags
);
2991 info
->blocked_open
++;
2993 save_flags(flags
); cli();
2994 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2995 (tty
->termios
->c_cflag
& CBAUD
))
2996 serial_out(info
, UART_MCR
,
2997 serial_inp(info
, UART_MCR
) |
2998 (UART_MCR_DTR
| UART_MCR_RTS
));
2999 restore_flags(flags
);
3000 set_current_state(TASK_INTERRUPTIBLE
);
3001 if (tty_hung_up_p(filp
) ||
3002 !(info
->flags
& ASYNC_INITIALIZED
)) {
3003 #ifdef SERIAL_DO_RESTART
3004 if (info
->flags
& ASYNC_HUP_NOTIFY
)
3007 retval
= -ERESTARTSYS
;
3013 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
3014 !(info
->flags
& ASYNC_CLOSING
) &&
3015 (do_clocal
|| (serial_in(info
, UART_MSR
) &
3018 if (signal_pending(current
)) {
3019 retval
= -ERESTARTSYS
;
3022 #ifdef SERIAL_DEBUG_OPEN
3023 printk("block_til_ready blocking: ttys%d, count = %d\n",
3024 info
->line
, state
->count
);
3028 set_current_state(TASK_RUNNING
);
3029 remove_wait_queue(&info
->open_wait
, &wait
);
3032 info
->blocked_open
--;
3033 #ifdef SERIAL_DEBUG_OPEN
3034 printk("block_til_ready after blocking: ttys%d, count = %d\n",
3035 info
->line
, state
->count
);
3039 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
3043 static int get_async_struct(int line
, struct async_struct
**ret_info
)
3045 struct async_struct
*info
;
3046 struct serial_state
*sstate
;
3048 sstate
= rs_table
+ line
;
3051 *ret_info
= sstate
->info
;
3054 info
= kmalloc(sizeof(struct async_struct
), GFP_KERNEL
);
3059 memset(info
, 0, sizeof(struct async_struct
));
3060 init_waitqueue_head(&info
->open_wait
);
3061 init_waitqueue_head(&info
->close_wait
);
3062 init_waitqueue_head(&info
->delta_msr_wait
);
3063 info
->magic
= SERIAL_MAGIC
;
3064 info
->port
= sstate
->port
;
3065 info
->flags
= sstate
->flags
;
3066 info
->io_type
= sstate
->io_type
;
3067 info
->iomem_base
= sstate
->iomem_base
;
3068 info
->iomem_reg_shift
= sstate
->iomem_reg_shift
;
3069 info
->xmit_fifo_size
= sstate
->xmit_fifo_size
;
3071 info
->tqueue
.routine
= do_softint
;
3072 info
->tqueue
.data
= info
;
3073 info
->state
= sstate
;
3075 kfree_s(info
, sizeof(struct async_struct
));
3076 *ret_info
= sstate
->info
;
3079 *ret_info
= sstate
->info
= info
;
3084 * This routine is called whenever a serial port is opened. It
3085 * enables interrupts for a serial port, linking in its async structure into
3086 * the IRQ chain. It also performs the serial-specific
3087 * initialization for the tty structure.
3089 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
3091 struct async_struct
*info
;
3096 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
3097 if ((line
< 0) || (line
>= NR_PORTS
)) {
3101 retval
= get_async_struct(line
, &info
);
3106 tty
->driver_data
= info
;
3108 if (serial_paranoia_check(info
, tty
->device
, "rs_open"))
3111 #ifdef SERIAL_DEBUG_OPEN
3112 printk("rs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
3113 info
->state
->count
);
3115 #if (LINUX_VERSION_CODE > 0x20100)
3116 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
3120 page
= get_zeroed_page(GFP_KERNEL
);
3127 tmp_buf
= (unsigned char *) page
;
3131 * If the port is the middle of closing, bail out now
3133 if (tty_hung_up_p(filp
) ||
3134 (info
->flags
& ASYNC_CLOSING
)) {
3135 if (info
->flags
& ASYNC_CLOSING
)
3136 interruptible_sleep_on(&info
->close_wait
);
3137 #ifdef SERIAL_DO_RESTART
3138 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
3139 -EAGAIN
: -ERESTARTSYS
);
3146 * Start up serial port
3148 retval
= startup(info
);
3153 retval
= block_til_ready(tty
, filp
, info
);
3155 #ifdef SERIAL_DEBUG_OPEN
3156 printk("rs_open returning after block_til_ready with %d\n",
3162 if ((info
->state
->count
== 1) &&
3163 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
3164 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
3165 *tty
->termios
= info
->state
->normal_termios
;
3167 *tty
->termios
= info
->state
->callout_termios
;
3168 change_speed(info
, 0);
3170 #ifdef CONFIG_SERIAL_CONSOLE
3171 if (sercons
.cflag
&& sercons
.index
== line
) {
3172 tty
->termios
->c_cflag
= sercons
.cflag
;
3174 change_speed(info
, 0);
3177 info
->session
= current
->session
;
3178 info
->pgrp
= current
->pgrp
;
3180 #ifdef SERIAL_DEBUG_OPEN
3181 printk("rs_open ttys%d successful...", info
->line
);
3187 * /proc fs routines....
3190 static inline int line_info(char *buf
, struct serial_state
*state
)
3192 struct async_struct
*info
= state
->info
, scr_info
;
3193 char stat_buf
[30], control
, status
;
3195 unsigned long flags
;
3197 ret
= sprintf(buf
, "%d: uart:%s port:%lX irq:%d",
3198 state
->line
, uart_config
[state
->type
].name
,
3199 state
->port
, state
->irq
);
3201 if (!state
->port
|| (state
->type
== PORT_UNKNOWN
)) {
3202 ret
+= sprintf(buf
+ret
, "\n");
3207 * Figure out the current RS-232 lines
3210 info
= &scr_info
; /* This is just for serial_{in,out} */
3212 info
->magic
= SERIAL_MAGIC
;
3213 info
->port
= state
->port
;
3214 info
->flags
= state
->flags
;
3218 save_flags(flags
); cli();
3219 status
= serial_in(info
, UART_MSR
);
3220 control
= info
!= &scr_info
? info
->MCR
: serial_in(info
, UART_MCR
);
3221 restore_flags(flags
);
3225 if (control
& UART_MCR_RTS
)
3226 strcat(stat_buf
, "|RTS");
3227 if (status
& UART_MSR_CTS
)
3228 strcat(stat_buf
, "|CTS");
3229 if (control
& UART_MCR_DTR
)
3230 strcat(stat_buf
, "|DTR");
3231 if (status
& UART_MSR_DSR
)
3232 strcat(stat_buf
, "|DSR");
3233 if (status
& UART_MSR_DCD
)
3234 strcat(stat_buf
, "|CD");
3235 if (status
& UART_MSR_RI
)
3236 strcat(stat_buf
, "|RI");
3239 ret
+= sprintf(buf
+ret
, " baud:%d",
3240 state
->baud_base
/ info
->quot
);
3243 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
3244 state
->icount
.tx
, state
->icount
.rx
);
3246 if (state
->icount
.frame
)
3247 ret
+= sprintf(buf
+ret
, " fe:%d", state
->icount
.frame
);
3249 if (state
->icount
.parity
)
3250 ret
+= sprintf(buf
+ret
, " pe:%d", state
->icount
.parity
);
3252 if (state
->icount
.brk
)
3253 ret
+= sprintf(buf
+ret
, " brk:%d", state
->icount
.brk
);
3255 if (state
->icount
.overrun
)
3256 ret
+= sprintf(buf
+ret
, " oe:%d", state
->icount
.overrun
);
3259 * Last thing is the RS-232 status lines
3261 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
3265 int rs_read_proc(char *page
, char **start
, off_t off
, int count
,
3266 int *eof
, void *data
)
3271 len
+= sprintf(page
, "serinfo:1.0 driver:%s%s revision:%s\n",
3272 serial_version
, LOCAL_VERSTRING
, serial_revdate
);
3273 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
3274 l
= line_info(page
+ len
, &rs_table
[i
]);
3276 if (len
+begin
> off
+count
)
3278 if (len
+begin
< off
) {
3285 if (off
>= len
+begin
)
3287 *start
= page
+ (off
-begin
);
3288 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
3292 * ---------------------------------------------------------------------
3293 * rs_init() and friends
3295 * rs_init() is called at boot-time to initialize the serial driver.
3296 * ---------------------------------------------------------------------
3300 * This routine prints out the appropriate serial driver version
3301 * number, and identifies which options were configured into this
3304 static char serial_options
[] __initdata
=
3309 #ifdef CONFIG_SERIAL_MANY_PORTS
3313 #ifdef CONFIG_SERIAL_MULTIPORT
3317 #ifdef CONFIG_SERIAL_SHARE_IRQ
3321 #ifdef CONFIG_SERIAL_DETECT_IRQ
3325 #ifdef ENABLE_SERIAL_PCI
3329 #ifdef ENABLE_SERIAL_PNP
3336 " no serial options enabled\n";
3340 static _INLINE_
void show_serial_version(void)
3342 printk(KERN_INFO
"%s version %s%s (%s) with%s", serial_name
,
3343 serial_version
, LOCAL_VERSTRING
, serial_revdate
,
3348 * This routine detect the IRQ of a serial port by clearing OUT2 when
3349 * no UART interrupt are requested (IER = 0) (*GPL*). This seems to work at
3350 * each time, as long as no other device permanently request the IRQ.
3351 * If no IRQ is detected, or multiple IRQ appear, this function returns 0.
3352 * The variable "state" and the field "state->port" should not be null.
3354 static unsigned detect_uart_irq (struct serial_state
* state
)
3358 unsigned char save_mcr
, save_ier
;
3359 struct async_struct scr_info
; /* serial_{in,out} because HUB6 */
3361 #ifdef CONFIG_SERIAL_MANY_PORTS
3362 unsigned char save_ICP
=0; /* no warning */
3363 unsigned short ICP
=0;
3365 if (state
->flags
& ASYNC_FOURPORT
) {
3366 ICP
= (state
->port
& 0xFE0) | 0x01F;
3367 save_ICP
= inb_p(ICP
);
3372 scr_info
.magic
= SERIAL_MAGIC
;
3373 scr_info
.state
= state
;
3374 scr_info
.port
= state
->port
;
3375 scr_info
.flags
= state
->flags
;
3377 scr_info
.hub6
= state
->hub6
;
3379 scr_info
.io_type
= state
->io_type
;
3380 scr_info
.iomem_base
= state
->iomem_base
;
3381 scr_info
.iomem_reg_shift
= state
->iomem_reg_shift
;
3383 /* forget possible initially masked and pending IRQ */
3384 probe_irq_off(probe_irq_on());
3385 save_mcr
= serial_inp(&scr_info
, UART_MCR
);
3386 save_ier
= serial_inp(&scr_info
, UART_IER
);
3387 serial_outp(&scr_info
, UART_MCR
, UART_MCR_OUT1
| UART_MCR_OUT2
);
3389 irqs
= probe_irq_on();
3390 serial_outp(&scr_info
, UART_MCR
, 0);
3392 if (state
->flags
& ASYNC_FOURPORT
) {
3393 serial_outp(&scr_info
, UART_MCR
,
3394 UART_MCR_DTR
| UART_MCR_RTS
);
3396 serial_outp(&scr_info
, UART_MCR
,
3397 UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
);
3399 serial_outp(&scr_info
, UART_IER
, 0x0f); /* enable all intrs */
3400 (void)serial_inp(&scr_info
, UART_LSR
);
3401 (void)serial_inp(&scr_info
, UART_RX
);
3402 (void)serial_inp(&scr_info
, UART_IIR
);
3403 (void)serial_inp(&scr_info
, UART_MSR
);
3404 serial_outp(&scr_info
, UART_TX
, 0xFF);
3406 irq
= probe_irq_off(irqs
);
3408 serial_outp(&scr_info
, UART_MCR
, save_mcr
);
3409 serial_outp(&scr_info
, UART_IER
, save_ier
);
3410 #ifdef CONFIG_SERIAL_MANY_PORTS
3411 if (state
->flags
& ASYNC_FOURPORT
)
3412 outb_p(save_ICP
, ICP
);
3414 return (irq
> 0)? irq
: 0;
3418 * This is a quickie test to see how big the FIFO is.
3419 * It doesn't work at all the time, more's the pity.
3421 static int size_fifo(struct async_struct
*info
)
3423 unsigned char old_fcr
, old_mcr
, old_dll
, old_dlm
;
3426 old_fcr
= serial_inp(info
, UART_FCR
);
3427 old_mcr
= serial_inp(info
, UART_MCR
);
3428 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
3429 UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
);
3430 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
);
3431 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3432 old_dll
= serial_inp(info
, UART_DLL
);
3433 old_dlm
= serial_inp(info
, UART_DLM
);
3434 serial_outp(info
, UART_DLL
, 0x01);
3435 serial_outp(info
, UART_DLM
, 0x00);
3436 serial_outp(info
, UART_LCR
, 0x03);
3437 for (count
= 0; count
< 256; count
++)
3438 serial_outp(info
, UART_TX
, count
);
3440 for (count
= 0; (serial_inp(info
, UART_LSR
) & UART_LSR_DR
) &&
3441 (count
< 256); count
++)
3442 serial_inp(info
, UART_RX
);
3443 serial_outp(info
, UART_FCR
, old_fcr
);
3444 serial_outp(info
, UART_MCR
, old_mcr
);
3445 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3446 serial_outp(info
, UART_DLL
, old_dll
);
3447 serial_outp(info
, UART_DLM
, old_dlm
);
3453 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
3454 * When this function is called we know it is at least a StarTech
3455 * 16650 V2, but it might be one of several StarTech UARTs, or one of
3456 * its clones. (We treat the broken original StarTech 16650 V1 as a
3457 * 16550, and why not? Startech doesn't seem to even acknowledge its
3460 * What evil have men's minds wrought...
3462 static void autoconfig_startech_uarts(struct async_struct
*info
,
3463 struct serial_state
*state
,
3464 unsigned long flags
)
3466 unsigned char scratch
, scratch2
, scratch3
;
3469 * First we check to see if it's an Oxford Semiconductor UART.
3471 * If we have to do this here because some non-National
3472 * Semiconductor clone chips lock up if you try writing to the
3473 * LSR register (which serial_icr_read does)
3475 if (state
->type
== PORT_16550A
) {
3477 * EFR [4] must be set else this test fails
3479 * This shouldn't be necessary, but Mike Hudson
3480 * (Exoray@isys.ca) claims that it's needed for 952
3481 * dual UART's (which are not recommended for new designs).
3483 serial_out(info
, UART_LCR
, 0xBF);
3484 serial_out(info
, UART_EFR
, 0x10);
3485 serial_out(info
, UART_LCR
, 0x00);
3486 /* Check for Oxford Semiconductor 16C950 */
3487 scratch
= serial_icr_read(info
, UART_ID1
);
3488 scratch2
= serial_icr_read(info
, UART_ID2
);
3489 scratch3
= serial_icr_read(info
, UART_ID3
);
3491 if (scratch
== 0x16 && scratch2
== 0xC9 &&
3492 (scratch3
== 0x50 || scratch3
== 0x52 ||
3493 scratch3
== 0x54)) {
3494 state
->type
= PORT_16C950
;
3495 state
->revision
= serial_icr_read(info
, UART_REV
) |
3502 * We check for a XR16C850 by setting DLL and DLM to 0, and
3503 * then reading back DLL and DLM. If DLM reads back 0x10,
3504 * then the UART is a XR16C850 and the DLL contains the chip
3505 * revision. If DLM reads back 0x14, then the UART is a
3509 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3510 serial_outp(info
, UART_DLL
, 0);
3511 serial_outp(info
, UART_DLM
, 0);
3512 state
->revision
= serial_inp(info
, UART_DLL
);
3513 scratch
= serial_inp(info
, UART_DLM
);
3514 serial_outp(info
, UART_LCR
, 0);
3515 if (scratch
== 0x10 || scratch
== 0x14) {
3516 state
->type
= PORT_16850
;
3521 * We distinguish between the '654 and the '650 by counting
3522 * how many bytes are in the FIFO. I'm using this for now,
3523 * since that's the technique that was sent to me in the
3524 * serial driver update, but I'm not convinced this works.
3525 * I've had problems doing this in the past. -TYT
3527 if (size_fifo(info
) == 64)
3528 state
->type
= PORT_16654
;
3530 state
->type
= PORT_16650V2
;
3534 * This routine is called by rs_init() to initialize a specific serial
3535 * port. It determines what type of UART chip this serial port is
3536 * using: 8250, 16450, 16550, 16550A. The important question is
3537 * whether or not this UART is a 16550A or not, since this will
3538 * determine whether or not we can use its FIFO features or not.
3540 static void autoconfig(struct serial_state
* state
)
3542 unsigned char status1
, status2
, scratch
, scratch2
, scratch3
;
3543 unsigned char save_lcr
, save_mcr
;
3544 struct async_struct
*info
, scr_info
;
3545 unsigned long flags
;
3547 state
->type
= PORT_UNKNOWN
;
3549 #ifdef SERIAL_DEBUG_AUTOCONF
3550 printk("Testing ttyS%d (0x%04lx, 0x%04x)...\n", state
->line
,
3551 state
->port
, (unsigned) state
->iomem_base
);
3554 if (!CONFIGURED_SERIAL_PORT(state
))
3557 info
= &scr_info
; /* This is just for serial_{in,out} */
3559 info
->magic
= SERIAL_MAGIC
;
3560 info
->state
= state
;
3561 info
->port
= state
->port
;
3562 info
->flags
= state
->flags
;
3564 info
->hub6
= state
->hub6
;
3566 info
->io_type
= state
->io_type
;
3567 info
->iomem_base
= state
->iomem_base
;
3568 info
->iomem_reg_shift
= state
->iomem_reg_shift
;
3570 save_flags(flags
); cli();
3572 if (!(state
->flags
& ASYNC_BUGGY_UART
) &&
3573 !state
->iomem_base
) {
3575 * Do a simple existence test first; if we fail this,
3576 * there's no point trying anything else.
3578 * 0x80 is used as a nonsense port to prevent against
3579 * false positives due to ISA bus float. The
3580 * assumption is that 0x80 is a non-existent port;
3581 * which should be safe since include/asm/io.h also
3582 * makes this assumption.
3584 scratch
= serial_inp(info
, UART_IER
);
3585 serial_outp(info
, UART_IER
, 0);
3589 scratch2
= serial_inp(info
, UART_IER
);
3590 serial_outp(info
, UART_IER
, 0x0F);
3594 scratch3
= serial_inp(info
, UART_IER
);
3595 serial_outp(info
, UART_IER
, scratch
);
3596 if (scratch2
|| scratch3
!= 0x0F) {
3597 #ifdef SERIAL_DEBUG_AUTOCONF
3598 printk("serial: ttyS%d: simple autoconfig failed "
3599 "(%02x, %02x)\n", state
->line
,
3600 scratch2
, scratch3
);
3602 restore_flags(flags
);
3603 return; /* We failed; there's nothing here */
3607 save_mcr
= serial_in(info
, UART_MCR
);
3608 save_lcr
= serial_in(info
, UART_LCR
);
3611 * Check to see if a UART is really there. Certain broken
3612 * internal modems based on the Rockwell chipset fail this
3613 * test, because they apparently don't implement the loopback
3614 * test mode. So this test is skipped on the COM 1 through
3615 * COM 4 ports. This *should* be safe, since no board
3616 * manufacturer would be stupid enough to design a board
3617 * that conflicts with COM 1-4 --- we hope!
3619 if (!(state
->flags
& ASYNC_SKIP_TEST
)) {
3620 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
3621 status1
= serial_inp(info
, UART_MSR
) & 0xF0;
3622 serial_outp(info
, UART_MCR
, save_mcr
);
3623 if (status1
!= 0x90) {
3624 #ifdef SERIAL_DEBUG_AUTOCONF
3625 printk("serial: ttyS%d: no UART loopback failed\n",
3628 restore_flags(flags
);
3632 serial_outp(info
, UART_LCR
, 0xBF); /* set up for StarTech test */
3633 serial_outp(info
, UART_EFR
, 0); /* EFR is the same as FCR */
3634 serial_outp(info
, UART_LCR
, 0);
3635 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3636 scratch
= serial_in(info
, UART_IIR
) >> 6;
3639 state
->type
= PORT_16450
;
3642 state
->type
= PORT_UNKNOWN
;
3645 state
->type
= PORT_16550
;
3648 state
->type
= PORT_16550A
;
3651 if (state
->type
== PORT_16550A
) {
3652 /* Check for Startech UART's */
3653 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3654 if (serial_in(info
, UART_EFR
) == 0) {
3655 state
->type
= PORT_16650
;
3657 serial_outp(info
, UART_LCR
, 0xBF);
3658 if (serial_in(info
, UART_EFR
) == 0)
3659 autoconfig_startech_uarts(info
, state
, flags
);
3662 if (state
->type
== PORT_16550A
) {
3663 /* Check for TI 16750 */
3664 serial_outp(info
, UART_LCR
, save_lcr
| UART_LCR_DLAB
);
3665 serial_outp(info
, UART_FCR
,
3666 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
3667 scratch
= serial_in(info
, UART_IIR
) >> 5;
3670 * If this is a 16750, and not a cheap UART
3671 * clone, then it should only go into 64 byte
3672 * mode if the UART_FCR7_64BYTE bit was set
3673 * while UART_LCR_DLAB was latched.
3675 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3676 serial_outp(info
, UART_LCR
, 0);
3677 serial_outp(info
, UART_FCR
,
3678 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
3679 scratch
= serial_in(info
, UART_IIR
) >> 5;
3681 state
->type
= PORT_16750
;
3683 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3685 #if defined(CONFIG_SERIAL_RSA) && defined(MODULE)
3686 if (state
->type
== PORT_16550A
) {
3689 for (i
= 0 ; i
< PORT_RSA_MAX
; ++i
) {
3690 if (!probe_rsa
[i
] && !force_rsa
[i
])
3692 if (((probe_rsa
[i
] != state
->port
) ||
3693 check_region(state
->port
+ UART_RSA_BASE
, 16)) &&
3694 (force_rsa
[i
] != state
->port
))
3696 if (!enable_rsa(info
))
3698 state
->type
= PORT_RSA
;
3699 state
->baud_base
= SERIAL_RSA_BAUD_BASE
;
3704 serial_outp(info
, UART_LCR
, save_lcr
);
3705 if (state
->type
== PORT_16450
) {
3706 scratch
= serial_in(info
, UART_SCR
);
3707 serial_outp(info
, UART_SCR
, 0xa5);
3708 status1
= serial_in(info
, UART_SCR
);
3709 serial_outp(info
, UART_SCR
, 0x5a);
3710 status2
= serial_in(info
, UART_SCR
);
3711 serial_outp(info
, UART_SCR
, scratch
);
3713 if ((status1
!= 0xa5) || (status2
!= 0x5a))
3714 state
->type
= PORT_8250
;
3716 state
->xmit_fifo_size
= uart_config
[state
->type
].dfl_xmit_fifo_size
;
3718 if (state
->type
== PORT_UNKNOWN
) {
3719 restore_flags(flags
);
3724 #ifdef CONFIG_SERIAL_RSA
3725 if (state
->type
== PORT_RSA
)
3726 request_region(info
->port
+ UART_RSA_BASE
, 16,
3727 "serial_rsa(auto)");
3730 request_region(info
->port
,8,"serial(auto)");
3736 #ifdef CONFIG_SERIAL_RSA
3737 if (state
->type
== PORT_RSA
)
3738 serial_outp(info
, UART_RSA_FRR
, 0);
3740 serial_outp(info
, UART_MCR
, save_mcr
);
3741 serial_outp(info
, UART_FCR
, (UART_FCR_ENABLE_FIFO
|
3742 UART_FCR_CLEAR_RCVR
|
3743 UART_FCR_CLEAR_XMIT
));
3744 serial_outp(info
, UART_FCR
, 0);
3745 (void)serial_in(info
, UART_RX
);
3746 serial_outp(info
, UART_IER
, 0);
3748 restore_flags(flags
);
3751 int register_serial(struct serial_struct
*req
);
3752 void unregister_serial(int line
);
3754 #if (LINUX_VERSION_CODE > 0x20100)
3755 EXPORT_SYMBOL(register_serial
);
3756 EXPORT_SYMBOL(unregister_serial
);
3758 static struct symbol_table serial_syms
= {
3759 #include <linux/symtab_begin.h>
3761 X(unregister_serial
),
3762 #include <linux/symtab_end.h>
3767 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
3769 static void __init
printk_pnp_dev_id(unsigned short vendor
,
3770 unsigned short device
)
3772 printk("%c%c%c%x%x%x%x",
3773 'A' + ((vendor
>> 2) & 0x3f) - 1,
3774 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
3775 'A' + ((vendor
>> 8) & 0x1f) - 1,
3776 (device
>> 4) & 0x0f,
3778 (device
>> 12) & 0x0f,
3779 (device
>> 8) & 0x0f);
3782 static _INLINE_
int get_pci_port(struct pci_dev
*dev
,
3783 struct pci_board
*board
,
3784 struct serial_struct
*req
,
3791 base_idx
= SPCI_FL_GET_BASE(board
->flags
);
3792 if (board
->flags
& SPCI_FL_BASE_TABLE
)
3795 if (board
->flags
& SPCI_FL_REGION_SZ_CAP
) {
3796 max_port
= pci_resource_len(dev
, base_idx
) / 8;
3797 if (idx
>= max_port
)
3801 port
= pci_resource_start(dev
, base_idx
) + board
->first_uart_offset
;
3803 if ((board
->flags
& SPCI_FL_BASE_TABLE
) == 0)
3804 port
+= idx
* (board
->uart_offset
? board
->uart_offset
: 8);
3806 if (IS_PCI_REGION_IOPORT(dev
, base_idx
)) {
3808 if (HIGH_BITS_OFFSET
)
3809 req
->port_high
= port
>> HIGH_BITS_OFFSET
;
3814 req
->io_type
= SERIAL_IO_MEM
;
3815 req
->iomem_base
= ioremap(port
, board
->uart_offset
);
3816 req
->iomem_reg_shift
= board
->reg_shift
;
3821 static _INLINE_
int get_pci_irq(struct pci_dev
*dev
,
3822 struct pci_board
*board
,
3827 if ((board
->flags
& SPCI_FL_IRQRESOURCE
) == 0)
3830 base_idx
= SPCI_FL_GET_IRQBASE(board
->flags
);
3831 if (board
->flags
& SPCI_FL_IRQ_TABLE
)
3834 return PCI_IRQ_RESOURCE(dev
, base_idx
);
3838 * Common enabler code shared by both PCI and ISAPNP probes
3840 static void __init
start_pci_pnp_board(struct pci_dev
*dev
,
3841 struct pci_board
*board
)
3844 struct serial_struct serial_req
;
3847 if (PREPARE_FUNC(dev
) && (PREPARE_FUNC(dev
))(dev
) < 0) {
3848 printk("serial: PNP device '");
3849 printk_pnp_dev_id(board
->vendor
, board
->device
);
3850 printk("' prepare failed\n");
3854 if (ACTIVATE_FUNC(dev
) && (ACTIVATE_FUNC(dev
))(dev
) < 0) {
3855 printk("serial: PNP device '");
3856 printk_pnp_dev_id(board
->vendor
, board
->device
);
3857 printk("' activate failed\n");
3861 if (!(board
->flags
& SPCI_FL_ISPNP
) && pci_enable_device(dev
)) {
3862 printk("serial: PCI device enable failed\n");
3867 * Run the initialization function, if any
3869 if (board
->init_fn
&& ((board
->init_fn
)(dev
, board
, 1) != 0))
3874 * Register the serial board in the array if we need to
3875 * shutdown the board on a module unload.
3877 if (DEACTIVATE_FUNC(dev
) || board
->init_fn
) {
3878 if (serial_pci_board_idx
>= NR_PCI_BOARDS
)
3880 serial_pci_board
[serial_pci_board_idx
].board
= *board
;
3881 serial_pci_board
[serial_pci_board_idx
].dev
= dev
;
3882 serial_pci_board_idx
++;
3886 base_baud
= board
->base_baud
;
3888 base_baud
= BASE_BAUD
;
3889 memset(&serial_req
, 0, sizeof(serial_req
));
3891 for (k
=0; k
< board
->num_ports
; k
++) {
3892 serial_req
.irq
= get_pci_irq(dev
, board
, k
);
3893 if (get_pci_port(dev
, board
, &serial_req
, k
))
3895 serial_req
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTOPROBE
;
3896 #ifdef SERIAL_DEBUG_PCI
3897 printk("Setup PCI/PNP port: port %x, irq %d, type %d\n",
3898 serial_req
.port
, serial_req
.irq
, serial_req
.io_type
);
3900 line
= register_serial(&serial_req
);
3903 rs_table
[line
].baud_base
= base_baud
;
3906 #endif /* ENABLE_SERIAL_PCI || ENABLE_SERIAL_PNP */
3908 #ifdef ENABLE_SERIAL_PCI
3910 * Some PCI serial cards using the PLX 9050 PCI interface chip require
3911 * that the card interrupt be explicitly enabled or disabled. This
3912 * seems to be mainly needed on card using the PLX which also use I/O
3919 pci_plx9050_fn(struct pci_dev
*dev
, struct pci_board
*board
, int enable
)
3921 u8 data
, *p
, irq_config
;
3925 pci_config
= PCI_COMMAND_MEMORY
;
3926 if (dev
->vendor
== PCI_VENDOR_ID_PANACOM
)
3928 if ((dev
->vendor
== PCI_VENDOR_ID_PLX
) &&
3929 (dev
->device
== PCI_VENDOR_ID_PLX_ROMULUS
)) {
3931 * As the megawolf cards have the int pins active
3932 * high, and have 2 UART chips, both ints must be
3933 * enabled on the 9050. Also, the UARTS are set in
3934 * 16450 mode by default, so we have to enable the
3935 * 16C950 'enhanced' mode so that we can use the deep
3939 pci_config
= PCI_COMMAND_MEMORY
| PCI_COMMAND_IO
;
3942 pci_read_config_byte(dev
, PCI_COMMAND
, &data
);
3945 pci_write_config_byte(dev
, PCI_COMMAND
,
3948 /* enable/disable interrupts */
3949 p
= ioremap(pci_resource_start(dev
, 0), 0x80);
3950 writel(enable
? irq_config
: 0x00, (unsigned long)p
+ 0x4c);
3954 pci_write_config_byte(dev
, PCI_COMMAND
,
3955 data
& ~pci_config
);
3961 * SIIG serial cards have an PCI interface chip which also controls
3962 * the UART clocking frequency. Each UART can be clocked independently
3963 * (except cards equiped with 4 UARTs) and initial clocking settings
3964 * are stored in the EEPROM chip. It can cause problems because this
3965 * version of serial driver doesn't support differently clocked UART's
3966 * on single PCI card. To prevent this, initialization functions set
3967 * high frequency clocking for all UART's on given card. It is safe (I
3968 * hope) because it doesn't touch EEPROM settings to prevent conflicts
3969 * with other OSes (like M$ DOS).
3971 * SIIG support added by Andrey Panin <pazke@mail.tp.ru>, 10/1999
3973 * There is two family of SIIG serial cards with different PCI
3974 * interface chip and different configuration methods:
3975 * - 10x cards have control registers in IO and/or memory space;
3976 * - 20x cards have control registers in standard PCI configuration space.
3979 #define PCI_DEVICE_ID_SIIG_1S_10x (PCI_DEVICE_ID_SIIG_1S_10x_550 & 0xfffc)
3980 #define PCI_DEVICE_ID_SIIG_2S_10x (PCI_DEVICE_ID_SIIG_2S_10x_550 & 0xfff8)
3986 pci_siig10x_fn(struct pci_dev
*dev
, struct pci_board
*board
, int enable
)
3990 if (!enable
) return 0;
3992 p
= ioremap(pci_resource_start(dev
, 0), 0x80);
3994 switch (dev
->device
& 0xfff8) {
3995 case PCI_DEVICE_ID_SIIG_1S_10x
: /* 1S */
3998 case PCI_DEVICE_ID_SIIG_2S_10x
: /* 2S, 2S1P */
4001 default: /* 1S1P, 4S */
4006 writew(readw((unsigned long) p
+ 0x28) & data
, (unsigned long) p
+ 0x28);
4011 #define PCI_DEVICE_ID_SIIG_2S_20x (PCI_DEVICE_ID_SIIG_2S_20x_550 & 0xfffc)
4012 #define PCI_DEVICE_ID_SIIG_2S1P_20x (PCI_DEVICE_ID_SIIG_2S1P_20x_550 & 0xfffc)
4018 pci_siig20x_fn(struct pci_dev
*dev
, struct pci_board
*board
, int enable
)
4022 if (!enable
) return 0;
4024 /* Change clock frequency for the first UART. */
4025 pci_read_config_byte(dev
, 0x6f, &data
);
4026 pci_write_config_byte(dev
, 0x6f, data
& 0xef);
4028 /* If this card has 2 UART, we have to do the same with second UART. */
4029 if (((dev
->device
& 0xfffc) == PCI_DEVICE_ID_SIIG_2S_20x
) ||
4030 ((dev
->device
& 0xfffc) == PCI_DEVICE_ID_SIIG_2S1P_20x
)) {
4031 pci_read_config_byte(dev
, 0x73, &data
);
4032 pci_write_config_byte(dev
, 0x73, data
& 0xef);
4037 /* Added for EKF Intel i960 serial boards */
4042 pci_inteli960ni_fn(struct pci_dev
*dev
,
4043 struct pci_board
*board
,
4046 unsigned long oldval
;
4048 if (!(board
->subdevice
& 0x1000))
4051 if (!enable
) /* is there something to deinit? */
4054 #ifdef SERIAL_DEBUG_PCI
4055 printk(KERN_DEBUG
" Subsystem ID %lx (intel 960)\n",
4056 (unsigned long) board
->subdevice
);
4058 /* is firmware started? */
4059 pci_read_config_dword(dev
, 0x44, (void*) &oldval
);
4060 if (oldval
== 0x00001000L
) { /* RESET value */
4061 printk(KERN_DEBUG
"Local i960 firmware missing");
4069 * This is the configuration table for all of the PCI serial boards
4072 static struct pci_board pci_boards
[] __initdata
= {
4074 * Vendor ID, Device ID,
4075 * Subvendor ID, Subdevice ID,
4076 * PCI Flags, Number of Ports, Base (Maximum) Baud Rate,
4077 * Offset to get to next UART's registers,
4078 * Register shift to use for memory-mapped I/O,
4079 * Initialization function, first UART offset
4081 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4082 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4083 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232
,
4084 SPCI_FL_BASE1
, 8, 1382400 },
4085 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4086 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4087 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232
,
4088 SPCI_FL_BASE1
, 4, 1382400 },
4089 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4090 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4091 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232
,
4092 SPCI_FL_BASE1
, 2, 1382400 },
4093 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4094 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4095 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232
,
4096 SPCI_FL_BASE1
, 8, 1382400 },
4097 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4098 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4099 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232
,
4100 SPCI_FL_BASE1
, 4, 1382400 },
4101 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4102 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4103 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232
,
4104 SPCI_FL_BASE1
, 2, 1382400 },
4105 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4106 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4107 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485
,
4108 SPCI_FL_BASE1
, 8, 921600 },
4109 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4110 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4111 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4
,
4112 SPCI_FL_BASE1
, 8, 921600 },
4113 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4114 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4115 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485
,
4116 SPCI_FL_BASE1
, 4, 921600 },
4117 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4118 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4119 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2
,
4120 SPCI_FL_BASE1
, 4, 921600 },
4121 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
4122 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4123 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485
,
4124 SPCI_FL_BASE1
, 2, 921600 },
4125 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4126 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4127 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485
,
4128 SPCI_FL_BASE1
, 8, 921600 },
4129 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4130 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4131 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4
,
4132 SPCI_FL_BASE1
, 8, 921600 },
4133 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4134 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4135 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485
,
4136 SPCI_FL_BASE1
, 4, 921600 },
4137 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4138 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4139 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2
,
4140 SPCI_FL_BASE1
, 4, 921600 },
4141 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
4142 PCI_SUBVENDOR_ID_CONNECT_TECH
,
4143 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485
,
4144 SPCI_FL_BASE1
, 2, 921600 },
4145 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_U530
,
4146 PCI_ANY_ID
, PCI_ANY_ID
,
4147 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 1, 115200 },
4148 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM2
,
4149 PCI_ANY_ID
, PCI_ANY_ID
,
4150 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4151 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM422
,
4152 PCI_ANY_ID
, PCI_ANY_ID
,
4153 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 115200 },
4154 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM232
,
4155 PCI_ANY_ID
, PCI_ANY_ID
,
4156 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4157 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_COMM4
,
4158 PCI_ANY_ID
, PCI_ANY_ID
,
4159 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 115200 },
4160 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_COMM8
,
4161 PCI_ANY_ID
, PCI_ANY_ID
,
4162 SPCI_FL_BASE2
, 8, 115200 },
4163 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_GTEK_SERIAL2
,
4164 PCI_ANY_ID
, PCI_ANY_ID
,
4165 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4166 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_SPCOM200
,
4167 PCI_ANY_ID
, PCI_ANY_ID
,
4168 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600 },
4169 /* VScom SPCOM800, from sl@s.pl */
4170 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_SPCOM800
,
4171 PCI_ANY_ID
, PCI_ANY_ID
,
4172 SPCI_FL_BASE2
, 8, 921600 },
4173 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4174 PCI_SUBVENDOR_ID_KEYSPAN
,
4175 PCI_SUBDEVICE_ID_KEYSPAN_SX2
,
4176 SPCI_FL_BASE2
, 2, 921600, /* IOMEM */
4177 0x400, 7, pci_plx9050_fn
},
4178 { PCI_VENDOR_ID_PANACOM
, PCI_DEVICE_ID_PANACOM_QUADMODEM
,
4179 PCI_ANY_ID
, PCI_ANY_ID
,
4180 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 921600,
4181 0x400, 7, pci_plx9050_fn
},
4182 { PCI_VENDOR_ID_PANACOM
, PCI_DEVICE_ID_PANACOM_DUALMODEM
,
4183 PCI_ANY_ID
, PCI_ANY_ID
,
4184 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4185 0x400, 7, pci_plx9050_fn
},
4186 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4187 PCI_SUBVENDOR_ID_CHASE_PCIFAST
,
4188 PCI_SUBDEVICE_ID_CHASE_PCIFAST4
,
4189 SPCI_FL_BASE2
, 4, 460800 },
4190 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4191 PCI_SUBVENDOR_ID_CHASE_PCIFAST
,
4192 PCI_SUBDEVICE_ID_CHASE_PCIFAST8
,
4193 SPCI_FL_BASE2
, 8, 460800 },
4194 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4195 PCI_SUBVENDOR_ID_CHASE_PCIFAST
,
4196 PCI_SUBDEVICE_ID_CHASE_PCIFAST16
,
4197 SPCI_FL_BASE2
, 16, 460800 },
4198 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4199 PCI_SUBVENDOR_ID_CHASE_PCIFAST
,
4200 PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC
,
4201 SPCI_FL_BASE2
, 16, 460800 },
4202 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4203 PCI_SUBVENDOR_ID_CHASE_PCIRAS
,
4204 PCI_SUBDEVICE_ID_CHASE_PCIRAS4
,
4205 SPCI_FL_BASE2
, 4, 460800 },
4206 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
4207 PCI_SUBVENDOR_ID_CHASE_PCIRAS
,
4208 PCI_SUBDEVICE_ID_CHASE_PCIRAS8
,
4209 SPCI_FL_BASE2
, 8, 460800 },
4210 /* Megawolf Romulus PCI Serial Card, from Mike Hudson */
4211 /* (Exoray@isys.ca) */
4212 { PCI_VENDOR_ID_PLX
, PCI_VENDOR_ID_PLX_ROMULUS
,
4214 SPCI_FL_BASE2
, 4, 921600,
4215 0x20, 2, pci_plx9050_fn
, 0x03 },
4216 { PCI_VENDOR_ID_QUATECH
, PCI_DEVICE_ID_QUATECH_QSC100
,
4217 PCI_ANY_ID
, PCI_ANY_ID
,
4218 SPCI_FL_BASE1
, 4, 115200 },
4219 { PCI_VENDOR_ID_QUATECH
, PCI_DEVICE_ID_QUATECH_DSC100
,
4220 PCI_ANY_ID
, PCI_ANY_ID
,
4221 SPCI_FL_BASE1
, 2, 115200 },
4222 { PCI_VENDOR_ID_QUATECH
, PCI_DEVICE_ID_QUATECH_ESC100D
,
4223 PCI_ANY_ID
, PCI_ANY_ID
,
4224 SPCI_FL_BASE1
, 8, 115200 },
4225 { PCI_VENDOR_ID_QUATECH
, PCI_DEVICE_ID_QUATECH_ESC100M
,
4226 PCI_ANY_ID
, PCI_ANY_ID
,
4227 SPCI_FL_BASE1
, 8, 115200 },
4228 { PCI_VENDOR_ID_SPECIALIX
, PCI_DEVICE_ID_OXSEMI_16PCI954
,
4229 PCI_VENDOR_ID_SPECIALIX
, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4
,
4230 SPCI_FL_BASE0
, 4, 921600 },
4231 { PCI_VENDOR_ID_OXSEMI
, PCI_DEVICE_ID_OXSEMI_16PCI954
,
4232 PCI_ANY_ID
, PCI_ANY_ID
,
4233 SPCI_FL_BASE0
, 4, 115200 },
4234 { PCI_VENDOR_ID_OXSEMI
, PCI_DEVICE_ID_OXSEMI_16PCI952
,
4235 PCI_ANY_ID
, PCI_ANY_ID
,
4236 SPCI_FL_BASE0
, 2, 115200 },
4237 /* This board uses the size of PCI Base region 0 to
4238 * signal now many ports are available */
4239 { PCI_VENDOR_ID_OXSEMI
, PCI_DEVICE_ID_OXSEMI_16PCI95N
,
4240 PCI_ANY_ID
, PCI_ANY_ID
,
4241 SPCI_FL_BASE0
| SPCI_FL_REGION_SZ_CAP
, 32, 115200 },
4242 { PCI_VENDOR_ID_TIMEDIA
, PCI_DEVICE_ID_TIMEDIA_1889
,
4243 PCI_ANY_ID
, PCI_ANY_ID
,
4244 SPCI_FL_BASE0
, 2, 921600 },
4245 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_DSERIAL
,
4246 PCI_ANY_ID
, PCI_ANY_ID
,
4247 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4248 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_QUATRO_A
,
4249 PCI_ANY_ID
, PCI_ANY_ID
,
4250 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4251 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_QUATRO_B
,
4252 PCI_ANY_ID
, PCI_ANY_ID
,
4253 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4254 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_PORT_PLUS
,
4255 PCI_ANY_ID
, PCI_ANY_ID
,
4256 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 460800 },
4257 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_QUAD_A
,
4258 PCI_ANY_ID
, PCI_ANY_ID
,
4259 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 460800 },
4260 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_QUAD_B
,
4261 PCI_ANY_ID
, PCI_ANY_ID
,
4262 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 460800 },
4263 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_SSERIAL
,
4264 PCI_ANY_ID
, PCI_ANY_ID
,
4265 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 115200 },
4266 { PCI_VENDOR_ID_LAVA
, PCI_DEVICE_ID_LAVA_PORT_650
,
4267 PCI_ANY_ID
, PCI_ANY_ID
,
4268 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 1, 460800 },
4269 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_10x_550
,
4270 PCI_ANY_ID
, PCI_ANY_ID
,
4271 SPCI_FL_BASE2
, 1, 460800,
4272 0, 0, pci_siig10x_fn
},
4273 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_10x_650
,
4274 PCI_ANY_ID
, PCI_ANY_ID
,
4275 SPCI_FL_BASE2
, 1, 460800,
4276 0, 0, pci_siig10x_fn
},
4277 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_10x_850
,
4278 PCI_ANY_ID
, PCI_ANY_ID
,
4279 SPCI_FL_BASE2
, 1, 460800,
4280 0, 0, pci_siig10x_fn
},
4281 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_550
,
4282 PCI_ANY_ID
, PCI_ANY_ID
,
4283 SPCI_FL_BASE2
, 1, 921600,
4284 0, 0, pci_siig10x_fn
},
4285 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_650
,
4286 PCI_ANY_ID
, PCI_ANY_ID
,
4287 SPCI_FL_BASE2
, 1, 921600,
4288 0, 0, pci_siig10x_fn
},
4289 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_10x_850
,
4290 PCI_ANY_ID
, PCI_ANY_ID
,
4291 SPCI_FL_BASE2
, 1, 921600,
4292 0, 0, pci_siig10x_fn
},
4293 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_10x_550
,
4294 PCI_ANY_ID
, PCI_ANY_ID
,
4295 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4296 0, 0, pci_siig10x_fn
},
4297 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_10x_650
,
4298 PCI_ANY_ID
, PCI_ANY_ID
,
4299 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4300 0, 0, pci_siig10x_fn
},
4301 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_10x_850
,
4302 PCI_ANY_ID
, PCI_ANY_ID
,
4303 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4304 0, 0, pci_siig10x_fn
},
4305 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_550
,
4306 PCI_ANY_ID
, PCI_ANY_ID
,
4307 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4308 0, 0, pci_siig10x_fn
},
4309 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_650
,
4310 PCI_ANY_ID
, PCI_ANY_ID
,
4311 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4312 0, 0, pci_siig10x_fn
},
4313 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_10x_850
,
4314 PCI_ANY_ID
, PCI_ANY_ID
,
4315 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600,
4316 0, 0, pci_siig10x_fn
},
4317 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_10x_550
,
4318 PCI_ANY_ID
, PCI_ANY_ID
,
4319 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 921600,
4320 0, 0, pci_siig10x_fn
},
4321 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_10x_650
,
4322 PCI_ANY_ID
, PCI_ANY_ID
,
4323 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 921600,
4324 0, 0, pci_siig10x_fn
},
4325 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_10x_850
,
4326 PCI_ANY_ID
, PCI_ANY_ID
,
4327 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 921600,
4328 0, 0, pci_siig10x_fn
},
4329 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_20x_550
,
4330 PCI_ANY_ID
, PCI_ANY_ID
,
4331 SPCI_FL_BASE0
, 1, 921600,
4332 0, 0, pci_siig20x_fn
},
4333 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_20x_650
,
4334 PCI_ANY_ID
, PCI_ANY_ID
,
4335 SPCI_FL_BASE0
, 1, 921600,
4336 0, 0, pci_siig20x_fn
},
4337 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S_20x_850
,
4338 PCI_ANY_ID
, PCI_ANY_ID
,
4339 SPCI_FL_BASE0
, 1, 921600,
4340 0, 0, pci_siig20x_fn
},
4341 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_550
,
4342 PCI_ANY_ID
, PCI_ANY_ID
,
4343 SPCI_FL_BASE0
, 1, 921600,
4344 0, 0, pci_siig20x_fn
},
4345 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_650
,
4346 PCI_ANY_ID
, PCI_ANY_ID
,
4347 SPCI_FL_BASE0
, 1, 921600,
4348 0, 0, pci_siig20x_fn
},
4349 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_1S1P_20x_850
,
4350 PCI_ANY_ID
, PCI_ANY_ID
,
4351 SPCI_FL_BASE0
, 1, 921600,
4352 0, 0, pci_siig20x_fn
},
4353 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_550
,
4354 PCI_ANY_ID
, PCI_ANY_ID
,
4355 SPCI_FL_BASE0
, 1, 921600,
4356 0, 0, pci_siig20x_fn
},
4357 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_650
,
4358 PCI_ANY_ID
, PCI_ANY_ID
,
4359 SPCI_FL_BASE0
, 1, 921600,
4360 0, 0, pci_siig20x_fn
},
4361 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2P1S_20x_850
,
4362 PCI_ANY_ID
, PCI_ANY_ID
,
4363 SPCI_FL_BASE0
, 1, 921600,
4364 0, 0, pci_siig20x_fn
},
4365 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_20x_550
,
4366 PCI_ANY_ID
, PCI_ANY_ID
,
4367 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4368 0, 0, pci_siig20x_fn
},
4369 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_20x_650
,
4370 PCI_ANY_ID
, PCI_ANY_ID
,
4371 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4372 0, 0, pci_siig20x_fn
},
4373 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S_20x_850
,
4374 PCI_ANY_ID
, PCI_ANY_ID
,
4375 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4376 0, 0, pci_siig20x_fn
},
4377 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_550
,
4378 PCI_ANY_ID
, PCI_ANY_ID
,
4379 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4380 0, 0, pci_siig20x_fn
},
4381 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_650
,
4382 PCI_ANY_ID
, PCI_ANY_ID
,
4383 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4384 0, 0, pci_siig20x_fn
},
4385 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_2S1P_20x_850
,
4386 PCI_ANY_ID
, PCI_ANY_ID
,
4387 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 2, 921600,
4388 0, 0, pci_siig20x_fn
},
4389 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_20x_550
,
4390 PCI_ANY_ID
, PCI_ANY_ID
,
4391 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 4, 921600,
4392 0, 0, pci_siig20x_fn
},
4393 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_20x_650
,
4394 PCI_ANY_ID
, PCI_ANY_ID
,
4395 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 4, 921600,
4396 0, 0, pci_siig20x_fn
},
4397 { PCI_VENDOR_ID_SIIG
, PCI_DEVICE_ID_SIIG_4S_20x_850
,
4398 PCI_ANY_ID
, PCI_ANY_ID
,
4399 SPCI_FL_BASE0
| SPCI_FL_BASE_TABLE
, 4, 921600,
4400 0, 0, pci_siig20x_fn
},
4401 /* Computone devices submitted by Doug McNash dmcnash@computone.com */
4402 { PCI_VENDOR_ID_COMPUTONE
, PCI_DEVICE_ID_COMPUTONE_PG
,
4403 PCI_SUBVENDOR_ID_COMPUTONE
, PCI_SUBDEVICE_ID_COMPUTONE_PG4
,
4404 SPCI_FL_BASE0
, 4, 921600, /* IOMEM */
4405 0x40, 2, NULL
, 0x200 },
4406 { PCI_VENDOR_ID_COMPUTONE
, PCI_DEVICE_ID_COMPUTONE_PG
,
4407 PCI_SUBVENDOR_ID_COMPUTONE
, PCI_SUBDEVICE_ID_COMPUTONE_PG8
,
4408 SPCI_FL_BASE0
, 8, 921600, /* IOMEM */
4409 0x40, 2, NULL
, 0x200 },
4410 { PCI_VENDOR_ID_COMPUTONE
, PCI_DEVICE_ID_COMPUTONE_PG
,
4411 PCI_SUBVENDOR_ID_COMPUTONE
, PCI_SUBDEVICE_ID_COMPUTONE_PG6
,
4412 SPCI_FL_BASE0
, 6, 921600, /* IOMEM */
4413 0x40, 2, NULL
, 0x200 },
4414 /* Digitan DS560-558, from jimd@esoft.com */
4415 { PCI_VENDOR_ID_ATT
, PCI_DEVICE_ID_ATT_VENUS_MODEM
,
4416 PCI_ANY_ID
, PCI_ANY_ID
,
4417 SPCI_FL_BASE1
, 1, 115200 },
4418 /* 3Com US Robotics 56k Voice Internal PCI model 5610 */
4419 { PCI_VENDOR_ID_USR
, 0x1008,
4420 PCI_ANY_ID
, PCI_ANY_ID
,
4421 SPCI_FL_BASE0
, 1, 115200 },
4422 /* Titan Electronic cards */
4423 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_100
,
4424 PCI_ANY_ID
, PCI_ANY_ID
,
4425 SPCI_FL_BASE0
, 1, 921600 },
4426 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_200
,
4427 PCI_ANY_ID
, PCI_ANY_ID
,
4428 SPCI_FL_BASE0
, 2, 921600 },
4429 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_400
,
4430 PCI_ANY_ID
, PCI_ANY_ID
,
4431 SPCI_FL_BASE0
, 4, 921600 },
4432 { PCI_VENDOR_ID_TITAN
, PCI_DEVICE_ID_TITAN_800B
,
4433 PCI_ANY_ID
, PCI_ANY_ID
,
4434 SPCI_FL_BASE0
, 4, 921600 },
4435 /* EKF addition for i960 Boards form EKF with serial port */
4436 { PCI_VENDOR_ID_INTEL
, 0x1960,
4438 SPCI_FL_BASE0
, 32, 921600, /* max 256 ports */
4439 8<<2, 2, pci_inteli960ni_fn
, 0x10000},
4440 /* RAStel 2 port modem, gerg@moreton.com.au */
4441 { PCI_VENDOR_ID_MORETON
, PCI_DEVICE_ID_RASTEL_2PORT
,
4442 PCI_ANY_ID
, PCI_ANY_ID
,
4443 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
4445 * Untested PCI modems, sent in from various folks...
4447 /* Elsa Model 56K PCI Modem, from Andreas Rath <arh@01019freenet.de> */
4448 { PCI_VENDOR_ID_ROCKWELL
, 0x1004,
4450 SPCI_FL_BASE1
, 1, 115200 },
4451 #if 0 /* No definition for PCI_DEVICE_ID_NEC_NILE4 */
4453 * NEC Vrc-5074 (Nile 4) builtin UART.
4455 { PCI_VENDOR_ID_NEC
, PCI_DEVICE_ID_NEC_NILE4
,
4456 PCI_ANY_ID
, PCI_ANY_ID
,
4457 SPCI_FL_BASE0
, 1, 520833,
4458 64, 3, NULL
, 0x300 },
4460 /* Generic serial board */
4463 SPCI_FL_BASE0
, 1, 115200 },
4467 * Given a complete unknown PCI device, try to use some heuristics to
4468 * guess what the configuration might be, based on the pitiful PCI
4469 * serial specs. Returns 0 on success, 1 on failure.
4471 static int _INLINE_
serial_pci_guess_board(struct pci_dev
*dev
,
4472 struct pci_board
*board
)
4474 int num_iomem
= 0, num_port
= 0, first_port
= -1;
4478 * If it is not a communications device or the programming
4479 * interface is greater than 6, give up.
4481 * (Should we try to make guesses for multiport serial devices
4484 if ((dev
->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL
||
4485 (dev
->class & 0xff) > 6)
4488 for (i
=0; i
< 6; i
++) {
4489 if (IS_PCI_REGION_IOPORT(dev
, i
)) {
4491 if (first_port
== -1)
4499 * If there is 1 or 0 iomem regions, and exactly one port, use
4502 if (num_iomem
<= 1 && num_port
== 1) {
4503 board
->flags
= first_port
;
4512 * Query PCI space for known serial boards
4513 * If found, add them to the PCI device space in rs_table[]
4515 * Accept a maximum of eight boards
4518 static void __init
probe_serial_pci(void)
4520 struct pci_dev
*dev
= NULL
;
4521 struct pci_board
*board
;
4523 #ifdef SERIAL_DEBUG_PCI
4524 printk(KERN_DEBUG
"Entered probe_serial_pci()\n");
4527 pci_for_each_dev(dev
) {
4528 for (board
= pci_boards
; board
->vendor
; board
++) {
4529 if (board
->vendor
!= (unsigned short) PCI_ANY_ID
&&
4530 dev
->vendor
!= board
->vendor
)
4532 if (board
->device
!= (unsigned short) PCI_ANY_ID
&&
4533 dev
->device
!= board
->device
)
4535 if (board
->subvendor
!= (unsigned short) PCI_ANY_ID
&&
4536 pci_get_subvendor(dev
) != board
->subvendor
)
4538 if (board
->subdevice
!= (unsigned short) PCI_ANY_ID
&&
4539 pci_get_subdevice(dev
) != board
->subdevice
)
4544 if (board
->vendor
== 0 && serial_pci_guess_board(dev
, board
))
4547 start_pci_pnp_board(dev
, board
);
4550 #ifdef SERIAL_DEBUG_PCI
4551 printk(KERN_DEBUG
"Leaving probe_serial_pci() (probe finished)\n");
4556 #endif /* ENABLE_SERIAL_PCI */
4558 #ifdef ENABLE_SERIAL_PNP
4561 unsigned short vendor
;
4562 unsigned short device
;
4565 static struct pnp_board pnp_devices
[] __initdata
= {
4566 /* Archtek America Corp. */
4567 /* Archtek SmartLink Modem 3334BT Plug & Play */
4568 { ISAPNP_VENDOR('A', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
4569 /* Anchor Datacomm BV */
4570 /* SXPro 144 External Data Fax Modem Plug & Play */
4571 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0001) },
4572 /* SXPro 288 External Data Fax Modem Plug & Play */
4573 { ISAPNP_VENDOR('A', 'D', 'C'), ISAPNP_DEVICE(0x0002) },
4574 /* Rockwell 56K ACF II Fax+Data+Voice Modem */
4575 { ISAPNP_VENDOR('A', 'K', 'Y'), ISAPNP_DEVICE(0x1021) },
4576 /* AZT3005 PnP SOUND DEVICE */
4577 { ISAPNP_VENDOR('A', 'Z', 'T'), ISAPNP_DEVICE(0x4001) },
4578 /* Best Data Products Inc. Smart One 336F PnP Modem */
4579 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
4581 /* Boca Complete Ofc Communicator 14.4 Data-FAX */
4582 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
4583 /* Boca Research 33,600 ACF Modem */
4584 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x1400) },
4585 /* Boca 33.6 Kbps Internal FD34FSVD */
4586 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x3400) },
4587 /* Boca 33.6 Kbps Internal FD34FSVD */
4588 { ISAPNP_VENDOR('B', 'R', 'I'), ISAPNP_DEVICE(0x0A49) },
4589 /* Best Data Products Inc. Smart One 336F PnP Modem */
4590 { ISAPNP_VENDOR('B', 'D', 'P'), ISAPNP_DEVICE(0x3336) },
4591 /* Computer Peripherals Inc */
4592 /* EuroViVa CommCenter-33.6 SP PnP */
4593 { ISAPNP_VENDOR('C', 'P', 'I'), ISAPNP_DEVICE(0x4050) },
4595 /* Creative Labs Phone Blaster 28.8 DSVD PnP Voice */
4596 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3001) },
4597 /* Creative Labs Modem Blaster 28.8 DSVD PnP Voice */
4598 { ISAPNP_VENDOR('C', 'T', 'L'), ISAPNP_DEVICE(0x3011) },
4600 /* Creative Modem Blaster Flash56 DI5601-1 */
4601 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x1032) },
4602 /* Creative Modem Blaster V.90 DI5660 */
4603 { ISAPNP_VENDOR('D', 'M', 'B'), ISAPNP_DEVICE(0x2001) },
4605 /* Fujitsu 33600 PnP-I2 R Plug & Play */
4606 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0202) },
4607 /* Fujitsu FMV-FX431 Plug & Play */
4608 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0205) },
4609 /* Fujitsu 33600 PnP-I4 R Plug & Play */
4610 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0206) },
4611 /* Fujitsu Fax Voice 33600 PNP-I5 R Plug & Play */
4612 { ISAPNP_VENDOR('F', 'U', 'J'), ISAPNP_DEVICE(0x0209) },
4613 /* Archtek America Corp. */
4614 /* Archtek SmartLink Modem 3334BT Plug & Play */
4615 { ISAPNP_VENDOR('G', 'V', 'C'), ISAPNP_DEVICE(0x000F) },
4617 /* Hayes Optima 288 V.34-V.FC + FAX + Voice Plug & Play */
4618 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x0001) },
4619 /* Hayes Optima 336 V.34 + FAX + Voice PnP */
4620 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000C) },
4621 /* Hayes Optima 336B V.34 + FAX + Voice PnP */
4622 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x000D) },
4623 /* Hayes Accura 56K Ext Fax Modem PnP */
4624 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5670) },
4625 /* Hayes Accura 56K Ext Fax Modem PnP */
4626 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5674) },
4627 /* Hayes Accura 56K Fax Modem PnP */
4628 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0x5675) },
4629 /* Hayes 288, V.34 + FAX */
4630 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF000) },
4631 /* Hayes Optima 288 V.34 + FAX + Voice, Plug & Play */
4632 { ISAPNP_VENDOR('H', 'A', 'Y'), ISAPNP_DEVICE(0xF001) },
4634 /* IBM Thinkpad 701 Internal Modem Voice */
4635 { ISAPNP_VENDOR('I', 'B', 'M'), ISAPNP_DEVICE(0x0033) },
4637 /* Intertex 28k8 33k6 Voice EXT PnP */
4638 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC801) },
4639 /* Intertex 33k6 56k Voice EXT PnP */
4640 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xC901) },
4641 /* Intertex 28k8 33k6 Voice SP EXT PnP */
4642 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD801) },
4643 /* Intertex 33k6 56k Voice SP EXT PnP */
4644 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xD901) },
4645 /* Intertex 28k8 33k6 Voice SP INT PnP */
4646 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF401) },
4647 /* Intertex 28k8 33k6 Voice SP EXT PnP */
4648 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF801) },
4649 /* Intertex 33k6 56k Voice SP EXT PnP */
4650 { ISAPNP_VENDOR('I', 'X', 'D'), ISAPNP_DEVICE(0xF901) },
4651 /* Kortex International */
4652 /* KORTEX 28800 Externe PnP */
4653 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0x4522) },
4654 /* KXPro 33.6 Vocal ASVD PnP */
4655 { ISAPNP_VENDOR('K', 'O', 'R'), ISAPNP_DEVICE(0xF661) },
4657 /* LASAT Internet 33600 PnP */
4658 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4040) },
4659 /* Lasat Safire 560 PnP */
4660 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x4540) },
4661 /* Lasat Safire 336 PnP */
4662 { ISAPNP_VENDOR('L', 'A', 'S'), ISAPNP_DEVICE(0x5440) },
4663 /* Microcom, Inc. */
4664 /* Microcom TravelPorte FAST V.34 Plug & Play */
4665 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x281) },
4666 /* Microcom DeskPorte V.34 FAST or FAST+ Plug & Play */
4667 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0336) },
4668 /* Microcom DeskPorte FAST EP 28.8 Plug & Play */
4669 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0339) },
4670 /* Microcom DeskPorte 28.8P Plug & Play */
4671 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0342) },
4672 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
4673 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
4674 /* Microcom DeskPorte FAST ES 28.8 Plug & Play */
4675 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
4676 /* Microcom DeskPorte 28.8S Internal Plug & Play */
4677 { ISAPNP_VENDOR('M', 'N', 'P'), ISAPNP_DEVICE(0x0502) },
4679 /* Motorola BitSURFR Plug & Play */
4680 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1105) },
4681 /* Motorola TA210 Plug & Play */
4682 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1111) },
4683 /* Motorola HMTA 200 (ISDN) Plug & Play */
4684 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1114) },
4685 /* Motorola BitSURFR Plug & Play */
4686 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1115) },
4687 /* Motorola Lifestyle 28.8 Internal */
4688 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1190) },
4689 /* Motorola V.3400 Plug & Play */
4690 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1501) },
4691 /* Motorola Lifestyle 28.8 V.34 Plug & Play */
4692 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1502) },
4693 /* Motorola Power 28.8 V.34 Plug & Play */
4694 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1505) },
4695 /* Motorola ModemSURFR External 28.8 Plug & Play */
4696 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1509) },
4697 /* Motorola Premier 33.6 Desktop Plug & Play */
4698 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150A) },
4699 /* Motorola VoiceSURFR 56K External PnP */
4700 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x150F) },
4701 /* Motorola ModemSURFR 56K External PnP */
4702 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1510) },
4703 /* Motorola ModemSURFR 56K Internal PnP */
4704 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1550) },
4705 /* Motorola ModemSURFR Internal 28.8 Plug & Play */
4706 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1560) },
4707 /* Motorola Premier 33.6 Internal Plug & Play */
4708 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x1580) },
4709 /* Motorola OnlineSURFR 28.8 Internal Plug & Play */
4710 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15B0) },
4711 /* Motorola VoiceSURFR 56K Internal PnP */
4712 { ISAPNP_VENDOR('M', 'O', 'T'), ISAPNP_DEVICE(0x15F0) },
4714 /* Deskline K56 Phone System PnP */
4715 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00A1) },
4716 /* PC Rider K56 Phone System PnP */
4717 { ISAPNP_VENDOR('M', 'V', 'X'), ISAPNP_DEVICE(0x00F2) },
4718 /* Pace 56 Voice Internal Plug & Play Modem */
4719 { ISAPNP_VENDOR('P', 'M', 'C'), ISAPNP_DEVICE(0x2430) },
4721 /* Generic standard PC COM port */
4722 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0500) },
4723 /* Generic 16550A-compatible COM port */
4724 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x0501) },
4725 /* Compaq 14400 Modem */
4726 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC000) },
4727 /* Compaq 2400/9600 Modem */
4728 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC001) },
4729 /* Dial-Up Networking Serial Cable between 2 PCs */
4730 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC031) },
4731 /* Dial-Up Networking Parallel Cable between 2 PCs */
4732 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC032) },
4733 /* Standard 9600 bps Modem */
4734 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC100) },
4735 /* Standard 14400 bps Modem */
4736 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC101) },
4737 /* Standard 28800 bps Modem*/
4738 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC102) },
4740 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC103) },
4741 /* Standard 9600 bps Modem*/
4742 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC104) },
4743 /* Standard 14400 bps Modem*/
4744 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC105) },
4745 /* Standard 28800 bps Modem*/
4746 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC106) },
4747 /* Standard Modem */
4748 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC107) },
4749 /* Standard 9600 bps Modem */
4750 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC108) },
4751 /* Standard 14400 bps Modem */
4752 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC109) },
4753 /* Standard 28800 bps Modem */
4754 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10A) },
4755 /* Standard Modem */
4756 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10B) },
4757 /* Standard 9600 bps Modem */
4758 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10C) },
4759 /* Standard 14400 bps Modem */
4760 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10D) },
4761 /* Standard 28800 bps Modem */
4762 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10E) },
4763 /* Standard Modem */
4764 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0xC10F) },
4765 /* Standard PCMCIA Card Modem */
4766 { ISAPNP_VENDOR('P', 'N', 'P'), ISAPNP_DEVICE(0x2000) },
4768 /* Modular Technology */
4769 /* Rockwell 33.6 DPF Internal PnP */
4770 /* Modular Technology 33.6 Internal PnP */
4771 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0030) },
4772 /* Kortex International */
4773 /* KORTEX 14400 Externe PnP */
4774 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x0100) },
4775 /* Viking Components, Inc */
4776 /* Viking 28.8 INTERNAL Fax+Data+Voice PnP */
4777 { ISAPNP_VENDOR('R', 'O', 'K'), ISAPNP_DEVICE(0x4920) },
4779 /* British Telecom */
4780 /* Modular Technology */
4781 /* Rockwell 33.6 DPF External PnP */
4782 /* BT Prologue 33.6 External PnP */
4783 /* Modular Technology 33.6 External PnP */
4784 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x00A0) },
4785 /* Viking 56K FAX INT */
4786 { ISAPNP_VENDOR('R', 'S', 'S'), ISAPNP_DEVICE(0x0262) },
4787 /* SupraExpress 28.8 Data/Fax PnP modem */
4788 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1310) },
4789 /* SupraExpress 33.6 Data/Fax PnP modem */
4790 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1421) },
4791 /* SupraExpress 33.6 Data/Fax PnP modem */
4792 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1590) },
4793 /* SupraExpress 33.6 Data/Fax PnP modem */
4794 { ISAPNP_VENDOR('S', 'U', 'P'), ISAPNP_DEVICE(0x1760) },
4796 /* Phoebe Micro 33.6 Data Fax 1433VQH Plug & Play */
4797 { ISAPNP_VENDOR('T', 'E', 'X'), ISAPNP_DEVICE(0x0011) },
4798 /* Archtek America Corp. */
4799 /* Archtek SmartLink Modem 3334BT Plug & Play */
4800 { ISAPNP_VENDOR('U', 'A', 'C'), ISAPNP_DEVICE(0x000F) },
4802 /* Gateway Telepath IIvi 33.6 */
4803 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0000) },
4804 /* Sportster Vi 14.4 PnP FAX Voicemail */
4805 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0004) },
4806 /* U.S. Robotics 33.6K Voice INT PnP */
4807 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0006) },
4808 /* U.S. Robotics 33.6K Voice EXT PnP */
4809 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x0007) },
4810 /* U.S. Robotics 33.6K Voice INT PnP */
4811 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2002) },
4812 /* U.S. Robotics 56K Voice INT PnP */
4813 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2070) },
4814 /* U.S. Robotics 56K Voice EXT PnP */
4815 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x2080) },
4816 /* U.S. Robotics 56K FAX INT */
4817 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3031) },
4818 /* U.S. Robotics 56K Voice INT PnP */
4819 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3070) },
4820 /* U.S. Robotics 56K Voice EXT PnP */
4821 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3080) },
4822 /* U.S. Robotics 56K Voice INT PnP */
4823 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x3090) },
4824 /* U.S. Robotics 56K Message */
4825 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9100) },
4826 /* U.S. Robotics 56K FAX EXT PnP*/
4827 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9160) },
4828 /* U.S. Robotics 56K FAX INT PnP*/
4829 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9170) },
4830 /* U.S. Robotics 56K Voice EXT PnP*/
4831 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9180) },
4832 /* U.S. Robotics 56K Voice INT PnP*/
4833 { ISAPNP_VENDOR('U', 'S', 'R'), ISAPNP_DEVICE(0x9190) },
4837 static void inline avoid_irq_share(struct pci_dev
*dev
)
4839 int i
, map
= 0x1FF8;
4840 struct serial_state
*state
= rs_table
;
4841 struct isapnp_irq
*irq
;
4842 struct isapnp_resources
*res
= dev
->sysdata
;
4844 for (i
= 0; i
< NR_PORTS
; i
++) {
4845 if (state
->type
!= PORT_UNKNOWN
)
4846 clear_bit(state
->irq
, &map
);
4850 for ( ; res
; res
= res
->alt
)
4851 for(irq
= res
->irq
; irq
; irq
= irq
->next
)
4855 static char *modem_names
[] __initdata
= {
4856 "MODEM", "Modem", "modem", "FAX", "Fax", "fax",
4857 "56K", "56k", "K56", "33.6", "28.8", "14.4",
4858 "33,600", "28,800", "14,400", "33.600", "28.800", "14.400",
4859 "33600", "28800", "14400", "V.90", "V.34", "V.32", 0
4862 static int __init
check_name(char *name
)
4864 char **tmp
= modem_names
;
4867 if (strstr(name
, *tmp
))
4874 static int inline check_compatible_id(struct pci_dev
*dev
)
4877 for (i
= 0; i
< DEVICE_COUNT_COMPATIBLE
; i
++)
4878 if ((dev
->vendor_compatible
[i
] ==
4879 ISAPNP_VENDOR('P', 'N', 'P')) &&
4880 (swab16(dev
->device_compatible
[i
]) >= 0xc000) &&
4881 (swab16(dev
->device_compatible
[i
]) <= 0xdfff))
4887 * Given a complete unknown ISA PnP device, try to use some heuristics to
4888 * detect modems. Currently use such heuristic set:
4889 * - dev->name or dev->bus->name must contain "modem" substring;
4890 * - device must have only one IO region (8 byte long) with base adress
4891 * 0x2e8, 0x3e8, 0x2f8 or 0x3f8.
4893 * Such detection looks very ugly, but can detect at least some of numerous
4894 * ISA PnP modems, alternatively we must hardcode all modems in pnp_devices[]
4897 static int _INLINE_
serial_pnp_guess_board(struct pci_dev
*dev
,
4898 struct pci_board
*board
)
4900 struct isapnp_resources
*res
= (struct isapnp_resources
*)dev
->sysdata
;
4901 struct isapnp_resources
*resa
;
4903 if (!(check_name(dev
->name
) || check_name(dev
->bus
->name
)) &&
4904 !(check_compatible_id(dev
)))
4907 if (!res
|| res
->next
)
4910 for (resa
= res
->alt
; resa
; resa
= resa
->alt
) {
4911 struct isapnp_port
*port
;
4912 for (port
= res
->port
; port
; port
= port
->next
)
4913 if ((port
->size
== 8) &&
4914 ((port
->min
== 0x2f8) ||
4915 (port
->min
== 0x3f8) ||
4916 (port
->min
== 0x2e8) ||
4917 (port
->min
== 0x3e8)))
4924 static void __init
probe_serial_pnp(void)
4926 struct pci_dev
*dev
= NULL
;
4927 struct pnp_board
*pnp_board
;
4928 struct pci_board board
;
4930 #ifdef SERIAL_DEBUG_PNP
4931 printk("Entered probe_serial_pnp()\n");
4933 if (!isapnp_present()) {
4934 #ifdef SERIAL_DEBUG_PNP
4935 printk("Leaving probe_serial_pnp() (no isapnp)\n");
4940 isapnp_for_each_dev(dev
) {
4944 memset(&board
, 0, sizeof(board
));
4945 board
.flags
= SPCI_FL_BASE0
| SPCI_FL_PNPDEFAULT
;
4946 board
.num_ports
= 1;
4947 board
.base_baud
= 115200;
4949 for (pnp_board
= pnp_devices
; pnp_board
->vendor
; pnp_board
++)
4950 if ((dev
->vendor
== pnp_board
->vendor
) &&
4951 (dev
->device
== pnp_board
->device
))
4954 if (pnp_board
->vendor
) {
4955 board
.vendor
= pnp_board
->vendor
;
4956 board
.device
= pnp_board
->device
;
4957 /* Special case that's more efficient to hardcode */
4958 if ((board
.vendor
== ISAPNP_VENDOR('A', 'K', 'Y') &&
4959 board
.device
== ISAPNP_DEVICE(0x1021)))
4960 board
.flags
|= SPCI_FL_NO_SHIRQ
;
4962 if (serial_pnp_guess_board(dev
, &board
))
4966 if (board
.flags
& SPCI_FL_NO_SHIRQ
)
4967 avoid_irq_share(dev
);
4968 start_pci_pnp_board(dev
, &board
);
4971 #ifdef SERIAL_DEBUG_PNP
4972 printk("Leaving probe_serial_pnp() (probe finished)\n");
4977 #endif /* ENABLE_SERIAL_PNP */
4980 * The serial driver boot-time initialization code!
4982 int __init
rs_init(void)
4985 struct serial_state
* state
;
4987 if (timer_table
[RS_TIMER
].fn
) {
4988 printk("RS_TIMER already set, another serial driver "
4989 "already loaded?\n");
4991 printk("Can't load serial driver module over built-in "
4997 init_bh(SERIAL_BH
, do_serial_bh
);
4998 timer_table
[RS_TIMER
].fn
= rs_timer
;
4999 timer_table
[RS_TIMER
].expires
= 0;
5001 for (i
= 0; i
< NR_IRQS
; i
++) {
5004 #ifdef CONFIG_SERIAL_MULTIPORT
5005 memset(&rs_multiport
[i
], 0,
5006 sizeof(struct rs_multiport_struct
));
5009 #ifdef CONFIG_SERIAL_CONSOLE
5011 * The interrupt of the serial console port
5014 if (sercons
.flags
& CON_CONSDEV
) {
5015 for(i
= 0; i
< NR_PORTS
; i
++)
5016 if (i
!= sercons
.index
&&
5017 rs_table
[i
].irq
== rs_table
[sercons
.index
].irq
)
5018 rs_table
[i
].irq
= 0;
5021 show_serial_version();
5023 /* Initialize the tty_driver structure */
5025 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
5026 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
5027 #if (LINUX_VERSION_CODE > 0x20100)
5028 serial_driver
.driver_name
= "serial";
5030 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5031 serial_driver
.name
= "tts/%d";
5033 serial_driver
.name
= "ttyS";
5035 serial_driver
.major
= TTY_MAJOR
;
5036 serial_driver
.minor_start
= 64 + SERIAL_DEV_OFFSET
;
5037 serial_driver
.num
= NR_PORTS
;
5038 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
5039 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
5040 serial_driver
.init_termios
= tty_std_termios
;
5041 serial_driver
.init_termios
.c_cflag
=
5042 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5043 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_NO_DEVFS
;
5044 serial_driver
.refcount
= &serial_refcount
;
5045 serial_driver
.table
= serial_table
;
5046 serial_driver
.termios
= serial_termios
;
5047 serial_driver
.termios_locked
= serial_termios_locked
;
5049 serial_driver
.open
= rs_open
;
5050 serial_driver
.close
= rs_close
;
5051 serial_driver
.write
= rs_write
;
5052 serial_driver
.put_char
= rs_put_char
;
5053 serial_driver
.flush_chars
= rs_flush_chars
;
5054 serial_driver
.write_room
= rs_write_room
;
5055 serial_driver
.chars_in_buffer
= rs_chars_in_buffer
;
5056 serial_driver
.flush_buffer
= rs_flush_buffer
;
5057 serial_driver
.ioctl
= rs_ioctl
;
5058 serial_driver
.throttle
= rs_throttle
;
5059 serial_driver
.unthrottle
= rs_unthrottle
;
5060 serial_driver
.set_termios
= rs_set_termios
;
5061 serial_driver
.stop
= rs_stop
;
5062 serial_driver
.start
= rs_start
;
5063 serial_driver
.hangup
= rs_hangup
;
5064 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
5065 serial_driver
.break_ctl
= rs_break
;
5067 #if (LINUX_VERSION_CODE >= 131343)
5068 serial_driver
.send_xchar
= rs_send_xchar
;
5069 serial_driver
.wait_until_sent
= rs_wait_until_sent
;
5070 serial_driver
.read_proc
= rs_read_proc
;
5074 * The callout device is just like normal device except for
5075 * major number and the subtype code.
5077 callout_driver
= serial_driver
;
5078 #if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
5079 callout_driver
.name
= "cua/%d";
5081 callout_driver
.name
= "cua";
5083 callout_driver
.major
= TTYAUX_MAJOR
;
5084 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
5085 #if (LINUX_VERSION_CODE >= 131343)
5086 callout_driver
.read_proc
= 0;
5087 callout_driver
.proc_entry
= 0;
5090 if (tty_register_driver(&serial_driver
))
5091 panic("Couldn't register serial driver\n");
5092 if (tty_register_driver(&callout_driver
))
5093 panic("Couldn't register callout driver\n");
5095 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
5096 state
->magic
= SSTATE_MAGIC
;
5098 state
->type
= PORT_UNKNOWN
;
5099 state
->custom_divisor
= 0;
5100 state
->close_delay
= 5*HZ
/10;
5101 state
->closing_wait
= 30*HZ
;
5102 state
->callout_termios
= callout_driver
.init_termios
;
5103 state
->normal_termios
= serial_driver
.init_termios
;
5104 state
->icount
.cts
= state
->icount
.dsr
=
5105 state
->icount
.rng
= state
->icount
.dcd
= 0;
5106 state
->icount
.rx
= state
->icount
.tx
= 0;
5107 state
->icount
.frame
= state
->icount
.parity
= 0;
5108 state
->icount
.overrun
= state
->icount
.brk
= 0;
5109 state
->irq
= irq_cannonicalize(state
->irq
);
5111 state
->io_type
= SERIAL_IO_HUB6
;
5112 if (state
->port
&& check_region(state
->port
,8))
5114 if (state
->flags
& ASYNC_BOOT_AUTOCONF
)
5117 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
5118 if (state
->type
== PORT_UNKNOWN
)
5120 if ( (state
->flags
& ASYNC_BOOT_AUTOCONF
)
5121 && (state
->flags
& ASYNC_AUTO_IRQ
)
5122 && (state
->port
!= 0))
5123 state
->irq
= detect_uart_irq(state
);
5124 printk(KERN_INFO
"ttyS%02d%s at 0x%04lx (irq = %d) is a %s\n",
5125 state
->line
+ SERIAL_DEV_OFFSET
,
5126 (state
->flags
& ASYNC_FOURPORT
) ? " FourPort" : "",
5127 state
->port
, state
->irq
,
5128 uart_config
[state
->type
].name
);
5129 tty_register_devfs(&serial_driver
, 0,
5130 serial_driver
.minor_start
+ state
->line
);
5131 tty_register_devfs(&callout_driver
, 0,
5132 callout_driver
.minor_start
+ state
->line
);
5134 #ifdef ENABLE_SERIAL_PCI
5137 #ifdef ENABLE_SERIAL_PNP
5144 * register_serial and unregister_serial allows for 16x50 serial ports to be
5145 * configured at run-time, to support PCMCIA modems.
5149 * register_serial - configure a 16x50 serial port at runtime
5150 * @req: request structure
5152 * Configure the serial port specified by the request. If the
5153 * port exists and is in use an error is returned. If the port
5154 * is not currently in the table it is added.
5156 * The port is then probed and if neccessary the IRQ is autodetected
5157 * If this fails an error is returned.
5159 * On success the port is ready to use and the line number is returned.
5162 int register_serial(struct serial_struct
*req
)
5165 unsigned long flags
;
5166 struct serial_state
*state
;
5167 struct async_struct
*info
;
5171 if (HIGH_BITS_OFFSET
)
5172 port
+= req
->port_high
<< HIGH_BITS_OFFSET
;
5174 save_flags(flags
); cli();
5175 for (i
= 0; i
< NR_PORTS
; i
++) {
5176 if ((rs_table
[i
].port
== port
) &&
5177 (rs_table
[i
].iomem_base
== req
->iomem_base
))
5180 if (i
== NR_PORTS
) {
5181 for (i
= 4; i
< NR_PORTS
; i
++)
5182 if ((rs_table
[i
].type
== PORT_UNKNOWN
) &&
5183 (rs_table
[i
].count
== 0))
5186 if (i
== NR_PORTS
) {
5187 for (i
= 0; i
< NR_PORTS
; i
++)
5188 if ((rs_table
[i
].type
== PORT_UNKNOWN
) &&
5189 (rs_table
[i
].count
== 0))
5192 if (i
== NR_PORTS
) {
5193 restore_flags(flags
);
5196 state
= &rs_table
[i
];
5197 if (rs_table
[i
].count
) {
5198 restore_flags(flags
);
5199 printk("Couldn't configure serial #%d (port=%ld,irq=%d): "
5200 "device already open\n", i
, port
, req
->irq
);
5203 state
->irq
= req
->irq
;
5205 state
->flags
= req
->flags
;
5206 state
->io_type
= req
->io_type
;
5207 state
->iomem_base
= req
->iomem_base
;
5208 state
->iomem_reg_shift
= req
->iomem_reg_shift
;
5210 state
->baud_base
= req
->baud_base
;
5211 if ((info
= state
->info
) != NULL
) {
5213 info
->flags
= req
->flags
;
5214 info
->io_type
= req
->io_type
;
5215 info
->iomem_base
= req
->iomem_base
;
5216 info
->iomem_reg_shift
= req
->iomem_reg_shift
;
5219 if (state
->type
== PORT_UNKNOWN
) {
5220 restore_flags(flags
);
5221 printk("register_serial(): autoconfig failed\n");
5224 restore_flags(flags
);
5226 if ((state
->flags
& ASYNC_AUTO_IRQ
) && CONFIGURED_SERIAL_PORT(state
))
5227 state
->irq
= detect_uart_irq(state
);
5229 printk(KERN_INFO
"ttyS%02d at %s 0x%04lx (irq = %d) is a %s\n",
5230 state
->line
+ SERIAL_DEV_OFFSET
,
5231 state
->iomem_base
? "iomem" : "port",
5232 state
->iomem_base
? (unsigned long)state
->iomem_base
:
5233 state
->port
, state
->irq
, uart_config
[state
->type
].name
);
5234 tty_register_devfs(&serial_driver
, 0,
5235 serial_driver
.minor_start
+ state
->line
);
5236 tty_register_devfs(&callout_driver
, 0,
5237 callout_driver
.minor_start
+ state
->line
);
5238 return state
->line
+ SERIAL_DEV_OFFSET
;
5242 * unregister_serial - deconfigure a 16x50 serial port
5243 * @line: line to deconfigure
5245 * The port specified is deconfigured and its resources are freed. Any
5246 * user of the port is disconnected as if carrier was dropped. Line is
5247 * the port number returned by register_serial().
5250 void unregister_serial(int line
)
5252 unsigned long flags
;
5253 struct serial_state
*state
= &rs_table
[line
];
5255 save_flags(flags
); cli();
5256 if (state
->info
&& state
->info
->tty
)
5257 tty_hangup(state
->info
->tty
);
5258 state
->type
= PORT_UNKNOWN
;
5259 printk(KERN_INFO
"tty%02d unloaded\n", state
->line
);
5260 /* These will be hidden, because they are devices that will no longer
5261 * be available to the system. (ie, PCMCIA modems, once ejected)
5263 tty_unregister_devfs(&serial_driver
,
5264 serial_driver
.minor_start
+ state
->line
);
5265 tty_unregister_devfs(&callout_driver
,
5266 callout_driver
.minor_start
+ state
->line
);
5267 restore_flags(flags
);
5273 unsigned long flags
;
5276 struct async_struct
*info
;
5278 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
5279 save_flags(flags
); cli();
5280 timer_active
&= ~(1 << RS_TIMER
);
5281 timer_table
[RS_TIMER
].fn
= NULL
;
5282 timer_table
[RS_TIMER
].expires
= 0;
5283 remove_bh(SERIAL_BH
);
5284 if ((e1
= tty_unregister_driver(&serial_driver
)))
5285 printk("serial: failed to unregister serial driver (%d)\n",
5287 if ((e2
= tty_unregister_driver(&callout_driver
)))
5288 printk("serial: failed to unregister callout driver (%d)\n",
5290 restore_flags(flags
);
5292 for (i
= 0; i
< NR_PORTS
; i
++) {
5293 if ((info
= rs_table
[i
].info
)) {
5294 rs_table
[i
].info
= NULL
;
5295 kfree_s(info
, sizeof(struct async_struct
));
5297 if ((rs_table
[i
].type
!= PORT_UNKNOWN
) && rs_table
[i
].port
) {
5298 #ifdef CONFIG_SERIAL_RSA
5299 if (rs_table
[i
].type
== PORT_RSA
)
5300 release_region(rs_table
[i
].port
+
5304 release_region(rs_table
[i
].port
, 8);
5306 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5307 if (rs_table
[i
].iomem_base
)
5308 iounmap(rs_table
[i
].iomem_base
);
5311 #if defined(ENABLE_SERIAL_PCI) || defined(ENABLE_SERIAL_PNP)
5312 for (i
=0; i
< serial_pci_board_idx
; i
++) {
5313 struct pci_board_inst
*brd
= &serial_pci_board
[i
];
5315 if (brd
->board
.init_fn
)
5316 (brd
->board
.init_fn
)(brd
->dev
, &brd
->board
, 0);
5318 if (DEACTIVATE_FUNC(brd
->dev
))
5319 (DEACTIVATE_FUNC(brd
->dev
))(brd
->dev
);
5323 unsigned long pg
= (unsigned long) tmp_buf
;
5330 module_init(rs_init
);
5331 module_exit(rs_fini
);
5335 * ------------------------------------------------------------
5336 * Serial console driver
5337 * ------------------------------------------------------------
5339 #ifdef CONFIG_SERIAL_CONSOLE
5341 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
5343 static struct async_struct async_sercons
;
5346 * Wait for transmitter & holding register to empty
5348 static inline void wait_for_xmitr(struct async_struct
*info
)
5350 unsigned int tmout
= 1000000;
5353 ((serial_in(info
, UART_LSR
) & BOTH_EMPTY
) != BOTH_EMPTY
));
5358 * Print a string to the serial port trying not to disturb
5359 * any possible real use of the port...
5361 * The console_lock must be held when we get here.
5363 static void serial_console_write(struct console
*co
, const char *s
,
5366 static struct async_struct
*info
= &async_sercons
;
5371 * First save the IER then disable the interrupts
5373 ier
= serial_in(info
, UART_IER
);
5374 serial_out(info
, UART_IER
, 0x00);
5377 * Now, do each character
5379 for (i
= 0; i
< count
; i
++, s
++) {
5380 wait_for_xmitr(info
);
5383 * Send the character out.
5384 * If a LF, also do CR...
5386 serial_out(info
, UART_TX
, *s
);
5388 wait_for_xmitr(info
);
5389 serial_out(info
, UART_TX
, 13);
5394 * Finally, Wait for transmitter & holding register to empty
5395 * and restore the IER
5397 wait_for_xmitr(info
);
5398 serial_out(info
, UART_IER
, ier
);
5402 * Receive character from the serial port
5404 static int serial_console_wait_key(struct console
*co
)
5406 static struct async_struct
*info
;
5409 info
= &async_sercons
;
5412 * First save the IER then disable the interrupts so
5413 * that the real driver for the port does not get the
5416 ier
= serial_in(info
, UART_IER
);
5417 serial_out(info
, UART_IER
, 0x00);
5419 while ((serial_in(info
, UART_LSR
) & UART_LSR_DR
) == 0);
5420 c
= serial_in(info
, UART_RX
);
5423 * Restore the interrupts
5425 serial_out(info
, UART_IER
, ier
);
5430 static kdev_t
serial_console_device(struct console
*c
)
5432 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
5436 * Setup initial baud/bits/parity. We do two things here:
5437 * - construct a cflag setting for the first rs_open()
5438 * - initialize the serial port
5439 * Return non-zero if we didn't find a serial port.
5441 static int __init
serial_console_setup(struct console
*co
, char *options
)
5443 static struct async_struct
*info
;
5444 struct serial_state
*state
;
5449 int cflag
= CREAD
| HUPCL
| CLOCAL
;
5454 baud
= simple_strtoul(options
, NULL
, 10);
5456 while(*s
>= '0' && *s
<= '9')
5458 if (*s
) parity
= *s
++;
5459 if (*s
) bits
= *s
- '0';
5463 * Now construct a cflag setting.
5512 * Divisor, bytesize and parity
5514 state
= rs_table
+ co
->index
;
5515 info
= &async_sercons
;
5516 info
->magic
= SERIAL_MAGIC
;
5517 info
->state
= state
;
5518 info
->port
= state
->port
;
5519 info
->flags
= state
->flags
;
5521 info
->hub6
= state
->hub6
;
5523 info
->io_type
= state
->io_type
;
5524 info
->iomem_base
= state
->iomem_base
;
5525 info
->iomem_reg_shift
= state
->iomem_reg_shift
;
5526 quot
= state
->baud_base
/ baud
;
5527 cval
= cflag
& (CSIZE
| CSTOPB
);
5528 #if defined(__powerpc__) || defined(__alpha__)
5530 #else /* !__powerpc__ && !__alpha__ */
5532 #endif /* !__powerpc__ && !__alpha__ */
5534 cval
|= UART_LCR_PARITY
;
5535 if (!(cflag
& PARODD
))
5536 cval
|= UART_LCR_EPAR
;
5539 * Disable UART interrupts, set DTR and RTS high
5542 serial_out(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
5543 serial_out(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
5544 serial_out(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
5545 serial_out(info
, UART_LCR
, cval
); /* reset DLAB */
5546 serial_out(info
, UART_IER
, 0);
5547 serial_out(info
, UART_MCR
, UART_MCR_DTR
| UART_MCR_RTS
);
5550 * If we read 0xff from the LSR, there is no UART here.
5552 if (serial_in(info
, UART_LSR
) == 0xff)
5558 static struct console sercons
= {
5560 serial_console_write
,
5562 serial_console_device
,
5563 serial_console_wait_key
,
5565 serial_console_setup
,
5575 void __init
serial_console_init(void)
5577 register_console(&sercons
);
5583 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"