Lines Matching +full:halt +full:- +full:regs

1 // SPDX-License-Identifier: GPL-2.0+
3 * aspeed-vhub -- Driver for Aspeed SoC "vHub" USB gadget
5 * epn.c - Generic endpoints management
25 #include <linux/dma-mapping.h>
42 unsigned int act = req->req.actual; in ast_vhub_epn_kick()
43 unsigned int len = req->req.length; in ast_vhub_epn_kick()
47 WARN_ON(req->active); in ast_vhub_epn_kick()
50 chunk = len - act; in ast_vhub_epn_kick()
51 if (chunk > ep->ep.maxpacket) in ast_vhub_epn_kick()
52 chunk = ep->ep.maxpacket; in ast_vhub_epn_kick()
53 else if ((chunk < ep->ep.maxpacket) || !req->req.zero) in ast_vhub_epn_kick()
54 req->last_desc = 1; in ast_vhub_epn_kick()
57 req, act, len, chunk, req->last_desc); in ast_vhub_epn_kick()
60 if (!req->req.dma) { in ast_vhub_epn_kick()
63 if (ep->epn.is_in) { in ast_vhub_epn_kick()
64 memcpy(ep->buf, req->req.buf + act, chunk); in ast_vhub_epn_kick()
65 vhub_dma_workaround(ep->buf); in ast_vhub_epn_kick()
67 writel(ep->buf_dma, ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_kick()
69 if (ep->epn.is_in) in ast_vhub_epn_kick()
70 vhub_dma_workaround(req->req.buf); in ast_vhub_epn_kick()
71 writel(req->req.dma + act, ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_kick()
75 req->active = true; in ast_vhub_epn_kick()
77 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick()
79 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick()
90 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack()
93 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_epn_handle_ack()
96 stat, ep->epn.is_in, req, req ? req->active : 0); in ast_vhub_epn_handle_ack()
106 if (!req->active) in ast_vhub_epn_handle_ack()
116 req->active = false; in ast_vhub_epn_handle_ack()
122 if (!req->req.dma && !ep->epn.is_in && len) { in ast_vhub_epn_handle_ack()
123 if (req->req.actual + len > req->req.length) { in ast_vhub_epn_handle_ack()
124 req->last_desc = 1; in ast_vhub_epn_handle_ack()
125 status = -EOVERFLOW; in ast_vhub_epn_handle_ack()
128 memcpy(req->req.buf + req->req.actual, ep->buf, len); in ast_vhub_epn_handle_ack()
132 req->req.actual += len; in ast_vhub_epn_handle_ack()
135 if (len < ep->ep.maxpacket) in ast_vhub_epn_handle_ack()
136 req->last_desc = 1; in ast_vhub_epn_handle_ack()
140 if (req->last_desc >= 0) { in ast_vhub_epn_handle_ack()
142 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, in ast_vhub_epn_handle_ack()
149 if (!req || req->active) in ast_vhub_epn_handle_ack()
161 * thus we can only have AST_VHUB_DESCS_COUNT-1 descriptors in ast_vhub_count_free_descs()
164 return (ep->epn.d_last + AST_VHUB_DESCS_COUNT - ep->epn.d_next - 1) & in ast_vhub_count_free_descs()
165 (AST_VHUB_DESCS_COUNT - 1); in ast_vhub_count_free_descs()
172 unsigned int act = req->act_count; in ast_vhub_epn_kick_desc()
173 unsigned int len = req->req.length; in ast_vhub_epn_kick_desc()
177 req->active = true; in ast_vhub_epn_kick_desc()
180 if (req->last_desc >= 0) in ast_vhub_epn_kick_desc()
184 act, len, ep->epn.chunk_max, ast_vhub_count_free_descs(ep)); in ast_vhub_epn_kick_desc()
187 while (ast_vhub_count_free_descs(ep) && req->last_desc < 0) { in ast_vhub_epn_kick_desc()
191 d_num = ep->epn.d_next; in ast_vhub_epn_kick_desc()
192 desc = &ep->epn.descs[d_num]; in ast_vhub_epn_kick_desc()
193 ep->epn.d_next = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1); in ast_vhub_epn_kick_desc()
196 chunk = len - act; in ast_vhub_epn_kick_desc()
197 if (chunk <= ep->epn.chunk_max) { in ast_vhub_epn_kick_desc()
206 if (!chunk || !req->req.zero || (chunk % ep->ep.maxpacket) != 0) in ast_vhub_epn_kick_desc()
207 req->last_desc = d_num; in ast_vhub_epn_kick_desc()
209 chunk = ep->epn.chunk_max; in ast_vhub_epn_kick_desc()
213 act, len, chunk, req->last_desc, d_num, in ast_vhub_epn_kick_desc()
217 desc->w0 = cpu_to_le32(req->req.dma + act); in ast_vhub_epn_kick_desc()
229 desc->w1 = cpu_to_le32(VHUB_DSC1_IN_SET_LEN(chunk)); in ast_vhub_epn_kick_desc()
230 if (req->last_desc >= 0 || !ast_vhub_count_free_descs(ep)) in ast_vhub_epn_kick_desc()
231 desc->w1 |= cpu_to_le32(VHUB_DSC1_IN_INTERRUPT); in ast_vhub_epn_kick_desc()
234 req->act_count = act = act + chunk; in ast_vhub_epn_kick_desc()
241 writel(VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next), in ast_vhub_epn_kick_desc()
242 ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_kick_desc()
245 ep->epn.d_next, readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS)); in ast_vhub_epn_kick_desc()
256 stat = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack_desc()
257 stat1 = readl(ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_handle_ack_desc()
264 req = list_first_entry_or_null(&ep->queue, struct ast_vhub_req, queue); in ast_vhub_epn_handle_ack_desc()
266 EPVDBG(ep, "ACK status=%08x is_in=%d ep->d_last=%d..%d\n", in ast_vhub_epn_handle_ack_desc()
267 stat, ep->epn.is_in, ep->epn.d_last, d_last); in ast_vhub_epn_handle_ack_desc()
270 while (ep->epn.d_last != d_last) { in ast_vhub_epn_handle_ack_desc()
276 d_num = ep->epn.d_last; in ast_vhub_epn_handle_ack_desc()
277 desc = &ep->epn.descs[d_num]; in ast_vhub_epn_handle_ack_desc()
278 ep->epn.d_last = (d_num + 1) & (AST_VHUB_DESCS_COUNT - 1); in ast_vhub_epn_handle_ack_desc()
281 len = VHUB_DSC1_IN_LEN(le32_to_cpu(desc->w1)); in ast_vhub_epn_handle_ack_desc()
284 d_num, len, req, req ? req->active : 0); in ast_vhub_epn_handle_ack_desc()
287 if (!req || !req->active) in ast_vhub_epn_handle_ack_desc()
291 req->req.actual += len; in ast_vhub_epn_handle_ack_desc()
294 is_last_desc = req->last_desc == d_num; in ast_vhub_epn_handle_ack_desc()
295 CHECK(ep, is_last_desc == (len < ep->ep.maxpacket || in ast_vhub_epn_handle_ack_desc()
296 (req->req.actual >= req->req.length && in ast_vhub_epn_handle_ack_desc()
297 !req->req.zero)), in ast_vhub_epn_handle_ack_desc()
300 is_last_desc, len, req->req.actual, req->req.length, in ast_vhub_epn_handle_ack_desc()
301 req->req.zero, ep->ep.maxpacket); in ast_vhub_epn_handle_ack_desc()
307 * d_last and ep->d_last should now be equal in ast_vhub_epn_handle_ack_desc()
309 CHECK(ep, d_last == ep->epn.d_last, in ast_vhub_epn_handle_ack_desc()
311 d_last, ep->epn.d_last); in ast_vhub_epn_handle_ack_desc()
313 /* Note: done will drop and re-acquire the lock */ in ast_vhub_epn_handle_ack_desc()
315 req = list_first_entry_or_null(&ep->queue, in ast_vhub_epn_handle_ack_desc()
329 if (ep->epn.desc_mode) in ast_vhub_epn_ack_irq()
340 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_queue()
346 if (!u_req || !u_req->complete || !u_req->buf) { in ast_vhub_epn_queue()
347 dev_warn(&vhub->pdev->dev, "Bogus EPn request ! u_req=%p\n", u_req); in ast_vhub_epn_queue()
349 dev_warn(&vhub->pdev->dev, "complete=%p internal=%d\n", in ast_vhub_epn_queue()
350 u_req->complete, req->internal); in ast_vhub_epn_queue()
352 return -EINVAL; in ast_vhub_epn_queue()
356 if (!ep->epn.enabled || !u_ep->desc || !ep->dev || !ep->d_idx || in ast_vhub_epn_queue()
357 !ep->dev->enabled) { in ast_vhub_epn_queue()
359 return -ESHUTDOWN; in ast_vhub_epn_queue()
367 * - The buffer is aligned to a 8 bytes boundary (HW requirement) in ast_vhub_epn_queue()
368 * - For a OUT endpoint, the request size is a multiple of the EP in ast_vhub_epn_queue()
378 if (ep->epn.desc_mode || in ast_vhub_epn_queue()
379 ((((unsigned long)u_req->buf & 7) == 0) && in ast_vhub_epn_queue()
380 (ep->epn.is_in || !(u_req->length & (u_ep->maxpacket - 1))))) { in ast_vhub_epn_queue()
381 rc = usb_gadget_map_request_by_dev(&vhub->pdev->dev, u_req, in ast_vhub_epn_queue()
382 ep->epn.is_in); in ast_vhub_epn_queue()
384 dev_warn(&vhub->pdev->dev, in ast_vhub_epn_queue()
389 u_req->dma = 0; in ast_vhub_epn_queue()
393 u_req->length, (u32)u_req->dma, u_req->zero, in ast_vhub_epn_queue()
394 u_req->short_not_ok, u_req->no_interrupt, in ast_vhub_epn_queue()
395 ep->epn.is_in); in ast_vhub_epn_queue()
398 u_req->status = -EINPROGRESS; in ast_vhub_epn_queue()
399 u_req->actual = 0; in ast_vhub_epn_queue()
400 req->act_count = 0; in ast_vhub_epn_queue()
401 req->active = false; in ast_vhub_epn_queue()
402 req->last_desc = -1; in ast_vhub_epn_queue()
403 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_epn_queue()
404 empty = list_empty(&ep->queue); in ast_vhub_epn_queue()
407 list_add_tail(&req->queue, &ep->queue); in ast_vhub_epn_queue()
409 if (ep->epn.desc_mode) in ast_vhub_epn_queue()
414 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_epn_queue()
425 if (ep->epn.desc_mode) in ast_vhub_stop_active_req()
426 writel(VHUB_EP_DMA_CTRL_RESET, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
428 writel(0, ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
432 state = readl(ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
440 dev_warn(&ep->vhub->pdev->dev, "Timeout waiting for DMA\n"); in ast_vhub_stop_active_req()
447 if (ep->epn.desc_mode) { in ast_vhub_stop_active_req()
458 reg = VHUB_EP_DMA_SET_RPTR(ep->epn.d_next) | in ast_vhub_stop_active_req()
459 VHUB_EP_DMA_SET_CPU_WPTR(ep->epn.d_next); in ast_vhub_stop_active_req()
460 writel(reg, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_stop_active_req()
463 writel(ep->epn.dma_conf, in ast_vhub_stop_active_req()
464 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
467 writel(ep->epn.dma_conf, in ast_vhub_stop_active_req()
468 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_stop_active_req()
475 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_dequeue()
478 int rc = -EINVAL; in ast_vhub_epn_dequeue()
480 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_epn_dequeue()
483 list_for_each_entry(iter, &ep->queue, queue) { in ast_vhub_epn_dequeue()
484 if (&iter->req != u_req) in ast_vhub_epn_dequeue()
492 req, req->active); in ast_vhub_epn_dequeue()
493 if (req->active) in ast_vhub_epn_dequeue()
495 ast_vhub_done(ep, req, -ECONNRESET); in ast_vhub_epn_dequeue()
499 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_epn_dequeue()
507 if (WARN_ON(ep->d_idx == 0)) in ast_vhub_update_epn_stall()
509 reg = readl(ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_update_epn_stall()
510 if (ep->epn.stalled || ep->epn.wedged) in ast_vhub_update_epn_stall()
514 writel(reg, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_update_epn_stall()
516 if (!ep->epn.stalled && !ep->epn.wedged) in ast_vhub_update_epn_stall()
517 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx), in ast_vhub_update_epn_stall()
518 ep->vhub->regs + AST_VHUB_EP_TOGGLE); in ast_vhub_update_epn_stall()
521 static int ast_vhub_set_halt_and_wedge(struct usb_ep* u_ep, bool halt, in ast_vhub_set_halt_and_wedge() argument
525 struct ast_vhub *vhub = ep->vhub; in ast_vhub_set_halt_and_wedge()
528 EPDBG(ep, "Set halt (%d) & wedge (%d)\n", halt, wedge); in ast_vhub_set_halt_and_wedge()
530 if (!u_ep || !u_ep->desc) in ast_vhub_set_halt_and_wedge()
531 return -EINVAL; in ast_vhub_set_halt_and_wedge()
532 if (ep->d_idx == 0) in ast_vhub_set_halt_and_wedge()
534 if (ep->epn.is_iso) in ast_vhub_set_halt_and_wedge()
535 return -EOPNOTSUPP; in ast_vhub_set_halt_and_wedge()
537 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_set_halt_and_wedge()
539 /* Fail with still-busy IN endpoints */ in ast_vhub_set_halt_and_wedge()
540 if (halt && ep->epn.is_in && !list_empty(&ep->queue)) { in ast_vhub_set_halt_and_wedge()
541 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_set_halt_and_wedge()
542 return -EAGAIN; in ast_vhub_set_halt_and_wedge()
544 ep->epn.stalled = halt; in ast_vhub_set_halt_and_wedge()
545 ep->epn.wedged = wedge; in ast_vhub_set_halt_and_wedge()
548 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_set_halt_and_wedge()
566 struct ast_vhub *vhub = ep->vhub; in ast_vhub_epn_disable()
572 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_epn_disable()
574 ep->epn.enabled = false; in ast_vhub_epn_disable()
580 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_disable()
583 imask = VHUB_EP_IRQ(ep->epn.g_idx); in ast_vhub_epn_disable()
584 ep_ier = readl(vhub->regs + AST_VHUB_EP_ACK_IER); in ast_vhub_epn_disable()
586 writel(ep_ier, vhub->regs + AST_VHUB_EP_ACK_IER); in ast_vhub_epn_disable()
587 writel(imask, vhub->regs + AST_VHUB_EP_ACK_ISR); in ast_vhub_epn_disable()
590 ast_vhub_nuke(ep, -ESHUTDOWN); in ast_vhub_epn_disable()
593 ep->ep.desc = NULL; in ast_vhub_epn_disable()
595 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_epn_disable()
612 return -EINVAL; in ast_vhub_epn_enable()
615 if (!ep->d_idx || !ep->dev || in ast_vhub_epn_enable()
616 desc->bDescriptorType != USB_DT_ENDPOINT || in ast_vhub_epn_enable()
617 maxpacket == 0 || maxpacket > ep->ep.maxpacket) { in ast_vhub_epn_enable()
619 ep->d_idx, ep->dev, desc->bDescriptorType, in ast_vhub_epn_enable()
620 maxpacket, ep->ep.maxpacket); in ast_vhub_epn_enable()
621 return -EINVAL; in ast_vhub_epn_enable()
623 if (ep->d_idx != usb_endpoint_num(desc)) { in ast_vhub_epn_enable()
625 return -EINVAL; in ast_vhub_epn_enable()
628 if (ep->epn.enabled) { in ast_vhub_epn_enable()
630 return -EBUSY; in ast_vhub_epn_enable()
632 dev = ep->dev; in ast_vhub_epn_enable()
633 vhub = ep->vhub; in ast_vhub_epn_enable()
636 if (!dev->driver) { in ast_vhub_epn_enable()
638 dev->driver, dev->gadget.speed); in ast_vhub_epn_enable()
639 return -ESHUTDOWN; in ast_vhub_epn_enable()
643 ep->epn.is_in = usb_endpoint_dir_in(desc); in ast_vhub_epn_enable()
644 ep->ep.maxpacket = maxpacket; in ast_vhub_epn_enable()
646 ep->epn.d_next = ep->epn.d_last = 0; in ast_vhub_epn_enable()
647 ep->epn.is_iso = false; in ast_vhub_epn_enable()
648 ep->epn.stalled = false; in ast_vhub_epn_enable()
649 ep->epn.wedged = false; in ast_vhub_epn_enable()
652 ep->epn.is_in ? "in" : "out", usb_ep_type_string(type), in ast_vhub_epn_enable()
656 ep->epn.desc_mode = ep->epn.descs && ep->epn.is_in; in ast_vhub_epn_enable()
657 if (ep->epn.desc_mode) in ast_vhub_epn_enable()
658 memset(ep->epn.descs, 0, 8 * AST_VHUB_DESCS_COUNT); in ast_vhub_epn_enable()
664 ep->epn.chunk_max = ep->ep.maxpacket; in ast_vhub_epn_enable()
665 if (ep->epn.is_in) { in ast_vhub_epn_enable()
666 ep->epn.chunk_max <<= 3; in ast_vhub_epn_enable()
667 while (ep->epn.chunk_max > 4095) in ast_vhub_epn_enable()
668 ep->epn.chunk_max -= ep->ep.maxpacket; in ast_vhub_epn_enable()
674 return -EINVAL; in ast_vhub_epn_enable()
683 ep->epn.is_iso = true; in ast_vhub_epn_enable()
686 return -EINVAL; in ast_vhub_epn_enable()
692 if (!ep->epn.is_in) in ast_vhub_epn_enable()
696 ep_conf |= VHUB_EP_CFG_SET_DEV(dev->index + 1); in ast_vhub_epn_enable()
699 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_epn_enable()
702 writel(0, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_enable()
704 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
707 writel(ep_conf, ep->epn.regs + AST_VHUB_EP_CONFIG); in ast_vhub_epn_enable()
709 if (ep->epn.desc_mode) { in ast_vhub_epn_enable()
711 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_enable()
714 writel(ep->epn.descs_dma, in ast_vhub_epn_enable()
715 ep->epn.regs + AST_VHUB_EP_DESC_BASE); in ast_vhub_epn_enable()
718 ep->epn.dma_conf = VHUB_EP_DMA_DESC_MODE; in ast_vhub_epn_enable()
719 if (ep->epn.is_in) in ast_vhub_epn_enable()
720 ep->epn.dma_conf |= VHUB_EP_DMA_IN_LONG_MODE; in ast_vhub_epn_enable()
723 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET, in ast_vhub_epn_enable()
724 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
727 writel(ep->epn.dma_conf, in ast_vhub_epn_enable()
728 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
731 ep->epn.dma_conf = VHUB_EP_DMA_SINGLE_STAGE; in ast_vhub_epn_enable()
734 writel(ep->epn.dma_conf | VHUB_EP_DMA_CTRL_RESET, in ast_vhub_epn_enable()
735 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
736 writel(ep->epn.dma_conf, in ast_vhub_epn_enable()
737 ep->epn.regs + AST_VHUB_EP_DMA_CTLSTAT); in ast_vhub_epn_enable()
738 writel(0, ep->epn.regs + AST_VHUB_EP_DESC_STATUS); in ast_vhub_epn_enable()
742 writel(VHUB_EP_TOGGLE_SET_EPNUM(ep->epn.g_idx), in ast_vhub_epn_enable()
743 vhub->regs + AST_VHUB_EP_TOGGLE); in ast_vhub_epn_enable()
746 imask = VHUB_EP_IRQ(ep->epn.g_idx); in ast_vhub_epn_enable()
747 writel(imask, vhub->regs + AST_VHUB_EP_ACK_ISR); in ast_vhub_epn_enable()
748 ep_ier = readl(vhub->regs + AST_VHUB_EP_ACK_IER); in ast_vhub_epn_enable()
750 writel(ep_ier, vhub->regs + AST_VHUB_EP_ACK_IER); in ast_vhub_epn_enable()
753 ep->epn.enabled = true; in ast_vhub_epn_enable()
755 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_epn_enable()
764 if (WARN_ON(!ep->dev || !ep->d_idx)) in ast_vhub_epn_dispose()
770 list_del_init(&ep->ep.ep_list); in ast_vhub_epn_dispose()
773 ep->dev->epns[ep->d_idx - 1] = NULL; in ast_vhub_epn_dispose()
776 kfree(ep->ep.name); in ast_vhub_epn_dispose()
777 ep->ep.name = NULL; in ast_vhub_epn_dispose()
778 dma_free_coherent(&ep->vhub->pdev->dev, in ast_vhub_epn_dispose()
781 ep->buf, ep->buf_dma); in ast_vhub_epn_dispose()
782 ep->buf = NULL; in ast_vhub_epn_dispose()
783 ep->epn.descs = NULL; in ast_vhub_epn_dispose()
786 ep->dev = NULL; in ast_vhub_epn_dispose()
803 struct ast_vhub *vhub = d->vhub; in ast_vhub_alloc_epn()
809 spin_lock_irqsave(&vhub->lock, flags); in ast_vhub_alloc_epn()
810 for (i = 0; i < vhub->max_epns; i++) in ast_vhub_alloc_epn()
811 if (vhub->epns[i].dev == NULL) in ast_vhub_alloc_epn()
813 if (i >= vhub->max_epns) { in ast_vhub_alloc_epn()
814 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_alloc_epn()
819 ep = &vhub->epns[i]; in ast_vhub_alloc_epn()
820 ep->dev = d; in ast_vhub_alloc_epn()
821 spin_unlock_irqrestore(&vhub->lock, flags); in ast_vhub_alloc_epn()
824 INIT_LIST_HEAD(&ep->queue); in ast_vhub_alloc_epn()
825 ep->d_idx = addr; in ast_vhub_alloc_epn()
826 ep->vhub = vhub; in ast_vhub_alloc_epn()
827 ep->ep.ops = &ast_vhub_epn_ops; in ast_vhub_alloc_epn()
828 ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", addr); in ast_vhub_alloc_epn()
829 d->epns[addr-1] = ep; in ast_vhub_alloc_epn()
830 ep->epn.g_idx = i; in ast_vhub_alloc_epn()
831 ep->epn.regs = vhub->regs + 0x200 + (i * 0x10); in ast_vhub_alloc_epn()
833 ep->buf = dma_alloc_coherent(&vhub->pdev->dev, in ast_vhub_alloc_epn()
836 &ep->buf_dma, GFP_KERNEL); in ast_vhub_alloc_epn()
837 if (!ep->buf) { in ast_vhub_alloc_epn()
838 kfree(ep->ep.name); in ast_vhub_alloc_epn()
839 ep->ep.name = NULL; in ast_vhub_alloc_epn()
842 ep->epn.descs = ep->buf + AST_VHUB_EPn_MAX_PACKET; in ast_vhub_alloc_epn()
843 ep->epn.descs_dma = ep->buf_dma + AST_VHUB_EPn_MAX_PACKET; in ast_vhub_alloc_epn()
845 usb_ep_set_maxpacket_limit(&ep->ep, AST_VHUB_EPn_MAX_PACKET); in ast_vhub_alloc_epn()
846 list_add_tail(&ep->ep.ep_list, &d->gadget.ep_list); in ast_vhub_alloc_epn()
847 ep->ep.caps.type_iso = true; in ast_vhub_alloc_epn()
848 ep->ep.caps.type_bulk = true; in ast_vhub_alloc_epn()
849 ep->ep.caps.type_int = true; in ast_vhub_alloc_epn()
850 ep->ep.caps.dir_in = true; in ast_vhub_alloc_epn()
851 ep->ep.caps.dir_out = true; in ast_vhub_alloc_epn()