Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * USB Serial Converter Generic functions |
| 3 | * |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 4 | * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License version |
| 9 | * 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/slab.h> |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 16 | #include <linux/sysrq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/tty.h> |
| 18 | #include <linux/tty_flip.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
| 21 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 22 | #include <linux/usb/serial.h> |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 24 | #include <linux/kfifo.h> |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 25 | #include <linux/serial.h> |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int debug; |
| 28 | |
| 29 | #ifdef CONFIG_USB_SERIAL_GENERIC |
David Brownell | b46d60f | 2007-03-23 12:51:55 -0700 | [diff] [blame] | 30 | |
| 31 | static int generic_probe(struct usb_interface *interface, |
| 32 | const struct usb_device_id *id); |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static __u16 vendor = 0x05f9; |
| 35 | static __u16 product = 0xffff; |
| 36 | |
| 37 | module_param(vendor, ushort, 0); |
| 38 | MODULE_PARM_DESC(vendor, "User specified USB idVendor"); |
| 39 | |
| 40 | module_param(product, ushort, 0); |
| 41 | MODULE_PARM_DESC(product, "User specified USB idProduct"); |
| 42 | |
| 43 | static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */ |
| 44 | |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 45 | /* we want to look at all devices, as the vendor/product id can change |
| 46 | * depending on the command line argument */ |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 47 | static const struct usb_device_id generic_serial_ids[] = { |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 48 | {.driver_info = 42}, |
| 49 | {} |
| 50 | }; |
| 51 | |
| 52 | static struct usb_driver generic_driver = { |
| 53 | .name = "usbserial_generic", |
| 54 | .probe = generic_probe, |
| 55 | .disconnect = usb_serial_disconnect, |
| 56 | .id_table = generic_serial_ids, |
| 57 | .no_dynamic_id = 1, |
| 58 | }; |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* All of the device info needed for the Generic Serial Converter */ |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 61 | struct usb_serial_driver usb_serial_generic_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 62 | .driver = { |
| 63 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 64 | .name = "generic", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 65 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | .id_table = generic_device_ids, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 67 | .usb_driver = &generic_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | .num_ports = 1, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 69 | .disconnect = usb_serial_generic_disconnect, |
| 70 | .release = usb_serial_generic_release, |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 71 | .throttle = usb_serial_generic_throttle, |
| 72 | .unthrottle = usb_serial_generic_unthrottle, |
Oliver Neukum | ec22559 | 2007-04-27 20:54:57 +0200 | [diff] [blame] | 73 | .resume = usb_serial_generic_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static int generic_probe(struct usb_interface *interface, |
| 77 | const struct usb_device_id *id) |
| 78 | { |
| 79 | const struct usb_device_id *id_pattern; |
| 80 | |
| 81 | id_pattern = usb_match_id(interface, generic_device_ids); |
| 82 | if (id_pattern != NULL) |
| 83 | return usb_serial_probe(interface, id); |
| 84 | return -ENODEV; |
| 85 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #endif |
| 87 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 88 | int usb_serial_generic_register(int _debug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | int retval = 0; |
| 91 | |
| 92 | debug = _debug; |
| 93 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 94 | generic_device_ids[0].idVendor = vendor; |
| 95 | generic_device_ids[0].idProduct = product; |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 96 | generic_device_ids[0].match_flags = |
| 97 | USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* register our generic driver with ourselves */ |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 100 | retval = usb_serial_register(&usb_serial_generic_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | if (retval) |
| 102 | goto exit; |
| 103 | retval = usb_register(&generic_driver); |
| 104 | if (retval) |
| 105 | usb_serial_deregister(&usb_serial_generic_device); |
| 106 | exit: |
| 107 | #endif |
| 108 | return retval; |
| 109 | } |
| 110 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 111 | void usb_serial_generic_deregister(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | { |
| 113 | #ifdef CONFIG_USB_SERIAL_GENERIC |
| 114 | /* remove our generic driver */ |
| 115 | usb_deregister(&generic_driver); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 116 | usb_serial_deregister(&usb_serial_generic_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #endif |
| 118 | } |
| 119 | |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 120 | int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | int result = 0; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 123 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 125 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 127 | /* clear the throttle flags */ |
| 128 | spin_lock_irqsave(&port->lock, flags); |
| 129 | port->throttled = 0; |
| 130 | port->throttle_req = 0; |
| 131 | spin_unlock_irqrestore(&port->lock, flags); |
| 132 | |
| 133 | /* if we have a bulk endpoint, start reading from it */ |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 134 | if (port->bulk_in_size) |
| 135 | result = usb_serial_generic_submit_read_urb(port, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | return result; |
| 138 | } |
Greg Kroah-Hartman | 815ddc9 | 2006-05-12 11:05:29 -0700 | [diff] [blame] | 139 | EXPORT_SYMBOL_GPL(usb_serial_generic_open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 141 | static void generic_cleanup(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct usb_serial *serial = port->serial; |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 144 | unsigned long flags; |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 145 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 147 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | if (serial->dev) { |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 150 | /* shutdown any bulk transfers that might be going on */ |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 151 | if (port->bulk_out_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | usb_kill_urb(port->write_urb); |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 153 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) |
| 154 | usb_kill_urb(port->write_urbs[i]); |
Johan Hovold | ec3ee50 | 2010-03-17 23:00:44 +0100 | [diff] [blame] | 155 | |
| 156 | spin_lock_irqsave(&port->lock, flags); |
| 157 | kfifo_reset_out(&port->write_fifo); |
| 158 | spin_unlock_irqrestore(&port->lock, flags); |
| 159 | } |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 160 | if (port->bulk_in_size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | usb_kill_urb(port->read_urb); |
| 162 | } |
| 163 | } |
| 164 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 165 | void usb_serial_generic_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 167 | dbg("%s - port %d", __func__, port->number); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 168 | generic_cleanup(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
Johan Hovold | f26788d | 2010-03-17 23:00:45 +0100 | [diff] [blame] | 170 | EXPORT_SYMBOL_GPL(usb_serial_generic_close); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame] | 172 | int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port, |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 173 | void *dest, size_t size) |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame] | 174 | { |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 175 | return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 176 | } |
| 177 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 178 | /** |
| 179 | * usb_serial_generic_write_start - kick off an URB write |
| 180 | * @port: Pointer to the &struct usb_serial_port data |
| 181 | * |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 182 | * Returns zero on success, or a negative errno value |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 183 | */ |
| 184 | static int usb_serial_generic_write_start(struct usb_serial_port *port) |
| 185 | { |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 186 | struct urb *urb; |
| 187 | int count, result; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 188 | unsigned long flags; |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 189 | int i; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 190 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 191 | if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags)) |
| 192 | return 0; |
| 193 | retry: |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 194 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 195 | if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) { |
| 196 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
Johan Hovold | 50a5f70 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 197 | spin_unlock_irqrestore(&port->lock, flags); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 198 | return 0; |
Johan Hovold | 50a5f70 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 199 | } |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 200 | i = (int)find_first_bit(&port->write_urbs_free, |
| 201 | ARRAY_SIZE(port->write_urbs)); |
Johan Hovold | 50a5f70 | 2010-03-17 23:06:02 +0100 | [diff] [blame] | 202 | spin_unlock_irqrestore(&port->lock, flags); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 203 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 204 | urb = port->write_urbs[i]; |
Johan Hovold | eaa3bcb | 2010-03-17 23:06:08 +0100 | [diff] [blame] | 205 | count = port->serial->type->prepare_write_buffer(port, |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 206 | urb->transfer_buffer, |
| 207 | port->bulk_out_size); |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 208 | urb->transfer_buffer_length = count; |
| 209 | usb_serial_debug_data(debug, &port->dev, __func__, count, |
| 210 | urb->transfer_buffer); |
| 211 | result = usb_submit_urb(urb, GFP_ATOMIC); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 212 | if (result) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 213 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 214 | __func__, result); |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 215 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 216 | return result; |
| 217 | } |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 218 | clear_bit(i, &port->write_urbs_free); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 219 | |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 220 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 221 | port->tx_bytes += count; |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 222 | spin_unlock_irqrestore(&port->lock, flags); |
| 223 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 224 | /* Try sending off another urb, unless in irq context (in which case |
| 225 | * there will be no free urb). */ |
| 226 | if (!in_irq()) |
| 227 | goto retry; |
| 228 | |
| 229 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
| 230 | |
| 231 | return 0; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
| 235 | * usb_serial_generic_write - generic write function for serial USB devices |
| 236 | * @tty: Pointer to &struct tty_struct for the device |
| 237 | * @port: Pointer to the &usb_serial_port structure for the device |
| 238 | * @buf: Pointer to the data to write |
| 239 | * @count: Number of bytes to write |
| 240 | * |
| 241 | * Returns the number of characters actually written, which may be anything |
| 242 | * from zero to @count. If an error occurs, it returns the negative errno |
| 243 | * value. |
| 244 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 245 | int usb_serial_generic_write(struct tty_struct *tty, |
| 246 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 250 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 252 | /* only do something if we have a bulk out endpoint */ |
| 253 | if (!port->bulk_out_size) |
| 254 | return -ENODEV; |
| 255 | |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 256 | if (!count) |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 257 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Stefani Seibold | 119eecc | 2009-12-23 09:10:48 +0100 | [diff] [blame] | 259 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 260 | result = usb_serial_generic_write_start(port); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 261 | if (result) |
| 262 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 264 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 266 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 268 | int usb_serial_generic_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 270 | struct usb_serial_port *port = tty->driver_data; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 271 | unsigned long flags; |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 272 | int room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 274 | dbg("%s - port %d", __func__, port->number); |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 275 | |
| 276 | if (!port->bulk_out_size) |
| 277 | return 0; |
| 278 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 279 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 280 | room = kfifo_avail(&port->write_fifo); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 281 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 283 | dbg("%s - returns %d", __func__, room); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 284 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 287 | int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 289 | struct usb_serial_port *port = tty->driver_data; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 290 | unsigned long flags; |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 291 | int chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 293 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 295 | if (!port->bulk_out_size) |
| 296 | return 0; |
| 297 | |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 298 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 299 | chars = kfifo_len(&port->write_fifo) + port->tx_bytes; |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 300 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 302 | dbg("%s - returns %d", __func__, chars); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 303 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 306 | int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, |
| 307 | gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | int result; |
| 310 | |
Johan Hovold | 056afc0 | 2010-03-17 23:05:54 +0100 | [diff] [blame] | 311 | result = usb_submit_urb(port->read_urb, mem_flags); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 312 | if (result && result != -EPERM) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 313 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 314 | __func__, result); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 315 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 316 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 318 | EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 319 | |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 320 | void usb_serial_generic_process_read_urb(struct urb *urb) |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 321 | { |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 322 | struct usb_serial_port *port = urb->context; |
| 323 | struct tty_struct *tty; |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 324 | char *ch = (char *)urb->transfer_buffer; |
| 325 | int i; |
| 326 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 327 | tty = tty_port_tty_get(&port->port); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 328 | if (!tty) |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 329 | return; |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 330 | |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 331 | /* The per character mucking around with sysrq path it too slow for |
| 332 | stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases |
| 333 | where the USB serial is not a console anyway */ |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 334 | if (!port->port.console || !port->sysrq) |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 335 | tty_insert_flip_string(tty, ch, urb->actual_length); |
| 336 | else { |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 337 | for (i = 0; i < urb->actual_length; i++, ch++) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 338 | if (!usb_serial_handle_sysrq_char(tty, port, *ch)) |
Alan Cox | 4cd1de0 | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 339 | tty_insert_flip_char(tty, *ch, TTY_NORMAL); |
| 340 | } |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 341 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 342 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 343 | tty_kref_put(tty); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 344 | } |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 345 | EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 346 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 347 | void usb_serial_generic_read_bulk_callback(struct urb *urb) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 348 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 349 | struct usb_serial_port *port = urb->context; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 350 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 351 | int status = urb->status; |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 352 | unsigned long flags; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 353 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 354 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 355 | |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 356 | if (unlikely(status != 0)) { |
| 357 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 358 | __func__, status); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 359 | return; |
| 360 | } |
| 361 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 362 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 363 | urb->actual_length, data); |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 364 | port->serial->type->process_read_urb(urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 365 | |
| 366 | /* Throttle the device if requested by tty */ |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 367 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 368 | port->throttled = port->throttle_req; |
| 369 | if (!port->throttled) { |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 370 | spin_unlock_irqrestore(&port->lock, flags); |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 371 | usb_serial_generic_submit_read_urb(port, GFP_ATOMIC); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 372 | } else |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 373 | spin_unlock_irqrestore(&port->lock, flags); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 374 | } |
Luiz Fernando N. Capitulino | 166ffcc | 2006-07-11 14:19:25 -0300 | [diff] [blame] | 375 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 377 | void usb_serial_generic_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 379 | unsigned long flags; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 380 | struct usb_serial_port *port = urb->context; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 381 | int status = urb->status; |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 382 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 384 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 386 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) |
| 387 | if (port->write_urbs[i] == urb) |
| 388 | break; |
| 389 | |
| 390 | spin_lock_irqsave(&port->lock, flags); |
| 391 | port->tx_bytes -= urb->transfer_buffer_length; |
| 392 | set_bit(i, &port->write_urbs_free); |
| 393 | spin_unlock_irqrestore(&port->lock, flags); |
| 394 | |
| 395 | if (status) { |
| 396 | dbg("%s - non-zero urb status: %d", __func__, status); |
Johan Hovold | 2591530 | 2010-01-06 15:48:42 -0800 | [diff] [blame] | 397 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 398 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 399 | kfifo_reset_out(&port->write_fifo); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 400 | spin_unlock_irqrestore(&port->lock, flags); |
| 401 | } else { |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame^] | 402 | usb_serial_generic_write_start(port); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 403 | } |
| 404 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 405 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
Greg Kroah-Hartman | bb83398 | 2005-11-17 09:48:18 -0800 | [diff] [blame] | 407 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 409 | void usb_serial_generic_throttle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 410 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 411 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 412 | unsigned long flags; |
| 413 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 414 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 415 | |
| 416 | /* Set the throttle request flag. It will be picked up |
| 417 | * by usb_serial_generic_read_bulk_callback(). */ |
| 418 | spin_lock_irqsave(&port->lock, flags); |
| 419 | port->throttle_req = 1; |
| 420 | spin_unlock_irqrestore(&port->lock, flags); |
| 421 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 422 | EXPORT_SYMBOL_GPL(usb_serial_generic_throttle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 423 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 424 | void usb_serial_generic_unthrottle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 425 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 426 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 427 | int was_throttled; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 428 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 429 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 430 | |
| 431 | /* Clear the throttle flags */ |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 432 | spin_lock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 433 | was_throttled = port->throttled; |
| 434 | port->throttled = port->throttle_req = 0; |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 435 | spin_unlock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 436 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 437 | if (was_throttled) |
| 438 | usb_serial_generic_submit_read_urb(port, GFP_KERNEL); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 439 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 440 | EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 441 | |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 442 | #ifdef CONFIG_MAGIC_SYSRQ |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 443 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 444 | struct usb_serial_port *port, unsigned int ch) |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 445 | { |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 446 | if (port->sysrq && port->port.console) { |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 447 | if (ch && time_before(jiffies, port->sysrq)) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 448 | handle_sysrq(ch, tty); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 449 | port->sysrq = 0; |
| 450 | return 1; |
| 451 | } |
| 452 | port->sysrq = 0; |
| 453 | } |
| 454 | return 0; |
| 455 | } |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 456 | #else |
| 457 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 458 | struct usb_serial_port *port, unsigned int ch) |
| 459 | { |
| 460 | return 0; |
| 461 | } |
| 462 | #endif |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 463 | EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); |
| 464 | |
| 465 | int usb_serial_handle_break(struct usb_serial_port *port) |
| 466 | { |
| 467 | if (!port->sysrq) { |
| 468 | port->sysrq = jiffies + HZ*5; |
| 469 | return 1; |
| 470 | } |
| 471 | port->sysrq = 0; |
| 472 | return 0; |
| 473 | } |
| 474 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
| 475 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 476 | int usb_serial_generic_resume(struct usb_serial *serial) |
| 477 | { |
| 478 | struct usb_serial_port *port; |
| 479 | int i, c = 0, r; |
| 480 | |
| 481 | for (i = 0; i < serial->num_ports; i++) { |
| 482 | port = serial->port[i]; |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 483 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 484 | continue; |
| 485 | |
| 486 | if (port->read_urb) { |
| 487 | r = usb_submit_urb(port->read_urb, GFP_NOIO); |
| 488 | if (r < 0) |
| 489 | c++; |
| 490 | } |
| 491 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 492 | if (port->bulk_out_size) { |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 493 | r = usb_serial_generic_write_start(port); |
| 494 | if (r < 0) |
| 495 | c++; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return c ? -EIO : 0; |
| 500 | } |
| 501 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); |
| 502 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 503 | void usb_serial_generic_disconnect(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | { |
| 505 | int i; |
| 506 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 507 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* stop reads and writes on all ports */ |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 510 | for (i = 0; i < serial->num_ports; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | generic_cleanup(serial->port[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 514 | void usb_serial_generic_release(struct usb_serial *serial) |
| 515 | { |
| 516 | dbg("%s", __func__); |
| 517 | } |