]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/serial/sh-sci.c
sh: Fix up the shared IRQ demuxer's control bit testing logic.
[linux-2.6-omap-h63xx.git] / drivers / serial / sh-sci.c
index 5bb57154855849a27e4cae6699ae916f10c37e3f..5c0f32c7fbf6b20c8e20fba1ec32f7e08af29909 100644 (file)
@@ -3,7 +3,7 @@
  *
  * SuperH on-chip serial module support.  (SCI with no FIFO / with FIFO)
  *
- *  Copyright (C) 2002 - 2006  Paul Mundt
+ *  Copyright (C) 2002 - 2008  Paul Mundt
  *  Modified to support SH7720 SCIF. Markus Brunner, Mark Jonas (Jul 2007).
  *
  * based off of the old drivers/char/sh-sci.c by:
@@ -46,6 +46,7 @@
 #include <linux/cpufreq.h>
 #include <linux/clk.h>
 #include <linux/ctype.h>
+#include <linux/err.h>
 
 #ifdef CONFIG_SUPERH
 #include <asm/clock.h>
@@ -249,8 +250,7 @@ static inline void h8300_sci_disable(struct uart_port *port)
 }
 #endif
 
-#if defined(SCI_ONLY) || defined(SCI_AND_SCIF) && \
-    defined(__H8300H__) || defined(__H8300S__)
+#if defined(__H8300H__) || defined(__H8300S__)
 static void sci_init_pins_sci(struct uart_port* port, unsigned int cflag)
 {
        int ch = (port->mapbase - SMR0) >> 3;
@@ -284,11 +284,6 @@ static void sci_init_pins_irda(struct uart_port *port, unsigned int cflag)
 #define sci_init_pins_irda NULL
 #endif
 
-#ifdef SCI_ONLY
-#define sci_init_pins_scif NULL
-#endif
-
-#if defined(SCIF_ONLY) || defined(SCI_AND_SCIF)
 #if defined(CONFIG_CPU_SUBTYPE_SH7710) || defined(CONFIG_CPU_SUBTYPE_SH7712)
 static void sci_init_pins_scif(struct uart_port* port, unsigned int cflag)
 {
@@ -448,7 +443,6 @@ static inline int scif_rxroom(struct uart_port *port)
        return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
 }
 #endif
-#endif /* SCIF_ONLY || SCI_AND_SCIF */
 
 static inline int sci_txroom(struct uart_port *port)
 {
@@ -484,11 +478,9 @@ static void sci_transmit_chars(struct uart_port *port)
                return;
        }
 
-#ifndef SCI_ONLY
        if (port->type == PORT_SCIF)
                count = scif_txroom(port);
        else
-#endif
                count = sci_txroom(port);
 
        do {
@@ -518,12 +510,10 @@ static void sci_transmit_chars(struct uart_port *port)
        } else {
                ctrl = sci_in(port, SCSCR);
 
-#if !defined(SCI_ONLY)
                if (port->type == PORT_SCIF) {
                        sci_in(port, SCxSR); /* Dummy read */
                        sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port));
                }
-#endif
 
                ctrl |= SCI_CTRL_FLAGS_TIE;
                sci_out(port, SCSCR, ctrl);
