diff options
author | Alan Cox <alan@linux.intel.com> | 2010-06-02 00:52:58 +0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-08-11 00:47:42 +0400 |
commit | de0c8cb314cc737c47a00de33cd6246accf94192 (patch) | |
tree | 95982a824b1ade10d5c9db21f122d7d56a04872e /drivers | |
parent | 61cd8a21d8a9fb4b11111270cf2d3aa919c20624 (diff) | |
download | linux-de0c8cb314cc737c47a00de33cd6246accf94192.tar.xz |
serial: add port helpers
We can make this the same as the ones that will be needed by the tty_port
helper logic that we want to move to but still call them from the existing
code base.
Signed-off-by: Alan Cox <alan@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/serial/serial_core.c | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c index 424b1c7e50c4..2379045e0871 100644 --- a/drivers/serial/serial_core.c +++ b/drivers/serial/serial_core.c @@ -1501,6 +1501,34 @@ static void uart_update_termios(struct tty_struct *tty, } } +static int uart_carrier_raised(struct tty_port *port) +{ + struct uart_state *state = container_of(port, struct uart_state, port); + struct uart_port *uport = state->uart_port; + int mctrl; + mutex_lock(&port->mutex); + spin_lock_irq(&uport->lock); + uport->ops->enable_ms(uport); + mctrl = uport->ops->get_mctrl(uport); + spin_unlock_irq(&uport->lock); + mutex_unlock(&port->mutex); + if (mctrl & TIOCM_CAR) + return 1; + return 0; +} + +static void uart_dtr_rts(struct tty_port *port, int onoff) +{ + struct uart_state *state = container_of(port, struct uart_state, port); + struct uart_port *uport = state->uart_port; + mutex_lock(&port->mutex); + if (onoff) + uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS); + else + uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS); + mutex_unlock(&port->mutex); +} + /* * Block the open until the port is ready. We must be called with * the per-port semaphore held. @@ -1509,9 +1537,7 @@ static int uart_block_til_ready(struct file *filp, struct uart_state *state) { DECLARE_WAITQUEUE(wait, current); - struct uart_port *uport = state->uart_port; struct tty_port *port = &state->port; - unsigned int mctrl; unsigned long flags; spin_lock_irqsave(&port->lock, flags); @@ -1555,23 +1581,14 @@ uart_block_til_ready(struct file *filp, struct uart_state *state) * not set RTS here - we want to make sure we catch * the data from the modem. */ - if (port->tty->termios->c_cflag & CBAUD) { - mutex_lock(&port->mutex); - uart_set_mctrl(uport, TIOCM_DTR); - mutex_unlock(&port->mutex); - } + if (port->tty->termios->c_cflag & CBAUD) + tty_port_raise_dtr_rts(port); /* * and wait for the carrier to indicate that the * modem is ready for us. */ - mutex_lock(&port->mutex); - spin_lock_irq(&uport->lock); - uport->ops->enable_ms(uport); - mctrl = uport->ops->get_mctrl(uport); - spin_unlock_irq(&uport->lock); - mutex_unlock(&port->mutex); - if (mctrl & TIOCM_CAR) + if (tty_port_carrier_raised(port)) break; schedule(); @@ -2349,6 +2366,11 @@ static const struct tty_operations uart_ops = { #endif }; +static const struct tty_port_operations uart_port_ops = { + .carrier_raised = uart_carrier_raised, + .dtr_rts = uart_dtr_rts, +}; + /** * uart_register_driver - register a driver with the uart core layer * @drv: low level driver structure @@ -2405,6 +2427,7 @@ int uart_register_driver(struct uart_driver *drv) struct tty_port *port = &state->port; tty_port_init(port); + port->ops = &uart_port_ops; port->close_delay = 500; /* .5 seconds */ port->closing_wait = 30000; /* 30 seconds */ tasklet_init(&state->tlet, uart_tasklet_action, |