blob: c4a47abfee68b227043dcd51c52367fac3a68fee [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>
Alan Coxae643872008-07-22 11:11:55 +010021#include <linux/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
Alan Coxae643872008-07-22 11:11:55 +010084int usb_serial_generic_register(int _debug)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
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;
Alan Coxae643872008-07-22 11:11:55 +010092 generic_device_ids[0].match_flags =
93 USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 /* register our generic driver with ourselves */
Alan Coxae643872008-07-22 11:11:55 +010096 retval = usb_serial_register(&usb_serial_generic_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 if (retval)
98 goto exit;
99 retval = usb_register(&generic_driver);
100 if (retval)
101 usb_serial_deregister(&usb_serial_generic_device);
102exit:
103#endif
104 return retval;
105}
106
Alan Coxae643872008-07-22 11:11:55 +0100107void usb_serial_generic_deregister(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
109#ifdef CONFIG_USB_SERIAL_GENERIC
110 /* remove our generic driver */
111 usb_deregister(&generic_driver);
Alan Coxae643872008-07-22 11:11:55 +0100112 usb_serial_deregister(&usb_serial_generic_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#endif
114}
115
Alan Cox95da3102008-07-22 11:09:07 +0100116int usb_serial_generic_open(struct tty_struct *tty,
117 struct usb_serial_port *port, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 struct usb_serial *serial = port->serial;
120 int result = 0;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100121 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Harvey Harrison441b62c2008-03-03 16:08:34 -0800123 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Alan Coxae643872008-07-22 11:11:55 +0100125 /* force low_latency on so that our tty_push actually forces the data
126 through, otherwise it is scheduled, and with high data rates (like
127 with OHCI) data can get lost. */
Alan Cox95da3102008-07-22 11:09:07 +0100128 if (tty)
129 tty->low_latency = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100131 /* clear the throttle flags */
132 spin_lock_irqsave(&port->lock, flags);
133 port->throttled = 0;
134 port->throttle_req = 0;
135 spin_unlock_irqrestore(&port->lock, flags);
136
137 /* if we have a bulk endpoint, start reading from it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if (serial->num_bulk_in) {
139 /* Start reading from the device */
Alan Coxae643872008-07-22 11:11:55 +0100140 usb_fill_bulk_urb(port->read_urb, serial->dev,
141 usb_rcvbulkpipe(serial->dev,
142 port->bulk_in_endpointAddress),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 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)
Alan Coxae643872008-07-22 11:11:55 +0100151 dev_err(&port->dev,
152 "%s - failed resubmitting read urb, error %d\n",
153 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
156 return result;
157}
Greg Kroah-Hartman815ddc92006-05-12 11:05:29 -0700158EXPORT_SYMBOL_GPL(usb_serial_generic_open);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Alan Cox95da3102008-07-22 11:09:07 +0100160static void generic_cleanup(struct usb_serial_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
162 struct usb_serial *serial = port->serial;
163
Harvey Harrison441b62c2008-03-03 16:08:34 -0800164 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 if (serial->dev) {
167 /* shutdown any bulk reads that might be going on */
168 if (serial->num_bulk_out)
169 usb_kill_urb(port->write_urb);
170 if (serial->num_bulk_in)
171 usb_kill_urb(port->read_urb);
172 }
173}
174
Oliver Neukumec225592007-04-27 20:54:57 +0200175int usb_serial_generic_resume(struct usb_serial *serial)
176{
177 struct usb_serial_port *port;
178 int i, c = 0, r;
179
180 for (i = 0; i < serial->num_ports; i++) {
181 port = serial->port[i];
Alan Cox95da3102008-07-22 11:09:07 +0100182 if (port->port.count && port->read_urb) {
Oliver Neukumec225592007-04-27 20:54:57 +0200183 r = usb_submit_urb(port->read_urb, GFP_NOIO);
184 if (r < 0)
185 c++;
186 }
187 }
188
189 return c ? -EIO : 0;
190}
191
Alan Cox95da3102008-07-22 11:09:07 +0100192void usb_serial_generic_close(struct tty_struct *tty,
Alan Coxae643872008-07-22 11:11:55 +0100193 struct usb_serial_port *port, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800195 dbg("%s - port %d", __func__, port->number);
Alan Coxae643872008-07-22 11:11:55 +0100196 generic_cleanup(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197}
198
Alan Cox95da3102008-07-22 11:09:07 +0100199int usb_serial_generic_write(struct tty_struct *tty,
200 struct usb_serial_port *port, const unsigned char *buf, int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
202 struct usb_serial *serial = port->serial;
203 int result;
204 unsigned char *data;
205
Harvey Harrison441b62c2008-03-03 16:08:34 -0800206 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 if (count == 0) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800209 dbg("%s - write request of 0 bytes", __func__);
Alan Coxae643872008-07-22 11:11:55 +0100210 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
212
213 /* only do something if we have a bulk out endpoint */
214 if (serial->num_bulk_out) {
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200215 unsigned long flags;
216 spin_lock_irqsave(&port->lock, flags);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700217 if (port->write_urb_busy) {
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200218 spin_unlock_irqrestore(&port->lock, flags);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800219 dbg("%s - already writing", __func__);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700220 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700222 port->write_urb_busy = 1;
Jiri Kosinaacd2a842007-10-20 00:05:19 +0200223 spin_unlock_irqrestore(&port->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Alan Coxae643872008-07-22 11:11:55 +0100225 count = (count > port->bulk_out_size) ?
226 port->bulk_out_size : count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
Alan Coxae643872008-07-22 11:11:55 +0100228 memcpy(port->write_urb->transfer_buffer, buf, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 data = port->write_urb->transfer_buffer;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800230 usb_serial_debug_data(debug, &port->dev, __func__, count, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 /* set up our urb */
Alan Coxae643872008-07-22 11:11:55 +0100233 usb_fill_bulk_urb(port->write_urb, serial->dev,
234 usb_sndbulkpipe(serial->dev,
235 port->bulk_out_endpointAddress),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 port->write_urb->transfer_buffer, count,
Alan Coxae643872008-07-22 11:11:55 +0100237 ((serial->type->write_bulk_callback) ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 serial->type->write_bulk_callback :
Alan Coxae643872008-07-22 11:11:55 +0100239 usb_serial_generic_write_bulk_callback),
240 port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /* send the data out the bulk port */
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700243 port->write_urb_busy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700245 if (result) {
Alan Coxae643872008-07-22 11:11:55 +0100246 dev_err(&port->dev,
247 "%s - failed submitting write urb, error %d\n",
248 __func__, result);
249 /* don't have to grab the lock here, as we will
250 retry if != 0 */
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700251 port->write_urb_busy = 0;
252 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 result = count;
254
255 return result;
256 }
257
258 /* no bulk out, so return 0 bytes written */
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700259 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Alan Coxae643872008-07-22 11:11:55 +0100262int usb_serial_generic_write_room(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Alan Cox95da3102008-07-22 11:09:07 +0100264 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 struct usb_serial *serial = port->serial;
266 int room = 0;
267
Harvey Harrison441b62c2008-03-03 16:08:34 -0800268 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700269
Alan Coxa5b6f602008-04-08 17:16:06 +0100270 /* FIXME: Locking */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (serial->num_bulk_out) {
Randall Nortman7a3ca7d2005-10-14 17:21:50 -0700272 if (!(port->write_urb_busy))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 room = port->bulk_out_size;
274 }
275
Harvey Harrison441b62c2008-03-03 16:08:34 -0800276 dbg("%s - returns %d", __func__, room);
Alan Coxa5b6f602008-04-08 17:16:06 +0100277 return room;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
Alan Cox95da3102008-07-22 11:09:07 +0100280int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Alan Cox95da3102008-07-22 11:09:07 +0100282 struct usb_serial_port *port = tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 struct usb_serial *serial = port->serial;
284 int chars = 0;
285
Harvey Harrison441b62c2008-03-03 16:08:34 -0800286 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Alan Coxa5b6f602008-04-08 17:16:06 +0100288 /* FIXME: Locking */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 if (serial->num_bulk_out) {
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700290 if (port->write_urb_busy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 chars = port->write_urb->transfer_buffer_length;
292 }
293
Harvey Harrison441b62c2008-03-03 16:08:34 -0800294 dbg("%s - returns %d", __func__, chars);
Alan Cox95da3102008-07-22 11:09:07 +0100295 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200298
299static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300{
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100301 struct urb *urb = port->read_urb;
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200302 struct usb_serial *serial = port->serial;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 int result;
304
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100305 /* Continue reading from device */
Alan Coxae643872008-07-22 11:11:55 +0100306 usb_fill_bulk_urb(urb, serial->dev,
307 usb_rcvbulkpipe(serial->dev,
308 port->bulk_in_endpointAddress),
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200309 urb->transfer_buffer,
310 urb->transfer_buffer_length,
Alan Coxae643872008-07-22 11:11:55 +0100311 ((serial->type->read_bulk_callback) ?
312 serial->type->read_bulk_callback :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 usb_serial_generic_read_bulk_callback), port);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200314 result = usb_submit_urb(urb, mem_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 if (result)
Alan Coxae643872008-07-22 11:11:55 +0100316 dev_err(&port->dev,
317 "%s - failed resubmitting read urb, error %d\n",
318 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100320
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200321/* Push data to tty layer and resubmit the bulk read URB */
Alan Cox95da3102008-07-22 11:09:07 +0100322static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200323{
324 struct urb *urb = port->read_urb;
Alan Cox4a90f092008-10-13 10:39:46 +0100325 struct tty_struct *tty = tty_port_tty_get(&port->port);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200326 int room;
327
328 /* Push data to tty */
329 if (tty && urb->actual_length) {
330 room = tty_buffer_request_room(tty, urb->actual_length);
331 if (room) {
332 tty_insert_flip_string(tty, urb->transfer_buffer, room);
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800333 tty_flip_buffer_push(tty);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200334 }
335 }
Alan Cox4a90f092008-10-13 10:39:46 +0100336 tty_kref_put(tty);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200337
338 resubmit_read_urb(port, GFP_ATOMIC);
339}
340
Alan Cox95da3102008-07-22 11:09:07 +0100341void usb_serial_generic_read_bulk_callback(struct urb *urb)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100342{
Ming Leicdc97792008-02-24 18:41:47 +0800343 struct usb_serial_port *port = urb->context;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100344 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700345 int status = urb->status;
Borislav Petkovbfaeafc2007-10-28 13:24:16 +0100346 unsigned long flags;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100347
Harvey Harrison441b62c2008-03-03 16:08:34 -0800348 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100349
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700350 if (unlikely(status != 0)) {
351 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800352 __func__, status);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100353 return;
354 }
355
Alan Coxae643872008-07-22 11:11:55 +0100356 usb_serial_debug_data(debug, &port->dev, __func__,
357 urb->actual_length, data);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100358
359 /* Throttle the device if requested by tty */
Borislav Petkovbfaeafc2007-10-28 13:24:16 +0100360 spin_lock_irqsave(&port->lock, flags);
Alan Coxae643872008-07-22 11:11:55 +0100361 port->throttled = port->throttle_req;
362 if (!port->throttled) {
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800363 spin_unlock_irqrestore(&port->lock, flags);
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200364 flush_and_resubmit_read_urb(port);
Alan Coxae643872008-07-22 11:11:55 +0100365 } else
Pete Zaitcevb507cc92008-03-04 23:28:42 -0800366 spin_unlock_irqrestore(&port->lock, flags);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100367}
Luiz Fernando N. Capitulino166ffcc2006-07-11 14:19:25 -0300368EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Alan Cox95da3102008-07-22 11:09:07 +0100370void usb_serial_generic_write_bulk_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Ming Leicdc97792008-02-24 18:41:47 +0800372 struct usb_serial_port *port = urb->context;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700373 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Harvey Harrison441b62c2008-03-03 16:08:34 -0800375 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700377 port->write_urb_busy = 0;
Greg Kroah-Hartmanfbd272252007-06-15 15:44:13 -0700378 if (status) {
379 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800380 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return;
382 }
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700383 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
Greg Kroah-Hartmanbb833982005-11-17 09:48:18 -0800385EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Alan Cox95da3102008-07-22 11:09:07 +0100387void usb_serial_generic_throttle(struct tty_struct *tty)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100388{
Alan Cox95da3102008-07-22 11:09:07 +0100389 struct usb_serial_port *port = tty->driver_data;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100390 unsigned long flags;
391
Harvey Harrison441b62c2008-03-03 16:08:34 -0800392 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100393
394 /* Set the throttle request flag. It will be picked up
395 * by usb_serial_generic_read_bulk_callback(). */
396 spin_lock_irqsave(&port->lock, flags);
397 port->throttle_req = 1;
398 spin_unlock_irqrestore(&port->lock, flags);
399}
400
Alan Cox95da3102008-07-22 11:09:07 +0100401void usb_serial_generic_unthrottle(struct tty_struct *tty)
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100402{
Alan Cox95da3102008-07-22 11:09:07 +0100403 struct usb_serial_port *port = tty->driver_data;
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100404 int was_throttled;
405 unsigned long flags;
406
Harvey Harrison441b62c2008-03-03 16:08:34 -0800407 dbg("%s - port %d", __func__, port->number);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100408
409 /* Clear the throttle flags */
410 spin_lock_irqsave(&port->lock, flags);
411 was_throttled = port->throttled;
412 port->throttled = port->throttle_req = 0;
413 spin_unlock_irqrestore(&port->lock, flags);
414
415 if (was_throttled) {
Oliver Neukum1abdeeb2007-05-07 12:09:33 +0200416 /* Resume reading from device */
417 resubmit_read_urb(port, GFP_KERNEL);
Joris van Rantwijk253ca922007-02-01 20:08:18 +0100418 }
419}
420
Alan Coxae643872008-07-22 11:11:55 +0100421void usb_serial_generic_shutdown(struct usb_serial *serial)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
423 int i;
424
Harvey Harrison441b62c2008-03-03 16:08:34 -0800425 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 /* stop reads and writes on all ports */
Alan Coxae643872008-07-22 11:11:55 +0100428 for (i = 0; i < serial->num_ports; ++i)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 generic_cleanup(serial->port[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431