Lines Matching +full:can +full:- +full:transceiver
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
32 #include <linux/dma-mapping.h>
41 #include <asm/mach-types.h>
43 #include <linux/omap-dma.h>
44 #include <linux/platform_data/usb-omap1.h>
46 #include <linux/soc/ti/omap1-usb.h>
47 #include <linux/soc/ti/omap1-soc.h>
48 #include <linux/soc/ti/omap1-io.h>
76 * initialization to choose among a set of pre-defined endpoint configs.
114 /*-------------------------------------------------------------------------*/
122 u16 num = ep->bEndpointAddress & 0x0f; in use_ep()
124 if (ep->bEndpointAddress & USB_DIR_IN) in use_ep()
142 /*-------------------------------------------------------------------------*/
154 || desc->bDescriptorType != USB_DT_ENDPOINT in omap_ep_enable()
155 || ep->bEndpointAddress != desc->bEndpointAddress in omap_ep_enable()
156 || ep->maxpacket < usb_endpoint_maxp(desc)) { in omap_ep_enable()
158 return -EINVAL; in omap_ep_enable()
161 if ((desc->bmAttributes == USB_ENDPOINT_XFER_BULK in omap_ep_enable()
162 && maxp != ep->maxpacket) in omap_ep_enable()
163 || usb_endpoint_maxp(desc) > ep->maxpacket in omap_ep_enable()
164 || !desc->wMaxPacketSize) { in omap_ep_enable()
165 DBG("%s, bad %s maxpacket\n", __func__, _ep->name); in omap_ep_enable()
166 return -ERANGE; in omap_ep_enable()
170 if ((desc->bmAttributes == USB_ENDPOINT_XFER_ISOC in omap_ep_enable()
171 && desc->bInterval != 1)) { in omap_ep_enable()
172 /* hardware wants period = 1; USB allows 2^(Interval-1) */ in omap_ep_enable()
173 DBG("%s, unsupported ISO period %dms\n", _ep->name, in omap_ep_enable()
174 1 << (desc->bInterval - 1)); in omap_ep_enable()
175 return -EDOM; in omap_ep_enable()
178 if (desc->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in omap_ep_enable()
179 DBG("%s, ISO nyet\n", _ep->name); in omap_ep_enable()
180 return -EDOM; in omap_ep_enable()
185 if (ep->bmAttributes != desc->bmAttributes in omap_ep_enable()
186 && ep->bmAttributes != USB_ENDPOINT_XFER_BULK in omap_ep_enable()
187 && desc->bmAttributes != USB_ENDPOINT_XFER_INT) { in omap_ep_enable()
188 DBG("%s, %s type mismatch\n", __func__, _ep->name); in omap_ep_enable()
189 return -EINVAL; in omap_ep_enable()
192 udc = ep->udc; in omap_ep_enable()
193 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) { in omap_ep_enable()
195 return -ESHUTDOWN; in omap_ep_enable()
198 spin_lock_irqsave(&udc->lock, flags); in omap_ep_enable()
200 ep->ep.desc = desc; in omap_ep_enable()
201 ep->irqs = 0; in omap_ep_enable()
202 ep->stopped = 0; in omap_ep_enable()
203 ep->ep.maxpacket = maxp; in omap_ep_enable()
206 ep->dma_channel = 0; in omap_ep_enable()
207 ep->has_dma = 0; in omap_ep_enable()
208 ep->lch = -1; in omap_ep_enable()
210 omap_writew(udc->clr_halt, UDC_CTRL); in omap_ep_enable()
211 ep->ackwait = 0; in omap_ep_enable()
214 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in omap_ep_enable()
215 list_add(&ep->iso, &udc->iso); in omap_ep_enable()
218 if (use_dma && desc->bmAttributes == USB_ENDPOINT_XFER_BULK) in omap_ep_enable()
219 /* FIXME ISO can dma, but prefers first channel */ in omap_ep_enable()
223 if (desc->bmAttributes != USB_ENDPOINT_XFER_ISOC in omap_ep_enable()
224 && !ep->has_dma in omap_ep_enable()
225 && !(ep->bEndpointAddress & USB_DIR_IN)) { in omap_ep_enable()
227 ep->ackwait = 1 + ep->double_buf; in omap_ep_enable()
230 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_enable()
231 VDBG("%s enabled\n", _ep->name); in omap_ep_enable()
242 if (!_ep || !ep->ep.desc) { in omap_ep_disable()
244 _ep ? ep->ep.name : NULL); in omap_ep_disable()
245 return -EINVAL; in omap_ep_disable()
248 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_disable()
249 ep->ep.desc = NULL; in omap_ep_disable()
250 nuke(ep, -ESHUTDOWN); in omap_ep_disable()
251 ep->ep.maxpacket = ep->maxpacket; in omap_ep_disable()
252 ep->has_dma = 0; in omap_ep_disable()
254 list_del_init(&ep->iso); in omap_ep_disable()
255 del_timer(&ep->timer); in omap_ep_disable()
257 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_disable()
259 VDBG("%s disabled\n", _ep->name); in omap_ep_disable()
263 /*-------------------------------------------------------------------------*/
274 INIT_LIST_HEAD(&req->queue); in omap_alloc_request()
276 return &req->req; in omap_alloc_request()
287 /*-------------------------------------------------------------------------*/
292 struct omap_udc *udc = ep->udc; in done()
293 unsigned stopped = ep->stopped; in done()
295 list_del_init(&req->queue); in done()
297 if (req->req.status == -EINPROGRESS) in done()
298 req->req.status = status; in done()
300 status = req->req.status; in done()
302 if (use_dma && ep->has_dma) in done()
303 usb_gadget_unmap_request(&udc->gadget, &req->req, in done()
304 (ep->bEndpointAddress & USB_DIR_IN)); in done()
307 if (status && status != -ESHUTDOWN) in done()
310 ep->ep.name, &req->req, status, in done()
311 req->req.actual, req->req.length); in done()
314 ep->stopped = 1; in done()
315 spin_unlock(&ep->udc->lock); in done()
316 usb_gadget_giveback_request(&ep->ep, &req->req); in done()
317 spin_lock(&ep->udc->lock); in done()
318 ep->stopped = stopped; in done()
321 /*-------------------------------------------------------------------------*/
335 len = min(req->req.length - req->req.actual, max); in write_packet()
336 req->req.actual += len; in write_packet()
343 max -= 2; in write_packet()
347 while (max--) in write_packet()
363 buf = req->req.buf + req->req.actual; in write_fifo()
366 /* PIO-IN isn't double buffered except for iso */ in write_fifo()
371 count = ep->ep.maxpacket; in write_fifo()
374 ep->ackwait = 1; in write_fifo()
377 if (count != ep->ep.maxpacket) in write_fifo()
379 else if (req->req.length == req->req.actual in write_fifo()
380 && !req->req.zero) in write_fifo()
400 len = min(req->req.length - req->req.actual, avail); in read_packet()
401 req->req.actual += len; in read_packet()
408 avail -= 2; in read_packet()
412 while (avail--) in read_packet()
424 buf = req->req.buf + req->req.actual; in read_fifo()
432 if (!ep->double_buf) in read_fifo()
434 ep->fnf = 1; in read_fifo()
440 avail = ep->ep.maxpacket; in read_fifo()
443 ep->fnf = ep->double_buf; in read_fifo()
448 if (count < ep->ep.maxpacket) { in read_fifo()
452 req->req.status = -EOVERFLOW; in read_fifo()
453 avail -= count; in read_fifo()
454 while (avail--) in read_fifo()
457 } else if (req->req.length == req->req.actual) in read_fifo()
462 if (!ep->bEndpointAddress) in read_fifo()
471 /*-------------------------------------------------------------------------*/
477 /* IN-DMA needs this on fault/cancel paths, so 15xx misreports in dma_src_len()
483 end = omap_get_dma_src_pos(ep->lch); in dma_src_len()
484 if (end == ep->dma_counter) in dma_src_len()
490 return end - start; in dma_src_len()
497 end = omap_get_dma_dst_pos(ep->lch); in dma_dest_len()
498 if (end == ep->dma_counter) in dma_dest_len()
506 return end - start; in dma_dest_len()
518 unsigned length = req->req.length - req->req.actual; in next_in_dma()
526 || (cpu_is_omap15xx() && length < ep->maxpacket)) { in next_in_dma()
528 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S8, in next_in_dma()
531 length = min(length / ep->maxpacket, in next_in_dma()
534 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, in next_in_dma()
535 ep->ep.maxpacket >> 1, length, sync_mode, in next_in_dma()
537 length *= ep->maxpacket; in next_in_dma()
539 omap_set_dma_src_params(ep->lch, OMAP_DMA_PORT_EMIFF, in next_in_dma()
540 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, in next_in_dma()
543 omap_start_dma(ep->lch); in next_in_dma()
544 ep->dma_counter = omap_get_dma_src_pos(ep->lch); in next_in_dma()
546 w |= UDC_TX_DONE_IE(ep->dma_channel); in next_in_dma()
548 omap_writew(UDC_TXN_START | txdma_ctrl, UDC_TXDMA(ep->dma_channel)); in next_in_dma()
549 req->dma_bytes = length; in next_in_dma()
557 req->req.actual += req->dma_bytes; in finish_in_dma()
560 if (req->req.actual < req->req.length) in finish_in_dma()
562 if (req->req.zero in finish_in_dma()
563 && req->dma_bytes != 0 in finish_in_dma()
564 && (req->req.actual % ep->maxpacket) == 0) in finish_in_dma()
567 req->req.actual += dma_src_len(ep, req->req.dma in finish_in_dma()
568 + req->req.actual); in finish_in_dma()
571 omap_stop_dma(ep->lch); in finish_in_dma()
573 w &= ~UDC_TX_DONE_IE(ep->dma_channel); in finish_in_dma()
580 unsigned int packets = req->req.length - req->req.actual; in next_out_dma()
585 packets /= ep->ep.maxpacket; in next_out_dma()
587 req->dma_bytes = packets * ep->ep.maxpacket; in next_out_dma()
588 omap_set_dma_transfer_params(ep->lch, OMAP_DMA_DATA_TYPE_S16, in next_out_dma()
589 ep->ep.maxpacket >> 1, packets, in next_out_dma()
592 omap_set_dma_dest_params(ep->lch, OMAP_DMA_PORT_EMIFF, in next_out_dma()
593 OMAP_DMA_AMODE_POST_INC, req->req.dma + req->req.actual, in next_out_dma()
595 ep->dma_counter = omap_get_dma_dst_pos(ep->lch); in next_out_dma()
597 omap_writew(UDC_RXN_STOP | (packets - 1), UDC_RXDMA(ep->dma_channel)); in next_out_dma()
599 w |= UDC_RX_EOT_IE(ep->dma_channel); in next_out_dma()
601 omap_writew(ep->bEndpointAddress & 0xf, UDC_EP_NUM); in next_out_dma()
604 omap_start_dma(ep->lch); in next_out_dma()
613 ep->dma_counter = (u16) (req->req.dma + req->req.actual); in finish_out_dma()
614 count = dma_dest_len(ep, req->req.dma + req->req.actual); in finish_out_dma()
615 count += req->req.actual; in finish_out_dma()
617 count--; in finish_out_dma()
618 if (count <= req->req.length) in finish_out_dma()
619 req->req.actual = count; in finish_out_dma()
621 if (count != req->dma_bytes || status) in finish_out_dma()
622 omap_stop_dma(ep->lch); in finish_out_dma()
625 else if (req->req.actual < req->req.length) in finish_out_dma()
630 w &= ~UDC_RX_EOT_IE(ep->dma_channel); in finish_out_dma()
643 ep = &udc->ep[16 + UDC_DMA_TX_SRC(dman_stat)]; in dma_irq()
644 ep->irqs++; in dma_irq()
645 /* can see TXN_DONE after dma abort */ in dma_irq()
646 if (!list_empty(&ep->queue)) { in dma_irq()
647 req = container_of(ep->queue.next, in dma_irq()
653 if (!list_empty(&ep->queue)) { in dma_irq()
654 req = container_of(ep->queue.next, in dma_irq()
662 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; in dma_irq()
663 ep->irqs++; in dma_irq()
664 /* can see RXN_EOT after dma abort */ in dma_irq()
665 if (!list_empty(&ep->queue)) { in dma_irq()
666 req = container_of(ep->queue.next, in dma_irq()
672 if (!list_empty(&ep->queue)) { in dma_irq()
673 req = container_of(ep->queue.next, in dma_irq()
680 ep = &udc->ep[UDC_DMA_RX_SRC(dman_stat)]; in dma_irq()
681 ep->irqs++; in dma_irq()
683 VDBG("%s, RX_CNT irq?\n", ep->ep.name); in dma_irq()
694 ERR("%s dma error, lch %d status %02x\n", ep->ep.name, lch, ch_status); in dma_error()
705 is_in = ep->bEndpointAddress & USB_DIR_IN; in dma_channel_claim()
712 ep->dma_channel = 0; in dma_channel_claim()
713 ep->lch = -1; in dma_channel_claim()
722 status = -EMLINK; in dma_channel_claim()
726 reg |= (0x0f & ep->bEndpointAddress) << (4 * (channel - 1)); in dma_channel_claim()
727 ep->dma_channel = channel; in dma_channel_claim()
730 dma_channel = OMAP_DMA_USB_W2FC_TX0 - 1 + channel; in dma_channel_claim()
732 ep->ep.name, dma_error, ep, &ep->lch); in dma_channel_claim()
736 omap_set_dma_src_burst_mode(ep->lch, in dma_channel_claim()
738 omap_set_dma_src_data_pack(ep->lch, 1); in dma_channel_claim()
740 omap_set_dma_dest_params(ep->lch, in dma_channel_claim()
747 dma_channel = OMAP_DMA_USB_W2FC_RX0 - 1 + channel; in dma_channel_claim()
749 ep->ep.name, dma_error, ep, &ep->lch); in dma_channel_claim()
753 omap_set_dma_src_params(ep->lch, in dma_channel_claim()
759 omap_set_dma_dest_burst_mode(ep->lch, in dma_channel_claim()
761 omap_set_dma_dest_data_pack(ep->lch, 1); in dma_channel_claim()
765 ep->dma_channel = 0; in dma_channel_claim()
767 ep->has_dma = 1; in dma_channel_claim()
768 omap_disable_dma_irq(ep->lch, OMAP_DMA_BLOCK_IRQ); in dma_channel_claim()
772 omap_set_dma_channel_mode(ep->lch, OMAP_DMA_LCH_P); in dma_channel_claim()
777 restart = !ep->stopped && !list_empty(&ep->queue); in dma_channel_claim()
780 DBG("%s no dma channel: %d%s\n", ep->ep.name, status, in dma_channel_claim()
783 DBG("%s claimed %cxdma%d lch %d%s\n", ep->ep.name, in dma_channel_claim()
785 ep->dma_channel - 1, ep->lch, in dma_channel_claim()
790 req = container_of(ep->queue.next, struct omap_req, queue); in dma_channel_claim()
791 if (ep->has_dma) in dma_channel_claim()
799 ep->ackwait = 1 + ep->double_buf; in dma_channel_claim()
808 int shift = 4 * (ep->dma_channel - 1); in dma_channel_release()
814 if (!list_empty(&ep->queue)) in dma_channel_release()
815 req = container_of(ep->queue.next, struct omap_req, queue); in dma_channel_release()
819 active = omap_get_dma_active_status(ep->lch); in dma_channel_release()
821 DBG("%s release %s %cxdma%d %p\n", ep->ep.name, in dma_channel_release()
823 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', in dma_channel_release()
824 ep->dma_channel - 1, req); in dma_channel_release()
826 /* NOTE: re-setting RX_REQ/TX_REQ because of a chip bug (before in dma_channel_release()
827 * OMAP 1710 ES2.0) where reading the DMA_CFG can clear them. in dma_channel_release()
831 if (ep->bEndpointAddress & USB_DIR_IN) { in dma_channel_release()
836 finish_in_dma(ep, req, -ECONNRESET); in dma_channel_release()
853 finish_out_dma(ep, req, -ECONNRESET, 0); in dma_channel_release()
855 omap_free_dma(ep->lch); in dma_channel_release()
856 ep->dma_channel = 0; in dma_channel_release()
857 ep->lch = -1; in dma_channel_release()
862 /*-------------------------------------------------------------------------*/
874 if (!_req || !req->req.complete || !req->req.buf in omap_ep_queue()
875 || !list_empty(&req->queue)) { in omap_ep_queue()
877 return -EINVAL; in omap_ep_queue()
879 if (!_ep || (!ep->ep.desc && ep->bEndpointAddress)) { in omap_ep_queue()
881 return -EINVAL; in omap_ep_queue()
883 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) { in omap_ep_queue()
884 if (req->req.length > ep->ep.maxpacket) in omap_ep_queue()
885 return -EMSGSIZE; in omap_ep_queue()
893 && ep->has_dma in omap_ep_queue()
894 && ep->bEndpointAddress != 0 in omap_ep_queue()
895 && (ep->bEndpointAddress & USB_DIR_IN) == 0 in omap_ep_queue()
896 && (req->req.length % ep->ep.maxpacket) != 0) { in omap_ep_queue()
898 return -EMSGSIZE; in omap_ep_queue()
901 udc = ep->udc; in omap_ep_queue()
902 if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) in omap_ep_queue()
903 return -ESHUTDOWN; in omap_ep_queue()
905 if (use_dma && ep->has_dma) in omap_ep_queue()
906 usb_gadget_map_request(&udc->gadget, &req->req, in omap_ep_queue()
907 (ep->bEndpointAddress & USB_DIR_IN)); in omap_ep_queue()
910 ep->ep.name, _req, _req->length, _req->buf); in omap_ep_queue()
912 spin_lock_irqsave(&udc->lock, flags); in omap_ep_queue()
914 req->req.status = -EINPROGRESS; in omap_ep_queue()
915 req->req.actual = 0; in omap_ep_queue()
917 /* maybe kickstart non-iso i/o queues */ in omap_ep_queue()
924 } else if (list_empty(&ep->queue) && !ep->stopped && !ep->ackwait) { in omap_ep_queue()
927 if (ep->bEndpointAddress == 0) { in omap_ep_queue()
928 if (!udc->ep0_pending || !list_empty(&ep->queue)) { in omap_ep_queue()
929 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_queue()
930 return -EL2HLT; in omap_ep_queue()
934 is_in = udc->ep0_in; in omap_ep_queue()
935 if (!req->req.length) { in omap_ep_queue()
939 * requests to non-control endpoints in omap_ep_queue()
941 if (udc->ep0_set_config) { in omap_ep_queue()
945 if (!udc->ep0_reset_config) in omap_ep_queue()
962 udc->ep0_pending = 0; in omap_ep_queue()
966 /* non-empty DATA stage */ in omap_ep_queue()
971 if (udc->ep0_setup) in omap_ep_queue()
976 is_in = ep->bEndpointAddress & USB_DIR_IN; in omap_ep_queue()
977 if (!ep->has_dma) in omap_ep_queue()
982 if (ep->has_dma) in omap_ep_queue()
990 ep->ackwait = 1 + ep->double_buf; in omap_ep_queue()
999 list_add_tail(&req->queue, &ep->queue); in omap_ep_queue()
1000 spin_unlock_irqrestore(&udc->lock, flags); in omap_ep_queue()
1012 return -EINVAL; in omap_ep_dequeue()
1014 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_dequeue()
1017 list_for_each_entry(iter, &ep->queue, queue) { in omap_ep_dequeue()
1018 if (&iter->req != _req) in omap_ep_dequeue()
1024 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_dequeue()
1025 return -EINVAL; in omap_ep_dequeue()
1028 if (use_dma && ep->dma_channel && ep->queue.next == &req->queue) { in omap_ep_dequeue()
1029 int channel = ep->dma_channel; in omap_ep_dequeue()
1037 done(ep, req, -ECONNRESET); in omap_ep_dequeue()
1038 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_dequeue()
1042 /*-------------------------------------------------------------------------*/
1048 int status = -EOPNOTSUPP; in omap_ep_set_halt()
1050 spin_lock_irqsave(&ep->udc->lock, flags); in omap_ep_set_halt()
1053 if (ep->bEndpointAddress == 0) { in omap_ep_set_halt()
1054 if (!ep->udc->ep0_pending) in omap_ep_set_halt()
1055 status = -EINVAL; in omap_ep_set_halt()
1057 if (ep->udc->ep0_set_config) { in omap_ep_set_halt()
1062 ep->udc->ep0_pending = 0; in omap_ep_set_halt()
1067 /* otherwise, all active non-ISO endpoints can halt */ in omap_ep_set_halt()
1068 } else if (ep->bmAttributes != USB_ENDPOINT_XFER_ISOC && ep->ep.desc) { in omap_ep_set_halt()
1071 if ((ep->bEndpointAddress & USB_DIR_IN) in omap_ep_set_halt()
1072 && !list_empty(&ep->queue)) { in omap_ep_set_halt()
1073 status = -EAGAIN; in omap_ep_set_halt()
1080 if (use_dma && ep->dma_channel in omap_ep_set_halt()
1081 && !list_empty(&ep->queue)) { in omap_ep_set_halt()
1082 channel = ep->dma_channel; in omap_ep_set_halt()
1092 status = -EAGAIN; in omap_ep_set_halt()
1099 omap_writew(ep->udc->clr_halt, UDC_CTRL); in omap_ep_set_halt()
1100 ep->ackwait = 0; in omap_ep_set_halt()
1101 if (!(ep->bEndpointAddress & USB_DIR_IN)) { in omap_ep_set_halt()
1103 ep->ackwait = 1 + ep->double_buf; in omap_ep_set_halt()
1108 VDBG("%s %s halt stat %d\n", ep->ep.name, in omap_ep_set_halt()
1111 spin_unlock_irqrestore(&ep->udc->lock, flags); in omap_ep_set_halt()
1130 /*-------------------------------------------------------------------------*/
1135 return (sof & UDC_TS_OK) ? (sof & UDC_TS) : -EL2NSYNC; in omap_get_frame()
1142 int retval = -EHOSTUNREACH; in omap_wakeup()
1146 spin_lock_irqsave(&udc->lock, flags); in omap_wakeup()
1147 if (udc->devstat & UDC_SUS) { in omap_wakeup()
1151 if (udc->devstat & (UDC_B_HNP_ENABLE|UDC_R_WK_OK)) { in omap_wakeup()
1157 /* NOTE: non-OTG systems may use SRP TOO... */ in omap_wakeup()
1158 } else if (!(udc->devstat & UDC_ATT)) { in omap_wakeup()
1159 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_wakeup()
1160 retval = otg_start_srp(udc->transceiver->otg); in omap_wakeup()
1162 spin_unlock_irqrestore(&udc->lock, flags); in omap_wakeup()
1174 gadget->is_selfpowered = (is_selfpowered != 0); in omap_set_selfpowered()
1176 spin_lock_irqsave(&udc->lock, flags); in omap_set_selfpowered()
1183 spin_unlock_irqrestore(&udc->lock, flags); in omap_set_selfpowered()
1190 return udc->driver && udc->softconnect && udc->vbus_active; in can_pullup()
1200 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { in pullup_enable()
1214 if (!gadget_is_otg(&udc->gadget) && !cpu_is_omap15xx()) { in pullup_disable()
1231 if (udc == NULL || udc->dc_clk == NULL || udc->hhc_clk == NULL) in omap_udc_enable_clock()
1235 clk_enable(udc->dc_clk); in omap_udc_enable_clock()
1236 clk_enable(udc->hhc_clk); in omap_udc_enable_clock()
1239 clk_disable(udc->hhc_clk); in omap_udc_enable_clock()
1240 clk_disable(udc->dc_clk); in omap_udc_enable_clock()
1245 * Called by whatever detects VBUS sessions: external transceiver
1255 spin_lock_irqsave(&udc->lock, flags); in omap_vbus_session()
1257 udc->vbus_active = (is_active != 0); in omap_vbus_session()
1267 if (udc->dc_clk != NULL && is_active) { in omap_vbus_session()
1268 if (!udc->clk_requested) { in omap_vbus_session()
1270 udc->clk_requested = 1; in omap_vbus_session()
1277 if (udc->dc_clk != NULL && !is_active) { in omap_vbus_session()
1278 if (udc->clk_requested) { in omap_vbus_session()
1280 udc->clk_requested = 0; in omap_vbus_session()
1283 spin_unlock_irqrestore(&udc->lock, flags); in omap_vbus_session()
1292 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_vbus_draw()
1293 return usb_phy_set_power(udc->transceiver, mA); in omap_vbus_draw()
1294 return -EOPNOTSUPP; in omap_vbus_draw()
1303 spin_lock_irqsave(&udc->lock, flags); in omap_pullup()
1304 udc->softconnect = (is_on != 0); in omap_pullup()
1309 spin_unlock_irqrestore(&udc->lock, flags); in omap_pullup()
1328 /*-------------------------------------------------------------------------*/
1330 /* dequeue ALL requests; caller holds udc->lock */
1335 ep->stopped = 1; in nuke()
1337 if (use_dma && ep->dma_channel) in nuke()
1342 if (ep->bEndpointAddress && ep->bmAttributes != USB_ENDPOINT_XFER_ISOC) in nuke()
1345 while (!list_empty(&ep->queue)) { in nuke()
1346 req = list_entry(ep->queue.next, struct omap_req, queue); in nuke()
1351 /* caller holds udc->lock */
1356 udc->gadget.speed = USB_SPEED_UNKNOWN; in udc_quiesce()
1357 nuke(&udc->ep[0], -ESHUTDOWN); in udc_quiesce()
1358 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) in udc_quiesce()
1359 nuke(ep, -ESHUTDOWN); in udc_quiesce()
1362 /*-------------------------------------------------------------------------*/
1368 if (!gadget_is_otg(&udc->gadget)) in update_otg()
1376 udc->gadget.b_hnp_enable = !!(devstat & UDC_B_HNP_ENABLE); in update_otg()
1377 udc->gadget.a_hnp_support = !!(devstat & UDC_A_HNP_SUPPORT); in update_otg()
1378 udc->gadget.a_alt_hnp_support = !!(devstat & UDC_A_ALT_HNP_SUPPORT); in update_otg()
1383 if (udc->gadget.b_hnp_enable) { in update_otg()
1395 struct omap_ep *ep0 = &udc->ep[0]; in ep0_irq()
1398 ep0->irqs++; in ep0_irq()
1421 if (!list_empty(&ep0->queue)) in ep0_irq()
1422 req = container_of(ep0->queue.next, struct omap_req, queue); in ep0_irq()
1432 if (udc->ep0_in) { in ep0_irq()
1439 if (!req && udc->ep0_pending) { in ep0_irq()
1444 udc->ep0_pending = 0; in ep0_irq()
1469 if (!udc->ep0_in) { in ep0_irq()
1477 udc->ep0_pending = 0; in ep0_irq()
1492 udc->ep0_pending = 0; in ep0_irq()
1514 int status = -EINVAL; in ep0_irq()
1536 udc->ep0_in = (u.r.bRequestType & USB_DIR_IN) != 0; in ep0_irq()
1537 udc->ep0_set_config = 0; in ep0_irq()
1538 udc->ep0_pending = 1; in ep0_irq()
1539 ep0->stopped = 0; in ep0_irq()
1540 ep0->ackwait = 0; in ep0_irq()
1548 udc->ep0_set_config = 1; in ep0_irq()
1549 udc->ep0_reset_config = (w_value == 0); in ep0_irq()
1556 if (udc->ep0_reset_config) in ep0_irq()
1569 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1573 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in ep0_irq()
1574 || !ep->ep.desc) in ep0_irq()
1577 omap_writew(udc->clr_halt, UDC_CTRL); in ep0_irq()
1578 ep->ackwait = 0; in ep0_irq()
1579 if (!(ep->bEndpointAddress & USB_DIR_IN)) { in ep0_irq()
1581 ep->ackwait = 1 + ep->double_buf; in ep0_irq()
1589 VDBG("%s halt cleared by host\n", ep->name); in ep0_irq()
1598 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1601 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC in ep0_irq()
1602 || ep == ep0 || !ep->ep.desc) in ep0_irq()
1604 if (use_dma && ep->has_dma) { in ep0_irq()
1605 /* this has rude side-effects (aborts) and in ep0_irq()
1606 * can't really work if DMA-IN is active in ep0_irq()
1608 DBG("%s host set_halt, NYET\n", ep->name); in ep0_irq()
1612 /* can't halt if fifo isn't empty... */ in ep0_irq()
1615 VDBG("%s halted by host\n", ep->name); in ep0_irq()
1622 udc->ep0_pending = 0; in ep0_irq()
1634 ep = &udc->ep[w_index & 0xf]; in ep0_irq()
1637 if (!ep->ep.desc) in ep0_irq()
1641 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in ep0_irq()
1644 /* FIXME don't assume non-halted endpoints!! */ in ep0_irq()
1645 ERR("%s status, can't report\n", ep->ep.name); in ep0_irq()
1650 * we'd detect non-existent interfaces, and stall. in ep0_irq()
1669 if (!udc->ep0_in && w_length) { in ep0_irq()
1697 udc->ep0_setup = 1; in ep0_irq()
1698 spin_unlock(&udc->lock); in ep0_irq()
1699 status = udc->driver->setup(&udc->gadget, &u.r); in ep0_irq()
1700 spin_lock(&udc->lock); in ep0_irq()
1701 udc->ep0_setup = 0; in ep0_irq()
1708 if (udc->ep0_set_config) { in ep0_irq()
1709 if (udc->ep0_reset_config) in ep0_irq()
1715 udc->ep0_pending = 0; in ep0_irq()
1720 /*-------------------------------------------------------------------------*/
1729 change = devstat ^ udc->devstat; in devstate_irq()
1730 udc->devstat = devstat; in devstate_irq()
1736 /* driver for any external transceiver will in devstate_irq()
1740 udc->gadget.speed = USB_SPEED_FULL; in devstate_irq()
1742 if (IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1744 /* if (driver->connect) call it */ in devstate_irq()
1745 } else if (udc->gadget.speed != USB_SPEED_UNKNOWN) { in devstate_irq()
1746 udc->gadget.speed = USB_SPEED_UNKNOWN; in devstate_irq()
1747 if (IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1750 udc->driver->driver.name); in devstate_irq()
1751 if (udc->driver->disconnect) { in devstate_irq()
1752 spin_unlock(&udc->lock); in devstate_irq()
1753 udc->driver->disconnect(&udc->gadget); in devstate_irq()
1754 spin_lock(&udc->lock); in devstate_irq()
1764 udc->gadget.speed = USB_SPEED_FULL; in devstate_irq()
1766 udc->driver->driver.name); in devstate_irq()
1775 if (udc->gadget.speed != USB_SPEED_UNKNOWN) { in devstate_irq()
1781 if (udc->gadget.speed == USB_SPEED_FULL in devstate_irq()
1782 && udc->driver->suspend) { in devstate_irq()
1783 spin_unlock(&udc->lock); in devstate_irq()
1784 udc->driver->suspend(&udc->gadget); in devstate_irq()
1785 spin_lock(&udc->lock); in devstate_irq()
1787 if (!IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1789 udc->transceiver, 1); in devstate_irq()
1792 if (!IS_ERR_OR_NULL(udc->transceiver)) in devstate_irq()
1794 udc->transceiver, 0); in devstate_irq()
1795 if (udc->gadget.speed == USB_SPEED_FULL in devstate_irq()
1796 && udc->driver->resume) { in devstate_irq()
1797 spin_unlock(&udc->lock); in devstate_irq()
1798 udc->driver->resume(&udc->gadget); in devstate_irq()
1799 spin_lock(&udc->lock); in devstate_irq()
1825 spin_lock_irqsave(&udc->lock, flags); in omap_udc_irq()
1852 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_irq()
1857 /* workaround for seemingly-lost IRQs for RX ACKs... */
1867 spin_lock_irqsave(&ep->udc->lock, flags); in pio_out_timer()
1868 if (!list_empty(&ep->queue) && ep->ackwait) { in pio_out_timer()
1873 || (ep->double_buf && HALF_FULL(stat_flg)))) { in pio_out_timer()
1876 VDBG("%s: lose, %04x\n", ep->ep.name, stat_flg); in pio_out_timer()
1877 req = container_of(ep->queue.next, in pio_out_timer()
1880 omap_writew(ep->bEndpointAddress, UDC_EP_NUM); in pio_out_timer()
1882 ep->ackwait = 1 + ep->double_buf; in pio_out_timer()
1886 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); in pio_out_timer()
1887 spin_unlock_irqrestore(&ep->udc->lock, flags); in pio_out_timer()
1900 spin_lock_irqsave(&udc->lock, flags); in omap_udc_pio_irq()
1909 ep = &udc->ep[epnum]; in omap_udc_pio_irq()
1910 ep->irqs++; in omap_udc_pio_irq()
1913 ep->fnf = 0; in omap_udc_pio_irq()
1915 ep->ackwait--; in omap_udc_pio_irq()
1916 if (!list_empty(&ep->queue)) { in omap_udc_pio_irq()
1918 req = container_of(ep->queue.next, in omap_udc_pio_irq()
1921 if (!ep->double_buf) in omap_udc_pio_irq()
1922 ep->fnf = 1; in omap_udc_pio_irq()
1933 if (ep->fnf) { in omap_udc_pio_irq()
1935 ep->ackwait = 1 + ep->double_buf; in omap_udc_pio_irq()
1937 mod_timer(&ep->timer, PIO_OUT_TIMEOUT); in omap_udc_pio_irq()
1945 ep = &udc->ep[16 + epnum]; in omap_udc_pio_irq()
1946 ep->irqs++; in omap_udc_pio_irq()
1950 ep->ackwait = 0; in omap_udc_pio_irq()
1951 if (!list_empty(&ep->queue)) { in omap_udc_pio_irq()
1952 req = container_of(ep->queue.next, in omap_udc_pio_irq()
1964 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_pio_irq()
1976 spin_lock_irqsave(&udc->lock, flags); in omap_udc_iso_irq()
1978 /* handle all non-DMA ISO transfers */ in omap_udc_iso_irq()
1979 list_for_each_entry(ep, &udc->iso, iso) { in omap_udc_iso_irq()
1983 if (ep->has_dma || list_empty(&ep->queue)) in omap_udc_iso_irq()
1985 req = list_entry(ep->queue.next, struct omap_req, queue); in omap_udc_iso_irq()
1993 if (ep->bEndpointAddress & USB_DIR_IN) { in omap_udc_iso_irq()
1995 /* done(ep, req, -EPROTO) */; in omap_udc_iso_irq()
2002 status = -EREMOTEIO; in omap_udc_iso_irq()
2004 status = -EILSEQ; in omap_udc_iso_irq()
2006 status = -ENOSR; in omap_udc_iso_irq()
2016 ep->irqs++; in omap_udc_iso_irq()
2017 if (!list_empty(&ep->queue)) in omap_udc_iso_irq()
2029 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_iso_irq()
2034 /*-------------------------------------------------------------------------*/
2050 spin_lock_irqsave(&udc->lock, flags); in omap_udc_start()
2052 list_for_each_entry(ep, &udc->gadget.ep_list, ep.ep_list) { in omap_udc_start()
2053 ep->irqs = 0; in omap_udc_start()
2054 if (ep->bmAttributes == USB_ENDPOINT_XFER_ISOC) in omap_udc_start()
2059 udc->ep0_pending = 0; in omap_udc_start()
2060 udc->ep[0].irqs = 0; in omap_udc_start()
2061 udc->softconnect = 1; in omap_udc_start()
2064 udc->driver = driver; in omap_udc_start()
2065 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_start()
2067 if (udc->dc_clk != NULL) in omap_udc_start()
2072 /* connect to bus through transceiver */ in omap_udc_start()
2073 if (!IS_ERR_OR_NULL(udc->transceiver)) { in omap_udc_start()
2074 status = otg_set_peripheral(udc->transceiver->otg, in omap_udc_start()
2075 &udc->gadget); in omap_udc_start()
2077 ERR("can't bind to transceiver\n"); in omap_udc_start()
2078 udc->driver = NULL; in omap_udc_start()
2089 /* boards that don't have VBUS sensing can't autogate 48MHz; in omap_udc_start()
2090 * can't enter deep sleep while a gadget driver is active. in omap_udc_start()
2093 omap_vbus_session(&udc->gadget, 1); in omap_udc_start()
2096 if (udc->dc_clk != NULL) in omap_udc_start()
2106 if (udc->dc_clk != NULL) in omap_udc_stop()
2110 omap_vbus_session(&udc->gadget, 0); in omap_udc_stop()
2112 if (!IS_ERR_OR_NULL(udc->transceiver)) in omap_udc_stop()
2113 (void) otg_set_peripheral(udc->transceiver->otg, NULL); in omap_udc_stop()
2117 spin_lock_irqsave(&udc->lock, flags); in omap_udc_stop()
2119 spin_unlock_irqrestore(&udc->lock, flags); in omap_udc_stop()
2121 udc->driver = NULL; in omap_udc_stop()
2123 if (udc->dc_clk != NULL) in omap_udc_stop()
2129 /*-------------------------------------------------------------------------*/
2148 if (use_dma && ep->has_dma) in proc_ep_show()
2150 (ep->bEndpointAddress & USB_DIR_IN) ? 't' : 'r', in proc_ep_show()
2151 ep->dma_channel - 1, ep->lch); in proc_ep_show()
2158 ep->name, buf, in proc_ep_show()
2159 ep->double_buf ? "dbuf " : "", in proc_ep_show()
2161 switch (ep->ackwait) { in proc_ep_show()
2175 ep->irqs, stat_flg, in proc_ep_show()
2190 if (list_empty(&ep->queue)) in proc_ep_show()
2193 list_for_each_entry(req, &ep->queue, queue) { in proc_ep_show()
2194 unsigned length = req->req.actual; in proc_ep_show()
2197 length += ((ep->bEndpointAddress & USB_DIR_IN) in proc_ep_show()
2199 (ep, req->req.dma + length); in proc_ep_show()
2203 &req->req, length, in proc_ep_show()
2204 req->req.length, req->req.buf); in proc_ep_show()
2299 spin_lock_irqsave(&udc->lock, flags); in proc_udc_show()
2310 "hmc %d, transceiver %s\n", in proc_udc_show()
2313 udc->driver ? udc->driver->driver.name : "(none)", in proc_udc_show()
2315 udc->transceiver in proc_udc_show()
2316 ? udc->transceiver->label in proc_udc_show()
2338 /* syscon2 is write-only */ in proc_udc_show()
2343 spin_unlock_irqrestore(&udc->lock, flags); in proc_udc_show()
2420 proc_ep_show(s, &udc->ep[0]); in proc_udc_show()
2422 list_for_each_entry(ep, &udc->gadget.ep_list, in proc_udc_show()
2424 if (ep->ep.desc) in proc_udc_show()
2429 spin_unlock_irqrestore(&udc->lock, flags); in proc_udc_show()
2450 /*-------------------------------------------------------------------------*/
2452 /* Before this controller can enumerate, we need to pick an endpoint
2457 * UDC_SYSCON_1.CFG_LOCK is set can now work. We won't use that
2468 ep = &udc->ep[addr & 0xf]; in omap_ep_setup()
2473 BUG_ON(ep->name[0]); in omap_ep_setup()
2505 /* double-buffering "not supported" on 15xx, in omap_ep_setup()
2506 * and ignored for PIO-IN on newer chips in omap_ep_setup()
2530 timer_setup(&ep->timer, pio_out_timer, 0); in omap_ep_setup()
2552 BUG_ON(strlen(name) >= sizeof ep->name); in omap_ep_setup()
2553 strscpy(ep->name, name, sizeof(ep->name)); in omap_ep_setup()
2554 INIT_LIST_HEAD(&ep->queue); in omap_ep_setup()
2555 INIT_LIST_HEAD(&ep->iso); in omap_ep_setup()
2556 ep->bEndpointAddress = addr; in omap_ep_setup()
2557 ep->bmAttributes = type; in omap_ep_setup()
2558 ep->double_buf = dbuf; in omap_ep_setup()
2559 ep->udc = udc; in omap_ep_setup()
2563 ep->ep.caps.type_control = true; in omap_ep_setup()
2564 ep->ep.caps.dir_in = true; in omap_ep_setup()
2565 ep->ep.caps.dir_out = true; in omap_ep_setup()
2568 ep->ep.caps.type_iso = true; in omap_ep_setup()
2571 ep->ep.caps.type_bulk = true; in omap_ep_setup()
2574 ep->ep.caps.type_int = true; in omap_ep_setup()
2579 ep->ep.caps.dir_in = true; in omap_ep_setup()
2581 ep->ep.caps.dir_out = true; in omap_ep_setup()
2583 ep->ep.name = ep->name; in omap_ep_setup()
2584 ep->ep.ops = &omap_ep_ops; in omap_ep_setup()
2585 ep->maxpacket = maxp; in omap_ep_setup()
2586 usb_ep_set_maxpacket_limit(&ep->ep, ep->maxpacket); in omap_ep_setup()
2587 list_add_tail(&ep->ep.ep_list, &udc->gadget.ep_list); in omap_ep_setup()
2595 if (!IS_ERR_OR_NULL(udc->transceiver)) { in omap_udc_release()
2596 usb_put_phy(udc->transceiver); in omap_udc_release()
2597 udc->transceiver = NULL; in omap_udc_release()
2601 if (udc->dc_clk) { in omap_udc_release()
2602 if (udc->clk_requested) in omap_udc_release()
2604 clk_unprepare(udc->hhc_clk); in omap_udc_release()
2605 clk_unprepare(udc->dc_clk); in omap_udc_release()
2606 clk_put(udc->hhc_clk); in omap_udc_release()
2607 clk_put(udc->dc_clk); in omap_udc_release()
2609 if (udc->done) in omap_udc_release()
2610 complete(udc->done); in omap_udc_release()
2632 return -ENOMEM; in omap_udc_setup()
2634 spin_lock_init(&udc->lock); in omap_udc_setup()
2636 udc->gadget.ops = &omap_gadget_ops; in omap_udc_setup()
2637 udc->gadget.ep0 = &udc->ep[0].ep; in omap_udc_setup()
2638 INIT_LIST_HEAD(&udc->gadget.ep_list); in omap_udc_setup()
2639 INIT_LIST_HEAD(&udc->iso); in omap_udc_setup()
2640 udc->gadget.speed = USB_SPEED_UNKNOWN; in omap_udc_setup()
2641 udc->gadget.max_speed = USB_SPEED_FULL; in omap_udc_setup()
2642 udc->gadget.name = driver_name; in omap_udc_setup()
2643 udc->gadget.quirk_ep_out_aligned_size = 1; in omap_udc_setup()
2644 udc->transceiver = xceiv; in omap_udc_setup()
2649 list_del_init(&udc->ep[0].ep.ep_list); in omap_udc_setup()
2651 /* initially disable all non-ep0 endpoints */ in omap_udc_setup()
2658 buf = omap_ep_setup(name "-bulk", addr, \ in omap_udc_setup()
2661 buf = omap_ep_setup(name "-int", addr, \ in omap_udc_setup()
2664 buf = omap_ep_setup(name "-iso", addr, \ in omap_udc_setup()
2737 return -ENODEV; in omap_udc_setup()
2740 INFO("fifo mode %d, %d bytes not used\n", fifo_mode, 2048 - buf); in omap_udc_setup()
2746 int status = -ENODEV; in omap_udc_probe()
2750 struct omap_usb_config *config = dev_get_platdata(&pdev->dev); in omap_udc_probe()
2755 if (!request_mem_region(pdev->resource[0].start, in omap_udc_probe()
2756 resource_size(&pdev->resource[0]), in omap_udc_probe()
2759 return -EBUSY; in omap_udc_probe()
2763 dc_clk = clk_get(&pdev->dev, "usb_dc_ck"); in omap_udc_probe()
2764 hhc_clk = clk_get(&pdev->dev, "usb_hhc_ck"); in omap_udc_probe()
2766 /* can't use omap_udc_enable_clock yet */ in omap_udc_probe()
2774 config->otg ? ", Mini-AB" : ""); in omap_udc_probe()
2784 * FIXME without really sensing VBUS, we can't in omap_udc_probe()
2796 /* The transceiver may package some GPIO logic or handle in omap_udc_probe()
2803 type = xceiv->label; in omap_udc_probe()
2804 else if (config->otg) { in omap_udc_probe()
2805 DBG("OTG requires external transceiver!\n"); in omap_udc_probe()
2827 DBG("external transceiver not registered!\n"); in omap_udc_probe()
2850 INFO("hmc mode %d, %s transceiver\n", hmc, type); in omap_udc_probe()
2861 udc->gadget.is_otg = (config->otg != 0); in omap_udc_probe()
2866 udc->clr_halt = UDC_RESET_EP | UDC_CLRDATA_TOGGLE; in omap_udc_probe()
2868 udc->clr_halt = UDC_RESET_EP; in omap_udc_probe()
2871 status = devm_request_irq(&pdev->dev, pdev->resource[1].start, in omap_udc_probe()
2874 ERR("can't get irq %d, err %d\n", in omap_udc_probe()
2875 (int) pdev->resource[1].start, status); in omap_udc_probe()
2879 /* USB "non-iso" IRQ (PIO for all but ep0) */ in omap_udc_probe()
2880 status = devm_request_irq(&pdev->dev, pdev->resource[2].start, in omap_udc_probe()
2883 ERR("can't get irq %d, err %d\n", in omap_udc_probe()
2884 (int) pdev->resource[2].start, status); in omap_udc_probe()
2888 status = devm_request_irq(&pdev->dev, pdev->resource[3].start, in omap_udc_probe()
2891 ERR("can't get irq %d, err %d\n", in omap_udc_probe()
2892 (int) pdev->resource[3].start, status); in omap_udc_probe()
2897 udc->dc_clk = dc_clk; in omap_udc_probe()
2898 udc->hhc_clk = hhc_clk; in omap_udc_probe()
2904 return usb_add_gadget_udc_release(&pdev->dev, &udc->gadget, in omap_udc_probe()
2922 release_mem_region(pdev->resource[0].start, in omap_udc_probe()
2923 resource_size(&pdev->resource[0])); in omap_udc_probe()
2932 udc->done = &done; in omap_udc_remove()
2934 usb_del_gadget_udc(&udc->gadget); in omap_udc_remove()
2938 release_mem_region(pdev->resource[0].start, in omap_udc_remove()
2939 resource_size(&pdev->resource[0])); in omap_udc_remove()
2946 * session active, rather than disconnecting, at least on boards that can
2949 * may involve talking to an external transceiver (e.g. isp1301).
2964 omap_pullup(&udc->gadget, 0); in omap_udc_suspend()
2973 omap_pullup(&udc->gadget, 1); in omap_udc_resume()
2977 return omap_wakeup(&udc->gadget); in omap_udc_resume()
2980 /*-------------------------------------------------------------------------*/