2 * f_acm.c -- USB CDC serial (ACM) function driver
4 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
5 * Copyright (C) 2008 by David Brownell
6 * Copyright (C) 2008 by Nokia Corporation
8 * This software is distributed under the terms of the GNU General
9 * Public License ("GPL") as published by the Free Software Foundation,
10 * either version 2 of that License or (at your option) any later version.
13 /* #define VERBOSE_DEBUG */
15 #include <linux/kernel.h>
16 #include <linux/device.h>
19 #include "gadget_chips.h"
23 * This CDC ACM function support just wraps control functions and
24 * notifications around the generic serial-over-usb code.
26 * Because CDC ACM is standardized by the USB-IF, many host operating
27 * systems have drivers for it. Accordingly, ACM is the preferred
28 * interop solution for serial-port type connections. The control
29 * models are often not necessary, and in any case don't do much in
30 * this bare-bones implementation.
32 * Note that even MS-Windows has some support for ACM. However, that
33 * support is somewhat broken because when you use ACM in a composite
34 * device, having multiple interfaces confuses the poor OS. It doesn't
35 * seem to understand CDC Union descriptors. The new "association"
36 * descriptors (roughly equivalent to CDC Unions) may sometimes help.
40 struct usb_endpoint_descriptor *in;
41 struct usb_endpoint_descriptor *out;
42 struct usb_endpoint_descriptor *notify;
52 /* lock is mostly for pending and notify_req ... they get accessed
53 * by callbacks both from tty (open/close/break) under its spinlock,
54 * and notify_req.complete() which can't use that lock.
58 struct acm_ep_descs fs;
59 struct acm_ep_descs hs;
61 struct usb_ep *notify;
62 struct usb_endpoint_descriptor *notify_desc;
63 struct usb_request *notify_req;
65 struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
67 /* SetControlLineState request -- CDC 1.1 section 6.2.14 (INPUT) */
68 u16 port_handshake_bits;
69 #define ACM_CTRL_RTS (1 << 1) /* unused with full duplex */
70 #define ACM_CTRL_DTR (1 << 0) /* host is ready for data r/w */
72 /* SerialState notification -- CDC 1.1 section 6.3.5 (OUTPUT) */
74 #define ACM_CTRL_OVERRUN (1 << 6)
75 #define ACM_CTRL_PARITY (1 << 5)
76 #define ACM_CTRL_FRAMING (1 << 4)
77 #define ACM_CTRL_RI (1 << 3)
78 #define ACM_CTRL_BRK (1 << 2)
79 #define ACM_CTRL_DSR (1 << 1)
80 #define ACM_CTRL_DCD (1 << 0)
83 static inline struct f_acm *func_to_acm(struct usb_function *f)
85 return container_of(f, struct f_acm, port.func);
88 static inline struct f_acm *port_to_acm(struct gserial *p)
90 return container_of(p, struct f_acm, port);
93 /*-------------------------------------------------------------------------*/
95 /* notification endpoint uses smallish and infrequent fixed-size messages */
97 #define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */
98 #define GS_NOTIFY_MAXPACKET 10 /* notification + 2 bytes */
100 /* interface and class descriptors: */
102 static struct usb_interface_descriptor acm_control_interface_desc __initdata = {
103 .bLength = USB_DT_INTERFACE_SIZE,
104 .bDescriptorType = USB_DT_INTERFACE,
105 /* .bInterfaceNumber = DYNAMIC */
107 .bInterfaceClass = USB_CLASS_COMM,
108 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
109 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
110 /* .iInterface = DYNAMIC */
113 static struct usb_interface_descriptor acm_data_interface_desc __initdata = {
114 .bLength = USB_DT_INTERFACE_SIZE,
115 .bDescriptorType = USB_DT_INTERFACE,
116 /* .bInterfaceNumber = DYNAMIC */
118 .bInterfaceClass = USB_CLASS_CDC_DATA,
119 .bInterfaceSubClass = 0,
120 .bInterfaceProtocol = 0,
121 /* .iInterface = DYNAMIC */
124 static struct usb_cdc_header_desc acm_header_desc __initdata = {
125 .bLength = sizeof(acm_header_desc),
126 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
128 .bcdCDC = __constant_cpu_to_le16(0x0110),
131 static struct usb_cdc_call_mgmt_descriptor
132 acm_call_mgmt_descriptor __initdata = {
133 .bLength = sizeof(acm_call_mgmt_descriptor),
134 .bDescriptorType = USB_DT_CS_INTERFACE,
135 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
137 /* .bDataInterface = DYNAMIC */
140 static struct usb_cdc_acm_descriptor acm_descriptor __initdata = {
141 .bLength = sizeof(acm_descriptor),
142 .bDescriptorType = USB_DT_CS_INTERFACE,
143 .bDescriptorSubType = USB_CDC_ACM_TYPE,
144 .bmCapabilities = USB_CDC_CAP_LINE,
147 static struct usb_cdc_union_desc acm_union_desc __initdata = {
148 .bLength = sizeof(acm_union_desc),
149 .bDescriptorType = USB_DT_CS_INTERFACE,
150 .bDescriptorSubType = USB_CDC_UNION_TYPE,
151 /* .bMasterInterface0 = DYNAMIC */
152 /* .bSlaveInterface0 = DYNAMIC */
155 /* full speed support: */
157 static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
158 .bLength = USB_DT_ENDPOINT_SIZE,
159 .bDescriptorType = USB_DT_ENDPOINT,
160 .bEndpointAddress = USB_DIR_IN,
161 .bmAttributes = USB_ENDPOINT_XFER_INT,
162 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
163 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
166 static struct usb_endpoint_descriptor acm_fs_in_desc __initdata = {
167 .bLength = USB_DT_ENDPOINT_SIZE,
168 .bDescriptorType = USB_DT_ENDPOINT,
169 .bEndpointAddress = USB_DIR_IN,
170 .bmAttributes = USB_ENDPOINT_XFER_BULK,
173 static struct usb_endpoint_descriptor acm_fs_out_desc __initdata = {
174 .bLength = USB_DT_ENDPOINT_SIZE,
175 .bDescriptorType = USB_DT_ENDPOINT,
176 .bEndpointAddress = USB_DIR_OUT,
177 .bmAttributes = USB_ENDPOINT_XFER_BULK,
180 static struct usb_descriptor_header *acm_fs_function[] __initdata = {
181 (struct usb_descriptor_header *) &acm_control_interface_desc,
182 (struct usb_descriptor_header *) &acm_header_desc,
183 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
184 (struct usb_descriptor_header *) &acm_descriptor,
185 (struct usb_descriptor_header *) &acm_union_desc,
186 (struct usb_descriptor_header *) &acm_fs_notify_desc,
187 (struct usb_descriptor_header *) &acm_data_interface_desc,
188 (struct usb_descriptor_header *) &acm_fs_in_desc,
189 (struct usb_descriptor_header *) &acm_fs_out_desc,
193 /* high speed support: */
195 static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
196 .bLength = USB_DT_ENDPOINT_SIZE,
197 .bDescriptorType = USB_DT_ENDPOINT,
198 .bEndpointAddress = USB_DIR_IN,
199 .bmAttributes = USB_ENDPOINT_XFER_INT,
200 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
201 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
204 static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = {
205 .bLength = USB_DT_ENDPOINT_SIZE,
206 .bDescriptorType = USB_DT_ENDPOINT,
207 .bmAttributes = USB_ENDPOINT_XFER_BULK,
208 .wMaxPacketSize = __constant_cpu_to_le16(512),
211 static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
212 .bLength = USB_DT_ENDPOINT_SIZE,
213 .bDescriptorType = USB_DT_ENDPOINT,
214 .bmAttributes = USB_ENDPOINT_XFER_BULK,
215 .wMaxPacketSize = __constant_cpu_to_le16(512),
218 static struct usb_descriptor_header *acm_hs_function[] __initdata = {
219 (struct usb_descriptor_header *) &acm_control_interface_desc,
220 (struct usb_descriptor_header *) &acm_header_desc,
221 (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
222 (struct usb_descriptor_header *) &acm_descriptor,
223 (struct usb_descriptor_header *) &acm_union_desc,
224 (struct usb_descriptor_header *) &acm_hs_notify_desc,
225 (struct usb_descriptor_header *) &acm_data_interface_desc,
226 (struct usb_descriptor_header *) &acm_hs_in_desc,
227 (struct usb_descriptor_header *) &acm_hs_out_desc,
231 /* string descriptors: */
233 #define ACM_CTRL_IDX 0
234 #define ACM_DATA_IDX 1
236 /* static strings, in UTF-8 */
237 static struct usb_string acm_string_defs[] = {
238 [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
239 [ACM_DATA_IDX].s = "CDC ACM Data",
240 { /* ZEROES END LIST */ },
243 static struct usb_gadget_strings acm_string_table = {
244 .language = 0x0409, /* en-us */
245 .strings = acm_string_defs,
248 static struct usb_gadget_strings *acm_strings[] = {
253 /*-------------------------------------------------------------------------*/
255 /* ACM control ... data handling is delegated to tty library code.
256 * The main task of this function is to activate and deactivate
257 * that code based on device state; track parameters like line
258 * speed, handshake state, and so on; and issue notifications.
261 static void acm_complete_set_line_coding(struct usb_ep *ep,
262 struct usb_request *req)
264 struct f_acm *acm = ep->driver_data;
265 struct usb_composite_dev *cdev = acm->port.func.config->cdev;
267 if (req->status != 0) {
268 DBG(cdev, "acm ttyGS%d completion, err %d\n",
269 acm->port_num, req->status);
273 /* normal completion */
274 if (req->actual != sizeof(acm->port_line_coding)) {
275 DBG(cdev, "acm ttyGS%d short resp, len %d\n",
276 acm->port_num, req->actual);
279 struct usb_cdc_line_coding *value = req->buf;
281 /* REVISIT: we currently just remember this data.
282 * If we change that, (a) validate it first, then
283 * (b) update whatever hardware needs updating,
284 * (c) worry about locking. This is information on
285 * the order of 9600-8-N-1 ... most of which means
286 * nothing unless we control a real RS232 line.
288 acm->port_line_coding = *value;
292 static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
294 struct f_acm *acm = func_to_acm(f);
295 struct usb_composite_dev *cdev = f->config->cdev;
296 struct usb_request *req = cdev->req;
297 int value = -EOPNOTSUPP;
298 u16 w_index = le16_to_cpu(ctrl->wIndex);
299 u16 w_value = le16_to_cpu(ctrl->wValue);
300 u16 w_length = le16_to_cpu(ctrl->wLength);
302 /* composite driver infrastructure handles everything except
303 * CDC class messages; interface activation uses set_alt().
305 * Note CDC spec table 4 lists the ACM request profile. It requires
306 * encapsulated command support ... we don't handle any, and respond
307 * to them by stalling. Options include get/set/clear comm features
308 * (not that useful) and SEND_BREAK.
310 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
312 /* SET_LINE_CODING ... just read and save what the host sends */
313 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
314 | USB_CDC_REQ_SET_LINE_CODING:
315 if (w_length != sizeof(struct usb_cdc_line_coding)
316 || w_index != acm->ctrl_id)
320 cdev->gadget->ep0->driver_data = acm;
321 req->complete = acm_complete_set_line_coding;
324 /* GET_LINE_CODING ... return what host sent, or initial value */
325 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
326 | USB_CDC_REQ_GET_LINE_CODING:
327 if (w_index != acm->ctrl_id)
330 value = min_t(unsigned, w_length,
331 sizeof(struct usb_cdc_line_coding));
332 memcpy(req->buf, &acm->port_line_coding, value);
335 /* SET_CONTROL_LINE_STATE ... save what the host sent */
336 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
337 | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
338 if (w_index != acm->ctrl_id)
343 /* REVISIT Hangup would be the right way, but since the hooks
344 * are not there we need to connect/disconnect.
346 if (w_value & ACM_CTRL_DTR)
347 gserial_connect(&acm->port, acm->port_num);
349 gserial_disconnect(&acm->port);
350 acm->port_handshake_bits = w_value;
355 VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
356 ctrl->bRequestType, ctrl->bRequest,
357 w_value, w_index, w_length);
360 /* respond with data transfer or status phase? */
362 DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
363 acm->port_num, ctrl->bRequestType, ctrl->bRequest,
364 w_value, w_index, w_length);
367 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
369 ERROR(cdev, "acm response on ttyGS%d, err %d\n",
370 acm->port_num, value);
373 /* device either stalls (value < 0) or reports success */
377 static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
379 struct f_acm *acm = func_to_acm(f);
380 struct usb_composite_dev *cdev = f->config->cdev;
382 /* we know alt == 0, so this is an activation or a reset */
384 if (intf == acm->ctrl_id) {
385 if (acm->notify->driver_data) {
386 VDBG(cdev, "reset acm control interface %d\n", intf);
387 usb_ep_disable(acm->notify);
389 VDBG(cdev, "init acm ctrl interface %d\n", intf);
390 acm->notify_desc = ep_choose(cdev->gadget,
394 usb_ep_enable(acm->notify, acm->notify_desc);
395 acm->notify->driver_data = acm;
397 } else if (intf == acm->data_id) {
398 if (acm->port.in->driver_data) {
399 DBG(cdev, "reset acm ttyGS%d\n", acm->port_num);
400 gserial_disconnect(&acm->port);
402 DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
403 acm->port.in_desc = ep_choose(cdev->gadget,
404 acm->hs.in, acm->fs.in);
405 acm->port.out_desc = ep_choose(cdev->gadget,
406 acm->hs.out, acm->fs.out);
408 gserial_connect(&acm->port, acm->port_num);
416 static void acm_disable(struct usb_function *f)
418 struct f_acm *acm = func_to_acm(f);
419 struct usb_composite_dev *cdev = f->config->cdev;
421 DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num);
422 gserial_disconnect(&acm->port);
423 usb_ep_disable(acm->notify);
424 acm->notify->driver_data = NULL;
427 /*-------------------------------------------------------------------------*/
430 * acm_cdc_notify - issue CDC notification to host
431 * @acm: wraps host to be notified
432 * @type: notification type
433 * @value: Refer to cdc specs, wValue field.
434 * @data: data to be sent
435 * @length: size of data
436 * Context: irqs blocked, acm->lock held, acm_notify_req non-null
438 * Returns zero on sucess or a negative errno.
440 * See section 6.3.5 of the CDC 1.1 specification for information
441 * about the only notification we issue: SerialState change.
443 static int acm_cdc_notify(struct f_acm *acm, u8 type, u16 value,
444 void *data, unsigned length)
446 struct usb_ep *ep = acm->notify;
447 struct usb_request *req;
448 struct usb_cdc_notification *notify;
449 const unsigned len = sizeof(*notify) + length;
453 req = acm->notify_req;
454 acm->notify_req = NULL;
455 acm->pending = false;
461 notify->bmRequestType = USB_DIR_IN | USB_TYPE_CLASS
462 | USB_RECIP_INTERFACE;
463 notify->bNotificationType = type;
464 notify->wValue = cpu_to_le16(value);
465 notify->wIndex = cpu_to_le16(acm->ctrl_id);
466 notify->wLength = cpu_to_le16(length);
467 memcpy(buf, data, length);
469 /* ep_queue() can complete immediately if it fills the fifo... */
470 spin_unlock(&acm->lock);
471 status = usb_ep_queue(ep, req, GFP_ATOMIC);
472 spin_lock(&acm->lock);
475 ERROR(acm->port.func.config->cdev,
476 "acm ttyGS%d can't notify serial state, %d\n",
477 acm->port_num, status);
478 acm->notify_req = req;
484 static int acm_notify_serial_state(struct f_acm *acm)
486 struct usb_composite_dev *cdev = acm->port.func.config->cdev;
489 spin_lock(&acm->lock);
490 if (acm->notify_req) {
491 DBG(cdev, "acm ttyGS%d serial state %04x\n",
492 acm->port_num, acm->serial_state);
493 status = acm_cdc_notify(acm, USB_CDC_NOTIFY_SERIAL_STATE,
494 0, &acm->serial_state, sizeof(acm->serial_state));
499 spin_unlock(&acm->lock);
503 static void acm_cdc_notify_complete(struct usb_ep *ep, struct usb_request *req)
505 struct f_acm *acm = req->context;
508 /* on this call path we do NOT hold the port spinlock,
509 * which is why ACM needs its own spinlock
511 spin_lock(&acm->lock);
512 if (req->status != -ESHUTDOWN)
514 acm->notify_req = req;
515 spin_unlock(&acm->lock);
518 acm_notify_serial_state(acm);
521 /* connect == the TTY link is open */
523 static void acm_connect(struct gserial *port)
525 struct f_acm *acm = port_to_acm(port);
527 acm->serial_state |= ACM_CTRL_DSR | ACM_CTRL_DCD;
528 acm_notify_serial_state(acm);
531 static void acm_disconnect(struct gserial *port)
533 struct f_acm *acm = port_to_acm(port);
535 acm->serial_state &= ~(ACM_CTRL_DSR | ACM_CTRL_DCD);
536 acm_notify_serial_state(acm);
539 static int acm_send_break(struct gserial *port, int duration)
541 struct f_acm *acm = port_to_acm(port);
544 state = acm->serial_state;
545 state &= ~ACM_CTRL_BRK;
547 state |= ACM_CTRL_BRK;
549 acm->serial_state = state;
550 return acm_notify_serial_state(acm);
553 /*-------------------------------------------------------------------------*/
555 /* ACM function driver setup/binding */
557 acm_bind(struct usb_configuration *c, struct usb_function *f)
559 struct usb_composite_dev *cdev = c->cdev;
560 struct f_acm *acm = func_to_acm(f);
564 /* allocate instance-specific interface IDs, and patch descriptors */
565 status = usb_interface_id(c, f);
568 acm->ctrl_id = status;
570 acm_control_interface_desc.bInterfaceNumber = status;
571 acm_union_desc .bMasterInterface0 = status;
573 status = usb_interface_id(c, f);
576 acm->data_id = status;
578 acm_data_interface_desc.bInterfaceNumber = status;
579 acm_union_desc.bSlaveInterface0 = status;
580 acm_call_mgmt_descriptor.bDataInterface = status;
584 /* allocate instance-specific endpoints */
585 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc);
589 ep->driver_data = cdev; /* claim */
591 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc);
595 ep->driver_data = cdev; /* claim */
597 ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc);
601 ep->driver_data = cdev; /* claim */
603 /* allocate notification */
604 acm->notify_req = gs_alloc_req(ep,
605 sizeof(struct usb_cdc_notification) + 2,
607 if (!acm->notify_req)
610 acm->notify_req->complete = acm_cdc_notify_complete;
611 acm->notify_req->context = acm;
613 /* copy descriptors, and track endpoint copies */
614 f->descriptors = usb_copy_descriptors(acm_fs_function);
618 acm->fs.in = usb_find_endpoint(acm_fs_function,
619 f->descriptors, &acm_fs_in_desc);
620 acm->fs.out = usb_find_endpoint(acm_fs_function,
621 f->descriptors, &acm_fs_out_desc);
622 acm->fs.notify = usb_find_endpoint(acm_fs_function,
623 f->descriptors, &acm_fs_notify_desc);
625 /* support all relevant hardware speeds... we expect that when
626 * hardware is dual speed, all bulk-capable endpoints work at
629 if (gadget_is_dualspeed(c->cdev->gadget)) {
630 acm_hs_in_desc.bEndpointAddress =
631 acm_fs_in_desc.bEndpointAddress;
632 acm_hs_out_desc.bEndpointAddress =
633 acm_fs_out_desc.bEndpointAddress;
634 acm_hs_notify_desc.bEndpointAddress =
635 acm_fs_notify_desc.bEndpointAddress;
637 /* copy descriptors, and track endpoint copies */
638 f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
640 acm->hs.in = usb_find_endpoint(acm_hs_function,
641 f->hs_descriptors, &acm_hs_in_desc);
642 acm->hs.out = usb_find_endpoint(acm_hs_function,
643 f->hs_descriptors, &acm_hs_out_desc);
644 acm->hs.notify = usb_find_endpoint(acm_hs_function,
645 f->hs_descriptors, &acm_hs_notify_desc);
648 DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
650 gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
651 acm->port.in->name, acm->port.out->name,
657 gs_free_req(acm->notify, acm->notify_req);
659 /* we might as well release our claims on endpoints */
661 acm->notify->driver_data = NULL;
663 acm->port.out->driver_data = NULL;
665 acm->port.in->driver_data = NULL;
667 ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
673 acm_unbind(struct usb_configuration *c, struct usb_function *f)
675 struct f_acm *acm = func_to_acm(f);
677 if (gadget_is_dualspeed(c->cdev->gadget))
678 usb_free_descriptors(f->hs_descriptors);
679 usb_free_descriptors(f->descriptors);
680 gs_free_req(acm->notify, acm->notify_req);
684 /* Some controllers can't support CDC ACM ... */
685 static inline bool can_support_cdc(struct usb_configuration *c)
687 /* SH3 doesn't support multiple interfaces */
688 if (gadget_is_sh(c->cdev->gadget))
691 /* sa1100 doesn't have a third interrupt endpoint */
692 if (gadget_is_sa1100(c->cdev->gadget))
695 /* everything else is *probably* fine ... */
700 * acm_bind_config - add a CDC ACM function to a configuration
701 * @c: the configuration to support the CDC ACM instance
702 * @port_num: /dev/ttyGS* port this interface will use
703 * Context: single threaded during gadget setup
705 * Returns zero on success, else negative errno.
707 * Caller must have called @gserial_setup() with enough ports to
708 * handle all the ones it binds. Caller is also responsible
709 * for calling @gserial_cleanup() before module unload.
711 int __init acm_bind_config(struct usb_configuration *c, u8 port_num)
716 if (!can_support_cdc(c))
719 /* REVISIT might want instance-specific strings to help
720 * distinguish instances ...
723 /* maybe allocate device-global string IDs, and patch descriptors */
724 if (acm_string_defs[ACM_CTRL_IDX].id == 0) {
725 status = usb_string_id(c->cdev);
728 acm_string_defs[ACM_CTRL_IDX].id = status;
730 acm_control_interface_desc.iInterface = status;
732 status = usb_string_id(c->cdev);
735 acm_string_defs[ACM_DATA_IDX].id = status;
737 acm_data_interface_desc.iInterface = status;
740 /* allocate and initialize one new instance */
741 acm = kzalloc(sizeof *acm, GFP_KERNEL);
745 spin_lock_init(&acm->lock);
747 acm->port_num = port_num;
749 acm->port.connect = acm_connect;
750 acm->port.disconnect = acm_disconnect;
751 acm->port.send_break = acm_send_break;
753 acm->port.func.name = "acm";
754 acm->port.func.strings = acm_strings;
755 /* descriptors are per-instance copies */
756 acm->port.func.bind = acm_bind;
757 acm->port.func.unbind = acm_unbind;
758 acm->port.func.set_alt = acm_set_alt;
759 acm->port.func.setup = acm_setup;
760 acm->port.func.disable = acm_disable;
762 status = usb_add_function(c, &acm->port.func);