f_acm.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. /*
  2. * f_acm.c -- USB CDC serial (ACM) function driver
  3. *
  4. * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
  5. * Copyright (C) 2008 by David Brownell
  6. * Copyright (C) 2008 by Nokia Corporation
  7. *
  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.
  11. */
  12. /* #define VERBOSE_DEBUG */
  13. #include <linux/kernel.h>
  14. #include <linux/device.h>
  15. #include "u_serial.h"
  16. #include "gadget_chips.h"
  17. /*
  18. * This CDC ACM function support just wraps control functions and
  19. * notifications around the generic serial-over-usb code.
  20. *
  21. * Because CDC ACM is standardized by the USB-IF, many host operating
  22. * systems have drivers for it. Accordingly, ACM is the preferred
  23. * interop solution for serial-port type connections. The control
  24. * models are often not necessary, and in any case don't do much in
  25. * this bare-bones implementation.
  26. *
  27. * Note that even MS-Windows has some support for ACM. However, that
  28. * support is somewhat broken because when you use ACM in a composite
  29. * device, having multiple interfaces confuses the poor OS. It doesn't
  30. * seem to understand CDC Union descriptors. The new "association"
  31. * descriptors (roughly equivalent to CDC Unions) may sometimes help.
  32. */
  33. struct acm_ep_descs {
  34. struct usb_endpoint_descriptor *in;
  35. struct usb_endpoint_descriptor *out;
  36. struct usb_endpoint_descriptor *notify;
  37. };
  38. struct f_acm {
  39. struct gserial port;
  40. u8 ctrl_id, data_id;
  41. u8 port_num;
  42. struct usb_descriptor_header **fs_function;
  43. struct acm_ep_descs fs;
  44. struct usb_descriptor_header **hs_function;
  45. struct acm_ep_descs hs;
  46. struct usb_ep *notify;
  47. struct usb_endpoint_descriptor *notify_desc;
  48. struct usb_cdc_line_coding port_line_coding; /* 8-N-1 etc */
  49. u16 port_handshake_bits;
  50. #define RS232_RTS (1 << 1) /* unused with full duplex */
  51. #define RS232_DTR (1 << 0) /* host is ready for data r/w */
  52. };
  53. static inline struct f_acm *func_to_acm(struct usb_function *f)
  54. {
  55. return container_of(f, struct f_acm, port.func);
  56. }
  57. /*-------------------------------------------------------------------------*/
  58. /* notification endpoint uses smallish and infrequent fixed-size messages */
  59. #define GS_LOG2_NOTIFY_INTERVAL 5 /* 1 << 5 == 32 msec */
  60. #define GS_NOTIFY_MAXPACKET 8
  61. /* interface and class descriptors: */
  62. static struct usb_interface_descriptor acm_control_interface_desc __initdata = {
  63. .bLength = USB_DT_INTERFACE_SIZE,
  64. .bDescriptorType = USB_DT_INTERFACE,
  65. /* .bInterfaceNumber = DYNAMIC */
  66. .bNumEndpoints = 1,
  67. .bInterfaceClass = USB_CLASS_COMM,
  68. .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
  69. .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
  70. /* .iInterface = DYNAMIC */
  71. };
  72. static struct usb_interface_descriptor acm_data_interface_desc __initdata = {
  73. .bLength = USB_DT_INTERFACE_SIZE,
  74. .bDescriptorType = USB_DT_INTERFACE,
  75. /* .bInterfaceNumber = DYNAMIC */
  76. .bNumEndpoints = 2,
  77. .bInterfaceClass = USB_CLASS_CDC_DATA,
  78. .bInterfaceSubClass = 0,
  79. .bInterfaceProtocol = 0,
  80. /* .iInterface = DYNAMIC */
  81. };
  82. static struct usb_cdc_header_desc acm_header_desc __initdata = {
  83. .bLength = sizeof(acm_header_desc),
  84. .bDescriptorType = USB_DT_CS_INTERFACE,
  85. .bDescriptorSubType = USB_CDC_HEADER_TYPE,
  86. .bcdCDC = __constant_cpu_to_le16(0x0110),
  87. };
  88. static struct usb_cdc_call_mgmt_descriptor
  89. acm_call_mgmt_descriptor __initdata = {
  90. .bLength = sizeof(acm_call_mgmt_descriptor),
  91. .bDescriptorType = USB_DT_CS_INTERFACE,
  92. .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
  93. .bmCapabilities = 0,
  94. /* .bDataInterface = DYNAMIC */
  95. };
  96. static struct usb_cdc_acm_descriptor acm_descriptor __initdata = {
  97. .bLength = sizeof(acm_descriptor),
  98. .bDescriptorType = USB_DT_CS_INTERFACE,
  99. .bDescriptorSubType = USB_CDC_ACM_TYPE,
  100. .bmCapabilities = (1 << 1),
  101. };
  102. static struct usb_cdc_union_desc acm_union_desc __initdata = {
  103. .bLength = sizeof(acm_union_desc),
  104. .bDescriptorType = USB_DT_CS_INTERFACE,
  105. .bDescriptorSubType = USB_CDC_UNION_TYPE,
  106. /* .bMasterInterface0 = DYNAMIC */
  107. /* .bSlaveInterface0 = DYNAMIC */
  108. };
  109. /* full speed support: */
  110. static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
  111. .bLength = USB_DT_ENDPOINT_SIZE,
  112. .bDescriptorType = USB_DT_ENDPOINT,
  113. .bEndpointAddress = USB_DIR_IN,
  114. .bmAttributes = USB_ENDPOINT_XFER_INT,
  115. .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
  116. .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
  117. };
  118. static struct usb_endpoint_descriptor acm_fs_in_desc __initdata = {
  119. .bLength = USB_DT_ENDPOINT_SIZE,
  120. .bDescriptorType = USB_DT_ENDPOINT,
  121. .bEndpointAddress = USB_DIR_IN,
  122. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  123. };
  124. static struct usb_endpoint_descriptor acm_fs_out_desc __initdata = {
  125. .bLength = USB_DT_ENDPOINT_SIZE,
  126. .bDescriptorType = USB_DT_ENDPOINT,
  127. .bEndpointAddress = USB_DIR_OUT,
  128. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  129. };
  130. static struct usb_descriptor_header *acm_fs_function[] __initdata = {
  131. (struct usb_descriptor_header *) &acm_control_interface_desc,
  132. (struct usb_descriptor_header *) &acm_header_desc,
  133. (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
  134. (struct usb_descriptor_header *) &acm_descriptor,
  135. (struct usb_descriptor_header *) &acm_union_desc,
  136. (struct usb_descriptor_header *) &acm_fs_notify_desc,
  137. (struct usb_descriptor_header *) &acm_data_interface_desc,
  138. (struct usb_descriptor_header *) &acm_fs_in_desc,
  139. (struct usb_descriptor_header *) &acm_fs_out_desc,
  140. NULL,
  141. };
  142. /* high speed support: */
  143. static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
  144. .bLength = USB_DT_ENDPOINT_SIZE,
  145. .bDescriptorType = USB_DT_ENDPOINT,
  146. .bEndpointAddress = USB_DIR_IN,
  147. .bmAttributes = USB_ENDPOINT_XFER_INT,
  148. .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET),
  149. .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
  150. };
  151. static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = {
  152. .bLength = USB_DT_ENDPOINT_SIZE,
  153. .bDescriptorType = USB_DT_ENDPOINT,
  154. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  155. .wMaxPacketSize = __constant_cpu_to_le16(512),
  156. };
  157. static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
  158. .bLength = USB_DT_ENDPOINT_SIZE,
  159. .bDescriptorType = USB_DT_ENDPOINT,
  160. .bmAttributes = USB_ENDPOINT_XFER_BULK,
  161. .wMaxPacketSize = __constant_cpu_to_le16(512),
  162. };
  163. static struct usb_descriptor_header *acm_hs_function[] __initdata = {
  164. (struct usb_descriptor_header *) &acm_control_interface_desc,
  165. (struct usb_descriptor_header *) &acm_header_desc,
  166. (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
  167. (struct usb_descriptor_header *) &acm_descriptor,
  168. (struct usb_descriptor_header *) &acm_union_desc,
  169. (struct usb_descriptor_header *) &acm_hs_notify_desc,
  170. (struct usb_descriptor_header *) &acm_data_interface_desc,
  171. (struct usb_descriptor_header *) &acm_hs_in_desc,
  172. (struct usb_descriptor_header *) &acm_hs_out_desc,
  173. NULL,
  174. };
  175. /* string descriptors: */
  176. #define ACM_CTRL_IDX 0
  177. #define ACM_DATA_IDX 1
  178. /* static strings, in UTF-8 */
  179. static struct usb_string acm_string_defs[] = {
  180. [ACM_CTRL_IDX].s = "CDC Abstract Control Model (ACM)",
  181. [ACM_DATA_IDX].s = "CDC ACM Data",
  182. { /* ZEROES END LIST */ },
  183. };
  184. static struct usb_gadget_strings acm_string_table = {
  185. .language = 0x0409, /* en-us */
  186. .strings = acm_string_defs,
  187. };
  188. static struct usb_gadget_strings *acm_strings[] = {
  189. &acm_string_table,
  190. NULL,
  191. };
  192. /*-------------------------------------------------------------------------*/
  193. /* ACM control ... data handling is delegated to tty library code.
  194. * The main task of this function is to activate and deactivate
  195. * that code based on device state; track parameters like line
  196. * speed, handshake state, and so on; and issue notifications.
  197. */
  198. static void acm_complete_set_line_coding(struct usb_ep *ep,
  199. struct usb_request *req)
  200. {
  201. struct f_acm *acm = ep->driver_data;
  202. struct usb_composite_dev *cdev = acm->port.func.config->cdev;
  203. if (req->status != 0) {
  204. DBG(cdev, "acm ttyGS%d completion, err %d\n",
  205. acm->port_num, req->status);
  206. return;
  207. }
  208. /* normal completion */
  209. if (req->actual != sizeof(acm->port_line_coding)) {
  210. DBG(cdev, "acm ttyGS%d short resp, len %d\n",
  211. acm->port_num, req->actual);
  212. usb_ep_set_halt(ep);
  213. } else {
  214. struct usb_cdc_line_coding *value = req->buf;
  215. /* REVISIT: we currently just remember this data.
  216. * If we change that, (a) validate it first, then
  217. * (b) update whatever hardware needs updating,
  218. * (c) worry about locking. This is information on
  219. * the order of 9600-8-N-1 ... most of which means
  220. * nothing unless we control a real RS232 line.
  221. */
  222. acm->port_line_coding = *value;
  223. }
  224. }
  225. static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
  226. {
  227. struct f_acm *acm = func_to_acm(f);
  228. struct usb_composite_dev *cdev = f->config->cdev;
  229. struct usb_request *req = cdev->req;
  230. int value = -EOPNOTSUPP;
  231. u16 w_index = le16_to_cpu(ctrl->wIndex);
  232. u16 w_value = le16_to_cpu(ctrl->wValue);
  233. u16 w_length = le16_to_cpu(ctrl->wLength);
  234. /* composite driver infrastructure handles everything except
  235. * CDC class messages; interface activation uses set_alt().
  236. */
  237. switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
  238. /* SET_LINE_CODING ... just read and save what the host sends */
  239. case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
  240. | USB_CDC_REQ_SET_LINE_CODING:
  241. if (w_length != sizeof(struct usb_cdc_line_coding)
  242. || w_index != acm->ctrl_id)
  243. goto invalid;
  244. value = w_length;
  245. cdev->gadget->ep0->driver_data = acm;
  246. req->complete = acm_complete_set_line_coding;
  247. break;
  248. /* GET_LINE_CODING ... return what host sent, or initial value */
  249. case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
  250. | USB_CDC_REQ_GET_LINE_CODING:
  251. if (w_index != acm->ctrl_id)
  252. goto invalid;
  253. value = min_t(unsigned, w_length,
  254. sizeof(struct usb_cdc_line_coding));
  255. memcpy(req->buf, &acm->port_line_coding, value);
  256. break;
  257. /* SET_CONTROL_LINE_STATE ... save what the host sent */
  258. case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
  259. | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
  260. if (w_index != acm->ctrl_id)
  261. goto invalid;
  262. value = 0;
  263. /* FIXME we should not allow data to flow until the
  264. * host sets the RS232_DTR bit; and when it clears
  265. * that bit, we should return to that no-flow state.
  266. */
  267. acm->port_handshake_bits = w_value;
  268. break;
  269. default:
  270. invalid:
  271. VDBG(cdev, "invalid control req%02x.%02x v%04x i%04x l%d\n",
  272. ctrl->bRequestType, ctrl->bRequest,
  273. w_value, w_index, w_length);
  274. }
  275. /* respond with data transfer or status phase? */
  276. if (value >= 0) {
  277. DBG(cdev, "acm ttyGS%d req%02x.%02x v%04x i%04x l%d\n",
  278. acm->port_num, ctrl->bRequestType, ctrl->bRequest,
  279. w_value, w_index, w_length);
  280. req->zero = 0;
  281. req->length = value;
  282. value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
  283. if (value < 0)
  284. ERROR(cdev, "acm response on ttyGS%d, err %d\n",
  285. acm->port_num, value);
  286. }
  287. /* device either stalls (value < 0) or reports success */
  288. return value;
  289. }
  290. static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
  291. {
  292. struct f_acm *acm = func_to_acm(f);
  293. struct usb_composite_dev *cdev = f->config->cdev;
  294. /* we know alt == 0, so this is an activation or a reset */
  295. if (intf == acm->ctrl_id) {
  296. /* REVISIT this may need more work when we start to
  297. * send notifications ...
  298. */
  299. if (acm->notify->driver_data) {
  300. VDBG(cdev, "reset acm control interface %d\n", intf);
  301. usb_ep_disable(acm->notify);
  302. } else {
  303. VDBG(cdev, "init acm ctrl interface %d\n", intf);
  304. acm->notify_desc = ep_choose(cdev->gadget,
  305. acm->hs.notify,
  306. acm->fs.notify);
  307. }
  308. usb_ep_enable(acm->notify, acm->notify_desc);
  309. acm->notify->driver_data = acm;
  310. } else if (intf == acm->data_id) {
  311. if (acm->port.in->driver_data) {
  312. DBG(cdev, "reset acm ttyGS%d\n", acm->port_num);
  313. gserial_disconnect(&acm->port);
  314. } else {
  315. DBG(cdev, "activate acm ttyGS%d\n", acm->port_num);
  316. acm->port.in_desc = ep_choose(cdev->gadget,
  317. acm->hs.in, acm->fs.in);
  318. acm->port.out_desc = ep_choose(cdev->gadget,
  319. acm->hs.out, acm->fs.out);
  320. }
  321. gserial_connect(&acm->port, acm->port_num);
  322. } else
  323. return -EINVAL;
  324. return 0;
  325. }
  326. static void acm_disable(struct usb_function *f)
  327. {
  328. struct f_acm *acm = func_to_acm(f);
  329. struct usb_composite_dev *cdev = f->config->cdev;
  330. DBG(cdev, "acm ttyGS%d deactivated\n", acm->port_num);
  331. gserial_disconnect(&acm->port);
  332. usb_ep_disable(acm->notify);
  333. acm->notify->driver_data = NULL;
  334. }
  335. /*-------------------------------------------------------------------------*/
  336. /* ACM function driver setup/binding */
  337. static int __init
  338. acm_bind(struct usb_configuration *c, struct usb_function *f)
  339. {
  340. struct usb_composite_dev *cdev = c->cdev;
  341. struct f_acm *acm = func_to_acm(f);
  342. int status;
  343. struct usb_ep *ep;
  344. /* allocate instance-specific interface IDs, and patch descriptors */
  345. status = usb_interface_id(c, f);
  346. if (status < 0)
  347. goto fail;
  348. acm->ctrl_id = status;
  349. acm_control_interface_desc.bInterfaceNumber = status;
  350. acm_union_desc .bMasterInterface0 = status;
  351. status = usb_interface_id(c, f);
  352. if (status < 0)
  353. goto fail;
  354. acm->data_id = status;
  355. acm_data_interface_desc.bInterfaceNumber = status;
  356. acm_union_desc.bSlaveInterface0 = status;
  357. acm_call_mgmt_descriptor.bDataInterface = status;
  358. status = -ENODEV;
  359. /* allocate instance-specific endpoints */
  360. ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc);
  361. if (!ep)
  362. goto fail;
  363. acm->port.in = ep;
  364. ep->driver_data = cdev; /* claim */
  365. ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc);
  366. if (!ep)
  367. goto fail;
  368. acm->port.out = ep;
  369. ep->driver_data = cdev; /* claim */
  370. ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc);
  371. if (!ep)
  372. goto fail;
  373. acm->notify = ep;
  374. ep->driver_data = cdev; /* claim */
  375. /* copy descriptors, and track endpoint copies */
  376. f->descriptors = usb_copy_descriptors(acm_fs_function);
  377. acm->fs.in = usb_find_endpoint(acm_fs_function,
  378. f->descriptors, &acm_fs_in_desc);
  379. acm->fs.out = usb_find_endpoint(acm_fs_function,
  380. f->descriptors, &acm_fs_out_desc);
  381. acm->fs.notify = usb_find_endpoint(acm_fs_function,
  382. f->descriptors, &acm_fs_notify_desc);
  383. /* support all relevant hardware speeds... we expect that when
  384. * hardware is dual speed, all bulk-capable endpoints work at
  385. * both speeds
  386. */
  387. if (gadget_is_dualspeed(c->cdev->gadget)) {
  388. acm_hs_in_desc.bEndpointAddress =
  389. acm_fs_in_desc.bEndpointAddress;
  390. acm_hs_out_desc.bEndpointAddress =
  391. acm_fs_out_desc.bEndpointAddress;
  392. acm_hs_notify_desc.bEndpointAddress =
  393. acm_fs_notify_desc.bEndpointAddress;
  394. /* copy descriptors, and track endpoint copies */
  395. f->hs_descriptors = usb_copy_descriptors(acm_hs_function);
  396. acm->hs.in = usb_find_endpoint(acm_hs_function,
  397. f->hs_descriptors, &acm_hs_in_desc);
  398. acm->hs.out = usb_find_endpoint(acm_hs_function,
  399. f->hs_descriptors, &acm_hs_out_desc);
  400. acm->hs.notify = usb_find_endpoint(acm_hs_function,
  401. f->hs_descriptors, &acm_hs_notify_desc);
  402. }
  403. /* FIXME provide a callback for triggering notifications */
  404. DBG(cdev, "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
  405. acm->port_num,
  406. gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
  407. acm->port.in->name, acm->port.out->name,
  408. acm->notify->name);
  409. return 0;
  410. fail:
  411. /* we might as well release our claims on endpoints */
  412. if (acm->notify)
  413. acm->notify->driver_data = NULL;
  414. if (acm->port.out)
  415. acm->port.out->driver_data = NULL;
  416. if (acm->port.in)
  417. acm->port.in->driver_data = NULL;
  418. ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
  419. return status;
  420. }
  421. static void
  422. acm_unbind(struct usb_configuration *c, struct usb_function *f)
  423. {
  424. if (gadget_is_dualspeed(c->cdev->gadget))
  425. usb_free_descriptors(f->hs_descriptors);
  426. usb_free_descriptors(f->descriptors);
  427. kfree(func_to_acm(f));
  428. }
  429. /* Some controllers can't support CDC ACM ... */
  430. static inline bool can_support_cdc(struct usb_configuration *c)
  431. {
  432. /* SH3 doesn't support multiple interfaces */
  433. if (gadget_is_sh(c->cdev->gadget))
  434. return false;
  435. /* sa1100 doesn't have a third interrupt endpoint */
  436. if (gadget_is_sa1100(c->cdev->gadget))
  437. return false;
  438. /* everything else is *probably* fine ... */
  439. return true;
  440. }
  441. /**
  442. * acm_bind_config - add a CDC ACM function to a configuration
  443. * @c: the configuration to support the CDC ACM instance
  444. * @port_num: /dev/ttyGS* port this interface will use
  445. * Context: single threaded during gadget setup
  446. *
  447. * Returns zero on success, else negative errno.
  448. *
  449. * Caller must have called @gserial_setup() with enough ports to
  450. * handle all the ones it binds. Caller is also responsible
  451. * for calling @gserial_cleanup() before module unload.
  452. */
  453. int __init acm_bind_config(struct usb_configuration *c, u8 port_num)
  454. {
  455. struct f_acm *acm;
  456. int status;
  457. if (!can_support_cdc(c))
  458. return -EINVAL;
  459. /* REVISIT might want instance-specific strings to help
  460. * distinguish instances ...
  461. */
  462. /* maybe allocate device-global string IDs, and patch descriptors */
  463. if (acm_string_defs[ACM_CTRL_IDX].id == 0) {
  464. status = usb_string_id(c->cdev);
  465. if (status < 0)
  466. return status;
  467. acm_string_defs[ACM_CTRL_IDX].id = status;
  468. acm_control_interface_desc.iInterface = status;
  469. status = usb_string_id(c->cdev);
  470. if (status < 0)
  471. return status;
  472. acm_string_defs[ACM_DATA_IDX].id = status;
  473. acm_data_interface_desc.iInterface = status;
  474. }
  475. /* allocate and initialize one new instance */
  476. acm = kzalloc(sizeof *acm, GFP_KERNEL);
  477. if (!acm)
  478. return -ENOMEM;
  479. acm->port_num = port_num;
  480. acm->port.func.name = "acm";
  481. acm->port.func.strings = acm_strings;
  482. /* descriptors are per-instance copies */
  483. acm->port.func.bind = acm_bind;
  484. acm->port.func.unbind = acm_unbind;
  485. acm->port.func.set_alt = acm_set_alt;
  486. acm->port.func.setup = acm_setup;
  487. acm->port.func.disable = acm_disable;
  488. status = usb_add_function(c, &acm->port.func);
  489. if (status)
  490. kfree(acm);
  491. return status;
  492. }