diff options
author | Jiri Slaby <jslaby@suse.cz> | 2012-04-02 07:54:47 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-09 15:04:30 -0400 |
commit | 266e37efbc28b051c1ffb1cdcf0a949973e660e3 (patch) | |
tree | 97841d29424eb6dd25da72a85b12a63792c3c371 /drivers/usb | |
parent | 8e32841634958d4927a85b484faf9d2c3c222e4d (diff) |
TTY: usb/u_serial, add tty_port
And use count from there.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/gadget/u_serial.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c index 6c23938d2711..a6212ff5a2e5 100644 --- a/drivers/usb/gadget/u_serial.c +++ b/drivers/usb/gadget/u_serial.c | |||
@@ -94,12 +94,12 @@ struct gs_buf { | |||
94 | * (and thus for each /dev/ node). | 94 | * (and thus for each /dev/ node). |
95 | */ | 95 | */ |
96 | struct gs_port { | 96 | struct gs_port { |
97 | struct tty_port port; | ||
97 | spinlock_t port_lock; /* guard port_* access */ | 98 | spinlock_t port_lock; /* guard port_* access */ |
98 | 99 | ||
99 | struct gserial *port_usb; | 100 | struct gserial *port_usb; |
100 | struct tty_struct *port_tty; | 101 | struct tty_struct *port_tty; |
101 | 102 | ||
102 | unsigned open_count; | ||
103 | bool openclose; /* open/close in progress */ | 103 | bool openclose; /* open/close in progress */ |
104 | u8 port_num; | 104 | u8 port_num; |
105 | 105 | ||
@@ -734,9 +734,9 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
734 | spin_lock_irq(&port->port_lock); | 734 | spin_lock_irq(&port->port_lock); |
735 | 735 | ||
736 | /* already open? Great. */ | 736 | /* already open? Great. */ |
737 | if (port->open_count) { | 737 | if (port->port.count) { |
738 | status = 0; | 738 | status = 0; |
739 | port->open_count++; | 739 | port->port.count++; |
740 | 740 | ||
741 | /* currently opening/closing? wait ... */ | 741 | /* currently opening/closing? wait ... */ |
742 | } else if (port->openclose) { | 742 | } else if (port->openclose) { |
@@ -795,7 +795,7 @@ static int gs_open(struct tty_struct *tty, struct file *file) | |||
795 | tty->driver_data = port; | 795 | tty->driver_data = port; |
796 | port->port_tty = tty; | 796 | port->port_tty = tty; |
797 | 797 | ||
798 | port->open_count = 1; | 798 | port->port.count = 1; |
799 | port->openclose = false; | 799 | port->openclose = false; |
800 | 800 | ||
801 | /* if connected, start the I/O stream */ | 801 | /* if connected, start the I/O stream */ |
@@ -837,11 +837,11 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
837 | 837 | ||
838 | spin_lock_irq(&port->port_lock); | 838 | spin_lock_irq(&port->port_lock); |
839 | 839 | ||
840 | if (port->open_count != 1) { | 840 | if (port->port.count != 1) { |
841 | if (port->open_count == 0) | 841 | if (port->port.count == 0) |
842 | WARN_ON(1); | 842 | WARN_ON(1); |
843 | else | 843 | else |
844 | --port->open_count; | 844 | --port->port.count; |
845 | goto exit; | 845 | goto exit; |
846 | } | 846 | } |
847 | 847 | ||
@@ -851,7 +851,7 @@ static void gs_close(struct tty_struct *tty, struct file *file) | |||
851 | * and sleep if necessary | 851 | * and sleep if necessary |
852 | */ | 852 | */ |
853 | port->openclose = true; | 853 | port->openclose = true; |
854 | port->open_count = 0; | 854 | port->port.count = 0; |
855 | 855 | ||
856 | gser = port->port_usb; | 856 | gser = port->port_usb; |
857 | if (gser && gser->disconnect) | 857 | if (gser && gser->disconnect) |
@@ -1034,6 +1034,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding) | |||
1034 | if (port == NULL) | 1034 | if (port == NULL) |
1035 | return -ENOMEM; | 1035 | return -ENOMEM; |
1036 | 1036 | ||
1037 | tty_port_init(&port->port); | ||
1037 | spin_lock_init(&port->port_lock); | 1038 | spin_lock_init(&port->port_lock); |
1038 | init_waitqueue_head(&port->close_wait); | 1039 | init_waitqueue_head(&port->close_wait); |
1039 | init_waitqueue_head(&port->drain_wait); | 1040 | init_waitqueue_head(&port->drain_wait); |
@@ -1155,7 +1156,7 @@ static int gs_closed(struct gs_port *port) | |||
1155 | int cond; | 1156 | int cond; |
1156 | 1157 | ||
1157 | spin_lock_irq(&port->port_lock); | 1158 | spin_lock_irq(&port->port_lock); |
1158 | cond = (port->open_count == 0) && !port->openclose; | 1159 | cond = (port->port.count == 0) && !port->openclose; |
1159 | spin_unlock_irq(&port->port_lock); | 1160 | spin_unlock_irq(&port->port_lock); |
1160 | return cond; | 1161 | return cond; |
1161 | } | 1162 | } |
@@ -1268,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num) | |||
1268 | /* if it's already open, start I/O ... and notify the serial | 1269 | /* if it's already open, start I/O ... and notify the serial |
1269 | * protocol about open/close status (connect/disconnect). | 1270 | * protocol about open/close status (connect/disconnect). |
1270 | */ | 1271 | */ |
1271 | if (port->open_count) { | 1272 | if (port->port.count) { |
1272 | pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); | 1273 | pr_debug("gserial_connect: start ttyGS%d\n", port->port_num); |
1273 | gs_start_io(port); | 1274 | gs_start_io(port); |
1274 | if (gser->connect) | 1275 | if (gser->connect) |
@@ -1315,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser) | |||
1315 | 1316 | ||
1316 | port->port_usb = NULL; | 1317 | port->port_usb = NULL; |
1317 | gser->ioport = NULL; | 1318 | gser->ioport = NULL; |
1318 | if (port->open_count > 0 || port->openclose) { | 1319 | if (port->port.count > 0 || port->openclose) { |
1319 | wake_up_interruptible(&port->drain_wait); | 1320 | wake_up_interruptible(&port->drain_wait); |
1320 | if (port->port_tty) | 1321 | if (port->port_tty) |
1321 | tty_hangup(port->port_tty); | 1322 | tty_hangup(port->port_tty); |
@@ -1331,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser) | |||
1331 | 1332 | ||
1332 | /* finally, free any unused/unusable I/O buffers */ | 1333 | /* finally, free any unused/unusable I/O buffers */ |
1333 | spin_lock_irqsave(&port->port_lock, flags); | 1334 | spin_lock_irqsave(&port->port_lock, flags); |
1334 | if (port->open_count == 0 && !port->openclose) | 1335 | if (port->port.count == 0 && !port->openclose) |
1335 | gs_buf_free(&port->port_write_buf); | 1336 | gs_buf_free(&port->port_write_buf); |
1336 | gs_free_requests(gser->out, &port->read_pool, NULL); | 1337 | gs_free_requests(gser->out, &port->read_pool, NULL); |
1337 | gs_free_requests(gser->out, &port->read_queue, NULL); | 1338 | gs_free_requests(gser->out, &port->read_queue, NULL); |