Serial: Do not read IIR in serial8250_start_tx when UART_BUG_TXEN
[safe/jmp/linux-2.6] / drivers / serial / 8250.c
index 849af9d..c3e37c8 100644 (file)
@@ -64,6 +64,8 @@ static int serial_index(struct uart_port *port)
        return (serial8250_reg.minor - 64) + port->line;
 }
 
+static unsigned int skip_txen_test; /* force skip of txen test at init time */
+
 /*
  * Debugging.
  */
@@ -137,6 +139,7 @@ struct uart_8250_port {
        unsigned char           mcr;
        unsigned char           mcr_mask;       /* mask of user bits */
        unsigned char           mcr_force;      /* mask of forced bits */
+       unsigned char           cur_iotype;     /* Running I/O type */
 
        /*
         * Some bits in registers are cleared on a read, so they must
@@ -279,6 +282,20 @@ static const struct serial8250_config uart_config[] = {
                .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
                .flags          = UART_CAP_FIFO,
        },
+       [PORT_OCTEON] = {
+               .name           = "OCTEON",
+               .fifo_size      = 64,
+               .tx_loadsz      = 64,
+               .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
+               .flags          = UART_CAP_FIFO,
+       },
+       [PORT_AR7] = {
+               .name           = "AR7",
+               .fifo_size      = 16,
+               .tx_loadsz      = 16,
+               .fcr            = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
+               .flags          = UART_CAP_FIFO | UART_CAP_AFE,
+       },
 };
 
 #if defined (CONFIG_SERIAL_8250_AU1X00)
@@ -464,6 +481,7 @@ static void io_serial_out(struct uart_port *p, int offset, int value)
 
 static void set_io_from_upio(struct uart_port *p)
 {
+       struct uart_8250_port *up = (struct uart_8250_port *)p;
        switch (p->iotype) {
        case UPIO_HUB6:
                p->serial_in = hub6_serial_in;
@@ -502,6 +520,8 @@ static void set_io_from_upio(struct uart_port *p)
                p->serial_out = io_serial_out;
                break;
        }
+       /* Remember loaded iotype */
+       up->cur_iotype = p->iotype;
 }
 
 static void
@@ -1069,7 +1089,7 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
        if (!up->port.iobase && !up->port.mapbase && !up->port.membase)
                return;
 
-       DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
+       DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04lx, 0x%p): ",
                       serial_index(&up->port), up->port.iobase, up->port.membase);
 
        /*
@@ -1319,14 +1339,12 @@ static void serial8250_start_tx(struct uart_port *port)
                serial_out(up, UART_IER, up->ier);
 
                if (up->bugs & UART_BUG_TXEN) {
-                       unsigned char lsr, iir;
+                       unsigned char lsr;
                        lsr = serial_in(up, UART_LSR);
                        up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
-                       iir = serial_in(up, UART_IIR) & 0x0f;
                        if ((up->port.type == PORT_RM9000) ?
-                               (lsr & UART_LSR_THRE &&
-                               (iir == UART_IIR_NO_INT || iir == UART_IIR_THRI)) :
-                               (lsr & UART_LSR_TEMT && iir & UART_IIR_NO_INT))
+                               (lsr & UART_LSR_THRE) :
+                               (lsr & UART_LSR_TEMT))
                                transmit_chars(up);
                }
        }
@@ -1364,7 +1382,7 @@ static void serial8250_enable_ms(struct uart_port *port)
 static void
 receive_chars(struct uart_8250_port *up, unsigned int *status)
 {
-       struct tty_struct *tty = up->port.info->port.tty;
+       struct tty_struct *tty = up->port.state->port.tty;
        unsigned char ch, lsr = *status;
        int max_count = 256;
        char flag;
@@ -1439,7 +1457,7 @@ ignore_char:
 
 static void transmit_chars(struct uart_8250_port *up)
 {
-       struct circ_buf *xmit = &up->port.info->xmit;
+       struct circ_buf *xmit = &up->port.state->xmit;
        int count;
 
        if (up->port.x_char) {
@@ -1482,7 +1500,7 @@ static unsigned int check_modem_status(struct uart_8250_port *up)
        status |= up->msr_saved_flags;
        up->msr_saved_flags = 0;
        if (status & UART_MSR_ANY_DELTA && up->ier & UART_IER_MSI &&
-           up->port.info != NULL) {
+           up->port.state != NULL) {
                if (status & UART_MSR_TERI)
                        up->port.icount.rng++;
                if (status & UART_MSR_DDSR)
@@ -1492,7 +1510,7 @@ static unsigned int check_modem_status(struct uart_8250_port *up)
                if (status & UART_MSR_DCTS)
                        uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
 
-               wake_up_interruptible(&up->port.info->delta_msr_wait);
+               wake_up_interruptible(&up->port.state->port.delta_msr_wait);
        }
 
        return status;
@@ -1659,7 +1677,7 @@ static int serial_link_irq_chain(struct uart_8250_port *up)
                INIT_LIST_HEAD(&up->list);
                i->head = &up->list;
                spin_unlock_irq(&i->lock);
-
+               irq_flags |= up->port.irqflags;
                ret = request_irq(up->port.irq, serial8250_interrupt,
                                  irq_flags, "serial", i);
                if (ret < 0)
@@ -1746,7 +1764,7 @@ static void serial8250_backup_timeout(unsigned long data)
        up->lsr_saved_flags |= lsr & LSR_SAVE_FLAGS;
        spin_unlock_irqrestore(&up->port.lock, flags);
        if ((iir & UART_IIR_NO_INT) && (up->ier & UART_IER_THRI) &&
-           (!uart_circ_empty(&up->port.info->xmit) || up->port.x_char) &&
+           (!uart_circ_empty(&up->port.state->xmit) || up->port.x_char) &&
            (lsr & UART_LSR_THRE)) {
                iir &= ~(UART_IIR_ID | UART_IIR_NO_INT);
                iir |= UART_IIR_THRI;
@@ -1930,6 +1948,9 @@ static int serial8250_startup(struct uart_port *port)
        up->capabilities = uart_config[up->port.type].flags;
        up->mcr = 0;
 
+       if (up->port.iotype != up->cur_iotype)
+               set_io_from_upio(port);
+
        if (up->port.type == PORT_16C950) {
                /* Wake up and initialize UART */
                up->acr = 0;
