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); |
Johan Hovold | b58af40 | 2010-08-04 15:45:57 +0200 | [diff] [blame] | 211 | spin_lock_irqsave(&port->lock, flags); |
| 212 | port->tx_bytes += count; |
| 213 | spin_unlock_irqrestore(&port->lock, flags); |
| 214 | |
| 215 | clear_bit(i, &port->write_urbs_free); |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 216 | result = usb_submit_urb(urb, GFP_ATOMIC); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 217 | if (result) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 218 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 219 | __func__, result); |
Johan Hovold | b58af40 | 2010-08-04 15:45:57 +0200 | [diff] [blame] | 220 | set_bit(i, &port->write_urbs_free); |
| 221 | spin_lock_irqsave(&port->lock, flags); |
| 222 | port->tx_bytes -= count; |
| 223 | spin_unlock_irqrestore(&port->lock, flags); |
| 224 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 225 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 226 | return result; |
| 227 | } |
Johan Hovold | 30af7fb | 2010-03-17 23:00:42 +0100 | [diff] [blame] | 228 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 229 | /* Try sending off another urb, unless in irq context (in which case |
| 230 | * there will be no free urb). */ |
| 231 | if (!in_irq()) |
| 232 | goto retry; |
| 233 | |
| 234 | clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); |
| 235 | |
| 236 | return 0; |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | /** |
| 240 | * usb_serial_generic_write - generic write function for serial USB devices |
| 241 | * @tty: Pointer to &struct tty_struct for the device |
| 242 | * @port: Pointer to the &usb_serial_port structure for the device |
| 243 | * @buf: Pointer to the data to write |
| 244 | * @count: Number of bytes to write |
| 245 | * |
| 246 | * Returns the number of characters actually written, which may be anything |
| 247 | * from zero to @count. If an error occurs, it returns the negative errno |
| 248 | * value. |
| 249 | */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 250 | int usb_serial_generic_write(struct tty_struct *tty, |
| 251 | struct usb_serial_port *port, const unsigned char *buf, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | int result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 255 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 257 | /* only do something if we have a bulk out endpoint */ |
| 258 | if (!port->bulk_out_size) |
| 259 | return -ENODEV; |
| 260 | |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 261 | if (!count) |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 262 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Stefani Seibold | 119eecc | 2009-12-23 09:10:48 +0100 | [diff] [blame] | 264 | count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 265 | result = usb_serial_generic_write_start(port); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 266 | if (result) |
| 267 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 269 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 271 | EXPORT_SYMBOL_GPL(usb_serial_generic_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 273 | int usb_serial_generic_write_room(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 275 | struct usb_serial_port *port = tty->driver_data; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 276 | unsigned long flags; |
Johan Hovold | 25d514c | 2010-03-17 23:06:07 +0100 | [diff] [blame] | 277 | int room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 279 | dbg("%s - port %d", __func__, port->number); |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 280 | |
| 281 | if (!port->bulk_out_size) |
| 282 | return 0; |
| 283 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 284 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 285 | room = kfifo_avail(&port->write_fifo); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 286 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 288 | dbg("%s - returns %d", __func__, room); |
Alan Cox | a5b6f60 | 2008-04-08 17:16:06 +0100 | [diff] [blame] | 289 | return room; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 292 | int usb_serial_generic_chars_in_buffer(struct tty_struct *tty) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 294 | struct usb_serial_port *port = tty->driver_data; |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 295 | unsigned long flags; |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 296 | int chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 298 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
Johan Hovold | eb8878a | 2010-02-27 16:24:49 +0100 | [diff] [blame] | 300 | if (!port->bulk_out_size) |
| 301 | return 0; |
| 302 | |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 303 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 304 | chars = kfifo_len(&port->write_fifo) + port->tx_bytes; |
Stefani Seibold | 25719e6b | 2010-01-05 14:30:31 +0100 | [diff] [blame] | 305 | spin_unlock_irqrestore(&port->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 307 | dbg("%s - returns %d", __func__, chars); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 308 | return chars; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 311 | int usb_serial_generic_submit_read_urb(struct usb_serial_port *port, |
| 312 | gfp_t mem_flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | int result; |
| 315 | |
Johan Hovold | 056afc0 | 2010-03-17 23:05:54 +0100 | [diff] [blame] | 316 | result = usb_submit_urb(port->read_urb, mem_flags); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 317 | if (result && result != -EPERM) { |
Johan Hovold | 1a1405e | 2010-03-17 23:06:01 +0100 | [diff] [blame] | 318 | dev_err(&port->dev, "%s - error submitting urb: %d\n", |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 319 | __func__, result); |
Johan Hovold | 0ae1474 | 2010-02-27 14:05:46 +0100 | [diff] [blame] | 320 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 321 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
Johan Hovold | 41bd72f | 2010-03-17 23:05:53 +0100 | [diff] [blame] | 323 | EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 324 | |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 325 | void usb_serial_generic_process_read_urb(struct urb *urb) |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 326 | { |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 327 | struct usb_serial_port *port = urb->context; |
| 328 | struct tty_struct *tty; |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 329 | char *ch = (char *)urb->transfer_buffer; |
| 330 | int i; |
| 331 | |
Johan Hovold | 56a1df4 | 2010-05-15 17:53:44 +0200 | [diff] [blame] | 332 | if (!urb->actual_length) |
| 333 | return; |
| 334 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 335 | tty = tty_port_tty_get(&port->port); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 336 | if (!tty) |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 337 | return; |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 338 | |
Alan Cox | 4cd1de0a | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 339 | /* The per character mucking around with sysrq path it too slow for |
| 340 | stuff like 3G modems, so shortcircuit it in the 99.9999999% of cases |
| 341 | where the USB serial is not a console anyway */ |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 342 | if (!port->port.console || !port->sysrq) |
Alan Cox | 4cd1de0a | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 343 | tty_insert_flip_string(tty, ch, urb->actual_length); |
| 344 | else { |
Alan Cox | 4cd1de0a | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 345 | for (i = 0; i < urb->actual_length; i++, ch++) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 346 | if (!usb_serial_handle_sysrq_char(tty, port, *ch)) |
Alan Cox | 4cd1de0a | 2009-07-09 13:35:52 +0100 | [diff] [blame] | 347 | tty_insert_flip_char(tty, *ch, TTY_NORMAL); |
| 348 | } |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 349 | } |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 350 | tty_flip_buffer_push(tty); |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 351 | tty_kref_put(tty); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 352 | } |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 353 | EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb); |
Oliver Neukum | 1abdeeb | 2007-05-07 12:09:33 +0200 | [diff] [blame] | 354 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 355 | void usb_serial_generic_read_bulk_callback(struct urb *urb) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 356 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 357 | struct usb_serial_port *port = urb->context; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 358 | unsigned char *data = urb->transfer_buffer; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 359 | int status = urb->status; |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 360 | unsigned long flags; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 361 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 362 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 363 | |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 364 | if (unlikely(status != 0)) { |
| 365 | dbg("%s - nonzero read bulk status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 366 | __func__, status); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 367 | return; |
| 368 | } |
| 369 | |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 370 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 371 | urb->actual_length, data); |
Johan Hovold | 2315432 | 2010-03-17 23:05:57 +0100 | [diff] [blame] | 372 | port->serial->type->process_read_urb(urb); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 373 | |
| 374 | /* Throttle the device if requested by tty */ |
Borislav Petkov | bfaeafc | 2007-10-28 13:24:16 +0100 | [diff] [blame] | 375 | spin_lock_irqsave(&port->lock, flags); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 376 | port->throttled = port->throttle_req; |
| 377 | if (!port->throttled) { |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 378 | spin_unlock_irqrestore(&port->lock, flags); |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 379 | usb_serial_generic_submit_read_urb(port, GFP_ATOMIC); |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 380 | } else |
Pete Zaitcev | b507cc9 | 2008-03-04 23:28:42 -0800 | [diff] [blame] | 381 | spin_unlock_irqrestore(&port->lock, flags); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 382 | } |
Luiz Fernando N. Capitulino | 166ffcc | 2006-07-11 14:19:25 -0300 | [diff] [blame] | 383 | EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 385 | void usb_serial_generic_write_bulk_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 387 | unsigned long flags; |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 388 | struct usb_serial_port *port = urb->context; |
Greg Kroah-Hartman | fbd27225 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 389 | int status = urb->status; |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 390 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 392 | dbg("%s - port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 394 | for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) |
| 395 | if (port->write_urbs[i] == urb) |
| 396 | break; |
| 397 | |
| 398 | spin_lock_irqsave(&port->lock, flags); |
| 399 | port->tx_bytes -= urb->transfer_buffer_length; |
| 400 | set_bit(i, &port->write_urbs_free); |
| 401 | spin_unlock_irqrestore(&port->lock, flags); |
| 402 | |
| 403 | if (status) { |
| 404 | dbg("%s - non-zero urb status: %d", __func__, status); |
Johan Hovold | 2591530 | 2010-01-06 15:48:42 -0800 | [diff] [blame] | 405 | |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 406 | spin_lock_irqsave(&port->lock, flags); |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 407 | kfifo_reset_out(&port->write_fifo); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 408 | spin_unlock_irqrestore(&port->lock, flags); |
| 409 | } else { |
Johan Hovold | c23e5fc | 2010-05-05 23:58:13 +0200 | [diff] [blame] | 410 | usb_serial_generic_write_start(port); |
Jason Wessel | 715b1dc | 2009-05-11 15:24:07 -0500 | [diff] [blame] | 411 | } |
| 412 | |
Pete Zaitcev | cf2c748 | 2006-05-22 21:58:49 -0700 | [diff] [blame] | 413 | usb_serial_port_softint(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
Greg Kroah-Hartman | bb83398 | 2005-11-17 09:48:18 -0800 | [diff] [blame] | 415 | EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 417 | void usb_serial_generic_throttle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 418 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 419 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 420 | unsigned long flags; |
| 421 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 422 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 423 | |
| 424 | /* Set the throttle request flag. It will be picked up |
| 425 | * by usb_serial_generic_read_bulk_callback(). */ |
| 426 | spin_lock_irqsave(&port->lock, flags); |
| 427 | port->throttle_req = 1; |
| 428 | spin_unlock_irqrestore(&port->lock, flags); |
| 429 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 430 | EXPORT_SYMBOL_GPL(usb_serial_generic_throttle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 431 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 432 | void usb_serial_generic_unthrottle(struct tty_struct *tty) |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 433 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 434 | struct usb_serial_port *port = tty->driver_data; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 435 | int was_throttled; |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 436 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 437 | dbg("%s - port %d", __func__, port->number); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 438 | |
| 439 | /* Clear the throttle flags */ |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 440 | spin_lock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 441 | was_throttled = port->throttled; |
| 442 | port->throttled = port->throttle_req = 0; |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 443 | spin_unlock_irq(&port->lock); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 444 | |
Johan Hovold | 0f3d5ba | 2010-03-17 23:05:56 +0100 | [diff] [blame] | 445 | if (was_throttled) |
| 446 | usb_serial_generic_submit_read_urb(port, GFP_KERNEL); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 447 | } |
Johan Hovold | f1e949a | 2010-03-17 23:05:59 +0100 | [diff] [blame] | 448 | EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle); |
Joris van Rantwijk | 253ca92 | 2007-02-01 20:08:18 +0100 | [diff] [blame] | 449 | |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 450 | #ifdef CONFIG_MAGIC_SYSRQ |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 451 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 452 | struct usb_serial_port *port, unsigned int ch) |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 453 | { |
Jason Wessel | bd5afa9 | 2010-03-08 21:50:12 -0600 | [diff] [blame] | 454 | if (port->sysrq && port->port.console) { |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 455 | if (ch && time_before(jiffies, port->sysrq)) { |
Alan Cox | 24a15a6 | 2009-07-09 13:36:22 +0100 | [diff] [blame] | 456 | handle_sysrq(ch, tty); |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 457 | port->sysrq = 0; |
| 458 | return 1; |
| 459 | } |
| 460 | port->sysrq = 0; |
| 461 | } |
| 462 | return 0; |
| 463 | } |
Randy Dunlap | 7f0ae3a | 2010-03-25 11:29:16 -0700 | [diff] [blame] | 464 | #else |
| 465 | int usb_serial_handle_sysrq_char(struct tty_struct *tty, |
| 466 | struct usb_serial_port *port, unsigned int ch) |
| 467 | { |
| 468 | return 0; |
| 469 | } |
| 470 | #endif |
Jason Wessel | 98fcb5f | 2009-05-11 15:24:09 -0500 | [diff] [blame] | 471 | EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char); |
| 472 | |
| 473 | int usb_serial_handle_break(struct usb_serial_port *port) |
| 474 | { |
| 475 | if (!port->sysrq) { |
| 476 | port->sysrq = jiffies + HZ*5; |
| 477 | return 1; |
| 478 | } |
| 479 | port->sysrq = 0; |
| 480 | return 0; |
| 481 | } |
| 482 | EXPORT_SYMBOL_GPL(usb_serial_handle_break); |
| 483 | |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 484 | int usb_serial_generic_resume(struct usb_serial *serial) |
| 485 | { |
| 486 | struct usb_serial_port *port; |
| 487 | int i, c = 0, r; |
| 488 | |
| 489 | for (i = 0; i < serial->num_ports; i++) { |
| 490 | port = serial->port[i]; |
Alan Stern | 1f87158 | 2010-02-17 10:05:47 -0500 | [diff] [blame] | 491 | if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 492 | continue; |
| 493 | |
| 494 | if (port->read_urb) { |
| 495 | r = usb_submit_urb(port->read_urb, GFP_NOIO); |
| 496 | if (r < 0) |
| 497 | c++; |
| 498 | } |
| 499 | |
Johan Hovold | 27c7acf | 2010-05-05 23:57:37 +0200 | [diff] [blame] | 500 | if (port->bulk_out_size) { |
David VomLehn | 8e8dce0 | 2009-08-28 12:54:27 -0700 | [diff] [blame] | 501 | r = usb_serial_generic_write_start(port); |
| 502 | if (r < 0) |
| 503 | c++; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | return c ? -EIO : 0; |
| 508 | } |
| 509 | EXPORT_SYMBOL_GPL(usb_serial_generic_resume); |
| 510 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 511 | void usb_serial_generic_disconnect(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | { |
| 513 | int i; |
| 514 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 515 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
| 517 | /* stop reads and writes on all ports */ |
Alan Cox | ae64387 | 2008-07-22 11:11:55 +0100 | [diff] [blame] | 518 | for (i = 0; i < serial->num_ports; ++i) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | generic_cleanup(serial->port[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 522 | void usb_serial_generic_release(struct usb_serial *serial) |
| 523 | { |
| 524 | dbg("%s", __func__); |
| 525 | } |