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 * This module exports the following rs232 io functions:
48 * Serial driver configuration section. Here are the various options:
51 * Enables support for the venerable Bell Technologies
54 * CONFIG_SERIAL_MANY_PORTS
55 * Enables support for ports beyond the standard, stupid
58 * CONFIG_SERIAL_MULTIPORT
59 * Enables support for special multiport board support.
61 * CONFIG_SERIAL_SHARE_IRQ
62 * Enables support for multiple serial ports on one IRQ
64 * CONFIG_SERIAL_DETECT_IRQ
65 * Enable the autodetection of IRQ on standart ports
67 * SERIAL_PARANOIA_CHECK
68 * Check the magic number for the async_structure where
72 #include <linux/config.h>
73 #include <linux/version.h>
75 #undef SERIAL_PARANOIA_CHECK
76 #define CONFIG_SERIAL_NOPAUSE_IO
77 #define SERIAL_DO_RESTART
78 #define CONFIG_SERIAL_PCI_MEMMAPPED
81 /* These defines are normally controlled by the autoconf.h */
82 #define CONFIG_SERIAL_MANY_PORTS
83 #define CONFIG_SERIAL_SHARE_IRQ
84 #define CONFIG_SERIAL_DETECT_IRQ
85 #define CONFIG_SERIAL_MULTIPORT
89 #if (defined(CONFIG_PCI) && (LINUX_VERSION_CODE >= 131072))
90 #define ENABLE_SERIAL_PCI
91 #define CONFIG_SERIAL_SHARE_IRQ
94 /* Set of debugging defines */
96 #undef SERIAL_DEBUG_INTR
97 #undef SERIAL_DEBUG_OPEN
98 #undef SERIAL_DEBUG_FLOW
99 #undef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
100 #undef SERIAL_DEBUG_PCI
104 #ifdef CONFIG_SERIAL_MULTIPORT
105 #ifndef CONFIG_SERIAL_SHARE_IRQ
106 #define CONFIG_SERIAL_SHARE_IRQ
111 #ifndef CONFIG_SERIAL_MANY_PORTS
112 #define CONFIG_SERIAL_MANY_PORTS
114 #ifndef CONFIG_SERIAL_SHARE_IRQ
115 #define CONFIG_SERIAL_SHARE_IRQ
119 #define RS_STROBE_TIME (10*HZ)
120 #define RS_ISR_PASS_LIMIT 256
122 #define IRQ_T(state) \
123 ((state->flags & ASYNC_SHARE_IRQ) ? SA_SHIRQ : SA_INTERRUPT)
125 #define SERIAL_INLINE
127 #if defined(MODULE) && defined(SERIAL_DEBUG_MCOUNT)
128 #define DBG_CNT(s) printk("(%s): [%x] refc=%d, serc=%d, ttyc=%d -> %s\n", \
129 kdevname(tty->device), (info->flags), serial_refcount,info->count,tty->count,s)
135 * End of serial driver configuration section.
138 #if (LINUX_VERSION_CODE > 66304)
140 #ifdef LOCAL_HEADERS /* We're building standalone */
147 #include <linux/modversions.h>
149 #else /* !NEW_MODULES */
153 #endif /* NEW_MODULES */
154 #include <linux/module.h>
157 #include "serial_local.h"
159 #include <linux/serial.h>
160 #include <linux/serial_reg.h>
161 #include <asm/serial.h>
162 static char *serial_version
= "4.30";
165 #include <linux/errno.h>
166 #include <linux/signal.h>
167 #include <linux/sched.h>
168 #include <linux/timer.h>
169 #include <linux/interrupt.h>
170 #include <linux/tty.h>
171 #include <linux/tty_flip.h>
172 #include <linux/major.h>
173 #include <linux/string.h>
174 #include <linux/fcntl.h>
175 #include <linux/ptrace.h>
176 #include <linux/ioport.h>
177 #include <linux/mm.h>
178 #include <linux/malloc.h>
179 #if (LINUX_VERSION_CODE >= 131343) /* 2.1.15 -- XX get correct version */
180 #include <linux/init.h>
182 #define __initfunc(x) x
184 #include <linux/delay.h>
185 #ifdef CONFIG_SERIAL_CONSOLE
186 #include <linux/console.h>
188 #ifdef ENABLE_SERIAL_PCI
189 #include <linux/pci.h>
192 #include <asm/system.h>
195 #include <asm/bitops.h>
197 #ifdef CONFIG_MAC_SERIAL
198 #define SERIAL_DEV_OFFSET 2
200 #define SERIAL_DEV_OFFSET 0
204 #define _INLINE_ inline
207 static char *serial_name
= "Serial driver";
209 static DECLARE_TASK_QUEUE(tq_serial
);
211 static struct tty_driver serial_driver
, callout_driver
;
212 static int serial_refcount
;
214 /* serial subtype definitions */
215 #ifndef SERIAL_TYPE_NORMAL
216 #define SERIAL_TYPE_NORMAL 1
217 #define SERIAL_TYPE_CALLOUT 2
220 /* number of characters left in xmit buffer before we ask for more */
221 #define WAKEUP_CHARS 256
224 * IRQ_timeout - How long the timeout should be for each IRQ
225 * should be after the IRQ has been active.
228 static struct async_struct
*IRQ_ports
[NR_IRQS
];
229 #ifdef CONFIG_SERIAL_MULTIPORT
230 static struct rs_multiport_struct rs_multiport
[NR_IRQS
];
232 static int IRQ_timeout
[NR_IRQS
];
233 #ifdef CONFIG_SERIAL_CONSOLE
234 static struct console sercons
;
237 static unsigned detect_uart_irq (struct serial_state
* state
);
238 static void autoconfig(struct serial_state
* info
);
239 static void change_speed(struct async_struct
*info
, struct termios
*old
);
240 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
);
243 * Here we define the default xmit fifo size used for each type of
246 static struct serial_uart_config uart_config
[] = {
251 { "16550A", 16, UART_CLEAR_FIFO
| UART_USE_FIFO
},
252 { "cirrus", 1, 0 }, /* usurped by cyclades.c */
253 { "ST16650", 1, UART_CLEAR_FIFO
|UART_STARTECH
},
254 { "ST16650V2", 32, UART_CLEAR_FIFO
| UART_USE_FIFO
|
256 { "TI16750", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
},
257 { "Startech", 1, 0}, /* usurped by cyclades.c */
258 { "16C950", 128, UART_CLEAR_FIFO
| UART_USE_FIFO
},
259 { "ST16654", 64, UART_CLEAR_FIFO
| UART_USE_FIFO
|
261 { "XR16850", 128, UART_CLEAR_FIFO
| UART_USE_FIFO
|
266 static struct serial_state rs_table
[RS_TABLE_SIZE
] = {
267 SERIAL_PORT_DFNS
/* Defined in serial.h */
270 #define NR_PORTS (sizeof(rs_table)/sizeof(struct serial_state))
272 #ifdef ENABLE_SERIAL_PCI
273 #define NR_PCI_BOARDS 8
274 static struct pci_board_inst serial_pci_board
[NR_PCI_BOARDS
];
275 static int serial_pci_board_idx
= 0;
276 #define PCI_BASE_ADDRESS(dev, r) ((dev)->resource[r].start)
277 #endif /* ENABLE_SERIAL_PCI */
279 static struct tty_struct
*serial_table
[NR_PORTS
];
280 static struct termios
*serial_termios
[NR_PORTS
];
281 static struct termios
*serial_termios_locked
[NR_PORTS
];
284 #define MIN(a,b) ((a) < (b) ? (a) : (b))
288 * tmp_buf is used as a temporary buffer by serial_write. We need to
289 * lock it in case the copy_from_user blocks while swapping in a page,
290 * and some other program tries to do a serial write at the same time.
291 * Since the lock will only come under contention when the system is
292 * swapping and available memory is low, it makes sense to share one
293 * buffer across all the serial ports, since it significantly saves
294 * memory if large numbers of serial ports are open.
296 static unsigned char *tmp_buf
;
298 static DECLARE_MUTEX(tmp_buf_sem
);
300 static struct semaphore tmp_buf_sem
= MUTEX
;
304 * Provide backwards compatibility for kernels prior to 2.1.XX.
306 #if (LINUX_VERSION_CODE < 0x20000)
307 typedef dev_t kdev_t
;
310 #if (LINUX_VERSION_CODE < 0x02017E)
311 static signed long schedule_timeout(signed long timeout
)
313 unsigned long expire
;
315 expire
= timeout
+ jiffies
;
317 current
->timeout
= jiffies
+ timeout
;
320 timeout
= expire
- jiffies
;
321 return timeout
< 0 ? 0 : timeout
;
326 #define time_after(a,b) ((long)(b) - (long)(a) < 0)
329 #if (LINUX_VERSION_CODE < 0x020100)
330 static inline int irq_cannonicalize(int irq
)
332 return ((irq
== 2) ? 9 : irq
);
336 #if (LINUX_VERSION_CODE < 131336)
337 static int copy_from_user(void *to
, const void *from_user
, unsigned long len
)
341 error
= verify_area(VERIFY_READ
, from_user
, len
);
344 memcpy_fromfs(to
, from_user
, len
);
348 static int copy_to_user(void *to_user
, const void *from
, unsigned long len
)
352 error
= verify_area(VERIFY_WRITE
, to_user
, len
);
355 memcpy_tofs(to_user
, from
, len
);
359 static inline int signal_pending(struct task_struct
*p
)
361 return (p
->signal
& (~p
->blocked
!= 0));
365 #include <asm/uaccess.h>
369 #define serial_isroot() (capable(CAP_SYS_ADMIN))
371 #define serial_isroot() (suser())
374 #if (LINUX_VERSION_CODE < 131394) /* 2.1.66 */
375 #define test_and_clear_bit(x,y) clear_bit(x,y)
377 static inline void remove_bh(int nr
)
380 bh_mask
&= ~(1 << nr
);
385 static inline int serial_paranoia_check(struct async_struct
*info
,
386 kdev_t device
, const char *routine
)
388 #ifdef SERIAL_PARANOIA_CHECK
389 static const char *badmagic
=
390 "Warning: bad magic number for serial struct (%s) in %s\n";
391 static const char *badinfo
=
392 "Warning: null async_struct for (%s) in %s\n";
395 printk(badinfo
, kdevname(device
), routine
);
398 if (info
->magic
!= SERIAL_MAGIC
) {
399 printk(badmagic
, kdevname(device
), routine
);
406 static inline unsigned int serial_in(struct async_struct
*info
, int offset
)
410 outb(info
->hub6
- 1 + offset
, info
->port
);
411 return inb(info
->port
+1);
414 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
415 if (info
->iomem_base
)
416 return readb(info
->iomem_base
+ (offset
<<info
->iomem_reg_shift
));
419 return inb(info
->port
+ offset
);
422 static inline unsigned int serial_inp(struct async_struct
*info
, int offset
)
426 outb(info
->hub6
- 1 + offset
, info
->port
);
427 return inb_p(info
->port
+1);
430 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
431 if (info
->iomem_base
)
432 return readb(info
->iomem_base
+ (offset
<<info
->iomem_reg_shift
));
435 #ifdef CONFIG_SERIAL_NOPAUSE_IO
436 return inb(info
->port
+ offset
);
438 return inb_p(info
->port
+ offset
);
442 static inline void serial_out(struct async_struct
*info
, int offset
, int value
)
446 outb(info
->hub6
- 1 + offset
, info
->port
);
447 outb(value
, info
->port
+1);
450 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
451 if (info
->iomem_base
)
452 writeb(value
, info
->iomem_base
+ (offset
<<info
->iomem_reg_shift
));
455 outb(value
, info
->port
+offset
);
458 static inline void serial_outp(struct async_struct
*info
, int offset
,
463 outb(info
->hub6
- 1 + offset
, info
->port
);
464 outb_p(value
, info
->port
+1);
467 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
468 if (info
->iomem_base
)
469 writeb(value
, info
->iomem_base
+ (offset
<<info
->iomem_reg_shift
));
472 #ifdef CONFIG_SERIAL_NOPAUSE_IO
473 outb(value
, info
->port
+offset
);
475 outb_p(value
, info
->port
+offset
);
482 void serial_icr_write(struct async_struct
*info
, int offset
, int value
)
484 serial_out(info
, UART_SCR
, offset
);
485 serial_out(info
, UART_ICR
, value
);
488 unsigned int serial_icr_read(struct async_struct
*info
, int offset
)
492 serial_icr_write(info
, UART_ACR
, info
->ACR
| UART_ACR_ICRRD
);
493 serial_out(info
, UART_SCR
, offset
);
494 value
= serial_in(info
, UART_ICR
);
495 serial_icr_write(info
, UART_ACR
, info
->ACR
);
500 * ------------------------------------------------------------
501 * rs_stop() and rs_start()
503 * This routines are called before setting or resetting tty->stopped.
504 * They enable or disable transmitter interrupts, as necessary.
505 * ------------------------------------------------------------
507 static void rs_stop(struct tty_struct
*tty
)
509 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
512 if (serial_paranoia_check(info
, tty
->device
, "rs_stop"))
515 save_flags(flags
); cli();
516 if (info
->IER
& UART_IER_THRI
) {
517 info
->IER
&= ~UART_IER_THRI
;
518 serial_out(info
, UART_IER
, info
->IER
);
520 if (info
->state
->type
== PORT_16C950
) {
521 info
->ACR
|= UART_ACR_TXDIS
;
522 serial_icr_write(info
, UART_ACR
, info
->ACR
);
524 restore_flags(flags
);
527 static void rs_start(struct tty_struct
*tty
)
529 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
532 if (serial_paranoia_check(info
, tty
->device
, "rs_start"))
535 save_flags(flags
); cli();
536 if (info
->xmit_cnt
&& info
->xmit_buf
&& !(info
->IER
& UART_IER_THRI
)) {
537 info
->IER
|= UART_IER_THRI
;
538 serial_out(info
, UART_IER
, info
->IER
);
540 if (info
->state
->type
== PORT_16C950
) {
541 info
->ACR
&= ~UART_ACR_TXDIS
;
542 serial_icr_write(info
, UART_ACR
, info
->ACR
);
544 restore_flags(flags
);
548 * ----------------------------------------------------------------------
550 * Here starts the interrupt handling routines. All of the following
551 * subroutines are declared as inline and are folded into
552 * rs_interrupt(). They were separated out for readability's sake.
554 * Note: rs_interrupt() is a "fast" interrupt, which means that it
555 * runs with interrupts turned off. People who may want to modify
556 * rs_interrupt() should try to keep the interrupt handler as fast as
557 * possible. After you are done making modifications, it is not a bad
560 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
562 * and look at the resulting assemble code in serial.s.
564 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
565 * -----------------------------------------------------------------------
569 * This routine is used by the interrupt handler to schedule
570 * processing in the software interrupt portion of the driver.
572 static _INLINE_
void rs_sched_event(struct async_struct
*info
,
575 info
->event
|= 1 << event
;
576 queue_task(&info
->tqueue
, &tq_serial
);
580 static _INLINE_
void receive_chars(struct async_struct
*info
,
583 struct tty_struct
*tty
= info
->tty
;
586 struct async_icount
*icount
;
588 icount
= &info
->state
->icount
;
590 ch
= serial_inp(info
, UART_RX
);
591 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
593 *tty
->flip
.char_buf_ptr
= ch
;
596 #ifdef SERIAL_DEBUG_INTR
597 printk("DR%02x:%02x...", ch
, *status
);
599 *tty
->flip
.flag_buf_ptr
= 0;
600 if (*status
& (UART_LSR_BI
| UART_LSR_PE
|
601 UART_LSR_FE
| UART_LSR_OE
)) {
603 * For statistics only
605 if (*status
& UART_LSR_BI
) {
606 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
608 } else if (*status
& UART_LSR_PE
)
610 else if (*status
& UART_LSR_FE
)
612 if (*status
& UART_LSR_OE
)
616 * Now check to see if character should be
617 * ignored, and mask off conditions which
620 if (*status
& info
->ignore_status_mask
) {
625 *status
&= info
->read_status_mask
;
627 if (*status
& (UART_LSR_BI
)) {
628 #ifdef SERIAL_DEBUG_INTR
629 printk("handling break....");
631 *tty
->flip
.flag_buf_ptr
= TTY_BREAK
;
632 if (info
->flags
& ASYNC_SAK
)
634 } else if (*status
& UART_LSR_PE
)
635 *tty
->flip
.flag_buf_ptr
= TTY_PARITY
;
636 else if (*status
& UART_LSR_FE
)
637 *tty
->flip
.flag_buf_ptr
= TTY_FRAME
;
638 if (*status
& UART_LSR_OE
) {
640 * Overrun is special, since it's
641 * reported immediately, and doesn't
642 * affect the current character
644 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
646 tty
->flip
.flag_buf_ptr
++;
647 tty
->flip
.char_buf_ptr
++;
648 *tty
->flip
.flag_buf_ptr
= TTY_OVERRUN
;
652 tty
->flip
.flag_buf_ptr
++;
653 tty
->flip
.char_buf_ptr
++;
656 *status
= serial_inp(info
, UART_LSR
);
657 } while (*status
& UART_LSR_DR
);
658 #if (LINUX_VERSION_CODE > 131394) /* 2.1.66 */
659 tty_flip_buffer_push(tty
);
661 queue_task_irq_off(&tty
->flip
.tqueue
, &tq_timer
);
665 static _INLINE_
void transmit_chars(struct async_struct
*info
, int *intr_done
)
670 serial_outp(info
, UART_TX
, info
->x_char
);
671 info
->state
->icount
.tx
++;
677 if ((info
->xmit_cnt
<= 0) || info
->tty
->stopped
||
678 info
->tty
->hw_stopped
) {
679 info
->IER
&= ~UART_IER_THRI
;
680 serial_out(info
, UART_IER
, info
->IER
);
684 count
= info
->xmit_fifo_size
;
686 serial_out(info
, UART_TX
, info
->xmit_buf
[info
->xmit_tail
++]);
687 info
->xmit_tail
= info
->xmit_tail
& (SERIAL_XMIT_SIZE
-1);
688 info
->state
->icount
.tx
++;
689 if (--info
->xmit_cnt
<= 0)
691 } while (--count
> 0);
693 if (info
->xmit_cnt
< WAKEUP_CHARS
)
694 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
696 #ifdef SERIAL_DEBUG_INTR
702 if (info
->xmit_cnt
<= 0) {
703 info
->IER
&= ~UART_IER_THRI
;
704 serial_out(info
, UART_IER
, info
->IER
);
708 static _INLINE_
void check_modem_status(struct async_struct
*info
)
711 struct async_icount
*icount
;
713 status
= serial_in(info
, UART_MSR
);
715 if (status
& UART_MSR_ANY_DELTA
) {
716 icount
= &info
->state
->icount
;
717 /* update input line counters */
718 if (status
& UART_MSR_TERI
)
720 if (status
& UART_MSR_DDSR
)
722 if (status
& UART_MSR_DDCD
) {
724 #ifdef CONFIG_HARD_PPS
725 if ((info
->flags
& ASYNC_HARDPPS_CD
) &&
726 (status
& UART_MSR_DCD
))
730 if (status
& UART_MSR_DCTS
)
732 wake_up_interruptible(&info
->delta_msr_wait
);
735 if ((info
->flags
& ASYNC_CHECK_CD
) && (status
& UART_MSR_DDCD
)) {
736 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
737 printk("ttys%d CD now %s...", info
->line
,
738 (status
& UART_MSR_DCD
) ? "on" : "off");
740 if (status
& UART_MSR_DCD
)
741 wake_up_interruptible(&info
->open_wait
);
742 else if (!((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
743 (info
->flags
& ASYNC_CALLOUT_NOHUP
))) {
744 #ifdef SERIAL_DEBUG_OPEN
745 printk("doing serial hangup...");
748 tty_hangup(info
->tty
);
751 if (info
->flags
& ASYNC_CTS_FLOW
) {
752 if (info
->tty
->hw_stopped
) {
753 if (status
& UART_MSR_CTS
) {
754 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
755 printk("CTS tx start...");
757 info
->tty
->hw_stopped
= 0;
758 info
->IER
|= UART_IER_THRI
;
759 serial_out(info
, UART_IER
, info
->IER
);
760 rs_sched_event(info
, RS_EVENT_WRITE_WAKEUP
);
764 if (!(status
& UART_MSR_CTS
)) {
765 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
766 printk("CTS tx stop...");
768 info
->tty
->hw_stopped
= 1;
769 info
->IER
&= ~UART_IER_THRI
;
770 serial_out(info
, UART_IER
, info
->IER
);
776 #ifdef CONFIG_SERIAL_SHARE_IRQ
778 * This is the serial driver's generic interrupt routine
780 static void rs_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
783 struct async_struct
* info
;
784 int pass_counter
= 0;
785 struct async_struct
*end_mark
= 0;
786 #ifdef CONFIG_SERIAL_MULTIPORT
788 struct rs_multiport_struct
*multi
;
791 #ifdef SERIAL_DEBUG_INTR
792 printk("rs_interrupt(%d)...", irq
);
795 info
= IRQ_ports
[irq
];
799 #ifdef CONFIG_SERIAL_MULTIPORT
800 multi
= &rs_multiport
[irq
];
801 if (multi
->port_monitor
)
802 first_multi
= inb(multi
->port_monitor
);
807 (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
)) {
814 info
->last_active
= jiffies
;
816 status
= serial_inp(info
, UART_LSR
);
817 #ifdef SERIAL_DEBUG_INTR
818 printk("status = %x...", status
);
820 if (status
& UART_LSR_DR
)
821 receive_chars(info
, &status
);
822 check_modem_status(info
);
823 if (status
& UART_LSR_THRE
)
824 transmit_chars(info
, 0);
827 info
= info
->next_port
;
829 info
= IRQ_ports
[irq
];
830 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
832 printk("rs loop break\n");
834 break; /* Prevent infinite loops */
838 } while (end_mark
!= info
);
839 #ifdef CONFIG_SERIAL_MULTIPORT
840 if (multi
->port_monitor
)
841 printk("rs port monitor (normal) irq %d: 0x%x, 0x%x\n",
842 info
->state
->irq
, first_multi
,
843 inb(multi
->port_monitor
));
845 #ifdef SERIAL_DEBUG_INTR
849 #endif /* #ifdef CONFIG_SERIAL_SHARE_IRQ */
853 * This is the serial driver's interrupt routine for a single port
855 static void rs_interrupt_single(int irq
, void *dev_id
, struct pt_regs
* regs
)
858 int pass_counter
= 0;
859 struct async_struct
* info
;
860 #ifdef CONFIG_SERIAL_MULTIPORT
862 struct rs_multiport_struct
*multi
;
865 #ifdef SERIAL_DEBUG_INTR
866 printk("rs_interrupt_single(%d)...", irq
);
869 info
= IRQ_ports
[irq
];
870 if (!info
|| !info
->tty
)
873 #ifdef CONFIG_SERIAL_MULTIPORT
874 multi
= &rs_multiport
[irq
];
875 if (multi
->port_monitor
)
876 first_multi
= inb(multi
->port_monitor
);
880 status
= serial_inp(info
, UART_LSR
);
881 #ifdef SERIAL_DEBUG_INTR
882 printk("status = %x...", status
);
884 if (status
& UART_LSR_DR
)
885 receive_chars(info
, &status
);
886 check_modem_status(info
);
887 if (status
& UART_LSR_THRE
)
888 transmit_chars(info
, 0);
889 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
891 printk("rs_single loop break.\n");
895 } while (!(serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
));
896 info
->last_active
= jiffies
;
897 #ifdef CONFIG_SERIAL_MULTIPORT
898 if (multi
->port_monitor
)
899 printk("rs port monitor (single) irq %d: 0x%x, 0x%x\n",
900 info
->state
->irq
, first_multi
,
901 inb(multi
->port_monitor
));
903 #ifdef SERIAL_DEBUG_INTR
908 #ifdef CONFIG_SERIAL_MULTIPORT
910 * This is the serial driver's for multiport boards
912 static void rs_interrupt_multi(int irq
, void *dev_id
, struct pt_regs
* regs
)
915 struct async_struct
* info
;
916 int pass_counter
= 0;
918 struct rs_multiport_struct
*multi
;
920 #ifdef SERIAL_DEBUG_INTR
921 printk("rs_interrupt_multi(%d)...", irq
);
924 info
= IRQ_ports
[irq
];
927 multi
= &rs_multiport
[irq
];
929 /* Should never happen */
930 printk("rs_interrupt_multi: NULL port1!\n");
933 if (multi
->port_monitor
)
934 first_multi
= inb(multi
->port_monitor
);
938 (serial_in(info
, UART_IIR
) & UART_IIR_NO_INT
))
941 info
->last_active
= jiffies
;
943 status
= serial_inp(info
, UART_LSR
);
944 #ifdef SERIAL_DEBUG_INTR
945 printk("status = %x...", status
);
947 if (status
& UART_LSR_DR
)
948 receive_chars(info
, &status
);
949 check_modem_status(info
);
950 if (status
& UART_LSR_THRE
)
951 transmit_chars(info
, 0);
954 info
= info
->next_port
;
958 info
= IRQ_ports
[irq
];
959 if (pass_counter
++ > RS_ISR_PASS_LIMIT
) {
961 printk("rs_multi loop break\n");
963 break; /* Prevent infinite loops */
965 if (multi
->port_monitor
)
966 printk("rs port monitor irq %d: 0x%x, 0x%x\n",
967 info
->state
->irq
, first_multi
,
968 inb(multi
->port_monitor
));
969 if ((inb(multi
->port1
) & multi
->mask1
) != multi
->match1
)
973 if ((inb(multi
->port2
) & multi
->mask2
) != multi
->match2
)
977 if ((inb(multi
->port3
) & multi
->mask3
) != multi
->match3
)
981 if ((inb(multi
->port4
) & multi
->mask4
) != multi
->match4
)
985 #ifdef SERIAL_DEBUG_INTR
992 * -------------------------------------------------------------------
993 * Here ends the serial interrupt routines.
994 * -------------------------------------------------------------------
998 * This routine is used to handle the "bottom half" processing for the
999 * serial driver, known also the "software interrupt" processing.
1000 * This processing is done at the kernel interrupt level, after the
1001 * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
1002 * is where time-consuming activities which can not be done in the
1003 * interrupt driver proper are done; the interrupt driver schedules
1004 * them using rs_sched_event(), and they get done here.
1006 static void do_serial_bh(void)
1008 run_task_queue(&tq_serial
);
1011 static void do_softint(void *private_
)
1013 struct async_struct
*info
= (struct async_struct
*) private_
;
1014 struct tty_struct
*tty
;
1020 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP
, &info
->event
)) {
1021 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1022 tty
->ldisc
.write_wakeup
)
1023 (tty
->ldisc
.write_wakeup
)(tty
);
1024 wake_up_interruptible(&tty
->write_wait
);
1029 * This subroutine is called when the RS_TIMER goes off. It is used
1030 * by the serial driver to handle ports that do not have an interrupt
1031 * (irq=0). This doesn't work very well for 16450's, but gives barely
1032 * passable results for a 16550A. (Although at the expense of much
1035 static void rs_timer(void)
1037 static unsigned long last_strobe
= 0;
1038 struct async_struct
*info
;
1040 unsigned long flags
;
1042 if ((jiffies
- last_strobe
) >= RS_STROBE_TIME
) {
1043 for (i
=1; i
< NR_IRQS
; i
++) {
1044 info
= IRQ_ports
[i
];
1047 save_flags(flags
); cli();
1048 #ifdef CONFIG_SERIAL_SHARE_IRQ
1049 if (info
->next_port
) {
1051 serial_out(info
, UART_IER
, 0);
1052 info
->IER
|= UART_IER_THRI
;
1053 serial_out(info
, UART_IER
, info
->IER
);
1054 info
= info
->next_port
;
1056 #ifdef CONFIG_SERIAL_MULTIPORT
1057 if (rs_multiport
[i
].port1
)
1058 rs_interrupt_multi(i
, NULL
, NULL
);
1061 rs_interrupt(i
, NULL
, NULL
);
1063 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1064 rs_interrupt_single(i
, NULL
, NULL
);
1065 restore_flags(flags
);
1068 last_strobe
= jiffies
;
1069 timer_table
[RS_TIMER
].expires
= jiffies
+ RS_STROBE_TIME
;
1070 timer_active
|= 1 << RS_TIMER
;
1073 save_flags(flags
); cli();
1074 #ifdef CONFIG_SERIAL_SHARE_IRQ
1075 rs_interrupt(0, NULL
, NULL
);
1077 rs_interrupt_single(0, NULL
, NULL
);
1079 restore_flags(flags
);
1081 timer_table
[RS_TIMER
].expires
= jiffies
+ IRQ_timeout
[0] - 2;
1086 * ---------------------------------------------------------------
1087 * Low level utility subroutines for the serial driver: routines to
1088 * figure out the appropriate timeout for an interrupt chain, routines
1089 * to initialize and startup a serial port, and routines to shutdown a
1090 * serial port. Useful stuff like that.
1091 * ---------------------------------------------------------------
1095 * This routine figures out the correct timeout for a particular IRQ.
1096 * It uses the smallest timeout of all of the serial ports in a
1097 * particular interrupt chain. Now only used for IRQ 0....
1099 static void figure_IRQ_timeout(int irq
)
1101 struct async_struct
*info
;
1102 int timeout
= 60*HZ
; /* 60 seconds === a long time :-) */
1104 info
= IRQ_ports
[irq
];
1106 IRQ_timeout
[irq
] = 60*HZ
;
1110 if (info
->timeout
< timeout
)
1111 timeout
= info
->timeout
;
1112 info
= info
->next_port
;
1115 timeout
= timeout
/ 2;
1116 IRQ_timeout
[irq
] = timeout
? timeout
: 1;
1119 static int startup(struct async_struct
* info
)
1121 unsigned long flags
;
1123 void (*handler
)(int, void *, struct pt_regs
*);
1124 struct serial_state
*state
= info
->state
;
1126 #ifdef CONFIG_SERIAL_MANY_PORTS
1130 page
= get_free_page(GFP_KERNEL
);
1134 save_flags(flags
); cli();
1136 if (info
->flags
& ASYNC_INITIALIZED
) {
1141 if (!CONFIGURED_SERIAL_PORT(state
) || !state
->type
) {
1143 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1150 info
->xmit_buf
= (unsigned char *) page
;
1152 #ifdef SERIAL_DEBUG_OPEN
1153 printk("starting up ttys%d (irq %d)...", info
->line
, state
->irq
);
1156 if (uart_config
[info
->state
->type
].flags
& UART_STARTECH
) {
1158 serial_outp(info
, UART_LCR
, 0xBF);
1159 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1161 * Turn off LCR == 0xBF so we actually set the IER
1162 * register on the XR16C850
1164 serial_outp(info
, UART_LCR
, 0);
1165 serial_outp(info
, UART_IER
, 0);
1167 * Now reset LCR so we can turn off the ECB bit
1169 serial_outp(info
, UART_LCR
, 0xBF);
1170 serial_outp(info
, UART_EFR
, 0);
1172 * For a XR16C850, we need to set the trigger levels
1174 if (info
->state
->type
== PORT_16850
) {
1175 serial_outp(info
, UART_FCTR
, UART_FCTR_TRGD
|
1177 serial_outp(info
, UART_TRG
, UART_TRG_96
);
1178 serial_outp(info
, UART_FCTR
, UART_FCTR_TRGD
|
1180 serial_outp(info
, UART_TRG
, UART_TRG_96
);
1182 serial_outp(info
, UART_LCR
, 0);
1185 if (info
->state
->type
== PORT_16750
) {
1187 serial_outp(info
, UART_IER
, 0);
1190 if (info
->state
->type
== PORT_16C950
) {
1191 /* Wake up and initialize UART */
1193 serial_outp(info
, UART_LCR
, 0xBF);
1194 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1195 serial_outp(info
, UART_IER
, 0);
1196 serial_outp(info
, UART_LCR
, 0);
1197 serial_icr_write(info
, UART_CSR
, 0); /* Reset the UART */
1198 serial_outp(info
, UART_LCR
, 0xBF);
1199 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1200 serial_outp(info
, UART_LCR
, 0);
1204 * Clear the FIFO buffers and disable them
1205 * (they will be reenabled in change_speed())
1207 if (uart_config
[state
->type
].flags
& UART_CLEAR_FIFO
) {
1208 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1209 serial_outp(info
, UART_FCR
, (UART_FCR_ENABLE_FIFO
|
1210 UART_FCR_CLEAR_RCVR
|
1211 UART_FCR_CLEAR_XMIT
));
1212 serial_outp(info
, UART_FCR
, 0);
1216 * Clear the interrupt registers.
1218 (void) serial_inp(info
, UART_LSR
);
1219 (void) serial_inp(info
, UART_RX
);
1220 (void) serial_inp(info
, UART_IIR
);
1221 (void) serial_inp(info
, UART_MSR
);
1224 * At this point there's no way the LSR could still be 0xFF;
1225 * if it is, then bail out, because there's likely no UART
1228 if (serial_inp(info
, UART_LSR
) == 0xff) {
1229 printk("LSR safety check engaged!\n");
1230 if (serial_isroot()) {
1232 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1239 * Allocate the IRQ if necessary
1241 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
1242 !IRQ_ports
[state
->irq
]->next_port
)) {
1243 if (IRQ_ports
[state
->irq
]) {
1244 #ifdef CONFIG_SERIAL_SHARE_IRQ
1245 free_irq(state
->irq
, NULL
);
1246 #ifdef CONFIG_SERIAL_MULTIPORT
1247 if (rs_multiport
[state
->irq
].port1
)
1248 handler
= rs_interrupt_multi
;
1251 handler
= rs_interrupt
;
1255 #endif /* CONFIG_SERIAL_SHARE_IRQ */
1257 handler
= rs_interrupt_single
;
1259 retval
= request_irq(state
->irq
, handler
, IRQ_T(state
),
1262 if (serial_isroot()) {
1264 set_bit(TTY_IO_ERROR
,
1273 * Insert serial port into IRQ chain.
1275 info
->prev_port
= 0;
1276 info
->next_port
= IRQ_ports
[state
->irq
];
1277 if (info
->next_port
)
1278 info
->next_port
->prev_port
= info
;
1279 IRQ_ports
[state
->irq
] = info
;
1280 figure_IRQ_timeout(state
->irq
);
1283 * Now, initialize the UART
1285 serial_outp(info
, UART_LCR
, UART_LCR_WLEN8
); /* reset DLAB */
1288 if (info
->tty
->termios
->c_cflag
& CBAUD
)
1289 info
->MCR
= UART_MCR_DTR
| UART_MCR_RTS
;
1290 #ifdef CONFIG_SERIAL_MANY_PORTS
1291 if (info
->flags
& ASYNC_FOURPORT
) {
1292 if (state
->irq
== 0)
1293 info
->MCR
|= UART_MCR_OUT1
;
1297 if (state
->irq
!= 0)
1298 info
->MCR
|= UART_MCR_OUT2
;
1300 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
1301 serial_outp(info
, UART_MCR
, info
->MCR
);
1304 * Finally, enable interrupts
1306 info
->IER
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
1307 serial_outp(info
, UART_IER
, info
->IER
); /* enable interrupts */
1309 #ifdef CONFIG_SERIAL_MANY_PORTS
1310 if (info
->flags
& ASYNC_FOURPORT
) {
1311 /* Enable interrupts on the AST Fourport board */
1312 ICP
= (info
->port
& 0xFE0) | 0x01F;
1319 * And clear the interrupt registers again for luck.
1321 (void)serial_inp(info
, UART_LSR
);
1322 (void)serial_inp(info
, UART_RX
);
1323 (void)serial_inp(info
, UART_IIR
);
1324 (void)serial_inp(info
, UART_MSR
);
1327 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1328 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1331 * Set up serial timers...
1333 timer_table
[RS_TIMER
].expires
= jiffies
+ 2*HZ
/100;
1334 timer_active
|= 1 << RS_TIMER
;
1337 * Set up the tty->alt_speed kludge
1339 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
1341 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1342 info
->tty
->alt_speed
= 57600;
1343 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1344 info
->tty
->alt_speed
= 115200;
1345 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
1346 info
->tty
->alt_speed
= 230400;
1347 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
1348 info
->tty
->alt_speed
= 460800;
1353 * and set the speed of the serial port
1355 change_speed(info
, 0);
1357 info
->flags
|= ASYNC_INITIALIZED
;
1358 restore_flags(flags
);
1362 restore_flags(flags
);
1367 * This routine will shutdown a serial port; interrupts are disabled, and
1368 * DTR is dropped if the hangup on close termio flag is on.
1370 static void shutdown(struct async_struct
* info
)
1372 unsigned long flags
;
1373 struct serial_state
*state
;
1376 if (!(info
->flags
& ASYNC_INITIALIZED
))
1379 state
= info
->state
;
1381 #ifdef SERIAL_DEBUG_OPEN
1382 printk("Shutting down serial port %d (irq %d)....", info
->line
,
1386 save_flags(flags
); cli(); /* Disable interrupts */
1389 * clear delta_msr_wait queue to avoid mem leaks: we may free the irq
1390 * here so the queue might never be waken up
1392 wake_up_interruptible(&info
->delta_msr_wait
);
1395 * First unlink the serial port from the IRQ chain...
1397 if (info
->next_port
)
1398 info
->next_port
->prev_port
= info
->prev_port
;
1399 if (info
->prev_port
)
1400 info
->prev_port
->next_port
= info
->next_port
;
1402 IRQ_ports
[state
->irq
] = info
->next_port
;
1403 figure_IRQ_timeout(state
->irq
);
1406 * Free the IRQ, if necessary
1408 if (state
->irq
&& (!IRQ_ports
[state
->irq
] ||
1409 !IRQ_ports
[state
->irq
]->next_port
)) {
1410 if (IRQ_ports
[state
->irq
]) {
1411 free_irq(state
->irq
, NULL
);
1412 retval
= request_irq(state
->irq
, rs_interrupt_single
,
1413 IRQ_T(state
), "serial", NULL
);
1416 printk("serial shutdown: request_irq: error %d"
1417 " Couldn't reacquire IRQ.\n", retval
);
1419 free_irq(state
->irq
, NULL
);
1422 if (info
->xmit_buf
) {
1423 free_page((unsigned long) info
->xmit_buf
);
1428 serial_outp(info
, UART_IER
, 0x00); /* disable all intrs */
1429 #ifdef CONFIG_SERIAL_MANY_PORTS
1430 if (info
->flags
& ASYNC_FOURPORT
) {
1431 /* reset interrupts on the AST Fourport board */
1432 (void) inb((info
->port
& 0xFE0) | 0x01F);
1433 info
->MCR
|= UART_MCR_OUT1
;
1436 info
->MCR
&= ~UART_MCR_OUT2
;
1437 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
1439 /* disable break condition */
1440 serial_out(info
, UART_LCR
, serial_inp(info
, UART_LCR
) & ~UART_LCR_SBC
);
1442 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
))
1443 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
1444 serial_outp(info
, UART_MCR
, info
->MCR
);
1446 /* disable FIFO's */
1447 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
1448 UART_FCR_CLEAR_XMIT
));
1449 (void)serial_in(info
, UART_RX
); /* read data port to reset things */
1452 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1454 if (uart_config
[info
->state
->type
].flags
& UART_STARTECH
) {
1455 /* Arrange to enter sleep mode */
1456 serial_outp(info
, UART_LCR
, 0xBF);
1457 serial_outp(info
, UART_EFR
, UART_EFR_ECB
);
1458 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
1459 serial_outp(info
, UART_LCR
, 0);
1461 if (info
->state
->type
== PORT_16750
) {
1462 /* Arrange to enter sleep mode */
1463 serial_outp(info
, UART_IER
, UART_IERX_SLEEP
);
1465 info
->flags
&= ~ASYNC_INITIALIZED
;
1466 restore_flags(flags
);
1469 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
1470 static int baud_table
[] = {
1471 0, 50, 75, 110, 134, 150, 200, 300,
1472 600, 1200, 1800, 2400, 4800, 9600, 19200,
1473 38400, 57600, 115200, 230400, 460800, 0 };
1475 static int tty_get_baud_rate(struct tty_struct
*tty
)
1477 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
1478 unsigned int cflag
, i
;
1480 cflag
= tty
->termios
->c_cflag
;
1486 tty
->termios
->c_cflag
&= ~CBAUDEX
;
1491 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
1493 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
1496 return baud_table
[i
];
1501 * This routine is called to set the UART divisor registers to match
1502 * the specified baud rate for a serial port.
1504 static void change_speed(struct async_struct
*info
,
1505 struct termios
*old_termios
)
1507 int quot
= 0, baud_base
, baud
;
1508 unsigned cflag
, cval
, fcr
= 0;
1510 unsigned long flags
;
1512 if (!info
->tty
|| !info
->tty
->termios
)
1514 cflag
= info
->tty
->termios
->c_cflag
;
1515 if (!CONFIGURED_SERIAL_PORT(info
))
1518 /* byte size and parity */
1519 switch (cflag
& CSIZE
) {
1520 case CS5
: cval
= 0x00; bits
= 7; break;
1521 case CS6
: cval
= 0x01; bits
= 8; break;
1522 case CS7
: cval
= 0x02; bits
= 9; break;
1523 case CS8
: cval
= 0x03; bits
= 10; break;
1524 /* Never happens, but GCC is too dumb to figure it out */
1525 default: cval
= 0x00; bits
= 7; break;
1527 if (cflag
& CSTOPB
) {
1531 if (cflag
& PARENB
) {
1532 cval
|= UART_LCR_PARITY
;
1535 if (!(cflag
& PARODD
))
1536 cval
|= UART_LCR_EPAR
;
1539 cval
|= UART_LCR_SPAR
;
1542 /* Determine divisor based on baud rate */
1543 baud
= tty_get_baud_rate(info
->tty
);
1545 baud
= 9600; /* B0 transition handled in rs_set_termios */
1546 baud_base
= info
->state
->baud_base
;
1547 if (info
->state
->type
== PORT_16C950
) {
1548 if (baud
<= baud_base
)
1549 serial_icr_write(info
, UART_TCR
, 0);
1550 else if (baud
<= 2*baud_base
) {
1551 serial_icr_write(info
, UART_TCR
, 0x8);
1552 baud_base
= baud_base
* 2;
1553 } else if (baud
<= 4*baud_base
) {
1554 serial_icr_write(info
, UART_TCR
, 0x4);
1555 baud_base
= baud_base
* 4;
1557 serial_icr_write(info
, UART_TCR
, 0);
1559 if (baud
== 38400 &&
1560 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1561 quot
= info
->state
->custom_divisor
;
1564 /* Special case since 134 is really 134.5 */
1565 quot
= (2*baud_base
/ 269);
1567 quot
= baud_base
/ baud
;
1569 /* If the quotient is zero refuse the change */
1570 if (!quot
&& old_termios
) {
1571 info
->tty
->termios
->c_cflag
&= ~CBAUD
;
1572 info
->tty
->termios
->c_cflag
|= (old_termios
->c_cflag
& CBAUD
);
1573 baud
= tty_get_baud_rate(info
->tty
);
1576 if (baud
== 38400 &&
1577 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
))
1578 quot
= info
->state
->custom_divisor
;
1581 /* Special case since 134 is really 134.5 */
1582 quot
= (2*baud_base
/ 269);
1584 quot
= baud_base
/ baud
;
1587 /* As a last resort, if the quotient is zero, default to 9600 bps */
1589 quot
= baud_base
/ 9600;
1591 info
->timeout
= ((info
->xmit_fifo_size
*HZ
*bits
*quot
) / baud_base
);
1592 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
1595 if (uart_config
[info
->state
->type
].flags
& UART_USE_FIFO
) {
1596 if ((info
->state
->baud_base
/ quot
) < 2400)
1597 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
1599 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_8
;
1601 if (info
->state
->type
== PORT_16750
)
1602 fcr
|= UART_FCR7_64BYTE
;
1604 /* CTS flow control flag and modem status interrupts */
1605 info
->IER
&= ~UART_IER_MSI
;
1606 if (info
->flags
& ASYNC_HARDPPS_CD
)
1607 info
->IER
|= UART_IER_MSI
;
1608 if (cflag
& CRTSCTS
) {
1609 info
->flags
|= ASYNC_CTS_FLOW
;
1610 info
->IER
|= UART_IER_MSI
;
1612 info
->flags
&= ~ASYNC_CTS_FLOW
;
1614 info
->flags
&= ~ASYNC_CHECK_CD
;
1616 info
->flags
|= ASYNC_CHECK_CD
;
1617 info
->IER
|= UART_IER_MSI
;
1619 serial_out(info
, UART_IER
, info
->IER
);
1622 * Set up parity check flag
1624 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
1626 info
->read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
1627 if (I_INPCK(info
->tty
))
1628 info
->read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
1629 if (I_BRKINT(info
->tty
) || I_PARMRK(info
->tty
))
1630 info
->read_status_mask
|= UART_LSR_BI
;
1633 * Characters to ignore
1635 info
->ignore_status_mask
= 0;
1636 if (I_IGNPAR(info
->tty
))
1637 info
->ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
1638 if (I_IGNBRK(info
->tty
)) {
1639 info
->ignore_status_mask
|= UART_LSR_BI
;
1641 * If we're ignore parity and break indicators, ignore
1642 * overruns too. (For real raw support).
1644 if (I_IGNPAR(info
->tty
))
1645 info
->ignore_status_mask
|= UART_LSR_OE
;
1648 * !!! ignore all characters if CREAD is not set
1650 if ((cflag
& CREAD
) == 0)
1651 info
->ignore_status_mask
|= UART_LSR_DR
;
1652 save_flags(flags
); cli();
1653 if (uart_config
[info
->state
->type
].flags
& UART_STARTECH
) {
1654 serial_outp(info
, UART_LCR
, 0xBF);
1655 serial_outp(info
, UART_EFR
,
1656 (cflag
& CRTSCTS
) ? UART_EFR_CTS
: 0);
1658 serial_outp(info
, UART_LCR
, cval
| UART_LCR_DLAB
); /* set DLAB */
1659 serial_outp(info
, UART_DLL
, quot
& 0xff); /* LS of divisor */
1660 serial_outp(info
, UART_DLM
, quot
>> 8); /* MS of divisor */
1661 if (info
->state
->type
== PORT_16750
)
1662 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1663 serial_outp(info
, UART_LCR
, cval
); /* reset DLAB */
1664 info
->LCR
= cval
; /* Save LCR */
1665 if (info
->state
->type
!= PORT_16750
)
1666 serial_outp(info
, UART_FCR
, fcr
); /* set fcr */
1667 restore_flags(flags
);
1670 static void rs_put_char(struct tty_struct
*tty
, unsigned char ch
)
1672 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1673 unsigned long flags
;
1675 if (serial_paranoia_check(info
, tty
->device
, "rs_put_char"))
1678 if (!tty
|| !info
->xmit_buf
)
1681 save_flags(flags
); cli();
1682 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
1683 restore_flags(flags
);
1687 info
->xmit_buf
[info
->xmit_head
++] = ch
;
1688 info
->xmit_head
&= SERIAL_XMIT_SIZE
-1;
1690 restore_flags(flags
);
1693 static void rs_flush_chars(struct tty_struct
*tty
)
1695 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1696 unsigned long flags
;
1698 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_chars"))
1701 if (info
->xmit_cnt
<= 0 || tty
->stopped
|| tty
->hw_stopped
||
1705 save_flags(flags
); cli();
1706 info
->IER
|= UART_IER_THRI
;
1707 serial_out(info
, UART_IER
, info
->IER
);
1708 restore_flags(flags
);
1711 static int rs_write(struct tty_struct
* tty
, int from_user
,
1712 const unsigned char *buf
, int count
)
1715 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1716 unsigned long flags
;
1718 if (serial_paranoia_check(info
, tty
->device
, "rs_write"))
1721 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
)
1729 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1730 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1734 c
-= copy_from_user(tmp_buf
, buf
, c
);
1741 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1742 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1743 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
1744 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1745 (SERIAL_XMIT_SIZE
-1));
1746 info
->xmit_cnt
+= c
;
1747 restore_flags(flags
);
1757 MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
1758 SERIAL_XMIT_SIZE
- info
->xmit_head
));
1760 restore_flags(flags
);
1763 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
1764 info
->xmit_head
= ((info
->xmit_head
+ c
) &
1765 (SERIAL_XMIT_SIZE
-1));
1766 info
->xmit_cnt
+= c
;
1767 restore_flags(flags
);
1773 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
&&
1774 !(info
->IER
& UART_IER_THRI
)) {
1775 info
->IER
|= UART_IER_THRI
;
1776 serial_out(info
, UART_IER
, info
->IER
);
1781 static int rs_write_room(struct tty_struct
*tty
)
1783 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1786 if (serial_paranoia_check(info
, tty
->device
, "rs_write_room"))
1788 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
1794 static int rs_chars_in_buffer(struct tty_struct
*tty
)
1796 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1798 if (serial_paranoia_check(info
, tty
->device
, "rs_chars_in_buffer"))
1800 return info
->xmit_cnt
;
1803 static void rs_flush_buffer(struct tty_struct
*tty
)
1805 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1806 unsigned long flags
;
1808 if (serial_paranoia_check(info
, tty
->device
, "rs_flush_buffer"))
1810 save_flags(flags
); cli();
1811 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1812 restore_flags(flags
);
1813 wake_up_interruptible(&tty
->write_wait
);
1814 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1815 tty
->ldisc
.write_wakeup
)
1816 (tty
->ldisc
.write_wakeup
)(tty
);
1820 * This function is used to send a high-priority XON/XOFF character to
1823 static void rs_send_xchar(struct tty_struct
*tty
, char ch
)
1825 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1827 if (serial_paranoia_check(info
, tty
->device
, "rs_send_char"))
1832 /* Make sure transmit interrupts are on */
1833 info
->IER
|= UART_IER_THRI
;
1834 serial_out(info
, UART_IER
, info
->IER
);
1839 * ------------------------------------------------------------
1842 * This routine is called by the upper-layer tty layer to signal that
1843 * incoming characters should be throttled.
1844 * ------------------------------------------------------------
1846 static void rs_throttle(struct tty_struct
* tty
)
1848 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1849 unsigned long flags
;
1850 #ifdef SERIAL_DEBUG_THROTTLE
1853 printk("throttle %s: %d....\n", tty_name(tty
, buf
),
1854 tty
->ldisc
.chars_in_buffer(tty
));
1857 if (serial_paranoia_check(info
, tty
->device
, "rs_throttle"))
1861 rs_send_xchar(tty
, STOP_CHAR(tty
));
1863 if (tty
->termios
->c_cflag
& CRTSCTS
)
1864 info
->MCR
&= ~UART_MCR_RTS
;
1866 save_flags(flags
); cli();
1867 serial_out(info
, UART_MCR
, info
->MCR
);
1868 restore_flags(flags
);
1871 static void rs_unthrottle(struct tty_struct
* tty
)
1873 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
1874 unsigned long flags
;
1875 #ifdef SERIAL_DEBUG_THROTTLE
1878 printk("unthrottle %s: %d....\n", tty_name(tty
, buf
),
1879 tty
->ldisc
.chars_in_buffer(tty
));
1882 if (serial_paranoia_check(info
, tty
->device
, "rs_unthrottle"))
1889 rs_send_xchar(tty
, START_CHAR(tty
));
1891 if (tty
->termios
->c_cflag
& CRTSCTS
)
1892 info
->MCR
|= UART_MCR_RTS
;
1893 save_flags(flags
); cli();
1894 serial_out(info
, UART_MCR
, info
->MCR
);
1895 restore_flags(flags
);
1899 * ------------------------------------------------------------
1900 * rs_ioctl() and friends
1901 * ------------------------------------------------------------
1904 static int get_serial_info(struct async_struct
* info
,
1905 struct serial_struct
* retinfo
)
1907 struct serial_struct tmp
;
1908 struct serial_state
*state
= info
->state
;
1912 memset(&tmp
, 0, sizeof(tmp
));
1913 tmp
.type
= state
->type
;
1914 tmp
.line
= state
->line
;
1915 tmp
.port
= state
->port
;
1916 tmp
.irq
= state
->irq
;
1917 tmp
.flags
= state
->flags
;
1918 tmp
.xmit_fifo_size
= state
->xmit_fifo_size
;
1919 tmp
.baud_base
= state
->baud_base
;
1920 tmp
.close_delay
= state
->close_delay
;
1921 tmp
.closing_wait
= state
->closing_wait
;
1922 tmp
.custom_divisor
= state
->custom_divisor
;
1923 tmp
.hub6
= state
->hub6
;
1924 if (copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
)))
1929 static int set_serial_info(struct async_struct
* info
,
1930 struct serial_struct
* new_info
)
1932 struct serial_struct new_serial
;
1933 struct serial_state old_state
, *state
;
1934 unsigned int i
,change_irq
,change_port
;
1937 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
1939 state
= info
->state
;
1942 change_irq
= new_serial
.irq
!= state
->irq
;
1943 change_port
= (new_serial
.port
!= state
->port
) ||
1944 (new_serial
.hub6
!= state
->hub6
);
1946 if (!serial_isroot()) {
1947 if (change_irq
|| change_port
||
1948 (new_serial
.baud_base
!= state
->baud_base
) ||
1949 (new_serial
.type
!= state
->type
) ||
1950 (new_serial
.close_delay
!= state
->close_delay
) ||
1951 (new_serial
.xmit_fifo_size
!= state
->xmit_fifo_size
) ||
1952 ((new_serial
.flags
& ~ASYNC_USR_MASK
) !=
1953 (state
->flags
& ~ASYNC_USR_MASK
)))
1955 state
->flags
= ((state
->flags
& ~ASYNC_USR_MASK
) |
1956 (new_serial
.flags
& ASYNC_USR_MASK
));
1957 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
1958 (new_serial
.flags
& ASYNC_USR_MASK
));
1959 state
->custom_divisor
= new_serial
.custom_divisor
;
1960 goto check_and_exit
;
1963 new_serial
.irq
= irq_cannonicalize(new_serial
.irq
);
1965 if ((new_serial
.irq
>= NR_IRQS
) || (new_serial
.port
> 0xffff) ||
1966 (new_serial
.baud_base
< 9600)|| (new_serial
.type
< PORT_UNKNOWN
) ||
1967 (new_serial
.type
> PORT_MAX
) || (new_serial
.type
== PORT_CIRRUS
) ||
1968 (new_serial
.type
== PORT_STARTECH
)) {
1972 if ((new_serial
.type
!= state
->type
) ||
1973 (new_serial
.xmit_fifo_size
<= 0))
1974 new_serial
.xmit_fifo_size
=
1975 uart_config
[state
->type
].dfl_xmit_fifo_size
;
1977 /* Make sure address is not already in use */
1978 if (new_serial
.type
) {
1979 for (i
= 0 ; i
< NR_PORTS
; i
++)
1980 if ((state
!= &rs_table
[i
]) &&
1981 (rs_table
[i
].port
== new_serial
.port
) &&
1986 if ((change_port
|| change_irq
) && (state
->count
> 1))
1990 * OK, past this point, all the error checking has been done.
1991 * At this point, we start making changes.....
1994 state
->baud_base
= new_serial
.baud_base
;
1995 state
->flags
= ((state
->flags
& ~ASYNC_FLAGS
) |
1996 (new_serial
.flags
& ASYNC_FLAGS
));
1997 info
->flags
= ((state
->flags
& ~ASYNC_INTERNAL_FLAGS
) |
1998 (info
->flags
& ASYNC_INTERNAL_FLAGS
));
1999 state
->custom_divisor
= new_serial
.custom_divisor
;
2000 state
->type
= new_serial
.type
;
2001 state
->close_delay
= new_serial
.close_delay
* HZ
/100;
2002 state
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
2003 #if (LINUX_VERSION_CODE > 0x200100)
2004 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2006 info
->xmit_fifo_size
= state
->xmit_fifo_size
=
2007 new_serial
.xmit_fifo_size
;
2009 if (state
->type
!= PORT_UNKNOWN
&& state
->port
)
2010 release_region(state
->port
,8);
2011 if (change_port
|| change_irq
) {
2013 * We need to shutdown the serial port at the old
2014 * port/irq combination.
2017 state
->irq
= new_serial
.irq
;
2018 info
->port
= state
->port
= new_serial
.port
;
2019 info
->hub6
= state
->hub6
= new_serial
.hub6
;
2021 if ((state
->type
!= PORT_UNKNOWN
) && state
->port
)
2022 request_region(state
->port
,8,"serial(set)");
2026 if (!state
->port
|| !state
->type
)
2028 if (info
->flags
& ASYNC_INITIALIZED
) {
2029 if (((old_state
.flags
& ASYNC_SPD_MASK
) !=
2030 (state
->flags
& ASYNC_SPD_MASK
)) ||
2031 (old_state
.custom_divisor
!= state
->custom_divisor
)) {
2032 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
2033 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
2034 info
->tty
->alt_speed
= 57600;
2035 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
2036 info
->tty
->alt_speed
= 115200;
2037 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
2038 info
->tty
->alt_speed
= 230400;
2039 if ((state
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
2040 info
->tty
->alt_speed
= 460800;
2042 change_speed(info
, 0);
2045 retval
= startup(info
);
2051 * get_lsr_info - get line status register info
2053 * Purpose: Let user call ioctl() to get info when the UART physically
2054 * is emptied. On bus types like RS485, the transmitter must
2055 * release the bus after transmitting. This must be done when
2056 * the transmit shift register is empty, not be done when the
2057 * transmit holding register is empty. This functionality
2058 * allows an RS485 driver to be written in user space.
2060 static int get_lsr_info(struct async_struct
* info
, unsigned int *value
)
2062 unsigned char status
;
2063 unsigned int result
;
2064 unsigned long flags
;
2066 save_flags(flags
); cli();
2067 status
= serial_in(info
, UART_LSR
);
2068 restore_flags(flags
);
2069 result
= ((status
& UART_LSR_TEMT
) ? TIOCSER_TEMT
: 0);
2070 if (copy_to_user(value
, &result
, sizeof(int)))
2076 static int get_modem_info(struct async_struct
* info
, unsigned int *value
)
2078 unsigned char control
, status
;
2079 unsigned int result
;
2080 unsigned long flags
;
2082 control
= info
->MCR
;
2083 save_flags(flags
); cli();
2084 status
= serial_in(info
, UART_MSR
);
2085 restore_flags(flags
);
2086 result
= ((control
& UART_MCR_RTS
) ? TIOCM_RTS
: 0)
2087 | ((control
& UART_MCR_DTR
) ? TIOCM_DTR
: 0)
2089 | ((control
& UART_MCR_OUT1
) ? TIOCM_OUT1
: 0)
2090 | ((control
& UART_MCR_OUT2
) ? TIOCM_OUT2
: 0)
2092 | ((status
& UART_MSR_DCD
) ? TIOCM_CAR
: 0)
2093 | ((status
& UART_MSR_RI
) ? TIOCM_RNG
: 0)
2094 | ((status
& UART_MSR_DSR
) ? TIOCM_DSR
: 0)
2095 | ((status
& UART_MSR_CTS
) ? TIOCM_CTS
: 0);
2097 if (copy_to_user(value
, &result
, sizeof(int)))
2102 static int set_modem_info(struct async_struct
* info
, unsigned int cmd
,
2103 unsigned int *value
)
2106 unsigned long flags
;
2108 if (copy_from_user(&arg
, value
, sizeof(int)))
2113 if (arg
& TIOCM_RTS
)
2114 info
->MCR
|= UART_MCR_RTS
;
2115 if (arg
& TIOCM_DTR
)
2116 info
->MCR
|= UART_MCR_DTR
;
2118 if (arg
& TIOCM_OUT1
)
2119 info
->MCR
|= UART_MCR_OUT1
;
2120 if (arg
& TIOCM_OUT2
)
2121 info
->MCR
|= UART_MCR_OUT2
;
2125 if (arg
& TIOCM_RTS
)
2126 info
->MCR
&= ~UART_MCR_RTS
;
2127 if (arg
& TIOCM_DTR
)
2128 info
->MCR
&= ~UART_MCR_DTR
;
2130 if (arg
& TIOCM_OUT1
)
2131 info
->MCR
&= ~UART_MCR_OUT1
;
2132 if (arg
& TIOCM_OUT2
)
2133 info
->MCR
&= ~UART_MCR_OUT2
;
2137 info
->MCR
= ((info
->MCR
& ~(UART_MCR_RTS
|
2143 | ((arg
& TIOCM_RTS
) ? UART_MCR_RTS
: 0)
2145 | ((arg
& TIOCM_OUT1
) ? UART_MCR_OUT1
: 0)
2146 | ((arg
& TIOCM_OUT2
) ? UART_MCR_OUT2
: 0)
2148 | ((arg
& TIOCM_DTR
) ? UART_MCR_DTR
: 0));
2153 save_flags(flags
); cli();
2154 info
->MCR
|= ALPHA_KLUDGE_MCR
; /* Don't ask */
2155 serial_out(info
, UART_MCR
, info
->MCR
);
2156 restore_flags(flags
);
2160 static int do_autoconfig(struct async_struct
* info
)
2164 if (!serial_isroot())
2167 if (info
->state
->count
> 1)
2172 autoconfig(info
->state
);
2173 if ((info
->state
->flags
& ASYNC_AUTO_IRQ
) &&
2174 (info
->state
->port
!= 0) &&
2175 (info
->state
->type
!= PORT_UNKNOWN
))
2176 info
->state
->irq
= detect_uart_irq(info
->state
);
2178 retval
= startup(info
);
2185 * rs_break() --- routine which turns the break handling on or off
2187 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2188 static void send_break( struct async_struct
* info
, int duration
)
2190 if (!CONFIGURED_SERIAL_PORT(info
))
2192 current
->state
= TASK_INTERRUPTIBLE
;
2193 current
->timeout
= jiffies
+ duration
;
2195 info
->LCR
|= UART_LCR_SBC
;
2196 serial_out(info
, UART_LCR
, info
->LCR
);
2198 info
->LCR
&= ~UART_LCR_SBC
;
2199 serial_out(info
, UART_LCR
, info
->LCR
);
2203 static void rs_break(struct tty_struct
*tty
, int break_state
)
2205 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2206 unsigned long flags
;
2208 if (serial_paranoia_check(info
, tty
->device
, "rs_break"))
2211 if (!CONFIGURED_SERIAL_PORT(info
))
2213 save_flags(flags
); cli();
2214 if (break_state
== -1)
2215 info
->LCR
|= UART_LCR_SBC
;
2217 info
->LCR
&= ~UART_LCR_SBC
;
2218 serial_out(info
, UART_LCR
, info
->LCR
);
2219 restore_flags(flags
);
2223 #ifdef CONFIG_SERIAL_MULTIPORT
2224 static int get_multiport_struct(struct async_struct
* info
,
2225 struct serial_multiport_struct
*retinfo
)
2227 struct serial_multiport_struct ret
;
2228 struct rs_multiport_struct
*multi
;
2230 multi
= &rs_multiport
[info
->state
->irq
];
2232 ret
.port_monitor
= multi
->port_monitor
;
2234 ret
.port1
= multi
->port1
;
2235 ret
.mask1
= multi
->mask1
;
2236 ret
.match1
= multi
->match1
;
2238 ret
.port2
= multi
->port2
;
2239 ret
.mask2
= multi
->mask2
;
2240 ret
.match2
= multi
->match2
;
2242 ret
.port3
= multi
->port3
;
2243 ret
.mask3
= multi
->mask3
;
2244 ret
.match3
= multi
->match3
;
2246 ret
.port4
= multi
->port4
;
2247 ret
.mask4
= multi
->mask4
;
2248 ret
.match4
= multi
->match4
;
2250 ret
.irq
= info
->state
->irq
;
2252 if (copy_to_user(retinfo
,&ret
,sizeof(*retinfo
)))
2257 static int set_multiport_struct(struct async_struct
* info
,
2258 struct serial_multiport_struct
*in_multi
)
2260 struct serial_multiport_struct new_multi
;
2261 struct rs_multiport_struct
*multi
;
2262 struct serial_state
*state
;
2263 int was_multi
, now_multi
;
2265 void (*handler
)(int, void *, struct pt_regs
*);
2267 if (!serial_isroot())
2269 state
= info
->state
;
2271 if (copy_from_user(&new_multi
, in_multi
,
2272 sizeof(struct serial_multiport_struct
)))
2275 if (new_multi
.irq
!= state
->irq
|| state
->irq
== 0 ||
2276 !IRQ_ports
[state
->irq
])
2279 multi
= &rs_multiport
[state
->irq
];
2280 was_multi
= (multi
->port1
!= 0);
2282 multi
->port_monitor
= new_multi
.port_monitor
;
2285 release_region(multi
->port1
,1);
2286 multi
->port1
= new_multi
.port1
;
2287 multi
->mask1
= new_multi
.mask1
;
2288 multi
->match1
= new_multi
.match1
;
2290 request_region(multi
->port1
,1,"serial(multiport1)");
2293 release_region(multi
->port2
,1);
2294 multi
->port2
= new_multi
.port2
;
2295 multi
->mask2
= new_multi
.mask2
;
2296 multi
->match2
= new_multi
.match2
;
2298 request_region(multi
->port2
,1,"serial(multiport2)");
2301 release_region(multi
->port3
,1);
2302 multi
->port3
= new_multi
.port3
;
2303 multi
->mask3
= new_multi
.mask3
;
2304 multi
->match3
= new_multi
.match3
;
2306 request_region(multi
->port3
,1,"serial(multiport3)");
2309 release_region(multi
->port4
,1);
2310 multi
->port4
= new_multi
.port4
;
2311 multi
->mask4
= new_multi
.mask4
;
2312 multi
->match4
= new_multi
.match4
;
2314 request_region(multi
->port4
,1,"serial(multiport4)");
2316 now_multi
= (multi
->port1
!= 0);
2318 if (IRQ_ports
[state
->irq
]->next_port
&&
2319 (was_multi
!= now_multi
)) {
2320 free_irq(state
->irq
, NULL
);
2322 handler
= rs_interrupt_multi
;
2324 handler
= rs_interrupt
;
2326 retval
= request_irq(state
->irq
, handler
, IRQ_T(state
),
2329 printk("Couldn't reallocate serial interrupt "
2337 static int rs_ioctl(struct tty_struct
*tty
, struct file
* file
,
2338 unsigned int cmd
, unsigned long arg
)
2340 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2341 struct async_icount cprev
, cnow
; /* kernel counter temps */
2342 struct serial_icounter_struct icount
;
2343 unsigned long flags
;
2344 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2348 if (serial_paranoia_check(info
, tty
->device
, "rs_ioctl"))
2351 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
2352 (cmd
!= TIOCSERCONFIG
) && (cmd
!= TIOCSERGSTRUCT
) &&
2353 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
2354 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2359 #if (LINUX_VERSION_CODE < 131394) /* Linux 2.1.66 */
2360 case TCSBRK
: /* SVID version: non-zero arg --> no break */
2361 retval
= tty_check_change(tty
);
2364 tty_wait_until_sent(tty
, 0);
2365 if (signal_pending(current
))
2368 send_break(info
, HZ
/4); /* 1/4 second */
2369 if (signal_pending(current
))
2373 case TCSBRKP
: /* support for POSIX tcsendbreak() */
2374 retval
= tty_check_change(tty
);
2377 tty_wait_until_sent(tty
, 0);
2378 if (signal_pending(current
))
2380 send_break(info
, arg
? arg
*(HZ
/10) : HZ
/4);
2381 if (signal_pending(current
))
2385 tmp
= C_CLOCAL(tty
) ? 1 : 0;
2386 if (copy_to_user((void *)arg
, &tmp
, sizeof(int)))
2390 if (copy_from_user(&tmp
, (void *)arg
, sizeof(int)))
2393 tty
->termios
->c_cflag
=
2394 ((tty
->termios
->c_cflag
& ~CLOCAL
) |
2395 (tmp
? CLOCAL
: 0));
2399 return get_modem_info(info
, (unsigned int *) arg
);
2403 return set_modem_info(info
, cmd
, (unsigned int *) arg
);
2405 return get_serial_info(info
,
2406 (struct serial_struct
*) arg
);
2408 return set_serial_info(info
,
2409 (struct serial_struct
*) arg
);
2411 return do_autoconfig(info
);
2413 case TIOCSERGETLSR
: /* Get line status register */
2414 return get_lsr_info(info
, (unsigned int *) arg
);
2416 case TIOCSERGSTRUCT
:
2417 if (copy_to_user((struct async_struct
*) arg
,
2418 info
, sizeof(struct async_struct
)))
2422 #ifdef CONFIG_SERIAL_MULTIPORT
2423 case TIOCSERGETMULTI
:
2424 return get_multiport_struct(info
,
2425 (struct serial_multiport_struct
*) arg
);
2426 case TIOCSERSETMULTI
:
2427 return set_multiport_struct(info
,
2428 (struct serial_multiport_struct
*) arg
);
2432 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
2433 * - mask passed in arg for lines of interest
2434 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
2435 * Caller should use TIOCGICOUNT to see which one it was
2438 save_flags(flags
); cli();
2439 /* note the counters on entry */
2440 cprev
= info
->state
->icount
;
2441 restore_flags(flags
);
2443 interruptible_sleep_on(&info
->delta_msr_wait
);
2444 /* see if a signal did it */
2445 if (signal_pending(current
))
2446 return -ERESTARTSYS
;
2447 save_flags(flags
); cli();
2448 cnow
= info
->state
->icount
; /* atomic copy */
2449 restore_flags(flags
);
2450 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2451 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
)
2452 return -EIO
; /* no change => error */
2453 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
2454 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
2455 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
2456 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
2464 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
2465 * Return: write counters to the user passed counter struct
2466 * NB: both 1->0 and 0->1 transitions are counted except for
2467 * RI where only 0->1 is counted.
2470 save_flags(flags
); cli();
2471 cnow
= info
->state
->icount
;
2472 restore_flags(flags
);
2473 icount
.cts
= cnow
.cts
;
2474 icount
.dsr
= cnow
.dsr
;
2475 icount
.rng
= cnow
.rng
;
2476 icount
.dcd
= cnow
.dcd
;
2477 icount
.rx
= cnow
.rx
;
2478 icount
.tx
= cnow
.tx
;
2479 icount
.frame
= cnow
.frame
;
2480 icount
.overrun
= cnow
.overrun
;
2481 icount
.parity
= cnow
.parity
;
2482 icount
.brk
= cnow
.brk
;
2483 icount
.buf_overrun
= cnow
.buf_overrun
;
2485 if (copy_to_user((void *)arg
, &icount
, sizeof(icount
)))
2490 /* "setserial -W" is called in Debian boot */
2491 printk ("TIOCSER?WILD ioctl obsolete, ignored.\n");
2495 return -ENOIOCTLCMD
;
2500 static void rs_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
2502 struct async_struct
*info
= (struct async_struct
*)tty
->driver_data
;
2503 unsigned long flags
;
2504 unsigned int cflag
= tty
->termios
->c_cflag
;
2506 if ( (cflag
== old_termios
->c_cflag
)
2507 && ( RELEVANT_IFLAG(tty
->termios
->c_iflag
)
2508 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
2511 change_speed(info
, old_termios
);
2513 /* Handle transition to B0 status */
2514 if ((old_termios
->c_cflag
& CBAUD
) &&
2516 info
->MCR
&= ~(UART_MCR_DTR
|UART_MCR_RTS
);
2517 save_flags(flags
); cli();
2518 serial_out(info
, UART_MCR
, info
->MCR
);
2519 restore_flags(flags
);
2522 /* Handle transition away from B0 status */
2523 if (!(old_termios
->c_cflag
& CBAUD
) &&
2525 info
->MCR
|= UART_MCR_DTR
;
2526 if (!(tty
->termios
->c_cflag
& CRTSCTS
) ||
2527 !test_bit(TTY_THROTTLED
, &tty
->flags
)) {
2528 info
->MCR
|= UART_MCR_RTS
;
2530 save_flags(flags
); cli();
2531 serial_out(info
, UART_MCR
, info
->MCR
);
2532 restore_flags(flags
);
2535 /* Handle turning off CRTSCTS */
2536 if ((old_termios
->c_cflag
& CRTSCTS
) &&
2537 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
2538 tty
->hw_stopped
= 0;
2544 * No need to wake up processes in open wait, since they
2545 * sample the CLOCAL flag once, and don't recheck it.
2546 * XXX It's not clear whether the current behavior is correct
2547 * or not. Hence, this may change.....
2549 if (!(old_termios
->c_cflag
& CLOCAL
) &&
2550 (tty
->termios
->c_cflag
& CLOCAL
))
2551 wake_up_interruptible(&info
->open_wait
);
2556 * ------------------------------------------------------------
2559 * This routine is called when the serial port gets closed. First, we
2560 * wait for the last remaining data to be sent. Then, we unlink its
2561 * async structure from the interrupt chain if necessary, and we free
2562 * that IRQ if nothing is left in the chain.
2563 * ------------------------------------------------------------
2565 static void rs_close(struct tty_struct
*tty
, struct file
* filp
)
2567 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2568 struct serial_state
*state
;
2569 unsigned long flags
;
2571 if (!info
|| serial_paranoia_check(info
, tty
->device
, "rs_close"))
2574 state
= info
->state
;
2576 save_flags(flags
); cli();
2578 if (tty_hung_up_p(filp
)) {
2579 DBG_CNT("before DEC-hung");
2581 restore_flags(flags
);
2585 #ifdef SERIAL_DEBUG_OPEN
2586 printk("rs_close ttys%d, count = %d\n", info
->line
, state
->count
);
2588 if ((tty
->count
== 1) && (state
->count
!= 1)) {
2590 * Uh, oh. tty->count is 1, which means that the tty
2591 * structure will be freed. state->count should always
2592 * be one in these conditions. If it's greater than
2593 * one, we've got real problems, since it means the
2594 * serial port won't be shutdown.
2596 printk("rs_close: bad serial port count; tty->count is 1, "
2597 "state->count is %d\n", state
->count
);
2600 if (--state
->count
< 0) {
2601 printk("rs_close: bad serial port count for ttys%d: %d\n",
2602 info
->line
, state
->count
);
2606 DBG_CNT("before DEC-2");
2608 restore_flags(flags
);
2611 info
->flags
|= ASYNC_CLOSING
;
2613 * Save the termios structure, since this port may have
2614 * separate termios for callout and dialin.
2616 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2617 info
->state
->normal_termios
= *tty
->termios
;
2618 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2619 info
->state
->callout_termios
= *tty
->termios
;
2621 * Now we wait for the transmit buffer to clear; and we notify
2622 * the line discipline to only process XON/XOFF characters.
2625 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
2626 tty_wait_until_sent(tty
, info
->closing_wait
);
2628 * At this point we stop accepting input. To do this, we
2629 * disable the receive line status interrupts, and tell the
2630 * interrupt driver to stop checking the data ready bit in the
2631 * line status register.
2633 info
->IER
&= ~UART_IER_RLSI
;
2634 info
->read_status_mask
&= ~UART_LSR_DR
;
2635 if (info
->flags
& ASYNC_INITIALIZED
) {
2636 serial_out(info
, UART_IER
, info
->IER
);
2638 * Before we drop DTR, make sure the UART transmitter
2639 * has completely drained; this is especially
2640 * important if there is a transmit FIFO!
2642 rs_wait_until_sent(tty
, info
->timeout
);
2645 if (tty
->driver
.flush_buffer
)
2646 tty
->driver
.flush_buffer(tty
);
2647 if (tty
->ldisc
.flush_buffer
)
2648 tty
->ldisc
.flush_buffer(tty
);
2652 if (info
->blocked_open
) {
2653 if (info
->close_delay
) {
2654 current
->state
= TASK_INTERRUPTIBLE
;
2655 schedule_timeout(info
->close_delay
);
2657 wake_up_interruptible(&info
->open_wait
);
2659 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
2661 wake_up_interruptible(&info
->close_wait
);
2663 restore_flags(flags
);
2667 * rs_wait_until_sent() --- wait until the transmitter is empty
2669 static void rs_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2671 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2672 unsigned long orig_jiffies
, char_time
;
2675 if (serial_paranoia_check(info
, tty
->device
, "rs_wait_until_sent"))
2678 if (info
->state
->type
== PORT_UNKNOWN
)
2681 if (info
->xmit_fifo_size
== 0)
2682 return; /* Just in case.... */
2684 orig_jiffies
= jiffies
;
2686 * Set the check interval to be 1/5 of the estimated time to
2687 * send a single character, and make it at least 1. The check
2688 * interval should also be less than the timeout.
2690 * Note: we have to use pretty tight timings here to satisfy
2693 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2694 char_time
= char_time
/ 5;
2698 char_time
= MIN(char_time
, timeout
);
2700 * If the transmitter hasn't cleared in twice the approximate
2701 * amount of time to send the entire FIFO, it probably won't
2702 * ever clear. This assumes the UART isn't doing flow
2703 * control, which is currently the case. Hence, if it ever
2704 * takes longer than info->timeout, this is probably due to a
2705 * UART bug of some kind. So, we clamp the timeout parameter at
2708 if (!timeout
|| timeout
> 2*info
->timeout
)
2709 timeout
= 2*info
->timeout
;
2710 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2711 printk("In rs_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2712 printk("jiff=%lu...", jiffies
);
2714 while (!((lsr
= serial_inp(info
, UART_LSR
)) & UART_LSR_TEMT
)) {
2715 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2716 printk("lsr = %d (jiff=%lu)...", lsr
, jiffies
);
2718 current
->state
= TASK_INTERRUPTIBLE
;
2719 schedule_timeout(char_time
);
2720 if (signal_pending(current
))
2722 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2725 current
->state
= TASK_RUNNING
;
2726 #ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
2727 printk("lsr = %d (jiff=%lu)...done\n", lsr
, jiffies
);
2732 * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
2734 static void rs_hangup(struct tty_struct
*tty
)
2736 struct async_struct
* info
= (struct async_struct
*)tty
->driver_data
;
2737 struct serial_state
*state
= info
->state
;
2739 if (serial_paranoia_check(info
, tty
->device
, "rs_hangup"))
2742 state
= info
->state
;
2744 rs_flush_buffer(tty
);
2748 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
2750 wake_up_interruptible(&info
->open_wait
);
2754 * ------------------------------------------------------------
2755 * rs_open() and friends
2756 * ------------------------------------------------------------
2758 static int block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2759 struct async_struct
*info
)
2761 #ifdef DECLARE_WAITQUEUE
2762 DECLARE_WAITQUEUE(wait
, current
);
2764 struct wait_queue wait
= { current
, NULL
};
2766 struct serial_state
*state
= info
->state
;
2768 int do_clocal
= 0, extra_count
= 0;
2769 unsigned long flags
;
2772 * If the device is in the middle of being closed, then block
2773 * until it's done, and then try again.
2775 if (tty_hung_up_p(filp
) ||
2776 (info
->flags
& ASYNC_CLOSING
)) {
2777 if (info
->flags
& ASYNC_CLOSING
)
2778 interruptible_sleep_on(&info
->close_wait
);
2779 #ifdef SERIAL_DO_RESTART
2780 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2781 -EAGAIN
: -ERESTARTSYS
);
2788 * If this is a callout device, then just make sure the normal
2789 * device isn't being used.
2791 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
2792 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2794 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2795 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
2796 (info
->session
!= current
->session
))
2798 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2799 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
2800 (info
->pgrp
!= current
->pgrp
))
2802 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
2807 * If non-blocking mode is set, or the port is not enabled,
2808 * then make the check up front and then exit.
2810 if ((filp
->f_flags
& O_NONBLOCK
) ||
2811 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2812 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2814 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2818 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
) {
2819 if (state
->normal_termios
.c_cflag
& CLOCAL
)
2822 if (tty
->termios
->c_cflag
& CLOCAL
)
2827 * Block waiting for the carrier detect and the line to become
2828 * free (i.e., not in use by the callout). While we are in
2829 * this loop, state->count is dropped by one, so that
2830 * rs_close() knows when to free things. We restore it upon
2831 * exit, either normal or abnormal.
2834 add_wait_queue(&info
->open_wait
, &wait
);
2835 #ifdef SERIAL_DEBUG_OPEN
2836 printk("block_til_ready before block: ttys%d, count = %d\n",
2837 state
->line
, state
->count
);
2839 save_flags(flags
); cli();
2840 if (!tty_hung_up_p(filp
)) {
2844 restore_flags(flags
);
2845 info
->blocked_open
++;
2847 save_flags(flags
); cli();
2848 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2849 (tty
->termios
->c_cflag
& CBAUD
))
2850 serial_out(info
, UART_MCR
,
2851 serial_inp(info
, UART_MCR
) |
2852 (UART_MCR_DTR
| UART_MCR_RTS
));
2853 restore_flags(flags
);
2854 set_current_state(TASK_INTERRUPTIBLE
);
2855 if (tty_hung_up_p(filp
) ||
2856 !(info
->flags
& ASYNC_INITIALIZED
)) {
2857 #ifdef SERIAL_DO_RESTART
2858 if (info
->flags
& ASYNC_HUP_NOTIFY
)
2861 retval
= -ERESTARTSYS
;
2867 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2868 !(info
->flags
& ASYNC_CLOSING
) &&
2869 (do_clocal
|| (serial_in(info
, UART_MSR
) &
2872 if (signal_pending(current
)) {
2873 retval
= -ERESTARTSYS
;
2876 #ifdef SERIAL_DEBUG_OPEN
2877 printk("block_til_ready blocking: ttys%d, count = %d\n",
2878 info
->line
, state
->count
);
2882 current
->state
= TASK_RUNNING
;
2883 remove_wait_queue(&info
->open_wait
, &wait
);
2886 info
->blocked_open
--;
2887 #ifdef SERIAL_DEBUG_OPEN
2888 printk("block_til_ready after blocking: ttys%d, count = %d\n",
2889 info
->line
, state
->count
);
2893 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2897 static int get_async_struct(int line
, struct async_struct
**ret_info
)
2899 struct async_struct
*info
;
2900 struct serial_state
*sstate
;
2902 sstate
= rs_table
+ line
;
2905 *ret_info
= sstate
->info
;
2908 info
= kmalloc(sizeof(struct async_struct
), GFP_KERNEL
);
2913 memset(info
, 0, sizeof(struct async_struct
));
2914 #ifdef DECLARE_WAITQUEUE
2915 init_waitqueue_head(&info
->open_wait
);
2916 init_waitqueue_head(&info
->close_wait
);
2917 init_waitqueue_head(&info
->delta_msr_wait
);
2919 info
->magic
= SERIAL_MAGIC
;
2920 info
->port
= sstate
->port
;
2921 info
->flags
= sstate
->flags
;
2922 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
2923 info
->iomem_base
= sstate
->iomem_base
;
2924 info
->iomem_reg_shift
= sstate
->iomem_reg_shift
;
2926 info
->xmit_fifo_size
= sstate
->xmit_fifo_size
;
2928 info
->tqueue
.routine
= do_softint
;
2929 info
->tqueue
.data
= info
;
2930 info
->state
= sstate
;
2932 kfree_s(info
, sizeof(struct async_struct
));
2933 *ret_info
= sstate
->info
;
2936 *ret_info
= sstate
->info
= info
;
2941 * This routine is called whenever a serial port is opened. It
2942 * enables interrupts for a serial port, linking in its async structure into
2943 * the IRQ chain. It also performs the serial-specific
2944 * initialization for the tty structure.
2946 static int rs_open(struct tty_struct
*tty
, struct file
* filp
)
2948 struct async_struct
*info
;
2953 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2954 if ((line
< 0) || (line
>= NR_PORTS
)) {
2958 retval
= get_async_struct(line
, &info
);
2963 tty
->driver_data
= info
;
2965 if (serial_paranoia_check(info
, tty
->device
, "rs_open"))
2968 #ifdef SERIAL_DEBUG_OPEN
2969 printk("rs_open %s%d, count = %d\n", tty
->driver
.name
, info
->line
,
2970 info
->state
->count
);
2972 #if (LINUX_VERSION_CODE > 0x20100)
2973 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2977 page
= get_free_page(GFP_KERNEL
);
2984 tmp_buf
= (unsigned char *) page
;
2988 * If the port is the middle of closing, bail out now
2990 if (tty_hung_up_p(filp
) ||
2991 (info
->flags
& ASYNC_CLOSING
)) {
2992 if (info
->flags
& ASYNC_CLOSING
)
2993 interruptible_sleep_on(&info
->close_wait
);
2994 #ifdef SERIAL_DO_RESTART
2995 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2996 -EAGAIN
: -ERESTARTSYS
);
3003 * Start up serial port
3005 retval
= startup(info
);
3010 retval
= block_til_ready(tty
, filp
, info
);
3012 #ifdef SERIAL_DEBUG_OPEN
3013 printk("rs_open returning after block_til_ready with %d\n",
3019 if ((info
->state
->count
== 1) &&
3020 (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
3021 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
3022 *tty
->termios
= info
->state
->normal_termios
;
3024 *tty
->termios
= info
->state
->callout_termios
;
3025 change_speed(info
, 0);
3027 #ifdef CONFIG_SERIAL_CONSOLE
3028 if (sercons
.cflag
&& sercons
.index
== line
) {
3029 tty
->termios
->c_cflag
= sercons
.cflag
;
3031 change_speed(info
, 0);
3034 info
->session
= current
->session
;
3035 info
->pgrp
= current
->pgrp
;
3037 #ifdef SERIAL_DEBUG_OPEN
3038 printk("rs_open ttys%d successful...", info
->line
);
3044 * /proc fs routines....
3047 static inline int line_info(char *buf
, struct serial_state
*state
)
3049 struct async_struct
*info
= state
->info
, scr_info
;
3050 char stat_buf
[30], control
, status
;
3052 unsigned long flags
;
3054 ret
= sprintf(buf
, "%d: uart:%s port:%X irq:%d",
3055 state
->line
, uart_config
[state
->type
].name
,
3056 state
->port
, state
->irq
);
3058 if (!state
->port
|| (state
->type
== PORT_UNKNOWN
)) {
3059 ret
+= sprintf(buf
+ret
, "\n");
3064 * Figure out the current RS-232 lines
3067 info
= &scr_info
; /* This is just for serial_{in,out} */
3069 info
->magic
= SERIAL_MAGIC
;
3070 info
->port
= state
->port
;
3071 info
->flags
= state
->flags
;
3075 save_flags(flags
); cli();
3076 status
= serial_in(info
, UART_MSR
);
3077 control
= info
? info
->MCR
: serial_in(info
, UART_MCR
);
3078 restore_flags(flags
);
3082 if (control
& UART_MCR_RTS
)
3083 strcat(stat_buf
, "|RTS");
3084 if (status
& UART_MSR_CTS
)
3085 strcat(stat_buf
, "|CTS");
3086 if (control
& UART_MCR_DTR
)
3087 strcat(stat_buf
, "|DTR");
3088 if (status
& UART_MSR_DSR
)
3089 strcat(stat_buf
, "|DSR");
3090 if (status
& UART_MSR_DCD
)
3091 strcat(stat_buf
, "|CD");
3092 if (status
& UART_MSR_RI
)
3093 strcat(stat_buf
, "|RI");
3096 ret
+= sprintf(buf
+ret
, " baud:%d",
3097 state
->baud_base
/ info
->quot
);
3100 ret
+= sprintf(buf
+ret
, " tx:%d rx:%d",
3101 state
->icount
.tx
, state
->icount
.rx
);
3103 if (state
->icount
.frame
)
3104 ret
+= sprintf(buf
+ret
, " fe:%d", state
->icount
.frame
);
3106 if (state
->icount
.parity
)
3107 ret
+= sprintf(buf
+ret
, " pe:%d", state
->icount
.parity
);
3109 if (state
->icount
.brk
)
3110 ret
+= sprintf(buf
+ret
, " brk:%d", state
->icount
.brk
);
3112 if (state
->icount
.overrun
)
3113 ret
+= sprintf(buf
+ret
, " oe:%d", state
->icount
.overrun
);
3116 * Last thing is the RS-232 status lines
3118 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
3122 int rs_read_proc(char *page
, char **start
, off_t off
, int count
,
3123 int *eof
, void *data
)
3128 len
+= sprintf(page
, "serinfo:1.0 driver:%s\n", serial_version
);
3129 for (i
= 0; i
< NR_PORTS
&& len
< 4000; i
++) {
3130 l
= line_info(page
+ len
, &rs_table
[i
]);
3132 if (len
+begin
> off
+count
)
3134 if (len
+begin
< off
) {
3141 if (off
>= len
+begin
)
3143 *start
= page
+ (begin
-off
);
3144 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
3148 * ---------------------------------------------------------------------
3149 * rs_init() and friends
3151 * rs_init() is called at boot-time to initialize the serial driver.
3152 * ---------------------------------------------------------------------
3156 * This routine prints out the appropriate serial driver version
3157 * number, and identifies which options were configured into this
3160 static _INLINE_
void show_serial_version(void)
3162 printk(KERN_INFO
"%s version %s with", serial_name
, serial_version
);
3167 #ifdef CONFIG_SERIAL_MANY_PORTS
3168 printk(" MANY_PORTS");
3171 #ifdef CONFIG_SERIAL_MULTIPORT
3172 printk(" MULTIPORT");
3175 #ifdef CONFIG_SERIAL_SHARE_IRQ
3176 printk(" SHARE_IRQ");
3179 #ifdef CONFIG_SERIAL_DETECT_IRQ
3180 printk(" DETECT_IRQ");
3183 #ifdef ENABLE_SERIAL_PCI
3184 printk(" SERIAL_PCI");
3185 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
3186 printk(" PCI_IOMEM");
3191 printk(" enabled\n");
3193 printk(" no serial options enabled\n");
3199 * This routine detect the IRQ of a serial port by clearing OUT2 when
3200 * no UART interrupt are requested (IER = 0) (*GPL*). This seems to work at
3201 * each time, as long as no other device permanently request the IRQ.
3202 * If no IRQ is detected, or multiple IRQ appear, this function returns 0.
3203 * The variable "state" and the field "state->port" should not be null.
3205 static unsigned detect_uart_irq (struct serial_state
* state
)
3209 unsigned char save_mcr
, save_ier
;
3210 struct async_struct scr_info
; /* serial_{in,out} because HUB6 */
3212 #ifdef CONFIG_SERIAL_MANY_PORTS
3213 unsigned char save_ICP
=0; /* no warning */
3214 unsigned short ICP
=0;
3216 if (state
->flags
& ASYNC_FOURPORT
) {
3217 ICP
= (state
->port
& 0xFE0) | 0x01F;
3218 save_ICP
= inb_p(ICP
);
3223 scr_info
.magic
= SERIAL_MAGIC
;
3224 scr_info
.port
= state
->port
;
3225 scr_info
.flags
= state
->flags
;
3227 scr_info
.hub6
= state
->hub6
;
3230 /* forget possible initially masked and pending IRQ */
3231 probe_irq_off(probe_irq_on());
3232 save_mcr
= serial_inp(&scr_info
, UART_MCR
);
3233 save_ier
= serial_inp(&scr_info
, UART_IER
);
3234 serial_outp(&scr_info
, UART_MCR
, UART_MCR_OUT1
| UART_MCR_OUT2
);
3236 irqs
= probe_irq_on();
3237 serial_outp(&scr_info
, UART_MCR
, 0);
3239 if (state
->flags
& ASYNC_FOURPORT
) {
3240 serial_outp(&scr_info
, UART_MCR
,
3241 UART_MCR_DTR
| UART_MCR_RTS
);
3243 serial_outp(&scr_info
, UART_MCR
,
3244 UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
);
3246 serial_outp(&scr_info
, UART_IER
, 0x0f); /* enable all intrs */
3247 (void)serial_inp(&scr_info
, UART_LSR
);
3248 (void)serial_inp(&scr_info
, UART_RX
);
3249 (void)serial_inp(&scr_info
, UART_IIR
);
3250 (void)serial_inp(&scr_info
, UART_MSR
);
3251 serial_outp(&scr_info
, UART_TX
, 0xFF);
3253 irq
= probe_irq_off(irqs
);
3255 serial_outp(&scr_info
, UART_MCR
, save_mcr
);
3256 serial_outp(&scr_info
, UART_IER
, save_ier
);
3257 #ifdef CONFIG_SERIAL_MANY_PORTS
3258 if (state
->flags
& ASYNC_FOURPORT
)
3259 outb_p(save_ICP
, ICP
);
3261 return (irq
> 0)? irq
: 0;
3265 * This is a quickie test to see how big the FIFO is.
3266 * It doesn't work at all the time, more's the pity.
3268 static int size_fifo(struct async_struct
*info
)
3270 unsigned char old_fcr
, old_mcr
, old_dll
, old_dlm
;
3273 old_fcr
= serial_inp(info
, UART_FCR
);
3274 old_mcr
= serial_inp(info
, UART_MCR
);
3275 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
3276 UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
);
3277 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
);
3278 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3279 old_dll
= serial_inp(info
, UART_DLL
);
3280 old_dlm
= serial_inp(info
, UART_DLM
);
3281 serial_outp(info
, UART_DLL
, 0x01);
3282 serial_outp(info
, UART_DLM
, 0x00);
3283 serial_outp(info
, UART_LCR
, 0x03);
3284 for (count
= 0; count
< 256; count
++)
3285 serial_outp(info
, UART_TX
, count
);
3287 for (count
= 0; (serial_inp(info
, UART_LSR
) & UART_LSR_DR
) &&
3288 (count
< 256); count
++)
3289 serial_inp(info
, UART_RX
);
3290 serial_outp(info
, UART_FCR
, old_fcr
);
3291 serial_outp(info
, UART_MCR
, old_mcr
);
3292 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3293 serial_outp(info
, UART_DLL
, old_dll
);
3294 serial_outp(info
, UART_DLM
, old_dlm
);
3300 * This is a helper routine to autodetect StarTech/Exar UART's. When
3301 * this function is called we know it is at least a StarTech 16650 V2,
3302 * but it might be one of several StarTech UARTs, or one of its
3303 * clones. (We treat the broken original StarTech 16650 V1 as a
3304 * 16550A, and why not? Startech doesn't seem to even acknowledge its
3307 * What evil have men's minds wrought...
3309 static void autoconfig_startech_uarts(struct async_struct
*info
,
3310 struct serial_state
*state
,
3311 unsigned long flags
)
3313 unsigned char scratch
, status1
, status2
, old_fctr
, old_emsr
;
3316 * Here we check for the XR16C85x family. We do this by
3317 * checking for to see if we can replace the scratch register
3318 * with the receive FIFO count register.
3320 * XXX I don't have one of these chips, but it should also be
3321 * possible to check for them by setting DLL and DLM to 0, and
3322 * then reading back DLL and DLM. If the DLM reads back as
3323 * 0x10, then the UART is a XR16C850 and the DLL contains the
3326 old_fctr
= serial_inp(info
, UART_FCTR
);
3327 serial_outp(info
, UART_FCTR
, old_fctr
| UART_FCTR_SCR_SWAP
);
3328 old_emsr
= serial_inp(info
, UART_EMSR
);
3329 serial_outp(info
, UART_EMSR
, 0x00);
3330 serial_outp(info
, UART_LCR
, 0x00);
3331 scratch
= serial_in(info
, UART_SCR
);
3332 serial_outp(info
, UART_SCR
, 0xa5);
3333 status1
= serial_in(info
, UART_SCR
);
3334 serial_outp(info
, UART_SCR
, 0x5a);
3335 status2
= serial_in(info
, UART_SCR
);
3336 serial_outp(info
, UART_SCR
, scratch
);
3337 if ((status1
!= 0xa5) || (status2
!= 0x5a)) {
3338 serial_outp(info
, UART_LCR
, 0xBF);
3339 serial_outp(info
, UART_FCTR
, old_fctr
| UART_FCTR_SCR_SWAP
);
3340 serial_outp(info
, UART_EMSR
, old_emsr
);
3341 serial_outp(info
, UART_FCTR
, old_fctr
);
3342 state
->type
= PORT_16850
;
3345 serial_outp(info
, UART_IER
, old_fctr
);
3348 * We distinguish between the '654 and the '650 by counting
3349 * how many bytes are in the FIFO. I'm using this for now,
3350 * since that's the technique that was sent to me in the
3351 * serial driver update, but I'm not convinced this works.
3352 * I've had problems doing this in the past. -TYT
3354 if (size_fifo(info
) == 64)
3355 state
->type
= PORT_16654
;
3357 state
->type
= PORT_16650V2
;
3361 * This routine is called by rs_init() to initialize a specific serial
3362 * port. It determines what type of UART chip this serial port is
3363 * using: 8250, 16450, 16550, 16550A. The important question is
3364 * whether or not this UART is a 16550A or not, since this will
3365 * determine whether or not we can use its FIFO features or not.
3367 static void autoconfig(struct serial_state
* state
)
3369 unsigned char status1
, status2
, scratch
, scratch2
, scratch3
;
3370 struct async_struct
*info
, scr_info
;
3371 unsigned long flags
;
3373 state
->type
= PORT_UNKNOWN
;
3375 if (!CONFIGURED_SERIAL_PORT(state
))
3378 info
= &scr_info
; /* This is just for serial_{in,out} */
3380 info
->magic
= SERIAL_MAGIC
;
3381 info
->state
= state
;
3382 info
->port
= state
->port
;
3383 info
->flags
= state
->flags
;
3385 info
->hub6
= state
->hub6
;
3387 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
3388 info
->iomem_base
= state
->iomem_base
;
3389 info
->iomem_reg_shift
= state
->iomem_reg_shift
;
3392 save_flags(flags
); cli();
3394 if (!state
->iomem_base
) {
3396 * Do a simple existence test first; if we fail this,
3397 * there's no point trying anything else.
3399 * 0x80 is used as a nonsense port to prevent against
3400 * false positives due to ISA bus float. The
3401 * assumption is that 0x80 is a non-existent port;
3402 * which should be safe since include/asm/io.h also
3403 * makes this assumption.
3405 scratch
= serial_inp(info
, UART_IER
);
3406 serial_outp(info
, UART_IER
, 0);
3408 scratch2
= serial_inp(info
, UART_IER
);
3409 serial_outp(info
, UART_IER
, scratch
);
3411 restore_flags(flags
);
3412 return; /* We failed; there's nothing here */
3417 * Check to see if a UART is really there. Certain broken
3418 * internal modems based on the Rockwell chipset fail this
3419 * test, because they apparently don't implement the loopback
3420 * test mode. So this test is skipped on the COM 1 through
3421 * COM 4 ports. This *should* be safe, since no board
3422 * manufacturer would be stupid enough to design a board
3423 * that conflicts with COM 1-4 --- we hope!
3425 if (!(state
->flags
& ASYNC_SKIP_TEST
)) {
3426 scratch
= serial_inp(info
, UART_MCR
);
3427 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| scratch
);
3428 serial_outp(info
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
3429 status1
= serial_inp(info
, UART_MSR
) & 0xF0;
3430 serial_outp(info
, UART_MCR
, scratch
);
3431 if (status1
!= 0x90) {
3432 restore_flags(flags
);
3437 scratch2
= serial_in(info
, UART_LCR
);
3438 serial_outp(info
, UART_LCR
, 0xBF); /* set up for StarTech test */
3439 serial_outp(info
, UART_EFR
, 0); /* EFR is the same as FCR */
3440 serial_outp(info
, UART_LCR
, 0);
3441 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3442 scratch
= serial_in(info
, UART_IIR
) >> 6;
3445 state
->type
= PORT_16450
;
3448 state
->type
= PORT_UNKNOWN
;
3451 state
->type
= PORT_16550
;
3454 state
->type
= PORT_16550A
;
3457 if (state
->type
== PORT_16550A
) {
3458 /* Check for Oxford Semiconductor 16C950 */
3459 scratch
= serial_icr_read(info
, UART_ID1
);
3460 scratch2
= serial_icr_read(info
, UART_ID2
);
3461 scratch3
= serial_icr_read(info
, UART_ID3
);
3463 if (scratch
== 0x16 && scratch2
== 0xC9 &&
3464 (scratch3
== 0x50 || scratch3
== 0x52 ||
3465 scratch3
== 0x54)) {
3466 state
->type
= PORT_16C950
;
3467 state
->revision
= serial_icr_read(info
, UART_REV
);
3470 if (state
->type
== PORT_16550A
) {
3471 /* Check for Startech UART's */
3472 serial_outp(info
, UART_LCR
, UART_LCR_DLAB
);
3473 if (serial_in(info
, UART_EFR
) == 0) {
3474 state
->type
= PORT_16650
;
3476 serial_outp(info
, UART_LCR
, 0xBF);
3477 if (serial_in(info
, UART_EFR
) == 0)
3478 autoconfig_startech_uarts(info
, state
, flags
);
3481 if (state
->type
== PORT_16550A
) {
3482 /* Check for TI 16750 */
3483 serial_outp(info
, UART_LCR
, scratch2
| UART_LCR_DLAB
);
3484 serial_outp(info
, UART_FCR
,
3485 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
3486 scratch
= serial_in(info
, UART_IIR
) >> 5;
3489 * If this is a 16750, and not a cheap UART
3490 * clone, then it should only go into 64 byte
3491 * mode if the UART_FCR7_64BYTE bit was set
3492 * while UART_LCR_DLAB was latched.
3494 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3495 serial_outp(info
, UART_LCR
, 0);
3496 serial_outp(info
, UART_FCR
,
3497 UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
3498 scratch
= serial_in(info
, UART_IIR
) >> 5;
3500 state
->type
= PORT_16750
;
3502 serial_outp(info
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
3504 serial_outp(info
, UART_LCR
, scratch2
);
3505 if (state
->type
== PORT_16450
) {
3506 scratch
= serial_in(info
, UART_SCR
);
3507 serial_outp(info
, UART_SCR
, 0xa5);
3508 status1
= serial_in(info
, UART_SCR
);
3509 serial_outp(info
, UART_SCR
, 0x5a);
3510 status2
= serial_in(info
, UART_SCR
);
3511 serial_outp(info
, UART_SCR
, scratch
);
3513 if ((status1
!= 0xa5) || (status2
!= 0x5a))
3514 state
->type
= PORT_8250
;
3516 state
->xmit_fifo_size
= uart_config
[state
->type
].dfl_xmit_fifo_size
;
3518 if (state
->type
== PORT_UNKNOWN
) {
3519 restore_flags(flags
);
3524 request_region(info
->port
,8,"serial(auto)");
3529 serial_outp(info
, UART_MCR
, 0x00 | ALPHA_KLUDGE_MCR
); /* Don't ask */
3530 serial_outp(info
, UART_FCR
, (UART_FCR_CLEAR_RCVR
|
3531 UART_FCR_CLEAR_XMIT
));
3532 (void)serial_in(info
, UART_RX
);
3533 serial_outp(info
, UART_IER
, 0);
3535 restore_flags(flags
);
3538 int register_serial(struct serial_struct
*req
);
3539 void unregister_serial(int line
);
3541 #if (LINUX_VERSION_CODE > 0x20100)
3542 EXPORT_SYMBOL(register_serial
);
3543 EXPORT_SYMBOL(unregister_serial
);
3545 static struct symbol_table serial_syms
= {
3546 #include <linux/symtab_begin.h>
3548 X(unregister_serial
),
3549 #include <linux/symtab_end.h>
3553 #ifdef ENABLE_SERIAL_PCI
3555 * Some PCI serial cards using the PLX 9050 PCI interface chip require
3556 * that the card interrupt be explicitly enabled or disabled. This
3557 * seems to be mainly needed on card using the PLX which also use I/O
3560 * Note that __init is a no-op if MODULE is defined; we depend on this.
3562 static void __init
pci_plx9050_fn(struct pci_dev
*dev
,
3563 struct pci_board
*board
,
3568 pci_read_config_byte(dev
, PCI_COMMAND
, &data
);
3571 pci_write_config_byte(dev
, PCI_COMMAND
,
3572 data
| PCI_COMMAND_MEMORY
);
3574 /* enable/disable interrupts */
3575 p
= ioremap(PCI_BASE_ADDRESS(dev
, 0), 0x80);
3576 writel(enable
? 0x41 : 0x00, p
+ 0x4c);
3580 pci_write_config_byte(dev
, PCI_COMMAND
,
3581 data
& ~PCI_COMMAND_MEMORY
);
3585 * This is the configuration table for all of the PCI serial boards
3588 static struct pci_board pci_boards
[] = {
3590 * Vendor ID, Device ID,
3591 * Subvendor ID, Subdevice ID,
3592 * Number of Ports, Base (Maximum) Baud Rate,
3593 * Offset of register holding Uart register offset
3594 * Mask to apply to above register's value
3596 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3597 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3598 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232
,
3599 SPCI_FL_BASE1
, 8, 1382400 },
3600 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3601 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3602 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232
,
3603 SPCI_FL_BASE1
, 4, 1382400 },
3604 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3605 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3606 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232
,
3607 SPCI_FL_BASE1
, 2, 1382400 },
3608 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3609 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3610 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_232
,
3611 SPCI_FL_BASE1
, 8, 1382400 },
3612 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3613 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3614 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_232
,
3615 SPCI_FL_BASE1
, 4, 1382400 },
3616 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3617 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3618 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_232
,
3619 SPCI_FL_BASE1
, 2, 1382400 },
3620 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3621 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3622 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485
,
3623 SPCI_FL_BASE1
, 8, 921600 },
3624 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3625 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3626 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4
,
3627 SPCI_FL_BASE1
, 8, 921600 },
3628 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3629 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3630 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485
,
3631 SPCI_FL_BASE1
, 4, 921600 },
3632 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3633 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3634 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2
,
3635 SPCI_FL_BASE1
, 4, 921600 },
3636 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960
,
3637 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3638 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485
,
3639 SPCI_FL_BASE1
, 2, 921600 },
3640 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3641 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3642 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485
,
3643 SPCI_FL_BASE1
, 8, 921600 },
3644 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3645 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3646 PCI_SUBDEVICE_ID_CONNECT_TECH_BH8_485_4_4
,
3647 SPCI_FL_BASE1
, 8, 921600 },
3648 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3649 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3650 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485
,
3651 SPCI_FL_BASE1
, 4, 921600 },
3652 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3653 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3654 PCI_SUBDEVICE_ID_CONNECT_TECH_BH4_485_2_2
,
3655 SPCI_FL_BASE1
, 4, 921600 },
3656 { PCI_VENDOR_ID_V3
, PCI_DEVICE_ID_V3_V960V2
,
3657 PCI_SUBVENDOR_ID_CONNECT_TECH
,
3658 PCI_SUBDEVICE_ID_CONNECT_TECH_BH2_485
,
3659 SPCI_FL_BASE1
, 2, 921600 },
3660 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_U530
,
3661 PCI_ANY_ID
, PCI_ANY_ID
,
3662 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 1, 115200 },
3663 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM2
,
3664 PCI_ANY_ID
, PCI_ANY_ID
,
3665 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
3666 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM422
,
3667 PCI_ANY_ID
, PCI_ANY_ID
,
3668 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 115200 },
3669 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_UCOMM232
,
3670 PCI_ANY_ID
, PCI_ANY_ID
,
3671 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
3672 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_COMM4
,
3673 PCI_ANY_ID
, PCI_ANY_ID
,
3674 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 4, 115200 },
3675 { PCI_VENDOR_ID_SEALEVEL
, PCI_DEVICE_ID_SEALEVEL_COMM8
,
3676 PCI_ANY_ID
, PCI_ANY_ID
,
3677 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 8, 115200 },
3678 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_GTEK_SERIAL2
,
3679 PCI_ANY_ID
, PCI_ANY_ID
,
3680 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 115200 },
3681 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_SPCOM200
,
3682 PCI_ANY_ID
, PCI_ANY_ID
,
3683 SPCI_FL_BASE2
| SPCI_FL_BASE_TABLE
, 2, 921600 },
3684 { PCI_VENDOR_ID_PLX
, PCI_DEVICE_ID_PLX_9050
,
3685 PCI_SUBVENDOR_ID_KEYSPAN
,
3686 PCI_SUBDEVICE_ID_KEYSPAN_SX2
,
3687 SPCI_FL_BASE2
| SPCI_FL_IOMEM
, 2, 921600,
3688 0x400, 7, pci_plx9050_fn
},
3689 { PCI_VENDOR_ID_PANACOM
, PCI_DEVICE_ID_PANACOM_QUADMODEM
,
3690 PCI_ANY_ID
, PCI_ANY_ID
,
3691 SPCI_FL_BASE2
| SPCI_FL_IOMEM
, 4, 921600,
3692 0x400, 7, pci_plx9050_fn
},
3693 { PCI_VENDOR_ID_PANACOM
, PCI_DEVICE_ID_PANACOM_DUALMODEM
,
3694 PCI_ANY_ID
, PCI_ANY_ID
,
3695 SPCI_FL_BASE2
| SPCI_FL_IOMEM
, 2, 921600,
3696 0x400, 7, pci_plx9050_fn
},
3701 * Query PCI space for known serial boards
3702 * If found, add them to the PCI device space in rs_table[]
3704 * Accept a maximum of eight boards
3707 static void probe_serial_pci(void)
3709 u16 subvendor
, subdevice
;
3711 struct pci_dev
*dev
= NULL
;
3712 struct pci_board
*board
;
3713 struct serial_struct fake_state
;
3714 int uart_offset
, base_baud
, base_idx
;
3717 #ifdef SERIAL_DEBUG_PCI
3718 printk(KERN_DEBUG
"Entered probe_serial_pci()\n");
3721 if (!pcibios_present()) {
3722 #ifdef SERIAL_DEBUG_PCI
3723 printk(KERN_DEBUG
"Leaving probe_serial_pci() (no pcibios)\n");
3728 for(dev
=pci_devices
; dev
; dev
=dev
->next
) {
3729 pci_read_config_word(dev
, PCI_SUBSYSTEM_VENDOR_ID
,
3731 pci_read_config_word(dev
, PCI_SUBSYSTEM_ID
, &subdevice
);
3733 for (board
= pci_boards
; board
->vendor
; board
++) {
3734 if (board
->vendor
!= (unsigned short) PCI_ANY_ID
&&
3735 dev
->vendor
!= board
->vendor
)
3737 if (board
->device
!= (unsigned short) PCI_ANY_ID
&&
3738 dev
->device
!= board
->device
)
3740 if (board
->subvendor
!= (unsigned short) PCI_ANY_ID
&&
3741 subvendor
!= board
->subvendor
)
3743 if (board
->subdevice
!= (unsigned short) PCI_ANY_ID
&&
3744 subdevice
!= board
->subdevice
)
3749 if (board
->vendor
== 0) {
3750 #ifdef SERIAL_DEBUG_PCI
3752 "Found unknown serial board: %x:%x, %x:%x, %x\n",
3753 dev
->vendor
, dev
->device
, subvendor
, subdevice
,
3756 " Addresses: %lx, %lx, %lx, %lx\n",
3757 PCI_BASE_ADDRESS(dev
, 0), PCI_BASE_ADDRESS(dev
, 1),
3758 PCI_BASE_ADDRESS(dev
, 2), PCI_BASE_ADDRESS(dev
, 3));
3764 * Run the initialization function, if any
3767 (board
->init_fn
)(dev
, board
, 1);
3770 * Register the serial board in the array so we can
3771 * shutdown the board later, if necessary.
3773 serial_pci_board
[serial_pci_board_idx
].board
= board
;
3774 serial_pci_board
[serial_pci_board_idx
].dev
= dev
;
3775 serial_pci_board_idx
++;
3777 base_idx
= board
->flags
& SPCI_FL_BASE_MASK
;
3778 port
= PCI_BASE_ADDRESS(dev
, base_idx
);
3779 if (board
->flags
& SPCI_FL_IOMEM
)
3780 port
&= PCI_BASE_ADDRESS_MEM_MASK
;
3782 port
&= PCI_BASE_ADDRESS_IO_MASK
;
3785 * Set some defaults for the loop below, which
3786 * actually registers each serial port belonging to
3789 uart_offset
= board
->uart_offset
;
3792 base_baud
= board
->base_baud
;
3794 base_baud
= BASE_BAUD
;
3795 #ifndef CONFIG_SERIAL_PCI_MEMMAPPED
3796 if (board
->flags
& SPCI_FL_IOMEM
) {
3797 #ifdef SERIAL_DEBUG_PCI
3799 "Can't support memory mapped PCI serial device\n");
3804 memset(&fake_state
, 0, sizeof(fake_state
));
3806 #ifdef SERIAL_DEBUG_PCI
3808 "Found Serial PCI device: %x:%x, %x:%x, %x\n",
3809 dev
->vendor
, dev
->device
, subvendor
, subdevice
,
3812 " IRQ: %d, base: %lx (%s), num_ports: %d\n",
3813 dev
->irq
, port
, board
->flags
& SPCI_FL_IOMEM
?
3814 "iomem" : "port", board
->num_ports
);
3817 for (k
=0; k
< board
->num_ports
; k
++) {
3818 if (board
->flags
& SPCI_FL_BASE_TABLE
) {
3819 port
= PCI_BASE_ADDRESS(dev
, base_idx
++);
3820 if (board
->flags
& SPCI_FL_IOMEM
)
3821 port
&= PCI_BASE_ADDRESS_MEM_MASK
;
3823 port
&= PCI_BASE_ADDRESS_IO_MASK
;
3825 fake_state
.irq
= dev
->irq
;
3826 fake_state
.port
= port
;
3827 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
3828 if (board
->flags
& SPCI_FL_IOMEM
) {
3829 fake_state
.iomem_base
=
3830 ioremap(port
, board
->uart_offset
);
3831 fake_state
.iomem_reg_shift
= board
->reg_shift
;
3832 fake_state
.port
= 0;
3835 port
+= uart_offset
;
3836 fake_state
.flags
= ASYNC_SKIP_TEST
| ASYNC_SHARE_IRQ
;
3837 line
= register_serial(&fake_state
);
3840 rs_table
[line
].baud_base
= base_baud
;
3844 #ifdef SERIAL_DEBUG_PCI
3845 printk(KERN_DEBUG
"Leaving probe_serial_pci() (probe finished)\n");
3850 #endif /* ENABLE_SERIAL_PCI */
3853 * The serial driver boot-time initialization code!
3855 int __init
rs_init(void)
3858 struct serial_state
* state
;
3859 extern void atomwide_serial_init (void);
3860 extern void dualsp_serial_init (void);
3862 #ifdef CONFIG_ATOMWIDE_SERIAL
3863 atomwide_serial_init ();
3865 #ifdef CONFIG_DUALSP_SERIAL
3866 dualsp_serial_init ();
3869 init_bh(SERIAL_BH
, do_serial_bh
);
3870 timer_table
[RS_TIMER
].fn
= rs_timer
;
3871 timer_table
[RS_TIMER
].expires
= 0;
3873 for (i
= 0; i
< NR_IRQS
; i
++) {
3876 #ifdef CONFIG_SERIAL_MULTIPORT
3877 memset(&rs_multiport
[i
], 0,
3878 sizeof(struct rs_multiport_struct
));
3881 #ifdef CONFIG_SERIAL_CONSOLE
3883 * The interrupt of the serial console port
3886 if (sercons
.flags
& CON_CONSDEV
) {
3887 for(i
= 0; i
< NR_PORTS
; i
++)
3888 if (i
!= sercons
.index
&&
3889 rs_table
[i
].irq
== rs_table
[sercons
.index
].irq
)
3890 rs_table
[i
].irq
= 0;
3893 show_serial_version();
3895 /* Initialize the tty_driver structure */
3897 memset(&serial_driver
, 0, sizeof(struct tty_driver
));
3898 serial_driver
.magic
= TTY_DRIVER_MAGIC
;
3899 #if (LINUX_VERSION_CODE > 0x20100)
3900 serial_driver
.driver_name
= "serial";
3902 serial_driver
.name
= "ttyS";
3903 serial_driver
.major
= TTY_MAJOR
;
3904 serial_driver
.minor_start
= 64 + SERIAL_DEV_OFFSET
;
3905 serial_driver
.num
= NR_PORTS
;
3906 serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
3907 serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
3908 serial_driver
.init_termios
= tty_std_termios
;
3909 serial_driver
.init_termios
.c_cflag
=
3910 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
3911 serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
3912 serial_driver
.refcount
= &serial_refcount
;
3913 serial_driver
.table
= serial_table
;
3914 serial_driver
.termios
= serial_termios
;
3915 serial_driver
.termios_locked
= serial_termios_locked
;
3917 serial_driver
.open
= rs_open
;
3918 serial_driver
.close
= rs_close
;
3919 serial_driver
.write
= rs_write
;
3920 serial_driver
.put_char
= rs_put_char
;
3921 serial_driver
.flush_chars
= rs_flush_chars
;
3922 serial_driver
.write_room
= rs_write_room
;
3923 serial_driver
.chars_in_buffer
= rs_chars_in_buffer
;
3924 serial_driver
.flush_buffer
= rs_flush_buffer
;
3925 serial_driver
.ioctl
= rs_ioctl
;
3926 serial_driver
.throttle
= rs_throttle
;
3927 serial_driver
.unthrottle
= rs_unthrottle
;
3928 serial_driver
.set_termios
= rs_set_termios
;
3929 serial_driver
.stop
= rs_stop
;
3930 serial_driver
.start
= rs_start
;
3931 serial_driver
.hangup
= rs_hangup
;
3932 #if (LINUX_VERSION_CODE >= 131394) /* Linux 2.1.66 */
3933 serial_driver
.break_ctl
= rs_break
;
3935 #if (LINUX_VERSION_CODE >= 131343)
3936 serial_driver
.send_xchar
= rs_send_xchar
;
3937 serial_driver
.wait_until_sent
= rs_wait_until_sent
;
3938 serial_driver
.read_proc
= rs_read_proc
;
3942 * The callout device is just like normal device except for
3943 * major number and the subtype code.
3945 callout_driver
= serial_driver
;
3946 callout_driver
.name
= "cua";
3947 callout_driver
.major
= TTYAUX_MAJOR
;
3948 callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
3949 #if (LINUX_VERSION_CODE >= 131343)
3950 callout_driver
.read_proc
= 0;
3951 callout_driver
.proc_entry
= 0;
3954 if (tty_register_driver(&serial_driver
))
3955 panic("Couldn't register serial driver\n");
3956 if (tty_register_driver(&callout_driver
))
3957 panic("Couldn't register callout driver\n");
3959 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
3960 state
->magic
= SSTATE_MAGIC
;
3962 state
->type
= PORT_UNKNOWN
;
3963 state
->custom_divisor
= 0;
3964 state
->close_delay
= 5*HZ
/10;
3965 state
->closing_wait
= 30*HZ
;
3966 state
->callout_termios
= callout_driver
.init_termios
;
3967 state
->normal_termios
= serial_driver
.init_termios
;
3968 state
->icount
.cts
= state
->icount
.dsr
=
3969 state
->icount
.rng
= state
->icount
.dcd
= 0;
3970 state
->icount
.rx
= state
->icount
.tx
= 0;
3971 state
->icount
.frame
= state
->icount
.parity
= 0;
3972 state
->icount
.overrun
= state
->icount
.brk
= 0;
3973 state
->irq
= irq_cannonicalize(state
->irq
);
3974 if (state
->port
&& check_region(state
->port
,8))
3976 if (state
->flags
& ASYNC_BOOT_AUTOCONF
)
3979 for (i
= 0, state
= rs_table
; i
< NR_PORTS
; i
++,state
++) {
3980 if (state
->type
== PORT_UNKNOWN
)
3982 if ( (state
->flags
& ASYNC_BOOT_AUTOCONF
)
3983 && (state
->flags
& ASYNC_AUTO_IRQ
)
3984 && (state
->port
!= 0))
3985 state
->irq
= detect_uart_irq(state
);
3986 printk(KERN_INFO
"ttyS%02d%s at 0x%04x (irq = %d) is a %s\n",
3987 state
->line
+ SERIAL_DEV_OFFSET
,
3988 (state
->flags
& ASYNC_FOURPORT
) ? " FourPort" : "",
3989 state
->port
, state
->irq
,
3990 uart_config
[state
->type
].name
);
3992 #ifdef ENABLE_SERIAL_PCI
3999 * register_serial and unregister_serial allows for serial ports to be
4000 * configured at run-time, to support PCMCIA modems.
4002 int register_serial(struct serial_struct
*req
)
4005 unsigned long flags
;
4006 struct serial_state
*state
;
4010 for (i
= 0; i
< NR_PORTS
; i
++) {
4011 if ((rs_table
[i
].port
== req
->port
) &&
4012 (rs_table
[i
].iomem_base
== req
->iomem_base
))
4015 if (i
== NR_PORTS
) {
4016 for (i
= 0; i
< NR_PORTS
; i
++)
4017 if ((rs_table
[i
].type
== PORT_UNKNOWN
) &&
4018 (rs_table
[i
].count
== 0))
4021 if (i
== NR_PORTS
) {
4022 restore_flags(flags
);
4025 state
= &rs_table
[i
];
4026 if (rs_table
[i
].count
) {
4027 restore_flags(flags
);
4028 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
4029 "device already open\n", i
, req
->port
, req
->irq
);
4032 state
->irq
= req
->irq
;
4033 state
->port
= req
->port
;
4034 state
->flags
= req
->flags
;
4035 #ifdef CONFIG_SERIAL_PCI_MEMMAPPED
4036 state
->iomem_base
= req
->iomem_base
;
4037 state
->iomem_reg_shift
= req
->iomem_reg_shift
;
4041 if (state
->type
== PORT_UNKNOWN
) {
4042 restore_flags(flags
);
4043 printk("register_serial(): autoconfig failed\n");
4046 restore_flags(flags
);
4048 if ((state
->flags
& ASYNC_AUTO_IRQ
) && CONFIGURED_SERIAL_PORT(state
))
4049 state
->irq
= detect_uart_irq(state
);
4051 printk(KERN_INFO
"ttyS%02d at %s 0x%04lx (irq = %d) is a %s\n",
4052 state
->line
+ SERIAL_DEV_OFFSET
,
4053 state
->iomem_base
? "iomem" : "port",
4054 state
->iomem_base
? (unsigned long)state
->iomem_base
:
4055 (unsigned long)state
->port
,
4056 state
->irq
, uart_config
[state
->type
].name
);
4057 return state
->line
+ SERIAL_DEV_OFFSET
;
4060 void unregister_serial(int line
)
4062 unsigned long flags
;
4063 struct serial_state
*state
= &rs_table
[line
];
4067 if (state
->info
&& state
->info
->tty
)
4068 tty_hangup(state
->info
->tty
);
4069 state
->type
= PORT_UNKNOWN
;
4070 printk(KERN_INFO
"tty%02d unloaded\n", state
->line
);
4071 restore_flags(flags
);
4075 int init_module(void)
4080 void cleanup_module(void)
4082 unsigned long flags
;
4085 struct async_struct
*info
;
4087 /* printk("Unloading %s: version %s\n", serial_name, serial_version); */
4090 timer_active
&= ~(1 << RS_TIMER
);
4091 timer_table
[RS_TIMER
].fn
= NULL
;
4092 timer_table
[RS_TIMER
].expires
= 0;
4093 remove_bh(SERIAL_BH
);
4094 if ((e1
= tty_unregister_driver(&serial_driver
)))
4095 printk("SERIAL: failed to unregister serial driver (%d)\n",
4097 if ((e2
= tty_unregister_driver(&callout_driver
)))
4098 printk("SERIAL: failed to unregister callout driver (%d)\n",
4100 restore_flags(flags
);
4102 for (i
= 0; i
< NR_PORTS
; i
++) {
4103 if ((rs_table
[i
].type
!= PORT_UNKNOWN
) && rs_table
[i
].port
)
4104 release_region(rs_table
[i
].port
, 8);
4105 info
= rs_table
[i
].info
;
4107 rs_table
[i
].info
= NULL
;
4108 kfree_s(info
, sizeof(struct async_struct
));
4110 #if defined(ENABLE_SERIAL_PCI) && defined (CONFIG_SERIAL_PCI_MEMMAPPED)
4111 if (rs_table
[i
].iomem_base
)
4112 iounmap(rs_table
[i
].iomem_base
);
4115 #ifdef ENABLE_SERIAL_PCI
4116 for (i
=0; i
< serial_pci_board_idx
; i
++) {
4117 struct pci_board_inst
*brd
= &serial_pci_board
[i
];
4119 if (brd
->board
->init_fn
)
4120 (brd
->board
->init_fn
)(brd
->dev
, brd
->board
, 0);
4124 free_page((unsigned long) tmp_buf
);
4132 * ------------------------------------------------------------
4133 * Serial console driver
4134 * ------------------------------------------------------------
4136 #ifdef CONFIG_SERIAL_CONSOLE
4138 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
4141 * Wait for transmitter & holding register to empty
4143 static inline void wait_for_xmitr(struct serial_state
*ser
)
4146 unsigned int tmout
= 1000000;
4149 lsr
= inb(ser
->port
+ UART_LSR
);
4150 if (--tmout
== 0) break;
4151 } while ((lsr
& BOTH_EMPTY
) != BOTH_EMPTY
);
4155 * Print a string to the serial port trying not to disturb
4156 * any possible real use of the port...
4158 static void serial_console_write(struct console
*co
, const char *s
,
4161 struct serial_state
*ser
;
4165 ser
= rs_table
+ co
->index
;
4167 * First save the IER then disable the interrupts
4169 ier
= inb(ser
->port
+ UART_IER
);
4170 outb(0x00, ser
->port
+ UART_IER
);
4173 * Now, do each character
4175 for (i
= 0; i
< count
; i
++, s
++) {
4176 wait_for_xmitr(ser
);
4179 * Send the character out.
4180 * If a LF, also do CR...
4182 outb(*s
, ser
->port
+ UART_TX
);
4184 wait_for_xmitr(ser
);
4185 outb(13, ser
->port
+ UART_TX
);
4190 * Finally, Wait for transmitter & holding register to empty
4191 * and restore the IER
4193 wait_for_xmitr(ser
);
4194 outb(ier
, ser
->port
+ UART_IER
);
4198 * Receive character from the serial port
4200 static int serial_console_wait_key(struct console
*co
)
4202 struct serial_state
*ser
;
4207 ser
= rs_table
+ co
->index
;
4210 * First save the IER then disable the interrupts so
4211 * that the real driver for the port does not get the
4214 ier
= inb(ser
->port
+ UART_IER
);
4215 outb(0x00, ser
->port
+ UART_IER
);
4218 lsr
= inb(ser
->port
+ UART_LSR
);
4219 } while (!(lsr
& UART_LSR_DR
));
4220 c
= inb(ser
->port
+ UART_RX
);
4223 * Restore the interrupts
4225 outb(ier
, ser
->port
+ UART_IER
);
4230 static kdev_t
serial_console_device(struct console
*c
)
4232 return MKDEV(TTY_MAJOR
, 64 + c
->index
);
4236 * Setup initial baud/bits/parity. We do two things here:
4237 * - construct a cflag setting for the first rs_open()
4238 * - initialize the serial port
4239 * Return non-zero if we didn't find a serial port.
4241 static int __init
serial_console_setup(struct console
*co
, char *options
)
4243 struct serial_state
*ser
;
4248 int cflag
= CREAD
| HUPCL
| CLOCAL
;
4253 baud
= simple_strtoul(options
, NULL
, 10);
4255 while(*s
>= '0' && *s
<= '9')
4257 if (*s
) parity
= *s
++;
4258 if (*s
) bits
= *s
- '0';
4262 * Now construct a cflag setting.
4311 * Divisor, bytesize and parity
4313 ser
= rs_table
+ co
->index
;
4314 quot
= ser
->baud_base
/ baud
;
4315 cval
= cflag
& (CSIZE
| CSTOPB
);
4316 #if defined(__powerpc__) || defined(__alpha__)
4318 #else /* !__powerpc__ && !__alpha__ */
4320 #endif /* !__powerpc__ && !__alpha__ */
4322 cval
|= UART_LCR_PARITY
;
4323 if (!(cflag
& PARODD
))
4324 cval
|= UART_LCR_EPAR
;
4327 * Disable UART interrupts, set DTR and RTS high
4330 outb(cval
| UART_LCR_DLAB
, ser
->port
+ UART_LCR
); /* set DLAB */
4331 outb(quot
& 0xff, ser
->port
+ UART_DLL
); /* LS of divisor */
4332 outb(quot
>> 8, ser
->port
+ UART_DLM
); /* MS of divisor */
4333 outb(cval
, ser
->port
+ UART_LCR
); /* reset DLAB */
4334 outb(0, ser
->port
+ UART_IER
);
4335 outb(UART_MCR_DTR
| UART_MCR_RTS
, ser
->port
+ UART_MCR
);
4338 * If we read 0xff from the LSR, there is no UART here.
4340 if (inb(ser
->port
+ UART_LSR
) == 0xff)
4345 static struct console sercons
= {
4347 serial_console_write
,
4349 serial_console_device
,
4350 serial_console_wait_key
,
4352 serial_console_setup
,
4362 long __init
serial_console_init(long kmem_start
, long kmem_end
)
4364 register_console(&sercons
);
4371 compile-command: "gcc -D__KERNEL__ -I../../include -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -fno-strict-aliasing -D__SMP__ -pipe -fno-strength-reduce -DCPU=686 -march=i686 -DMODULE -DMODVERSIONS -include ../../include/linux/modversions.h -DEXPORT_SYMTAB -c serial.c"