watchdog: s3c2410_wdt - Add extra option to include watchdog for Samsung SoCs
[safe/jmp/linux-2.6] / drivers / serial / sunsab.c
index 493d5bb..5e81bc6 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/init.h>
+#include <linux/of_device.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/prom.h>
-#include <asm/of_device.h>
 
-#if defined(CONFIG_SERIAL_SUNZILOG_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
+#if defined(CONFIG_SERIAL_SUNSAB_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
 #endif
 
@@ -59,6 +58,7 @@ struct uart_sunsab_port {
        unsigned char                   interrupt_mask1;/* ISR1 masking         */
        unsigned char                   pvr_dtr_bit;    /* Which PVR bit is DTR */
        unsigned char                   pvr_dsr_bit;    /* Which PVR bit is DSR */
+       unsigned int                    gis_shift;
        int                             type;           /* SAB82532 version     */
 
        /* Setting configuration bits while the transmitter is active
@@ -117,8 +117,8 @@ receive_chars(struct uart_sunsab_port *up,
        int count = 0;
        int i;
 
-       if (up->port.info != NULL)              /* Unopened serial console */
-               tty = up->port.info->tty;
+       if (up->port.state != NULL)             /* Unopened serial console */
+               tty = up->port.state->port.tty;
 
        /* Read number of BYTES (Character + Status) available. */
        if (stat->sreg.isr0 & SAB82532_ISR0_RPF) {
@@ -229,7 +229,7 @@ static void sunsab_tx_idle(struct uart_sunsab_port *);
 static void transmit_chars(struct uart_sunsab_port *up,
                           union sab82532_irq_status *stat)
 {
-       struct circ_buf *xmit = &up->port.info->xmit;
+       struct circ_buf *xmit = &up->port.state->xmit;
        int i;
 
        if (stat->sreg.isr1 & SAB82532_ISR1_ALLS) {
@@ -297,7 +297,7 @@ static void check_status(struct uart_sunsab_port *up,
                up->port.icount.dsr++;
        }
 
-       wake_up_interruptible(&up->port.info->delta_msr_wait);
+       wake_up_interruptible(&up->port.state->port.delta_msr_wait);
 }
 
 static irqreturn_t sunsab_interrupt(int irq, void *dev_id)
@@ -306,13 +306,15 @@ static irqreturn_t sunsab_interrupt(int irq, void *dev_id)
        struct tty_struct *tty;
        union sab82532_irq_status status;
        unsigned long flags;
+       unsigned char gis;
 
        spin_lock_irqsave(&up->port.lock, flags);
 
        status.stat = 0;
-       if (readb(&up->regs->r.gis) & SAB82532_GIS_ISA0)
+       gis = readb(&up->regs->r.gis) >> up->gis_shift;
+       if (gis & 1)
                status.sreg.isr0 = readb(&up->regs->r.isr0);
-       if (readb(&up->regs->r.gis) & SAB82532_GIS_ISA1)
+       if (gis & 2)
                status.sreg.isr1 = readb(&up->regs->r.isr1);
 
        tty = NULL;
@@ -328,35 +330,6 @@ static irqreturn_t sunsab_interrupt(int irq, void *dev_id)
                        transmit_chars(up, &status);
        }
 
-       spin_unlock(&up->port.lock);
-
-       if (tty)
-               tty_flip_buffer_push(tty);
-
-       up++;
-
-       spin_lock(&up->port.lock);
-
-       status.stat = 0;
-       if (readb(&up->regs->r.gis) & SAB82532_GIS_ISB0)
-               status.sreg.isr0 = readb(&up->regs->r.isr0);
-       if (readb(&up->regs->r.gis) & SAB82532_GIS_ISB1)
-               status.sreg.isr1 = readb(&up->regs->r.isr1);
-
-       tty = NULL;
-       if (status.stat) {
-               if ((status.sreg.isr0 & (SAB82532_ISR0_TCD | SAB82532_ISR0_TIME |
-                                        SAB82532_ISR0_RFO | SAB82532_ISR0_RPF)) ||
-                   (status.sreg.isr1 & SAB82532_ISR1_BRK))
-
-                       tty = receive_chars(up, &status);
-               if ((status.sreg.isr0 & SAB82532_ISR0_CDSC) ||
-                   (status.sreg.isr1 & (SAB82532_ISR1_BRK | SAB82532_ISR1_CSC)))
-                       check_status(up, &status);
-               if (status.sreg.isr1 & (SAB82532_ISR1_ALLS | SAB82532_ISR1_XPR))
-                       transmit_chars(up, &status);
-       }
-
        spin_unlock_irqrestore(&up->port.lock, flags);
 
        if (tty)
@@ -456,7 +429,7 @@ static void sunsab_tx_idle(struct uart_sunsab_port *up)
 static void sunsab_start_tx(struct uart_port *port)
 {
        struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
-       struct circ_buf *xmit = &up->port.info->xmit;
+       struct circ_buf *xmit = &up->port.state->xmit;
        int i;
 
        up->interrupt_mask1 &= ~(SAB82532_IMR1_ALLS|SAB82532_IMR1_XPR);
@@ -501,7 +474,7 @@ static void sunsab_stop_rx(struct uart_port *port)
 {
        struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
 
-       up->interrupt_mask0 |= SAB82532_ISR0_TCD;
+       up->interrupt_mask0 |= SAB82532_IMR0_TCD;
        writeb(up->interrupt_mask1, &up->regs->w.imr0);
 }
 
@@ -540,6 +513,10 @@ static int sunsab_startup(struct uart_port *port)
        struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
        unsigned long flags;
        unsigned char tmp;
+       int err = request_irq(up->port.irq, sunsab_interrupt,
+                             IRQF_SHARED, "sab", up);
+       if (err)
+               return err;
 
        spin_lock_irqsave(&up->port.lock, flags);
 
@@ -642,6 +619,7 @@ static void sunsab_shutdown(struct uart_port *port)
 #endif
 
        spin_unlock_irqrestore(&up->port.lock, flags);
+       free_irq(up->port.irq, up);
 }
 
 /*
@@ -848,35 +826,43 @@ static struct uart_ops sunsab_pops = {
 
 static struct uart_driver sunsab_reg = {
        .owner                  = THIS_MODULE,
-       .driver_name            = "serial",
+       .driver_name            = "sunsab",
        .dev_name               = "ttyS",
        .major                  = TTY_MAJOR,
 };
 
 static struct uart_sunsab_port *sunsab_ports;
-static int num_channels;
 
 #ifdef CONFIG_SERIAL_SUNSAB_CONSOLE
 
 static void sunsab_console_putchar(struct uart_port *port, int c)
 {
        struct uart_sunsab_port *up = (struct uart_sunsab_port *)port;
-       unsigned long flags;
-
-       spin_lock_irqsave(&up->port.lock, flags);
 
        sunsab_tec_wait(up);
        writeb(c, &up->regs->w.tic);
-
-       spin_unlock_irqrestore(&up->port.lock, flags);
 }
 
 static void sunsab_console_write(struct console *con, const char *s, unsigned n)
 {
        struct uart_sunsab_port *up = &sunsab_ports[con->index];
+       unsigned long flags;
+       int locked = 1;
+
+       local_irq_save(flags);
+       if (up->port.sysrq) {
+               locked = 0;
+       } else if (oops_in_progress) {
+               locked = spin_trylock(&up->port.lock);
+       } else
+               spin_lock(&up->port.lock);
 
        uart_console_write(&up->port, s, n, sunsab_console_putchar);
        sunsab_tec_wait(up);
+
+       if (locked)
+               spin_unlock(&up->port.lock);
+       local_irq_restore(flags);
 }
 
 static int sunsab_console_setup(struct console *con, char *options)
@@ -897,7 +883,7 @@ static int sunsab_console_setup(struct console *con, char *options)
        printk("Console: ttyS%d (SAB82532)\n",
               (sunsab_reg.minor - 64) + con->index);
 
-       sunserial_console_termios(con);
+       sunserial_console_termios(con, to_of_device(up->port.dev)->dev.of_node);
 
        switch (con->cflag & CBAUD) {
        case B150: baud = 150; break;
@@ -960,22 +946,6 @@ static struct console sunsab_console = {
 
 static inline struct console *SUNSAB_CONSOLE(void)
 {
-       int i;
-
-       if (con_is_present())
-               return NULL;
-
-       for (i = 0; i < num_channels; i++) {
-               int this_minor = sunsab_reg.minor + i;
-
-               if ((this_minor - 64) == (serial_console - 1))
-                       break;
-       }
-       if (i == num_channels)
-               return NULL;
-
-       sunsab_console.index = i;
-
        return &sunsab_console;
 }
 #else
@@ -1016,9 +986,11 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
        if ((up->port.line & 0x1) == 0) {
                up->pvr_dsr_bit = (1 << 0);
                up->pvr_dtr_bit = (1 << 1);
+               up->gis_shift = 2;
        } else {
                up->pvr_dsr_bit = (1 << 3);
                up->pvr_dtr_bit = (1 << 2);
+               up->gis_shift = 0;
        }
        up->cached_pvr = (1 << 1) | (1 << 2) | (1 << 4);
        writeb(up->cached_pvr, &up->regs->w.pvr);
@@ -1031,18 +1003,6 @@ static int __devinit sunsab_init_one(struct uart_sunsab_port *up,
        up->tec_timeout = SAB82532_MAX_TEC_TIMEOUT;
        up->cec_timeout = SAB82532_MAX_CEC_TIMEOUT;
 
-       if (!(up->port.line & 0x01)) {
-               int err;
-
-               err = request_irq(up->port.irq, sunsab_interrupt,
-                                 IRQF_SHARED, "sab", up);
-               if (err) {
-                       of_iounmap(up->port.membase,
-                                  sizeof(union sab82532_async_regs));
-                       return err;
-               }
-       }
-
        return 0;
 }
 
@@ -1058,50 +1018,69 @@ static int __devinit sab_probe(struct of_device *op, const struct of_device_id *
                              0,
                              (inst * 2) + 0);
        if (err)
-               return err;
+               goto out;
 
        err = sunsab_init_one(&up[1], op,
                              sizeof(union sab82532_async_regs),
                              (inst * 2) + 1);
-       if (err) {
-               of_iounmap(up[0].port.membase,
-                          sizeof(union sab82532_async_regs));
-               free_irq(up[0].port.irq, &up[0]);
-               return err;
-       }
+       if (err)
+               goto out1;
+
+       sunserial_console_match(SUNSAB_CONSOLE(), op->dev.of_node,
+                               &sunsab_reg, up[0].port.line,
+                               false);
+
+       sunserial_console_match(SUNSAB_CONSOLE(), op->dev.of_node,
+                               &sunsab_reg, up[1].port.line,
+                               false);
 
-       uart_add_one_port(&sunsab_reg, &up[0].port);
-       uart_add_one_port(&sunsab_reg, &up[1].port);
+       err = uart_add_one_port(&sunsab_reg, &up[0].port);
+       if (err)
+               goto out2;
+
+       err = uart_add_one_port(&sunsab_reg, &up[1].port);
+       if (err)
+               goto out3;
 
        dev_set_drvdata(&op->dev, &up[0]);
 
        inst++;
 
        return 0;
-}
 
-static void __devexit sab_remove_one(struct uart_sunsab_port *up)
-{
-       uart_remove_one_port(&sunsab_reg, &up->port);
-       if (!(up->port.line & 1))
-               free_irq(up->port.irq, up);
-       of_iounmap(up->port.membase,
+out3:
+       uart_remove_one_port(&sunsab_reg, &up[0].port);
+out2:
+       of_iounmap(&op->resource[0],
+                  up[1].port.membase,
+                  sizeof(union sab82532_async_regs));
+out1:
+       of_iounmap(&op->resource[0],
+                  up[0].port.membase,
                   sizeof(union sab82532_async_regs));
+out:
+       return err;
 }
 
 static int __devexit sab_remove(struct of_device *op)
 {
        struct uart_sunsab_port *up = dev_get_drvdata(&op->dev);
 
-       sab_remove_one(&up[0]);
-       sab_remove_one(&up[1]);
+       uart_remove_one_port(&sunsab_reg, &up[1].port);
+       uart_remove_one_port(&sunsab_reg, &up[0].port);
+       of_iounmap(&op->resource[0],
+                  up[1].port.membase,
+                  sizeof(union sab82532_async_regs));
+       of_iounmap(&op->resource[0],
+                  up[0].port.membase,
+                  sizeof(union sab82532_async_regs));
 
        dev_set_drvdata(&op->dev, NULL);
 
        return 0;
 }
 
-static struct of_device_id sab_match[] = {
+static const struct of_device_id sab_match[] = {
        {
                .name = "se",
        },
@@ -1114,8 +1093,11 @@ static struct of_device_id sab_match[] = {
 MODULE_DEVICE_TABLE(of, sab_match);
 
 static struct of_platform_driver sab_driver = {
-       .name           = "sab",
-       .match_table    = sab_match,
+       .driver = {
+               .name = "sab",
+               .owner = THIS_MODULE,
+               .of_match_table = sab_match,
+       },
        .probe          = sab_probe,
        .remove         = __devexit_p(sab_remove),
 };
@@ -1124,8 +1106,8 @@ static int __init sunsab_init(void)
 {
        struct device_node *dp;
        int err;
+       int num_channels = 0;
 
-       num_channels = 0;
        for_each_node_by_name(dp, "se")
                num_channels += 2;
        for_each_node_by_name(dp, "serial") {
@@ -1139,20 +1121,13 @@ static int __init sunsab_init(void)
                if (!sunsab_ports)
                        return -ENOMEM;
 
-               sunsab_reg.minor = sunserial_current_minor;
-               sunsab_reg.nr = num_channels;
-
-               err = uart_register_driver(&sunsab_reg);
+               err = sunserial_register_minors(&sunsab_reg, num_channels);
                if (err) {
                        kfree(sunsab_ports);
                        sunsab_ports = NULL;
 
                        return err;
                }
-
-               sunsab_reg.tty_driver->name_base = sunsab_reg.minor - 64;
-               sunsab_reg.cons = SUNSAB_CONSOLE();
-               sunserial_current_minor += num_channels;
        }
 
        return of_register_driver(&sab_driver, &of_bus_type);
@@ -1161,9 +1136,8 @@ static int __init sunsab_init(void)
 static void __exit sunsab_exit(void)
 {
        of_unregister_driver(&sab_driver);
-       if (num_channels) {
-               sunserial_current_minor -= num_channels;
-               uart_unregister_driver(&sunsab_reg);
+       if (sunsab_reg.nr) {
+               sunserial_unregister_minors(&sunsab_reg, sunsab_reg.nr);
        }
 
        kfree(sunsab_ports);