Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[safe/jmp/linux-2.6] / drivers / char / vme_scc.c
index 1718b3c..12de120 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/fcntl.h>
 #include <linux/major.h>
 #include <linux/delay.h>
-#include <linux/slab.h>
 #include <linux/miscdevice.h>
 #include <linux/console.h>
 #include <linux/init.h>
@@ -69,7 +68,7 @@ static void scc_disable_tx_interrupts(void * ptr);
 static void scc_enable_tx_interrupts(void * ptr);
 static void scc_disable_rx_interrupts(void * ptr);
 static void scc_enable_rx_interrupts(void * ptr);
-static int  scc_get_CD(void * ptr);
+static int  scc_carrier_raised(struct tty_port *port);
 static void scc_shutdown_port(void * ptr);
 static int scc_set_real_termios(void  *ptr);
 static void scc_hungup(void  *ptr);
@@ -100,7 +99,6 @@ static struct real_driver scc_real_driver = {
         scc_enable_tx_interrupts,
         scc_disable_rx_interrupts,
         scc_enable_rx_interrupts,
-        scc_get_CD,
         scc_shutdown_port,
         scc_set_real_termios,
         scc_chars_in_buffer,
@@ -129,11 +127,15 @@ static const struct tty_operations scc_ops = {
        .break_ctl = scc_break_ctl,
 };
 
+static const struct tty_port_operations scc_port_ops = {
+       .carrier_raised = scc_carrier_raised,
+};
+
 /*----------------------------------------------------------------------------
  * vme_scc_init() and support functions
  *---------------------------------------------------------------------------*/
 
-static int scc_init_drivers(void)
+static int __init scc_init_drivers(void)
 {
        int error;
 
@@ -169,13 +171,15 @@ static int scc_init_drivers(void)
 /* ports[] array is indexed by line no (i.e. [0] for ttyS0, [1] for ttyS1).
  */
 
-static void scc_init_portstructs(void)
+static void __init scc_init_portstructs(void)
 {
        struct scc_port *port;
        int i;
 
        for (i = 0; i < 2; i++) {
                port = scc_ports + i;
+               tty_port_init(&port->gs.port);
+               port->gs.port.ops = &scc_port_ops;
                port->gs.magic = SCC_MAGIC;
                port->gs.close_delay = HZ/2;
                port->gs.closing_wait = 30 * HZ;
@@ -190,9 +194,10 @@ static void scc_init_portstructs(void)
 
 
 #ifdef CONFIG_MVME147_SCC
-static int mvme147_scc_init(void)
+static int __init mvme147_scc_init(void)
 {
        struct scc_port *port;
+       int error;
 
        printk(KERN_INFO "SCC: MVME147 Serial Driver\n");
        /* Init channel A */
@@ -202,14 +207,23 @@ static int mvme147_scc_init(void)
        port->datap = port->ctrlp + 1;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(MVME147_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-A TX", port);
-       request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail;
+       error = request_irq(MVME147_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-A status", port);
-       request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_tx;
+       error = request_irq(MVME147_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-A RX", port);
-       request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_stat;
+       error = request_irq(MVME147_IRQ_SCCA_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_rx;
+
        {
                SCC_ACCESS_INIT(port);
 
@@ -229,14 +243,23 @@ static int mvme147_scc_init(void)
        port->datap = port->ctrlp + 1;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(MVME147_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-B TX", port);
-       request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_spcond;
+       error = request_irq(MVME147_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-B status", port);
-       request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_b_tx;
+       error = request_irq(MVME147_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-B RX", port);
-       request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_stat;
+       error = request_irq(MVME147_IRQ_SCCB_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_rx;
+
        {
                SCC_ACCESS_INIT(port);
 
@@ -252,14 +275,32 @@ static int mvme147_scc_init(void)
        scc_init_drivers();
 
        return 0;
+
+fail_free_b_rx:
+       free_irq(MVME147_IRQ_SCCB_RX, port);
+fail_free_b_stat:
+       free_irq(MVME147_IRQ_SCCB_STAT, port);
+fail_free_b_tx:
+       free_irq(MVME147_IRQ_SCCB_TX, port);
+fail_free_a_spcond:
+       free_irq(MVME147_IRQ_SCCA_SPCOND, port);
+fail_free_a_rx:
+       free_irq(MVME147_IRQ_SCCA_RX, port);
+fail_free_a_stat:
+       free_irq(MVME147_IRQ_SCCA_STAT, port);
+fail_free_a_tx:
+       free_irq(MVME147_IRQ_SCCA_TX, port);
+fail:
+       return error;
 }
 #endif
 
 
 #ifdef CONFIG_MVME162_SCC
-static int mvme162_scc_init(void)
+static int __init mvme162_scc_init(void)
 {
        struct scc_port *port;
+       int error;
 
        if (!(mvme16x_config & MVME16x_CONFIG_GOT_SCCA))
                return (-ENODEV);
@@ -272,14 +313,23 @@ static int mvme162_scc_init(void)
        port->datap = port->ctrlp + 2;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(MVME162_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-A TX", port);
-       request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail;
+       error = request_irq(MVME162_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-A status", port);
-       request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_tx;
+       error = request_irq(MVME162_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-A RX", port);
-       request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_stat;
+       error = request_irq(MVME162_IRQ_SCCA_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_rx;
+
        {
                SCC_ACCESS_INIT(port);
 
@@ -299,14 +349,22 @@ static int mvme162_scc_init(void)
        port->datap = port->ctrlp + 2;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(MVME162_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-B TX", port);
-       request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_spcond;
+       error = request_irq(MVME162_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-B status", port);
-       request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_b_tx;
+       error = request_irq(MVME162_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-B RX", port);
-       request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_stat;
+       error = request_irq(MVME162_IRQ_SCCB_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_rx;
 
        {
                SCC_ACCESS_INIT(port);  /* Either channel will do */
@@ -323,14 +381,32 @@ static int mvme162_scc_init(void)
        scc_init_drivers();
 
        return 0;
+
+fail_free_b_rx:
+       free_irq(MVME162_IRQ_SCCB_RX, port);
+fail_free_b_stat:
+       free_irq(MVME162_IRQ_SCCB_STAT, port);
+fail_free_b_tx:
+       free_irq(MVME162_IRQ_SCCB_TX, port);
+fail_free_a_spcond:
+       free_irq(MVME162_IRQ_SCCA_SPCOND, port);
+fail_free_a_rx:
+       free_irq(MVME162_IRQ_SCCA_RX, port);
+fail_free_a_stat:
+       free_irq(MVME162_IRQ_SCCA_STAT, port);
+fail_free_a_tx:
+       free_irq(MVME162_IRQ_SCCA_TX, port);
+fail:
+       return error;
 }
 #endif
 
 
 #ifdef CONFIG_BVME6000_SCC
-static int bvme6000_scc_init(void)
+static int __init bvme6000_scc_init(void)
 {
        struct scc_port *port;
+       int error;
 
        printk(KERN_INFO "SCC: BVME6000 Serial Driver\n");
        /* Init channel A */
@@ -340,14 +416,23 @@ static int bvme6000_scc_init(void)
        port->datap = port->ctrlp + 4;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(BVME_IRQ_SCCA_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-A TX", port);
-       request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail;
+       error = request_irq(BVME_IRQ_SCCA_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-A status", port);
-       request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_tx;
+       error = request_irq(BVME_IRQ_SCCA_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-A RX", port);
-       request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_stat;
+       error = request_irq(BVME_IRQ_SCCA_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-A special cond", port);
+       if (error)
+               goto fail_free_a_rx;
+
        {
                SCC_ACCESS_INIT(port);
 
@@ -367,14 +452,22 @@ static int bvme6000_scc_init(void)
        port->datap = port->ctrlp + 4;
        port->port_a = &scc_ports[0];
        port->port_b = &scc_ports[1];
-       request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
+       error = request_irq(BVME_IRQ_SCCB_TX, scc_tx_int, IRQF_DISABLED,
                            "SCC-B TX", port);
-       request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_a_spcond;
+       error = request_irq(BVME_IRQ_SCCB_STAT, scc_stat_int, IRQF_DISABLED,
                            "SCC-B status", port);
-       request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
+       if (error)
+               goto fail_free_b_tx;
+       error = request_irq(BVME_IRQ_SCCB_RX, scc_rx_int, IRQF_DISABLED,
                            "SCC-B RX", port);
-       request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int, IRQF_DISABLED,
-                           "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_stat;
+       error = request_irq(BVME_IRQ_SCCB_SPCOND, scc_spcond_int,
+                           IRQF_DISABLED, "SCC-B special cond", port);
+       if (error)
+               goto fail_free_b_rx;
 
        {
                SCC_ACCESS_INIT(port);  /* Either channel will do */
@@ -388,11 +481,28 @@ static int bvme6000_scc_init(void)
        scc_init_drivers();
 
        return 0;
+
+fail:
+       free_irq(BVME_IRQ_SCCA_STAT, port);
+fail_free_a_tx:
+       free_irq(BVME_IRQ_SCCA_RX, port);
+fail_free_a_stat:
+       free_irq(BVME_IRQ_SCCA_SPCOND, port);
+fail_free_a_rx:
+       free_irq(BVME_IRQ_SCCB_TX, port);
+fail_free_a_spcond:
+       free_irq(BVME_IRQ_SCCB_STAT, port);
+fail_free_b_tx:
+       free_irq(BVME_IRQ_SCCB_RX, port);
+fail_free_b_stat:
+       free_irq(BVME_IRQ_SCCB_SPCOND, port);
+fail_free_b_rx:
+       return error;
 }
 #endif
 
 
-static int vme_scc_init(void)
+static int __init vme_scc_init(void)
 {
        int res = -ENODEV;
 
@@ -624,10 +734,10 @@ static void scc_enable_rx_interrupts(void *ptr)
 }
 
 
-static int scc_get_CD(void *ptr)
+static int scc_carrier_raised(struct tty_port *port)
 {
-       struct scc_port *port = ptr;
-       unsigned channel = port->channel;
+       struct scc_port *sc = container_of(port, struct scc_port, gs.port);
+       unsigned channel = sc->channel;
 
        return !!(scc_last_status_reg[channel] & SR_DCD);
 }
@@ -638,7 +748,7 @@ static void scc_shutdown_port(void *ptr)
        struct scc_port *port = ptr;
 
        port->gs.port.flags &= ~ GS_ACTIVE;
-       if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) {
+       if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) {
                scc_setsignals (port, 0, 0);
        }
 }
@@ -779,7 +889,7 @@ static void scc_setsignals(struct scc_port *port, int dtr, int rts)
 
 static void scc_send_xchar(struct tty_struct *tty, char ch)
 {
-       struct scc_port *port = (struct scc_port *)tty->driver_data;
+       struct scc_port *port = tty->driver_data;
 
        port->x_char = ch;
        if (ch)
@@ -896,7 +1006,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp)
                return retval;
        }
 
-       port->c_dcd = scc_get_CD (port);
+       port->c_dcd = tty_port_carrier_raised(&port->gs.port);
 
        scc_enable_rx_interrupts(port);
 
@@ -906,7 +1016,7 @@ static int scc_open (struct tty_struct * tty, struct file * filp)
 
 static void scc_throttle (struct tty_struct * tty)
 {
-       struct scc_port *port = (struct scc_port *)tty->driver_data;
+       struct scc_port *port = tty->driver_data;
        unsigned long   flags;
        SCC_ACCESS_INIT(port);
 
@@ -922,7 +1032,7 @@ static void scc_throttle (struct tty_struct * tty)
 
 static void scc_unthrottle (struct tty_struct * tty)
 {
-       struct scc_port *port = (struct scc_port *)tty->driver_data;
+       struct scc_port *port = tty->driver_data;
        unsigned long   flags;
        SCC_ACCESS_INIT(port);
 
@@ -945,7 +1055,7 @@ static int scc_ioctl(struct tty_struct *tty, struct file *file,
 
 static int scc_break_ctl(struct tty_struct *tty, int break_state)
 {
-       struct scc_port *port = (struct scc_port *)tty->driver_data;
+       struct scc_port *port = tty->driver_data;
        unsigned long   flags;
        SCC_ACCESS_INIT(port);