17 #include <linux/slab.h>
18 #include <linux/kernel.h>
19 #include <linux/device.h>
62 #define ACM_CTRL_RTS (1 << 1)
63 #define ACM_CTRL_DTR (1 << 0)
67 #define ACM_CTRL_OVERRUN (1 << 6)
68 #define ACM_CTRL_PARITY (1 << 5)
69 #define ACM_CTRL_FRAMING (1 << 4)
70 #define ACM_CTRL_RI (1 << 3)
71 #define ACM_CTRL_BRK (1 << 2)
72 #define ACM_CTRL_DSR (1 << 1)
73 #define ACM_CTRL_DCD (1 << 0)
90 #define GS_LOG2_NOTIFY_INTERVAL 5
91 #define GS_NOTIFY_MAXPACKET 10
96 acm_iad_descriptor = {
97 .bLength =
sizeof acm_iad_descriptor,
101 .bInterfaceCount = 2,
126 .bInterfaceSubClass = 0,
127 .bInterfaceProtocol = 0,
132 .bLength =
sizeof(acm_header_desc),
139 acm_call_mgmt_descriptor = {
140 .bLength =
sizeof(acm_call_mgmt_descriptor),
148 .bLength =
sizeof(acm_descriptor),
155 .bLength =
sizeof(acm_union_desc),
255 .bLength =
sizeof acm_ss_bulk_comp_desc,
278 #define ACM_CTRL_IDX 0
279 #define ACM_DATA_IDX 1
280 #define ACM_IAD_IDX 2
283 static struct usb_string acm_string_defs[] = {
292 .strings = acm_string_defs,
308 static void acm_complete_set_line_coding(
struct usb_ep *ep,
315 DBG(cdev,
"acm ttyGS%d completion, err %d\n",
322 DBG(cdev,
"acm ttyGS%d short resp, len %d\n",
341 struct f_acm *acm = func_to_acm(f);
367 cdev->
gadget->ep0->driver_data = acm;
368 req->
complete = acm_complete_set_line_coding;
377 value =
min_t(
unsigned, w_length,
399 VDBG(cdev,
"invalid control req%02x.%02x v%04x i%04x l%d\n",
401 w_value, w_index, w_length);
406 DBG(cdev,
"acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
408 w_value, w_index, w_length);
413 ERROR(cdev,
"acm response on ttyGS%d, err %d\n",
423 struct f_acm *acm = func_to_acm(f);
429 if (acm->
notify->driver_data) {
430 VDBG(cdev,
"reset acm control interface %d\n", intf);
431 usb_ep_disable(acm->
notify);
433 VDBG(cdev,
"init acm ctrl interface %d\n", intf);
437 usb_ep_enable(acm->
notify);
438 acm->
notify->driver_data = acm;
440 }
else if (intf == acm->
data_id) {
441 if (acm->
port.in->driver_data) {
445 if (!acm->
port.in->desc || !acm->
port.out->desc) {
446 DBG(cdev,
"activate acm ttyGS%d\n", acm->
port_num);
466 struct f_acm *acm = func_to_acm(f);
469 DBG(cdev,
"acm ttyGS%d deactivated\n", acm->
port_num);
471 usb_ep_disable(acm->
notify);
497 const unsigned len =
sizeof(*notify) +
length;
515 memcpy(buf, data, length);
518 spin_unlock(&acm->
lock);
520 spin_lock(&acm->
lock);
524 "acm ttyGS%d can't notify serial state, %d\n",
532 static int acm_notify_serial_state(
struct f_acm *acm)
537 spin_lock(&acm->
lock);
539 DBG(cdev,
"acm ttyGS%d serial state %04x\n",
547 spin_unlock(&acm->
lock);
559 spin_lock(&acm->
lock);
563 spin_unlock(&acm->
lock);
566 acm_notify_serial_state(acm);
573 struct f_acm *acm = port_to_acm(port);
576 acm_notify_serial_state(acm);
581 struct f_acm *acm = port_to_acm(port);
584 acm_notify_serial_state(acm);
589 struct f_acm *acm = port_to_acm(port);
598 return acm_notify_serial_state(acm);
608 struct f_acm *acm = func_to_acm(f);
659 acm->
notify_req->complete = acm_cdc_notify_complete;
671 if (gadget_is_dualspeed(c->
cdev->gadget)) {
682 if (gadget_is_superspeed(c->
cdev->gadget)) {
694 DBG(cdev,
"acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
696 gadget_is_superspeed(c->
cdev->gadget) ?
"super" :
697 gadget_is_dualspeed(c->
cdev->gadget) ?
"dual" :
"full",
698 acm->
port.in->name, acm->
port.out->name,
714 ERROR(cdev,
"%s/%p: can't bind, err %d\n", f->
name, f, status);
722 struct f_acm *acm = func_to_acm(f);
724 if (gadget_is_dualspeed(c->
cdev->gadget))
726 if (gadget_is_superspeed(c->
cdev->gadget))
757 if (!can_support_cdc(c))
797 acm->
port.connect = acm_connect;
798 acm->
port.disconnect = acm_disconnect;
801 acm->
port.func.name =
"acm";
802 acm->
port.func.strings = acm_strings;
804 acm->
port.func.bind = acm_bind;
805 acm->
port.func.unbind = acm_unbind;
806 acm->
port.func.set_alt = acm_set_alt;
807 acm->
port.func.setup = acm_setup;
808 acm->
port.func.disable = acm_disable;