aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@linux.intel.com>2010-06-01 16:52:58 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-10 16:47:42 -0400
commitde0c8cb314cc737c47a00de33cd6246accf94192 (patch)
tree95982a824b1ade10d5c9db21f122d7d56a04872e /drivers/serial
parent61cd8a21d8a9fb4b11111270cf2d3aa919c20624 (diff)
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/serial')
-rw-r--r--drivers/serial/serial_core.c51
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,
1501 } 1501 }
1502} 1502}
1503 1503
1504static int uart_carrier_raised(struct tty_port *port)
1505{
1506 struct uart_state *state = container_of(port, struct uart_state, port);
1507 struct uart_port *uport = state->uart_port;
1508 int mctrl;
1509 mutex_lock(&port->mutex);
1510 spin_lock_irq(&uport->lock);
1511 uport->ops->enable_ms(uport);
1512 mctrl = uport->ops->get_mctrl(uport);
1513 spin_unlock_irq(&uport->lock);
1514 mutex_unlock(&port->mutex);
1515 if (mctrl & TIOCM_CAR)
1516 return 1;
1517 return 0;
1518}
1519
1520static void uart_dtr_rts(struct tty_port *port, int onoff)
1521{
1522 struct uart_state *state = container_of(port, struct uart_state, port);
1523 struct uart_port *uport = state->uart_port;
1524 mutex_lock(&port->mutex);
1525 if (onoff)
1526 uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
1527 else
1528 uart_clear_mctrl(uport, TIOCM_DTR | TIOCM_RTS);
1529 mutex_unlock(&port->mutex);
1530}
1531
1504/* 1532/*
1505 * Block the open until the port is ready. We must be called with 1533 * Block the open until the port is ready. We must be called with
1506 * the per-port semaphore held. 1534 * the per-port semaphore held.
@@ -1509,9 +1537,7 @@ static int
1509uart_block_til_ready(struct file *filp, struct uart_state *state) 1537uart_block_til_ready(struct file *filp, struct uart_state *state)
1510{ 1538{
1511 DECLARE_WAITQUEUE(wait, current); 1539 DECLARE_WAITQUEUE(wait, current);
1512 struct uart_port *uport = state->uart_port;
1513 struct tty_port *port = &state->port; 1540 struct tty_port *port = &state->port;
1514 unsigned int mctrl;
1515 unsigned long flags; 1541 unsigned long flags;
1516 1542
1517 spin_lock_irqsave(&port->lock, flags); 1543 spin_lock_irqsave(&port->lock, flags);
@@ -1555,23 +1581,14 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
1555 * not set RTS here - we want to make sure we catch 1581 * not set RTS here - we want to make sure we catch
1556 * the data from the modem. 1582 * the data from the modem.
1557 */ 1583 */
1558 if (port->tty->termios->c_cflag & CBAUD) { 1584 if (port->tty->termios->c_cflag & CBAUD)
1559 mutex_lock(&port->mutex); 1585 tty_port_raise_dtr_rts(port);
1560 uart_set_mctrl(uport, TIOCM_DTR);
1561 mutex_unlock(&port->mutex);
1562 }
1563 1586
1564 /* 1587 /*
1565 * and wait for the carrier to indicate that the 1588 * and wait for the carrier to indicate that the
1566 * modem is ready for us. 1589 * modem is ready for us.
1567 */ 1590 */
1568 mutex_lock(&port->mutex); 1591 if (tty_port_carrier_raised(port))
1569 spin_lock_irq(&uport->lock);
1570 uport->ops->enable_ms(uport);
1571 mctrl = uport->ops->get_mctrl(uport);
1572 spin_unlock_irq(&uport->lock);
1573 mutex_unlock(&port->mutex);
1574 if (mctrl & TIOCM_CAR)
1575 break; 1592 break;
1576 1593
1577 schedule(); 1594 schedule();
@@ -2349,6 +2366,11 @@ static const struct tty_operations uart_ops = {
2349#endif 2366#endif
2350}; 2367};
2351 2368
2369static const struct tty_port_operations uart_port_ops = {
2370 .carrier_raised = uart_carrier_raised,
2371 .dtr_rts = uart_dtr_rts,
2372};
2373
2352/** 2374/**
2353 * uart_register_driver - register a driver with the uart core layer 2375 * uart_register_driver - register a driver with the uart core layer
2354 * @drv: low level driver structure 2376 * @drv: low level driver structure
@@ -2405,6 +2427,7 @@ int uart_register_driver(struct uart_driver *drv)
2405 struct tty_port *port = &state->port; 2427 struct tty_port *port = &state->port;
2406 2428
2407 tty_port_init(port); 2429 tty_port_init(port);
2430 port->ops = &uart_port_ops;
2408 port->close_delay = 500; /* .5 seconds */ 2431 port->close_delay = 500; /* .5 seconds */
2409 port->closing_wait = 30000; /* 30 seconds */ 2432 port->closing_wait = 30000; /* 30 seconds */
2410 tasklet_init(&state->tlet, uart_tasklet_action, 2433 tasklet_init(&state->tlet, uart_tasklet_action,