diff options
author | Alan Cox <alan@redhat.com> | 2008-07-22 06:11:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-22 16:03:24 -0400 |
commit | ae64387a54fd519d68aa7d1aacba095140f1a647 (patch) | |
tree | 230e1e05ae5bdb9e1b2a395d403fedb0e0370854 /drivers/usb | |
parent | af6d780b578778d442278ac4894ff10847bebae2 (diff) |
tty-usb-generic: Code cleanup
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/serial/generic.c | 87 |
1 files changed, 49 insertions, 38 deletions
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c index 5128018c2766..fe84c88ec20c 100644 --- a/drivers/usb/serial/generic.c +++ b/drivers/usb/serial/generic.c | |||
@@ -18,7 +18,7 @@ | |||
18 | #include <linux/moduleparam.h> | 18 | #include <linux/moduleparam.h> |
19 | #include <linux/usb.h> | 19 | #include <linux/usb.h> |
20 | #include <linux/usb/serial.h> | 20 | #include <linux/usb/serial.h> |
21 | #include <asm/uaccess.h> | 21 | #include <linux/uaccess.h> |
22 | 22 | ||
23 | 23 | ||
24 | static int debug; | 24 | static int debug; |
@@ -81,7 +81,7 @@ static int generic_probe(struct usb_interface *interface, | |||
81 | } | 81 | } |
82 | #endif | 82 | #endif |
83 | 83 | ||
84 | int usb_serial_generic_register (int _debug) | 84 | int usb_serial_generic_register(int _debug) |
85 | { | 85 | { |
86 | int retval = 0; | 86 | int retval = 0; |
87 | 87 | ||
@@ -89,10 +89,11 @@ int usb_serial_generic_register (int _debug) | |||
89 | #ifdef CONFIG_USB_SERIAL_GENERIC | 89 | #ifdef CONFIG_USB_SERIAL_GENERIC |
90 | generic_device_ids[0].idVendor = vendor; | 90 | generic_device_ids[0].idVendor = vendor; |
91 | generic_device_ids[0].idProduct = product; | 91 | generic_device_ids[0].idProduct = product; |
92 | generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; | 92 | generic_device_ids[0].match_flags = |
93 | USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; | ||
93 | 94 | ||
94 | /* register our generic driver with ourselves */ | 95 | /* register our generic driver with ourselves */ |
95 | retval = usb_serial_register (&usb_serial_generic_device); | 96 | retval = usb_serial_register(&usb_serial_generic_device); |
96 | if (retval) | 97 | if (retval) |
97 | goto exit; | 98 | goto exit; |
98 | retval = usb_register(&generic_driver); | 99 | retval = usb_register(&generic_driver); |
@@ -103,12 +104,12 @@ exit: | |||
103 | return retval; | 104 | return retval; |
104 | } | 105 | } |
105 | 106 | ||
106 | void usb_serial_generic_deregister (void) | 107 | void usb_serial_generic_deregister(void) |
107 | { | 108 | { |
108 | #ifdef CONFIG_USB_SERIAL_GENERIC | 109 | #ifdef CONFIG_USB_SERIAL_GENERIC |
109 | /* remove our generic driver */ | 110 | /* remove our generic driver */ |
110 | usb_deregister(&generic_driver); | 111 | usb_deregister(&generic_driver); |
111 | usb_serial_deregister (&usb_serial_generic_device); | 112 | usb_serial_deregister(&usb_serial_generic_device); |
112 | #endif | 113 | #endif |
113 | } | 114 | } |
114 | 115 | ||
@@ -121,9 +122,9 @@ int usb_serial_generic_open(struct tty_struct *tty, | |||
121 | 122 | ||
122 | dbg("%s - port %d", __func__, port->number); | 123 | dbg("%s - port %d", __func__, port->number); |
123 | 124 | ||
124 | /* force low_latency on so that our tty_push actually forces the data through, | 125 | /* force low_latency on so that our tty_push actually forces the data |
125 | otherwise it is scheduled, and with high data rates (like with OHCI) data | 126 | through, otherwise it is scheduled, and with high data rates (like |
126 | can get lost. */ | 127 | with OHCI) data can get lost. */ |
127 | if (tty) | 128 | if (tty) |
128 | tty->low_latency = 1; | 129 | tty->low_latency = 1; |
129 | 130 | ||
@@ -136,8 +137,9 @@ int usb_serial_generic_open(struct tty_struct *tty, | |||
136 | /* if we have a bulk endpoint, start reading from it */ | 137 | /* if we have a bulk endpoint, start reading from it */ |
137 | if (serial->num_bulk_in) { | 138 | if (serial->num_bulk_in) { |
138 | /* Start reading from the device */ | 139 | /* Start reading from the device */ |
139 | usb_fill_bulk_urb (port->read_urb, serial->dev, | 140 | usb_fill_bulk_urb(port->read_urb, serial->dev, |
140 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), | 141 | usb_rcvbulkpipe(serial->dev, |
142 | port->bulk_in_endpointAddress), | ||
141 | port->read_urb->transfer_buffer, | 143 | port->read_urb->transfer_buffer, |
142 | port->read_urb->transfer_buffer_length, | 144 | port->read_urb->transfer_buffer_length, |
143 | ((serial->type->read_bulk_callback) ? | 145 | ((serial->type->read_bulk_callback) ? |
@@ -146,7 +148,9 @@ int usb_serial_generic_open(struct tty_struct *tty, | |||
146 | port); | 148 | port); |
147 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); | 149 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
148 | if (result) | 150 | if (result) |
149 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); | 151 | dev_err(&port->dev, |
152 | "%s - failed resubmitting read urb, error %d\n", | ||
153 | __func__, result); | ||
150 | } | 154 | } |
151 | 155 | ||
152 | return result; | 156 | return result; |
@@ -194,10 +198,10 @@ int usb_serial_generic_resume(struct usb_serial *serial) | |||
194 | } | 198 | } |
195 | 199 | ||
196 | void usb_serial_generic_close(struct tty_struct *tty, | 200 | void usb_serial_generic_close(struct tty_struct *tty, |
197 | struct usb_serial_port *port, struct file * filp) | 201 | struct usb_serial_port *port, struct file *filp) |
198 | { | 202 | { |
199 | dbg("%s - port %d", __func__, port->number); | 203 | dbg("%s - port %d", __func__, port->number); |
200 | generic_cleanup (port); | 204 | generic_cleanup(port); |
201 | } | 205 | } |
202 | 206 | ||
203 | int usb_serial_generic_write(struct tty_struct *tty, | 207 | int usb_serial_generic_write(struct tty_struct *tty, |
@@ -211,7 +215,7 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
211 | 215 | ||
212 | if (count == 0) { | 216 | if (count == 0) { |
213 | dbg("%s - write request of 0 bytes", __func__); | 217 | dbg("%s - write request of 0 bytes", __func__); |
214 | return (0); | 218 | return 0; |
215 | } | 219 | } |
216 | 220 | ||
217 | /* only do something if we have a bulk out endpoint */ | 221 | /* only do something if we have a bulk out endpoint */ |
@@ -226,27 +230,32 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
226 | port->write_urb_busy = 1; | 230 | port->write_urb_busy = 1; |
227 | spin_unlock_irqrestore(&port->lock, flags); | 231 | spin_unlock_irqrestore(&port->lock, flags); |
228 | 232 | ||
229 | count = (count > port->bulk_out_size) ? port->bulk_out_size : count; | 233 | count = (count > port->bulk_out_size) ? |
234 | port->bulk_out_size : count; | ||
230 | 235 | ||
231 | memcpy (port->write_urb->transfer_buffer, buf, count); | 236 | memcpy(port->write_urb->transfer_buffer, buf, count); |
232 | data = port->write_urb->transfer_buffer; | 237 | data = port->write_urb->transfer_buffer; |
233 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); | 238 | usb_serial_debug_data(debug, &port->dev, __func__, count, data); |
234 | 239 | ||
235 | /* set up our urb */ | 240 | /* set up our urb */ |
236 | usb_fill_bulk_urb (port->write_urb, serial->dev, | 241 | usb_fill_bulk_urb(port->write_urb, serial->dev, |
237 | usb_sndbulkpipe (serial->dev, | 242 | usb_sndbulkpipe(serial->dev, |
238 | port->bulk_out_endpointAddress), | 243 | port->bulk_out_endpointAddress), |
239 | port->write_urb->transfer_buffer, count, | 244 | port->write_urb->transfer_buffer, count, |
240 | ((serial->type->write_bulk_callback) ? | 245 | ((serial->type->write_bulk_callback) ? |
241 | serial->type->write_bulk_callback : | 246 | serial->type->write_bulk_callback : |
242 | usb_serial_generic_write_bulk_callback), port); | 247 | usb_serial_generic_write_bulk_callback), |
248 | port); | ||
243 | 249 | ||
244 | /* send the data out the bulk port */ | 250 | /* send the data out the bulk port */ |
245 | port->write_urb_busy = 1; | 251 | port->write_urb_busy = 1; |
246 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); | 252 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
247 | if (result) { | 253 | if (result) { |
248 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result); | 254 | dev_err(&port->dev, |
249 | /* don't have to grab the lock here, as we will retry if != 0 */ | 255 | "%s - failed submitting write urb, error %d\n", |
256 | __func__, result); | ||
257 | /* don't have to grab the lock here, as we will | ||
258 | retry if != 0 */ | ||
250 | port->write_urb_busy = 0; | 259 | port->write_urb_busy = 0; |
251 | } else | 260 | } else |
252 | result = count; | 261 | result = count; |
@@ -258,7 +267,7 @@ int usb_serial_generic_write(struct tty_struct *tty, | |||
258 | return 0; | 267 | return 0; |
259 | } | 268 | } |
260 | 269 | ||
261 | int usb_serial_generic_write_room (struct tty_struct *tty) | 270 | int usb_serial_generic_write_room(struct tty_struct *tty) |
262 | { | 271 | { |
263 | struct usb_serial_port *port = tty->driver_data; | 272 | struct usb_serial_port *port = tty->driver_data; |
264 | struct usb_serial *serial = port->serial; | 273 | struct usb_serial *serial = port->serial; |
@@ -302,17 +311,19 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) | |||
302 | int result; | 311 | int result; |
303 | 312 | ||
304 | /* Continue reading from device */ | 313 | /* Continue reading from device */ |
305 | usb_fill_bulk_urb (urb, serial->dev, | 314 | usb_fill_bulk_urb(urb, serial->dev, |
306 | usb_rcvbulkpipe (serial->dev, | 315 | usb_rcvbulkpipe(serial->dev, |
307 | port->bulk_in_endpointAddress), | 316 | port->bulk_in_endpointAddress), |
308 | urb->transfer_buffer, | 317 | urb->transfer_buffer, |
309 | urb->transfer_buffer_length, | 318 | urb->transfer_buffer_length, |
310 | ((serial->type->read_bulk_callback) ? | 319 | ((serial->type->read_bulk_callback) ? |
311 | serial->type->read_bulk_callback : | 320 | serial->type->read_bulk_callback : |
312 | usb_serial_generic_read_bulk_callback), port); | 321 | usb_serial_generic_read_bulk_callback), port); |
313 | result = usb_submit_urb(urb, mem_flags); | 322 | result = usb_submit_urb(urb, mem_flags); |
314 | if (result) | 323 | if (result) |
315 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); | 324 | dev_err(&port->dev, |
325 | "%s - failed resubmitting read urb, error %d\n", | ||
326 | __func__, result); | ||
316 | } | 327 | } |
317 | 328 | ||
318 | /* Push data to tty layer and resubmit the bulk read URB */ | 329 | /* Push data to tty layer and resubmit the bulk read URB */ |
@@ -349,16 +360,17 @@ void usb_serial_generic_read_bulk_callback(struct urb *urb) | |||
349 | return; | 360 | return; |
350 | } | 361 | } |
351 | 362 | ||
352 | usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data); | 363 | usb_serial_debug_data(debug, &port->dev, __func__, |
364 | urb->actual_length, data); | ||
353 | 365 | ||
354 | /* Throttle the device if requested by tty */ | 366 | /* Throttle the device if requested by tty */ |
355 | spin_lock_irqsave(&port->lock, flags); | 367 | spin_lock_irqsave(&port->lock, flags); |
356 | if (!(port->throttled = port->throttle_req)) { | 368 | port->throttled = port->throttle_req; |
369 | if (!port->throttled) { | ||
357 | spin_unlock_irqrestore(&port->lock, flags); | 370 | spin_unlock_irqrestore(&port->lock, flags); |
358 | flush_and_resubmit_read_urb(port); | 371 | flush_and_resubmit_read_urb(port); |
359 | } else { | 372 | } else |
360 | spin_unlock_irqrestore(&port->lock, flags); | 373 | spin_unlock_irqrestore(&port->lock, flags); |
361 | } | ||
362 | } | 374 | } |
363 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); | 375 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
364 | 376 | ||
@@ -413,15 +425,14 @@ void usb_serial_generic_unthrottle(struct tty_struct *tty) | |||
413 | } | 425 | } |
414 | } | 426 | } |
415 | 427 | ||
416 | void usb_serial_generic_shutdown (struct usb_serial *serial) | 428 | void usb_serial_generic_shutdown(struct usb_serial *serial) |
417 | { | 429 | { |
418 | int i; | 430 | int i; |
419 | 431 | ||
420 | dbg("%s", __func__); | 432 | dbg("%s", __func__); |
421 | 433 | ||
422 | /* stop reads and writes on all ports */ | 434 | /* stop reads and writes on all ports */ |
423 | for (i=0; i < serial->num_ports; ++i) { | 435 | for (i = 0; i < serial->num_ports; ++i) |
424 | generic_cleanup(serial->port[i]); | 436 | generic_cleanup(serial->port[i]); |
425 | } | ||
426 | } | 437 | } |
427 | 438 | ||