]> err.no Git - linux-2.6/blobdiff - drivers/serial/bfin_5xx.c
scsi: use non-racy method for proc entries creation
[linux-2.6] / drivers / serial / bfin_5xx.c
index 2fb3081c5022736c581faed033ce3aed80038dbd..5f55534a290ba8d00000c694cef8c28496347090 100644 (file)
@@ -48,7 +48,7 @@
 #define DMA_RX_XCOUNT          512
 #define DMA_RX_YCOUNT          (PAGE_SIZE / DMA_RX_XCOUNT)
 
-#define DMA_RX_FLUSH_JIFFIES   5
+#define DMA_RX_FLUSH_JIFFIES   (HZ / 50)
 
 #ifdef CONFIG_SERIAL_BFIN_DMA
 static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart);
@@ -151,7 +151,8 @@ void kgdb_put_debug_char(int chr)
 {
        struct bfin_serial_port *uart;
        
-       if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
+       if (CONFIG_KGDB_UART_PORT < 0
+               || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
                uart = &bfin_serial_ports[0];
        else
                uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
@@ -173,7 +174,8 @@ int kgdb_get_debug_char(void)
        struct bfin_serial_port *uart;
        unsigned char chr;
 
-       if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS)
+       if (CONFIG_KGDB_UART_PORT < 0
+               || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
                uart = &bfin_serial_ports[0];
        else
                uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
@@ -192,7 +194,7 @@ int kgdb_get_debug_char(void)
 }
 #endif
 
-#if ANOMALY_05000230 && defined(CONFIG_SERIAL_BFIN_PIO)
+#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
 # define UART_GET_ANOMALY_THRESHOLD(uart)    ((uart)->anomaly_threshold)
 # define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
 #else
@@ -237,7 +239,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
        }
 #endif
 
