aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/mxser.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2009-01-02 08:46:10 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-01-02 13:19:39 -0500
commit36c621d82b956ff6ff72273f848af53e6c581aba (patch)
treeedd387d8275a8f25277d264ffed94e8d1c2ba048 /drivers/char/mxser.c
parent3b6826b250633361f08a6427a4ac0035e5d88c72 (diff)
tty: Introduce a tty_port generic block_til_ready
Start sucking more commonality out of the drivers into a single piece of core code. Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char/mxser.c')
-rw-r--r--drivers/char/mxser.c71
1 files changed, 1 insertions, 70 deletions
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index e2471cf1ee95..08ba6eb1a380 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -558,75 +558,6 @@ static void mxser_raise_dtr_rts(struct tty_port *port)
558 spin_unlock_irqrestore(&mp->slock, flags); 558 spin_unlock_irqrestore(&mp->slock, flags);
559} 559}
560 560
561static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
562 struct mxser_port *mp)
563{
564 DECLARE_WAITQUEUE(wait, current);
565 int retval;
566 int do_clocal = 0;
567 unsigned long flags;
568 int cd;
569 struct tty_port *port = &mp->port;
570
571 /*
572 * If non-blocking mode is set, or the port is not enabled,
573 * then make the check up front and then exit.
574 */
575 if ((filp->f_flags & O_NONBLOCK) ||
576 test_bit(TTY_IO_ERROR, &tty->flags)) {
577 port->flags |= ASYNC_NORMAL_ACTIVE;
578 return 0;
579 }
580
581 if (tty->termios->c_cflag & CLOCAL)
582 do_clocal = 1;
583
584 /*
585 * Block waiting for the carrier detect and the line to become
586 * free (i.e., not in use by the callout). While we are in
587 * this loop, port->count is dropped by one, so that
588 * mxser_close() knows when to free things. We restore it upon
589 * exit, either normal or abnormal.
590 */
591 retval = 0;
592 add_wait_queue(&port->open_wait, &wait);
593
594 spin_lock_irqsave(&port->lock, flags);
595 if (!tty_hung_up_p(filp))
596 port->count--;
597 port->blocked_open++;
598 spin_unlock_irqrestore(&port->lock, flags);
599 while (1) {
600 tty_port_raise_dtr_rts(port);
601 set_current_state(TASK_INTERRUPTIBLE);
602 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
603 if (port->flags & ASYNC_HUP_NOTIFY)
604 retval = -EAGAIN;
605 else
606 retval = -ERESTARTSYS;
607 break;
608 }
609 cd = tty_port_carrier_raised(port);
610 if (!(port->flags & ASYNC_CLOSING) && (do_clocal || cd))
611 break;
612 if (signal_pending(current)) {
613 retval = -ERESTARTSYS;
614 break;
615 }
616 schedule();
617 }
618 set_current_state(TASK_RUNNING);
619 remove_wait_queue(&port->open_wait, &wait);
620 spin_lock_irqsave(&port->lock, flags);
621 if (!tty_hung_up_p(filp))
622 port->count++;
623 port->blocked_open--;
624 if (retval == 0)
625 port->flags |= ASYNC_NORMAL_ACTIVE;
626 spin_unlock_irqrestore(&port->lock, flags);
627 return 0;
628}
629
630static int mxser_set_baud(struct tty_struct *tty, long newspd) 561static int mxser_set_baud(struct tty_struct *tty, long newspd)
631{ 562{
632 struct mxser_port *info = tty->driver_data; 563 struct mxser_port *info = tty->driver_data;
@@ -1110,7 +1041,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1110 if (retval) 1041 if (retval)
1111 return retval; 1042 return retval;
1112 1043
1113 retval = mxser_block_til_ready(tty, filp, info); 1044 retval = tty_port_block_til_ready(&info->port, tty, filp);
1114 if (retval) 1045 if (retval)
1115 return retval; 1046 return retval;
1116 1047