Lines Matching +full:pc +full:- +full:ack
1 // SPDX-License-Identifier: GPL-2.0+
3 * f_thor.c -- USB TIZEN THOR Downloader gadget function
9 * git://review.tizen.org/kernel/u-boot
48 /* THOR protocol - transmission handling */
59 debug("-RSP: %d, %d\n", rsp->rsp, rsp->rsp_data); in send_rsp()
62 static void send_data_rsp(s32 ack, s32 count) in send_data_rsp() argument
67 rsp->ack = ack; in send_data_rsp()
68 rsp->count = count; in send_data_rsp()
73 debug("-DATA RSP: %d, %d\n", ack, count); in send_data_rsp()
81 rsp->rsp = rqt->rqt; in process_rqt_info()
82 rsp->rsp_data = rqt->rqt_data; in process_rqt_info()
84 switch (rqt->rqt_data) { in process_rqt_info()
86 rsp->int_data[0] = VER_PROTOCOL_MAJOR; in process_rqt_info()
87 rsp->int_data[1] = VER_PROTOCOL_MINOR; in process_rqt_info()
90 snprintf(rsp->str_data[0], sizeof(rsp->str_data[0]), in process_rqt_info()
94 sprintf(rsp->str_data[0], "%s", U_BOOT_VERSION); in process_rqt_info()
97 sprintf(rsp->str_data[0], "%s", "k unknown"); in process_rqt_info()
100 sprintf(rsp->str_data[0], "%s", "p unknown"); in process_rqt_info()
103 sprintf(rsp->str_data[0], "%s", "c unknown"); in process_rqt_info()
106 return -EINVAL; in process_rqt_info()
118 rsp->rsp = rqt->rqt; in process_rqt_cmd()
119 rsp->rsp_data = rqt->rqt_data; in process_rqt_cmd()
121 switch (rqt->rqt_data) { in process_rqt_cmd()
136 printf("Command not supported -> cmd: %d\n", rqt->rqt_data); in process_rqt_cmd()
137 return -EINVAL; in process_rqt_cmd()
161 while (total - rcv_cnt >= packet_size) { in download_head()
185 /* Calculate the amount of data to arrive from PC (in bytes) */ in download_head()
186 left_to_rcv = total - rcv_cnt; in download_head()
192 *left = left_to_rcv + buf - transfer_buffer; in download_head()
221 return -ENOENT; in download_tail()
227 return -ENXIO; in download_tail()
260 rsp->rsp = rqt->rqt; in process_rqt_download()
261 rsp->rsp_data = rqt->rqt_data; in process_rqt_download()
263 switch (rqt->rqt_data) { in process_rqt_download()
265 thor_file_size = (unsigned long long int)rqt->int_data[0] + in process_rqt_download()
266 (((unsigned long long int)rqt->int_data[1]) in process_rqt_download()
271 file_type = rqt->int_data[0]; in process_rqt_download()
273 puts("PIT table file - not supported\n"); in process_rqt_download()
274 rsp->ack = -ENOTSUPP; in process_rqt_download()
275 ret = rsp->ack; in process_rqt_download()
279 thor_file_size = (unsigned long long int)rqt->int_data[1] + in process_rqt_download()
280 (((unsigned long long int)rqt->int_data[2]) in process_rqt_download()
282 memcpy(f_name, rqt->str_data[0], F_NAME_BUF_SIZE); in process_rqt_download()
288 rsp->int_data[0] = THOR_PACKET_SIZE; in process_rqt_download()
294 rsp->ack = -ENODEV; in process_rqt_download()
295 ret = rsp->ack; in process_rqt_download()
309 rsp->ack = download_tail(left, cnt); in process_rqt_download()
310 ret = rsp->ack; in process_rqt_download()
318 pr_err("Operation not supported: %d", rqt->rqt_data); in process_rqt_download()
319 ret = -ENOTSUPP; in process_rqt_download()
329 int ret = -EINVAL; in process_data()
333 debug("+RQT: %d, %d\n", rqt->rqt, rqt->rqt_data); in process_data()
335 switch (rqt->rqt) { in process_data()
349 pr_err("unknown request (%d)", rqt->rqt); in process_data()
363 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) in ep_desc()
515 /*-------------------------------------------------------------------------*/
524 req->length = length; in alloc_ep_req()
525 req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, length); in alloc_ep_req()
526 if (!req->buf) { in alloc_ep_req()
536 struct thor_dev *dev = thor_func->dev; in thor_rx_data()
539 data_to_rx = dev->out_req->length; in thor_rx_data()
542 dev->out_req->length = data_to_rx; in thor_rx_data()
543 debug("dev->out_req->length:%d dev->rxdata:%d\n", in thor_rx_data()
544 dev->out_req->length, dev->rxdata); in thor_rx_data()
546 status = usb_ep_queue(dev->out_ep, dev->out_req, 0); in thor_rx_data()
548 pr_err("kill %s: resubmit %d bytes --> %d", in thor_rx_data()
549 dev->out_ep->name, dev->out_req->length, status); in thor_rx_data()
550 usb_ep_set_halt(dev->out_ep); in thor_rx_data()
551 return -EAGAIN; in thor_rx_data()
554 while (!dev->rxdata) { in thor_rx_data()
557 return -1; in thor_rx_data()
559 dev->rxdata = 0; in thor_rx_data()
560 data_to_rx -= dev->out_req->actual; in thor_rx_data()
568 struct thor_dev *dev = thor_func->dev; in thor_tx_data()
569 unsigned char *ptr = dev->in_req->buf; in thor_tx_data()
575 dev->in_req->length = len; in thor_tx_data()
577 debug("%s: dev->in_req->length:%d to_cpy:%zd\n", __func__, in thor_tx_data()
578 dev->in_req->length, sizeof(data)); in thor_tx_data()
580 status = usb_ep_queue(dev->in_ep, dev->in_req, 0); in thor_tx_data()
582 pr_err("kill %s: resubmit %d bytes --> %d", in thor_tx_data()
583 dev->in_ep->name, dev->in_req->length, status); in thor_tx_data()
584 usb_ep_set_halt(dev->in_ep); in thor_tx_data()
588 while (!dev->txdata) in thor_tx_data()
591 dev->txdata = 0; in thor_tx_data()
596 struct thor_dev *dev = thor_func->dev; in thor_rx_tx_complete()
597 int status = req->status; in thor_rx_tx_complete()
602 if (ep == dev->out_ep) in thor_rx_tx_complete()
603 dev->rxdata = 1; in thor_rx_tx_complete()
605 dev->txdata = 1; in thor_rx_tx_complete()
610 case -ECONNABORTED: /* hardware forced ep reset */ in thor_rx_tx_complete()
611 case -ECONNRESET: /* request dequeued */ in thor_rx_tx_complete()
612 case -ESHUTDOWN: /* disconnect from host */ in thor_rx_tx_complete()
613 case -EREMOTEIO: /* short read */ in thor_rx_tx_complete()
614 case -EOVERFLOW: in thor_rx_tx_complete()
619 debug("%s complete --> %d, %d/%d\n", ep->name, in thor_rx_tx_complete()
620 status, req->actual, req->length); in thor_rx_tx_complete()
625 if (req->status || req->actual != req->length) in thor_setup_complete()
626 debug("setup complete --> %d, %d/%d\n", in thor_setup_complete()
627 req->status, req->actual, req->length); in thor_setup_complete()
633 struct thor_dev *dev = thor_func->dev; in thor_func_setup()
634 struct usb_request *req = dev->req; in thor_func_setup()
635 struct usb_gadget *gadget = dev->gadget; in thor_func_setup()
638 u16 len = le16_to_cpu(ctrl->wLength); in thor_func_setup()
641 ctrl->bRequestType, ctrl->bRequest, ctrl->wValue, ctrl->wIndex, in thor_func_setup()
642 ctrl->wLength); in thor_func_setup()
644 switch (ctrl->bRequest) { in thor_func_setup()
651 thor_func->dev->configuration_done = 1; in thor_func_setup()
655 pr_err("thor_setup: unknown request: %d", ctrl->bRequest); in thor_func_setup()
659 req->length = value; in thor_func_setup()
660 req->zero = value < len; in thor_func_setup()
661 value = usb_ep_queue(gadget->ep0, req, 0); in thor_func_setup()
664 req->status = 0; in thor_func_setup()
674 struct thor_dev *dev = thor_func->dev; in thor_set_dma()
676 debug("in_req:%p, out_req:%p\n", dev->in_req, dev->out_req); in thor_set_dma()
679 dev->out_req->buf = addr; in thor_set_dma()
680 dev->out_req->length = len; in thor_set_dma()
685 struct thor_dev *dev = thor_func->dev; in thor_init()
689 while (!dev->configuration_done) in thor_init()
693 /* detect the download request from Host PC */ in thor_init()
696 return -1; in thor_init()
700 puts("Download request from the Host PC\n"); in thor_init()
707 return -1; in thor_init()
717 /* receive the data from Host PC */ in thor_handle()
741 if (req->buf) in free_ep_req()
742 free(req->buf); in free_ep_req()
748 struct usb_gadget *gadget = c->cdev->gadget; in thor_func_bind()
757 return -ENOMEM; in thor_func_bind()
760 dev->gadget = gadget; in thor_func_bind()
761 f_thor->dev = dev; in thor_func_bind()
769 dev->req = usb_ep_alloc_request(gadget->ep0, 0); in thor_func_bind()
770 if (!dev->req) { in thor_func_bind()
771 status = -ENOMEM; in thor_func_bind()
774 dev->req->buf = memalign(CONFIG_SYS_CACHELINE_SIZE, in thor_func_bind()
776 if (!dev->req->buf) { in thor_func_bind()
777 status = -ENOMEM; in thor_func_bind()
781 dev->req->complete = thor_setup_complete; in thor_func_bind()
800 /* allocate instance-specific endpoints */ in thor_func_bind()
803 status = -ENODEV; in thor_func_bind()
812 dev->in_ep = ep; /* Store IN EP for enabling @ setup */ in thor_func_bind()
813 ep->driver_data = dev; in thor_func_bind()
817 status = -ENODEV; in thor_func_bind()
825 dev->out_ep = ep; /* Store OUT EP for enabling @ setup */ in thor_func_bind()
826 ep->driver_data = dev; in thor_func_bind()
830 status = -ENODEV; in thor_func_bind()
834 dev->int_ep = ep; in thor_func_bind()
835 ep->driver_data = dev; in thor_func_bind()
841 f->hs_descriptors = (struct usb_descriptor_header **) in thor_func_bind()
844 if (!f->hs_descriptors) in thor_func_bind()
849 dev->out_ep, dev->out_req); in thor_func_bind()
854 if (dev->req) in thor_func_bind()
855 free_ep_req(gadget->ep0, dev->req); in thor_func_bind()
863 struct thor_dev *dev = f_thor->dev; in thor_unbind()
865 free_ep_req(dev->gadget->ep0, dev->req); in thor_unbind()
874 struct thor_dev *dev = f_thor->dev; in thor_func_disable()
879 if (dev->in_ep->driver_data) { in thor_func_disable()
880 usb_ep_disable(dev->in_ep); in thor_func_disable()
881 free_ep_req(dev->in_ep, dev->in_req); in thor_func_disable()
882 dev->in_ep->driver_data = NULL; in thor_func_disable()
885 if (dev->out_ep->driver_data) { in thor_func_disable()
886 usb_ep_disable(dev->out_ep); in thor_func_disable()
887 usb_ep_free_request(dev->out_ep, dev->out_req); in thor_func_disable()
888 dev->out_ep->driver_data = NULL; in thor_func_disable()
891 if (dev->int_ep->driver_data) { in thor_func_disable()
892 usb_ep_disable(dev->int_ep); in thor_func_disable()
893 dev->int_ep->driver_data = NULL; in thor_func_disable()
899 struct usb_composite_dev *cdev = f->config->cdev; in thor_eps_setup()
900 struct usb_gadget *gadget = cdev->gadget; in thor_eps_setup()
901 struct thor_dev *dev = thor_func->dev; in thor_eps_setup()
907 ep = dev->in_ep; in thor_eps_setup()
909 debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress); in thor_eps_setup()
915 ep->driver_data = cdev; /* claim */ in thor_eps_setup()
918 result = -EIO; in thor_eps_setup()
922 memset(req->buf, 0, req->length); in thor_eps_setup()
923 req->complete = thor_rx_tx_complete; in thor_eps_setup()
924 dev->in_req = req; in thor_eps_setup()
925 ep = dev->out_ep; in thor_eps_setup()
927 debug("(d)bEndpointAddress: 0x%x\n", d->bEndpointAddress); in thor_eps_setup()
933 ep->driver_data = cdev; /* claim */ in thor_eps_setup()
936 result = -EIO; in thor_eps_setup()
940 req->complete = thor_rx_tx_complete; in thor_eps_setup()
941 dev->out_req = req; in thor_eps_setup()
943 ep = dev->int_ep; in thor_eps_setup()
944 ep->driver_data = cdev; /* claim */ in thor_eps_setup()
949 usb_ep_disable(dev->out_ep); in thor_eps_setup()
952 free_ep_req(dev->in_ep, dev->in_req); in thor_eps_setup()
953 dev->in_req = NULL; in thor_eps_setup()
956 usb_ep_disable(dev->in_ep); in thor_eps_setup()
965 struct thor_dev *dev = thor_func->dev; in thor_func_set_alt()
969 __func__, f->name, intf, alt); in thor_func_set_alt()
980 dev->configuration_done = 1; in thor_func_set_alt()
992 debug("%s: cdev: 0x%p\n", __func__, c->cdev); in thor_func_init()
996 return -ENOMEM; in thor_func_init()
1000 f_thor->usb_function.name = "f_thor"; in thor_func_init()
1001 f_thor->usb_function.bind = thor_func_bind; in thor_func_init()
1002 f_thor->usb_function.unbind = thor_unbind; in thor_func_init()
1003 f_thor->usb_function.setup = thor_func_setup; in thor_func_init()
1004 f_thor->usb_function.set_alt = thor_func_set_alt; in thor_func_init()
1005 f_thor->usb_function.disable = thor_func_disable; in thor_func_init()
1007 status = usb_add_function(c, &f_thor->usb_function); in thor_func_init()