@@ -546,11 +536,9 @@ static inline void sci_receive_chars(struct uart_port *port)
                return;
 
        while (1) {
-#if !defined(SCI_ONLY)
                if (port->type == PORT_SCIF)
                        count = scif_rxroom(port);
                else
-#endif
                        count = sci_rxroom(port);
 
                /* Don't copy more bytes than there is room for in the buffer */
@@ -809,26 +797,27 @@ static irqreturn_t sci_br_interrupt(int irq, void *ptr)
 
 static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
 {
-        unsigned short ssr_status, scr_status;
-        struct uart_port *port = ptr;
+       unsigned short ssr_status, scr_status;
+       struct uart_port *port = ptr;
+       irqreturn_t ret = IRQ_NONE;
 
         ssr_status = sci_in(port,SCxSR);
         scr_status = sci_in(port,SCSCR);
 
        /* Tx Interrupt */
-        if ((ssr_status & 0x0020) && (scr_status & 0x0080))
-                sci_tx_interrupt(irq, ptr);
+       if ((ssr_status & 0x0020) && (scr_status & SCI_CTRL_FLAGS_TIE))
+               ret = sci_tx_interrupt(irq, ptr);
        /* Rx Interrupt */
-        if ((ssr_status & 0x0002) && (scr_status & 0x0040))
-                sci_rx_interrupt(irq, ptr);
+       if ((ssr_status & 0x0002) && (scr_status & SCI_CTRL_FLAGS_RIE))
+               ret = sci_rx_interrupt(irq, ptr);
        /* Error Interrupt */
-        if ((ssr_status & 0x0080) && (scr_status & 0x0400))
-                sci_er_interrupt(irq, ptr);
+       if ((ssr_status & 0x0080) && (scr_status & SCI_CTRL_FLAGS_REIE))
+               ret = sci_er_interrupt(irq, ptr);
        /* Break Interrupt */
-        if ((ssr_status & 0x0010) && (scr_status & 0x0200))
-                sci_br_interrupt(irq, ptr);
+       if ((ssr_status & 0x0010) && (scr_status & SCI_CTRL_FLAGS_REIE))
+               ret = sci_br_interrupt(irq, ptr);
 
-       return IRQ_HANDLED;
+       return ret;
 }
 
 #if defined(CONFIG_CPU_FREQ) && defined(CONFIG_HAVE_CLK)
@@ -1053,10 +1042,8 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 
        sci_out(port, SCSCR, 0x00);     /* TE=0, RE=0, CKE1=0 */
 
-#if !defined(SCI_ONLY)
        if (port->type == PORT_SCIF)
                sci_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST);
-#endif
 
        smr_val = sci_in(port, SCSMR) & 3;
        if ((termios->c_cflag & CSIZE) == CS7)
@@ -1132,19 +1119,23 @@ static void sci_config_port(struct uart_port *port, int flags)
                break;
        }
 
-#if defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
-       if (port->mapbase == 0)
+       if (port->flags & UPF_IOREMAP && !port->membase) {
+#if defined(CONFIG_SUPERH64)
                port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF");
-
-       port->membase = (void __iomem *)port->mapbase;
+               port->membase = (void __iomem *)port->mapbase;
+#else
+               port->membase = ioremap_nocache(port->mapbase, 0x40);
 #endif
+
+               printk(KERN_ERR "sci: can't remap port#%d\n", port->line);
+       }
 }
 
 static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
 {
        struct sci_port *s = &sci_ports[port->line];
 
-       if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > NR_IRQS)
+       if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
                return -EINVAL;
        if (ser->baud_base < 2400)
                /* No paper tape reader for Mitch.. */
@@ -1423,7 +1414,7 @@ static struct uart_driver sci_uart_driver = {
 static int __devinit sci_probe(struct platform_device *dev)
 {
        struct plat_sci_port *p = dev->dev.platform_data;
-       int i;
+       int i, ret = -EINVAL;
 
        for (i = 0; p && p->flags != 0; p++, i++) {
                struct sci_port *sciport = &sci_ports[i];
@@ -1440,12 +1431,22 @@ static int __devinit sci_probe(struct platform_device *dev)
 
                sciport->port.mapbase   = p->mapbase;
 
-               /*
-                * For the simple (and majority of) cases where we don't need
-                * to do any remapping, just cast the cookie directly.
-                */
-               if (p->mapbase && !p->membase && !(p->flags & UPF_IOREMAP))
-                       p->membase = (void __iomem *)p->mapbase;
+               if (p->mapbase && !p->membase) {
+                       if (p->flags & UPF_IOREMAP) {
+                               p->membase = ioremap_nocache(p->mapbase, 0x40);
+                               if (IS_ERR(p->membase)) {
+                                       ret = PTR_ERR(p->membase);
+                                       goto err_unreg;
+                               }
+                       } else {
+                               /*
+                                * For the simple (and majority of) cases
+                                * where we don't need to do any remapping,
+                                * just cast the cookie directly.
+                                */
+                               p->membase = (void __iomem *)p->mapbase;
+                       }
+               }
 
                sciport->port.membase   = p->membase;
 
@@ -1476,6 +1477,12 @@ static int __devinit sci_probe(struct platform_device *dev)
 #endif
 
        return 0;
+
+err_unreg:
+       for (i = i - 1; i >= 0; i--)
+               uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
+
+       return ret;
 }
 
 static int __devexit sci_remove(struct platform_device *dev)