blob: 2665fa4168f99b35a8c595aa24cb3fc4e8ab8529 [file] [log] [blame]
Loic Poulaineb78f832021-11-25 18:16:15 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * USB CDC serial (ACM) function driver
4 *
5 * Copyright (C) 2003 Al Borchers (alborchers@steinerpoint.com)
6 * Copyright (C) 2008 by David Brownell
7 * Copyright (C) 2008 by Nokia Corporation
8 * Copyright (C) 2009 by Samsung Electronics
9 * Copyright (c) 2021, Linaro Ltd <loic.poulain@linaro.org>
10 */
11
12#include <circbuf.h>
Loic Poulaineb78f832021-11-25 18:16:15 +010013#include <console.h>
14#include <errno.h>
15#include <g_dnl.h>
16#include <malloc.h>
17#include <memalign.h>
18#include <stdio_dev.h>
19#include <version.h>
20#include <watchdog.h>
21
22#include <linux/usb/ch9.h>
23#include <linux/usb/gadget.h>
24#include <linux/usb/composite.h>
25#include <linux/usb/cdc.h>
26
27#define REQ_SIZE_MAX 512
28
29struct f_acm {
30 int ctrl_id;
31 int data_id;
32
33 struct usb_ep *ep_in;
34 struct usb_ep *ep_out;
35 struct usb_ep *ep_notify;
36
37 struct usb_request *req_in;
38 struct usb_request *req_out;
39
40 bool connected;
41 bool tx_on;
42
43 circbuf_t rx_buf;
44 circbuf_t tx_buf;
45
46 struct usb_function usb_function;
47
48 struct usb_cdc_line_coding line_coding;
49 u16 handshake_bits;
50#define ACM_CTRL_RTS BIT(1) /* unused with full duplex */
51#define ACM_CTRL_DTR BIT(0) /* host is ready for data r/w */
52
Marek Vasutce1b62d2023-09-01 11:50:00 +020053 struct udevice *udc;
Loic Poulaineb78f832021-11-25 18:16:15 +010054};
55
56static struct f_acm *default_acm_function;
57
58static inline struct f_acm *func_to_acm(struct usb_function *f)
59{
60 return container_of(f, struct f_acm, usb_function);
61}
62
63static inline struct f_acm *stdio_to_acm(struct stdio_dev *s)
64{
65 /* stdio dev is cloned on registration, do not use container_of */
66 return s->priv;
67}
68
69static struct usb_interface_assoc_descriptor
70acm_iad_descriptor = {
71 .bLength = sizeof(acm_iad_descriptor),
72 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
73 .bFirstInterface = 0,
74 .bInterfaceCount = 2, // control + data
75 .bFunctionClass = USB_CLASS_COMM,
76 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
77 .bFunctionProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
78};
79
80static struct usb_interface_descriptor acm_control_intf_desc = {
81 .bLength = USB_DT_INTERFACE_SIZE,
82 .bDescriptorType = USB_DT_INTERFACE,
83 .bNumEndpoints = 1,
84 .bInterfaceClass = USB_CLASS_COMM,
85 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
86 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
87};
88
89static struct usb_interface_descriptor acm_data_intf_desc = {
90 .bLength = sizeof(acm_data_intf_desc),
91 .bDescriptorType = USB_DT_INTERFACE,
92 .bNumEndpoints = 2,
93 .bInterfaceClass = USB_CLASS_CDC_DATA,
94};
95
96static struct usb_cdc_header_desc acm_header_desc = {
97 .bLength = sizeof(acm_header_desc),
98 .bDescriptorType = USB_DT_CS_INTERFACE,
99 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
100 .bcdCDC = __constant_cpu_to_le16(0x0110),
101};
102
103static struct usb_cdc_call_mgmt_descriptor acm_call_mgmt_desc = {
104 .bLength = sizeof(acm_call_mgmt_desc),
105 .bDescriptorType = USB_DT_CS_INTERFACE,
106 .bDescriptorSubType = USB_CDC_CALL_MANAGEMENT_TYPE,
107 .bmCapabilities = 0,
108 .bDataInterface = 0x01,
109};
110
111static struct usb_cdc_acm_descriptor acm_desc = {
112 .bLength = sizeof(acm_desc),
113 .bDescriptorType = USB_DT_CS_INTERFACE,
114 .bDescriptorSubType = USB_CDC_ACM_TYPE,
115 .bmCapabilities = USB_CDC_CAP_LINE,
116};
117
118static struct usb_cdc_union_desc acm_union_desc = {
119 .bLength = sizeof(acm_union_desc),
120 .bDescriptorType = USB_DT_CS_INTERFACE,
121 .bDescriptorSubType = USB_CDC_UNION_TYPE,
122 .bMasterInterface0 = 0x00,
123 .bSlaveInterface0 = 0x01,
124};
125
126static struct usb_endpoint_descriptor acm_fs_notify_desc = {
127 .bLength = USB_DT_ENDPOINT_SIZE,
128 .bDescriptorType = USB_DT_ENDPOINT,
129 .bEndpointAddress = 3 | USB_DIR_IN,
130 .bmAttributes = USB_ENDPOINT_XFER_INT,
131 .wMaxPacketSize = __constant_cpu_to_le16(64),
132 .bInterval = 32,
133};
134
135static struct usb_endpoint_descriptor acm_fs_in_desc = {
136 .bLength = USB_DT_ENDPOINT_SIZE,
137 .bDescriptorType = USB_DT_ENDPOINT,
138 .bEndpointAddress = USB_DIR_IN,
139 .bmAttributes = USB_ENDPOINT_XFER_BULK,
140};
141
142static struct usb_endpoint_descriptor acm_fs_out_desc = {
143 .bLength = USB_DT_ENDPOINT_SIZE,
144 .bDescriptorType = USB_DT_ENDPOINT,
145 .bEndpointAddress = USB_DIR_OUT,
146 .bmAttributes = USB_ENDPOINT_XFER_BULK,
147};
148
149static struct usb_descriptor_header *acm_fs_function[] = {
150 (struct usb_descriptor_header *)&acm_iad_descriptor,
151 (struct usb_descriptor_header *)&acm_control_intf_desc,
152 (struct usb_descriptor_header *)&acm_header_desc,
153 (struct usb_descriptor_header *)&acm_call_mgmt_desc,
154 (struct usb_descriptor_header *)&acm_desc,
155 (struct usb_descriptor_header *)&acm_union_desc,
156 (struct usb_descriptor_header *)&acm_fs_notify_desc,
157 (struct usb_descriptor_header *)&acm_data_intf_desc,
158 (struct usb_descriptor_header *)&acm_fs_in_desc,
159 (struct usb_descriptor_header *)&acm_fs_out_desc,
160 NULL,
161};
162
163static struct usb_endpoint_descriptor acm_hs_notify_desc = {
164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT,
166 .bmAttributes = USB_ENDPOINT_XFER_INT,
167 .wMaxPacketSize = __constant_cpu_to_le16(64),
168 .bInterval = 11,
169};
170
171static struct usb_endpoint_descriptor acm_hs_in_desc = {
172 .bLength = USB_DT_ENDPOINT_SIZE,
173 .bDescriptorType = USB_DT_ENDPOINT,
174 .bmAttributes = USB_ENDPOINT_XFER_BULK,
175 .wMaxPacketSize = __constant_cpu_to_le16(512),
176};
177
178static struct usb_endpoint_descriptor acm_hs_out_desc = {
179 .bLength = USB_DT_ENDPOINT_SIZE,
180 .bDescriptorType = USB_DT_ENDPOINT,
181 .bmAttributes = USB_ENDPOINT_XFER_BULK,
182 .wMaxPacketSize = __constant_cpu_to_le16(512),
183};
184
185static struct usb_descriptor_header *acm_hs_function[] = {
186 (struct usb_descriptor_header *)&acm_iad_descriptor,
187 (struct usb_descriptor_header *)&acm_control_intf_desc,
188 (struct usb_descriptor_header *)&acm_header_desc,
189 (struct usb_descriptor_header *)&acm_call_mgmt_desc,
190 (struct usb_descriptor_header *)&acm_desc,
191 (struct usb_descriptor_header *)&acm_union_desc,
192 (struct usb_descriptor_header *)&acm_hs_notify_desc,
193 (struct usb_descriptor_header *)&acm_data_intf_desc,
194 (struct usb_descriptor_header *)&acm_hs_in_desc,
195 (struct usb_descriptor_header *)&acm_hs_out_desc,
196 NULL,
197};
198
199static inline struct usb_endpoint_descriptor *
200ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
201 struct usb_endpoint_descriptor *fs)
202{
203 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
204 return hs;
205 return fs;
206}
207
208static int acm_bind(struct usb_configuration *c, struct usb_function *f)
209{
210 struct usb_gadget *gadget = c->cdev->gadget;
211 struct f_acm *f_acm = func_to_acm(f);
212 struct usb_ep *ep;
213 int id;
214
215 id = usb_interface_id(c, f);
216 if (id < 0)
217 return id;
218
219 acm_iad_descriptor.bFirstInterface = id;
220 acm_control_intf_desc.bInterfaceNumber = id;
221 acm_union_desc.bMasterInterface0 = id;
222
223 f_acm->ctrl_id = id;
224
225 id = usb_interface_id(c, f);
226 if (id < 0)
227 return id;
228
229 acm_data_intf_desc.bInterfaceNumber = id;
230 acm_union_desc.bSlaveInterface0 = id;
231 acm_call_mgmt_desc.bDataInterface = id;
232
233 f_acm->data_id = id;
234
235 /* allocate instance-specific endpoints */
236 ep = usb_ep_autoconfig(gadget, &acm_fs_in_desc);
237 if (!ep)
238 return -ENODEV;
239
240 f_acm->ep_in = ep;
Stephan Gerholdbde45c52025-04-07 16:59:35 +0200241 ep->driver_data = c->cdev; /* claim */
Loic Poulaineb78f832021-11-25 18:16:15 +0100242
243 ep = usb_ep_autoconfig(gadget, &acm_fs_out_desc);
244 if (!ep)
245 return -ENODEV;
246
247 f_acm->ep_out = ep;
Stephan Gerholdbde45c52025-04-07 16:59:35 +0200248 ep->driver_data = c->cdev; /* claim */
Loic Poulaineb78f832021-11-25 18:16:15 +0100249
250 ep = usb_ep_autoconfig(gadget, &acm_fs_notify_desc);
251 if (!ep)
252 return -ENODEV;
253
254 f_acm->ep_notify = ep;
Stephan Gerholdbde45c52025-04-07 16:59:35 +0200255 ep->driver_data = c->cdev; /* claim */
Loic Poulaineb78f832021-11-25 18:16:15 +0100256
257 if (gadget_is_dualspeed(gadget)) {
258 /* Assume endpoint addresses are the same for both speeds */
259 acm_hs_in_desc.bEndpointAddress = acm_fs_in_desc.bEndpointAddress;
260 acm_hs_out_desc.bEndpointAddress = acm_fs_out_desc.bEndpointAddress;
261 acm_hs_notify_desc.bEndpointAddress = acm_fs_notify_desc.bEndpointAddress;
262 }
263
264 return 0;
265}
266
267static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
268{
269 struct f_acm *f_acm = func_to_acm(f);
270
271 if (default_acm_function == f_acm)
272 default_acm_function = NULL;
273
274 buf_free(&f_acm->rx_buf);
275 buf_free(&f_acm->tx_buf);
276
277 free(f_acm);
278}
279
280static void acm_notify_complete(struct usb_ep *ep, struct usb_request *req)
281{
282 /* nothing to do */
283}
284
285static void acm_tx_complete(struct usb_ep *ep, struct usb_request *req)
286{
287 struct f_acm *f_acm = req->context;
288
289 f_acm->tx_on = true;
290}
291
292static void acm_rx_complete(struct usb_ep *ep, struct usb_request *req)
293{
294 struct f_acm *f_acm = req->context;
295
296 buf_push(&f_acm->rx_buf, req->buf, req->actual);
297
298 /* Queue RX req again */
299 req->actual = 0;
300 usb_ep_queue(ep, req, 0);
301}
302
303static struct usb_request *acm_start_ep(struct usb_ep *ep, void *complete_cb,
304 void *context)
305{
306 struct usb_request *req;
307
308 req = usb_ep_alloc_request(ep, 0);
309 if (!req)
310 return NULL;
311
312 req->length = REQ_SIZE_MAX;
313 req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, REQ_SIZE_MAX);
314 if (!req->buf) {
315 usb_ep_free_request(ep, req);
316 return NULL;
317 }
318
319 memset(req->buf, 0, req->length);
320 req->complete = complete_cb;
321 req->context = context;
322
323 return req;
324}
325
326static int acm_start_data(struct f_acm *f_acm, struct usb_gadget *gadget)
327{
328 const struct usb_endpoint_descriptor *d;
329 int ret;
330
331 /* EP IN */
332 d = ep_desc(gadget, &acm_hs_in_desc, &acm_fs_in_desc);
333 ret = usb_ep_enable(f_acm->ep_in, d);
334 if (ret)
335 return ret;
336
337 f_acm->req_in = acm_start_ep(f_acm->ep_in, acm_tx_complete, f_acm);
338
339 /* EP OUT */
340 d = ep_desc(gadget, &acm_hs_out_desc, &acm_fs_out_desc);
341 ret = usb_ep_enable(f_acm->ep_out, d);
342 if (ret)
343 return ret;
344
345 f_acm->req_out = acm_start_ep(f_acm->ep_out, acm_rx_complete, f_acm);
346
347 /* Start OUT transfer (EP OUT) */
348 ret = usb_ep_queue(f_acm->ep_out, f_acm->req_out, 0);
349 if (ret)
350 return ret;
351
352 return 0;
353}
354
355static int acm_start_ctrl(struct f_acm *f_acm, struct usb_gadget *gadget)
356{
357 const struct usb_endpoint_descriptor *d;
358
359 usb_ep_disable(f_acm->ep_notify);
360
361 d = ep_desc(gadget, &acm_hs_notify_desc, &acm_fs_notify_desc);
362 usb_ep_enable(f_acm->ep_notify, d);
363
364 acm_start_ep(f_acm->ep_notify, acm_notify_complete, f_acm);
365
366 return 0;
367}
368
369static int acm_set_alt(struct usb_function *f, unsigned int intf, unsigned int alt)
370{
371 struct usb_gadget *gadget = f->config->cdev->gadget;
372 struct f_acm *f_acm = func_to_acm(f);
373
374 if (intf == f_acm->ctrl_id) {
375 return acm_start_ctrl(f_acm, gadget);
376 } else if (intf == f_acm->data_id) {
377 acm_start_data(f_acm, gadget);
378 f_acm->connected = true;
379 f_acm->tx_on = true;
380 return 0;
381 }
382
383 return -EINVAL;
384}
385
386static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
387{
388 struct usb_gadget *gadget = f->config->cdev->gadget;
389 struct usb_request *req = f->config->cdev->req;
390 u16 w_index = le16_to_cpu(ctrl->wIndex);
391 u16 w_value = le16_to_cpu(ctrl->wValue);
392 u16 w_length = le16_to_cpu(ctrl->wLength);
393 struct f_acm *f_acm = func_to_acm(f);
394 int value = -1;
395
396 switch ((ctrl->bRequestType << 8) | ctrl->bRequest) {
397 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
398 | USB_CDC_REQ_SET_LINE_CODING:
399 /* SET_LINE_CODING */
400
401 if (w_length != sizeof(f_acm->line_coding) || w_index != f_acm->ctrl_id)
402 goto invalid;
403
404 value = w_length;
405
406 memcpy(&f_acm->line_coding, req->buf, value);
407
408 break;
409 case ((USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
410 | USB_CDC_REQ_GET_LINE_CODING:
411 /* GET_LINE_CODING */
412
413 if (w_length != sizeof(f_acm->line_coding) || w_index != f_acm->ctrl_id)
414 goto invalid;
415
416 value = w_length;
417
418 memcpy(req->buf, &f_acm->line_coding, value);
419
420 break;
421 case ((USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE) << 8)
422 | USB_CDC_REQ_SET_CONTROL_LINE_STATE:
423 /* SET_CONTROL_LINE_STATE */
424
425 if (w_index != f_acm->ctrl_id)
426 goto invalid;
427
428 value = 0;
429
430 f_acm->handshake_bits = w_value;
431
432 break;
433 default:
434invalid:
435 printf("invalid control req%02x.%02x v%04x i%04x l%d\n",
436 ctrl->bRequestType, ctrl->bRequest, w_value, w_index,
437 w_length);
438 }
439
440 /* respond with data transfer or status phase? */
441 if (value >= 0) {
442 req->zero = 0;
443 req->length = value;
444 usb_ep_queue(gadget->ep0, req, GFP_ATOMIC);
445 }
446
447 return 0;
448}
449
450static void acm_disable(struct usb_function *f)
451{
452 struct f_acm *f_acm = func_to_acm(f);
453
454 usb_ep_disable(f_acm->ep_out);
455 usb_ep_disable(f_acm->ep_in);
456 usb_ep_disable(f_acm->ep_notify);
457
458 if (f_acm->req_out) {
459 free(f_acm->req_out->buf);
460 usb_ep_free_request(f_acm->ep_out, f_acm->req_out);
461 f_acm->req_out = NULL;
462 }
463
464 if (f_acm->req_in) {
465 free(f_acm->req_in->buf);
466 usb_ep_free_request(f_acm->ep_in, f_acm->req_in);
467 f_acm->req_in = NULL;
468 }
469}
470
471/* static strings, in UTF-8 */
472static struct usb_string acm_string_defs[] = {
473 [0].s = "CDC Abstract Control Model (ACM)",
474 [1].s = "CDC ACM Data",
475 [2].s = "CDC Serial",
476 { } /* end of list */
477};
478
479static struct usb_gadget_strings acm_string_table = {
480 .language = 0x0409, /* en-us */
481 .strings = acm_string_defs,
482};
483
484static struct usb_gadget_strings *acm_strings[] = {
485 &acm_string_table,
486 NULL,
487};
488
489static void __acm_tx(struct f_acm *f_acm)
490{
491 int len, ret;
492
493 do {
Marek Vasutce1b62d2023-09-01 11:50:00 +0200494 dm_usb_gadget_handle_interrupts(f_acm->udc);
Loic Poulaineb78f832021-11-25 18:16:15 +0100495
496 if (!(f_acm->handshake_bits & ACM_CTRL_DTR))
497 break;
498
499 if (!f_acm->tx_on)
500 continue;
501
502 len = buf_pop(&f_acm->tx_buf, f_acm->req_in->buf, REQ_SIZE_MAX);
503 if (!len)
504 break;
505
506 f_acm->req_in->length = len;
507
508 ret = usb_ep_queue(f_acm->ep_in, f_acm->req_in, 0);
509 if (ret)
510 break;
511
512 f_acm->tx_on = false;
513
514 /* Do not reset the watchdog, if TX is stuck there is probably
515 * a real issue.
516 */
517 } while (1);
518}
519
520static bool acm_connected(struct stdio_dev *dev)
521{
522 struct f_acm *f_acm = stdio_to_acm(dev);
523
524 /* give a chance to process udc irq */
Marek Vasutce1b62d2023-09-01 11:50:00 +0200525 dm_usb_gadget_handle_interrupts(f_acm->udc);
Loic Poulaineb78f832021-11-25 18:16:15 +0100526
527 return f_acm->connected;
528}
529
530static int acm_add(struct usb_configuration *c)
531{
532 struct f_acm *f_acm;
533 int status;
534
535 f_acm = calloc(1, sizeof(*f_acm));
536 if (!f_acm)
537 return -ENOMEM;
538
539 f_acm->usb_function.name = "f_acm";
540 f_acm->usb_function.bind = acm_bind;
541 f_acm->usb_function.unbind = acm_unbind;
542 f_acm->usb_function.set_alt = acm_set_alt;
543 f_acm->usb_function.disable = acm_disable;
544 f_acm->usb_function.strings = acm_strings;
545 f_acm->usb_function.descriptors = acm_fs_function;
546 f_acm->usb_function.hs_descriptors = acm_hs_function;
547 f_acm->usb_function.setup = acm_setup;
Marek Vasutce1b62d2023-09-01 11:50:00 +0200548
549 status = udc_device_get_by_index(0, &f_acm->udc);
550 if (status)
551 return status;
Loic Poulaineb78f832021-11-25 18:16:15 +0100552
553 status = usb_add_function(c, &f_acm->usb_function);
554 if (status) {
555 free(f_acm);
556 return status;
557 }
558
559 buf_init(&f_acm->rx_buf, 2048);
560 buf_init(&f_acm->tx_buf, 2048);
561
562 if (!default_acm_function)
563 default_acm_function = f_acm;
564
565 return status;
566}
567
568DECLARE_GADGET_BIND_CALLBACK(usb_serial_acm, acm_add);
569
570/* STDIO */
571static int acm_stdio_tstc(struct stdio_dev *dev)
572{
573 struct f_acm *f_acm = stdio_to_acm(dev);
574
Marek Vasutce1b62d2023-09-01 11:50:00 +0200575 dm_usb_gadget_handle_interrupts(f_acm->udc);
Loic Poulaineb78f832021-11-25 18:16:15 +0100576
577 return (f_acm->rx_buf.size > 0);
578}
579
580static int acm_stdio_getc(struct stdio_dev *dev)
581{
582 struct f_acm *f_acm = stdio_to_acm(dev);
583 char c;
584
585 /* Wait for a character to arrive. */
586 while (!acm_stdio_tstc(dev))
Stefan Roese80877fa2022-09-02 14:10:46 +0200587 schedule();
Loic Poulaineb78f832021-11-25 18:16:15 +0100588
589 buf_pop(&f_acm->rx_buf, &c, 1);
590
591 return c;
592}
593
594static void acm_stdio_putc(struct stdio_dev *dev, const char c)
595{
596 struct f_acm *f_acm = stdio_to_acm(dev);
597
598 if (c == '\n')
599 buf_push(&f_acm->tx_buf, "\r", 1);
600
601 buf_push(&f_acm->tx_buf, &c, 1);
602
603 if (!f_acm->connected)
604 return;
605
606 __acm_tx(f_acm);
607}
608
609static void acm_stdio_puts(struct stdio_dev *dev, const char *str)
610{
611 struct f_acm *f_acm = stdio_to_acm(dev);
612
613 while (*str) {
614 if (*str == '\n')
615 buf_push(&f_acm->tx_buf, "\r", 1);
616
617 buf_push(&f_acm->tx_buf, str++, 1);
618 }
619
620 if (!f_acm->connected)
621 return;
622
623 __acm_tx(f_acm);
624}
625
626static int acm_stdio_start(struct stdio_dev *dev)
627{
Caleb Connollyd4fe66f2024-03-20 14:30:49 +0000628 struct udevice *udc;
Loic Poulaineb78f832021-11-25 18:16:15 +0100629 int ret;
630
631 if (dev->priv) { /* function already exist */
632 return 0;
633 }
634
Caleb Connollyd4fe66f2024-03-20 14:30:49 +0000635 ret = udc_device_get_by_index(0, &udc);
636 if (ret) {
637 pr_err("USB init failed: %d\n", ret);
638 return ret;
639 }
640
641 g_dnl_clear_detach();
642
Loic Poulaineb78f832021-11-25 18:16:15 +0100643 ret = g_dnl_register("usb_serial_acm");
644 if (ret)
645 return ret;
646
647 if (default_acm_function)
648 dev->priv = default_acm_function;
649 else
650 return -ENODEV;
651
652 while (!acm_connected(dev)) {
653 if (ctrlc())
654 return -ECANCELED;
655
Stefan Roese80877fa2022-09-02 14:10:46 +0200656 schedule();
Loic Poulaineb78f832021-11-25 18:16:15 +0100657 }
658
659 return 0;
660}
661
662static int acm_stdio_stop(struct stdio_dev *dev)
663{
664 g_dnl_unregister();
665 g_dnl_clear_detach();
666
667 return 0;
668}
669
670int drv_usbacm_init(void)
671{
672 struct stdio_dev stdio;
673
674 strcpy(stdio.name, "usbacm");
675 stdio.flags = DEV_FLAGS_INPUT | DEV_FLAGS_OUTPUT;
676 stdio.tstc = acm_stdio_tstc;
677 stdio.getc = acm_stdio_getc;
678 stdio.putc = acm_stdio_putc;
679 stdio.puts = acm_stdio_puts;
680 stdio.start = acm_stdio_start;
681 stdio.stop = acm_stdio_stop;
682 stdio.priv = NULL;
683 stdio.ext = 0;
684
685 return stdio_register(&stdio);
686}