Lines Matching +full:dbg +full:- +full:halt

1 // SPDX-License-Identifier: GPL-2.0+
3 * omap_udc.c -- for OMAP full speed udc; most chips support OTG.
6 * Copyright (C) 2004-2005 David Brownell
31 #include <linux/dma-mapping.h>
40 #include <asm/mach-types.h>
42 #include <linux/omap-dma.h>
43 #include <linux/platform_data/usb-omap1.h>
45 #include <linux/soc/ti/omap1-usb.h>
46 #include <linux/soc/ti/omap1-soc.h>
47 #include <linux/soc/ti/omap1-io.h>
75 * initialization to choose among a set of pre-defined endpoint configs.
113 /*-------------------------------------------------------------------------*/
121 u16 num = ep->bEndpointAddress & 0x0f; in use_ep()
123 if (ep->bEndpointAddress & USB_DIR_IN) in use_ep()
141 /*-------------------------------------------------------------------------*/
153 || desc->bDescriptorType != USB_DT_ENDPOINT in omap_ep_enable()
154 || ep->bEndpointAddress != desc->bEndpointAddress in omap_ep_enable()
155 || ep->maxpacket < usb_endpoint_maxp(desc)) { in omap_ep_enable()
156 DBG("%s, bad ep or descriptor\n", __func__); in omap_ep_enable()
157 return -EINVAL; in omap_ep_enable()
160 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK in omap_ep_enable()
161 && maxp != ep->maxpacket) in omap_ep_enable()
162 || usb_endpoint_maxp(desc) > ep->maxpacket in omap_ep_enable()
163 || !desc->wMaxPacketSize) { in omap_ep_enable()
164 DBG("%s, bad %s maxpacket\n", __func__, _ep->name); in omap_ep_enable()
165 return -ERANGE; in omap_ep_enable()
169 if ((desc->bmAttributes == USB_ENDPOINT_XFER_ISOC in omap_ep_enable()
170 && desc->bInterval != 1)) { in omap_ep_enable()
171 /* hardware wants period = 1; USB allows 2^(Interval-1) */ in omap_ep_enable()
172 DBG("%s, unsupported ISO period %dms\n", _ep->name, in omap_ep_enable()
173 1 << (desc->bInterval - 1)); in omap_ep_enable()
174 return -EDOM; in omap_ep_enable()
177 if (desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in omap_ep_enable()
178 DBG("%s, ISO nyet\n", _ep->name); in omap_ep_enable()
179 return -EDOM; in omap_ep_enable()
184 if (ep->bmAttributes != desc->bmAttributes in omap_ep_enable()
185 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK in omap_ep_enable()
186 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { in omap_ep_enable()
187 DBG("%s, %s type mismatch\n", __func__, _ep->name); in omap_ep_enable()
188 return -EINVAL; in omap_ep_enable()
191 udc = ep->udc; in omap_ep_enable()
192 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in omap_ep_enable()
193 DBG("%s, bogus device state\n", __func__); in omap_ep_enable()
194 return -ESHUTDOWN; in omap_ep_enable()
197 spin_lock_irqsave(&udc->lock, flags); in omap_ep_enable()
199 ep->ep.desc = desc; in omap_ep_enable()
200 ep->irqs = 0; in omap_ep_enable()
201 ep->stopped = 0; in omap_ep_enable()
202 ep->ep.maxpacket = maxp; in omap_ep_enable()
205 ep->dma_channel = 0; in omap_ep_enable()
206 ep->has_dma = 0; in omap_ep_enable()
207 ep->lch = -1; in omap_ep_enable()
209 omap_writew(udc->clr_halt, UDC_CTRL); in omap_ep_enable()
210 ep->ackwait = 0; in omap_ep_enable()
213 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in omap_ep_enable()
214 list_add(&ep->iso, &udc->iso); in omap_ep_enable()
217 if (use_dma && desc->bmAttributes == USB_ENDPOINT_XFER_BULK) in omap_ep_enable()
222 if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC in omap_ep_enable()
223 && !ep->has_dma in omap_ep_enable()
224 && !(ep->bEndpointAddress & USB_DIR_IN)) { in omap_ep_enable()
226 ep->ackwait = 1 + ep->double_buf; in omap_ep_enable()
229 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_enable()
230 VDBG("%s enabled\n", _ep->name); in omap_ep_enable()
241 if (!_ep || !ep->ep.desc) { in omap_ep_disable()
242 DBG("%s, %s not enabled\n", __func__, in omap_ep_disable()
243 _ep ? ep->ep.name : NULL); in omap_ep_disable()
244 return -EINVAL; in omap_ep_disable()
247 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_disable()
248 ep->ep.desc = NULL; in omap_ep_disable()
249 nuke(ep, -ESHUTDOWN); in omap_ep_disable()
250 ep->ep.maxpacket = ep->maxpacket; in omap_ep_disable()
251 ep->has_dma = 0; in omap_ep_disable()
253 list_del_init(&ep->iso); in omap_ep_disable()
254 del_timer(&ep->timer); in omap_ep_disable()
256 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_disable()
258 VDBG("%s disabled\n", _ep->name); in omap_ep_disable()
262 /*-------------------------------------------------------------------------*/
273 INIT_LIST_HEAD(&req->queue); in omap_alloc_request()
275 return &req->req; in omap_alloc_request()
286 /*-------------------------------------------------------------------------*/
291 struct omap_udc *udc = ep->udc; in done()
292 unsigned stopped = ep->stopped; in done()
294 list_del_init(&req->queue); in done()
296 if (req->req.status == -EINPROGRESS) in done()
297 req->req.status = status; in done()
299 status = req->req.status; in done()
301 if (use_dma && ep->has_dma) in done()
302 usb_gadget_unmap_request(&udc->gadget, &req->req, in done()
303 (ep->bEndpointAddress & USB_DIR_IN)); in done()
306 if (status && status != -ESHUTDOWN) in done()
309 ep->ep.name, &req->req, status, in done()
310 req->req.actual, req->req.length); in done()
313 ep->stopped = 1; in done()
314 spin_unlock(&ep->udc->lock); in done()
315 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
316 spin_lock(&ep->udc->lock); in done()
317 ep->stopped = stopped; in done()
320 /*-------------------------------------------------------------------------*/
334 len = min(req->req.length - req->req.actual, max); in write_packet()
335 req->req.actual += len; in write_packet()
342 max -= 2; in write_packet()
346 while (max--) in write_packet()
362 buf = req->req.buf + req->req.actual; in write_fifo()
365 /* PIO-IN isn't double buffered except for iso */ in write_fifo()
370 count = ep->ep.maxpacket; in write_fifo()
373 ep->ackwait = 1; in write_fifo()
376 if (count != ep->ep.maxpacket) in write_fifo()
378 else if (req->req.length == req->req.actual in write_fifo()
379 && !req->req.zero) in write_fifo()
399 len = min(req->req.length - req->req.actual, avail); in read_packet()
400 req->req.actual += len; in read_packet()
407 avail -= 2; in read_packet()
411 while (avail--) in read_packet()
423 buf = req->req.buf + req->req.actual; in read_fifo()
431 if (!ep->double_buf) in read_fifo()
433 ep->fnf = 1; in read_fifo()
439 avail = ep->ep.maxpacket; in read_fifo()
442 ep->fnf = ep->double_buf; in read_fifo()
447 if (count < ep->ep.maxpacket) { in read_fifo()
451 req->req.status = -EOVERFLOW; in read_fifo()
452 avail -= count; in read_fifo()
453 while (avail--) in read_fifo()
456 } else if (req->req.length == req->req.actual) in read_fifo()
461 if (!ep->bEndpointAddress) in read_fifo()
470 /*-------------------------------------------------------------------------*/
476 /* IN-DMA needs this on fault/cancel paths, so 15xx misreports in dma_src_len()
482 end = omap_get_dma_src_pos(ep->lch); in dma_src_len()
483 if (end == ep->dma_counter) in dma_src_len()
489 return end - start; in dma_src_len()
496 end = omap_get_dma_dst_pos(ep->lch); in dma_dest_len()
497 if (end == ep->dma_counter) in dma_dest_len()
505 return end - start; in dma_dest_len()
517 unsigned length = req->req.length - req->req.actual; in next_in_dma()
525 || (cpu_is_omap15xx() && length < ep->maxpacket)) { in next_in_dma()
527 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, in next_in_dma()
530 length = min(length / ep->maxpacket, in next_in_dma()
533 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, in next_in_dma()
534 ep->ep.maxpacket >> 1, length, sync_mode, in next_in_dma()
536 length *= ep->maxpacket; in next_in_dma()
538 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, in next_in_dma()
539 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, in next_in_dma()
542 omap_start_dma(ep->lch); in next_in_dma()
543 ep->dma_counter = omap_get_dma_src_pos(ep->lch); in next_in_dma()
545 w |= UDC_TX_DONE_IE(ep->dma_channel); in next_in_dma()
547 omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel)); in next_in_dma()
548 req->dma_bytes = length; in next_in_dma()
556 req->req.actual += req->dma_bytes; in finish_in_dma()
559 if (req->req.actual < req->req.length) in finish_in_dma()
561 if (req->req.zero in finish_in_dma()
562 && req->dma_bytes != 0 in finish_in_dma()
563 && (req->req.actual % ep->maxpacket) == 0) in finish_in_dma()
566 req->req.actual += dma_src_len(ep, req->req.dma in finish_in_dma()
567 + req->req.actual); in finish_in_dma()
570 omap_stop_dma(ep->lch); in finish_in_dma()
572 w &= ~UDC_TX_DONE_IE(ep->dma_channel); in finish_in_dma()
579 unsigned packets = req->req.length - req->req.actual; in next_out_dma()
584 packets /= ep->ep.maxpacket; in next_out_dma()
586 req->dma_bytes = packets * ep->ep.maxpacket; in next_out_dma()
587 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, in next_out_dma()
588 ep->ep.maxpacket >> 1, packets, in next_out_dma()
591 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, in next_out_dma()
592 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, in next_out_dma()
594 ep->dma_counter = omap_get_dma_dst_pos(ep->lch); in next_out_dma()
596 omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel)); in next_out_dma()
598 w |= UDC_RX_EOT_IE(ep->dma_channel); in next_out_dma()
600 omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM); in next_out_dma()
603 omap_start_dma(ep->lch); in next_out_dma()
612 ep->dma_counter = (u16) (req->req.dma + req->req.actual); in finish_out_dma()
613 count = dma_dest_len(ep, req->req.dma + req->req.actual); in finish_out_dma()
614 count += req->req.actual; in finish_out_dma()
616 count--; in finish_out_dma()
617 if (count <= req->req.length) in finish_out_dma()
618 req->req.actual = count; in finish_out_dma()
620 if (count != req->dma_bytes || status) in finish_out_dma()
621 omap_stop_dma(ep->lch); in finish_out_dma()
624 else if (req->req.actual < req->req.length) in finish_out_dma()
629 w &= ~UDC_RX_EOT_IE(ep->dma_channel); in finish_out_dma()
642 ep = &udc->ep[16 + UDC_DMA_TX_SRC(dman_stat)]; in dma_irq()
643 ep->irqs++; in dma_irq()
645 if (!list_empty(&ep->queue)) { in dma_irq()
646 req = container_of(ep->queue.next, in dma_irq()
652 if (!list_empty(&ep->queue)) { in dma_irq()
653 req = container_of(ep->queue.next, in dma_irq()
661 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; in dma_irq()
662 ep->irqs++; in dma_irq()
664 if (!list_empty(&ep->queue)) { in dma_irq()
665 req = container_of(ep->queue.next, in dma_irq()
671 if (!list_empty(&ep->queue)) { in dma_irq()
672 req = container_of(ep->queue.next, in dma_irq()
679 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; in dma_irq()
680 ep->irqs++; in dma_irq()
682 VDBG("%s, RX_CNT irq?\n", ep->ep.name); in dma_irq()
693 ERR("%s dma error, lch %d status %02x\n", ep->ep.name, lch, ch_status); in dma_error()
704 is_in = ep->bEndpointAddress & USB_DIR_IN; in dma_channel_claim()
711 ep->dma_channel = 0; in dma_channel_claim()
712 ep->lch = -1; in dma_channel_claim()
721 status = -EMLINK; in dma_channel_claim()
725 reg |= (0x0f & ep->bEndpointAddress) << (4 * (channel - 1)); in dma_channel_claim()
726 ep->dma_channel = channel; in dma_channel_claim()
729 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel; in dma_channel_claim()
731 ep->ep.name, dma_error, ep, &ep->lch); in dma_channel_claim()
735 omap_set_dma_src_burst_mode(ep->lch, in dma_channel_claim()
737 omap_set_dma_src_data_pack(ep->lch, 1); in dma_channel_claim()
739 omap_set_dma_dest_params(ep->lch, in dma_channel_claim()
746 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel; in dma_channel_claim()
748 ep->ep.name, dma_error, ep, &ep->lch); in dma_channel_claim()
752 omap_set_dma_src_params(ep->lch, in dma_channel_claim()
758 omap_set_dma_dest_burst_mode(ep->lch, in dma_channel_claim()
760 omap_set_dma_dest_data_pack(ep->lch, 1); in dma_channel_claim()
764 ep->dma_channel = 0; in dma_channel_claim()
766 ep->has_dma = 1; in dma_channel_claim()
767 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); in dma_channel_claim()
771 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); in dma_channel_claim()
776 restart = !ep->stopped && !list_empty(&ep->queue); in dma_channel_claim()
779 DBG("%s no dma channel: %d%s\n", ep->ep.name, status, in dma_channel_claim()
782 DBG("%s claimed %cxdma%d lch %d%s\n", ep->ep.name, in dma_channel_claim()
784 ep->dma_channel - 1, ep->lch, in dma_channel_claim()
789 req = container_of(ep->queue.next, struct omap_req, queue); in dma_channel_claim()
790 if (ep->has_dma) in dma_channel_claim()
798 ep->ackwait = 1 + ep->double_buf; in dma_channel_claim()
807 int shift = 4 * (ep->dma_channel - 1); in dma_channel_release()
813 if (!list_empty(&ep->queue)) in dma_channel_release()
814 req = container_of(ep->queue.next, struct omap_req, queue); in dma_channel_release()
818 active = omap_get_dma_active_status(ep->lch); in dma_channel_release()
820 DBG("%s release %s %cxdma%d %p\n", ep->ep.name, in dma_channel_release()
822 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', in dma_channel_release()
823 ep->dma_channel - 1, req); in dma_channel_release()
825 /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before in dma_channel_release()
830 if (ep->bEndpointAddress & USB_DIR_IN) { in dma_channel_release()
835 finish_in_dma(ep, req, -ECONNRESET); in dma_channel_release()
852 finish_out_dma(ep, req, -ECONNRESET, 0); in dma_channel_release()
854 omap_free_dma(ep->lch); in dma_channel_release()
855 ep->dma_channel = 0; in dma_channel_release()
856 ep->lch = -1; in dma_channel_release()
861 /*-------------------------------------------------------------------------*/
873 if (!_req || !req->req.complete || !req->req.buf in omap_ep_queue()
874 || !list_empty(&req->queue)) { in omap_ep_queue()
875 DBG("%s, bad params\n", __func__); in omap_ep_queue()
876 return -EINVAL; in omap_ep_queue()
878 if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) { in omap_ep_queue()
879 DBG("%s, bad ep\n", __func__); in omap_ep_queue()
880 return -EINVAL; in omap_ep_queue()
882 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in omap_ep_queue()
883 if (req->req.length > ep->ep.maxpacket) in omap_ep_queue()
884 return -EMSGSIZE; in omap_ep_queue()
892 && ep->has_dma in omap_ep_queue()
893 && ep->bEndpointAddress != 0 in omap_ep_queue()
894 && (ep->bEndpointAddress & USB_DIR_IN) == 0 in omap_ep_queue()
895 && (req->req.length % ep->ep.maxpacket) != 0) { in omap_ep_queue()
896 DBG("%s, no partial packet OUT reads\n", __func__); in omap_ep_queue()
897 return -EMSGSIZE; in omap_ep_queue()
900 udc = ep->udc; in omap_ep_queue()
901 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) in omap_ep_queue()
902 return -ESHUTDOWN; in omap_ep_queue()
904 if (use_dma && ep->has_dma) in omap_ep_queue()
905 usb_gadget_map_request(&udc->gadget, &req->req, in omap_ep_queue()
906 (ep->bEndpointAddress & USB_DIR_IN)); in omap_ep_queue()
909 ep->ep.name, _req, _req->length, _req->buf); in omap_ep_queue()
911 spin_lock_irqsave(&udc->lock, flags); in omap_ep_queue()
913 req->req.status = -EINPROGRESS; in omap_ep_queue()
914 req->req.actual = 0; in omap_ep_queue()
916 /* maybe kickstart non-iso i/o queues */ in omap_ep_queue()
923 } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) { in omap_ep_queue()
926 if (ep->bEndpointAddress == 0) { in omap_ep_queue()
927 if (!udc->ep0_pending || !list_empty(&ep->queue)) { in omap_ep_queue()
928 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_queue()
929 return -EL2HLT; in omap_ep_queue()
933 is_in = udc->ep0_in; in omap_ep_queue()
934 if (!req->req.length) { in omap_ep_queue()
938 * requests to non-control endpoints in omap_ep_queue()
940 if (udc->ep0_set_config) { in omap_ep_queue()
944 if (!udc->ep0_reset_config) in omap_ep_queue()
961 udc->ep0_pending = 0; in omap_ep_queue()
965 /* non-empty DATA stage */ in omap_ep_queue()
970 if (udc->ep0_setup) in omap_ep_queue()
975 is_in = ep->bEndpointAddress & USB_DIR_IN; in omap_ep_queue()
976 if (!ep->has_dma) in omap_ep_queue()
981 if (ep->has_dma) in omap_ep_queue()
989 ep->ackwait = 1 + ep->double_buf; in omap_ep_queue()
998 list_add_tail(&req->queue, &ep->queue); in omap_ep_queue()
999 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_queue()
1011 return -EINVAL; in omap_ep_dequeue()
1013 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_dequeue()
1016 list_for_each_entry(iter, &ep->queue, queue) { in omap_ep_dequeue()
1017 if (&iter->req != _req) in omap_ep_dequeue()
1023 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_dequeue()
1024 return -EINVAL; in omap_ep_dequeue()
1027 if (use_dma && ep->dma_channel && ep->queue.next == &req->queue) { in omap_ep_dequeue()
1028 int channel = ep->dma_channel; in omap_ep_dequeue()
1036 done(ep, req, -ECONNRESET); in omap_ep_dequeue()
1037 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_dequeue()
1041 /*-------------------------------------------------------------------------*/
1047 int status = -EOPNOTSUPP; in omap_ep_set_halt()
1049 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_set_halt()
1052 if (ep->bEndpointAddress == 0) { in omap_ep_set_halt()
1053 if (!ep->udc->ep0_pending) in omap_ep_set_halt()
1054 status = -EINVAL; in omap_ep_set_halt()
1056 if (ep->udc->ep0_set_config) { in omap_ep_set_halt()
1061 ep->udc->ep0_pending = 0; in omap_ep_set_halt()
1066 /* otherwise, all active non-ISO endpoints can halt */ in omap_ep_set_halt()
1067 } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) { in omap_ep_set_halt()
1070 if ((ep->bEndpointAddress & USB_DIR_IN) in omap_ep_set_halt()
1071 && !list_empty(&ep->queue)) { in omap_ep_set_halt()
1072 status = -EAGAIN; in omap_ep_set_halt()
1079 if (use_dma && ep->dma_channel in omap_ep_set_halt()
1080 && !list_empty(&ep->queue)) { in omap_ep_set_halt()
1081 channel = ep->dma_channel; in omap_ep_set_halt()
1091 status = -EAGAIN; in omap_ep_set_halt()
1098 omap_writew(ep->udc->clr_halt, UDC_CTRL); in omap_ep_set_halt()
1099 ep->ackwait = 0; in omap_ep_set_halt()
1100 if (!(ep->bEndpointAddress & USB_DIR_IN)) { in omap_ep_set_halt()
1102 ep->ackwait = 1 + ep->double_buf; in omap_ep_set_halt()
1107 VDBG("%s %s halt stat %d\n", ep->ep.name, in omap_ep_set_halt()
1110 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_set_halt()
1129 /*-------------------------------------------------------------------------*/
1134 return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC; in omap_get_frame()
1141 int retval = -EHOSTUNREACH; in omap_wakeup()
1145 spin_lock_irqsave(&udc->lock, flags); in omap_wakeup()
1146 if (udc->devstat & UDC_SUS) { in omap_wakeup()
1150 if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) { in omap_wakeup()
1151 DBG("remote wakeup...\n"); in omap_wakeup()
1156 /* NOTE: non-OTG systems may use SRP TOO... */ in omap_wakeup()
1157 } else if (!(udc->devstat & UDC_ATT)) { in omap_wakeup()
1158 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_wakeup()
1159 retval = otg_start_srp(udc->transceiver->otg); in omap_wakeup()
1161 spin_unlock_irqrestore(&udc->lock, flags); in omap_wakeup()
1173 gadget->is_selfpowered = (is_selfpowered != 0); in omap_set_selfpowered()
1175 spin_lock_irqsave(&udc->lock, flags); in omap_set_selfpowered()
1182 spin_unlock_irqrestore(&udc->lock, flags); in omap_set_selfpowered()
1189 return udc->driver && udc->softconnect && udc->vbus_active; in can_pullup()
1199 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { in pullup_enable()
1213 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { in pullup_disable()
1230 if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL) in omap_udc_enable_clock()
1234 clk_enable(udc->dc_clk); in omap_udc_enable_clock()
1235 clk_enable(udc->hhc_clk); in omap_udc_enable_clock()
1238 clk_disable(udc->hhc_clk); in omap_udc_enable_clock()
1239 clk_disable(udc->dc_clk); in omap_udc_enable_clock()
1254 spin_lock_irqsave(&udc->lock, flags); in omap_vbus_session()
1256 udc->vbus_active = (is_active != 0); in omap_vbus_session()
1266 if (udc->dc_clk != NULL && is_active) { in omap_vbus_session()
1267 if (!udc->clk_requested) { in omap_vbus_session()
1269 udc->clk_requested = 1; in omap_vbus_session()
1276 if (udc->dc_clk != NULL && !is_active) { in omap_vbus_session()
1277 if (udc->clk_requested) { in omap_vbus_session()
1279 udc->clk_requested = 0; in omap_vbus_session()
1282 spin_unlock_irqrestore(&udc->lock, flags); in omap_vbus_session()
1291 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_vbus_draw()
1292 return usb_phy_set_power(udc->transceiver, mA); in omap_vbus_draw()
1293 return -EOPNOTSUPP; in omap_vbus_draw()
1302 spin_lock_irqsave(&udc->lock, flags); in omap_pullup()
1303 udc->softconnect = (is_on != 0); in omap_pullup()
1308 spin_unlock_irqrestore(&udc->lock, flags); in omap_pullup()
1327 /*-------------------------------------------------------------------------*/
1329 /* dequeue ALL requests; caller holds udc->lock */
1334 ep->stopped = 1; in nuke()
1336 if (use_dma && ep->dma_channel) in nuke()
1341 if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC) in nuke()
1344 while (!list_empty(&ep->queue)) { in nuke()
1345 req = list_entry(ep->queue.next, struct omap_req, queue); in nuke()
1350 /* caller holds udc->lock */
1355 udc->gadget.speed = USB_SPEED_UNKNOWN; in udc_quiesce()
1356 nuke(&udc->ep[0], -ESHUTDOWN); in udc_quiesce()
1357 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) in udc_quiesce()
1358 nuke(ep, -ESHUTDOWN); in udc_quiesce()
1361 /*-------------------------------------------------------------------------*/
1367 if (!gadget_is_otg(&udc->gadget)) in update_otg()
1375 udc->gadget.b_hnp_enable = !!(devstat & UDC_B_HNP_ENABLE); in update_otg()
1376 udc->gadget.a_hnp_support = !!(devstat & UDC_A_HNP_SUPPORT); in update_otg()
1377 udc->gadget.a_alt_hnp_support = !!(devstat & UDC_A_ALT_HNP_SUPPORT); in update_otg()
1382 if (udc->gadget.b_hnp_enable) { in update_otg()
1394 struct omap_ep *ep0 = &udc->ep[0]; in ep0_irq()
1397 ep0->irqs++; in ep0_irq()
1420 if (!list_empty(&ep0->queue)) in ep0_irq()
1421 req = container_of(ep0->queue.next, struct omap_req, queue); in ep0_irq()
1431 if (udc->ep0_in) { in ep0_irq()
1438 if (!req && udc->ep0_pending) { in ep0_irq()
1443 udc->ep0_pending = 0; in ep0_irq()
1468 if (!udc->ep0_in) { in ep0_irq()
1476 udc->ep0_pending = 0; in ep0_irq()
1491 udc->ep0_pending = 0; in ep0_irq()
1513 int status = -EINVAL; in ep0_irq()
1535 udc->ep0_in = (u.r.bRequestType & USB_DIR_IN) != 0; in ep0_irq()
1536 udc->ep0_set_config = 0; in ep0_irq()
1537 udc->ep0_pending = 1; in ep0_irq()
1538 ep0->stopped = 0; in ep0_irq()
1539 ep0->ackwait = 0; in ep0_irq()
1547 udc->ep0_set_config = 1; in ep0_irq()
1548 udc->ep0_reset_config = (w_value == 0); in ep0_irq()
1555 if (udc->ep0_reset_config) in ep0_irq()
1562 /* clear endpoint halt */ in ep0_irq()
1568 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1572 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in ep0_irq()
1573 || !ep->ep.desc) in ep0_irq()
1576 omap_writew(udc->clr_halt, UDC_CTRL); in ep0_irq()
1577 ep->ackwait = 0; in ep0_irq()
1578 if (!(ep->bEndpointAddress & USB_DIR_IN)) { in ep0_irq()
1580 ep->ackwait = 1 + ep->double_buf; in ep0_irq()
1588 VDBG("%s halt cleared by host\n", ep->name); in ep0_irq()
1591 /* set endpoint halt */ in ep0_irq()
1597 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1600 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in ep0_irq()
1601 || ep == ep0 || !ep->ep.desc) in ep0_irq()
1603 if (use_dma && ep->has_dma) { in ep0_irq()
1604 /* this has rude side-effects (aborts) and in ep0_irq()
1605 * can't really work if DMA-IN is active in ep0_irq()
1607 DBG("%s host set_halt, NYET\n", ep->name); in ep0_irq()
1611 /* can't halt if fifo isn't empty... */ in ep0_irq()
1614 VDBG("%s halted by host\n", ep->name); in ep0_irq()
1621 udc->ep0_pending = 0; in ep0_irq()
1633 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1636 if (!ep->ep.desc) in ep0_irq()
1640 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in ep0_irq()
1643 /* FIXME don't assume non-halted endpoints!! */ in ep0_irq()
1644 ERR("%s status, can't report\n", ep->ep.name); in ep0_irq()
1649 * we'd detect non-existent interfaces, and stall. in ep0_irq()
1668 if (!udc->ep0_in && w_length) { in ep0_irq()
1690 * (causing a protocol stall, not a real halt). A in ep0_irq()
1696 udc->ep0_setup = 1; in ep0_irq()
1697 spin_unlock(&udc->lock); in ep0_irq()
1698 status = udc->driver->setup(&udc->gadget, &u.r); in ep0_irq()
1699 spin_lock(&udc->lock); in ep0_irq()
1700 udc->ep0_setup = 0; in ep0_irq()
1707 if (udc->ep0_set_config) { in ep0_irq()
1708 if (udc->ep0_reset_config) in ep0_irq()
1714 udc->ep0_pending = 0; in ep0_irq()
1719 /*-------------------------------------------------------------------------*/
1728 change = devstat ^ udc->devstat; in devstate_irq()
1729 udc->devstat = devstat; in devstate_irq()
1739 udc->gadget.speed = USB_SPEED_FULL; in devstate_irq()
1741 if (IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1743 /* if (driver->connect) call it */ in devstate_irq()
1744 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { in devstate_irq()
1745 udc->gadget.speed = USB_SPEED_UNKNOWN; in devstate_irq()
1746 if (IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1748 DBG("disconnect, gadget %s\n", in devstate_irq()
1749 udc->driver->driver.name); in devstate_irq()
1750 if (udc->driver->disconnect) { in devstate_irq()
1751 spin_unlock(&udc->lock); in devstate_irq()
1752 udc->driver->disconnect(&udc->gadget); in devstate_irq()
1753 spin_lock(&udc->lock); in devstate_irq()
1763 udc->gadget.speed = USB_SPEED_FULL; in devstate_irq()
1765 udc->driver->driver.name); in devstate_irq()
1774 if (udc->gadget.speed != USB_SPEED_UNKNOWN) { in devstate_irq()
1780 if (udc->gadget.speed == USB_SPEED_FULL in devstate_irq()
1781 && udc->driver->suspend) { in devstate_irq()
1782 spin_unlock(&udc->lock); in devstate_irq()
1783 udc->driver->suspend(&udc->gadget); in devstate_irq()
1784 spin_lock(&udc->lock); in devstate_irq()
1786 if (!IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1788 udc->transceiver, 1); in devstate_irq()
1791 if (!IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1793 udc->transceiver, 0); in devstate_irq()
1794 if (udc->gadget.speed == USB_SPEED_FULL in devstate_irq()
1795 && udc->driver->resume) { in devstate_irq()
1796 spin_unlock(&udc->lock); in devstate_irq()
1797 udc->driver->resume(&udc->gadget); in devstate_irq()
1798 spin_lock(&udc->lock); in devstate_irq()
1824 spin_lock_irqsave(&udc->lock, flags); in omap_udc_irq()
1850 DBG("udc_irq, unhandled %03x\n", irq_src); in omap_udc_irq()
1851 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_irq()
1856 /* workaround for seemingly-lost IRQs for RX ACKs... */
1866 spin_lock_irqsave(&ep->udc->lock, flags); in pio_out_timer()
1867 if (!list_empty(&ep->queue) && ep->ackwait) { in pio_out_timer()
1872 || (ep->double_buf && HALF_FULL(stat_flg)))) { in pio_out_timer()
1875 VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); in pio_out_timer()
1876 req = container_of(ep->queue.next, in pio_out_timer()
1879 omap_writew(ep->bEndpointAddress, UDC_EP_NUM); in pio_out_timer()
1881 ep->ackwait = 1 + ep->double_buf; in pio_out_timer()
1885 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); in pio_out_timer()
1886 spin_unlock_irqrestore(&ep->udc->lock, flags); in pio_out_timer()
1899 spin_lock_irqsave(&udc->lock, flags); in omap_udc_pio_irq()
1908 ep = &udc->ep[epnum]; in omap_udc_pio_irq()
1909 ep->irqs++; in omap_udc_pio_irq()
1912 ep->fnf = 0; in omap_udc_pio_irq()
1914 ep->ackwait--; in omap_udc_pio_irq()
1915 if (!list_empty(&ep->queue)) { in omap_udc_pio_irq()
1917 req = container_of(ep->queue.next, in omap_udc_pio_irq()
1920 if (!ep->double_buf) in omap_udc_pio_irq()
1921 ep->fnf = 1; in omap_udc_pio_irq()
1932 if (ep->fnf) { in omap_udc_pio_irq()
1934 ep->ackwait = 1 + ep->double_buf; in omap_udc_pio_irq()
1936 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); in omap_udc_pio_irq()
1944 ep = &udc->ep[16 + epnum]; in omap_udc_pio_irq()
1945 ep->irqs++; in omap_udc_pio_irq()
1949 ep->ackwait = 0; in omap_udc_pio_irq()
1950 if (!list_empty(&ep->queue)) { in omap_udc_pio_irq()
1951 req = container_of(ep->queue.next, in omap_udc_pio_irq()
1963 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_pio_irq()
1975 spin_lock_irqsave(&udc->lock, flags); in omap_udc_iso_irq()
1977 /* handle all non-DMA ISO transfers */ in omap_udc_iso_irq()
1978 list_for_each_entry(ep, &udc->iso, iso) { in omap_udc_iso_irq()
1982 if (ep->has_dma || list_empty(&ep->queue)) in omap_udc_iso_irq()
1984 req = list_entry(ep->queue.next, struct omap_req, queue); in omap_udc_iso_irq()
1992 if (ep->bEndpointAddress & USB_DIR_IN) { in omap_udc_iso_irq()
1994 /* done(ep, req, -EPROTO) */; in omap_udc_iso_irq()
2001 status = -EREMOTEIO; in omap_udc_iso_irq()
2003 status = -EILSEQ; in omap_udc_iso_irq()
2005 status = -ENOSR; in omap_udc_iso_irq()
2015 ep->irqs++; in omap_udc_iso_irq()
2016 if (!list_empty(&ep->queue)) in omap_udc_iso_irq()
2028 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_iso_irq()
2033 /*-------------------------------------------------------------------------*/
2049 spin_lock_irqsave(&udc->lock, flags); in omap_udc_start()
2051 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { in omap_udc_start()
2052 ep->irqs = 0; in omap_udc_start()
2053 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in omap_udc_start()
2058 udc->ep0_pending = 0; in omap_udc_start()
2059 udc->ep[0].irqs = 0; in omap_udc_start()
2060 udc->softconnect = 1; in omap_udc_start()
2063 udc->driver = driver; in omap_udc_start()
2064 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_start()
2066 if (udc->dc_clk != NULL) in omap_udc_start()
2072 if (!IS_ERR_OR_NULL(udc->transceiver)) { in omap_udc_start()
2073 status = otg_set_peripheral(udc->transceiver->otg, in omap_udc_start()
2074 &udc->gadget); in omap_udc_start()
2077 udc->driver = NULL; in omap_udc_start()
2092 omap_vbus_session(&udc->gadget, 1); in omap_udc_start()
2095 if (udc->dc_clk != NULL) in omap_udc_start()
2105 if (udc->dc_clk != NULL) in omap_udc_stop()
2109 omap_vbus_session(&udc->gadget, 0); in omap_udc_stop()
2111 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_udc_stop()
2112 (void) otg_set_peripheral(udc->transceiver->otg, NULL); in omap_udc_stop()
2116 spin_lock_irqsave(&udc->lock, flags); in omap_udc_stop()
2118 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_stop()
2120 udc->driver = NULL; in omap_udc_stop()
2122 if (udc->dc_clk != NULL) in omap_udc_stop()
2128 /*-------------------------------------------------------------------------*/
2147 if (use_dma && ep->has_dma) in proc_ep_show()
2149 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', in proc_ep_show()
2150 ep->dma_channel - 1, ep->lch); in proc_ep_show()
2157 ep->name, buf, in proc_ep_show()
2158 ep->double_buf ? "dbuf " : "", in proc_ep_show()
2160 switch (ep->ackwait) { in proc_ep_show()
2174 ep->irqs, stat_flg, in proc_ep_show()
2181 (stat_flg & UDC_EP_HALTED) ? "HALT " : "", in proc_ep_show()
2189 if (list_empty(&ep->queue)) in proc_ep_show()
2192 list_for_each_entry(req, &ep->queue, queue) { in proc_ep_show()
2193 unsigned length = req->req.actual; in proc_ep_show()
2196 length += ((ep->bEndpointAddress & USB_DIR_IN) in proc_ep_show()
2198 (ep, req->req.dma + length); in proc_ep_show()
2202 &req->req, length, in proc_ep_show()
2203 req->req.length, req->req.buf); in proc_ep_show()
2298 spin_lock_irqsave(&udc->lock, flags); in proc_udc_show()
2312 udc->driver ? udc->driver->driver.name : "(none)", in proc_udc_show()
2314 udc->transceiver in proc_udc_show()
2315 ? udc->transceiver->label in proc_udc_show()
2337 /* syscon2 is write-only */ in proc_udc_show()
2342 spin_unlock_irqrestore(&udc->lock, flags); in proc_udc_show()
2419 proc_ep_show(s, &udc->ep[0]); in proc_udc_show()
2421 list_for_each_entry(ep, &udc->gadget.ep_list, in proc_udc_show()
2423 if (ep->ep.desc) in proc_udc_show()
2428 spin_unlock_irqrestore(&udc->lock, flags); in proc_udc_show()
2449 /*-------------------------------------------------------------------------*/
2467 ep = &udc->ep[addr & 0xf]; in omap_ep_setup()
2472 BUG_ON(ep->name[0]); in omap_ep_setup()
2504 /* double-buffering "not supported" on 15xx, in omap_ep_setup()
2505 * and ignored for PIO-IN on newer chips in omap_ep_setup()
2529 timer_setup(&ep->timer, pio_out_timer, 0); in omap_ep_setup()
2536 DBG("%s addr %02x rxtx %04x maxp %d%s buf %d\n", in omap_ep_setup()
2551 BUG_ON(strlen(name) >= sizeof ep->name); in omap_ep_setup()
2552 strscpy(ep->name, name, sizeof(ep->name)); in omap_ep_setup()
2553 INIT_LIST_HEAD(&ep->queue); in omap_ep_setup()
2554 INIT_LIST_HEAD(&ep->iso); in omap_ep_setup()
2555 ep->bEndpointAddress = addr; in omap_ep_setup()
2556 ep->bmAttributes = type; in omap_ep_setup()
2557 ep->double_buf = dbuf; in omap_ep_setup()
2558 ep->udc = udc; in omap_ep_setup()
2562 ep->ep.caps.type_control = true; in omap_ep_setup()
2563 ep->ep.caps.dir_in = true; in omap_ep_setup()
2564 ep->ep.caps.dir_out = true; in omap_ep_setup()
2567 ep->ep.caps.type_iso = true; in omap_ep_setup()
2570 ep->ep.caps.type_bulk = true; in omap_ep_setup()
2573 ep->ep.caps.type_int = true; in omap_ep_setup()
2578 ep->ep.caps.dir_in = true; in omap_ep_setup()
2580 ep->ep.caps.dir_out = true; in omap_ep_setup()
2582 ep->ep.name = ep->name; in omap_ep_setup()
2583 ep->ep.ops = &omap_ep_ops; in omap_ep_setup()
2584 ep->maxpacket = maxp; in omap_ep_setup()
2585 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); in omap_ep_setup()
2586 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in omap_ep_setup()
2594 if (!IS_ERR_OR_NULL(udc->transceiver)) { in omap_udc_release()
2595 usb_put_phy(udc->transceiver); in omap_udc_release()
2596 udc->transceiver = NULL; in omap_udc_release()
2600 if (udc->dc_clk) { in omap_udc_release()
2601 if (udc->clk_requested) in omap_udc_release()
2603 clk_unprepare(udc->hhc_clk); in omap_udc_release()
2604 clk_unprepare(udc->dc_clk); in omap_udc_release()
2605 clk_put(udc->hhc_clk); in omap_udc_release()
2606 clk_put(udc->dc_clk); in omap_udc_release()
2608 if (udc->done) in omap_udc_release()
2609 complete(udc->done); in omap_udc_release()
2631 return -ENOMEM; in omap_udc_setup()
2633 spin_lock_init(&udc->lock); in omap_udc_setup()
2635 udc->gadget.ops = &omap_gadget_ops; in omap_udc_setup()
2636 udc->gadget.ep0 = &udc->ep[0].ep; in omap_udc_setup()
2637 INIT_LIST_HEAD(&udc->gadget.ep_list); in omap_udc_setup()
2638 INIT_LIST_HEAD(&udc->iso); in omap_udc_setup()
2639 udc->gadget.speed = USB_SPEED_UNKNOWN; in omap_udc_setup()
2640 udc->gadget.max_speed = USB_SPEED_FULL; in omap_udc_setup()
2641 udc->gadget.name = driver_name; in omap_udc_setup()
2642 udc->gadget.quirk_ep_out_aligned_size = 1; in omap_udc_setup()
2643 udc->transceiver = xceiv; in omap_udc_setup()
2648 list_del_init(&udc->ep[0].ep.ep_list); in omap_udc_setup()
2650 /* initially disable all non-ep0 endpoints */ in omap_udc_setup()
2657 buf = omap_ep_setup(name "-bulk", addr, \ in omap_udc_setup()
2660 buf = omap_ep_setup(name "-int", addr, \ in omap_udc_setup()
2663 buf = omap_ep_setup(name "-iso", addr, \ in omap_udc_setup()
2736 return -ENODEV; in omap_udc_setup()
2739 INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf); in omap_udc_setup()
2745 int status = -ENODEV; in omap_udc_probe()
2749 struct omap_usb_config *config = dev_get_platdata(&pdev->dev); in omap_udc_probe()
2754 if (!request_mem_region(pdev->resource[0].start, in omap_udc_probe()
2755 resource_size(&pdev->resource[0]), in omap_udc_probe()
2757 DBG("request_mem_region failed\n"); in omap_udc_probe()
2758 return -EBUSY; in omap_udc_probe()
2762 dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); in omap_udc_probe()
2763 hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck"); in omap_udc_probe()
2773 config->otg ? ", Mini-AB" : ""); in omap_udc_probe()
2802 type = xceiv->label; in omap_udc_probe()
2803 else if (config->otg) { in omap_udc_probe()
2804 DBG("OTG requires external transceiver!\n"); in omap_udc_probe()
2826 DBG("external transceiver not registered!\n"); in omap_udc_probe()
2860 udc->gadget.is_otg = (config->otg != 0); in omap_udc_probe()
2865 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; in omap_udc_probe()
2867 udc->clr_halt = UDC_RESET_EP; in omap_udc_probe()
2870 status = devm_request_irq(&pdev->dev, pdev->resource[1].start, in omap_udc_probe()
2874 (int) pdev->resource[1].start, status); in omap_udc_probe()
2878 /* USB "non-iso" IRQ (PIO for all but ep0) */ in omap_udc_probe()
2879 status = devm_request_irq(&pdev->dev, pdev->resource[2].start, in omap_udc_probe()
2883 (int) pdev->resource[2].start, status); in omap_udc_probe()
2887 status = devm_request_irq(&pdev->dev, pdev->resource[3].start, in omap_udc_probe()
2891 (int) pdev->resource[3].start, status); in omap_udc_probe()
2896 udc->dc_clk = dc_clk; in omap_udc_probe()
2897 udc->hhc_clk = hhc_clk; in omap_udc_probe()
2903 return usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, in omap_udc_probe()
2921 release_mem_region(pdev->resource[0].start, in omap_udc_probe()
2922 resource_size(&pdev->resource[0])); in omap_udc_probe()
2931 udc->done = &done; in omap_udc_remove()
2933 usb_del_gadget_udc(&udc->gadget); in omap_udc_remove()
2937 release_mem_region(pdev->resource[0].start, in omap_udc_remove()
2938 resource_size(&pdev->resource[0])); in omap_udc_remove()
2963 omap_pullup(&udc->gadget, 0); in omap_udc_suspend()
2971 DBG("resume + wakeup/SRP\n"); in omap_udc_resume()
2972 omap_pullup(&udc->gadget, 1); in omap_udc_resume()
2976 return omap_wakeup(&udc->gadget); in omap_udc_resume()
2979 /*-------------------------------------------------------------------------*/