blob: 5128018c276619c3163fbe1df74cbc00f61314a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070012#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-Hartmana9698882006-07-11 21:22:58 -070020#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Johannes Hölzld9b1b782006-12-17 21:50:24 +010023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int debug;
25
26#ifdef CONFIG_USB_SERIAL_GENERIC
David Brownellb46d60f2007-03-23 12:51:55 -070027
28static int generic_probe(struct usb_interface *interface,
29 const struct usb_device_id *id);
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static __u16 vendor = 0x05f9;
32static __u16 product = 0xffff;
33
34module_param(vendor, ushort, 0);
35MODULE_PARM_DESC(vendor, "User specified USB idVendor");
36
37module_param(product, ushort, 0);
38MODULE_PARM_DESC(product, "User specified USB idProduct");
39
40static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
41
Johannes Hölzld9b1b782006-12-17 21:50:24 +010042/* we want to look at all devices, as the vendor/product id can change
43 * depending on the command line argument */
44static struct usb_device_id generic_serial_ids[] = {
45 {.driver_info = 42},
46 {}
47};
48
49static 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 Torvalds1da177e2005-04-16 15:20:36 -070057/* All of the device info needed for the Generic Serial Converter */
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -070058struct usb_serial_driver usb_serial_generic_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -070059 .driver = {
60 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -070061 .name = "generic",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -070062 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 .id_table = generic_device_ids,
Johannes Hölzld9b1b782006-12-17 21:50:24 +010064 .usb_driver = &generic_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 .num_ports = 1,
66 .shutdown = usb_serial_generic_shutdown,
Joris van Rantwijk253ca922007-02-01 20:08:18 +010067 .throttle = usb_serial_generic_throttle,
68 .unthrottle = usb_serial_generic_unthrottle,
Oliver Neukumec225592007-04-27 20:54:57 +020069 .resume = usb_serial_generic_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070};
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072static int generic_probe(struct usb_interface *interface,
73 const struct usb_device_id *id)
74{
75 const struct usb_device_id *id_pattern;
76
77 id_pattern = usb_match_id(interface, generic_device_ids);
78 if (id_pattern != NULL)
79 return usb_serial_probe(interface, id);
80 return -ENODEV;
81}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#endif
83
84int usb_serial_generic_register (int _debug)
85{
86 int retval = 0;
87
88 debug = _debug;
89#ifdef CONFIG_USB_SERIAL_GENERIC
90 generic_device_ids[0].idVendor = vendor;
91 generic_device_ids[0].idProduct = product;
92 generic_device_ids[0].match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
93
94 /* register our generic driver with ourselves */
95 retval = usb_serial_register (&usb_serial_generic_device);
96 if (retval)
97 goto exit;
98 retval = usb_register(&generic_driver);
99 if (retval)
100 usb_serial_deregister(&usb_serial_generic_device);
101exit:
102#endif
103 return retval;
104}
105
106void usb_serial_generic_deregister (void)
107{
108#ifdef CONFIG_USB_SERIAL_GENERIC
109 /* remove our generic driver */
110 usb_deregister(&generic_driver);
111 usb_serial_deregister (&usb_serial_generic_device);
112#endif
113}
114
Alan Cox95da3102008-07-22 11:09:07 +0100115int usb_serial_generic_open(struct tty_struct *tty,
116 struct usb_serial_port *port, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117{
118 struct usb_serial *serial = port->serial;
119 int result = 0;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100120 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Harvey Harrison441b62c2008-03-03 16:08:34 -0800122 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* force low_latency on so that our tty_push actually forces the data through,
125 otherwise it is scheduled, and with high data rates (like with OHCI) data
126 can get lost. */
Alan Cox95da3102008-07-22 11:09:07 +0100127 if (tty)
128 tty->low_latency = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100130 /* clear the throttle flags */
131 spin_lock_irqsave(&port->lock, flags);
132 port->throttled = 0;
133 port->throttle_req = 0;
134 spin_unlock_irqrestore(&port->lock, flags);
135
136 /* if we have a bulk endpoint, start reading from it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 if (serial->num_bulk_in) {
138 /* Start reading from the device */
139 usb_fill_bulk_urb (port->read_urb, serial->dev,
140 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress),
141 port->read_urb->transfer_buffer,
142 port->read_urb->transfer_buffer_length,
143 ((serial->type->read_bulk_callback) ?
144 serial->type->read_bulk_callback :
145 usb_serial_generic_read_bulk_callback),
146 port);
147 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
148 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800149 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151
152 return result;
153}
Greg Kroah-Hartman815ddc92006-05-12 11:05:29 -0700154EXPORT_SYMBOL_GPL(usb_serial_generic_open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Alan Cox95da3102008-07-22 11:09:07 +0100156static void generic_cleanup(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 struct usb_serial *serial = port->serial;
159
Harvey Harrison441b62c2008-03-03 16:08:34 -0800160 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 if (serial->dev) {
163 /* shutdown any bulk reads that might be going on */
164 if (serial->num_bulk_out)
165 usb_kill_urb(port->write_urb);
166 if (serial->num_bulk_in)
167 usb_kill_urb(port->read_urb);
168 }
169}
170
Oliver Neukumec225592007-04-27 20:54:57 +0200171int usb_serial_generic_resume(struct usb_serial *serial)
172{
173 struct usb_serial_port *port;
174 int i, c = 0, r;
175
Sarah Sharpf0fbd5b2007-11-13 17:10:09 -0800176#ifdef CONFIG_PM
177 /*
178 * If this is an autoresume, don't submit URBs.
179 * They will be submitted in the open function instead.
180 */
181 if (serial->dev->auto_pm)
182 return 0;
183#endif
Oliver Neukumec225592007-04-27 20:54:57 +0200184 for (i = 0; i < serial->num_ports; i++) {
185 port = serial->port[i];
Alan Cox95da3102008-07-22 11:09:07 +0100186 if (port->port.count && port->read_urb) {
Oliver Neukumec225592007-04-27 20:54:57 +0200187 r = usb_submit_urb(port->read_urb, GFP_NOIO);
188 if (r < 0)
189 c++;
190 }
191 }
192
193 return c ? -EIO : 0;
194}
195
Alan Cox95da3102008-07-22 11:09:07 +0100196void usb_serial_generic_close(struct tty_struct *tty,
197 struct usb_serial_port *port, struct file * filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800199 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 generic_cleanup (port);
201}
202
Alan Cox95da3102008-07-22 11:09:07 +0100203int usb_serial_generic_write(struct tty_struct *tty,
204 struct usb_serial_port *port, const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 struct usb_serial *serial = port->serial;
207 int result;
208 unsigned char *data;
209
Harvey Harrison441b62c2008-03-03 16:08:34 -0800210 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 if (count == 0) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800213 dbg("%s - write request of 0 bytes", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return (0);
215 }
216
217 /* only do something if we have a bulk out endpoint */
218 if (serial->num_bulk_out) {
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200219 unsigned long flags;
220 spin_lock_irqsave(&port->lock, flags);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700221 if (port->write_urb_busy) {
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200222 spin_unlock_irqrestore(&port->lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800223 dbg("%s - already writing", __func__);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700224 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 }
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700226 port->write_urb_busy = 1;
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200227 spin_unlock_irqrestore(&port->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
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;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800233 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
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-Hartman507ca9b2005-04-23 12:49:16 -0700245 port->write_urb_busy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700247 if (result) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800248 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700249 /* don't have to grab the lock here, as we will retry if != 0 */
250 port->write_urb_busy = 0;
251 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 result = count;
253
254 return result;
255 }
256
257 /* no bulk out, so return 0 bytes written */
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700258 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
Alan Cox95da3102008-07-22 11:09:07 +0100261int usb_serial_generic_write_room (struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
Alan Cox95da3102008-07-22 11:09:07 +0100263 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 struct usb_serial *serial = port->serial;
265 int room = 0;
266
Harvey Harrison441b62c2008-03-03 16:08:34 -0800267 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700268
Alan Coxa5b6f602008-04-08 17:16:06 +0100269 /* FIXME: Locking */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (serial->num_bulk_out) {
Randall Nortman7a3ca7d2005-10-14 17:21:50 -0700271 if (!(port->write_urb_busy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 room = port->bulk_out_size;
273 }
274
Harvey Harrison441b62c2008-03-03 16:08:34 -0800275 dbg("%s - returns %d", __func__, room);
Alan Coxa5b6f602008-04-08 17:16:06 +0100276 return room;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277}
278
Alan Cox95da3102008-07-22 11:09:07 +0100279int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
Alan Cox95da3102008-07-22 11:09:07 +0100281 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 struct usb_serial *serial = port->serial;
283 int chars = 0;
284
Harvey Harrison441b62c2008-03-03 16:08:34 -0800285 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Alan Coxa5b6f602008-04-08 17:16:06 +0100287 /* FIXME: Locking */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (serial->num_bulk_out) {
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700289 if (port->write_urb_busy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 chars = port->write_urb->transfer_buffer_length;
291 }
292
Harvey Harrison441b62c2008-03-03 16:08:34 -0800293 dbg("%s - returns %d", __func__, chars);
Alan Cox95da3102008-07-22 11:09:07 +0100294 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200297
298static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100300 struct urb *urb = port->read_urb;
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200301 struct usb_serial *serial = port->serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 int result;
303
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100304 /* Continue reading from device */
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200305 usb_fill_bulk_urb (urb, serial->dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 usb_rcvbulkpipe (serial->dev,
307 port->bulk_in_endpointAddress),
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200308 urb->transfer_buffer,
309 urb->transfer_buffer_length,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 ((serial->type->read_bulk_callback) ?
311 serial->type->read_bulk_callback :
312 usb_serial_generic_read_bulk_callback), port);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200313 result = usb_submit_urb(urb, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800315 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100317
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200318/* Push data to tty layer and resubmit the bulk read URB */
Alan Cox95da3102008-07-22 11:09:07 +0100319static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200320{
321 struct urb *urb = port->read_urb;
Alan Cox95da3102008-07-22 11:09:07 +0100322 struct tty_struct *tty = port->port.tty;
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200323 int room;
324
325 /* Push data to tty */
326 if (tty && urb->actual_length) {
327 room = tty_buffer_request_room(tty, urb->actual_length);
328 if (room) {
329 tty_insert_flip_string(tty, urb->transfer_buffer, room);
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800330 tty_flip_buffer_push(tty);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200331 }
332 }
333
334 resubmit_read_urb(port, GFP_ATOMIC);
335}
336
Alan Cox95da3102008-07-22 11:09:07 +0100337void usb_serial_generic_read_bulk_callback(struct urb *urb)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100338{
Ming Leicdc97792008-02-24 18:41:47 +0800339 struct usb_serial_port *port = urb->context;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100340 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700341 int status = urb->status;
Borislav Petkovbfaeafc2007-10-28 13:24:16 +0100342 unsigned long flags;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100343
Harvey Harrison441b62c2008-03-03 16:08:34 -0800344 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100345
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700346 if (unlikely(status != 0)) {
347 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800348 __func__, status);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100349 return;
350 }
351
Harvey Harrison441b62c2008-03-03 16:08:34 -0800352 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100353
354 /* Throttle the device if requested by tty */
Borislav Petkovbfaeafc2007-10-28 13:24:16 +0100355 spin_lock_irqsave(&port->lock, flags);
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800356 if (!(port->throttled = port->throttle_req)) {
357 spin_unlock_irqrestore(&port->lock, flags);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200358 flush_and_resubmit_read_urb(port);
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800359 } else {
360 spin_unlock_irqrestore(&port->lock, flags);
361 }
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100362}
Luiz Fernando N. Capitulino166ffcc2006-07-11 14:19:25 -0300363EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Alan Cox95da3102008-07-22 11:09:07 +0100365void usb_serial_generic_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366{
Ming Leicdc97792008-02-24 18:41:47 +0800367 struct usb_serial_port *port = urb->context;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700368 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Harvey Harrison441b62c2008-03-03 16:08:34 -0800370 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700372 port->write_urb_busy = 0;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700373 if (status) {
374 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800375 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return;
377 }
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700378 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379}
Greg Kroah-Hartmanbb833982005-11-17 09:48:18 -0800380EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Alan Cox95da3102008-07-22 11:09:07 +0100382void usb_serial_generic_throttle(struct tty_struct *tty)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100383{
Alan Cox95da3102008-07-22 11:09:07 +0100384 struct usb_serial_port *port = tty->driver_data;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100385 unsigned long flags;
386
Harvey Harrison441b62c2008-03-03 16:08:34 -0800387 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100388
389 /* Set the throttle request flag. It will be picked up
390 * by usb_serial_generic_read_bulk_callback(). */
391 spin_lock_irqsave(&port->lock, flags);
392 port->throttle_req = 1;
393 spin_unlock_irqrestore(&port->lock, flags);
394}
395
Alan Cox95da3102008-07-22 11:09:07 +0100396void usb_serial_generic_unthrottle(struct tty_struct *tty)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100397{
Alan Cox95da3102008-07-22 11:09:07 +0100398 struct usb_serial_port *port = tty->driver_data;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100399 int was_throttled;
400 unsigned long flags;
401
Harvey Harrison441b62c2008-03-03 16:08:34 -0800402 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100403
404 /* Clear the throttle flags */
405 spin_lock_irqsave(&port->lock, flags);
406 was_throttled = port->throttled;
407 port->throttled = port->throttle_req = 0;
408 spin_unlock_irqrestore(&port->lock, flags);
409
410 if (was_throttled) {
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200411 /* Resume reading from device */
412 resubmit_read_urb(port, GFP_KERNEL);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100413 }
414}
415
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416void usb_serial_generic_shutdown (struct usb_serial *serial)
417{
418 int i;
419
Harvey Harrison441b62c2008-03-03 16:08:34 -0800420 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 /* stop reads and writes on all ports */
423 for (i=0; i < serial->num_ports; ++i) {
424 generic_cleanup(serial->port[i]);
425 }
426}
427