@@ -2005,7 +2026,7 @@ static int serial8250_startup(struct uart_port *port)
                 * allow register changes to become visible.
                 */
                spin_lock_irqsave(&up->port.lock, flags);
-               if (up->port.flags & UPF_SHARE_IRQ)
+               if (up->port.irqflags & IRQF_SHARED)
                        disable_irq_nosync(up->port.irq);
 
                wait_for_xmitr(up, UART_LSR_THRE);
@@ -2018,7 +2039,7 @@ static int serial8250_startup(struct uart_port *port)
                iir = serial_in(up, UART_IIR);
                serial_out(up, UART_IER, 0);
 
-               if (up->port.flags & UPF_SHARE_IRQ)
+               if (up->port.irqflags & IRQF_SHARED)
                        enable_irq(up->port.irq);
                spin_unlock_irqrestore(&up->port.lock, flags);
 
@@ -2076,6 +2097,20 @@ static int serial8250_startup(struct uart_port *port)
 
        serial8250_set_mctrl(&up->port, up->port.mctrl);
 
+       /* Serial over Lan (SoL) hack:
+          Intel 8257x Gigabit ethernet chips have a
+          16550 emulation, to be used for Serial Over Lan.
+          Those chips take a longer time than a normal
+          serial device to signalize that a transmission
+          data was queued. Due to that, the above test generally
+          fails. One solution would be to delay the reading of
+          iir. However, this is not reliable, since the timeout
+          is variable. So, let's just don't test if we receive
+          TX irq. This way, we'll never enable UART_BUG_TXEN.
+        */
+       if (skip_txen_test || up->port.flags & UPF_NO_TXEN_TEST)
+               goto dont_test_tx_en;
+
        /*
         * Do a quick test to see if we receive an
         * interrupt when we enable the TX irq.
@@ -2095,6 +2130,7 @@ static int serial8250_startup(struct uart_port *port)
                up->bugs &= ~UART_BUG_TXEN;
        }
 
+dont_test_tx_en:
        spin_unlock_irqrestore(&up->port.lock, flags);
 
        /*
@@ -2236,7 +2272,9 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
        /*
         * Ask the core to calculate the divisor for us.
         */
