diff options
author | Alan Cox <alan@redhat.com> | 2009-01-02 08:46:10 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-01-02 13:19:39 -0500 |
commit | 36c621d82b956ff6ff72273f848af53e6c581aba (patch) | |
tree | edd387d8275a8f25277d264ffed94e8d1c2ba048 /drivers/char/riscom8.c | |
parent | 3b6826b250633361f08a6427a4ac0035e5d88c72 (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/riscom8.c')
-rw-r--r-- | drivers/char/riscom8.c | 86 |
1 files changed, 1 insertions, 85 deletions
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c index 14662d7aa628..af34c2054a09 100644 --- a/drivers/char/riscom8.c +++ b/drivers/char/riscom8.c | |||
@@ -874,90 +874,6 @@ static int carrier_raised(struct tty_port *port) | |||
874 | return CD; | 874 | return CD; |
875 | } | 875 | } |
876 | 876 | ||
877 | static int block_til_ready(struct tty_struct *tty, struct file *filp, | ||
878 | struct riscom_port *rp) | ||
879 | { | ||
880 | DECLARE_WAITQUEUE(wait, current); | ||
881 | int retval; | ||
882 | int do_clocal = 0; | ||
883 | int CD; | ||
884 | unsigned long flags; | ||
885 | struct tty_port *port = &rp->port; | ||
886 | |||
887 | /* | ||
888 | * If the device is in the middle of being closed, then block | ||
889 | * until it's done, and then try again. | ||
890 | */ | ||
891 | if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { | ||
892 | interruptible_sleep_on(&port->close_wait); | ||
893 | if (port->flags & ASYNC_HUP_NOTIFY) | ||
894 | return -EAGAIN; | ||
895 | else | ||
896 | return -ERESTARTSYS; | ||
897 | } | ||
898 | |||
899 | /* | ||
900 | * If non-blocking mode is set, or the port is not enabled, | ||
901 | * then make the check up front and then exit. | ||
902 | */ | ||
903 | if ((filp->f_flags & O_NONBLOCK) || | ||
904 | (tty->flags & (1 << TTY_IO_ERROR))) { | ||
905 | port->flags |= ASYNC_NORMAL_ACTIVE; | ||
906 | return 0; | ||
907 | } | ||
908 | |||
909 | if (C_CLOCAL(tty)) | ||
910 | do_clocal = 1; | ||
911 | |||
912 | /* | ||
913 | * Block waiting for the carrier detect and the line to become | ||
914 | * free (i.e., not in use by the callout). While we are in | ||
915 | * this loop, info->count is dropped by one, so that | ||
916 | * rs_close() knows when to free things. We restore it upon | ||
917 | * exit, either normal or abnormal. | ||
918 | */ | ||
919 | retval = 0; | ||
920 | add_wait_queue(&port->open_wait, &wait); | ||
921 | |||
922 | spin_lock_irqsave(&port->lock, flags); | ||
923 | if (!tty_hung_up_p(filp)) | ||
924 | port->count--; | ||
925 | port->blocked_open++; | ||
926 | spin_unlock_irqrestore(&port->lock, flags); | ||
927 | |||
928 | while (1) { | ||
929 | |||
930 | CD = tty_port_carrier_raised(port); | ||
931 | set_current_state(TASK_INTERRUPTIBLE); | ||
932 | if (tty_hung_up_p(filp) || | ||
933 | !(port->flags & ASYNC_INITIALIZED)) { | ||
934 | if (port->flags & ASYNC_HUP_NOTIFY) | ||
935 | retval = -EAGAIN; | ||
936 | else | ||
937 | retval = -ERESTARTSYS; | ||
938 | break; | ||
939 | } | ||
940 | if (!(port->flags & ASYNC_CLOSING) && | ||
941 | (do_clocal || CD)) | ||
942 | break; | ||
943 | if (signal_pending(current)) { | ||
944 | retval = -ERESTARTSYS; | ||
945 | break; | ||
946 | } | ||
947 | schedule(); | ||
948 | } | ||
949 | __set_current_state(TASK_RUNNING); | ||
950 | remove_wait_queue(&port->open_wait, &wait); | ||
951 | spin_lock_irqsave(&port->lock, flags); | ||
952 | if (!tty_hung_up_p(filp)) | ||
953 | port->count++; | ||
954 | port->blocked_open--; | ||
955 | if (retval == 0) | ||
956 | port->flags |= ASYNC_NORMAL_ACTIVE; | ||
957 | spin_unlock_irqrestore(&port->lock, flags); | ||
958 | return 0; | ||
959 | } | ||
960 | |||
961 | static int rc_open(struct tty_struct *tty, struct file *filp) | 877 | static int rc_open(struct tty_struct *tty, struct file *filp) |
962 | { | 878 | { |
963 | int board; | 879 | int board; |
@@ -984,7 +900,7 @@ static int rc_open(struct tty_struct *tty, struct file *filp) | |||
984 | 900 | ||
985 | error = rc_setup_port(bp, port); | 901 | error = rc_setup_port(bp, port); |
986 | if (error == 0) | 902 | if (error == 0) |
987 | error = block_til_ready(tty, filp, port); | 903 | error = tty_port_block_til_ready(&port->port, tty, filp); |
988 | return error; | 904 | return error; |
989 | } | 905 | } |
990 | 906 | ||