diff options
Diffstat (limited to 'drivers/usb/class')
-rw-r--r-- | drivers/usb/class/cdc-acm.c | 530 | ||||
-rw-r--r-- | drivers/usb/class/cdc-acm.h | 7 | ||||
-rw-r--r-- | drivers/usb/class/cdc-wdm.c | 1 | ||||
-rw-r--r-- | drivers/usb/class/usblp.c | 6 | ||||
-rw-r--r-- | drivers/usb/class/usbtmc.c | 16 |
5 files changed, 351 insertions, 209 deletions
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 7a1164dd1d37..e1f89416ef8c 100644 --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c | |||
@@ -16,7 +16,8 @@ | |||
16 | * v0.9 - thorough cleaning, URBification, almost a rewrite | 16 | * v0.9 - thorough cleaning, URBification, almost a rewrite |
17 | * v0.10 - some more cleanups | 17 | * v0.10 - some more cleanups |
18 | * v0.11 - fixed flow control, read error doesn't stop reads | 18 | * v0.11 - fixed flow control, read error doesn't stop reads |
19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced | 19 | * v0.12 - added TIOCM ioctls, added break handling, made struct acm |
20 | * kmalloced | ||
20 | * v0.13 - added termios, added hangup | 21 | * v0.13 - added termios, added hangup |
21 | * v0.14 - sized down struct acm | 22 | * v0.14 - sized down struct acm |
22 | * v0.15 - fixed flow control again - characters could be lost | 23 | * v0.15 - fixed flow control again - characters could be lost |
@@ -62,7 +63,7 @@ | |||
62 | #include <linux/tty_flip.h> | 63 | #include <linux/tty_flip.h> |
63 | #include <linux/module.h> | 64 | #include <linux/module.h> |
64 | #include <linux/mutex.h> | 65 | #include <linux/mutex.h> |
65 | #include <asm/uaccess.h> | 66 | #include <linux/uaccess.h> |
66 | #include <linux/usb.h> | 67 | #include <linux/usb.h> |
67 | #include <linux/usb/cdc.h> | 68 | #include <linux/usb/cdc.h> |
68 | #include <asm/byteorder.h> | 69 | #include <asm/byteorder.h> |
@@ -87,7 +88,10 @@ static struct acm *acm_table[ACM_TTY_MINORS]; | |||
87 | 88 | ||
88 | static DEFINE_MUTEX(open_mutex); | 89 | static DEFINE_MUTEX(open_mutex); |
89 | 90 | ||
90 | #define ACM_READY(acm) (acm && acm->dev && acm->used) | 91 | #define ACM_READY(acm) (acm && acm->dev && acm->port.count) |
92 | |||
93 | static const struct tty_port_operations acm_port_ops = { | ||
94 | }; | ||
91 | 95 | ||
92 | #ifdef VERBOSE_DEBUG | 96 | #ifdef VERBOSE_DEBUG |
93 | #define verbose 1 | 97 | #define verbose 1 |
@@ -99,13 +103,15 @@ static DEFINE_MUTEX(open_mutex); | |||
99 | * Functions for ACM control messages. | 103 | * Functions for ACM control messages. |
100 | */ | 104 | */ |
101 | 105 | ||
102 | static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) | 106 | static int acm_ctrl_msg(struct acm *acm, int request, int value, |
107 | void *buf, int len) | ||
103 | { | 108 | { |
104 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), | 109 | int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), |
105 | request, USB_RT_ACM, value, | 110 | request, USB_RT_ACM, value, |
106 | acm->control->altsetting[0].desc.bInterfaceNumber, | 111 | acm->control->altsetting[0].desc.bInterfaceNumber, |
107 | buf, len, 5000); | 112 | buf, len, 5000); |
108 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); | 113 | dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", |
114 | request, value, len, retval); | ||
109 | return retval < 0 ? retval : 0; | 115 | return retval < 0 ? retval : 0; |
110 | } | 116 | } |
111 | 117 | ||
@@ -150,9 +156,8 @@ static int acm_wb_is_avail(struct acm *acm) | |||
150 | 156 | ||
151 | n = ACM_NW; | 157 | n = ACM_NW; |
152 | spin_lock_irqsave(&acm->write_lock, flags); | 158 | spin_lock_irqsave(&acm->write_lock, flags); |
153 | for (i = 0; i < ACM_NW; i++) { | 159 | for (i = 0; i < ACM_NW; i++) |
154 | n -= acm->wb[i].use; | 160 | n -= acm->wb[i].use; |
155 | } | ||
156 | spin_unlock_irqrestore(&acm->write_lock, flags); | 161 | spin_unlock_irqrestore(&acm->write_lock, flags); |
157 | return n; | 162 | return n; |
158 | } | 163 | } |
@@ -183,7 +188,8 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb) | |||
183 | wb->urb->transfer_buffer_length = wb->len; | 188 | wb->urb->transfer_buffer_length = wb->len; |
184 | wb->urb->dev = acm->dev; | 189 | wb->urb->dev = acm->dev; |
185 | 190 | ||
186 | if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { | 191 | rc = usb_submit_urb(wb->urb, GFP_ATOMIC); |
192 | if (rc < 0) { | ||
187 | dbg("usb_submit_urb(write bulk) failed: %d", rc); | 193 | dbg("usb_submit_urb(write bulk) failed: %d", rc); |
188 | acm_write_done(acm, wb); | 194 | acm_write_done(acm, wb); |
189 | } | 195 | } |
@@ -262,6 +268,7 @@ static void acm_ctrl_irq(struct urb *urb) | |||
262 | { | 268 | { |
263 | struct acm *acm = urb->context; | 269 | struct acm *acm = urb->context; |
264 | struct usb_cdc_notification *dr = urb->transfer_buffer; | 270 | struct usb_cdc_notification *dr = urb->transfer_buffer; |
271 | struct tty_struct *tty; | ||
265 | unsigned char *data; | 272 | unsigned char *data; |
266 | int newctrl; | 273 | int newctrl; |
267 | int retval; | 274 | int retval; |
@@ -287,40 +294,45 @@ static void acm_ctrl_irq(struct urb *urb) | |||
287 | 294 | ||
288 | data = (unsigned char *)(dr + 1); | 295 | data = (unsigned char *)(dr + 1); |
289 | switch (dr->bNotificationType) { | 296 | switch (dr->bNotificationType) { |
297 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | ||
298 | dbg("%s network", dr->wValue ? | ||
299 | "connected to" : "disconnected from"); | ||
300 | break; | ||
290 | 301 | ||
291 | case USB_CDC_NOTIFY_NETWORK_CONNECTION: | 302 | case USB_CDC_NOTIFY_SERIAL_STATE: |
292 | 303 | tty = tty_port_tty_get(&acm->port); | |
293 | dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); | 304 | newctrl = get_unaligned_le16(data); |
294 | break; | ||
295 | |||
296 | case USB_CDC_NOTIFY_SERIAL_STATE: | ||
297 | |||
298 | newctrl = get_unaligned_le16(data); | ||
299 | 305 | ||
300 | if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | 306 | if (tty) { |
307 | if (!acm->clocal && | ||
308 | (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { | ||
301 | dbg("calling hangup"); | 309 | dbg("calling hangup"); |
302 | tty_hangup(acm->tty); | 310 | tty_hangup(tty); |
303 | } | 311 | } |
312 | tty_kref_put(tty); | ||
313 | } | ||
304 | 314 | ||
305 | acm->ctrlin = newctrl; | 315 | acm->ctrlin = newctrl; |
306 | |||
307 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
308 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
309 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
310 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
311 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
312 | 316 | ||
317 | dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c", | ||
318 | acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', | ||
319 | acm->ctrlin & ACM_CTRL_DSR ? '+' : '-', | ||
320 | acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', | ||
321 | acm->ctrlin & ACM_CTRL_RI ? '+' : '-', | ||
322 | acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', | ||
323 | acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-', | ||
324 | acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-'); | ||
313 | break; | 325 | break; |
314 | 326 | ||
315 | default: | 327 | default: |
316 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", | 328 | dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", |
317 | dr->bNotificationType, dr->wIndex, | 329 | dr->bNotificationType, dr->wIndex, |
318 | dr->wLength, data[0], data[1]); | 330 | dr->wLength, data[0], data[1]); |
319 | break; | 331 | break; |
320 | } | 332 | } |
321 | exit: | 333 | exit: |
322 | usb_mark_last_busy(acm->dev); | 334 | usb_mark_last_busy(acm->dev); |
323 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 335 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
324 | if (retval) | 336 | if (retval) |
325 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " | 337 | dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " |
326 | "result %d", __func__, retval); | 338 | "result %d", __func__, retval); |
@@ -371,15 +383,15 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
371 | { | 383 | { |
372 | struct acm *acm = (void *)_acm; | 384 | struct acm *acm = (void *)_acm; |
373 | struct acm_rb *buf; | 385 | struct acm_rb *buf; |
374 | struct tty_struct *tty = acm->tty; | 386 | struct tty_struct *tty; |
375 | struct acm_ru *rcv; | 387 | struct acm_ru *rcv; |
376 | unsigned long flags; | 388 | unsigned long flags; |
377 | unsigned char throttled; | 389 | unsigned char throttled; |
390 | struct usb_host_endpoint *ep; | ||
378 | 391 | ||
379 | dbg("Entering acm_rx_tasklet"); | 392 | dbg("Entering acm_rx_tasklet"); |
380 | 393 | ||
381 | if (!ACM_READY(acm)) | 394 | if (!ACM_READY(acm)) { |
382 | { | ||
383 | dbg("acm_rx_tasklet: ACM not ready"); | 395 | dbg("acm_rx_tasklet: ACM not ready"); |
384 | return; | 396 | return; |
385 | } | 397 | } |
@@ -387,12 +399,13 @@ static void acm_rx_tasklet(unsigned long _acm) | |||
387 | spin_lock_irqsave(&acm->throttle_lock, flags); | 399 | spin_lock_irqsave(&acm->throttle_lock, flags); |
388 | throttled = acm->throttle; | 400 | throttled = acm->throttle; |
389 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 401 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
390 | if (throttled) | 402 | if (throttled) { |
391 | { | ||
392 | dbg("acm_rx_tasklet: throttled"); | 403 | dbg("acm_rx_tasklet: throttled"); |
393 | return; | 404 | return; |
394 | } | 405 | } |
395 | 406 | ||
407 | tty = tty_port_tty_get(&acm->port); | ||
408 | |||
396 | next_buffer: | 409 | next_buffer: |
397 | spin_lock_irqsave(&acm->read_lock, flags); | 410 | spin_lock_irqsave(&acm->read_lock, flags); |
398 | if (list_empty(&acm->filled_read_bufs)) { | 411 | if (list_empty(&acm->filled_read_bufs)) { |
@@ -406,20 +419,22 @@ next_buffer: | |||
406 | 419 | ||
407 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); | 420 | dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); |
408 | 421 | ||
409 | tty_buffer_request_room(tty, buf->size); | 422 | if (tty) { |
410 | spin_lock_irqsave(&acm->throttle_lock, flags); | 423 | spin_lock_irqsave(&acm->throttle_lock, flags); |
411 | throttled = acm->throttle; | 424 | throttled = acm->throttle; |
412 | spin_unlock_irqrestore(&acm->throttle_lock, flags); | 425 | spin_unlock_irqrestore(&acm->throttle_lock, flags); |
413 | if (!throttled) | 426 | if (!throttled) { |
414 | tty_insert_flip_string(tty, buf->base, buf->size); | 427 | tty_buffer_request_room(tty, buf->size); |
415 | tty_flip_buffer_push(tty); | 428 | tty_insert_flip_string(tty, buf->base, buf->size); |
416 | 429 | tty_flip_buffer_push(tty); | |
417 | if (throttled) { | 430 | } else { |
418 | dbg("Throttling noticed"); | 431 | tty_kref_put(tty); |
419 | spin_lock_irqsave(&acm->read_lock, flags); | 432 | dbg("Throttling noticed"); |
420 | list_add(&buf->list, &acm->filled_read_bufs); | 433 | spin_lock_irqsave(&acm->read_lock, flags); |
421 | spin_unlock_irqrestore(&acm->read_lock, flags); | 434 | list_add(&buf->list, &acm->filled_read_bufs); |
422 | return; | 435 | spin_unlock_irqrestore(&acm->read_lock, flags); |
436 | return; | ||
437 | } | ||
423 | } | 438 | } |
424 | 439 | ||
425 | spin_lock_irqsave(&acm->read_lock, flags); | 440 | spin_lock_irqsave(&acm->read_lock, flags); |
@@ -428,6 +443,8 @@ next_buffer: | |||
428 | goto next_buffer; | 443 | goto next_buffer; |
429 | 444 | ||
430 | urbs: | 445 | urbs: |
446 | tty_kref_put(tty); | ||
447 | |||
431 | while (!list_empty(&acm->spare_read_bufs)) { | 448 | while (!list_empty(&acm->spare_read_bufs)) { |
432 | spin_lock_irqsave(&acm->read_lock, flags); | 449 | spin_lock_irqsave(&acm->read_lock, flags); |
433 | if (list_empty(&acm->spare_read_urbs)) { | 450 | if (list_empty(&acm->spare_read_urbs)) { |
@@ -446,18 +463,28 @@ urbs: | |||
446 | 463 | ||
447 | rcv->buffer = buf; | 464 | rcv->buffer = buf; |
448 | 465 | ||
449 | usb_fill_bulk_urb(rcv->urb, acm->dev, | 466 | ep = (usb_pipein(acm->rx_endpoint) ? acm->dev->ep_in : acm->dev->ep_out) |
450 | acm->rx_endpoint, | 467 | [usb_pipeendpoint(acm->rx_endpoint)]; |
451 | buf->base, | 468 | if (usb_endpoint_xfer_int(&ep->desc)) |
452 | acm->readsize, | 469 | usb_fill_int_urb(rcv->urb, acm->dev, |
453 | acm_read_bulk, rcv); | 470 | acm->rx_endpoint, |
471 | buf->base, | ||
472 | acm->readsize, | ||
473 | acm_read_bulk, rcv, ep->desc.bInterval); | ||
474 | else | ||
475 | usb_fill_bulk_urb(rcv->urb, acm->dev, | ||
476 | acm->rx_endpoint, | ||
477 | buf->base, | ||
478 | acm->readsize, | ||
479 | acm_read_bulk, rcv); | ||
454 | rcv->urb->transfer_dma = buf->dma; | 480 | rcv->urb->transfer_dma = buf->dma; |
455 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 481 | rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
456 | 482 | ||
457 | /* This shouldn't kill the driver as unsuccessful URBs are returned to the | 483 | /* This shouldn't kill the driver as unsuccessful URBs are |
458 | free-urbs-pool and resubmited ASAP */ | 484 | returned to the free-urbs-pool and resubmited ASAP */ |
459 | spin_lock_irqsave(&acm->read_lock, flags); | 485 | spin_lock_irqsave(&acm->read_lock, flags); |
460 | if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | 486 | if (acm->susp_count || |
487 | usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { | ||
461 | list_add(&buf->list, &acm->spare_read_bufs); | 488 | list_add(&buf->list, &acm->spare_read_bufs); |
462 | list_add(&rcv->list, &acm->spare_read_urbs); | 489 | list_add(&rcv->list, &acm->spare_read_urbs); |
463 | acm->processing = 0; | 490 | acm->processing = 0; |
@@ -499,11 +526,14 @@ static void acm_write_bulk(struct urb *urb) | |||
499 | static void acm_softint(struct work_struct *work) | 526 | static void acm_softint(struct work_struct *work) |
500 | { | 527 | { |
501 | struct acm *acm = container_of(work, struct acm, work); | 528 | struct acm *acm = container_of(work, struct acm, work); |
529 | struct tty_struct *tty; | ||
502 | 530 | ||
503 | dev_vdbg(&acm->data->dev, "tx work\n"); | 531 | dev_vdbg(&acm->data->dev, "tx work\n"); |
504 | if (!ACM_READY(acm)) | 532 | if (!ACM_READY(acm)) |
505 | return; | 533 | return; |
506 | tty_wakeup(acm->tty); | 534 | tty = tty_port_tty_get(&acm->port); |
535 | tty_wakeup(tty); | ||
536 | tty_kref_put(tty); | ||
507 | } | 537 | } |
508 | 538 | ||
509 | static void acm_waker(struct work_struct *waker) | 539 | static void acm_waker(struct work_struct *waker) |
@@ -530,7 +560,7 @@ static void acm_waker(struct work_struct *waker) | |||
530 | static int acm_tty_open(struct tty_struct *tty, struct file *filp) | 560 | static int acm_tty_open(struct tty_struct *tty, struct file *filp) |
531 | { | 561 | { |
532 | struct acm *acm; | 562 | struct acm *acm; |
533 | int rv = -EINVAL; | 563 | int rv = -ENODEV; |
534 | int i; | 564 | int i; |
535 | dbg("Entering acm_tty_open."); | 565 | dbg("Entering acm_tty_open."); |
536 | 566 | ||
@@ -543,8 +573,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
543 | rv = 0; | 573 | rv = 0; |
544 | 574 | ||
545 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); | 575 | set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); |
576 | |||
546 | tty->driver_data = acm; | 577 | tty->driver_data = acm; |
547 | acm->tty = tty; | 578 | tty_port_tty_set(&acm->port, tty); |
548 | 579 | ||
549 | if (usb_autopm_get_interface(acm->control) < 0) | 580 | if (usb_autopm_get_interface(acm->control) < 0) |
550 | goto early_bail; | 581 | goto early_bail; |
@@ -552,11 +583,10 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
552 | acm->control->needs_remote_wakeup = 1; | 583 | acm->control->needs_remote_wakeup = 1; |
553 | 584 | ||
554 | mutex_lock(&acm->mutex); | 585 | mutex_lock(&acm->mutex); |
555 | if (acm->used++) { | 586 | if (acm->port.count++) { |
556 | usb_autopm_put_interface(acm->control); | 587 | usb_autopm_put_interface(acm->control); |
557 | goto done; | 588 | goto done; |
558 | } | 589 | } |
559 | |||
560 | 590 | ||
561 | acm->ctrlurb->dev = acm->dev; | 591 | acm->ctrlurb->dev = acm->dev; |
562 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { | 592 | if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { |
@@ -567,22 +597,22 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp) | |||
567 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && | 597 | if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && |
568 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) | 598 | (acm->ctrl_caps & USB_CDC_CAP_LINE)) |
569 | goto full_bailout; | 599 | goto full_bailout; |
600 | |||
570 | usb_autopm_put_interface(acm->control); | 601 | usb_autopm_put_interface(acm->control); |
571 | 602 | ||
572 | INIT_LIST_HEAD(&acm->spare_read_urbs); | 603 | INIT_LIST_HEAD(&acm->spare_read_urbs); |
573 | INIT_LIST_HEAD(&acm->spare_read_bufs); | 604 | INIT_LIST_HEAD(&acm->spare_read_bufs); |
574 | INIT_LIST_HEAD(&acm->filled_read_bufs); | 605 | INIT_LIST_HEAD(&acm->filled_read_bufs); |
575 | for (i = 0; i < acm->rx_buflimit; i++) { | 606 | |
607 | for (i = 0; i < acm->rx_buflimit; i++) | ||
576 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); | 608 | list_add(&(acm->ru[i].list), &acm->spare_read_urbs); |
577 | } | 609 | for (i = 0; i < acm->rx_buflimit; i++) |
578 | for (i = 0; i < acm->rx_buflimit; i++) { | ||
579 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); | 610 | list_add(&(acm->rb[i].list), &acm->spare_read_bufs); |
580 | } | ||
581 | 611 | ||
582 | acm->throttle = 0; | 612 | acm->throttle = 0; |
583 | 613 | ||
584 | tasklet_schedule(&acm->urb_task); | 614 | tasklet_schedule(&acm->urb_task); |
585 | 615 | rv = tty_port_block_til_ready(&acm->port, tty, filp); | |
586 | done: | 616 | done: |
587 | mutex_unlock(&acm->mutex); | 617 | mutex_unlock(&acm->mutex); |
588 | err_out: | 618 | err_out: |
@@ -593,16 +623,17 @@ full_bailout: | |||
593 | usb_kill_urb(acm->ctrlurb); | 623 | usb_kill_urb(acm->ctrlurb); |
594 | bail_out: | 624 | bail_out: |
595 | usb_autopm_put_interface(acm->control); | 625 | usb_autopm_put_interface(acm->control); |
596 | acm->used--; | 626 | acm->port.count--; |
597 | mutex_unlock(&acm->mutex); | 627 | mutex_unlock(&acm->mutex); |
598 | early_bail: | 628 | early_bail: |
599 | mutex_unlock(&open_mutex); | 629 | mutex_unlock(&open_mutex); |
630 | tty_port_tty_set(&acm->port, NULL); | ||
600 | return -EIO; | 631 | return -EIO; |
601 | } | 632 | } |
602 | 633 | ||
603 | static void acm_tty_unregister(struct acm *acm) | 634 | static void acm_tty_unregister(struct acm *acm) |
604 | { | 635 | { |
605 | int i,nr; | 636 | int i, nr; |
606 | 637 | ||
607 | nr = acm->rx_buflimit; | 638 | nr = acm->rx_buflimit; |
608 | tty_unregister_device(acm_tty_driver, acm->minor); | 639 | tty_unregister_device(acm_tty_driver, acm->minor); |
@@ -619,41 +650,56 @@ static void acm_tty_unregister(struct acm *acm) | |||
619 | 650 | ||
620 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); | 651 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); |
621 | 652 | ||
653 | static void acm_port_down(struct acm *acm, int drain) | ||
654 | { | ||
655 | int i, nr = acm->rx_buflimit; | ||
656 | mutex_lock(&open_mutex); | ||
657 | if (acm->dev) { | ||
658 | usb_autopm_get_interface(acm->control); | ||
659 | acm_set_control(acm, acm->ctrlout = 0); | ||
660 | /* try letting the last writes drain naturally */ | ||
661 | if (drain) { | ||
662 | wait_event_interruptible_timeout(acm->drain_wait, | ||
663 | (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev, | ||
664 | ACM_CLOSE_TIMEOUT * HZ); | ||
665 | } | ||
666 | usb_kill_urb(acm->ctrlurb); | ||
667 | for (i = 0; i < ACM_NW; i++) | ||
668 | usb_kill_urb(acm->wb[i].urb); | ||
669 | for (i = 0; i < nr; i++) | ||
670 | usb_kill_urb(acm->ru[i].urb); | ||
671 | acm->control->needs_remote_wakeup = 0; | ||
672 | usb_autopm_put_interface(acm->control); | ||
673 | } | ||
674 | mutex_unlock(&open_mutex); | ||
675 | } | ||
676 | |||
677 | static void acm_tty_hangup(struct tty_struct *tty) | ||
678 | { | ||
679 | struct acm *acm = tty->driver_data; | ||
680 | tty_port_hangup(&acm->port); | ||
681 | acm_port_down(acm, 0); | ||
682 | } | ||
683 | |||
622 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) | 684 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) |
623 | { | 685 | { |
624 | struct acm *acm = tty->driver_data; | 686 | struct acm *acm = tty->driver_data; |
625 | int i,nr; | ||
626 | 687 | ||
627 | if (!acm || !acm->used) | 688 | /* Perform the closing process and see if we need to do the hardware |
689 | shutdown */ | ||
690 | if (!acm || tty_port_close_start(&acm->port, tty, filp) == 0) | ||
628 | return; | 691 | return; |
629 | 692 | acm_port_down(acm, 0); | |
630 | nr = acm->rx_buflimit; | 693 | tty_port_close_end(&acm->port, tty); |
631 | mutex_lock(&open_mutex); | 694 | mutex_lock(&open_mutex); |
632 | if (!--acm->used) { | 695 | tty_port_tty_set(&acm->port, NULL); |
633 | if (acm->dev) { | 696 | if (!acm->dev) |
634 | usb_autopm_get_interface(acm->control); | 697 | acm_tty_unregister(acm); |
635 | acm_set_control(acm, acm->ctrlout = 0); | ||
636 | |||
637 | /* try letting the last writes drain naturally */ | ||
638 | wait_event_interruptible_timeout(acm->drain_wait, | ||
639 | (ACM_NW == acm_wb_is_avail(acm)) | ||
640 | || !acm->dev, | ||
641 | ACM_CLOSE_TIMEOUT * HZ); | ||
642 | |||
643 | usb_kill_urb(acm->ctrlurb); | ||
644 | for (i = 0; i < ACM_NW; i++) | ||
645 | usb_kill_urb(acm->wb[i].urb); | ||
646 | for (i = 0; i < nr; i++) | ||
647 | usb_kill_urb(acm->ru[i].urb); | ||
648 | acm->control->needs_remote_wakeup = 0; | ||
649 | usb_autopm_put_interface(acm->control); | ||
650 | } else | ||
651 | acm_tty_unregister(acm); | ||
652 | } | ||
653 | mutex_unlock(&open_mutex); | 698 | mutex_unlock(&open_mutex); |
654 | } | 699 | } |
655 | 700 | ||
656 | static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) | 701 | static int acm_tty_write(struct tty_struct *tty, |
702 | const unsigned char *buf, int count) | ||
657 | { | 703 | { |
658 | struct acm *acm = tty->driver_data; | 704 | struct acm *acm = tty->driver_data; |
659 | int stat; | 705 | int stat; |
@@ -669,7 +715,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
669 | return 0; | 715 | return 0; |
670 | 716 | ||
671 | spin_lock_irqsave(&acm->write_lock, flags); | 717 | spin_lock_irqsave(&acm->write_lock, flags); |
672 | if ((wbn = acm_wb_alloc(acm)) < 0) { | 718 | wbn = acm_wb_alloc(acm); |
719 | if (wbn < 0) { | ||
673 | spin_unlock_irqrestore(&acm->write_lock, flags); | 720 | spin_unlock_irqrestore(&acm->write_lock, flags); |
674 | return 0; | 721 | return 0; |
675 | } | 722 | } |
@@ -681,7 +728,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c | |||
681 | wb->len = count; | 728 | wb->len = count; |
682 | spin_unlock_irqrestore(&acm->write_lock, flags); | 729 | spin_unlock_irqrestore(&acm->write_lock, flags); |
683 | 730 | ||
684 | if ((stat = acm_write_start(acm, wbn)) < 0) | 731 | stat = acm_write_start(acm, wbn); |
732 | if (stat < 0) | ||
685 | return stat; | 733 | return stat; |
686 | return count; | 734 | return count; |
687 | } | 735 | } |
@@ -702,7 +750,7 @@ static int acm_tty_chars_in_buffer(struct tty_struct *tty) | |||
702 | { | 750 | { |
703 | struct acm *acm = tty->driver_data; | 751 | struct acm *acm = tty->driver_data; |
704 | if (!ACM_READY(acm)) | 752 | if (!ACM_READY(acm)) |
705 | return -EINVAL; | 753 | return 0; |
706 | /* | 754 | /* |
707 | * This is inaccurate (overcounts), but it works. | 755 | * This is inaccurate (overcounts), but it works. |
708 | */ | 756 | */ |
@@ -767,8 +815,10 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
767 | return -EINVAL; | 815 | return -EINVAL; |
768 | 816 | ||
769 | newctrl = acm->ctrlout; | 817 | newctrl = acm->ctrlout; |
770 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 818 | set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | |
771 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | 819 | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); |
820 | clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | | ||
821 | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); | ||
772 | 822 | ||
773 | newctrl = (newctrl & ~clear) | set; | 823 | newctrl = (newctrl & ~clear) | set; |
774 | 824 | ||
@@ -777,7 +827,8 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file, | |||
777 | return acm_set_control(acm, acm->ctrlout = newctrl); | 827 | return acm_set_control(acm, acm->ctrlout = newctrl); |
778 | } | 828 | } |
779 | 829 | ||
780 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 830 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, |
831 | unsigned int cmd, unsigned long arg) | ||
781 | { | 832 | { |
782 | struct acm *acm = tty->driver_data; | 833 | struct acm *acm = tty->driver_data; |
783 | 834 | ||
@@ -799,7 +850,8 @@ static const __u8 acm_tty_size[] = { | |||
799 | 5, 6, 7, 8 | 850 | 5, 6, 7, 8 |
800 | }; | 851 | }; |
801 | 852 | ||
802 | static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) | 853 | static void acm_tty_set_termios(struct tty_struct *tty, |
854 | struct ktermios *termios_old) | ||
803 | { | 855 | { |
804 | struct acm *acm = tty->driver_data; | 856 | struct acm *acm = tty->driver_data; |
805 | struct ktermios *termios = tty->termios; | 857 | struct ktermios *termios = tty->termios; |
@@ -809,19 +861,23 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios | |||
809 | if (!ACM_READY(acm)) | 861 | if (!ACM_READY(acm)) |
810 | return; | 862 | return; |
811 | 863 | ||
864 | /* FIXME: Needs to support the tty_baud interface */ | ||
865 | /* FIXME: Broken on sparc */ | ||
812 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + | 866 | newline.dwDTERate = cpu_to_le32p(acm_tty_speed + |
813 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); | 867 | (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); |
814 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; | 868 | newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; |
815 | newline.bParityType = termios->c_cflag & PARENB ? | 869 | newline.bParityType = termios->c_cflag & PARENB ? |
816 | (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | 870 | (termios->c_cflag & PARODD ? 1 : 2) + |
871 | (termios->c_cflag & CMSPAR ? 2 : 0) : 0; | ||
817 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; | 872 | newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; |
818 | 873 | /* FIXME: Needs to clear unsupported bits in the termios */ | |
819 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); | 874 | acm->clocal = ((termios->c_cflag & CLOCAL) != 0); |
820 | 875 | ||
821 | if (!newline.dwDTERate) { | 876 | if (!newline.dwDTERate) { |
822 | newline.dwDTERate = acm->line.dwDTERate; | 877 | newline.dwDTERate = acm->line.dwDTERate; |
823 | newctrl &= ~ACM_CTRL_DTR; | 878 | newctrl &= ~ACM_CTRL_DTR; |
824 | } else newctrl |= ACM_CTRL_DTR; | 879 | } else |
880 | newctrl |= ACM_CTRL_DTR; | ||
825 | 881 | ||
826 | if (newctrl != acm->ctrlout) | 882 | if (newctrl != acm->ctrlout) |
827 | acm_set_control(acm, acm->ctrlout = newctrl); | 883 | acm_set_control(acm, acm->ctrlout = newctrl); |
@@ -846,9 +902,8 @@ static void acm_write_buffers_free(struct acm *acm) | |||
846 | struct acm_wb *wb; | 902 | struct acm_wb *wb; |
847 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); | 903 | struct usb_device *usb_dev = interface_to_usbdev(acm->control); |
848 | 904 | ||
849 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { | 905 | for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) |
850 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); | 906 | usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); |
851 | } | ||
852 | } | 907 | } |
853 | 908 | ||
854 | static void acm_read_buffers_free(struct acm *acm) | 909 | static void acm_read_buffers_free(struct acm *acm) |
@@ -857,7 +912,8 @@ static void acm_read_buffers_free(struct acm *acm) | |||
857 | int i, n = acm->rx_buflimit; | 912 | int i, n = acm->rx_buflimit; |
858 | 913 | ||
859 | for (i = 0; i < n; i++) | 914 | for (i = 0; i < n; i++) |
860 | usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); | 915 | usb_buffer_free(usb_dev, acm->readsize, |
916 | acm->rb[i].base, acm->rb[i].dma); | ||
861 | } | 917 | } |
862 | 918 | ||
863 | /* Little helper: write buffers allocate */ | 919 | /* Little helper: write buffers allocate */ |
@@ -882,8 +938,8 @@ static int acm_write_buffers_alloc(struct acm *acm) | |||
882 | return 0; | 938 | return 0; |
883 | } | 939 | } |
884 | 940 | ||
885 | static int acm_probe (struct usb_interface *intf, | 941 | static int acm_probe(struct usb_interface *intf, |
886 | const struct usb_device_id *id) | 942 | const struct usb_device_id *id) |
887 | { | 943 | { |
888 | struct usb_cdc_union_desc *union_header = NULL; | 944 | struct usb_cdc_union_desc *union_header = NULL; |
889 | struct usb_cdc_country_functional_desc *cfd = NULL; | 945 | struct usb_cdc_country_functional_desc *cfd = NULL; |
@@ -891,13 +947,13 @@ static int acm_probe (struct usb_interface *intf, | |||
891 | int buflen = intf->altsetting->extralen; | 947 | int buflen = intf->altsetting->extralen; |
892 | struct usb_interface *control_interface; | 948 | struct usb_interface *control_interface; |
893 | struct usb_interface *data_interface; | 949 | struct usb_interface *data_interface; |
894 | struct usb_endpoint_descriptor *epctrl; | 950 | struct usb_endpoint_descriptor *epctrl = NULL; |
895 | struct usb_endpoint_descriptor *epread; | 951 | struct usb_endpoint_descriptor *epread = NULL; |
896 | struct usb_endpoint_descriptor *epwrite; | 952 | struct usb_endpoint_descriptor *epwrite = NULL; |
897 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 953 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
898 | struct acm *acm; | 954 | struct acm *acm; |
899 | int minor; | 955 | int minor; |
900 | int ctrlsize,readsize; | 956 | int ctrlsize, readsize; |
901 | u8 *buf; | 957 | u8 *buf; |
902 | u8 ac_management_function = 0; | 958 | u8 ac_management_function = 0; |
903 | u8 call_management_function = 0; | 959 | u8 call_management_function = 0; |
@@ -906,6 +962,7 @@ static int acm_probe (struct usb_interface *intf, | |||
906 | unsigned long quirks; | 962 | unsigned long quirks; |
907 | int num_rx_buf; | 963 | int num_rx_buf; |
908 | int i; | 964 | int i; |
965 | int combined_interfaces = 0; | ||
909 | 966 | ||
910 | /* normal quirks */ | 967 | /* normal quirks */ |
911 | quirks = (unsigned long)id->driver_info; | 968 | quirks = (unsigned long)id->driver_info; |
@@ -917,7 +974,7 @@ static int acm_probe (struct usb_interface *intf, | |||
917 | control_interface = usb_ifnum_to_if(usb_dev, 0); | 974 | control_interface = usb_ifnum_to_if(usb_dev, 0); |
918 | goto skip_normal_probe; | 975 | goto skip_normal_probe; |
919 | } | 976 | } |
920 | 977 | ||
921 | /* normal probing*/ | 978 | /* normal probing*/ |
922 | if (!buffer) { | 979 | if (!buffer) { |
923 | dev_err(&intf->dev, "Weird descriptor references\n"); | 980 | dev_err(&intf->dev, "Weird descriptor references\n"); |
@@ -925,8 +982,10 @@ static int acm_probe (struct usb_interface *intf, | |||
925 | } | 982 | } |
926 | 983 | ||
927 | if (!buflen) { | 984 | if (!buflen) { |
928 | if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { | 985 | if (intf->cur_altsetting->endpoint->extralen && |
929 | dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); | 986 | intf->cur_altsetting->endpoint->extra) { |
987 | dev_dbg(&intf->dev, | ||
988 | "Seeking extra descriptors on endpoint\n"); | ||
930 | buflen = intf->cur_altsetting->endpoint->extralen; | 989 | buflen = intf->cur_altsetting->endpoint->extralen; |
931 | buffer = intf->cur_altsetting->endpoint->extra; | 990 | buffer = intf->cur_altsetting->endpoint->extra; |
932 | } else { | 991 | } else { |
@@ -937,47 +996,43 @@ static int acm_probe (struct usb_interface *intf, | |||
937 | } | 996 | } |
938 | 997 | ||
939 | while (buflen > 0) { | 998 | while (buflen > 0) { |
940 | if (buffer [1] != USB_DT_CS_INTERFACE) { | 999 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
941 | dev_err(&intf->dev, "skipping garbage\n"); | 1000 | dev_err(&intf->dev, "skipping garbage\n"); |
942 | goto next_desc; | 1001 | goto next_desc; |
943 | } | 1002 | } |
944 | 1003 | ||
945 | switch (buffer [2]) { | 1004 | switch (buffer[2]) { |
946 | case USB_CDC_UNION_TYPE: /* we've found it */ | 1005 | case USB_CDC_UNION_TYPE: /* we've found it */ |
947 | if (union_header) { | 1006 | if (union_header) { |
948 | dev_err(&intf->dev, "More than one " | 1007 | dev_err(&intf->dev, "More than one " |
949 | "union descriptor, " | 1008 | "union descriptor, skipping ...\n"); |
950 | "skipping ...\n"); | 1009 | goto next_desc; |
951 | goto next_desc; | ||
952 | } | ||
953 | union_header = (struct usb_cdc_union_desc *) | ||
954 | buffer; | ||
955 | break; | ||
956 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
957 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
958 | break; | ||
959 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
960 | break; /* for now we ignore it */ | ||
961 | case USB_CDC_ACM_TYPE: | ||
962 | ac_management_function = buffer[3]; | ||
963 | break; | ||
964 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
965 | call_management_function = buffer[3]; | ||
966 | call_interface_num = buffer[4]; | ||
967 | if ((call_management_function & 3) != 3) | ||
968 | dev_err(&intf->dev, "This device " | ||
969 | "cannot do calls on its own. " | ||
970 | "It is no modem.\n"); | ||
971 | break; | ||
972 | default: | ||
973 | /* there are LOTS more CDC descriptors that | ||
974 | * could legitimately be found here. | ||
975 | */ | ||
976 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
977 | "type %02x, length %d\n", | ||
978 | buffer[2], buffer[0]); | ||
979 | break; | ||
980 | } | 1010 | } |
1011 | union_header = (struct usb_cdc_union_desc *)buffer; | ||
1012 | break; | ||
1013 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
1014 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
1015 | break; | ||
1016 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
1017 | break; /* for now we ignore it */ | ||
1018 | case USB_CDC_ACM_TYPE: | ||
1019 | ac_management_function = buffer[3]; | ||
1020 | break; | ||
1021 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
1022 | call_management_function = buffer[3]; | ||
1023 | call_interface_num = buffer[4]; | ||
1024 | if ((call_management_function & 3) != 3) | ||
1025 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); | ||
1026 | break; | ||
1027 | default: | ||
1028 | /* there are LOTS more CDC descriptors that | ||
1029 | * could legitimately be found here. | ||
1030 | */ | ||
1031 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
1032 | "type %02x, length %d\n", | ||
1033 | buffer[2], buffer[0]); | ||
1034 | break; | ||
1035 | } | ||
981 | next_desc: | 1036 | next_desc: |
982 | buflen -= buffer[0]; | 1037 | buflen -= buffer[0]; |
983 | buffer += buffer[0]; | 1038 | buffer += buffer[0]; |
@@ -985,33 +1040,72 @@ next_desc: | |||
985 | 1040 | ||
986 | if (!union_header) { | 1041 | if (!union_header) { |
987 | if (call_interface_num > 0) { | 1042 | if (call_interface_num > 0) { |
988 | dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); | 1043 | dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); |
989 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); | 1044 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); |
990 | control_interface = intf; | 1045 | control_interface = intf; |
991 | } else { | 1046 | } else { |
992 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | 1047 | if (intf->cur_altsetting->desc.bNumEndpoints != 3) { |
993 | return -ENODEV; | 1048 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); |
1049 | return -ENODEV; | ||
1050 | } else { | ||
1051 | dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n"); | ||
1052 | combined_interfaces = 1; | ||
1053 | control_interface = data_interface = intf; | ||
1054 | goto look_for_collapsed_interface; | ||
1055 | } | ||
994 | } | 1056 | } |
995 | } else { | 1057 | } else { |
996 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | 1058 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); |
997 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); | 1059 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); |
998 | if (!control_interface || !data_interface) { | 1060 | if (!control_interface || !data_interface) { |
999 | dev_dbg(&intf->dev,"no interfaces\n"); | 1061 | dev_dbg(&intf->dev, "no interfaces\n"); |
1000 | return -ENODEV; | 1062 | return -ENODEV; |
1001 | } | 1063 | } |
1002 | } | 1064 | } |
1003 | 1065 | ||
1004 | if (data_interface_num != call_interface_num) | 1066 | if (data_interface_num != call_interface_num) |
1005 | dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); | 1067 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1068 | |||
1069 | if (control_interface == data_interface) { | ||
1070 | /* some broken devices designed for windows work this way */ | ||
1071 | dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); | ||
1072 | combined_interfaces = 1; | ||
1073 | /* a popular other OS doesn't use it */ | ||
1074 | quirks |= NO_CAP_LINE; | ||
1075 | if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { | ||
1076 | dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); | ||
1077 | return -EINVAL; | ||
1078 | } | ||
1079 | look_for_collapsed_interface: | ||
1080 | for (i = 0; i < 3; i++) { | ||
1081 | struct usb_endpoint_descriptor *ep; | ||
1082 | ep = &data_interface->cur_altsetting->endpoint[i].desc; | ||
1083 | |||
1084 | if (usb_endpoint_is_int_in(ep)) | ||
1085 | epctrl = ep; | ||
1086 | else if (usb_endpoint_is_bulk_out(ep)) | ||
1087 | epwrite = ep; | ||
1088 | else if (usb_endpoint_is_bulk_in(ep)) | ||
1089 | epread = ep; | ||
1090 | else | ||
1091 | return -EINVAL; | ||
1092 | } | ||
1093 | if (!epctrl || !epread || !epwrite) | ||
1094 | return -ENODEV; | ||
1095 | else | ||
1096 | goto made_compressed_probe; | ||
1097 | } | ||
1006 | 1098 | ||
1007 | skip_normal_probe: | 1099 | skip_normal_probe: |
1008 | 1100 | ||
1009 | /*workaround for switched interfaces */ | 1101 | /*workaround for switched interfaces */ |
1010 | if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { | 1102 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1011 | if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { | 1103 | != CDC_DATA_INTERFACE_TYPE) { |
1104 | if (control_interface->cur_altsetting->desc.bInterfaceClass | ||
1105 | == CDC_DATA_INTERFACE_TYPE) { | ||
1012 | struct usb_interface *t; | 1106 | struct usb_interface *t; |
1013 | dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); | 1107 | dev_dbg(&intf->dev, |
1014 | 1108 | "Your device has switched interfaces.\n"); | |
1015 | t = control_interface; | 1109 | t = control_interface; |
1016 | control_interface = data_interface; | 1110 | control_interface = data_interface; |
1017 | data_interface = t; | 1111 | data_interface = t; |
@@ -1021,11 +1115,12 @@ skip_normal_probe: | |||
1021 | } | 1115 | } |
1022 | 1116 | ||
1023 | /* Accept probe requests only for the control interface */ | 1117 | /* Accept probe requests only for the control interface */ |
1024 | if (intf != control_interface) | 1118 | if (!combined_interfaces && intf != control_interface) |
1025 | return -ENODEV; | 1119 | return -ENODEV; |
1026 | 1120 | ||
1027 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ | 1121 | if (!combined_interfaces && usb_interface_claimed(data_interface)) { |
1028 | dev_dbg(&intf->dev,"The data interface isn't available\n"); | 1122 | /* valid in this context */ |
1123 | dev_dbg(&intf->dev, "The data interface isn't available\n"); | ||
1029 | return -EBUSY; | 1124 | return -EBUSY; |
1030 | } | 1125 | } |
1031 | 1126 | ||
@@ -1042,12 +1137,13 @@ skip_normal_probe: | |||
1042 | if (!usb_endpoint_dir_in(epread)) { | 1137 | if (!usb_endpoint_dir_in(epread)) { |
1043 | /* descriptors are swapped */ | 1138 | /* descriptors are swapped */ |
1044 | struct usb_endpoint_descriptor *t; | 1139 | struct usb_endpoint_descriptor *t; |
1045 | dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); | 1140 | dev_dbg(&intf->dev, |
1046 | 1141 | "The data interface has switched endpoints\n"); | |
1047 | t = epread; | 1142 | t = epread; |
1048 | epread = epwrite; | 1143 | epread = epwrite; |
1049 | epwrite = t; | 1144 | epwrite = t; |
1050 | } | 1145 | } |
1146 | made_compressed_probe: | ||
1051 | dbg("interfaces are valid"); | 1147 | dbg("interfaces are valid"); |
1052 | for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++); | 1148 | for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++); |
1053 | 1149 | ||
@@ -1056,19 +1152,24 @@ skip_normal_probe: | |||
1056 | return -ENODEV; | 1152 | return -ENODEV; |
1057 | } | 1153 | } |
1058 | 1154 | ||
1059 | if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { | 1155 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1156 | if (acm == NULL) { | ||
1060 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); | 1157 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); |
1061 | goto alloc_fail; | 1158 | goto alloc_fail; |
1062 | } | 1159 | } |
1063 | 1160 | ||
1064 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); | 1161 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); |
1065 | readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); | 1162 | readsize = le16_to_cpu(epread->wMaxPacketSize) * |
1163 | (quirks == SINGLE_RX_URB ? 1 : 2); | ||
1164 | acm->combined_interfaces = combined_interfaces; | ||
1066 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; | 1165 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; |
1067 | acm->control = control_interface; | 1166 | acm->control = control_interface; |
1068 | acm->data = data_interface; | 1167 | acm->data = data_interface; |
1069 | acm->minor = minor; | 1168 | acm->minor = minor; |
1070 | acm->dev = usb_dev; | 1169 | acm->dev = usb_dev; |
1071 | acm->ctrl_caps = ac_management_function; | 1170 | acm->ctrl_caps = ac_management_function; |
1171 | if (quirks & NO_CAP_LINE) | ||
1172 | acm->ctrl_caps &= ~USB_CDC_CAP_LINE; | ||
1072 | acm->ctrlsize = ctrlsize; | 1173 | acm->ctrlsize = ctrlsize; |
1073 | acm->readsize = readsize; | 1174 | acm->readsize = readsize; |
1074 | acm->rx_buflimit = num_rx_buf; | 1175 | acm->rx_buflimit = num_rx_buf; |
@@ -1082,6 +1183,8 @@ skip_normal_probe: | |||
1082 | spin_lock_init(&acm->read_lock); | 1183 | spin_lock_init(&acm->read_lock); |
1083 | mutex_init(&acm->mutex); | 1184 | mutex_init(&acm->mutex); |
1084 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); | 1185 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
1186 | tty_port_init(&acm->port); | ||
1187 | acm->port.ops = &acm_port_ops; | ||
1085 | 1188 | ||
1086 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 1189 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1087 | if (!buf) { | 1190 | if (!buf) { |
@@ -1103,8 +1206,10 @@ skip_normal_probe: | |||
1103 | for (i = 0; i < num_rx_buf; i++) { | 1206 | for (i = 0; i < num_rx_buf; i++) { |
1104 | struct acm_ru *rcv = &(acm->ru[i]); | 1207 | struct acm_ru *rcv = &(acm->ru[i]); |
1105 | 1208 | ||
1106 | if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1209 | rcv->urb = usb_alloc_urb(0, GFP_KERNEL); |
1107 | dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); | 1210 | if (rcv->urb == NULL) { |
1211 | dev_dbg(&intf->dev, | ||
1212 | "out of memory (read urbs usb_alloc_urb)\n"); | ||
1108 | goto alloc_fail7; | 1213 | goto alloc_fail7; |
1109 | } | 1214 | } |
1110 | 1215 | ||
@@ -1117,26 +1222,34 @@ skip_normal_probe: | |||
1117 | rb->base = usb_buffer_alloc(acm->dev, readsize, | 1222 | rb->base = usb_buffer_alloc(acm->dev, readsize, |
1118 | GFP_KERNEL, &rb->dma); | 1223 | GFP_KERNEL, &rb->dma); |
1119 | if (!rb->base) { | 1224 | if (!rb->base) { |
1120 | dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); | 1225 | dev_dbg(&intf->dev, |
1226 | "out of memory (read bufs usb_buffer_alloc)\n"); | ||
1121 | goto alloc_fail7; | 1227 | goto alloc_fail7; |
1122 | } | 1228 | } |
1123 | } | 1229 | } |
1124 | for(i = 0; i < ACM_NW; i++) | 1230 | for (i = 0; i < ACM_NW; i++) { |
1125 | { | ||
1126 | struct acm_wb *snd = &(acm->wb[i]); | 1231 | struct acm_wb *snd = &(acm->wb[i]); |
1127 | 1232 | ||
1128 | if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1233 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1129 | dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); | 1234 | if (snd->urb == NULL) { |
1235 | dev_dbg(&intf->dev, | ||
1236 | "out of memory (write urbs usb_alloc_urb)"); | ||
1130 | goto alloc_fail7; | 1237 | goto alloc_fail7; |
1131 | } | 1238 | } |
1132 | 1239 | ||
1133 | usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | 1240 | if (usb_endpoint_xfer_int(epwrite)) |
1241 | usb_fill_int_urb(snd->urb, usb_dev, | ||
1242 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | ||
1243 | NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); | ||
1244 | else | ||
1245 | usb_fill_bulk_urb(snd->urb, usb_dev, | ||
1246 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | ||
1134 | NULL, acm->writesize, acm_write_bulk, snd); | 1247 | NULL, acm->writesize, acm_write_bulk, snd); |
1135 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1248 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1136 | snd->instance = acm; | 1249 | snd->instance = acm; |
1137 | } | 1250 | } |
1138 | 1251 | ||
1139 | usb_set_intfdata (intf, acm); | 1252 | usb_set_intfdata(intf, acm); |
1140 | 1253 | ||
1141 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | 1254 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); |
1142 | if (i < 0) | 1255 | if (i < 0) |
@@ -1147,7 +1260,8 @@ skip_normal_probe: | |||
1147 | if (!acm->country_codes) | 1260 | if (!acm->country_codes) |
1148 | goto skip_countries; | 1261 | goto skip_countries; |
1149 | acm->country_code_size = cfd->bLength - 4; | 1262 | acm->country_code_size = cfd->bLength - 4; |
1150 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | 1263 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1264 | cfd->bLength - 4); | ||
1151 | acm->country_rel_date = cfd->iCountryCodeRelDate; | 1265 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1152 | 1266 | ||
1153 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | 1267 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); |
@@ -1156,7 +1270,8 @@ skip_normal_probe: | |||
1156 | goto skip_countries; | 1270 | goto skip_countries; |
1157 | } | 1271 | } |
1158 | 1272 | ||
1159 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | 1273 | i = device_create_file(&intf->dev, |
1274 | &dev_attr_iCountryCodeRelDate); | ||
1160 | if (i < 0) { | 1275 | if (i < 0) { |
1161 | kfree(acm->country_codes); | 1276 | kfree(acm->country_codes); |
1162 | goto skip_countries; | 1277 | goto skip_countries; |
@@ -1164,8 +1279,11 @@ skip_normal_probe: | |||
1164 | } | 1279 | } |
1165 | 1280 | ||
1166 | skip_countries: | 1281 | skip_countries: |
1167 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 1282 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
1168 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 1283 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1284 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | ||
1285 | /* works around buggy devices */ | ||
1286 | epctrl->bInterval ? epctrl->bInterval : 0xff); | ||
1169 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1287 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1170 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | 1288 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; |
1171 | 1289 | ||
@@ -1212,7 +1330,7 @@ static void stop_data_traffic(struct acm *acm) | |||
1212 | tasklet_disable(&acm->urb_task); | 1330 | tasklet_disable(&acm->urb_task); |
1213 | 1331 | ||
1214 | usb_kill_urb(acm->ctrlurb); | 1332 | usb_kill_urb(acm->ctrlurb); |
1215 | for(i = 0; i < ACM_NW; i++) | 1333 | for (i = 0; i < ACM_NW; i++) |
1216 | usb_kill_urb(acm->wb[i].urb); | 1334 | usb_kill_urb(acm->wb[i].urb); |
1217 | for (i = 0; i < acm->rx_buflimit; i++) | 1335 | for (i = 0; i < acm->rx_buflimit; i++) |
1218 | usb_kill_urb(acm->ru[i].urb); | 1336 | usb_kill_urb(acm->ru[i].urb); |
@@ -1227,13 +1345,14 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1227 | { | 1345 | { |
1228 | struct acm *acm = usb_get_intfdata(intf); | 1346 | struct acm *acm = usb_get_intfdata(intf); |
1229 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 1347 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1348 | struct tty_struct *tty; | ||
1230 | 1349 | ||
1231 | /* sibling interface is already cleaning up */ | 1350 | /* sibling interface is already cleaning up */ |
1232 | if (!acm) | 1351 | if (!acm) |
1233 | return; | 1352 | return; |
1234 | 1353 | ||
1235 | mutex_lock(&open_mutex); | 1354 | mutex_lock(&open_mutex); |
1236 | if (acm->country_codes){ | 1355 | if (acm->country_codes) { |
1237 | device_remove_file(&acm->control->dev, | 1356 | device_remove_file(&acm->control->dev, |
1238 | &dev_attr_wCountryCodes); | 1357 | &dev_attr_wCountryCodes); |
1239 | device_remove_file(&acm->control->dev, | 1358 | device_remove_file(&acm->control->dev, |
@@ -1247,22 +1366,26 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1247 | stop_data_traffic(acm); | 1366 | stop_data_traffic(acm); |
1248 | 1367 | ||
1249 | acm_write_buffers_free(acm); | 1368 | acm_write_buffers_free(acm); |
1250 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 1369 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, |
1370 | acm->ctrl_dma); | ||
1251 | acm_read_buffers_free(acm); | 1371 | acm_read_buffers_free(acm); |
1252 | 1372 | ||
1253 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | 1373 | if (!acm->combined_interfaces) |
1374 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | ||
1254 | acm->data : acm->control); | 1375 | acm->data : acm->control); |
1255 | 1376 | ||
1256 | if (!acm->used) { | 1377 | if (acm->port.count == 0) { |
1257 | acm_tty_unregister(acm); | 1378 | acm_tty_unregister(acm); |
1258 | mutex_unlock(&open_mutex); | 1379 | mutex_unlock(&open_mutex); |
1259 | return; | 1380 | return; |
1260 | } | 1381 | } |
1261 | 1382 | ||
1262 | mutex_unlock(&open_mutex); | 1383 | mutex_unlock(&open_mutex); |
1263 | 1384 | tty = tty_port_tty_get(&acm->port); | |
1264 | if (acm->tty) | 1385 | if (tty) { |
1265 | tty_hangup(acm->tty); | 1386 | tty_hangup(tty); |
1387 | tty_kref_put(tty); | ||
1388 | } | ||
1266 | } | 1389 | } |
1267 | 1390 | ||
1268 | #ifdef CONFIG_PM | 1391 | #ifdef CONFIG_PM |
@@ -1297,7 +1420,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1297 | */ | 1420 | */ |
1298 | mutex_lock(&acm->mutex); | 1421 | mutex_lock(&acm->mutex); |
1299 | 1422 | ||
1300 | if (acm->used) | 1423 | if (acm->port.count) |
1301 | stop_data_traffic(acm); | 1424 | stop_data_traffic(acm); |
1302 | 1425 | ||
1303 | mutex_unlock(&acm->mutex); | 1426 | mutex_unlock(&acm->mutex); |
@@ -1319,7 +1442,7 @@ static int acm_resume(struct usb_interface *intf) | |||
1319 | return 0; | 1442 | return 0; |
1320 | 1443 | ||
1321 | mutex_lock(&acm->mutex); | 1444 | mutex_lock(&acm->mutex); |
1322 | if (acm->used) { | 1445 | if (acm->port.count) { |
1323 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 1446 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); |
1324 | if (rv < 0) | 1447 | if (rv < 0) |
1325 | goto err_out; | 1448 | goto err_out; |
@@ -1387,6 +1510,9 @@ static struct usb_device_id acm_ids[] = { | |||
1387 | Maybe we should define a new | 1510 | Maybe we should define a new |
1388 | quirk for this. */ | 1511 | quirk for this. */ |
1389 | }, | 1512 | }, |
1513 | { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */ | ||
1514 | .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */ | ||
1515 | }, | ||
1390 | 1516 | ||
1391 | /* control interfaces with various AT-command sets */ | 1517 | /* control interfaces with various AT-command sets */ |
1392 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1518 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
@@ -1398,7 +1524,7 @@ static struct usb_device_id acm_ids[] = { | |||
1398 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1524 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1399 | USB_CDC_ACM_PROTO_AT_GSM) }, | 1525 | USB_CDC_ACM_PROTO_AT_GSM) }, |
1400 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1526 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1401 | USB_CDC_ACM_PROTO_AT_3G ) }, | 1527 | USB_CDC_ACM_PROTO_AT_3G) }, |
1402 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1528 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1403 | USB_CDC_ACM_PROTO_AT_CDMA) }, | 1529 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
1404 | 1530 | ||
@@ -1406,7 +1532,7 @@ static struct usb_device_id acm_ids[] = { | |||
1406 | { } | 1532 | { } |
1407 | }; | 1533 | }; |
1408 | 1534 | ||
1409 | MODULE_DEVICE_TABLE (usb, acm_ids); | 1535 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1410 | 1536 | ||
1411 | static struct usb_driver acm_driver = { | 1537 | static struct usb_driver acm_driver = { |
1412 | .name = "cdc_acm", | 1538 | .name = "cdc_acm", |
@@ -1429,6 +1555,7 @@ static struct usb_driver acm_driver = { | |||
1429 | static const struct tty_operations acm_ops = { | 1555 | static const struct tty_operations acm_ops = { |
1430 | .open = acm_tty_open, | 1556 | .open = acm_tty_open, |
1431 | .close = acm_tty_close, | 1557 | .close = acm_tty_close, |
1558 | .hangup = acm_tty_hangup, | ||
1432 | .write = acm_tty_write, | 1559 | .write = acm_tty_write, |
1433 | .write_room = acm_tty_write_room, | 1560 | .write_room = acm_tty_write_room, |
1434 | .ioctl = acm_tty_ioctl, | 1561 | .ioctl = acm_tty_ioctl, |
@@ -1460,7 +1587,8 @@ static int __init acm_init(void) | |||
1460 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | 1587 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, |
1461 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 1588 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1462 | acm_tty_driver->init_termios = tty_std_termios; | 1589 | acm_tty_driver->init_termios = tty_std_termios; |
1463 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 1590 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
1591 | HUPCL | CLOCAL; | ||
1464 | tty_set_operations(acm_tty_driver, &acm_ops); | 1592 | tty_set_operations(acm_tty_driver, &acm_ops); |
1465 | 1593 | ||
1466 | retval = tty_register_driver(acm_tty_driver); | 1594 | retval = tty_register_driver(acm_tty_driver); |
@@ -1492,7 +1620,7 @@ static void __exit acm_exit(void) | |||
1492 | module_init(acm_init); | 1620 | module_init(acm_init); |
1493 | module_exit(acm_exit); | 1621 | module_exit(acm_exit); |
1494 | 1622 | ||
1495 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1623 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1496 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1624 | MODULE_DESCRIPTION(DRIVER_DESC); |
1497 | MODULE_LICENSE("GPL"); | 1625 | MODULE_LICENSE("GPL"); |
1498 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); | 1626 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h index 1f95e7aa1b66..1602324808ba 100644 --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h | |||
@@ -89,8 +89,8 @@ struct acm { | |||
89 | struct usb_device *dev; /* the corresponding usb device */ | 89 | struct usb_device *dev; /* the corresponding usb device */ |
90 | struct usb_interface *control; /* control interface */ | 90 | struct usb_interface *control; /* control interface */ |
91 | struct usb_interface *data; /* data interface */ | 91 | struct usb_interface *data; /* data interface */ |
92 | struct tty_struct *tty; /* the corresponding tty */ | 92 | struct tty_port port; /* our tty port data */ |
93 | struct urb *ctrlurb; /* urbs */ | 93 | struct urb *ctrlurb; /* urbs */ |
94 | u8 *ctrl_buffer; /* buffers of urbs */ | 94 | u8 *ctrl_buffer; /* buffers of urbs */ |
95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ | 95 | dma_addr_t ctrl_dma; /* dma handles of buffers */ |
96 | u8 *country_codes; /* country codes from device */ | 96 | u8 *country_codes; /* country codes from device */ |
@@ -120,12 +120,12 @@ struct acm { | |||
120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ | 120 | unsigned int ctrlout; /* output control lines (DTR, RTS) */ |
121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ | 121 | unsigned int writesize; /* max packet size for the output bulk endpoint */ |
122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ | 122 | unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ |
123 | unsigned int used; /* someone has this acm's device open */ | ||
124 | unsigned int minor; /* acm minor number */ | 123 | unsigned int minor; /* acm minor number */ |
125 | unsigned char throttle; /* throttled by tty layer */ | 124 | unsigned char throttle; /* throttled by tty layer */ |
126 | unsigned char clocal; /* termios CLOCAL */ | 125 | unsigned char clocal; /* termios CLOCAL */ |
127 | unsigned int ctrl_caps; /* control capabilities from the class specific header */ | 126 | unsigned int ctrl_caps; /* control capabilities from the class specific header */ |
128 | unsigned int susp_count; /* number of suspended interfaces */ | 127 | unsigned int susp_count; /* number of suspended interfaces */ |
128 | int combined_interfaces:1; /* control and data collapsed */ | ||
129 | struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ | 129 | struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ |
130 | }; | 130 | }; |
131 | 131 | ||
@@ -134,3 +134,4 @@ struct acm { | |||
134 | /* constants describing various quirks and errors */ | 134 | /* constants describing various quirks and errors */ |
135 | #define NO_UNION_NORMAL 1 | 135 | #define NO_UNION_NORMAL 1 |
136 | #define SINGLE_RX_URB 2 | 136 | #define SINGLE_RX_URB 2 |
137 | #define NO_CAP_LINE 4 | ||
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c index 0fe434505ac4..ba589d4ca8bc 100644 --- a/drivers/usb/class/cdc-wdm.c +++ b/drivers/usb/class/cdc-wdm.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
16 | #include <linux/slab.h> | 16 | #include <linux/slab.h> |
17 | #include <linux/module.h> | 17 | #include <linux/module.h> |
18 | #include <linux/smp_lock.h> | ||
19 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
20 | #include <linux/uaccess.h> | 19 | #include <linux/uaccess.h> |
21 | #include <linux/bitops.h> | 20 | #include <linux/bitops.h> |
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c index d2747a49b974..26c09f0257db 100644 --- a/drivers/usb/class/usblp.c +++ b/drivers/usb/class/usblp.c | |||
@@ -1057,8 +1057,14 @@ static const struct file_operations usblp_fops = { | |||
1057 | .release = usblp_release, | 1057 | .release = usblp_release, |
1058 | }; | 1058 | }; |
1059 | 1059 | ||
1060 | static char *usblp_nodename(struct device *dev) | ||
1061 | { | ||
1062 | return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev)); | ||
1063 | } | ||
1064 | |||
1060 | static struct usb_class_driver usblp_class = { | 1065 | static struct usb_class_driver usblp_class = { |
1061 | .name = "lp%d", | 1066 | .name = "lp%d", |
1067 | .nodename = usblp_nodename, | ||
1062 | .fops = &usblp_fops, | 1068 | .fops = &usblp_fops, |
1063 | .minor_base = USBLP_MINOR_BASE, | 1069 | .minor_base = USBLP_MINOR_BASE, |
1064 | }; | 1070 | }; |
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c index c40a9b284cc9..b09a527f7341 100644 --- a/drivers/usb/class/usbtmc.c +++ b/drivers/usb/class/usbtmc.c | |||
@@ -751,7 +751,7 @@ static int get_capabilities(struct usbtmc_device_data *data) | |||
751 | { | 751 | { |
752 | struct device *dev = &data->usb_dev->dev; | 752 | struct device *dev = &data->usb_dev->dev; |
753 | char *buffer; | 753 | char *buffer; |
754 | int rv; | 754 | int rv = 0; |
755 | 755 | ||
756 | buffer = kmalloc(0x18, GFP_KERNEL); | 756 | buffer = kmalloc(0x18, GFP_KERNEL); |
757 | if (!buffer) | 757 | if (!buffer) |
@@ -763,7 +763,7 @@ static int get_capabilities(struct usbtmc_device_data *data) | |||
763 | 0, 0, buffer, 0x18, USBTMC_TIMEOUT); | 763 | 0, 0, buffer, 0x18, USBTMC_TIMEOUT); |
764 | if (rv < 0) { | 764 | if (rv < 0) { |
765 | dev_err(dev, "usb_control_msg returned %d\n", rv); | 765 | dev_err(dev, "usb_control_msg returned %d\n", rv); |
766 | return rv; | 766 | goto err_out; |
767 | } | 767 | } |
768 | 768 | ||
769 | dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); | 769 | dev_dbg(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
@@ -773,7 +773,8 @@ static int get_capabilities(struct usbtmc_device_data *data) | |||
773 | dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]); | 773 | dev_dbg(dev, "USB488 device capabilities are %x\n", buffer[15]); |
774 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { | 774 | if (buffer[0] != USBTMC_STATUS_SUCCESS) { |
775 | dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); | 775 | dev_err(dev, "GET_CAPABILITIES returned %x\n", buffer[0]); |
776 | return -EPERM; | 776 | rv = -EPERM; |
777 | goto err_out; | ||
777 | } | 778 | } |
778 | 779 | ||
779 | data->capabilities.interface_capabilities = buffer[4]; | 780 | data->capabilities.interface_capabilities = buffer[4]; |
@@ -781,8 +782,9 @@ static int get_capabilities(struct usbtmc_device_data *data) | |||
781 | data->capabilities.usb488_interface_capabilities = buffer[14]; | 782 | data->capabilities.usb488_interface_capabilities = buffer[14]; |
782 | data->capabilities.usb488_device_capabilities = buffer[15]; | 783 | data->capabilities.usb488_device_capabilities = buffer[15]; |
783 | 784 | ||
785 | err_out: | ||
784 | kfree(buffer); | 786 | kfree(buffer); |
785 | return 0; | 787 | return rv; |
786 | } | 788 | } |
787 | 789 | ||
788 | #define capability_attribute(name) \ | 790 | #define capability_attribute(name) \ |
@@ -927,21 +929,27 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
927 | switch (cmd) { | 929 | switch (cmd) { |
928 | case USBTMC_IOCTL_CLEAR_OUT_HALT: | 930 | case USBTMC_IOCTL_CLEAR_OUT_HALT: |
929 | retval = usbtmc_ioctl_clear_out_halt(data); | 931 | retval = usbtmc_ioctl_clear_out_halt(data); |
932 | break; | ||
930 | 933 | ||
931 | case USBTMC_IOCTL_CLEAR_IN_HALT: | 934 | case USBTMC_IOCTL_CLEAR_IN_HALT: |
932 | retval = usbtmc_ioctl_clear_in_halt(data); | 935 | retval = usbtmc_ioctl_clear_in_halt(data); |
936 | break; | ||
933 | 937 | ||
934 | case USBTMC_IOCTL_INDICATOR_PULSE: | 938 | case USBTMC_IOCTL_INDICATOR_PULSE: |
935 | retval = usbtmc_ioctl_indicator_pulse(data); | 939 | retval = usbtmc_ioctl_indicator_pulse(data); |
940 | break; | ||
936 | 941 | ||
937 | case USBTMC_IOCTL_CLEAR: | 942 | case USBTMC_IOCTL_CLEAR: |
938 | retval = usbtmc_ioctl_clear(data); | 943 | retval = usbtmc_ioctl_clear(data); |
944 | break; | ||
939 | 945 | ||
940 | case USBTMC_IOCTL_ABORT_BULK_OUT: | 946 | case USBTMC_IOCTL_ABORT_BULK_OUT: |
941 | retval = usbtmc_ioctl_abort_bulk_out(data); | 947 | retval = usbtmc_ioctl_abort_bulk_out(data); |
948 | break; | ||
942 | 949 | ||
943 | case USBTMC_IOCTL_ABORT_BULK_IN: | 950 | case USBTMC_IOCTL_ABORT_BULK_IN: |
944 | retval = usbtmc_ioctl_abort_bulk_in(data); | 951 | retval = usbtmc_ioctl_abort_bulk_in(data); |
952 | break; | ||
945 | } | 953 | } |
946 | 954 | ||
947 | mutex_unlock(&data->io_mutex); | 955 | mutex_unlock(&data->io_mutex); |