Lines Matching refs:ep

121 static void use_ep(struct omap_ep *ep, u16 select)
123 u16 num = ep->bEndpointAddress & 0x0f;
125 if (ep->bEndpointAddress & USB_DIR_IN)
141 static void dma_channel_claim(struct omap_ep *ep, unsigned preferred);
148 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
156 || ep->bEndpointAddress != desc->bEndpointAddress
157 || ep->maxpacket < usb_endpoint_maxp(desc)) {
158 DBG("%s, bad ep or descriptor\n", __func__);
163 && maxp != ep->maxpacket)
164 || usb_endpoint_maxp(desc) > ep->maxpacket
186 if (ep->bmAttributes != desc->bmAttributes
187 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK
193 udc = ep->udc;
201 ep->ep.desc = desc;
202 ep->irqs = 0;
203 ep->stopped = 0;
204 ep->ep.maxpacket = maxp;
207 ep->dma_channel = 0;
208 ep->has_dma = 0;
209 ep->lch = -1;
210 use_ep(ep, UDC_EP_SEL);
212 ep->ackwait = 0;
215 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
216 list_add(&ep->iso, &udc->iso);
221 dma_channel_claim(ep, 0);
225 && !ep->has_dma
226 && !(ep->bEndpointAddress & USB_DIR_IN)) {
228 ep->ackwait = 1 + ep->double_buf;
240 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
243 if (!_ep || !ep->ep.desc) {
245 _ep ? ep->ep.name : NULL);
249 spin_lock_irqsave(&ep->udc->lock, flags);
250 ep->ep.desc = NULL;
251 nuke(ep, -ESHUTDOWN);
252 ep->ep.maxpacket = ep->maxpacket;
253 ep->has_dma = 0;
255 list_del_init(&ep->iso);
256 del_timer(&ep->timer);
258 spin_unlock_irqrestore(&ep->udc->lock, flags);
267 omap_alloc_request(struct usb_ep *ep, gfp_t gfp_flags)
281 omap_free_request(struct usb_ep *ep, struct usb_request *_req)
291 done(struct omap_ep *ep, struct omap_req *req, int status)
293 struct omap_udc *udc = ep->udc;
294 unsigned stopped = ep->stopped;
303 if (use_dma && ep->has_dma)
305 (ep->bEndpointAddress & USB_DIR_IN));
311 ep->ep.name, &req->req, status,
315 ep->stopped = 1;
316 spin_unlock(&ep->udc->lock);
317 usb_gadget_giveback_request(&ep->ep, &req->req);
318 spin_lock(&ep->udc->lock);
319 ep->stopped = stopped;
357 static int write_fifo(struct omap_ep *ep, struct omap_req *req)
372 count = ep->ep.maxpacket;
375 ep->ackwait = 1;
378 if (count != ep->ep.maxpacket)
391 done(ep, req, 0);
419 static int read_fifo(struct omap_ep *ep, struct omap_req *req)
433 if (!ep->double_buf)
435 ep->fnf = 1;
441 avail = ep->ep.maxpacket;
444 ep->fnf = ep->double_buf;
449 if (count < ep->ep.maxpacket) {
463 if (!ep->bEndpointAddress)
466 done(ep, req, 0);
474 static u16 dma_src_len(struct omap_ep *ep, dma_addr_t start)
484 end = omap_get_dma_src_pos(ep->lch);
485 if (end == ep->dma_counter)
494 static u16 dma_dest_len(struct omap_ep *ep, dma_addr_t start)
498 end = omap_get_dma_dst_pos(ep->lch);
499 if (end == ep->dma_counter)
516 static void next_in_dma(struct omap_ep *ep, struct omap_req *req)
527 || (cpu_is_omap15xx() && length < ep->maxpacket)) {
529 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8,
532 length = min(length / ep->maxpacket,
535 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
536 ep->ep.maxpacket >> 1, length, sync_mode,
538 length *= ep->maxpacket;
540 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF,
544 omap_start_dma(ep->lch);
545 ep->dma_counter = omap_get_dma_src_pos(ep->lch);
547 w |= UDC_TX_DONE_IE(ep->dma_channel);
549 omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel));
553 static void finish_in_dma(struct omap_ep *ep, struct omap_req *req, int status)
565 && (req->req.actual % ep->maxpacket) == 0)
568 req->req.actual += dma_src_len(ep, req->req.dma
572 omap_stop_dma(ep->lch);
574 w &= ~UDC_TX_DONE_IE(ep->dma_channel);
576 done(ep, req, status);
579 static void next_out_dma(struct omap_ep *ep, struct omap_req *req)
586 packets /= ep->ep.maxpacket;
588 req->dma_bytes = packets * ep->ep.maxpacket;
589 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16,
590 ep->ep.maxpacket >> 1, packets,
593 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF,
596 ep->dma_counter = omap_get_dma_dst_pos(ep->lch);
598 omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel));
600 w |= UDC_RX_EOT_IE(ep->dma_channel);
602 omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM);
605 omap_start_dma(ep->lch);
609 finish_out_dma(struct omap_ep *ep, struct omap_req *req, int status, int one)
614 ep->dma_counter = (u16) (req->req.dma + req->req.actual);
615 count = dma_dest_len(ep, req->req.dma + req->req.actual);
623 omap_stop_dma(ep->lch);
631 w &= ~UDC_RX_EOT_IE(ep->dma_channel);
633 done(ep, req, status);
639 struct omap_ep *ep;
644 ep = &udc->ep[16 + UDC_DMA_TX_SRC(dman_stat)];
645 ep->irqs++;
647 if (!list_empty(&ep->queue)) {
648 req = container_of(ep->queue.next,
650 finish_in_dma(ep, req, 0);
654 if (!list_empty(&ep->queue)) {
655 req = container_of(ep->queue.next,
657 next_in_dma(ep, req);
663 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)];
664 ep->irqs++;
666 if (!list_empty(&ep->queue)) {
667 req = container_of(ep->queue.next,
669 finish_out_dma(ep, req, 0, dman_stat & UDC_DMA_RX_SB);
673 if (!list_empty(&ep->queue)) {
674 req = container_of(ep->queue.next,
676 next_out_dma(ep, req);
681 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)];
682 ep->irqs++;
684 VDBG("%s, RX_CNT irq?\n", ep->ep.name);
691 struct omap_ep *ep = data;
695 ERR("%s dma error, lch %d status %02x\n", ep->ep.name, lch, ch_status);
700 static void dma_channel_claim(struct omap_ep *ep, unsigned channel)
706 is_in = ep->bEndpointAddress & USB_DIR_IN;
713 ep->dma_channel = 0;
714 ep->lch = -1;
727 reg |= (0x0f & ep->bEndpointAddress) << (4 * (channel - 1));
728 ep->dma_channel = channel;
733 ep->ep.name, dma_error, ep, &ep->lch);
737 omap_set_dma_src_burst_mode(ep->lch,
739 omap_set_dma_src_data_pack(ep->lch, 1);
741 omap_set_dma_dest_params(ep->lch,
750 ep->ep.name, dma_error, ep, &ep->lch);
754 omap_set_dma_src_params(ep->lch,
760 omap_set_dma_dest_burst_mode(ep->lch,
762 omap_set_dma_dest_data_pack(ep->lch, 1);
766 ep->dma_channel = 0;
768 ep->has_dma = 1;
769 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ);
773 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P);
778 restart = !ep->stopped && !list_empty(&ep->queue);
781 DBG("%s no dma channel: %d%s\n", ep->ep.name, status,
784 DBG("%s claimed %cxdma%d lch %d%s\n", ep->ep.name,
786 ep->dma_channel - 1, ep->lch,
791 req = container_of(ep->queue.next, struct omap_req, queue);
792 if (ep->has_dma)
793 (is_in ? next_in_dma : next_out_dma)(ep, req);
795 use_ep(ep, UDC_EP_SEL);
796 (is_in ? write_fifo : read_fifo)(ep, req);
800 ep->ackwait = 1 + ep->double_buf;
807 static void dma_channel_release(struct omap_ep *ep)
809 int shift = 4 * (ep->dma_channel - 1);
815 if (!list_empty(&ep->queue))
816 req = container_of(ep->queue.next, struct omap_req, queue);
820 active = omap_get_dma_active_status(ep->lch);
822 DBG("%s release %s %cxdma%d %p\n", ep->ep.name,
824 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r',
825 ep->dma_channel - 1, req);
832 if (ep->bEndpointAddress & USB_DIR_IN) {
837 finish_in_dma(ep, req, -ECONNRESET);
840 use_ep(ep, UDC_EP_SEL);
854 finish_out_dma(ep, req, -ECONNRESET, 0);
856 omap_free_dma(ep->lch);
857 ep->dma_channel = 0;
858 ep->lch = -1;
868 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
880 if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) {
881 DBG("%s, bad ep\n", __func__);
884 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) {
885 if (req->req.length > ep->ep.maxpacket)
894 && ep->has_dma
895 && ep->bEndpointAddress != 0
896 && (ep->bEndpointAddress & USB_DIR_IN) == 0
897 && (req->req.length % ep->ep.maxpacket) != 0) {
902 udc = ep->udc;
906 if (use_dma && ep->has_dma)
908 (ep->bEndpointAddress & USB_DIR_IN));
911 ep->ep.name, _req, _req->length, _req->buf);
925 } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) {
928 if (ep->bEndpointAddress == 0) {
929 if (!udc->ep0_pending || !list_empty(&ep->queue)) {
964 done(ep, req, 0);
977 is_in = ep->bEndpointAddress & USB_DIR_IN;
978 if (!ep->has_dma)
979 use_ep(ep, UDC_EP_SEL);
983 if (ep->has_dma)
984 (is_in ? next_in_dma : next_out_dma)(ep, req);
986 if ((is_in ? write_fifo : read_fifo)(ep, req) == 1)
991 ep->ackwait = 1 + ep->double_buf;
1000 list_add_tail(&req->queue, &ep->queue);
1008 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
1015 spin_lock_irqsave(&ep->udc->lock, flags);
1018 list_for_each_entry(iter, &ep->queue, queue) {
1025 spin_unlock_irqrestore(&ep->udc->lock, flags);
1029 if (use_dma && ep->dma_channel && ep->queue.next == &req->queue) {
1030 int channel = ep->dma_channel;
1035 dma_channel_release(ep);
1036 dma_channel_claim(ep, channel);
1038 done(ep, req, -ECONNRESET);
1039 spin_unlock_irqrestore(&ep->udc->lock, flags);
1047 struct omap_ep *ep = container_of(_ep, struct omap_ep, ep);
1051 spin_lock_irqsave(&ep->udc->lock, flags);
1054 if (ep->bEndpointAddress == 0) {
1055 if (!ep->udc->ep0_pending)
1058 if (ep->udc->ep0_set_config) {
1063 ep->udc->ep0_pending = 0;
1069 } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) {
1072 if ((ep->bEndpointAddress & USB_DIR_IN)
1073 && !list_empty(&ep->queue)) {
1081 if (use_dma && ep->dma_channel
1082 && !list_empty(&ep->queue)) {
1083 channel = ep->dma_channel;
1084 dma_channel_release(ep);
1088 use_ep(ep, UDC_EP_SEL);
1097 dma_channel_claim(ep, channel);
1099 use_ep(ep, 0);
1100 omap_writew(ep->udc->clr_halt, UDC_CTRL);
1101 ep->ackwait = 0;
1102 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1104 ep->ackwait = 1 + ep->double_buf;
1109 VDBG("%s %s halt stat %d\n", ep->ep.name,
1112 spin_unlock_irqrestore(&ep->udc->lock, flags);
1332 static void nuke(struct omap_ep *ep, int status)
1336 ep->stopped = 1;
1338 if (use_dma && ep->dma_channel)
1339 dma_channel_release(ep);
1341 use_ep(ep, 0);
1343 if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC)
1346 while (!list_empty(&ep->queue)) {
1347 req = list_entry(ep->queue.next, struct omap_req, queue);
1348 done(ep, req, status);
1355 struct omap_ep *ep;
1358 nuke(&udc->ep[0], -ESHUTDOWN);
1359 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list)
1360 nuke(ep, -ESHUTDOWN);
1396 struct omap_ep *ep0 = &udc->ep[0];
1516 struct omap_ep *ep;
1544 /* udc needs to know when ep != 0 is valid */
1570 ep = &udc->ep[w_index & 0xf];
1571 if (ep != ep0) {
1573 ep += 16;
1574 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1575 || !ep->ep.desc)
1577 use_ep(ep, 0);
1579 ep->ackwait = 0;
1580 if (!(ep->bEndpointAddress & USB_DIR_IN)) {
1582 ep->ackwait = 1 + ep->double_buf;
1590 VDBG("%s halt cleared by host\n", ep->name);
1599 ep = &udc->ep[w_index & 0xf];
1601 ep += 16;
1602 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC
1603 || ep == ep0 || !ep->ep.desc)
1605 if (use_dma && ep->has_dma) {
1609 DBG("%s host set_halt, NYET\n", ep->name);
1612 use_ep(ep, 0);
1616 VDBG("%s halted by host\n", ep->name);
1635 ep = &udc->ep[w_index & 0xf];
1637 ep += 16;
1638 if (!ep->ep.desc)
1642 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
1646 ERR("%s status, can't report\n", ep->ep.name);
1864 struct omap_ep *ep = from_timer(ep, t, timer);
1868 spin_lock_irqsave(&ep->udc->lock, flags);
1869 if (!list_empty(&ep->queue) && ep->ackwait) {
1870 use_ep(ep, UDC_EP_SEL);
1874 || (ep->double_buf && HALF_FULL(stat_flg)))) {
1877 VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg);
1878 req = container_of(ep->queue.next,
1880 (void) read_fifo(ep, req);
1881 omap_writew(ep->bEndpointAddress, UDC_EP_NUM);
1883 ep->ackwait = 1 + ep->double_buf;
1887 mod_timer(&ep->timer, PIO_OUT_TIMEOUT);
1888 spin_unlock_irqrestore(&ep->udc->lock, flags);
1895 struct omap_ep *ep;
1910 ep = &udc->ep[epnum];
1911 ep->irqs++;
1914 ep->fnf = 0;
1916 ep->ackwait--;
1917 if (!list_empty(&ep->queue)) {
1919 req = container_of(ep->queue.next,
1921 stat = read_fifo(ep, req);
1922 if (!ep->double_buf)
1923 ep->fnf = 1;
1934 if (ep->fnf) {
1936 ep->ackwait = 1 + ep->double_buf;
1938 mod_timer(&ep->timer, PIO_OUT_TIMEOUT);
1946 ep = &udc->ep[16 + epnum];
1947 ep->irqs++;
1951 ep->ackwait = 0;
1952 if (!list_empty(&ep->queue)) {
1953 req = container_of(ep->queue.next,
1955 (void) write_fifo(ep, req);
1973 struct omap_ep *ep;
1980 list_for_each_entry(ep, &udc->iso, iso) {
1984 if (ep->has_dma || list_empty(&ep->queue))
1986 req = list_entry(ep->queue.next, struct omap_req, queue);
1988 use_ep(ep, UDC_EP_SEL);
1994 if (ep->bEndpointAddress & USB_DIR_IN) {
1996 /* done(ep, req, -EPROTO) */;
1998 write_fifo(ep, req);
2010 /* done(ep, req, status) */;
2012 read_fifo(ep, req);
2017 ep->irqs++;
2018 if (!list_empty(&ep->queue))
2047 struct omap_ep *ep;
2053 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) {
2054 ep->irqs = 0;
2055 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC)
2057 use_ep(ep, 0);
2061 udc->ep[0].irqs = 0;
2141 static void proc_ep_show(struct seq_file *s, struct omap_ep *ep)
2147 use_ep(ep, 0);
2149 if (use_dma && ep->has_dma)
2151 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r',
2152 ep->dma_channel - 1, ep->lch);
2159 ep->name, buf,
2160 ep->double_buf ? "dbuf " : "",
2162 switch (ep->ackwait) {
2176 ep->irqs, stat_flg,
2191 if (list_empty(&ep->queue))
2194 list_for_each_entry(req, &ep->queue, queue) {
2198 length += ((ep->bEndpointAddress & USB_DIR_IN)
2200 (ep, req->req.dma + length);
2297 struct omap_ep *ep;
2423 proc_ep_show(s, &udc->ep[0]);
2425 list_for_each_entry(ep, &udc->gadget.ep_list,
2426 ep.ep_list) {
2427 if (ep->ep.desc)
2428 proc_ep_show(s, ep);
2467 struct omap_ep *ep;
2471 ep = &udc->ep[addr & 0xf];
2473 ep += 16;
2475 /* in case of ep init table bugs */
2476 BUG_ON(ep->name[0]);
2533 timer_setup(&ep->timer, pio_out_timer, 0);
2555 BUG_ON(strlen(name) >= sizeof ep->name);
2556 strscpy(ep->name, name, sizeof(ep->name));
2557 INIT_LIST_HEAD(&ep->queue);
2558 INIT_LIST_HEAD(&ep->iso);
2559 ep->bEndpointAddress = addr;
2560 ep->bmAttributes = type;
2561 ep->double_buf = dbuf;
2562 ep->udc = udc;
2566 ep->ep.caps.type_control = true;
2567 ep->ep.caps.dir_in = true;
2568 ep->ep.caps.dir_out = true;
2571 ep->ep.caps.type_iso = true;
2574 ep->ep.caps.type_bulk = true;
2577 ep->ep.caps.type_int = true;
2582 ep->ep.caps.dir_in = true;
2584 ep->ep.caps.dir_out = true;
2586 ep->ep.name = ep->name;
2587 ep->ep.ops = &omap_ep_ops;
2588 ep->maxpacket = maxp;
2589 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket);
2590 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list);
2640 udc->gadget.ep0 = &udc->ep[0].ep;
2652 list_del_init(&udc->ep[0].ep.ep_list);