2 * f_thor.c -- USB TIZEN THOR Downloader gadget function
4 * Copyright (C) 2013 Samsung Electronics
5 * Lukasz Majewski <l.majewski@samsung.com>
8 * git://review.tizen.org/kernel/u-boot
11 * Copyright (C) 2009 Samsung Electronics
12 * Minkyu Kang <mk7.kang@samsung.com>
13 * Sanghee Kim <sh0130.kim@samsung.com>
15 * SPDX-License-Identifier: GPL-2.0+
22 #include <linux/usb/ch9.h>
23 #include <linux/usb/gadget.h>
24 #include <linux/usb/composite.h>
25 #include <linux/usb/cdc.h>
31 static void thor_tx_data(unsigned char *data, int len);
32 static void thor_set_dma(void *addr, int len);
33 static int thor_rx_data(void);
35 static struct f_thor *thor_func;
36 static inline struct f_thor *func_to_thor(struct usb_function *f)
38 return container_of(f, struct f_thor, usb_function);
41 DEFINE_CACHE_ALIGN_BUFFER(unsigned char, thor_tx_data_buf,
42 sizeof(struct rsp_box));
43 DEFINE_CACHE_ALIGN_BUFFER(unsigned char, thor_rx_data_buf,
44 sizeof(struct rqt_box));
46 /* ********************************************************** */
47 /* THOR protocol - transmission handling */
48 /* ********************************************************** */
49 DEFINE_CACHE_ALIGN_BUFFER(char, f_name, F_NAME_BUF_SIZE);
50 static unsigned long long int thor_file_size;
51 static int alt_setting_num;
53 static void send_rsp(const struct rsp_box *rsp)
55 memcpy(thor_tx_data_buf, rsp, sizeof(struct rsp_box));
56 thor_tx_data(thor_tx_data_buf, sizeof(struct rsp_box));
58 debug("-RSP: %d, %d\n", rsp->rsp, rsp->rsp_data);
61 static void send_data_rsp(s32 ack, s32 count)
63 ALLOC_CACHE_ALIGN_BUFFER(struct data_rsp_box, rsp,
64 sizeof(struct data_rsp_box));
69 memcpy(thor_tx_data_buf, rsp, sizeof(struct data_rsp_box));
70 thor_tx_data(thor_tx_data_buf, sizeof(struct data_rsp_box));
72 debug("-DATA RSP: %d, %d\n", ack, count);
75 static int process_rqt_info(const struct rqt_box *rqt)
77 ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
78 memset(rsp, 0, sizeof(struct rsp_box));
81 rsp->rsp_data = rqt->rqt_data;
83 switch (rqt->rqt_data) {
84 case RQT_INFO_VER_PROTOCOL:
85 rsp->int_data[0] = VER_PROTOCOL_MAJOR;
86 rsp->int_data[1] = VER_PROTOCOL_MINOR;
89 snprintf(rsp->str_data[0], sizeof(rsp->str_data[0]),
92 case RQT_INIT_VER_BOOT:
93 sprintf(rsp->str_data[0], "%s", U_BOOT_VERSION);
95 case RQT_INIT_VER_KERNEL:
96 sprintf(rsp->str_data[0], "%s", "k unknown");
98 case RQT_INIT_VER_PLATFORM:
99 sprintf(rsp->str_data[0], "%s", "p unknown");
101 case RQT_INIT_VER_CSC:
102 sprintf(rsp->str_data[0], "%s", "c unknown");
112 static int process_rqt_cmd(const struct rqt_box *rqt)
114 ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
115 memset(rsp, 0, sizeof(struct rsp_box));
118 rsp->rsp_data = rqt->rqt_data;
120 switch (rqt->rqt_data) {
122 debug("TARGET RESET\n");
126 run_command("reset", 0);
128 case RQT_CMD_POWEROFF:
129 case RQT_CMD_EFSCLEAR:
132 printf("Command not supported -> cmd: %d\n", rqt->rqt_data);
139 static long long int download_head(unsigned long long total,
140 unsigned int packet_size,
144 long long int rcv_cnt = 0, left_to_rcv, ret_rcv;
145 struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num);
146 void *transfer_buffer = dfu_get_buf(dfu_entity);
147 void *buf = transfer_buffer;
148 int usb_pkt_cnt = 0, ret;
151 * Files smaller than THOR_STORE_UNIT_SIZE (now 32 MiB) are stored on
153 * The packet response is sent on the purpose after successful data
154 * chunk write. There is a room for improvement when asynchronous write
157 while (total - rcv_cnt >= packet_size) {
158 thor_set_dma(buf, packet_size);
160 ret_rcv = thor_rx_data();
164 debug("%d: RCV data count: %llu cnt: %d\n", usb_pkt_cnt,
167 if ((rcv_cnt % THOR_STORE_UNIT_SIZE) == 0) {
168 ret = dfu_write(dfu_get_entity(alt_setting_num),
169 transfer_buffer, THOR_STORE_UNIT_SIZE,
172 error("DFU write failed [%d] cnt: %d",
176 buf = transfer_buffer;
178 send_data_rsp(0, ++usb_pkt_cnt);
181 /* Calculate the amount of data to arrive from PC (in bytes) */
182 left_to_rcv = total - rcv_cnt;
185 * Calculate number of data already received. but not yet stored
186 * on the medium (they are smaller than THOR_STORE_UNIT_SIZE)
188 *left = left_to_rcv + buf - transfer_buffer;
189 debug("%s: left: %llu left_to_rcv: %llu buf: 0x%p\n", __func__,
190 *left, left_to_rcv, buf);
193 thor_set_dma(buf, packet_size);
194 ret_rcv = thor_rx_data();
198 send_data_rsp(0, ++usb_pkt_cnt);
201 debug("%s: %llu total: %llu cnt: %d\n", __func__, rcv_cnt, total, *cnt);
206 static int download_tail(long long int left, int cnt)
208 struct dfu_entity *dfu_entity = dfu_get_entity(alt_setting_num);
209 void *transfer_buffer = dfu_get_buf(dfu_entity);
212 debug("%s: left: %llu cnt: %d\n", __func__, left, cnt);
215 ret = dfu_write(dfu_entity, transfer_buffer, left, cnt++);
217 error("DFU write failed [%d]: left: %llu", ret, left);
223 * To store last "packet" or write file from buffer to filesystem
224 * DFU storage backend requires dfu_flush
226 * This also frees memory malloc'ed by dfu_get_buf(), so no explicit
227 * need fo call dfu_free_buf() is needed.
229 ret = dfu_flush(dfu_entity, transfer_buffer, 0, cnt);
231 error("DFU flush failed!");
236 static long long int process_rqt_download(const struct rqt_box *rqt)
238 ALLOC_CACHE_ALIGN_BUFFER(struct rsp_box, rsp, sizeof(struct rsp_box));
239 static long long int left, ret_head;
240 int file_type, ret = 0;
243 memset(rsp, 0, sizeof(struct rsp_box));
245 rsp->rsp_data = rqt->rqt_data;
247 switch (rqt->rqt_data) {
249 thor_file_size = rqt->int_data[0];
250 debug("INIT: total %d bytes\n", rqt->int_data[0]);
252 case RQT_DL_FILE_INFO:
253 file_type = rqt->int_data[0];
254 if (file_type == FILE_TYPE_PIT) {
255 puts("PIT table file - not supported\n");
256 rsp->ack = -ENOTSUPP;
261 thor_file_size = rqt->int_data[1];
262 memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE);
264 debug("INFO: name(%s, %d), size(%llu), type(%d)\n",
265 f_name, 0, thor_file_size, file_type);
267 rsp->int_data[0] = THOR_PACKET_SIZE;
269 alt_setting_num = dfu_get_alt(f_name);
270 if (alt_setting_num < 0) {
271 error("Alt setting [%d] to write not found!",
277 case RQT_DL_FILE_START:
279 ret_head = download_head(thor_file_size, THOR_PACKET_SIZE,
286 case RQT_DL_FILE_END:
287 debug("DL FILE_END\n");
288 rsp->ack = download_tail(left, cnt);
297 error("Operation not supported: %d", rqt->rqt_data);
305 static int process_data(void)
307 ALLOC_CACHE_ALIGN_BUFFER(struct rqt_box, rqt, sizeof(struct rqt_box));
310 memcpy(rqt, thor_rx_data_buf, sizeof(struct rqt_box));
312 debug("+RQT: %d, %d\n", rqt->rqt, rqt->rqt_data);
316 ret = process_rqt_info(rqt);
319 ret = process_rqt_cmd(rqt);
322 ret = (int) process_rqt_download(rqt);
325 puts("RQT: UPLOAD not supported!\n");
328 error("unknown request (%d)", rqt->rqt);
334 /* ********************************************************** */
335 /* THOR USB Function */
336 /* ********************************************************** */
338 static inline struct usb_endpoint_descriptor *
339 ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs,
340 struct usb_endpoint_descriptor *fs)
342 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
347 static struct usb_interface_descriptor thor_downloader_intf_data = {
348 .bLength = sizeof(thor_downloader_intf_data),
349 .bDescriptorType = USB_DT_INTERFACE,
352 .bInterfaceClass = USB_CLASS_CDC_DATA,
355 static struct usb_endpoint_descriptor fs_in_desc = {
356 .bLength = USB_DT_ENDPOINT_SIZE,
357 .bDescriptorType = USB_DT_ENDPOINT,
359 .bEndpointAddress = USB_DIR_IN,
360 .bmAttributes = USB_ENDPOINT_XFER_BULK,
363 static struct usb_endpoint_descriptor fs_out_desc = {
364 .bLength = USB_DT_ENDPOINT_SIZE,
365 .bDescriptorType = USB_DT_ENDPOINT,
367 .bEndpointAddress = USB_DIR_OUT,
368 .bmAttributes = USB_ENDPOINT_XFER_BULK,
371 /* CDC configuration */
372 static struct usb_interface_descriptor thor_downloader_intf_int = {
373 .bLength = sizeof(thor_downloader_intf_int),
374 .bDescriptorType = USB_DT_INTERFACE,
377 .bInterfaceClass = USB_CLASS_COMM,
378 /* 0x02 Abstract Line Control Model */
379 .bInterfaceSubClass = USB_CDC_SUBCLASS_ACM,
380 /* 0x01 Common AT commands */
381 .bInterfaceProtocol = USB_CDC_ACM_PROTO_AT_V25TER,
384 static struct usb_cdc_header_desc thor_downloader_cdc_header = {
385 .bLength = sizeof(thor_downloader_cdc_header),
386 .bDescriptorType = 0x24, /* CS_INTERFACE */
387 .bDescriptorSubType = 0x00,
391 static struct usb_cdc_call_mgmt_descriptor thor_downloader_cdc_call = {
392 .bLength = sizeof(thor_downloader_cdc_call),
393 .bDescriptorType = 0x24, /* CS_INTERFACE */
394 .bDescriptorSubType = 0x01,
395 .bmCapabilities = 0x00,
396 .bDataInterface = 0x01,
399 static struct usb_cdc_acm_descriptor thor_downloader_cdc_abstract = {
400 .bLength = sizeof(thor_downloader_cdc_abstract),
401 .bDescriptorType = 0x24, /* CS_INTERFACE */
402 .bDescriptorSubType = 0x02,
403 .bmCapabilities = 0x00,
406 static struct usb_cdc_union_desc thor_downloader_cdc_union = {
407 .bLength = sizeof(thor_downloader_cdc_union),
408 .bDescriptorType = 0x24, /* CS_INTERFACE */
409 .bDescriptorSubType = USB_CDC_UNION_TYPE,
412 static struct usb_endpoint_descriptor fs_int_desc = {
413 .bLength = USB_DT_ENDPOINT_SIZE,
414 .bDescriptorType = USB_DT_ENDPOINT,
416 .bEndpointAddress = 3 | USB_DIR_IN,
417 .bmAttributes = USB_ENDPOINT_XFER_INT,
418 .wMaxPacketSize = __constant_cpu_to_le16(16),
423 static struct usb_interface_assoc_descriptor
424 thor_iad_descriptor = {
425 .bLength = sizeof(thor_iad_descriptor),
426 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
428 .bFirstInterface = 0,
429 .bInterfaceCount = 2, /* control + data */
430 .bFunctionClass = USB_CLASS_COMM,
431 .bFunctionSubClass = USB_CDC_SUBCLASS_ACM,
432 .bFunctionProtocol = USB_CDC_PROTO_NONE,
435 static struct usb_endpoint_descriptor hs_in_desc = {
436 .bLength = USB_DT_ENDPOINT_SIZE,
437 .bDescriptorType = USB_DT_ENDPOINT,
439 .bmAttributes = USB_ENDPOINT_XFER_BULK,
440 .wMaxPacketSize = __constant_cpu_to_le16(512),
443 static struct usb_endpoint_descriptor hs_out_desc = {
444 .bLength = USB_DT_ENDPOINT_SIZE,
445 .bDescriptorType = USB_DT_ENDPOINT,
447 .bmAttributes = USB_ENDPOINT_XFER_BULK,
448 .wMaxPacketSize = __constant_cpu_to_le16(512),
451 static struct usb_endpoint_descriptor hs_int_desc = {
452 .bLength = USB_DT_ENDPOINT_SIZE,
453 .bDescriptorType = USB_DT_ENDPOINT,
455 .bmAttributes = USB_ENDPOINT_XFER_INT,
456 .wMaxPacketSize = __constant_cpu_to_le16(16),
462 * This attribute vendor descriptor is necessary for correct operation with
463 * Windows version of THOR download program
465 * It prevents windows driver from sending zero lenght packet (ZLP) after
466 * each THOR_PACKET_SIZE. This assures consistent behaviour with libusb
468 static struct usb_cdc_attribute_vendor_descriptor thor_downloader_cdc_av = {
469 .bLength = sizeof(thor_downloader_cdc_av),
470 .bDescriptorType = 0x24,
471 .bDescriptorSubType = 0x80,
477 static const struct usb_descriptor_header *hs_thor_downloader_function[] = {
478 (struct usb_descriptor_header *)&thor_iad_descriptor,
480 (struct usb_descriptor_header *)&thor_downloader_intf_int,
481 (struct usb_descriptor_header *)&thor_downloader_cdc_header,
482 (struct usb_descriptor_header *)&thor_downloader_cdc_call,
483 (struct usb_descriptor_header *)&thor_downloader_cdc_abstract,
484 (struct usb_descriptor_header *)&thor_downloader_cdc_union,
485 (struct usb_descriptor_header *)&hs_int_desc,
487 (struct usb_descriptor_header *)&thor_downloader_intf_data,
488 (struct usb_descriptor_header *)&thor_downloader_cdc_av,
489 (struct usb_descriptor_header *)&hs_in_desc,
490 (struct usb_descriptor_header *)&hs_out_desc,
494 /*-------------------------------------------------------------------------*/
495 static struct usb_request *alloc_ep_req(struct usb_ep *ep, unsigned length)
497 struct usb_request *req;
499 req = usb_ep_alloc_request(ep, 0);
503 req->length = length;
504 req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, length);
506 usb_ep_free_request(ep, req);
513 static int thor_rx_data(void)
515 struct thor_dev *dev = thor_func->dev;
516 int data_to_rx, tmp, status;
518 data_to_rx = dev->out_req->length;
521 dev->out_req->length = data_to_rx;
522 debug("dev->out_req->length:%d dev->rxdata:%d\n",
523 dev->out_req->length, dev->rxdata);
525 status = usb_ep_queue(dev->out_ep, dev->out_req, 0);
527 error("kill %s: resubmit %d bytes --> %d",
528 dev->out_ep->name, dev->out_req->length, status);
529 usb_ep_set_halt(dev->out_ep);
533 while (!dev->rxdata) {
534 usb_gadget_handle_interrupts();
539 data_to_rx -= dev->out_req->actual;
540 } while (data_to_rx);
545 static void thor_tx_data(unsigned char *data, int len)
547 struct thor_dev *dev = thor_func->dev;
548 unsigned char *ptr = dev->in_req->buf;
552 memcpy(ptr, data, len);
554 dev->in_req->length = len;
556 debug("%s: dev->in_req->length:%d to_cpy:%d\n", __func__,
557 dev->in_req->length, sizeof(data));
559 status = usb_ep_queue(dev->in_ep, dev->in_req, 0);
561 error("kill %s: resubmit %d bytes --> %d",
562 dev->in_ep->name, dev->in_req->length, status);
563 usb_ep_set_halt(dev->in_ep);
566 /* Wait until tx interrupt received */
568 usb_gadget_handle_interrupts();
573 static void thor_rx_tx_complete(struct usb_ep *ep, struct usb_request *req)
575 struct thor_dev *dev = thor_func->dev;
576 int status = req->status;
578 debug("%s: ep_ptr:%p, req_ptr:%p\n", __func__, ep, req);
581 if (ep == dev->out_ep)
588 /* this endpoint is normally active while we're configured */
589 case -ECONNABORTED: /* hardware forced ep reset */
590 case -ECONNRESET: /* request dequeued */
591 case -ESHUTDOWN: /* disconnect from host */
592 case -EREMOTEIO: /* short read */
594 error("ERROR:%d", status);
598 debug("%s complete --> %d, %d/%d\n", ep->name,
599 status, req->actual, req->length);
602 static struct usb_request *thor_start_ep(struct usb_ep *ep)
604 struct usb_request *req;
606 req = alloc_ep_req(ep, THOR_PACKET_SIZE);
607 debug("%s: ep:%p req:%p\n", __func__, ep, req);
612 memset(req->buf, 0, req->length);
613 req->complete = thor_rx_tx_complete;
618 static void thor_setup_complete(struct usb_ep *ep, struct usb_request *req)
620 if (req->status || req->actual != req->length)
621 debug("setup complete --> %d, %d/%d\n",
622 req->status, req->actual, req->length);
626 thor_func_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)
628 struct thor_dev *dev = thor_func->dev;
629 struct usb_request *req = dev->req;
630 struct usb_gadget *gadget = dev->gadget;
633 u16 len = le16_to_cpu(ctrl->wLength);
635 debug("Req_Type: 0x%x Req: 0x%x wValue: 0x%x wIndex: 0x%x wLen: 0x%x\n",
636 ctrl->bRequestType, ctrl->bRequest, ctrl->wValue, ctrl->wIndex,
639 switch (ctrl->bRequest) {
640 case USB_CDC_REQ_SET_CONTROL_LINE_STATE:
643 case USB_CDC_REQ_SET_LINE_CODING:
645 /* Line Coding set done = configuration done */
646 thor_func->dev->configuration_done = 1;
650 error("thor_setup: unknown request: %d", ctrl->bRequest);
655 req->zero = value < len;
656 value = usb_ep_queue(gadget->ep0, req, 0);
658 debug("%s: ep_queue: %d\n", __func__, value);
666 /* Specific to the THOR protocol */
667 static void thor_set_dma(void *addr, int len)
669 struct thor_dev *dev = thor_func->dev;
671 debug("in_req:%p, out_req:%p\n", dev->in_req, dev->out_req);
672 debug("addr:%p, len:%d\n", addr, len);
674 dev->out_req->buf = addr;
675 dev->out_req->length = len;
680 struct thor_dev *dev = thor_func->dev;
682 /* Wait for a device enumeration and configuration settings */
683 debug("THOR enumeration/configuration setting....\n");
684 while (!dev->configuration_done)
685 usb_gadget_handle_interrupts();
687 thor_set_dma(thor_rx_data_buf, strlen("THOR"));
688 /* detect the download request from Host PC */
689 if (thor_rx_data() < 0) {
690 printf("%s: Data not received!\n", __func__);
694 if (!strncmp((char *)thor_rx_data_buf, "THOR", strlen("THOR"))) {
695 puts("Download request from the Host PC\n");
696 udelay(30 * 1000); /* 30 ms */
698 strcpy((char *)thor_tx_data_buf, "ROHT");
699 thor_tx_data(thor_tx_data_buf, strlen("ROHT"));
701 puts("Wrong reply information\n");
708 int thor_handle(void)
712 /* receive the data from Host PC */
714 thor_set_dma(thor_rx_data_buf, sizeof(struct rqt_box));
715 ret = thor_rx_data();
718 ret = process_data();
722 printf("%s: No data received!\n", __func__);
730 static int thor_func_bind(struct usb_configuration *c, struct usb_function *f)
732 struct usb_gadget *gadget = c->cdev->gadget;
733 struct f_thor *f_thor = func_to_thor(f);
734 struct thor_dev *dev;
739 dev = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*dev));
743 memset(dev, 0, sizeof(*dev));
744 dev->gadget = gadget;
747 debug("%s: usb_configuration: 0x%p usb_function: 0x%p\n",
749 debug("f_thor: 0x%p thor: 0x%p\n", f_thor, dev);
752 /* preallocate control response and buffer */
753 dev->req = usb_ep_alloc_request(gadget->ep0, 0);
758 dev->req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE,
759 gadget->ep0->maxpacket);
760 if (!dev->req->buf) {
765 dev->req->complete = thor_setup_complete;
767 /* DYNAMIC interface numbers assignments */
768 status = usb_interface_id(c, f);
773 thor_downloader_intf_int.bInterfaceNumber = status;
774 thor_downloader_cdc_union.bMasterInterface0 = status;
776 status = usb_interface_id(c, f);
781 thor_downloader_intf_data.bInterfaceNumber = status;
782 thor_downloader_cdc_union.bSlaveInterface0 = status;
784 /* allocate instance-specific endpoints */
785 ep = usb_ep_autoconfig(gadget, &fs_in_desc);
791 if (gadget_is_dualspeed(gadget)) {
792 hs_in_desc.bEndpointAddress =
793 fs_in_desc.bEndpointAddress;
796 dev->in_ep = ep; /* Store IN EP for enabling @ setup */
798 ep = usb_ep_autoconfig(gadget, &fs_out_desc);
804 if (gadget_is_dualspeed(gadget))
805 hs_out_desc.bEndpointAddress =
806 fs_out_desc.bEndpointAddress;
808 dev->out_ep = ep; /* Store OUT EP for enabling @ setup */
810 ep = usb_ep_autoconfig(gadget, &fs_int_desc);
818 if (gadget_is_dualspeed(gadget)) {
819 hs_int_desc.bEndpointAddress =
820 fs_int_desc.bEndpointAddress;
822 f->hs_descriptors = (struct usb_descriptor_header **)
823 &hs_thor_downloader_function;
825 if (!f->hs_descriptors)
829 debug("%s: out_ep:%p out_req:%p\n", __func__,
830 dev->out_ep, dev->out_req);
839 static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
842 usb_ep_free_request(ep, req);
845 static void thor_unbind(struct usb_configuration *c, struct usb_function *f)
847 struct f_thor *f_thor = func_to_thor(f);
848 struct thor_dev *dev = f_thor->dev;
851 memset(thor_func, 0, sizeof(*thor_func));
855 static void thor_func_disable(struct usb_function *f)
857 struct f_thor *f_thor = func_to_thor(f);
858 struct thor_dev *dev = f_thor->dev;
860 debug("%s:\n", __func__);
862 /* Avoid freeing memory when ep is still claimed */
863 if (dev->in_ep->driver_data) {
864 free_ep_req(dev->in_ep, dev->in_req);
865 usb_ep_disable(dev->in_ep);
866 dev->in_ep->driver_data = NULL;
869 if (dev->out_ep->driver_data) {
870 dev->out_req->buf = NULL;
871 usb_ep_free_request(dev->out_ep, dev->out_req);
872 usb_ep_disable(dev->out_ep);
873 dev->out_ep->driver_data = NULL;
876 if (dev->int_ep->driver_data) {
877 usb_ep_disable(dev->int_ep);
878 dev->int_ep->driver_data = NULL;
882 static int thor_eps_setup(struct usb_function *f)
884 struct usb_composite_dev *cdev = f->config->cdev;
885 struct usb_gadget *gadget = cdev->gadget;
886 struct thor_dev *dev = thor_func->dev;
887 struct usb_endpoint_descriptor *d;
888 struct usb_request *req;
893 d = ep_desc(gadget, &hs_in_desc, &fs_in_desc);
894 debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
896 result = usb_ep_enable(ep, d);
900 ep->driver_data = cdev; /* claim */
901 req = thor_start_ep(ep);
910 d = ep_desc(gadget, &hs_out_desc, &fs_out_desc);
911 debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress);
913 result = usb_ep_enable(ep, d);
917 ep->driver_data = cdev; /* claim */
918 req = thor_start_ep(ep);
928 ep->driver_data = cdev; /* claim */
934 static int thor_func_set_alt(struct usb_function *f,
935 unsigned intf, unsigned alt)
937 struct thor_dev *dev = thor_func->dev;
940 debug("%s: func: %s intf: %d alt: %d\n",
941 __func__, f->name, intf, alt);
945 debug("ACM INTR interface\n");
948 debug("Communication Data interface\n");
949 result = thor_eps_setup(f);
951 error("%s: EPs setup failed!", __func__);
952 dev->configuration_done = 1;
959 static int thor_func_init(struct usb_configuration *c)
961 struct f_thor *f_thor;
964 debug("%s: cdev: 0x%p\n", __func__, c->cdev);
966 f_thor = memalign(CONFIG_SYS_CACHELINE_SIZE, sizeof(*f_thor));
970 memset(f_thor, 0, sizeof(*f_thor));
972 f_thor->usb_function.name = "f_thor";
973 f_thor->usb_function.bind = thor_func_bind;
974 f_thor->usb_function.unbind = thor_unbind;
975 f_thor->usb_function.setup = thor_func_setup;
976 f_thor->usb_function.set_alt = thor_func_set_alt;
977 f_thor->usb_function.disable = thor_func_disable;
979 status = usb_add_function(c, &f_thor->usb_function);
986 int thor_add(struct usb_configuration *c)
988 debug("%s:\n", __func__);
989 return thor_func_init(c);
992 DECLARE_GADGET_BIND_CALLBACK(usb_dnl_thor, thor_add);