Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Serial Converter Generic functions |
| 3 | * |
| 4 | * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License version |
| 8 | * 2 as published by the Free Software Foundation. |
| 9 | * |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/errno.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/tty.h> |
| 16 | #include <linux/tty_flip.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
| 19 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 20 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static int debug; |
| 25 | |
| 26 | #ifdef CONFIG_USB_SERIAL_GENERIC |
David Brownell | b46d60f | 2007-03-23 12:51:55 -0700 | [diff] [blame] | 27 | |
| 28 | static int generic_probe(struct usb_interface *interface, |
| 29 | const struct usb_device_id *id); |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | static __u16 vendor = 0x05f9; |
| 32 | static __u16 product = 0xffff; |
| 33 | |
| 34 | module_param(vendor, ushort, 0); |
| 35 | MODULE_PARM_DESC(vendor, "User specified USB idVendor"); |
| 36 | |
| 37 | module_param(product, ushort, 0); |
| 38 | MODULE_PARM_DESC(product, "User specified USB idProduct"); |
| 39 | |
| 40 | static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ |
| 41 | |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 42 | /* we want to look at all devices, as the vendor/product id can change |
| 43 | * depending on the command line argument */ |
| 44 | static struct usb_device_id generic_serial_ids[] = { |
| 45 | {.driver_info = 42}, |
| 46 | {} |
| 47 | }; |
| 48 | |
| 49 | static struct usb_driver generic_driver = { |
| 50 | .name = "usbserial_generic", |
| 51 | .probe = generic_probe, |
| 52 | .disconnect = usb_serial_disconnect, |
| 53 | .id_table = generic_serial_ids, |
| 54 | .no_dynamic_id = 1, |
| 55 | }; |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* All of the device info needed for the Generic Serial Converter */ |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 58 | struct usb_serial_driver usb_serial_generic_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 59 | .driver = { |
| 60 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 61 | .name = "generic", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 62 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | .id_table = generic_device_ids, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 64 | .usb_driver = &generic_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | .num_interrupt_in = NUM_DONT_CARE, |
| 66 | .num_bulk_in = NUM_DONT_CARE, |
| 67 | .num_bulk_out = NUM_DONT_CARE, |
| 68 | .num_ports = 1, |
| 69 | .shutdown = usb_serial_generic_shutdown, |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 70 | .throttle = usb_serial_generic_throttle, |
| 71 | .unthrottle = usb_serial_generic_unthrottle, |
Oliver Neukum | ec22559 | 2007-04-27 20:54:57 +0200 | [diff] [blame] | 72 | .resume = usb_serial_generic_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | static int generic_probe(struct usb_interface *interface, |
| 76 | const struct usb_device_id *id) |
| 77 | { |
| 78 | const struct usb_device_id *id_pattern; |
| 79 | |
| 80 | id_pattern = usb_match_id(interface, generic_device_ids); |
| 81 | if (id_pattern != NULL) |
| 82 | return usb_serial_probe(interface, id); |
| 83 | return -ENODEV; |
| 84 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #endif |
| 86 | |
| 87 | int usb_serial_generic_register (int _debug) |
| 88 | { |
| 89 | int retval = 0; |
| 90 | |
| 91 | debug = _debug; |
| 92 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 93 | generic_device_ids[0].idVendor = vendor; |
| 94 | generic_device_ids[0].idProduct = product; |
| 95 | generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; |
| 96 | |
| 97 | /* register our generic driver with ourselves */ |
| 98 | retval = usb_serial_register (&usb_serial_generic_device); |
| 99 | if (retval) |
| 100 | goto exit; |
| 101 | retval = usb_register(&generic_driver); |
| 102 | if (retval) |
| 103 | usb_serial_deregister(&usb_serial_generic_device); |
| 104 | exit: |
| 105 | #endif |
| 106 | return retval; |
| 107 | } |
| 108 | |
| 109 | void usb_serial_generic_deregister (void) |
| 110 | { |
| 111 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 112 | /* remove our generic driver */ |
| 113 | usb_deregister(&generic_driver); |
| 114 | usb_serial_deregister (&usb_serial_generic_device); |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | int usb_serial_generic_open (struct usb_serial_port *port, struct file *filp) |
| 119 | { |
| 120 | struct usb_serial *serial = port->serial; |
| 121 | int result = 0; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 122 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 125 | |
| 126 | /* force low_latency on so that our tty_push actually forces the data through, |
| 127 | otherwise it is scheduled, and with high data rates (like with OHCI) data |
| 128 | can get lost. */ |
| 129 | if (port->tty) |
| 130 | port->tty->low_latency = 1; |
| 131 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 132 | /* clear the throttle flags */ |
| 133 | spin_lock_irqsave(&port->lock, flags); |
| 134 | port->throttled = 0; |
| 135 | port->throttle_req = 0; |
| 136 | spin_unlock_irqrestore(&port->lock, flags); |
| 137 | |
| 138 | /* if we have a bulk endpoint, start reading from it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | if (serial->num_bulk_in) { |
| 140 | /* Start reading from the device */ |
| 141 | usb_fill_bulk_urb (port->read_urb, serial->dev, |
| 142 | usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), |
| 143 | port->read_urb->transfer_buffer, |
| 144 | port->read_urb->transfer_buffer_length, |
| 145 | ((serial->type->read_bulk_callback) ? |
| 146 | serial->type->read_bulk_callback : |
| 147 | usb_serial_generic_read_bulk_callback), |
| 148 | port); |
| 149 | result = usb_submit_urb(port->read_urb, GFP_KERNEL); |
| 150 | if (result) |
| 151 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); |
| 152 | } |
| 153 | |
| 154 | return result; |
| 155 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 156 | EXPORT_SYMBOL_GPL(usb_serial_generic_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | static void generic_cleanup (struct usb_serial_port *port) |
| 159 | { |
| 160 | struct usb_serial *serial = port->serial; |
| 161 | |
| 162 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 163 | |
| 164 | if (serial->dev) { |
| 165 | /* shutdown any bulk reads that might be going on */ |
| 166 | if (serial->num_bulk_out) |
| 167 | usb_kill_urb(port->write_urb); |
| 168 | if (serial->num_bulk_in) |
| 169 | usb_kill_urb(port->read_urb); |
| 170 | } |
| 171 | } |
| 172 | |
Oliver Neukum | ec22559 | 2007-04-27 20:54:57 +0200 | [diff] [blame] | 173 | int usb_serial_generic_resume(struct usb_serial *serial) |
| 174 | { |
| 175 | struct usb_serial_port *port; |
| 176 | int i, c = 0, r; |
| 177 | |
Sarah Sharp | f0fbd5b | 2007-11-13 17:10:09 -0800 | [diff] [blame] | 178 | #ifdef CONFIG_PM |
| 179 | /* |
| 180 | * If this is an autoresume, don't submit URBs. |
| 181 | * They will be submitted in the open function instead. |
| 182 | */ |
| 183 | if (serial->dev->auto_pm) |
| 184 | return 0; |
| 185 | #endif |
Oliver Neukum | ec22559 | 2007-04-27 20:54:57 +0200 | [diff] [blame] | 186 | for (i = 0; i < serial->num_ports; i++) { |
| 187 | port = serial->port[i]; |
| 188 | if (port->open_count && port->read_urb) { |
| 189 | r = usb_submit_urb(port->read_urb, GFP_NOIO); |
| 190 | if (r < 0) |
| 191 | c++; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return c ? -EIO : 0; |
| 196 | } |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | void usb_serial_generic_close (struct usb_serial_port *port, struct file * filp) |
| 199 | { |
| 200 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 201 | generic_cleanup (port); |
| 202 | } |
| 203 | |
| 204 | int usb_serial_generic_write(struct usb_serial_port *port, const unsigned char *buf, int count) |
| 205 | { |
| 206 | struct usb_serial *serial = port->serial; |
| 207 | int result; |
| 208 | unsigned char *data; |
| 209 | |
| 210 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 211 | |
| 212 | if (count == 0) { |
| 213 | dbg("%s - write request of 0 bytes", __FUNCTION__); |
| 214 | return (0); |
| 215 | } |
| 216 | |
| 217 | /* only do something if we have a bulk out endpoint */ |
| 218 | if (serial->num_bulk_out) { |
Jiri Kosina | acd2a84 | 2007-10-20 00:05:19 +0200 | [diff] [blame] | 219 | unsigned long flags; |
| 220 | spin_lock_irqsave(&port->lock, flags); |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 221 | if (port->write_urb_busy) { |
Jiri Kosina | acd2a84 | 2007-10-20 00:05:19 +0200 | [diff] [blame] | 222 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | dbg("%s - already writing", __FUNCTION__); |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 224 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 226 | port->write_urb_busy = 1; |
Jiri Kosina | acd2a84 | 2007-10-20 00:05:19 +0200 | [diff] [blame] | 227 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | count = (count > port->bulk_out_size) ? port->bulk_out_size : count; |
| 230 | |
| 231 | memcpy (port->write_urb->transfer_buffer, buf, count); |
| 232 | data = port->write_urb->transfer_buffer; |
| 233 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, count, data); |
| 234 | |
| 235 | /* set up our urb */ |
| 236 | usb_fill_bulk_urb (port->write_urb, serial->dev, |
| 237 | usb_sndbulkpipe (serial->dev, |
| 238 | port->bulk_out_endpointAddress), |
| 239 | port->write_urb->transfer_buffer, count, |
| 240 | ((serial->type->write_bulk_callback) ? |
| 241 | serial->type->write_bulk_callback : |
| 242 | usb_serial_generic_write_bulk_callback), port); |
| 243 | |
| 244 | /* send the data out the bulk port */ |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 245 | port->write_urb_busy = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | result = usb_submit_urb(port->write_urb, GFP_ATOMIC); |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 247 | if (result) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result); |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 249 | /* don't have to grab the lock here, as we will retry if != 0 */ |
| 250 | port->write_urb_busy = 0; |
| 251 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | result = count; |
| 253 | |
| 254 | return result; |
| 255 | } |
| 256 | |
| 257 | /* no bulk out, so return 0 bytes written */ |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 258 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | int usb_serial_generic_write_room (struct usb_serial_port *port) |
| 262 | { |
| 263 | struct usb_serial *serial = port->serial; |
| 264 | int room = 0; |
| 265 | |
| 266 | dbg("%s - port %d", __FUNCTION__, port->number); |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | if (serial->num_bulk_out) { |
Randall Nortman | 7a3ca7d | 2005-10-14 17:21:50 -0700 | [diff] [blame] | 269 | if (!(port->write_urb_busy)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | room = port->bulk_out_size; |
| 271 | } |
| 272 | |
| 273 | dbg("%s - returns %d", __FUNCTION__, room); |
| 274 | return (room); |
| 275 | } |
| 276 | |
| 277 | int usb_serial_generic_chars_in_buffer (struct usb_serial_port *port) |
| 278 | { |
| 279 | struct usb_serial *serial = port->serial; |
| 280 | int chars = 0; |
| 281 | |
| 282 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 283 | |
| 284 | if (serial->num_bulk_out) { |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 285 | if (port->write_urb_busy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | chars = port->write_urb->transfer_buffer_length; |
| 287 | } |
| 288 | |
| 289 | dbg("%s - returns %d", __FUNCTION__, chars); |
| 290 | return (chars); |
| 291 | } |
| 292 | |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 293 | |
| 294 | static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | { |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 296 | struct urb *urb = port->read_urb; |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 297 | struct usb_serial *serial = port->serial; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | int result; |
| 299 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 300 | /* Continue reading from device */ |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 301 | usb_fill_bulk_urb (urb, serial->dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | usb_rcvbulkpipe (serial->dev, |
| 303 | port->bulk_in_endpointAddress), |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 304 | urb->transfer_buffer, |
| 305 | urb->transfer_buffer_length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | ((serial->type->read_bulk_callback) ? |
| 307 | serial->type->read_bulk_callback : |
| 308 | usb_serial_generic_read_bulk_callback), port); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 309 | result = usb_submit_urb(urb, mem_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (result) |
| 311 | dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result); |
| 312 | } |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 313 | |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 314 | /* Push data to tty layer and resubmit the bulk read URB */ |
| 315 | static void flush_and_resubmit_read_urb (struct usb_serial_port *port) |
| 316 | { |
| 317 | struct urb *urb = port->read_urb; |
| 318 | struct tty_struct *tty = port->tty; |
| 319 | int room; |
| 320 | |
| 321 | /* Push data to tty */ |
| 322 | if (tty && urb->actual_length) { |
| 323 | room = tty_buffer_request_room(tty, urb->actual_length); |
| 324 | if (room) { |
| 325 | tty_insert_flip_string(tty, urb->transfer_buffer, room); |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame^] | 326 | tty_flip_buffer_push(tty); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
| 330 | resubmit_read_urb(port, GFP_ATOMIC); |
| 331 | } |
| 332 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 333 | void usb_serial_generic_read_bulk_callback (struct urb *urb) |
| 334 | { |
| 335 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
| 336 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 337 | int status = urb->status; |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 338 | unsigned long flags; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 339 | |
| 340 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 341 | |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 342 | if (unlikely(status != 0)) { |
| 343 | dbg("%s - nonzero read bulk status received: %d", |
| 344 | __FUNCTION__, status); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 345 | return; |
| 346 | } |
| 347 | |
| 348 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, urb->actual_length, data); |
| 349 | |
| 350 | /* Throttle the device if requested by tty */ |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 351 | spin_lock_irqsave(&port->lock, flags); |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame^] | 352 | if (!(port->throttled = port->throttle_req)) { |
| 353 | spin_unlock_irqrestore(&port->lock, flags); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 354 | flush_and_resubmit_read_urb(port); |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame^] | 355 | } else { |
| 356 | spin_unlock_irqrestore(&port->lock, flags); |
| 357 | } |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 358 | } |
Luiz Fernando N. Capitulino | 166ffcc | 2006-07-11 14:19:25 -0300 | [diff] [blame] | 359 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 361 | void usb_serial_generic_write_bulk_callback (struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | struct usb_serial_port *port = (struct usb_serial_port *)urb->context; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 364 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 367 | |
Greg Kroah-Hartman | 507ca9b | 2005-04-23 12:49:16 -0700 | [diff] [blame] | 368 | port->write_urb_busy = 0; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 369 | if (status) { |
| 370 | dbg("%s - nonzero write bulk status received: %d", |
| 371 | __FUNCTION__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | return; |
| 373 | } |
| 374 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 375 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
Greg Kroah-Hartman | bb83398 | 2005-11-17 09:48:18 -0800 | [diff] [blame] | 377 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 379 | void usb_serial_generic_throttle (struct usb_serial_port *port) |
| 380 | { |
| 381 | unsigned long flags; |
| 382 | |
| 383 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 384 | |
| 385 | /* Set the throttle request flag. It will be picked up |
| 386 | * by usb_serial_generic_read_bulk_callback(). */ |
| 387 | spin_lock_irqsave(&port->lock, flags); |
| 388 | port->throttle_req = 1; |
| 389 | spin_unlock_irqrestore(&port->lock, flags); |
| 390 | } |
| 391 | |
| 392 | void usb_serial_generic_unthrottle (struct usb_serial_port *port) |
| 393 | { |
| 394 | int was_throttled; |
| 395 | unsigned long flags; |
| 396 | |
| 397 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 398 | |
| 399 | /* Clear the throttle flags */ |
| 400 | spin_lock_irqsave(&port->lock, flags); |
| 401 | was_throttled = port->throttled; |
| 402 | port->throttled = port->throttle_req = 0; |
| 403 | spin_unlock_irqrestore(&port->lock, flags); |
| 404 | |
| 405 | if (was_throttled) { |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 406 | /* Resume reading from device */ |
| 407 | resubmit_read_urb(port, GFP_KERNEL); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 408 | } |
| 409 | } |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | void usb_serial_generic_shutdown (struct usb_serial *serial) |
| 412 | { |
| 413 | int i; |
| 414 | |
| 415 | dbg("%s", __FUNCTION__); |
| 416 | |
| 417 | /* stop reads and writes on all ports */ |
| 418 | for (i=0; i < serial->num_ports; ++i) { |
| 419 | generic_cleanup(serial->port[i]); |
| 420 | } |
| 421 | } |
| 422 | |