diff options
Diffstat (limited to 'drivers/usb/serial/usb-serial.c')
-rw-r--r-- | drivers/usb/serial/usb-serial.c | 387 |
1 files changed, 206 insertions, 181 deletions
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c index 353798631903..8c2d531eedea 100644 --- a/drivers/usb/serial/usb-serial.c +++ b/drivers/usb/serial/usb-serial.c | |||
@@ -12,7 +12,8 @@ | |||
12 | * This driver was originally based on the ACM driver by Armin Fuerst (which was | 12 | * This driver was originally based on the ACM driver by Armin Fuerst (which was |
13 | * based on a driver by Brad Keryan) | 13 | * based on a driver by Brad Keryan) |
14 | * | 14 | * |
15 | * See Documentation/usb/usb-serial.txt for more information on using this driver | 15 | * See Documentation/usb/usb-serial.txt for more information on using this |
16 | * driver | ||
16 | * | 17 | * |
17 | */ | 18 | */ |
18 | 19 | ||
@@ -28,7 +29,7 @@ | |||
28 | #include <linux/spinlock.h> | 29 | #include <linux/spinlock.h> |
29 | #include <linux/mutex.h> | 30 | #include <linux/mutex.h> |
30 | #include <linux/list.h> | 31 | #include <linux/list.h> |
31 | #include <asm/uaccess.h> | 32 | #include <linux/uaccess.h> |
32 | #include <linux/usb.h> | 33 | #include <linux/usb.h> |
33 | #include <linux/usb/serial.h> | 34 | #include <linux/usb/serial.h> |
34 | #include "pl2303.h" | 35 | #include "pl2303.h" |
@@ -59,7 +60,8 @@ static struct usb_driver usb_serial_driver = { | |||
59 | */ | 60 | */ |
60 | 61 | ||
61 | static int debug; | 62 | static int debug; |
62 | static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; /* initially all NULL */ | 63 | /* initially all NULL */ |
64 | static struct usb_serial *serial_table[SERIAL_TTY_MINORS]; | ||
63 | static DEFINE_MUTEX(table_lock); | 65 | static DEFINE_MUTEX(table_lock); |
64 | static LIST_HEAD(usb_serial_driver_list); | 66 | static LIST_HEAD(usb_serial_driver_list); |
65 | 67 | ||
@@ -76,7 +78,8 @@ struct usb_serial *usb_serial_get_by_index(unsigned index) | |||
76 | return serial; | 78 | return serial; |
77 | } | 79 | } |
78 | 80 | ||
79 | static struct usb_serial *get_free_serial (struct usb_serial *serial, int num_ports, unsigned int *minor) | 81 | static struct usb_serial *get_free_serial(struct usb_serial *serial, |
82 | int num_ports, unsigned int *minor) | ||
80 | { | 83 | { |
81 | unsigned int i, j; | 84 | unsigned int i, j; |
82 | int good_spot; | 85 | int good_spot; |
@@ -122,9 +125,8 @@ static void return_serial(struct usb_serial *serial) | |||
122 | if (serial == NULL) | 125 | if (serial == NULL) |
123 | return; | 126 | return; |
124 | 127 | ||
125 | for (i = 0; i < serial->num_ports; ++i) { | 128 | for (i = 0; i < serial->num_ports; ++i) |
126 | serial_table[serial->minor + i] = NULL; | 129 | serial_table[serial->minor + i] = NULL; |
127 | } | ||
128 | } | 130 | } |
129 | 131 | ||
130 | static void destroy_serial(struct kref *kref) | 132 | static void destroy_serial(struct kref *kref) |
@@ -143,7 +145,7 @@ static void destroy_serial(struct kref *kref) | |||
143 | return_serial(serial); | 145 | return_serial(serial); |
144 | 146 | ||
145 | for (i = 0; i < serial->num_ports; ++i) | 147 | for (i = 0; i < serial->num_ports; ++i) |
146 | serial->port[i]->open_count = 0; | 148 | serial->port[i]->port.count = 0; |
147 | 149 | ||
148 | /* the ports are cleaned up and released in port_release() */ | 150 | /* the ports are cleaned up and released in port_release() */ |
149 | for (i = 0; i < serial->num_ports; ++i) | 151 | for (i = 0; i < serial->num_ports; ++i) |
@@ -156,7 +158,8 @@ static void destroy_serial(struct kref *kref) | |||
156 | * not get cleaned up in port_release() as it was never registered with | 158 | * not get cleaned up in port_release() as it was never registered with |
157 | * the driver core */ | 159 | * the driver core */ |
158 | if (serial->num_ports < serial->num_port_pointers) { | 160 | if (serial->num_ports < serial->num_port_pointers) { |
159 | for (i = serial->num_ports; i < serial->num_port_pointers; ++i) { | 161 | for (i = serial->num_ports; |
162 | i < serial->num_port_pointers; ++i) { | ||
160 | port = serial->port[i]; | 163 | port = serial->port[i]; |
161 | if (!port) | 164 | if (!port) |
162 | continue; | 165 | continue; |
@@ -167,7 +170,7 @@ static void destroy_serial(struct kref *kref) | |||
167 | usb_put_dev(serial->dev); | 170 | usb_put_dev(serial->dev); |
168 | 171 | ||
169 | /* free up any memory that we allocated */ | 172 | /* free up any memory that we allocated */ |
170 | kfree (serial); | 173 | kfree(serial); |
171 | } | 174 | } |
172 | 175 | ||
173 | void usb_serial_put(struct usb_serial *serial) | 176 | void usb_serial_put(struct usb_serial *serial) |
@@ -180,13 +183,13 @@ void usb_serial_put(struct usb_serial *serial) | |||
180 | /***************************************************************************** | 183 | /***************************************************************************** |
181 | * Driver tty interface functions | 184 | * Driver tty interface functions |
182 | *****************************************************************************/ | 185 | *****************************************************************************/ |
183 | static int serial_open (struct tty_struct *tty, struct file * filp) | 186 | static int serial_open (struct tty_struct *tty, struct file *filp) |
184 | { | 187 | { |
185 | struct usb_serial *serial; | 188 | struct usb_serial *serial; |
186 | struct usb_serial_port *port; | 189 | struct usb_serial_port *port; |
187 | unsigned int portNumber; | 190 | unsigned int portNumber; |
188 | int retval; | 191 | int retval; |
189 | 192 | ||
190 | dbg("%s", __func__); | 193 | dbg("%s", __func__); |
191 | 194 | ||
192 | /* get the serial object associated with this tty pointer */ | 195 | /* get the serial object associated with this tty pointer */ |
@@ -207,15 +210,15 @@ static int serial_open (struct tty_struct *tty, struct file * filp) | |||
207 | retval = -ERESTARTSYS; | 210 | retval = -ERESTARTSYS; |
208 | goto bailout_kref_put; | 211 | goto bailout_kref_put; |
209 | } | 212 | } |
210 | 213 | ||
211 | ++port->open_count; | 214 | ++port->port.count; |
212 | 215 | ||
213 | /* set up our port structure making the tty driver | 216 | /* set up our port structure making the tty driver |
214 | * remember our port object, and us it */ | 217 | * remember our port object, and us it */ |
215 | tty->driver_data = port; | 218 | tty->driver_data = port; |
216 | port->tty = tty; | 219 | port->port.tty = tty; |
217 | 220 | ||
218 | if (port->open_count == 1) { | 221 | if (port->port.count == 1) { |
219 | 222 | ||
220 | /* lock this module before we call it | 223 | /* lock this module before we call it |
221 | * this may fail, which means we must bail out, | 224 | * this may fail, which means we must bail out, |
@@ -228,9 +231,9 @@ static int serial_open (struct tty_struct *tty, struct file * filp) | |||
228 | retval = usb_autopm_get_interface(serial->interface); | 231 | retval = usb_autopm_get_interface(serial->interface); |
229 | if (retval) | 232 | if (retval) |
230 | goto bailout_module_put; | 233 | goto bailout_module_put; |
231 | /* only call the device specific open if this | 234 | /* only call the device specific open if this |
232 | * is the first time the port is opened */ | 235 | * is the first time the port is opened */ |
233 | retval = serial->type->open(port, filp); | 236 | retval = serial->type->open(tty, port, filp); |
234 | if (retval) | 237 | if (retval) |
235 | goto bailout_interface_put; | 238 | goto bailout_interface_put; |
236 | } | 239 | } |
@@ -243,16 +246,16 @@ bailout_interface_put: | |||
243 | bailout_module_put: | 246 | bailout_module_put: |
244 | module_put(serial->type->driver.owner); | 247 | module_put(serial->type->driver.owner); |
245 | bailout_mutex_unlock: | 248 | bailout_mutex_unlock: |
246 | port->open_count = 0; | 249 | port->port.count = 0; |
247 | tty->driver_data = NULL; | 250 | tty->driver_data = NULL; |
248 | port->tty = NULL; | 251 | port->port.tty = NULL; |
249 | mutex_unlock(&port->mutex); | 252 | mutex_unlock(&port->mutex); |
250 | bailout_kref_put: | 253 | bailout_kref_put: |
251 | usb_serial_put(serial); | 254 | usb_serial_put(serial); |
252 | return retval; | 255 | return retval; |
253 | } | 256 | } |
254 | 257 | ||
255 | static void serial_close(struct tty_struct *tty, struct file * filp) | 258 | static void serial_close(struct tty_struct *tty, struct file *filp) |
256 | { | 259 | { |
257 | struct usb_serial_port *port = tty->driver_data; | 260 | struct usb_serial_port *port = tty->driver_data; |
258 | 261 | ||
@@ -263,26 +266,26 @@ static void serial_close(struct tty_struct *tty, struct file * filp) | |||
263 | 266 | ||
264 | mutex_lock(&port->mutex); | 267 | mutex_lock(&port->mutex); |
265 | 268 | ||
266 | if (port->open_count == 0) { | 269 | if (port->port.count == 0) { |
267 | mutex_unlock(&port->mutex); | 270 | mutex_unlock(&port->mutex); |
268 | return; | 271 | return; |
269 | } | 272 | } |
270 | 273 | ||
271 | --port->open_count; | 274 | --port->port.count; |
272 | if (port->open_count == 0) | 275 | if (port->port.count == 0) |
273 | /* only call the device specific close if this | 276 | /* only call the device specific close if this |
274 | * port is being closed by the last owner */ | 277 | * port is being closed by the last owner */ |
275 | port->serial->type->close(port, filp); | 278 | port->serial->type->close(tty, port, filp); |
276 | 279 | ||
277 | if (port->open_count == (port->console? 1 : 0)) { | 280 | if (port->port.count == (port->console? 1 : 0)) { |
278 | if (port->tty) { | 281 | if (port->port.tty) { |
279 | if (port->tty->driver_data) | 282 | if (port->port.tty->driver_data) |
280 | port->tty->driver_data = NULL; | 283 | port->port.tty->driver_data = NULL; |
281 | port->tty = NULL; | 284 | port->port.tty = NULL; |
282 | } | 285 | } |
283 | } | 286 | } |
284 | 287 | ||
285 | if (port->open_count == 0) { | 288 | if (port->port.count == 0) { |
286 | mutex_lock(&port->serial->disc_mutex); | 289 | mutex_lock(&port->serial->disc_mutex); |
287 | if (!port->serial->disconnected) | 290 | if (!port->serial->disconnected) |
288 | usb_autopm_put_interface(port->serial->interface); | 291 | usb_autopm_put_interface(port->serial->interface); |
@@ -294,7 +297,8 @@ static void serial_close(struct tty_struct *tty, struct file * filp) | |||
294 | usb_serial_put(port->serial); | 297 | usb_serial_put(port->serial); |
295 | } | 298 | } |
296 | 299 | ||
297 | static int serial_write (struct tty_struct * tty, const unsigned char *buf, int count) | 300 | static int serial_write(struct tty_struct *tty, const unsigned char *buf, |
301 | int count) | ||
298 | { | 302 | { |
299 | struct usb_serial_port *port = tty->driver_data; | 303 | struct usb_serial_port *port = tty->driver_data; |
300 | int retval = -ENODEV; | 304 | int retval = -ENODEV; |
@@ -304,107 +308,112 @@ static int serial_write (struct tty_struct * tty, const unsigned char *buf, int | |||
304 | 308 | ||
305 | dbg("%s - port %d, %d byte(s)", __func__, port->number, count); | 309 | dbg("%s - port %d, %d byte(s)", __func__, port->number, count); |
306 | 310 | ||
307 | /* open_count is managed under the mutex lock for the tty so cannot | 311 | /* count is managed under the mutex lock for the tty so cannot |
308 | drop to zero until after the last close completes */ | 312 | drop to zero until after the last close completes */ |
309 | WARN_ON(!port->open_count); | 313 | WARN_ON(!port->port.count); |
310 | 314 | ||
311 | /* pass on to the driver specific version of this function */ | 315 | /* pass on to the driver specific version of this function */ |
312 | retval = port->serial->type->write(port, buf, count); | 316 | retval = port->serial->type->write(tty, port, buf, count); |
313 | 317 | ||
314 | exit: | 318 | exit: |
315 | return retval; | 319 | return retval; |
316 | } | 320 | } |
317 | 321 | ||
318 | static int serial_write_room (struct tty_struct *tty) | 322 | static int serial_write_room(struct tty_struct *tty) |
319 | { | 323 | { |
320 | struct usb_serial_port *port = tty->driver_data; | 324 | struct usb_serial_port *port = tty->driver_data; |
321 | dbg("%s - port %d", __func__, port->number); | 325 | dbg("%s - port %d", __func__, port->number); |
322 | WARN_ON(!port->open_count); | 326 | WARN_ON(!port->port.count); |
323 | /* pass on to the driver specific version of this function */ | 327 | /* pass on to the driver specific version of this function */ |
324 | return port->serial->type->write_room(port); | 328 | return port->serial->type->write_room(tty); |
325 | } | 329 | } |
326 | 330 | ||
327 | static int serial_chars_in_buffer (struct tty_struct *tty) | 331 | static int serial_chars_in_buffer(struct tty_struct *tty) |
328 | { | 332 | { |
329 | struct usb_serial_port *port = tty->driver_data; | 333 | struct usb_serial_port *port = tty->driver_data; |
330 | dbg("%s = port %d", __func__, port->number); | 334 | dbg("%s = port %d", __func__, port->number); |
331 | 335 | ||
332 | WARN_ON(!port->open_count); | 336 | WARN_ON(!port->port.count); |
333 | /* pass on to the driver specific version of this function */ | 337 | /* pass on to the driver specific version of this function */ |
334 | return port->serial->type->chars_in_buffer(port); | 338 | return port->serial->type->chars_in_buffer(tty); |
335 | } | 339 | } |
336 | 340 | ||
337 | static void serial_throttle (struct tty_struct * tty) | 341 | static void serial_throttle(struct tty_struct *tty) |
338 | { | 342 | { |
339 | struct usb_serial_port *port = tty->driver_data; | 343 | struct usb_serial_port *port = tty->driver_data; |
340 | dbg("%s - port %d", __func__, port->number); | 344 | dbg("%s - port %d", __func__, port->number); |
341 | 345 | ||
342 | WARN_ON(!port->open_count); | 346 | WARN_ON(!port->port.count); |
343 | /* pass on to the driver specific version of this function */ | 347 | /* pass on to the driver specific version of this function */ |
344 | if (port->serial->type->throttle) | 348 | if (port->serial->type->throttle) |
345 | port->serial->type->throttle(port); | 349 | port->serial->type->throttle(tty); |
346 | } | 350 | } |
347 | 351 | ||
348 | static void serial_unthrottle (struct tty_struct * tty) | 352 | static void serial_unthrottle(struct tty_struct *tty) |
349 | { | 353 | { |
350 | struct usb_serial_port *port = tty->driver_data; | 354 | struct usb_serial_port *port = tty->driver_data; |
351 | dbg("%s - port %d", __func__, port->number); | 355 | dbg("%s - port %d", __func__, port->number); |
352 | 356 | ||
353 | WARN_ON(!port->open_count); | 357 | WARN_ON(!port->port.count); |
354 | /* pass on to the driver specific version of this function */ | 358 | /* pass on to the driver specific version of this function */ |
355 | if (port->serial->type->unthrottle) | 359 | if (port->serial->type->unthrottle) |
356 | port->serial->type->unthrottle(port); | 360 | port->serial->type->unthrottle(tty); |
357 | } | 361 | } |
358 | 362 | ||
359 | static int serial_ioctl (struct tty_struct *tty, struct file * file, unsigned int cmd, unsigned long arg) | 363 | static int serial_ioctl(struct tty_struct *tty, struct file *file, |
364 | unsigned int cmd, unsigned long arg) | ||
360 | { | 365 | { |
361 | struct usb_serial_port *port = tty->driver_data; | 366 | struct usb_serial_port *port = tty->driver_data; |
362 | int retval = -ENODEV; | 367 | int retval = -ENODEV; |
363 | 368 | ||
364 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); | 369 | dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd); |
365 | 370 | ||
366 | WARN_ON(!port->open_count); | 371 | WARN_ON(!port->port.count); |
367 | 372 | ||
368 | /* pass on to the driver specific version of this function if it is available */ | 373 | /* pass on to the driver specific version of this function |
374 | if it is available */ | ||
369 | if (port->serial->type->ioctl) { | 375 | if (port->serial->type->ioctl) { |
370 | lock_kernel(); | 376 | lock_kernel(); |
371 | retval = port->serial->type->ioctl(port, file, cmd, arg); | 377 | retval = port->serial->type->ioctl(tty, file, cmd, arg); |
372 | unlock_kernel(); | 378 | unlock_kernel(); |
373 | } | 379 | } else |
374 | else | ||
375 | retval = -ENOIOCTLCMD; | 380 | retval = -ENOIOCTLCMD; |
376 | return retval; | 381 | return retval; |
377 | } | 382 | } |
378 | 383 | ||
379 | static void serial_set_termios (struct tty_struct *tty, struct ktermios * old) | 384 | static void serial_set_termios(struct tty_struct *tty, struct ktermios *old) |
380 | { | 385 | { |
381 | struct usb_serial_port *port = tty->driver_data; | 386 | struct usb_serial_port *port = tty->driver_data; |
382 | dbg("%s - port %d", __func__, port->number); | 387 | dbg("%s - port %d", __func__, port->number); |
383 | 388 | ||
384 | WARN_ON(!port->open_count); | 389 | WARN_ON(!port->port.count); |
385 | /* pass on to the driver specific version of this function if it is available */ | 390 | /* pass on to the driver specific version of this function |
391 | if it is available */ | ||
386 | if (port->serial->type->set_termios) | 392 | if (port->serial->type->set_termios) |
387 | port->serial->type->set_termios(port, old); | 393 | port->serial->type->set_termios(tty, port, old); |
388 | else | 394 | else |
389 | tty_termios_copy_hw(tty->termios, old); | 395 | tty_termios_copy_hw(tty->termios, old); |
390 | } | 396 | } |
391 | 397 | ||
392 | static void serial_break (struct tty_struct *tty, int break_state) | 398 | static int serial_break(struct tty_struct *tty, int break_state) |
393 | { | 399 | { |
394 | struct usb_serial_port *port = tty->driver_data; | 400 | struct usb_serial_port *port = tty->driver_data; |
395 | 401 | ||
396 | dbg("%s - port %d", __func__, port->number); | 402 | dbg("%s - port %d", __func__, port->number); |
397 | 403 | ||
398 | WARN_ON(!port->open_count); | 404 | WARN_ON(!port->port.count); |
399 | /* pass on to the driver specific version of this function if it is available */ | 405 | /* pass on to the driver specific version of this function |
406 | if it is available */ | ||
400 | if (port->serial->type->break_ctl) { | 407 | if (port->serial->type->break_ctl) { |
401 | lock_kernel(); | 408 | lock_kernel(); |
402 | port->serial->type->break_ctl(port, break_state); | 409 | port->serial->type->break_ctl(tty, break_state); |
403 | unlock_kernel(); | 410 | unlock_kernel(); |
404 | } | 411 | } |
412 | return 0; | ||
405 | } | 413 | } |
406 | 414 | ||
407 | static int serial_read_proc (char *page, char **start, off_t off, int count, int *eof, void *data) | 415 | static int serial_read_proc(char *page, char **start, off_t off, int count, |
416 | int *eof, void *data) | ||
408 | { | 417 | { |
409 | struct usb_serial *serial; | 418 | struct usb_serial *serial; |
410 | int length = 0; | 419 | int length = 0; |
@@ -413,26 +422,29 @@ static int serial_read_proc (char *page, char **start, off_t off, int count, int | |||
413 | char tmp[40]; | 422 | char tmp[40]; |
414 | 423 | ||
415 | dbg("%s", __func__); | 424 | dbg("%s", __func__); |
416 | length += sprintf (page, "usbserinfo:1.0 driver:2.0\n"); | 425 | length += sprintf(page, "usbserinfo:1.0 driver:2.0\n"); |
417 | for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { | 426 | for (i = 0; i < SERIAL_TTY_MINORS && length < PAGE_SIZE; ++i) { |
418 | serial = usb_serial_get_by_index(i); | 427 | serial = usb_serial_get_by_index(i); |
419 | if (serial == NULL) | 428 | if (serial == NULL) |
420 | continue; | 429 | continue; |
421 | 430 | ||
422 | length += sprintf (page+length, "%d:", i); | 431 | length += sprintf(page+length, "%d:", i); |
423 | if (serial->type->driver.owner) | 432 | if (serial->type->driver.owner) |
424 | length += sprintf (page+length, " module:%s", module_name(serial->type->driver.owner)); | 433 | length += sprintf(page+length, " module:%s", |
425 | length += sprintf (page+length, " name:\"%s\"", serial->type->description); | 434 | module_name(serial->type->driver.owner)); |
426 | length += sprintf (page+length, " vendor:%04x product:%04x", | 435 | length += sprintf(page+length, " name:\"%s\"", |
427 | le16_to_cpu(serial->dev->descriptor.idVendor), | 436 | serial->type->description); |
428 | le16_to_cpu(serial->dev->descriptor.idProduct)); | 437 | length += sprintf(page+length, " vendor:%04x product:%04x", |
429 | length += sprintf (page+length, " num_ports:%d", serial->num_ports); | 438 | le16_to_cpu(serial->dev->descriptor.idVendor), |
430 | length += sprintf (page+length, " port:%d", i - serial->minor + 1); | 439 | le16_to_cpu(serial->dev->descriptor.idProduct)); |
431 | 440 | length += sprintf(page+length, " num_ports:%d", | |
441 | serial->num_ports); | ||
442 | length += sprintf(page+length, " port:%d", | ||
443 | i - serial->minor + 1); | ||
432 | usb_make_path(serial->dev, tmp, sizeof(tmp)); | 444 | usb_make_path(serial->dev, tmp, sizeof(tmp)); |
433 | length += sprintf (page+length, " path:%s", tmp); | 445 | length += sprintf(page+length, " path:%s", tmp); |
434 | 446 | ||
435 | length += sprintf (page+length, "\n"); | 447 | length += sprintf(page+length, "\n"); |
436 | if ((length + begin) > (off + count)) { | 448 | if ((length + begin) > (off + count)) { |
437 | usb_serial_put(serial); | 449 | usb_serial_put(serial); |
438 | goto done; | 450 | goto done; |
@@ -448,31 +460,31 @@ done: | |||
448 | if (off >= (length + begin)) | 460 | if (off >= (length + begin)) |
449 | return 0; | 461 | return 0; |
450 | *start = page + (off-begin); | 462 | *start = page + (off-begin); |
451 | return ((count < begin+length-off) ? count : begin+length-off); | 463 | return (count < begin+length-off) ? count : begin+length-off; |
452 | } | 464 | } |
453 | 465 | ||
454 | static int serial_tiocmget (struct tty_struct *tty, struct file *file) | 466 | static int serial_tiocmget(struct tty_struct *tty, struct file *file) |
455 | { | 467 | { |
456 | struct usb_serial_port *port = tty->driver_data; | 468 | struct usb_serial_port *port = tty->driver_data; |
457 | 469 | ||
458 | dbg("%s - port %d", __func__, port->number); | 470 | dbg("%s - port %d", __func__, port->number); |
459 | 471 | ||
460 | WARN_ON(!port->open_count); | 472 | WARN_ON(!port->port.count); |
461 | if (port->serial->type->tiocmget) | 473 | if (port->serial->type->tiocmget) |
462 | return port->serial->type->tiocmget(port, file); | 474 | return port->serial->type->tiocmget(tty, file); |
463 | return -EINVAL; | 475 | return -EINVAL; |
464 | } | 476 | } |
465 | 477 | ||
466 | static int serial_tiocmset (struct tty_struct *tty, struct file *file, | 478 | static int serial_tiocmset(struct tty_struct *tty, struct file *file, |
467 | unsigned int set, unsigned int clear) | 479 | unsigned int set, unsigned int clear) |
468 | { | 480 | { |
469 | struct usb_serial_port *port = tty->driver_data; | 481 | struct usb_serial_port *port = tty->driver_data; |
470 | 482 | ||
471 | dbg("%s - port %d", __func__, port->number); | 483 | dbg("%s - port %d", __func__, port->number); |
472 | 484 | ||
473 | WARN_ON(!port->open_count); | 485 | WARN_ON(!port->port.count); |
474 | if (port->serial->type->tiocmset) | 486 | if (port->serial->type->tiocmset) |
475 | return port->serial->type->tiocmset(port, file, set, clear); | 487 | return port->serial->type->tiocmset(tty, file, set, clear); |
476 | return -EINVAL; | 488 | return -EINVAL; |
477 | } | 489 | } |
478 | 490 | ||
@@ -485,6 +497,7 @@ void usb_serial_port_softint(struct usb_serial_port *port) | |||
485 | { | 497 | { |
486 | schedule_work(&port->work); | 498 | schedule_work(&port->work); |
487 | } | 499 | } |
500 | EXPORT_SYMBOL_GPL(usb_serial_port_softint); | ||
488 | 501 | ||
489 | static void usb_serial_port_work(struct work_struct *work) | 502 | static void usb_serial_port_work(struct work_struct *work) |
490 | { | 503 | { |
@@ -493,11 +506,11 @@ static void usb_serial_port_work(struct work_struct *work) | |||
493 | struct tty_struct *tty; | 506 | struct tty_struct *tty; |
494 | 507 | ||
495 | dbg("%s - port %d", __func__, port->number); | 508 | dbg("%s - port %d", __func__, port->number); |
496 | 509 | ||
497 | if (!port) | 510 | if (!port) |
498 | return; | 511 | return; |
499 | 512 | ||
500 | tty = port->tty; | 513 | tty = port->port.tty; |
501 | if (!tty) | 514 | if (!tty) |
502 | return; | 515 | return; |
503 | 516 | ||
@@ -546,9 +559,9 @@ static void port_free(struct usb_serial_port *port) | |||
546 | kfree(port); | 559 | kfree(port); |
547 | } | 560 | } |
548 | 561 | ||
549 | static struct usb_serial * create_serial (struct usb_device *dev, | 562 | static struct usb_serial *create_serial(struct usb_device *dev, |
550 | struct usb_interface *interface, | 563 | struct usb_interface *interface, |
551 | struct usb_serial_driver *driver) | 564 | struct usb_serial_driver *driver) |
552 | { | 565 | { |
553 | struct usb_serial *serial; | 566 | struct usb_serial *serial; |
554 | 567 | ||
@@ -567,7 +580,7 @@ static struct usb_serial * create_serial (struct usb_device *dev, | |||
567 | } | 580 | } |
568 | 581 | ||
569 | static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf, | 582 | static const struct usb_device_id *match_dynamic_id(struct usb_interface *intf, |
570 | struct usb_serial_driver *drv) | 583 | struct usb_serial_driver *drv) |
571 | { | 584 | { |
572 | struct usb_dynid *dynid; | 585 | struct usb_dynid *dynid; |
573 | 586 | ||
@@ -599,7 +612,8 @@ exit: | |||
599 | return id; | 612 | return id; |
600 | } | 613 | } |
601 | 614 | ||
602 | static struct usb_serial_driver *search_serial_device(struct usb_interface *iface) | 615 | static struct usb_serial_driver *search_serial_device( |
616 | struct usb_interface *iface) | ||
603 | { | 617 | { |
604 | const struct usb_device_id *id; | 618 | const struct usb_device_id *id; |
605 | struct usb_serial_driver *drv; | 619 | struct usb_serial_driver *drv; |
@@ -617,7 +631,7 @@ static struct usb_serial_driver *search_serial_device(struct usb_interface *ifac | |||
617 | int usb_serial_probe(struct usb_interface *interface, | 631 | int usb_serial_probe(struct usb_interface *interface, |
618 | const struct usb_device_id *id) | 632 | const struct usb_device_id *id) |
619 | { | 633 | { |
620 | struct usb_device *dev = interface_to_usbdev (interface); | 634 | struct usb_device *dev = interface_to_usbdev(interface); |
621 | struct usb_serial *serial = NULL; | 635 | struct usb_serial *serial = NULL; |
622 | struct usb_serial_port *port; | 636 | struct usb_serial_port *port; |
623 | struct usb_host_interface *iface_desc; | 637 | struct usb_host_interface *iface_desc; |
@@ -646,7 +660,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
646 | return -ENODEV; | 660 | return -ENODEV; |
647 | } | 661 | } |
648 | 662 | ||
649 | serial = create_serial (dev, interface, type); | 663 | serial = create_serial(dev, interface, type); |
650 | if (!serial) { | 664 | if (!serial) { |
651 | unlock_kernel(); | 665 | unlock_kernel(); |
652 | dev_err(&interface->dev, "%s - out of memory\n", __func__); | 666 | dev_err(&interface->dev, "%s - out of memory\n", __func__); |
@@ -659,8 +673,9 @@ int usb_serial_probe(struct usb_interface *interface, | |||
659 | 673 | ||
660 | if (!try_module_get(type->driver.owner)) { | 674 | if (!try_module_get(type->driver.owner)) { |
661 | unlock_kernel(); | 675 | unlock_kernel(); |
662 | dev_err(&interface->dev, "module get failed, exiting\n"); | 676 | dev_err(&interface->dev, |
663 | kfree (serial); | 677 | "module get failed, exiting\n"); |
678 | kfree(serial); | ||
664 | return -EIO; | 679 | return -EIO; |
665 | } | 680 | } |
666 | 681 | ||
@@ -670,8 +685,8 @@ int usb_serial_probe(struct usb_interface *interface, | |||
670 | 685 | ||
671 | if (retval) { | 686 | if (retval) { |
672 | unlock_kernel(); | 687 | unlock_kernel(); |
673 | dbg ("sub driver rejected device"); | 688 | dbg("sub driver rejected device"); |
674 | kfree (serial); | 689 | kfree(serial); |
675 | return retval; | 690 | return retval; |
676 | } | 691 | } |
677 | } | 692 | } |
@@ -712,7 +727,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
712 | } | 727 | } |
713 | 728 | ||
714 | #if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE) | 729 | #if defined(CONFIG_USB_SERIAL_PL2303) || defined(CONFIG_USB_SERIAL_PL2303_MODULE) |
715 | /* BEGIN HORRIBLE HACK FOR PL2303 */ | 730 | /* BEGIN HORRIBLE HACK FOR PL2303 */ |
716 | /* this is needed due to the looney way its endpoints are set up */ | 731 | /* this is needed due to the looney way its endpoints are set up */ |
717 | if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && | 732 | if (((le16_to_cpu(dev->descriptor.idVendor) == PL2303_VENDOR_ID) && |
718 | (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || | 733 | (le16_to_cpu(dev->descriptor.idProduct) == PL2303_PRODUCT_ID)) || |
@@ -741,7 +756,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
741 | if (num_bulk_in == 0 || num_bulk_out == 0) { | 756 | if (num_bulk_in == 0 || num_bulk_out == 0) { |
742 | unlock_kernel(); | 757 | unlock_kernel(); |
743 | dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); | 758 | dev_info(&interface->dev, "PL-2303 hack: descriptors matched but endpoints did not\n"); |
744 | kfree (serial); | 759 | kfree(serial); |
745 | return -ENODEV; | 760 | return -ENODEV; |
746 | } | 761 | } |
747 | } | 762 | } |
@@ -753,8 +768,9 @@ int usb_serial_probe(struct usb_interface *interface, | |||
753 | num_ports = num_bulk_out; | 768 | num_ports = num_bulk_out; |
754 | if (num_ports == 0) { | 769 | if (num_ports == 0) { |
755 | unlock_kernel(); | 770 | unlock_kernel(); |
756 | dev_err(&interface->dev, "Generic device with no bulk out, not allowed.\n"); | 771 | dev_err(&interface->dev, |
757 | kfree (serial); | 772 | "Generic device with no bulk out, not allowed.\n"); |
773 | kfree(serial); | ||
758 | return -EIO; | 774 | return -EIO; |
759 | } | 775 | } |
760 | } | 776 | } |
@@ -764,11 +780,12 @@ int usb_serial_probe(struct usb_interface *interface, | |||
764 | if (type->calc_num_ports) { | 780 | if (type->calc_num_ports) { |
765 | if (!try_module_get(type->driver.owner)) { | 781 | if (!try_module_get(type->driver.owner)) { |
766 | unlock_kernel(); | 782 | unlock_kernel(); |
767 | dev_err(&interface->dev, "module get failed, exiting\n"); | 783 | dev_err(&interface->dev, |
768 | kfree (serial); | 784 | "module get failed, exiting\n"); |
785 | kfree(serial); | ||
769 | return -EIO; | 786 | return -EIO; |
770 | } | 787 | } |
771 | num_ports = type->calc_num_ports (serial); | 788 | num_ports = type->calc_num_ports(serial); |
772 | module_put(type->driver.owner); | 789 | module_put(type->driver.owner); |
773 | } | 790 | } |
774 | if (!num_ports) | 791 | if (!num_ports) |
@@ -786,7 +803,8 @@ int usb_serial_probe(struct usb_interface *interface, | |||
786 | type->description); | 803 | type->description); |
787 | 804 | ||
788 | /* create our ports, we need as many as the max endpoints */ | 805 | /* create our ports, we need as many as the max endpoints */ |
789 | /* we don't use num_ports here cauz some devices have more endpoint pairs than ports */ | 806 | /* we don't use num_ports here because some devices have more |
807 | endpoint pairs than ports */ | ||
790 | max_endpoints = max(num_bulk_in, num_bulk_out); | 808 | max_endpoints = max(num_bulk_in, num_bulk_out); |
791 | max_endpoints = max(max_endpoints, num_interrupt_in); | 809 | max_endpoints = max(max_endpoints, num_interrupt_in); |
792 | max_endpoints = max(max_endpoints, num_interrupt_out); | 810 | max_endpoints = max(max_endpoints, num_interrupt_out); |
@@ -794,7 +812,8 @@ int usb_serial_probe(struct usb_interface *interface, | |||
794 | serial->num_port_pointers = max_endpoints; | 812 | serial->num_port_pointers = max_endpoints; |
795 | unlock_kernel(); | 813 | unlock_kernel(); |
796 | 814 | ||
797 | dbg("%s - setting up %d port structures for this device", __func__, max_endpoints); | 815 | dbg("%s - setting up %d port structures for this device", |
816 | __func__, max_endpoints); | ||
798 | for (i = 0; i < max_endpoints; ++i) { | 817 | for (i = 0; i < max_endpoints; ++i) { |
799 | port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); | 818 | port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); |
800 | if (!port) | 819 | if (!port) |
@@ -810,7 +829,7 @@ int usb_serial_probe(struct usb_interface *interface, | |||
810 | for (i = 0; i < num_bulk_in; ++i) { | 829 | for (i = 0; i < num_bulk_in; ++i) { |
811 | endpoint = bulk_in_endpoint[i]; | 830 | endpoint = bulk_in_endpoint[i]; |
812 | port = serial->port[i]; | 831 | port = serial->port[i]; |
813 | port->read_urb = usb_alloc_urb (0, GFP_KERNEL); | 832 | port->read_urb = usb_alloc_urb(0, GFP_KERNEL); |
814 | if (!port->read_urb) { | 833 | if (!port->read_urb) { |
815 | dev_err(&interface->dev, "No free urbs available\n"); | 834 | dev_err(&interface->dev, "No free urbs available\n"); |
816 | goto probe_error; | 835 | goto probe_error; |
@@ -818,17 +837,17 @@ int usb_serial_probe(struct usb_interface *interface, | |||
818 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 837 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
819 | port->bulk_in_size = buffer_size; | 838 | port->bulk_in_size = buffer_size; |
820 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; | 839 | port->bulk_in_endpointAddress = endpoint->bEndpointAddress; |
821 | port->bulk_in_buffer = kmalloc (buffer_size, GFP_KERNEL); | 840 | port->bulk_in_buffer = kmalloc(buffer_size, GFP_KERNEL); |
822 | if (!port->bulk_in_buffer) { | 841 | if (!port->bulk_in_buffer) { |
823 | dev_err(&interface->dev, "Couldn't allocate bulk_in_buffer\n"); | 842 | dev_err(&interface->dev, |
843 | "Couldn't allocate bulk_in_buffer\n"); | ||
824 | goto probe_error; | 844 | goto probe_error; |
825 | } | 845 | } |
826 | usb_fill_bulk_urb (port->read_urb, dev, | 846 | usb_fill_bulk_urb(port->read_urb, dev, |
827 | usb_rcvbulkpipe (dev, | 847 | usb_rcvbulkpipe(dev, |
828 | endpoint->bEndpointAddress), | 848 | endpoint->bEndpointAddress), |
829 | port->bulk_in_buffer, buffer_size, | 849 | port->bulk_in_buffer, buffer_size, |
830 | serial->type->read_bulk_callback, | 850 | serial->type->read_bulk_callback, port); |
831 | port); | ||
832 | } | 851 | } |
833 | 852 | ||
834 | for (i = 0; i < num_bulk_out; ++i) { | 853 | for (i = 0; i < num_bulk_out; ++i) { |
@@ -842,17 +861,17 @@ int usb_serial_probe(struct usb_interface *interface, | |||
842 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 861 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
843 | port->bulk_out_size = buffer_size; | 862 | port->bulk_out_size = buffer_size; |
844 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; | 863 | port->bulk_out_endpointAddress = endpoint->bEndpointAddress; |
845 | port->bulk_out_buffer = kmalloc (buffer_size, GFP_KERNEL); | 864 | port->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL); |
846 | if (!port->bulk_out_buffer) { | 865 | if (!port->bulk_out_buffer) { |
847 | dev_err(&interface->dev, "Couldn't allocate bulk_out_buffer\n"); | 866 | dev_err(&interface->dev, |
867 | "Couldn't allocate bulk_out_buffer\n"); | ||
848 | goto probe_error; | 868 | goto probe_error; |
849 | } | 869 | } |
850 | usb_fill_bulk_urb (port->write_urb, dev, | 870 | usb_fill_bulk_urb(port->write_urb, dev, |
851 | usb_sndbulkpipe (dev, | 871 | usb_sndbulkpipe(dev, |
852 | endpoint->bEndpointAddress), | 872 | endpoint->bEndpointAddress), |
853 | port->bulk_out_buffer, buffer_size, | 873 | port->bulk_out_buffer, buffer_size, |
854 | serial->type->write_bulk_callback, | 874 | serial->type->write_bulk_callback, port); |
855 | port); | ||
856 | } | 875 | } |
857 | 876 | ||
858 | if (serial->type->read_int_callback) { | 877 | if (serial->type->read_int_callback) { |
@@ -861,73 +880,82 @@ int usb_serial_probe(struct usb_interface *interface, | |||
861 | port = serial->port[i]; | 880 | port = serial->port[i]; |
862 | port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); | 881 | port->interrupt_in_urb = usb_alloc_urb(0, GFP_KERNEL); |
863 | if (!port->interrupt_in_urb) { | 882 | if (!port->interrupt_in_urb) { |
864 | dev_err(&interface->dev, "No free urbs available\n"); | 883 | dev_err(&interface->dev, |
884 | "No free urbs available\n"); | ||
865 | goto probe_error; | 885 | goto probe_error; |
866 | } | 886 | } |
867 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 887 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
868 | port->interrupt_in_endpointAddress = endpoint->bEndpointAddress; | 888 | port->interrupt_in_endpointAddress = |
869 | port->interrupt_in_buffer = kmalloc (buffer_size, GFP_KERNEL); | 889 | endpoint->bEndpointAddress; |
890 | port->interrupt_in_buffer = kmalloc(buffer_size, | ||
891 | GFP_KERNEL); | ||
870 | if (!port->interrupt_in_buffer) { | 892 | if (!port->interrupt_in_buffer) { |
871 | dev_err(&interface->dev, "Couldn't allocate interrupt_in_buffer\n"); | 893 | dev_err(&interface->dev, |
894 | "Couldn't allocate interrupt_in_buffer\n"); | ||
872 | goto probe_error; | 895 | goto probe_error; |
873 | } | 896 | } |
874 | usb_fill_int_urb (port->interrupt_in_urb, dev, | 897 | usb_fill_int_urb(port->interrupt_in_urb, dev, |
875 | usb_rcvintpipe (dev, | 898 | usb_rcvintpipe(dev, |
876 | endpoint->bEndpointAddress), | 899 | endpoint->bEndpointAddress), |
877 | port->interrupt_in_buffer, buffer_size, | 900 | port->interrupt_in_buffer, buffer_size, |
878 | serial->type->read_int_callback, port, | 901 | serial->type->read_int_callback, port, |
879 | endpoint->bInterval); | 902 | endpoint->bInterval); |
880 | } | 903 | } |
881 | } else if (num_interrupt_in) { | 904 | } else if (num_interrupt_in) { |
882 | dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined"); | 905 | dbg("the device claims to support interrupt in transfers, but read_int_callback is not defined"); |
883 | } | 906 | } |
884 | 907 | ||
885 | if (serial->type->write_int_callback) { | 908 | if (serial->type->write_int_callback) { |
886 | for (i = 0; i < num_interrupt_out; ++i) { | 909 | for (i = 0; i < num_interrupt_out; ++i) { |
887 | endpoint = interrupt_out_endpoint[i]; | 910 | endpoint = interrupt_out_endpoint[i]; |
888 | port = serial->port[i]; | 911 | port = serial->port[i]; |
889 | port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); | 912 | port->interrupt_out_urb = usb_alloc_urb(0, GFP_KERNEL); |
890 | if (!port->interrupt_out_urb) { | 913 | if (!port->interrupt_out_urb) { |
891 | dev_err(&interface->dev, "No free urbs available\n"); | 914 | dev_err(&interface->dev, |
915 | "No free urbs available\n"); | ||
892 | goto probe_error; | 916 | goto probe_error; |
893 | } | 917 | } |
894 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); | 918 | buffer_size = le16_to_cpu(endpoint->wMaxPacketSize); |
895 | port->interrupt_out_size = buffer_size; | 919 | port->interrupt_out_size = buffer_size; |
896 | port->interrupt_out_endpointAddress = endpoint->bEndpointAddress; | 920 | port->interrupt_out_endpointAddress = |
897 | port->interrupt_out_buffer = kmalloc (buffer_size, GFP_KERNEL); | 921 | endpoint->bEndpointAddress; |
922 | port->interrupt_out_buffer = kmalloc(buffer_size, | ||
923 | GFP_KERNEL); | ||
898 | if (!port->interrupt_out_buffer) { | 924 | if (!port->interrupt_out_buffer) { |
899 | dev_err(&interface->dev, "Couldn't allocate interrupt_out_buffer\n"); | 925 | dev_err(&interface->dev, |
926 | "Couldn't allocate interrupt_out_buffer\n"); | ||
900 | goto probe_error; | 927 | goto probe_error; |
901 | } | 928 | } |
902 | usb_fill_int_urb (port->interrupt_out_urb, dev, | 929 | usb_fill_int_urb(port->interrupt_out_urb, dev, |
903 | usb_sndintpipe (dev, | 930 | usb_sndintpipe(dev, |
904 | endpoint->bEndpointAddress), | 931 | endpoint->bEndpointAddress), |
905 | port->interrupt_out_buffer, buffer_size, | 932 | port->interrupt_out_buffer, buffer_size, |
906 | serial->type->write_int_callback, port, | 933 | serial->type->write_int_callback, port, |
907 | endpoint->bInterval); | 934 | endpoint->bInterval); |
908 | } | 935 | } |
909 | } else if (num_interrupt_out) { | 936 | } else if (num_interrupt_out) { |
910 | dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined"); | 937 | dbg("the device claims to support interrupt out transfers, but write_int_callback is not defined"); |
911 | } | 938 | } |
912 | 939 | ||
913 | /* if this device type has an attach function, call it */ | 940 | /* if this device type has an attach function, call it */ |
914 | if (type->attach) { | 941 | if (type->attach) { |
915 | if (!try_module_get(type->driver.owner)) { | 942 | if (!try_module_get(type->driver.owner)) { |
916 | dev_err(&interface->dev, "module get failed, exiting\n"); | 943 | dev_err(&interface->dev, |
944 | "module get failed, exiting\n"); | ||
917 | goto probe_error; | 945 | goto probe_error; |
918 | } | 946 | } |
919 | retval = type->attach (serial); | 947 | retval = type->attach(serial); |
920 | module_put(type->driver.owner); | 948 | module_put(type->driver.owner); |
921 | if (retval < 0) | 949 | if (retval < 0) |
922 | goto probe_error; | 950 | goto probe_error; |
923 | if (retval > 0) { | 951 | if (retval > 0) { |
924 | /* quietly accept this device, but don't bind to a serial port | 952 | /* quietly accept this device, but don't bind to a |
925 | * as it's about to disappear */ | 953 | serial port as it's about to disappear */ |
926 | goto exit; | 954 | goto exit; |
927 | } | 955 | } |
928 | } | 956 | } |
929 | 957 | ||
930 | if (get_free_serial (serial, num_ports, &minor) == NULL) { | 958 | if (get_free_serial(serial, num_ports, &minor) == NULL) { |
931 | dev_err(&interface->dev, "No more free serial devices\n"); | 959 | dev_err(&interface->dev, "No more free serial devices\n"); |
932 | goto probe_error; | 960 | goto probe_error; |
933 | } | 961 | } |
@@ -949,11 +977,11 @@ int usb_serial_probe(struct usb_interface *interface, | |||
949 | "continuing\n"); | 977 | "continuing\n"); |
950 | } | 978 | } |
951 | 979 | ||
952 | usb_serial_console_init (debug, minor); | 980 | usb_serial_console_init(debug, minor); |
953 | 981 | ||
954 | exit: | 982 | exit: |
955 | /* success */ | 983 | /* success */ |
956 | usb_set_intfdata (interface, serial); | 984 | usb_set_intfdata(interface, serial); |
957 | return 0; | 985 | return 0; |
958 | 986 | ||
959 | probe_error: | 987 | probe_error: |
@@ -989,29 +1017,30 @@ probe_error: | |||
989 | /* free up any memory that we allocated */ | 1017 | /* free up any memory that we allocated */ |
990 | for (i = 0; i < serial->num_port_pointers; ++i) | 1018 | for (i = 0; i < serial->num_port_pointers; ++i) |
991 | kfree(serial->port[i]); | 1019 | kfree(serial->port[i]); |
992 | kfree (serial); | 1020 | kfree(serial); |
993 | return -EIO; | 1021 | return -EIO; |
994 | } | 1022 | } |
1023 | EXPORT_SYMBOL_GPL(usb_serial_probe); | ||
995 | 1024 | ||
996 | void usb_serial_disconnect(struct usb_interface *interface) | 1025 | void usb_serial_disconnect(struct usb_interface *interface) |
997 | { | 1026 | { |
998 | int i; | 1027 | int i; |
999 | struct usb_serial *serial = usb_get_intfdata (interface); | 1028 | struct usb_serial *serial = usb_get_intfdata(interface); |
1000 | struct device *dev = &interface->dev; | 1029 | struct device *dev = &interface->dev; |
1001 | struct usb_serial_port *port; | 1030 | struct usb_serial_port *port; |
1002 | 1031 | ||
1003 | usb_serial_console_disconnect(serial); | 1032 | usb_serial_console_disconnect(serial); |
1004 | dbg ("%s", __func__); | 1033 | dbg("%s", __func__); |
1005 | 1034 | ||
1006 | mutex_lock(&serial->disc_mutex); | 1035 | mutex_lock(&serial->disc_mutex); |
1007 | usb_set_intfdata (interface, NULL); | 1036 | usb_set_intfdata(interface, NULL); |
1008 | /* must set a flag, to signal subdrivers */ | 1037 | /* must set a flag, to signal subdrivers */ |
1009 | serial->disconnected = 1; | 1038 | serial->disconnected = 1; |
1010 | for (i = 0; i < serial->num_ports; ++i) { | 1039 | for (i = 0; i < serial->num_ports; ++i) { |
1011 | port = serial->port[i]; | 1040 | port = serial->port[i]; |
1012 | if (port) { | 1041 | if (port) { |
1013 | if (port->tty) | 1042 | if (port->port.tty) |
1014 | tty_hangup(port->tty); | 1043 | tty_hangup(port->port.tty); |
1015 | kill_traffic(port); | 1044 | kill_traffic(port); |
1016 | } | 1045 | } |
1017 | } | 1046 | } |
@@ -1021,6 +1050,7 @@ void usb_serial_disconnect(struct usb_interface *interface) | |||
1021 | usb_serial_put(serial); | 1050 | usb_serial_put(serial); |
1022 | dev_info(dev, "device disconnected\n"); | 1051 | dev_info(dev, "device disconnected\n"); |
1023 | } | 1052 | } |
1053 | EXPORT_SYMBOL_GPL(usb_serial_disconnect); | ||
1024 | 1054 | ||
1025 | int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) | 1055 | int usb_serial_suspend(struct usb_interface *intf, pm_message_t message) |
1026 | { | 1056 | { |
@@ -1079,9 +1109,8 @@ static int __init usb_serial_init(void) | |||
1079 | return -ENOMEM; | 1109 | return -ENOMEM; |
1080 | 1110 | ||
1081 | /* Initialize our global data */ | 1111 | /* Initialize our global data */ |
1082 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) { | 1112 | for (i = 0; i < SERIAL_TTY_MINORS; ++i) |
1083 | serial_table[i] = NULL; | 1113 | serial_table[i] = NULL; |
1084 | } | ||
1085 | 1114 | ||
1086 | result = bus_register(&usb_serial_bus_type); | 1115 | result = bus_register(&usb_serial_bus_type); |
1087 | if (result) { | 1116 | if (result) { |
@@ -1096,9 +1125,11 @@ static int __init usb_serial_init(void) | |||
1096 | usb_serial_tty_driver->minor_start = 0; | 1125 | usb_serial_tty_driver->minor_start = 0; |
1097 | usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; | 1126 | usb_serial_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; |
1098 | usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; | 1127 | usb_serial_tty_driver->subtype = SERIAL_TYPE_NORMAL; |
1099 | usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 1128 | usb_serial_tty_driver->flags = TTY_DRIVER_REAL_RAW | |
1129 | TTY_DRIVER_DYNAMIC_DEV; | ||
1100 | usb_serial_tty_driver->init_termios = tty_std_termios; | 1130 | usb_serial_tty_driver->init_termios = tty_std_termios; |
1101 | usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 1131 | usb_serial_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
1132 | | HUPCL | CLOCAL; | ||
1102 | usb_serial_tty_driver->init_termios.c_ispeed = 9600; | 1133 | usb_serial_tty_driver->init_termios.c_ispeed = 9600; |
1103 | usb_serial_tty_driver->init_termios.c_ospeed = 9600; | 1134 | usb_serial_tty_driver->init_termios.c_ospeed = 9600; |
1104 | tty_set_operations(usb_serial_tty_driver, &serial_ops); | 1135 | tty_set_operations(usb_serial_tty_driver, &serial_ops); |
@@ -1136,7 +1167,7 @@ exit_reg_driver: | |||
1136 | bus_unregister(&usb_serial_bus_type); | 1167 | bus_unregister(&usb_serial_bus_type); |
1137 | 1168 | ||
1138 | exit_bus: | 1169 | exit_bus: |
1139 | err ("%s - returning with error %d", __func__, result); | 1170 | err("%s - returning with error %d", __func__, result); |
1140 | put_tty_driver(usb_serial_tty_driver); | 1171 | put_tty_driver(usb_serial_tty_driver); |
1141 | return result; | 1172 | return result; |
1142 | } | 1173 | } |
@@ -1163,7 +1194,7 @@ module_exit(usb_serial_exit); | |||
1163 | if (!type->function) { \ | 1194 | if (!type->function) { \ |
1164 | type->function = usb_serial_generic_##function; \ | 1195 | type->function = usb_serial_generic_##function; \ |
1165 | dbg("Had to override the " #function \ | 1196 | dbg("Had to override the " #function \ |
1166 | " usb serial operation with the generic one.");\ | 1197 | " usb serial operation with the generic one.");\ |
1167 | } \ | 1198 | } \ |
1168 | } while (0) | 1199 | } while (0) |
1169 | 1200 | ||
@@ -1180,8 +1211,9 @@ static void fixup_generic(struct usb_serial_driver *device) | |||
1180 | set_to_generic_if_null(device, resume); | 1211 | set_to_generic_if_null(device, resume); |
1181 | } | 1212 | } |
1182 | 1213 | ||
1183 | int usb_serial_register(struct usb_serial_driver *driver) /* must be called with BKL held */ | 1214 | int usb_serial_register(struct usb_serial_driver *driver) |
1184 | { | 1215 | { |
1216 | /* must be called with BKL held */ | ||
1185 | int retval; | 1217 | int retval; |
1186 | 1218 | ||
1187 | fixup_generic(driver); | 1219 | fixup_generic(driver); |
@@ -1194,37 +1226,30 @@ int usb_serial_register(struct usb_serial_driver *driver) /* must be called with | |||
1194 | 1226 | ||
1195 | retval = usb_serial_bus_register(driver); | 1227 | retval = usb_serial_bus_register(driver); |
1196 | if (retval) { | 1228 | if (retval) { |
1197 | err("problem %d when registering driver %s", retval, driver->description); | 1229 | err("problem %d when registering driver %s", |
1230 | retval, driver->description); | ||
1198 | list_del(&driver->driver_list); | 1231 | list_del(&driver->driver_list); |
1199 | } | 1232 | } else |
1200 | else | 1233 | info("USB Serial support registered for %s", |
1201 | info("USB Serial support registered for %s", driver->description); | 1234 | driver->description); |
1202 | 1235 | ||
1203 | return retval; | 1236 | return retval; |
1204 | } | 1237 | } |
1238 | EXPORT_SYMBOL_GPL(usb_serial_register); | ||
1205 | 1239 | ||
1206 | 1240 | ||
1207 | void usb_serial_deregister(struct usb_serial_driver *device) /* must be called with BKL held */ | 1241 | void usb_serial_deregister(struct usb_serial_driver *device) |
1208 | { | 1242 | { |
1243 | /* must be called with BKL held */ | ||
1209 | info("USB Serial deregistering driver %s", device->description); | 1244 | info("USB Serial deregistering driver %s", device->description); |
1210 | list_del(&device->driver_list); | 1245 | list_del(&device->driver_list); |
1211 | usb_serial_bus_deregister(device); | 1246 | usb_serial_bus_deregister(device); |
1212 | } | 1247 | } |
1213 | |||
1214 | |||
1215 | |||
1216 | /* If the usb-serial core is built into the core, the usb-serial drivers | ||
1217 | need these symbols to load properly as modules. */ | ||
1218 | EXPORT_SYMBOL_GPL(usb_serial_register); | ||
1219 | EXPORT_SYMBOL_GPL(usb_serial_deregister); | 1248 | EXPORT_SYMBOL_GPL(usb_serial_deregister); |
1220 | EXPORT_SYMBOL_GPL(usb_serial_probe); | ||
1221 | EXPORT_SYMBOL_GPL(usb_serial_disconnect); | ||
1222 | EXPORT_SYMBOL_GPL(usb_serial_port_softint); | ||
1223 | |||
1224 | 1249 | ||
1225 | /* Module information */ | 1250 | /* Module information */ |
1226 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1251 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1227 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1252 | MODULE_DESCRIPTION(DRIVER_DESC); |
1228 | MODULE_LICENSE("GPL"); | 1253 | MODULE_LICENSE("GPL"); |
1229 | 1254 | ||
1230 | module_param(debug, bool, S_IRUGO | S_IWUSR); | 1255 | module_param(debug, bool, S_IRUGO | S_IWUSR); |