2 * Driver for 8250/16550-type serial ports
4 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
6 * Copyright (C) 2001 Russell King.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * A note about mapbase / membase
15 * mapbase is the physical address of the IO port.
16 * membase is an 'ioremapped' cookie.
19 #if defined(CONFIG_SERIAL_8250_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <linux/ioport.h>
26 #include <linux/init.h>
27 #include <linux/console.h>
28 #include <linux/sysrq.h>
29 #include <linux/delay.h>
30 #include <linux/platform_device.h>
31 #include <linux/tty.h>
32 #include <linux/ratelimit.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial_reg.h>
35 #include <linux/serial_core.h>
36 #include <linux/serial.h>
37 #include <linux/serial_8250.h>
38 #include <linux/nmi.h>
39 #include <linux/mutex.h>
40 #include <linux/slab.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;
67 static unsigned int skip_txen_test; /* force skip of txen test at init time */
73 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
75 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
79 #define DEBUG_INTR(fmt...) printk(fmt)
81 #define DEBUG_INTR(fmt...) do { } while (0)
84 #define PASS_LIMIT 512
86 #define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
90 * We default to IRQ0 for the "no irq" hack. Some
91 * machine types want others as well - they're free
92 * to redefine this in their header file.
94 #define is_real_interrupt(irq) ((irq) != 0)
96 #ifdef CONFIG_SERIAL_8250_DETECT_IRQ
97 #define CONFIG_SERIAL_DETECT_IRQ 1
99 #ifdef CONFIG_SERIAL_8250_MANY_PORTS
100 #define CONFIG_SERIAL_MANY_PORTS 1
104 * HUB6 is always on. This will be removed once the header
105 * files have been cleaned.
107 #define CONFIG_HUB6 1
109 #include <asm/serial.h>
111 * SERIAL_PORT_DFNS tells us about built-in ports that have no
112 * standard enumeration mechanism. Platforms that can find all
113 * serial ports via mechanisms like ACPI or PCI need not supply it.
115 #ifndef SERIAL_PORT_DFNS
116 #define SERIAL_PORT_DFNS
119 static const struct old_serial_port old_serial_port[] = {
120 SERIAL_PORT_DFNS /* defined in asm/serial.h */
123 #define UART_NR CONFIG_SERIAL_8250_NR_UARTS
125 #ifdef CONFIG_SERIAL_8250_RSA
127 #define PORT_RSA_MAX 4
128 static unsigned long probe_rsa[PORT_RSA_MAX];
129 static unsigned int probe_rsa_count;
130 #endif /* CONFIG_SERIAL_8250_RSA */
133 struct hlist_node node;
135 spinlock_t lock; /* Protects list not the hash */
136 struct list_head *head;
139 #define NR_IRQ_HASH 32 /* Can be adjusted later */
140 static struct hlist_head irq_lists[NR_IRQ_HASH];
141 static DEFINE_MUTEX(hash_mutex); /* Used to walk the hash */
144 * Here we define the default xmit fifo size used for each type of UART.
146 static const struct serial8250_config uart_config[] = {
171 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
172 .flags = UART_CAP_FIFO,
183 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
189 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
191 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
197 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10 |
199 .flags = UART_CAP_FIFO | UART_CAP_SLEEP | UART_CAP_AFE,
207 .name = "16C950/954",
210 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
211 /* UART_CAP_EFR breaks billionon CF bluetooth card. */
212 .flags = UART_CAP_FIFO | UART_CAP_SLEEP,
218 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
220 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
226 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
227 .flags = UART_CAP_FIFO | UART_CAP_EFR | UART_CAP_SLEEP,
233 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_11,
234 .flags = UART_CAP_FIFO,
240 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
241 .flags = UART_CAP_FIFO | UART_NATSEMI,
247 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
248 .flags = UART_CAP_FIFO | UART_CAP_UUE | UART_CAP_RTOIE,
254 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
255 .flags = UART_CAP_FIFO,
261 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
262 .flags = UART_CAP_FIFO,
268 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
269 .flags = UART_CAP_FIFO | UART_CAP_AFE,
275 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
276 .flags = UART_CAP_FIFO | UART_CAP_AFE,
282 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 |
284 .flags = UART_CAP_FIFO | UART_CAP_RTOIE,
290 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
291 .flags = UART_CAP_FIFO | UART_CAP_AFE | UART_CAP_EFR,
295 #if defined(CONFIG_MIPS_ALCHEMY)
297 /* Au1x00 UART hardware has a weird register layout */
298 static const u8 au_io_in_map[] = {
308 static const u8 au_io_out_map[] = {
316 /* sane hardware needs no mapping */
317 static inline int map_8250_in_reg(struct uart_port *p, int offset)
319 if (p->iotype != UPIO_AU)
321 return au_io_in_map[offset];
324 static inline int map_8250_out_reg(struct uart_port *p, int offset)
326 if (p->iotype != UPIO_AU)
328 return au_io_out_map[offset];
331 #elif defined(CONFIG_SERIAL_8250_RM9K)
355 static inline int map_8250_in_reg(struct uart_port *p, int offset)
357 if (p->iotype != UPIO_RM9000)
359 return regmap_in[offset];
362 static inline int map_8250_out_reg(struct uart_port *p, int offset)
364 if (p->iotype != UPIO_RM9000)
366 return regmap_out[offset];
371 /* sane hardware needs no mapping */
372 #define map_8250_in_reg(up, offset) (offset)
373 #define map_8250_out_reg(up, offset) (offset)
377 static unsigned int hub6_serial_in(struct uart_port *p, int offset)
379 offset = map_8250_in_reg(p, offset) << p->regshift;
380 outb(p->hub6 - 1 + offset, p->iobase);
381 return inb(p->iobase + 1);
384 static void hub6_serial_out(struct uart_port *p, int offset, int value)
386 offset = map_8250_out_reg(p, offset) << p->regshift;
387 outb(p->hub6 - 1 + offset, p->iobase);
388 outb(value, p->iobase + 1);
391 static unsigned int mem_serial_in(struct uart_port *p, int offset)
393 offset = map_8250_in_reg(p, offset) << p->regshift;
394 return readb(p->membase + offset);
397 static void mem_serial_out(struct uart_port *p, int offset, int value)
399 offset = map_8250_out_reg(p, offset) << p->regshift;
400 writeb(value, p->membase + offset);
403 static void mem32_serial_out(struct uart_port *p, int offset, int value)
405 offset = map_8250_out_reg(p, offset) << p->regshift;
406 writel(value, p->membase + offset);
409 static unsigned int mem32_serial_in(struct uart_port *p, int offset)
411 offset = map_8250_in_reg(p, offset) << p->regshift;
412 return readl(p->membase + offset);
415 static unsigned int au_serial_in(struct uart_port *p, int offset)
417 offset = map_8250_in_reg(p, offset) << p->regshift;
418 return __raw_readl(p->membase + offset);
421 static void au_serial_out(struct uart_port *p, int offset, int value)
423 offset = map_8250_out_reg(p, offset) << p->regshift;
424 __raw_writel(value, p->membase + offset);
427 static unsigned int io_serial_in(struct uart_port *p, int offset)
429 offset = map_8250_in_reg(p, offset) << p->regshift;
430 return inb(p->iobase + offset);
433 static void io_serial_out(struct uart_port *p, int offset, int value)
435 offset = map_8250_out_reg(p, offset) << p->regshift;
436 outb(value, p->iobase + offset);
439 static int serial8250_default_handle_irq(struct uart_port *port);
441 static void set_io_from_upio(struct uart_port *p)
443 struct uart_8250_port *up =
444 container_of(p, struct uart_8250_port, port);
447 p->serial_in = hub6_serial_in;
448 p->serial_out = hub6_serial_out;
452 p->serial_in = mem_serial_in;
453 p->serial_out = mem_serial_out;
458 p->serial_in = mem32_serial_in;
459 p->serial_out = mem32_serial_out;
463 p->serial_in = au_serial_in;
464 p->serial_out = au_serial_out;
468 p->serial_in = io_serial_in;
469 p->serial_out = io_serial_out;
472 /* Remember loaded iotype */
473 up->cur_iotype = p->iotype;
474 p->handle_irq = serial8250_default_handle_irq;
478 serial_out_sync(struct uart_8250_port *up, int offset, int value)
480 struct uart_port *p = &up->port;
485 p->serial_out(p, offset, value);
486 p->serial_in(p, UART_LCR); /* safe, no side-effects */
489 p->serial_out(p, offset, value);
493 #define serial_in(up, offset) \
494 (up->port.serial_in(&(up)->port, (offset)))
495 #define serial_out(up, offset, value) \
496 (up->port.serial_out(&(up)->port, (offset), (value)))
498 * We used to support using pause I/O for certain machines. We
499 * haven't supported this for a while, but just in case it's badly
500 * needed for certain old 386 machines, I've left these #define's
503 #define serial_inp(up, offset) serial_in(up, offset)
504 #define serial_outp(up, offset, value) serial_out(up, offset, value)
506 /* Uart divisor latch read */
507 static inline int _serial_dl_read(struct uart_8250_port *up)
509 return serial_inp(up, UART_DLL) | serial_inp(up, UART_DLM) << 8;
512 /* Uart divisor latch write */
513 static inline void _serial_dl_write(struct uart_8250_port *up, int value)
515 serial_outp(up, UART_DLL, value & 0xff);
516 serial_outp(up, UART_DLM, value >> 8 & 0xff);
519 #if defined(CONFIG_MIPS_ALCHEMY)
520 /* Au1x00 haven't got a standard divisor latch */
521 static int serial_dl_read(struct uart_8250_port *up)
523 if (up->port.iotype == UPIO_AU)
524 return __raw_readl(up->port.membase + 0x28);
526 return _serial_dl_read(up);
529 static void serial_dl_write(struct uart_8250_port *up, int value)
531 if (up->port.iotype == UPIO_AU)
532 __raw_writel(value, up->port.membase + 0x28);
534 _serial_dl_write(up, value);
536 #elif defined(CONFIG_SERIAL_8250_RM9K)
537 static int serial_dl_read(struct uart_8250_port *up)
539 return (up->port.iotype == UPIO_RM9000) ?
540 (((__raw_readl(up->port.membase + 0x10) << 8) |
541 (__raw_readl(up->port.membase + 0x08) & 0xff)) & 0xffff) :
545 static void serial_dl_write(struct uart_8250_port *up, int value)
547 if (up->port.iotype == UPIO_RM9000) {
548 __raw_writel(value, up->port.membase + 0x08);
549 __raw_writel(value >> 8, up->port.membase + 0x10);
551 _serial_dl_write(up, value);
555 #define serial_dl_read(up) _serial_dl_read(up)
556 #define serial_dl_write(up, value) _serial_dl_write(up, value)
562 static void serial_icr_write(struct uart_8250_port *up, int offset, int value)
564 serial_out(up, UART_SCR, offset);
565 serial_out(up, UART_ICR, value);
568 static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
572 serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
573 serial_out(up, UART_SCR, offset);
574 value = serial_in(up, UART_ICR);
575 serial_icr_write(up, UART_ACR, up->acr);
583 static void serial8250_clear_fifos(struct uart_8250_port *p)
585 if (p->capabilities & UART_CAP_FIFO) {
586 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO);
587 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO |
588 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
589 serial_outp(p, UART_FCR, 0);
594 * IER sleep support. UARTs which have EFRs need the "extended
595 * capability" bit enabled. Note that on XR16C850s, we need to
596 * reset LCR to write to IER.
598 static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
600 if (p->capabilities & UART_CAP_SLEEP) {
601 if (p->capabilities & UART_CAP_EFR) {
602 serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B);
603 serial_outp(p, UART_EFR, UART_EFR_ECB);
604 serial_outp(p, UART_LCR, 0);
606 serial_outp(p, UART_IER, sleep ? UART_IERX_SLEEP : 0);
607 if (p->capabilities & UART_CAP_EFR) {
608 serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_B);
609 serial_outp(p, UART_EFR, 0);
610 serial_outp(p, UART_LCR, 0);
615 #ifdef CONFIG_SERIAL_8250_RSA
617 * Attempts to turn on the RSA FIFO. Returns zero on failure.
618 * We set the port uart clock rate if we succeed.
620 static int __enable_rsa(struct uart_8250_port *up)
625 mode = serial_inp(up, UART_RSA_MSR);
626 result = mode & UART_RSA_MSR_FIFO;
629 serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
630 mode = serial_inp(up, UART_RSA_MSR);
631 result = mode & UART_RSA_MSR_FIFO;
635 up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
640 static void enable_rsa(struct uart_8250_port *up)
642 if (up->port.type == PORT_RSA) {
643 if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
644 spin_lock_irq(&up->port.lock);
646 spin_unlock_irq(&up->port.lock);
648 if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
649 serial_outp(up, UART_RSA_FRR, 0);
654 * Attempts to turn off the RSA FIFO. Returns zero on failure.
655 * It is unknown why interrupts were disabled in here. However,
656 * the caller is expected to preserve this behaviour by grabbing
657 * the spinlock before calling this function.
659 static void disable_rsa(struct uart_8250_port *up)
664 if (up->port.type == PORT_RSA &&
665 up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
666 spin_lock_irq(&up->port.lock);
668 mode = serial_inp(up, UART_RSA_MSR);
669 result = !(mode & UART_RSA_MSR_FIFO);
672 serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
673 mode = serial_inp(up, UART_RSA_MSR);
674 result = !(mode & UART_RSA_MSR_FIFO);
678 up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
679 spin_unlock_irq(&up->port.lock);
682 #endif /* CONFIG_SERIAL_8250_RSA */
685 * This is a quickie test to see how big the FIFO is.
686 * It doesn't work at all the time, more's the pity.
688 static int size_fifo(struct uart_8250_port *up)
690 unsigned char old_fcr, old_mcr, old_lcr;
691 unsigned short old_dl;
694 old_lcr = serial_inp(up, UART_LCR);
695 serial_outp(up, UART_LCR, 0);
696 old_fcr = serial_inp(up, UART_FCR);
697 old_mcr = serial_inp(up, UART_MCR);
698 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
699 UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
700 serial_outp(up, UART_MCR, UART_MCR_LOOP);
701 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A);
702 old_dl = serial_dl_read(up);
703 serial_dl_write(up, 0x0001);
704 serial_outp(up, UART_LCR, 0x03);
705 for (count = 0; count < 256; count++)
706 serial_outp(up, UART_TX, count);
707 mdelay(20);/* FIXME - schedule_timeout */
708 for (count = 0; (serial_inp(up, UART_LSR) & UART_LSR_DR) &&
709 (count < 256); count++)
710 serial_inp(up, UART_RX);
711 serial_outp(up, UART_FCR, old_fcr);
712 serial_outp(up, UART_MCR, old_mcr);
713 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A);
714 serial_dl_write(up, old_dl);
715 serial_outp(up, UART_LCR, old_lcr);
721 * Read UART ID using the divisor method - set DLL and DLM to zero
722 * and the revision will be in DLL and device type in DLM. We
723 * preserve the device state across this.
725 static unsigned int autoconfig_read_divisor_id(struct uart_8250_port *p)
727 unsigned char old_dll, old_dlm, old_lcr;
730 old_lcr = serial_inp(p, UART_LCR);
731 serial_outp(p, UART_LCR, UART_LCR_CONF_MODE_A);
733 old_dll = serial_inp(p, UART_DLL);
734 old_dlm = serial_inp(p, UART_DLM);
736 serial_outp(p, UART_DLL, 0);
737 serial_outp(p, UART_DLM, 0);
739 id = serial_inp(p, UART_DLL) | serial_inp(p, UART_DLM) << 8;
741 serial_outp(p, UART_DLL, old_dll);
742 serial_outp(p, UART_DLM, old_dlm);
743 serial_outp(p, UART_LCR, old_lcr);
749 * This is a helper routine to autodetect StarTech/Exar/Oxsemi UART's.
750 * When this function is called we know it is at least a StarTech
751 * 16650 V2, but it might be one of several StarTech UARTs, or one of
752 * its clones. (We treat the broken original StarTech 16650 V1 as a
753 * 16550, and why not? Startech doesn't seem to even acknowledge its
756 * What evil have men's minds wrought...
758 static void autoconfig_has_efr(struct uart_8250_port *up)
760 unsigned int id1, id2, id3, rev;
763 * Everything with an EFR has SLEEP
765 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
768 * First we check to see if it's an Oxford Semiconductor UART.
770 * If we have to do this here because some non-National
771 * Semiconductor clone chips lock up if you try writing to the
772 * LSR register (which serial_icr_read does)
776 * Check for Oxford Semiconductor 16C950.
778 * EFR [4] must be set else this test fails.
780 * This shouldn't be necessary, but Mike Hudson (Exoray@isys.ca)
781 * claims that it's needed for 952 dual UART's (which are not
782 * recommended for new designs).
785 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
786 serial_out(up, UART_EFR, UART_EFR_ECB);
787 serial_out(up, UART_LCR, 0x00);
788 id1 = serial_icr_read(up, UART_ID1);
789 id2 = serial_icr_read(up, UART_ID2);
790 id3 = serial_icr_read(up, UART_ID3);
791 rev = serial_icr_read(up, UART_REV);
793 DEBUG_AUTOCONF("950id=%02x:%02x:%02x:%02x ", id1, id2, id3, rev);
795 if (id1 == 0x16 && id2 == 0xC9 &&
796 (id3 == 0x50 || id3 == 0x52 || id3 == 0x54)) {
797 up->port.type = PORT_16C950;
800 * Enable work around for the Oxford Semiconductor 952 rev B
801 * chip which causes it to seriously miscalculate baud rates
804 if (id3 == 0x52 && rev == 0x01)
805 up->bugs |= UART_BUG_QUOT;
810 * We check for a XR16C850 by setting DLL and DLM to 0, and then
811 * reading back DLL and DLM. The chip type depends on the DLM
813 * 0x10 - XR16C850 and the DLL contains the chip revision.
817 id1 = autoconfig_read_divisor_id(up);
818 DEBUG_AUTOCONF("850id=%04x ", id1);
821 if (id2 == 0x10 || id2 == 0x12 || id2 == 0x14) {
822 up->port.type = PORT_16850;
827 * It wasn't an XR16C850.
829 * We distinguish between the '654 and the '650 by counting
830 * how many bytes are in the FIFO. I'm using this for now,
831 * since that's the technique that was sent to me in the
832 * serial driver update, but I'm not convinced this works.
833 * I've had problems doing this in the past. -TYT
835 if (size_fifo(up) == 64)
836 up->port.type = PORT_16654;
838 up->port.type = PORT_16650V2;
842 * We detected a chip without a FIFO. Only two fall into
843 * this category - the original 8250 and the 16450. The
844 * 16450 has a scratch register (accessible with LCR=0)
846 static void autoconfig_8250(struct uart_8250_port *up)
848 unsigned char scratch, status1, status2;
850 up->port.type = PORT_8250;
852 scratch = serial_in(up, UART_SCR);
853 serial_outp(up, UART_SCR, 0xa5);
854 status1 = serial_in(up, UART_SCR);
855 serial_outp(up, UART_SCR, 0x5a);
856 status2 = serial_in(up, UART_SCR);
857 serial_outp(up, UART_SCR, scratch);
859 if (status1 == 0xa5 && status2 == 0x5a)
860 up->port.type = PORT_16450;
863 static int broken_efr(struct uart_8250_port *up)
866 * Exar ST16C2550 "A2" devices incorrectly detect as
867 * having an EFR, and report an ID of 0x0201. See
868 * http://linux.derkeiler.com/Mailing-Lists/Kernel/2004-11/4812.html
870 if (autoconfig_read_divisor_id(up) == 0x0201 && size_fifo(up) == 16)
876 static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
878 unsigned char status;
880 status = serial_in(up, 0x04); /* EXCR2 */
881 #define PRESL(x) ((x) & 0x30)
882 if (PRESL(status) == 0x10) {
883 /* already in high speed mode */
886 status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
887 status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
888 serial_outp(up, 0x04, status);
894 * We know that the chip has FIFOs. Does it have an EFR? The
895 * EFR is located in the same register position as the IIR and
896 * we know the top two bits of the IIR are currently set. The
897 * EFR should contain zero. Try to read the EFR.
899 static void autoconfig_16550a(struct uart_8250_port *up)
901 unsigned char status1, status2;
902 unsigned int iersave;
904 up->port.type = PORT_16550A;
905 up->capabilities |= UART_CAP_FIFO;
908 * Check for presence of the EFR when DLAB is set.
909 * Only ST16C650V1 UARTs pass this test.
911 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A);
912 if (serial_in(up, UART_EFR) == 0) {
913 serial_outp(up, UART_EFR, 0xA8);
914 if (serial_in(up, UART_EFR) != 0) {
915 DEBUG_AUTOCONF("EFRv1 ");
916 up->port.type = PORT_16650;
917 up->capabilities |= UART_CAP_EFR | UART_CAP_SLEEP;
919 DEBUG_AUTOCONF("Motorola 8xxx DUART ");
921 serial_outp(up, UART_EFR, 0);
926 * Maybe it requires 0xbf to be written to the LCR.
927 * (other ST16C650V2 UARTs, TI16C752A, etc)
929 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
930 if (serial_in(up, UART_EFR) == 0 && !broken_efr(up)) {
931 DEBUG_AUTOCONF("EFRv2 ");
932 autoconfig_has_efr(up);
937 * Check for a National Semiconductor SuperIO chip.
938 * Attempt to switch to bank 2, read the value of the LOOP bit
939 * from EXCR1. Switch back to bank 0, change it in MCR. Then
940 * switch back to bank 2, read it from EXCR1 again and check
941 * it's changed. If so, set baud_base in EXCR2 to 921600. -- dwmw2
943 serial_outp(up, UART_LCR, 0);
944 status1 = serial_in(up, UART_MCR);
945 serial_outp(up, UART_LCR, 0xE0);
946 status2 = serial_in(up, 0x02); /* EXCR1 */
948 if (!((status2 ^ status1) & UART_MCR_LOOP)) {
949 serial_outp(up, UART_LCR, 0);
950 serial_outp(up, UART_MCR, status1 ^ UART_MCR_LOOP);
951 serial_outp(up, UART_LCR, 0xE0);
952 status2 = serial_in(up, 0x02); /* EXCR1 */
953 serial_outp(up, UART_LCR, 0);
954 serial_outp(up, UART_MCR, status1);
956 if ((status2 ^ status1) & UART_MCR_LOOP) {
959 serial_outp(up, UART_LCR, 0xE0);
961 quot = serial_dl_read(up);
964 if (ns16550a_goto_highspeed(up))
965 serial_dl_write(up, quot);
967 serial_outp(up, UART_LCR, 0);
969 up->port.uartclk = 921600*16;
970 up->port.type = PORT_NS16550A;
971 up->capabilities |= UART_NATSEMI;
977 * No EFR. Try to detect a TI16750, which only sets bit 5 of
978 * the IIR when 64 byte FIFO mode is enabled when DLAB is set.
979 * Try setting it with and without DLAB set. Cheap clones
980 * set bit 5 without DLAB set.
982 serial_outp(up, UART_LCR, 0);
983 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
984 status1 = serial_in(up, UART_IIR) >> 5;
985 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
986 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_A);
987 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
988 status2 = serial_in(up, UART_IIR) >> 5;
989 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
990 serial_outp(up, UART_LCR, 0);
992 DEBUG_AUTOCONF("iir1=%d iir2=%d ", status1, status2);
994 if (status1 == 6 && status2 == 7) {
995 up->port.type = PORT_16750;
996 up->capabilities |= UART_CAP_AFE | UART_CAP_SLEEP;
1001 * Try writing and reading the UART_IER_UUE bit (b6).
1002 * If it works, this is probably one of the Xscale platform's
1004 * We're going to explicitly set the UUE bit to 0 before
1005 * trying to write and read a 1 just to make sure it's not
1006 * already a 1 and maybe locked there before we even start start.
1008 iersave = serial_in(up, UART_IER);
1009 serial_outp(up, UART_IER, iersave & ~UART_IER_UUE);
1010 if (!(serial_in(up, UART_IER) & UART_IER_UUE)) {
1012 * OK it's in a known zero state, try writing and reading
1013 * without disturbing the current state of the other bits.
1015 serial_outp(up, UART_IER, iersave | UART_IER_UUE);
1016 if (serial_in(up, UART_IER) & UART_IER_UUE) {
1019 * We'll leave the UART_IER_UUE bit set to 1 (enabled).
1021 DEBUG_AUTOCONF("Xscale ");
1022 up->port.type = PORT_XSCALE;
1023 up->capabilities |= UART_CAP_UUE | UART_CAP_RTOIE;
1028 * If we got here we couldn't force the IER_UUE bit to 0.
1029 * Log it and continue.
1031 DEBUG_AUTOCONF("Couldn't force IER_UUE to 0 ");
1033 serial_outp(up, UART_IER, iersave);
1036 * Exar uarts have EFR in a weird location
1038 if (up->port.flags & UPF_EXAR_EFR) {
1039 up->port.type = PORT_XR17D15X;
1040 up->capabilities |= UART_CAP_AFE | UART_CAP_EFR;
1044 * We distinguish between 16550A and U6 16550A by counting
1045 * how many bytes are in the FIFO.
1047 if (up->port.type == PORT_16550A && size_fifo(up) == 64) {
1048 up->port.type = PORT_U6_16550A;
1049 up->capabilities |= UART_CAP_AFE;
1054 * This routine is called by rs_init() to initialize a specific serial
1055 * port. It determines what type of UART chip this serial port is
1056 * using: 8250, 16450, 16550, 16550A. The important question is
1057 * whether or not this UART is a 16550A or not, since this will
1058 * determine whether or not we can use its FIFO features or not.
1060 static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
1062 unsigned char status1, scratch, scratch2, scratch3;
1063 unsigned char save_lcr, save_mcr;
1064 unsigned long flags;
1066 if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
1069 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ",
1070 serial_index(&up->port), up->port.iobase, up->port.membase);
1073 * We really do need global IRQs disabled here - we're going to
1074 * be frobbing the chips IRQ enable register to see if it exists.
1076 spin_lock_irqsave(&up->port.lock, flags);
1078 up->capabilities = 0;
1081 if (!(up->port.flags & UPF_BUGGY_UART)) {
1083 * Do a simple existence test first; if we fail this,
1084 * there's no point trying anything else.
1086 * 0x80 is used as a nonsense port to prevent against
1087 * false positives due to ISA bus float. The
1088 * assumption is that 0x80 is a non-existent port;
1089 * which should be safe since include/asm/io.h also
1090 * makes this assumption.
1092 * Note: this is safe as long as MCR bit 4 is clear
1093 * and the device is in "PC" mode.
1095 scratch = serial_inp(up, UART_IER);
1096 serial_outp(up, UART_IER, 0);
1101 * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
1102 * 16C754B) allow only to modify them if an EFR bit is set.
1104 scratch2 = serial_inp(up, UART_IER) & 0x0f;
1105 serial_outp(up, UART_IER, 0x0F);
1109 scratch3 = serial_inp(up, UART_IER) & 0x0f;
1110 serial_outp(up, UART_IER, scratch);
1111 if (scratch2 != 0 || scratch3 != 0x0F) {
1113 * We failed; there's nothing here
1115 DEBUG_AUTOCONF("IER test failed (%02x, %02x) ",
1116 scratch2, scratch3);
1121 save_mcr = serial_in(up, UART_MCR);
1122 save_lcr = serial_in(up, UART_LCR);
1125 * Check to see if a UART is really there. Certain broken
1126 * internal modems based on the Rockwell chipset fail this
1127 * test, because they apparently don't implement the loopback
1128 * test mode. So this test is skipped on the COM 1 through
1129 * COM 4 ports. This *should* be safe, since no board
1130 * manufacturer would be stupid enough to design a board
1131 * that conflicts with COM 1-4 --- we hope!
1133 if (!(up->port.flags & UPF_SKIP_TEST)) {
1134 serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
1135 status1 = serial_inp(up, UART_MSR) & 0xF0;
1136 serial_outp(up, UART_MCR, save_mcr);
1137 if (status1 != 0x90) {
1138 DEBUG_AUTOCONF("LOOP test failed (%02x) ",
1145 * We're pretty sure there's a port here. Lets find out what
1146 * type of port it is. The IIR top two bits allows us to find
1147 * out if it's 8250 or 16450, 16550, 16550A or later. This
1148 * determines what we test for next.
1150 * We also initialise the EFR (if any) to zero for later. The
1151 * EFR occupies the same register location as the FCR and IIR.
1153 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
1154 serial_outp(up, UART_EFR, 0);
1155 serial_outp(up, UART_LCR, 0);
1157 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
1158 scratch = serial_in(up, UART_IIR) >> 6;
1160 DEBUG_AUTOCONF("iir=%d ", scratch);
1164 autoconfig_8250(up);
1167 up->port.type = PORT_UNKNOWN;
1170 up->port.type = PORT_16550;
1173 autoconfig_16550a(up);
1177 #ifdef CONFIG_SERIAL_8250_RSA
1179 * Only probe for RSA ports if we got the region.
1181 if (up->port.type == PORT_16550A && probeflags & PROBE_RSA) {
1184 for (i = 0 ; i < probe_rsa_count; ++i) {
1185 if (probe_rsa[i] == up->port.iobase &&
1187 up->port.type = PORT_RSA;
1194 serial_outp(up, UART_LCR, save_lcr);
1196 if (up->capabilities != uart_config[up->port.type].flags) {
1198 "ttyS%d: detected caps %08x should be %08x\n",
1199 serial_index(&up->port), up->capabilities,
1200 uart_config[up->port.type].flags);
1203 up->port.fifosize = uart_config[up->port.type].fifo_size;
1204 up->capabilities = uart_config[up->port.type].flags;
1205 up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
1207 if (up->port.type == PORT_UNKNOWN)
1213 #ifdef CONFIG_SERIAL_8250_RSA
1214 if (up->port.type == PORT_RSA)
1215 serial_outp(up, UART_RSA_FRR, 0);
1217 serial_outp(up, UART_MCR, save_mcr);
1218 serial8250_clear_fifos(up);
1219 serial_in(up, UART_RX);
1220 if (up->capabilities & UART_CAP_UUE)
1221 serial_outp(up, UART_IER, UART_IER_UUE);
1223 serial_outp(up, UART_IER, 0);
1226 spin_unlock_irqrestore(&up->port.lock, flags);
1227 DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
1230 static void autoconfig_irq(struct uart_8250_port *up)
1232 unsigned char save_mcr, save_ier;
1233 unsigned char save_ICP = 0;
1234 unsigned int ICP = 0;
1238 if (up->port.flags & UPF_FOURPORT) {
1239 ICP = (up->port.iobase & 0xfe0) | 0x1f;
1240 save_ICP = inb_p(ICP);
1245 /* forget possible initially masked and pending IRQ */
1246 probe_irq_off(probe_irq_on());
1247 save_mcr = serial_inp(up, UART_MCR);
1248 save_ier = serial_inp(up, UART_IER);
1249 serial_outp(up, UART_MCR, UART_MCR_OUT1 | UART_MCR_OUT2);
1251 irqs = probe_irq_on();
1252 serial_outp(up, UART_MCR, 0);
1254 if (up->port.flags & UPF_FOURPORT) {
1255 serial_outp(up, UART_MCR,
1256 UART_MCR_DTR | UART_MCR_RTS);
1258 serial_outp(up, UART_MCR,
1259 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
1261 serial_outp(up, UART_IER, 0x0f); /* enable all intrs */
1262 (void)serial_inp(up, UART_LSR);
1263 (void)serial_inp(up, UART_RX);
1264 (void)serial_inp(up, UART_IIR);
1265 (void)serial_inp(up, UART_MSR);
1266 serial_outp(up, UART_TX, 0xFF);
1268 irq = probe_irq_off(irqs);
1270 serial_outp(up, UART_MCR, save_mcr);
1271 serial_outp(up, UART_IER, save_ier);
1273 if (up->port.flags & UPF_FOURPORT)
1274 outb_p(save_ICP, ICP);
1276 up->port.irq = (irq > 0) ? irq : 0;
1279 static inline void __stop_tx(struct uart_8250_port *p)
1281 if (p->ier & UART_IER_THRI) {
1282 p->ier &= ~UART_IER_THRI;
1283 serial_out(p, UART_IER, p->ier);
1287 static void serial8250_stop_tx(struct uart_port *port)
1289 struct uart_8250_port *up =
1290 container_of(port, struct uart_8250_port, port);
1295 * We really want to stop the transmitter from sending.
1297 if (up->port.type == PORT_16C950) {
1298 up->acr |= UART_ACR_TXDIS;
1299 serial_icr_write(up, UART_ACR, up->acr);
1303 static void serial8250_start_tx(struct uart_port *port)
1305 struct uart_8250_port *up =
1306 container_of(port, struct uart_8250_port, port);
1308 if (!(up->ier & UART_IER_THRI)) {
1309 up->ier |= UART_IER_THRI;
1310 serial_out(up, UART_IER, up->ier);
1312 if (up->bugs & UART_BUG_TXEN) {
1314 lsr = serial_in(up, UART_LSR);
1315 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1316 if ((up->port.type == PORT_RM9000) ?
1317 (lsr & UART_LSR_THRE) :
1318 (lsr & UART_LSR_TEMT))
1319 serial8250_tx_chars(up);
1324 * Re-enable the transmitter if we disabled it.
1326 if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
1327 up->acr &= ~UART_ACR_TXDIS;
1328 serial_icr_write(up, UART_ACR, up->acr);
1332 static void serial8250_stop_rx(struct uart_port *port)
1334 struct uart_8250_port *up =
1335 container_of(port, struct uart_8250_port, port);
1337 up->ier &= ~UART_IER_RLSI;
1338 up->port.read_status_mask &= ~UART_LSR_DR;
1339 serial_out(up, UART_IER, up->ier);
1342 static void serial8250_enable_ms(struct uart_port *port)
1344 struct uart_8250_port *up =
1345 container_of(port, struct uart_8250_port, port);
1347 /* no MSR capabilities */
1348 if (up->bugs & UART_BUG_NOMSR)
1351 up->ier |= UART_IER_MSI;
1352 serial_out(up, UART_IER, up->ier);
1356 * Clear the Tegra rx fifo after a break
1358 * FIXME: This needs to become a port specific callback once we have a
1359 * framework for this
1361 static void clear_rx_fifo(struct uart_8250_port *up)
1363 unsigned int status, tmout = 10000;
1365 status = serial_in(up, UART_LSR);
1366 if (status & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
1367 status = serial_in(up, UART_RX);
1377 * serial8250_rx_chars: processes according to the passed in LSR
1378 * value, and returns the remaining LSR bits not handled
1379 * by this Rx routine.
1382 serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr)
1384 struct tty_struct *tty = up->port.state->port.tty;
1386 int max_count = 256;
1390 if (likely(lsr & UART_LSR_DR))
1391 ch = serial_inp(up, UART_RX);
1394 * Intel 82571 has a Serial Over Lan device that will
1395 * set UART_LSR_BI without setting UART_LSR_DR when
1396 * it receives a break. To avoid reading from the
1397 * receive buffer without UART_LSR_DR bit set, we
1398 * just force the read character to be 0
1403 up->port.icount.rx++;
1405 lsr |= up->lsr_saved_flags;
1406 up->lsr_saved_flags = 0;
1408 if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
1410 * For statistics only
1412 if (lsr & UART_LSR_BI) {
1413 lsr &= ~(UART_LSR_FE | UART_LSR_PE);
1414 up->port.icount.brk++;
1416 * If tegra port then clear the rx fifo to
1417 * accept another break/character.
1419 if (up->port.type == PORT_TEGRA)
1423 * We do the SysRQ and SAK checking
1424 * here because otherwise the break
1425 * may get masked by ignore_status_mask
1426 * or read_status_mask.
1428 if (uart_handle_break(&up->port))
1430 } else if (lsr & UART_LSR_PE)
1431 up->port.icount.parity++;
1432 else if (lsr & UART_LSR_FE)
1433 up->port.icount.frame++;
1434 if (lsr & UART_LSR_OE)
1435 up->port.icount.overrun++;
1438 * Mask off conditions which should be ignored.
1440 lsr &= up->port.read_status_mask;
1442 if (lsr & UART_LSR_BI) {
1443 DEBUG_INTR("handling break....");
1445 } else if (lsr & UART_LSR_PE)
1447 else if (lsr & UART_LSR_FE)
1450 if (uart_handle_sysrq_char(&up->port, ch))
1453 uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
1456 lsr = serial_inp(up, UART_LSR);
1457 } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
1458 spin_unlock(&up->port.lock);
1459 tty_flip_buffer_push(tty);
1460 spin_lock(&up->port.lock);
1463 EXPORT_SYMBOL_GPL(serial8250_rx_chars);
1465 void serial8250_tx_chars(struct uart_8250_port *up)
1467 struct circ_buf *xmit = &up->port.state->xmit;
1470 if (up->port.x_char) {
1471 serial_outp(up, UART_TX, up->port.x_char);
1472 up->port.icount.tx++;
1473 up->port.x_char = 0;
1476 if (uart_tx_stopped(&up->port)) {
1477 serial8250_stop_tx(&up->port);
1480 if (uart_circ_empty(xmit)) {
1485 count = up->tx_loadsz;
1487 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
1488 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
1489 up->port.icount.tx++;
1490 if (uart_circ_empty(xmit))
1492 } while (--count > 0);
1494 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
1495 uart_write_wakeup(&up->port);
1497 DEBUG_INTR("THRE...");
1499 if (uart_circ_empty(xmit))
1502 EXPORT_SYMBOL_GPL(serial8250_tx_chars);
1504 unsigned int serial8250_modem_status(struct uart_8250_port *up)
1506 unsigned int status = serial_in(up, UART_MSR);
1508 status |= up->msr_saved_flags;
1509 up->msr_saved_flags = 0;
1510 if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
1511 up->port.state != NULL) {
1512 if (status & UART_MSR_TERI)
1513 up->port.icount.rng++;
1514 if (status & UART_MSR_DDSR)
1515 up->port.icount.dsr++;
1516 if (status & UART_MSR_DDCD)
1517 uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
1518 if (status & UART_MSR_DCTS)
1519 uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
1521 wake_up_interruptible(&up->port.state->port.delta_msr_wait);
1526 EXPORT_SYMBOL_GPL(serial8250_modem_status);
1529 * This handles the interrupt from one port.
1531 int serial8250_handle_irq(struct uart_port *port, unsigned int iir)
1533 unsigned char status;
1534 unsigned long flags;
1535 struct uart_8250_port *up =
1536 container_of(port, struct uart_8250_port, port);
1538 if (iir & UART_IIR_NO_INT)
1541 spin_lock_irqsave(&up->port.lock, flags);
1543 status = serial_inp(up, UART_LSR);
1545 DEBUG_INTR("status = %x...", status);
1547 if (status & (UART_LSR_DR | UART_LSR_BI))
1548 status = serial8250_rx_chars(up, status);
1549 serial8250_modem_status(up);
1550 if (status & UART_LSR_THRE)
1551 serial8250_tx_chars(up);
1553 spin_unlock_irqrestore(&up->port.lock, flags);
1556 EXPORT_SYMBOL_GPL(serial8250_handle_irq);
1558 static int serial8250_default_handle_irq(struct uart_port *port)
1560 struct uart_8250_port *up =
1561 container_of(port, struct uart_8250_port, port);
1562 unsigned int iir = serial_in(up, UART_IIR);
1564 return serial8250_handle_irq(port, iir);
1568 * This is the serial driver's interrupt routine.
1570 * Arjan thinks the old way was overly complex, so it got simplified.
1571 * Alan disagrees, saying that need the complexity to handle the weird
1572 * nature of ISA shared interrupts. (This is a special exception.)
1574 * In order to handle ISA shared interrupts properly, we need to check
1575 * that all ports have been serviced, and therefore the ISA interrupt
1576 * line has been de-asserted.
1578 * This means we need to loop through all ports. checking that they
1579 * don't have an interrupt pending.
1581 static irqreturn_t serial8250_interrupt(int irq, void *dev_id)
1583 struct irq_info *i = dev_id;
1584 struct list_head *l, *end = NULL;
1585 int pass_counter = 0, handled = 0;
1587 DEBUG_INTR("serial8250_interrupt(%d)...", irq);
1589 spin_lock(&i->lock);
1593 struct uart_8250_port *up;
1594 struct uart_port *port;
1597 up = list_entry(l, struct uart_8250_port, list);
1599 skip = pass_counter && up->port.flags & UPF_IIR_ONCE;
1601 if (!skip && port->handle_irq(port)) {
1604 } else if (end == NULL)
1609 if (l == i->head && pass_counter++ > PASS_LIMIT) {
1610 /* If we hit this, we're dead. */
1611 printk_ratelimited(KERN_ERR
1612 "serial8250: too much work for irq%d\n", irq);
1617 spin_unlock(&i->lock);
1619 DEBUG_INTR("end.\n");
1621 return IRQ_RETVAL(handled);
1625 * To support ISA shared interrupts, we need to have one interrupt
1626 * handler that ensures that the IRQ line has been deasserted
1627 * before returning. Failing to do this will result in the IRQ
1628 * line being stuck active, and, since ISA irqs are edge triggered,
1629 * no more IRQs will be seen.
1631 static void serial_do_unlink(struct irq_info *i, struct uart_8250_port *up)
1633 spin_lock_irq(&i->lock);
1635 if (!list_empty(i->head)) {
1636 if (i->head == &up->list)
1637 i->head = i->head->next;
1638 list_del(&up->list);
1640 BUG_ON(i->head != &up->list);
1643 spin_unlock_irq(&i->lock);
1644 /* List empty so throw away the hash node */
1645 if (i->head == NULL) {
1646 hlist_del(&i->node);
1651 static int serial_link_irq_chain(struct uart_8250_port *up)
1653 struct hlist_head *h;
1654 struct hlist_node *n;
1656 int ret, irq_flags = up->port.flags & UPF_SHARE_IRQ ? IRQF_SHARED : 0;
1658 mutex_lock(&hash_mutex);
1660 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1662 hlist_for_each(n, h) {
1663 i = hlist_entry(n, struct irq_info, node);
1664 if (i->irq == up->port.irq)
1669 i = kzalloc(sizeof(struct irq_info), GFP_KERNEL);
1671 mutex_unlock(&hash_mutex);
1674 spin_lock_init(&i->lock);
1675 i->irq = up->port.irq;
1676 hlist_add_head(&i->node, h);
1678 mutex_unlock(&hash_mutex);
1680 spin_lock_irq(&i->lock);
1683 list_add(&up->list, i->head);
1684 spin_unlock_irq(&i->lock);
1688 INIT_LIST_HEAD(&up->list);
1689 i->head = &up->list;
1690 spin_unlock_irq(&i->lock);
1691 irq_flags |= up->port.irqflags;
1692 ret = request_irq(up->port.irq, serial8250_interrupt,
1693 irq_flags, "serial", i);
1695 serial_do_unlink(i, up);
1701 static void serial_unlink_irq_chain(struct uart_8250_port *up)
1704 struct hlist_node *n;
1705 struct hlist_head *h;
1707 mutex_lock(&hash_mutex);
1709 h = &irq_lists[up->port.irq % NR_IRQ_HASH];
1711 hlist_for_each(n, h) {
1712 i = hlist_entry(n, struct irq_info, node);
1713 if (i->irq == up->port.irq)
1718 BUG_ON(i->head == NULL);
1720 if (list_empty(i->head))
1721 free_irq(up->port.irq, i);
1723 serial_do_unlink(i, up);
1724 mutex_unlock(&hash_mutex);
1728 * This function is used to handle ports that do not have an
1729 * interrupt. This doesn't work very well for 16450's, but gives
1730 * barely passable results for a 16550A. (Although at the expense
1731 * of much CPU overhead).
1733 static void serial8250_timeout(unsigned long data)
1735 struct uart_8250_port *up = (struct uart_8250_port *)data;
1737 up->port.handle_irq(&up->port);
1738 mod_timer(&up->timer, jiffies + uart_poll_timeout(&up->port));
1741 static void serial8250_backup_timeout(unsigned long data)
1743 struct uart_8250_port *up = (struct uart_8250_port *)data;
1744 unsigned int iir, ier = 0, lsr;
1745 unsigned long flags;
1747 spin_lock_irqsave(&up->port.lock, flags);
1750 * Must disable interrupts or else we risk racing with the interrupt
1753 if (is_real_interrupt(up->port.irq)) {
1754 ier = serial_in(up, UART_IER);
1755 serial_out(up, UART_IER, 0);
1758 iir = serial_in(up, UART_IIR);
1761 * This should be a safe test for anyone who doesn't trust the
1762 * IIR bits on their UART, but it's specifically designed for
1763 * the "Diva" UART used on the management processor on many HP
1764 * ia64 and parisc boxes.
1766 lsr = serial_in(up, UART_LSR);
1767 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1768 if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
1769 (!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) &&
1770 (lsr & UART_LSR_THRE)) {
1771 iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
1772 iir |= UART_IIR_THRI;
1775 if (!(iir & UART_IIR_NO_INT))
1776 serial8250_tx_chars(up);
1778 if (is_real_interrupt(up->port.irq))
1779 serial_out(up, UART_IER, ier);
1781 spin_unlock_irqrestore(&up->port.lock, flags);
1783 /* Standard timer interval plus 0.2s to keep the port running */
1784 mod_timer(&up->timer,
1785 jiffies + uart_poll_timeout(&up->port) + HZ / 5);
1788 static unsigned int serial8250_tx_empty(struct uart_port *port)
1790 struct uart_8250_port *up =
1791 container_of(port, struct uart_8250_port, port);
1792 unsigned long flags;
1795 spin_lock_irqsave(&up->port.lock, flags);
1796 lsr = serial_in(up, UART_LSR);
1797 up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
1798 spin_unlock_irqrestore(&up->port.lock, flags);
1800 return (lsr & BOTH_EMPTY) == BOTH_EMPTY ? TIOCSER_TEMT : 0;
1803 static unsigned int serial8250_get_mctrl(struct uart_port *port)
1805 struct uart_8250_port *up =
1806 container_of(port, struct uart_8250_port, port);
1807 unsigned int status;
1810 status = serial8250_modem_status(up);
1813 if (status & UART_MSR_DCD)
1815 if (status & UART_MSR_RI)
1817 if (status & UART_MSR_DSR)
1819 if (status & UART_MSR_CTS)
1824 static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
1826 struct uart_8250_port *up =
1827 container_of(port, struct uart_8250_port, port);
1828 unsigned char mcr = 0;
1830 if (mctrl & TIOCM_RTS)
1831 mcr |= UART_MCR_RTS;
1832 if (mctrl & TIOCM_DTR)
1833 mcr |= UART_MCR_DTR;
1834 if (mctrl & TIOCM_OUT1)
1835 mcr |= UART_MCR_OUT1;
1836 if (mctrl & TIOCM_OUT2)
1837 mcr |= UART_MCR_OUT2;
1838 if (mctrl & TIOCM_LOOP)
1839 mcr |= UART_MCR_LOOP;
1841 mcr = (mcr & up->mcr_mask) | up->mcr_force | up->mcr;
1843 serial_out(up, UART_MCR, mcr);
1846 static void serial8250_break_ctl(struct uart_port *port, int break_state)
1848 struct uart_8250_port *up =
1849 container_of(port, struct uart_8250_port, port);
1850 unsigned long flags;
1852 spin_lock_irqsave(&up->port.lock, flags);
1853 if (break_state == -1)
1854 up->lcr |= UART_LCR_SBC;
1856 up->lcr &= ~UART_LCR_SBC;
1857 serial_out(up, UART_LCR, up->lcr);
1858 spin_unlock_irqrestore(&up->port.lock, flags);
1862 * Wait for transmitter & holding register to empty
1864 static void wait_for_xmitr(struct uart_8250_port *up, int bits)
1866 unsigned int status, tmout = 10000;
1868 /* Wait up to 10ms for the character(s) to be sent. */
1870 status = serial_in(up, UART_LSR);
1872 up->lsr_saved_flags |= status & LSR_SAVE_FLAGS;
1874 if ((status & bits) == bits)
1881 /* Wait up to 1s for flow control if necessary */
1882 if (up->port.flags & UPF_CONS_FLOW) {
1884 for (tmout = 1000000; tmout; tmout--) {
1885 unsigned int msr = serial_in(up, UART_MSR);
1886 up->msr_saved_flags |= msr & MSR_SAVE_FLAGS;
1887 if (msr & UART_MSR_CTS)
1890 touch_nmi_watchdog();
1895 #ifdef CONFIG_CONSOLE_POLL
1897 * Console polling routines for writing and reading from the uart while
1898 * in an interrupt or debug context.
1901 static int serial8250_get_poll_char(struct uart_port *port)
1903 struct uart_8250_port *up =
1904 container_of(port, struct uart_8250_port, port);
1905 unsigned char lsr = serial_inp(up, UART_LSR);
1907 if (!(lsr & UART_LSR_DR))
1908 return NO_POLL_CHAR;
1910 return serial_inp(up, UART_RX);
1914 static void serial8250_put_poll_char(struct uart_port *port,
1918 struct uart_8250_port *up =
1919 container_of(port, struct uart_8250_port, port);
1922 * First save the IER then disable the interrupts
1924 ier = serial_in(up, UART_IER);
1925 if (up->capabilities & UART_CAP_UUE)
1926 serial_out(up, UART_IER, UART_IER_UUE);
1928 serial_out(up, UART_IER, 0);
1930 wait_for_xmitr(up, BOTH_EMPTY);
1932 * Send the character out.
1933 * If a LF, also do CR...
1935 serial_out(up, UART_TX, c);
1937 wait_for_xmitr(up, BOTH_EMPTY);
1938 serial_out(up, UART_TX, 13);
1942 * Finally, wait for transmitter to become empty
1943 * and restore the IER
1945 wait_for_xmitr(up, BOTH_EMPTY);
1946 serial_out(up, UART_IER, ier);
1949 #endif /* CONFIG_CONSOLE_POLL */
1951 static int serial8250_startup(struct uart_port *port)
1953 struct uart_8250_port *up =
1954 container_of(port, struct uart_8250_port, port);
1955 unsigned long flags;
1956 unsigned char lsr, iir;
1959 up->port.fifosize = uart_config[up->port.type].fifo_size;
1960 up->tx_loadsz = uart_config[up->port.type].tx_loadsz;
1961 up->capabilities = uart_config[up->port.type].flags;
1964 if (up->port.iotype != up->cur_iotype)
1965 set_io_from_upio(port);
1967 if (up->port.type == PORT_16C950) {
1968 /* Wake up and initialize UART */
1970 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
1971 serial_outp(up, UART_EFR, UART_EFR_ECB);
1972 serial_outp(up, UART_IER, 0);
1973 serial_outp(up, UART_LCR, 0);
1974 serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
1975 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
1976 serial_outp(up, UART_EFR, UART_EFR_ECB);
1977 serial_outp(up, UART_LCR, 0);
1980 #ifdef CONFIG_SERIAL_8250_RSA
1982 * If this is an RSA port, see if we can kick it up to the
1983 * higher speed clock.
1989 * Clear the FIFO buffers and disable them.
1990 * (they will be reenabled in set_termios())
1992 serial8250_clear_fifos(up);
1995 * Clear the interrupt registers.
1997 (void) serial_inp(up, UART_LSR);
1998 (void) serial_inp(up, UART_RX);
1999 (void) serial_inp(up, UART_IIR);
2000 (void) serial_inp(up, UART_MSR);
2003 * At this point, there's no way the LSR could still be 0xff;
2004 * if it is, then bail out, because there's likely no UART
2007 if (!(up->port.flags & UPF_BUGGY_UART) &&
2008 (serial_inp(up, UART_LSR) == 0xff)) {
2009 printk_ratelimited(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
2010 serial_index(&up->port));
2015 * For a XR16C850, we need to set the trigger levels
2017 if (up->port.type == PORT_16850) {
2020 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
2022 fctr = serial_inp(up, UART_FCTR) & ~(UART_FCTR_RX|UART_FCTR_TX);
2023 serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_RX);
2024 serial_outp(up, UART_TRG, UART_TRG_96);
2025 serial_outp(up, UART_FCTR, fctr | UART_FCTR_TRGD | UART_FCTR_TX);
2026 serial_outp(up, UART_TRG, UART_TRG_96);
2028 serial_outp(up, UART_LCR, 0);
2031 if (is_real_interrupt(up->port.irq)) {
2034 * Test for UARTs that do not reassert THRE when the
2035 * transmitter is idle and the interrupt has already
2036 * been cleared. Real 16550s should always reassert
2037 * this interrupt whenever the transmitter is idle and
2038 * the interrupt is enabled. Delays are necessary to
2039 * allow register changes to become visible.
2041 spin_lock_irqsave(&up->port.lock, flags);
2042 if (up->port.irqflags & IRQF_SHARED)
2043 disable_irq_nosync(up->port.irq);
2045 wait_for_xmitr(up, UART_LSR_THRE);
2046 serial_out_sync(up, UART_IER, UART_IER_THRI);
2047 udelay(1); /* allow THRE to set */
2048 iir1 = serial_in(up, UART_IIR);
2049 serial_out(up, UART_IER, 0);
2050 serial_out_sync(up, UART_IER, UART_IER_THRI);
2051 udelay(1); /* allow a working UART time to re-assert THRE */
2052 iir = serial_in(up, UART_IIR);
2053 serial_out(up, UART_IER, 0);
2055 if (up->port.irqflags & IRQF_SHARED)
2056 enable_irq(up->port.irq);
2057 spin_unlock_irqrestore(&up->port.lock, flags);
2060 * If the interrupt is not reasserted, setup a timer to
2061 * kick the UART on a regular basis.
2063 if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) {
2064 up->bugs |= UART_BUG_THRE;
2065 pr_debug("ttyS%d - using backup timer\n",
2066 serial_index(port));
2071 * The above check will only give an accurate result the first time
2072 * the port is opened so this value needs to be preserved.
2074 if (up->bugs & UART_BUG_THRE) {
2075 up->timer.function = serial8250_backup_timeout;
2076 up->timer.data = (unsigned long)up;
2077 mod_timer(&up->timer, jiffies +
2078 uart_poll_timeout(port) + HZ / 5);
2082 * If the "interrupt" for this port doesn't correspond with any
2083 * hardware interrupt, we use a timer-based system. The original
2084 * driver used to do this with IRQ0.
2086 if (!is_real_interrupt(up->port.irq)) {
2087 up->timer.data = (unsigned long)up;
2088 mod_timer(&up->timer, jiffies + uart_poll_timeout(port));
2090 retval = serial_link_irq_chain(up);
2096 * Now, initialize the UART
2098 serial_outp(up, UART_LCR, UART_LCR_WLEN8);
2100 spin_lock_irqsave(&up->port.lock, flags);
2101 if (up->port.flags & UPF_FOURPORT) {
2102 if (!is_real_interrupt(up->port.irq))
2103 up->port.mctrl |= TIOCM_OUT1;
2106 * Most PC uarts need OUT2 raised to enable interrupts.
2108 if (is_real_interrupt(up->port.irq))
2109 up->port.mctrl |= TIOCM_OUT2;
2111 serial8250_set_mctrl(&up->port, up->port.mctrl);
2113 /* Serial over Lan (SoL) hack:
2114 Intel 8257x Gigabit ethernet chips have a
2115 16550 emulation, to be used for Serial Over Lan.
2116 Those chips take a longer time than a normal
2117 serial device to signalize that a transmission
2118 data was queued. Due to that, the above test generally
2119 fails. One solution would be to delay the reading of
2120 iir. However, this is not reliable, since the timeout
2121 is variable. So, let's just don't test if we receive
2122 TX irq. This way, we'll never enable UART_BUG_TXEN.
2124 if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST)
2125 goto dont_test_tx_en;
2128 * Do a quick test to see if we receive an
2129 * interrupt when we enable the TX irq.
2131 serial_outp(up, UART_IER, UART_IER_THRI);
2132 lsr = serial_in(up, UART_LSR);
2133 iir = serial_in(up, UART_IIR);
2134 serial_outp(up, UART_IER, 0);
2136 if (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT) {
2137 if (!(up->bugs & UART_BUG_TXEN)) {
2138 up->bugs |= UART_BUG_TXEN;
2139 pr_debug("ttyS%d - enabling bad tx status workarounds\n",
2140 serial_index(port));
2143 up->bugs &= ~UART_BUG_TXEN;
2147 spin_unlock_irqrestore(&up->port.lock, flags);
2150 * Clear the interrupt registers again for luck, and clear the
2151 * saved flags to avoid getting false values from polling
2152 * routines or the previous session.
2154 serial_inp(up, UART_LSR);
2155 serial_inp(up, UART_RX);
2156 serial_inp(up, UART_IIR);
2157 serial_inp(up, UART_MSR);
2158 up->lsr_saved_flags = 0;
2159 up->msr_saved_flags = 0;
2162 * Finally, enable interrupts. Note: Modem status interrupts
2163 * are set via set_termios(), which will be occurring imminently
2164 * anyway, so we don't enable them here.
2166 up->ier = UART_IER_RLSI | UART_IER_RDI;
2167 serial_outp(up, UART_IER, up->ier);
2169 if (up->port.flags & UPF_FOURPORT) {
2172 * Enable interrupts on the AST Fourport board
2174 icp = (up->port.iobase & 0xfe0) | 0x01f;
2182 static void serial8250_shutdown(struct uart_port *port)
2184 struct uart_8250_port *up =
2185 container_of(port, struct uart_8250_port, port);
2186 unsigned long flags;
2189 * Disable interrupts from this port
2192 serial_outp(up, UART_IER, 0);
2194 spin_lock_irqsave(&up->port.lock, flags);
2195 if (up->port.flags & UPF_FOURPORT) {
2196 /* reset interrupts on the AST Fourport board */
2197 inb((up->port.iobase & 0xfe0) | 0x1f);
2198 up->port.mctrl |= TIOCM_OUT1;
2200 up->port.mctrl &= ~TIOCM_OUT2;
2202 serial8250_set_mctrl(&up->port, up->port.mctrl);
2203 spin_unlock_irqrestore(&up->port.lock, flags);
2206 * Disable break condition and FIFOs
2208 serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
2209 serial8250_clear_fifos(up);
2211 #ifdef CONFIG_SERIAL_8250_RSA
2213 * Reset the RSA board back to 115kbps compat mode.
2219 * Read data port to reset things, and then unlink from
2222 (void) serial_in(up, UART_RX);
2224 del_timer_sync(&up->timer);
2225 up->timer.function = serial8250_timeout;
2226 if (is_real_interrupt(up->port.irq))
2227 serial_unlink_irq_chain(up);
2230 static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int baud)
2235 * Handle magic divisors for baud rates above baud_base on
2236 * SMSC SuperIO chips.
2238 if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
2239 baud == (port->uartclk/4))
2241 else if ((port->flags & UPF_MAGIC_MULTIPLIER) &&
2242 baud == (port->uartclk/8))
2245 quot = uart_get_divisor(port, baud);
2251 serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
2252 struct ktermios *old)
2254 struct uart_8250_port *up =
2255 container_of(port, struct uart_8250_port, port);
2256 unsigned char cval, fcr = 0;
2257 unsigned long flags;
2258 unsigned int baud, quot;
2260 switch (termios->c_cflag & CSIZE) {
2262 cval = UART_LCR_WLEN5;
2265 cval = UART_LCR_WLEN6;
2268 cval = UART_LCR_WLEN7;
2272 cval = UART_LCR_WLEN8;
2276 if (termios->c_cflag & CSTOPB)
2277 cval |= UART_LCR_STOP;
2278 if (termios->c_cflag & PARENB)
2279 cval |= UART_LCR_PARITY;
2280 if (!(termios->c_cflag & PARODD))
2281 cval |= UART_LCR_EPAR;
2283 if (termios->c_cflag & CMSPAR)
2284 cval |= UART_LCR_SPAR;
2288 * Ask the core to calculate the divisor for us.
2290 baud = uart_get_baud_rate(port, termios, old,
2291 port->uartclk / 16 / 0xffff,
2292 port->uartclk / 16);
2293 quot = serial8250_get_divisor(port, baud);
2296 * Oxford Semi 952 rev B workaround
2298 if (up->bugs & UART_BUG_QUOT && (quot & 0xff) == 0)
2301 if (up->capabilities & UART_CAP_FIFO && up->port.fifosize > 1) {
2303 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
2305 fcr = uart_config[up->port.type].fcr;
2309 * MCR-based auto flow control. When AFE is enabled, RTS will be
2310 * deasserted when the receive FIFO contains more characters than
2311 * the trigger, or the MCR RTS bit is cleared. In the case where
2312 * the remote UART is not using CTS auto flow control, we must
2313 * have sufficient FIFO entries for the latency of the remote
2314 * UART to respond. IOW, at least 32 bytes of FIFO.
2316 if (up->capabilities & UART_CAP_AFE && up->port.fifosize >= 32) {
2317 up->mcr &= ~UART_MCR_AFE;
2318 if (termios->c_cflag & CRTSCTS)
2319 up->mcr |= UART_MCR_AFE;
2323 * Ok, we're now changing the port state. Do it with
2324 * interrupts disabled.
2326 spin_lock_irqsave(&up->port.lock, flags);
2329 * Update the per-port timeout.
2331 uart_update_timeout(port, termios->c_cflag, baud);
2333 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
2334 if (termios->c_iflag & INPCK)
2335 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
2336 if (termios->c_iflag & (BRKINT | PARMRK))
2337 up->port.read_status_mask |= UART_LSR_BI;
2340 * Characteres to ignore
2342 up->port.ignore_status_mask = 0;
2343 if (termios->c_iflag & IGNPAR)
2344 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
2345 if (termios->c_iflag & IGNBRK) {
2346 up->port.ignore_status_mask |= UART_LSR_BI;
2348 * If we're ignoring parity and break indicators,
2349 * ignore overruns too (for real raw support).
2351 if (termios->c_iflag & IGNPAR)
2352 up->port.ignore_status_mask |= UART_LSR_OE;
2356 * ignore all characters if CREAD is not set
2358 if ((termios->c_cflag & CREAD) == 0)
2359 up->port.ignore_status_mask |= UART_LSR_DR;
2362 * CTS flow control flag and modem status interrupts
2364 up->ier &= ~UART_IER_MSI;
2365 if (!(up->bugs & UART_BUG_NOMSR) &&
2366 UART_ENABLE_MS(&up->port, termios->c_cflag))
2367 up->ier |= UART_IER_MSI;
2368 if (up->capabilities & UART_CAP_UUE)
2369 up->ier |= UART_IER_UUE;
2370 if (up->capabilities & UART_CAP_RTOIE)
2371 up->ier |= UART_IER_RTOIE;
2373 serial_out(up, UART_IER, up->ier);
2375 if (up->capabilities & UART_CAP_EFR) {
2376 unsigned char efr = 0;
2378 * TI16C752/Startech hardware flow control. FIXME:
2379 * - TI16C752 requires control thresholds to be set.
2380 * - UART_MCR_RTS is ineffective if auto-RTS mode is enabled.
2382 if (termios->c_cflag & CRTSCTS)
2383 efr |= UART_EFR_CTS;
2385 serial_outp(up, UART_LCR, UART_LCR_CONF_MODE_B);
2386 if (up->port.flags & UPF_EXAR_EFR)
2387 serial_outp(up, UART_XR_EFR, efr);
2389 serial_outp(up, UART_EFR, efr);
2392 #ifdef CONFIG_ARCH_OMAP
2393 /* Workaround to enable 115200 baud on OMAP1510 internal ports */
2394 if (cpu_is_omap1510() && is_omap_port(up)) {
2395 if (baud == 115200) {
2397 serial_out(up, UART_OMAP_OSC_12M_SEL, 1);
2399 serial_out(up, UART_OMAP_OSC_12M_SEL, 0);
2403 if (up->capabilities & UART_NATSEMI) {
2404 /* Switch to bank 2 not bank 1, to avoid resetting EXCR2 */
2405 serial_outp(up, UART_LCR, 0xe0);
2407 serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
2410 serial_dl_write(up, quot);
2413 * LCR DLAB must be set to enable 64-byte FIFO mode. If the FCR
2414 * is written without DLAB set, this mode will be disabled.
2416 if (up->port.type == PORT_16750)
2417 serial_outp(up, UART_FCR, fcr);
2419 serial_outp(up, UART_LCR, cval); /* reset DLAB */
2420 up->lcr = cval; /* Save LCR */
2421 if (up->port.type != PORT_16750) {
2422 if (fcr & UART_FCR_ENABLE_FIFO) {
2423 /* emulated UARTs (Lucent Venus 167x) need two steps */
2424 serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
2426 serial_outp(up, UART_FCR, fcr); /* set fcr */
2428 serial8250_set_mctrl(&up->port, up->port.mctrl);
2429 spin_unlock_irqrestore(&up->port.lock, flags);
2430 /* Don't rewrite B0 */
2431 if (tty_termios_baud_rate(termios))
2432 tty_termios_encode_baud_rate(termios, baud, baud);
2434 EXPORT_SYMBOL(serial8250_do_set_termios);
2437 serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2438 struct ktermios *old)
2440 if (port->set_termios)
2441 port->set_termios(port, termios, old);
2443 serial8250_do_set_termios(port, termios, old);
2447 serial8250_set_ldisc(struct uart_port *port, int new)
2450 port->flags |= UPF_HARDPPS_CD;
2451 serial8250_enable_ms(port);
2453 port->flags &= ~UPF_HARDPPS_CD;
2457 void serial8250_do_pm(struct uart_port *port, unsigned int state,
2458 unsigned int oldstate)
2460 struct uart_8250_port *p =
2461 container_of(port, struct uart_8250_port, port);
2463 serial8250_set_sleep(p, state != 0);
2465 EXPORT_SYMBOL(serial8250_do_pm);
2468 serial8250_pm(struct uart_port *port, unsigned int state,
2469 unsigned int oldstate)
2472 port->pm(port, state, oldstate);
2474 serial8250_do_pm(port, state, oldstate);
2477 static unsigned int serial8250_port_size(struct uart_8250_port *pt)
2479 if (pt->port.iotype == UPIO_AU)
2481 #ifdef CONFIG_ARCH_OMAP
2482 if (is_omap_port(pt))
2483 return 0x16 << pt->port.regshift;
2485 return 8 << pt->port.regshift;
2489 * Resource handling.
2491 static int serial8250_request_std_resource(struct uart_8250_port *up)
2493 unsigned int size = serial8250_port_size(up);
2496 switch (up->port.iotype) {
2501 if (!up->port.mapbase)
2504 if (!request_mem_region(up->port.mapbase, size, "serial")) {
2509 if (up->port.flags & UPF_IOREMAP) {
2510 up->port.membase = ioremap_nocache(up->port.mapbase,
2512 if (!up->port.membase) {
2513 release_mem_region(up->port.mapbase, size);
2521 if (!request_region(up->port.iobase, size, "serial"))
2528 static void serial8250_release_std_resource(struct uart_8250_port *up)
2530 unsigned int size = serial8250_port_size(up);
2532 switch (up->port.iotype) {
2537 if (!up->port.mapbase)
2540 if (up->port.flags & UPF_IOREMAP) {
2541 iounmap(up->port.membase);
2542 up->port.membase = NULL;
2545 release_mem_region(up->port.mapbase, size);
2550 release_region(up->port.iobase, size);
2555 static int serial8250_request_rsa_resource(struct uart_8250_port *up)
2557 unsigned long start = UART_RSA_BASE << up->port.regshift;
2558 unsigned int size = 8 << up->port.regshift;
2561 switch (up->port.iotype) {
2564 start += up->port.iobase;
2565 if (request_region(start, size, "serial-rsa"))
2575 static void serial8250_release_rsa_resource(struct uart_8250_port *up)
2577 unsigned long offset = UART_RSA_BASE << up->port.regshift;
2578 unsigned int size = 8 << up->port.regshift;
2580 switch (up->port.iotype) {
2583 release_region(up->port.iobase + offset, size);
2588 static void serial8250_release_port(struct uart_port *port)
2590 struct uart_8250_port *up =
2591 container_of(port, struct uart_8250_port, port);
2593 serial8250_release_std_resource(up);
2594 if (up->port.type == PORT_RSA)
2595 serial8250_release_rsa_resource(up);
2598 static int serial8250_request_port(struct uart_port *port)
2600 struct uart_8250_port *up =
2601 container_of(port, struct uart_8250_port, port);
2604 ret = serial8250_request_std_resource(up);
2605 if (ret == 0 && up->port.type == PORT_RSA) {
2606 ret = serial8250_request_rsa_resource(up);
2608 serial8250_release_std_resource(up);
2614 static void serial8250_config_port(struct uart_port *port, int flags)
2616 struct uart_8250_port *up =
2617 container_of(port, struct uart_8250_port, port);
2618 int probeflags = PROBE_ANY;
2622 * Find the region that we can probe for. This in turn
2623 * tells us whether we can probe for the type of port.
2625 ret = serial8250_request_std_resource(up);
2629 ret = serial8250_request_rsa_resource(up);
2631 probeflags &= ~PROBE_RSA;
2633 if (up->port.iotype != up->cur_iotype)
2634 set_io_from_upio(port);
2636 if (flags & UART_CONFIG_TYPE)
2637 autoconfig(up, probeflags);
2639 /* if access method is AU, it is a 16550 with a quirk */
2640 if (up->port.type == PORT_16550A && up->port.iotype == UPIO_AU)
2641 up->bugs |= UART_BUG_NOMSR;
2643 if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
2646 if (up->port.type != PORT_RSA && probeflags & PROBE_RSA)
2647 serial8250_release_rsa_resource(up);
2648 if (up->port.type == PORT_UNKNOWN)
2649 serial8250_release_std_resource(up);
2653 serial8250_verify_port(struct uart_port *port, struct serial_struct *ser)
2655 if (ser->irq >= nr_irqs || ser->irq < 0 ||
2656 ser->baud_base < 9600 || ser->type < PORT_UNKNOWN ||
2657 ser->type >= ARRAY_SIZE(uart_config) || ser->type == PORT_CIRRUS ||
2658 ser->type == PORT_STARTECH)
2664 serial8250_type(struct uart_port *port)
2666 int type = port->type;
2668 if (type >= ARRAY_SIZE(uart_config))
2670 return uart_config[type].name;
2673 static struct uart_ops serial8250_pops = {
2674 .tx_empty = serial8250_tx_empty,
2675 .set_mctrl = serial8250_set_mctrl,
2676 .get_mctrl = serial8250_get_mctrl,
2677 .stop_tx = serial8250_stop_tx,
2678 .start_tx = serial8250_start_tx,
2679 .stop_rx = serial8250_stop_rx,
2680 .enable_ms = serial8250_enable_ms,
2681 .break_ctl = serial8250_break_ctl,
2682 .startup = serial8250_startup,
2683 .shutdown = serial8250_shutdown,
2684 .set_termios = serial8250_set_termios,
2685 .set_ldisc = serial8250_set_ldisc,
2686 .pm = serial8250_pm,
2687 .type = serial8250_type,
2688 .release_port = serial8250_release_port,
2689 .request_port = serial8250_request_port,
2690 .config_port = serial8250_config_port,
2691 .verify_port = serial8250_verify_port,
2692 #ifdef CONFIG_CONSOLE_POLL
2693 .poll_get_char = serial8250_get_poll_char,
2694 .poll_put_char = serial8250_put_poll_char,
2698 static struct uart_8250_port serial8250_ports[UART_NR];
2700 static void (*serial8250_isa_config)(int port, struct uart_port *up,
2701 unsigned short *capabilities);
2703 void serial8250_set_isa_configurator(
2704 void (*v)(int port, struct uart_port *up, unsigned short *capabilities))
2706 serial8250_isa_config = v;
2708 EXPORT_SYMBOL(serial8250_set_isa_configurator);
2710 static void __init serial8250_isa_init_ports(void)
2712 struct uart_8250_port *up;
2713 static int first = 1;
2720 for (i = 0; i < nr_uarts; i++) {
2721 struct uart_8250_port *up = &serial8250_ports[i];
2724 spin_lock_init(&up->port.lock);
2726 init_timer(&up->timer);
2727 up->timer.function = serial8250_timeout;
2730 * ALPHA_KLUDGE_MCR needs to be killed.
2732 up->mcr_mask = ~ALPHA_KLUDGE_MCR;
2733 up->mcr_force = ALPHA_KLUDGE_MCR;
2735 up->port.ops = &serial8250_pops;
2739 irqflag = IRQF_SHARED;
2741 for (i = 0, up = serial8250_ports;
2742 i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
2744 up->port.iobase = old_serial_port[i].port;
2745 up->port.irq = irq_canonicalize(old_serial_port[i].irq);
2746 up->port.irqflags = old_serial_port[i].irqflags;
2747 up->port.uartclk = old_serial_port[i].baud_base * 16;
2748 up->port.flags = old_serial_port[i].flags;
2749 up->port.hub6 = old_serial_port[i].hub6;
2750 up->port.membase = old_serial_port[i].iomem_base;
2751 up->port.iotype = old_serial_port[i].io_type;
2752 up->port.regshift = old_serial_port[i].iomem_reg_shift;
2753 set_io_from_upio(&up->port);
2754 up->port.irqflags |= irqflag;
2755 if (serial8250_isa_config != NULL)
2756 serial8250_isa_config(i, &up->port, &up->capabilities);
2762 serial8250_init_fixed_type_port(struct uart_8250_port *up, unsigned int type)
2764 up->port.type = type;
2765 up->port.fifosize = uart_config[type].fifo_size;
2766 up->capabilities = uart_config[type].flags;
2767 up->tx_loadsz = uart_config[type].tx_loadsz;
2771 serial8250_register_ports(struct uart_driver *drv, struct device *dev)
2775 for (i = 0; i < nr_uarts; i++) {
2776 struct uart_8250_port *up = &serial8250_ports[i];
2777 up->cur_iotype = 0xFF;
2780 serial8250_isa_init_ports();
2782 for (i = 0; i < nr_uarts; i++) {
2783 struct uart_8250_port *up = &serial8250_ports[i];
2787 if (up->port.flags & UPF_FIXED_TYPE)
2788 serial8250_init_fixed_type_port(up, up->port.type);
2790 uart_add_one_port(drv, &up->port);
2794 #ifdef CONFIG_SERIAL_8250_CONSOLE
2796 static void serial8250_console_putchar(struct uart_port *port, int ch)
2798 struct uart_8250_port *up =
2799 container_of(port, struct uart_8250_port, port);
2801 wait_for_xmitr(up, UART_LSR_THRE);
2802 serial_out(up, UART_TX, ch);
2806 * Print a string to the serial port trying not to disturb
2807 * any possible real use of the port...
2809 * The console_lock must be held when we get here.
2812 serial8250_console_write(struct console *co, const char *s, unsigned int count)
2814 struct uart_8250_port *up = &serial8250_ports[co->index];
2815 unsigned long flags;
2819 touch_nmi_watchdog();
2821 local_irq_save(flags);
2822 if (up->port.sysrq) {
2823 /* serial8250_handle_irq() already took the lock */
2825 } else if (oops_in_progress) {
2826 locked = spin_trylock(&up->port.lock);
2828 spin_lock(&up->port.lock);
2831 * First save the IER then disable the interrupts
2833 ier = serial_in(up, UART_IER);
2835 if (up->capabilities & UART_CAP_UUE)
2836 serial_out(up, UART_IER, UART_IER_UUE);
2838 serial_out(up, UART_IER, 0);
2840 uart_console_write(&up->port, s, count, serial8250_console_putchar);
2843 * Finally, wait for transmitter to become empty
2844 * and restore the IER
2846 wait_for_xmitr(up, BOTH_EMPTY);
2847 serial_out(up, UART_IER, ier);
2850 * The receive handling will happen properly because the
2851 * receive ready bit will still be set; it is not cleared
2852 * on read. However, modem control will not, we must
2853 * call it if we have saved something in the saved flags
2854 * while processing with interrupts off.
2856 if (up->msr_saved_flags)
2857 serial8250_modem_status(up);
2860 spin_unlock(&up->port.lock);
2861 local_irq_restore(flags);
2864 static int __init serial8250_console_setup(struct console *co, char *options)
2866 struct uart_port *port;
2873 * Check whether an invalid uart number has been specified, and
2874 * if so, search for the first available port that does have
2877 if (co->index >= nr_uarts)
2879 port = &serial8250_ports[co->index].port;
2880 if (!port->iobase && !port->membase)
2884 uart_parse_options(options, &baud, &parity, &bits, &flow);
2886 return uart_set_options(port, co, baud, parity, bits, flow);
2889 static int serial8250_console_early_setup(void)
2891 return serial8250_find_port_for_earlycon();
2894 static struct console serial8250_console = {
2896 .write = serial8250_console_write,
2897 .device = uart_console_device,
2898 .setup = serial8250_console_setup,
2899 .early_setup = serial8250_console_early_setup,
2900 .flags = CON_PRINTBUFFER | CON_ANYTIME,
2902 .data = &serial8250_reg,
2905 static int __init serial8250_console_init(void)
2907 if (nr_uarts > UART_NR)
2910 serial8250_isa_init_ports();
2911 register_console(&serial8250_console);
2914 console_initcall(serial8250_console_init);
2916 int serial8250_find_port(struct uart_port *p)
2919 struct uart_port *port;
2921 for (line = 0; line < nr_uarts; line++) {
2922 port = &serial8250_ports[line].port;
2923 if (uart_match_port(p, port))
2929 #define SERIAL8250_CONSOLE &serial8250_console
2931 #define SERIAL8250_CONSOLE NULL
2934 static struct uart_driver serial8250_reg = {
2935 .owner = THIS_MODULE,
2936 .driver_name = "serial",
2940 .cons = SERIAL8250_CONSOLE,
2944 * early_serial_setup - early registration for 8250 ports
2946 * Setup an 8250 port structure prior to console initialisation. Use
2947 * after console initialisation will cause undefined behaviour.
2949 int __init early_serial_setup(struct uart_port *port)
2951 struct uart_port *p;
2953 if (port->line >= ARRAY_SIZE(serial8250_ports))
2956 serial8250_isa_init_ports();
2957 p = &serial8250_ports[port->line].port;
2958 p->iobase = port->iobase;
2959 p->membase = port->membase;
2961 p->irqflags = port->irqflags;
2962 p->uartclk = port->uartclk;
2963 p->fifosize = port->fifosize;
2964 p->regshift = port->regshift;
2965 p->iotype = port->iotype;
2966 p->flags = port->flags;
2967 p->mapbase = port->mapbase;
2968 p->private_data = port->private_data;
2969 p->type = port->type;
2970 p->line = port->line;
2972 set_io_from_upio(p);
2973 if (port->serial_in)
2974 p->serial_in = port->serial_in;
2975 if (port->serial_out)
2976 p->serial_out = port->serial_out;
2977 if (port->handle_irq)
2978 p->handle_irq = port->handle_irq;
2980 p->handle_irq = serial8250_default_handle_irq;
2986 * serial8250_suspend_port - suspend one serial port
2987 * @line: serial line number
2989 * Suspend one serial port.
2991 void serial8250_suspend_port(int line)
2993 uart_suspend_port(&serial8250_reg, &serial8250_ports[line].port);
2997 * serial8250_resume_port - resume one serial port
2998 * @line: serial line number
3000 * Resume one serial port.
3002 void serial8250_resume_port(int line)
3004 struct uart_8250_port *up = &serial8250_ports[line];
3006 if (up->capabilities & UART_NATSEMI) {
3007 /* Ensure it's still in high speed mode */
3008 serial_outp(up, UART_LCR, 0xE0);
3010 ns16550a_goto_highspeed(up);
3012 serial_outp(up, UART_LCR, 0);
3013 up->port.uartclk = 921600*16;
3015 uart_resume_port(&serial8250_reg, &up->port);
3019 * Register a set of serial devices attached to a platform device. The
3020 * list is terminated with a zero flags entry, which means we expect
3021 * all entries to have at least UPF_BOOT_AUTOCONF set.
3023 static int __devinit serial8250_probe(struct platform_device *dev)
3025 struct plat_serial8250_port *p = dev->dev.platform_data;
3026 struct uart_port port;
3027 int ret, i, irqflag = 0;
3029 memset(&port, 0, sizeof(struct uart_port));
3032 irqflag = IRQF_SHARED;
3034 for (i = 0; p && p->flags != 0; p++, i++) {
3035 port.iobase = p->iobase;
3036 port.membase = p->membase;
3038 port.irqflags = p->irqflags;
3039 port.uartclk = p->uartclk;
3040 port.regshift = p->regshift;
3041 port.iotype = p->iotype;
3042 port.flags = p->flags;
3043 port.mapbase = p->mapbase;
3044 port.hub6 = p->hub6;
3045 port.private_data = p->private_data;
3046 port.type = p->type;
3047 port.serial_in = p->serial_in;
3048 port.serial_out = p->serial_out;
3049 port.handle_irq = p->handle_irq;
3050 port.set_termios = p->set_termios;
3052 port.dev = &dev->dev;
3053 port.irqflags |= irqflag;
3054 ret = serial8250_register_port(&port);
3056 dev_err(&dev->dev, "unable to register port at index %d "
3057 "(IO%lx MEM%llx IRQ%d): %d\n", i,
3058 p->iobase, (unsigned long long)p->mapbase,
3066 * Remove serial ports registered against a platform device.
3068 static int __devexit serial8250_remove(struct platform_device *dev)
3072 for (i = 0; i < nr_uarts; i++) {
3073 struct uart_8250_port *up = &serial8250_ports[i];
3075 if (up->port.dev == &dev->dev)
3076 serial8250_unregister_port(i);
3081 static int serial8250_suspend(struct platform_device *dev, pm_message_t state)
3085 for (i = 0; i < UART_NR; i++) {
3086 struct uart_8250_port *up = &serial8250_ports[i];
3088 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
3089 uart_suspend_port(&serial8250_reg, &up->port);
3095 static int serial8250_resume(struct platform_device *dev)
3099 for (i = 0; i < UART_NR; i++) {
3100 struct uart_8250_port *up = &serial8250_ports[i];
3102 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
3103 serial8250_resume_port(i);
3109 static struct platform_driver serial8250_isa_driver = {
3110 .probe = serial8250_probe,
3111 .remove = __devexit_p(serial8250_remove),
3112 .suspend = serial8250_suspend,
3113 .resume = serial8250_resume,
3115 .name = "serial8250",
3116 .owner = THIS_MODULE,
3121 * This "device" covers _all_ ISA 8250-compatible serial devices listed
3122 * in the table in include/asm/serial.h
3124 static struct platform_device *serial8250_isa_devs;
3127 * serial8250_register_port and serial8250_unregister_port allows for
3128 * 16x50 serial ports to be configured at run-time, to support PCMCIA
3129 * modems and PCI multiport cards.
3131 static DEFINE_MUTEX(serial_mutex);
3133 static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *port)
3138 * First, find a port entry which matches.
3140 for (i = 0; i < nr_uarts; i++)
3141 if (uart_match_port(&serial8250_ports[i].port, port))
3142 return &serial8250_ports[i];
3145 * We didn't find a matching entry, so look for the first
3146 * free entry. We look for one which hasn't been previously
3147 * used (indicated by zero iobase).
3149 for (i = 0; i < nr_uarts; i++)
3150 if (serial8250_ports[i].port.type == PORT_UNKNOWN &&
3151 serial8250_ports[i].port.iobase == 0)
3152 return &serial8250_ports[i];
3155 * That also failed. Last resort is to find any entry which
3156 * doesn't have a real port associated with it.
3158 for (i = 0; i < nr_uarts; i++)
3159 if (serial8250_ports[i].port.type == PORT_UNKNOWN)
3160 return &serial8250_ports[i];
3166 * serial8250_register_port - register a serial port
3167 * @port: serial port template
3169 * Configure the serial port specified by the request. If the
3170 * port exists and is in use, it is hung up and unregistered
3173 * The port is then probed and if necessary the IRQ is autodetected
3174 * If this fails an error is returned.
3176 * On success the port is ready to use and the line number is returned.
3178 int serial8250_register_port(struct uart_port *port)
3180 struct uart_8250_port *uart;
3183 if (port->uartclk == 0)
3186 mutex_lock(&serial_mutex);
3188 uart = serial8250_find_match_or_unused(port);
3190 uart_remove_one_port(&serial8250_reg, &uart->port);
3192 uart->port.iobase = port->iobase;
3193 uart->port.membase = port->membase;
3194 uart->port.irq = port->irq;
3195 uart->port.irqflags = port->irqflags;
3196 uart->port.uartclk = port->uartclk;
3197 uart->port.fifosize = port->fifosize;
3198 uart->port.regshift = port->regshift;
3199 uart->port.iotype = port->iotype;
3200 uart->port.flags = port->flags | UPF_BOOT_AUTOCONF;
3201 uart->port.mapbase = port->mapbase;
3202 uart->port.private_data = port->private_data;
3204 uart->port.dev = port->dev;
3206 if (port->flags & UPF_FIXED_TYPE)
3207 serial8250_init_fixed_type_port(uart, port->type);
3209 set_io_from_upio(&uart->port);
3210 /* Possibly override default I/O functions. */
3211 if (port->serial_in)
3212 uart->port.serial_in = port->serial_in;
3213 if (port->serial_out)
3214 uart->port.serial_out = port->serial_out;
3215 if (port->handle_irq)
3216 uart->port.handle_irq = port->handle_irq;
3217 /* Possibly override set_termios call */
3218 if (port->set_termios)
3219 uart->port.set_termios = port->set_termios;
3221 uart->port.pm = port->pm;
3223 if (serial8250_isa_config != NULL)
3224 serial8250_isa_config(0, &uart->port,
3225 &uart->capabilities);
3227 ret = uart_add_one_port(&serial8250_reg, &uart->port);
3229 ret = uart->port.line;
3231 mutex_unlock(&serial_mutex);
3235 EXPORT_SYMBOL(serial8250_register_port);
3238 * serial8250_unregister_port - remove a 16x50 serial port at runtime
3239 * @line: serial line number
3241 * Remove one serial port. This may not be called from interrupt
3242 * context. We hand the port back to the our control.
3244 void serial8250_unregister_port(int line)
3246 struct uart_8250_port *uart = &serial8250_ports[line];
3248 mutex_lock(&serial_mutex);
3249 uart_remove_one_port(&serial8250_reg, &uart->port);
3250 if (serial8250_isa_devs) {
3251 uart->port.flags &= ~UPF_BOOT_AUTOCONF;
3252 uart->port.type = PORT_UNKNOWN;
3253 uart->port.dev = &serial8250_isa_devs->dev;
3254 uart->capabilities = uart_config[uart->port.type].flags;
3255 uart_add_one_port(&serial8250_reg, &uart->port);
3257 uart->port.dev = NULL;
3259 mutex_unlock(&serial_mutex);
3261 EXPORT_SYMBOL(serial8250_unregister_port);
3263 static int __init serial8250_init(void)
3267 if (nr_uarts > UART_NR)
3270 printk(KERN_INFO "Serial: 8250/16550 driver, "
3271 "%d ports, IRQ sharing %sabled\n", nr_uarts,
3272 share_irqs ? "en" : "dis");
3275 ret = sunserial_register_minors(&serial8250_reg, UART_NR);
3277 serial8250_reg.nr = UART_NR;
3278 ret = uart_register_driver(&serial8250_reg);
3283 serial8250_isa_devs = platform_device_alloc("serial8250",
3284 PLAT8250_DEV_LEGACY);
3285 if (!serial8250_isa_devs) {
3287 goto unreg_uart_drv;
3290 ret = platform_device_add(serial8250_isa_devs);
3294 serial8250_register_ports(&serial8250_reg, &serial8250_isa_devs->dev);
3296 ret = platform_driver_register(&serial8250_isa_driver);
3300 platform_device_del(serial8250_isa_devs);
3302 platform_device_put(serial8250_isa_devs);
3305 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3307 uart_unregister_driver(&serial8250_reg);
3313 static void __exit serial8250_exit(void)
3315 struct platform_device *isa_dev = serial8250_isa_devs;
3318 * This tells serial8250_unregister_port() not to re-register
3319 * the ports (thereby making serial8250_isa_driver permanently
3322 serial8250_isa_devs = NULL;
3324 platform_driver_unregister(&serial8250_isa_driver);
3325 platform_device_unregister(isa_dev);
3328 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3330 uart_unregister_driver(&serial8250_reg);
3334 module_init(serial8250_init);
3335 module_exit(serial8250_exit);
3337 EXPORT_SYMBOL(serial8250_suspend_port);
3338 EXPORT_SYMBOL(serial8250_resume_port);
3340 MODULE_LICENSE("GPL");
3341 MODULE_DESCRIPTION("Generic 8250/16x50 serial driver");
3343 module_param(share_irqs, uint, 0644);
3344 MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
3347 module_param(nr_uarts, uint, 0644);
3348 MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
3350 module_param(skip_txen_test, uint, 0644);
3351 MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
3353 #ifdef CONFIG_SERIAL_8250_RSA
3354 module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
3355 MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");
3357 MODULE_ALIAS_CHARDEV_MAJOR(TTY_MAJOR);