-       baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
+       baud = uart_get_baud_rate(port, termios, old,
+                                 port->uartclk / 16 / 0xffff,
+                                 port->uartclk / 16);
        quot = serial8250_get_divisor(port, baud);
 
        /*
@@ -2541,6 +2579,9 @@ static void serial8250_config_port(struct uart_port *port, int flags)
        if (ret < 0)
                probeflags &= ~PROBE_RSA;
 
+       if (up->port.iotype != up->cur_iotype)
+               set_io_from_upio(port);
+
        if (flags & UART_CONFIG_TYPE)
                autoconfig(up, probeflags);
        if (up->port.type != PORT_UNKNOWN && flags & UART_CONFIG_IRQ)
@@ -2603,7 +2644,7 @@ static void __init serial8250_isa_init_ports(void)
 {
        struct uart_8250_port *up;
        static int first = 1;
-       int i;
+       int i, irqflag = 0;
 
        if (!first)
                return;
@@ -2627,11 +2668,15 @@ static void __init serial8250_isa_init_ports(void)
                up->port.ops = &serial8250_pops;
        }
 
+       if (share_irqs)
+               irqflag = IRQF_SHARED;
+
        for (i = 0, up = serial8250_ports;
             i < ARRAY_SIZE(old_serial_port) && i < nr_uarts;
             i++, up++) {
                up->port.iobase   = old_serial_port[i].port;
                up->port.irq      = irq_canonicalize(old_serial_port[i].irq);
+               up->port.irqflags = old_serial_port[i].irqflags;
                up->port.uartclk  = old_serial_port[i].baud_base * 16;
                up->port.flags    = old_serial_port[i].flags;
                up->port.hub6     = old_serial_port[i].hub6;
@@ -2639,8 +2684,7 @@ static void __init serial8250_isa_init_ports(void)
                up->port.iotype   = old_serial_port[i].io_type;
                up->port.regshift = old_serial_port[i].iomem_reg_shift;
                set_io_from_upio(&up->port);
-               if (share_irqs)
-                       up->port.flags |= UPF_SHARE_IRQ;
+               up->port.irqflags |= irqflag;
        }
 }
 
@@ -2649,6 +2693,11 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
 {
        int i;
 
+       for (i = 0; i < nr_uarts; i++) {
+               struct uart_8250_port *up = &serial8250_ports[i];
+               up->cur_iotype = 0xFF;
+       }
+
        serial8250_isa_init_ports();
 
        for (i = 0; i < nr_uarts; i++) {
@@ -2825,6 +2874,7 @@ int __init early_serial_setup(struct uart_port *port)
        p->iobase       = port->iobase;
        p->membase      = port->membase;
        p->irq          = port->irq;
+       p->irqflags     = port->irqflags;
        p->uartclk      = port->uartclk;
        p->fifosize     = port->fifosize;
        p->regshift     = port->regshift;
@@ -2832,6 +2882,8 @@ int __init early_serial_setup(struct uart_port *port)
        p->flags        = port->flags;
        p->mapbase      = port->mapbase;
        p->private_data = port->private_data;
+       p->type         = port->type;
+       p->line         = port->line;
 
        set_io_from_upio(p);
        if (port->serial_in)
@@ -2888,14 +2940,18 @@ static int __devinit serial8250_probe(struct platform_device *dev)
 {
        struct plat_serial8250_port *p = dev->dev.platform_data;
        struct uart_port port;
-       int ret, i;
+       int ret, i, irqflag = 0;
 
        memset(&port, 0, sizeof(struct uart_port));
 
+       if (share_irqs)
+               irqflag = IRQF_SHARED;
+
        for (i = 0; p && p->flags != 0; p++, i++) {
                port.iobase             = p->iobase;
                port.membase            = p->membase;
                port.irq                = p->irq;
+               port.irqflags           = p->irqflags;
                port.uartclk            = p->uartclk;
                port.regshift           = p->regshift;
                port.iotype             = p->iotype;
@@ -2903,11 +2959,11 @@ static int __devinit serial8250_probe(struct platform_device *dev)
                port.mapbase            = p->mapbase;
                port.hub6               = p->hub6;
                port.private_data       = p->private_data;
+               port.type               = p->type;
                port.serial_in          = p->serial_in;
                port.serial_out         = p->serial_out;
                port.dev                = &dev->dev;
-               if (share_irqs)
-                       port.flags |= UPF_SHARE_IRQ;
+               port.irqflags           |= irqflag;
                ret = serial8250_register_port(&port);
                if (ret < 0) {
                        dev_err(&dev->dev, "unable to register port at index %d "
@@ -3049,6 +3105,7 @@ int serial8250_register_port(struct uart_port *port)
                uart->port.iobase       = port->iobase;
                uart->port.membase      = port->membase;
                uart->port.irq          = port->irq;
+               uart->port.irqflags     = port->irqflags;
                uart->port.uartclk      = port->uartclk;
                uart->port.fifosize     = port->fifosize;
                uart->port.regshift     = port->regshift;
@@ -3058,6 +3115,14 @@ int serial8250_register_port(struct uart_port *port)
                uart->port.private_data = port->private_data;
                if (port->dev)
                        uart->port.dev = port->dev;
+
+               if (port->flags & UPF_FIXED_TYPE) {
+                       uart->port.type = port->type;
+                       uart->port.fifosize = uart_config[port->type].fifo_size;
+                       uart->capabilities = uart_config[port->type].flags;
+                       uart->tx_loadsz = uart_config[port->type].tx_loadsz;
+               }
+
                set_io_from_upio(&uart->port);
                /* Possibly override default I/O functions.  */
                if (port->serial_in)
@@ -3107,7 +3172,7 @@ static int __init serial8250_init(void)
        if (nr_uarts > UART_NR)
                nr_uarts = UART_NR;
 
-       printk(KERN_INFO "Serial: 8250/16550 driver"
+       printk(KERN_INFO "Serial: 8250/16550 driver"
                "%d ports, IRQ sharing %sabled\n", nr_uarts,
                share_irqs ? "en" : "dis");
 
@@ -3187,6 +3252,9 @@ MODULE_PARM_DESC(share_irqs, "Share IRQs with other non-8250/16x50 devices"
 module_param(nr_uarts, uint, 0644);
 MODULE_PARM_DESC(nr_uarts, "Maximum number of UARTs supported. (1-" __MODULE_STRING(CONFIG_SERIAL_8250_NR_UARTS) ")");
 
+module_param(skip_txen_test, uint, 0644);
+MODULE_PARM_DESC(skip_txen_test, "Skip checking for the TXEN bug at init time");
+
 #ifdef CONFIG_SERIAL_8250_RSA
 module_param_array(probe_rsa, ulong, &probe_rsa_count, 0444);
 MODULE_PARM_DESC(probe_rsa, "Probe I/O ports for RSA");