serial: move port users helper
[pandora-kernel.git] / drivers / serial / serial_core.c
index 9d42e57..3c45a8d 100644 (file)
@@ -52,8 +52,6 @@ static struct lock_class_key port_lock_key;
 
 #define HIGH_BITS_OFFSET       ((sizeof(long)-sizeof(int))*8)
 
-#define uart_users(state)      ((state)->port.count + (state)->port.blocked_open)
-
 #ifdef CONFIG_SERIAL_CORE_CONSOLE
 #define uart_console(port)     ((port)->cons && (port)->cons->index == (port)->line)
 #else
@@ -215,7 +213,8 @@ static int uart_startup(struct uart_state *state, int init_hw)
 static void uart_shutdown(struct uart_state *state)
 {
        struct uart_port *uport = state->uart_port;
-       struct tty_struct *tty = state->port.tty;
+       struct tty_port *port = &state->port;
+       struct tty_struct *tty = port->tty;
 
        /*
         * Set the TTY IO error marker
@@ -223,7 +222,7 @@ static void uart_shutdown(struct uart_state *state)
        if (tty)
                set_bit(TTY_IO_ERROR, &tty->flags);
 
-       if (test_and_clear_bit(ASYNCB_INITIALIZED, &state->port.flags)) {
+       if (test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) {
                /*
                 * Turn off DTR and RTS early.
                 */
@@ -237,7 +236,7 @@ static void uart_shutdown(struct uart_state *state)
                 * any outstanding file descriptors should be pointing at
                 * hung_up_tty_fops now.
                 */
-               wake_up_interruptible(&state->delta_msr_wait);
+               wake_up_interruptible(&port->delta_msr_wait);
 
                /*
                 * Free the IRQ and disable the port.
@@ -757,7 +756,7 @@ static int uart_set_info(struct uart_state *state,
                /*
                 * Make sure that we are the sole user of this port.
                 */
-               if (uart_users(state) > 1)
+               if (tty_port_users(port) > 1)
                        goto exit;
 
                /*
@@ -973,7 +972,7 @@ static int uart_do_autoconfig(struct uart_state *state)
                return -ERESTARTSYS;
 
        ret = -EBUSY;
-       if (uart_users(state) == 1) {
+       if (tty_port_users(port) == 1) {
                uart_shutdown(state);
 
                /*
@@ -1004,11 +1003,15 @@ static int uart_do_autoconfig(struct uart_state *state)
  * - mask passed in arg for lines of interest
  *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  * Caller should use TIOCGICOUNT to see which one it was
+ *
+ * FIXME: This wants extracting into a common all driver implementation
+ * of TIOCMWAIT using tty_port.
  */
 static int
 uart_wait_modem_status(struct uart_state *state, unsigned long arg)
 {
        struct uart_port *uport = state->uart_port;
+       struct tty_port *port = &state->port;
        DECLARE_WAITQUEUE(wait, current);
        struct uart_icount cprev, cnow;
        int ret;
@@ -1025,7 +1028,7 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
        uport->ops->enable_ms(uport);
        spin_unlock_irq(&uport->lock);
 
-       add_wait_queue(&state->delta_msr_wait, &wait);
+       add_wait_queue(&port->delta_msr_wait, &wait);
        for (;;) {
                spin_lock_irq(&uport->lock);
                memcpy(&cnow, &uport->icount, sizeof(struct uart_icount));
@@ -1053,7 +1056,7 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
        }
 
        current->state = TASK_RUNNING;
-       remove_wait_queue(&state->delta_msr_wait, &wait);
+       remove_wait_queue(&port->delta_msr_wait, &wait);
 
        return ret;
 }
@@ -1430,7 +1433,7 @@ static void uart_hangup(struct tty_struct *tty)
                clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
                port->tty = NULL;
                wake_up_interruptible(&port->open_wait);
-               wake_up_interruptible(&state->delta_msr_wait);
+               wake_up_interruptible(&port->delta_msr_wait);
        }
        mutex_unlock(&port->mutex);
 }
@@ -2378,7 +2381,6 @@ int uart_register_driver(struct uart_driver *drv)
                tty_port_init(port);
                port->close_delay     = 500;    /* .5 seconds */
                port->closing_wait    = 30000;  /* 30 seconds */
-               init_waitqueue_head(&state->delta_msr_wait);
                tasklet_init(&state->tlet, uart_tasklet_action,
                             (unsigned long)state);
        }