-       if (ANOMALY_05000230) {
+       if (ANOMALY_05000363) {
                /* The BF533 (and BF561) family of processors have a nice anomaly
                 * where they continuously generate characters for a "single" break.
                 * We have to basically ignore this flood until the "next" valid
@@ -249,9 +251,6 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
                 * timeout was picked as it must absolutely be larger than 1
                 * character time +/- some percent.  So 1.5 sounds good.  All other
                 * Blackfin families operate properly.  Woo.
-                * Note: While Anomaly 05000230 does not directly address this,
-                *       the changes that went in for it also fixed this issue.
-                *       That anomaly was fixed in 0.5+ silicon.  I like bunnies.
                 */
                if (anomaly_start.tv_sec) {
                        struct timeval curr;
@@ -285,7 +284,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
        }
 
        if (status & BI) {
-               if (ANOMALY_05000230)
+               if (ANOMALY_05000363)
                        if (bfin_revid() < 5)
                                do_gettimeofday(&anomaly_start);
                uart->port.icount.brk++;
@@ -393,7 +392,6 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
 {
        struct circ_buf *xmit = &uart->port.info->xmit;
        unsigned short ier;
-       int flags = 0;
 
        uart->tx_done = 0;
 
@@ -415,7 +413,6 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
         */
        bfin_serial_mctrl_check(uart);
 
-       spin_lock_irqsave(&uart->port.lock, flags);
        uart->tx_count = CIRC_CNT(xmit->head, xmit->tail, UART_XMIT_SIZE);
        if (uart->tx_count > (UART_XMIT_SIZE - xmit->tail))
                uart->tx_count = UART_XMIT_SIZE - xmit->tail;
@@ -439,7 +436,6 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
        ier |= ETBEI;
        UART_PUT_IER(uart, ier);
 #endif
-       spin_unlock_irqrestore(&uart->port.lock, flags);
 }
 
 static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
@@ -450,7 +446,9 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
        status = UART_GET_LSR(uart);
        UART_CLEAR_LSR(uart);
 
-       uart->port.icount.rx += CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail, UART_XMIT_SIZE);;
+       uart->port.icount.rx +=
+               CIRC_CNT(uart->rx_dma_buf.head, uart->rx_dma_buf.tail,
+               UART_XMIT_SIZE);
 
        if (status & BI) {
                uart->port.icount.brk++;
@@ -476,10 +474,12 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
        else
                flg = TTY_NORMAL;
 
-       for (i = uart->rx_dma_buf.head; i < uart->rx_dma_buf.tail; i++) {
-               if (uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
-                       goto dma_ignore_char;
-               uart_insert_char(&uart->port, status, OE, uart->rx_dma_buf.buf[i], flg);
+       for (i = uart->rx_dma_buf.tail; i != uart->rx_dma_buf.head; i++) {
+               if (i >= UART_XMIT_SIZE)
+                       i = 0;
+               if (!uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
+                       uart_insert_char(&uart->port, status, OE,
+                               uart->rx_dma_buf.buf[i], flg);
        }
 
  dma_ignore_char:
@@ -489,23 +489,24 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
 void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
 {
        int x_pos, pos;
-       int flags = 0;
 
-       spin_lock_irqsave(&uart->port.lock, flags);
-       x_pos = DMA_RX_XCOUNT - get_dma_curr_xcount(uart->rx_dma_channel);
+       uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
+       x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
+       uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
+       if (uart->rx_dma_nrows == DMA_RX_YCOUNT)
+               uart->rx_dma_nrows = 0;
+       x_pos = DMA_RX_XCOUNT - x_pos;
        if (x_pos == DMA_RX_XCOUNT)
                x_pos = 0;
 
        pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos;
-
-       if (pos>uart->rx_dma_buf.tail) {
-               uart->rx_dma_buf.tail = pos;
+       if (pos != uart->rx_dma_buf.tail) {
+               uart->rx_dma_buf.head = pos;
                bfin_serial_dma_rx_chars(uart);
-               uart->rx_dma_buf.head = uart->rx_dma_buf.tail;
+               uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
        }
-       spin_unlock_irqrestore(&uart->port.lock, flags);
-       uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES;
-       add_timer(&(uart->rx_dma_timer));
+
+       mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
 }
 
 static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
@@ -525,12 +526,12 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
                ier &= ~ETBEI;
                UART_PUT_IER(uart, ier);
 #endif
-               if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
-                       uart_write_wakeup(&uart->port);
-
                xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
                uart->port.icount.tx += uart->tx_count;
 
+               if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+                       uart_write_wakeup(&uart->port);
+
                bfin_serial_dma_tx_chars(uart);
        }
 
@@ -543,20 +544,13 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
        struct bfin_serial_port *uart = dev_id;
        unsigned short irqstat;
 
-       uart->rx_dma_nrows++;
-       uart->rx_dma_buf.tail = DMA_RX_XCOUNT * uart->rx_dma_nrows;
-       bfin_serial_dma_rx_chars(uart);
-       if (uart->rx_dma_nrows >= DMA_RX_YCOUNT) {
-               uart->rx_dma_nrows = 0;
-               uart->rx_dma_buf.tail = 0;
-       }
-       uart->rx_dma_buf.head = uart->rx_dma_buf.tail;
-
        spin_lock(&uart->port.lock);
        irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
        clear_dma_irqstat(uart->rx_dma_channel);
-
        spin_unlock(&uart->port.lock);
+
+       mod_timer(&(uart->rx_dma_timer), jiffies);
+
        return IRQ_HANDLED;
 }
 #endif
@@ -751,7 +745,7 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
        struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
        unsigned long flags;
        unsigned int baud, quot;
-       unsigned short val, ier, lsr, lcr = 0;
+       unsigned short val, ier, lcr = 0;
 
        switch (termios->c_cflag & CSIZE) {
        case CS8:
@@ -808,10 +802,6 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
 
        UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
 
-       do {
-               lsr = UART_GET_LSR(uart);
-       } while (!(lsr & TEMT));
-
        /* Disable UART */
        ier = UART_GET_IER(uart);
 #ifdef CONFIG_BF54x
@@ -902,6 +892,31 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
        return 0;
 }
 
+/*
+ * Enable the IrDA function if tty->ldisc.num is N_IRDA.
+ * In other cases, disable IrDA function.
+ */
+static void bfin_set_ldisc(struct tty_struct *tty)
+{
+       int line = tty->index;
+       unsigned short val;
+
+       if (line >= tty->driver->num)
+               return;
+
+       switch (tty->ldisc.num) {
+       case N_IRDA:
+               val = UART_GET_GCTL(&bfin_serial_ports[line]);
+               val |= (IREN | RPOLC);
+               UART_PUT_GCTL(&bfin_serial_ports[line], val);
+               break;
+       default:
+               val = UART_GET_GCTL(&bfin_serial_ports[line]);
+               val &= ~(IREN | RPOLC);
+               UART_PUT_GCTL(&bfin_serial_ports[line], val);
+       }
+}
+
 static struct uart_ops bfin_serial_pops = {
        .tx_empty       = bfin_serial_tx_empty,
        .set_mctrl      = bfin_serial_set_mctrl,
@@ -1174,7 +1189,7 @@ static struct uart_driver bfin_serial_reg = {
        .dev_name               = BFIN_SERIAL_NAME,
        .major                  = BFIN_SERIAL_MAJOR,
        .minor                  = BFIN_SERIAL_MINOR,
-       .nr                     = NR_PORTS,
+       .nr                     = BFIN_UART_NR_PORTS,
        .cons                   = BFIN_SERIAL_CONSOLE,
 };
 
@@ -1245,6 +1260,7 @@ static struct platform_driver bfin_serial_driver = {
        .resume         = bfin_serial_resume,
        .driver         = {
                .name   = "bfin-uart",
+               .owner  = THIS_MODULE,
        },
 };
 
@@ -1262,6 +1278,7 @@ static int __init bfin_serial_init(void)
 
        ret = uart_register_driver(&bfin_serial_reg);
        if (ret == 0) {
+               bfin_serial_reg.tty_driver->set_ldisc = bfin_set_ldisc;
                ret = platform_driver_register(&bfin_serial_driver);
                if (ret) {
                        pr_debug("uart register failed\n");
@@ -1303,3 +1320,4 @@ MODULE_AUTHOR("Aubrey.Li <aubrey.li@analog.com>");
 MODULE_DESCRIPTION("Blackfin generic serial port driver");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_CHARDEV_MAJOR(BFIN_SERIAL_MAJOR);
+MODULE_ALIAS("platform:bfin-uart");