Lines Matching full:acm
3 * f_acm.c -- USB CDC serial (ACM) function driver
24 * This CDC ACM function support just wraps control functions and
27 * Because CDC ACM is standardized by the USB-IF, many host operating
28 * systems have drivers for it. Accordingly, ACM is the preferred
33 * Note that even MS-Windows has some support for ACM. However, that
34 * support is somewhat broken because when you use ACM in a composite
272 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
273 [ACM_DATA_IDX].s = "CDC ACM Data",
290 /* ACM control ... data handling is delegated to tty library code.
299 struct f_acm *acm = ep->driver_data; in acm_complete_set_line_coding() local
300 struct usb_composite_dev *cdev = acm->port.func.config->cdev; in acm_complete_set_line_coding()
303 dev_dbg(&cdev->gadget->dev, "acm ttyGS%d completion, err %d\n", in acm_complete_set_line_coding()
304 acm->port_num, req->status); in acm_complete_set_line_coding()
309 if (req->actual != sizeof(acm->port_line_coding)) { in acm_complete_set_line_coding()
310 dev_dbg(&cdev->gadget->dev, "acm ttyGS%d short resp, len %d\n", in acm_complete_set_line_coding()
311 acm->port_num, req->actual); in acm_complete_set_line_coding()
323 acm->port_line_coding = *value; in acm_complete_set_line_coding()
331 struct f_acm *acm = func_to_acm(f); in acm_setup() local
342 * Note CDC spec table 4 lists the ACM request profile. It requires in acm_setup()
353 || w_index != acm->ctrl_id) in acm_setup()
357 cdev->gadget->ep0->driver_data = acm; in acm_setup()
364 if (w_index != acm->ctrl_id) in acm_setup()
369 memcpy(req->buf, &acm->port_line_coding, value); in acm_setup()
375 if (w_index != acm->ctrl_id) in acm_setup()
384 acm->port_handshake_bits = w_value; in acm_setup()
389 if (w_index != acm->ctrl_id) in acm_setup()
392 acm_send_break(&acm->port, w_value); in acm_setup()
406 "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n", in acm_setup()
407 acm->port_num, ctrl->bRequestType, ctrl->bRequest, in acm_setup()
413 ERROR(cdev, "acm response on ttyGS%d, err %d\n", in acm_setup()
414 acm->port_num, value); in acm_setup()
423 struct f_acm *acm = func_to_acm(f); in acm_set_alt() local
428 if (intf == acm->ctrl_id) { in acm_set_alt()
429 if (acm->notify->enabled) { in acm_set_alt()
431 "reset acm control interface %d\n", intf); in acm_set_alt()
432 usb_ep_disable(acm->notify); in acm_set_alt()
435 if (!acm->notify->desc) in acm_set_alt()
436 if (config_ep_by_speed(cdev->gadget, f, acm->notify)) in acm_set_alt()
439 usb_ep_enable(acm->notify); in acm_set_alt()
441 } else if (intf == acm->data_id) { in acm_set_alt()
442 if (acm->notify->enabled) { in acm_set_alt()
444 "reset acm ttyGS%d\n", acm->port_num); in acm_set_alt()
445 gserial_disconnect(&acm->port); in acm_set_alt()
447 if (!acm->port.in->desc || !acm->port.out->desc) { in acm_set_alt()
449 "activate acm ttyGS%d\n", acm->port_num); in acm_set_alt()
451 acm->port.in) || in acm_set_alt()
453 acm->port.out)) { in acm_set_alt()
454 acm->port.in->desc = NULL; in acm_set_alt()
455 acm->port.out->desc = NULL; in acm_set_alt()
459 gserial_connect(&acm->port, acm->port_num); in acm_set_alt()
469 struct f_acm *acm = func_to_acm(f); in acm_disable() local
472 dev_dbg(&cdev->gadget->dev, "acm ttyGS%d deactivated\n", acm->port_num); in acm_disable()
473 gserial_disconnect(&acm->port); in acm_disable()
474 usb_ep_disable(acm->notify); in acm_disable()
481 * @acm: wraps host to be notified
486 * Context: irqs blocked, acm->lock held, acm_notify_req non-null
493 static int acm_cdc_notify(struct f_acm *acm, u8 type, u16 value, in acm_cdc_notify() argument
496 struct usb_ep *ep = acm->notify; in acm_cdc_notify()
503 req = acm->notify_req; in acm_cdc_notify()
504 acm->notify_req = NULL; in acm_cdc_notify()
505 acm->pending = false; in acm_cdc_notify()
515 notify->wIndex = cpu_to_le16(acm->ctrl_id); in acm_cdc_notify()
520 spin_unlock(&acm->lock); in acm_cdc_notify()
522 spin_lock(&acm->lock); in acm_cdc_notify()
525 ERROR(acm->port.func.config->cdev, in acm_cdc_notify()
526 "acm ttyGS%d can't notify serial state, %d\n", in acm_cdc_notify()
527 acm->port_num, status); in acm_cdc_notify()
528 acm->notify_req = req; in acm_cdc_notify()
534 static int acm_notify_serial_state(struct f_acm *acm) in acm_notify_serial_state() argument
536 struct usb_composite_dev *cdev = acm->port.func.config->cdev; in acm_notify_serial_state()
540 spin_lock(&acm->lock); in acm_notify_serial_state()
541 if (acm->notify_req) { in acm_notify_serial_state()
542 dev_dbg(&cdev->gadget->dev, "acm ttyGS%d serial state %04x\n", in acm_notify_serial_state()
543 acm->port_num, acm->serial_state); in acm_notify_serial_state()
544 serial_state = cpu_to_le16(acm->serial_state); in acm_notify_serial_state()
545 status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE, in acm_notify_serial_state()
546 0, &serial_state, sizeof(acm->serial_state)); in acm_notify_serial_state()
548 acm->pending = true; in acm_notify_serial_state()
551 spin_unlock(&acm->lock); in acm_notify_serial_state()
557 struct f_acm *acm = req->context; in acm_cdc_notify_complete() local
561 * which is why ACM needs its own spinlock in acm_cdc_notify_complete()
563 spin_lock(&acm->lock); in acm_cdc_notify_complete()
565 doit = acm->pending; in acm_cdc_notify_complete()
566 acm->notify_req = req; in acm_cdc_notify_complete()
567 spin_unlock(&acm->lock); in acm_cdc_notify_complete()
570 acm_notify_serial_state(acm); in acm_cdc_notify_complete()
577 struct f_acm *acm = port_to_acm(port); in acm_connect() local
579 acm->serial_state |= USB_CDC_SERIAL_STATE_DSR | USB_CDC_SERIAL_STATE_DCD; in acm_connect()
580 acm_notify_serial_state(acm); in acm_connect()
585 struct f_acm *acm = port_to_acm(port); in acm_disconnect() local
587 acm->serial_state &= ~(USB_CDC_SERIAL_STATE_DSR | USB_CDC_SERIAL_STATE_DCD); in acm_disconnect()
588 acm_notify_serial_state(acm); in acm_disconnect()
593 struct f_acm *acm = port_to_acm(port); in acm_send_break() local
596 state = acm->serial_state; in acm_send_break()
601 acm->serial_state = state; in acm_send_break()
602 return acm_notify_serial_state(acm); in acm_send_break()
607 /* ACM function driver setup/binding */
612 struct f_acm *acm = func_to_acm(f); in acm_bind() local
634 acm->ctrl_id = status; in acm_bind()
643 acm->data_id = status; in acm_bind()
655 acm->port.in = ep; in acm_bind()
660 acm->port.out = ep; in acm_bind()
665 acm->notify = ep; in acm_bind()
667 acm_iad_descriptor.bFunctionProtocol = acm->bInterfaceProtocol; in acm_bind()
668 acm_control_interface_desc.bInterfaceProtocol = acm->bInterfaceProtocol; in acm_bind()
671 acm->notify_req = gs_alloc_req(ep, in acm_bind()
674 if (!acm->notify_req) in acm_bind()
677 acm->notify_req->complete = acm_cdc_notify_complete; in acm_bind()
678 acm->notify_req->context = acm; in acm_bind()
698 "acm ttyGS%d: IN/%s OUT/%s NOTIFY/%s\n", in acm_bind()
699 acm->port_num, in acm_bind()
700 acm->port.in->name, acm->port.out->name, in acm_bind()
701 acm->notify->name); in acm_bind()
705 if (acm->notify_req) in acm_bind()
706 gs_free_req(acm->notify, acm->notify_req); in acm_bind()
715 struct f_acm *acm = func_to_acm(f); in acm_unbind() local
719 if (acm->notify_req) in acm_unbind()
720 gs_free_req(acm->notify, acm->notify_req); in acm_unbind()
725 struct f_acm *acm = func_to_acm(f); in acm_free_func() local
730 kfree(acm); in acm_free_func()
738 struct f_acm *acm = func_to_acm(f); in acm_resume() local
740 gserial_resume(&acm->port); in acm_resume()
745 struct f_acm *acm = func_to_acm(f); in acm_suspend() local
747 gserial_suspend(&acm->port); in acm_suspend()
753 struct f_acm *acm; in acm_alloc_func() local
755 acm = kzalloc(sizeof(*acm), GFP_KERNEL); in acm_alloc_func()
756 if (!acm) in acm_alloc_func()
759 spin_lock_init(&acm->lock); in acm_alloc_func()
761 acm->port.connect = acm_connect; in acm_alloc_func()
762 acm->port.disconnect = acm_disconnect; in acm_alloc_func()
763 acm->port.send_break = acm_send_break; in acm_alloc_func()
765 acm->port.func.name = "acm"; in acm_alloc_func()
766 acm->port.func.strings = acm_strings; in acm_alloc_func()
768 acm->port.func.bind = acm_bind; in acm_alloc_func()
769 acm->port.func.set_alt = acm_set_alt; in acm_alloc_func()
770 acm->port.func.setup = acm_setup; in acm_alloc_func()
771 acm->port.func.disable = acm_disable; in acm_alloc_func()
775 acm->port_num = opts->port_num; in acm_alloc_func()
776 acm->bInterfaceProtocol = opts->protocol; in acm_alloc_func()
779 acm->port.func.unbind = acm_unbind; in acm_alloc_func()
780 acm->port.func.free_func = acm_free_func; in acm_alloc_func()
781 acm->port.func.resume = acm_resume; in acm_alloc_func()
782 acm->port.func.suspend = acm_suspend; in acm_alloc_func()
784 return &acm->port.func; in acm_alloc_func()
904 DECLARE_USB_FUNCTION_INIT(acm, acm_alloc_instance, acm_alloc_func);
905 MODULE_DESCRIPTION("USB CDC serial (ACM) function driver");