Lines Matching +full:rzn1 +full:- +full:usbf

1 // SPDX-License-Identifier: GPL-2.0
3 * Renesas USBF USB Function driver
10 #include <linux/dma-mapping.h>
131 /* EPn registers offsets from Base + USBF_BASE_EPN(n-1). n=1..15 */
209 /* AHB-EPC Bridge registers */
244 /* EPn DMA registers offsets from Base USBF_BASE_DMA_EPN(n-1). n=1..15*/
345 [0] = USBF_EP_INFO("ep0-ctrl",
349 /* ep1: buf @0x0020, 2 buffers 512 bytes -> (512 * 2 / 4) words */
350 [1] = USBF_EP_INFO("ep1-bulk",
354 /* ep2: buf @0x0120, 2 buffers 512 bytes -> (512 * 2 / 4) words */
355 [2] = USBF_EP_INFO("ep2-bulk",
359 /* ep3: buf @0x0220, 1 buffer 512 bytes -> (512 * 2 / 4) words */
360 [3] = USBF_EP_INFO("ep3-bulk",
364 /* ep4: buf @0x02A0, 1 buffer 512 bytes -> (512 * 1 / 4) words */
365 [4] = USBF_EP_INFO("ep4-bulk",
369 /* ep5: buf @0x0320, 1 buffer 512 bytes -> (512 * 2 / 4) words */
370 [5] = USBF_EP_INFO("ep5-bulk",
374 /* ep6: buf @0x03A0, 1 buffer 1024 bytes -> (1024 * 1 / 4) words */
375 [6] = USBF_EP_INFO("ep6-int",
379 /* ep7: buf @0x04A0, 1 buffer 1024 bytes -> (1024 * 1 / 4) words */
380 [7] = USBF_EP_INFO("ep7-int",
384 /* ep8: buf @0x0520, 1 buffer 1024 bytes -> (1024 * 1 / 4) words */
385 [8] = USBF_EP_INFO("ep8-int",
389 /* ep9: buf @0x0620, 1 buffer 1024 bytes -> (1024 * 1 / 4) words */
390 [9] = USBF_EP_INFO("ep9-int",
394 /* ep10: buf @0x0720, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
395 [10] = USBF_EP_INFO("ep10-iso",
399 /* ep11: buf @0x0920, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
400 [11] = USBF_EP_INFO("ep11-iso",
404 /* ep12: buf @0x0B20, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
405 [12] = USBF_EP_INFO("ep12-iso",
409 /* ep13: buf @0x0D20, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
410 [13] = USBF_EP_INFO("ep13-iso",
414 /* ep14: buf @0x0F20, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
415 [14] = USBF_EP_INFO("ep14-iso",
419 /* ep15: buf @0x1120, 2 buffers 1024 bytes -> (1024 * 2 / 4) words */
420 [15] = USBF_EP_INFO("ep15-iso",
428 return readl(udc->regs + offset); in usbf_reg_readl()
433 writel(val, udc->regs + offset); in usbf_reg_writel()
467 return readl(ep->regs + offset); in usbf_ep_reg_readl()
473 readsl(ep->regs + offset, dst, count); in usbf_ep_reg_read_rep()
478 writel(val, ep->regs + offset); in usbf_ep_reg_writel()
484 writesl(ep->regs + offset, src, count); in usbf_ep_reg_write_rep()
518 return readl(ep->dma_regs + offset); in usbf_ep_dma_reg_readl()
524 writel(val, ep->dma_regs + offset); in usbf_ep_dma_reg_writel()
566 left = req->req.length - req->req.actual; in usbf_ep0_pio_in()
569 if (!req->is_zero_sent) { in usbf_ep0_pio_in()
570 if (req->req.length == 0) { in usbf_ep0_pio_in()
571 dev_dbg(ep0->udc->dev, "ep0 send null\n"); in usbf_ep0_pio_in()
573 req->is_zero_sent = 1; in usbf_ep0_pio_in()
574 return -EINPROGRESS; in usbf_ep0_pio_in()
576 if ((req->req.actual % ep0->ep.maxpacket) == 0) { in usbf_ep0_pio_in()
577 if (req->req.zero) { in usbf_ep0_pio_in()
578 dev_dbg(ep0->udc->dev, "ep0 send null\n"); in usbf_ep0_pio_in()
580 req->is_zero_sent = 1; in usbf_ep0_pio_in()
581 return -EINPROGRESS; in usbf_ep0_pio_in()
588 if (left > ep0->ep.maxpacket) in usbf_ep0_pio_in()
589 left = ep0->ep.maxpacket; in usbf_ep0_pio_in()
591 buf = req->req.buf; in usbf_ep0_pio_in()
592 buf += req->req.actual; in usbf_ep0_pio_in()
598 req->req.actual += (nb * sizeof(u32)); in usbf_ep0_pio_in()
599 left -= (nb * sizeof(u32)); in usbf_ep0_pio_in()
607 req->req.actual += left; in usbf_ep0_pio_in()
611 dev_dbg(ep0->udc->dev, "ep0 send %u/%u\n", in usbf_ep0_pio_in()
612 req->req.actual, req->req.length); in usbf_ep0_pio_in()
614 return -EINPROGRESS; in usbf_ep0_pio_in()
627 if (ep0->status & USBF_EP0_OUT_INT) { in usbf_ep0_pio_out()
631 buf = req->req.buf; in usbf_ep0_pio_out()
632 buf += req->req.actual; in usbf_ep0_pio_out()
634 left = req->req.length - req->req.actual; in usbf_ep0_pio_out()
636 dev_dbg(ep0->udc->dev, "ep0 recv %u, left %u\n", count, left); in usbf_ep0_pio_out()
638 if (left > ep0->ep.maxpacket) in usbf_ep0_pio_out()
639 left = ep0->ep.maxpacket; in usbf_ep0_pio_out()
642 req_status = -EOVERFLOW; in usbf_ep0_pio_out()
652 req->req.actual += (nb * sizeof(u32)); in usbf_ep0_pio_out()
653 count -= (nb * sizeof(u32)); in usbf_ep0_pio_out()
658 req->req.actual += count; in usbf_ep0_pio_out()
661 dev_dbg(ep0->udc->dev, "ep0 recv %u/%u\n", in usbf_ep0_pio_out()
662 req->req.actual, req->req.length); in usbf_ep0_pio_out()
665 dev_dbg(ep0->udc->dev, "ep0 req.status=%d\n", req_status); in usbf_ep0_pio_out()
666 req->req.status = req_status; in usbf_ep0_pio_out()
670 if (recv < ep0->ep.maxpacket) { in usbf_ep0_pio_out()
671 dev_dbg(ep0->udc->dev, "ep0 short packet\n"); in usbf_ep0_pio_out()
672 /* This is a short packet -> It is the end */ in usbf_ep0_pio_out()
673 req->req.status = 0; in usbf_ep0_pio_out()
679 * - Has transferred exactly the expected amount of data in usbf_ep0_pio_out()
680 * - Transfers a packet with a payload size less than in usbf_ep0_pio_out()
681 * wMaxPacketSize or transfers a zero-length packet in usbf_ep0_pio_out()
683 if (req->req.actual == req->req.length) { in usbf_ep0_pio_out()
684 req->req.status = 0; in usbf_ep0_pio_out()
689 if (ep0->status & USBF_EP0_OUT_NULL_INT) { in usbf_ep0_pio_out()
691 dev_dbg(ep0->udc->dev, "ep0 null packet\n"); in usbf_ep0_pio_out()
692 if (req->req.actual != req->req.length) { in usbf_ep0_pio_out()
693 req->req.status = req->req.short_not_ok ? in usbf_ep0_pio_out()
694 -EREMOTEIO : 0; in usbf_ep0_pio_out()
696 req->req.status = 0; in usbf_ep0_pio_out()
701 return -EINPROGRESS; in usbf_ep0_pio_out()
711 ret = readl_poll_timeout_atomic(ep0->regs + USBF_REG_EP0_STATUS, sts, in usbf_ep0_fifo_flush()
715 dev_err(ep0->udc->dev, "ep0 flush fifo timed out\n"); in usbf_ep0_fifo_flush()
743 left = req->req.length - req->req.actual; in usbf_epn_pio_in()
746 if (!req->is_zero_sent) { in usbf_epn_pio_in()
747 if (req->req.length == 0) { in usbf_epn_pio_in()
748 dev_dbg(epn->udc->dev, "ep%u send_null\n", epn->id); in usbf_epn_pio_in()
750 req->is_zero_sent = 1; in usbf_epn_pio_in()
751 return -EINPROGRESS; in usbf_epn_pio_in()
753 if ((req->req.actual % epn->ep.maxpacket) == 0) { in usbf_epn_pio_in()
754 if (req->req.zero) { in usbf_epn_pio_in()
755 dev_dbg(epn->udc->dev, "ep%u send_null\n", in usbf_epn_pio_in()
756 epn->id); in usbf_epn_pio_in()
758 req->is_zero_sent = 1; in usbf_epn_pio_in()
759 return -EINPROGRESS; in usbf_epn_pio_in()
766 if (left > epn->ep.maxpacket) in usbf_epn_pio_in()
767 left = epn->ep.maxpacket; in usbf_epn_pio_in()
769 buf = req->req.buf; in usbf_epn_pio_in()
770 buf += req->req.actual; in usbf_epn_pio_in()
776 req->req.actual += (nb * sizeof(u32)); in usbf_epn_pio_in()
777 left -= (nb * sizeof(u32)); in usbf_epn_pio_in()
782 req->req.actual += left; in usbf_epn_pio_in()
789 dev_dbg(epn->udc->dev, "ep%u send %u/%u\n", epn->id, req->req.actual, in usbf_epn_pio_in()
790 req->req.length); in usbf_epn_pio_in()
792 return -EINPROGRESS; in usbf_epn_pio_in()
807 if (!IS_ALIGNED((uintptr_t)req->req.buf, 4)) { in usbf_epn_dma_in()
808 dev_dbg(epn->udc->dev, "ep%u buf unaligned -> fallback pio\n", in usbf_epn_dma_in()
809 epn->id); in usbf_epn_dma_in()
813 left = req->req.length - req->req.actual; in usbf_epn_dma_in()
815 switch (req->xfer_step) { in usbf_epn_dma_in()
819 dev_dbg(epn->udc->dev, "ep%u send null\n", epn->id); in usbf_epn_dma_in()
821 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
825 dev_dbg(epn->udc->dev, "ep%u send residue %u\n", epn->id, in usbf_epn_dma_in()
828 req->req.buf + req->req.actual, left); in usbf_epn_dma_in()
829 req->req.actual += left; in usbf_epn_dma_in()
830 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
834 ret = usb_gadget_map_request(&epn->udc->gadget, &req->req, 1); in usbf_epn_dma_in()
836 dev_err(epn->udc->dev, "usb_gadget_map_request failed (%d)\n", in usbf_epn_dma_in()
840 req->is_mapped = 1; in usbf_epn_dma_in()
842 npkt = DIV_ROUND_UP(left, epn->ep.maxpacket); in usbf_epn_dma_in()
843 lastpkt = (left % epn->ep.maxpacket); in usbf_epn_dma_in()
845 lastpkt = epn->ep.maxpacket; in usbf_epn_dma_in()
849 USBF_SYS_EPN_MPKT(epn->ep.maxpacket) | USBF_SYS_EPN_LMPKT(lastpkt)); in usbf_epn_dma_in()
851 req->req.dma); in usbf_epn_dma_in()
861 /* The end of DMA transfer at the USBF level needs to be handle in usbf_epn_dma_in()
870 epn->bridge_on_dma_end = usbf_epn_enable_in_end_int; in usbf_epn_dma_in()
880 req->dma_size = (npkt - 1) * epn->ep.maxpacket + lastpkt; in usbf_epn_dma_in()
882 dev_dbg(epn->udc->dev, "ep%u dma xfer %zu\n", epn->id, in usbf_epn_dma_in()
883 req->dma_size); in usbf_epn_dma_in()
885 req->xfer_step = USBF_XFER_WAIT_DMA; in usbf_epn_dma_in()
889 if (!(epn->status & USBF_EPN_IN_END_INT)) { in usbf_epn_dma_in()
890 dev_dbg(epn->udc->dev, "ep%u dma not done\n", epn->id); in usbf_epn_dma_in()
893 dev_dbg(epn->udc->dev, "ep%u dma done\n", epn->id); in usbf_epn_dma_in()
895 usb_gadget_unmap_request(&epn->udc->gadget, &req->req, 1); in usbf_epn_dma_in()
896 req->is_mapped = 0; in usbf_epn_dma_in()
904 req->req.actual += req->dma_size; in usbf_epn_dma_in()
906 left = req->req.length - req->req.actual; in usbf_epn_dma_in()
910 dev_dbg(epn->udc->dev, "ep%u send residue %u\n", epn->id, in usbf_epn_dma_in()
913 req->req.buf + req->req.actual, left); in usbf_epn_dma_in()
914 req->req.actual += left; in usbf_epn_dma_in()
915 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
919 if (req->req.actual % epn->ep.maxpacket) { in usbf_epn_dma_in()
923 dev_dbg(epn->udc->dev, "ep%u send short\n", epn->id); in usbf_epn_dma_in()
929 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
936 if (req->req.zero) { in usbf_epn_dma_in()
937 req->xfer_step = USBF_XFER_SEND_NULL; in usbf_epn_dma_in()
942 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
946 dev_dbg(epn->udc->dev, "ep%u send null\n", epn->id); in usbf_epn_dma_in()
948 req->xfer_step = USBF_XFER_WAIT_END; in usbf_epn_dma_in()
952 if (!(epn->status & USBF_EPN_IN_INT)) { in usbf_epn_dma_in()
953 dev_dbg(epn->udc->dev, "ep%u end not done\n", epn->id); in usbf_epn_dma_in()
956 dev_dbg(epn->udc->dev, "ep%u send done %u/%u\n", epn->id, in usbf_epn_dma_in()
957 req->req.actual, req->req.length); in usbf_epn_dma_in()
958 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_in()
962 return -EINPROGRESS; in usbf_epn_dma_in()
983 if (epn->status & USBF_EPN_OUT_INT) { in usbf_epn_pio_out()
988 buf = req->req.buf; in usbf_epn_pio_out()
989 buf += req->req.actual; in usbf_epn_pio_out()
991 left = req->req.length - req->req.actual; in usbf_epn_pio_out()
993 dev_dbg(epn->udc->dev, "ep%u recv %u, left %u, mpkt %u\n", epn->id, in usbf_epn_pio_out()
994 recv, left, epn->ep.maxpacket); in usbf_epn_pio_out()
996 if (left > epn->ep.maxpacket) in usbf_epn_pio_out()
997 left = epn->ep.maxpacket; in usbf_epn_pio_out()
1000 req_status = -EOVERFLOW; in usbf_epn_pio_out()
1010 req->req.actual += (nb * sizeof(u32)); in usbf_epn_pio_out()
1011 count -= (nb * sizeof(u32)); in usbf_epn_pio_out()
1015 req->req.actual += count; in usbf_epn_pio_out()
1018 dev_dbg(epn->udc->dev, "ep%u recv %u/%u\n", epn->id, in usbf_epn_pio_out()
1019 req->req.actual, req->req.length); in usbf_epn_pio_out()
1022 dev_dbg(epn->udc->dev, "ep%u req.status=%d\n", epn->id, in usbf_epn_pio_out()
1024 req->req.status = req_status; in usbf_epn_pio_out()
1028 if (recv < epn->ep.maxpacket) { in usbf_epn_pio_out()
1029 dev_dbg(epn->udc->dev, "ep%u short packet\n", epn->id); in usbf_epn_pio_out()
1030 /* This is a short packet -> It is the end */ in usbf_epn_pio_out()
1031 req->req.status = 0; in usbf_epn_pio_out()
1035 /* Request full -> complete */ in usbf_epn_pio_out()
1036 if (req->req.actual == req->req.length) { in usbf_epn_pio_out()
1037 req->req.status = 0; in usbf_epn_pio_out()
1042 if (epn->status & USBF_EPN_OUT_NULL_INT) { in usbf_epn_pio_out()
1044 dev_dbg(epn->udc->dev, "ep%u null packet\n", epn->id); in usbf_epn_pio_out()
1045 if (req->req.actual != req->req.length) { in usbf_epn_pio_out()
1046 req->req.status = req->req.short_not_ok ? in usbf_epn_pio_out()
1047 -EREMOTEIO : 0; in usbf_epn_pio_out()
1049 req->req.status = 0; in usbf_epn_pio_out()
1054 return -EINPROGRESS; in usbf_epn_pio_out()
1066 usbf_ep_dma_reg_writel(epn, USBF_REG_DMA_EPN_DCR2, USBF_SYS_EPN_MPKT(epn->ep.maxpacket)); in usbf_epn_dma_out_send_dma()
1078 /* The end of DMA transfer at the USBF level needs to be handled in usbf_epn_dma_out_send_dma()
1087 epn->bridge_on_dma_end = usbf_epn_enable_out_end_int; in usbf_epn_dma_out_send_dma()
1118 usbf_reg_bitclr(epn->udc, USBF_REG_AHBBINTEN, in usbf_epn_dma_out_send_dma()
1119 USBF_SYS_DMA_ENDINTEN_EPN(epn->id)); in usbf_epn_dma_out_send_dma()
1122 usbf_reg_writel(epn->udc, USBF_REG_AHBBINT, in usbf_epn_dma_out_send_dma()
1123 USBF_SYS_DMA_ENDINT_EPN(epn->id)); in usbf_epn_dma_out_send_dma()
1152 usbf_reg_bitset(epn->udc, USBF_REG_AHBBINTEN, in usbf_epn_dma_out_complete_dma()
1153 USBF_SYS_DMA_ENDINTEN_EPN(epn->id)); in usbf_epn_dma_out_complete_dma()
1165 epn->dma_regs + USBF_REG_DMA_EPN_DCR1, in usbf_epn_dma_out_complete_dma()
1169 dev_err(epn->udc->dev, "ep%u wait bridge timed out\n", in usbf_epn_dma_out_complete_dma()
1170 epn->id); in usbf_epn_dma_out_complete_dma()
1180 return dmacnt * epn->ep.maxpacket; in usbf_epn_dma_out_complete_dma()
1195 if (!IS_ALIGNED((uintptr_t)req->req.buf, 4)) { in usbf_epn_dma_out()
1196 dev_dbg(epn->udc->dev, "ep%u buf unaligned -> fallback pio\n", in usbf_epn_dma_out()
1197 epn->id); in usbf_epn_dma_out()
1201 switch (req->xfer_step) { in usbf_epn_dma_out()
1204 if (epn->status & USBF_EPN_OUT_NULL_INT) { in usbf_epn_dma_out()
1205 dev_dbg(epn->udc->dev, "ep%u null packet\n", epn->id); in usbf_epn_dma_out()
1206 if (req->req.actual != req->req.length) { in usbf_epn_dma_out()
1207 req->req.status = req->req.short_not_ok ? in usbf_epn_dma_out()
1208 -EREMOTEIO : 0; in usbf_epn_dma_out()
1210 req->req.status = 0; in usbf_epn_dma_out()
1215 if (!(epn->status & USBF_EPN_OUT_INT)) { in usbf_epn_dma_out()
1216 dev_dbg(epn->udc->dev, "ep%u OUT_INT not set -> spurious\n", in usbf_epn_dma_out()
1217 epn->id); in usbf_epn_dma_out()
1224 dev_dbg(epn->udc->dev, "ep%u recv = 0 -> spurious\n", in usbf_epn_dma_out()
1225 epn->id); in usbf_epn_dma_out()
1229 left = req->req.length - req->req.actual; in usbf_epn_dma_out()
1231 dev_dbg(epn->udc->dev, "ep%u recv %u, left %u, mpkt %u\n", epn->id, in usbf_epn_dma_out()
1232 recv, left, epn->ep.maxpacket); in usbf_epn_dma_out()
1235 dev_err(epn->udc->dev, "ep%u overflow (%u/%u)\n", in usbf_epn_dma_out()
1236 epn->id, recv, left); in usbf_epn_dma_out()
1237 req->req.status = -EOVERFLOW; in usbf_epn_dma_out()
1238 return -EOVERFLOW; in usbf_epn_dma_out()
1241 if (recv < epn->ep.maxpacket) { in usbf_epn_dma_out()
1243 dev_dbg(epn->udc->dev, "ep%u short packet\n", epn->id); in usbf_epn_dma_out()
1246 req->req.buf + req->req.actual, recv); in usbf_epn_dma_out()
1247 req->req.actual += recv; in usbf_epn_dma_out()
1249 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u\n", in usbf_epn_dma_out()
1250 epn->id, req->req.actual, req->req.length); in usbf_epn_dma_out()
1252 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1256 ret = usb_gadget_map_request(&epn->udc->gadget, &req->req, 0); in usbf_epn_dma_out()
1258 dev_err(epn->udc->dev, "map request failed (%d)\n", in usbf_epn_dma_out()
1262 req->is_mapped = 1; in usbf_epn_dma_out()
1265 req->req.dma + req->req.actual, in usbf_epn_dma_out()
1267 req->dma_size = recv & ~0x3; in usbf_epn_dma_out()
1269 dev_dbg(epn->udc->dev, "ep%u dma short xfer %zu\n", epn->id, in usbf_epn_dma_out()
1270 req->dma_size); in usbf_epn_dma_out()
1272 req->xfer_step = USBF_XFER_WAIT_DMA_SHORT; in usbf_epn_dma_out()
1276 ret = usb_gadget_map_request(&epn->udc->gadget, &req->req, 0); in usbf_epn_dma_out()
1278 dev_err(epn->udc->dev, "map request failed (%d)\n", in usbf_epn_dma_out()
1282 req->is_mapped = 1; in usbf_epn_dma_out()
1289 npkt = left / epn->ep.maxpacket; in usbf_epn_dma_out()
1291 req->req.dma + req->req.actual, in usbf_epn_dma_out()
1293 req->dma_size = npkt * epn->ep.maxpacket; in usbf_epn_dma_out()
1295 dev_dbg(epn->udc->dev, "ep%u dma xfer %zu (%u)\n", epn->id, in usbf_epn_dma_out()
1296 req->dma_size, npkt); in usbf_epn_dma_out()
1298 req->xfer_step = USBF_XFER_WAIT_DMA; in usbf_epn_dma_out()
1302 if (!(epn->status & USBF_EPN_OUT_END_INT)) { in usbf_epn_dma_out()
1303 dev_dbg(epn->udc->dev, "ep%u dma short not done\n", epn->id); in usbf_epn_dma_out()
1306 dev_dbg(epn->udc->dev, "ep%u dma short done\n", epn->id); in usbf_epn_dma_out()
1310 usb_gadget_unmap_request(&epn->udc->gadget, &req->req, 0); in usbf_epn_dma_out()
1311 req->is_mapped = 0; in usbf_epn_dma_out()
1313 req->req.actual += req->dma_size; in usbf_epn_dma_out()
1320 dev_dbg(epn->udc->dev, "ep%u recv residue %u\n", epn->id, in usbf_epn_dma_out()
1323 req->req.buf + req->req.actual, count); in usbf_epn_dma_out()
1324 req->req.actual += count; in usbf_epn_dma_out()
1327 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u\n", epn->id, in usbf_epn_dma_out()
1328 req->req.actual, req->req.length); in usbf_epn_dma_out()
1330 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1334 if (!(epn->status & USBF_EPN_OUT_END_INT)) { in usbf_epn_dma_out()
1335 dev_dbg(epn->udc->dev, "ep%u dma not done\n", epn->id); in usbf_epn_dma_out()
1338 dev_dbg(epn->udc->dev, "ep%u dma done\n", epn->id); in usbf_epn_dma_out()
1343 count = req->dma_size - dma_left; in usbf_epn_dma_out()
1345 dev_dbg(epn->udc->dev, "ep%u dma xfer done %u\n", epn->id, in usbf_epn_dma_out()
1348 req->req.actual += count; in usbf_epn_dma_out()
1350 if (epn->status & USBF_EPN_OUT_NULL_INT) { in usbf_epn_dma_out()
1352 dev_dbg(epn->udc->dev, "ep%u dma stopped by null pckt\n", in usbf_epn_dma_out()
1353 epn->id); in usbf_epn_dma_out()
1354 usb_gadget_unmap_request(&epn->udc->gadget, in usbf_epn_dma_out()
1355 &req->req, 0); in usbf_epn_dma_out()
1356 req->is_mapped = 0; in usbf_epn_dma_out()
1361 if (req->req.actual != req->req.length) { in usbf_epn_dma_out()
1362 req->req.status = req->req.short_not_ok ? in usbf_epn_dma_out()
1363 -EREMOTEIO : 0; in usbf_epn_dma_out()
1365 req->req.status = 0; in usbf_epn_dma_out()
1367 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u\n", in usbf_epn_dma_out()
1368 epn->id, req->req.actual, req->req.length); in usbf_epn_dma_out()
1369 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1375 left = req->req.length - req->req.actual; in usbf_epn_dma_out()
1377 dev_err(epn->udc->dev, in usbf_epn_dma_out()
1378 "ep%u overflow (%u/%u)\n", epn->id, in usbf_epn_dma_out()
1380 req->req.status = -EOVERFLOW; in usbf_epn_dma_out()
1381 usb_gadget_unmap_request(&epn->udc->gadget, in usbf_epn_dma_out()
1382 &req->req, 0); in usbf_epn_dma_out()
1383 req->is_mapped = 0; in usbf_epn_dma_out()
1385 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1386 return -EOVERFLOW; in usbf_epn_dma_out()
1391 req->req.dma + req->req.actual, in usbf_epn_dma_out()
1393 req->dma_size = recv & ~0x3; in usbf_epn_dma_out()
1395 dev_dbg(epn->udc->dev, "ep%u dma short xfer %zu\n", in usbf_epn_dma_out()
1396 epn->id, req->dma_size); in usbf_epn_dma_out()
1398 req->xfer_step = USBF_XFER_WAIT_DMA_SHORT; in usbf_epn_dma_out()
1402 usb_gadget_unmap_request(&epn->udc->gadget, &req->req, 0); in usbf_epn_dma_out()
1403 req->is_mapped = 0; in usbf_epn_dma_out()
1407 dev_dbg(epn->udc->dev, "ep%u recv residue %u\n", in usbf_epn_dma_out()
1408 epn->id, count); in usbf_epn_dma_out()
1410 req->req.buf + req->req.actual, count); in usbf_epn_dma_out()
1411 req->req.actual += count; in usbf_epn_dma_out()
1414 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u\n", epn->id, in usbf_epn_dma_out()
1415 req->req.actual, req->req.length); in usbf_epn_dma_out()
1417 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1424 epn->status = 0; in usbf_epn_dma_out()
1425 epn->bridge_on_dma_end = usbf_epn_process_queue; in usbf_epn_dma_out()
1427 req->xfer_step = USBF_XFER_WAIT_BRIDGE; in usbf_epn_dma_out()
1431 dev_dbg(epn->udc->dev, "ep%u bridge transfers done\n", epn->id); in usbf_epn_dma_out()
1438 usb_gadget_unmap_request(&epn->udc->gadget, &req->req, 0); in usbf_epn_dma_out()
1439 req->is_mapped = 0; in usbf_epn_dma_out()
1441 req->req.actual += req->dma_size; in usbf_epn_dma_out()
1443 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_out()
1444 left = req->req.length - req->req.actual; in usbf_epn_dma_out()
1447 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u\n", epn->id, in usbf_epn_dma_out()
1448 req->req.actual, req->req.length); in usbf_epn_dma_out()
1451 dev_dbg(epn->udc->dev, "ep%u recv done %u/%u, wait more data\n", in usbf_epn_dma_out()
1452 epn->id, req->req.actual, req->req.length); in usbf_epn_dma_out()
1456 return -EINPROGRESS; in usbf_epn_dma_out()
1464 * If EP[m]_REQEN = 0b is set during DMA transfer, AHB-EPC stops DMA in usbf_epn_dma_stop()
1478 dev_dbg(epn->udc->dev, "ep%u %s dma abort\n", epn->id, in usbf_epn_dma_abort()
1479 epn->is_in ? "in" : "out"); in usbf_epn_dma_abort()
1481 epn->bridge_on_dma_end = NULL; in usbf_epn_dma_abort()
1485 usb_gadget_unmap_request(&epn->udc->gadget, &req->req, in usbf_epn_dma_abort()
1486 epn->is_in ? 1 : 0); in usbf_epn_dma_abort()
1487 req->is_mapped = 0; in usbf_epn_dma_abort()
1491 if (epn->is_in) { in usbf_epn_dma_abort()
1505 usbf_reg_writel(epn->udc, USBF_REG_AHBBINT, USBF_SYS_DMA_ENDINT_EPN(epn->id)); in usbf_epn_dma_abort()
1508 usbf_reg_bitset(epn->udc, USBF_REG_AHBBINTEN, in usbf_epn_dma_abort()
1509 USBF_SYS_DMA_ENDINTEN_EPN(epn->id)); in usbf_epn_dma_abort()
1512 req->xfer_step = USBF_XFER_START; in usbf_epn_dma_abort()
1521 dev_dbg(epn->udc->dev, "ep%u %s fifo flush\n", epn->id, in usbf_epn_fifo_flush()
1522 epn->is_in ? "in" : "out"); in usbf_epn_fifo_flush()
1530 ret = readl_poll_timeout_atomic(epn->regs + USBF_REG_EPN_STATUS, sts, in usbf_epn_fifo_flush()
1534 dev_err(epn->udc->dev, "ep%u flush fifo timed out\n", epn->id); in usbf_epn_fifo_flush()
1540 list_del_init(&req->queue); in usbf_ep_req_done()
1543 req->req.status = status; in usbf_ep_req_done()
1545 if (req->req.status == -EINPROGRESS) in usbf_ep_req_done()
1546 req->req.status = status; in usbf_ep_req_done()
1549 dev_dbg(ep->udc->dev, "ep%u %s req done length %u/%u, status=%d\n", ep->id, in usbf_ep_req_done()
1550 ep->is_in ? "in" : "out", in usbf_ep_req_done()
1551 req->req.actual, req->req.length, req->req.status); in usbf_ep_req_done()
1553 if (req->is_mapped) in usbf_ep_req_done()
1556 spin_unlock(&ep->udc->lock); in usbf_ep_req_done()
1557 usb_gadget_giveback_request(&ep->ep, &req->req); in usbf_ep_req_done()
1558 spin_lock(&ep->udc->lock); in usbf_ep_req_done()
1565 dev_dbg(ep->udc->dev, "ep%u %s nuke status %d\n", ep->id, in usbf_ep_nuke()
1566 ep->is_in ? "in" : "out", in usbf_ep_nuke()
1569 while (!list_empty(&ep->queue)) { in usbf_ep_nuke()
1570 req = list_first_entry(&ep->queue, struct usbf_req, queue); in usbf_ep_nuke()
1574 if (ep->id == 0) in usbf_ep_nuke()
1584 if (ep->id == 0) { in usbf_ep_is_stalled()
1590 if (ep->is_in) in usbf_ep_is_stalled()
1604 req = list_first_entry_or_null(&epn->queue, struct usbf_req, queue); in usbf_epn_start_queue()
1606 if (epn->is_in) { in usbf_epn_start_queue()
1607 if (req && !epn->is_processing) { in usbf_epn_start_queue()
1608 ret = epn->dma_regs ? in usbf_epn_start_queue()
1611 if (ret != -EINPROGRESS) { in usbf_epn_start_queue()
1612 dev_err(epn->udc->dev, in usbf_epn_start_queue()
1618 return ret ? ret : -EIO; in usbf_epn_start_queue()
1650 if (ep->is_in) { in usbf_ep_process_queue()
1652 if (ep->id) { in usbf_ep_process_queue()
1653 usbf_ep_xfer = ep->dma_regs ? in usbf_ep_process_queue()
1658 if (ep->id) { in usbf_ep_process_queue()
1659 usbf_ep_xfer = ep->dma_regs ? in usbf_ep_process_queue()
1664 req = list_first_entry_or_null(&ep->queue, struct usbf_req, queue); in usbf_ep_process_queue()
1666 dev_err(ep->udc->dev, in usbf_ep_process_queue()
1667 "no request available for ep%u %s process\n", ep->id, in usbf_ep_process_queue()
1668 ep->is_in ? "in" : "out"); in usbf_ep_process_queue()
1669 return -ENOENT; in usbf_ep_process_queue()
1677 if (!ep->is_in && ep->id != 0) { in usbf_ep_process_queue()
1683 if (ret == -EINPROGRESS) { in usbf_ep_process_queue()
1684 if (!ep->is_in && ep->id != 0) { in usbf_ep_process_queue()
1694 is_processing = ep->is_processing; in usbf_ep_process_queue()
1695 ep->is_processing = 1; in usbf_ep_process_queue()
1697 ep->is_processing = is_processing; in usbf_ep_process_queue()
1705 if (ep->id == 0) in usbf_ep_process_queue()
1711 req = list_first_entry_or_null(&ep->queue, struct usbf_req, in usbf_ep_process_queue()
1714 if (ep->is_in) in usbf_ep_process_queue()
1717 if (ep->id != 0) { in usbf_ep_process_queue()
1733 return req ? -EINPROGRESS : 0; in usbf_ep_process_queue()
1744 dev_dbg(ep->udc->dev, "ep%u %s %s\n", ep->id, in usbf_ep_stall()
1745 ep->is_in ? "in" : "out", in usbf_ep_stall()
1748 if (ep->id == 0) { in usbf_ep_stall()
1757 if (ep->is_in) in usbf_ep_stall()
1764 first = list_first_entry_or_null(&ep->queue, struct usbf_req, queue); in usbf_ep_stall()
1765 if (first && first->is_mapped) { in usbf_ep_stall()
1767 * SET_FEATURE and then un-halts the endpoint in usbf_ep_stall()
1772 if (ep->is_in) { in usbf_ep_stall()
1793 ep0->udc->ep0state = EP0_IDLE; in usbf_ep0_enable()
1794 ep0->disabled = 0; in usbf_ep0_enable()
1797 usbf_reg_bitset(ep0->udc, USBF_REG_USB_INT_ENA, USBF_USB_EPN_EN(0)); in usbf_ep0_enable()
1805 base_addr = usbf_ep_info[epn->id].base_addr; in usbf_epn_enable()
1807 USBF_EPN_BASEAD(base_addr) | USBF_EPN_MPKT(epn->ep.maxpacket)); in usbf_epn_enable()
1810 if (epn->is_in) { in usbf_epn_enable()
1819 if (epn->is_in) in usbf_epn_enable()
1832 struct usbf_udc *udc = ep->udc; in usbf_ep_enable()
1836 if (ep->id == 0) in usbf_ep_enable()
1837 return -EINVAL; in usbf_ep_enable()
1839 if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) in usbf_ep_enable()
1840 return -EINVAL; in usbf_ep_enable()
1842 dev_dbg(ep->udc->dev, "ep%u %s mpkts %d\n", ep->id, in usbf_ep_enable()
1846 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_enable()
1847 ep->is_in = usb_endpoint_dir_in(desc); in usbf_ep_enable()
1848 ep->ep.maxpacket = usb_endpoint_maxp(desc); in usbf_ep_enable()
1854 ep->disabled = 0; in usbf_ep_enable()
1857 usbf_reg_bitset(udc, USBF_REG_USB_INT_ENA, USBF_USB_EPN_EN(ep->id)); in usbf_ep_enable()
1860 if (ep->dma_regs) { in usbf_ep_enable()
1861 ep->bridge_on_dma_end = NULL; in usbf_ep_enable()
1863 USBF_SYS_DMA_ENDINTEN_EPN(ep->id)); in usbf_ep_enable()
1868 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_enable()
1881 usbf_ep_nuke(epn, -ESHUTDOWN); in usbf_epn_disable()
1889 struct usbf_udc *udc = ep->udc; in usbf_ep_disable()
1893 if (ep->id == 0) in usbf_ep_disable()
1894 return -EINVAL; in usbf_ep_disable()
1896 dev_dbg(ep->udc->dev, "ep%u %s mpkts %d\n", ep->id, in usbf_ep_disable()
1897 ep->is_in ? "in" : "out", ep->ep.maxpacket); in usbf_ep_disable()
1899 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_disable()
1900 ep->disabled = 1; in usbf_ep_disable()
1902 if (ep->dma_regs) { in usbf_ep_disable()
1904 USBF_SYS_DMA_ENDINTEN_EPN(ep->id)); in usbf_ep_disable()
1905 ep->bridge_on_dma_end = NULL; in usbf_ep_disable()
1908 usbf_reg_bitclr(udc, USBF_REG_USB_INT_ENA, USBF_USB_EPN_EN(ep->id)); in usbf_ep_disable()
1911 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_disable()
1921 req->req.actual = 0; in usbf_ep0_queue()
1922 req->req.status = -EINPROGRESS; in usbf_ep0_queue()
1923 req->is_zero_sent = 0; in usbf_ep0_queue()
1925 list_add_tail(&req->queue, &ep0->queue); in usbf_ep0_queue()
1927 if (ep0->udc->ep0state == EP0_IN_STATUS_START_PHASE) in usbf_ep0_queue()
1930 if (!ep0->is_in) in usbf_ep0_queue()
1933 if (ep0->udc->ep0state == EP0_IN_STATUS_PHASE) { in usbf_ep0_queue()
1934 if (req->req.length) { in usbf_ep0_queue()
1935 dev_err(ep0->udc->dev, in usbf_ep0_queue()
1937 req->req.length); in usbf_ep0_queue()
1938 return -EINVAL; in usbf_ep0_queue()
1940 ep0->delayed_status = 0; in usbf_ep0_queue()
1942 if (!ep0->is_processing) { in usbf_ep0_queue()
1944 if (ret != -EINPROGRESS) { in usbf_ep0_queue()
1945 dev_err(ep0->udc->dev, in usbf_ep0_queue()
1950 return ret ? ret : -EIO; in usbf_ep0_queue()
1963 if (ep->disabled) { in usbf_epn_queue()
1964 dev_err(ep->udc->dev, "ep%u request queue while disable\n", in usbf_epn_queue()
1965 ep->id); in usbf_epn_queue()
1966 return -ESHUTDOWN; in usbf_epn_queue()
1969 req->req.actual = 0; in usbf_epn_queue()
1970 req->req.status = -EINPROGRESS; in usbf_epn_queue()
1971 req->is_zero_sent = 0; in usbf_epn_queue()
1972 req->xfer_step = USBF_XFER_START; in usbf_epn_queue()
1974 was_empty = list_empty(&ep->queue); in usbf_epn_queue()
1975 list_add_tail(&req->queue, &ep->queue); in usbf_epn_queue()
1989 struct usbf_udc *udc = ep->udc; in usbf_ep_queue()
1993 if (!_req || !_req->buf) in usbf_ep_queue()
1994 return -EINVAL; in usbf_ep_queue()
1996 if (!udc || !udc->driver) in usbf_ep_queue()
1997 return -EINVAL; in usbf_ep_queue()
1999 dev_dbg(ep->udc->dev, "ep%u %s req queue length %u, zero %u, short_not_ok %u\n", in usbf_ep_queue()
2000 ep->id, ep->is_in ? "in" : "out", in usbf_ep_queue()
2001 req->req.length, req->req.zero, req->req.short_not_ok); in usbf_ep_queue()
2003 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_queue()
2004 if (ep->id == 0) in usbf_ep_queue()
2008 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_queue()
2021 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_dequeue()
2023 dev_dbg(ep->udc->dev, "ep%u %s req dequeue length %u/%u\n", in usbf_ep_dequeue()
2024 ep->id, ep->is_in ? "in" : "out", in usbf_ep_dequeue()
2025 req->req.actual, req->req.length); in usbf_ep_dequeue()
2027 first = list_is_first(&req->queue, &ep->queue); in usbf_ep_dequeue()
2032 is_processing = ep->is_processing; in usbf_ep_dequeue()
2033 ep->is_processing = 1; in usbf_ep_dequeue()
2034 usbf_ep_req_done(ep, req, -ECONNRESET); in usbf_ep_dequeue()
2035 ep->is_processing = is_processing; in usbf_ep_dequeue()
2042 if (ep->id) in usbf_ep_dequeue()
2048 if (ep->id == 0) { in usbf_ep_dequeue()
2058 usbf_ep_nuke(ep, -ECONNRESET); in usbf_ep_dequeue()
2059 ep->udc->ep0state = EP0_IDLE; in usbf_ep_dequeue()
2069 usbf_ep_nuke(ep, -EIO); in usbf_ep_dequeue()
2072 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_dequeue()
2088 INIT_LIST_HEAD(&req->queue); in usbf_ep_alloc_request()
2090 return &req->req; in usbf_ep_alloc_request()
2105 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_free_request()
2106 list_del_init(&req->queue); in usbf_ep_free_request()
2107 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_free_request()
2117 if (ep->id == 0) in usbf_ep_set_halt()
2118 return -EINVAL; in usbf_ep_set_halt()
2120 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_set_halt()
2122 if (!list_empty(&ep->queue)) { in usbf_ep_set_halt()
2123 ret = -EAGAIN; in usbf_ep_set_halt()
2129 ep->is_wedged = 0; in usbf_ep_set_halt()
2133 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_set_halt()
2144 if (ep->id == 0) in usbf_ep_set_wedge()
2145 return -EINVAL; in usbf_ep_set_wedge()
2147 spin_lock_irqsave(&ep->udc->lock, flags); in usbf_ep_set_wedge()
2148 if (!list_empty(&ep->queue)) { in usbf_ep_set_wedge()
2149 ret = -EAGAIN; in usbf_ep_set_wedge()
2153 ep->is_wedged = 1; in usbf_ep_set_wedge()
2157 spin_unlock_irqrestore(&ep->udc->lock, flags); in usbf_ep_set_wedge()
2182 memcpy(ep0->udc->ep0_buf, buf, length); in usbf_ep0_fill_req()
2184 req->req.buf = ep0->udc->ep0_buf; in usbf_ep0_fill_req()
2185 req->req.length = length; in usbf_ep0_fill_req()
2186 req->req.dma = 0; in usbf_ep0_fill_req()
2187 req->req.zero = true; in usbf_ep0_fill_req()
2188 req->req.complete = complete ? complete : usbf_ep0_req_complete; in usbf_ep0_fill_req()
2189 req->req.status = -EINPROGRESS; in usbf_ep0_fill_req()
2190 req->req.context = NULL; in usbf_ep0_fill_req()
2191 req->req.actual = 0; in usbf_ep0_fill_req()
2200 return &udc->ep[0]; in usbf_get_ep_by_addr()
2202 for (i = 1; i < ARRAY_SIZE(udc->ep); i++) { in usbf_get_ep_by_addr()
2203 ep = &udc->ep[i]; in usbf_get_ep_by_addr()
2205 if (!ep->ep.desc) in usbf_get_ep_by_addr()
2208 if (ep->ep.desc->bEndpointAddress == address) in usbf_get_ep_by_addr()
2220 spin_unlock(&udc->lock); in usbf_req_delegate()
2221 ret = udc->driver->setup(&udc->gadget, ctrlrequest); in usbf_req_delegate()
2222 spin_lock(&udc->lock); in usbf_req_delegate()
2224 dev_dbg(udc->dev, "udc driver setup failed %d\n", ret); in usbf_req_delegate()
2228 dev_dbg(udc->dev, "delayed status set\n"); in usbf_req_delegate()
2229 udc->ep[0].delayed_status = 1; in usbf_req_delegate()
2244 wValue = le16_to_cpu(ctrlrequest->wValue); in usbf_req_get_status()
2245 wLength = le16_to_cpu(ctrlrequest->wLength); in usbf_req_get_status()
2246 wIndex = le16_to_cpu(ctrlrequest->wIndex); in usbf_req_get_status()
2248 switch (ctrlrequest->bRequestType) { in usbf_req_get_status()
2254 if (udc->gadget.is_selfpowered) in usbf_req_get_status()
2257 if (udc->is_remote_wakeup) in usbf_req_get_status()
2268 return -EINVAL; in usbf_req_get_status()
2285 usbf_ep0_fill_req(&udc->ep[0], &udc->setup_reply, &status_data, in usbf_req_get_status()
2287 usbf_ep0_queue(&udc->ep[0], &udc->setup_reply, GFP_ATOMIC); in usbf_req_get_status()
2304 wValue = le16_to_cpu(ctrlrequest->wValue); in usbf_req_clear_set_feature()
2305 wLength = le16_to_cpu(ctrlrequest->wLength); in usbf_req_clear_set_feature()
2306 wIndex = le16_to_cpu(ctrlrequest->wIndex); in usbf_req_clear_set_feature()
2308 switch (ctrlrequest->bRequestType) { in usbf_req_clear_set_feature()
2316 udc->is_remote_wakeup = is_set; in usbf_req_clear_set_feature()
2325 return -EINVAL; in usbf_req_clear_set_feature()
2327 if ((ep->id == 0) && is_set) { in usbf_req_clear_set_feature()
2332 return -EINVAL; in usbf_req_clear_set_feature()
2334 if (ep->is_wedged && !is_set) { in usbf_req_clear_set_feature()
2359 if (_req->status == 0) { in usbf_ep0_req_set_address_complete()
2360 /* ... without any errors -> Signaled the state to the core. */ in usbf_ep0_req_set_address_complete()
2361 usb_gadget_set_state(&ep->udc->gadget, USB_STATE_ADDRESS); in usbf_ep0_req_set_address_complete()
2378 wValue = le16_to_cpu(ctrlrequest->wValue); in usbf_req_set_address()
2379 wLength = le16_to_cpu(ctrlrequest->wLength); in usbf_req_set_address()
2380 wIndex = le16_to_cpu(ctrlrequest->wIndex); in usbf_req_set_address()
2382 if (ctrlrequest->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) in usbf_req_set_address()
2386 return -EINVAL; in usbf_req_set_address()
2396 usbf_ep0_fill_req(&udc->ep[0], &udc->setup_reply, NULL, 0, in usbf_req_set_address()
2398 usbf_ep0_queue(&udc->ep[0], &udc->setup_reply, GFP_ATOMIC); in usbf_req_set_address()
2418 wValue = le16_to_cpu(ctrlrequest->wValue); in usbf_req_set_configuration()
2419 wLength = le16_to_cpu(ctrlrequest->wLength); in usbf_req_set_configuration()
2420 wIndex = le16_to_cpu(ctrlrequest->wIndex); in usbf_req_set_configuration()
2422 if ((ctrlrequest->bRequestType != (USB_DIR_OUT | USB_RECIP_DEVICE)) || in usbf_req_set_configuration()
2424 /* No error detected by driver->setup() but it is not an USB2.0 in usbf_req_set_configuration()
2436 spin_unlock(&udc->lock); in usbf_req_set_configuration()
2437 usb_gadget_set_state(&udc->gadget, USB_STATE_ADDRESS); in usbf_req_set_configuration()
2438 spin_lock(&udc->lock); in usbf_req_set_configuration()
2450 struct usbf_udc *udc = ep0->udc; in usbf_handle_ep0_setup()
2457 dev_dbg(ep0->udc->dev, in usbf_handle_ep0_setup()
2465 udc->ep0state = EP0_IN_DATA_PHASE; in usbf_handle_ep0_setup()
2469 ep0->is_in = 1; in usbf_handle_ep0_setup()
2471 udc->ep0state = EP0_OUT_DATA_PHASE; in usbf_handle_ep0_setup()
2474 ep0->is_in = 0; in usbf_handle_ep0_setup()
2477 udc->ep0state = EP0_IN_STATUS_START_PHASE; in usbf_handle_ep0_setup()
2478 ep0->is_in = 1; in usbf_handle_ep0_setup()
2481 /* We starts a new control transfer -> Clear the delayed status flag */ in usbf_handle_ep0_setup()
2482 ep0->delayed_status = 0; in usbf_handle_ep0_setup()
2485 /* This is not a USB standard request -> delelate */ in usbf_handle_ep0_setup()
2524 struct usbf_udc *udc = ep0->udc; in usbf_handle_ep0_data_status()
2529 case -ENOENT: in usbf_handle_ep0_data_status()
2530 dev_err(udc->dev, in usbf_handle_ep0_data_status()
2534 case -EINPROGRESS: in usbf_handle_ep0_data_status()
2540 udc->ep0state = next_ep0state; in usbf_handle_ep0_data_status()
2543 dev_err(udc->dev, in usbf_handle_ep0_data_status()
2553 struct usbf_udc *udc = ep0->udc; in usbf_handle_ep0_out_status_start()
2559 ep0->is_in = 0; in usbf_handle_ep0_out_status_start()
2561 req = list_first_entry_or_null(&ep0->queue, struct usbf_req, queue); in usbf_handle_ep0_out_status_start()
2563 usbf_ep0_fill_req(ep0, &udc->setup_reply, NULL, 0, NULL); in usbf_handle_ep0_out_status_start()
2564 usbf_ep0_queue(ep0, &udc->setup_reply, GFP_ATOMIC); in usbf_handle_ep0_out_status_start()
2566 if (req->req.length) { in usbf_handle_ep0_out_status_start()
2567 dev_err(udc->dev, in usbf_handle_ep0_out_status_start()
2569 req->req.length); in usbf_handle_ep0_out_status_start()
2572 udc->ep0state = EP0_OUT_STATUS_PHASE; in usbf_handle_ep0_out_status_start()
2578 struct usbf_udc *udc = ep0->udc; in usbf_handle_ep0_in_status_start()
2585 ep0->is_in = 1; in usbf_handle_ep0_in_status_start()
2588 req = list_first_entry_or_null(&ep0->queue, struct usbf_req, queue); in usbf_handle_ep0_in_status_start()
2590 if (ep0->delayed_status) { in usbf_handle_ep0_in_status_start()
2591 dev_dbg(ep0->udc->dev, in usbf_handle_ep0_in_status_start()
2592 "EP0_IN_STATUS_START_PHASE ep0->delayed_status set\n"); in usbf_handle_ep0_in_status_start()
2593 udc->ep0state = EP0_IN_STATUS_PHASE; in usbf_handle_ep0_in_status_start()
2597 usbf_ep0_fill_req(ep0, &udc->setup_reply, NULL, in usbf_handle_ep0_in_status_start()
2599 usbf_ep0_queue(ep0, &udc->setup_reply, in usbf_handle_ep0_in_status_start()
2602 req = list_first_entry_or_null(&ep0->queue, struct usbf_req, queue); in usbf_handle_ep0_in_status_start()
2604 if (req->req.length) { in usbf_handle_ep0_in_status_start()
2605 dev_err(udc->dev, in usbf_handle_ep0_in_status_start()
2607 req->req.length); in usbf_handle_ep0_in_status_start()
2612 if (ret != -EINPROGRESS) { in usbf_handle_ep0_in_status_start()
2614 udc->ep0state = EP0_IN_STATUS_END_PHASE; in usbf_handle_ep0_in_status_start()
2618 udc->ep0state = EP0_IN_STATUS_PHASE; in usbf_handle_ep0_in_status_start()
2624 struct usbf_udc *udc = ep0->udc; in usbf_ep0_interrupt()
2629 ep0->status = usbf_ep_reg_readl(ep0, USBF_REG_EP0_STATUS); in usbf_ep0_interrupt()
2630 usbf_ep_reg_writel(ep0, USBF_REG_EP0_STATUS, ~ep0->status); in usbf_ep0_interrupt()
2632 dev_dbg(ep0->udc->dev, "ep0 status=0x%08x, enable=%08x\n, ctrl=0x%08x\n", in usbf_ep0_interrupt()
2633 ep0->status, in usbf_ep0_interrupt()
2637 sts = ep0->status & (USBF_EP0_SETUP_INT | USBF_EP0_IN_INT | USBF_EP0_OUT_INT | in usbf_ep0_interrupt()
2643 dev_dbg(ep0->udc->dev, "udc->ep0state=%d\n", udc->ep0state); in usbf_ep0_interrupt()
2646 prev_ep0state = udc->ep0state; in usbf_ep0_interrupt()
2647 switch (udc->ep0state) { in usbf_ep0_interrupt()
2653 dev_dbg(ep0->udc->dev, "ep0 handle setup\n"); in usbf_ep0_interrupt()
2662 dev_dbg(ep0->udc->dev, "ep0 handle in data phase\n"); in usbf_ep0_interrupt()
2672 dev_dbg(ep0->udc->dev, "ep0 handle out status start phase\n"); in usbf_ep0_interrupt()
2681 dev_dbg(ep0->udc->dev, "ep0 handle out status phase\n"); in usbf_ep0_interrupt()
2692 dev_dbg(ep0->udc->dev, "ep0 handle out status end phase\n"); in usbf_ep0_interrupt()
2693 udc->ep0state = EP0_IDLE; in usbf_ep0_interrupt()
2701 dev_dbg(ep0->udc->dev, "ep0 handle out data phase\n"); in usbf_ep0_interrupt()
2711 dev_dbg(ep0->udc->dev, "ep0 handle in status start phase\n"); in usbf_ep0_interrupt()
2720 dev_dbg(ep0->udc->dev, "ep0 handle in status phase\n"); in usbf_ep0_interrupt()
2730 dev_dbg(ep0->udc->dev, "ep0 handle in status end\n"); in usbf_ep0_interrupt()
2731 udc->ep0state = EP0_IDLE; in usbf_ep0_interrupt()
2735 udc->ep0state = EP0_IDLE; in usbf_ep0_interrupt()
2740 dev_dbg(ep0->udc->dev, "ep0 failed (%d)\n", ret); in usbf_ep0_interrupt()
2741 /* Failure -> stall. in usbf_ep0_interrupt()
2748 usbf_ep_nuke(ep0, -EPROTO); in usbf_ep0_interrupt()
2750 udc->ep0state = EP0_IDLE; in usbf_ep0_interrupt()
2754 } while ((prev_ep0state != udc->ep0state) || (prev_sts != sts)); in usbf_ep0_interrupt()
2756 dev_dbg(ep0->udc->dev, "ep0 done udc->ep0state=%d, status=0x%08x. next=0x%08x\n", in usbf_ep0_interrupt()
2757 udc->ep0state, sts, in usbf_ep0_interrupt()
2767 case -ENOENT: in usbf_epn_process_queue()
2768 dev_warn(epn->udc->dev, "ep%u %s, no request available\n", in usbf_epn_process_queue()
2769 epn->id, epn->is_in ? "in" : "out"); in usbf_epn_process_queue()
2771 case -EINPROGRESS: in usbf_epn_process_queue()
2779 dev_err(epn->udc->dev, "ep%u %s, process queue failed (%d)\n", in usbf_epn_process_queue()
2780 epn->id, epn->is_in ? "in" : "out", ret); in usbf_epn_process_queue()
2785 dev_dbg(epn->udc->dev, "ep%u %s failed (%d)\n", epn->id, in usbf_epn_process_queue()
2786 epn->is_in ? "in" : "out", ret); in usbf_epn_process_queue()
2797 epn->status = usbf_ep_reg_readl(epn, USBF_REG_EPN_STATUS); in usbf_epn_interrupt()
2799 usbf_ep_reg_writel(epn, USBF_REG_EPN_STATUS, ~(epn->status & ena)); in usbf_epn_interrupt()
2801 dev_dbg(epn->udc->dev, "ep%u %s status=0x%08x, enable=%08x\n, ctrl=0x%08x\n", in usbf_epn_interrupt()
2802 epn->id, epn->is_in ? "in" : "out", epn->status, ena, in usbf_epn_interrupt()
2805 if (epn->disabled) { in usbf_epn_interrupt()
2806 dev_warn(epn->udc->dev, "ep%u %s, interrupt while disabled\n", in usbf_epn_interrupt()
2807 epn->id, epn->is_in ? "in" : "out"); in usbf_epn_interrupt()
2811 sts = epn->status & ena; in usbf_epn_interrupt()
2815 dev_dbg(epn->udc->dev, "ep%u %s process queue (in interrupts)\n", in usbf_epn_interrupt()
2816 epn->id, epn->is_in ? "in" : "out"); in usbf_epn_interrupt()
2822 dev_dbg(epn->udc->dev, "ep%u %s process queue (out interrupts)\n", in usbf_epn_interrupt()
2823 epn->id, epn->is_in ? "in" : "out"); in usbf_epn_interrupt()
2827 dev_dbg(epn->udc->dev, "ep%u %s done status=0x%08x. next=0x%08x\n", in usbf_epn_interrupt()
2828 epn->id, epn->is_in ? "in" : "out", in usbf_epn_interrupt()
2834 ep->status = 0; in usbf_ep_reset()
2836 usbf_ep_nuke(ep, -ESHUTDOWN); in usbf_ep_reset()
2843 for (i = 0; i < ARRAY_SIZE(udc->ep); i++) { in usbf_reset()
2844 if (udc->ep[i].disabled) in usbf_reset()
2847 usbf_ep_reset(&udc->ep[i]); in usbf_reset()
2851 udc->gadget.speed = USB_SPEED_HIGH; in usbf_reset()
2853 udc->gadget.speed = USB_SPEED_FULL; in usbf_reset()
2856 udc->is_remote_wakeup = false; in usbf_reset()
2859 usbf_ep0_enable(&udc->ep[0]); in usbf_reset()
2861 if (udc->driver) { in usbf_reset()
2863 spin_unlock(&udc->lock); in usbf_reset()
2864 usb_gadget_udc_reset(&udc->gadget, udc->driver); in usbf_reset()
2865 spin_lock(&udc->lock); in usbf_reset()
2871 if (udc->is_usb_suspended) { in usbf_driver_suspend()
2872 dev_dbg(udc->dev, "already suspended\n"); in usbf_driver_suspend()
2876 dev_dbg(udc->dev, "do usb suspend\n"); in usbf_driver_suspend()
2877 udc->is_usb_suspended = true; in usbf_driver_suspend()
2879 if (udc->driver && udc->driver->suspend) { in usbf_driver_suspend()
2880 spin_unlock(&udc->lock); in usbf_driver_suspend()
2881 udc->driver->suspend(&udc->gadget); in usbf_driver_suspend()
2882 spin_lock(&udc->lock); in usbf_driver_suspend()
2896 if (!udc->is_usb_suspended) in usbf_driver_resume()
2899 dev_dbg(udc->dev, "do usb resume\n"); in usbf_driver_resume()
2900 udc->is_usb_suspended = false; in usbf_driver_resume()
2902 if (udc->driver && udc->driver->resume) { in usbf_driver_resume()
2903 spin_unlock(&udc->lock); in usbf_driver_resume()
2904 udc->driver->resume(&udc->gadget); in usbf_driver_resume()
2905 spin_lock(&udc->lock); in usbf_driver_resume()
2918 spin_lock_irqsave(&udc->lock, flags); in usbf_epc_irq()
2924 dev_dbg(udc->dev, "int_sts=0x%08x\n", int_sts); in usbf_epc_irq()
2927 dev_dbg(udc->dev, "handle resume\n"); in usbf_epc_irq()
2932 dev_dbg(udc->dev, "handle bus reset\n"); in usbf_epc_irq()
2939 udc->gadget.speed = USB_SPEED_HIGH; in usbf_epc_irq()
2941 udc->gadget.speed = USB_SPEED_FULL; in usbf_epc_irq()
2942 dev_dbg(udc->dev, "handle speed change (%s)\n", in usbf_epc_irq()
2943 udc->gadget.speed == USB_SPEED_HIGH ? "High" : "Full"); in usbf_epc_irq()
2948 usbf_ep0_interrupt(&udc->ep[0]); in usbf_epc_irq()
2951 for (i = 1; i < ARRAY_SIZE(udc->ep); i++) { in usbf_epc_irq()
2952 ep = &udc->ep[i]; in usbf_epc_irq()
2961 dev_dbg(udc->dev, "handle suspend\n"); in usbf_epc_irq()
2965 spin_unlock_irqrestore(&udc->lock, flags); in usbf_epc_irq()
2979 spin_lock_irqsave(&udc->lock, flags); in usbf_ahb_epc_irq()
2987 dev_dbg(udc->dev, "handle vbus (1)\n"); in usbf_ahb_epc_irq()
2988 spin_unlock(&udc->lock); in usbf_ahb_epc_irq()
2989 usb_udc_vbus_handler(&udc->gadget, true); in usbf_ahb_epc_irq()
2990 usb_gadget_set_state(&udc->gadget, USB_STATE_POWERED); in usbf_ahb_epc_irq()
2991 spin_lock(&udc->lock); in usbf_ahb_epc_irq()
2993 dev_dbg(udc->dev, "handle vbus (0)\n"); in usbf_ahb_epc_irq()
2994 udc->is_usb_suspended = false; in usbf_ahb_epc_irq()
2995 spin_unlock(&udc->lock); in usbf_ahb_epc_irq()
2996 usb_udc_vbus_handler(&udc->gadget, false); in usbf_ahb_epc_irq()
2997 usb_gadget_set_state(&udc->gadget, in usbf_ahb_epc_irq()
2999 spin_lock(&udc->lock); in usbf_ahb_epc_irq()
3003 for (i = 1; i < ARRAY_SIZE(udc->ep); i++) { in usbf_ahb_epc_irq()
3005 epn = &udc->ep[i]; in usbf_ahb_epc_irq()
3006 dev_dbg(epn->udc->dev, in usbf_ahb_epc_irq()
3008 epn->id, epn->bridge_on_dma_end); in usbf_ahb_epc_irq()
3009 ep_action = epn->bridge_on_dma_end; in usbf_ahb_epc_irq()
3011 epn->bridge_on_dma_end = NULL; in usbf_ahb_epc_irq()
3017 spin_unlock_irqrestore(&udc->lock, flags); in usbf_ahb_epc_irq()
3028 dev_info(udc->dev, "start (driver '%s')\n", driver->driver.name); in usbf_udc_start()
3030 spin_lock_irqsave(&udc->lock, flags); in usbf_udc_start()
3033 udc->driver = driver; in usbf_udc_start()
3038 spin_unlock_irqrestore(&udc->lock, flags); in usbf_udc_start()
3048 spin_lock_irqsave(&udc->lock, flags); in usbf_udc_stop()
3053 udc->driver = NULL; in usbf_udc_stop()
3055 spin_unlock_irqrestore(&udc->lock, flags); in usbf_udc_stop()
3057 dev_info(udc->dev, "stopped\n"); in usbf_udc_stop()
3072 * D+ signal Pull-up in usbf_attach()
3093 for (i = 0; i < ARRAY_SIZE(udc->ep); i++) { in usbf_detach()
3094 if (udc->ep[i].disabled) in usbf_detach()
3097 usbf_ep_reset(&udc->ep[i]); in usbf_detach()
3101 * Do not Pull-up D+ signal in usbf_detach()
3115 dev_dbg(udc->dev, "pullup %d\n", is_on); in usbf_pullup()
3117 spin_lock_irqsave(&udc->lock, flags); in usbf_pullup()
3122 spin_unlock_irqrestore(&udc->lock, flags); in usbf_pullup()
3133 spin_lock_irqsave(&udc->lock, flags); in usbf_udc_set_selfpowered()
3134 gadget->is_selfpowered = (is_selfpowered != 0); in usbf_udc_set_selfpowered()
3135 spin_unlock_irqrestore(&udc->lock, flags); in usbf_udc_set_selfpowered()
3146 spin_lock_irqsave(&udc->lock, flags); in usbf_udc_wakeup()
3148 if (!udc->is_remote_wakeup) { in usbf_udc_wakeup()
3149 dev_dbg(udc->dev, "remote wakeup not allowed\n"); in usbf_udc_wakeup()
3150 ret = -EINVAL; in usbf_udc_wakeup()
3154 dev_dbg(udc->dev, "do wakeup\n"); in usbf_udc_wakeup()
3162 spin_unlock_irqrestore(&udc->lock, flags); in usbf_udc_wakeup()
3187 if (epn->ep.caps.type_control || epn->ep.caps.type_iso || in usbf_epn_check()
3188 !epn->ep.caps.type_bulk || epn->ep.caps.type_int) { in usbf_epn_check()
3189 dev_err(epn->udc->dev, in usbf_epn_check()
3190 "ep%u caps mismatch, bulk expected\n", epn->id); in usbf_epn_check()
3191 ret = -EINVAL; in usbf_epn_check()
3196 if (epn->ep.caps.type_control || epn->ep.caps.type_iso || in usbf_epn_check()
3197 epn->ep.caps.type_bulk || !epn->ep.caps.type_int) { in usbf_epn_check()
3198 dev_err(epn->udc->dev, in usbf_epn_check()
3199 "ep%u caps mismatch, int expected\n", epn->id); in usbf_epn_check()
3200 ret = -EINVAL; in usbf_epn_check()
3205 if (epn->ep.caps.type_control || !epn->ep.caps.type_iso || in usbf_epn_check()
3206 epn->ep.caps.type_bulk || epn->ep.caps.type_int) { in usbf_epn_check()
3207 dev_err(epn->udc->dev, in usbf_epn_check()
3208 "ep%u caps mismatch, iso expected\n", epn->id); in usbf_epn_check()
3209 ret = -EINVAL; in usbf_epn_check()
3214 dev_err(epn->udc->dev, "ep%u unknown type\n", epn->id); in usbf_epn_check()
3215 ret = -EINVAL; in usbf_epn_check()
3221 if (!usbf_ep_info[epn->id].is_double) { in usbf_epn_check()
3222 dev_err(epn->udc->dev, in usbf_epn_check()
3224 epn->id); in usbf_epn_check()
3225 ret = -EINVAL; in usbf_epn_check()
3229 if (usbf_ep_info[epn->id].is_double) { in usbf_epn_check()
3230 dev_err(epn->udc->dev, in usbf_epn_check()
3232 epn->id); in usbf_epn_check()
3233 ret = -EINVAL; in usbf_epn_check()
3237 dev_dbg(epn->udc->dev, "ep%u (%s) %s, %s buffer %u, checked %s\n", in usbf_epn_check()
3238 epn->id, epn->ep.name, type_txt, buf_txt, in usbf_epn_check()
3239 epn->ep.maxpacket_limit, ret ? "failed" : "ok"); in usbf_epn_check()
3246 struct device *dev = &pdev->dev; in usbf_probe()
3255 return -ENOMEM; in usbf_probe()
3258 udc->dev = dev; in usbf_probe()
3259 spin_lock_init(&udc->lock); in usbf_probe()
3261 udc->regs = devm_platform_ioremap_resource(pdev, 0); in usbf_probe()
3262 if (IS_ERR(udc->regs)) in usbf_probe()
3263 return PTR_ERR(udc->regs); in usbf_probe()
3265 devm_pm_runtime_enable(&pdev->dev); in usbf_probe()
3266 ret = pm_runtime_resume_and_get(&pdev->dev); in usbf_probe()
3270 dev_info(dev, "USBF version: %08x\n", in usbf_probe()
3279 udc->gadget.speed = USB_SPEED_FULL; in usbf_probe()
3280 udc->gadget.max_speed = USB_SPEED_HIGH; in usbf_probe()
3281 udc->gadget.ops = &usbf_gadget_ops; in usbf_probe()
3283 udc->gadget.name = dev->driver->name; in usbf_probe()
3284 udc->gadget.dev.parent = dev; in usbf_probe()
3285 udc->gadget.ep0 = &udc->ep[0].ep; in usbf_probe()
3290 udc->gadget.quirk_avoids_skb_reserve = 1; in usbf_probe()
3292 INIT_LIST_HEAD(&udc->gadget.ep_list); in usbf_probe()
3296 INIT_LIST_HEAD(&udc->setup_reply.queue); in usbf_probe()
3298 for (i = 0; i < ARRAY_SIZE(udc->ep); i++) { in usbf_probe()
3299 ep = &udc->ep[i]; in usbf_probe()
3306 INIT_LIST_HEAD(&ep->queue); in usbf_probe()
3308 ep->id = i; in usbf_probe()
3309 ep->disabled = 1; in usbf_probe()
3310 ep->udc = udc; in usbf_probe()
3311 ep->ep.ops = &usbf_ep_ops; in usbf_probe()
3312 ep->ep.name = usbf_ep_info[i].name; in usbf_probe()
3313 ep->ep.caps = usbf_ep_info[i].caps; in usbf_probe()
3314 usb_ep_set_maxpacket_limit(&ep->ep, in usbf_probe()
3317 if (ep->id == 0) { in usbf_probe()
3318 ep->regs = ep->udc->regs + USBF_BASE_EP0; in usbf_probe()
3320 ep->regs = ep->udc->regs + USBF_BASE_EPN(ep->id - 1); in usbf_probe()
3326 ep->dma_regs = ep->udc->regs + in usbf_probe()
3327 USBF_BASE_DMA_EPN(ep->id - 1); in usbf_probe()
3329 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in usbf_probe()
3336 ret = devm_request_irq(dev, irq, usbf_epc_irq, 0, "usbf-epc", udc); in usbf_probe()
3345 ret = devm_request_irq(dev, irq, usbf_ahb_epc_irq, 0, "usbf-ahb-epc", udc); in usbf_probe()
3356 ret = usb_add_gadget_udc(dev, &udc->gadget); in usbf_probe()
3367 usb_del_gadget_udc(&udc->gadget); in usbf_remove()
3369 pm_runtime_put(&pdev->dev); in usbf_remove()
3373 { .compatible = "renesas,rzn1-usbf" },
3390 MODULE_DESCRIPTION("Renesas R-Car Gen3 & RZ/N1 USB Function driver");