2 * linux/drivers/char/8250.c
4 * Driver for 8250/16550-type serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
8 * Copyright (C) 2001 Russell King.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * A note about mapbase / membase
17 * mapbase is the physical address of the IO port.
18 * membase is an 'ioremapped' cookie.
21 #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
25 #include <linux/module.h>
26 #include <linux/moduleparam.h>
27 #include <linux/ioport.h>
28 #include <linux/init.h>
29 #include <linux/console.h>
30 #include <linux/sysrq.h>
31 #include <linux/delay.h>
32 #include <linux/platform_device.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial_reg.h>
36 #include <linux/serial_core.h>
37 #include <linux/serial.h>
38 #include <linux/serial_8250.h>
39 #include <linux/nmi.h>
40 #include <linux/mutex.h>
53 * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
54 * is unsafe when used on edge-triggered interrupts.
56 static unsigned int share_irqs
= SERIAL8250_SHARE_IRQS
;
58 static unsigned int nr_uarts
= CONFIG_SERIAL_8250_RUNTIME_UARTS
;
60 static struct uart_driver serial8250_reg
;
62 static int serial_index(struct uart_port
*port
)
64 return (serial8250_reg
.minor
- 64) + port
->line
;
71 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
73 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
77 #define DEBUG_INTR(fmt...) printk(fmt)
79 #define DEBUG_INTR(fmt...) do { } while (0)
82 #define PASS_LIMIT 256
85 * We default to IRQ0 for the "no irq" hack. Some
86 * machine types want others as well - they're free
87 * to redefine this in their header file.
89 #define is_real_interrupt(irq) ((irq) != 0)
91 #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
92 #define CONFIG_SERIAL_DETECT_IRQ 1
94 #ifdef CONFIG_SERIAL_8250_MANY_PORTS
95 #define CONFIG_SERIAL_MANY_PORTS 1
99 * HUB6 is always on. This will be removed once the header
100 * files have been cleaned.
102 #define CONFIG_HUB6 1
104 #include <asm/serial.h>
106 * SERIAL_PORT_DFNS tells us about built-in ports that have no
107 * standard enumeration mechanism. Platforms that can find all
108 * serial ports via mechanisms like ACPI or PCI need not supply it.
110 #ifndef SERIAL_PORT_DFNS
111 #define SERIAL_PORT_DFNS
114 static const struct old_serial_port old_serial_port
[] = {
115 SERIAL_PORT_DFNS
/* defined in asm/serial.h */
118 #define UART_NR CONFIG_SERIAL_8250_NR_UARTS
120 #ifdef CONFIG_SERIAL_8250_RSA
122 #define PORT_RSA_MAX 4
123 static unsigned long probe_rsa
[PORT_RSA_MAX
];
124 static unsigned int probe_rsa_count
;
125 #endif /* CONFIG_SERIAL_8250_RSA */
127 struct uart_8250_port
{
128 struct uart_port port
;
129 struct timer_list timer
; /* "no irq" timer */
130 struct list_head list
; /* ports on this IRQ */
131 unsigned short capabilities
; /* port capabilities */
132 unsigned short bugs
; /* port bugs */
133 unsigned int tx_loadsz
; /* transmit fifo load size */
138 unsigned char mcr_mask
; /* mask of user bits */
139 unsigned char mcr_force
; /* mask of forced bits */
142 * Some bits in registers are cleared on a read, so they must
143 * be saved whenever the register is read but the bits will not
144 * be immediately processed.
146 #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
147 unsigned char lsr_saved_flags
;
148 #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
149 unsigned char msr_saved_flags
;
152 * We provide a per-port pm hook.
154 void (*pm
)(struct uart_port
*port
,
155 unsigned int state
, unsigned int old
);
159 struct hlist_node node
;
161 spinlock_t lock
; /* Protects list not the hash */
162 struct list_head
*head
;
165 #define NR_IRQ_HASH 32 /* Can be adjusted later */
166 static struct hlist_head irq_lists
[NR_IRQ_HASH
];
167 static DEFINE_MUTEX(hash_mutex
); /* Used to walk the hash */
170 * Here we define the default xmit fifo size used for each type of UART.
172 static const struct serial8250_config uart_config
[] = {
197 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
198 .flags
= UART_CAP_FIFO
,
209 .flags
= UART_CAP_FIFO
| UART_CAP_EFR
| UART_CAP_SLEEP
,
215 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_01
|
217 .flags
= UART_CAP_FIFO
| UART_CAP_EFR
| UART_CAP_SLEEP
,
223 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
|
225 .flags
= UART_CAP_FIFO
| UART_CAP_SLEEP
| UART_CAP_AFE
,
233 .name
= "16C950/954",
236 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
237 .flags
= UART_CAP_FIFO
,
243 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_01
|
245 .flags
= UART_CAP_FIFO
| UART_CAP_EFR
| UART_CAP_SLEEP
,
251 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
252 .flags
= UART_CAP_FIFO
| UART_CAP_EFR
| UART_CAP_SLEEP
,
258 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_11
,
259 .flags
= UART_CAP_FIFO
,
265 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
266 .flags
= UART_CAP_FIFO
| UART_NATSEMI
,
272 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
273 .flags
= UART_CAP_FIFO
| UART_CAP_UUE
,
279 .fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_R_TRIG_10
,
280 .flags
= UART_CAP_FIFO
,
284 #if defined (CONFIG_SERIAL_8250_AU1X00)
286 /* Au1x00 UART hardware has a weird register layout */
287 static const u8 au_io_in_map
[] = {
297 static const u8 au_io_out_map
[] = {
305 /* sane hardware needs no mapping */
306 static inline int map_8250_in_reg(struct uart_port
*p
, int offset
)
308 if (p
->iotype
!= UPIO_AU
)
310 return au_io_in_map
[offset
];
313 static inline int map_8250_out_reg(struct uart_port
*p
, int offset
)
315 if (p
->iotype
!= UPIO_AU
)
317 return au_io_out_map
[offset
];
320 #elif defined(CONFIG_SERIAL_8250_RM9K)
344 static inline int map_8250_in_reg(struct uart_port
*p
, int offset
)
346 if (p
->iotype
!= UPIO_RM9000
)
348 return regmap_in
[offset
];
351 static inline int map_8250_out_reg(struct uart_port
*p
, int offset
)
353 if (p
->iotype
!= UPIO_RM9000
)
355 return regmap_out
[offset
];
360 /* sane hardware needs no mapping */
361 #define map_8250_in_reg(up, offset) (offset)
362 #define map_8250_out_reg(up, offset) (offset)
366 static unsigned int hub6_serial_in(struct uart_port
*p
, int offset
)
368 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
369 outb(p
->hub6
- 1 + offset
, p
->iobase
);
370 return inb(p
->iobase
+ 1);
373 static void hub6_serial_out(struct uart_port
*p
, int offset
, int value
)
375 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
376 outb(p
->hub6
- 1 + offset
, p
->iobase
);
377 outb(value
, p
->iobase
+ 1);
380 static unsigned int mem_serial_in(struct uart_port
*p
, int offset
)
382 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
383 return readb(p
->membase
+ offset
);
386 static void mem_serial_out(struct uart_port
*p
, int offset
, int value
)
388 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
389 writeb(value
, p
->membase
+ offset
);
392 static void mem32_serial_out(struct uart_port
*p
, int offset
, int value
)
394 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
395 writel(value
, p
->membase
+ offset
);
398 static unsigned int mem32_serial_in(struct uart_port
*p
, int offset
)
400 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
401 return readl(p
->membase
+ offset
);
404 #ifdef CONFIG_SERIAL_8250_AU1X00
405 static unsigned int au_serial_in(struct uart_port
*p
, int offset
)
407 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
408 return __raw_readl(p
->membase
+ offset
);
411 static void au_serial_out(struct uart_port
*p
, int offset
, int value
)
413 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
414 __raw_writel(value
, p
->membase
+ offset
);
418 static unsigned int tsi_serial_in(struct uart_port
*p
, int offset
)
421 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
422 if (offset
== UART_IIR
) {
423 tmp
= readl(p
->membase
+ (UART_IIR
& ~3));
424 return (tmp
>> 16) & 0xff; /* UART_IIR % 4 == 2 */
426 return readb(p
->membase
+ offset
);
429 static void tsi_serial_out(struct uart_port
*p
, int offset
, int value
)
431 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
432 if (!((offset
== UART_IER
) && (value
& UART_IER_UUE
)))
433 writeb(value
, p
->membase
+ offset
);
436 static void dwapb_serial_out(struct uart_port
*p
, int offset
, int value
)
438 int save_offset
= offset
;
439 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
440 /* Save the LCR value so it can be re-written when a
441 * Busy Detect interrupt occurs. */
442 if (save_offset
== UART_LCR
) {
443 struct uart_8250_port
*up
= (struct uart_8250_port
*)p
;
446 writeb(value
, p
->membase
+ offset
);
447 /* Read the IER to ensure any interrupt is cleared before
448 * returning from ISR. */
449 if (save_offset
== UART_TX
|| save_offset
== UART_IER
)
450 value
= p
->serial_in(p
, UART_IER
);
453 static unsigned int io_serial_in(struct uart_port
*p
, int offset
)
455 offset
= map_8250_in_reg(p
, offset
) << p
->regshift
;
456 return inb(p
->iobase
+ offset
);
459 static void io_serial_out(struct uart_port
*p
, int offset
, int value
)
461 offset
= map_8250_out_reg(p
, offset
) << p
->regshift
;
462 outb(value
, p
->iobase
+ offset
);
465 static void set_io_from_upio(struct uart_port
*p
)
469 p
->serial_in
= hub6_serial_in
;
470 p
->serial_out
= hub6_serial_out
;
474 p
->serial_in
= mem_serial_in
;
475 p
->serial_out
= mem_serial_out
;
480 p
->serial_in
= mem32_serial_in
;
481 p
->serial_out
= mem32_serial_out
;
484 #ifdef CONFIG_SERIAL_8250_AU1X00
486 p
->serial_in
= au_serial_in
;
487 p
->serial_out
= au_serial_out
;
491 p
->serial_in
= tsi_serial_in
;
492 p
->serial_out
= tsi_serial_out
;
496 p
->serial_in
= mem_serial_in
;
497 p
->serial_out
= dwapb_serial_out
;
501 p
->serial_in
= io_serial_in
;
502 p
->serial_out
= io_serial_out
;
508 serial_out_sync(struct uart_8250_port
*up
, int offset
, int value
)
510 struct uart_port
*p
= &up
->port
;
514 #ifdef CONFIG_SERIAL_8250_AU1X00
518 p
->serial_out(p
, offset
, value
);
519 p
->serial_in(p
, UART_LCR
); /* safe, no side-effects */
522 p
->serial_out(p
, offset
, value
);
526 #define serial_in(up, offset) \
527 (up->port.serial_in(&(up)->port, (offset)))
528 #define serial_out(up, offset, value) \
529 (up->port.serial_out(&(up)->port, (offset), (value)))
531 * We used to support using pause I/O for certain machines. We
532 * haven't supported this for a while, but just in case it's badly
533 * needed for certain old 386 machines, I've left these #define's
536 #define serial_inp(up, offset) serial_in(up, offset)
537 #define serial_outp(up, offset, value) serial_out(up, offset, value)
539 /* Uart divisor latch read */
540 static inline int _serial_dl_read(struct uart_8250_port
*up
)
542 return serial_inp(up
, UART_DLL
) | serial_inp(up
, UART_DLM
) << 8;
545 /* Uart divisor latch write */
546 static inline void _serial_dl_write(struct uart_8250_port
*up
, int value
)
548 serial_outp(up
, UART_DLL
, value
& 0xff);
549 serial_outp(up
, UART_DLM
, value
>> 8 & 0xff);
552 #if defined(CONFIG_SERIAL_8250_AU1X00)
553 /* Au1x00 haven't got a standard divisor latch */
554 static int serial_dl_read(struct uart_8250_port
*up
)
556 if (up
->port
.iotype
== UPIO_AU
)
557 return __raw_readl(up
->port
.membase
+ 0x28);
559 return _serial_dl_read(up
);
562 static void serial_dl_write(struct uart_8250_port
*up
, int value
)
564 if (up
->port
.iotype
== UPIO_AU
)
565 __raw_writel(value
, up
->port
.membase
+ 0x28);
567 _serial_dl_write(up
, value
);
569 #elif defined(CONFIG_SERIAL_8250_RM9K)
570 static int serial_dl_read(struct uart_8250_port
*up
)
572 return (up
->port
.iotype
== UPIO_RM9000
) ?
573 (((__raw_readl(up
->port
.membase
+ 0x10) << 8) |
574 (__raw_readl(up
->port
.membase
+ 0x08) & 0xff)) & 0xffff) :
578 static void serial_dl_write(struct uart_8250_port
*up
, int value
)
580 if (up
->port
.iotype
== UPIO_RM9000
) {
581 __raw_writel(value
, up
->port
.membase
+ 0x08);
582 __raw_writel(value
>> 8, up
->port
.membase
+ 0x10);
584 _serial_dl_write(up
, value
);
588 #define serial_dl_read(up) _serial_dl_read(up)
589 #define serial_dl_write(up, value) _serial_dl_write(up, value)
595 static void serial_icr_write(struct uart_8250_port
*up
, int offset
, int value
)
597 serial_out(up
, UART_SCR
, offset
);
598 serial_out(up
, UART_ICR
, value
);
601 static unsigned int serial_icr_read(struct uart_8250_port
*up
, int offset
)
605 serial_icr_write(up
, UART_ACR
, up
->acr
| UART_ACR_ICRRD
);
606 serial_out(up
, UART_SCR
, offset
);
607 value
= serial_in(up
, UART_ICR
);
608 serial_icr_write(up
, UART_ACR
, up
->acr
);
616 static void serial8250_clear_fifos(struct uart_8250_port
*p
)
618 if (p
->capabilities
& UART_CAP_FIFO
) {
619 serial_outp(p
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
620 serial_outp(p
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
621 UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
);
622 serial_outp(p
, UART_FCR
, 0);
627 * IER sleep support. UARTs which have EFRs need the "extended
628 * capability" bit enabled. Note that on XR16C850s, we need to
629 * reset LCR to write to IER.
631 static void serial8250_set_sleep(struct uart_8250_port
*p
, int sleep
)
633 if (p
->capabilities
& UART_CAP_SLEEP
) {
634 if (p
->capabilities
& UART_CAP_EFR
) {
635 serial_outp(p
, UART_LCR
, 0xBF);
636 serial_outp(p
, UART_EFR
, UART_EFR_ECB
);
637 serial_outp(p
, UART_LCR
, 0);
639 serial_outp(p
, UART_IER
, sleep
? UART_IERX_SLEEP
: 0);
640 if (p
->capabilities
& UART_CAP_EFR
) {
641 serial_outp(p
, UART_LCR
, 0xBF);
642 serial_outp(p
, UART_EFR
, 0);
643 serial_outp(p
, UART_LCR
, 0);
648 #ifdef CONFIG_SERIAL_8250_RSA
650 * Attempts to turn on the RSA FIFO. Returns zero on failure.
651 * We set the port uart clock rate if we succeed.
653 static int __enable_rsa(struct uart_8250_port
*up
)
658 mode
= serial_inp(up
, UART_RSA_MSR
);
659 result
= mode
& UART_RSA_MSR_FIFO
;
662 serial_outp(up
, UART_RSA_MSR
, mode
| UART_RSA_MSR_FIFO
);
663 mode
= serial_inp(up
, UART_RSA_MSR
);
664 result
= mode
& UART_RSA_MSR_FIFO
;
668 up
->port
.uartclk
= SERIAL_RSA_BAUD_BASE
* 16;
673 static void enable_rsa(struct uart_8250_port
*up
)
675 if (up
->port
.type
== PORT_RSA
) {
676 if (up
->port
.uartclk
!= SERIAL_RSA_BAUD_BASE
* 16) {
677 spin_lock_irq(&up
->port
.lock
);
679 spin_unlock_irq(&up
->port
.lock
);
681 if (up
->port
.uartclk
== SERIAL_RSA_BAUD_BASE
* 16)
682 serial_outp(up
, UART_RSA_FRR
, 0);
687 * Attempts to turn off the RSA FIFO. Returns zero on failure.
688 * It is unknown why interrupts were disabled in here. However,
689 * the caller is expected to preserve this behaviour by grabbing
690 * the spinlock before calling this function.
692 static void disable_rsa(struct uart_8250_port
*up
)
697 if (up
->port
.type
== PORT_RSA
&&
698 up
->port
.uartclk
== SERIAL_RSA_BAUD_BASE
* 16) {
699 spin_lock_irq(&up
->port
.lock
);
701 mode
= serial_inp(up
, UART_RSA_MSR
);
702 result
= !(mode
& UART_RSA_MSR_FIFO
);
705 serial_outp(up
, UART_RSA_MSR
, mode
& ~UART_RSA_MSR_FIFO
);
706 mode
= serial_inp(up
, UART_RSA_MSR
);
707 result
= !(mode
& UART_RSA_MSR_FIFO
);
711 up
->port
.uartclk
= SERIAL_RSA_BAUD_BASE_LO
* 16;
712 spin_unlock_irq(&up
->port
.lock
);
715 #endif /* CONFIG_SERIAL_8250_RSA */
718 * This is a quickie test to see how big the FIFO is.
719 * It doesn't work at all the time, more's the pity.
721 static int size_fifo(struct uart_8250_port
*up
)
723 unsigned char old_fcr
, old_mcr
, old_lcr
;
724 unsigned short old_dl
;
727 old_lcr
= serial_inp(up
, UART_LCR
);
728 serial_outp(up
, UART_LCR
, 0);
729 old_fcr
= serial_inp(up
, UART_FCR
);
730 old_mcr
= serial_inp(up
, UART_MCR
);
731 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
|
732 UART_FCR_CLEAR_RCVR
| UART_FCR_CLEAR_XMIT
);
733 serial_outp(up
, UART_MCR
, UART_MCR_LOOP
);
734 serial_outp(up
, UART_LCR
, UART_LCR_DLAB
);
735 old_dl
= serial_dl_read(up
);
736 serial_dl_write(up
, 0x0001);
737 serial_outp(up
, UART_LCR
, 0x03);
738 for (count
= 0; count
< 256; count
++)
739 serial_outp(up
, UART_TX
, count
);
740 mdelay(20);/* FIXME - schedule_timeout */
741 for (count
= 0; (serial_inp(up
, UART_LSR
) & UART_LSR_DR
) &&
742 (count
< 256); count
++)
743 serial_inp(up
, UART_RX
);
744 serial_outp(up
, UART_FCR
, old_fcr
);
745 serial_outp(up
, UART_MCR
, old_mcr
);
746 serial_outp(up
, UART_LCR
, UART_LCR_DLAB
);
747 serial_dl_write(up
, old_dl
);
748 serial_outp(up
, UART_LCR
, old_lcr
);
754 * Read UART ID using the divisor method - set DLL and DLM to zero
755 * and the revision will be in DLL and device type in DLM. We
756 * preserve the device state across this.
758 static unsigned int autoconfig_read_divisor_id(struct uart_8250_port
*p
)
760 unsigned char old_dll
, old_dlm
, old_lcr
;
763 old_lcr
= serial_inp(p
, UART_LCR
);
764 serial_outp(p
, UART_LCR
, UART_LCR_DLAB
);
766 old_dll
= serial_inp(p
, UART_DLL
);
767 old_dlm
= serial_inp(p
, UART_DLM
);
769 serial_outp(p
, UART_DLL
, 0);
770 serial_outp(p
, UART_DLM
, 0);
772 id
= serial_inp(p
, UART_DLL
) | serial_inp(p
, UART_DLM
) << 8;
774 serial_outp(p
, UART_DLL
, old_dll
);
775 serial_outp(p
, UART_DLM
, old_dlm
);
776 serial_outp(p
, UART_LCR
, old_lcr
);
782 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
783 * When this function is called we know it is at least a StarTech
784 * 16650 V2, but it might be one of several StarTech UARTs, or one of
785 * its clones. (We treat the broken original StarTech 16650 V1 as a
786 * 16550, and why not? Startech doesn't seem to even acknowledge its
789 * What evil have men's minds wrought...
791 static void autoconfig_has_efr(struct uart_8250_port
*up
)
793 unsigned int id1
, id2
, id3
, rev
;
796 * Everything with an EFR has SLEEP
798 up
->capabilities
|= UART_CAP_EFR
| UART_CAP_SLEEP
;
801 * First we check to see if it's an Oxford Semiconductor UART.
803 * If we have to do this here because some non-National
804 * Semiconductor clone chips lock up if you try writing to the
805 * LSR register (which serial_icr_read does)
809 * Check for Oxford Semiconductor 16C950.
811 * EFR [4] must be set else this test fails.
813 * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
814 * claims that it's needed for 952 dual UART's (which are not
815 * recommended for new designs).
818 serial_out(up
, UART_LCR
, 0xBF);
819 serial_out(up
, UART_EFR
, UART_EFR_ECB
);
820 serial_out(up
, UART_LCR
, 0x00);
821 id1
= serial_icr_read(up
, UART_ID1
);
822 id2
= serial_icr_read(up
, UART_ID2
);
823 id3
= serial_icr_read(up
, UART_ID3
);
824 rev
= serial_icr_read(up
, UART_REV
);
826 DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1
, id2
, id3
, rev
);
828 if (id1
== 0x16 && id2
== 0xC9 &&
829 (id3
== 0x50 || id3
== 0x52 || id3
== 0x54)) {
830 up
->port
.type
= PORT_16C950
;
833 * Enable work around for the Oxford Semiconductor 952 rev B
834 * chip which causes it to seriously miscalculate baud rates
837 if (id3
== 0x52 && rev
== 0x01)
838 up
->bugs
|= UART_BUG_QUOT
;
843 * We check for a XR16C850 by setting DLL and DLM to 0, and then
844 * reading back DLL and DLM. The chip type depends on the DLM
846 * 0x10 - XR16C850 and the DLL contains the chip revision.
850 id1
= autoconfig_read_divisor_id(up
);
851 DEBUG_AUTOCONF("850id=%04x ", id1
);
854 if (id2
== 0x10 || id2
== 0x12 || id2
== 0x14) {
855 up
->port
.type
= PORT_16850
;
860 * It wasn't an XR16C850.
862 * We distinguish between the '654 and the '650 by counting
863 * how many bytes are in the FIFO. I'm using this for now,
864 * since that's the technique that was sent to me in the
865 * serial driver update, but I'm not convinced this works.
866 * I've had problems doing this in the past. -TYT
868 if (size_fifo(up
) == 64)
869 up
->port
.type
= PORT_16654
;
871 up
->port
.type
= PORT_16650V2
;
875 * We detected a chip without a FIFO. Only two fall into
876 * this category - the original 8250 and the 16450. The
877 * 16450 has a scratch register (accessible with LCR=0)
879 static void autoconfig_8250(struct uart_8250_port
*up
)
881 unsigned char scratch
, status1
, status2
;
883 up
->port
.type
= PORT_8250
;
885 scratch
= serial_in(up
, UART_SCR
);
886 serial_outp(up
, UART_SCR
, 0xa5);
887 status1
= serial_in(up
, UART_SCR
);
888 serial_outp(up
, UART_SCR
, 0x5a);
889 status2
= serial_in(up
, UART_SCR
);
890 serial_outp(up
, UART_SCR
, scratch
);
892 if (status1
== 0xa5 && status2
== 0x5a)
893 up
->port
.type
= PORT_16450
;
896 static int broken_efr(struct uart_8250_port
*up
)
899 * Exar ST16C2550 "A2" devices incorrectly detect as
900 * having an EFR, and report an ID of 0x0201. See
901 * http://www.exar.com/info.php?pdf=dan180_oct2004.pdf
903 if (autoconfig_read_divisor_id(up
) == 0x0201 && size_fifo(up
) == 16)
910 * We know that the chip has FIFOs. Does it have an EFR? The
911 * EFR is located in the same register position as the IIR and
912 * we know the top two bits of the IIR are currently set. The
913 * EFR should contain zero. Try to read the EFR.
915 static void autoconfig_16550a(struct uart_8250_port
*up
)
917 unsigned char status1
, status2
;
918 unsigned int iersave
;
920 up
->port
.type
= PORT_16550A
;
921 up
->capabilities
|= UART_CAP_FIFO
;
924 * Check for presence of the EFR when DLAB is set.
925 * Only ST16C650V1 UARTs pass this test.
927 serial_outp(up
, UART_LCR
, UART_LCR_DLAB
);
928 if (serial_in(up
, UART_EFR
) == 0) {
929 serial_outp(up
, UART_EFR
, 0xA8);
930 if (serial_in(up
, UART_EFR
) != 0) {
931 DEBUG_AUTOCONF("EFRv1 ");
932 up
->port
.type
= PORT_16650
;
933 up
->capabilities
|= UART_CAP_EFR
| UART_CAP_SLEEP
;
935 DEBUG_AUTOCONF("Motorola 8xxx DUART ");
937 serial_outp(up
, UART_EFR
, 0);
942 * Maybe it requires 0xbf to be written to the LCR.
943 * (other ST16C650V2 UARTs, TI16C752A, etc)
945 serial_outp(up
, UART_LCR
, 0xBF);
946 if (serial_in(up
, UART_EFR
) == 0 && !broken_efr(up
)) {
947 DEBUG_AUTOCONF("EFRv2 ");
948 autoconfig_has_efr(up
);
953 * Check for a National Semiconductor SuperIO chip.
954 * Attempt to switch to bank 2, read the value of the LOOP bit
955 * from EXCR1. Switch back to bank 0, change it in MCR. Then
956 * switch back to bank 2, read it from EXCR1 again and check
957 * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
959 serial_outp(up
, UART_LCR
, 0);
960 status1
= serial_in(up
, UART_MCR
);
961 serial_outp(up
, UART_LCR
, 0xE0);
962 status2
= serial_in(up
, 0x02); /* EXCR1 */
964 if (!((status2
^ status1
) & UART_MCR_LOOP
)) {
965 serial_outp(up
, UART_LCR
, 0);
966 serial_outp(up
, UART_MCR
, status1
^ UART_MCR_LOOP
);
967 serial_outp(up
, UART_LCR
, 0xE0);
968 status2
= serial_in(up
, 0x02); /* EXCR1 */
969 serial_outp(up
, UART_LCR
, 0);
970 serial_outp(up
, UART_MCR
, status1
);
972 if ((status2
^ status1
) & UART_MCR_LOOP
) {
975 serial_outp(up
, UART_LCR
, 0xE0);
977 quot
= serial_dl_read(up
);
980 status1
= serial_in(up
, 0x04); /* EXCR2 */
981 status1
&= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
982 status1
|= 0x10; /* 1.625 divisor for baud_base --> 921600 */
983 serial_outp(up
, 0x04, status1
);
985 serial_dl_write(up
, quot
);
987 serial_outp(up
, UART_LCR
, 0);
989 up
->port
.uartclk
= 921600*16;
990 up
->port
.type
= PORT_NS16550A
;
991 up
->capabilities
|= UART_NATSEMI
;
997 * No EFR. Try to detect a TI16750, which only sets bit 5 of
998 * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
999 * Try setting it with and without DLAB set. Cheap clones
1000 * set bit 5 without DLAB set.
1002 serial_outp(up
, UART_LCR
, 0);
1003 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
1004 status1
= serial_in(up
, UART_IIR
) >> 5;
1005 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1006 serial_outp(up
, UART_LCR
, UART_LCR_DLAB
);
1007 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
| UART_FCR7_64BYTE
);
1008 status2
= serial_in(up
, UART_IIR
) >> 5;
1009 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1010 serial_outp(up
, UART_LCR
, 0);
1012 DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1
, status2
);
1014 if (status1
== 6 && status2
== 7) {
1015 up
->port
.type
= PORT_16750
;
1016 up
->capabilities
|= UART_CAP_AFE
| UART_CAP_SLEEP
;
1021 * Try writing and reading the UART_IER_UUE bit (b6).
1022 * If it works, this is probably one of the Xscale platform's
1024 * We're going to explicitly set the UUE bit to 0 before
1025 * trying to write and read a 1 just to make sure it's not
1026 * already a 1 and maybe locked there before we even start start.
1028 iersave
= serial_in(up
, UART_IER
);
1029 serial_outp(up
, UART_IER
, iersave
& ~UART_IER_UUE
);
1030 if (!(serial_in(up
, UART_IER
) & UART_IER_UUE
)) {
1032 * OK it's in a known zero state, try writing and reading
1033 * without disturbing the current state of the other bits.
1035 serial_outp(up
, UART_IER
, iersave
| UART_IER_UUE
);
1036 if (serial_in(up
, UART_IER
) & UART_IER_UUE
) {
1039 * We'll leave the UART_IER_UUE bit set to 1 (enabled).
1041 DEBUG_AUTOCONF("Xscale ");
1042 up
->port
.type
= PORT_XSCALE
;
1043 up
->capabilities
|= UART_CAP_UUE
;
1048 * If we got here we couldn't force the IER_UUE bit to 0.
1049 * Log it and continue.
1051 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
1053 serial_outp(up
, UART_IER
, iersave
);
1057 * This routine is called by rs_init() to initialize a specific serial
1058 * port. It determines what type of UART chip this serial port is
1059 * using: 8250, 16450, 16550, 16550A. The important question is
1060 * whether or not this UART is a 16550A or not, since this will
1061 * determine whether or not we can use its FIFO features or not.
1063 static void autoconfig(struct uart_8250_port
*up
, unsigned int probeflags
)
1065 unsigned char status1
, scratch
, scratch2
, scratch3
;
1066 unsigned char save_lcr
, save_mcr
;
1067 unsigned long flags
;
1069 if (!up
->port
.iobase
&& !up
->port
.mapbase
&& !up
->port
.membase
)
1072 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
1073 serial_index(&up
->port
), up
->port
.iobase
, up
->port
.membase
);
1076 * We really do need global IRQs disabled here - we're going to
1077 * be frobbing the chips IRQ enable register to see if it exists.
1079 spin_lock_irqsave(&up
->port
.lock
, flags
);
1081 up
->capabilities
= 0;
1084 if (!(up
->port
.flags
& UPF_BUGGY_UART
)) {
1086 * Do a simple existence test first; if we fail this,
1087 * there's no point trying anything else.
1089 * 0x80 is used as a nonsense port to prevent against
1090 * false positives due to ISA bus float. The
1091 * assumption is that 0x80 is a non-existent port;
1092 * which should be safe since include/asm/io.h also
1093 * makes this assumption.
1095 * Note: this is safe as long as MCR bit 4 is clear
1096 * and the device is in "PC" mode.
1098 scratch
= serial_inp(up
, UART_IER
);
1099 serial_outp(up
, UART_IER
, 0);
1104 * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
1105 * 16C754B) allow only to modify them if an EFR bit is set.
1107 scratch2
= serial_inp(up
, UART_IER
) & 0x0f;
1108 serial_outp(up
, UART_IER
, 0x0F);
1112 scratch3
= serial_inp(up
, UART_IER
) & 0x0f;
1113 serial_outp(up
, UART_IER
, scratch
);
1114 if (scratch2
!= 0 || scratch3
!= 0x0F) {
1116 * We failed; there's nothing here
1118 DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
1119 scratch2
, scratch3
);
1124 save_mcr
= serial_in(up
, UART_MCR
);
1125 save_lcr
= serial_in(up
, UART_LCR
);
1128 * Check to see if a UART is really there. Certain broken
1129 * internal modems based on the Rockwell chipset fail this
1130 * test, because they apparently don't implement the loopback
1131 * test mode. So this test is skipped on the COM 1 through
1132 * COM 4 ports. This *should* be safe, since no board
1133 * manufacturer would be stupid enough to design a board
1134 * that conflicts with COM 1-4 --- we hope!
1136 if (!(up
->port
.flags
& UPF_SKIP_TEST
)) {
1137 serial_outp(up
, UART_MCR
, UART_MCR_LOOP
| 0x0A);
1138 status1
= serial_inp(up
, UART_MSR
) & 0xF0;
1139 serial_outp(up
, UART_MCR
, save_mcr
);
1140 if (status1
!= 0x90) {
1141 DEBUG_AUTOCONF("LOOP test failed (%02x) ",
1148 * We're pretty sure there's a port here. Lets find out what
1149 * type of port it is. The IIR top two bits allows us to find
1150 * out if it's 8250 or 16450, 16550, 16550A or later. This
1151 * determines what we test for next.
1153 * We also initialise the EFR (if any) to zero for later. The
1154 * EFR occupies the same register location as the FCR and IIR.
1156 serial_outp(up
, UART_LCR
, 0xBF);
1157 serial_outp(up
, UART_EFR
, 0);
1158 serial_outp(up
, UART_LCR
, 0);
1160 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
1161 scratch
= serial_in(up
, UART_IIR
) >> 6;
1163 DEBUG_AUTOCONF("iir=%d ", scratch
);
1167 autoconfig_8250(up
);
1170 up
->port
.type
= PORT_UNKNOWN
;
1173 up
->port
.type
= PORT_16550
;
1176 autoconfig_16550a(up
);
1180 #ifdef CONFIG_SERIAL_8250_RSA
1182 * Only probe for RSA ports if we got the region.
1184 if (up
->port
.type
== PORT_16550A
&& probeflags
& PROBE_RSA
) {
1187 for (i
= 0 ; i
< probe_rsa_count
; ++i
) {
1188 if (probe_rsa
[i
] == up
->port
.iobase
&&
1190 up
->port
.type
= PORT_RSA
;
1197 #ifdef CONFIG_SERIAL_8250_AU1X00
1198 /* if access method is AU, it is a 16550 with a quirk */
1199 if (up
->port
.type
== PORT_16550A
&& up
->port
.iotype
== UPIO_AU
)
1200 up
->bugs
|= UART_BUG_NOMSR
;
1203 serial_outp(up
, UART_LCR
, save_lcr
);
1205 if (up
->capabilities
!= uart_config
[up
->port
.type
].flags
) {
1207 "ttyS%d: detected caps %08x should be %08x\n",
1208 serial_index(&up
->port
), up
->capabilities
,
1209 uart_config
[up
->port
.type
].flags
);
1212 up
->port
.fifosize
= uart_config
[up
->port
.type
].fifo_size
;
1213 up
->capabilities
= uart_config
[up
->port
.type
].flags
;
1214 up
->tx_loadsz
= uart_config
[up
->port
.type
].tx_loadsz
;
1216 if (up
->port
.type
== PORT_UNKNOWN
)
1222 #ifdef CONFIG_SERIAL_8250_RSA
1223 if (up
->port
.type
== PORT_RSA
)
1224 serial_outp(up
, UART_RSA_FRR
, 0);
1226 serial_outp(up
, UART_MCR
, save_mcr
);
1227 serial8250_clear_fifos(up
);
1228 serial_in(up
, UART_RX
);
1229 if (up
->capabilities
& UART_CAP_UUE
)
1230 serial_outp(up
, UART_IER
, UART_IER_UUE
);
1232 serial_outp(up
, UART_IER
, 0);
1235 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1236 DEBUG_AUTOCONF("type=%s\n", uart_config
[up
->port
.type
].name
);
1239 static void autoconfig_irq(struct uart_8250_port
*up
)
1241 unsigned char save_mcr
, save_ier
;
1242 unsigned char save_ICP
= 0;
1243 unsigned int ICP
= 0;
1247 if (up
->port
.flags
& UPF_FOURPORT
) {
1248 ICP
= (up
->port
.iobase
& 0xfe0) | 0x1f;
1249 save_ICP
= inb_p(ICP
);
1254 /* forget possible initially masked and pending IRQ */
1255 probe_irq_off(probe_irq_on());
1256 save_mcr
= serial_inp(up
, UART_MCR
);
1257 save_ier
= serial_inp(up
, UART_IER
);
1258 serial_outp(up
, UART_MCR
, UART_MCR_OUT1
| UART_MCR_OUT2
);
1260 irqs
= probe_irq_on();
1261 serial_outp(up
, UART_MCR
, 0);
1263 if (up
->port
.flags
& UPF_FOURPORT
) {
1264 serial_outp(up
, UART_MCR
,
1265 UART_MCR_DTR
| UART_MCR_RTS
);
1267 serial_outp(up
, UART_MCR
,
1268 UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
);
1270 serial_outp(up
, UART_IER
, 0x0f); /* enable all intrs */
1271 (void)serial_inp(up
, UART_LSR
);
1272 (void)serial_inp(up
, UART_RX
);
1273 (void)serial_inp(up
, UART_IIR
);
1274 (void)serial_inp(up
, UART_MSR
);
1275 serial_outp(up
, UART_TX
, 0xFF);
1277 irq
= probe_irq_off(irqs
);
1279 serial_outp(up
, UART_MCR
, save_mcr
);
1280 serial_outp(up
, UART_IER
, save_ier
);
1282 if (up
->port
.flags
& UPF_FOURPORT
)
1283 outb_p(save_ICP
, ICP
);
1285 up
->port
.irq
= (irq
> 0) ? irq
: 0;
1288 static inline void __stop_tx(struct uart_8250_port
*p
)
1290 if (p
->ier
& UART_IER_THRI
) {
1291 p
->ier
&= ~UART_IER_THRI
;
1292 serial_out(p
, UART_IER
, p
->ier
);
1296 static void serial8250_stop_tx(struct uart_port
*port
)
1298 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1303 * We really want to stop the transmitter from sending.
1305 if (up
->port
.type
== PORT_16C950
) {
1306 up
->acr
|= UART_ACR_TXDIS
;
1307 serial_icr_write(up
, UART_ACR
, up
->acr
);
1311 static void transmit_chars(struct uart_8250_port
*up
);
1313 static void serial8250_start_tx(struct uart_port
*port
)
1315 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1317 if (!(up
->ier
& UART_IER_THRI
)) {
1318 up
->ier
|= UART_IER_THRI
;
1319 serial_out(up
, UART_IER
, up
->ier
);
1321 if (up
->bugs
& UART_BUG_TXEN
) {
1322 unsigned char lsr
, iir
;
1323 lsr
= serial_in(up
, UART_LSR
);
1324 up
->lsr_saved_flags
|= lsr
& LSR_SAVE_FLAGS
;
1325 iir
= serial_in(up
, UART_IIR
) & 0x0f;
1326 if ((up
->port
.type
== PORT_RM9000
) ?
1327 (lsr
& UART_LSR_THRE
&&
1328 (iir
== UART_IIR_NO_INT
|| iir
== UART_IIR_THRI
)) :
1329 (lsr
& UART_LSR_TEMT
&& iir
& UART_IIR_NO_INT
))
1335 * Re-enable the transmitter if we disabled it.
1337 if (up
->port
.type
== PORT_16C950
&& up
->acr
& UART_ACR_TXDIS
) {
1338 up
->acr
&= ~UART_ACR_TXDIS
;
1339 serial_icr_write(up
, UART_ACR
, up
->acr
);
1343 static void serial8250_stop_rx(struct uart_port
*port
)
1345 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1347 up
->ier
&= ~UART_IER_RLSI
;
1348 up
->port
.read_status_mask
&= ~UART_LSR_DR
;
1349 serial_out(up
, UART_IER
, up
->ier
);
1352 static void serial8250_enable_ms(struct uart_port
*port
)
1354 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1356 /* no MSR capabilities */
1357 if (up
->bugs
& UART_BUG_NOMSR
)
1360 up
->ier
|= UART_IER_MSI
;
1361 serial_out(up
, UART_IER
, up
->ier
);
1365 receive_chars(struct uart_8250_port
*up
, unsigned int *status
)
1367 struct tty_struct
*tty
= up
->port
.info
->port
.tty
;
1368 unsigned char ch
, lsr
= *status
;
1369 int max_count
= 256;
1373 if (likely(lsr
& UART_LSR_DR
))
1374 ch
= serial_inp(up
, UART_RX
);
1377 * Intel 82571 has a Serial Over Lan device that will
1378 * set UART_LSR_BI without setting UART_LSR_DR when
1379 * it receives a break. To avoid reading from the
1380 * receive buffer without UART_LSR_DR bit set, we
1381 * just force the read character to be 0
1386 up
->port
.icount
.rx
++;
1388 lsr
|= up
->lsr_saved_flags
;
1389 up
->lsr_saved_flags
= 0;
1391 if (unlikely(lsr
& UART_LSR_BRK_ERROR_BITS
)) {
1393 * For statistics only
1395 if (lsr
& UART_LSR_BI
) {
1396 lsr
&= ~(UART_LSR_FE
| UART_LSR_PE
);
1397 up
->port
.icount
.brk
++;
1399 * We do the SysRQ and SAK checking
1400 * here because otherwise the break
1401 * may get masked by ignore_status_mask
1402 * or read_status_mask.
1404 if (uart_handle_break(&up
->port
))
1406 } else if (lsr
& UART_LSR_PE
)
1407 up
->port
.icount
.parity
++;
1408 else if (lsr
& UART_LSR_FE
)
1409 up
->port
.icount
.frame
++;
1410 if (lsr
& UART_LSR_OE
)
1411 up
->port
.icount
.overrun
++;
1414 * Mask off conditions which should be ignored.
1416 lsr
&= up
->port
.read_status_mask
;
1418 if (lsr
& UART_LSR_BI
) {
1419 DEBUG_INTR("handling break....");
1421 } else if (lsr
& UART_LSR_PE
)
1423 else if (lsr
& UART_LSR_FE
)
1426 if (uart_handle_sysrq_char(&up
->port
, ch
))
1429 uart_insert_char(&up
->port
, lsr
, UART_LSR_OE
, ch
, flag
);
1432 lsr
= serial_inp(up
, UART_LSR
);
1433 } while ((lsr
& (UART_LSR_DR
| UART_LSR_BI
)) && (max_count
-- > 0));
1434 spin_unlock(&up
->port
.lock
);
1435 tty_flip_buffer_push(tty
);
1436 spin_lock(&up
->port
.lock
);
1440 static void transmit_chars(struct uart_8250_port
*up
)
1442 struct circ_buf
*xmit
= &up
->port
.info
->xmit
;
1445 if (up
->port
.x_char
) {
1446 serial_outp(up
, UART_TX
, up
->port
.x_char
);
1447 up
->port
.icount
.tx
++;
1448 up
->port
.x_char
= 0;
1451 if (uart_tx_stopped(&up
->port
)) {
1452 serial8250_stop_tx(&up
->port
);
1455 if (uart_circ_empty(xmit
)) {
1460 count
= up
->tx_loadsz
;
1462 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
1463 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
1464 up
->port
.icount
.tx
++;
1465 if (uart_circ_empty(xmit
))
1467 } while (--count
> 0);
1469 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
1470 uart_write_wakeup(&up
->port
);
1472 DEBUG_INTR("THRE...");
1474 if (uart_circ_empty(xmit
))
1478 static unsigned int check_modem_status(struct uart_8250_port
*up
)
1480 unsigned int status
= serial_in(up
, UART_MSR
);
1482 status
|= up
->msr_saved_flags
;
1483 up
->msr_saved_flags
= 0;
1484 if (status
& UART_MSR_ANY_DELTA
&& up
->ier
& UART_IER_MSI
&&
1485 up
->port
.info
!= NULL
) {
1486 if (status
& UART_MSR_TERI
)
1487 up
->port
.icount
.rng
++;
1488 if (status
& UART_MSR_DDSR
)
1489 up
->port
.icount
.dsr
++;
1490 if (status
& UART_MSR_DDCD
)
1491 uart_handle_dcd_change(&up
->port
, status
& UART_MSR_DCD
);
1492 if (status
& UART_MSR_DCTS
)
1493 uart_handle_cts_change(&up
->port
, status
& UART_MSR_CTS
);
1495 wake_up_interruptible(&up
->port
.info
->delta_msr_wait
);
1502 * This handles the interrupt from one port.
1504 static void serial8250_handle_port(struct uart_8250_port
*up
)
1506 unsigned int status
;
1507 unsigned long flags
;
1509 spin_lock_irqsave(&up
->port
.lock
, flags
);
1511 status
= serial_inp(up
, UART_LSR
);
1513 DEBUG_INTR("status = %x...", status
);
1515 if (status
& (UART_LSR_DR
| UART_LSR_BI
))
1516 receive_chars(up
, &status
);
1517 check_modem_status(up
);
1518 if (status
& UART_LSR_THRE
)
1521 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1525 * This is the serial driver's interrupt routine.
1527 * Arjan thinks the old way was overly complex, so it got simplified.
1528 * Alan disagrees, saying that need the complexity to handle the weird
1529 * nature of ISA shared interrupts. (This is a special exception.)
1531 * In order to handle ISA shared interrupts properly, we need to check
1532 * that all ports have been serviced, and therefore the ISA interrupt
1533 * line has been de-asserted.
1535 * This means we need to loop through all ports. checking that they
1536 * don't have an interrupt pending.
1538 static irqreturn_t
serial8250_interrupt(int irq
, void *dev_id
)
1540 struct irq_info
*i
= dev_id
;
1541 struct list_head
*l
, *end
= NULL
;
1542 int pass_counter
= 0, handled
= 0;
1544 DEBUG_INTR("serial8250_interrupt(%d)...", irq
);
1546 spin_lock(&i
->lock
);
1550 struct uart_8250_port
*up
;
1553 up
= list_entry(l
, struct uart_8250_port
, list
);
1555 iir
= serial_in(up
, UART_IIR
);
1556 if (!(iir
& UART_IIR_NO_INT
)) {
1557 serial8250_handle_port(up
);
1562 } else if (up
->port
.iotype
== UPIO_DWAPB
&&
1563 (iir
& UART_IIR_BUSY
) == UART_IIR_BUSY
) {
1564 /* The DesignWare APB UART has an Busy Detect (0x07)
1565 * interrupt meaning an LCR write attempt occured while the
1566 * UART was busy. The interrupt must be cleared by reading
1567 * the UART status register (USR) and the LCR re-written. */
1568 unsigned int status
;
1569 status
= *(volatile u32
*)up
->port
.private_data
;
1570 serial_out(up
, UART_LCR
, up
->lcr
);
1575 } else if (end
== NULL
)
1580 if (l
== i
->head
&& pass_counter
++ > PASS_LIMIT
) {
1581 /* If we hit this, we're dead. */
1582 printk(KERN_ERR
"serial8250: too much work for "
1588 spin_unlock(&i
->lock
);
1590 DEBUG_INTR("end.\n");
1592 return IRQ_RETVAL(handled
);
1596 * To support ISA shared interrupts, we need to have one interrupt
1597 * handler that ensures that the IRQ line has been deasserted
1598 * before returning. Failing to do this will result in the IRQ
1599 * line being stuck active, and, since ISA irqs are edge triggered,
1600 * no more IRQs will be seen.
1602 static void serial_do_unlink(struct irq_info
*i
, struct uart_8250_port
*up
)
1604 spin_lock_irq(&i
->lock
);
1606 if (!list_empty(i
->head
)) {
1607 if (i
->head
== &up
->list
)
1608 i
->head
= i
->head
->next
;
1609 list_del(&up
->list
);
1611 BUG_ON(i
->head
!= &up
->list
);
1614 spin_unlock_irq(&i
->lock
);
1615 /* List empty so throw away the hash node */
1616 if (i
->head
== NULL
) {
1617 hlist_del(&i
->node
);
1622 static int serial_link_irq_chain(struct uart_8250_port
*up
)
1624 struct hlist_head
*h
;
1625 struct hlist_node
*n
;
1627 int ret
, irq_flags
= up
->port
.flags
& UPF_SHARE_IRQ
? IRQF_SHARED
: 0;
1629 mutex_lock(&hash_mutex
);
1631 h
= &irq_lists
[up
->port
.irq
% NR_IRQ_HASH
];
1633 hlist_for_each(n
, h
) {
1634 i
= hlist_entry(n
, struct irq_info
, node
);
1635 if (i
->irq
== up
->port
.irq
)
1640 i
= kzalloc(sizeof(struct irq_info
), GFP_KERNEL
);
1642 mutex_unlock(&hash_mutex
);
1645 spin_lock_init(&i
->lock
);
1646 i
->irq
= up
->port
.irq
;
1647 hlist_add_head(&i
->node
, h
);
1649 mutex_unlock(&hash_mutex
);
1651 spin_lock_irq(&i
->lock
);
1654 list_add(&up
->list
, i
->head
);
1655 spin_unlock_irq(&i
->lock
);
1659 INIT_LIST_HEAD(&up
->list
);
1660 i
->head
= &up
->list
;
1661 spin_unlock_irq(&i
->lock
);
1663 ret
= request_irq(up
->port
.irq
, serial8250_interrupt
,
1664 irq_flags
, "serial", i
);
1666 serial_do_unlink(i
, up
);
1672 static void serial_unlink_irq_chain(struct uart_8250_port
*up
)
1675 struct hlist_node
*n
;
1676 struct hlist_head
*h
;
1678 mutex_lock(&hash_mutex
);
1680 h
= &irq_lists
[up
->port
.irq
% NR_IRQ_HASH
];
1682 hlist_for_each(n
, h
) {
1683 i
= hlist_entry(n
, struct irq_info
, node
);
1684 if (i
->irq
== up
->port
.irq
)
1689 BUG_ON(i
->head
== NULL
);
1691 if (list_empty(i
->head
))
1692 free_irq(up
->port
.irq
, i
);
1694 serial_do_unlink(i
, up
);
1695 mutex_unlock(&hash_mutex
);
1698 /* Base timer interval for polling */
1699 static inline int poll_timeout(int timeout
)
1701 return timeout
> 6 ? (timeout
/ 2 - 2) : 1;
1705 * This function is used to handle ports that do not have an
1706 * interrupt. This doesn't work very well for 16450's, but gives
1707 * barely passable results for a 16550A. (Although at the expense
1708 * of much CPU overhead).
1710 static void serial8250_timeout(unsigned long data
)
1712 struct uart_8250_port
*up
= (struct uart_8250_port
*)data
;
1715 iir
= serial_in(up
, UART_IIR
);
1716 if (!(iir
& UART_IIR_NO_INT
))
1717 serial8250_handle_port(up
);
1718 mod_timer(&up
->timer
, jiffies
+ poll_timeout(up
->port
.timeout
));
1721 static void serial8250_backup_timeout(unsigned long data
)
1723 struct uart_8250_port
*up
= (struct uart_8250_port
*)data
;
1724 unsigned int iir
, ier
= 0, lsr
;
1725 unsigned long flags
;
1728 * Must disable interrupts or else we risk racing with the interrupt
1731 if (is_real_interrupt(up
->port
.irq
)) {
1732 ier
= serial_in(up
, UART_IER
);
1733 serial_out(up
, UART_IER
, 0);
1736 iir
= serial_in(up
, UART_IIR
);
1739 * This should be a safe test for anyone who doesn't trust the
1740 * IIR bits on their UART, but it's specifically designed for
1741 * the "Diva" UART used on the management processor on many HP
1742 * ia64 and parisc boxes.
1744 spin_lock_irqsave(&up
->port
.lock
, flags
);
1745 lsr
= serial_in(up
, UART_LSR
);
1746 up
->lsr_saved_flags
|= lsr
& LSR_SAVE_FLAGS
;
1747 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1748 if ((iir
& UART_IIR_NO_INT
) && (up
->ier
& UART_IER_THRI
) &&
1749 (!uart_circ_empty(&up
->port
.info
->xmit
) || up
->port
.x_char
) &&
1750 (lsr
& UART_LSR_THRE
)) {
1751 iir
&= ~(UART_IIR_ID
| UART_IIR_NO_INT
);
1752 iir
|= UART_IIR_THRI
;
1755 if (!(iir
& UART_IIR_NO_INT
))
1756 serial8250_handle_port(up
);
1758 if (is_real_interrupt(up
->port
.irq
))
1759 serial_out(up
, UART_IER
, ier
);
1761 /* Standard timer interval plus 0.2s to keep the port running */
1762 mod_timer(&up
->timer
,
1763 jiffies
+ poll_timeout(up
->port
.timeout
) + HZ
/ 5);
1766 static unsigned int serial8250_tx_empty(struct uart_port
*port
)
1768 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1769 unsigned long flags
;
1772 spin_lock_irqsave(&up
->port
.lock
, flags
);
1773 lsr
= serial_in(up
, UART_LSR
);
1774 up
->lsr_saved_flags
|= lsr
& LSR_SAVE_FLAGS
;
1775 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1777 return lsr
& UART_LSR_TEMT
? TIOCSER_TEMT
: 0;
1780 static unsigned int serial8250_get_mctrl(struct uart_port
*port
)
1782 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1783 unsigned int status
;
1786 status
= check_modem_status(up
);
1789 if (status
& UART_MSR_DCD
)
1791 if (status
& UART_MSR_RI
)
1793 if (status
& UART_MSR_DSR
)
1795 if (status
& UART_MSR_CTS
)
1800 static void serial8250_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
1802 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1803 unsigned char mcr
= 0;
1805 if (mctrl
& TIOCM_RTS
)
1806 mcr
|= UART_MCR_RTS
;
1807 if (mctrl
& TIOCM_DTR
)
1808 mcr
|= UART_MCR_DTR
;
1809 if (mctrl
& TIOCM_OUT1
)
1810 mcr
|= UART_MCR_OUT1
;
1811 if (mctrl
& TIOCM_OUT2
)
1812 mcr
|= UART_MCR_OUT2
;
1813 if (mctrl
& TIOCM_LOOP
)
1814 mcr
|= UART_MCR_LOOP
;
1816 mcr
= (mcr
& up
->mcr_mask
) | up
->mcr_force
| up
->mcr
;
1818 serial_out(up
, UART_MCR
, mcr
);
1821 static void serial8250_break_ctl(struct uart_port
*port
, int break_state
)
1823 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1824 unsigned long flags
;
1826 spin_lock_irqsave(&up
->port
.lock
, flags
);
1827 if (break_state
== -1)
1828 up
->lcr
|= UART_LCR_SBC
;
1830 up
->lcr
&= ~UART_LCR_SBC
;
1831 serial_out(up
, UART_LCR
, up
->lcr
);
1832 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
1835 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
1838 * Wait for transmitter & holding register to empty
1840 static void wait_for_xmitr(struct uart_8250_port
*up
, int bits
)
1842 unsigned int status
, tmout
= 10000;
1844 /* Wait up to 10ms for the character(s) to be sent. */
1846 status
= serial_in(up
, UART_LSR
);
1848 up
->lsr_saved_flags
|= status
& LSR_SAVE_FLAGS
;
1853 } while ((status
& bits
) != bits
);
1855 /* Wait up to 1s for flow control if necessary */
1856 if (up
->port
.flags
& UPF_CONS_FLOW
) {
1858 for (tmout
= 1000000; tmout
; tmout
--) {
1859 unsigned int msr
= serial_in(up
, UART_MSR
);
1860 up
->msr_saved_flags
|= msr
& MSR_SAVE_FLAGS
;
1861 if (msr
& UART_MSR_CTS
)
1864 touch_nmi_watchdog();
1869 #ifdef CONFIG_CONSOLE_POLL
1871 * Console polling routines for writing and reading from the uart while
1872 * in an interrupt or debug context.
1875 static int serial8250_get_poll_char(struct uart_port
*port
)
1877 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1878 unsigned char lsr
= serial_inp(up
, UART_LSR
);
1880 while (!(lsr
& UART_LSR_DR
))
1881 lsr
= serial_inp(up
, UART_LSR
);
1883 return serial_inp(up
, UART_RX
);
1887 static void serial8250_put_poll_char(struct uart_port
*port
,
1891 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1894 * First save the IER then disable the interrupts
1896 ier
= serial_in(up
, UART_IER
);
1897 if (up
->capabilities
& UART_CAP_UUE
)
1898 serial_out(up
, UART_IER
, UART_IER_UUE
);
1900 serial_out(up
, UART_IER
, 0);
1902 wait_for_xmitr(up
, BOTH_EMPTY
);
1904 * Send the character out.
1905 * If a LF, also do CR...
1907 serial_out(up
, UART_TX
, c
);
1909 wait_for_xmitr(up
, BOTH_EMPTY
);
1910 serial_out(up
, UART_TX
, 13);
1914 * Finally, wait for transmitter to become empty
1915 * and restore the IER
1917 wait_for_xmitr(up
, BOTH_EMPTY
);
1918 serial_out(up
, UART_IER
, ier
);
1921 #endif /* CONFIG_CONSOLE_POLL */
1923 static int serial8250_startup(struct uart_port
*port
)
1925 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
1926 unsigned long flags
;
1927 unsigned char lsr
, iir
;
1930 up
->capabilities
= uart_config
[up
->port
.type
].flags
;
1933 if (up
->port
.type
== PORT_16C950
) {
1934 /* Wake up and initialize UART */
1936 serial_outp(up
, UART_LCR
, 0xBF);
1937 serial_outp(up
, UART_EFR
, UART_EFR_ECB
);
1938 serial_outp(up
, UART_IER
, 0);
1939 serial_outp(up
, UART_LCR
, 0);
1940 serial_icr_write(up
, UART_CSR
, 0); /* Reset the UART */
1941 serial_outp(up
, UART_LCR
, 0xBF);
1942 serial_outp(up
, UART_EFR
, UART_EFR_ECB
);
1943 serial_outp(up
, UART_LCR
, 0);
1946 #ifdef CONFIG_SERIAL_8250_RSA
1948 * If this is an RSA port, see if we can kick it up to the
1949 * higher speed clock.
1955 * Clear the FIFO buffers and disable them.
1956 * (they will be reenabled in set_termios())
1958 serial8250_clear_fifos(up
);
1961 * Clear the interrupt registers.
1963 (void) serial_inp(up
, UART_LSR
);
1964 (void) serial_inp(up
, UART_RX
);
1965 (void) serial_inp(up
, UART_IIR
);
1966 (void) serial_inp(up
, UART_MSR
);
1969 * At this point, there's no way the LSR could still be 0xff;
1970 * if it is, then bail out, because there's likely no UART
1973 if (!(up
->port
.flags
& UPF_BUGGY_UART
) &&
1974 (serial_inp(up
, UART_LSR
) == 0xff)) {
1975 printk(KERN_INFO
"ttyS%d: LSR safety check engaged!\n",
1976 serial_index(&up
->port
));
1981 * For a XR16C850, we need to set the trigger levels
1983 if (up
->port
.type
== PORT_16850
) {
1986 serial_outp(up
, UART_LCR
, 0xbf);
1988 fctr
= serial_inp(up
, UART_FCTR
) & ~(UART_FCTR_RX
|UART_FCTR_TX
);
1989 serial_outp(up
, UART_FCTR
, fctr
| UART_FCTR_TRGD
| UART_FCTR_RX
);
1990 serial_outp(up
, UART_TRG
, UART_TRG_96
);
1991 serial_outp(up
, UART_FCTR
, fctr
| UART_FCTR_TRGD
| UART_FCTR_TX
);
1992 serial_outp(up
, UART_TRG
, UART_TRG_96
);
1994 serial_outp(up
, UART_LCR
, 0);
1997 if (is_real_interrupt(up
->port
.irq
)) {
2000 * Test for UARTs that do not reassert THRE when the
2001 * transmitter is idle and the interrupt has already
2002 * been cleared. Real 16550s should always reassert
2003 * this interrupt whenever the transmitter is idle and
2004 * the interrupt is enabled. Delays are necessary to
2005 * allow register changes to become visible.
2007 spin_lock_irqsave(&up
->port
.lock
, flags
);
2008 if (up
->port
.flags
& UPF_SHARE_IRQ
)
2009 disable_irq_nosync(up
->port
.irq
);
2011 wait_for_xmitr(up
, UART_LSR_THRE
);
2012 serial_out_sync(up
, UART_IER
, UART_IER_THRI
);
2013 udelay(1); /* allow THRE to set */
2014 iir1
= serial_in(up
, UART_IIR
);
2015 serial_out(up
, UART_IER
, 0);
2016 serial_out_sync(up
, UART_IER
, UART_IER_THRI
);
2017 udelay(1); /* allow a working UART time to re-assert THRE */
2018 iir
= serial_in(up
, UART_IIR
);
2019 serial_out(up
, UART_IER
, 0);
2021 if (up
->port
.flags
& UPF_SHARE_IRQ
)
2022 enable_irq(up
->port
.irq
);
2023 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
2026 * If the interrupt is not reasserted, setup a timer to
2027 * kick the UART on a regular basis.
2029 if (!(iir1
& UART_IIR_NO_INT
) && (iir
& UART_IIR_NO_INT
)) {
2030 up
->bugs
|= UART_BUG_THRE
;
2031 pr_debug("ttyS%d - using backup timer\n",
2032 serial_index(port
));
2037 * The above check will only give an accurate result the first time
2038 * the port is opened so this value needs to be preserved.
2040 if (up
->bugs
& UART_BUG_THRE
) {
2041 up
->timer
.function
= serial8250_backup_timeout
;
2042 up
->timer
.data
= (unsigned long)up
;
2043 mod_timer(&up
->timer
, jiffies
+
2044 poll_timeout(up
->port
.timeout
) + HZ
/ 5);
2048 * If the "interrupt" for this port doesn't correspond with any
2049 * hardware interrupt, we use a timer-based system. The original
2050 * driver used to do this with IRQ0.
2052 if (!is_real_interrupt(up
->port
.irq
)) {
2053 up
->timer
.data
= (unsigned long)up
;
2054 mod_timer(&up
->timer
, jiffies
+ poll_timeout(up
->port
.timeout
));
2056 retval
= serial_link_irq_chain(up
);
2062 * Now, initialize the UART
2064 serial_outp(up
, UART_LCR
, UART_LCR_WLEN8
);
2066 spin_lock_irqsave(&up
->port
.lock
, flags
);
2067 if (up
->port
.flags
& UPF_FOURPORT
) {
2068 if (!is_real_interrupt(up
->port
.irq
))
2069 up
->port
.mctrl
|= TIOCM_OUT1
;
2072 * Most PC uarts need OUT2 raised to enable interrupts.
2074 if (is_real_interrupt(up
->port
.irq
))
2075 up
->port
.mctrl
|= TIOCM_OUT2
;
2077 serial8250_set_mctrl(&up
->port
, up
->port
.mctrl
);
2080 * Do a quick test to see if we receive an
2081 * interrupt when we enable the TX irq.
2083 serial_outp(up
, UART_IER
, UART_IER_THRI
);
2084 lsr
= serial_in(up
, UART_LSR
);
2085 iir
= serial_in(up
, UART_IIR
);
2086 serial_outp(up
, UART_IER
, 0);
2088 if (lsr
& UART_LSR_TEMT
&& iir
& UART_IIR_NO_INT
) {
2089 if (!(up
->bugs
& UART_BUG_TXEN
)) {
2090 up
->bugs
|= UART_BUG_TXEN
;
2091 pr_debug("ttyS%d - enabling bad tx status workarounds\n",
2092 serial_index(port
));
2095 up
->bugs
&= ~UART_BUG_TXEN
;
2098 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
2101 * Clear the interrupt registers again for luck, and clear the
2102 * saved flags to avoid getting false values from polling
2103 * routines or the previous session.
2105 serial_inp(up
, UART_LSR
);
2106 serial_inp(up
, UART_RX
);
2107 serial_inp(up
, UART_IIR
);
2108 serial_inp(up
, UART_MSR
);
2109 up
->lsr_saved_flags
= 0;
2110 up
->msr_saved_flags
= 0;
2113 * Finally, enable interrupts. Note: Modem status interrupts
2114 * are set via set_termios(), which will be occurring imminently
2115 * anyway, so we don't enable them here.
2117 up
->ier
= UART_IER_RLSI
| UART_IER_RDI
;
2118 serial_outp(up
, UART_IER
, up
->ier
);
2120 if (up
->port
.flags
& UPF_FOURPORT
) {
2123 * Enable interrupts on the AST Fourport board
2125 icp
= (up
->port
.iobase
& 0xfe0) | 0x01f;
2133 static void serial8250_shutdown(struct uart_port
*port
)
2135 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2136 unsigned long flags
;
2139 * Disable interrupts from this port
2142 serial_outp(up
, UART_IER
, 0);
2144 spin_lock_irqsave(&up
->port
.lock
, flags
);
2145 if (up
->port
.flags
& UPF_FOURPORT
) {
2146 /* reset interrupts on the AST Fourport board */
2147 inb((up
->port
.iobase
& 0xfe0) | 0x1f);
2148 up
->port
.mctrl
|= TIOCM_OUT1
;
2150 up
->port
.mctrl
&= ~TIOCM_OUT2
;
2152 serial8250_set_mctrl(&up
->port
, up
->port
.mctrl
);
2153 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
2156 * Disable break condition and FIFOs
2158 serial_out(up
, UART_LCR
, serial_inp(up
, UART_LCR
) & ~UART_LCR_SBC
);
2159 serial8250_clear_fifos(up
);
2161 #ifdef CONFIG_SERIAL_8250_RSA
2163 * Reset the RSA board back to 115kbps compat mode.
2169 * Read data port to reset things, and then unlink from
2172 (void) serial_in(up
, UART_RX
);
2174 del_timer_sync(&up
->timer
);
2175 up
->timer
.function
= serial8250_timeout
;
2176 if (is_real_interrupt(up
->port
.irq
))
2177 serial_unlink_irq_chain(up
);
2180 static unsigned int serial8250_get_divisor(struct uart_port
*port
, unsigned int baud
)
2185 * Handle magic divisors for baud rates above baud_base on
2186 * SMSC SuperIO chips.
2188 if ((port
->flags
& UPF_MAGIC_MULTIPLIER
) &&
2189 baud
== (port
->uartclk
/4))
2191 else if ((port
->flags
& UPF_MAGIC_MULTIPLIER
) &&
2192 baud
== (port
->uartclk
/8))
2195 quot
= uart_get_divisor(port
, baud
);
2201 serial8250_set_termios(struct uart_port
*port
, struct ktermios
*termios
,
2202 struct ktermios
*old
)
2204 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2205 unsigned char cval
, fcr
= 0;
2206 unsigned long flags
;
2207 unsigned int baud
, quot
;
2209 switch (termios
->c_cflag
& CSIZE
) {
2211 cval
= UART_LCR_WLEN5
;
2214 cval
= UART_LCR_WLEN6
;
2217 cval
= UART_LCR_WLEN7
;
2221 cval
= UART_LCR_WLEN8
;
2225 if (termios
->c_cflag
& CSTOPB
)
2226 cval
|= UART_LCR_STOP
;
2227 if (termios
->c_cflag
& PARENB
)
2228 cval
|= UART_LCR_PARITY
;
2229 if (!(termios
->c_cflag
& PARODD
))
2230 cval
|= UART_LCR_EPAR
;
2232 if (termios
->c_cflag
& CMSPAR
)
2233 cval
|= UART_LCR_SPAR
;
2237 * Ask the core to calculate the divisor for us.
2239 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
2240 quot
= serial8250_get_divisor(port
, baud
);
2243 * Oxford Semi 952 rev B workaround
2245 if (up
->bugs
& UART_BUG_QUOT
&& (quot
& 0xff) == 0)
2248 if (up
->capabilities
& UART_CAP_FIFO
&& up
->port
.fifosize
> 1) {
2250 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_TRIGGER_1
;
2252 fcr
= uart_config
[up
->port
.type
].fcr
;
2256 * MCR-based auto flow control. When AFE is enabled, RTS will be
2257 * deasserted when the receive FIFO contains more characters than
2258 * the trigger, or the MCR RTS bit is cleared. In the case where
2259 * the remote UART is not using CTS auto flow control, we must
2260 * have sufficient FIFO entries for the latency of the remote
2261 * UART to respond. IOW, at least 32 bytes of FIFO.
2263 if (up
->capabilities
& UART_CAP_AFE
&& up
->port
.fifosize
>= 32) {
2264 up
->mcr
&= ~UART_MCR_AFE
;
2265 if (termios
->c_cflag
& CRTSCTS
)
2266 up
->mcr
|= UART_MCR_AFE
;
2270 * Ok, we're now changing the port state. Do it with
2271 * interrupts disabled.
2273 spin_lock_irqsave(&up
->port
.lock
, flags
);
2276 * Update the per-port timeout.
2278 uart_update_timeout(port
, termios
->c_cflag
, baud
);
2280 up
->port
.read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
2281 if (termios
->c_iflag
& INPCK
)
2282 up
->port
.read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
2283 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
2284 up
->port
.read_status_mask
|= UART_LSR_BI
;
2287 * Characteres to ignore
2289 up
->port
.ignore_status_mask
= 0;
2290 if (termios
->c_iflag
& IGNPAR
)
2291 up
->port
.ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
2292 if (termios
->c_iflag
& IGNBRK
) {
2293 up
->port
.ignore_status_mask
|= UART_LSR_BI
;
2295 * If we're ignoring parity and break indicators,
2296 * ignore overruns too (for real raw support).
2298 if (termios
->c_iflag
& IGNPAR
)
2299 up
->port
.ignore_status_mask
|= UART_LSR_OE
;
2303 * ignore all characters if CREAD is not set
2305 if ((termios
->c_cflag
& CREAD
) == 0)
2306 up
->port
.ignore_status_mask
|= UART_LSR_DR
;
2309 * CTS flow control flag and modem status interrupts
2311 up
->ier
&= ~UART_IER_MSI
;
2312 if (!(up
->bugs
& UART_BUG_NOMSR
) &&
2313 UART_ENABLE_MS(&up
->port
, termios
->c_cflag
))
2314 up
->ier
|= UART_IER_MSI
;
2315 if (up
->capabilities
& UART_CAP_UUE
)
2316 up
->ier
|= UART_IER_UUE
| UART_IER_RTOIE
;
2318 serial_out(up
, UART_IER
, up
->ier
);
2320 if (up
->capabilities
& UART_CAP_EFR
) {
2321 unsigned char efr
= 0;
2323 * TI16C752/Startech hardware flow control. FIXME:
2324 * - TI16C752 requires control thresholds to be set.
2325 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
2327 if (termios
->c_cflag
& CRTSCTS
)
2328 efr
|= UART_EFR_CTS
;
2330 serial_outp(up
, UART_LCR
, 0xBF);
2331 serial_outp(up
, UART_EFR
, efr
);
2334 #ifdef CONFIG_ARCH_OMAP
2335 /* Workaround to enable 115200 baud on OMAP1510 internal ports */
2336 if (cpu_is_omap1510() && is_omap_port(up
)) {
2337 if (baud
== 115200) {
2339 serial_out(up
, UART_OMAP_OSC_12M_SEL
, 1);
2341 serial_out(up
, UART_OMAP_OSC_12M_SEL
, 0);
2345 if (up
->capabilities
& UART_NATSEMI
) {
2346 /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */
2347 serial_outp(up
, UART_LCR
, 0xe0);
2349 serial_outp(up
, UART_LCR
, cval
| UART_LCR_DLAB
);/* set DLAB */
2352 serial_dl_write(up
, quot
);
2355 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
2356 * is written without DLAB set, this mode will be disabled.
2358 if (up
->port
.type
== PORT_16750
)
2359 serial_outp(up
, UART_FCR
, fcr
);
2361 serial_outp(up
, UART_LCR
, cval
); /* reset DLAB */
2362 up
->lcr
= cval
; /* Save LCR */
2363 if (up
->port
.type
!= PORT_16750
) {
2364 if (fcr
& UART_FCR_ENABLE_FIFO
) {
2365 /* emulated UARTs (Lucent Venus 167x) need two steps */
2366 serial_outp(up
, UART_FCR
, UART_FCR_ENABLE_FIFO
);
2368 serial_outp(up
, UART_FCR
, fcr
); /* set fcr */
2370 serial8250_set_mctrl(&up
->port
, up
->port
.mctrl
);
2371 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
2372 /* Don't rewrite B0 */
2373 if (tty_termios_baud_rate(termios
))
2374 tty_termios_encode_baud_rate(termios
, baud
, baud
);
2378 serial8250_pm(struct uart_port
*port
, unsigned int state
,
2379 unsigned int oldstate
)
2381 struct uart_8250_port
*p
= (struct uart_8250_port
*)port
;
2383 serial8250_set_sleep(p
, state
!= 0);
2386 p
->pm(port
, state
, oldstate
);
2389 static unsigned int serial8250_port_size(struct uart_8250_port
*pt
)
2391 if (pt
->port
.iotype
== UPIO_AU
)
2393 #ifdef CONFIG_ARCH_OMAP
2394 if (is_omap_port(pt
))
2395 return 0x16 << pt
->port
.regshift
;
2397 return 8 << pt
->port
.regshift
;
2401 * Resource handling.
2403 static int serial8250_request_std_resource(struct uart_8250_port
*up
)
2405 unsigned int size
= serial8250_port_size(up
);
2408 switch (up
->port
.iotype
) {
2414 if (!up
->port
.mapbase
)
2417 if (!request_mem_region(up
->port
.mapbase
, size
, "serial")) {
2422 if (up
->port
.flags
& UPF_IOREMAP
) {
2423 up
->port
.membase
= ioremap_nocache(up
->port
.mapbase
,
2425 if (!up
->port
.membase
) {
2426 release_mem_region(up
->port
.mapbase
, size
);
2434 if (!request_region(up
->port
.iobase
, size
, "serial"))
2441 static void serial8250_release_std_resource(struct uart_8250_port
*up
)
2443 unsigned int size
= serial8250_port_size(up
);
2445 switch (up
->port
.iotype
) {
2451 if (!up
->port
.mapbase
)
2454 if (up
->port
.flags
& UPF_IOREMAP
) {
2455 iounmap(up
->port
.membase
);
2456 up
->port
.membase
= NULL
;
2459 release_mem_region(up
->port
.mapbase
, size
);
2464 release_region(up
->port
.iobase
, size
);
2469 static int serial8250_request_rsa_resource(struct uart_8250_port
*up
)
2471 unsigned long start
= UART_RSA_BASE
<< up
->port
.regshift
;
2472 unsigned int size
= 8 << up
->port
.regshift
;
2475 switch (up
->port
.iotype
) {
2478 start
+= up
->port
.iobase
;
2479 if (request_region(start
, size
, "serial-rsa"))
2489 static void serial8250_release_rsa_resource(struct uart_8250_port
*up
)
2491 unsigned long offset
= UART_RSA_BASE
<< up
->port
.regshift
;
2492 unsigned int size
= 8 << up
->port
.regshift
;
2494 switch (up
->port
.iotype
) {
2497 release_region(up
->port
.iobase
+ offset
, size
);
2502 static void serial8250_release_port(struct uart_port
*port
)
2504 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2506 serial8250_release_std_resource(up
);
2507 if (up
->port
.type
== PORT_RSA
)
2508 serial8250_release_rsa_resource(up
);
2511 static int serial8250_request_port(struct uart_port
*port
)
2513 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2516 ret
= serial8250_request_std_resource(up
);
2517 if (ret
== 0 && up
->port
.type
== PORT_RSA
) {
2518 ret
= serial8250_request_rsa_resource(up
);
2520 serial8250_release_std_resource(up
);
2526 static void serial8250_config_port(struct uart_port
*port
, int flags
)
2528 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2529 int probeflags
= PROBE_ANY
;
2533 * Find the region that we can probe for. This in turn
2534 * tells us whether we can probe for the type of port.
2536 ret
= serial8250_request_std_resource(up
);
2540 ret
= serial8250_request_rsa_resource(up
);
2542 probeflags
&= ~PROBE_RSA
;
2544 if (flags
& UART_CONFIG_TYPE
)
2545 autoconfig(up
, probeflags
);
2546 if (up
->port
.type
!= PORT_UNKNOWN
&& flags
& UART_CONFIG_IRQ
)
2549 if (up
->port
.type
!= PORT_RSA
&& probeflags
& PROBE_RSA
)
2550 serial8250_release_rsa_resource(up
);
2551 if (up
->port
.type
== PORT_UNKNOWN
)
2552 serial8250_release_std_resource(up
);
2556 serial8250_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
2558 if (ser
->irq
>= nr_irqs
|| ser
->irq
< 0 ||
2559 ser
->baud_base
< 9600 || ser
->type
< PORT_UNKNOWN
||
2560 ser
->type
>= ARRAY_SIZE(uart_config
) || ser
->type
== PORT_CIRRUS
||
2561 ser
->type
== PORT_STARTECH
)
2567 serial8250_type(struct uart_port
*port
)
2569 int type
= port
->type
;
2571 if (type
>= ARRAY_SIZE(uart_config
))
2573 return uart_config
[type
].name
;
2576 static struct uart_ops serial8250_pops
= {
2577 .tx_empty
= serial8250_tx_empty
,
2578 .set_mctrl
= serial8250_set_mctrl
,
2579 .get_mctrl
= serial8250_get_mctrl
,
2580 .stop_tx
= serial8250_stop_tx
,
2581 .start_tx
= serial8250_start_tx
,
2582 .stop_rx
= serial8250_stop_rx
,
2583 .enable_ms
= serial8250_enable_ms
,
2584 .break_ctl
= serial8250_break_ctl
,
2585 .startup
= serial8250_startup
,
2586 .shutdown
= serial8250_shutdown
,
2587 .set_termios
= serial8250_set_termios
,
2588 .pm
= serial8250_pm
,
2589 .type
= serial8250_type
,
2590 .release_port
= serial8250_release_port
,
2591 .request_port
= serial8250_request_port
,
2592 .config_port
= serial8250_config_port
,
2593 .verify_port
= serial8250_verify_port
,
2594 #ifdef CONFIG_CONSOLE_POLL
2595 .poll_get_char
= serial8250_get_poll_char
,
2596 .poll_put_char
= serial8250_put_poll_char
,
2600 static struct uart_8250_port serial8250_ports
[UART_NR
];
2602 static void __init
serial8250_isa_init_ports(void)
2604 struct uart_8250_port
*up
;
2605 static int first
= 1;
2612 for (i
= 0; i
< nr_uarts
; i
++) {
2613 struct uart_8250_port
*up
= &serial8250_ports
[i
];
2616 spin_lock_init(&up
->port
.lock
);
2618 init_timer(&up
->timer
);
2619 up
->timer
.function
= serial8250_timeout
;
2622 * ALPHA_KLUDGE_MCR needs to be killed.
2624 up
->mcr_mask
= ~ALPHA_KLUDGE_MCR
;
2625 up
->mcr_force
= ALPHA_KLUDGE_MCR
;
2627 up
->port
.ops
= &serial8250_pops
;
2630 for (i
= 0, up
= serial8250_ports
;
2631 i
< ARRAY_SIZE(old_serial_port
) && i
< nr_uarts
;
2633 up
->port
.iobase
= old_serial_port
[i
].port
;
2634 up
->port
.irq
= irq_canonicalize(old_serial_port
[i
].irq
);
2635 up
->port
.uartclk
= old_serial_port
[i
].baud_base
* 16;
2636 up
->port
.flags
= old_serial_port
[i
].flags
;
2637 up
->port
.hub6
= old_serial_port
[i
].hub6
;
2638 up
->port
.membase
= old_serial_port
[i
].iomem_base
;
2639 up
->port
.iotype
= old_serial_port
[i
].io_type
;
2640 up
->port
.regshift
= old_serial_port
[i
].iomem_reg_shift
;
2641 set_io_from_upio(&up
->port
);
2643 up
->port
.flags
|= UPF_SHARE_IRQ
;
2648 serial8250_register_ports(struct uart_driver
*drv
, struct device
*dev
)
2652 serial8250_isa_init_ports();
2654 for (i
= 0; i
< nr_uarts
; i
++) {
2655 struct uart_8250_port
*up
= &serial8250_ports
[i
];
2658 uart_add_one_port(drv
, &up
->port
);
2662 #ifdef CONFIG_SERIAL_8250_CONSOLE
2664 static void serial8250_console_putchar(struct uart_port
*port
, int ch
)
2666 struct uart_8250_port
*up
= (struct uart_8250_port
*)port
;
2668 wait_for_xmitr(up
, UART_LSR_THRE
);
2669 serial_out(up
, UART_TX
, ch
);
2673 * Print a string to the serial port trying not to disturb
2674 * any possible real use of the port...
2676 * The console_lock must be held when we get here.
2679 serial8250_console_write(struct console
*co
, const char *s
, unsigned int count
)
2681 struct uart_8250_port
*up
= &serial8250_ports
[co
->index
];
2682 unsigned long flags
;
2686 touch_nmi_watchdog();
2688 local_irq_save(flags
);
2689 if (up
->port
.sysrq
) {
2690 /* serial8250_handle_port() already took the lock */
2692 } else if (oops_in_progress
) {
2693 locked
= spin_trylock(&up
->port
.lock
);
2695 spin_lock(&up
->port
.lock
);
2698 * First save the IER then disable the interrupts
2700 ier
= serial_in(up
, UART_IER
);
2702 if (up
->capabilities
& UART_CAP_UUE
)
2703 serial_out(up
, UART_IER
, UART_IER_UUE
);
2705 serial_out(up
, UART_IER
, 0);
2707 uart_console_write(&up
->port
, s
, count
, serial8250_console_putchar
);
2710 * Finally, wait for transmitter to become empty
2711 * and restore the IER
2713 wait_for_xmitr(up
, BOTH_EMPTY
);
2714 serial_out(up
, UART_IER
, ier
);
2717 * The receive handling will happen properly because the
2718 * receive ready bit will still be set; it is not cleared
2719 * on read. However, modem control will not, we must
2720 * call it if we have saved something in the saved flags
2721 * while processing with interrupts off.
2723 if (up
->msr_saved_flags
)
2724 check_modem_status(up
);
2727 spin_unlock(&up
->port
.lock
);
2728 local_irq_restore(flags
);
2731 static int __init
serial8250_console_setup(struct console
*co
, char *options
)
2733 struct uart_port
*port
;
2740 * Check whether an invalid uart number has been specified, and
2741 * if so, search for the first available port that does have
2744 if (co
->index
>= nr_uarts
)
2746 port
= &serial8250_ports
[co
->index
].port
;
2747 if (!port
->iobase
&& !port
->membase
)
2751 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
2753 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
2756 static int serial8250_console_early_setup(void)
2758 return serial8250_find_port_for_earlycon();
2761 static struct console serial8250_console
= {
2763 .write
= serial8250_console_write
,
2764 .device
= uart_console_device
,
2765 .setup
= serial8250_console_setup
,
2766 .early_setup
= serial8250_console_early_setup
,
2767 .flags
= CON_PRINTBUFFER
,
2769 .data
= &serial8250_reg
,
2772 static int __init
serial8250_console_init(void)
2774 if (nr_uarts
> UART_NR
)
2777 serial8250_isa_init_ports();
2778 register_console(&serial8250_console
);
2781 console_initcall(serial8250_console_init
);
2783 int serial8250_find_port(struct uart_port
*p
)
2786 struct uart_port
*port
;
2788 for (line
= 0; line
< nr_uarts
; line
++) {
2789 port
= &serial8250_ports
[line
].port
;
2790 if (uart_match_port(p
, port
))
2796 #define SERIAL8250_CONSOLE &serial8250_console
2798 #define SERIAL8250_CONSOLE NULL
2801 static struct uart_driver serial8250_reg
= {
2802 .owner
= THIS_MODULE
,
2803 .driver_name
= "serial",
2807 .cons
= SERIAL8250_CONSOLE
,
2811 * early_serial_setup - early registration for 8250 ports
2813 * Setup an 8250 port structure prior to console initialisation. Use
2814 * after console initialisation will cause undefined behaviour.
2816 int __init
early_serial_setup(struct uart_port
*port
)
2818 struct uart_port
*p
;
2820 if (port
->line
>= ARRAY_SIZE(serial8250_ports
))
2823 serial8250_isa_init_ports();
2824 p
= &serial8250_ports
[port
->line
].port
;
2825 p
->iobase
= port
->iobase
;
2826 p
->membase
= port
->membase
;
2828 p
->uartclk
= port
->uartclk
;
2829 p
->fifosize
= port
->fifosize
;
2830 p
->regshift
= port
->regshift
;
2831 p
->iotype
= port
->iotype
;
2832 p
->flags
= port
->flags
;
2833 p
->mapbase
= port
->mapbase
;
2834 p
->private_data
= port
->private_data
;
2836 set_io_from_upio(p
);
2837 if (port
->serial_in
)
2838 p
->serial_in
= port
->serial_in
;
2839 if (port
->serial_out
)
2840 p
->serial_out
= port
->serial_out
;
2846 * serial8250_suspend_port - suspend one serial port
2847 * @line: serial line number
2849 * Suspend one serial port.
2851 void serial8250_suspend_port(int line
)
2853 uart_suspend_port(&serial8250_reg
, &serial8250_ports
[line
].port
);
2857 * serial8250_resume_port - resume one serial port
2858 * @line: serial line number
2860 * Resume one serial port.
2862 void serial8250_resume_port(int line
)
2864 struct uart_8250_port
*up
= &serial8250_ports
[line
];
2866 if (up
->capabilities
& UART_NATSEMI
) {
2869 /* Ensure it's still in high speed mode */
2870 serial_outp(up
, UART_LCR
, 0xE0);
2872 tmp
= serial_in(up
, 0x04); /* EXCR2 */
2873 tmp
&= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
2874 tmp
|= 0x10; /* 1.625 divisor for baud_base --> 921600 */
2875 serial_outp(up
, 0x04, tmp
);
2877 serial_outp(up
, UART_LCR
, 0);
2879 uart_resume_port(&serial8250_reg
, &up
->port
);
2883 * Register a set of serial devices attached to a platform device. The
2884 * list is terminated with a zero flags entry, which means we expect
2885 * all entries to have at least UPF_BOOT_AUTOCONF set.
2887 static int __devinit
serial8250_probe(struct platform_device
*dev
)
2889 struct plat_serial8250_port
*p
= dev
->dev
.platform_data
;
2890 struct uart_port port
;
2893 memset(&port
, 0, sizeof(struct uart_port
));
2895 for (i
= 0; p
&& p
->flags
!= 0; p
++, i
++) {
2896 port
.iobase
= p
->iobase
;
2897 port
.membase
= p
->membase
;
2899 port
.uartclk
= p
->uartclk
;
2900 port
.regshift
= p
->regshift
;
2901 port
.iotype
= p
->iotype
;
2902 port
.flags
= p
->flags
;
2903 port
.mapbase
= p
->mapbase
;
2904 port
.hub6
= p
->hub6
;
2905 port
.private_data
= p
->private_data
;
2906 port
.type
= p
->type
;
2907 port
.serial_in
= p
->serial_in
;
2908 port
.serial_out
= p
->serial_out
;
2909 port
.dev
= &dev
->dev
;
2911 port
.flags
|= UPF_SHARE_IRQ
;
2912 ret
= serial8250_register_port(&port
);
2914 dev_err(&dev
->dev
, "unable to register port at index %d "
2915 "(IO%lx MEM%llx IRQ%d): %d\n", i
,
2916 p
->iobase
, (unsigned long long)p
->mapbase
,
2924 * Remove serial ports registered against a platform device.
2926 static int __devexit
serial8250_remove(struct platform_device
*dev
)
2930 for (i
= 0; i
< nr_uarts
; i
++) {
2931 struct uart_8250_port
*up
= &serial8250_ports
[i
];
2933 if (up
->port
.dev
== &dev
->dev
)
2934 serial8250_unregister_port(i
);
2939 static int serial8250_suspend(struct platform_device
*dev
, pm_message_t state
)
2943 for (i
= 0; i
< UART_NR
; i
++) {
2944 struct uart_8250_port
*up
= &serial8250_ports
[i
];
2946 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
2947 uart_suspend_port(&serial8250_reg
, &up
->port
);
2953 static int serial8250_resume(struct platform_device
*dev
)
2957 for (i
= 0; i
< UART_NR
; i
++) {
2958 struct uart_8250_port
*up
= &serial8250_ports
[i
];
2960 if (up
->port
.type
!= PORT_UNKNOWN
&& up
->port
.dev
== &dev
->dev
)
2961 serial8250_resume_port(i
);
2967 static struct platform_driver serial8250_isa_driver
= {
2968 .probe
= serial8250_probe
,
2969 .remove
= __devexit_p(serial8250_remove
),
2970 .suspend
= serial8250_suspend
,
2971 .resume
= serial8250_resume
,
2973 .name
= "serial8250",
2974 .owner
= THIS_MODULE
,
2979 * This "device" covers _all_ ISA 8250-compatible serial devices listed
2980 * in the table in include/asm/serial.h
2982 static struct platform_device
*serial8250_isa_devs
;
2985 * serial8250_register_port and serial8250_unregister_port allows for
2986 * 16x50 serial ports to be configured at run-time, to support PCMCIA
2987 * modems and PCI multiport cards.
2989 static DEFINE_MUTEX(serial_mutex
);
2991 static struct uart_8250_port
*serial8250_find_match_or_unused(struct uart_port
*port
)
2996 * First, find a port entry which matches.
2998 for (i
= 0; i
< nr_uarts
; i
++)
2999 if (uart_match_port(&serial8250_ports
[i
].port
, port
))
3000 return &serial8250_ports
[i
];
3003 * We didn't find a matching entry, so look for the first
3004 * free entry. We look for one which hasn't been previously
3005 * used (indicated by zero iobase).
3007 for (i
= 0; i
< nr_uarts
; i
++)
3008 if (serial8250_ports
[i
].port
.type
== PORT_UNKNOWN
&&
3009 serial8250_ports
[i
].port
.iobase
== 0)
3010 return &serial8250_ports
[i
];
3013 * That also failed. Last resort is to find any entry which
3014 * doesn't have a real port associated with it.
3016 for (i
= 0; i
< nr_uarts
; i
++)
3017 if (serial8250_ports
[i
].port
.type
== PORT_UNKNOWN
)
3018 return &serial8250_ports
[i
];
3024 * serial8250_register_port - register a serial port
3025 * @port: serial port template
3027 * Configure the serial port specified by the request. If the
3028 * port exists and is in use, it is hung up and unregistered
3031 * The port is then probed and if necessary the IRQ is autodetected
3032 * If this fails an error is returned.
3034 * On success the port is ready to use and the line number is returned.
3036 int serial8250_register_port(struct uart_port
*port
)
3038 struct uart_8250_port
*uart
;
3041 if (port
->uartclk
== 0)
3044 mutex_lock(&serial_mutex
);
3046 uart
= serial8250_find_match_or_unused(port
);
3048 uart_remove_one_port(&serial8250_reg
, &uart
->port
);
3050 uart
->port
.iobase
= port
->iobase
;
3051 uart
->port
.membase
= port
->membase
;
3052 uart
->port
.irq
= port
->irq
;
3053 uart
->port
.uartclk
= port
->uartclk
;
3054 uart
->port
.fifosize
= port
->fifosize
;
3055 uart
->port
.regshift
= port
->regshift
;
3056 uart
->port
.iotype
= port
->iotype
;
3057 uart
->port
.flags
= port
->flags
| UPF_BOOT_AUTOCONF
;
3058 uart
->port
.mapbase
= port
->mapbase
;
3059 uart
->port
.private_data
= port
->private_data
;
3061 uart
->port
.dev
= port
->dev
;
3063 if (port
->flags
& UPF_FIXED_TYPE
) {
3064 uart
->port
.type
= port
->type
;
3065 uart
->port
.fifosize
= uart_config
[port
->type
].fifo_size
;
3066 uart
->capabilities
= uart_config
[port
->type
].flags
;
3067 uart
->tx_loadsz
= uart_config
[port
->type
].tx_loadsz
;
3070 set_io_from_upio(&uart
->port
);
3071 /* Possibly override default I/O functions. */
3072 if (port
->serial_in
)
3073 uart
->port
.serial_in
= port
->serial_in
;
3074 if (port
->serial_out
)
3075 uart
->port
.serial_out
= port
->serial_out
;
3077 ret
= uart_add_one_port(&serial8250_reg
, &uart
->port
);
3079 ret
= uart
->port
.line
;
3081 mutex_unlock(&serial_mutex
);
3085 EXPORT_SYMBOL(serial8250_register_port
);
3088 * serial8250_unregister_port - remove a 16x50 serial port at runtime
3089 * @line: serial line number
3091 * Remove one serial port. This may not be called from interrupt
3092 * context. We hand the port back to the our control.
3094 void serial8250_unregister_port(int line
)
3096 struct uart_8250_port
*uart
= &serial8250_ports
[line
];
3098 mutex_lock(&serial_mutex
);
3099 uart_remove_one_port(&serial8250_reg
, &uart
->port
);
3100 if (serial8250_isa_devs
) {
3101 uart
->port
.flags
&= ~UPF_BOOT_AUTOCONF
;
3102 uart
->port
.type
= PORT_UNKNOWN
;
3103 uart
->port
.dev
= &serial8250_isa_devs
->dev
;
3104 uart_add_one_port(&serial8250_reg
, &uart
->port
);
3106 uart
->port
.dev
= NULL
;
3108 mutex_unlock(&serial_mutex
);
3110 EXPORT_SYMBOL(serial8250_unregister_port
);
3112 static int __init
serial8250_init(void)
3116 if (nr_uarts
> UART_NR
)
3119 printk(KERN_INFO
"Serial: 8250/16550 driver"
3120 "%d ports, IRQ sharing %sabled\n", nr_uarts
,
3121 share_irqs
? "en" : "dis");
3124 ret
= sunserial_register_minors(&serial8250_reg
, UART_NR
);
3126 serial8250_reg
.nr
= UART_NR
;
3127 ret
= uart_register_driver(&serial8250_reg
);
3132 serial8250_isa_devs
= platform_device_alloc("serial8250",
3133 PLAT8250_DEV_LEGACY
);
3134 if (!serial8250_isa_devs
) {
3136 goto unreg_uart_drv
;
3139 ret
= platform_device_add(serial8250_isa_devs
);
3143 serial8250_register_ports(&serial8250_reg
, &serial8250_isa_devs
->dev
);
3145 ret
= platform_driver_register(&serial8250_isa_driver
);
3149 platform_device_del(serial8250_isa_devs
);
3151 platform_device_put(serial8250_isa_devs
);
3154 sunserial_unregister_minors(&serial8250_reg
, UART_NR
);
3156 uart_unregister_driver(&serial8250_reg
);
3162 static void __exit
serial8250_exit(void)
3164 struct platform_device
*isa_dev
= serial8250_isa_devs
;
3167 * This tells serial8250_unregister_port() not to re-register
3168 * the ports (thereby making serial8250_isa_driver permanently
3171 serial8250_isa_devs
= NULL
;
3173 platform_driver_unregister(&serial8250_isa_driver
);
3174 platform_device_unregister(isa_dev
);
3177 sunserial_unregister_minors(&serial8250_reg
, UART_NR
);
3179 uart_unregister_driver(&serial8250_reg
);
3183 module_init(serial8250_init
);
3184 module_exit(serial8250_exit
);
3186 EXPORT_SYMBOL(serial8250_suspend_port
);
3187 EXPORT_SYMBOL(serial8250_resume_port
);
3189 MODULE_LICENSE("GPL");
3190 MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
3192 module_param(share_irqs
, uint
, 0644);
3193 MODULE_PARM_DESC(share_irqs
, "Share IRQs with other non-8250/16x50 devices"
3196 module_param(nr_uarts
, uint
, 0644);
3197 MODULE_PARM_DESC(nr_uarts
, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS
) ")");
3199 #ifdef CONFIG_SERIAL_8250_RSA
3200 module_param_array(probe_rsa
, ulong
, &probe_rsa_count
, 0444);
3201 MODULE_PARM_DESC(probe_rsa
, "Probe I/O ports for RSA");
3203 MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR
);